26#include <tqobjectlist.h> 
   27#include <tqapplication.h> 
   33#include "spinbox2.moc" 
   34#include "spinbox2private.moc" 
   42static const char* mirrorStyles[] = {
 
   46static bool mirrorStyle(
const TQStyle&);
 
   49int SpinBox2::mReverseLayout = -1;
 
   52    : TQFrame(parent, name),
 
   53      mReverseWithLayout(true)
 
   55    mUpdown2Frame = 
new TQFrame(
this);
 
   56    mSpinboxFrame = 
new TQFrame(
this);
 
   57    mUpdown2 = 
new ExtraSpinBox(mUpdown2Frame, 
"updown2");
 
   59    mSpinbox = 
new MainSpinBox(
this, mSpinboxFrame);
 
   63SpinBox2::SpinBox2(
int minValue, 
int maxValue, 
int step, 
int step2, TQWidget* parent, 
const char* name)
 
   64    : TQFrame(parent, name),
 
   65      mReverseWithLayout(true)
 
   67    mUpdown2Frame = 
new TQFrame(
this);
 
   68    mSpinboxFrame = 
new TQFrame(
this);
 
   69    mUpdown2 = 
new ExtraSpinBox(
minValue, 
maxValue, step2, mUpdown2Frame, 
"updown2");
 
   77    if (mReverseLayout < 0)
 
   78        mReverseLayout = TQApplication::reverseLayout() ? 1 : 0;
 
   79    mMinValue      = mSpinbox->minValue();
 
   80    mMaxValue      = mSpinbox->maxValue();
 
   81    mLineStep      = mSpinbox->lineStep();
 
   82    mLineShiftStep = mSpinbox->lineShiftStep();
 
   83    mPageStep      = mUpdown2->lineStep();
 
   84    mPageShiftStep = mUpdown2->lineShiftStep();
 
   85    mSpinbox->setSelectOnStep(
false);    
 
   86    mUpdown2->setSelectOnStep(
false);    
 
   87    setFocusProxy(mSpinbox);
 
   88    mUpdown2->setFocusPolicy(TQWidget::NoFocus);
 
   89    mSpinMirror = 
new SpinMirror(mUpdown2, mUpdown2Frame, 
this);
 
   90    if (!mirrorStyle(style()))
 
   92    connect(mSpinbox, TQ_SIGNAL(
valueChanged(
int)), TQ_SLOT(valueChange()));
 
   95    connect(mUpdown2, TQ_SIGNAL(stepped(
int)), TQ_SLOT(stepPage(
int)));
 
   96    connect(mUpdown2, TQ_SIGNAL(styleUpdated()), TQ_SLOT(updateMirror()));
 
  101    if (
static_cast<int>(ro) != 
static_cast<int>(mSpinbox->isReadOnly()))
 
  103        mSpinbox->setReadOnly(ro);
 
  104        mUpdown2->setReadOnly(ro);
 
  105        mSpinMirror->setReadOnly(ro);
 
  111    if (reverse != mReverseWithLayout)
 
  113        mReverseWithLayout = reverse;
 
  121    TQFrame::setEnabled(enabled);
 
  127    mSpinbox->setWrapping(on);
 
  128    mUpdown2->setWrapping(on);
 
  133    return mUpdown2->upRect();
 
  138    return mUpdown2->downRect();
 
  145        mUpdown2->setLineStep(step);   
 
  147        mSpinbox->setLineStep(step);
 
  156        mUpdown2->setLineStep(line);   
 
  157        mSpinbox->setLineStep(page);
 
  161        mSpinbox->setLineStep(line);
 
  162        mUpdown2->setLineStep(page);
 
  168    mLineShiftStep = line;
 
  169    mPageShiftStep = page;
 
  172        mUpdown2->setLineShiftStep(line);   
 
  173        mSpinbox->setLineShiftStep(page);
 
  177        mSpinbox->setLineShiftStep(line);
 
  178        mUpdown2->setLineShiftStep(page);
 
  184    if (mSpinbox->buttonSymbols() == newSymbols)
 
  186    mSpinbox->setButtonSymbols(newSymbols);
 
  187    mUpdown2->setButtonSymbols(newSymbols);
 
  192    return (val < mMinValue) ? mMinValue : (val > mMaxValue) ? mMaxValue : val;
 
  198    mSpinbox->setMinValue(val);
 
  199    mUpdown2->setMinValue(val);
 
  205    mSpinbox->setMaxValue(val);
 
  206    mUpdown2->setMaxValue(val);
 
  209void SpinBox2::valueChange()
 
  211    int val = mSpinbox->value();
 
  212    bool blocked = mUpdown2->signalsBlocked();
 
  213    mUpdown2->blockSignals(
true);
 
  214    mUpdown2->setValue(val);
 
  215    mUpdown2->blockSignals(blocked);
 
  223void SpinBox2::showEvent(TQShowEvent*)
 
  228TQSize SpinBox2::sizeHint()
 const 
  231    TQSize size = mSpinbox->sizeHint();
 
  232    size.setWidth(size.width() - xSpinbox + wUpdown2 + wGap);
 
  236TQSize SpinBox2::minimumSizeHint()
 const 
  239    TQSize size = mSpinbox->minimumSizeHint();
 
  240    size.setWidth(size.width() - xSpinbox + wUpdown2 + wGap);
 
  244void SpinBox2::styleChange(TQStyle&)
 
  246    if (mirrorStyle(style()))
 
  257void SpinBox2::updateMirror()
 
  259    mSpinMirror->setNormalButtons(TQPixmap::grabWidget(mUpdown2Frame, 0, 0));
 
  265void SpinBox2::arrange()
 
  268    TQRect arrowRect = TQStyle::visualRect(TQRect(0, 0, wUpdown2, height()), 
this);
 
  269    mUpdown2Frame->setGeometry(arrowRect);
 
  270    mUpdown2->setGeometry(-xUpdown2, 0, mUpdown2->width(), height());
 
  271    mSpinboxFrame->setGeometry(TQStyle::visualRect(TQRect(wUpdown2 + wGap, 0, width() - wUpdown2 - wGap, height()), 
this));
 
  272    mSpinbox->setGeometry(-xSpinbox, 0, mSpinboxFrame->width() + xSpinbox, height());
 
  273    mSpinMirror->resize(wUpdown2, mUpdown2->height());
 
  274    mSpinMirror->setGeometry(arrowRect);
 
  276    mSpinMirror->setNormalButtons(TQPixmap::grabWidget(mUpdown2Frame, 0, 0));
 
  283void SpinBox2::getMetrics()
 const 
  285    TQRect rect = mUpdown2->style().querySubControlMetrics(TQStyle::CC_SpinWidget, mUpdown2, TQStyle::SC_SpinWidgetButtonField);
 
  286    if (style().inherits(
"PlastikStyle"))
 
  287        rect.setLeft(rect.left() - 1);    
 
  288    xUpdown2 = mReverseLayout ? 0 : rect.left();
 
  289    wUpdown2 = mUpdown2->width() - rect.left();
 
  290    xSpinbox = mSpinbox->style().querySubControlMetrics(TQStyle::CC_SpinWidget, mSpinbox, TQStyle::SC_SpinWidgetEditField).left();
 
  294    if (style().inherits(
"TQMotifPlusStyle"))
 
  306void SpinBox2::stepPage(
int step)
 
  308    if (abs(step) == mUpdown2->lineStep())
 
  309        mSpinbox->setValue(mUpdown2->value());
 
  313        int oldValue = mSpinbox->value();
 
  321                oldValue -= oldValue % mUpdown2->lineStep();
 
  323                oldValue += (-oldValue) % mUpdown2->lineStep();
 
  325        int adjust = mSpinbox->shiftStepAdjustment(oldValue, step);
 
  327        &&  ((step > 0  &&  oldValue + step >= mSpinbox->maxValue())
 
  328          || (step < 0  &&  oldValue + step <= mSpinbox->
minValue())))
 
  330        mSpinbox->addValue(adjust + step);
 
  332    bool focus = mSpinbox->selectOnStep() && mUpdown2->hasFocus();
 
  334        mSpinbox->selectAll();
 
  337    mSpinMirror->redraw(TQPixmap::grabWidget(mUpdown2Frame, 0, 0));
 
  351int SpinBox2::MainSpinBox::shiftStepAdjustment(
int oldValue, 
int shiftStep)
 
  353    if (owner->reverseButtons())
 
  360            oldValue -= oldValue % lineStep();
 
  362            oldValue += (-oldValue) % lineStep();
 
  379void ExtraSpinBox::paintEvent(TQPaintEvent* e)
 
  381    SpinBox::paintEvent(e);
 
  382    if (mNewStylePending)
 
  384        mNewStylePending = 
