[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kexi] src: Make the default "Smallest readable font" used by Kexi in property editor, toolbar, etc.
From: Jaroslaw Staniek <staniek () kde ! org>
Date: 2016-02-29 23:12:19
Message-ID: E1aaWzD-0000sv-HY () scm ! kde ! org
[Download RAW message or body]
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 = new QWidget(this);
- d->topBarHWidget->setFont(KexiUtils::smallFont());
+ d->topBarHWidget->setFont(KexiUtils::smallestReadableFont());
d->mainLyr->addWidget(d->topBarHWidget);
QHBoxLayout *topBarHLyr = new QHBoxLayout(d->topBarHWidget); //needed 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ław Staniek <staniek@kde.org>
+
+ Contains code from kfontsettingsdata.cpp:
+ Copyright (C) 2000, 2006 David Faure <faure@kde.org>
+ Copyright 2008 Friedrich W. H. Kossebau <kossebau@kde.org>
+ Copyright 2013 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
+
+ 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 License
+ 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 <KConfigGroup>
+
+FontSettingsData::FontSettingsData()
+{
+ for (int i = 0; i < FontTypesCount; ++i) {
+ m_fonts[i] = 0;
+ }
+}
+
+FontSettingsData::~FontSettingsData()
+{
+ for (int i = 0; i < FontTypesCount; ++i) {
+ delete m_fonts[i];
+ }
+}
+
+static const char GeneralId[] = "General";
+static const char DefaultFont[] = "Noto Sans";
+
+static const FontData DefaultFontData[FontSettingsData::FontTypesCount] = {
+ { GeneralId, "font", DefaultFont, 10, -1, QFont::SansSerif },
+ { GeneralId, "fixed", "Oxygen Mono", 9, -1, QFont::Monospace },
+ { GeneralId, "toolBarFont", DefaultFont, 9, -1, QFont::SansSerif },
+ { GeneralId, "menuFont", DefaultFont, 10, -1, QFont::SansSerif },
+ { "WM", "activeFont", DefaultFont, 10, -1, QFont::SansSerif },
+ { GeneralId, "taskbarFont", DefaultFont, 10, -1, QFont::SansSerif },
+ { GeneralId, "smallestReadableFont", DefaultFont, 8, -1, QFont::SansSerif }
+};
+
+QFont FontSettingsData::font(FontTypes fontType)
+{
+ QFont *cachedFont = m_fonts[fontType];
+ if (!cachedFont) {
+ const FontData &fontData = DefaultFontData[fontType];
+ cachedFont = new QFont(fontData.FontName, fontData.Size, fontData.Weight);
+ cachedFont->setStyleHint(fontData.StyleHint);
+ if (!m_kdeGlobals) {
+ m_kdeGlobals = KSharedConfig::openConfig(QStringLiteral("kdeglobals"), \
KConfig::NoGlobals); + }
+ const KConfigGroup configGroup(m_kdeGlobals, fontData.ConfigGroupKey);
+ QString fontInfo = configGroup.readEntry(fontData.ConfigKey, QString());
+
+ //If we have serialized information for this font, restore it
+ //NOTE: We are not using KConfig directly because we can't call QFont::QFont \
from here + if (!fontInfo.isEmpty()) {
+ cachedFont->fromString(fontInfo);
+ }
+ m_fonts[fontType] = 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ław Staniek <staniek@kde.org>
+
+ Contains code from kfontsettingsdata.cpp:
+ Copyright (C) 2000, 2006 David Faure <faure@kde.org>
+ Copyright 2008 Friedrich W. H. Kossebau <kossebau@kde.org>
+ Copyright 2013 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
+
+ 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 License
+ 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 <QFont>
+#include <KSharedConfig>
+
+//! @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 = 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/SmallToolButton.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 = new KexiDBDebugTreeWidget(page);
kexiDBDebugPage->setObjectName("kexiDbDebugPage");
- kexiDBDebugPage->setFont(KexiUtils::smallFont(kexiDBDebugPage));
+ kexiDBDebugPage->setFont(KexiUtils::smallestReadableFont());
QObject::connect(btn_copy, SIGNAL(clicked()), kexiDBDebugPage, \
SLOT(copy()));
QObject::connect(btn_clear, SIGNAL(clicked()), kexiDBDebugPage, \
SLOT(clear())); vbox->addWidget(kexiDBDebugPage);
@@ -114,7 +114,7 @@ static void addAlterTableActionDebug(const QString& text, int \
nestingLevel) hbox->addWidget(btn_sim);
kexiAlterTableActionDebugPage = new QTreeWidget(page);
- kexiAlterTableActionDebugPage->setFont(KexiUtils::smallFont(kexiAlterTableActionDebugPage));
+ kexiAlterTableActionDebugPage->setFont(KexiUtils::smallestReadableFont());
kexiAlterTableActionDebugPage->setObjectName("kexiAlterTableActionDebugPage");
QObject::connect(btn_clear, SIGNAL(clicked()), \
kexiAlterTableActionDebugPage, 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 <KexiIcon.h>
@@ -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 = init->font();
- const int wdth = QApplication::desktop()->screenGeometry(init).width();
- int size = 10 + qMax(0, wdth - 1100) / 100;
- size = qMin(init->fontInfo().pixelSize(), size);
- size = qMax(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont).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 = 0, \
const QString &captio const QUrl &directory = QUrl());
/*! A global setting for minimal readable font.
- \a init is a widget that should be passed if no qApp->mainWidget() is available \
yet.
- The size of font is not smaller than the one returned by
- QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont). */
-KEXIUTILS_EXPORT QFont smallFont(QWidget *init = 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 now 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 factor1
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 = propertyEditorGroup.readEntry("FontSize", -1);
- QFont f(KexiUtils::smallFont());
- if (size > 0)
- f.setPixelSize(size);
+ QFont f(KexiUtils::smallestReadableFont());
+ const qreal pointSizeF = propertyEditorGroup.readEntry("FontPointSize", \
-1.0f); // points are more accurate + if (pointSizeF > 0.0) {
+ f.setPointSizeF(pointSizeF);
+ } else {
+ const int pixelSize = propertyEditorGroup.readEntry("FontSize", -1); // \
compatibility with Kexi 2.x + if (pixelSize > 0) {
+ f.setPixelSize(pixelSize);
+ }
+ }
d->propEditorTabWidget->setFont(f);
d->enable_slotPropertyEditorVisibilityChanged = 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 = KexiMainWindowIface::global()->userMode();
KToolBar *tbar;
- KexiUtils::smallFont(this/*init*/);
slotSettingsChanged(0);//KGlobalSettings::FontChanged
//! @todo KEXI3 port from KGlobalSettings::Private::_k_slotNotifyChange:
//! connect(KGlobalSettings::self(), SIGNAL(settingsChanged(int)), this, \
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 = d->detailsTable->x() + d->scrollArea->horizontalScrollBar()->value();
int ry = 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/kexirecordnavigator.cpp index 7e0dba5..d69ec9e 100644
--- a/src/widget/utils/kexirecordnavigator.cpp
+++ b/src/widget/utils/kexirecordnavigator.cpp
@@ -122,7 +122,7 @@ KexiRecordNavigator::KexiRecordNavigator(QAbstractScrollArea \
&parentView, QWidge d->lyr->addWidget(d->textLabel);
setLabelText(xi18n("Record:"));
- setFont( KexiUtils::smallFont() );
+ setFont(KexiUtils::smallestReadableFont());
QFontMetrics fm(font());
d->nav1DigitWidth = fm.width("8");
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic