bac7cac1e86f84ec5377a7059b55c701b230fcb3
[pulseview.git] / pv / widgets / timestampspinbox.hpp
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2015 Jens Steinhauser <jens.steinhauser@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 #ifndef PULSEVIEW_PV_WIDGETS_TIMESTAMPSPINBOX_HPP
22 #define PULSEVIEW_PV_WIDGETS_TIMESTAMPSPINBOX_HPP
23
24 #include "pv/util.hpp"
25
26 #include <QAbstractSpinBox>
27
28 namespace pv {
29 namespace widgets {
30
31 class TimestampSpinBox : public QAbstractSpinBox
32 {
33         Q_OBJECT
34
35         Q_PROPERTY(unsigned precision
36                 READ precision
37                 WRITE setPrecision)
38
39         // Needed because of some strange behaviour of the Qt4 MOC that would add
40         // a reference to a 'staticMetaObject' member of 'pv::util' (the namespace)
41         // if pv::util::Timestamp is used directly in the Q_PROPERTY macros below.
42         // Didn't happen with the Qt5 MOC in this case, however others have had
43         // similar problems with Qt5: https://bugreports.qt.io/browse/QTBUG-37519
44         typedef pv::util::Timestamp Timestamp;
45
46         Q_PROPERTY(Timestamp singleStep
47                 READ singleStep
48                 WRITE setSingleStep)
49
50         Q_PROPERTY(Timestamp value
51                 READ value
52                 WRITE setValue
53                 NOTIFY valueChanged
54                 USER true)
55
56 public:
57         TimestampSpinBox(QWidget* parent = nullptr);
58
59         void stepBy(int steps) override;
60
61         StepEnabled stepEnabled() const override;
62
63         unsigned precision() const;
64         void setPrecision(unsigned precision);
65
66         const pv::util::Timestamp& singleStep() const;
67         void setSingleStep(const pv::util::Timestamp& step);
68
69         const pv::util::Timestamp& value() const;
70
71         QSize minimumSizeHint() const override;
72
73 public Q_SLOTS:
74         void setValue(const pv::util::Timestamp& val);
75
76 Q_SIGNALS:
77         void valueChanged(const pv::util::Timestamp&);
78
79 private Q_SLOTS:
80         void on_editingFinished();
81
82 private:
83         unsigned precision_;
84         pv::util::Timestamp stepsize_;
85         pv::util::Timestamp value_;
86
87         void updateEdit();
88 };
89
90 } // widgets
91 } // pv
92
93 #endif