Q3TimeEdit Class Reference

#include <q3datetimeedit.h>

Inheritance diagram for Q3TimeEdit:

Inheritance graph
[legend]
Collaboration diagram for Q3TimeEdit:

Collaboration graph
[legend]
List of all members.

Detailed Description

The Q3TimeEdit class provides a time editor.

Q3TimeEdit allows the user to edit times by using the keyboard or the arrow keys to increase/decrease time values. The arrow keys can be used to move from section to section within the Q3TimeEdit box. The user can automatically be moved to the next section once they complete a section using setAutoAdvance(). Times appear in hour, minute, second order. It is recommended that the Q3TimeEdit is initialised with a time, e.g.

    QTime timeNow = QTime::currentTime();
    Q3TimeEdit *timeEdit = new Q3TimeEdit(timeNow, this);
    timeEdit->setRange(timeNow, timeNow.addSecs(60 * 60));
Here we've created a Q3TimeEdit widget set to the current time. We've also set the minimum value to the current time and the maximum time to one hour from now.

The maximum and minimum values for a time value in the time editor default to the maximum and minimum values for a QTime. You can change this by calling setMinValue(), setMaxValue() or setRange().

Terminology: A QTimeWidget consists of three sections, one each for the hour, minute and second. You can change the separator character using setSeparator(), by default the separator is read from the system's settings.

datetimewidgets.png Date Time Widgets

See also:
QTime Q3DateEdit Q3DateTimeEdit

Definition at line 136 of file q3datetimeedit.h.

Public Types

enum  Display

Public Slots

virtual void setTime (const QTime &time)

Signals

void valueChanged (const QTime &time)

Public Member Functions

 Q3TimeEdit (QWidget *parent=0, const char *name=0)
 Q3TimeEdit (const QTime &time, QWidget *parent=0, const char *name=0)
 ~Q3TimeEdit ()
QSize sizeHint () const
QSize minimumSizeHint () const
QTime time () const
virtual void setAutoAdvance (bool advance)
bool autoAdvance () const
virtual void setMinValue (const QTime &d)
QTime minValue () const
virtual void setMaxValue (const QTime &d)
QTime maxValue () const
virtual void setRange (const QTime &min, const QTime &max)
QString separator () const
virtual void setSeparator (const QString &s)
uint display () const
void setDisplay (uint disp)
void removeFirstNumber (int sec)

Protected Slots

void updateButtons ()

Protected Member Functions

bool event (QEvent *e)
void timerEvent (QTimerEvent *e)
void resizeEvent (QResizeEvent *)
void stepUp ()
void stepDown ()
QString sectionFormattedText (int sec)
void addNumber (int sec, int num)
void removeLastNumber (int sec)
bool setFocusSection (int s)
virtual bool outOfRange (int h, int m, int s) const
virtual void setHour (int h)
virtual void setMinute (int m)
virtual void setSecond (int s)

Private Member Functions

void init ()
QString sectionText (int sec)

Private Attributes

Q3TimeEditPrivated


Member Enumeration Documentation

enum Q3TimeEdit::Display

This enum defines the sections that comprise a time

Hours The hours section Minutes The minutes section Seconds The seconds section AMPM The AM/PM section

The values can be or'ed together to show any combination.

Definition at line 147 of file q3datetimeedit.h.

00147                  {
00148         Hours        = 0x01,
00149         Minutes        = 0x02,
00150         Seconds        = 0x04,
00151         /*Reserved = 0x08,*/
00152         AMPM        = 0x10
00153     };


Constructor & Destructor Documentation

Q3TimeEdit::Q3TimeEdit ( QWidget parent = 0,
const char *  name = 0 
)

Constructs an empty time edit with parent parent and called name.

Definition at line 1816 of file q3datetimeedit.cpp.

References init().

01817     : Q3DateTimeEditBase(parent, name)
01818 {
01819     init();
01820 }

Here is the call graph for this function:

Q3TimeEdit::Q3TimeEdit ( const QTime time,
QWidget parent = 0,
const char *  name = 0 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Constructs a time edit with the initial time value, time, parent parent and called name.

Definition at line 1829 of file q3datetimeedit.cpp.

References init(), setTime(), and time().

01830     : Q3DateTimeEditBase(parent, name)
01831 {
01832     init();
01833     setTime(time);
01834 }

Here is the call graph for this function:

Q3TimeEdit::~Q3TimeEdit (  ) 

Destroys the object and frees any allocated resources.

Definition at line 1879 of file q3datetimeedit.cpp.

References cleanup(), d, and refcount.

01880 {
01881     delete d;
01882     if (!--refcount)
01883         cleanup();
01884 }

Here is the call graph for this function:


Member Function Documentation

QSize Q3TimeEdit::sizeHint (  )  const [virtual]

Reimplemented from QWidget.

Definition at line 2536 of file q3datetimeedit.cpp.

References AMPM, Q3TimeEditPrivate::controls, d, Q3TimeEditPrivate::display, Q3TimeEditPrivate::ed, QWidget::ensurePolished(), QWidget::font(), QString::fromLatin1(), QApplication::globalStrut(), h, lAM, QFontMetrics::lineSpacing(), QStyle::pixelMetric(), QStyle::PM_DefaultFrameWidth, qMax(), Q3DateTimeEditor::separator(), QWidget::style(), Q3SpinWidget::upRect(), w, QRect::width(), and QFontMetrics::width().

Referenced by minimumSizeHint(), Q3DateTimeEdit::resizeEvent(), and Q3DateTimeEdit::sizeHint().

02537 {
02538     ensurePolished();
02539     QFontMetrics fm(font());
02540     int fw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, this);
02541     int h = fm.lineSpacing() + 2;
02542     int w = 2 + fm.width('9') * 6 + fm.width(d->ed->separator()) * 2 +
02543         d->controls->upRect().width() + fw * 4;
02544     if (d->display & AMPM) {
02545         if (lAM)
02546             w += fm.width(*lAM) + 4;
02547         else
02548             w += fm.width(QString::fromLatin1("AM")) + 4;
02549     }
02550 
02551     return QSize(w, qMax(h + fw * 2,20)).expandedTo(QApplication::globalStrut());
02552 }

Here is the call graph for this function:

QSize Q3TimeEdit::minimumSizeHint (  )  const [virtual]

Reimplemented from QWidget.

Definition at line 2556 of file q3datetimeedit.cpp.

References sizeHint().

Referenced by Q3DateTimeEdit::minimumSizeHint().

02557 {
02558     return sizeHint();
02559 }

Here is the call graph for this function:

void Q3TimeEdit::setTime ( const QTime time  )  [virtual, slot]

Definition at line 1973 of file q3datetimeedit.cpp.

References Q3TimeEditPrivate::changed, d, Q3TimeEditPrivate::ed, emit, Q3TimeEditPrivate::h, QTime::hour(), QTime::isValid(), Q3TimeEditPrivate::m, maxValue(), QTime::minute(), minValue(), QWidget::rect(), QWidget::repaint(), Q3TimeEditPrivate::s, QTime::second(), time(), and valueChanged().

Referenced by Q3TimeEdit(), and Q3DateTimeEdit::setDateTime().

01974 {
01975     if (!time.isValid()) {
01976         d->h = 0;
01977         d->m = 0;
01978         d->s = 0;
01979     } else {
01980         if (time > maxValue() || time < minValue())
01981             return;
01982         d->h = time.hour();
01983         d->m = time.minute();
01984         d->s = time.second();
01985         emit valueChanged(time);
01986     }
01987     d->changed = false;
01988     d->ed->repaint(d->ed->rect());
01989 }

QTime Q3TimeEdit::time (  )  const

Definition at line 1991 of file q3datetimeedit.cpp.

References d, Q3TimeEditPrivate::h, QTime::isValid(), Q3TimeEditPrivate::m, and Q3TimeEditPrivate::s.

Referenced by addNumber(), Q3DateTimeEdit::dateTime(), event(), Q3TimeEdit(), setFocusSection(), setTime(), stepDown(), stepUp(), and updateButtons().

01992 {
01993     if (QTime::isValid(d->h, d->m, d->s))
01994         return QTime(d->h, d->m, d->s);
01995     return QTime();
01996 }

Here is the call graph for this function:

void Q3TimeEdit::setAutoAdvance ( bool  advance  )  [virtual]

Definition at line 2008 of file q3datetimeedit.cpp.

References Q3TimeEditPrivate::adv, and d.

Referenced by Q3DateTimeEdit::setAutoAdvance().

02009 {
02010     d->adv = advance;
02011 }

bool Q3TimeEdit::autoAdvance (  )  const

Definition at line 2013 of file q3datetimeedit.cpp.

References Q3TimeEditPrivate::adv, and d.

02014 {
02015     return d->adv;
02016 }

virtual void Q3TimeEdit::setMinValue ( const QTime d  )  [inline, virtual]

Definition at line 170 of file q3datetimeedit.h.

References d.

00170 { setRange(d, maxValue()); }

QTime Q3TimeEdit::minValue (  )  const

Definition at line 1897 of file q3datetimeedit.cpp.

References d, and Q3TimeEditPrivate::min.

Referenced by outOfRange(), setTime(), and updateButtons().

01898 {
01899     return d->min;
01900 }

virtual void Q3TimeEdit::setMaxValue ( const QTime d  )  [inline, virtual]

Definition at line 172 of file q3datetimeedit.h.

References d.

00172 { setRange(minValue(), d); }

QTime Q3TimeEdit::maxValue (  )  const

Definition at line 1913 of file q3datetimeedit.cpp.

References d, and Q3TimeEditPrivate::max.

Referenced by outOfRange(), setTime(), and updateButtons().

01914 {
01915     return d->max;
01916 }

void Q3TimeEdit::setRange ( const QTime min,
const QTime max 
) [virtual]

Sets the valid input range for the editor to be from min to max inclusive. If min is invalid no minimum time is set. Similarly, if max is invalid no maximum time is set.

Definition at line 1925 of file q3datetimeedit.cpp.

References d, QTime::isValid(), Q3TimeEditPrivate::max, and Q3TimeEditPrivate::min.

01926 {
01927     if (min.isValid())
01928         d->min = min;
01929     if (max.isValid())
01930         d->max = max;
01931 }

Here is the call graph for this function:

QString Q3TimeEdit::separator (  )  const

Returns the editor's separator.

Definition at line 2032 of file q3datetimeedit.cpp.

References d, Q3TimeEditPrivate::ed, and Q3DateTimeEditor::separator().

Referenced by sectionFormattedText(), and setFocusSection().

02033 {
02034     return d->ed->separator();
02035 }

Here is the call graph for this function:

void Q3TimeEdit::setSeparator ( const QString s  )  [virtual]

Sets the separator to s. Note that currently only the first character of s is used.

Definition at line 2023 of file q3datetimeedit.cpp.

References d, Q3TimeEditPrivate::ed, s, and Q3DateTimeEditor::setSeparator().

02024 {
02025     d->ed->setSeparator(s);
02026 }

Here is the call graph for this function:

uint Q3TimeEdit::display (  )  const

Definition at line 1960 of file q3datetimeedit.cpp.

References d, and Q3TimeEditPrivate::display.

01961 {
01962     return d->display;
01963 }

void Q3TimeEdit::setDisplay ( uint  disp  ) 

Definition at line 1940 of file q3datetimeedit.cpp.

References AMPM, Q3DateTimeEditor::appendSection(), Q3DateTimeEditor::clearSections(), d, Q3TimeEditPrivate::display, Q3TimeEditPrivate::ed, Hours, Minutes, Seconds, Q3DateTimeEditor::setFocusSection(), and QWidget::update().

01941 {
01942     if (d->display == display)
01943         return;
01944 
01945     d->ed->clearSections();
01946     d->display = display;
01947     if (d->display & Hours)
01948         d->ed->appendSection(QNumberSection(0,0, true, 0));
01949     if (d->display & Minutes)
01950         d->ed->appendSection(QNumberSection(0,0, true, 1));
01951     if (d->display & Seconds)
01952         d->ed->appendSection(QNumberSection(0,0, true, 2));
01953     if (d->display & AMPM)
01954         d->ed->appendSection(QNumberSection(0,0, false, 3));
01955 
01956     d->ed->setFocusSection(0);
01957     d->ed->update();
01958 }

Here is the call graph for this function:

void Q3TimeEdit::removeFirstNumber ( int  sec  ) 

Definition at line 2460 of file q3datetimeedit.cpp.

References d, Q3TimeEditPrivate::ed, Q3TimeEditPrivate::h, QString::length(), Q3TimeEditPrivate::m, Q3DateTimeEditor::mapSection(), QString::mid(), QString::number(), QWidget::rect(), QWidget::repaint(), Q3TimeEditPrivate::s, and QString::toInt().

02461 {
02462     if (sec == -1)
02463         return;
02464     sec = d->ed->mapSection(sec);
02465     QString txt;
02466     switch(sec) {
02467     case 0:
02468         txt = QString::number(d->h);
02469         break;
02470     case 1:
02471         txt = QString::number(d->m);
02472         break;
02473     case 2:
02474         txt = QString::number(d->s);
02475         break;
02476     }
02477     txt = txt.mid(1, txt.length()) + "0";
02478     switch(sec) {
02479     case 0:
02480         d->h = txt.toInt();
02481         break;
02482     case 1:
02483         d->m = txt.toInt();
02484         break;
02485     case 2:
02486         d->s = txt.toInt();
02487         break;
02488     }
02489     d->ed->repaint(d->ed->rect());
02490 }

Here is the call graph for this function:

void Q3TimeEdit::valueChanged ( const QTime time  )  [signal]

This signal is emitted whenever the editor's value changes. The time parameter is the new value.

Referenced by addNumber(), event(), setFocusSection(), setTime(), stepDown(), and stepUp().

bool Q3TimeEdit::event ( QEvent e  )  [protected, virtual]

Reimplemented from QWidget.

Definition at line 2049 of file q3datetimeedit.cpp.

References Q3TimeEditPrivate::changed, d, Q3TimeEditPrivate::ed, emit, QWidget::event(), QEvent::FocusOut, QEvent::LocaleChange, localTimeSep(), readLocaleSettings(), Q3DateTimeEditor::setSeparator(), time(), QEvent::type(), Q3TimeEditPrivate::typing, and valueChanged().

02050 {
02051     if (e->type() == QEvent::FocusOut) {
02052         d->typing = false;
02053         if (d->changed) {
02054             emit valueChanged(time());
02055             d->changed = false;
02056         }
02057     } else if (e->type() == QEvent::LocaleChange) {
02058         readLocaleSettings();
02059         d->ed->setSeparator(localTimeSep());
02060     }
02061     return Q3DateTimeEditBase::event(e);
02062 }

Here is the call graph for this function:

void Q3TimeEdit::timerEvent ( QTimerEvent e  )  [protected, virtual]

Reimplemented from QObject.

Definition at line 2068 of file q3datetimeedit.cpp.

References d, and Q3TimeEditPrivate::overwrite.

02069 {
02070     d->overwrite = true;
02071 }

void Q3TimeEdit::resizeEvent ( QResizeEvent  )  [protected, virtual]

Reimplemented from QWidget.

Definition at line 2529 of file q3datetimeedit.cpp.

References Q3TimeEditPrivate::controls, d, QWidget::height(), QWidget::resize(), and QWidget::width().

02530 {
02531     d->controls->resize(width(), height());
02532 }

Here is the call graph for this function:

void Q3TimeEdit::stepUp (  )  [protected, virtual]

Implements Q3DateTimeEditBase.

Definition at line 2078 of file q3datetimeedit.cpp.

References Q3TimeEditPrivate::changed, d, Q3TimeEditPrivate::ed, emit, Q3DateTimeEditor::focusSection(), Q3TimeEditPrivate::h, QTime::hour(), Q3TimeEditPrivate::m, Q3DateTimeEditor::mapSection(), Q3TimeEditPrivate::min, QTime::minute(), outOfRange(), qWarning(), QWidget::rect(), QWidget::repaint(), Q3TimeEditPrivate::s, QTime::second(), setHour(), setMinute(), setSecond(), time(), and valueChanged().

Referenced by init().

02079 {
02080     int sec = d->ed->mapSection(d->ed->focusSection());
02081     bool accepted = true;
02082     switch(sec) {
02083     case 0:
02084         if (!outOfRange(d->h+1, d->m, d->s))
02085             setHour(d->h+1);
02086         else
02087             setHour(d->min.hour());
02088         break;
02089     case 1:
02090         if (!outOfRange(d->h, d->m+1, d->s))
02091             setMinute(d->m+1);
02092         else
02093             setMinute(d->min.minute());
02094         break;
02095     case 2:
02096         if (!outOfRange(d->h, d->m, d->s+1))
02097             setSecond(d->s+1);
02098         else
02099             setSecond(d->min.second());
02100         break;
02101     case 3:
02102         if (d->h < 12)
02103             setHour(d->h+12);
02104         else
02105             setHour(d->h-12);
02106         break;
02107     default:
02108         accepted = false;
02109         qWarning("Q3TimeEdit::stepUp: Focus section out of range!");
02110         break;
02111     }
02112     if (accepted) {
02113         d->changed = false;
02114         emit valueChanged(time());
02115     }
02116     d->ed->repaint(d->ed->rect());
02117 }

Here is the call graph for this function:

void Q3TimeEdit::stepDown (  )  [protected, virtual]

Implements Q3DateTimeEditBase.

Definition at line 2124 of file q3datetimeedit.cpp.

References Q3TimeEditPrivate::changed, d, Q3TimeEditPrivate::ed, emit, Q3DateTimeEditor::focusSection(), Q3TimeEditPrivate::h, QTime::hour(), Q3TimeEditPrivate::m, Q3DateTimeEditor::mapSection(), Q3TimeEditPrivate::max, QTime::minute(), outOfRange(), qWarning(), QWidget::rect(), QWidget::repaint(), Q3TimeEditPrivate::s, QTime::second(), setHour(), setMinute(), setSecond(), time(), and valueChanged().

Referenced by init().

02125 {
02126     int sec = d->ed->mapSection(d->ed->focusSection());
02127 
02128     bool accepted = true;
02129     switch(sec) {
02130     case 0:
02131         if (!outOfRange(d->h-1, d->m, d->s))
02132             setHour(d->h-1);
02133         else
02134             setHour(d->max.hour());
02135         break;
02136     case 1:
02137         if (!outOfRange(d->h, d->m-1, d->s))
02138             setMinute(d->m-1);
02139         else
02140             setMinute(d->max.minute());
02141         break;
02142     case 2:
02143         if (!outOfRange(d->h, d->m, d->s-1))
02144             setSecond(d->s-1);
02145         else
02146             setSecond(d->max.second());
02147         break;
02148     case 3:
02149         if (d->h > 11)
02150             setHour(d->h-12);
02151         else
02152             setHour(d->h+12);
02153         break;
02154     default:
02155         accepted = false;
02156         qWarning("Q3TimeEdit::stepDown: Focus section out of range!");
02157         break;
02158     }
02159     if (accepted) {
02160         d->changed = false;
02161         emit valueChanged(time());
02162     }
02163     d->ed->repaint(d->ed->rect());
02164 }

Here is the call graph for this function:

QString Q3TimeEdit::sectionFormattedText ( int  sec  )  [protected, virtual]

Returns the formatted number for section sec. This will correspond to either the hour, minute or second section, depending on sec.

Implements Q3DateTimeEditBase.

Definition at line 2173 of file q3datetimeedit.cpp.

References d, Q3TimeEditPrivate::ed, Q3DateTimeEditor::focusSection(), QString::length(), QDATETIMEEDIT_HIDDEN_CHAR, QString::rightJustified(), sectionText(), separator(), Q3DateTimeEditor::setSectionSelection(), and Q3TimeEditPrivate::typing.

02174 {
02175     QString txt;
02176     txt = sectionText(sec);
02177     txt = txt.rightJustified(2, QDATETIMEEDIT_HIDDEN_CHAR);
02178     int offset = sec*2+sec*separator().length() + txt.length();
02179     if (d->typing && sec == d->ed->focusSection())
02180         d->ed->setSectionSelection(sec, offset - txt.length(), offset);
02181     else
02182         d->ed->setSectionSelection(sec, offset - txt.length(), offset);
02183 
02184     return txt;
02185 }

Here is the call graph for this function:

void Q3TimeEdit::addNumber ( int  sec,
int  num 
) [protected, virtual]

Implements Q3DateTimeEditBase.

Definition at line 2327 of file q3datetimeedit.cpp.

References Q3TimeEditPrivate::adv, AMPM, Q3TimeEditPrivate::changed, d, Q3TimeEditPrivate::display, Q3TimeEditPrivate::ed, emit, Q3DateTimeEditor::focusSection(), Q3TimeEditPrivate::h, QObject::killTimer(), QString::length(), Q3TimeEditPrivate::m, Q3DateTimeEditor::mapSection(), QString::number(), outOfRange(), Q3TimeEditPrivate::overwrite, qApp, QWidget::rect(), QWidget::repaint(), Q3TimeEditPrivate::s, setFocusSection(), QObject::startTimer(), time(), Q3TimeEditPrivate::timerId, QString::toInt(), Q3TimeEditPrivate::typing, and valueChanged().

