File indexing completed on 2024-04-14 14:11:47
0001 /* 0002 SPDX-FileCopyrightText: 2002 Jason Harris <kstars@30doradus.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QWidget> 0010 #include <QAction> 0011 0012 class QToolButton; 0013 0014 #define TUB_ALLUNITS 8 0015 0016 /** 0017 * @class TimeUnitBox 0018 * @short Provides a second set of up/down buttons for TimeStepBox. 0019 * A pair of buttons, arranged one above the other, labeled "+"/"-". These buttons 0020 * are to be paired with the TimeSpinBox widget. Their function is to provide 0021 * a way to cycle through the possible time steps using larger intervals than the up/down 0022 * buttons of the TimeSpinBox. For example, say the Spinbox currently shows a timestep of 0023 * "1 sec". Increasing the timestep with the spinbox up-button will change it to 0024 * "2 sec", while using the "+" button of this widget will change it to "1 min". 0025 * 0026 * The idea is that these "outer" buttons always change to the next even unit of time. 0027 * 0028 * @note this widget is not to be used on its own; it is combined with the TimeSpinBox 0029 * widget to form the TimeStepBox composite widget. 0030 * 0031 * @author Jason Harris 0032 * @version 1.0 0033 */ 0034 0035 class QToolButton; 0036 0037 class TimeUnitBox : public QWidget 0038 { 0039 Q_OBJECT 0040 0041 public: 0042 /** Constructor */ 0043 explicit TimeUnitBox(QWidget *parent = nullptr, bool daysonly = false); 0044 0045 /** @return the value of UnitStep for the current spinbox value() */ 0046 int unitValue(); 0047 0048 /** 0049 * @short the same as unitValue, except you can get the UnitStep for any value, not just the current one. 0050 * @return the value of UnitStep for the index value given as an argument. 0051 */ 0052 int getUnitValue(int); 0053 0054 /** 0055 * Set the value which describes which time-unit is displayed in the TimeSpinBox. 0056 * @p value the new value 0057 */ 0058 void setValue(int value) { Value = value; } 0059 /** @return the internal value describing the time-unit of the TimeSpinBox. */ 0060 int value() const { return Value; } 0061 0062 /** Set the minimum value for the internal time-unit value */ 0063 void setMinimum(int minValue) { MinimumValue = minValue; } 0064 /** Set the maximum value for the internal time-unit value */ 0065 void setMaximum(int maxValue) { MaximumValue = maxValue; } 0066 0067 /** @return the minimum value for the internal time-unit value */ 0068 int minValue() const { return MinimumValue; } 0069 /** @return the maximum value for the internal time-unit value */ 0070 int maxValue() const { return MaximumValue; } 0071 0072 bool daysOnly() const { return DaysOnly; } 0073 void setDaysOnly(bool daysonly); 0074 0075 QAction *increaseUnitsAction() const { return IncreaseAction; } 0076 QAction *decreaseUnitsAction() const { return DecreaseAction; } 0077 0078 signals: 0079 void valueChanged(int); 0080 0081 private slots: 0082 /** Increment the internal time-unit value */ 0083 void increase(); 0084 /** Decrement the internal time-unit value */ 0085 void decrease(); 0086 0087 private: 0088 bool DaysOnly { false }; 0089 QToolButton *UpButton { nullptr }; 0090 QToolButton *DownButton { nullptr }; 0091 QAction *IncreaseAction { nullptr }; 0092 QAction *DecreaseAction { nullptr }; 0093 int MinimumValue { 0 }; 0094 int MaximumValue { 0 }; 0095 int Value { 0 }; 0096 int UnitStep[TUB_ALLUNITS]; 0097 };