Changeset View
Changeset View
Standalone View
Standalone View
src/ksqueezedtextlabel.h
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | |||||
54 | * label->setText("new text"); // this will not work | 54 | * label->setText("new text"); // this will not work | ||
55 | * squeezed->setText("new text"); // works as expected | 55 | * squeezed->setText("new text"); // works as expected | ||
56 | * static_cast<KSqueezedTextLabel*>(label)->setText("new text"); // works as expected | 56 | * static_cast<KSqueezedTextLabel*>(label)->setText("new text"); // works as expected | ||
57 | * \endcode | 57 | * \endcode | ||
58 | * | 58 | * | ||
59 | * @author Ronny Standtke <Ronny.Standtke@gmx.de> | 59 | * @author Ronny Standtke <Ronny.Standtke@gmx.de> | ||
60 | */ | 60 | */ | ||
61 | 61 | | |||
62 | // TODO KF6: | ||||
63 | // - make more functions virtual (to benefit subclasses of KSqueezedTextLabel) | ||||
64 | // - try to eliminate need for non-virtual-warning (to benefit use as QLabel), | ||||
65 | // see https://phabricator.kde.org/D7164 for some ideas/considerations | ||||
66 | | ||||
62 | /* | 67 | /* | ||
63 | * QLabel | 68 | * QLabel | ||
64 | */ | 69 | */ | ||
65 | class KWIDGETSADDONS_EXPORT KSqueezedTextLabel : public QLabel | 70 | class KWIDGETSADDONS_EXPORT KSqueezedTextLabel : public QLabel | ||
66 | { | 71 | { | ||
67 | Q_OBJECT | 72 | Q_OBJECT | ||
68 | Q_PROPERTY(Qt::TextElideMode textElideMode READ textElideMode WRITE setTextElideMode) | 73 | Q_PROPERTY(Qt::TextElideMode textElideMode READ textElideMode WRITE setTextElideMode) | ||
74 | Q_PROPERTY(int indent READ indent WRITE setIndent) | ||||
75 | Q_PROPERTY(int margin READ margin WRITE setMargin) | ||||
76 | Q_PROPERTY(int lineWidth READ lineWidth WRITE setLineWidth) | ||||
69 | 77 | | |||
70 | public: | 78 | public: | ||
71 | /** | 79 | /** | ||
72 | * Default constructor. | 80 | * Default constructor. | ||
73 | * @param parent the label's parent object | 81 | * @param parent the label's parent object | ||
74 | */ | 82 | */ | ||
75 | explicit KSqueezedTextLabel(QWidget *parent = nullptr); | 83 | explicit KSqueezedTextLabel(QWidget *parent = nullptr); | ||
76 | 84 | | |||
Show All 14 Lines | |||||
91 | 99 | | |||
92 | /** | 100 | /** | ||
93 | * @return the label's preferred size, which is wide enough | 101 | * @return the label's preferred size, which is wide enough | ||
94 | * to display the text without squeezing it | 102 | * to display the text without squeezing it | ||
95 | */ | 103 | */ | ||
96 | QSize sizeHint() const Q_DECL_OVERRIDE; | 104 | QSize sizeHint() const Q_DECL_OVERRIDE; | ||
97 | 105 | | |||
98 | /** | 106 | /** | ||
107 | * Sets the indentation of the label. | ||||
108 | * | ||||
109 | * @param indent the amount of indentation in pixels | ||||
110 | * | ||||
111 | * Reimplementation of QLabel::setIndent(). | ||||
112 | * | ||||
113 | * @warning The corresponding function in the base class is not virtual. | ||||
114 | * Therefore make sure to call this function on objects of type KSqueezedTextLabel, | ||||
115 | * as shown in the @ref non-virtual-warning "example in the class description". | ||||
116 | * | ||||
117 | * @since 5.38 | ||||
118 | */ | ||||
119 | void setIndent(int indent); | ||||
120 | | ||||
121 | /** | ||||
122 | * Sets the margin of the label. | ||||
123 | * | ||||
124 | * @param margin the margin size in pixels | ||||
125 | * | ||||
126 | * Reimplementation of QLabel::setMargin(). | ||||
127 | * | ||||
128 | * @warning The corresponding function in the base class is not virtual. | ||||
129 | * Therefore make sure to call this function on objects of type KSqueezedTextLabel, | ||||
130 | * as shown in the @ref non-virtual-warning "example in the class description". | ||||
131 | * | ||||
132 | * @since 5.38 | ||||
133 | */ | ||||
134 | void setMargin(int margin); | ||||
135 | | ||||
136 | /** | ||||
137 | * Sets the frame width of the label. | ||||
138 | * | ||||
139 | * @param width the frame width in pixels | ||||
140 | * | ||||
141 | * Reimplementation of QLabel::setLineWidth(). | ||||
142 | * | ||||
143 | * @warning The corresponding function in the base class is not virtual. | ||||
144 | * Therefore make sure to call this function on objects of type KSqueezedTextLabel, | ||||
145 | * as shown in the @ref non-virtual-warning "example in the class description". | ||||
146 | * | ||||
147 | * @see QFrame::setFrameStyle() | ||||
148 | * | ||||
149 | * @since 5.38 | ||||
150 | */ | ||||
151 | void setLineWidth(int width); | ||||
152 | | ||||
153 | /** | ||||
99 | * Overridden for internal reasons; the API remains unaffected. | 154 | * Overridden for internal reasons; the API remains unaffected. | ||
100 | */ | 155 | */ | ||
101 | virtual void setAlignment(Qt::Alignment); | 156 | virtual void setAlignment(Qt::Alignment); | ||
102 | 157 | | |||
103 | /** | 158 | /** | ||
104 | * @return the text elide mode | 159 | * @return the text elide mode | ||
105 | */ | 160 | */ | ||
106 | Qt::TextElideMode textElideMode() const; | 161 | Qt::TextElideMode textElideMode() const; | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 209 | protected: | |||
167 | */ | 222 | */ | ||
168 | void contextMenuEvent(QContextMenuEvent *) Q_DECL_OVERRIDE; | 223 | void contextMenuEvent(QContextMenuEvent *) Q_DECL_OVERRIDE; | ||
169 | 224 | | |||
170 | /** | 225 | /** | ||
171 | * does the dirty work | 226 | * does the dirty work | ||
172 | */ | 227 | */ | ||
173 | void squeezeTextToLabel(); | 228 | void squeezeTextToLabel(); | ||
174 | 229 | | |||
230 | /** | ||||
231 | * @return the rectangle to squeeze the text into | ||||
232 | * | ||||
233 | * Reimplementation of QLabel::contentsRect(). | ||||
234 | * | ||||
235 | * @warning The corresponding function in the base class is not virtual. | ||||
236 | * Therefore make sure to call this function on objects of type KSqueezedTextLabel, | ||||
237 | * as shown in the @ref non-virtual-warning "example in the class description". | ||||
238 | * | ||||
239 | * @since 5.38 | ||||
240 | */ | ||||
241 | QRect contentsRect() const; | ||||
242 | | ||||
175 | private: | 243 | private: | ||
176 | Q_PRIVATE_SLOT(d, void _k_copyFullText()) | 244 | Q_PRIVATE_SLOT(d, void _k_copyFullText()) | ||
177 | KSqueezedTextLabelPrivate *const d; | 245 | KSqueezedTextLabelPrivate *const d; | ||
178 | }; | 246 | }; | ||
179 | 247 | | |||
180 | #endif // KSQUEEZEDTEXTLABEL_H | 248 | #endif // KSQUEEZEDTEXTLABEL_H |