Commit 79902969 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Move the dockwidget font calculation to KoDockRegistry

We had duplicated code in a number of places, so put that in one
place. It also seems that SmallestReadableFont often is bigger
than GeneralFont, so check that.
parent 44df1f47
......@@ -44,7 +44,6 @@
#include <QSignalMapper>
#include <QTabBar>
#include <QMoveEvent>
#include <QFontDatabase>
#include <QUrl>
#include <QMessageBox>
#include <QTemporaryFile>
......@@ -1639,12 +1638,14 @@ QDockWidget* KisMainWindow::createDockWidget(KoDockFactoryBase* factory)
}
KoDockWidgetTitleBar *titleBar = dynamic_cast<KoDockWidgetTitleBar*>(dockWidget->titleBarWidget());
// Check if the dock widget is supposed to be collapsable
if (!dockWidget->titleBarWidget()) {
titleBar = new KoDockWidgetTitleBar(dockWidget);
dockWidget->setTitleBarWidget(titleBar);
titleBar->setCollapsable(factory->isCollapsable());
}
titleBar->setFont(KoDockRegistry::dockFont());
dockWidget->setObjectName(factory->id());
dockWidget->setParent(this);
......@@ -1692,22 +1693,20 @@ QDockWidget* KisMainWindow::createDockWidget(KoDockFactoryBase* factory)
if (titleBar && collapsed)
titleBar->setCollapsed(true);
if (titleBar && locked)
titleBar->setLocked(true);
d->dockWidgetsMap.insert(factory->id(), dockWidget);
} else {
}
else {
dockWidget = d->dockWidgetsMap[factory->id()];
}
KConfigGroup group( KSharedConfig::openConfig(), "GUI");
QFont dockWidgetFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
qreal pointSize = group.readEntry("palettefontsize", dockWidgetFont.pointSize() * 0.75);
dockWidgetFont.setPointSizeF(qMax(pointSize,QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont).pointSizeF()));
#ifdef Q_OS_MAC
dockWidget->setAttribute(Qt::WA_MacSmallSize, true);
#endif
dockWidget->setFont(dockWidgetFont);
dockWidget->setFont(KoDockRegistry::dockFont());
connect(dockWidget, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(forceDockTabFonts()));
......@@ -1718,11 +1717,7 @@ void KisMainWindow::forceDockTabFonts()
{
foreach(QObject *child, children()) {
if (child->inherits("QTabBar")) {
KConfigGroup group( KSharedConfig::openConfig(), "GUI");
QFont dockWidgetFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
qreal pointSize = group.readEntry("palettefontsize", dockWidgetFont.pointSize() * 0.75);
dockWidgetFont.setPointSizeF(qMax(pointSize, QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont).pointSizeF()));
((QTabBar *)child)->setFont(dockWidgetFont);
((QTabBar *)child)->setFont(KoDockRegistry::dockFont());
}
}
}
......@@ -1973,18 +1968,11 @@ QPointer<KisView>KisMainWindow::activeKisView()
void KisMainWindow::newOptionWidgets(const QList<QPointer<QWidget> > &optionWidgetList)
{
KConfigGroup group( KSharedConfig::openConfig(), "GUI");
QFont dockWidgetFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
qreal pointSize = group.readEntry("palettefontsize", dockWidgetFont.pointSize() * 0.75);
dockWidgetFont.setPointSizeF(qMax(pointSize, QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont).pointSizeF()));
dockWidgetFont.setPointSizeF(pointSize);
foreach(QWidget *w, optionWidgetList) {
#ifdef Q_OS_MAC
w->setAttribute(Qt::WA_MacSmallSize, true);
#endif
w->setFont(dockWidgetFont);
w->setFont(KoDockRegistry::dockFont());
}
if (d->toolOptionsDocker) {
......
......@@ -35,6 +35,8 @@
#include <kconfig.h>
#include <klocalizedstring.h>
#include <KoDockRegistry.h>
#include <kis_icon_utils.h>
#include <kis_icon_utils.h>
#include <kis_paintop_preset.h>
......@@ -71,12 +73,7 @@ KisPaintOpPresetsPopup::KisPaintOpPresetsPopup(KisCanvasResourceProvider * resou
, m_d(new Private())
{
setObjectName("KisPaintOpPresetsPopup");
KConfigGroup group( KSharedConfig::openConfig(), "GUI");
m_d->smallFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
qreal pointSize = group.readEntry("palettefontsize", m_d->smallFont.pointSize() * 0.75);
pointSize = qMax(pointSize, QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont).pointSizeF());
m_d->smallFont.setPointSizeF(pointSize);
setFont(m_d->smallFont);
setFont(KoDockRegistry::dockFont());
m_d->resourceProvider = resourceProvider;
......
......@@ -32,6 +32,7 @@
#include <QApplication>
#include <QFontDatabase>
#include <KoDockRegistry.h>
#include <kconfig.h>
#include <klocalizedstring.h>
......@@ -119,12 +120,7 @@ KisToolOptionsPopup::KisToolOptionsPopup(QWidget *parent)
setObjectName("KisToolOptionsPopup");
KConfigGroup group( KSharedConfig::openConfig(), "GUI");
d->smallFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
qreal pointSize = group.readEntry("palettefontsize", d->smallFont.pointSize() * 0.75);
pointSize = qMax(pointSize, QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont).pointSizeF());
d->smallFont.setPointSizeF(pointSize);
setFont(d->smallFont);
setFont(KoDockRegistry::dockFont());
KisConfig cfg;
d->detached = !cfg.paintopPopupDetached();
......
......@@ -19,8 +19,14 @@
#include "KoDockRegistry.h"
#include "KoPluginLoader.h"
#include <QGlobalStatic>
#include <QFontDatabase>
#include <QDebug>
#include <ksharedconfig.h>
#include <kconfiggroup.h>
#include "KoPluginLoader.h"
Q_GLOBAL_STATIC(KoDockRegistry, s_instance)
......@@ -54,3 +60,25 @@ KoDockRegistry* KoDockRegistry::instance()
}
return s_instance;
}
QFont KoDockRegistry::dockFont()
{
KConfigGroup group( KSharedConfig::openConfig(), "GUI");
QFont dockWidgetFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
QFont smallFont = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont);
int pointSize = group.readEntry("palettefontsize", dockWidgetFont.pointSize());
// Not set by the user
if (pointSize == dockWidgetFont.pointSize()) {
// and there is no setting for the smallest readable font, calculate something small
if (smallFont.pointSize() >= pointSize) {
smallFont.setPointSizeF(pointSize * 0.9);
}
}
else {
// paletteFontSize was set, use that
smallFont.setPointSize(pointSize);
}
return smallFont;
}
......@@ -20,8 +20,11 @@
#ifndef KODOCKREGISTRY_
#define KODOCKREGISTRY_
#include <QFont>
#include "KoGenericRegistry.h"
#include "KoDockFactoryBase.h"
#include "flake_export.h"
/**
......@@ -45,6 +48,13 @@ public:
*/
static KoDockRegistry *instance();
/**
* @brief dockFontSize calculates a smallish font size for dock widgets to use
* @return the point size in floating point.
*/
static QFont dockFont();
private:
KoDockRegistry(const KoDockRegistry&);
......
......@@ -75,12 +75,7 @@ KoDockerManager::~KoDockerManager()
void KoDockerManager::newOptionWidgets(const QList<QPointer<QWidget> > &optionWidgetList)
{
d->toolOptionsDocker->setOptionWidgets(optionWidgetList);
KConfigGroup group( KSharedConfig::openConfig(), "GUI");
QFont dockWidgetFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
qreal pointSize = group.readEntry("palettefontsize", dockWidgetFont.pointSize() * 0.75);
pointSize = qMax(pointSize, QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont).pointSizeF());
dockWidgetFont.setPointSizeF(pointSize);
dockWidgetFont.setPointSizeF(KoDockRegistry::dockFont());
foreach(QWidget *w, optionWidgetList) {
#ifdef Q_OS_MAC
......
......@@ -1893,15 +1893,10 @@ QDockWidget* KoMainWindow::createDockWidget(KoDockFactoryBase* factory)
dockWidget = d->dockWidgetsMap[ factory->id()];
}
KConfigGroup group( KSharedConfig::openConfig(), "GUI");
QFont dockWidgetFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
qreal pointSize = group.readEntry("palettefontsize", dockWidgetFont.pointSize() * 0.75);
pointSize = qMax(pointSize, QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont).pointSizeF());
dockWidgetFont.setPointSizeF(pointSize);
#ifdef Q_OS_MAC
dockWidget->setAttribute(Qt::WA_MacSmallSize, true);
#endif
dockWidget->setFont(dockWidgetFont);
dockWidget->setFont(KoDockRegistry::dockFont());
connect(dockWidget, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(forceDockTabFonts()));
......@@ -1913,10 +1908,7 @@ void KoMainWindow::forceDockTabFonts()
QObjectList chis = children();
for (int i = 0; i < chis.size(); ++i) {
if (chis.at(i)->inherits("QTabBar")) {
QFont dockWidgetFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
qreal pointSize = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont).pointSizeF();
dockWidgetFont.setPointSizeF(pointSize);
((QTabBar *)chis.at(i))->setFont(dockWidgetFont);
((QTabBar *)chis.at(i))->setFont(KoDockRegistry::dockFont());
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment