-
Notifications
You must be signed in to change notification settings - Fork 0
/
gotoflashcarddialog.cpp
66 lines (50 loc) · 2.09 KB
/
gotoflashcarddialog.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
#include "gotoflashcarddialog.h"
GoToFlashcardDialog::GoToFlashcardDialog(Reader* parent, int count) {
this->setObjectName("goToFlashcard");
this->setWindowTitle("Go to flashcard");
this->setWindowIcon(parent->windowIcon());
// Geometry
int width = 300, height = 150;
QScreen* screen = qApp->primaryScreen();
QRect screenGeometry = screen->geometry();
int x = (screenGeometry.width() - width) / 2;
int y = (screenGeometry.height() - height) / 2;
this->setGeometry(x, y, width, height);
this->setFixedSize(width, height);
this->setWindowFlag(Qt::WindowStaysOnTopHint);
this->setStyleSheet(parent->styleSheet());
// UI
QVBoxLayout* mainLayout = new QVBoxLayout(this);
QLabel* specifyLabel = new QLabel("Specify which flashcard you want to go to");
mainLayout->addWidget(specifyLabel);
QHBoxLayout* fieldLayout = new QHBoxLayout();
QSpinBox* spinBox = new QSpinBox();
spinBox->setMinimum(1);
spinBox->setMaximum(count);
fieldLayout->addWidget(spinBox);
QLabel* maxLabel = new QLabel(QString("/%1").arg(QString::number(count)));
fieldLayout->addWidget(maxLabel);
mainLayout->addLayout(fieldLayout);
QHBoxLayout* buttonsLayout = new QHBoxLayout();
buttonsLayout->addSpacerItem(new QSpacerItem(0, 0,
QSizePolicy::MinimumExpanding,
QSizePolicy::Ignored));
QPushButton* cancelButton = new QPushButton("Cancel");
buttonsLayout->addWidget(cancelButton);
QPushButton* goButton = new QPushButton("Go");
goButton->setDefault(true);
goButton->setAutoDefault(true);
buttonsLayout->addWidget(goButton);
mainLayout->addLayout(buttonsLayout);
// Making connections
connect(cancelButton, &QPushButton::clicked, this, [this]() {
this->hide();
delete this;
});
connect(goButton, &QPushButton::clicked, this, [this, spinBox, parent]() {
parent->loadFlashcard(spinBox->value(), false);
parent->mTurnedOver = false;
this->hide();
delete this;
});
}