false;
 
  394SpinMirror::SpinMirror(
SpinBox* spinbox, TQFrame* spinFrame, TQWidget* parent, 
const char* name)
 
  395    : TQCanvasView(new TQCanvas, parent, name),
 
  397      mSpinFrame(spinFrame),
 
  400    setVScrollBarMode(TQScrollView::AlwaysOff);
 
  401    setHScrollBarMode(TQScrollView::AlwaysOff);
 
  402    setFrameStyle(TQFrame::NoFrame);
 
  406    TQObjectList* spinwidgets = spinbox->queryList(
"TQSpinWidget", 0, 
false, 
true);
 
  407    mSpinWidget = (
SpinBox*)spinwidgets->getFirst();
 
  411void SpinMirror::setNormalButtons(
const TQPixmap& px)
 
  414    redraw(mNormalButtons);
 
  417void SpinMirror::redraw()
 
  419    redraw(TQPixmap::grabWidget(mSpinFrame, 0, 0));
 
  422void SpinMirror::redraw(
const TQPixmap& px)
 
  424    TQCanvas* c = canvas();
 
  425    c->setBackgroundPixmap(px);
 
  430void SpinMirror::resize(
int w, 
int h)
 
  432    canvas()->resize(w, h);
 
  433    TQCanvasView::resize(w, h);
 
  434    resizeContents(w, h);
 
  435    setWorldMatrix(TQWMatrix(-1, 0, 0, 1, w - 1, 0));  
 
  441void SpinMirror::contentsMouseEvent(TQMouseEvent* e)
 
  445    TQPoint pt = contentsToViewport(e->pos());
 
  446    pt.setX(pt.x() + mSpinbox->upRect().left());
 
  447    TQApplication::postEvent(mSpinWidget, 
new TQMouseEvent(e->type(), pt, e->button(), e->state()));
 
  452        case TQEvent::MouseButtonPress:
 
  453        case TQEvent::MouseButtonRelease:
 
  454            TQTimer::singleShot(0, 
this, TQ_SLOT(redraw()));
 
  464void SpinMirror::contentsWheelEvent(TQWheelEvent* e)
 
  468    TQPoint pt = contentsToViewport(e->pos());
 
  469    pt.setX(pt.x() + mSpinbox->upRect().left());
 
  470    TQApplication::postEvent(mSpinWidget, 
new TQWheelEvent(pt, e->delta(), e->state(), e->orientation()));
 
  477bool SpinMirror::event(TQEvent* e)
 
  483            TQApplication::postEvent(mSpinWidget, 
new TQEvent(e->type()));
 
  484            TQTimer::singleShot(0, 
this, TQ_SLOT(redraw()));
 
  486        case TQEvent::FocusIn:
 
  487            mSpinbox->setFocus();
 
  488            TQTimer::singleShot(0, 
this, TQ_SLOT(redraw()));
 
  493    return TQCanvasView::event(e);
 
  505static bool mirrorStyle(
const TQStyle& style)
 
  507    for (
const char** s = mirrorStyles;  *s;  ++s)
 
  508        if (style.inherits(*s))
 
TQRect down2Rect() const
Returns the geometry of the left-hand "down" button.
 
int minValue() const
Returns the minimum value of the spin box.
 
bool reverseButtons() const
Returns whether the spin button pairs will be reversed for a right-to-left language.
 
void valueChanged(int value)
Signal which is emitted whenever the value of the spin box changes.
 
int bound(int val) const
Returns the specified value clamped to the range of the spin box.
 
void setSteps(int line, int page)
Sets the unshifted step increments for the two pairs of spin buttons, i.e.
 
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.
 
void setLineStep(int step)
Sets the unshifted step increment for the right-hand spin buttons, i.e.
 
virtual void setMinValue(int val)
Sets the minimum value of the spin box.
 
TQRect up2Rect() const
Returns the geometry of the left-hand "up" button.
 
virtual void setReadOnly(bool readOnly)
Sets whether the spin box can be changed by the user.
 
virtual void setMaxValue(int val)
Sets the maximum value of the spin box.
 
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...
 
SpinBox2(TQWidget *parent=0, const char *name=0)
Constructor.
 
virtual void setButtonSymbols(TQSpinBox::ButtonSymbols)
Sets the button symbols to use (arrows or plus/minus).
 
virtual void setEnabled(bool enabled)
Sets whether the widget is enabled.
 
void setShiftSteps(int line, int page)
Sets the shifted step increments for the two pairs of spin buttons, i.e.
 
Spin box with accelerated shift key stepping and read-only option.
 
virtual int shiftStepAdjustment(int oldValue, int shiftStep)
Returns the initial adjustment to the value for a shift step up or down.