Freeciv-3.3
Loading...
Searching...
No Matches
client
gui-qt
voteinfo_bar.cpp
Go to the documentation of this file.
1
/***********************************************************************
2
Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; either version 2, or (at your option)
6
any later version.
7
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
12
***********************************************************************/
13
14
#ifdef HAVE_CONFIG_H
15
#include <fc_config.h>
16
#endif
17
18
// Qt
19
#include <QGridLayout>
20
#include <QPainter>
21
22
// client
23
#include "
voteinfo.h
"
24
25
// gui-qt
26
#include "
fc_client.h
"
27
28
#include "
voteinfo_bar.h
"
29
30
/***********************************************************************/
33
pregamevote::pregamevote
(QWidget *
parent
)
34
{
35
setParent
(
parent
);
36
layout
=
new
QGridLayout
;
37
label_text
=
new
QLabel;
38
label_vote_text
=
new
QLabel;
39
vote_yes
=
new
QPushButton(
_
(
"Yes"
));
40
vote_no
=
new
QPushButton(
_
(
"No"
));
41
vote_abstain
=
new
QPushButton(
_
(
"Abstain"
));
42
lab_yes
=
new
QLabel;
43
lab_no
=
new
QLabel;
44
lab_abstain
=
new
QLabel;
45
voters
=
new
QLabel;
46
label_text
->setAlignment(Qt::AlignHCenter);
47
label_vote_text
->setAlignment(Qt::AlignHCenter);
48
label_text
->setTextFormat(Qt::RichText);
49
label_vote_text
->setTextFormat(Qt::RichText);
50
layout
->addWidget(
label_text
, 0, 0, 1, 7);
51
layout
->addWidget(
label_vote_text
, 1, 0, 1, 7);
52
layout
->addWidget(
vote_yes
, 2, 0, 1, 1);
53
layout
->addWidget(
vote_no
, 2, 2, 1, 1);
54
layout
->addWidget(
vote_abstain
, 2, 4, 1, 1);
55
layout
->addWidget(
lab_yes
, 2, 1, 1, 1);
56
layout
->addWidget(
lab_no
, 2, 3, 1, 1);
57
layout
->addWidget(
lab_abstain
, 2, 5, 1, 1);
58
layout
->addWidget(
voters
, 2, 6, 1, 1);
59
setLayout
(
layout
);
60
connect(
vote_yes
, &QAbstractButton::clicked,
this
, &
pregamevote::v_yes
);
61
connect(
vote_no
, &QAbstractButton::clicked,
this
, &
pregamevote::v_no
);
62
connect(
vote_abstain
, &QAbstractButton::clicked,
this
, &
pregamevote::v_abstain
);
63
64
}
65
66
/***********************************************************************/
69
void
pregamevote::v_abstain
()
70
{
71
struct
voteinfo
*
vi
;
72
73
vi
=
voteinfo_queue_get_current
(
nullptr
);
74
if
(
vi
==
nullptr
) {
75
return
;
76
}
77
voteinfo_do_vote
(
vi
->vote_no,
CVT_ABSTAIN
);
78
}
79
80
/***********************************************************************/
83
void
pregamevote::v_no
()
84
{
85
struct
voteinfo
*
vi
;
86
87
vi
=
voteinfo_queue_get_current
(
nullptr
);
88
if
(
vi
==
nullptr
) {
89
return
;
90
}
91
voteinfo_do_vote
(
vi
->vote_no,
CVT_NO
);
92
}
93
94
/***********************************************************************/
97
void
pregamevote::v_yes
()
98
{
99
struct
voteinfo
*
vi
;
100
101
vi
=
voteinfo_queue_get_current
(
nullptr
);
102
if
(
vi
==
nullptr
) {
103
return
;
104
}
105
voteinfo_do_vote
(
vi
->vote_no,
CVT_YES
);
106
}
107
108
/***********************************************************************/
111
void
pregamevote::update_vote
()
112
{
113
int
vote_count
, index;
114
struct
voteinfo
*
vi
=
nullptr
;
115
char
buf
[1024], status[1024],
color
[32];
116
bool
running
;
117
118
show
();
119
vote_count
=
voteinfo_queue_size
();
120
vi
=
voteinfo_queue_get_current
(&index);
121
if
(
vi
!=
nullptr
&&
vi
->resolved &&
vi
->passed) {
122
// TRANS: Describing a vote that passed.
123
fc_snprintf
(status,
sizeof
(status),
_
(
"[passed]"
));
124
sz_strlcpy
(
color
,
"green"
);
125
}
else
if
(
vi
!=
nullptr
&&
vi
->resolved && !
vi
->passed) {
126
// TRANS: Describing a vote that failed.
127
fc_snprintf
(status,
sizeof
(status),
_
(
"[failed]"
));
128
sz_strlcpy
(
color
,
"red"
);
129
}
else
if
(
vi
!=
nullptr
&&
vi
->remove_time > 0) {
130
// TRANS: Describing a vote that was removed.
131
fc_snprintf
(status,
sizeof
(status),
_
(
"[removed]"
));
132
sz_strlcpy
(
color
,
"grey"
);
133
}
else
{
134
status[0] =
'\0'
;
135
}
136
if
(status[0] !=
'\0'
) {
137
fc_snprintf
(
buf
,
sizeof
(
buf
),
138
"<b><p style=\"background-color: %s\"> %s</p></b> "
,
139
color
, status);
140
sz_strlcpy
(status,
buf
);
141
}
else
{
142
buf
[0] =
'\0'
;
143
}
144
if
(
vi
!=
nullptr
) {
145
lab_yes
->setText(QString::number(
vi
->yes));
146
lab_no
->setText(QString::number(
vi
->no));
147
lab_abstain
->setText(QString::number(
vi
->abstain));
148
if
(
buf
[0] !=
'\0'
) {
149
label_text
->setText(
buf
);
150
}
else
{
151
label_text
->setText(
QString
(
_
(
"<b>%1 called a vote for:</b>"
)).
152
arg(
QString
(
vi
->user).toHtmlEscaped()));
153
}
154
label_vote_text
->setText(
QString
(
"</b><p style=\"color:"
155
" red\"> %1</p></b>"
)
156
.arg(
QString
(
vi
->desc).toHtmlEscaped()));
157
voters
->setText(
QString
(
" /%1"
).arg(
vi
->num_voters));
158
}
else
{
159
label_text
->setText(
""
);
160
lab_yes
->setText(
"-"
);
161
lab_no
->setText(
"-"
);
162
lab_abstain
->setText(
"-"
);
163
}
164
running
=
vi
!=
nullptr
&& !
vi
->resolved &&
vi
->remove_time == 0;
165
vote_yes
->setEnabled(
running
);
166
vote_no
->setEnabled(
running
);
167
vote_abstain
->setEnabled(
running
);
168
169
if
(
vote_count
< 1) {
170
hide
();
171
}
172
update();
173
}
174
175
/***********************************************************************/
178
pregamevote::~pregamevote
()
179
{
180
}
181
182
/***********************************************************************/
185
xvote::xvote
(QWidget *
parent
) :
pregamevote
(
parent
)
186
{
187
QPalette
palette
;
188
189
setParent
(
parent
);
190
palette
.setColor(QPalette::WindowText,
QColor
(0, 255, 255));
191
label_text
->setPalette(
palette
);
192
label_vote_text
->setPalette(
palette
);
193
palette
.setColor(QPalette::WindowText,
QColor
(255, 255, 0));
194
lab_yes
->setPalette(
palette
);
195
lab_no
->setPalette(
palette
);
196
lab_abstain
->setPalette(
palette
);
197
voters
->setPalette(
palette
);
198
}
199
200
/***********************************************************************/
203
void
xvote::paint
(
QPainter
*
painter
,
QPaintEvent
*
event
)
204
{
205
painter
->setBrush(
QColor
(90, 90, 192, 185));
206
painter
->drawRect(0, 0,
width
(),
height
());
207
painter
->setBrush(
QColor
(90, 90, 192, 185));
208
painter
->drawRect(5, 5,
width
() - 10,
height
() - 10);
209
}
210
211
/***********************************************************************/
214
void
xvote::paintEvent
(
QPaintEvent
*
event
)
215
{
216
QPainter
painter
;
217
218
painter
.begin(
this
);
219
paint
(&
painter
,
event
);
220
painter
.end();
221
}
222
223
/***********************************************************************/
227
void
voteinfo_gui_update
(
void
)
228
{
229
if
(
gui
()->
current_page
() ==
PAGE_START
) {
230
gui
()->pre_vote->update_vote();
231
}
232
if
(
gui
()->
current_page
() ==
PAGE_GAME
) {
233
234
if
(
gui
()->x_vote !=
nullptr
) {
235
gui
()->x_vote->show();
236
gui
()->x_vote->update_vote();
237
}
238
}
239
}
height
struct canvas int int struct sprite int int int int height
Definition
canvas_g.h:44
width
struct canvas int int struct sprite int int int width
Definition
canvas_g.h:44
pregamevote
Definition
voteinfo_bar.h:31
pregamevote::vote_yes
QPushButton * vote_yes
Definition
voteinfo_bar.h:39
pregamevote::layout
QGridLayout * layout
Definition
voteinfo_bar.h:46
pregamevote::label_vote_text
QLabel * label_vote_text
Definition
voteinfo_bar.h:38
pregamevote::v_yes
void v_yes()
Definition
voteinfo_bar.cpp:97
pregamevote::voters
QLabel * voters
Definition
voteinfo_bar.h:45
pregamevote::vote_abstain
QPushButton * vote_abstain
Definition
voteinfo_bar.h:41
pregamevote::v_no
void v_no()
Definition
voteinfo_bar.cpp:83
pregamevote::pregamevote
pregamevote(QWidget *parent=nullptr)
Definition
voteinfo_bar.cpp:33
pregamevote::lab_abstain
QLabel * lab_abstain
Definition
voteinfo_bar.h:44
pregamevote::~pregamevote
~pregamevote()
Definition
voteinfo_bar.cpp:178
pregamevote::v_abstain
void v_abstain()
Definition
voteinfo_bar.cpp:69
pregamevote::lab_yes
QLabel * lab_yes
Definition
voteinfo_bar.h:42
pregamevote::update_vote
void update_vote()
Definition
voteinfo_bar.cpp:111
pregamevote::label_text
QLabel * label_text
Definition
voteinfo_bar.h:37
pregamevote::vote_no
QPushButton * vote_no
Definition
voteinfo_bar.h:40
pregamevote::lab_no
QLabel * lab_no
Definition
voteinfo_bar.h:43
xvote::paintEvent
void paintEvent(QPaintEvent *event)
Definition
voteinfo_bar.cpp:214
xvote::paint
void paint(QPainter *painter, QPaintEvent *event)
Definition
voteinfo_bar.cpp:203
xvote::xvote
xvote(QWidget *parent)
Definition
voteinfo_bar.cpp:185
incite_cost
char * incite_cost
Definition
comments.c:76
event
enum event_type event
Definition
events.c:81
fc_client.h
_
#define _(String)
Definition
fcintl.h:67
current_page
static enum client_pages current_page
Definition
pages.c:78
show
#define show(id)
Definition
widget.h:235
hide
#define hide(id)
Definition
widget.h:238
voteinfo_bar.h
gui
static mpgui * gui
Definition
mpgui_qt.cpp:52
color
Definition
colors.h:21
voteinfo
Definition
voteinfo.h:29
fc_snprintf
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition
support.c:960
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition
support.h:195
voteinfo_do_vote
void voteinfo_do_vote(int vote_no, enum client_vote_type vote)
Definition
voteinfo.c:234
voteinfo_queue_get_current
struct voteinfo * voteinfo_queue_get_current(int *pindex)
Definition
voteinfo.c:201
voteinfo_queue_size
int voteinfo_queue_size(void)
Definition
voteinfo.c:291
voteinfo.h
CVT_YES
@ CVT_YES
Definition
voteinfo.h:24
CVT_NO
@ CVT_NO
Definition
voteinfo.h:25
CVT_ABSTAIN
@ CVT_ABSTAIN
Definition
voteinfo.h:26
voteinfo_gui_update
void voteinfo_gui_update(void)
Definition
voteinfo_bar.cpp:227
Generated on Sun Dec 22 2024 22:30:35 for Freeciv-3.3 by
1.9.8