-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
120 lines (101 loc) · 4.35 KB
/
Copy pathmainwindow.cpp
File metadata and controls
120 lines (101 loc) · 4.35 KB
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QRect>
#include <QDesktopWidget>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
_timer(new QTimer(this)),
_pillsCount(0), _step(1)
{
connect (_timer, SIGNAL(timeout()), this, SLOT(nullMultiplier()));
/*----------------УСТАНОВКА ИНТЕРФЕЙСА-НАЧАЛО-------------------*/
ui->setupUi(this);
nullMultiplier();
setCentralWidget(ui->stackedWidget);
/* размеры приложения */
// на десктопе
QRect screenGeometry = geometry();
// на андроиде
// QRect screenGeometry = qApp->desktop()->availableGeometry(ui->pillButton);
// установка размеров кнопки
_pillSize = screenGeometry.width() / 2;
ui->pillButton->resize(_pillSize, _pillSize);
ui->pillButton->setIconSize(QSize(_pillSize, _pillSize));
// центрирование кнопки
QPoint center(centerXBetweenAB(_pillSize, 0, screenGeometry.width()),
centerXBetweenAB(_pillSize, 0, screenGeometry.height()));
ui->pillButton->move(center);
// центрирование счетчика
QRect widgetGeometry = ui->counterLabel->geometry();
center = QPoint(centerXBetweenAB(widgetGeometry.width(), 0, screenGeometry.width()),
centerXBetweenAB(widgetGeometry.height(), 0, ui->pillButton->y()));
ui->counterLabel->move(center);
// центрирование шага
widgetGeometry = ui->stepLabel->geometry();
center = QPoint(centerXBetweenAB(widgetGeometry.width(), 0, screenGeometry.width()),
centerXBetweenAB(widgetGeometry.height(), _pillSize + ui->pillButton->y(), screenGeometry.height()));
ui->stepLabel->move(center);
/*----------------УСТАНОВКА ИНТЕРФЕЙСА-КОНЕЦ--------------------*/
}
MainWindow::~MainWindow() {
delete ui;
}
/* Возвращает такую координату, чтобы отрезок,
* длиной x оказался ровно по центру между begin и end */
int MainWindow::centerXBetweenAB(int x, int begin, int end) {
return begin + (end - begin - x) / 2;
}
void MainWindow::on_pillButton_clicked() {
// получение таблеточек
_pillsCount += _step * _multiplier;
// вывод информации на экран
ui->counterLabel->setText(QString::number(_pillsCount));
ui->stepLabel->setText(tr("+") + QString::number(_step * _multiplier));
/* временный множитель, пропадающий через 2 секунды
* после прекращения кликания. увеличивает свое значение
* каждые 5 кликов на 10 процентов */
++_clicksCount; // был произведен клик
// если 2 секунды еще не прошло
if (_timer->isActive()) {
if (_clicksCount == CLICKS_TO_INC_MULTIPLIER) {
_multiplier += _step * MULTIPLIER_INCREMENT;
_clicksCount = 0;
}
}
// если прошло 2 секунды после последнего клика
else {
nullMultiplier();
}
_timer->start(TIME_TO_NULL_MULTIPLIER);
}
void MainWindow::on_pillButton_pressed() {
ui->pillButton->setIconSize(QSize(_pillSize / 2, _pillSize));
}
void MainWindow::on_pillButton_released() {
ui->pillButton->setIconSize(QSize(_pillSize, _pillSize));
}
// обнуление количества кликов подряд и установка множителя = 1
void MainWindow::nullMultiplier() {
_clicksCount = 0;
_multiplier = 1;
ui->stepLabel->setText("");
}
void MainWindow::on_openUpgradesButton_clicked() {
ui->stackedWidget->setCurrentIndex(1);
}
void MainWindow::on_fromUpgradesToGameButton_clicked() {
ui->stackedWidget->setCurrentIndex(0);
}
void MainWindow::on_fromUpgradesToGameButton_pressed() {
ui->fromUpgradesToGameButton->setIconSize(QSize(45, 50));
}
void MainWindow::on_fromUpgradesToGameButton_released() {
ui->fromUpgradesToGameButton->setIconSize(QSize(50, 50));
}
void MainWindow::on_openUpgradesButton_pressed() {
ui->openUpgradesButton->setIconSize(QSize(45, 50));
}
void MainWindow::on_openUpgradesButton_released() {
ui->openUpgradesButton->setIconSize(QSize(50, 50));
}