Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qxdgdesktopportaltheme.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6
7#include <private/qguiapplication_p.h>
8#include <qpa/qplatformtheme_p.h>
9#include <qpa/qplatformthemefactory_p.h>
10#include <qpa/qplatformintegration.h>
11
12#include <QDBusConnection>
13#include <QDBusMessage>
14#include <QDBusPendingCall>
15#include <QDBusPendingCallWatcher>
16#include <QDBusPendingReply>
17#include <QDBusReply>
18
20
21using namespace Qt::StringLiterals;
22
24{
25public:
30 };
31
34 { }
35
37 {
38 delete baseTheme;
39 }
40
57 {
58 switch (colorschemePref) {
61 default: return Qt::ColorScheme::Unknown;
62 }
63 }
64
68};
69
72{
74
77 // 1) Look for a theme plugin.
78 for (const QString &themeName : std::as_const(themeNames)) {
79 d->baseTheme = QPlatformThemeFactory::create(themeName, nullptr);
80 if (d->baseTheme)
81 break;
82 }
83
84 // 2) If no theme plugin was found ask the platform integration to
85 // create a theme
86 if (!d->baseTheme) {
87 for (const QString &themeName : std::as_const(themeNames)) {
89 if (d->baseTheme)
90 break;
91 }
92 // No error message; not having a theme plugin is allowed.
93 }
94
95 // 3) Fall back on the built-in "null" platform theme.
96 if (!d->baseTheme)
97 d->baseTheme = new QPlatformTheme;
98
99 // Get information about portal version
100 QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.portal.Desktop"_L1,
101 "/org/freedesktop/portal/desktop"_L1,
102 "org.freedesktop.DBus.Properties"_L1,
103 "Get"_L1);
104 message << "org.freedesktop.portal.FileChooser"_L1 << "version"_L1;
109 if (reply.isValid()) {
110 d->fileChooserPortalVersion = reply.value().toUInt();
111 }
112 watcher->deleteLater();
113 });
114
115 // Get information about system theme preference
116 message = QDBusMessage::createMethodCall("org.freedesktop.portal.Desktop"_L1,
117 "/org/freedesktop/portal/desktop"_L1,
118 "org.freedesktop.portal.Settings"_L1,
119 "Read"_L1);
120 message << "org.freedesktop.appearance"_L1 << "color-scheme"_L1;
121
122 // this must not be asyncCall() because we have to set appearance now
124 if (reply.isValid()) {
125 const QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(reply.value());
128 }
129}
130
132{
133 Q_D(const QXdgDesktopPortalTheme);
134 return d->baseTheme->createPlatformMenuItem();
135}
136
138{
139 Q_D(const QXdgDesktopPortalTheme);
140 return d->baseTheme->createPlatformMenu();
141}
142
144{
145 Q_D(const QXdgDesktopPortalTheme);
146 return d->baseTheme->createPlatformMenuBar();
147}
148
150{
151 Q_D(const QXdgDesktopPortalTheme);
152 return d->baseTheme->showPlatformMenuBar();
153}
154
156{
157 Q_D(const QXdgDesktopPortalTheme);
158
159 if (type == FileDialog)
160 return true;
161
162 return d->baseTheme->usePlatformNativeDialog(type);
163}
164
166{
167 Q_D(const QXdgDesktopPortalTheme);
168
169 if (type == FileDialog && d->fileChooserPortalVersion) {
170 // Older versions of FileChooser portal don't support opening directories, therefore we fallback
171 // to native file dialog opened inside the sandbox to open a directory.
172 if (d->baseTheme->usePlatformNativeDialog(type))
173 return new QXdgDesktopPortalFileDialog(static_cast<QPlatformFileDialogHelper*>(d->baseTheme->createPlatformDialogHelper(type)),
174 d->fileChooserPortalVersion);
175
177 }
178
179 return d->baseTheme->createPlatformDialogHelper(type);
180}
181
182#ifndef QT_NO_SYSTEMTRAYICON
184{
185 Q_D(const QXdgDesktopPortalTheme);
186 return d->baseTheme->createPlatformSystemTrayIcon();
187}
188#endif
189
191{
192 Q_D(const QXdgDesktopPortalTheme);
193 return d->baseTheme->palette(type);
194}
195
197{
198 Q_D(const QXdgDesktopPortalTheme);
199 return d->baseTheme->font(type);
200}
201
203{
204 Q_D(const QXdgDesktopPortalTheme);
205 return d->baseTheme->themeHint(hint);
206}
207
209{
210 Q_D(const QXdgDesktopPortalTheme);
211 if (d->colorScheme == Qt::ColorScheme::Unknown)
212 return d->baseTheme->colorScheme();
213 return d->colorScheme;
214}
215
217{
218 Q_D(const QXdgDesktopPortalTheme);
219 return d->baseTheme->standardPixmap(sp, size);
220}
221
223 QPlatformTheme::IconOptions iconOptions) const
224{
225 Q_D(const QXdgDesktopPortalTheme);
226 return d->baseTheme->fileIcon(fileInfo, iconOptions);
227}
228
230{
231 Q_D(const QXdgDesktopPortalTheme);
232 return d->baseTheme->createIconEngine(iconName);
233}
234
235#if QT_CONFIG(shortcut)
236QList<QKeySequence> QXdgDesktopPortalTheme::keyBindings(QKeySequence::StandardKey key) const
237{
238 Q_D(const QXdgDesktopPortalTheme);
239 return d->baseTheme->keyBindings(key);
240}
241#endif
242
244{
245 Q_D(const QXdgDesktopPortalTheme);
246 return d->baseTheme->standardButtonText(button);
247}
248
QDBusMessage call(const QDBusMessage &message, QDBus::CallMode mode=QDBus::Block, int timeout=-1) const
Sends the message over this connection and blocks, waiting for a reply, for at most timeout milliseco...
static QDBusConnection sessionBus()
Returns a QDBusConnection object opened with the session bus.
QDBusPendingCall asyncCall(const QDBusMessage &message, int timeout=-1) const
\inmodule QtDBus
static QDBusMessage createMethodCall(const QString &destination, const QString &path, const QString &interface, const QString &method)
Constructs a new DBus message representing a method call.
void finished(QDBusPendingCallWatcher *self=nullptr)
This signal is emitted when the pending call has finished and its reply is available.
\inmodule QtDBus
\inmodule QtDBus
\inmodule QtDBus
Definition qdbusreply.h:24
\inmodule QtDBus
QVariant variant() const
Returns this D-Bus variant as a QVariant object.
\inmodule QtCore \reentrant
Definition qfileinfo.h:22
\reentrant
Definition qfont.h:20
static QPlatformIntegration * platform_integration
The QIconEngine class provides an abstract base class for QIcon renderers.
Definition qiconengine.h:15
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
Definition qlist.h:74
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
The QPlatformDialogHelper class allows for platform-specific customization of dialogs.
The QPlatformFileDialogHelper class allows for platform-specific customization of file dialogs.
virtual QStringList themeNames() const
virtual QPlatformTheme * createPlatformTheme(const QString &name) const
static QPlatformTheme * create(const QString &key, const QString &platformPluginPath=QString())
The QPlatformTheme class allows customizing the UI based on themes.
ThemeHint
This enum describes the available theme hints.
\inmodule QtCore
Definition qsize.h:207
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
Definition qvariant.h:64
uint toUInt(bool *ok=nullptr) const
Returns the variant as an unsigned int if the variant has userType() \l QMetaType::UInt,...
static Qt::ColorScheme colorSchemeFromXdgPref(const XdgColorschemePref colorschemePref)
Qt::ColorScheme colorScheme() const override
QPlatformMenuItem * createPlatformMenuItem() const override
QPixmap standardPixmap(StandardPixmap sp, const QSizeF &size) const override
QIcon fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions iconOptions={ }) const override
Return an icon for fileInfo, observing iconOptions.
QString standardButtonText(int button) const override
Returns the text of a standard button.
bool usePlatformNativeDialog(DialogType type) const override
QPlatformSystemTrayIcon * createPlatformSystemTrayIcon() const override
Factory function for QSystemTrayIcon.
QIconEngine * createIconEngine(const QString &iconName) const override
Factory function for the QIconEngine used by QIcon::fromTheme().
QPlatformDialogHelper * createPlatformDialogHelper(DialogType type) const override
const QPalette * palette(Palette type=SystemPalette) const override
const QFont * font(Font type=SystemFont) const override
QPlatformMenuBar * createPlatformMenuBar() const override
QPlatformMenu * createPlatformMenu() const override
QVariant themeHint(ThemeHint hint) const override
QPushButton * button
[2]
Combined button and popup list for selecting options.
ColorScheme
Definition qnamespace.h:49
static QString themeName()
GLuint64 key
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum type
GLuint GLsizei const GLchar * message
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
#define sp
unsigned int uint
Definition qtypes.h:29
static const wchar_t * themeNames[QWindowsVistaStylePrivate::NThemes]
QFutureWatcher< int > watcher
QNetworkReply * reply