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 QLABEL_H
41#define QLABEL_H
42
43#include <QtWidgets/qtwidgetsglobal.h>
44#include <QtWidgets/qframe.h>
45
46QT_REQUIRE_CONFIG(label);
47
48QT_BEGIN_NAMESPACE
49
50
51class QLabelPrivate;
52
53class Q_WIDGETS_EXPORT QLabel : public QFrame
54{
55 Q_OBJECT
56 Q_PROPERTY(QString text READ text WRITE setText)
57 Q_PROPERTY(Qt::TextFormat textFormat READ textFormat WRITE setTextFormat)
58 Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
59 Q_PROPERTY(bool scaledContents READ hasScaledContents WRITE setScaledContents)
60 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
61 Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
62 Q_PROPERTY(int margin READ margin WRITE setMargin)
63 Q_PROPERTY(int indent READ indent WRITE setIndent)
64 Q_PROPERTY(bool openExternalLinks READ openExternalLinks WRITE setOpenExternalLinks)
65 Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
66 Q_PROPERTY(bool hasSelectedText READ hasSelectedText)
67 Q_PROPERTY(QString selectedText READ selectedText)
68
69public:
70 explicit QLabel(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags());
71 explicit QLabel(const QString &text, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags());
72 ~QLabel();
73
74 QString text() const;
75 const QPixmap *pixmap() const;
76#ifndef QT_NO_PICTURE
77 const QPicture *picture() const;
78#endif
79#if QT_CONFIG(movie)
80 QMovie *movie() const;
81#endif
82
83 Qt::TextFormat textFormat() const;
84 void setTextFormat(Qt::TextFormat);
85
86 Qt::Alignment alignment() const;
87 void setAlignment(Qt::Alignment);
88
89 void setWordWrap(bool on);
90 bool wordWrap() const;
91
92 int indent() const;
93 void setIndent(int);
94
95 int margin() const;
96 void setMargin(int);
97
98 bool hasScaledContents() const;
99 void setScaledContents(bool);
100 QSize sizeHint() const override;
101 QSize minimumSizeHint() const override;
102#ifndef QT_NO_SHORTCUT
103 void setBuddy(QWidget *);
104 QWidget *buddy() const;
105#endif
106 int heightForWidth(int) const override;
107
108 bool openExternalLinks() const;
109 void setOpenExternalLinks(bool open);
110
111 void setTextInteractionFlags(Qt::TextInteractionFlags flags);
112 Qt::TextInteractionFlags textInteractionFlags() const;
113
114 void setSelection(int, int);
115 bool hasSelectedText() const;
116 QString selectedText() const;
117 int selectionStart() const;
118
119public Q_SLOTS:
120 void setText(const QString &);
121 void setPixmap(const QPixmap &);
122#ifndef QT_NO_PICTURE
123 void setPicture(const QPicture &);
124#endif
125#if QT_CONFIG(movie)
126 void setMovie(QMovie *movie);
127#endif
128 void setNum(int);
129 void setNum(double);
130 void clear();
131
132Q_SIGNALS:
133 void linkActivated(const QString& link);
134 void linkHovered(const QString& link);
135
136protected:
137 bool event(QEvent *e) override;
138 void keyPressEvent(QKeyEvent *ev) override;
139 void paintEvent(QPaintEvent *) override;
140 void changeEvent(QEvent *) override;
141 void mousePressEvent(QMouseEvent *ev) override;
142 void mouseMoveEvent(QMouseEvent *ev) override;
143 void mouseReleaseEvent(QMouseEvent *ev) override;
144#ifndef QT_NO_CONTEXTMENU
145 void contextMenuEvent(QContextMenuEvent *ev) override;
146#endif // QT_NO_CONTEXTMENU
147 void focusInEvent(QFocusEvent *ev) override;
148 void focusOutEvent(QFocusEvent *ev) override;
149 bool focusNextPrevChild(bool next) override;
150
151
152private:
153 Q_DISABLE_COPY(QLabel)
154 Q_DECLARE_PRIVATE(QLabel)
155#if QT_CONFIG(movie)
156 Q_PRIVATE_SLOT(d_func(), void _q_movieUpdated(const QRect&))
157 Q_PRIVATE_SLOT(d_func(), void _q_movieResized(const QSize&))
158#endif
159 Q_PRIVATE_SLOT(d_func(), void _q_linkHovered(const QString &))
160
161#ifndef QT_NO_SHORTCUT
162 Q_PRIVATE_SLOT(d_func(), void _q_buddyDeleted())
163#endif
164 friend class QTipLabel;
165 friend class QMessageBoxPrivate;
166 friend class QBalloonTip;
167};
168
169QT_END_NAMESPACE
170
171#endif // QLABEL_H
172