nss: upgrade to release 3.73
[LibreOffice.git] / vcl / unx / kf5 / KF5SalFrame.cxx
blob8f14594586d2f36a5c1680ebf69fdf8a09e0366d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <memory>
21 #include <QtGui/QColor>
22 #include <QtWidgets/QStyle>
23 #include <QtWidgets/QToolTip>
24 #include <QtWidgets/QApplication>
25 #include <QtWidgets/QMenuBar>
27 #include <KConfig>
28 #include <KConfigGroup>
29 #include <KSharedConfig>
31 #include <Qt5FontFace.hxx>
32 #include "KF5SalFrame.hxx"
34 #include <tools/color.hxx>
36 #include <vcl/font.hxx>
37 #include <vcl/settings.hxx>
38 #include <sal/log.hxx>
40 #include <unx/fontmanager.hxx>
42 #include <svdata.hxx>
44 #include <optional>
46 KF5SalFrame::KF5SalFrame(KF5SalFrame* pParent, SalFrameStyleFlags nState, bool bUseCairo)
47 : Qt5Frame(pParent, nState, bUseCairo)
51 /** Helper function to add information to Font from QFont.
53 Mostly grabbed from the Gtk+ vclplug (salnativewidgets-gtk.cxx).
55 static vcl::Font toFont(const QFont& rQFont, const css::lang::Locale& rLocale)
57 psp::FastPrintFontInfo aInfo;
58 QFontInfo qFontInfo(rQFont);
60 // set family name
61 aInfo.m_aFamilyName = OUString(static_cast<const char*>(rQFont.family().toUtf8()),
62 strlen(static_cast<const char*>(rQFont.family().toUtf8())),
63 RTL_TEXTENCODING_UTF8);
65 aInfo.m_eItalic = Qt5FontFace::toFontItalic(qFontInfo.style());
66 aInfo.m_eWeight = Qt5FontFace::toFontWeight(qFontInfo.weight());
67 aInfo.m_eWidth = Qt5FontFace::toFontWidth(rQFont.stretch());
69 SAL_INFO("vcl.kf5", "font name BEFORE system match: \"" << aInfo.m_aFamilyName << "\"");
71 // match font to e.g. resolve "Sans"
72 psp::PrintFontManager::get().matchFont(aInfo, rLocale);
74 SAL_INFO("vcl.kf5", "font match " << (aInfo.m_nID != 0 ? "succeeded" : "failed")
75 << ", name AFTER: \"" << aInfo.m_aFamilyName << "\"");
77 // font height
78 int nPointHeight = qFontInfo.pointSize();
79 if (nPointHeight <= 0)
80 nPointHeight = rQFont.pointSize();
82 // Create the font
83 vcl::Font aFont(aInfo.m_aFamilyName, Size(0, nPointHeight));
84 if (aInfo.m_eWeight != WEIGHT_DONTKNOW)
85 aFont.SetWeight(aInfo.m_eWeight);
86 if (aInfo.m_eWidth != WIDTH_DONTKNOW)
87 aFont.SetWidthType(aInfo.m_eWidth);
88 if (aInfo.m_eItalic != ITALIC_DONTKNOW)
89 aFont.SetItalic(aInfo.m_eItalic);
90 if (aInfo.m_ePitch != PITCH_DONTKNOW)
91 aFont.SetPitch(aInfo.m_ePitch);
93 return aFont;
96 /** Implementation of KDE integration's main method.
98 void KF5SalFrame::UpdateSettings(AllSettings& rSettings)
100 Qt5Frame::UpdateSettings(rSettings);
102 StyleSettings style(rSettings.GetStyleSettings());
103 bool bSetTitleFont = false;
105 // WM settings
106 /*KConfig *pConfig = KGlobal::config().data();
107 if ( pConfig )
109 const char *pKey;
112 KConfigGroup aWMGroup = pConfig->group( "WM" );
114 pKey = "titleFont";
115 if (aWMGroup.hasKey(pKey))
117 vcl::Font aFont = toFont(aWMGroup.readEntry(pKey, QFont()),
118 rSettings.GetUILanguageTag().getLocale());
119 style.SetTitleFont( aFont );
120 bSetTitleFont = true;
124 KConfigGroup aIconsGroup = pConfig->group("Icons");
126 pKey = "Theme";
127 if (aIconsGroup.hasKey(pKey))
128 style.SetPreferredIconTheme( readEntryUntranslated(&aIconsGroup, pKey));
130 //toolbar
131 pKey = "toolbarFont";
132 if (aIconsGroup.hasKey(pKey))
134 vcl::Font aFont = toFont(aIconsGroup.readEntry(pKey, QFont()),
135 rSettings.GetUILanguageTag().getLocale());
136 style.SetToolFont( aFont );
140 // Font
141 vcl::Font aFont = toFont(QApplication::font(), rSettings.GetUILanguageTag().getLocale());
143 style.BatchSetFonts(aFont, aFont);
145 aFont.SetWeight(WEIGHT_BOLD);
146 if (!bSetTitleFont)
148 style.SetTitleFont(aFont);
150 style.SetFloatTitleFont(aFont);
151 style.SetHelpFont(toFont(QToolTip::font(), rSettings.GetUILanguageTag().getLocale()));
153 int flash_time = QApplication::cursorFlashTime();
154 style.SetCursorBlinkTime(flash_time != 0 ? flash_time / 2 : STYLE_CURSOR_NOBLINKTIME);
156 // Menu
157 std::unique_ptr<QMenuBar> pMenuBar = std::make_unique<QMenuBar>();
158 aFont = toFont(pMenuBar->font(), rSettings.GetUILanguageTag().getLocale());
159 style.SetMenuFont(aFont);
161 rSettings.SetStyleSettings(style);
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */