summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2022-05-02 08:50:33 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2022-05-25 08:32:12 +0200
commit7bf9629d4f3e8504b5d09685d7721275b3287443 (patch)
treec22872bd2a75698cafe44e59554631c664196dc3
parent4a54a24c207f3040390e2fefec41cbbf0edd5eca (diff)
tdf#125925 Qt migrate KF5 theme font settings code
Currently all implemented Qt platforms use freetype and fontconfig to handle the font selection, so just move the font styling code from the kf5 VCL plugin to qt. This really minimizes kf5 by just keeping the special file picker handling in that VCL plugin. Change-Id: I0bbb2496379396afc46e34fe0d026702dce1492e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134862 Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de> Tested-by: Jenkins
-rw-r--r--vcl/Library_vclplug_kf5.mk1
-rw-r--r--vcl/qt5/QtFrame.cxx67
-rw-r--r--vcl/unx/kf5/KF5SalFrame.cxx164
-rw-r--r--vcl/unx/kf5/KF5SalFrame.hxx37
-rw-r--r--vcl/unx/kf5/KF5SalInstance.cxx21
-rw-r--r--vcl/unx/kf5/KF5SalInstance.hxx3
6 files changed, 64 insertions, 229 deletions
diff --git a/vcl/Library_vclplug_kf5.mk b/vcl/Library_vclplug_kf5.mk
index 9e44e5f182fd..fe89ec00ec05 100644
--- a/vcl/Library_vclplug_kf5.mk
+++ b/vcl/Library_vclplug_kf5.mk
@@ -64,7 +64,6 @@ $(eval $(call gb_Library_use_externals,vclplug_kf5,\
$(eval $(call gb_Library_add_exception_objects,vclplug_kf5,\
vcl/unx/kf5/KF5FilePicker \
- vcl/unx/kf5/KF5SalFrame \
vcl/unx/kf5/KF5SalInstance \
))
diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx
index 440cd8048d76..6d65aaf6f386 100644
--- a/vcl/qt5/QtFrame.cxx
+++ b/vcl/qt5/QtFrame.cxx
@@ -22,6 +22,7 @@
#include <QtData.hxx>
#include <QtDragAndDrop.hxx>
+#include <QtFontFace.hxx>
#include <QtGraphics.hxx>
#include <QtInstance.hxx>
#include <QtMainWindow.hxx>
@@ -66,6 +67,8 @@
#include <cairo.h>
#include <headless/svpgdi.hxx>
+#include <unx/fontmanager.hxx>
+
#if CHECK_QT5_USING_X11 && QT5_HAVE_XCB_ICCCM
static bool g_bNeedsWmHintsWindowGroup = true;
static xcb_atom_t g_aXcbClientLeaderAtom = 0;
@@ -1056,12 +1059,51 @@ static Color toColor(const QColor& rColor)
return Color(rColor.red(), rColor.green(), rColor.blue());
}
+static bool toVclFont(const QFont& rQFont, const css::lang::Locale& rLocale, vcl::Font& rVclFont)
+{
+ psp::FastPrintFontInfo aInfo;
+ QFontInfo qFontInfo(rQFont);
+
+ OUString sFamilyName = toOUString(rQFont.family());
+ aInfo.m_aFamilyName = sFamilyName;
+ aInfo.m_eItalic = QtFontFace::toFontItalic(qFontInfo.style());
+ aInfo.m_eWeight = QtFontFace::toFontWeight(qFontInfo.weight());
+ aInfo.m_eWidth = QtFontFace::toFontWidth(rQFont.stretch());
+
+ psp::PrintFontManager::get().matchFont(aInfo, rLocale);
+ SAL_INFO("vcl.qt", "font match result for '"
+ << sFamilyName << "': "
+ << (aInfo.m_nID != 0 ? OUString::Concat("'") + aInfo.m_aFamilyName + "'"
+ : OUString("failed")));
+
+ if (aInfo.m_nID == 0)
+ return false;
+
+ int nPointHeight = qFontInfo.pointSize();
+ if (nPointHeight <= 0)
+ nPointHeight = rQFont.pointSize();
+
+ vcl::Font aFont(aInfo.m_aFamilyName, Size(0, nPointHeight));
+ if (aInfo.m_eWeight != WEIGHT_DONTKNOW)
+ aFont.SetWeight(aInfo.m_eWeight);
+ if (aInfo.m_eWidth != WIDTH_DONTKNOW)
+ aFont.SetWidthType(aInfo.m_eWidth);
+ if (aInfo.m_eItalic != ITALIC_DONTKNOW)
+ aFont.SetItalic(aInfo.m_eItalic);
+ if (aInfo.m_ePitch != PITCH_DONTKNOW)
+ aFont.SetPitch(aInfo.m_ePitch);
+
+ rVclFont = aFont;
+ return true;
+}
+
void QtFrame::UpdateSettings(AllSettings& rSettings)
{
if (QtData::noNativeControls())
return;
StyleSettings style(rSettings.GetStyleSettings());
+ const css::lang::Locale aLocale = rSettings.GetUILanguageTag().getLocale();
// General settings
QPalette pal = QApplication::palette();
@@ -1146,9 +1188,6 @@ void QtFrame::UpdateSettings(AllSettings& rSettings)
style.SetHelpTextColor(
toColor(QToolTip::palette().color(QPalette::Active, QPalette::ToolTipText)));
- const int flash_time = QApplication::cursorFlashTime();
- style.SetCursorBlinkTime(flash_time != 0 ? flash_time / 2 : STYLE_CURSOR_NOBLINKTIME);
-
// Menu
std::unique_ptr<QMenuBar> pMenuBar = std::make_unique<QMenuBar>();
QPalette qMenuCG = pMenuBar->palette();
@@ -1184,6 +1223,24 @@ void QtFrame::UpdateSettings(AllSettings& rSettings)
}
style.SetMenuBarHighlightTextColor(style.GetMenuHighlightTextColor());
+ // Default fonts
+ vcl::Font aFont;
+ if (toVclFont(QApplication::font(), aLocale, aFont))
+ {
+ style.BatchSetFonts(aFont, aFont);
+ aFont.SetWeight(WEIGHT_BOLD);
+ style.SetTitleFont(aFont);
+ style.SetFloatTitleFont(aFont);
+ }
+
+ // Tooltip font
+ if (toVclFont(QToolTip::font(), aLocale, aFont))
+ style.SetHelpFont(aFont);
+
+ // Menu bar font
+ if (toVclFont(pMenuBar->font(), aLocale, aFont))
+ style.SetMenuFont(aFont);
+
// Icon theme
style.SetPreferredIconTheme(toOUString(QIcon::themeName()));
@@ -1195,6 +1252,10 @@ void QtFrame::UpdateSettings(AllSettings& rSettings)
style.SetShadowColor(toColor(pal.color(QPalette::Disabled, QPalette::WindowText)));
style.SetDarkShadowColor(toColor(pal.color(QPalette::Inactive, QPalette::WindowText)));
+ // Cursor blink interval
+ int nFlashTime = QApplication::cursorFlashTime();
+ style.SetCursorBlinkTime(nFlashTime != 0 ? nFlashTime / 2 : STYLE_CURSOR_NOBLINKTIME);
+
rSettings.SetStyleSettings(style);
}
diff --git a/vcl/unx/kf5/KF5SalFrame.cxx b/vcl/unx/kf5/KF5SalFrame.cxx
deleted file mode 100644
index f33011837470..000000000000
--- a/vcl/unx/kf5/KF5SalFrame.cxx
+++ /dev/null
@@ -1,164 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <memory>
-#include <QtGui/QColor>
-#include <QtWidgets/QStyle>
-#include <QtWidgets/QToolTip>
-#include <QtWidgets/QApplication>
-#include <QtWidgets/QMenuBar>
-
-#include <KConfig>
-#include <KConfigGroup>
-#include <KSharedConfig>
-
-#include <QtFontFace.hxx>
-#include "KF5SalFrame.hxx"
-
-#include <tools/color.hxx>
-
-#include <vcl/font.hxx>
-#include <vcl/settings.hxx>
-#include <sal/log.hxx>
-
-#include <unx/fontmanager.hxx>
-
-#include <svdata.hxx>
-
-#include <optional>
-
-KF5SalFrame::KF5SalFrame(KF5SalFrame* pParent, SalFrameStyleFlags nState, bool bUseCairo)
- : QtFrame(pParent, nState, bUseCairo)
-{
-}
-
-/** Helper function to add information to Font from QFont.
-
- Mostly grabbed from the Gtk+ vclplug (salnativewidgets-gtk.cxx).
-*/
-static vcl::Font toFont(const QFont& rQFont, const css::lang::Locale& rLocale)
-{
- psp::FastPrintFontInfo aInfo;
- QFontInfo qFontInfo(rQFont);
-
- // set family name
- aInfo.m_aFamilyName = OUString(static_cast<const char*>(rQFont.family().toUtf8()),
- strlen(static_cast<const char*>(rQFont.family().toUtf8())),
- RTL_TEXTENCODING_UTF8);
-
- aInfo.m_eItalic = QtFontFace::toFontItalic(qFontInfo.style());
- aInfo.m_eWeight = QtFontFace::toFontWeight(qFontInfo.weight());
- aInfo.m_eWidth = QtFontFace::toFontWidth(rQFont.stretch());
-
- SAL_INFO("vcl.kf5", "font name BEFORE system match: \"" << aInfo.m_aFamilyName << "\"");
-
- // match font to e.g. resolve "Sans"
- psp::PrintFontManager::get().matchFont(aInfo, rLocale);
-
- SAL_INFO("vcl.kf5", "font match " << (aInfo.m_nID != 0 ? "succeeded" : "failed")
- << ", name AFTER: \"" << aInfo.m_aFamilyName << "\"");
-
- // font height
- int nPointHeight = qFontInfo.pointSize();
- if (nPointHeight <= 0)
- nPointHeight = rQFont.pointSize();
-
- // Create the font
- vcl::Font aFont(aInfo.m_aFamilyName, Size(0, nPointHeight));
- if (aInfo.m_eWeight != WEIGHT_DONTKNOW)
- aFont.SetWeight(aInfo.m_eWeight);
- if (aInfo.m_eWidth != WIDTH_DONTKNOW)
- aFont.SetWidthType(aInfo.m_eWidth);
- if (aInfo.m_eItalic != ITALIC_DONTKNOW)
- aFont.SetItalic(aInfo.m_eItalic);
- if (aInfo.m_ePitch != PITCH_DONTKNOW)
- aFont.SetPitch(aInfo.m_ePitch);
-
- return aFont;
-}
-
-/** Implementation of KDE integration's main method.
-*/
-void KF5SalFrame::UpdateSettings(AllSettings& rSettings)
-{
- QtFrame::UpdateSettings(rSettings);
-
- StyleSettings style(rSettings.GetStyleSettings());
- bool bSetTitleFont = false;
-
- // WM settings
- /*KConfig *pConfig = KGlobal::config().data();
- if ( pConfig )
- {
- const char *pKey;
-
- {
- KConfigGroup aWMGroup = pConfig->group( "WM" );
-
- pKey = "titleFont";
- if (aWMGroup.hasKey(pKey))
- {
- vcl::Font aFont = toFont(aWMGroup.readEntry(pKey, QFont()),
- rSettings.GetUILanguageTag().getLocale());
- style.SetTitleFont( aFont );
- bSetTitleFont = true;
- }
- }
-
- KConfigGroup aIconsGroup = pConfig->group("Icons");
-
- pKey = "Theme";
- if (aIconsGroup.hasKey(pKey))
- style.SetPreferredIconTheme( readEntryUntranslated(&aIconsGroup, pKey));
-
- //toolbar
- pKey = "toolbarFont";
- if (aIconsGroup.hasKey(pKey))
- {
- vcl::Font aFont = toFont(aIconsGroup.readEntry(pKey, QFont()),
- rSettings.GetUILanguageTag().getLocale());
- style.SetToolFont( aFont );
- }
- }*/
-
- // Font
- vcl::Font aFont = toFont(QApplication::font(), rSettings.GetUILanguageTag().getLocale());
-
- style.BatchSetFonts(aFont, aFont);
-
- aFont.SetWeight(WEIGHT_BOLD);
- if (!bSetTitleFont)
- {
- style.SetTitleFont(aFont);
- }
- style.SetFloatTitleFont(aFont);
- style.SetHelpFont(toFont(QToolTip::font(), rSettings.GetUILanguageTag().getLocale()));
-
- int flash_time = QApplication::cursorFlashTime();
- style.SetCursorBlinkTime(flash_time != 0 ? flash_time / 2 : STYLE_CURSOR_NOBLINKTIME);
-
- // Menu
- std::unique_ptr<QMenuBar> pMenuBar = std::make_unique<QMenuBar>();
- aFont = toFont(pMenuBar->font(), rSettings.GetUILanguageTag().getLocale());
- style.SetMenuFont(aFont);
-
- rSettings.SetStyleSettings(style);
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/kf5/KF5SalFrame.hxx b/vcl/unx/kf5/KF5SalFrame.hxx
deleted file mode 100644
index d7c82c375a9d..000000000000
--- a/vcl/unx/kf5/KF5SalFrame.hxx
+++ /dev/null
@@ -1,37 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#pragma once
-
-#include <memory>
-
-#include <QtFrame.hxx>
-#include <QtSvpGraphics.hxx>
-
-class QWidget;
-
-class KF5SalFrame : public QtFrame
-{
-public:
- KF5SalFrame(KF5SalFrame* pParent, SalFrameStyleFlags nStyle, bool bUseCairo);
-
- virtual void UpdateSettings(AllSettings& rSettings) override;
-};
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/kf5/KF5SalInstance.cxx b/vcl/unx/kf5/KF5SalInstance.cxx
index 1a7fce697a0b..de3e2fe4d6ee 100644
--- a/vcl/unx/kf5/KF5SalInstance.cxx
+++ b/vcl/unx/kf5/KF5SalInstance.cxx
@@ -28,7 +28,6 @@
#include <QtData.hxx>
#include "KF5FilePicker.hxx"
-#include "KF5SalFrame.hxx"
#include "KF5SalInstance.hxx"
using namespace com::sun::star;
@@ -40,26 +39,6 @@ KF5SalInstance::KF5SalInstance(std::unique_ptr<QApplication>& pQApp, bool bUseCa
pSVData->maAppData.mxToolkitName = constructToolkitID(u"kf5");
}
-SalFrame* KF5SalInstance::CreateChildFrame(SystemParentData* /*pParent*/, SalFrameStyleFlags nStyle)
-{
- SalFrame* pRet(nullptr);
- RunInMainThread([&, this]() { pRet = new KF5SalFrame(nullptr, nStyle, useCairo()); });
- assert(pRet);
- return pRet;
-}
-
-SalFrame* KF5SalInstance::CreateFrame(SalFrame* pParent, SalFrameStyleFlags nStyle)
-{
- assert(!pParent || dynamic_cast<KF5SalFrame*>(pParent));
-
- SalFrame* pRet(nullptr);
- RunInMainThread([&, this]() {
- pRet = new KF5SalFrame(static_cast<KF5SalFrame*>(pParent), nStyle, useCairo());
- });
- assert(pRet);
- return pRet;
-}
-
bool KF5SalInstance::hasNativeFileSelection() const
{
if (Application::GetDesktopEnvironment() == "PLASMA5")
diff --git a/vcl/unx/kf5/KF5SalInstance.hxx b/vcl/unx/kf5/KF5SalInstance.hxx
index add3b112af98..3fb6a793a5ae 100644
--- a/vcl/unx/kf5/KF5SalInstance.hxx
+++ b/vcl/unx/kf5/KF5SalInstance.hxx
@@ -28,9 +28,6 @@ class KF5SalInstance final : public QtInstance
createPicker(css::uno::Reference<css::uno::XComponentContext> const& context,
QFileDialog::FileMode) override;
- SalFrame* CreateFrame(SalFrame* pParent, SalFrameStyleFlags nStyle) override;
- SalFrame* CreateChildFrame(SystemParentData* pParent, SalFrameStyleFlags nStyle) override;
-
public:
explicit KF5SalInstance(std::unique_ptr<QApplication>& pQApp, bool bUseCairo);
};