#include <rwidgetutils.h>
A label to show text adjusted to widget size
Definition at line 218 of file rwidgetutils.cpp.
◆ RAdjustableLabel()
| KDcrawIface::RAdjustableLabel::RAdjustableLabel |
( |
QWidget *const | parent = 0 | ) |
|
|
explicit |
Definition at line 231 of file rwidgetutils.cpp.
232 : QLabel(parent),
234{
235 setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
236}
◆ ~RAdjustableLabel()
| KDcrawIface::RAdjustableLabel::~RAdjustableLabel |
( |
| ) |
|
|
override |
◆ adjustedText()
| QString KDcrawIface::RAdjustableLabel::adjustedText |
( |
| ) |
const |
◆ adjustTextToLabel()
| void KDcrawIface::RAdjustableLabel::adjustTextToLabel |
( |
| ) |
|
|
private |
Definition at line 301 of file rwidgetutils.cpp.
302{
303 QFontMetrics fm(fontMetrics());
305 int lblW =
size().width();
306 bool adjusted = false;
307
308 Q_FOREACH(
const QString& line,
d->ajdText.split(QLatin1Char(
'\n')))
309 {
310 int lineW = fm.horizontalAdvance(line);
311 if (lineW > lblW)
312 {
313 adjusted = true;
314 adjustedLines << fm.elidedText(line,
d->emode, lblW);
315 }
316 else
317 {
318 adjustedLines << line;
319 }
320 }
321
322 if (adjusted)
323 {
324 QLabel::setText(adjustedLines.join(QStringLiteral("\n")));
325 setToolTip(
d->ajdText);
326 }
327 else
328 {
329 QLabel::setText(
d->ajdText);
330 setToolTip(QString());
331 }
332}
int size(const Forest< T > &forest)
References d.
◆ clear()
| void KDcrawIface::RAdjustableLabel::clear |
( |
| ) |
|
|
inlineprivate |
◆ minimumSizeHint()
| QSize KDcrawIface::RAdjustableLabel::minimumSizeHint |
( |
| ) |
const |
|
override |
Definition at line 248 of file rwidgetutils.cpp.
249{
250 QSize sh = QLabel::minimumSizeHint();
251 sh.setWidth(-1);
252 return sh;
253}
◆ Private()
| KDcrawIface::RAdjustableLabel::Private |
( |
| ) |
|
|
inline |
◆ resizeEvent()
| void KDcrawIface::RAdjustableLabel::resizeEvent |
( |
QResizeEvent * | | ) |
|
|
overrideprivate |
◆ setAdjustedText
| void KDcrawIface::RAdjustableLabel::setAdjustedText |
( |
const QString & | text = QString() | ) |
|
|
slot |
◆ setAlignment()
| void KDcrawIface::RAdjustableLabel::setAlignment |
( |
Qt::Alignment | align | ) |
|
Definition at line 288 of file rwidgetutils.cpp.
289{
290 QString
tmp(
d->ajdText);
291 QLabel::setAlignment(alignment);
293}
References d.
◆ setElideMode()
| void KDcrawIface::RAdjustableLabel::setElideMode |
( |
Qt::TextElideMode | mode | ) |
|
◆ setText()
| void KDcrawIface::RAdjustableLabel::setText |
( |
const QString & | | ) |
|
|
inlineprivate |
◆ sizeHint()
| QSize KDcrawIface::RAdjustableLabel::sizeHint |
( |
| ) |
const |
|
override |
Definition at line 255 of file rwidgetutils.cpp.
256{
257 QFontMetrics fm(fontMetrics());
258 QRect geom = geometry();
259 QPoint
p(geom.width() / 2 + geom.left(), geom.height() / 2 + geom.top());
260 QScreen *s = qApp->screenAt(
p);
261 int maxW;
262 if (s) {
263 maxW = s->availableGeometry().width() * 3 / 4;
264 }
265 else {
266 maxW = 1024;
267 }
268 int currentW = fm.horizontalAdvance(
d->ajdText);
269
270 return (QSize(currentW > maxW ? maxW : currentW, QLabel::
sizeHint().height()));
271}
QSize sizeHint() const override
References d, and p.
◆ text()
| QString KDcrawIface::RAdjustableLabel::text |
( |
| ) |
const |
|
inlineprivate |
◆ ajdText
| QString KDcrawIface::RAdjustableLabel::ajdText |
| Private* const KDcrawIface::RAdjustableLabel::d |
|
private |
◆ emode
| Qt::TextElideMode KDcrawIface::RAdjustableLabel::emode |
The documentation for this class was generated from the following files: