Freeciv-3.3
Loading...
Searching...
No Matches
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/***********************************************************************/
34{
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);
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/***********************************************************************/
70{
71 struct voteinfo *vi;
72
74 if (vi == nullptr) {
75 return;
76 }
78}
79
80/***********************************************************************/
84{
85 struct voteinfo *vi;
86
88 if (vi == nullptr) {
89 return;
90 }
91 voteinfo_do_vote(vi->vote_no, CVT_NO);
92}
93
94/***********************************************************************/
98{
99 struct voteinfo *vi;
100
102 if (vi == nullptr) {
103 return;
104 }
105 voteinfo_do_vote(vi->vote_no, CVT_YES);
106}
107
108/***********************************************************************/
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();
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/***********************************************************************/
181
182/***********************************************************************/
186{
188
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/***********************************************************************/
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/***********************************************************************/
215{
217
218 painter.begin(this);
220 painter.end();
221}
222
223/***********************************************************************/
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}
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
QPushButton * vote_yes
QGridLayout * layout
QLabel * label_vote_text
QLabel * voters
QPushButton * vote_abstain
pregamevote(QWidget *parent=nullptr)
QLabel * lab_abstain
QLabel * lab_yes
QLabel * label_text
QPushButton * vote_no
QLabel * lab_no
void paintEvent(QPaintEvent *event)
void paint(QPainter *painter, QPaintEvent *event)
xvote(QWidget *parent)
char * incite_cost
Definition comments.c:76
enum event_type event
Definition events.c:81
#define _(String)
Definition fcintl.h:67
static enum client_pages current_page
Definition pages.c:78
#define show(id)
Definition widget.h:235
#define hide(id)
Definition widget.h:238
static mpgui * gui
Definition mpgui_qt.cpp:52
Definition colors.h:21
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#define sz_strlcpy(dest, src)
Definition support.h:195
void voteinfo_do_vote(int vote_no, enum client_vote_type vote)
Definition voteinfo.c:234
struct voteinfo * voteinfo_queue_get_current(int *pindex)
Definition voteinfo.c:201
int voteinfo_queue_size(void)
Definition voteinfo.c:291
@ CVT_YES
Definition voteinfo.h:24
@ CVT_NO
Definition voteinfo.h:25
@ CVT_ABSTAIN
Definition voteinfo.h:26
void voteinfo_gui_update(void)