spinbox2.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <qglobal.h>
00026 #if QT_VERSION >= 300
00027
00028 #include <qstyle.h>
00029
00030 #include "spinbox2.moc"
00031
00032
00033 SpinBox2::SpinBox2(QWidget* parent, const char* name)
00034 : QFrame(parent, name)
00035 {
00036 updown2Frame = new QFrame(this);
00037 spinboxFrame = new QFrame(this);
00038 updown2 = new SB2_SpinWidget(updown2Frame, "updown2");
00039 spinbox = new SB2_SpinBox(this, spinboxFrame);
00040 initSpinBox2();
00041 }
00042
00043
00044 SpinBox2::SpinBox2(int minValue, int maxValue, int step, int step2, QWidget* parent, const char* name)
00045 : QFrame(parent, name)
00046 {
00047 updown2Frame = new QFrame(this);
00048 spinboxFrame = new QFrame(this);
00049 updown2 = new SB2_SpinWidget(minValue, maxValue, step2, updown2Frame, "updown2");
00050 spinbox = new SB2_SpinBox(minValue, maxValue, step, this, spinboxFrame);
00051 spinbox->setSteps(step, step2);
00052 initSpinBox2();
00053 }
00054
00055 void SpinBox2::initSpinBox2()
00056 {
00057 selectOnStep = false;
00058 setFocusProxy(spinbox);
00059 connect(spinbox, SIGNAL(valueChanged(int)), SLOT(valueChange()));
00060 connect(spinbox, SIGNAL(valueChanged(int)), SIGNAL(valueChanged(int)));
00061 connect(spinbox, SIGNAL(valueChanged(const QString&)), SIGNAL(valueChanged(const QString&)));
00062 connect(updown2, SIGNAL(stepped(int)), SLOT(stepped2(int)));
00063 }
00064
00065 void SpinBox2::setButtonSymbols(QSpinBox::ButtonSymbols newSymbols)
00066 {
00067 if (spinbox->buttonSymbols() == newSymbols)
00068 return;
00069 spinbox->setButtonSymbols(newSymbols);
00070 updown2->setButtonSymbols(newSymbols);
00071 }
00072
00073 void SpinBox2::addVal(int change)
00074 {
00075 int newval = spinbox->value() + change;
00076 if (newval > spinbox->maxValue())
00077 {
00078 if (spinbox->wrapping())
00079 {
00080 int range = spinbox->maxValue() - spinbox->minValue() + 1;
00081 newval = spinbox->minValue() + (newval - spinbox->maxValue() - 1) % range;
00082 }
00083 else
00084 newval = spinbox->maxValue();
00085 }
00086 else if (newval < spinbox->minValue())
00087 {
00088 if (spinbox->wrapping())
00089 {
00090 int range = spinbox->maxValue() - spinbox->minValue() + 1;
00091 newval = spinbox->maxValue() - (spinbox->minValue() - 1 - newval) % range;
00092 }
00093 else
00094 newval = spinbox->minValue();
00095 }
00096 spinbox->setValue(newval);
00097 }
00098
00099 void SpinBox2::valueChange()
00100 {
00101 bool blocked = updown2->signalsBlocked();
00102 updown2->blockSignals(true);
00103 updown2->setValue(spinbox->value());
00104 updown2->blockSignals(blocked);
00105 }
00106
00107 void SpinBox2::stepped2(int direction)
00108 {
00109 bool focus = selectOnStep && updown2->hasFocus();
00110 if (focus)
00111 spinbox->setFocus();
00112 int step = spinbox->pageStep();
00113 addVal(direction >= 0 ? step : -step);
00114 if (focus)
00115 updown2->setFocus();
00116 }
00117
00118
00119
00120
00121 void SpinBox2::showEvent(QShowEvent*)
00122 {
00123 arrange();
00124 }
00125
00126 QSize SpinBox2::sizeHint() const
00127 {
00128 getMetrics();
00129 QSize size = spinbox->sizeHint();
00130 size.setWidth(size.width() - xSpinbox + wUpdown2 + wGap);
00131 return size;
00132 }
00133
00134 QSize SpinBox2::minimumSizeHint() const
00135 {
00136 getMetrics();
00137 QSize size = spinbox->minimumSizeHint();
00138 size.setWidth(size.width() - xSpinbox + wUpdown2 + wGap);
00139 return size;
00140 }
00141
00142 void SpinBox2::arrange()
00143 {
00144 getMetrics();
00145 updown2Frame->setGeometry(QStyle::visualRect(QRect(0, 0, wUpdown2, height()), this));
00146 updown2->setGeometry(-xUpdown2, 0, updown2->width(), height());
00147 spinboxFrame->setGeometry(QStyle::visualRect(QRect(wUpdown2 + wGap, 0, width() - wUpdown2 - wGap, height()), this));
00148 spinbox->setGeometry(-xSpinbox, 0, spinboxFrame->width() + xSpinbox, height());
00149 }
00150
00151 void SpinBox2::getMetrics() const
00152 {
00153 QRect rect = updown2->style().querySubControlMetrics(QStyle::CC_SpinWidget, updown2, QStyle::SC_SpinWidgetButtonField);
00154 xUpdown2 = rect.left();
00155 wUpdown2 = updown2->width() - xUpdown2;
00156 xSpinbox = spinbox->style().querySubControlMetrics(QStyle::CC_SpinWidget, spinbox, QStyle::SC_SpinWidgetEditField).left();
00157 wGap = 0;
00158
00159
00160 if (style().isA("QMotifPlusStyle"))
00161 {
00162 xSpinbox = 0;
00163 wGap = 2;
00164 }
00165 }
00166
00167
00168 void SpinBox2::SB2_SpinBox::valueChange()
00169 {
00170 bool focus = !spinBox2->selectOnStep && hasFocus();
00171 if (focus)
00172 clearFocus();
00173 QSpinBox::valueChange();
00174 if (focus)
00175 setFocus();
00176 }
00177
00178 void SB2_SpinWidget::valueChange()
00179 {
00180 bool focus = hasFocus();
00181 if (focus)
00182 clearFocus();
00183 QSpinBox::valueChange();
00184 if (focus)
00185 setFocus();
00186 }
00187
00188 #endif // QT_VERSION >= 300
This file is part of the documentation for kdelibs Version 3.1.4.