Mark some Calc slots as inactive in readonly mode
[LibreOffice.git] / vcl / qt5 / QtInstanceSpinButton.cxx
blob22b4ba401c25ac655de0c9965d72f183989d2615
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
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/.
8 */
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)
19 assert(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)
42 SolarMutexGuard g;
43 GetQtInstance().RunInMainThread([&] { (m_pSpinBox->setValue(nValue)); });
46 sal_Int64 QtInstanceSpinButton::get_value() const
48 SolarMutexGuard g;
50 sal_Int64 nValue;
51 GetQtInstance().RunInMainThread([&] { nValue = std::round(m_pSpinBox->value()); });
52 return nValue;
55 void QtInstanceSpinButton::set_range(sal_Int64 nMin, sal_Int64 nMax)
57 SolarMutexGuard g;
58 GetQtInstance().RunInMainThread([&] { (m_pSpinBox->setRange(nMin, nMax)); });
61 void QtInstanceSpinButton::get_range(sal_Int64& rMin, sal_Int64& rMax) const
63 SolarMutexGuard g;
65 GetQtInstance().RunInMainThread([&] {
66 rMin = std::round(m_pSpinBox->minimum());
67 rMax = std::round(m_pSpinBox->maximum());
68 });
71 void QtInstanceSpinButton::set_increments(sal_Int64 nStep, sal_Int64)
73 SolarMutexGuard g;
75 GetQtInstance().RunInMainThread([&] { m_pSpinBox->setSingleStep(nStep); });
78 void QtInstanceSpinButton::get_increments(sal_Int64& rStep, sal_Int64& rPage) const
80 SolarMutexGuard g;
82 GetQtInstance().RunInMainThread([&] {
83 rStep = std::round(m_pSpinBox->singleStep());
84 rPage = rStep;
85 });
88 void QtInstanceSpinButton::set_digits(unsigned int nDigits)
90 SolarMutexGuard g;
92 GetQtInstance().RunInMainThread([&] { m_pSpinBox->setDecimals(nDigits); });
95 unsigned int QtInstanceSpinButton::get_digits() const
97 SolarMutexGuard g;
99 unsigned int nDigits = 0;
100 GetQtInstance().RunInMainThread([&] { nDigits = o3tl::make_unsigned(m_pSpinBox->decimals()); });
101 return nDigits;
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: */