-
Notifications
You must be signed in to change notification settings - Fork 14
/
settingsdialog.cpp
400 lines (349 loc) · 12.8 KB
/
settingsdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
/*
* Copyright 2013-2014 KanMemo Project.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "settingsdialog.h"
#include "ui_settingsdialog.h"
#include <QMessageBox>
#include <QFileDialog>
#include <QFile>
#include <QDebug>
class SettingsDialog::Private
{
public:
Private(SettingsDialog *parent);
private:
SettingsDialog *q;
Ui::SettingsDialog ui;
public:
QString savePath;
bool unusedTwitter;
bool savePng;
bool maskAdmiralName;
bool maskHqLevel;
bool proxyEnable;
QString proxyHost;
quint16 proxyPort;
bool useCookie;
bool disableContextMenu;
bool disableExitShortcut;
bool viewButtleResult;
bool operatingCombinedFleet;
SettingsDialog::ButtleResultPosition buttleResultPosition;
QBoxLayout::Direction buttleResultDirection;
qreal buttleResultOpacity;
bool timerAutoStart;
bool tweetFinished;
};
SettingsDialog::Private::Private(SettingsDialog *parent)
: q(parent)
{
ui.setupUi(q);
connect(ui.buttonBox, &QDialogButtonBox::accepted, [this](){
if(!QFile::exists(ui.savePathEdit->text())){
QMessageBox::warning(q, "warning", "save path not found.");
return;
}
savePath = ui.savePathEdit->text();
unusedTwitter = ui.unusedTwittercheckBox->isChecked();
savePng = ui.savePngCheckBox->isChecked();
maskAdmiralName = ui.maskAdmiralNameCheckBox->isChecked();
maskHqLevel = ui.maskHqLevelCheckBox->isChecked();
proxyEnable = ui.proxyEnableCheckBox->isChecked();
proxyHost = ui.proxyHost->text();
proxyPort = ui.proxyPort->value();
useCookie = ui.useCookieCheckBox->isChecked();
disableContextMenu = ui.disableContextMenu->isChecked();
disableExitShortcut = ui.disableExitShortcut->isChecked();
viewButtleResult = ui.viewButtleResultCheckBox->isChecked();
operatingCombinedFleet = ui.operatingCombinedFleetCheckBox->isChecked();
switch(ui.buttleResultPositionComboBox->currentIndex()){
case 0: buttleResultPosition = LeftTop; break;
case 1: buttleResultPosition = RightTop; break;
case 2: buttleResultPosition = LeftBottom; break;
case 3: buttleResultPosition = RightBottom; break;
case 4: buttleResultPosition = Center; break;
default: buttleResultPosition = RightTop; break;
}
switch(ui.buttleResultOpacityComboBox->currentIndex()){
case 0: buttleResultOpacity = 1.0; break;
case 1: buttleResultOpacity = 0.75; break;
case 2: buttleResultOpacity = 0.5; break;
case 3: buttleResultOpacity = 0.25; break;
default: buttleResultOpacity = 1.0; break;
}
switch(ui.buttleResultDirectionComboBox->currentIndex()){
case 0: buttleResultDirection = QBoxLayout::LeftToRight; break;
case 1: buttleResultDirection = QBoxLayout::TopToBottom; break;
default: buttleResultDirection = QBoxLayout::TopToBottom; break;
}
timerAutoStart = ui.timerAutoStartCheckBox->isChecked();
tweetFinished = ui.tweetFinishedCheckBox->isChecked();
q->accept();
});
connect(ui.buttonBox, &QDialogButtonBox::rejected, q, &QDialog::reject);
//保存パスの参照ボタン
connect(ui.selectPathButton, &QToolButton::clicked, [this]() {
QString path = q->selectSavePath(q, ui.savePathEdit->text());
if(QFile::exists(path))
q->setSavePath(path);
});
connect(q, &SettingsDialog::savePathChanged, ui.savePathEdit, &QLineEdit::setText);
connect(q, &SettingsDialog::unusedTwitterChanged, ui.unusedTwittercheckBox, &QCheckBox::setChecked);
connect(q, &SettingsDialog::savePngChanged, ui.savePngCheckBox, &QCheckBox::setChecked);
connect(q, &SettingsDialog::maskAdmiralNameChanged, ui.maskAdmiralNameCheckBox, &QCheckBox::setChecked);
connect(q, &SettingsDialog::maskHqLevelChanged, ui.maskHqLevelCheckBox, &QCheckBox::setChecked);
connect(q, &SettingsDialog::proxyEnableChanged, ui.proxyEnableCheckBox, &QCheckBox::setChecked);
connect(q, &SettingsDialog::proxyHostChanged, ui.proxyHost, &QLineEdit::setText);
connect(q, &SettingsDialog::proxyPortChanged, ui.proxyPort, &QSpinBox::setValue);
connect(q, &SettingsDialog::useCookieChanged, ui.useCookieCheckBox, &QCheckBox::setChecked);
connect(q, &SettingsDialog::disableContextMenuChanged, ui.disableContextMenu, &QCheckBox::setChecked);
connect(q, &SettingsDialog::disableExitShortcutChanged, ui.disableExitShortcut, &QCheckBox::setChecked);
connect(q, &SettingsDialog::viewButtleResultChanged, ui.viewButtleResultCheckBox, &QCheckBox::setChecked);
connect(q, &SettingsDialog::operatingCombinedFleetChanged, ui.operatingCombinedFleetCheckBox, &QCheckBox::setChecked);
connect(q, &SettingsDialog::buttleResultPositionChanged, [this](ButtleResultPosition position){
int index = 1;
switch(position){
case LeftTop: index = 0; break;
case RightTop: index = 1; break;
case LeftBottom: index = 2; break;
case RightBottom: index = 3; break;
case Center: index = 4; break;
default: index = 1; break;
}
ui.buttleResultPositionComboBox->setCurrentIndex(index);
});
connect(q, &SettingsDialog::buttleResultOpacityChanged, [this](qreal opacity){
if(opacity > 0.999){ //1.0
ui.buttleResultOpacityComboBox->setCurrentIndex(0);
}else if(opacity > 0.749){ //0.75
ui.buttleResultOpacityComboBox->setCurrentIndex(1);
}else if(opacity > 0.499){ //0.5
ui.buttleResultOpacityComboBox->setCurrentIndex(2);
}else if(opacity > 0.249){ //0.25
ui.buttleResultOpacityComboBox->setCurrentIndex(3);
}else{
ui.buttleResultOpacityComboBox->setCurrentIndex(0);
}
});
connect(q, &SettingsDialog::buttleResultDirectionChanged, [this](QBoxLayout::Direction direction){
int dir = 0;
switch(direction){
case QBoxLayout::LeftToRight: dir = 0; break;
case QBoxLayout::TopToBottom: dir = 1; break;
default: dir = 1; break;
}
ui.buttleResultDirectionComboBox->setCurrentIndex(dir);
});
connect(q, &SettingsDialog::timerAutoStartChanged, ui.timerAutoStartCheckBox, &QCheckBox::setChecked);
connect(q, &SettingsDialog::tweetFinishedChanged, ui.tweetFinishedCheckBox, &QCheckBox::setChecked);
QSpinBox * portNum = ui.proxyPort;
portNum->setMinimum(1);
portNum->setMaximum(65535);
}
SettingsDialog::SettingsDialog(QWidget *parent)
: QDialog(parent)
, d(new Private(this))
{
connect(this, &QObject::destroyed, [this]() { delete d; });
}
const QString &SettingsDialog::savePath() const
{
return d->savePath;
}
void SettingsDialog::setSavePath(const QString &savePath)
{
if (d->savePath == savePath) return;
d->savePath = savePath;
emit savePathChanged(savePath);
}
QString SettingsDialog::selectSavePath(QWidget *parent, const QString ¤tPath)
{
return QFileDialog::getExistingDirectory(parent, tr("Select save folder"),
currentPath,
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
}
bool SettingsDialog::unusedTwitter() const
{
return d->unusedTwitter;
}
void SettingsDialog::setUnusedTwitter(bool unusedTwitter)
{
if (d->unusedTwitter == unusedTwitter) return;
d->unusedTwitter = unusedTwitter;
emit unusedTwitterChanged(unusedTwitter);
}
bool SettingsDialog::savePng() const
{
return d->savePng;
}
void SettingsDialog::setSavePng(bool savePng)
{
if (d->savePng == savePng) return;
d->savePng = savePng;
emit savePngChanged(savePng);
}
bool SettingsDialog::isMaskAdmiralName() const
{
return d->maskAdmiralName;
}
void SettingsDialog::setMaskAdmiralName(bool maskAdmiralName)
{
if (d->maskAdmiralName == maskAdmiralName) return;
d->maskAdmiralName = maskAdmiralName;
emit maskAdmiralNameChanged(maskAdmiralName);
}
bool SettingsDialog::isMaskHqLevel() const
{
return d->maskHqLevel;
}
bool SettingsDialog::isProxyEnable() const
{
return d->proxyEnable;
}
void SettingsDialog::setMaskHqLevel(bool maskHqLevel)
{
if (d->maskHqLevel == maskHqLevel) return;
d->maskHqLevel = maskHqLevel;
emit maskHqLevelChanged(maskHqLevel);
}
void SettingsDialog::setProxyEnable(bool enable)
{
if(d->proxyEnable == enable) return;
d->proxyEnable = enable;
emit proxyEnableChanged(enable);
}
const QString &SettingsDialog::proxyHost() const
{
return d->proxyHost;
}
void SettingsDialog::setProxyHost(const QString &proxyHost)
{
if(d->proxyHost == proxyHost) return;
d->proxyHost = proxyHost;
emit proxyHostChanged(proxyHost);
}
quint16 SettingsDialog::proxyPort() const
{
return d->proxyPort;
}
bool SettingsDialog::useCookie() const
{
return d->useCookie;
}
//右クリックメニューを無効
bool SettingsDialog::disableContextMenu() const
{
return d->disableContextMenu;
}
//Ctrl+Qで終了を無効化
bool SettingsDialog::disableExitShortcut() const
{
return d->disableExitShortcut;
}
bool SettingsDialog::viewButtleResult() const
{
return d->viewButtleResult;
}
bool SettingsDialog::operatingCombinedFleet() const
{
return d->operatingCombinedFleet;
}
SettingsDialog::ButtleResultPosition SettingsDialog::buttleResultPosition() const
{
return d->buttleResultPosition;
}
QBoxLayout::Direction SettingsDialog::buttleResultDirection() const
{
return d->buttleResultDirection;
}
qreal SettingsDialog::buttleResultOpacity() const
{
return d->buttleResultOpacity;
}
bool SettingsDialog::timerAutoStart() const
{
return d->timerAutoStart;
}
bool SettingsDialog::tweetFinished() const
{
return d->tweetFinished;
}
void SettingsDialog::setProxyPort(quint16 proxyPort)
{
if(d->proxyPort == proxyPort) return;
d->proxyPort = proxyPort;
emit proxyPortChanged(proxyPort);
}
void SettingsDialog::setUseCookie(bool use)
{
if(d->useCookie == use) return;
d->useCookie = use;
emit useCookieChanged(use);
}
void SettingsDialog::setDisableContextMenu(bool disable)
{
if(d->disableContextMenu == disable) return;
d->disableContextMenu = disable;
emit disableContextMenuChanged(disable);
}
void SettingsDialog::setDisableExitShortcut(bool disable)
{
if(d->disableExitShortcut == disable) return;
d->disableExitShortcut = disable;
emit disableExitShortcutChanged(disable);
}
void SettingsDialog::setViewButtleResult(bool view)
{
if(d->viewButtleResult == view) return;
d->viewButtleResult = view;
emit viewButtleResultChanged(view);
}
void SettingsDialog::setOperatingCombinedFleet(bool operate)
{
if(d->operatingCombinedFleet == operate) return;
d->operatingCombinedFleet = operate;
emit operatingCombinedFleetChanged(operate);
}
void SettingsDialog::setButtleResultPosition(SettingsDialog::ButtleResultPosition position)
{
if(d->buttleResultPosition == position) return;
d->buttleResultPosition = position;
emit buttleResultPositionChanged(position);
}
void SettingsDialog::setButtleResultDirection(QBoxLayout::Direction direction)
{
if(d->buttleResultDirection == direction) return;
d->buttleResultDirection = direction;
emit buttleResultDirectionChanged(direction);
}
void SettingsDialog::setButtleResultOpacity(qreal opacity)
{
if(d->buttleResultOpacity == opacity) return;
d->buttleResultOpacity = opacity;
emit buttleResultOpacityChanged(opacity);
}
void SettingsDialog::setTimerAutoStart(bool start)
{
if(d->timerAutoStart == start) return;
d->timerAutoStart = start;
emit timerAutoStartChanged(start);
}
void SettingsDialog::setTweetFinished(bool tweet)
{
if(d->tweetFinished == tweet) return;
d->tweetFinished = tweet;
emit tweetFinishedChanged(tweet);
}