02328 {
02329     if (sec == -1)
02330         return;
02331     sec = d->ed->mapSection(sec);
02332     if (d->timerId)
02333         killTimer(d->timerId);
02334     d->timerId = 0;
02335     bool overwrite = false;
02336     bool accepted = false;
02337     d->typing = true;
02338     QString txt;
02339 
02340     switch(sec) {
02341     case 0:
02342         txt = (d->display & AMPM && d->h > 12) ?
02343             QString::number(d->h - 12) : QString::number(d->h);
02344 
02345         if (d->overwrite || txt.length() == 2) {
02346             if (d->display & AMPM && num == 0)
02347                 break; // Don't process 0 in 12 hour clock mode
02348             if (d->display & AMPM && d->h > 11)
02349                 num += 12;
02350             if (!outOfRange(num, d->m, d->s)) {
02351                 accepted = true;
02352                 d->h = num;
02353             }
02354         } else {
02355             txt += QString::number(num);
02356             int temp = txt.toInt();
02357 
02358             if (d->display & AMPM) {
02359                 if (temp == 12) {
02360                     if (d->h < 12) {
02361                         temp = 0;
02362                     }
02363                     accepted = true;
02364                 } else if (outOfRange(temp + 12, d->m, d->s)) {
02365                     txt = QString::number(d->h);
02366                 } else {
02367                     if (d->h > 11) {
02368                         temp += 12;
02369                     }
02370                     accepted = true;
02371                 }
02372             } else if (!(d->display & AMPM) && outOfRange(temp, d->m, d->s)) {
02373                 txt = QString::number(d->h);
02374             } else {
02375                 accepted = true;
02376             }
02377 
02378             if (accepted)
02379                 d->h = temp;
02380 
02381             if (d->adv && txt.length() == 2) {
02382                 setFocusSection(d->ed->focusSection()+1);
02383                 overwrite = true;
02384             }
02385         }
02386         break;
02387 
02388     case 1:
02389         txt = QString::number(d->m);
02390         if (d->overwrite || txt.length() == 2) {
02391             if (!outOfRange(d->h, num, d->s)) {
02392                 accepted = true;
02393                 d->m = num;
02394             }
02395         } else {
02396             txt += QString::number(num);
02397             int temp = txt.toInt();
02398             if (temp > 59)
02399                 temp = num;
02400             if (outOfRange(d->h, temp, d->s))
02401                 txt = QString::number(d->m);
02402             else {
02403                 accepted = true;
02404                 d->m = temp;
02405             }
02406             if (d->adv && txt.length() == 2) {
02407                 setFocusSection(d->ed->focusSection()+1);
02408                 overwrite = true;
02409             }
02410         }
02411         break;
02412 
02413     case 2:
02414         txt = QString::number(d->s);
02415         if (d->overwrite || txt.length() == 2) {
02416             if (!outOfRange(d->h, d->m, num)) {
02417                 accepted = true;
02418                 d->s = num;
02419             }
02420         } else {
02421             txt += QString::number(num);
02422             int temp = txt.toInt();
02423             if (temp > 59)
02424                 temp = num;
02425             if (outOfRange(d->h, d->m, temp))
02426                 txt = QString::number(d->s);
02427             else {
02428                 accepted = true;
02429                 d->s = temp;
02430             }
02431             if (d->adv && txt.length() == 2) {
02432                 setFocusSection(d->ed->focusSection()+1);
02433                 overwrite = true;
02434             }
02435         }
02436         break;
02437 
02438     case 3:
02439         break;
02440 
02441     default:
02442         break;
02443     }
02444     d->changed = !accepted;
02445     if (accepted)
02446         emit valueChanged(time());
02447     d->overwrite = overwrite;
02448     d->timerId = startTimer(qApp->doubleClickInterval()*4);
02449     d->ed->repaint(d->ed->rect());
02450 }

Here is the call graph for this function:

void Q3TimeEdit::removeLastNumber ( int  sec  )  [protected, virtual]

Implements Q3DateTimeEditBase.

Definition at line 2495 of file q3datetimeedit.cpp.

References d, Q3TimeEditPrivate::ed, Q3TimeEditPrivate::h, QString::length(), Q3TimeEditPrivate::m, Q3DateTimeEditor::mapSection(), QString::mid(), QString::number(), QWidget::rect(), QWidget::repaint(), Q3TimeEditPrivate::s, and QString::toInt().

02496 {
02497     if (sec == -1)
02498         return;
02499     sec = d->ed->mapSection(sec);
02500     QString txt;
02501     switch(sec) {
02502     case 0:
02503         txt = QString::number(d->h);
02504         break;
02505     case 1:
02506         txt = QString::number(d->m);
02507         break;
02508     case 2:
02509         txt = QString::number(d->s);
02510         break;
02511     }
02512     txt = txt.mid(0, txt.length()-1);
02513     switch(sec) {
02514     case 0:
02515         d->h = txt.toInt();
02516         break;
02517     case 1:
02518         d->m = txt.toInt();
02519         break;
02520     case 2:
02521         d->s = txt.toInt();
02522         break;
02523     }
02524     d->ed->repaint(d->ed->rect());
02525 }

Here is the call graph for this function:

