QtBase  v6.3.1
qapplication_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWidgets module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QAPPLICATION_P_H
41 #define QAPPLICATION_P_H
42 
43 //
44 // W A R N I N G
45 // -------------
46 //
47 // This file is not part of the Qt API. It exists for the convenience
48 // of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp
49 // and many other. This header file may change from version to version
50 // without notice, or even be removed.
51 //
52 // We mean it.
53 //
54 
55 #include <QtWidgets/private/qtwidgetsglobal_p.h>
56 #include "QtWidgets/qapplication.h"
57 #include "QtGui/qevent.h"
58 #include "QtGui/qfont.h"
59 #include "QtGui/qcursor.h"
60 #include "QtGui/qregion.h"
61 #include "QtGui/qwindow.h"
62 #include "qwidget.h"
63 #include <qpa/qplatformnativeinterface.h>
64 #include "QtCore/qmutex.h"
65 #include "QtCore/qtranslator.h"
66 #include "QtCore/qbasictimer.h"
67 #include "QtCore/qhash.h"
68 #include "QtCore/qpointer.h"
69 #include "private/qcoreapplication_p.h"
70 #include "QtCore/qpoint.h"
71 #include <QTime>
72 #include <qpa/qwindowsysteminterface.h>
73 #include <qpa/qwindowsysteminterface_p.h>
74 #include <qpa/qplatformintegration.h>
75 #include "private/qguiapplication_p.h"
76 
78 
79 class QClipboard;
80 class QGraphicsScene;
81 class QObject;
82 class QWidget;
83 class QSocketNotifier;
84 class QPointingDevice;
85 #ifndef QT_NO_GESTURES
86 class QGestureManager;
87 #endif
88 
89 extern Q_GUI_EXPORT bool qt_is_tty_app;
90 #ifndef QT_NO_CLIPBOARD
91 extern QClipboard *qt_clipboard;
92 #endif
93 
95 Q_WIDGETS_EXPORT FontHash *qt_app_fonts_hash();
96 
97 #define QApplicationPrivateBase QGuiApplicationPrivate
98 
99 class Q_WIDGETS_EXPORT QApplicationPrivate : public QApplicationPrivateBase
100 {
101  Q_DECLARE_PUBLIC(QApplication)
102 public:
103  QApplicationPrivate(int &argc, char **argv, int flags);
105 
106  virtual void notifyLayoutDirectionChange() override;
107  virtual void notifyActiveWindowChange(QWindow *) override;
108 
109  static bool autoSipEnabled;
110  static QString desktopStyleKey();
111 
112  void createEventDispatcher() override;
113  static void dispatchEnterLeave(QWidget *enter, QWidget *leave, const QPointF &globalPosF);
114  static QWidget *desktop();
115  void notifyWindowIconChanged() override;
116 
117 #ifndef QT_NO_ACTION
118  QActionPrivate *createActionPrivate() const override;
119 #endif
120 #ifndef QT_NO_SHORTCUT
121  QShortcutPrivate *createShortcutPrivate() const override;
122 #endif
123 
124  //modality
125  bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = nullptr) const override;
126  static bool isBlockedByModal(QWidget *widget);
127  static bool modalState();
128  static bool tryModalHelper(QWidget *widget, QWidget **rettop = nullptr);
129 
130 #ifdef QT_KEYPAD_NAVIGATION
131  static bool keypadNavigationEnabled()
132  {
133  return navigationMode == Qt::NavigationModeKeypadTabOrder ||
134  navigationMode == Qt::NavigationModeKeypadDirectional;
135  }
136 #endif
137 
138  bool notify_helper(QObject *receiver, QEvent * e);
139 
140  void init();
141  void initialize();
142  void process_cmdline();
143 
144  static bool inPopupMode();
145  bool popupActive() override { return inPopupMode(); }
146  bool closeAllPopups() override;
147  void closePopup(QWidget *popup);
148  void openPopup(QWidget *popup);
149  static void setFocusWidget(QWidget *focus, Qt::FocusReason reason);
150  static QWidget *focusNextPrevChild_helper(QWidget *toplevel, bool next,
151  bool *wrappingOccurred = nullptr);
152 
153 #if QT_CONFIG(graphicsview)
154  // Maintain a list of all scenes to ensure font and palette propagation to
155  // all scenes.
156  QList<QGraphicsScene *> scene_list;
157 #endif
158 
160  QPoint toolTipPos, toolTipGlobalPos, hoverGlobalPos;
162 
163  static QSize app_strut;
165  static QStyle *app_style;
166 
167 protected:
168  void notifyThemeChanged() override;
169 
170  QPalette basePalette() const override;
171  void handlePaletteChanged(const char *className = nullptr) override;
172 
173 #if QT_CONFIG(draganddrop)
174  void notifyDragStarted(const QDrag *) override;
175 #endif // QT_CONFIG(draganddrop)
176 
177 public:
178  static QFont *sys_font;
179  static QFont *set_font;
184 #if QT_CONFIG(wheelevent)
185  static int wheel_scroll_lines;
186  static QPointer<QWidget> wheel_widget;
187 #endif
188 
189  static int enabledAnimations; // Combination of QPlatformTheme::UiEffect
190  static bool widgetCount; // Coupled with -widgetcount switch
191 
192  static void initializeWidgetPalettesFromTheme();
193  static void initializeWidgetFontHash();
194  static void setSystemFont(const QFont &font);
195 
198 
199  static QApplicationPrivate *instance() { return self; }
200 
201 #ifdef QT_KEYPAD_NAVIGATION
202  static QWidget *oldEditFocus;
203  static Qt::NavigationMode navigationMode;
204 #endif
205 
206 #ifndef QT_NO_STYLE_STYLESHEET
208 #endif
210  static QWidget *pickMouseReceiver(QWidget *candidate, const QPoint &windowPos, QPoint *pos,
211  QEvent::Type type, Qt::MouseButtons buttons,
212  QWidget *buttonDown, QWidget *alienWidget);
213  static bool sendMouseEvent(QWidget *receiver, QMouseEvent *event, QWidget *alienWidget,
214  QWidget *native, QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver,
215  bool spontaneous = true, bool onlyDispatchEnterLeave = false);
216  void sendSyntheticEnterLeave(QWidget *widget);
217 
219  {
220  if (QWindow *window = widget->windowHandle())
221  return window;
222  if (const QWidget *nativeParent = widget->nativeParentWidget())
223  return nativeParent->windowHandle();
224  return nullptr;
225  }
226 
227 #ifdef Q_OS_WIN
228  static HWND getHWNDForWidget(const QWidget *widget)
229  {
230  if (QWindow *window = windowForWidget(widget))
232  return static_cast<HWND> (QGuiApplication::platformNativeInterface()->
233  nativeResourceForWindow(QByteArrayLiteral("handle"), window));
234  return 0;
235  }
236 #endif
237 
238 #ifndef QT_NO_GESTURES
241 #endif
242 
243  static bool updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent);
244  void initializeMultitouch();
245  void initializeMultitouch_sys();
246  void cleanupMultitouch();
247  void cleanupMultitouch_sys();
248  QWidget *findClosestTouchPointTarget(const QPointingDevice *device, const QEventPoint &touchPoint);
249  void appendTouchPoint(const QEventPoint &touchPoint);
250  void removeTouchPoint(int touchPointId);
251  enum ImplicitTouchGrabMode { GrabAcceptedPoints, GrabAllPoints };
252  void activateImplicitTouchGrab(QWidget *widget, QTouchEvent *touchBeginEvent,
253  ImplicitTouchGrabMode grabMode = GrabAcceptedPoints);
254  static bool translateRawTouchEvent(QWidget *widget, const QTouchEvent *touchEvent);
255  static void translateTouchCancel(const QPointingDevice *device, ulong timestamp);
256 
257  QPixmap applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const override;
258 
259 private:
260  static QApplicationPrivate *self;
261  static bool tryCloseAllWidgetWindows(QWindowList *processedWindows);
262 
263  static void giveFocusAccordingToFocusPolicy(QWidget *w, QEvent *event, QPoint localPos);
264  static bool shouldSetFocus(QWidget *w, Qt::FocusPolicy policy);
265 
266 
267  static bool isAlien(QWidget *);
268 };
269 
270 extern void qt_qpa_set_cursor(QWidget * w, bool force);
271 
273 
274 #endif // QAPPLICATION_P_H
The QApplication class manages the GUI application's control flow and main settings.
Definition: qapplication.h:68
static QWindow * windowForWidget(const QWidget *widget)
static QWidget * focus_widget
static QPointer< QWidget > leaveAfterRelease
QGestureManager * gestureManager
bool popupActive() override
QBasicTimer toolTipFallAsleep
static QWidget * hidden_focus_widget
QPointer< QWidget > toolTipWidget
static QWidget * active_window
static PaletteHash widgetPalettes
static int enabledAnimations
static QString styleSheet
static bool widgetCount
static QFont * sys_font
static QWidgetList * popupWidgets
static QStyle * app_style
static QWidget * main_widget
static bool autoSipEnabled
static QApplicationPrivate * instance()
static QSize app_strut
void appendTouchPoint(const QEventPoint &touchPoint)
static QFont * set_font
void removeTouchPoint(int touchPointId)
The QBasicTimer class provides timer events for objects.
Definition: qbasictimer.h:52
The QClipboard class provides access to the window system clipboard. \inmodule QtGui.
Definition: qclipboard.h:56
The QDrag class provides support for MIME-based drag and drop data transfer.
Definition: qdrag.h:58
The QEvent class is the base class of all event classes. Event objects contain event parameters.
Definition: qcoreevent.h:58
The QEventPoint class provides information about a point in a QPointerEvent.
Definition: qeventpoint.h:56
The QFont class specifies a query for a font used for drawing text.
Definition: qfont.h:56
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
static QPlatformNativeInterface * platformNativeInterface()
Mode
Definition: qicon.h:58
Definition: qlist.h:108
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:231
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:55
The QPixmap class is an off-screen image representation that can be used as a paint device.
Definition: qpixmap.h:63
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:52
The QPointingDevice class describes a device from which mouse, touch or tablet events originate.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:55
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition: qstyle.h:65
The QTouchEvent class contains parameters that describe a touch event.
Definition: qevent.h:1020
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
QWidget * nativeParentWidget() const
Definition: qwidget.cpp:4339
QWindow * windowHandle() const
Definition: qwidget.cpp:2495
The QWindow class represents a window in the underlying windowing system.
Definition: qwindow.h:99
Definition: base.h:37
QOpenGLWidget * widget
[1]
bool focus
[0]
double e
short next
Definition: keywords.cpp:454
QTouchEventSequence touchEvent(QWindow *window, QPointingDevice *device, bool autoCommit=true)
Definition: qtesttouch.h:78
NavigationMode
Definition: qnamespace.h:1676
@ NavigationModeKeypadDirectional
Definition: qnamespace.h:1679
@ NavigationModeKeypadTabOrder
Definition: qnamespace.h:1678
FocusPolicy
Definition: qnamespace.h:131
FocusReason
Definition: qnamespace.h:1360
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld init[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld SRC pixld MASK if DST_R else pixld DST_R endif if src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head if pixblock_size cache_preload_simple endif process_pixblock_tail pixinterleave dst_w_basereg irp if pixblock_size chunk_size tst beq if DST_W else pixst DST_W else mov ORIG_W endif add lsl if lsl endif if lsl endif lsl endif lsl endif lsl endif subs mov DST_W if regs_shortage str endif bge start_of_loop_label endm macro generate_composite_function
Q_WIDGETS_EXPORT FontHash * qt_app_fonts_hash()
Q_GUI_EXPORT bool qt_is_tty_app
void qt_qpa_set_cursor(QWidget *w, bool force)
Definition: qwidget.cpp:5020
QHash< QByteArray, QFont > FontHash
QClipboard * qt_clipboard
#define QApplicationPrivateBase
#define QByteArrayLiteral(str)
Definition: qbytearray.h:80
unsigned long ulong
Definition: qglobal.h:335
GLenum type
Definition: qopengl.h:270
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLbitfield flags
struct _cl_event * event
Definition: qopenglext.h:2998
#define leave(x)
Definition: qurlquery.cpp:243
const char className[16]
[1]
Definition: qwizard.cpp:135
aWidget window() -> setWindowTitle("New Window Title")
[2]
QSizePolicy policy
socketLayer initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv4Protocol)