summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2019-05-19 05:33:38 -0400
committerGravatar Lioncash2019-05-19 05:35:34 -0400
commitbc6972caf9c036fabd9ad0201e882aa7132116a2 (patch)
tree9222d94acc1bde6f1a24b8321010e66a9fc7ec81 /src
parentMerge pull request #2457 from lioncash/about (diff)
downloadyuzu-bc6972caf9c036fabd9ad0201e882aa7132116a2.tar.gz
yuzu-bc6972caf9c036fabd9ad0201e882aa7132116a2.tar.xz
yuzu-bc6972caf9c036fabd9ad0201e882aa7132116a2.zip
yuzu/util: Remove unused spinbox.cpp/.h
This has been left unused since the removal of the vestigial surface viewer. Given it has no uses left, this can be removed as well.
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/CMakeLists.txt2
-rw-r--r--src/yuzu/util/spinbox.cpp278
-rw-r--r--src/yuzu/util/spinbox.h86
3 files changed, 0 insertions, 366 deletions
diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt
index 5138bd9a3..7e883991a 100644
--- a/src/yuzu/CMakeLists.txt
+++ b/src/yuzu/CMakeLists.txt
@@ -82,8 +82,6 @@ add_executable(yuzu
82 util/limitable_input_dialog.h 82 util/limitable_input_dialog.h
83 util/sequence_dialog/sequence_dialog.cpp 83 util/sequence_dialog/sequence_dialog.cpp
84 util/sequence_dialog/sequence_dialog.h 84 util/sequence_dialog/sequence_dialog.h
85 util/spinbox.cpp
86 util/spinbox.h
87 util/util.cpp 85 util/util.cpp
88 util/util.h 86 util/util.h
89 compatdb.cpp 87 compatdb.cpp
diff --git a/src/yuzu/util/spinbox.cpp b/src/yuzu/util/spinbox.cpp
deleted file mode 100644
index 14ef1e884..000000000
--- a/src/yuzu/util/spinbox.cpp
+++ /dev/null
@@ -1,278 +0,0 @@
1// Licensed under GPLv2 or any later version
2// Refer to the license.txt file included.
3
4// Copyright 2014 Tony Wasserka
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions are met:
9//
10// * Redistributions of source code must retain the above copyright
11// notice, this list of conditions and the following disclaimer.
12// * Redistributions in binary form must reproduce the above copyright
13// notice, this list of conditions and the following disclaimer in the
14// documentation and/or other materials provided with the distribution.
15// * Neither the name of the owner nor the names of its contributors may
16// be used to endorse or promote products derived from this software
17// without specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31#include <cstdlib>
32#include <QLineEdit>
33#include <QRegExpValidator>
34#include "common/assert.h"
35#include "yuzu/util/spinbox.h"
36
37CSpinBox::CSpinBox(QWidget* parent)
38 : QAbstractSpinBox(parent), min_value(-100), max_value(100), value(0), base(10), num_digits(0) {
39 // TODO: Might be nice to not immediately call the slot.
40 // Think of an address that is being replaced by a different one, in which case a lot
41 // invalid intermediate addresses would be read from during editing.
42 connect(lineEdit(), &QLineEdit::textEdited, this, &CSpinBox::OnEditingFinished);
43
44 UpdateText();
45}
46
47void CSpinBox::SetValue(qint64 val) {
48 auto old_value = value;
49 value = std::max(std::min(val, max_value), min_value);
50
51 if (old_value != value) {
52 UpdateText();
53 emit ValueChanged(value);
54 }
55}
56
57void CSpinBox::SetRange(qint64 min, qint64 max) {
58 min_value = min;
59 max_value = max;
60
61 SetValue(value);
62 UpdateText();
63}
64
65void CSpinBox::stepBy(int steps) {
66 auto new_value = value;
67 // Scale number of steps by the currently selected digit
68 // TODO: Move this code elsewhere and enable it.
69 // TODO: Support for num_digits==0, too
70 // TODO: Support base!=16, too
71 // TODO: Make the cursor not jump back to the end of the line...
72 /*if (base == 16 && num_digits > 0) {
73 int digit = num_digits - (lineEdit()->cursorPosition() - prefix.length()) - 1;
74 digit = std::max(0, std::min(digit, num_digits - 1));
75 steps <<= digit * 4;
76 }*/
77
78 // Increment "new_value" by "steps", and perform annoying overflow checks, too.
79 if (steps < 0 && new_value + steps > new_value) {
80 new_value = std::numeric_limits<qint64>::min();
81 } else if (steps > 0 && new_value + steps < new_value) {
82 new_value = std::numeric_limits<qint64>::max();
83 } else {
84 new_value += steps;
85 }
86
87 SetValue(new_value);
88 UpdateText();
89}
90
91QAbstractSpinBox::StepEnabled CSpinBox::stepEnabled() const {
92 StepEnabled ret = StepNone;
93
94 if (value > min_value)
95 ret |= StepDownEnabled;
96
97 if (value < max_value)
98 ret |= StepUpEnabled;
99
100 return ret;
101}
102
103void CSpinBox::SetBase(int base) {
104 this->base = base;
105
106 UpdateText();
107}
108
109void CSpinBox::SetNumDigits(int num_digits) {
110 this->num_digits = num_digits;
111
112 UpdateText();
113}
114
115void CSpinBox::SetPrefix(const QString& prefix) {
116 this->prefix = prefix;
117
118 UpdateText();
119}
120
121void CSpinBox::SetSuffix(const QString& suffix) {
122 this->suffix = suffix;
123
124 UpdateText();
125}
126
127static QString StringToInputMask(const QString& input) {
128 QString mask = input;
129
130 // ... replace any special characters by their escaped counterparts ...
131 mask.replace("\\", "\\\\");
132 mask.replace("A", "\\A");
133 mask.replace("a", "\\a");
134 mask.replace("N", "\\N");
135 mask.replace("n", "\\n");
136 mask.replace("X", "\\X");
137 mask.replace("x", "\\x");
138 mask.replace("9", "\\9");
139 mask.replace("0", "\\0");
140 mask.replace("D", "\\D");
141 mask.replace("d", "\\d");
142 mask.replace("#", "\\#");
143 mask.replace("H", "\\H");
144 mask.replace("h", "\\h");
145 mask.replace("B", "\\B");
146 mask.replace("b", "\\b");
147 mask.replace(">", "\\>");
148 mask.replace("<", "\\<");
149 mask.replace("!", "\\!");
150
151 return mask;
152}
153
154void CSpinBox::UpdateText() {
155 // If a fixed number of digits is used, we put the line edit in insertion mode by setting an
156 // input mask.
157 QString mask;
158 if (num_digits != 0) {
159 mask += StringToInputMask(prefix);
160
161 // For base 10 and negative range, demand a single sign character
162 if (HasSign())
163 mask += "X"; // identified as "-" or "+" in the validator
164
165 // Uppercase digits greater than 9.
166 mask += ">";
167
168 // Match num_digits digits
169 // Digits irrelevant to the chosen number base are filtered in the validator
170 mask += QString("H").repeated(std::max(num_digits, 1));
171
172 // Switch off case conversion
173 mask += "!";
174
175 mask += StringToInputMask(suffix);
176 }
177 lineEdit()->setInputMask(mask);
178
179 // Set new text without changing the cursor position. This will cause the cursor to briefly
180 // appear at the end of the line and then to jump back to its original position. That's
181 // a bit ugly, but better than having setText() move the cursor permanently all the time.
182 int cursor_position = lineEdit()->cursorPosition();
183 lineEdit()->setText(TextFromValue());
184 lineEdit()->setCursorPosition(cursor_position);
185}
186
187QString CSpinBox::TextFromValue() {
188 return prefix + QString(HasSign() ? ((value < 0) ? "-" : "+") : "") +
189 QString("%1").arg(std::abs(value), num_digits, base, QLatin1Char('0')).toUpper() +
190 suffix;
191}
192
193qint64 CSpinBox::ValueFromText() {
194 unsigned strpos = prefix.length();
195
196 QString num_string = text().mid(strpos, text().length() - strpos - suffix.length());
197 return num_string.toLongLong(nullptr, base);
198}
199
200bool CSpinBox::HasSign() const {
201 return base == 10 && min_value < 0;
202}
203
204void CSpinBox::OnEditingFinished() {
205 // Only update for valid input
206 QString input = lineEdit()->text();
207 int pos = 0;
208 if (QValidator::Acceptable == validate(input, pos))
209 SetValue(ValueFromText());
210}
211
212QValidator::State CSpinBox::validate(QString& input, int& pos) const {
213 if (!prefix.isEmpty() && input.left(prefix.length()) != prefix)
214 return QValidator::Invalid;
215
216 int strpos = prefix.length();
217
218 // Empty "numbers" allowed as intermediate values
219 if (strpos >= input.length() - HasSign() - suffix.length())
220 return QValidator::Intermediate;
221
222 DEBUG_ASSERT(base <= 10 || base == 16);
223 QString regexp;
224
225 // Demand sign character for negative ranges
226 if (HasSign())
227 regexp += "[+\\-]";
228
229 // Match digits corresponding to the chosen number base.
230 regexp += QString("[0-%1").arg(std::min(base, 9));
231 if (base == 16) {
232 regexp += "a-fA-F";
233 }
234 regexp += "]";
235
236 // Specify number of digits
237 if (num_digits > 0) {
238 regexp += QString("{%1}").arg(num_digits);
239 } else {
240 regexp += "+";
241 }
242
243 // Match string
244 QRegExp num_regexp(regexp);
245 int num_pos = strpos;
246 QString sub_input = input.mid(strpos, input.length() - strpos - suffix.length());
247
248 if (!num_regexp.exactMatch(sub_input) && num_regexp.matchedLength() == 0)
249 return QValidator::Invalid;
250
251 sub_input = sub_input.left(num_regexp.matchedLength());
252 bool ok;
253 qint64 val = sub_input.toLongLong(&ok, base);
254
255 if (!ok)
256 return QValidator::Invalid;
257
258 // Outside boundaries => don't accept
259 if (val < min_value || val > max_value)
260 return QValidator::Invalid;
261
262 // Make sure we are actually at the end of this string...
263 strpos += num_regexp.matchedLength();
264
265 if (!suffix.isEmpty() && input.mid(strpos) != suffix) {
266 return QValidator::Invalid;
267 } else {
268 strpos += suffix.length();
269 }
270
271 if (strpos != input.length())
272 return QValidator::Invalid;
273
274 // At this point we can say for sure that the input is fine. Let's fix it up a bit though
275 input.replace(num_pos, sub_input.length(), sub_input.toUpper());
276
277 return QValidator::Acceptable;
278}
diff --git a/src/yuzu/util/spinbox.h b/src/yuzu/util/spinbox.h
deleted file mode 100644
index 2fa1db3a4..000000000
--- a/src/yuzu/util/spinbox.h
+++ /dev/null
@@ -1,86 +0,0 @@
1// Licensed under GPLv2 or any later version
2// Refer to the license.txt file included.
3
4// Copyright 2014 Tony Wasserka
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions are met:
9//
10// * Redistributions of source code must retain the above copyright
11// notice, this list of conditions and the following disclaimer.
12// * Redistributions in binary form must reproduce the above copyright
13// notice, this list of conditions and the following disclaimer in the
14// documentation and/or other materials provided with the distribution.
15// * Neither the name of the owner nor the names of its contributors may
16// be used to endorse or promote products derived from this software
17// without specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31#pragma once
32
33#include <QAbstractSpinBox>
34#include <QtGlobal>
35
36class QVariant;
37
38/**
39 * A custom spin box widget with enhanced functionality over Qt's QSpinBox
40 */
41class CSpinBox : public QAbstractSpinBox {
42 Q_OBJECT
43
44public:
45 explicit CSpinBox(QWidget* parent = nullptr);
46
47 void stepBy(int steps) override;
48 StepEnabled stepEnabled() const override;
49
50 void SetValue(qint64 val);
51
52 void SetRange(qint64 min, qint64 max);
53
54 void SetBase(int base);
55
56 void SetPrefix(const QString& prefix);
57 void SetSuffix(const QString& suffix);
58
59 void SetNumDigits(int num_digits);
60
61 QValidator::State validate(QString& input, int& pos) const override;
62
63signals:
64 void ValueChanged(qint64 val);
65
66private slots:
67 void OnEditingFinished();
68
69private:
70 void UpdateText();
71
72 bool HasSign() const;
73
74 QString TextFromValue();
75 qint64 ValueFromText();
76
77 qint64 min_value, max_value;
78
79 qint64 value;
80
81 QString prefix, suffix;
82
83 int base;
84
85 int num_digits;
86};