bool Q3TimeEdit::setFocusSection ( int  sec  )  [protected, virtual]

Implements Q3DateTimeEditBase.

Definition at line 2192 of file q3datetimeedit.cpp.

References Q3TimeEditPrivate::changed, d, Q3TimeEditPrivate::ed, emit, Q3DateTimeEditor::focusSection(), QObject::killTimer(), QString::length(), Q3TimeEditPrivate::overwrite, QDATETIMEEDIT_HIDDEN_CHAR, QString::rightJustified(), sectionText(), separator(), Q3DateTimeEditor::setFocusSection(), Q3DateTimeEditor::setSectionSelection(), time(), Q3TimeEditPrivate::timerId, Q3TimeEditPrivate::typing, and valueChanged().

Referenced by addNumber().

02193 {
02194     if (sec != d->ed->focusSection()) {
02195         if (d->timerId)
02196             killTimer(d->timerId);
02197         d->timerId = 0;
02198         d->overwrite = true;
02199         d->typing = false;
02200         QString txt = sectionText(sec);
02201         txt = txt.rightJustified(2, QDATETIMEEDIT_HIDDEN_CHAR);
02202         int offset = sec*2+sec*separator().length() + txt.length();
02203         d->ed->setSectionSelection(sec, offset - txt.length(), offset);
02204         if (d->changed) {
02205             emit valueChanged(time());
02206             d->changed = false;
02207         }
02208     }
02209     return d->ed->setFocusSection(sec);
02210 }

Here is the call graph for this function:

bool Q3TimeEdit::outOfRange ( int  h,
int  m,
int  s 
) const [protected, virtual]

Definition at line 2310 of file q3datetimeedit.cpp.

References QTime::isValid(), maxValue(), and minValue().

Referenced by addNumber(), stepDown(), and stepUp().

02311 {
02312     if (QTime::isValid(h, m, s)) {
02313         QTime currentTime(h, m, s);
02314         if (currentTime > maxValue() ||
02315              currentTime < minValue())
02316             return true;
02317         else
02318             return false;
02319     }
02320     return true;
02321 }

Here is the call graph for this function:

void Q3TimeEdit::setHour ( int  h  )  [protected, virtual]

Sets the hour to h, which must be a valid hour, i.e. in the range 0..24.

Definition at line 2218 of file q3datetimeedit.cpp.

References d, and Q3TimeEditPrivate::h.

Referenced by stepDown(), and stepUp().

02219 {
02220     if (h < 0)
02221         h = 0;
02222     if (h > 23)
02223         h = 23;
02224     d->h = h;
02225 }

void Q3TimeEdit::setMinute ( int  m  )  [protected, virtual]

Sets the minute to m, which must be a valid minute, i.e. in the range 0..59.

Definition at line 2233 of file q3datetimeedit.cpp.

References d, and Q3TimeEditPrivate::m.

Referenced by stepDown(), and stepUp().

02234 {
02235     if (m < 0)
02236         m = 0;
02237     if (m > 59)
02238         m = 59;
02239     d->m = m;
02240 }

void Q3TimeEdit::setSecond ( int  s  )  [protected, virtual]

Sets the second to s, which must be a valid second, i.e. in the range 0..59.

Definition at line 2248 of file q3datetimeedit.cpp.

References d, and Q3TimeEditPrivate::s.

Referenced by stepDown(), and stepUp().

02249 {
02250     if (s < 0)
02251         s = 0;
02252     if (s > 59)
02253         s = 59;
02254     d->s = s;
02255 }

void Q3TimeEdit::updateButtons (  )  [protected, slot]

Definition at line 2567 of file q3datetimeedit.cpp.

References Q3TimeEditPrivate::controls, d, QWidget::isEnabled(), maxValue(), minValue(), Q3SpinWidget::setDownEnabled(), Q3SpinWidget::setUpEnabled(), and time().

02568 {
02569     if (!isEnabled())
02570         return;
02571 
02572     bool upEnabled = time() < maxValue();
02573     bool downEnabled = time() > minValue();
02574 
02575     d->controls->setUpEnabled(upEnabled);
02576     d->controls->setDownEnabled(downEnabled);
02577 }

void Q3TimeEdit::init (  )  [private]

Definition at line 1839 of file q3datetimeedit.cpp.

References Q3TimeEditPrivate::adv, AMPM, Q3DateTimeEditor::appendSection(), Q3TimeEditPrivate::changed, QObject::connect(), Q3TimeEditPrivate::controls, d, Q3TimeEditPrivate::display, Q3TimeEditPrivate::ed, QSizePolicy::Fixed, Q3TimeEditPrivate::h, Hours, lAMPM, localTimeSep(), Q3TimeEditPrivate::m, Q3TimeEditPrivate::max, Q3TimeEditPrivate::min, QSizePolicy::Minimum, Minutes, Q3TimeEditPrivate::overwrite, refcount, Q3TimeEditPrivate::s, Seconds, Q3SpinWidget::setEditWidget(), QWidget::setFocusProxy(), Q3DateTimeEditor::setSeparator(), QWidget::setSizePolicy(), SIGNAL, SLOT, stepDown(), stepUp(), Q3TimeEditPrivate::timerId, and Q3TimeEditPrivate::typing.

Referenced by Q3TimeEdit().

01840 {
01841     d = new Q3TimeEditPrivate();
01842     d->controls = new QDateTimeSpinWidget(this, 0);
01843     d->ed = new Q3DateTimeEditor(this, d->controls, "time edit base");
01844     d->controls->setEditWidget(d->ed);
01845     setFocusProxy(d->ed);
01846     connect(d->controls, SIGNAL(stepUpPressed()), SLOT(stepUp()));
01847     connect(d->controls, SIGNAL(stepDownPressed()), SLOT(stepDown()));
01848 
01849     d->ed->appendSection(QNumberSection(0,0, true, 0));
01850     d->ed->appendSection(QNumberSection(0,0, true, 1));
01851     d->ed->appendSection(QNumberSection(0,0, true, 2));
01852     d->ed->setSeparator(localTimeSep());
01853 
01854     d->h = 0;
01855     d->m = 0;
01856     d->s = 0;
01857     d->display = Hours | Minutes | Seconds;
01858     if (lAMPM) {
01859         d->display |= AMPM;
01860         d->ed->appendSection(QNumberSection(0,0, false, 3));
01861     }
01862     d->adv = false;
01863     d->overwrite = true;
01864     d->timerId = 0;
01865     d->typing = false;
01866     d->min = QTime(0, 0, 0);
01867     d->max = QTime(23, 59, 59);
01868     d->changed = false;
01869 
01870     setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
01871 
01872     refcount++;
01873 }

Here is the call graph for this function:

QString Q3TimeEdit::sectionText ( int  sec  )  [private]

Definition at line 2264 of file q3datetimeedit.cpp.

References AMPM, d, Q3TimeEditPrivate::display, Q3TimeEditPrivate::ed, QString::fromLatin1(), Q3TimeEditPrivate::h, lAM, lPM, Q3TimeEditPrivate::m, Q3DateTimeEditor::mapSection(), QString::number(), and Q3TimeEditPrivate::s.

Referenced by sectionFormattedText(), and setFocusSection().

02265 {
02266     sec = d->ed->mapSection(sec);
02267 
02268     QString txt;
02269     switch(sec) {
02270     case 0:
02271         if (!(d->display & AMPM) || (d->h < 13 && d->h)) {    // I wished the day stared at 0:00 for everybody
02272             txt = QString::number(d->h);
02273         } else {
02274             if (d->h)
02275                 txt = QString::number(d->h - 12);
02276             else
02277                 txt = "12";
02278         }
02279         break;
02280     case 1:
02281         txt = QString::number(d->m);
02282         break;
02283     case 2:
02284         txt = QString::number(d->s);
02285         break;
02286     case 3:
02287         if (d->h < 12) {
02288             if (lAM)
02289                 txt = *lAM;
02290             else
02291                 txt = QString::fromLatin1("AM");
02292         } else {
02293             if (lPM)
02294                 txt = *lPM;
02295             else
02296                 txt = QString::fromLatin1("PM");
02297         }
02298         break;
02299     default:
02300         break;
02301     }
02302     return txt;
02303 }

Here is the call graph for this function:


Member Data Documentation

Q3TimeEditPrivate* Q3TimeEdit::d [private]

Definition at line 211 of file q3datetimeedit.h.

Referenced by addNumber(), autoAdvance(), display(), event(), init(), maxValue(), minValue(), removeFirstNumber(), removeLastNumber(), resizeEvent(), sectionFormattedText(), sectionText(), separator(), setAutoAdvance(), setDisplay(), setFocusSection(), setHour(), setMinute(), setRange(), setSecond(), setSeparator(), setTime(), sizeHint(), stepDown(), stepUp(), time(), timerEvent(), updateButtons(), and ~Q3TimeEdit().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 16:34:53 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1