summaryrefslogtreecommitdiff
path: root/src/citra_qt/util/spinbox.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/citra_qt/util/spinbox.h')
-rw-r--r--src/citra_qt/util/spinbox.h88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/citra_qt/util/spinbox.h b/src/citra_qt/util/spinbox.h
new file mode 100644
index 000000000..ee7f08ec2
--- /dev/null
+++ b/src/citra_qt/util/spinbox.h
@@ -0,0 +1,88 @@
1// Licensed under GPLv2 or any later version
2// Refer to the license.txt file included.
3
4
5// Copyright 2014 Tony Wasserka
6// All rights reserved.
7//
8// Redistribution and use in source and binary forms, with or without
9// modification, are permitted provided that the following conditions are met:
10//
11// * Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// * Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// * Neither the name of the owner nor the names of its contributors may
17// be used to endorse or promote products derived from this software
18// without specific prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32
33#pragma once
34
35#include <QAbstractSpinBox>
36#include <QtGlobal>
37
38class QVariant;
39
40/**
41 * A custom spin box widget with enhanced functionality over Qt's QSpinBox
42 */
43class CSpinBox : public QAbstractSpinBox {
44 Q_OBJECT
45
46public:
47 CSpinBox(QWidget* parent = nullptr);
48
49 void stepBy(int steps) override;
50 StepEnabled stepEnabled() const override;
51
52 void SetValue(qint64 val);
53
54 void SetRange(qint64 min, qint64 max);
55
56 void SetBase(int base);
57
58 void SetPrefix(const QString& prefix);
59 void SetSuffix(const QString& suffix);
60
61 void SetNumDigits(int num_digits);
62
63 QValidator::State validate(QString& input, int& pos) const override;
64
65signals:
66 void ValueChanged(qint64 val);
67
68private slots:
69 void OnEditingFinished();
70
71private:
72 void UpdateText();
73
74 bool HasSign() const;
75
76 QString TextFromValue();
77 qint64 ValueFromText();
78
79 qint64 min_value, max_value;
80
81 qint64 value;
82
83 QString prefix, suffix;
84
85 int base;
86
87 int num_digits;
88};