| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2017 The Qt Company Ltd. |
| 4 | ** Contact: http://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Labs Platform module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or later as published by the Free |
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
| 29 | ** the packaging of this file. Please review the following information to |
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be |
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
| 32 | ** |
| 33 | ** $QT_END_LICENSE$ |
| 34 | ** |
| 35 | ****************************************************************************/ |
| 36 | |
| 37 | #ifndef QWIDGETPLATFORM_P_H |
| 38 | #define QWIDGETPLATFORM_P_H |
| 39 | |
| 40 | // |
| 41 | // W A R N I N G |
| 42 | // ------------- |
| 43 | // |
| 44 | // This file is not part of the Qt API. It exists purely as an |
| 45 | // implementation detail. This header file may change from version to |
| 46 | // version without notice, or even be removed. |
| 47 | // |
| 48 | // We mean it. |
| 49 | // |
| 50 | |
| 51 | #include <QtCore/qdebug.h> |
| 52 | #include <QtCore/qcoreapplication.h> |
| 53 | #include <QtGui/qpa/qplatformtheme.h> |
| 54 | #include <QtGui/qpa/qplatformdialoghelper.h> |
| 55 | #include <QtGui/qpa/qplatformsystemtrayicon.h> |
| 56 | #include <QtGui/qpa/qplatformmenu.h> |
| 57 | |
| 58 | #ifdef QT_WIDGETS_LIB |
| 59 | #include <QtWidgets/qtwidgetsglobal.h> |
| 60 | #if QT_CONFIG(colordialog) |
| 61 | #include "qwidgetplatformcolordialog_p.h" |
| 62 | #endif |
| 63 | #if QT_CONFIG(filedialog) |
| 64 | #include "qwidgetplatformfiledialog_p.h" |
| 65 | #endif |
| 66 | #if QT_CONFIG(fontdialog) |
| 67 | #include "qwidgetplatformfontdialog_p.h" |
| 68 | #endif |
| 69 | #if QT_CONFIG(messagebox) |
| 70 | #include "qwidgetplatformmessagedialog_p.h" |
| 71 | #endif |
| 72 | #if QT_CONFIG(menu) |
| 73 | #include "qwidgetplatformmenu_p.h" |
| 74 | #include "qwidgetplatformmenuitem_p.h" |
| 75 | #endif |
| 76 | #ifndef QT_NO_SYSTEMTRAYICON |
| 77 | #include "qwidgetplatformsystemtrayicon_p.h" |
| 78 | #endif |
| 79 | #endif |
| 80 | |
| 81 | QT_BEGIN_NAMESPACE |
| 82 | |
| 83 | #ifndef QT_WIDGETS_LIB |
| 84 | typedef QPlatformMenu QWidgetPlatformMenu; |
| 85 | typedef QPlatformMenuItem QWidgetPlatformMenuItem; |
| 86 | typedef QPlatformColorDialogHelper QWidgetPlatformColorDialog; |
| 87 | typedef QPlatformFileDialogHelper QWidgetPlatformFileDialog; |
| 88 | typedef QPlatformFontDialogHelper QWidgetPlatformFontDialog; |
| 89 | typedef QPlatformMessageDialogHelper QWidgetPlatformMessageDialog; |
| 90 | typedef QPlatformSystemTrayIcon QWidgetPlatformSystemTrayIcon; |
| 91 | #endif |
| 92 | |
| 93 | namespace QWidgetPlatform |
| 94 | { |
| 95 | static inline bool isAvailable(const char *type) |
| 96 | { |
| 97 | if (!qApp->inherits(classname: "QApplication" )) { |
| 98 | qCritical(msg: "\nERROR: No native %s implementation available." |
| 99 | "\nQt Labs Platform requires Qt Widgets on this setup." |
| 100 | "\nAdd 'QT += widgets' to .pro and create QApplication in main().\n" , type); |
| 101 | return false; |
| 102 | } |
| 103 | return true; |
| 104 | } |
| 105 | |
| 106 | template<typename T> |
| 107 | static inline T *createWidget(const char *name, QObject *parent) |
| 108 | { |
| 109 | static bool available = isAvailable(type: name); |
| 110 | #ifdef QT_WIDGETS_LIB |
| 111 | if (available) |
| 112 | return new T(parent); |
| 113 | #else |
| 114 | Q_UNUSED(parent) |
| 115 | Q_UNUSED(available) |
| 116 | #endif |
| 117 | return nullptr; |
| 118 | } |
| 119 | |
| 120 | static inline QPlatformMenu *(QObject *parent = nullptr) { |
| 121 | #if defined(QT_WIDGETS_LIB) && QT_CONFIG(menu) |
| 122 | return createWidget<QWidgetPlatformMenu>(name: "Menu" , parent); |
| 123 | #else |
| 124 | Q_UNUSED(parent); |
| 125 | return nullptr; |
| 126 | #endif |
| 127 | } |
| 128 | static inline QPlatformMenuItem *(QObject *parent = nullptr) { |
| 129 | #if defined(QT_WIDGETS_LIB) && QT_CONFIG(menu) |
| 130 | return createWidget<QWidgetPlatformMenuItem>(name: "MenuItem" , parent); |
| 131 | #else |
| 132 | Q_UNUSED(parent); |
| 133 | return nullptr; |
| 134 | #endif |
| 135 | } |
| 136 | static inline QPlatformSystemTrayIcon *createSystemTrayIcon(QObject *parent = nullptr) { |
| 137 | #ifndef QT_NO_SYSTEMTRAYICON |
| 138 | return createWidget<QWidgetPlatformSystemTrayIcon>(name: "SystemTrayIcon" , parent); |
| 139 | #else |
| 140 | Q_UNUSED(parent); |
| 141 | return nullptr; |
| 142 | #endif |
| 143 | } |
| 144 | static inline QPlatformDialogHelper *createDialog(QPlatformTheme::DialogType type, QObject *parent = nullptr) |
| 145 | { |
| 146 | #if !defined(QT_WIDGETS_LIB) || !(QT_CONFIG(colordialog) || QT_CONFIG(filedialog) || QT_CONFIG(fontdialog) || QT_CONFIG(messagebox)) |
| 147 | Q_UNUSED(parent); |
| 148 | #endif |
| 149 | switch (type) { |
| 150 | #if defined(QT_WIDGETS_LIB) && QT_CONFIG(colordialog) |
| 151 | case QPlatformTheme::ColorDialog: return createWidget<QWidgetPlatformColorDialog>(name: "ColorDialog" , parent); |
| 152 | #endif |
| 153 | #if defined(QT_WIDGETS_LIB) && QT_CONFIG(filedialog) |
| 154 | case QPlatformTheme::FileDialog: return createWidget<QWidgetPlatformFileDialog>(name: "FileDialog" , parent); |
| 155 | #endif |
| 156 | #if defined(QT_WIDGETS_LIB) && QT_CONFIG(fontdialog) |
| 157 | case QPlatformTheme::FontDialog: return createWidget<QWidgetPlatformFontDialog>(name: "FontDialog" , parent); |
| 158 | #endif |
| 159 | #if defined(QT_WIDGETS_LIB) && QT_CONFIG(messagebox) |
| 160 | case QPlatformTheme::MessageDialog: return createWidget<QWidgetPlatformMessageDialog>(name: "MessageDialog" , parent); |
| 161 | #endif |
| 162 | default: break; |
| 163 | } |
| 164 | return nullptr; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | QT_END_NAMESPACE |
| 169 | |
| 170 | #endif // QWIDGETPLATFORM_P_H |
| 171 | |