Public Slots | Public Member Functions | Properties | Friends

QxtProgressLabel Class Reference
[QxtGui]

A label showing progress related time values. More...

#include <qxtprogresslabel.h>

Collaboration diagram for QxtProgressLabel:
Collaboration graph
[legend]

List of all members.

Public Slots

void setValue (int value)
void refresh ()
void restart ()
virtual void timerEvent (QTimerEvent *event)

Public Member Functions

 QxtProgressLabel (QWidget *parent=0, Qt::WindowFlags flags=0)
 QxtProgressLabel (const QString &text, QWidget *parent=0, Qt::WindowFlags flags=0)
virtual ~QxtProgressLabel ()
QString contentFormat () const
void setContentFormat (const QString &format)
QString timeFormat () const
void setTimeFormat (const QString &format)
int updateInterval () const
void setUpdateInterval (int msecs)

Properties

QString contentFormat
 This property holds the content format of the progress label.
QString timeFormat
 This property holds the time format of the progress label.
int updateInterval
 This property holds the update interval of the progress label.

Friends

class QxtProgressLabelPrivate

Detailed Description

A label showing progress related time values.

QxtProgressLabel is a label widget able to show elapsed and remaining time of a progress. Usage is as simple as connecting signal QProgressBar::valueChanged() to slot QxtProgressLabel::setValue().

Example usage:

    QProgressBar* bar = new QProgressBar(this);
    QxtProgressLabel* label = new QxtProgressLabel(this);
    connect(bar, SIGNAL(valueChanged(int)), label, SLOT(setValue(int)));
qxtprogresslabel.png

QxtProgressLabel in action.

Definition at line 34 of file qxtprogresslabel.h.


Constructor & Destructor Documentation

QxtProgressLabel::QxtProgressLabel ( QWidget *  parent = 0,
Qt::WindowFlags  flags = 0 
) [explicit]

Constructs a new QxtProgressLabel with parent and flags.

Definition at line 72 of file qxtprogresslabel.cpp.

References QXT_INIT_PRIVATE, and refresh().

        : QLabel(parent, flags)
{
    QXT_INIT_PRIVATE(QxtProgressLabel);
    refresh();
}
QxtProgressLabel::QxtProgressLabel ( const QString &  text,
QWidget *  parent = 0,
Qt::WindowFlags  flags = 0 
) [explicit]

Constructs a new QxtProgressLabel with text, parent and flags.

Definition at line 82 of file qxtprogresslabel.cpp.

References QXT_INIT_PRIVATE, and refresh().

        : QLabel(text, parent, flags)
{
    QXT_INIT_PRIVATE(QxtProgressLabel);
    refresh();
}
QxtProgressLabel::~QxtProgressLabel (  ) [virtual]

Destructs the progress label.

Definition at line 92 of file qxtprogresslabel.cpp.

{}

Member Function Documentation

QString QxtProgressLabel::contentFormat (  ) const
void QxtProgressLabel::refresh (  ) [slot]

Refreshes the content.

Definition at line 213 of file qxtprogresslabel.cpp.

Referenced by QxtProgressLabel(), restart(), setContentFormat(), setTimeFormat(), setValue(), and timerEvent().

{
    // elapsed
    qreal elapsed = 0;
    if (qxt_d().start.isValid())
        elapsed = qxt_d().start.elapsed() / 1000.0;
    QTime etime(0, 0);
    etime = etime.addSecs(static_cast<int>(elapsed));

    // percentage
    qreal percent = 0;
    if (qxt_d().cachedMax != 0)
        percent = (qxt_d().cachedVal - qxt_d().cachedMin) / static_cast<qreal>(qxt_d().cachedMax);
    qreal total = 0;
    if (percent != 0)
        total = elapsed / percent;

    // remaining
    QTime rtime(0, 0);
    rtime = rtime.addSecs(static_cast<int>(total - elapsed));

    // format
    QString tformat = qxt_d().tformat;
    if (tformat.isEmpty())
        tformat = tr("mm:ss");
    QString cformat = qxt_d().cformat;
    if (cformat.isEmpty())
        cformat = tr("ETA: %r");

    QString result = QString(cformat).replace("%e", etime.toString(tformat));
    result = result.replace("%r", rtime.toString(tformat));
    setText(result);
}
void QxtProgressLabel::restart (  ) [slot]

Restarts the calculation of elapsed and remaining times.

Definition at line 201 of file qxtprogresslabel.cpp.

References refresh().

Referenced by setValue().

{
    qxt_d().cachedMin = 0;
    qxt_d().cachedMax = 0;
    qxt_d().cachedVal = 0;
    qxt_d().start.restart();
    refresh();
}
void QxtProgressLabel::setContentFormat ( const QString &  format )

Definition at line 116 of file qxtprogresslabel.cpp.

References refresh().

{
    if (qxt_d().cformat != format)
    {
        qxt_d().cformat = format;
        refresh();
    }
}
void QxtProgressLabel::setTimeFormat ( const QString &  format )

Definition at line 139 of file qxtprogresslabel.cpp.

References refresh().

{
    if (qxt_d().tformat != format)
    {
        qxt_d().tformat = format;
        refresh();
    }
}
void QxtProgressLabel::setUpdateInterval ( int  msecs )

Definition at line 161 of file qxtprogresslabel.cpp.

{
    qxt_d().interval = msecs;
    if (msecs < 0)
    {
        if (qxt_d().timer.isActive())
            qxt_d().timer.stop();
    }
    else
    {
        if (!qxt_d().timer.isActive())
            qxt_d().timer.start(msecs, this);
    }
}
void QxtProgressLabel::setValue ( int  value ) [slot]

Sets the current value to value.

Note:
Calling this slot by hand has no effect. Connect this slot to QProgressBar::valueChange().

Definition at line 182 of file qxtprogresslabel.cpp.

References refresh(), and restart().

{
    QProgressBar* bar = qobject_cast<QProgressBar*>(sender());
    if (bar)
    {
        if (!qxt_d().start.isValid())
            restart();

        qxt_d().cachedMin = bar->minimum();
        qxt_d().cachedMax = bar->maximum();
        qxt_d().cachedVal = value;

        refresh();
    }
}
QString QxtProgressLabel::timeFormat (  ) const
void QxtProgressLabel::timerEvent ( QTimerEvent *  event ) [virtual, slot]

Definition at line 250 of file qxtprogresslabel.cpp.

References refresh().

{
    Q_UNUSED(event);
    refresh();
}
int QxtProgressLabel::updateInterval (  ) const

Friends And Related Function Documentation

friend class QxtProgressLabelPrivate [friend]

Definition at line 37 of file qxtprogresslabel.h.


Property Documentation

QString QxtProgressLabel::contentFormat [read, write]

This property holds the content format of the progress label.

The content of the label is formatted according to this property. The default value is an empty string which defaults to "ETA: %r".

The following variables may be used in the format string:

VariableOutput
%eelapsed time
%rremaining time
See also:
timeFormat

Definition at line 37 of file qxtprogresslabel.h.

QString QxtProgressLabel::timeFormat [read, write]

This property holds the time format of the progress label.

Time values are formatted according to this property. The default value is an empty string which defaults to "mm:ss".

See also:
contentFormat, QTime::toString()

Definition at line 39 of file qxtprogresslabel.h.

int QxtProgressLabel::updateInterval [read, write]

This property holds the update interval of the progress label.

The content of the progress label is updated according to this interval. A negative interval makes the content to update only during value changes. The default value is -1.

Definition at line 40 of file qxtprogresslabel.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines