File indexing completed on 2024-07-07 07:09:17

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 <QSpinBox>
0010 #include <QStringList>
0011 
0012 /**
0013  * @class TimeSpinBox
0014  * Custom spinbox to handle selection of timestep values with variable units.
0015  * @note this should only be used internally, embedded in a TimeStepBox widget.
0016  *
0017  * @author Jason Harris
0018  * @version 1.0
0019  */
0020 class TimeSpinBox : public QSpinBox
0021 {
0022     Q_OBJECT
0023   public:
0024     /** Constructor */
0025     explicit TimeSpinBox(QWidget *parent, bool daysOnly = false);
0026     /** Destructor (empty) */
0027     ~TimeSpinBox() override = default;
0028 
0029     /**
0030      * Convert the internal value to a display string.
0031      * @note reimplemented from QSpinBox
0032      * @p value the internal value to convert to a display string
0033      * @return the display string
0034      */
0035     QString textFromValue(int value) const override;
0036 
0037     /**
0038      * Convert the displayed string to an internal value.
0039      * @note reimplemented from QSpinBox
0040      * @p ok bool pointer set to true if conversion was successful
0041      * @return internal value converted from displayed text
0042      */
0043     int valueFromText(const QString &text) const override;
0044 
0045     /** @return the current TimeStep setting */
0046     float timeScale() const;
0047 
0048     void setDaysOnly(bool daysonly);
0049     bool daysOnly() const { return DaysOnly; }
0050 
0051   signals:
0052     void scaleChanged(float s);
0053 
0054   public slots:
0055     void changeScale(float s);
0056 
0057   protected slots:
0058     void reportChange();
0059 
0060   private:
0061     bool DaysOnly { false };
0062     float TimeScale[43];
0063     QStringList TimeString;
0064 };