-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptiondialog.cpp
107 lines (94 loc) · 3.68 KB
/
optiondialog.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
#include "optiondialog.h"
#include "ui_optiondialog.h"
#include "sheet.h"
#ifdef __wasm__
#include "ui_wasm.h"
#else
#include "ui_sheet.h"
#endif
optionDialog::optionDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::optionDialog)
{
QFont font({ QString("Segoe UIHS") });
setFont(font);
ui->setupUi(this);
#ifdef unix
setStyleSheet("color: #000; background: #fff;");
#endif
connect(ui->totalPointsLineEdit, SIGNAL(textChanged(QString)), this, SLOT(numeric(QString)));
connect(ui->complicationsLineEdit, SIGNAL(textChanged(QString)), this, SLOT(numeric(QString)));
connect(ui->activePointsPerEND, SIGNAL(textChanged(QString)), this, SLOT(numeric(QString)));
connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(pickSomething(int)));
connect(this, SIGNAL(accepted()), this, SLOT(accept()));
auto rect = ui->banner->geometry();
rect.setSize({ 293, 109 }); // NOLINT
ui->banner->setGeometry(rect);
ui->banner->setAlignment(Qt::AlignCenter);
if (Sheet::ref().option().banner().isEmpty()) Sheet::ref().option().banner() = ":/gfx/HeroSystem-Banner.png";
setBanner(Sheet::ref().option().banner());
Sheet::ref().fixButtonBox(ui->buttonBox);
}
optionDialog::~optionDialog()
{
delete ui;
}
QMap<int, int> table { // NOLINT
{ 25, 15 }, // NOLINT
{ 50, 25 }, // NOLINT
{ 100, 30 }, // NOLINT
{ 175, 50 }, // NOLINT
{ 225, 50 }, // NOLINT
{ 275, 50 }, // NOLINT
{ 300, 60 }, // NOLINT
{ 400, 75 }, // NOLINT
{ 500, 75 }, // NOLINT
{ 650, 100 }, // NOLINT
{ 750, 100 } // NOLINT
};
void optionDialog::accept() {
Sheet::ref().option().banner(banner());
Sheet::ref().option().complications(Points(complications()));
Sheet::ref().option().equipmentFree(equipmentFree());
Sheet::ref().option().showFrequencyRolls(showFrequencyRolls());
Sheet::ref().option().showNotesPage(showNotesPage());
Sheet::ref().option().activePerEND(Points(activePointsPerEND()));
Sheet::ref().option().totalPoints(Points(totalPoints()));
Sheet::ref().option().normalHumanMaxima(normalHumanMaxima());
Sheet::ref().option().store();
Sheet::ref().UI()->optLabel->setVisible(Sheet::ref().option().showNotesPage());
Sheet::ref().updateDisplay();
Sheet::ref().changed();
close();
}
void optionDialog::mouseReleaseEvent(QMouseEvent* evt) {
QRect rect = ui->banner->geometry();
QPoint pos = evt->position().toPoint();
if (!rect.contains(pos)) return;
QStringList banners = Sheet::ref().getBanners();
auto which = banners.indexOf(_banner) + 1;
if (which == banners.length()) which = 0;
setBanner(banners[which]);
}
void optionDialog::numeric(QString) {
QLineEdit* edit = dynamic_cast<QLineEdit*>(sender());
QString txt = edit->text();
if (txt.isEmpty() || isNumber(txt)) {
if (txt.isEmpty()) ui->comboBox->setCurrentIndex(table.count()); // NOLINT
else {
int cp = ui->totalPointsLineEdit->text().toInt();
auto keys = table.keys();
if (!keys.contains(cp)) ui->comboBox->setCurrentIndex(table.count()); // NOLINT
else if (table[cp] != ui->complicationsLineEdit->text().toInt()) ui->comboBox->setCurrentIndex(table.count()); // NOLINT
else ui->comboBox->setCurrentIndex(keys.indexOf(cp)); // NOLINT
}
return;
}
edit->undo();
}
void optionDialog::pickSomething(int something) {
if (something >= table.count()) return;
auto keys = table.keys();
ui->totalPointsLineEdit->setText(QString("%1").arg(keys[something]));
ui->complicationsLineEdit->setText(QString("%1").arg(table[keys[something]]));
}