From kde-commits Mon Feb 29 23:12:19 2016 From: Jaroslaw Staniek Date: Mon, 29 Feb 2016 23:12:19 +0000 To: kde-commits Subject: [kexi] src: Make the default "Smallest readable font" used by Kexi in property editor, toolbar, etc. Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=145678878529768 Git commit bb8f8f4bef601aa86eb2db590490d9a0142d4a39 by Jaroslaw Staniek. Committed on 29/02/2016 at 23:07. Pushed by staniek into branch 'master'. Make the default "Smallest readable font" used by Kexi in property editor, = toolbar, etc. - make it work without platform plugins - keep PropertyEditor/FontSize setting for pixel size, use it properly - add PropertyEditor/FontPointSize setting for specifying point size - don't depend on screen resolution, it's is a risky choice FIXED-IN:2.9.11 BUG:358662 (from calligra.git ed015764e30b1) M +2 -2 src/core/KexiView.cpp M +1 -0 src/kexiutils/CMakeLists.txt A +76 -0 src/kexiutils/FontSettings_p.cpp [License: LGPL (v2+)] A +76 -0 src/kexiutils/FontSettings_p.h [License: LGPL (v2+)] M +1 -1 src/kexiutils/SmallToolButton.cpp M +2 -2 src/kexiutils/debuggui.cpp M +4 -11 src/kexiutils/utils.cpp M +5 -4 src/kexiutils/utils.h M +10 -6 src/main/KexiMainWindow.cpp M +0 -1 src/main/KexiMainWindow_p.cpp M +1 -1 src/widget/relations/KexiRelationsConnection.cpp M +1 -1 src/widget/utils/kexirecordnavigator.cpp http://commits.kde.org/kexi/bb8f8f4bef601aa86eb2db590490d9a0142d4a39 diff --git a/src/core/KexiView.cpp b/src/core/KexiView.cpp index 29a342b..04b11a7 100644 --- a/src/core/KexiView.cpp +++ b/src/core/KexiView.cpp @@ -148,7 +148,7 @@ public: btn->setText(text); btn->setIcon(a->icon()); QFont f(q->font()); - f.setPixelSize(KexiUtils::smallFont().pixelSize()); + f.setPointSizeF(KexiUtils::smallestReadableFont().pointSizeF()); btn->setFont(f); btn->setToolTip(a->toolTip()); btn->setWhatsThis(a->whatsThis()); @@ -239,7 +239,7 @@ KexiView::KexiView(QWidget *parent) = if (parentWidget()->inherits("KexiWindow")) { d->topBarHWidget =3D new QWidget(this); - d->topBarHWidget->setFont(KexiUtils::smallFont()); + d->topBarHWidget->setFont(KexiUtils::smallestReadableFont()); d->mainLyr->addWidget(d->topBarHWidget); QHBoxLayout *topBarHLyr =3D new QHBoxLayout(d->topBarHWidget); //n= eeded unless KexiFlowLayout properly handles contents margins topBarHLyr->setContentsMargins(0, 0, 0, 0); diff --git a/src/kexiutils/CMakeLists.txt b/src/kexiutils/CMakeLists.txt index d5624c4..8a4dea2 100644 --- a/src/kexiutils/CMakeLists.txt +++ b/src/kexiutils/CMakeLists.txt @@ -4,6 +4,7 @@ include_directories(completer) = set(kexiutils_LIB_SRCS utils.cpp + FontSettings_p.cpp InternalPropertyMap.cpp SmallToolButton.cpp KexiCommandLinkButton.cpp diff --git a/src/kexiutils/FontSettings_p.cpp b/src/kexiutils/FontSettings_= p.cpp new file mode 100644 index 0000000..a0a7a2c --- /dev/null +++ b/src/kexiutils/FontSettings_p.cpp @@ -0,0 +1,76 @@ +/* This file is part of the KDE project + Copyright (C) 2003-2016 Jaros=C5=82aw Staniek + + Contains code from kfontsettingsdata.cpp: + Copyright (C) 2000, 2006 David Faure + Copyright 2008 Friedrich W. H. Kossebau + Copyright 2013 Aleix Pol Gonzalez + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public Licen= se + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include "FontSettings_p.h" +#include + +FontSettingsData::FontSettingsData() +{ + for (int i =3D 0; i < FontTypesCount; ++i) { + m_fonts[i] =3D 0; + } +} + +FontSettingsData::~FontSettingsData() +{ + for (int i =3D 0; i < FontTypesCount; ++i) { + delete m_fonts[i]; + } +} + +static const char GeneralId[] =3D "General"; +static const char DefaultFont[] =3D "Noto Sans"; + +static const FontData DefaultFontData[FontSettingsData::FontTypesCount] = =3D { + { GeneralId, "font", DefaultFont, 10, -1, QFont::Sans= Serif }, + { GeneralId, "fixed", "Oxygen Mono", 9, -1, QFont::Mon= ospace }, + { GeneralId, "toolBarFont", DefaultFont, 9, -1, QFont::SansS= erif }, + { GeneralId, "menuFont", DefaultFont, 10, -1, QFont::Sans= Serif }, + { "WM", "activeFont", DefaultFont, 10, -1, QFont::Sans= Serif }, + { GeneralId, "taskbarFont", DefaultFont, 10, -1, QFont::Sans= Serif }, + { GeneralId, "smallestReadableFont", DefaultFont, 8, -1, QFont::SansS= erif } +}; + +QFont FontSettingsData::font(FontTypes fontType) +{ + QFont *cachedFont =3D m_fonts[fontType]; + if (!cachedFont) { + const FontData &fontData =3D DefaultFontData[fontType]; + cachedFont =3D new QFont(fontData.FontName, fontData.Size, fontDat= a.Weight); + cachedFont->setStyleHint(fontData.StyleHint); + if (!m_kdeGlobals) { + m_kdeGlobals =3D KSharedConfig::openConfig(QStringLiteral("kde= globals"), KConfig::NoGlobals); + } + const KConfigGroup configGroup(m_kdeGlobals, fontData.ConfigGroupK= ey); + QString fontInfo =3D configGroup.readEntry(fontData.ConfigKey, QSt= ring()); + + //If we have serialized information for this font, restore it + //NOTE: We are not using KConfig directly because we can't call QF= ont::QFont from here + if (!fontInfo.isEmpty()) { + cachedFont->fromString(fontInfo); + } + m_fonts[fontType] =3D cachedFont; + } + return *cachedFont; +} diff --git a/src/kexiutils/FontSettings_p.h b/src/kexiutils/FontSettings_p.h new file mode 100644 index 0000000..4c2b021 --- /dev/null +++ b/src/kexiutils/FontSettings_p.h @@ -0,0 +1,76 @@ +/* This file is part of the KDE project + Copyright (C) 2003-2016 Jaros=C5=82aw Staniek + + Contains code from kfontsettingsdata.cpp: + Copyright (C) 2000, 2006 David Faure + Copyright 2008 Friedrich W. H. Kossebau + Copyright 2013 Aleix Pol Gonzalez + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public Licen= se + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef KEXIUTILS_FONTSETTINGS_H +#define KEXIUTILS_FONTSETTINGS_H + +#include +#include + +//! @internal For KexiUtils::smallestReadableFont(), etc. +struct FontData { + const char *ConfigGroupKey; + const char *ConfigKey; + const char *FontName; + int Size; + int Weight; + QFont::StyleHint StyleHint; +}; + +//! @internal For KexiUtils::smallestReadableFont(), etc. +class FontSettingsData // : public QObject +{ + //Q_OBJECT +public: + // if adding a new type here also add an entry to DefaultFontData + enum FontTypes { + GeneralFont =3D 0, + FixedFont, + ToolbarFont, + MenuFont, + WindowTitleFont, + TaskbarFont, + SmallestReadableFont, + FontTypesCount + }; + +public: + FontSettingsData(); + ~FontSettingsData(); + +//public Q_SLOTS: +// void dropFontSettingsCache(); + +//private Q_SLOTS: +// void delayedDBusConnects(); + +public: // access, is not const due to caching + QFont font(FontTypes fontType); + +private: + QFont *m_fonts[FontTypesCount]; + KSharedConfigPtr m_kdeGlobals; +}; + +#endif diff --git a/src/kexiutils/SmallToolButton.cpp b/src/kexiutils/SmallToolBut= ton.cpp index 90557a0..fdde344 100644 --- a/src/kexiutils/SmallToolButton.cpp +++ b/src/kexiutils/SmallToolButton.cpp @@ -108,7 +108,7 @@ void KexiSmallToolButton::init() { setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); QFont f(font()); - f.setPixelSize(KexiUtils::smallFont().pixelSize()); + f.setPointSizeF(KexiUtils::smallestReadableFont().pointSizeF()); setFont(f); setAutoRaise(true); QToolButton::setToolButtonStyle(Qt::ToolButtonTextBesideIcon); diff --git a/src/kexiutils/debuggui.cpp b/src/kexiutils/debuggui.cpp index 469eeb7..4e0e672 100644 --- a/src/kexiutils/debuggui.cpp +++ b/src/kexiutils/debuggui.cpp @@ -61,7 +61,7 @@ static void addKexiDBDebug(const QString& text) = kexiDBDebugPage =3D new KexiDBDebugTreeWidget(page); kexiDBDebugPage->setObjectName("kexiDbDebugPage"); - kexiDBDebugPage->setFont(KexiUtils::smallFont(kexiDBDebugPage)); + kexiDBDebugPage->setFont(KexiUtils::smallestReadableFont()); QObject::connect(btn_copy, SIGNAL(clicked()), kexiDBDebugPage, SLO= T(copy())); QObject::connect(btn_clear, SIGNAL(clicked()), kexiDBDebugPage, SL= OT(clear())); vbox->addWidget(kexiDBDebugPage); @@ -114,7 +114,7 @@ static void addAlterTableActionDebug(const QString& tex= t, int nestingLevel) hbox->addWidget(btn_sim); = kexiAlterTableActionDebugPage =3D new QTreeWidget(page); - kexiAlterTableActionDebugPage->setFont(KexiUtils::smallFont(kexiAl= terTableActionDebugPage)); + kexiAlterTableActionDebugPage->setFont(KexiUtils::smallestReadable= Font()); kexiAlterTableActionDebugPage->setObjectName("kexiAlterTableAction= DebugPage"); QObject::connect(btn_clear, SIGNAL(clicked()), kexiAlterTableActio= nDebugPage, SLOT(clear())); vbox->addWidget(kexiAlterTableActionDebugPage); diff --git a/src/kexiutils/utils.cpp b/src/kexiutils/utils.cpp index 695ef15..b35e29f 100644 --- a/src/kexiutils/utils.cpp +++ b/src/kexiutils/utils.cpp @@ -30,6 +30,7 @@ = #include "utils.h" #include "utils_p.h" +#include "FontSettings_p.h" #include "kexiutils_global.h" #include = @@ -543,19 +544,11 @@ const WidgetMargins KexiUtils::operator+ ( = //--------- = -Q_GLOBAL_STATIC(QFont, _smallFont) +Q_GLOBAL_STATIC(FontSettingsData, g_fontSettings) = -QFont KexiUtils::smallFont(QWidget *init) +QFont KexiUtils::smallestReadableFont() { - if (init) { - *_smallFont =3D init->font(); - const int wdth =3D QApplication::desktop()->screenGeometry(init).w= idth(); - int size =3D 10 + qMax(0, wdth - 1100) / 100; - size =3D qMin(init->fontInfo().pixelSize(), size); - size =3D qMax(QFontDatabase::systemFont(QFontDatabase::SmallestRea= dableFont).pixelSize(), size); - _smallFont->setPixelSize(size); - } - return *_smallFont; + return g_fontSettings->font(FontSettingsData::SmallestReadableFont); } = //--------------------- diff --git a/src/kexiutils/utils.h b/src/kexiutils/utils.h index 320041b..bdad04f 100644 --- a/src/kexiutils/utils.h +++ b/src/kexiutils/utils.h @@ -242,10 +242,11 @@ KEXIUTILS_EXPORT QUrl getSaveImageUrl(QWidget *parent= =3D 0, const QString &captio const QUrl &directory =3D QUrl()); = /*! A global setting for minimal readable font. - \a init is a widget that should be passed if no qApp->mainWidget() is ava= ilable yet. - The size of font is not smaller than the one returned by - QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont). */ -KEXIUTILS_EXPORT QFont smallFont(QWidget *init =3D 0); + This can be used in dockers, rulers and other places where space is at a = premium. + @see QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont). + @todo Add integration with KDE platform theme (how to detect it?); for no= w we don't assume it's installed +*/ +KEXIUTILS_EXPORT QFont smallestReadableFont(); = /*! \return a color being a result of blending \a c1 with \a c2 with \a fa= ctor1 and \a factor1 factors: (c1*factor1+c2*factor2)/(factor1+factor2). */ diff --git a/src/main/KexiMainWindow.cpp b/src/main/KexiMainWindow.cpp index 101e13b..89649a1 100644 --- a/src/main/KexiMainWindow.cpp +++ b/src/main/KexiMainWindow.cpp @@ -428,8 +428,6 @@ KexiMainWindow::KexiMainWindow(QWidget *parent) setupMainWidget(); updateAppCaption(); = - (void)KexiUtils::smallFont(this/*init*/); - if (!d->userMode) { setupContextHelp(); setupPropertyEditor(); @@ -1945,10 +1943,16 @@ void KexiMainWindow::setupPropertyEditor() //! @todo REMOVE? d->propEditor->installEventFilter(this); = KConfigGroup propertyEditorGroup(d->config->group("PropertyEditor"= )); - int size =3D propertyEditorGroup.readEntry("FontSize", -1); - QFont f(KexiUtils::smallFont()); - if (size > 0) - f.setPixelSize(size); + QFont f(KexiUtils::smallestReadableFont()); + const qreal pointSizeF =3D propertyEditorGroup.readEntry("FontPoin= tSize", -1.0f); // points are more accurate + if (pointSizeF > 0.0) { + f.setPointSizeF(pointSizeF); + } else { + const int pixelSize =3D propertyEditorGroup.readEntry("FontSiz= e", -1); // compatibility with Kexi 2.x + if (pixelSize > 0) { + f.setPixelSize(pixelSize); + } + } d->propEditorTabWidget->setFont(f); = d->enable_slotPropertyEditorVisibilityChanged =3D false; diff --git a/src/main/KexiMainWindow_p.cpp b/src/main/KexiMainWindow_p.cpp index d72e2a0..14eb050 100644 --- a/src/main/KexiMainWindow_p.cpp +++ b/src/main/KexiMainWindow_p.cpp @@ -621,7 +621,6 @@ KexiTabbedToolBar::KexiTabbedToolBar(QWidget *parent) const bool userMode =3D KexiMainWindowIface::global()->userMode(); KToolBar *tbar; = - KexiUtils::smallFont(this/*init*/); slotSettingsChanged(0);//KGlobalSettings::FontChanged //! @todo KEXI3 port from KGlobalSettings::Private::_k_slotNotifyChang= e: //! connect(KGlobalSettings::self(), SIGNAL(settingsChanged(int)), thi= s, SLOT(slotSettingsChanged(int))); diff --git a/src/widget/relations/KexiRelationsConnection.cpp b/src/widget/= relations/KexiRelationsConnection.cpp index e7e5cd4..eb4455c 100644 --- a/src/widget/relations/KexiRelationsConnection.cpp +++ b/src/widget/relations/KexiRelationsConnection.cpp @@ -90,7 +90,7 @@ KexiRelationsConnection::drawConnection(QPainter *p) int rx =3D d->detailsTable->x() + d->scrollArea->horizontalScrollBar()= ->value(); int ry =3D d->detailsTable->globalY(d->detailsField); = - QFont f(KexiUtils::smallFont(d->scrollArea)); + QFont f(KexiUtils::smallestReadableFont()); f.setBold(true); p->setFont(f); QFontMetrics fm(f); diff --git a/src/widget/utils/kexirecordnavigator.cpp b/src/widget/utils/ke= xirecordnavigator.cpp index 7e0dba5..d69ec9e 100644 --- a/src/widget/utils/kexirecordnavigator.cpp +++ b/src/widget/utils/kexirecordnavigator.cpp @@ -122,7 +122,7 @@ KexiRecordNavigator::KexiRecordNavigator(QAbstractScrol= lArea &parentView, QWidge d->lyr->addWidget(d->textLabel); setLabelText(xi18n("Record:")); = - setFont( KexiUtils::smallFont() ); + setFont(KexiUtils::smallestReadableFont()); QFontMetrics fm(font()); d->nav1DigitWidth =3D fm.width("8"); =