23#include <tqvalidator.h> 
   24#include <tqlineedit.h> 
   27#include "timespinbox.moc" 
   30class TimeSpinBox::TimeValidator : 
public TQValidator
 
   33        TimeValidator(
int minMin, 
int maxMin, TQWidget* parent, 
const char* name = 0)
 
   34            : TQValidator(parent, name),
 
   35                  minMinute(minMin), maxMinute(maxMin), m12Hour(false), mPm(false) { }
 
   36        virtual State validate(TQString&, 
int&) 
const;
 
   37        int  minMinute, maxMinute;
 
   58    : 
SpinBox2(0, 1439, 1, 60, parent, name),
 
   63      mEnteredSetValue(false)
 
   65    mValidator = 
new TimeValidator(0, 1439, 
this, 
"TimeSpinBox validator");
 
   66    mValidator->m12Hour = m12Hour;
 
   73    connect(
this, TQ_SIGNAL(
valueChanged(
int)), TQ_SLOT(slotValueChanged(
int)));
 
   80    : 
SpinBox2(minMinute, maxMinute, 1, 60, parent, name),
 
   81      mMinimumValue(minMinute),
 
   84      mEnteredSetValue(false)
 
   86    mValidator = 
new TimeValidator(minMinute, maxMinute, 
this, 
"TimeSpinBox validator");
 
   91    setAlignment(TQApplication::reverseLayout() ? TQt::AlignLeft : TQt::AlignRight);
 
   96    return i18n(
"Press the Shift key while clicking the spin buttons to adjust the time by a larger step (6 hours / 5 minutes).");
 
  104TQString TimeSpinBox::mapValueToText(
int v)
 
  114    s.sprintf((
wrapping() ? 
"%02d:%02d" : 
"%d:%02d"), v/60, v%60);
 
  124int TimeSpinBox::mapTextToValue(
bool* ok)
 
  127    int colon = 
text.find(
':');
 
  131        TQString hour   = 
text.left(colon).stripWhiteSpace();
 
  132        TQString minute = 
text.mid(colon + 1).stripWhiteSpace();
 
  133        if (!minute.isEmpty())
 
  137            int m = minute.toUInt(&okmin);
 
  140                h = hour.toUInt(&okhour);
 
  141            if (okhour  &&  okmin  &&  m < 60)
 
  145                    if (h == 0  ||  h > 12)
 
  153                if (t >= mMinimumValue  &&  t <= 
maxValue())
 
  162    else if (
text.length() == 4)
 
  166        int mins = 
text.toUInt(&okn);
 
  173                if (h == 0  ||  h > 12)
 
  181            if (h < 24  &&  m < 60  &&  t >= mMinimumValue  &&  t <= 
maxValue())
 
  202    if (valid  &&  mInvalid)
 
  205        if (
value() < mMinimumValue)
 
  210    else if (!valid  &&  !mInvalid)
 
  224    mMinimumValue = minutes;
 
  233    if (!mEnteredSetValue)
 
  235        mEnteredSetValue = 
true;
 
  236        mPm = (minutes >= 720);
 
  248            mEnteredSetValue = 
false;
 
  275    return value() >= mMinimumValue;
 
  278void TimeSpinBox::slotValueChanged(
int value)
 
  280    mPm = mValidator->mPm = (
value >= 720);
 
  283TQSize TimeSpinBox::sizeHint()
 const 
  285    TQSize sz = SpinBox2::sizeHint();
 
  286    TQFontMetrics fm(font());
 
  287    return TQSize(sz.width() + fm.width(
":"), sz.height());
 
  290TQSize TimeSpinBox::minimumSizeHint()
 const 
  292    TQSize sz = SpinBox2::minimumSizeHint();
 
  293    TQFontMetrics fm(font());
 
  294    return TQSize(sz.width() + fm.width(
":"), sz.height());
 
  302TQValidator::State TimeSpinBox::TimeValidator::validate(TQString& text, 
int& )
 const 
  304    TQString cleanText = text.stripWhiteSpace();
 
  305    if (cleanText.isEmpty())
 
  306        return TQValidator::Intermediate;
 
  307    TQValidator::State state = TQValidator::Acceptable;
 
  312    int colon = cleanText.find(
':');
 
  315        TQString minute = cleanText.mid(colon + 1);
 
  316        if (minute.isEmpty())
 
  317            state = TQValidator::Intermediate;
 
  318        else if ((mn = minute.toUInt(&ok)) >= 60  ||  !ok)
 
  319            return TQValidator::Invalid;
 
  321        hour = cleanText.left(colon);
 
  323    else if (maxMinute >= 1440)
 
  327        state = TQValidator::Intermediate;
 
  331        if (cleanText.length() > 4)
 
  332            return TQValidator::Invalid;
 
  333        if (cleanText.length() < 4)
 
  334            state = TQValidator::Intermediate;
 
  335        hour = cleanText.left(2);
 
  336        TQString minute = cleanText.mid(2);
 
  337        if (!minute.isEmpty()
 
  338        &&  ((mn = minute.toUInt(&ok)) >= 60  ||  !ok))
 
  339            return TQValidator::Invalid;
 
  344        hr = hour.toUInt(&ok);
 
  347            if (hr == 0  ||  hr > 12)
 
  354        if (!ok  ||  hr > maxMinute/60)
 
  355            return TQValidator::Invalid;
 
  357    if (state == TQValidator::Acceptable)
 
  359        int t = hr * 60 + mn;
 
  360        if (t < minMinute  ||  t > maxMinute)
 
  361            return TQValidator::Invalid;
 
Spin box with a pair of spin buttons on either side.
 
bool wrapping() const
Returns whether it is possible to step the value from the highest value to the lowest value and vice ...
 
void setAlignment(int a)
Set the text alignment of the widget.
 
TQString text() const
Returns the spin box's text, including any prefix() and suffix().
 
virtual void setValidator(const TQValidator *v)
Sets the validator to v.
 
void valueChanged(int value)
Signal which is emitted whenever the value of the spin box changes.
 
void setSelectOnStep(bool sel)
Sets whether the spin box value text should be selected when its value is stepped.
 
void setReverseWithLayout(bool reverse)
Sets whether the spin button pairs should be reversed for a right-to-left language.
 
int maxValue() const
Returns the maximum value of the spin box.
 
virtual void setSpecialValueText(const TQString &text)
Sets the special-value text which, if non-null, is displayed instead of a numeric value when the curr...
 
virtual void setMinValue(int val)
Sets the minimum value of the spin box.
 
virtual void stepDown()
Decrements the current value by subtracting the unshifted step increment for the right-hand spin butt...
 
virtual TQString cleanText() const
Returns the spin box's text with no prefix(), suffix() or leading or trailing whitespace.
 
virtual void setWrapping(bool on)
Sets whether it is possible to step the value from the highest value to the lowest value and vice ver...
 
int value() const
Returns the current value of the spin box.
 
virtual void setValue(int val)
Sets the current value to val.
 
virtual void stepUp()
Increments the current value by adding the unshifted step increment for the right-hand spin buttons.
 
void setShiftSteps(int line, int page)
Sets the shifted step increments for the two pairs of spin buttons, i.e.
 
virtual void stepUp()
Increments the spin box value.
 
static TQString shiftWhatsThis()
Returns a text describing use of the shift key as an accelerator for the spin buttons,...
 
virtual void setMinValue(int minutes)
Sets the maximum value which can be held in the spin box.
 
virtual void setValue(int minutes)
Sets the value of the spin box.
 
TQTime time() const
Returns the current value held in the spin box.
 
bool isValid() const
Returns true if the spin box holds a valid value.
 
virtual void stepDown()
Decrements the spin box value.
 
void setValid(bool)
Sets the spin box as holding a valid or invalid value.
 
TimeSpinBox(bool use24hour, TQWidget *parent=0, const char *name=0)
Constructor for a wrapping time spin box which can be used to enter a time of day.