File indexing completed on 2024-05-12 15:27:41
0001 /*************************************************************************** 0002 File : DateTimeSpinBox.h 0003 Project : LabPlot 0004 Description : widget for setting datetimes with a spinbox 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2019 Martin Marmsoler (martin.marmsoler@gmail.com) 0007 0008 ***************************************************************************/ 0009 0010 /*************************************************************************** 0011 * * 0012 * This program is free software; you can redistribute it and/or modify * 0013 * it under the terms of the GNU General Public License as published by * 0014 * the Free Software Foundation; either version 2 of the License, or * 0015 * (at your option) any later version. * 0016 * * 0017 * This program is distributed in the hope that it will be useful, * 0018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0020 * GNU General Public License for more details. * 0021 * * 0022 * You should have received a copy of the GNU General Public License * 0023 * along with this program; if not, write to the Free Software * 0024 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0025 * Boston, MA 02110-1301 USA * 0026 * * 0027 ***************************************************************************/ 0028 0029 #ifndef DATETIMESPINBOX_H 0030 #define DATETIMESPINBOX_H 0031 0032 #include <QAbstractSpinBox> 0033 0034 class QRegularExpressionValidator; 0035 0036 // Assumption: Month has always 30 days 0037 class DateTimeSpinBox : public QAbstractSpinBox { 0038 0039 Q_OBJECT; 0040 private: 0041 enum Type { 0042 year, 0043 month, 0044 day, 0045 hour, 0046 minute, 0047 second, 0048 millisecond 0049 }; 0050 0051 public: 0052 explicit DateTimeSpinBox(QWidget* parent); 0053 void keyPressEvent(QKeyEvent*) override; 0054 void stepBy(int steps) override; 0055 QAbstractSpinBox::StepEnabled stepEnabled() const override; 0056 bool increaseValue(Type type, int step); 0057 bool changeValue(qint64& thisType, Type nextTypeType, int step); 0058 Type determineType(int cursorPos) const; 0059 void writeValue(); 0060 void setValue(qint64 increment); 0061 qint64 value(); 0062 void getValue(); 0063 void setCursorPosition(Type type); 0064 bool valid(); 0065 0066 private: 0067 QRegularExpressionValidator *m_regularExpressionValidator; 0068 qint64 m_year{0}, m_month{0}, m_day{0}, m_hour{0}, m_minute{0}, m_second{0}, m_millisecond{0}; 0069 0070 signals: 0071 void valueChanged(); 0072 }; 0073 0074 #endif // DATETIMESPINBOX_H