File indexing completed on 2025-02-23 04:09:08
0001 /* 0002 * SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef __SLIDER_AND_SPIN_BOX_SYNC_H 0008 #define __SLIDER_AND_SPIN_BOX_SYNC_H 0009 0010 #include <QObject> 0011 #include <functional> 0012 0013 class QSpinBox; 0014 class KisDoubleSliderSpinBox; 0015 0016 /** 0017 * Syncs a slider measured in percentage with a spin box 0018 * measuring real value getting value from \p parentValueOp. 0019 * 0020 * E.g. 0021 * 0022 * parentValueOp() --- total system memory in MiB 0023 * slider --- percentage of the memory we can use 0024 * spinBox --- amount o fmemory we can use in MiB 0025 * slotParentValueChanged() --- should be called every time 0026 * total memory changes 0027 */ 0028 class SliderAndSpinBoxSync : public QObject 0029 { 0030 Q_OBJECT 0031 using IntFunction = std::function<int()>; 0032 0033 public: 0034 SliderAndSpinBoxSync(KisDoubleSliderSpinBox *slider, 0035 QSpinBox *spinBox, 0036 IntFunction parentValueOp); 0037 0038 ~SliderAndSpinBoxSync() override; 0039 0040 public Q_SLOTS: 0041 void slotParentValueChanged(); 0042 0043 private Q_SLOTS: 0044 void sliderChanged(qreal value); 0045 void spinBoxChanged(int value); 0046 0047 private: 0048 KisDoubleSliderSpinBox *m_slider; 0049 QSpinBox *m_spinBox; 0050 IntFunction m_parentValueOp; 0051 0052 bool m_blockUpdates; 0053 }; 0054 0055 #endif /* __SLIDER_AND_SPIN_BOX_SYNC_H */