| 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_H |
| 5 | #define QLABEL_H |
| 6 | |
| 7 | #include <QtWidgets/qtwidgetsglobal.h> |
| 8 | #include <QtWidgets/qframe.h> |
| 9 | #include <QtGui/qpicture.h> |
| 10 | #include <QtGui/qtextdocument.h> |
| 11 | |
| 12 | QT_REQUIRE_CONFIG(label); |
| 13 | |
| 14 | QT_BEGIN_NAMESPACE |
| 15 | |
| 16 | |
| 17 | class QLabelPrivate; |
| 18 | |
| 19 | class Q_WIDGETS_EXPORT QLabel : public QFrame |
| 20 | { |
| 21 | Q_OBJECT |
| 22 | Q_PROPERTY(QString text READ text WRITE setText) |
| 23 | Q_PROPERTY(Qt::TextFormat textFormat READ textFormat WRITE setTextFormat) |
| 24 | Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap) |
| 25 | Q_PROPERTY(bool scaledContents READ hasScaledContents WRITE setScaledContents) |
| 26 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) |
| 27 | Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap) |
| 28 | Q_PROPERTY(int margin READ margin WRITE setMargin) |
| 29 | Q_PROPERTY(int indent READ indent WRITE setIndent) |
| 30 | Q_PROPERTY(bool openExternalLinks READ openExternalLinks WRITE setOpenExternalLinks) |
| 31 | Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags |
| 32 | WRITE setTextInteractionFlags) |
| 33 | Q_PROPERTY(bool hasSelectedText READ hasSelectedText) |
| 34 | Q_PROPERTY(QString selectedText READ selectedText) |
| 35 | |
| 36 | public: |
| 37 | explicit QLabel(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags()); |
| 38 | explicit QLabel(const QString &text, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags()); |
| 39 | ~QLabel(); |
| 40 | |
| 41 | QString text() const; |
| 42 | |
| 43 | #if QT_DEPRECATED_SINCE(6,6) |
| 44 | QPixmap pixmap(Qt::ReturnByValueConstant) const { return pixmap(); } |
| 45 | #endif |
| 46 | QPixmap pixmap() const; |
| 47 | |
| 48 | #ifndef QT_NO_PICTURE |
| 49 | #if QT_DEPRECATED_SINCE(6,6) |
| 50 | QPicture picture(Qt::ReturnByValueConstant) const { return picture(); } |
| 51 | #endif |
| 52 | QPicture picture() const; |
| 53 | #endif |
| 54 | #if QT_CONFIG(movie) |
| 55 | QMovie *movie() const; |
| 56 | #endif |
| 57 | |
| 58 | Qt::TextFormat textFormat() const; |
| 59 | void setTextFormat(Qt::TextFormat); |
| 60 | |
| 61 | QTextDocument::ResourceProvider resourceProvider() const; |
| 62 | void setResourceProvider(const QTextDocument::ResourceProvider &provider); |
| 63 | |
| 64 | Qt::Alignment alignment() const; |
| 65 | void setAlignment(Qt::Alignment); |
| 66 | |
| 67 | void setWordWrap(bool on); |
| 68 | bool wordWrap() const; |
| 69 | |
| 70 | int indent() const; |
| 71 | void setIndent(int); |
| 72 | |
| 73 | int margin() const; |
| 74 | void setMargin(int); |
| 75 | |
| 76 | bool hasScaledContents() const; |
| 77 | void setScaledContents(bool); |
| 78 | QSize sizeHint() const override; |
| 79 | QSize minimumSizeHint() const override; |
| 80 | #ifndef QT_NO_SHORTCUT |
| 81 | void setBuddy(QWidget *); |
| 82 | QWidget *buddy() const; |
| 83 | #endif |
| 84 | int heightForWidth(int) const override; |
| 85 | |
| 86 | bool openExternalLinks() const; |
| 87 | void setOpenExternalLinks(bool open); |
| 88 | |
| 89 | void setTextInteractionFlags(Qt::TextInteractionFlags flags); |
| 90 | Qt::TextInteractionFlags textInteractionFlags() const; |
| 91 | |
| 92 | void setSelection(int, int); |
| 93 | bool hasSelectedText() const; |
| 94 | QString selectedText() const; |
| 95 | int selectionStart() const; |
| 96 | |
| 97 | public Q_SLOTS: |
| 98 | void setText(const QString &); |
| 99 | void setPixmap(const QPixmap &); |
| 100 | #ifndef QT_NO_PICTURE |
| 101 | void setPicture(const QPicture &); |
| 102 | #endif |
| 103 | #if QT_CONFIG(movie) |
| 104 | void setMovie(QMovie *movie); |
| 105 | #endif |
| 106 | void setNum(int); |
| 107 | void setNum(double); |
| 108 | void clear(); |
| 109 | |
| 110 | Q_SIGNALS: |
| 111 | void linkActivated(const QString& link); |
| 112 | void linkHovered(const QString& link); |
| 113 | |
| 114 | protected: |
| 115 | bool event(QEvent *e) override; |
| 116 | void keyPressEvent(QKeyEvent *ev) override; |
| 117 | void paintEvent(QPaintEvent *) override; |
| 118 | void changeEvent(QEvent *) override; |
| 119 | void mousePressEvent(QMouseEvent *ev) override; |
| 120 | void mouseMoveEvent(QMouseEvent *ev) override; |
| 121 | void mouseReleaseEvent(QMouseEvent *ev) override; |
| 122 | #ifndef QT_NO_CONTEXTMENU |
| 123 | void (QContextMenuEvent *ev) override; |
| 124 | #endif // QT_NO_CONTEXTMENU |
| 125 | void focusInEvent(QFocusEvent *ev) override; |
| 126 | void focusOutEvent(QFocusEvent *ev) override; |
| 127 | bool focusNextPrevChild(bool next) override; |
| 128 | |
| 129 | |
| 130 | private: |
| 131 | Q_DISABLE_COPY(QLabel) |
| 132 | Q_DECLARE_PRIVATE(QLabel) |
| 133 | friend class QTipLabel; |
| 134 | friend class QMessageBoxPrivate; |
| 135 | friend class QBalloonTip; |
| 136 | }; |
| 137 | |
| 138 | QT_END_NAMESPACE |
| 139 | |
| 140 | #endif // QLABEL_H |
| 141 | |