-
Notifications
You must be signed in to change notification settings - Fork 0
/
PreferencesWindow.cpp
74 lines (57 loc) · 2.41 KB
/
PreferencesWindow.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
#include "PreferencesWindow.hpp"
#include <QCloseEvent>
#include <QGuiApplication>
#include <QScreen>
#include "MainWindow.hpp"
PreferencesWindow::PreferencesWindow() : QDialog() {
setWindowTitle("Preferences");
setFixedSize(PREFSWINDOW_WIDTH, PREFSWINDOW_HEIGHT);
strideLayout = new QHBoxLayout();
increaseLayout = new QHBoxLayout();
decreaseLayout = new QHBoxLayout();
bottomButtonLayout = new QHBoxLayout();
mainLayout = new QVBoxLayout();
strideLabel = new QLabel(" Stride: ");
strideLayout->addWidget(strideLabel);
spinbox = new QSpinBox(); // Qt will manage its lifetime
spinbox->setMinimum(1);
spinbox->setMaximum(100);
spinbox->setValue(10);
spinbox->setFixedWidth(LABEL_SPINBOX_WIDTH);
keySeqEditIncrease = new QKeySequenceEdit(Qt::Key_F6);
keySeqEditDecrease = new QKeySequenceEdit(Qt::Key_F5);
keySeqEditIncrease->setFixedWidth(LABEL_SPINBOX_WIDTH);
keySeqEditDecrease->setFixedWidth(LABEL_SPINBOX_WIDTH);
increaseLabel = new QLabel(" Increase:");
increaseLayout->addWidget(increaseLabel);
increaseLayout->addWidget(keySeqEditIncrease);
decreaseLabel = new QLabel(" Decrease:");
decreaseLayout->addWidget(decreaseLabel);
decreaseLayout->addWidget(keySeqEditDecrease);
resetButton = new QPushButton("Reset", this);
applyButton = new QPushButton("Apply", this);
bottomButtonLayout->addWidget(resetButton);
bottomButtonLayout->addWidget(applyButton);
strideLayout->addWidget(spinbox);
mainLayout->addLayout(strideLayout);
mainLayout->addLayout(increaseLayout);
mainLayout->addLayout(decreaseLayout);
mainLayout->addLayout(bottomButtonLayout);
setLayout(mainLayout);
// Make preferences appear in the center
QRect screenGeometry = QGuiApplication::screens().at(0)->geometry();
posX = ((screenGeometry.width() - this->width()) / 2) - this->width() / 2;
posY = (screenGeometry.height() - this->height()) / 2 +
screenGeometry.top() - this->height() / 2;
}
void PreferencesWindow::closeEvent(QCloseEvent* event) {
event->ignore();
hide();
}
void PreferencesWindow::showEvent(QShowEvent* event) {
QDialog::showEvent(event);
QRect screenGeometry = QGuiApplication::screens().at(0)->geometry();
posX = ((screenGeometry.width() - this->width()) / 2);
posY = (screenGeometry.height() - this->height()) / 2 + screenGeometry.top();
this->move(posX, posY);
}