Krita Source Code Documentation
Loading...
Searching...
No Matches
KDcrawIface::RAdjustableLabel Class Reference

#include <rwidgetutils.h>

+ Inheritance diagram for KDcrawIface::RAdjustableLabel:

Public Slots

void setAdjustedText (const QString &text=QString())
 

Public Member Functions

QString adjustedText () const
 
QSize minimumSizeHint () const override
 
 Private ()
 
 RAdjustableLabel (QWidget *const parent=0)
 
void setAlignment (Qt::Alignment align)
 
void setElideMode (Qt::TextElideMode mode)
 
QSize sizeHint () const override
 
 ~RAdjustableLabel () override
 

Public Attributes

QString ajdText
 
Qt::TextElideMode emode
 

Private Member Functions

void adjustTextToLabel ()
 
void clear ()
 
void resizeEvent (QResizeEvent *) override
 
void setText (const QString &)
 
QString text () const
 
- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Detailed Description

A label to show text adjusted to widget size

Definition at line 218 of file rwidgetutils.cpp.

Constructor & Destructor Documentation

◆ RAdjustableLabel()

KDcrawIface::RAdjustableLabel::RAdjustableLabel ( QWidget *const parent = 0)
explicit

Definition at line 231 of file rwidgetutils.cpp.

232 : QLabel(parent),
233 d(new Private)
234{
235 setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
236}

◆ ~RAdjustableLabel()

KDcrawIface::RAdjustableLabel::~RAdjustableLabel ( )
override

Definition at line 238 of file rwidgetutils.cpp.

239{
240 delete d;
241}

References d.

Member Function Documentation

◆ adjustedText()

QString KDcrawIface::RAdjustableLabel::adjustedText ( ) const

Definition at line 283 of file rwidgetutils.cpp.

284{
285 return d->ajdText;
286}

References d.

◆ adjustTextToLabel()

void KDcrawIface::RAdjustableLabel::adjustTextToLabel ( )
private

Definition at line 301 of file rwidgetutils.cpp.

302{
303 QFontMetrics fm(fontMetrics());
304 QStringList adjustedLines;
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)
Definition KisForest.h:1232

References d.

◆ clear()

void KDcrawIface::RAdjustableLabel::clear ( )
inlineprivate

Definition at line 154 of file rwidgetutils.h.

154{}; // Use setdjustedText(QString()) instead.

◆ 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

Definition at line 222 of file rwidgetutils.cpp.

223 {
224 emode = Qt::ElideMiddle;
225 }

◆ resizeEvent()

void KDcrawIface::RAdjustableLabel::resizeEvent ( QResizeEvent * )
overrideprivate

Definition at line 243 of file rwidgetutils.cpp.

References adjustTextToLabel().

◆ setAdjustedText

void KDcrawIface::RAdjustableLabel::setAdjustedText ( const QString & text = QString())
slot

Definition at line 273 of file rwidgetutils.cpp.

274{
275 d->ajdText = text;
276
277 if (d->ajdText.isNull())
278 QLabel::clear();
279
281}

References adjustTextToLabel(), d, and text().

◆ 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);
292 d->ajdText = tmp;
293}

References d.

◆ setElideMode()

void KDcrawIface::RAdjustableLabel::setElideMode ( Qt::TextElideMode mode)

Definition at line 295 of file rwidgetutils.cpp.

296{
297 d->emode = mode;
299}

References adjustTextToLabel(), and d.

◆ setText()

void KDcrawIface::RAdjustableLabel::setText ( const QString & )
inlineprivate

Definition at line 153 of file rwidgetutils.h.

153{}; // Use setAdjustedText(text) instead.

◆ 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}
const Params2D p
QSize sizeHint() const override

References d, and p.

◆ text()

QString KDcrawIface::RAdjustableLabel::text ( ) const
inlineprivate

Definition at line 152 of file rwidgetutils.h.

152{ return QString(); }; // Use adjustedText() instead.

Member Data Documentation

◆ ajdText

QString KDcrawIface::RAdjustableLabel::ajdText

Definition at line 227 of file rwidgetutils.cpp.

◆ d

Private* const KDcrawIface::RAdjustableLabel::d
private

Definition at line 159 of file rwidgetutils.h.

◆ emode

Qt::TextElideMode KDcrawIface::RAdjustableLabel::emode

Definition at line 228 of file rwidgetutils.cpp.


The documentation for this class was generated from the following files: