1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <QtInstanceSpinButton.hxx>
11 #include <QtInstanceSpinButton.moc>
13 #include <vcl/qt/QtUtils.hxx>
15 QtInstanceSpinButton::QtInstanceSpinButton(QtDoubleSpinBox
* pSpinBox
)
16 : QtInstanceEntry(pSpinBox
->lineEdit())
17 , m_pSpinBox(pSpinBox
)
21 connect(m_pSpinBox
, QOverload
<double>::of(&QtDoubleSpinBox::valueChanged
), this,
22 &QtInstanceSpinButton::handleValueChanged
);
24 // While QtInstanceEntry generally takes care of handling signals
25 // for the spinbox's QLineEdit, this doesn't work when the value
26 // is changed as a result of setting a new spinbox value (e.g.
27 // by using the spinbox buttons), as the QLineEdit signals are blocked
28 // then, see QAbstractSpinBoxPrivate::updateEdit in qtbase:
29 // https://code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/widgets/qabstractspinbox.cpp?id=ced47a590aeb85953a16eaf362887f14c2815c45#n1790
30 // Therefore, connect the QDoubleSpinBox::textChanged signal
31 // to the slot that calls signal_changed() instead to ensure
32 // it gets called nonetheless, and disconnect from the other signal.
33 disconnect(pSpinBox
->lineEdit(), &QLineEdit::textChanged
, this, nullptr);
34 connect(m_pSpinBox
, &QDoubleSpinBox::textChanged
, this,
35 &QtInstanceSpinButton::handleTextChanged
);
38 QWidget
* QtInstanceSpinButton::getQWidget() const { return m_pSpinBox
; }
40 void QtInstanceSpinButton::set_value(sal_Int64 nValue
)
43 GetQtInstance().RunInMainThread([&] { (m_pSpinBox
->setValue(nValue
)); });
46 sal_Int64
QtInstanceSpinButton::get_value() const
51 GetQtInstance().RunInMainThread([&] { nValue
= std::round(m_pSpinBox
->value()); });
55 void QtInstanceSpinButton::set_range(sal_Int64 nMin
, sal_Int64 nMax
)
58 GetQtInstance().RunInMainThread([&] { (m_pSpinBox
->setRange(nMin
, nMax
)); });
61 void QtInstanceSpinButton::get_range(sal_Int64
& rMin
, sal_Int64
& rMax
) const
65 GetQtInstance().RunInMainThread([&] {
66 rMin
= std::round(m_pSpinBox
->minimum());
67 rMax
= std::round(m_pSpinBox
->maximum());
71 void QtInstanceSpinButton::set_increments(sal_Int64 nStep
, sal_Int64
)
75 GetQtInstance().RunInMainThread([&] { m_pSpinBox
->setSingleStep(nStep
); });
78 void QtInstanceSpinButton::get_increments(sal_Int64
& rStep
, sal_Int64
& rPage
) const
82 GetQtInstance().RunInMainThread([&] {
83 rStep
= std::round(m_pSpinBox
->singleStep());
88 void QtInstanceSpinButton::set_digits(unsigned int nDigits
)
92 GetQtInstance().RunInMainThread([&] { m_pSpinBox
->setDecimals(nDigits
); });
95 unsigned int QtInstanceSpinButton::get_digits() const
99 unsigned int nDigits
= 0;
100 GetQtInstance().RunInMainThread([&] { nDigits
= o3tl::make_unsigned(m_pSpinBox
->decimals()); });
104 void QtInstanceSpinButton::handleValueChanged()
106 SolarMutexGuard aGuard
;
107 signal_value_changed();
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */