qlabel.h 5.6 KB

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