Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwidgetplatform_p.h
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
4#ifndef QWIDGETPLATFORM_P_H
5#define QWIDGETPLATFORM_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qdebug.h>
19#include <QtCore/qcoreapplication.h>
20#include <QtGui/qpa/qplatformtheme.h>
21#include <QtGui/qpa/qplatformdialoghelper.h>
22#include <QtGui/qpa/qplatformsystemtrayicon.h>
23#include <QtGui/qpa/qplatformmenu.h>
24
25#ifdef QT_WIDGETS_LIB
26#include <QtWidgets/qtwidgetsglobal.h>
27#if QT_CONFIG(colordialog)
29#endif
30#if QT_CONFIG(filedialog)
32#endif
33#if QT_CONFIG(fontdialog)
35#endif
36#if QT_CONFIG(messagebox)
38#endif
39#if QT_CONFIG(menu)
42#endif
43#ifndef QT_NO_SYSTEMTRAYICON
45#endif
46#endif
47
49
50#ifndef QT_WIDGETS_LIB
58#endif
59
61{
62 static inline bool isAvailable(const char *type)
63 {
64 if (!qApp->inherits("QApplication")) {
65 qCritical("\nERROR: No native %s implementation available."
66 "\nQt Labs Platform requires Qt Widgets on this setup."
67 "\nAdd 'QT += widgets' to .pro and create QApplication in main().\n", type);
68 return false;
69 }
70 return true;
71 }
72
73 template<typename T>
74 static inline T *createWidget(const char *name, QObject *parent)
75 {
76 static bool available = isAvailable(name);
77#ifdef QT_WIDGETS_LIB
78 if (available)
79 return new T(parent);
80#else
81 Q_UNUSED(parent);
82 Q_UNUSED(available);
83#endif
84 return nullptr;
85 }
86
87 static inline QPlatformMenu *createMenu(QObject *parent = nullptr) {
88#if defined(QT_WIDGETS_LIB) && QT_CONFIG(menu)
89 return createWidget<QWidgetPlatformMenu>("Menu", parent);
90#else
91 Q_UNUSED(parent);
92 return nullptr;
93#endif
94 }
95 static inline QPlatformMenuItem *createMenuItem(QObject *parent = nullptr) {
96#if defined(QT_WIDGETS_LIB) && QT_CONFIG(menu)
97 return createWidget<QWidgetPlatformMenuItem>("MenuItem", parent);
98#else
99 Q_UNUSED(parent);
100 return nullptr;
101#endif
102 }
103 static inline QPlatformSystemTrayIcon *createSystemTrayIcon(QObject *parent = nullptr) {
104#ifndef QT_NO_SYSTEMTRAYICON
105 return createWidget<QWidgetPlatformSystemTrayIcon>("SystemTrayIcon", parent);
106#else
107 Q_UNUSED(parent);
108 return nullptr;
109#endif
110 }
112 {
113#if !defined(QT_WIDGETS_LIB) || !(QT_CONFIG(colordialog) || QT_CONFIG(filedialog) || QT_CONFIG(fontdialog) || QT_CONFIG(messagebox))
114 Q_UNUSED(parent);
115#endif
116 switch (type) {
117#if defined(QT_WIDGETS_LIB) && QT_CONFIG(colordialog)
118 case QPlatformTheme::ColorDialog: return createWidget<QWidgetPlatformColorDialog>("ColorDialog", parent);
119#endif
120#if defined(QT_WIDGETS_LIB) && QT_CONFIG(filedialog)
121 case QPlatformTheme::FileDialog: return createWidget<QWidgetPlatformFileDialog>("FileDialog", parent);
122#endif
123#if defined(QT_WIDGETS_LIB) && QT_CONFIG(fontdialog)
124 case QPlatformTheme::FontDialog: return createWidget<QWidgetPlatformFontDialog>("FontDialog", parent);
125#endif
126#if defined(QT_WIDGETS_LIB) && QT_CONFIG(messagebox)
127 case QPlatformTheme::MessageDialog: return createWidget<QWidgetPlatformMessageDialog>("MessageDialog", parent);
128#endif
129 default: break;
130 }
131 return nullptr;
132 }
133}
134
136
137#endif // QWIDGETPLATFORM_P_H
\inmodule QtCore
Definition qobject.h:103
The QPlatformColorDialogHelper class allows for platform-specific customization of color dialogs.
The QPlatformDialogHelper class allows for platform-specific customization of dialogs.
The QPlatformFileDialogHelper class allows for platform-specific customization of file dialogs.
The QPlatformFontDialogHelper class allows for platform-specific customization of font dialogs.
The QPlatformMessageDialogHelper class allows for platform-specific customization of Message dialogs.
Combined button and popup list for selecting options.
static T * createWidget(const char *name, QObject *parent)
static QPlatformSystemTrayIcon * createSystemTrayIcon(QObject *parent=nullptr)
static bool isAvailable(const char *type)
static QPlatformMenu * createMenu(QObject *parent=nullptr)
static QPlatformDialogHelper * createDialog(QPlatformTheme::DialogType type, QObject *parent=nullptr)
static QPlatformMenuItem * createMenuItem(QObject *parent=nullptr)
#define qApp
#define qCritical
Definition qlogging.h:167
GLenum type
GLuint name
#define Q_UNUSED(x)
QPlatformMessageDialogHelper QWidgetPlatformMessageDialog
QPlatformFileDialogHelper QWidgetPlatformFileDialog
QPlatformColorDialogHelper QWidgetPlatformColorDialog
QPlatformFontDialogHelper QWidgetPlatformFontDialog
QPlatformMenuItem QWidgetPlatformMenuItem
QT_BEGIN_NAMESPACE typedef QPlatformMenu QWidgetPlatformMenu
QPlatformSystemTrayIcon QWidgetPlatformSystemTrayIcon