13#include <QStylePainter>
14#include <QStyleOptionSlider>
19#include <QDoubleSpinBox>
23#include <klocalizedstring.h>
28 ,d(new KoSliderComboPrivate())
35 d->container->setAttribute(Qt::WA_WindowPropagation);
36 QStyleOptionComboBox opt;
40 d->slider =
new QSlider(Qt::Horizontal);
41 d->slider->setMinimum(0);
42 d->slider->setMaximum(256);
43 d->slider->setPageStep(10);
44 d->slider->setValue(0);
46 d->firstShowOfSlider =
false;
48 QHBoxLayout *layout =
new QHBoxLayout(
d->container);
49 layout->setContentsMargins(2, 2, 2, 2);
50 layout->setSpacing(2);
51 layout->addWidget(
d->slider);
52 d->container->resize(200, 30);
54 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
57 setEditText(QLocale().toString(0.0,
d->decimals));
78 const QFontMetrics &fm = fontMetrics();
79 sh.setWidth(5 * fm.horizontalAdvance(QLatin1Char(
'8')));
80 sh.setHeight(qMax(fm.lineSpacing(), 14) + 2);
83 QStyleOptionComboBox opt;
85 opt.subControls = QStyle::SC_All;
87 sh = style()->sizeFromContents(QStyle::CT_ComboBox, &opt, sh,
this);
92void KoSliderCombo::KoSliderComboPrivate::showPopup()
94 if(firstShowOfSlider) {
96 firstShowOfSlider =
false;
99 QStyleOptionSlider opt;
100 opt.initFrom(slider);
102 opt.sliderPosition = opt.sliderValue = slider->value();
103 int hdlPos = thePublic->style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle).center().x();
105 QStyleOptionComboBox optThis;
106 optThis.initFrom(thePublic);
107 optThis.subControls = QStyle::SC_All;
108 optThis.editable =
true;
109 int arrowPos = thePublic->style()->subControlRect(QStyle::CC_ComboBox, &optThis, QStyle::SC_ComboBoxArrow).center().x();
111 QSize popSize = container->size();
112 QRect popupRect(thePublic->mapToGlobal(QPoint(arrowPos - hdlPos - slider->x(), thePublic->size().height())), popSize);
115 QRect screenRect = thePublic->screen()->availableGeometry();
117 if (popupRect.right() > screenRect.right())
118 popupRect.translate(screenRect.right() - popupRect.right(), 0);
119 if (popupRect.left() < screenRect.left())
120 popupRect.translate(screenRect.left() - popupRect.left(), 0);
121 if (popupRect.bottom() > screenRect.bottom())
122 popupRect.translate(0, -(thePublic->height() + container->height()));
124 container->setGeometry(popupRect);
130void KoSliderCombo::KoSliderComboPrivate::hidePopup()
144 case QEvent::EnabledChange:
148 case QEvent::PaletteChange:
149 d->container->setPalette(
palette());
154 QComboBox::changeEvent(e);
159 QStylePainter gc(
this);
161 gc.setPen(
palette().color(QPalette::Text));
163 QStyleOptionComboBox opt;
165 opt.subControls = QStyle::SC_All;
167 gc.drawComplexControl(QStyle::CC_ComboBox, opt);
168 gc.drawControl(QStyle::CE_ComboBoxLabel, opt);
173 QStyleOptionComboBox opt;
175 opt.subControls = QStyle::SC_All;
177 QStyle::SubControl sc = style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, e->pos(),
179 if (sc == QStyle::SC_ComboBoxArrow && !
d->container->isVisible())
184 QComboBox::mousePressEvent(e);
191 else QComboBox::keyPressEvent(e);
200void KoSliderCombo::KoSliderComboPrivate::lineEditFinished()
202 qreal
value = QLocale().toDouble(thePublic->currentText());
203 slider->blockSignals(
true);
204 slider->setValue(
int((
value - minimum) * 256 / (maximum - minimum) + 0.5));
205 slider->blockSignals(
false);
206 Q_EMIT thePublic->valueChanged(
value,
true);
209void KoSliderCombo::KoSliderComboPrivate::sliderValueChanged(
int slidervalue)
211 thePublic->setEditText(QLocale().
toString(minimum + (maximum - minimum)*slidervalue/256, decimals));
213 qreal
value = QLocale().toDouble(thePublic->currentText());
214 Q_EMIT thePublic->valueChanged(
value,
false);
217void KoSliderCombo::KoSliderComboPrivate::sliderReleased()
219 qreal
value = QLocale().toDouble(thePublic->currentText());
220 Q_EMIT thePublic->valueChanged(
value,
true);
240 return QLocale().toDouble(currentText());
246 if (dec == 0) lineEdit()->setValidator(
new QIntValidator(
this));
247 else lineEdit()->setValidator(
new QDoubleValidator(
this));
266 setEditText(QLocale().toString(
value,
d->decimals));
267 d->slider->blockSignals(
true);
268 d->slider->setValue(
int((
value -
d->minimum) * 256 / (
d->maximum -
d->minimum) + 0.5));
269 d->slider->blockSignals(
false);
274#include <moc_KoSliderCombo.cpp>
float value(const T *src, size_t ch)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void setDecimals(int number)
void setMinimum(qreal min)
void mousePressEvent(QMouseEvent *e) override
reimplemented from QComboBox
void setValue(qreal value)
void wheelEvent(QWheelEvent *e) override
reimplemented from QComboBox
void hideEvent(QHideEvent *) override
reimplemented from QComboBox
QSize sizeHint() const override
reimplemented from QComboBox
KoSliderComboPrivate *const d
void changeEvent(QEvent *e) override
reimplemented from QComboBox
void setMaximum(qreal max)
~KoSliderCombo() override
void valueChanged(qreal value, bool final)
KoSliderCombo(QWidget *parent=0)
QSize minimumSizeHint() const override
reimplemented from QComboBox
void sliderValueChanged(int value)
void paintEvent(QPaintEvent *) override
reimplemented from QComboBox
void keyPressEvent(QKeyEvent *e) override
reimplemented from QComboBox
QString toString(const QString &value)
rgba palette[MAX_PALETTE]