Geometrize  1.0
An application for geometrizing images into geometric primitives
elidedlabel.h
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) Yash (http://speedovation.com/)
4 //
5 // Modifications Copyright (c) 2021, Sam Twidale.
6 // Contact: https://samcodes.co.uk/contact/
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
28 #include <memory>
29 
30 #include <QLabel>
31 
32 class QEvent;
33 
34 namespace geometrize
35 {
36 
37 namespace dialog
38 {
39 
43 class ElidedLabel : public QLabel
44 {
45  Q_OBJECT
46 
50  enum class TrimMode
51  {
52  None
53  };
54 
55 public:
56  explicit ElidedLabel(QWidget* parent = nullptr, Qt::WindowFlags flags = Qt::Widget);
57  ElidedLabel(const QString& text, QWidget* parent = nullptr, Qt::WindowFlags flags = Qt::Widget);
58  ElidedLabel(const QString& text, Qt::TextElideMode elideMode, ElidedLabel::TrimMode trimMode, QWidget* parent = nullptr, Qt::WindowFlags flags = Qt::Widget);
59  virtual ~ElidedLabel();
60 
65  Qt::TextElideMode getElideMode() const;
66 
71  void setElideMode(Qt::TextElideMode elideMode);
72 
76  void setText(const QString&);
77 
78 protected:
79  void changeEvent(QEvent*) override;
80  void paintEvent(QPaintEvent*) override;
81  void resizeEvent(QResizeEvent*) override;
82 
83 private:
84  class ElidedLabelImpl;
85  std::unique_ptr<ElidedLabelImpl> d;
86 };
87 
88 }
89 
90 }
geometrize::dialog::ElidedLabel::TrimMode
TrimMode
The TrimMode enum specifies the type of additional trimming done after the label text is elided.
Definition: elidedlabel.h:51
geometrize::dialog::ElidedLabel::ElidedLabelImpl::q
ElidedLabel * q
Definition: elidedlabel.cpp:92
geometrize::dialog::ElidedLabel::ElidedLabelImpl::ElidedLabelImpl
ElidedLabelImpl(ElidedLabel *pQ, const Qt::TextElideMode elideMode=Qt::ElideLeft, const ElidedLabel::TrimMode trimMode=TrimMode::None)
Definition: elidedlabel.cpp:42
geometrize::dialog::ElidedLabel::setElideMode
void setElideMode(Qt::TextElideMode elideMode)
setElideMode Set the elide mode used when displaying text.
Definition: elidedlabel.cpp:125
geometrize::dialog::ElidedLabel::changeEvent
void changeEvent(QEvent *) override
Definition: elidedlabel.cpp:152
geometrize::dialog::ElidedLabel::ElidedLabelImpl::m_elidedText
QString m_elidedText
The cached elided text.
Definition: elidedlabel.cpp:95
geometrize::dialog::ElidedLabel::~ElidedLabel
virtual ~ElidedLabel()
Definition: elidedlabel.cpp:116
geometrize::dialog::ElidedLabel::ElidedLabelImpl::m_elideMode
Qt::TextElideMode m_elideMode
The current elision mode.
Definition: elidedlabel.cpp:93
geometrize::dialog::ElidedLabel::ElidedLabelImpl
Definition: elidedlabel.cpp:40
geometrize::dialog::ElidedLabel::ElidedLabelImpl::m_trimMode
ElidedLabel::TrimMode m_trimMode
The current post-elision trim mode.
Definition: elidedlabel.cpp:94
geometrize::dialog::ElidedLabel::setText
void setText(const QString &)
setText overrides QLabel::setText.
Definition: elidedlabel.cpp:130
geometrize::dialog::ElidedLabel::d
std::unique_ptr< ElidedLabelImpl > d
Definition: elidedlabel.h:84
geometrize
Definition: commandlineparser.cpp:73
geometrize::dialog::ElidedLabel::getElideMode
Qt::TextElideMode getElideMode() const
getElideMode Get the elide mode currently used when displaying text.
Definition: elidedlabel.cpp:120
geometrize::dialog::ElidedLabel::paintEvent
void paintEvent(QPaintEvent *) override
Definition: elidedlabel.cpp:142
geometrize::dialog::ElidedLabel::TrimMode::None
@ None
Does no extra trimming.
geometrize::dialog::ElidedLabel::ElidedLabelImpl::getElidedText
QString getElidedText() const
Definition: elidedlabel.cpp:64
geometrize::dialog::ElidedLabel::ElidedLabelImpl::onLanguageChange
void onLanguageChange()
Definition: elidedlabel.cpp:81
elidedlabel.h
geometrize::dialog::ElidedLabel::ElidedLabel
ElidedLabel(QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::Widget)
Definition: elidedlabel.cpp:98
geometrize::dialog::ElidedLabel::resizeEvent
void resizeEvent(QResizeEvent *) override
Definition: elidedlabel.cpp:136
geometrize::dialog::ElidedLabel::ElidedLabelImpl::populateUi
void populateUi()
Definition: elidedlabel.cpp:87
geometrize::dialog::ElidedLabel::ElidedLabelImpl::setText
void setText(const QString &text)
Definition: elidedlabel.cpp:59
geometrize::dialog::ElidedLabel::ElidedLabelImpl::cacheElidedText
void cacheElidedText(const QString &text, const int width)
Definition: elidedlabel.cpp:69
geometrize::dialog::ElidedLabel::ElidedLabelImpl::getElideMode
Qt::TextElideMode getElideMode() const
Definition: elidedlabel.cpp:48
geometrize::dialog::ElidedLabel::ElidedLabelImpl::setElideMode
void setElideMode(const Qt::TextElideMode elideMode)
Definition: elidedlabel.cpp:53
geometrize::dialog::ElidedLabel
The ElidedLabel class is a label that elides text that does not fit within it.
Definition: elidedlabel.h:44