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 "qpicture.h"
30#include "qpixmap.h"
31#if QT_CONFIG(menu)
32#include "qmenu.h"
33#endif
34
35#include <QtCore/qpointer.h>
36
37#include <array>
38#include <optional>
39
40QT_BEGIN_NAMESPACE
41
42class Q_AUTOTEST_EXPORT QLabelPrivate : public QFramePrivate
43{
44 Q_DECLARE_PUBLIC(QLabel)
45public:
46 QLabelPrivate();
47 ~QLabelPrivate();
48
49 void init();
50 void clearContents();
51 void updateLabel();
52 QSize sizeForWidth(int w) const;
53
54#if QT_CONFIG(movie)
55 void movieUpdated(const QRect &rect);
56 void movieResized(const QSize &size);
57#endif
58#ifndef QT_NO_SHORTCUT
59 void updateShortcut();
60 void buddyDeleted();
61#endif
62 inline bool needTextControl() const {
63 Q_Q(const QLabel);
64 return isTextLabel
65 && (effectiveTextFormat != Qt::PlainText
66 || (textInteractionFlags & (Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard))
67 || q->focusPolicy() != Qt::NoFocus);
68 }
69
70 void ensureTextPopulated() const;
71 void ensureTextLayouted() const;
72 void ensureTextControl() const;
73 void sendControlEvent(QEvent *e);
74
75 void linkHovered(const QString &link);
76
77 QRectF layoutRect() const;
78 QRect documentRect() const;
79 QPoint layoutPoint(const QPoint& p) const;
80 Qt::LayoutDirection textDirection() const;
81#ifndef QT_NO_CONTEXTMENU
82 QMenu *createStandardContextMenu(const QPoint &pos);
83#endif
84
85 mutable QSize sh;
86 mutable QSize msh;
87 QString text;
88 std::optional<QIcon> icon;
89 QSize pixmapSize;
90#ifndef QT_NO_PICTURE
91 std::optional<QPicture> picture;
92#endif
93#if QT_CONFIG(movie)
94 QPointer<QMovie> movie;
95 std::array<QMetaObject::Connection, 2> movieConnections;
96#endif
97 mutable QWidgetTextControl *control = nullptr;
98 mutable QTextCursor shortcutCursor;
99#ifndef QT_NO_CURSOR
100 QCursor cursor;
101#endif
102#ifndef QT_NO_SHORTCUT
103 QPointer<QWidget> buddy;
104 int shortcutId = 0;
105#endif
106 Qt::TextFormat textformat = Qt::AutoText;
107 Qt::TextFormat effectiveTextFormat = Qt::PlainText;
108 Qt::TextInteractionFlags textInteractionFlags = Qt::LinksAccessibleByMouse;
109 mutable QSizePolicy sizePolicy;
110 int margin = 0;
111 int align = Qt::AlignLeft | Qt::AlignVCenter | Qt::TextExpandTabs;
112 int indent = -1;
113 mutable uint valid_hints : 1;
114 uint scaledcontents : 1;
115 mutable uint textLayoutDirty : 1;
116 mutable uint textDirty : 1;
117 mutable uint isTextLabel : 1;
118 mutable uint hasShortcut : 1;
119#ifndef QT_NO_CURSOR
120 uint validCursor : 1;
121 uint onAnchor : 1;
122#endif
123 uint openExternalLinks : 1;
124 // <-- space for more bit field values here
125 QTextDocument::ResourceProvider resourceProvider = nullptr;
126
127 friend class QMessageBoxPrivate;
128};
129
130QT_END_NAMESPACE
131
132#endif // QLABEL_P_H
133

source code of qtbase/src/widgets/widgets/qlabel_p.h