forked from hBuzzy/SignalsAndSlots
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.cpp
More file actions
72 lines (55 loc) · 2.32 KB
/
Copy pathwidget.cpp
File metadata and controls
72 lines (55 loc) · 2.32 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
#include "widget.h"
#include <QHBoxLayout>
#include <QLabel>
#include <QPointer>
#include <QProgressBar>
#include <QPushButton>
#include "enemy.h"
#include "player.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) {
ui->setupUi(this);
Player *player = new Player(100);
Enemy *enemy = new Enemy(10);
QProgressBar *healthBar = new QProgressBar;
int minValue = 0;
healthBar->setRange(minValue, player->GetMaxHealth());
healthBar->setValue(player->GetMaxHealth());
healthBar->setTextVisible(false);
QPointer<QLabel> healthBarCaption = new QLabel;
healthBarCaption->setText("Полоска здоровья");
QPointer<QPushButton> damageButton = new QPushButton;
damageButton->setText("Нанести урон");
QWidget *widget = new QWidget;
QGridLayout *widgetLayout = new QGridLayout;
widgetLayout->addWidget(healthBarCaption, 0, 0);
widgetLayout->addWidget(healthBar, 0, 1);
widgetLayout->addWidget(damageButton, 1, 0, 1, 2);
widget->setLayout(widgetLayout);
int spacerWidth = 1;
int spacerHeight = 1;
QSpacerItem *topSpacer = new QSpacerItem(
spacerWidth, spacerHeight, QSizePolicy::Minimum, QSizePolicy::Expanding);
QSpacerItem *bottomSpacer = new QSpacerItem(
spacerWidth, spacerHeight, QSizePolicy::Minimum, QSizePolicy::Expanding);
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
mainLayout->addItem(topSpacer);
mainLayout->addWidget(widget);
mainLayout->addItem(bottomSpacer);
connect(damageButton, &QPushButton::clicked, enemy,
&Enemy::OnDamageButtonClicked);
connect(enemy, &Enemy::MakeDamage, player, &Player::TakeDamage);
connect(player, &Player::HealthChanged, healthBar, &QProgressBar::setValue);
const QString dangerStyle =
"QProgressBar::chunk {background: #F44336; Width: 20px; margin: 0.5px;"
"border: 1px solid black; border-radius:8px; Border-Radius: 4px;} "
"QProgressBar { text-align: center; font-size:14px; border-radius:8px; "
"color:black;}";
const QString normalStyle =
"QProgressBar::chunk {background: #009688; Width: 20px; margin: 0.5px; "
"border: 1px solid black; border-radius:8px; Border-Radius: 4px;} "
"QProgressBar { text-align: center; font-size:14px; border-radius:8px; "
"color:black;}";
}
Widget::~Widget() { delete ui; }