1 | // Copyright (C) 2016 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 QLABEL_P_H |
5 | #define QLABEL_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 <QtWidgets/private/qtwidgetsglobal_p.h> |
19 | #include "qlabel.h" |
20 | |
21 | #include "private/qtextdocumentlayout_p.h" |
22 | #include "private/qwidgettextcontrol_p.h" |
23 | #include "qtextdocumentfragment.h" |
24 | #include "qframe_p.h" |
25 | #include "qtextdocument.h" |
26 | #if QT_CONFIG(movie) |
27 | #include "qmovie.h" |
28 | #endif |
29 | #include "qimage.h" |
30 | #include "qbitmap.h" |
31 | #include "qpicture.h" |
32 | #if QT_CONFIG(menu) |
33 | #include "qmenu.h" |
34 | #endif |
35 | |
36 | #include <optional> |
37 | |
38 | QT_BEGIN_NAMESPACE |
39 | |
40 | class Q_AUTOTEST_EXPORT QLabelPrivate : public QFramePrivate |
41 | { |
42 | Q_DECLARE_PUBLIC(QLabel) |
43 | public: |
44 | QLabelPrivate(); |
45 | ~QLabelPrivate(); |
46 | |
47 | void init(); |
48 | void clearContents(); |
49 | void updateLabel(); |
50 | QSize sizeForWidth(int w) const; |
51 | |
52 | #if QT_CONFIG(movie) |
53 | void _q_movieUpdated(const QRect&); |
54 | void _q_movieResized(const QSize&); |
55 | #endif |
56 | #ifndef QT_NO_SHORTCUT |
57 | void updateShortcut(); |
58 | void _q_buddyDeleted(); |
59 | #endif |
60 | inline bool needTextControl() const { |
61 | Q_Q(const QLabel); |
62 | return isTextLabel |
63 | && (effectiveTextFormat != Qt::PlainText |
64 | || (textInteractionFlags & (Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard)) |
65 | || q->focusPolicy() != Qt::NoFocus); |
66 | } |
67 | |
68 | void ensureTextPopulated() const; |
69 | void ensureTextLayouted() const; |
70 | void ensureTextControl() const; |
71 | void sendControlEvent(QEvent *e); |
72 | |
73 | void _q_linkHovered(const QString &link); |
74 | |
75 | QRectF layoutRect() const; |
76 | QRect documentRect() const; |
77 | QPoint layoutPoint(const QPoint& p) const; |
78 | Qt::LayoutDirection textDirection() const; |
79 | #ifndef QT_NO_CONTEXTMENU |
80 | QMenu *createStandardContextMenu(const QPoint &pos); |
81 | #endif |
82 | |
83 | mutable QSize sh; |
84 | mutable QSize msh; |
85 | QString text; |
86 | std::optional<QPixmap> pixmap; |
87 | std::optional<QPixmap> scaledpixmap; |
88 | std::optional<QImage> cachedimage; |
89 | #ifndef QT_NO_PICTURE |
90 | std::optional<QPicture> picture; |
91 | #endif |
92 | #if QT_CONFIG(movie) |
93 | QPointer<QMovie> movie; |
94 | #endif |
95 | mutable QWidgetTextControl *control; |
96 | mutable QTextCursor shortcutCursor; |
97 | #ifndef QT_NO_CURSOR |
98 | QCursor cursor; |
99 | #endif |
100 | #ifndef QT_NO_SHORTCUT |
101 | QPointer<QWidget> buddy; |
102 | int shortcutId; |
103 | #endif |
104 | Qt::TextFormat textformat; |
105 | Qt::TextFormat effectiveTextFormat; |
106 | Qt::TextInteractionFlags textInteractionFlags; |
107 | mutable QSizePolicy sizePolicy; |
108 | int margin; |
109 | ushort align; |
110 | short indent; |
111 | mutable uint valid_hints : 1; |
112 | uint scaledcontents : 1; |
113 | mutable uint textLayoutDirty : 1; |
114 | mutable uint textDirty : 1; |
115 | mutable uint isTextLabel : 1; |
116 | mutable uint hasShortcut : 1; |
117 | #ifndef QT_NO_CURSOR |
118 | uint validCursor : 1; |
119 | uint onAnchor : 1; |
120 | #endif |
121 | uint openExternalLinks : 1; |
122 | // <-- space for more bit field values here |
123 | QTextDocument::ResourceProvider resourceProvider; |
124 | |
125 | friend class QMessageBoxPrivate; |
126 | }; |
127 | |
128 | QT_END_NAMESPACE |
129 | |
130 | #endif // QLABEL_P_H |
131 | |