ElidingLabel.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef ElidingLabelH
  2. #define ElidingLabelH
  3. /*******************************************************************************
  4. ** Qt Advanced Docking System
  5. ** Copyright (C) 2017 Uwe Kindler
  6. **
  7. ** This library is free software; you can redistribute it and/or
  8. ** modify it under the terms of the GNU Lesser General Public
  9. ** License as published by the Free Software Foundation; either
  10. ** version 2.1 of the License, or (at your option) any later version.
  11. **
  12. ** This library is distributed in the hope that it will be useful,
  13. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. ** Lesser General Public License for more details.
  16. **
  17. ** You should have received a copy of the GNU Lesser General Public
  18. ** License along with this library; If not, see <http://www.gnu.org/licenses/>.
  19. ******************************************************************************/
  20. //============================================================================
  21. /// \file ElidingLabel.h
  22. /// \author Uwe Kindler
  23. /// \date 05.11.2018
  24. /// \brief Declaration of CElidingLabel
  25. //============================================================================
  26. //============================================================================
  27. // INCLUDES
  28. //============================================================================
  29. #include <QLabel>
  30. #include "ads_globals.h"
  31. namespace ads
  32. {
  33. struct ElidingLabelPrivate;
  34. /**
  35. * A QLabel that supports eliding text.
  36. * Because the functions setText() and text() are no virtual functions setting
  37. * and reading the text via a pointer to the base class QLabel does not work
  38. * properly
  39. */
  40. class ADS_EXPORT CElidingLabel : public QLabel
  41. {
  42. Q_OBJECT
  43. private:
  44. ElidingLabelPrivate* d;
  45. friend struct ElidingLabelPrivate;
  46. protected:
  47. virtual void mouseReleaseEvent(QMouseEvent* event) override;
  48. virtual void resizeEvent( QResizeEvent *event ) override;
  49. virtual void mouseDoubleClickEvent( QMouseEvent *ev ) override;
  50. public:
  51. using Super = QLabel;
  52. CElidingLabel(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags ());
  53. CElidingLabel(const QString& text, QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags ());
  54. virtual ~CElidingLabel();
  55. /**
  56. * Returns the text elide mode.
  57. * The default mode is ElideNone
  58. */
  59. Qt::TextElideMode elideMode() const;
  60. /**
  61. * Sets the text elide mode
  62. */
  63. void setElideMode(Qt::TextElideMode mode);
  64. /**
  65. * This function indicates whether the text on this label is currently elided
  66. */
  67. bool isElided() const;
  68. public: // reimplements QLabel ----------------------------------------------
  69. virtual QSize minimumSizeHint() const override;
  70. virtual QSize sizeHint() const override;
  71. void setText(const QString &text);
  72. QString text() const;
  73. Q_SIGNALS:
  74. /**
  75. * This signal is emitted if the user clicks on the label (i.e. pressed
  76. * down then released while the mouse cursor is inside the label)
  77. */
  78. void clicked();
  79. /**
  80. * This signal is emitted if the user does a double click on the label
  81. */
  82. void doubleClicked();
  83. /**
  84. * This signal is emitted when isElided() state of this label is changed
  85. */
  86. void elidedChanged(bool elided);
  87. }; //class CElidingLabel
  88. } // namespace QtLabb
  89. //---------------------------------------------------------------------------
  90. #endif // ElidingLabelH