Freeciv-3.4
Loading...
Searching...
No Matches
citydlg.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 <QApplication>
20#include <QCheckBox>
21#include <QGroupBox>
22#include <QHeaderView>
23#include <QImage>
24#include <QMenu>
25#include <QMessageBox>
26#include <QPainter>
27#include <QRadioButton>
28#include <QRect>
29#include <QScreen>
30#include <QScrollArea>
31#include <QScrollBar>
32#include <QSplitter>
33#include <QToolTip>
34#include <QVBoxLayout>
35#include <QWheelEvent>
36#include <QWidgetAction>
37
38// utility
39#include "support.h"
40
41// common
42#include "citizens.h"
43#include "city.h"
44#include "counters.h"
45#include "game.h"
46
47//agents
48#include "cma_core.h"
49#include "cma_fec.h"
50
51// client
52#include "citydlg_common.h"
53#include "client_main.h"
54#include "climisc.h"
55#include "control.h"
56#include "global_worklist.h"
57#include "helpdata.h"
58#include "mapview_common.h"
59#include "movement.h"
60#include "sprite.h"
61#include "text.h"
62#include "tilespec.h"
63
64// gui-qt
65#include "citydlg.h"
66#include "colors.h"
67#include "fc_client.h"
68#include "gui_main.h"
69#include "hudwidget.h"
70
71static bool city_dlg_created = false;
76extern QString split_text(QString text, bool cut);
77extern QString cut_helptext(QString text);
78
79/************************************************************************/
83{
84 m_timer.start();
85 startTimer(50);
87 sfont = new QFont;
89 pix = nullptr;
90}
91
92/************************************************************************/
96{
97 if (pix != nullptr) {
98 delete pix;
99 }
100 delete sfont;
101}
102
103/************************************************************************/
110
111/************************************************************************/
115{
116 struct sprite *sprite;
118 QImage img;
120 QRect crop;
121
122 if (VUT_UTYPE == target->kind) {
125 } else {
127 }
128 if (pix != nullptr) {
129 delete pix;
130 }
131 if (sprite == nullptr) {
132 pix = nullptr;
133 return;
134 }
135 img = sprite->pm->toImage();
137 cropped_img = img.copy(crop);
138 tpix = QPixmap::fromImage(cropped_img);
139 pix = new QPixmap(tpix.width(), tpix.height());
140 pix->fill(Qt::transparent);
141 pixmap_copy(pix, &tpix, 0 , 0, 0, 0, tpix.width(), tpix.height());
142}
143
144/************************************************************************/
148{
149 struct sprite *sprite;
150
153 } else {
154 sprite = nullptr;
155 }
156 if (pix != nullptr) {
157 delete pix;
158 }
159 if (sprite == nullptr) {
160 pix = nullptr;
161 return;
162 }
163 pix = new QPixmap(sprite->pm->width(),
164 sprite->pm->height());
165 pix->fill(Qt::transparent);
166 pixmap_copy(pix, sprite->pm, 0 , 0, 0, 0,
167 sprite->pm->width(), sprite->pm->height());
168 if (isVisible()) {
169 update();
170 }
171}
172
173/************************************************************************/
177{
178 if ((value() != minimum() && value() < maximum())
179 || (0 == minimum() && 0 == maximum())) {
180 m_animate_step = m_timer.elapsed() / 50;
181 update();
182 }
183}
184
185/************************************************************************/
189{
190 QPainter p;
192 QColor c;
193 QRect r, rx, r2;
194 int max;
195 int f_pixel_size;
196 int pix_width = 0;
197 int pixel_size = sfont->pixelSize();
198 int pbw, pbh;
199
200 if (pix != nullptr) {
201 pix_width = height() - 4;
202 }
203
204 if (pixel_size > 0) {
206 } else {
208
209 f_pixel_size = fm.height();
210 }
211
212 pbw = width();
213 pbh = height();
214
215 rx.setX(0);
216 rx.setY(0);
217 rx.setWidth(pbw);
218 rx.setHeight(pbh);
219 p.begin(this);
220 p.drawLine(rx.topLeft(), rx.topRight());
221 p.drawLine(rx.bottomLeft(), rx.bottomRight());
222
223 max = maximum();
224
225 if (max == 0) {
226 max = 1;
227 }
228
229 r = QRect(0, 0, pbw * value() / max, pbh);
230
231 gx = QLinearGradient(0 , 0, 0, pbh);
232 c = QColor(palette().color(QPalette::Highlight));
233 gx.setColorAt(0, c);
234 gx.setColorAt(0.5, QColor(40, 40, 40));
235 gx.setColorAt(1, c);
236 p.fillRect(r, QBrush(gx));
237 p.setClipRegion(reg.translated(m_animate_step % 32, 0));
238
239 g = QLinearGradient(0 , 0, pbw, pbh);
240 c.setAlphaF(0.1);
241 g.setColorAt(0, c);
242 c.setAlphaF(0.9);
243 g.setColorAt(1, c);
244 p.fillRect(r, QBrush(g));
245
246 p.setClipping(false);
247 r2 = QRect(pbw * value() / max, 0, pbw, pbh);
248 c = palette().color(QPalette::Window);
249 p.fillRect(r2, c);
250
251 // Draw icon
252 if (pix != nullptr) {
253 p.setCompositionMode(QPainter::CompositionMode_SourceOver);
254 p.drawPixmap(2 , 2, pix_width
255 * static_cast<float>(pix->width()) / pix->height(),
256 pix_width, *pix, 0, 0, pix->width(), pix->height());
257 }
258
259 // Draw text
260 c = palette().color(QPalette::Text);
261 p.setPen(c);
262 sfont->setCapitalization(QFont::AllUppercase);
263 sfont->setBold(true);
264
265 if (text().contains('\n')) {
266 QString s1, s2;
267 int i, j;
268 QFont tmp_font = *sfont; // Don't make changes to font to be kept
269
270 i = text().indexOf('\n');
271 s1 = text().left(i);
272 s2 = text().right(text().length() - i);
273
274 if (2 * f_pixel_size >= 3 * pbh / 2) {
275 tmp_font.setPixelSize(pbh / 3);
276 }
277
278 p.setFont(tmp_font);
279
280 j = pbh - 2 * f_pixel_size;
281 p.setCompositionMode(QPainter::CompositionMode_ColorDodge);
283
284 if (fm.horizontalAdvance(s1) > rx.width()) {
285 s1 = fm.elidedText(s1, Qt::ElideRight, rx.width());
286 }
287
288 i = rx.width() - fm.horizontalAdvance(s1) + pix_width;
289 i = qMax(0, i);
290 p.drawText(i / 2, j / 3 + f_pixel_size, s1);
291
292 if (fm.horizontalAdvance(s2) > rx.width()) {
293 s2 = fm.elidedText(s2, Qt::ElideRight, rx.width());
294 }
295
296 i = rx.width() - fm.horizontalAdvance(s2) + pix_width;
297 i = qMax(0, i);
298
299 p.drawText(i / 2, pbh - j / 3, s2);
300 } else {
301 QString s;
302 int i, j;
303
304 p.setFont(*sfont);
305
306 s = text();
307 j = pbh - f_pixel_size;
308 p.setCompositionMode(QPainter::CompositionMode_ColorDodge);
310
311 if (fm.horizontalAdvance(s) > rx.width()) {
312 s = fm.elidedText(s, Qt::ElideRight, rx.width());
313 }
314
315 i = rx.width() - fm.horizontalAdvance(s) + pix_width;
316 i = qMax(0, i);
317 p.drawText(i / 2, j / 2 + f_pixel_size, s);
318 }
319
320 p.end();
321}
322
323/************************************************************************/
327{
328 int offset;
329 QRect r(-50, 0, width() + 50, height());
330 int chunk_width = 16;
331 int size = width() + 50;
332 reg = QRegion();
333
334 for (offset = 0; offset < (size * 2); offset += (chunk_width * 2)) {
335 QPolygon a;
336
337 a.setPoints(4, r.x(), r.y() + offset,
338 r.x() + r.width(), (r.y() + offset) - size,
339 r.x() + r.width(),
340 (r.y() + offset + chunk_width) - size,
341 r.x(), r.y() + offset + chunk_width);
342 reg += QRegion(a);
343 }
344
345}
346
347/************************************************************************/
350static void pixmap_put_x(QPixmap *pix)
351{
352 QPen pen(QColor(0, 0, 0));
353 QPainter p;
354
355 pen.setWidth(2);
356 p.begin(pix);
357 p.setRenderHint(QPainter::Antialiasing);
358 p.setPen(pen);
359 p.drawLine(0, 0, pix->width(), pix->height());
360 p.drawLine(pix->width(), 0, 0, pix->height());
361 p.end();
362}
363
364/************************************************************************/
367impr_item::impr_item(QWidget *parent, const impr_type *building,
368 struct city *pcity): QLabel(parent)
369{
371 dlgcity = pcity;
372 impr = building;
373 impr_pixmap = nullptr;
374 struct sprite *sprite;
375 sprite = get_building_sprite(tileset , building);
376
377 if (sprite != nullptr) {
379 sprite->pm->height());
380 impr_pixmap->map_pixmap.fill(Qt::transparent);
381 pixmap_copy(&impr_pixmap->map_pixmap, sprite->pm, 0 , 0, 0, 0,
382 sprite->pm->width(), sprite->pm->height());
383 } else {
385 impr_pixmap->map_pixmap.fill(Qt::red);
386 }
387
391}
392
393/************************************************************************/
397{
398 if (impr_pixmap) {
400 }
401}
402
403/************************************************************************/
407{
409 update();
410}
411
412/************************************************************************/
416{
417 struct sprite *sprite;
418 QPainter p;
419
420 if (impr_pixmap) {
422 }
423
425 if (impr && sprite) {
427 sprite->pm->height());
428 impr_pixmap->map_pixmap.fill(QColor(palette().color(QPalette::Highlight)));
429 pixmap_copy(&impr_pixmap->map_pixmap, sprite->pm, 0 , 0, 0, 0,
430 sprite->pm->width(), sprite->pm->height());
431 } else {
433 impr_pixmap->map_pixmap.fill(QColor(palette().color(QPalette::Highlight)));
434 }
435
436 init_pix();
437}
438
439/************************************************************************/
443{
444 struct sprite *sprite;
445
446 if (impr_pixmap) {
448 }
449
451 if (impr && sprite) {
453 sprite->pm->height());
454 impr_pixmap->map_pixmap.fill(Qt::transparent);
455 pixmap_copy(&impr_pixmap->map_pixmap, sprite->pm, 0 , 0, 0, 0,
456 sprite->pm->width(), sprite->pm->height());
457 } else {
459 impr_pixmap->map_pixmap.fill(Qt::red);
460 }
461
462 init_pix();
463}
464
465/************************************************************************/
469{
471 layout = new QHBoxLayout(this);
472 init_layout();
473}
474
475/************************************************************************/
479{
480 QSizePolicy size_fixed_policy(QSizePolicy::Fixed,
481 QSizePolicy::MinimumExpanding,
482 QSizePolicy::Slider);
483
486}
487
488/************************************************************************/
492{
493
494}
495
496/************************************************************************/
500{
501 impr_list.append(item);
502}
503
504/************************************************************************/
508{
509 int i = impr_list.count();
510 impr_item *ui;
511 int j;
512 setUpdatesEnabled(false);
513 setMouseTracking(false);
514
515 for (j = 0; j < i; j++) {
516 ui = impr_list[j];
517 layout->removeWidget(ui);
518 delete ui;
519 }
520
521 while (!impr_list.empty()) {
522 impr_list.removeFirst();
523 }
524
525 setMouseTracking(true);
526 setUpdatesEnabled(true);
527}
528
529/************************************************************************/
533{
534 QPoint p;
535
536 p = parentWidget()->parentWidget()->pos();
537 p = mapToGlobal(p);
538
539 QWheelEvent new_event(QPoint(5, 5), p + QPoint(5,5), event->pixelDelta(),
540 event->angleDelta(),
541 event->buttons(),
542 event->modifiers(),
543 event->phase(), false, event->source());
544
545 QApplication::sendEvent(parentWidget(), &new_event);
546}
547
548/************************************************************************/
552{
553 int i = impr_list.count();
554 int j;
555 int h = 0;
556 impr_item *ui;
557
558 setUpdatesEnabled(false);
559 hide();
560
561 for (j = 0; j < i; j++) {
562 ui = impr_list[j];
563 h = ui->height();
564 layout->addWidget(ui, 0, Qt::AlignVCenter);
565 }
566
567 if (impr_list.count() > 0) {
568 parentWidget()->parentWidget()->setFixedHeight(city_dlg->scroll_height
569 + h + 6);
570 } else {
571 parentWidget()->parentWidget()->setFixedHeight(0);
572 }
573
574 show();
575 setUpdatesEnabled(true);
576 layout->update();
578}
579
580/************************************************************************/
584{
585 QPoint p;
586
587 p = parentWidget()->parentWidget()->pos();
588 p = mapToGlobal(p);
589
590 QWheelEvent new_event(QPoint(5, 5), p + QPoint(5,5), event->pixelDelta(),
591 event->angleDelta(),
592 event->buttons(),
593 event->modifiers(),
594 event->phase(), false, event->source());
595
596 QApplication::sendEvent(parentWidget()->parentWidget(),
597 &new_event);
598}
599
600/************************************************************************/
604{
606 return;
607 }
608
609 if (event->button() == Qt::LeftButton) {
610 char buf[256];
611 int price;
612 const int impr_id = improvement_number(impr);
613 const int city_id = dlgcity->id;
615
617 impr) != TR_SUCCESS) {
618 return;
619 }
620
622
625 PL_("Sell %s for %d gold?",
626 "Sell %s for %d gold?", price),
628
629 ask->set_text_title(buf, (_("Sell improvement?")));
630 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
631 ask->setAttribute(Qt::WA_DeleteOnClose);
632 connect(ask, &hud_message_box::accepted, [=]() {
633 struct city *pcity = game_city_by_number(city_id);
634
635 if (pcity == nullptr) {
636 return;
637 }
639 });
640 ask->show();
641 }
642}
643
644/************************************************************************/
648 bool supp, int hppy_cost) : QLabel()
649{
652 QImage img;
653 QRect crop;
654 qunit = punit;
655 struct canvas *unit_pixmap;
656 struct tileset *tmp;
657 float isosize;
658
660 supported = supp;
661
662 tmp = nullptr;
663 if (unscaled_tileset) {
664 tmp = tileset;
666 }
667 isosize = 0.6;
669 isosize = 0.45;
670 }
671
672 if (punit) {
673 if (supported) {
676 } else {
679 }
680
681 unit_pixmap->map_pixmap.fill(Qt::transparent);
682 put_unit(punit, unit_pixmap, 1.0, 0, 0);
683
684 if (supported) {
688 }
689 } else {
691 unit_pixmap->map_pixmap.fill(Qt::transparent);
692 }
693
694 img = unit_pixmap->map_pixmap.toImage();
696 cropped_img = img.copy(crop);
699 * isosize, Qt::SmoothTransformation);
700 } else {
702 Qt::SmoothTransformation);
703 }
705 if (tmp != nullptr) {
706 tileset = tmp;
707 }
708
710 setFixedWidth(unit_img.width() + 4);
711 setFixedHeight(unit_img.height());
713}
714
715/************************************************************************/
719{
720 setPixmap(QPixmap::fromImage(unit_img));
721 update();
722}
723
724/************************************************************************/
730
731/************************************************************************/
735{
736 QMenu *menu;
737
739 return;
740 }
741
742 if (unit_owner(qunit) != client_player()) {
743 return;
744 }
745
746 menu = new QMenu(gui()->central_wdg);
747 menu->addAction(activate);
748 menu->addAction(activate_and_close);
749
750 if (sentry) {
751 menu->addAction(sentry);
752 }
753
754 if (fortify) {
755 menu->addAction(fortify);
756 }
757
758 if (change_home) {
759 menu->addAction(change_home);
760 }
761
762 if (load) {
763 menu->addAction(load);
764 }
765
766 if (unload) {
767 menu->addAction(unload);
768 }
769
770 if (unload_trans) {
771 menu->addAction(unload_trans);
772 }
773
774 if (disband_action) {
775 menu->addAction(disband_action);
776 }
777
778 if (upgrade) {
779 menu->addAction(upgrade);
780 }
781
782 menu->popup(event->globalPos());
783}
784
785/************************************************************************/
789{
790 struct unit_list *qunits;
791
793 return;
794 }
795
798 activate = new QAction(_("Activate unit"), this);
799 connect(activate, &QAction::triggered, this, &unit_item::activate_unit);
800 activate_and_close = new QAction(_("Activate and close dialog"), this);
801 connect(activate_and_close, &QAction::triggered, this,
803
805 sentry = new QAction(_("Sentry unit"), this);
806 connect(sentry, &QAction::triggered, this, &unit_item::sentry_unit);
807 } else {
808 sentry = nullptr;
809 }
810
812 fortify = new QAction(_("Fortify unit"), this);
813 connect(fortify, &QAction::triggered, this, &unit_item::fortify_unit);
814 } else {
815 fortify = nullptr;
816 }
818 disband_action = new QAction(_("Disband unit"), this);
819 connect(disband_action, &QAction::triggered, this, &unit_item::disband);
820 } else {
821 disband_action = nullptr;
822 }
823
826 this);
827 connect(change_home, &QAction::triggered, this, &unit_item::change_homecity);
828 } else {
829 change_home = nullptr;
830 }
831
832 if (units_can_load(qunits)) {
833 load = new QAction(_("Load"), this);
834 connect(load, &QAction::triggered, this, &unit_item::load_unit);
835 } else {
836 load = nullptr;
837 }
838
839 if (units_can_unload(&(wld.map), qunits)) {
840 unload = new QAction(_("Unload"), this);
841 connect(unload, &QAction::triggered, this, &unit_item::unload_unit);
842 } else {
843 unload = nullptr;
844 }
845
847 unload_trans = new QAction(_("Unload All From Transporter"), this);
848 connect(unload_trans, &QAction::triggered, this, &unit_item::unload_all);
849 } else {
850 unload_trans = nullptr;
851 }
852
853 if (units_can_upgrade(&(wld.map), qunits)) {
854 upgrade = new QAction(_("Upgrade Unit"), this);
855 connect(upgrade, &QAction::triggered, this, &unit_item::upgrade_unit);
856 } else {
857 upgrade = nullptr;
858 }
859
861}
862
863/************************************************************************/
867{
868 struct unit_list *punits;
870
871 if (punit == nullptr) {
872 return;
873 }
874
879}
880
881/************************************************************************/
888
889/************************************************************************/
896
897/************************************************************************/
904
905/************************************************************************/
916
917/************************************************************************/
926
927/************************************************************************/
937
938/************************************************************************/
942{
943 if (qunit) {
945 }
946}
947
948/************************************************************************/
952{
953 if (qunit) {
955 }
956}
957
958/************************************************************************/
962{
963 QImage temp_img(unit_img.size(), QImage::Format_ARGB32_Premultiplied);
964 QPainter p;
965
966 p.begin(&temp_img);
967 p.fillRect(0, 0, unit_img.width(), unit_img.height(),
968 QColor(palette().color(QPalette::Highlight)));
969 p.drawImage(0, 0, unit_img);
970 p.end();
971
972 setPixmap(QPixmap::fromImage(temp_img));
973 update();
974}
975
976/************************************************************************/
980{
981 init_pix();
982}
983
984/************************************************************************/
988{
989 QPoint p;
990
991 p = parentWidget()->parentWidget()->pos();
992 p = mapToGlobal(p);
993
994 QWheelEvent new_event(QPoint(5, 5), p + QPoint(5,5), event->pixelDelta(),
995 event->angleDelta(),
996 event->buttons(),
997 event->modifiers(),
998 event->phase(), false, event->source());
999
1000 QApplication::sendEvent(parentWidget()->parentWidget(),
1001 &new_event);
1002}
1003
1004/************************************************************************/
1008{
1009 if (event->button() == Qt::LeftButton) {
1010 if (qunit) {
1013 }
1014 }
1015}
1016
1017/************************************************************************/
1021{
1022 if (qunit) {
1024 }
1025}
1026
1027/************************************************************************/
1031{
1032 layout = new QHBoxLayout(this);
1033 init_layout();
1034 supports = supp;
1035}
1036
1037/************************************************************************/
1041{
1043 unit_list.clear();
1044}
1045
1046/************************************************************************/
1050{
1051 unit_list.append(item);
1052}
1053
1054/************************************************************************/
1058{
1059 QSizePolicy size_fixed_policy(QSizePolicy::Fixed,
1060 QSizePolicy::MinimumExpanding,
1061 QSizePolicy::Slider);
1064}
1065
1066/************************************************************************/
1070{
1071 QPoint p;
1072
1073 p = parentWidget()->parentWidget()->pos();
1074 p = mapToGlobal(p);
1075
1076 QWheelEvent new_event(QPoint(5, 5), p + QPoint(5,5), event->pixelDelta(),
1077 event->angleDelta(),
1078 event->buttons(),
1079 event->modifiers(),
1080 event->phase(), false, event->source());
1081
1082 QApplication::sendEvent(parentWidget(), &new_event);
1083}
1084
1085/************************************************************************/
1089{
1090 int i = unit_list.count();
1091 int j;
1092 int h;
1093 float hexfix;
1094 unit_item *ui;
1095
1096 setUpdatesEnabled(false);
1097 hide();
1098
1099 for (j = 0; j < i; j++) {
1100 ui = unit_list[j];
1101 layout->addWidget(ui, 0, Qt::AlignVCenter);
1102 }
1103
1104 hexfix = 1.0;
1106 hexfix = 0.75;
1107 }
1108
1110 h = tileset_unit_width(get_tileset()) * 0.7 * hexfix + 6;
1111 } else {
1113 }
1114 if (unit_list.count() > 0) {
1115 parentWidget()->parentWidget()->setFixedHeight(city_dlg->scroll_height
1116 + h);
1117 } else {
1118 parentWidget()->parentWidget()->setFixedHeight(0);
1119 }
1120 show();
1121 setUpdatesEnabled(true);
1122 layout->update();
1124}
1125
1126/************************************************************************/
1130{
1131 int i = unit_list.count();
1132 unit_item *ui;
1133 int j;
1134 setUpdatesEnabled(false);
1135 setMouseTracking(false);
1136
1137 for (j = 0; j < i; j++) {
1138 ui = unit_list[j];
1139 layout->removeWidget(ui);
1140 delete ui;
1141 }
1142
1143 while (!unit_list.empty()) {
1144 unit_list.removeFirst();
1145 }
1146
1147 setMouseTracking(true);
1148 setUpdatesEnabled(true);
1149}
1150
1151/************************************************************************/
1155city_label::city_label(int t, QWidget *parent) : QLabel(parent)
1156{
1157 type = t;
1158}
1159
1160/************************************************************************/
1164{
1165 int citnum, i;
1166 int w = tileset_small_sprite_width(tileset) / gui()->map_scale;
1167 int num_citizens = pcity->size;
1168
1169 if (cma_is_city_under_agent(pcity, nullptr)) {
1170 return;
1171 }
1172
1173 i = 1 + (num_citizens * 5 / 200);
1174 w = w / i;
1175 citnum = event->pos().x() / w;
1176
1177 if (!can_client_issue_orders()) {
1178 return;
1179 }
1180
1182}
1183
1184/************************************************************************/
1188{
1189 pcity = pciti;
1190}
1191
1192/************************************************************************/
1196{
1198 radius = 0;
1204 view->map_pixmap.fill(Qt::black);
1206 miniview->map_pixmap.fill(Qt::black);
1207 delta_x = 0;
1208 delta_y = 0;
1209 setContextMenuPolicy(Qt::CustomContextMenu);
1210 connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
1211 this, SLOT(context_menu(const QPoint &)));
1212}
1213
1214/************************************************************************/
1222
1223/************************************************************************/
1227{
1229 QString str;
1230
1231 painter.begin(this);
1232 painter.drawPixmap(0, 0, zoomed_pixmap);
1233
1234 if (cma_is_city_under_agent(mcity, nullptr)) {
1235 painter.fillRect(0, 0, zoomed_pixmap.width(), zoomed_pixmap.height(),
1236 QBrush(QColor(60, 60 , 60 , 110)));
1237 painter.setPen(QColor(255, 255, 255));
1238 // TRANS: %1 is a custom string chosen by player.
1239 str = QString(_("Governor %1"))
1241 painter.drawText(5, zoomed_pixmap.height() - 10, str);
1242 }
1243
1244 painter.end();
1245}
1246
1247/************************************************************************/
1250void city_map::set_pixmap(struct city *pcity, float z)
1251{
1252 int r, max_r;
1253 QSize size;
1254
1255 zoom = z;
1257
1258 if (radius != r) {
1260 radius = r;
1262 cutted_width = wdth * (r + 1) / max_r;
1263 cutted_height = height * (r + 1) / max_r;
1266 delta_x = (wdth - cutted_width) / 2;
1267 delta_y = (height - cutted_height) / 2;
1269 miniview->map_pixmap.fill(Qt::black);
1270 }
1271
1275 size = miniview->map_pixmap.size();
1277 Qt::KeepAspectRatio,
1278 Qt::SmoothTransformation);
1280 mcity = pcity;
1281}
1282
1283/************************************************************************/
1287{
1288 return zoomed_pixmap.size();
1289}
1290
1291/************************************************************************/
1295{
1296 return zoomed_pixmap.size();
1297}
1298
1299/************************************************************************/
1303{
1305 QPoint pos;
1306
1307 if (!can_client_issue_orders() || event->button() != Qt::LeftButton) {
1308 return;
1309 }
1310
1311 pos = event->pos();
1312 canvas_x = pos.x() / zoom + delta_x;
1313 canvas_y = pos.y() / zoom + delta_y;
1314
1316 canvas_x, canvas_y)) {
1318 }
1319}
1320
1321/************************************************************************/
1325{
1327 QAction *con_cultivate = nullptr;
1328 QAction *con_irrig = nullptr;
1329 QAction *con_plant = nullptr;
1330 QAction *con_mine = nullptr;
1331 QAction *con_road = nullptr;
1332 QAction *con_trfrm = nullptr;
1333 QAction *con_clean = nullptr;
1334 QAction *con_clear = nullptr;
1335 QMenu *con_menu;
1337 struct terrain *pterr;
1338 struct tile *ptile;
1339 struct universal for_terr;
1340 struct worker_task *ptask;
1341 int city_id = mcity->id;
1342
1343 if (!can_client_issue_orders()) {
1344 return;
1345 }
1346
1347 canvas_x = point.x() / zoom + delta_x;
1348 canvas_y = point.y() / zoom + delta_y;
1349
1351 canvas_x, canvas_y)) {
1352 return;
1353 }
1354
1356 city_x, city_y);
1357 pterr = tile_terrain(ptile);
1358 for_terr.kind = VUT_TERRAIN;
1359 for_terr.value.terrain = pterr;
1361
1362 wid_act = new QWidgetAction(this);
1363 wid_act->setDefaultWidget(new QLabel(_("Autoworker activity:")));
1364
1365 con_menu = new QMenu(this);
1366 con_menu->addAction(wid_act);
1367
1368 if (pterr->plant_result != nullptr
1370 con_plant = con_menu->addAction(_("Plant"));
1371 }
1373 con_mine = con_menu->addAction(Q_("?act:Mine"));
1374 }
1375
1376 if (pterr->cultivate_result != nullptr
1378 con_cultivate = con_menu->addAction(_("Cultivate"));
1379 }
1381 con_irrig = con_menu->addAction(_("Irrigate"));
1382 }
1383
1384 if (pterr->transform_result != pterr && pterr->transform_result != nullptr
1386 nullptr, &for_terr)) {
1387 con_trfrm = con_menu->addAction(_("Transform"));
1388 }
1389
1390 if (next_extra_for_tile(ptile, EC_ROAD, city_owner(mcity), nullptr) != nullptr) {
1391 con_road = con_menu->addAction(_("Road"));
1392 }
1393
1394 if (prev_extra_in_tile(ptile, ERM_CLEAN,
1395 city_owner(mcity), nullptr) != nullptr) {
1396 con_clean = con_menu->addAction(_("Clean"));
1397 }
1398
1399 if (ptask != nullptr) {
1400 con_clear = con_menu->addAction(_("Clear"));
1401 }
1402
1403 con_menu->setAttribute(Qt::WA_DeleteOnClose);
1404 connect(con_menu, &QMenu::triggered,
1406 bool target = false;
1407 struct packet_worker_task task;
1408
1409 if (!act) {
1410 return;
1411 }
1412
1413 task.city_id = city_id;
1414
1415 if (act == con_road) {
1417 target = TRUE;
1418 } else if (act == con_mine) {
1419 task.activity = ACTIVITY_MINE;
1420 target = TRUE;
1421 } else if (act == con_plant) {
1422 task.activity = ACTIVITY_PLANT;
1423 } else if (act == con_irrig) {
1425 target = TRUE;
1426 } else if (act == con_cultivate) {
1428 } else if (act == con_trfrm) {
1430 } else if (act == con_clean) {
1431 task.activity = ACTIVITY_CLEAN;
1432 target = TRUE;
1433 } else if (act == con_clear) {
1434 task.activity = ACTIVITY_LAST;
1435 } else {
1436 // Closed dialog without selecting any activity entry.
1437 return;
1438 }
1439
1440 task.want = 100;
1441
1442 if (target) {
1443 enum extra_cause cause = activity_to_extra_cause(task.activity);
1445 struct extra_type *tgt;
1446
1447 if (cause != EC_NONE) {
1448 tgt = next_extra_for_tile(ptile, cause, city_owner(mcity), nullptr);
1449 } else if (rmcause != ERM_NONE) {
1450 tgt = prev_extra_in_tile(ptile, rmcause, city_owner(mcity), nullptr);
1451 } else {
1452 tgt = nullptr;
1453 }
1454
1455 if (tgt != nullptr) {
1456 task.tgt = extra_index(tgt);
1457 } else {
1458 task.tgt = -1;
1459 }
1460 } else {
1461 task.tgt = -1;
1462 }
1463
1464 task.tile_id = ptile->index;
1466 });
1467
1468 con_menu->popup(mapToGlobal(point));
1469}
1470
1471/************************************************************************/
1475{
1476 QFont f = QApplication::font();
1477 QFont *small_font;
1478 QFontMetrics fm(f);
1484 QHeaderView *header;
1485 QLabel *lab2, *label, *ql, *some_label;
1486 QPushButton *qpush2;
1488 QSizePolicy size_expanding_policy(QSizePolicy::Expanding,
1489 QSizePolicy::Expanding);
1490 QSlider *slider;
1491 QStringList info_list, str_list;
1496 int list_size;
1497 int h = 2 * fm.height() + 2;
1498
1501 zoom = 1.0;
1502
1504 central_splitter->setOpaqueResize(false);
1506 central_left_splitter->setOpaqueResize(false);
1508 prod_unit_splitter->setOpaqueResize(false);
1509
1510 setMouseTracking(true);
1511 selected_row_p = -1;
1512 dlgcity = nullptr;
1513 lcity_name = new QPushButton(this);
1514 lcity_name->setToolTip(_("Click to change city name"));
1515
1517 single_page_layout->setContentsMargins(0, 0 ,0 ,0);
1518 size_expanding_policy.setHorizontalStretch(0);
1519 size_expanding_policy.setVerticalStretch(0);
1521 current_building = 0;
1522
1523 // Map view
1524 map_box = new QGroupBox(this);
1525
1526 // City information widget texts about surpluses and so on
1527 info_wdg = new QWidget(this);
1528
1529 // Fill info_wdg with labels
1531
1532 info_wdg->setFont(*small_font);
1533 info_grid_layout->setSpacing(0);
1534 info_grid_layout->setContentsMargins(0, 0, 0, 0);
1535
1536
1537 for (enum city_info info_field = city_info_begin();
1540
1541 ql = new QLabel(_(city_info_name(info_field)), info_wdg);
1542 ql->setFont(*small_font);
1543 ql->setProperty(fonts::notify_label, "true");
1544 info_grid_layout->addWidget(ql, info_field, 0);
1545 qlt[info_field] = new QLabel(info_wdg);
1546 qlt[info_field]->setFont(*small_font);
1547 qlt[info_field]->setProperty(fonts::notify_label, "true");
1548 info_grid_layout->addWidget(qlt[info_field], info_field, 1);
1549 info_grid_layout->setRowStretch(info_field, 0);
1550 }
1551
1552 info_wdg->setLayout(info_grid_layout);
1553
1554 // Buy button
1555 buy_button = new QPushButton();
1556 buy_button->setIcon(fc_icons::instance()->get_icon("help-donate"));
1557 connect(buy_button, &QAbstractButton::clicked, this, &city_dialog::buy);
1558
1559 connect(lcity_name, &QAbstractButton::clicked, this, &city_dialog::city_rename);
1561 citizen_pixmap = nullptr;
1562 view = new city_map(this);
1563
1564 zoom_vbox = new QVBoxLayout();
1565 zoom_in_button = new QPushButton();
1566 zoom_in_button->setIcon(fc_icons::instance()->get_icon("plus"));
1567 zoom_in_button->setIconSize(QSize(16, 16));
1568 zoom_in_button->setFixedSize(QSize(20, 20));
1569 zoom_in_button->setToolTip(_("Zoom in"));
1570 connect(zoom_in_button, &QAbstractButton::clicked, this, &city_dialog::zoom_in);
1571 zoom_out_button = new QPushButton();
1572 zoom_out_button->setIcon(fc_icons::instance()->get_icon("minus"));
1573 zoom_out_button->setIconSize(QSize(16, 16));
1574 zoom_out_button->setFixedSize(QSize(20, 20));
1575 zoom_out_button->setToolTip(_("Zoom out"));
1576 connect(zoom_out_button, &QAbstractButton::clicked, this, &city_dialog::zoom_out);
1577 zoom_vbox->addWidget(zoom_in_button);
1578 zoom_vbox->addWidget(zoom_out_button);
1579
1580 // City map group box
1583 hbox_layout->addStretch(100);
1584 hbox_layout->addWidget(view);
1585 hbox_layout->addStretch(100);
1586 hbox_layout->addLayout(zoom_vbox);
1587 vbox_layout->addLayout(hbox_layout);
1588 vbox_layout->addWidget(lcity_name);
1589 map_box->setLayout(vbox_layout);
1590 map_box->setTitle(_("City map"));
1591
1592 // Current/supported units/improvements widgets
1593 supp_units = new QLabel();
1594 curr_units = new QLabel();
1595 curr_impr = new QLabel();
1596 curr_units->setAlignment(Qt::AlignLeft);
1597 curr_impr->setAlignment(Qt::AlignLeft);
1598 supp_units->setAlignment(Qt::AlignLeft);
1599 supported_units = new unit_info(true);
1600 scroll = new QScrollArea;
1601 scroll->setWidgetResizable(true);
1602 scroll->setMaximumHeight(tileset_unit_with_upkeep_height(get_tileset()) + 6
1603 + scroll->horizontalScrollBar()->height());
1604 scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1605 scroll->setWidget(supported_units);
1606 current_units = new unit_info(false);
1607 scroll2 = new QScrollArea;
1608 scroll2->setWidgetResizable(true);
1609 scroll2->setMaximumHeight(tileset_unit_height(get_tileset()) + 6
1610 + scroll2->horizontalScrollBar()->height());
1611 scroll2->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1612 scroll2->setWidget(current_units);
1613 scroll_height = scroll2->horizontalScrollBar()->height();
1614 city_buildings = new impr_info(this);
1615 scroll3 = new QScrollArea;
1616 scroll3->setWidgetResizable(true);
1617 scroll3->setMaximumHeight(tileset_unit_height(tileset) + 6
1618 + scroll3->horizontalScrollBar()->height());
1619 scroll3->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1620 scroll3->setWidget(city_buildings);
1621 scroll->setProperty("city_scroll", true);
1622 scroll2->setProperty("city_scroll", true);
1623 scroll3->setProperty("city_scroll", true);
1624
1627 right_layout = new QVBoxLayout();
1629 units_layout = new QVBoxLayout();
1630 left_layout = new QVBoxLayout();
1631
1632 /* Checkboxes to show units/wonders/imrovements
1633 * on production list */
1636 show_buildings->setToolTip(_("Show buildings"));
1637 show_buildings->setChecked(true);
1638 label = new QLabel();
1639 label->setPixmap(*fc_icons::instance()->get_pixmap("building"));
1640 label->setToolTip(_("Show buildings"));
1641 prod_option_layout->addWidget(show_buildings, Qt::AlignLeft);
1642 prod_option_layout->addWidget(label, Qt::AlignLeft);
1643 prod_option_layout->addStretch(100);
1644 label = new QLabel();
1645 label->setPixmap(*fc_icons::instance()->get_pixmap("cunits"));
1646 label->setToolTip(_("Show units"));
1647 show_units = new QCheckBox;
1648 show_units->setToolTip(_("Show units"));
1649 show_units->setChecked(true);
1650 prod_option_layout->addWidget(show_units, Qt::AlignHCenter);
1651 prod_option_layout->addWidget(label, Qt::AlignHCenter);
1652 prod_option_layout->addStretch(100);
1653 label = new QLabel();
1654 label->setPixmap(*fc_icons::instance()->get_pixmap("wonder"));
1655 label->setToolTip(_("Show wonders"));
1656 show_wonders = new QCheckBox;
1657 show_wonders->setToolTip(_("Show wonders"));
1658 show_wonders->setChecked(true);
1659 prod_option_layout->addWidget(show_wonders);
1660 prod_option_layout->addWidget(label);
1661 prod_option_layout->addStretch(100);
1662 label = new QLabel();
1663 label->setPixmap(*fc_icons::instance()->get_pixmap("future"));
1664 label->setToolTip(_("Show future targets"));
1666 future_targets->setToolTip(_("Show future targets"));
1667 future_targets->setChecked(false);
1669 prod_option_layout->addWidget(label, Qt::AlignRight);
1670 prod_options = new QGroupBox(this);
1671 prod_options->setLayout(prod_option_layout);
1672 prod_options->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
1673
1674 // Prev/next and close buttons
1675 button = new QPushButton;
1676 button->setIcon(fc_icons::instance()->get_icon("city-close"));
1677 button->setIconSize(QSize(56, 56));
1678 button->setToolTip(_("Close city dialog"));
1679 connect(button, &QAbstractButton::clicked, this, &QWidget::hide);
1680
1681 next_city_but = new QPushButton();
1682 next_city_but->setIcon(fc_icons::instance()->get_icon("city-right"));
1683 next_city_but->setIconSize(QSize(56, 56));
1684 next_city_but->setToolTip(_("Show next city"));
1685 connect(next_city_but, &QAbstractButton::clicked, this, &city_dialog::next_city);
1686
1687 prev_city_but = new QPushButton();
1688 connect(prev_city_but, &QAbstractButton::clicked, this, &city_dialog::prev_city);
1689 prev_city_but->setIcon(fc_icons::instance()->get_icon("city-left"));
1690 prev_city_but->setIconSize(QSize(56, 56));
1691 prev_city_but->setToolTip(_("Show previous city"));
1692
1693 happiness_button = new QPushButton();
1694 happiness_button->setIcon(fc_icons::instance()->get_icon("city-switch"));
1695 happiness_button->setIconSize(QSize(56, 28));
1696 connect(happiness_button, &QAbstractButton::clicked, this, &city_dialog::show_happiness);
1697
1698 button->setFixedSize(64, 64);
1699 prev_city_but->setFixedSize(64, 64);
1700 next_city_but->setFixedSize(64, 64);
1701 happiness_button->setFixedSize(64, 32);
1703 vbox_layout->addWidget(prev_city_but);
1704 vbox_layout->addWidget(next_city_but);
1705 vbox_layout->addWidget(button);
1706 vbox_layout->addWidget(happiness_button, Qt::AlignHCenter);
1707
1708 counterss_button = new QPushButton();
1709 connect(counterss_button, &QAbstractButton::clicked, this, &city_dialog::show_counters);
1710 vbox_layout->addWidget(counterss_button, Qt::AlignHCenter);
1711
1712 update_tabs();
1714
1715 hbox_layout->addLayout(vbox_layout, Qt::AlignLeft);
1716 hbox_layout->addWidget(info_wdg, Qt::AlignLeft);
1717 hbox_layout->addWidget(map_box, Qt::AlignCenter);
1718
1719 // Layout with city view and buttons
1720 lefttop_layout->addWidget(citizens_label, Qt::AlignHCenter);
1721 lefttop_layout->addStretch(0);
1722 lefttop_layout->addLayout(hbox_layout);
1723 lefttop_layout->addStretch(50);
1724
1725 // Layout for units/buildings
1726 curr_unit_wdg = new QWidget();
1727 supp_unit_wdg = new QWidget();
1728 curr_impr_wdg = new QWidget();
1729 v_layout = new QVBoxLayout;
1730 v_layout->addWidget(curr_impr);
1731 v_layout->addWidget(scroll3);
1732 v_layout->setContentsMargins(0 , 0 , 0, 0);
1733 v_layout->setSpacing(0);
1734 curr_impr_wdg->setLayout(v_layout);
1735 v_layout = new QVBoxLayout;
1736 v_layout->addWidget(curr_units);
1737 v_layout->addWidget(scroll2);
1738 v_layout->setContentsMargins(0 , 0 , 0, 0);
1739 v_layout->setSpacing(0);
1740 curr_unit_wdg->setLayout(v_layout);
1741 v_layout = new QVBoxLayout;
1742 v_layout->addWidget(supp_units);
1743 v_layout->addWidget(scroll);
1744 v_layout->setContentsMargins(0 , 0 , 0, 0);
1745 v_layout->setSpacing(0);
1746 supp_unit_wdg->setLayout(v_layout);
1747
1748 units_layout->addWidget(curr_unit_wdg);
1749 units_layout->addWidget(supp_unit_wdg);
1750 units_layout->addWidget(curr_impr_wdg);
1751 units_layout->setSpacing(0);
1752 units_layout->setContentsMargins(0 , 0 , 0, 0);
1753
1754 vbox = new QVBoxLayout;
1756 qgbprod = new QGroupBox;
1757 group_box = new QGroupBox(_("Worklist Option"));
1759 work_next_but = new QPushButton(fc_icons::instance()->get_icon(
1760 "go-down"), "");
1761 work_prev_but = new QPushButton(fc_icons::instance()->get_icon(
1762 "go-up"), "");
1763 work_add_but = new QPushButton(fc_icons::instance()->get_icon(
1764 "list-add"), "");
1765 work_rem_but = new QPushButton(style()->standardIcon(
1766 QStyle::SP_DialogDiscardButton), "");
1767 work_but_layout->addWidget(work_add_but);
1768 work_but_layout->addWidget(work_next_but);
1769 work_but_layout->addWidget(work_prev_but);
1770 work_but_layout->addWidget(work_rem_but);
1772 production_combo_p->setToolTip(_("Click to change current production"));
1773 p_table_p = new QTableWidget;
1774
1775 r1 = new QRadioButton(_("Change"));
1776 r2 = new QRadioButton(_("Insert Before"));
1777 r3 = new QRadioButton(_("Insert After"));
1778 r4 = new QRadioButton(_("Add Last"));
1779 r4->setChecked(true);
1780 group_box->setLayout(vbox);
1781
1782
1783 p_table_p->setColumnCount(3);
1784 p_table_p->setProperty("showGrid", "false");
1785 p_table_p->setProperty("selectionBehavior", "SelectRows");
1786 p_table_p->setEditTriggers(QAbstractItemView::NoEditTriggers);
1787 p_table_p->verticalHeader()->setVisible(false);
1788 p_table_p->horizontalHeader()->setVisible(false);
1789 p_table_p->setSelectionMode(QAbstractItemView::SingleSelection);
1790 production_combo_p->setFixedHeight(h);
1791 p_table_p->setMinimumWidth(200);
1792 p_table_p->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow);
1793 p_table_p->setContextMenuPolicy(Qt::CustomContextMenu);
1794 p_table_p->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
1795 header = p_table_p->horizontalHeader();
1796 header->setStretchLastSection(true);
1797
1798 qgbprod->setTitle(_("Worklist"));
1799 vbox_layout->setSpacing(0);
1800 vbox_layout->addWidget(prod_options);
1801 vbox_layout->addWidget(buy_button);
1802 vbox_layout->addWidget(production_combo_p);
1803 vbox_layout->addLayout(work_but_layout);
1804 vbox_layout->addWidget(p_table_p);
1805 qgbprod->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1806 qgbprod->setLayout(vbox_layout);
1807
1808 worklist_layout->setSpacing(0);
1809 worklist_layout->addWidget(qgbprod);
1810 connect(p_table_p,
1811 &QWidget::customContextMenuRequested, this,
1814 connect(work_add_but, &QAbstractButton::clicked, this, &city_dialog::show_targets_worklist);
1815 connect(work_prev_but, &QAbstractButton::clicked, this, &city_dialog::worklist_up);
1816 connect(work_next_but, &QAbstractButton::clicked, this, &city_dialog::worklist_down);
1817 connect(work_rem_but, &QAbstractButton::clicked, this, &city_dialog::worklist_del);
1818 connect(p_table_p,
1819 &QTableWidget::itemDoubleClicked,
1821 connect(p_table_p->selectionModel(),
1823 const QItemSelection &)),
1825 const QItemSelection &)));
1826 happiness_group = new QGroupBox(_("Happiness"));
1827 gridl = new QGridLayout;
1828
1829 nationality_table = new QTableWidget;
1830 nationality_table->setColumnCount(3);
1831 nationality_table->setProperty("showGrid", "false");
1832 nationality_table->setProperty("selectionBehavior", "SelectRows");
1833 nationality_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
1834 nationality_table->verticalHeader()->setVisible(false);
1835 nationality_table->horizontalHeader()->setStretchLastSection(true);
1836
1837 info_list.clear();
1838 info_list << _("Cities:") << _("Luxuries:") << _("Buildings:")
1839 << _("Nationality:") << _("Units:") << _("Wonders:");
1840
1841 for (int i = 0; i < info_list.count(); i++) {
1842 lab_table[i] = new city_label(1 + i, this);
1843 gridl->addWidget(lab_table[i], i, 1, 1, 1);
1844 lab2 = new QLabel(this);
1845 lab2->setFont(*small_font);
1846 lab2->setProperty(fonts::notify_label, "true");
1847 lab2->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
1848 lab2->setText(info_list.at(i));
1849 gridl->addWidget(lab2, i, 0, 1, 1);
1850 }
1851
1852 gridl->setSpacing(0);
1853 happiness_group->setLayout(gridl);
1854
1855
1859 happiness_layout->setStretch(0, 10);
1860 happiness_widget = new QWidget();
1862 qgbox = new QGroupBox(_("Presets:"));
1863 qsliderbox = new QGroupBox(_("Governor settings"));
1864 result_box = new QGroupBox(_("Results:"));
1865 hbox = new QHBoxLayout;
1866 gridl = new QGridLayout;
1868
1870 counterss_frame = new QFrame();
1872
1873 qpush2
1874 = new QPushButton(style()->standardIcon(QStyle::SP_DialogSaveButton),
1875 _("Save"));
1876 connect(qpush2, &QAbstractButton::pressed, this, &city_dialog::save_cma);
1877
1878 cma_info_text = new QLabel;
1879 cma_info_text->setFont(*small_font);
1880 cma_info_text->setAlignment(Qt::AlignCenter);
1881 cma_table = new QTableWidget;
1882 cma_table->setColumnCount(1);
1883 cma_table->setProperty("showGrid", "false");
1884 cma_table->setProperty("selectionBehavior", "SelectRows");
1885 cma_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
1886 cma_table->setSelectionMode(QAbstractItemView::SingleSelection);
1887 cma_table->setContextMenuPolicy(Qt::CustomContextMenu);
1888 cma_table->verticalHeader()->setVisible(false);
1889 cma_table->horizontalHeader()->setVisible(false);
1890 cma_table->horizontalHeader()->setSectionResizeMode(
1891 QHeaderView::Stretch);
1892
1893 connect(cma_table->selectionModel(),
1895 const QItemSelection &)),
1897 const QItemSelection &)));
1898 connect(cma_table,
1899 &QWidget::customContextMenuRequested, this,
1901 connect(cma_table, &QTableWidget::cellDoubleClicked, this,
1903 gridl->addWidget(cma_table, 0, 0, 1, 2);
1904 qgbox->setLayout(gridl);
1905 hbox->addWidget(cma_info_text);
1906 result_box->setLayout(hbox);
1907 str_list << _("Food") << _("Shield") << _("Trade") << _("Gold")
1908 << _("Luxury") << _("Science") << _("Celebrate")
1909 << _("Maximize growth");
1910 some_label = new QLabel(_("Minimal Surplus"));
1912 some_label->setAlignment(Qt::AlignRight);
1913 slider_grid->addWidget(some_label, 0, 0, 1, 3);
1914 some_label = new QLabel(_("Priority"));
1916 some_label->setAlignment(Qt::AlignCenter);
1917 slider_grid->addWidget(some_label, 0, 3, 1, 2);
1918
1919 list_size = str_list.count();
1920 for (int i = 0; i < list_size; i++) {
1921 some_label = new QLabel(str_list.at(i));
1922 slider_grid->addWidget(some_label, i + 1, 0, 1, 1);
1923 some_label = new QLabel("0");
1924 some_label->setMinimumWidth(25);
1925
1926 if (i < list_size - 2) {
1927 slider = new QSlider(Qt::Horizontal);
1928 slider->setPageStep(1);
1929 slider->setFocusPolicy(Qt::TabFocus);
1930 slider_tab[2 * i] = slider;
1931 slider->setRange(-20, 20);
1932 slider->setSingleStep(1);
1933 slider_grid->addWidget(some_label, i + 1, 1, 1, 1);
1934 slider_grid->addWidget(slider, i + 1, 2, 1, 1);
1935 slider->setProperty("FC", QVariant::fromValue((void *)some_label));
1936
1937 connect(slider, &QAbstractSlider::valueChanged, this, &city_dialog::cma_slider);
1938 } else if (i == list_size - 2) {
1940 slider_grid->addWidget(cma_celeb_checkbox, i + 1, 2 , 1 , 1);
1941#ifdef FC_QT6X_MODE
1942 // Qt-6.7
1943 connect(cma_celeb_checkbox,
1944 &QCheckBox::checkStateChanged, this, &city_dialog::cma_toggle_changed);
1945#else // FC_QT6X_MODE
1946 connect(cma_celeb_checkbox,
1947 &QCheckBox::stateChanged, this, &city_dialog::cma_toggle_changed_depr);
1948#endif // FC_QT6X_MODE
1949 } else {
1950 fc_assert(i == list_size - 1);
1951
1953 slider_grid->addWidget(cma_max_growth, i + 1, 2 , 1 , 1);
1954#ifdef FC_QT6X_MODE
1955 // Qt-6.7
1956 connect(cma_max_growth,
1957 &QCheckBox::checkStateChanged, this, &city_dialog::cma_toggle_changed);
1958#else // FC_QT6X_MODE
1959 connect(cma_max_growth,
1960 &QCheckBox::stateChanged, this, &city_dialog::cma_toggle_changed_depr);
1961#endif // FC_QT6X_MODE
1962 }
1963
1964 if (i <= list_size - 2) {
1965 some_label = new QLabel("0");
1966 some_label->setMinimumWidth(25);
1967 slider = new QSlider(Qt::Horizontal);
1968 slider->setFocusPolicy(Qt::TabFocus);
1969 slider->setRange(0, 25);
1970 slider_tab[2 * i + 1] = slider;
1971 slider->setProperty("FC", QVariant::fromValue((void *)some_label));
1972 slider_grid->addWidget(some_label, i + 1, 3, 1, 1);
1973 slider_grid->addWidget(slider, i + 1, 4, 1, 1);
1974 connect(slider, &QAbstractSlider::valueChanged, this, &city_dialog::cma_slider);
1975 }
1976 }
1977
1978 cma_enable_but = new QPushButton();
1979 cma_enable_but->setFocusPolicy(Qt::TabFocus);
1980 connect(cma_enable_but, &QAbstractButton::pressed, this, &city_dialog::cma_enable);
1981 slider_grid->addWidget(cma_enable_but, O_LAST + 4, 0, 1, 3);
1982 slider_grid->addWidget(qpush2, O_LAST + 4, 3, 1, 2);
1983
1984 qsliderbox->setLayout(slider_grid);
1985 cma_result = new QLabel;
1986 cma_result_pix = new QLabel;
1987
1988 hbox = new QHBoxLayout;
1989 QScrollArea *govA = new QScrollArea();
1990 hbox->addWidget(cma_result_pix);
1991 hbox->addWidget(cma_result);
1992 hbox->addStretch(10);
1993 govA->setWidget(qsliderbox);
1994 govA->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
1995 right_layout->addWidget(qgbox);
1996 right_layout->addLayout(hbox);
1997 right_layout->addWidget(govA);
1998
1999 split_widget1 = new QWidget;
2000 split_widget1->setLayout(worklist_layout);
2001 split_widget2 = new QWidget;
2002 split_widget2->setLayout(units_layout);
2005 prod_unit_splitter->setStretchFactor(0, 3);
2006 prod_unit_splitter->setStretchFactor(1, 97);
2007 prod_unit_splitter->setOrientation(Qt::Horizontal);
2009 top_widget = new QWidget;
2010 top_widget->setLayout(lefttop_layout);
2011 top_widget->setSizePolicy(QSizePolicy::Minimum,
2012 QSizePolicy::Minimum);
2013 scroll_info = new QScrollArea();
2014 scroll_info->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
2015 scroll_unit = new QScrollArea();
2016 scroll_info->setWidget(top_widget);
2017 scroll_info->setWidgetResizable(true);
2018 prod_happ_widget = new QWidget;
2019 prod_happ_widget->setLayout(leftbot_layout);
2020 prod_happ_widget->setSizePolicy(QSizePolicy::MinimumExpanding,
2021 QSizePolicy::MinimumExpanding);
2022 scroll_unit->setWidget(prod_happ_widget);
2023 scroll_unit->setWidgetResizable(true);
2026 central_left_splitter->setStretchFactor(0, 40);
2027 central_left_splitter->setStretchFactor(1, 60);
2028 central_left_splitter->setOrientation(Qt::Vertical);
2030
2031 split_widget1 = new QWidget(this);
2032 split_widget2 = new QWidget(this);
2033 split_widget1->setLayout(left_layout);
2034 split_widget2->setLayout(right_layout);
2035 central_splitter->addWidget(split_widget1);
2036 central_splitter->addWidget(split_widget2);
2037 central_splitter->setStretchFactor(0, 99);
2038 central_splitter->setStretchFactor(1, 1);
2039 central_splitter->setOrientation(Qt::Horizontal);
2041 setSizeGripEnabled(true);
2043
2044 installEventFilter(this);
2045
2046 ::city_dlg_created = true;
2047
2049}
2050
2051/************************************************************************/
2055{
2056
2057 cid cprod;
2058 int i, pos;
2059 int item, targets_used;
2061 QString str;
2062 struct item items[MAX_NUM_PRODUCTION_TARGETS];
2063 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
2064 struct universal univ;
2065
2066 pos = 0;
2069 name_and_sort_items(targets, targets_used, items, false, dlgcity);
2070
2071 for (item = 0; item < targets_used; item++) {
2072 if (can_city_build_now(&(wld.map), dlgcity, &items[item].item)) {
2073 prod_list << cid_encode(items[item].item);
2074 }
2075 }
2076
2077 for (i = 0; i < prod_list.size(); i++) {
2078 if (prod_list.at(i) == cprod) {
2079 if (next) {
2080 pos = i + 1;
2081 } else {
2082 pos = i - 1;
2083 }
2084 }
2085 }
2086 if (pos == prod_list.size()) {
2087 pos = 0;
2088 }
2089 if (pos == - 1) {
2090 pos = prod_list.size() - 1;
2091 }
2092 univ = cid_decode(static_cast<cid>(prod_list.at(pos)));
2094}
2095
2096/************************************************************************/
2100{
2101 if (current_tab == happiness) {
2102 happiness_button->setToolTip(_("Show city production"));
2103 counterss_button->setToolTip(_("Show counters information"));
2104
2105 } else {
2106 happiness_button->setToolTip(_("Show happiness information"));
2107
2108 if (current_tab == counters) {
2109 counterss_button->setToolTip(_("Show city production"));
2110 }
2111 else {
2112 counterss_button->setToolTip(_("Show counters information"));
2113 }
2114 }
2115}
2116
2117/************************************************************************/
2121{
2123 setUpdatesEnabled(false);
2124
2125
2126 if (current_tab != happiness) {
2127 leftbot_layout->replaceWidget(active_tab,
2129 Qt::FindDirectChildrenOnly);
2130 active_tab->hide();
2131 happiness_widget->show();
2132 happiness_widget->updateGeometry();
2134 } else {
2135 /* We do not change prod_unit_splitter to current_tab,
2136 * because happiness is active tab and clicked -
2137 * switching to default */
2138 leftbot_layout->replaceWidget(happiness_widget,
2140 Qt::FindDirectChildrenOnly);
2141 prod_unit_splitter->show();
2142 prod_unit_splitter->updateGeometry();
2143 happiness_widget->hide();
2145 }
2146
2147 setUpdatesEnabled(true);
2148 update();
2149 update_tabs();
2150}
2151
2152/************************************************************************/
2156{
2158 setUpdatesEnabled(false);
2159
2160
2161 if (current_tab != counters) {
2162 leftbot_layout->replaceWidget(active_tab,
2164 Qt::FindDirectChildrenOnly);
2165 active_tab->hide();
2166 counterss_frame->show();
2167 counterss_frame->updateGeometry();
2169 } else {
2170 /* We do not change prod_unit_splitter to current_tab,
2171 * because counters is active tab and clicked -
2172 * switching to default */
2173 leftbot_layout->replaceWidget(counterss_frame,
2175 Qt::FindDirectChildrenOnly);
2176 prod_unit_splitter->show();
2177 prod_unit_splitter->updateGeometry();
2178 counterss_frame->hide();
2180 }
2181
2182 setUpdatesEnabled(true);
2183 update();
2184 update_tabs();
2185}
2186
2187/************************************************************************/
2191{
2192 struct player *pplayer = client_player();
2193
2194 if (pplayer == nullptr
2195 || city_owner(dlgcity) != pplayer) {
2196 prev_city_but->setDisabled(true);
2197 next_city_but->setDisabled(true);
2198 buy_button->setDisabled(true);
2199 cma_enable_but->setDisabled(true);
2200 production_combo_p->setDisabled(true);
2201 current_units->setDisabled(true);
2202 supported_units->setDisabled(true);
2203 view->setDisabled(true);
2204 } else {
2205 prev_city_but->setEnabled(true);
2206 next_city_but->setEnabled(true);
2207 buy_button->setEnabled(true);
2208 cma_enable_but->setEnabled(true);
2209 production_combo_p->setEnabled(true);
2210 current_units->setEnabled(true);
2211 supported_units->setEnabled(true);
2212 view->setEnabled(true);
2213 }
2214
2216 cma_enable_but->setEnabled(true);
2217 } else {
2218 cma_enable_but->setDisabled(true);
2219 }
2220
2222}
2223
2224/************************************************************************/
2228{
2229 struct player *pplayer = client_player();
2230
2231 work_next_but->setDisabled(true);
2232 work_prev_but->setDisabled(true);
2233 work_add_but->setDisabled(true);
2234 work_rem_but->setDisabled(true);
2235
2236 if (pplayer != nullptr
2237 && city_owner(dlgcity) == pplayer) {
2238 work_add_but->setEnabled(true);
2239
2240 if (selected_row_p >= 0 && selected_row_p < p_table_p->rowCount()) {
2241 work_rem_but->setEnabled(true);
2242 }
2243
2244 if (selected_row_p >= 0 && selected_row_p < p_table_p->rowCount() - 1) {
2245 work_next_but->setEnabled(true);
2246 }
2247
2248 if (selected_row_p > 0 && selected_row_p < p_table_p->rowCount()) {
2249 work_prev_but->setEnabled(true);
2250 }
2251 }
2252}
2253
2254/************************************************************************/
2258{
2259 if (citizen_pixmap) {
2260 citizen_pixmap->detach();
2261 delete citizen_pixmap;
2262 }
2263
2264 cma_table->clear();
2265 p_table_p->clear();
2266 nationality_table->clear();
2268 supported_units->clear_layout();
2269 removeEventFilter(this);
2270 ::city_dlg_created = false;
2271
2272 // Delete the one widget that currently does NOT have a parent
2273 if (current_tab == common) {
2274 delete happiness_widget;
2275 delete counterss_frame;
2276 }
2277 else if (current_tab == counters) {
2278 delete happiness_widget;
2279 delete prod_unit_splitter;
2280 }else {
2281 delete counterss_frame;
2282 delete prod_unit_splitter;
2283 }
2284}
2285
2286/************************************************************************/
2290{
2291 gui()->qt_settings.city_geometry = saveGeometry();
2292 gui()->qt_settings.city_splitter1 = prod_unit_splitter->saveState();
2293 gui()->qt_settings.city_splitter2 = central_left_splitter->saveState();
2294 gui()->qt_settings.city_splitter3 = central_splitter->saveState();
2295}
2296
2297/************************************************************************/
2301{
2302 if (!gui()->qt_settings.city_geometry.isNull()) {
2303 restoreGeometry(gui()->qt_settings.city_geometry);
2304 prod_unit_splitter->restoreState(gui()->qt_settings.city_splitter1);
2305 central_left_splitter->restoreState(gui()->qt_settings.city_splitter2);
2306 central_splitter->restoreState(gui()->qt_settings.city_splitter3);
2307 } else {
2308 QRect rect = QApplication::primaryScreen()->availableGeometry();
2309
2310 resize((rect.width() * 4) / 5, (rect.height() * 5) / 6);
2311 }
2312}
2313
2314/************************************************************************/
2318{
2319 gui()->qt_settings.city_geometry = saveGeometry();
2320 gui()->qt_settings.city_splitter1 = prod_unit_splitter->saveState();
2321 gui()->qt_settings.city_splitter2 = central_left_splitter->saveState();
2322 gui()->qt_settings.city_splitter3 = central_splitter->saveState();
2323}
2324
2325/************************************************************************/
2328bool city_dialog::eventFilter(QObject *obj, QEvent *event)
2329{
2330
2331 if (obj == this) {
2332 if (event->type() == QEvent::KeyPress) {
2333 }
2334
2335 if (event->type() == QEvent::ShortcutOverride) {
2336 QKeyEvent *key_event = static_cast<QKeyEvent *>(event);
2337 if (key_event->key() == Qt::Key_Right) {
2338 next_city();
2339 event->setAccepted(true);
2340 return true;
2341 }
2342 if (key_event->key() == Qt::Key_Left) {
2343 prev_city();
2344 event->setAccepted(true);
2345 return true;
2346 }
2347 if (key_event->key() == Qt::Key_Up) {
2348 change_production(true);
2349 event->setAccepted(true);
2350 return true;
2351 }
2352 if (key_event->key() == Qt::Key_Down) {
2353 change_production(false);
2354 event->setAccepted(true);
2355 return true;
2356 }
2357 }
2358 }
2359 return QObject::eventFilter(obj, event);
2360}
2361
2362/************************************************************************/
2366{
2368 const int city_id = dlgcity->id;
2369
2370 if (!can_client_issue_orders()) {
2371 return;
2372 }
2373
2374 ask = new hud_input_box(gui()->central_wdg);
2375 ask->set_text_title_definput(_("What should we rename the city to?"),
2376 _("Rename City"), city_name_get(dlgcity));
2377 ask->setAttribute(Qt::WA_DeleteOnClose);
2378 connect(ask, &hud_message_box::accepted, this, [=]() {
2379 struct city *pcity = game_city_by_number(city_id);
2381
2382 if (!pcity) {
2383 return;
2384 }
2385
2386 ask_bytes = ask->input_edit.text().toUtf8();
2387 ::city_rename(pcity, ask_bytes.data());
2388 });
2389 ask->show();
2390}
2391
2392/************************************************************************/
2396{
2397 zoom = zoom * 1.2;
2398 if (dlgcity) {
2399 view->set_pixmap(dlgcity, zoom);
2400 }
2402 left_layout->update();
2403}
2404
2405/************************************************************************/
2409{
2410 zoom = zoom / 1.2;
2411 if (dlgcity) {
2412 view->set_pixmap(dlgcity, zoom);
2413 }
2415 left_layout->update();
2416}
2417
2418/************************************************************************/
2422{
2423 hud_input_box *ask = new hud_input_box(gui()->central_wdg);
2424
2425 ask->set_text_title_definput(_("What should we name the preset?"),
2426 _("Name new preset"),
2427 _("new preset"));
2428 ask->setAttribute(Qt::WA_DeleteOnClose);
2429 connect(ask, &hud_message_box::accepted, this,
2431 struct cm_parameter param;
2432 QByteArray ask_bytes = ask->input_edit.text().toUtf8();
2433 QString text = ask_bytes.data();
2434 if (!text.isEmpty()) {
2435 param.allow_disorder = false;
2436 param.allow_specialists = true;
2437 param.require_happy = cma_celeb_checkbox->isChecked();
2438 param.max_growth = cma_max_growth->isChecked();
2439 param.happy_factor = slider_tab[2 * O_LAST + 1]->value();
2440
2441 for (int i = O_FOOD; i < O_LAST; i++) {
2442 param.minimal_surplus[i] = slider_tab[2 * i]->value();
2443 param.factor[i] = slider_tab[2 * i + 1]->value();
2444 }
2445
2446 ask_bytes = text.toUtf8();
2447 cmafec_preset_add(ask_bytes.data(), &param);
2449 }
2450 });
2451 ask->show();
2452}
2453
2454/************************************************************************/
2458{
2459 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2461
2462 return;
2463 }
2464
2465 cma_changed();
2467}
2468
2469/************************************************************************/
2473{
2474 struct cm_parameter param;
2475
2476 param.allow_disorder = false;
2477 param.allow_specialists = true;
2478 param.require_happy = cma_celeb_checkbox->isChecked();
2479 param.max_growth = cma_max_growth->isChecked();
2480 param.happy_factor = slider_tab[2 * O_LAST + 1]->value();
2481
2482 for (int i = O_FOOD; i < O_LAST; i++) {
2483 param.minimal_surplus[i] = slider_tab[2 * i]->value();
2484 param.factor[i] = slider_tab[2 * i + 1]->value();
2485 }
2486
2488}
2489
2490/************************************************************************/
2494{
2495 const struct cm_parameter *param;
2496
2497 if (!can_client_issue_orders()) {
2498 return;
2499 }
2501 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2503 }
2504
2507}
2508
2509/************************************************************************/
2513 const QItemSelection &ds)
2514{
2515 const struct cm_parameter *param;
2516 QModelIndex index;
2517 QModelIndexList indexes = sl.indexes();
2518
2519 if (indexes.isEmpty() || cma_table->signalsBlocked()) {
2520 return;
2521 }
2522
2523 index = indexes.at(0);
2524 int ind = index.row();
2525
2526 if (cma_table->currentRow() == -1 || cmafec_preset_num() == 0) {
2527 return;
2528 }
2529
2532
2533 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2536 }
2537}
2538
2539/************************************************************************/
2543{
2544 struct cm_parameter param;
2545 const struct cm_parameter *cparam;
2546 int output;
2547 QVariant qvar;
2548 QLabel *label;
2549
2550 if (!cma_is_city_under_agent(dlgcity, &param)) {
2551 if (cma_table->currentRow() == -1 || cmafec_preset_num() == 0) {
2552 return;
2553 }
2555 cm_copy_parameter(&param, cparam);
2556 }
2557
2558 for (output = O_FOOD; output < 2 * O_LAST; output++) {
2559 slider_tab[output]->blockSignals(true);
2560 }
2561
2562 for (output = O_FOOD; output < O_LAST; output++) {
2563 qvar = slider_tab[2 * output + 1]->property("FC");
2564 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2565 label->setText(QString::number(param.factor[output]));
2566 slider_tab[2 * output + 1]->setValue(param.factor[output]);
2567 qvar = slider_tab[2 * output]->property("FC");
2568 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2569 label->setText(QString::number(param.minimal_surplus[output]));
2570 slider_tab[2 * output]->setValue(param.minimal_surplus[output]);
2571 }
2572
2573 slider_tab[2 * O_LAST + 1]->blockSignals(true);
2574 qvar = slider_tab[2 * O_LAST + 1]->property("FC");
2575 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2576 label->setText(QString::number(param.happy_factor));
2577 slider_tab[2 * O_LAST + 1]->setValue(param.happy_factor);
2578 slider_tab[2 * O_LAST + 1]->blockSignals(false);
2579 cma_celeb_checkbox->blockSignals(true);
2580 cma_celeb_checkbox->setChecked(param.require_happy);
2581 cma_celeb_checkbox->blockSignals(false);
2582 cma_max_growth->blockSignals(true);
2583 cma_max_growth->setChecked(param.max_growth);
2584 cma_max_growth->blockSignals(false);
2585
2586 for (output = O_FOOD; output < 2 * O_LAST; output++) {
2587 slider_tab[output]->blockSignals(false);
2588 }
2589}
2590
2591/************************************************************************/
2595{
2596 QString s;
2598 struct cm_parameter param;
2599 QPixmap pix;
2600 int i;
2601
2602 cma_table->clear();
2603 cma_table->setRowCount(0);
2604
2605 for (i = 0; i < cmafec_preset_num(); i++) {
2606 item = new QTableWidgetItem;
2607 item->setText(cmafec_preset_get_descr(i));
2608 cma_table->insertRow(i);
2609 cma_table->setItem(i, 0, item);
2610 }
2611
2612 if (cmafec_preset_num() == 0) {
2613 cma_table->insertRow(0);
2614 item = new QTableWidgetItem;
2615 item->setText(_("No governor defined"));
2616 cma_table->setItem(0, 0, item);
2617 }
2618
2619 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2620 view->update();
2622 pix = style()->standardPixmap(QStyle::SP_DialogApplyButton);
2623 pix = pix.scaled(2 * pix.width(), 2 * pix.height(),
2624 Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
2625 cma_result_pix->setPixmap(pix);
2626 cma_result_pix->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
2627 // TRANS: %1 is custom string chosen by player
2628 cma_result->setText(QString(_("<h3>Governor Enabled<br>(%1)</h3>"))
2629 .arg(s.toHtmlEscaped()));
2630 cma_result->setAlignment(Qt::AlignCenter);
2631 } else {
2632 pix = style()->standardPixmap(QStyle::SP_DialogCancelButton);
2633 pix = pix.scaled(1.6 * pix.width(), 1.6 * pix.height(),
2634 Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
2635 cma_result_pix->setPixmap(pix);
2636 cma_result_pix->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
2637 cma_result->setText(QString(_("<h3>Governor Disabled</h3>")));
2638 cma_result->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
2639 }
2640
2641 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2644 cm_parameter *const >(&param));
2645 if (i >= 0 && i < cma_table->rowCount()) {
2646 cma_table->blockSignals(true);
2647 cma_table->setCurrentCell(i, 0);
2648 cma_table->blockSignals(false);
2649 }
2650
2651 cma_enable_but->setText(_("Disable"));
2652 } else {
2653 cma_enable_but->setText(_("Enable"));
2654 }
2656}
2657
2658/************************************************************************/
2662{
2663 int i;
2665
2666 i = cma_table->currentRow();
2667
2668 if (i == -1 || cmafec_preset_num() == 0) {
2669 return;
2670 }
2671
2673 ask->set_text_title(_("Remove this preset?"), cmafec_preset_get_descr(i));
2674 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
2675 ask->setDefaultButton(QMessageBox::Cancel);
2676 ask->setAttribute(Qt::WA_DeleteOnClose);
2677 connect(ask, &hud_message_box::accepted, this,
2681 });
2682 ask->show();
2683}
2684
2685/************************************************************************/
2688void city_dialog::cma_toggle_changed(Qt::CheckState state)
2689{
2690 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2691 cma_changed();
2693 }
2694}
2695
2696/************************************************************************/
2701{
2702 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2703 cma_changed();
2705 }
2706}
2707
2708/************************************************************************/
2712{
2713 QVariant qvar;
2714 QSlider *slider;
2715 QLabel *label;
2716
2718 qvar = slider->property("FC");
2719
2720 if (qvar.isNull() || !qvar.isValid()) {
2721 return;
2722 }
2723
2724 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2725 label->setText(QString::number(value));
2726
2727 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2728 cma_changed();
2730 }
2731}
2732
2733/************************************************************************/
2753
2754/************************************************************************/
2758{
2759 QMenu *cma_menu = new QMenu(this);
2761
2762 cma_menu->setAttribute(Qt::WA_DeleteOnClose);
2763 cma_del_item = cma_menu->addAction(_("Remove Governor"));
2764 connect(cma_menu, &QMenu::triggered, this,
2766 if (act == cma_del_item) {
2767 cma_remove();
2768 }
2769 });
2770
2771 cma_menu->popup(QCursor::pos());
2772}
2773
2774/************************************************************************/
2778{
2779 QAction *action;
2780 QAction *disband;
2785 QMap<QString, cid>::const_iterator map_iter;
2786 QMenu *change_menu;
2787 QMenu *insert_menu;
2788 QMenu *list_menu;
2789 QMenu *options_menu;
2790 int city_id = dlgcity->id;
2791
2792 if (!can_client_issue_orders()) {
2793 return;
2794 }
2795 list_menu = new QMenu(this);
2796 change_menu = list_menu->addMenu(_("Change worklist"));
2797 insert_menu = list_menu->addMenu(_("Insert worklist"));
2798 wl_clear = list_menu->addAction(_("Clear"));
2799 connect(wl_clear, &QAction::triggered, this, &city_dialog::clear_worklist);
2800 list.clear();
2801
2805
2806 if (list.count() == 0) {
2807 wl_empty = change_menu->addAction(_("(no worklists defined)"));
2808 insert_menu->addAction(wl_empty);
2809 }
2810
2811 map_iter = list.constBegin();
2812
2813 while (map_iter != list.constEnd()) {
2814 action = change_menu->addAction(map_iter.key());
2815 action->setData(map_iter.value());
2816
2817 action = insert_menu->addAction(map_iter.key());
2818 action->setData(map_iter.value());
2819
2820 map_iter++;
2821 }
2822
2823 wl_save = list_menu->addAction(_("Save worklist"));
2824 connect(wl_save, &QAction::triggered, this, &city_dialog::save_worklist);
2825 options_menu = list_menu->addMenu(_("Options"));
2826 disband = options_menu->addAction(_("Allow disbanding city"));
2827 disband->setCheckable(true);
2828 disband->setChecked(is_city_option_set(dlgcity, CITYO_DISBAND));
2829 connect(disband, &QAction::triggered, this,
2831
2832 connect(change_menu, &QMenu::triggered, this, [=](QAction *act) {
2833 QVariant id = act->data();
2834 struct city *pcity = game_city_by_number(city_id);
2835 const struct worklist *worklist;
2836
2837 if (!pcity) {
2838 return;
2839 }
2840
2841 fc_assert_ret(id.typeId() == QMetaType::Int);
2842
2845 });
2846
2847 connect(insert_menu, &QMenu::triggered, this,
2849 QVariant id = act->data();
2850 struct city *pcity = game_city_by_number(city_id);
2851 const struct worklist *worklist;
2852
2853 if (!pcity) {
2854 return;
2855 }
2856
2857 fc_assert_ret(id.typeId() == QMetaType::Int);
2858
2861 });
2862
2863 list_menu->popup(QCursor::pos());
2864}
2865
2866/************************************************************************/
2870{
2871 QString str;
2872 int value;
2873 struct player *pplayer = client_player();
2874
2875 buy_button->setDisabled(true);
2876
2877 if (!client_is_observer() && pplayer != nullptr) {
2878 value = dlgcity->client.buy_cost;
2879 str = QString(PL_("Buy (%1 gold)", "Buy (%1 gold)",
2880 value)).arg(QString::number(value));
2881
2882 if (pplayer->economic.gold >= value && value != 0) {
2883 buy_button->setEnabled(true);
2884 }
2885 } else {
2886 str = QString(_("Buy"));
2887 }
2888
2889 buy_button->setText(str);
2890}
2891
2892/************************************************************************/
2896{
2897 enum citizen_category categories[MAX_CITY_SIZE];
2898 int i, j, width, height;
2899 QPainter p;
2900 QPixmap *pix;
2902 int num_supers
2904 ARRAY_SIZE(categories) - num_citizens,
2905 &categories[num_citizens]);
2906
2907 int w = tileset_small_sprite_width(tileset) / gui()->map_scale;
2908 int h = tileset_small_sprite_height(tileset) / gui()->map_scale;
2909
2910 if (num_supers >= 0) {
2911 /* Just draw superspecialists in the common roster */
2913 } else {
2914 /* FIXME: show them in some compact way */
2915 num_citizens = ARRAY_SIZE(categories);
2916 }
2917 i = 1 + (num_citizens * 5 / 200);
2918 w = w / i;
2919 QRect source_rect(0, 0, w, h);
2920 QRect dest_rect(0, 0, w, h);
2921 width = w * num_citizens;
2922 height = h;
2923
2924 if (citizen_pixmap) {
2925 citizen_pixmap->detach();
2926 delete citizen_pixmap;
2927 }
2928
2930
2931 for (j = 0, i = 0; i < num_citizens; i++, j++) {
2932 dest_rect.moveTo(i * w, 0);
2933 pix = get_citizen_sprite(tileset, categories[j], j, dlgcity)->pm;
2934 p.begin(citizen_pixmap);
2935 p.drawPixmap(dest_rect, *pix, source_rect);
2936 p.end();
2937 }
2938
2940 citizens_label->setPixmap(*citizen_pixmap);
2941
2944
2945 for (int k = 0; k < FEELING_LAST - 1; k++) {
2948 static_cast<citizen_feeling>(k),
2949 categories);
2950
2951 for (j = 0, i = 0; i < num_citizens; i++, j++) {
2952 dest_rect.moveTo(i * w, 0);
2953 pix = get_citizen_sprite(tileset, categories[j], j, dlgcity)->pm;
2954 p.begin(citizen_pixmap);
2955 p.drawPixmap(dest_rect, *pix, source_rect);
2956 p.end();
2957 }
2958
2959 lab_table[k]->setPixmap(*citizen_pixmap);
2960
2961 switch (k) {
2962 case FEELING_BASE:
2963 lab_table[k]->setToolTip(text_happiness_cities(dlgcity));
2964 break;
2965
2966 case FEELING_LUXURY:
2967 lab_table[k]->setToolTip(text_happiness_luxuries(dlgcity));
2968 break;
2969
2970 case FEELING_EFFECT :
2972 break;
2973
2976 break;
2977
2978 case FEELING_MARTIAL:
2979 lab_table[k]->setToolTip(text_happiness_units(dlgcity));
2980 break;
2981
2982 default:
2983 break;
2984 }
2985 }
2986}
2987
2988/************************************************************************/
2992{
2993 setUpdatesEnabled(false);
2994 production_combo_p->blockSignals(true);
2995
2996 if (dlgcity) {
2997 view->set_pixmap(dlgcity, zoom);
2998 view->update();
2999 update_title();
3006 update_units();
3010 } else {
3012 }
3013
3014 production_combo_p->blockSignals(false);
3015 setUpdatesEnabled(true);
3017 update();
3018}
3019
3020/************************************************************************/
3024{
3025 QFont *small_font;
3026
3028
3029 qDeleteAll(counterss_frame->findChildren<QWidget*>("", Qt::FindDirectChildrenOnly));
3031 QString helptext;
3032 char buf[1024];
3033 QLabel *name, *value, *activated, *help;
3034
3035 name = new QLabel(name_translation_get(&pcount->name));
3036 fc_snprintf(buf, sizeof(buf), _("Current value is: %d"),
3038 value = new QLabel(buf);
3039 fc_snprintf(buf, sizeof(buf), _("Activated once value equal "
3040 "or higher than: %d"),
3041 pcount->checkpoint);
3042 activated = new QLabel(buf);
3043 if (pcount->helptext != nullptr) {
3044 strvec_iterate(pcount->helptext, text_) {
3045 helptext += text_;
3047 }
3048 help = new QLabel(helptext);
3049
3050 name->setFont(*small_font);
3051 value->setFont(*small_font);
3052 activated->setFont(*small_font);
3053 help->setFont(*small_font);
3054
3055 counterss_layout->addWidget(name);
3056 counterss_layout->addWidget(value);
3057 counterss_layout->addWidget(activated);
3058 counterss_layout->addWidget(help);
3060}
3061
3062/************************************************************************/
3066{
3067 QFont f = QApplication::font();
3068 QFontMetrics fm(f);
3069 QPixmap *pix = nullptr;
3071 QString str;
3074 char buf[8];
3076 int h;
3077 int i = 0;
3078 struct sprite *sprite;
3079
3080 h = fm.height() + 6;
3081 nationality_table->clear();
3082 nationality_table->setRowCount(0);
3083 info_list.clear();
3084 info_list << _("#") << _("Flag") << _("Nation");
3085 nationality_table->setHorizontalHeaderLabels(info_list);
3086
3087 citizens_iterate(dlgcity, pslot, nationality) {
3088 nationality_table->insertRow(i);
3089
3090 for (int j = 0; j < nationality_table->columnCount(); j++) {
3091 item = new QTableWidgetItem;
3092
3093 switch (j) {
3094 case 0:
3096
3097 if (nationality_i == 0) {
3098 str = "-";
3099 } else {
3100 fc_snprintf(buf, sizeof(buf), "%d", nationality_i);
3101 str = QString(buf);
3102 }
3103
3104 item->setText(str);
3105 break;
3106
3107 case 1:
3110 (player_slot_get_player(pslot)));
3111
3112 if (sprite != nullptr) {
3113 pix = sprite->pm;
3114 pix_scaled = pix->scaledToHeight(h);
3115 item->setData(Qt::DecorationRole, pix_scaled);
3116 } else {
3117 item->setText("FLAG MISSING");
3118 }
3119 break;
3120
3121 case 2:
3123 (player_slot_get_player(pslot)));
3124 break;
3125
3126 default:
3127 break;
3128 }
3129 nationality_table->setItem(i, j, item);
3130 }
3131 i++;
3133 nationality_table->horizontalHeader()->setStretchLastSection(false);
3134 nationality_table->resizeColumnsToContents();
3135 nationality_table->resizeRowsToContents();
3136 nationality_table->horizontalHeader()->setStretchLastSection(true);
3137}
3138
3139/************************************************************************/
3143{
3144 int illness = 0;
3145 char buffer[512];
3146 char buf_info[NUM_INFO_FIELDS][512];
3147 char buf_tooltip[NUM_INFO_FIELDS][512];
3148 int granaryturns;
3149 int spec, supers;
3150
3151 for (int i = 0; i < NUM_INFO_FIELDS; i++) {
3152 buf_info[i][0] = '\0';
3153 buf_tooltip[i][0] = '\0';
3154 }
3155
3156 // Fill the buffers with the necessary info
3157 spec = city_specialists(dlgcity);
3159
3161 "%3d (%4d)", dlgcity->size, spec);
3162 if (supers) {
3164 _("Population: %d, Specialists: %d + %d"),
3165 dlgcity->size, spec, supers);
3166 } else {
3168 _("Population: %d, Specialists: %d"),
3169 dlgcity->size, spec);
3170 }
3171 fc_snprintf(buf_info[INFO_FOOD], sizeof(buf_info[INFO_FOOD]), "%3d (%+4d)",
3174 "%3d (%+4d)", dlgcity->prod[O_SHIELD] + dlgcity->waste[O_SHIELD],
3176 fc_snprintf(buf_info[INFO_TRADE], sizeof(buf_info[INFO_TRADE]), "%3d (%+4d)",
3179 fc_snprintf(buf_info[INFO_GOLD], sizeof(buf_info[INFO_GOLD]), "%3d (%+4d)",
3186 "%4d/%-4d", dlgcity->food_stock,
3188
3190 sizeof(buf_tooltip[INFO_FOOD]));
3192 sizeof(buf_tooltip[INFO_SHIELD]));
3194 sizeof(buf_tooltip[INFO_TRADE]));
3196 sizeof(buf_tooltip[INFO_GOLD]));
3198 sizeof(buf_tooltip[INFO_SCIENCE]));
3200 sizeof(buf_tooltip[INFO_LUXURY]));
3202 sizeof(buf_tooltip[INFO_CULTURE]));
3204 sizeof(buf_tooltip[INFO_POLLUTION]));
3206 sizeof(buf_tooltip[INFO_ILLNESS]));
3207
3209
3210 if (granaryturns == 0) {
3211 // TRANS: city growth is blocked. Keep short.
3212 fc_snprintf(buf_info[INFO_GROWTH], sizeof(buf_info[INFO_GROWTH]), _("blocked"));
3213 } else if (granaryturns == FC_INFINITY) {
3214 // TRANS: city is not growing. Keep short.
3215 fc_snprintf(buf_info[INFO_GROWTH], sizeof(buf_info[INFO_GROWTH]), _("never"));
3216 } else {
3217 /* A negative value means we'll have famine in that many turns.
3218 But that's handled down below. */
3219 // TRANS: city growth turns. Keep short.
3221 PL_("%d turn", "%d turns", abs(granaryturns)),
3222 abs(granaryturns));
3223 }
3224
3226 "%4d", dlgcity->waste[O_TRADE]);
3233
3234 if (!game.info.illness_on) {
3236 " -.-");
3237 } else {
3238 illness = city_illness_calc(dlgcity, nullptr, nullptr, nullptr, nullptr);
3239 // Illness is in tenth of percent
3241 "%5.1f%%", (float) illness / 10.0);
3242 }
3243 if (dlgcity->steal) {
3245 PL_("%d time", "%d times", dlgcity->steal), dlgcity->steal);
3246 } else {
3248 _("Not stolen"));
3249 }
3250
3252 sizeof(buf_info[INFO_AIRLIFT]));
3254 sizeof(buf_tooltip[INFO_AIRLIFT]));
3255
3256 get_city_dialog_output_text(dlgcity, O_FOOD, buffer, sizeof(buffer));
3257
3258 for (int i = 0; i < NUM_INFO_FIELDS; i++) {
3259 qlt[i]->setText(QString(buf_info[i]));
3260
3261 if (buf_tooltip[i][0]) {
3262 qlt[i]->setToolTip("<pre>" + QString(buf_tooltip[i]).toHtmlEscaped()
3263 + "</pre>");
3264 }
3265 }
3266}
3267
3268/************************************************************************/
3272{
3275
3276 setContentsMargins(0, 0 ,0 ,0);
3278 dlgcity = qcity;
3279 production_combo_p->blockSignals(true);
3280 refresh();
3281 production_combo_p->blockSignals(false);
3282}
3283
3284/************************************************************************/
3288{
3289 struct worklist queue;
3290
3291 city_get_queue(dlgcity, &queue);
3292
3294 return;
3295 }
3296
3298 city_set_queue(dlgcity, &queue);
3299}
3300
3301/************************************************************************/
3305{
3306 unit_item *ui;
3307 struct unit_list *units;
3308 char buf[256];
3309 int n;
3310 int happy_cost;
3312 struct player *pplayer = client_player();
3313 const struct civ_map *nmap = &(wld.map);
3314
3315 supported_units->setUpdatesEnabled(false);
3316 supported_units->clear_layout();
3317
3318 if (pplayer != nullptr
3319 && city_owner(dlgcity) != pplayer) {
3321 } else {
3322 units = dlgcity->units_supported;
3323 }
3324
3325 unit_list_iterate(units, punit) {
3327 ui = new unit_item(this, punit, true, happy_cost);
3328 ui->init_pix();
3329 supported_units->add_item(ui);
3331 n = unit_list_size(units);
3332 fc_snprintf(buf, sizeof(buf), _("Supported units %d"), n);
3333 supp_units->setText(QString(buf));
3334 supported_units->update_units();
3335 supported_units->setUpdatesEnabled(true);
3336 current_units->setUpdatesEnabled(true);
3338
3339 if (pplayer != nullptr
3340 && city_owner(dlgcity) != pplayer) {
3342 } else {
3343 units = dlgcity->tile->units;
3344 }
3345
3346 unit_list_iterate(units, punit) {
3347 ui = new unit_item(this , punit, false);
3348 ui->init_pix();
3351
3352 n = unit_list_size(units);
3353 fc_snprintf(buf, sizeof(buf), _("Present units %d"), n);
3354 curr_units->setText(QString(buf));
3355
3357 current_units->setUpdatesEnabled(true);
3358}
3359
3360/************************************************************************/
3364 const QItemSelection &ds)
3365{
3366 QModelIndex index;
3367 QModelIndexList indexes = sl.indexes();
3368
3369 if (indexes.isEmpty()) {
3370 return;
3371 }
3372
3373 index = indexes.at(0);
3374 selected_row_p = index.row();
3376}
3377
3378/************************************************************************/
3382{
3383 int size, i;
3384 struct city *other_pcity = nullptr;
3385 struct player *pplayer = client_player();
3386
3387 if (pplayer == nullptr) {
3388 return;
3389 }
3390
3391 size = city_list_size(pplayer->cities);
3392
3393 if (size <= 1) {
3394 return;
3395 }
3396
3397 for (i = 0; i < size; i++) {
3398 if (dlgcity == city_list_get(pplayer->cities, i)) {
3399 break;
3400 }
3401 }
3402
3403 if (i >= size - 1) {
3404 // Current city last in the list (size - 1) or disappeared (size)
3405 other_pcity = city_list_get(pplayer->cities, 0);
3406 } else {
3407 other_pcity = city_list_get(pplayer->cities, i + 1);
3408 }
3409
3412}
3413
3414/************************************************************************/
3418{
3419 int size, i;
3420 struct city *other_pcity = nullptr;
3421 struct player *pplayer = client_player();
3422
3423 if (pplayer == nullptr) {
3424 return;
3425 }
3426
3427 size = city_list_size(pplayer->cities);
3428
3429 if (size <= 1) {
3430 return;
3431 }
3432
3433 for (i = 0; i < size; i++) {
3434 if (dlgcity == city_list_get(pplayer->cities, i)) {
3435 break;
3436 }
3437 }
3438
3439 if (i == 0 || i == size) {
3440 // Current city in the beginning of the list or disappeared
3441 other_pcity = city_list_get(pplayer->cities, size - 1);
3442 } else {
3443 other_pcity = city_list_get(pplayer->cities, i - 1);
3444 }
3445
3448}
3449
3450/************************************************************************/
3454{
3455 char buf[32];
3456 QString str;
3458
3460 production_combo_p->setRange(0, cost);
3462 if (dlgcity->shield_stock >= cost) {
3463 production_combo_p->setValue(cost);
3464 } else {
3466 }
3467 production_combo_p->setAlignment(Qt::AlignCenter);
3468 str = QString(buf);
3469 str = str.simplified();
3470
3471 production_combo_p->setFormat(QString("(%p%) %2\n%1")
3473 str));
3474
3475 production_combo_p->updateGeometry();
3476
3477}
3478
3479/************************************************************************/
3483{
3484 char buf[1024], buf2[1024];
3486 int value = dlgcity->client.buy_cost;
3488 int city_id = dlgcity->id;
3489
3490 if (!can_client_issue_orders()) {
3491 return;
3492 }
3493
3495 fc_snprintf(buf2, ARRAY_SIZE(buf2), PL_("Treasury contains %d gold.",
3496 "Treasury contains %d gold.",
3497 client_player()->economic.gold),
3498 client_player()->economic.gold);
3499 fc_snprintf(buf, ARRAY_SIZE(buf), PL_("Buy %s for %d gold?",
3500 "Buy %s for %d gold?", value),
3501 name, value);
3502 ask->set_text_title(buf, buf2);
3503 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
3504 ask->setDefaultButton(QMessageBox::Cancel);
3505 ask->setAttribute(Qt::WA_DeleteOnClose);
3506 connect(ask, &hud_message_box::accepted, this, [=]() {
3507 struct city *pcity = game_city_by_number(city_id);
3508
3509 if (!pcity) {
3510 return;
3511 }
3512
3514 });
3515 ask->show();
3516}
3517
3518/************************************************************************/
3522{
3523 QFont f = QApplication::font();
3524 QFontMetrics fm(f);
3525 QPixmap *pix = nullptr;
3529 struct sprite *sprite;
3530 int h, cost, item, targets_used, col, upkeep;
3531 struct item items[MAX_NUM_PRODUCTION_TARGETS];
3532 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
3533 struct worklist queue;
3534 impr_item *ui;
3535
3536 upkeep = 0;
3537 city_buildings->setUpdatesEnabled(false);
3539
3540 h = fm.height() + 6;
3542 name_and_sort_items(targets, targets_used, items, false, dlgcity);
3543
3544 for (item = 0; item < targets_used; item++) {
3545 struct universal target = items[item].item;
3546
3547 ui = new impr_item(this, target.value.building, dlgcity);
3548 ui->init_pix();
3550
3551 fc_assert_action(VUT_IMPROVEMENT == target.kind, continue);
3553 upkeep = upkeep + city_improvement_upkeep(dlgcity, target.value.building);
3554 if (sprite != nullptr) {
3555 pix = sprite->pm;
3556 pix_scaled = pix->scaledToHeight(h);
3557 }
3558 }
3559
3560 city_get_queue(dlgcity, &queue);
3561 p_table_p->setRowCount(worklist_length(&queue));
3562
3563 for (int i = 0; i < worklist_length(&queue); i++) {
3564 struct universal target = queue.entries[i];
3565
3566 tooltip = "";
3567
3568 if (VUT_UTYPE == target.kind) {
3570 cost = utype_build_shield_cost(dlgcity, nullptr, target.value.utype);
3571 tooltip = get_tooltip_unit(target.value.utype, true).trimmed();
3575 } else {
3579 dlgcity, true).trimmed();
3580
3582 cost = -1;
3583 } else {
3585 }
3586 }
3587
3588 for (col = 0; col < 3; col++) {
3589 qitem = new QTableWidgetItem();
3590 qitem->setToolTip(tooltip);
3591
3592 switch (col) {
3593 case 0:
3594 if (sprite) {
3595 pix = sprite->pm;
3596 pix_scaled = pix->scaledToHeight(h);
3597 qitem->setData(Qt::DecorationRole, pix_scaled);
3598 }
3599 break;
3600
3601 case 1:
3602 if (str.contains('[') && str.contains(']')) {
3603 int ii, ij;
3604
3605 ii = str.lastIndexOf('[');
3606 ij = str.lastIndexOf(']');
3607 if (ij > ii) {
3608 str = str.remove(ii, ij - ii + 1);
3609 }
3610 }
3611 qitem->setText(str);
3612 break;
3613
3614 case 2:
3615 qitem->setTextAlignment(Qt::AlignRight);
3616 qitem->setText(QString::number(cost));
3617 break;
3618 }
3619 p_table_p->setItem(i, col, qitem);
3620 }
3621 }
3622
3623 p_table_p->horizontalHeader()->setStretchLastSection(false);
3624 p_table_p->resizeColumnsToContents();
3625 p_table_p->resizeRowsToContents();
3626 p_table_p->horizontalHeader()->setStretchLastSection(true);
3627
3629 city_buildings->setUpdatesEnabled(true);
3630 city_buildings->setUpdatesEnabled(true);
3631
3632 curr_impr->setText(QString(_("Improvements - upkeep %1")).arg(upkeep));
3633}
3634
3635/************************************************************************/
3639{
3640 cid id;
3641 QVariant qvar;
3642
3644 struct universal univ;
3645
3646 id = qvar.toInt();
3647 univ = cid_production(id);
3649 }
3650}
3651
3652/************************************************************************/
3657{
3659 int when = 1;
3660
3661 pw = new production_widget(this, dlgcity, future_targets->isChecked(),
3662 when, selected_row_p, show_units->isChecked(),
3663 false, show_wonders->isChecked(),
3664 show_buildings->isChecked());
3665 pw->show();
3666}
3667
3668/************************************************************************/
3673{
3675 int when = 4;
3676
3677 pw = new production_widget(this, dlgcity, future_targets->isChecked(),
3678 when, selected_row_p, show_units->isChecked(),
3679 false, show_wonders->isChecked(),
3680 show_buildings->isChecked());
3681 pw->show();
3682}
3683
3684/************************************************************************/
3688{
3689 struct worklist empty;
3690
3691 if (!can_client_issue_orders()) {
3692 return;
3693 }
3694
3697}
3698
3699/************************************************************************/
3703{
3704 QModelIndex index;
3705 struct worklist queue;
3706 struct universal *target;
3707
3709 return;
3710 }
3711
3712 target = new universal;
3713 city_get_queue(dlgcity, &queue);
3714 worklist_peek_ith(&queue, target, selected_row_p);
3716 worklist_insert(&queue, target, selected_row_p - 1);
3717 city_set_queue(dlgcity, &queue);
3718 index = p_table_p->model()->index(selected_row_p - 1, 0);
3719 p_table_p->setCurrentIndex(index);
3720 delete target;
3721
3722}
3723
3724/************************************************************************/
3728{
3730
3731 if (selected_row_p < 0
3732 || selected_row_p >= p_table_p->rowCount()) {
3733 return;
3734 }
3735
3739}
3740
3741/************************************************************************/
3745{
3746 QModelIndex index;
3747 struct worklist queue;
3748 struct universal *target;
3749
3751 return;
3752 }
3753
3754 target = new universal;
3755 city_get_queue(dlgcity, &queue);
3756 worklist_peek_ith(&queue, target, selected_row_p);
3758 worklist_insert(&queue, target, selected_row_p + 1);
3759 city_set_queue(dlgcity, &queue);
3760 index = p_table_p->model()->index(selected_row_p + 1, 0);
3761 p_table_p->setCurrentIndex(index);
3762 delete target;
3763}
3764
3765/************************************************************************/
3769{
3770 hud_input_box *ask = new hud_input_box(gui()->central_wdg);
3771 int city_id = dlgcity->id;
3772
3773 ask->set_text_title_definput(_("What should we name new worklist?"),
3774 _("Save current worklist"),
3775 _("New worklist"));
3776 ask->setAttribute(Qt::WA_DeleteOnClose);
3777 connect(ask, &hud_message_box::accepted, [=]() {
3778 struct global_worklist *gw;
3779 struct worklist queue;
3781 QString text;
3782 struct city *pcity = game_city_by_number(city_id);
3783
3784 ask_bytes = ask->input_edit.text().toUtf8();
3785 text = ask_bytes.data();
3786 if (!text.isEmpty()) {
3787 ask_bytes = text.toUtf8();
3789 city_get_queue(pcity, &queue);
3790 global_worklist_set(gw, &queue);
3791 }
3792 });
3793 ask->show();
3794}
3795
3796/************************************************************************/
3800{
3801 QString buf;
3802
3803 // Defeat keyboard shortcut mnemonics
3805 .replace("&", "&&"));
3806
3807 if (city_unhappy(dlgcity)) {
3808 // TRANS: city dialog title
3809 buf = QString(_("%1 - %2 citizens - DISORDER")).arg(city_name_get(dlgcity),
3811 } else if (city_celebrating(dlgcity)) {
3812 // TRANS: city dialog title
3813 buf = QString(_("%1 - %2 citizens - celebrating")).arg(city_name_get(dlgcity),
3815 } else if (city_happy(dlgcity)) {
3816 // TRANS: city dialog title
3817 buf = QString(_("%1 - %2 citizens - happy")).arg(city_name_get(dlgcity),
3819 } else {
3820 // TRANS: city dialog title
3821 buf = QString(_("%1 - %2 citizens")).arg(city_name_get(dlgcity),
3823 }
3824
3826}
3827
3828/************************************************************************/
3833{
3834 if (!::city_dlg_created) {
3835 ::city_dlg = new city_dialog(gui()->mapview_wdg);
3836 }
3837
3839 city_dlg->show();
3840 city_dlg->activateWindow();
3841 city_dlg->raise();
3842}
3843
3844/************************************************************************/
3848{
3849 if (!::city_dlg_created) {
3850 return;
3851 }
3852
3853 city_dlg->close();
3854 ::city_dlg_created = false;
3855}
3856
3857/************************************************************************/
3861{
3862 if (!::city_dlg_created) {
3863 return;
3864 }
3865
3867}
3868
3869/************************************************************************/
3876
3877/************************************************************************/
3881{
3882 if (!::city_dlg_created) {
3883 return;
3884 }
3885
3887 city_dlg->refresh();
3888 }
3889}
3890
3891/************************************************************************/
3895{
3897 QFont *f;
3898
3899 if (!::city_dlg_created) {
3900 return;
3901 }
3902
3903 l = city_dlg->findChildren<QLabel *>();
3904
3906
3907 for (int i = 0; i < l.size(); ++i) {
3908 if (l.at(i)->property(fonts::notify_label).isValid()) {
3909 l.at(i)->setFont(*f);
3910 }
3911 }
3912}
3913
3914/************************************************************************/
3931
3932/************************************************************************/
3936{
3937 if (!::city_dlg_created) {
3938 return false;
3939 }
3940
3941 if (city_dlg->dlgcity == pcity && city_dlg->isVisible()) {
3942 return true;
3943 }
3944
3945 return false;
3946}
3947
3948/************************************************************************/
3951bool fc_tooltip::eventFilter(QObject *obj, QEvent *ev)
3952{
3955 QRect rect;
3956
3957 if (ev->type() == QEvent::ToolTip) {
3959
3960 if (!view) {
3961 return false;
3962 }
3963
3964 help_event = static_cast<QHelpEvent *>(ev);
3965 QPoint pos = help_event->pos();
3966 QModelIndex index = view->indexAt(pos);
3967 QPoint hpos;
3968
3969 if (!index.isValid()) {
3970 return false;
3971 }
3972
3973 item_tooltip = view->model()->data(index, Qt::ToolTipRole).toString();
3974 rect = view->visualRect(index);
3975
3976 hpos = help_event->globalPos();
3977
3978 rect.setX(rect.x() + hpos.x());
3979 rect.setY(rect.y() + hpos.y());
3980
3981 if (!item_tooltip.isEmpty()) {
3982 QToolTip::showText(help_event->globalPos(), item_tooltip, view, rect);
3983 } else {
3984 QToolTip::hideText();
3985 }
3986
3987 return true;
3988 }
3989
3990 return false;
3991}
3992
3993/************************************************************************/
3997{
3998 return QString("<b>" + text + "</b>");
3999}
4000
4001/************************************************************************/
4006 bool ext)
4007{
4009 QString upkeep;
4010 QString s1, s2, str;
4011 const char *req = skip_intl_qualifier_prefix(_("?tech:None"));
4012 struct player *pplayer = client_player();
4013
4014 if (pcity != nullptr) {
4015 upkeep = QString::number(city_improvement_upkeep(pcity, building));
4016 } else {
4017 upkeep = QString::number(building->upkeep);
4018 }
4020 if (pobs->source.kind == VUT_ADVANCE) {
4021 req = advance_name_translation(pobs->source.value.advance);
4022 break;
4023 }
4025 s2 = QString(req);
4026 str = _("Obsolete by:");
4027 str = str + " " + s2;
4028 def_str = "<p style='white-space:pre'><b>"
4029 + QString(improvement_name_translation(building)).toHtmlEscaped()
4030 + "</b>\n";
4031 if (pcity != nullptr) {
4032 def_str += QString(_("Cost: %1, Upkeep: %2\n"))
4033 .arg(impr_build_shield_cost(pcity, building))
4034 .arg(upkeep).toHtmlEscaped();
4035 } else {
4037 nullptr, building);
4038
4039 def_str += QString(_("Cost Estimate: %1, Upkeep: %2\n"))
4040 .arg(cost_est)
4041 .arg(upkeep).toHtmlEscaped();
4042 }
4043 if (s1.compare(s2) != 0) {
4044 def_str = def_str + str.toHtmlEscaped() + "\n";
4045 }
4046 def_str = def_str + "\n";
4047 if (ext) {
4048 char buffer[8192];
4049
4050 str = helptext_building(buffer, sizeof(buffer), pplayer,
4051 nullptr, building);
4052 str = cut_helptext(str);
4053 str = split_text(str, true);
4054 str = str.trimmed();
4055 def_str = def_str + str.toHtmlEscaped();
4056 }
4057 return def_str;
4058}
4059
4060/************************************************************************/
4064QString get_tooltip_unit(const struct unit_type *utype, bool ext)
4065{
4068 QString str;
4069 const struct unit_type *obsolete;
4070 struct advance *tech;
4071
4072 def_str = "<b>"
4073 + QString(utype_name_translation(utype)).toHtmlEscaped()
4074 + "</b>\n";
4075 obsolete = utype->obsoleted_by;
4076 if (obsolete) {
4077 // FIXME: Don't give the impression that primary tech is (always) the only one.
4079 obsolete_str = QString("</td></tr><tr><td colspan=\"3\">");
4080 if (tech && tech != advance_by_number(A_NONE)) {
4081 /* TRANS: this and nearby literal strings are interpreted
4082 * as (Qt) HTML */
4083 obsolete_str = obsolete_str + QString(_("Obsoleted by %1 (%2)."))
4085 .arg(advance_name_translation(tech)).toHtmlEscaped();
4086 } else {
4087 obsolete_str = obsolete_str + QString(_("Obsoleted by %1."))
4088 .arg(utype_name_translation(obsolete)).toHtmlEscaped();
4089 }
4090 }
4091 def_str += "<table width=\"100\%\"><tr><td>"
4092 + bold(QString(_("Attack:"))) + " "
4093 + QString::number(utype->attack_strength).toHtmlEscaped()
4094 + QString("</td><td>") + bold(QString(_("Defense:"))) + " "
4095 + QString::number(utype->defense_strength).toHtmlEscaped()
4096 + QString("</td><td>") + bold(QString(_("Move:"))) + " "
4097 + QString(move_points_text(utype->move_rate, TRUE)).toHtmlEscaped()
4098 + QString("</td></tr><tr><td>")
4099 + bold(QString(_("Cost:"))) + " "
4100 + QString::number(utype_build_shield_cost_base(utype))
4101 .toHtmlEscaped()
4102 + QString("</td><td colspan=\"2\">")
4103 + bold(QString(_("Basic Upkeep:")))
4104 + " " + QString(helptext_unit_upkeep_str(utype)).toHtmlEscaped()
4105 + QString("</td></tr><tr><td>")
4106 + bold(QString(_("Hitpoints:"))) + " "
4107 + QString::number(utype->hp).toHtmlEscaped()
4108 + QString("</td><td>") + bold(QString(_("Firepower:"))) + " "
4109 + QString::number(utype->firepower).toHtmlEscaped()
4110 + QString("</td><td>") + bold(QString(_("Vision:"))) + " "
4111 + QString::number((int) sqrt((double) utype->vision_radius_sq))
4112 .toHtmlEscaped()
4113 + obsolete_str
4114 + QString("</td></tr></table><p style='white-space:pre'>");
4115 if (ext) {
4116 char buffer[8192];
4117 char buf2[1];
4118
4119 buf2[0] = '\0';
4120 str = helptext_unit(buffer, sizeof(buffer), client_player(),
4121 buf2, utype, TRUE);
4122 str = cut_helptext(str);
4123 str = split_text(str, true);
4124 str = str.trimmed().toHtmlEscaped();
4125 def_str = def_str + str;
4126 }
4127
4128 return def_str;
4129};
4130
4131/************************************************************************/
4135{
4138 char buffer[8192];
4139 char buf2[1];
4140 struct universal *target;
4141 struct player *pplayer = client_player();
4142
4143 buf2[0] = '\0';
4144 target = reinterpret_cast<universal *>(qvar.value<void *>());
4145
4146 if (target == nullptr) {
4147 } else if (VUT_UTYPE == target->kind) {
4149 str = helptext_unit(buffer, sizeof(buffer), pplayer,
4150 buf2, target->value.utype, TRUE);
4151 } else {
4152 if (!is_convert_improvement(target->value.building)) {
4154 }
4155
4156 str = helptext_building(buffer, sizeof(buffer), pplayer,
4157 nullptr, target->value.building);
4158 }
4159
4160 // Remove all lines from help which has '*' in first 3 chars
4162 ret_str = split_text(ret_str, true);
4163 ret_str = ret_str.trimmed();
4164 ret_str = def_str + ret_str.toHtmlEscaped();
4165
4166 return ret_str;
4167}
4168
4169/************************************************************************/
4173 QObject *parent,
4174 struct city *city)
4175 : QItemDelegate(parent)
4176{
4177 pd = sh;
4178 item_height = sh.y();
4179 pcity = city;
4180}
4181
4182/************************************************************************/
4187 const QModelIndex &index) const
4188{
4189 struct universal *target;
4190 QString name;
4191 QVariant qvar;
4192 QPixmap *pix;
4194 QRect rect1;
4195 QRect rect2;
4196 struct sprite *sprite;
4197 bool useless = false;
4198 bool is_convert = false;
4199 bool is_neutral = false;
4200 bool is_sea = false;
4201 bool is_flying = false;
4202 bool is_unit = true;
4203 QPixmap pix_dec(option.rect.width(), option.rect.height());
4205 color col;
4206 QIcon icon = current_app()->style()->standardIcon(QStyle::SP_DialogCancelButton);
4207 bool free_sprite = false;
4208 struct unit_class *pclass;
4209
4210 if (!option.rect.isValid()) {
4211 return;
4212 }
4213
4214 qvar = index.data();
4215
4216 if (!qvar.isValid()) {
4217 return;
4218 }
4219
4220 target = reinterpret_cast<universal *>(qvar.value<void *>());
4221
4222 if (target == nullptr) {
4223 col.qcolor = Qt::white;
4224 sprite = qtg_create_sprite(100, 100, &col);
4225 free_sprite = true;
4226 *sprite->pm = icon.pixmap(100, 100);
4227 name = _("Cancel");
4228 is_unit = false;
4229 } else if (VUT_UTYPE == target->kind) {
4232 pclass = utype_class(target->value.utype);
4236 is_sea = true;
4237 }
4238
4239 if ((utype_fuel(target->value.utype)
4244 /* FIXME: Assumed to be flying since only missiles can do suicide
4245 * attacks in classic-like rulesets. This isn't true for all
4246 * rulesets. Not a high priority to fix since all is_flying and
4247 * is_sea is used for is to set a color. */
4249 target->value.utype)) {
4250 if (is_sea) {
4251 is_sea = false;
4252 }
4253 is_flying = true;
4254 }
4255
4259 } else {
4260 is_unit = false;
4263 useless = is_improvement_redundant(pcity, target->value.building);
4264 is_convert = (target->value.building->genus == IG_CONVERT);
4265 }
4266
4267 if (sprite != nullptr) {
4268 pix = sprite->pm;
4269 pix_scaled = pix->scaledToHeight(item_height - 2, Qt::SmoothTransformation);
4270
4271 if (useless) {
4273 }
4274 }
4275
4276 opt = QItemDelegate::setOptions(index, option);
4277 painter->save();
4278 opt.displayAlignment = Qt::AlignLeft;
4279 opt.textElideMode = Qt::ElideMiddle;
4280 QItemDelegate::drawBackground(painter, opt, index);
4281 rect1 = option.rect;
4282 rect1.setWidth(pix_scaled.width() + 4);
4283 rect2 = option.rect;
4284 rect2.setLeft(option.rect.left() + rect1.width());
4285 rect2.setTop(rect2.top() + (rect2.height()
4286 - painter->fontMetrics().height()) / 2);
4287 QItemDelegate::drawDisplay(painter, opt, rect2, name);
4288
4289 if (is_unit) {
4290 if (is_sea) {
4291 pix_dec.fill(QColor(0, 0, 255, 80));
4292 } else if (is_flying) {
4293 pix_dec.fill(QColor(220, 0, 0, 80));
4294 } else if (is_neutral) {
4295 pix_dec.fill(QColor(0, 120, 0, 40));
4296 } else {
4297 pix_dec.fill(QColor(0, 0, 150, 40));
4298 }
4299
4300 QItemDelegate::drawDecoration(painter, option, option.rect, pix_dec);
4301 }
4302
4303 if (is_convert) {
4304 pix_dec.fill(QColor(255, 255, 0, 70));
4305 QItemDelegate::drawDecoration(painter, option, option.rect, pix_dec);
4306 }
4307
4308 if (!pix_scaled.isNull()) {
4309 QItemDelegate::drawDecoration(painter, opt, rect1, pix_scaled);
4310 }
4311
4312 drawFocus(painter, opt, option.rect);
4313
4314 painter->restore();
4315
4316 if (free_sprite) {
4318 }
4319}
4320
4321/************************************************************************/
4326 const QRect &rect) const
4327{
4328 QPixmap pix(option.rect.width(), option.rect.height());
4329
4330 if ((option.state & QStyle::State_MouseOver) == 0 || !rect.isValid()) {
4331 return;
4332 }
4333
4334 pix.fill(QColor(50, 50, 50, 50));
4335 QItemDelegate::drawDecoration(painter, option, option.rect, pix);
4336}
4337
4338/************************************************************************/
4342 const QModelIndex &index) const
4343{
4344 QSize s;
4345
4346 s.setWidth(pd.x());
4347 s.setHeight(pd.y());
4348 return s;
4349}
4350
4351/************************************************************************/
4355 QObject *parent): QObject()
4356{
4358 target = ptarget;
4359}
4360
4361/************************************************************************/
4365{
4366 // Allocated as renegade in model
4367 if (target != nullptr) {
4368 delete target;
4369 }
4370}
4371
4372/************************************************************************/
4376{
4377 return QVariant::fromValue((void *)target);
4378}
4379
4380/************************************************************************/
4384{
4385 return false;
4386}
4387
4388/************************************************************************/
4392 bool su, bool sw, bool sb,
4393 QObject *parent)
4394 : QAbstractListModel(parent)
4395{
4396 show_units = su;
4397 show_wonders = sw;
4399 mcity = pcity;
4400 future_t = f;
4401 populate();
4402}
4403
4404/************************************************************************/
4412
4413/************************************************************************/
4417{
4418 if (!index.isValid()) {
4419 return QVariant();
4420 }
4421
4422 if (index.row() >= 0 && index.row() < rowCount() && index.column() >= 0
4423 && index.column() < columnCount()
4424 && (index.column() + index.row() * 3 < city_target_list.count())) {
4425 int r, c, t, new_index;
4426
4427 r = index.row();
4428 c = index.column();
4429 t = r * 3 + c;
4430 new_index = t / 3 + rowCount() * c;
4431 // Exception, shift whole column
4432 if ((c == 2) && city_target_list.count() % 3 == 1) {
4433 new_index = t / 3 + rowCount() * c - 1;
4434 }
4435 if (role == Qt::ToolTipRole) {
4437 }
4438
4439 return city_target_list[new_index]->data();
4440 }
4441
4442 return QVariant();
4443}
4444
4445/************************************************************************/
4449{
4451 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
4452 struct item items[MAX_NUM_PRODUCTION_TARGETS];
4453 struct universal *renegade;
4454 int item, targets_used;
4455 QString str;
4457 QFontMetrics fm(f);
4458
4459 sh.setY(fm.height() * 2);
4460 sh.setX(0);
4461
4463 city_target_list.clear();
4464
4466 future_t);
4467 name_and_sort_items(targets, targets_used, items, false, mcity);
4468
4469 for (item = 0; item < targets_used; item++) {
4470 if (future_t || can_city_build_now(&(wld.map), mcity, &items[item].item)) {
4471 renegade = new universal(items[item].item);
4472
4473 // Renegade deleted in production_item destructor
4474 if (VUT_UTYPE == renegade->kind) {
4475 str = utype_name_translation(renegade->value.utype);
4476 sh.setX(qMax(sh.x(), fm.horizontalAdvance(str)));
4477
4478 if (show_units) {
4479 pi = new production_item(renegade, this);
4481 } else {
4482 delete renegade;
4483 }
4484 } else {
4485 str = improvement_name_translation(renegade->value.building);
4486 sh.setX(qMax(sh.x(), fm.horizontalAdvance(str)));
4487
4488 if ((is_wonder(renegade->value.building) && show_wonders)
4489 || (is_improvement(renegade->value.building) && show_buildings)
4490 || (is_convert_improvement(renegade->value.building))
4491 || (is_special_improvement(renegade->value.building)
4492 && show_buildings)) {
4493 pi = new production_item(renegade, this);
4495 } else {
4496 delete renegade;
4497 }
4498 }
4499 }
4500 }
4501
4502 pi = new production_item(nullptr, this);
4504 sh.setX(2 * sh.y() + sh.x());
4505 sh.setX(qMin(sh.x(), 250));
4506}
4507
4508/************************************************************************/
4512 const QVariant &value, int role)
4513{
4514 if (!index.isValid() || role != Qt::DisplayRole || role != Qt::ToolTipRole)
4515 return false;
4516
4517 if (index.row() >= 0 && index.row() < rowCount() && index.column() >= 0
4518 && index.column() < columnCount()) {
4519 bool change = city_target_list[index.row()]->setData();
4520 return change;
4521 }
4522
4523 return false;
4524}
4525
4526/************************************************************************/
4535 bool future, int when, int curr,
4536 bool show_units, bool buy,
4537 bool show_wonders,
4538 bool show_buildings): QTableView()
4539{
4540 QPoint pos, sh;
4541 QRect rect = QApplication::primaryScreen()->availableGeometry();
4542 int desk_width = rect.width();
4543 int desk_height = rect.height();
4544 fc_tt = new fc_tooltip(this);
4545 setAttribute(Qt::WA_DeleteOnClose);
4546 setWindowFlags(Qt::Popup);
4547 verticalHeader()->setVisible(false);
4548 horizontalHeader()->setVisible(false);
4549 setProperty("showGrid", false);
4551 sh_units = show_units;
4552 pw_city = pcity;
4553 buy_it = buy;
4554 when_change = when;
4555 list_model = new city_production_model(pw_city, future, show_units,
4556 show_wonders, show_buildings, this);
4557 sh = list_model->sh;
4558 c_p_d = new city_production_delegate(sh, this, pw_city);
4561 viewport()->installEventFilter(fc_tt);
4562 installEventFilter(this);
4564 const QItemSelection &)),
4566 const QItemSelection &)));
4569 setFixedWidth(3 * sh.x() + 6);
4570 setFixedHeight(list_model->rowCount()*sh.y() + 6);
4571
4572 if (width() > desk_width) {
4574 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
4575 } else {
4576 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
4577 }
4578
4579 if (height() > desk_height) {
4581 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
4582 } else {
4583 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
4584 }
4585
4586 pos = QCursor::pos();
4587
4588 if (pos.x() + width() > desk_width) {
4589 pos.setX(desk_width - width());
4590 } else if (pos.x() - width() < 0) {
4591 pos.setX(0);
4592 }
4593
4594 if (pos.y() + height() > desk_height) {
4595 pos.setY(desk_height - height());
4596 } else if (pos.y() - height() < 0) {
4597 pos.setY(0);
4598 }
4599
4600 move(pos);
4601 setMouseTracking(true);
4602 setFocus();
4603}
4604
4605/************************************************************************/
4609{
4610 if (event->button() == Qt::RightButton) {
4611 close();
4612 return;
4613 }
4614
4615 QAbstractItemView::mousePressEvent(event);
4616}
4617
4618/************************************************************************/
4622{
4623 QRect pw_rect;
4624 QPoint br;
4625
4626 if (obj != this)
4627 return false;
4628
4629 if (ev->type() == QEvent::MouseButtonPress) {
4630 pw_rect.setTopLeft(pos());
4631 br.setX(pos().x() + width());
4632 br.setY(pos().y() + height());
4633 pw_rect.setBottomRight(br);
4634
4635 if (!pw_rect.contains(QCursor::pos())) {
4636 close();
4637 }
4638 }
4639
4640 return false;
4641}
4642
4643/************************************************************************/
4647 const QItemSelection &ds)
4648{
4649 QModelIndexList indexes = selectionModel()->selectedIndexes();
4650 QModelIndex index;
4651 QVariant qvar;
4652 struct worklist queue;
4653 struct universal *target;
4654
4655 if (indexes.isEmpty() || client_is_observer()) {
4656 return;
4657 }
4658 index = indexes.at(0);
4659 qvar = index.data(Qt::UserRole);
4660 if (!qvar.isValid()) {
4661 return;
4662 }
4663 target = reinterpret_cast<universal *>(qvar.value<void *>());
4664 if (target != nullptr) {
4665 city_get_queue(pw_city, &queue);
4666 switch (when_change) {
4667 case 0: // Change current target
4669 if (city_can_buy(pw_city) && buy_it) {
4671 }
4672 break;
4673
4674 case 1: // Change current (selected on list)
4677 } else {
4679 worklist_insert(&queue, target, curr_selection);
4680 city_set_queue(pw_city, &queue);
4681 }
4682 break;
4683
4684 case 2: // Insert before
4686 curr_selection = 0;
4687 }
4690 worklist_insert(&queue, target, curr_selection);
4691 city_set_queue(pw_city, &queue);
4692 break;
4693
4694 case 3: // Insert after
4696 city_queue_insert(pw_city, -1, target);
4697 break;
4698 }
4700 worklist_insert(&queue, target, curr_selection);
4701 city_set_queue(pw_city, &queue);
4702 break;
4703
4704 case 4: // Add last
4705 city_queue_insert(pw_city, -1, target);
4706 break;
4707
4708 default:
4709 break;
4710 }
4711 }
4712 close();
4713 destroy();
4714}
4715
4716/************************************************************************/
4720{
4721 delete c_p_d;
4722 delete list_model;
4723 viewport()->removeEventFilter(fc_tt);
4724 removeEventFilter(this);
4725}
const char * action_id_name_translation(action_id act_id)
Definition actions.c:1271
#define action_id_univs_not_blocking(act_id, act_uni, tgt_uni)
Definition actions.h:740
#define str
Definition astring.c:76
#define n
Definition astring.c:77
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_CLR(bv, bit)
Definition bitvector.h:94
QRect zealous_crop_rect(QImage &p)
Definition canvas.cpp:419
void qtg_canvas_free(struct canvas *store)
Definition canvas.cpp:48
struct canvas * qtg_canvas_create(int width, int height)
Definition canvas.cpp:36
void qtg_canvas_copy(struct canvas *dest, struct canvas *src, int src_x, int src_y, int dest_x, int dest_y, int width, int height)
Definition canvas.cpp:79
void pixmap_copy(QPixmap *dest, QPixmap *src, int src_x, int src_y, int dest_x, int dest_y, int width, int height)
Definition canvas.cpp:101
static QFont * get_font(enum client_font font)
Definition canvas.cpp:379
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
struct canvas int int canvas_y
Definition canvas_g.h:43
struct canvas int canvas_x
Definition canvas_g.h:43
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
citizens citizens_nation_get(const struct city *pcity, const struct player_slot *pslot)
Definition citizens.c:74
#define citizens_iterate_end
Definition citizens.h:54
#define citizens_iterate(_pcity, _pslot, _nationality)
Definition citizens.h:48
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:663
int city_production_build_shield_cost(const struct city *pcity)
Definition city.c:737
int city_granary_size(int city_size)
Definition city.c:2132
struct tile * city_map_to_tile(const struct civ_map *nmap, const struct tile *city_center, int city_radius_sq, int city_map_x, int city_map_y)
Definition city.c:305
int city_superspecialists(const struct city *pcity)
Definition city.c:3358
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
int city_improvement_upkeep(const struct city *pcity, const struct impr_type *b)
Definition city.c:1255
bool is_city_option_set(const struct city *pcity, enum city_options option)
Definition city.c:3428
int city_population(const struct city *pcity)
Definition city.c:1191
int city_unit_unhappiness(const struct civ_map *nmap, struct unit *punit, int *free_unhappy)
Definition city.c:3049
bool city_unhappy(const struct city *pcity)
Definition city.c:1626
bool city_celebrating(const struct city *pcity)
Definition city.c:1645
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size, int *ill_trade, int *ill_pollution)
Definition city.c:2870
bool city_happy(const struct city *pcity)
Definition city.c:1614
int city_map_radius_sq_get(const struct city *pcity)
Definition city.c:137
int rs_max_city_radius_sq(void)
Definition city.c:159
citizens city_specialists(const struct city *pcity)
Definition city.c:3343
bool can_city_build_now(const struct civ_map *nmap, const struct city *pcity, const struct universal *target)
Definition city.c:1013
int city_turns_to_grow(const struct city *pcity)
Definition city.c:1996
const char * city_production_name_translation(const struct city *pcity)
Definition city.c:700
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
citizen_category
Definition city.h:265
#define city_owner(_pcity_)
Definition city.h:563
#define MAX_CITY_SIZE
Definition city.h:104
citizen_feeling
Definition city.h:276
@ FEELING_EFFECT
Definition city.h:279
@ FEELING_LUXURY
Definition city.h:278
@ FEELING_FINAL
Definition city.h:282
@ FEELING_LAST
Definition city.h:283
@ FEELING_BASE
Definition city.h:277
@ FEELING_NATIONALITY
Definition city.h:280
@ FEELING_MARTIAL
Definition city.h:281
void qtg_popdown_city_dialog(struct city *pcity)
Definition citydlg.cpp:3860
void qtg_real_city_dialog_refresh(struct city *pcity)
Definition citydlg.cpp:3880
QString split_text(QString text, bool cut)
Definition optiondlg.cpp:62
void city_font_update()
Definition citydlg.cpp:3894
bool qtg_city_dialog_is_open(struct city *pcity)
Definition citydlg.cpp:3935
QString get_tooltip(QVariant qvar)
Definition citydlg.cpp:4134
void qtg_popdown_all_city_dialogs()
Definition citydlg.cpp:3872
static city_dialog * city_dlg
Definition citydlg.cpp:75
void qtg_refresh_unit_city_dialogs(struct unit *punit)
Definition citydlg.cpp:3919
static QString bold(QString text)
Definition citydlg.cpp:3996
void qtg_real_city_dialog_popup(struct city *pcity)
Definition citydlg.cpp:3832
QString get_tooltip_improvement(const impr_type *building, struct city *pcity, bool ext)
Definition citydlg.cpp:4005
static bool city_dlg_created
Definition citydlg.cpp:71
static void pixmap_put_x(QPixmap *pix)
Definition citydlg.cpp:350
QString cut_helptext(QString text)
QString get_tooltip_unit(const struct unit_type *utype, bool ext)
Definition citydlg.cpp:4064
void destroy_city_dialog()
Definition citydlg.cpp:3847
void get_city_dialog_output_text(const struct city *pcity, Output_type_id otype, char *buf, size_t bufsz)
void get_city_dialog_production(struct city *pcity, char *buffer, size_t buffer_len)
int city_set_worklist(struct city *pcity, const struct worklist *pworklist)
int get_city_citizen_types(struct city *pcity, enum citizen_feeling idx, enum citizen_category *categories)
int city_buy_production(struct city *pcity)
bool city_queue_insert(struct city *pcity, int position, struct universal *item)
bool city_queue_insert_worklist(struct city *pcity, int position, const struct worklist *worklist)
int city_toggle_worker(struct city *pcity, int city_x, int city_y)
void get_city_dialog_airlift_text(const struct city *pcity, char *buf, size_t bufsz)
bool city_set_queue(struct city *pcity, const struct worklist *pqueue)
int city_change_production(struct city *pcity, struct universal *target)
void city_rotate_specialist(struct city *pcity, int citizen_index)
int get_citydlg_canvas_width(void)
bool canvas_to_city_pos(int *city_x, int *city_y, int city_radius_sq, int canvas_x, int canvas_y)
int city_try_fill_superspecialists(struct city *pcity, int cat_len, enum citizen_category *categories)
void get_city_dialog_airlift_value(const struct city *pcity, char *buf, size_t bufsz)
void city_get_queue(struct city *pcity, struct worklist *pqueue)
void city_dialog_redraw_map(struct city *pcity, struct canvas *pcanvas)
int city_sell_improvement(struct city *pcity, Impr_type_id sell_id)
void get_city_dialog_pollution_text(const struct city *pcity, char *buf, size_t bufsz)
void get_city_dialog_culture_text(const struct city *pcity, char *buf, size_t bufsz)
bool city_can_buy(const struct city *pcity)
int get_citydlg_canvas_height(void)
void get_city_dialog_illness_text(const struct city *pcity, char *buf, size_t bufsz)
void set_city(struct city *pcity)
Definition citydlg.cpp:1187
struct city * pcity
Definition citydlg.h:418
city_label(int type, QWidget *parent=nullptr)
Definition citydlg.cpp:1155
void mousePressEvent(QMouseEvent *event)
Definition citydlg.cpp:1163
int wdth
Definition citydlg.h:279
int cutted_height
Definition citydlg.h:282
QSize sizeHint() const
Definition citydlg.cpp:1286
void paintEvent(QPaintEvent *event)
Definition citydlg.cpp:1226
void mousePressEvent(QMouseEvent *event)
Definition citydlg.cpp:1302
int height
Definition citydlg.h:280
void set_pixmap(struct city *pcity, float z)
Definition citydlg.cpp:1250
void context_menu(QPoint point)
Definition citydlg.cpp:1324
canvas * miniview
Definition citydlg.h:266
struct city * mcity
Definition citydlg.h:276
QSize minimumSizeHint() const
Definition citydlg.cpp:1294
float zoom
Definition citydlg.h:278
QPixmap zoomed_pixmap
Definition citydlg.h:267
city_map(QWidget *parent)
Definition citydlg.cpp:1195
int cutted_width
Definition citydlg.h:281
int radius
Definition citydlg.h:277
int delta_y
Definition citydlg.h:284
int delta_x
Definition citydlg.h:283
city_production_delegate(QPoint sh, QObject *parent, struct city *city)
Definition citydlg.cpp:4172
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition citydlg.cpp:4185
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition citydlg.cpp:4341
struct city * pcity
Definition citydlg.h:310
void drawFocus(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect) const
Definition citydlg.cpp:4324
int rowCount(const QModelIndex &index=QModelIndex()) const
Definition citydlg.h:348
QList< production_item * > city_target_list
Definition citydlg.h:364
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole)
Definition citydlg.cpp:4511
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition citydlg.h:352
city_production_model(struct city *pcity, bool f, bool su, bool sw, bool sb, QObject *parent=nullptr)
Definition citydlg.cpp:4391
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition citydlg.cpp:4416
struct city * mcity
Definition citydlg.h:365
static fc_font * instance()
Definition fonts.cpp:41
QFont * get_font(QString name)
Definition fonts.cpp:63
static fc_icons * instance()
bool eventFilter(QObject *obj, QEvent *event)
Definition citydlg.cpp:3951
void update_buildings()
Definition citydlg.cpp:551
QHBoxLayout * layout
Definition citydlg.h:252
void add_item(impr_item *item)
Definition citydlg.cpp:499
void wheelEvent(QWheelEvent *event)
Definition citydlg.cpp:532
impr_info(QWidget *parent)
Definition citydlg.cpp:468
void clear_layout()
Definition citydlg.cpp:507
void init_layout()
Definition citydlg.cpp:478
QList< impr_item * > impr_list
Definition citydlg.h:253
void mouseDoubleClickEvent(QMouseEvent *event)
Definition citydlg.cpp:603
impr_item(QWidget *parent, const struct impr_type *building, struct city *pcity)
Definition citydlg.cpp:367
void init_pix()
Definition citydlg.cpp:406
void enterEvent(QEnterEvent *event)
Definition citydlg.cpp:415
struct canvas * impr_pixmap
Definition citydlg.h:229
struct city * dlgcity
Definition citydlg.h:230
const struct impr_type * impr
Definition citydlg.h:228
void leaveEvent(QEvent *event)
Definition citydlg.cpp:442
void wheelEvent(QWheelEvent *event)
Definition citydlg.cpp:583
struct universal * target
Definition citydlg.h:334
QVariant data() const
Definition citydlg.cpp:4375
production_item(struct universal *ptarget, QObject *parent)
Definition citydlg.cpp:4354
bool eventFilter(QObject *obj, QEvent *ev)
Definition citydlg.cpp:4621
void prod_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:4646
void mousePressEvent(QMouseEvent *event)
Definition citydlg.cpp:4608
city_production_model * list_model
Definition citydlg.h:379
struct city * pw_city
Definition citydlg.h:396
fc_tooltip * fc_tt
Definition citydlg.h:401
city_production_delegate * c_p_d
Definition citydlg.h:380
production_widget(QWidget *parent, struct city *pcity, bool future, int when, int curr, bool show_units, bool buy=false, bool show_wonders=true, bool show_buildings=true)
Definition citydlg.cpp:4534
progress_bar(QWidget *parent)
Definition citydlg.cpp:82
void paintEvent(QPaintEvent *event)
Definition citydlg.cpp:188
int m_animate_step
Definition citydlg.h:133
void resizeEvent(QResizeEvent *event)
Definition citydlg.cpp:106
QRegion reg
Definition citydlg.h:135
void set_pixmap(struct universal *target)
Definition citydlg.cpp:114
void create_region()
Definition citydlg.cpp:326
QElapsedTimer m_timer
Definition citydlg.h:114
void timerEvent(QTimerEvent *event)
Definition citydlg.cpp:176
QPixmap * pix
Definition citydlg.h:134
QFont * sfont
Definition citydlg.h:136
void clicked()
void wheelEvent(QWheelEvent *event)
Definition citydlg.cpp:1069
void init_layout()
Definition citydlg.cpp:1057
unit_info(bool supp)
Definition citydlg.cpp:1030
void add_item(unit_item *item)
Definition citydlg.cpp:1049
QHBoxLayout * layout
Definition citydlg.h:205
void update_units()
Definition citydlg.cpp:1088
void clear_layout()
Definition citydlg.cpp:1129
QList< unit_item * > unit_list
Definition citydlg.h:206
bool supports
Definition citydlg.h:209
QAction * activate
Definition citydlg.h:147
QAction * disband_action
Definition citydlg.h:145
void enterEvent(QEnterEvent *event)
Definition citydlg.cpp:961
void contextMenuEvent(QContextMenuEvent *ev)
Definition citydlg.cpp:734
QAction * sentry
Definition citydlg.h:149
struct unit * qunit
Definition citydlg.h:164
QAction * activate_and_close
Definition citydlg.h:148
void mousePressEvent(QMouseEvent *event)
Definition citydlg.cpp:1007
int happy_cost
Definition citydlg.h:168
void change_homecity()
Definition citydlg.cpp:920
QAction * unload
Definition citydlg.h:152
QAction * upgrade
Definition citydlg.h:153
bool supported
Definition citydlg.h:169
void fortify_unit()
Definition citydlg.cpp:951
void sentry_unit()
Definition citydlg.cpp:1020
QAction * unload_trans
Definition citydlg.h:154
void load_unit()
Definition citydlg.cpp:884
void wheelEvent(QWheelEvent *event)
Definition citydlg.cpp:987
QAction * load
Definition citydlg.h:151
void activate_unit()
Definition citydlg.cpp:941
QAction * change_home
Definition citydlg.h:146
QAction * fortify
Definition citydlg.h:150
QImage unit_img
Definition citydlg.h:165
void create_actions()
Definition citydlg.cpp:788
void unload_all()
Definition citydlg.cpp:900
void disband()
Definition citydlg.cpp:866
void upgrade_unit()
Definition citydlg.cpp:908
void init_pix()
Definition citydlg.cpp:718
void leaveEvent(QEvent *event)
Definition citydlg.cpp:979
unit_item(QWidget *parent, struct unit *punit, bool supp=false, int happy_cost=0)
Definition citydlg.cpp:647
void unload_unit()
Definition citydlg.cpp:892
void activate_and_close_dialog()
Definition citydlg.cpp:930
bool client_is_observer(void)
struct civclient client
bool can_client_issue_orders(void)
#define client_player()
int collect_eventually_buildable_targets(struct universal *targets, struct city *pcity, bool advanced_tech)
Definition climisc.c:819
void name_and_sort_items(struct universal *targets, int num_targets, struct item *items, bool show_cost, struct city *pcity)
Definition climisc.c:650
cid cid_encode(struct universal target)
Definition climisc.c:483
int collect_already_built_targets(struct universal *targets, struct city *pcity)
Definition climisc.c:913
struct universal cid_decode(cid id)
Definition climisc.c:526
#define MAX_NUM_PRODUCTION_TARGETS
Definition climisc.h:89
#define cid_production
Definition climisc.h:71
int cid
Definition climisc.h:31
static struct fc_sockaddr_list * list
Definition clinet.c:102
void cm_copy_parameter(struct cm_parameter *dest, const struct cm_parameter *const src)
Definition cm.c:2176
bool cma_is_city_under_agent(const struct city *pcity, struct cm_parameter *parameter)
Definition cma_core.c:552
void cma_put_city_under_agent(struct city *pcity, const struct cm_parameter *const parameter)
Definition cma_core.c:524
void cma_release_city(struct city *pcity)
Definition cma_core.c:542
char * cmafec_preset_get_descr(int idx)
Definition cma_fec.c:169
const char * cmafec_get_short_descr_of_city(const struct city *pcity)
Definition cma_fec.c:221
const struct cm_parameter * cmafec_preset_get_parameter(int idx)
Definition cma_fec.c:182
void cmafec_preset_add(const char *descr_name, struct cm_parameter *pparam)
Definition cma_fec.c:136
int cmafec_preset_get_index_of_parameter(const struct cm_parameter *const parameter)
Definition cma_fec.c:196
void cmafec_preset_remove(int idx)
Definition cma_fec.c:153
int cmafec_preset_num(void)
Definition cma_fec.c:213
void cmafec_get_fe_parameter(struct city *pcity, struct cm_parameter *dest)
Definition cma_fec.c:115
char * incite_cost
Definition comments.c:77
void request_unit_fortify(struct unit *punit)
Definition control.c:2353
struct unit * request_unit_unload_all(struct unit *punit)
Definition control.c:1511
void unit_focus_set(struct unit *punit)
Definition control.c:506
void request_unit_change_homecity(struct unit *punit)
Definition control.c:2094
void request_unit_unload(struct unit *pcargo)
Definition control.c:2194
void request_unit_sentry(struct unit *punit)
Definition control.c:2342
#define can_unit_do_activity_client(_punit_, _act_)
Definition control.h:41
int counter_index(const struct counter *pcount)
Definition counters.c:174
#define city_counters_iterate_end
Definition counters.h:64
#define city_counters_iterate(pcount)
Definition counters.h:57
bool qtg_request_transport(struct unit *pcargo, struct tile *ptile)
Definition dialogs.cpp:4948
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:74
int int id
Definition editgui_g.h:28
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:842
enum event_type event
Definition events.c:81
struct extra_type * next_extra_for_tile(const struct tile *ptile, enum extra_cause cause, const struct player *pplayer, const struct unit *punit)
Definition extras.c:779
struct extra_type * prev_extra_in_tile(const struct tile *ptile, enum extra_rmcause rmcause, const struct player *pplayer, const struct unit *punit)
Definition extras.c:804
enum extra_cause activity_to_extra_cause(enum unit_activity act)
Definition extras.c:1090
enum extra_rmcause activity_to_extra_rmcause(enum unit_activity act)
Definition extras.c:1111
#define extra_index(_e_)
Definition extras.h:183
unsigned char citizens
Definition fc_types.h:249
#define EC_NONE
Definition fc_types.h:808
@ TR_SUCCESS
Definition fc_types.h:941
#define ERM_NONE
Definition fc_types.h:831
@ O_SHIELD
Definition fc_types.h:103
@ O_FOOD
Definition fc_types.h:103
@ O_TRADE
Definition fc_types.h:103
@ O_SCIENCE
Definition fc_types.h:103
@ O_LUXURY
Definition fc_types.h:103
@ O_GOLD
Definition fc_types.h:103
@ O_LAST
Definition fc_types.h:103
const char * skip_intl_qualifier_prefix(const char *str)
Definition fcintl.c:48
#define Q_(String)
Definition fcintl.h:70
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
const char * population_to_text(int thousand_citizen)
Definition game.c:742
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
struct city * game_city_by_number(int id)
Definition game.c:107
struct global_worklist * global_worklist_by_id(int id)
bool global_worklist_set(struct global_worklist *pgwl, const struct worklist *pwl)
const char * global_worklist_name(const struct global_worklist *pgwl)
int global_worklist_id(const struct global_worklist *pgwl)
const struct worklist * global_worklist_get(const struct global_worklist *pgwl)
struct global_worklist * global_worklist_new(const char *name)
#define global_worklists_iterate(pgwl)
#define global_worklists_iterate_end
void canvas_free(struct canvas *store)
Definition canvas.c:44
@ INFO_LUXURY
Definition citydlg.c:120
@ INFO_STEAL
Definition citydlg.c:122
@ INFO_CORRUPTION
Definition citydlg.c:121
@ NUM_INFO_FIELDS
Definition citydlg.c:123
@ INFO_ILLNESS
Definition citydlg.c:122
@ INFO_WASTE
Definition citydlg.c:121
@ INFO_GROWTH
Definition citydlg.c:120
@ INFO_SHIELD
Definition citydlg.c:119
@ INFO_CULTURE
Definition citydlg.c:121
@ INFO_GOLD
Definition citydlg.c:119
@ INFO_SCIENCE
Definition citydlg.c:120
@ INFO_POLLUTION
Definition citydlg.c:121
@ INFO_TRADE
Definition citydlg.c:119
@ INFO_AIRLIFT
Definition citydlg.c:122
@ INFO_GRANARY
Definition citydlg.c:120
@ INFO_FOOD
Definition citydlg.c:119
void popup_upgrade_dialog(struct unit_list *punits)
Definition dialogs.c:1435
void popup_disband_dialog(struct unit_list *punits)
Definition dialogs.c:1473
static struct tile * pos
Definition finddlg.c:53
const char * tooltip
Definition repodlgs.c:1315
void free_sprite(struct sprite *s)
Definition sprite.c:278
static GMenu * change_menu
Definition cityrep.c:126
static GMenu * options_menu
Definition menu.c:84
QString get_tooltip_improvement(const impr_type *building, struct city *pcity=nullptr, bool ext=false)
Definition citydlg.cpp:4005
QString get_tooltip(QVariant qvar)
Definition citydlg.cpp:4134
void set_theme_style()
Definition themes.cpp:107
#define CAPTURE_DEFAULT_THIS
Definition gui_main.h:23
#define show(id)
Definition widget.h:235
#define hide(id)
Definition widget.h:238
QApplication * current_app()
Definition gui_main.cpp:227
char * helptext_unit(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, const struct unit_type *utype, bool class_help)
Definition helpdata.c:1992
char * helptext_unit_upkeep_str(const struct unit_type *utype)
Definition helpdata.c:5079
char * helptext_building(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, const struct impr_type *pimprove)
Definition helpdata.c:1439
int impr_sell_gold(const struct impr_type *pimprove)
enum test_result test_player_sell_building_now(struct player *pplayer, struct city *pcity, const struct impr_type *pimprove)
bool is_special_improvement(const struct impr_type *pimprove)
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
bool is_improvement(const struct impr_type *pimprove)
Impr_type_id improvement_number(const struct impr_type *pimprove)
int impr_build_shield_cost(const struct city *pcity, const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool is_convert_improvement(const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
int impr_estimate_build_shield_cost(const struct player *pplayer, const struct tile *ptile, const struct impr_type *pimprove)
const char * name
Definition inputfile.c:127
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_action(condition, action)
Definition log.h:188
int send_packet_worker_task(struct connection *pc, const struct packet_worker_task *packet)
int dsend_packet_city_options_req(struct connection *pc, int city_id, bv_city_options options, enum city_wl_cancel_behavior wl_cb)
void put_unit(const struct unit *punit, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
void put_unit_city_overlays(struct unit *punit, struct canvas *pcanvas, int canvas_x, int canvas_y, int *upkeep_cost, int happy_cost)
void center_tile_mapcanvas(const struct tile *ptile)
const char * move_points_text(int mp, bool reduce)
Definition movement.c:1066
static mpgui * gui
Definition mpgui_qt.cpp:53
static const char * name_translation_get(const struct name_translation *ptrans)
const char *const default_font
Definition fonts.h:27
const char *const notify_label
Definition fonts.h:28
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
const char * text_happiness_cities(const struct city *pcity)
Definition text.c:1953
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
Definition player.c:1217
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:432
void qtg_free_sprite(struct sprite *s)
Definition sprite.cpp:172
struct sprite * qtg_create_sprite(int width, int height, struct color *pcolor)
Definition sprite.cpp:181
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
#define ARRAY_SIZE(x)
Definition shared.h:85
#define FC_INFINITY
Definition shared.h:36
size_t size
Definition specvec.h:72
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
#define strvec_iterate(psv, str)
#define strvec_iterate_end
QPixmap map_pixmap
Definition canvas.h:25
void setup_ui(struct city *qcity)
Definition citydlg.cpp:3271
int current_building
Definition citydlg.h:504
void worklist_up()
Definition citydlg.cpp:3702
city_label * citizens_label
Definition citydlg.h:447
QPushButton * lcity_name
Definition citydlg.h:490
void show_happiness()
Definition citydlg.cpp:2120
void closeEvent(QCloseEvent *event)
Definition citydlg.cpp:2317
void show_counters()
Definition citydlg.cpp:2155
void update_nation_table()
Definition citydlg.cpp:3065
void hideEvent(QHideEvent *event)
Definition citydlg.cpp:2289
void cma_toggle_changed_depr(int state)
Definition citydlg.cpp:2700
QPushButton * work_next_but
Definition citydlg.h:478
void next_city()
Definition citydlg.cpp:3381
progress_bar * production_combo_p
Definition citydlg.h:462
QTableWidget * nationality_table
Definition citydlg.h:464
QRadioButton * r3
Definition citydlg.h:472
QTableWidget * cma_table
Definition citydlg.h:465
void showEvent(QShowEvent *event)
Definition citydlg.cpp:2300
QPushButton * happiness_button
Definition citydlg.h:482
void cma_double_clicked(int row, int column)
Definition citydlg.cpp:2493
void display_worklist_menu(const QPoint &p)
Definition citydlg.cpp:2777
void update_disabled()
Definition citydlg.cpp:2190
QLabel * supp_units
Definition citydlg.h:459
QPushButton * next_city_but
Definition citydlg.h:476
QLabel * qlt[NUM_INFO_FIELDS]
Definition citydlg.h:455
QPushButton * work_prev_but
Definition citydlg.h:479
QHBoxLayout * single_page_layout
Definition citydlg.h:436
void update_buy_button()
Definition citydlg.cpp:2869
int selected_row_p
Definition citydlg.h:491
QHBoxLayout * leftbot_layout
Definition citydlg.h:442
void update_building()
Definition citydlg.cpp:3453
QPushButton * zoom_in_button
Definition citydlg.h:484
void save_worklist()
Definition citydlg.cpp:3768
void worklist_del()
Definition citydlg.cpp:3727
QGridLayout * info_grid_layout
Definition citydlg.h:449
void clear_worklist()
Definition citydlg.cpp:3687
QPushButton * counterss_button
Definition citydlg.h:483
impr_info * city_buildings
Definition citydlg.h:489
QLabel * curr_impr
Definition citydlg.h:461
city_label * lab_table[6]
Definition citydlg.h:448
int scroll_height
Definition citydlg.h:500
QLabel * curr_units
Definition citydlg.h:460
unit_info * current_units
Definition citydlg.h:487
void zoom_out()
Definition citydlg.cpp:2408
void zoom_in()
Definition citydlg.cpp:2395
struct unit_node_vector supported_units
Definition citydlg.c:163
QPushButton * zoom_out_button
Definition citydlg.h:485
struct city * pcity
Definition citydlg.c:138
struct city_dialog::@148 happiness
void update_info_label()
Definition citydlg.cpp:3142
QPushButton * work_add_but
Definition citydlg.h:480
QSplitter * central_left_splitter
Definition citydlg.h:440
void disband_state_changed(bool allow_disband)
Definition citydlg.cpp:2736
void update_citizens()
Definition citydlg.cpp:2895
QRadioButton * r1
Definition citydlg.h:472
void cma_slider(int val)
Definition citydlg.cpp:2711
QCheckBox * cma_celeb_checkbox
Definition citydlg.h:466
QCheckBox * show_units
Definition citydlg.h:469
enum city_dialog::city_dialog_tab current_tab
void worklist_down()
Definition citydlg.cpp:3744
void update_title()
Definition citydlg.cpp:3799
QLabel * cma_info_text
Definition citydlg.h:456
void dbl_click_p(QTableWidgetItem *item)
Definition citydlg.cpp:3287
QPushButton * cma_enable_but
Definition citydlg.h:475
QLabel * cma_result
Definition citydlg.h:457
void cma_remove()
Definition citydlg.cpp:2661
QSlider * slider_tab[2 *O_LAST+2]
Definition citydlg.h:492
QPushButton * button
Definition citydlg.h:473
bool eventFilter(QObject *obj, QEvent *event)
Definition citydlg.cpp:2328
QSplitter * prod_unit_splitter
Definition citydlg.h:439
QVBoxLayout * left_layout
Definition citydlg.h:445
void prev_city()
Definition citydlg.cpp:3417
void city_rename()
Definition citydlg.cpp:2365
void refresh()
Definition citydlg.cpp:2991
void update_cma_tab()
Definition citydlg.cpp:2594
QPushButton * work_rem_but
Definition citydlg.h:481
float zoom
Definition citydlg.h:501
QSplitter * central_splitter
Definition citydlg.h:441
QWidget * prod_happ_widget
Definition citydlg.h:443
void show_targets()
Definition citydlg.cpp:3656
city_dialog(QWidget *parent=nullptr)
Definition citydlg.cpp:1474
void cma_toggle_changed(Qt::CheckState state)
Definition citydlg.cpp:2688
QVBoxLayout * counterss_layout
Definition citydlg.h:438
QFrame * counterss_frame
Definition citydlg.h:453
QWidget * top_widget
Definition citydlg.h:444
void update_tabs()
Definition citydlg.cpp:2099
QPushButton * prev_city_but
Definition citydlg.h:477
void cma_enable()
Definition citydlg.cpp:2457
QLabel * cma_result_pix
Definition citydlg.h:458
struct city * dlgcity
Definition citydlg.h:499
void update_counters_table()
Definition citydlg.cpp:3023
void update_sliders()
Definition citydlg.cpp:2542
void update_improvements()
Definition citydlg.cpp:3521
GtkWidget * worklist
Definition citydlg.c:176
QHBoxLayout * happiness_layout
Definition citydlg.h:437
QCheckBox * future_targets
Definition citydlg.h:468
void change_production(bool next)
Definition citydlg.cpp:2054
void cma_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:2512
QCheckBox * cma_max_growth
Definition citydlg.h:467
void item_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:3363
void show_targets_worklist()
Definition citydlg.cpp:3672
QCheckBox * show_wonders
Definition citydlg.h:471
void cma_context_menu(const QPoint &p)
Definition citydlg.cpp:2757
void cma_changed()
Definition citydlg.cpp:2472
QPushButton * buy_button
Definition citydlg.h:474
QRadioButton * r4
Definition citydlg.h:472
struct city_dialog::@149 counters
void update_units()
Definition citydlg.cpp:3304
QRadioButton * r2
Definition citydlg.h:472
QTableWidget * p_table_p
Definition citydlg.h:463
void save_cma()
Definition citydlg.cpp:2421
QPixmap * citizen_pixmap
Definition citydlg.h:486
void production_changed(int index)
Definition citydlg.cpp:3638
void update_prod_buttons()
Definition citydlg.cpp:2227
QWidget * happiness_widget
Definition citydlg.h:452
QGroupBox * happiness_group
Definition citydlg.h:451
QCheckBox * show_buildings
Definition citydlg.h:470
Definition city.h:318
struct worker_task_list * task_reqs
Definition city.h:410
int surplus[O_LAST]
Definition city.h:353
enum city_wl_cancel_behavior wlcb
Definition city.h:402
int food_stock
Definition city.h:365
int * counter_values
Definition city.h:406
int pollution
Definition city.h:367
int id
Definition city.h:324
int waste[O_LAST]
Definition city.h:354
struct unit_list * info_units_present
Definition city.h:474
struct unit_list * info_units_supported
Definition city.h:473
struct universal production
Definition city.h:394
int steal
Definition city.h:412
citizens size
Definition city.h:330
int culture
Definition city.h:465
int buy_cost
Definition city.h:466
struct city::@18::@21 client
struct tile * tile
Definition city.h:320
int shield_stock
Definition city.h:366
int prod[O_LAST]
Definition city.h:356
struct unit_list * units_supported
Definition city.h:404
struct packet_game_info info
Definition game.h:89
struct connection conn
Definition client_main.h:96
bool allow_disorder
Definition cm.h:44
int factor[O_LAST]
Definition cm.h:47
bool max_growth
Definition cm.h:42
bool allow_specialists
Definition cm.h:45
bool require_happy
Definition cm.h:43
int minimal_surplus[O_LAST]
Definition cm.h:41
int happy_factor
Definition cm.h:48
Definition colors.h:21
Definition mapimg.c:367
enum impr_genus_id genus
Definition improvement.h:63
struct requirement_vector obsolete_by
Definition improvement.h:59
Definition climisc.h:82
struct universal item
Definition climisc.h:83
enum unit_activity activity
struct city_list * cities
Definition player.h:281
struct player_economic economic
Definition player.h:284
QPixmap * pm
Definition sprite.h:25
Definition tile.h:50
int index
Definition tile.h:51
struct unit_list * units
Definition tile.h:58
int defense_strength
Definition unittype.h:523
int firepower
Definition unittype.h:532
const struct unit_type * obsoleted_by
Definition unittype.h:536
int vision_radius_sq
Definition unittype.h:529
int move_rate
Definition unittype.h:524
int attack_strength
Definition unittype.h:522
Definition unit.h:140
int upkeep[O_LAST]
Definition unit.h:150
int id
Definition unit.h:147
struct tile * tile
Definition unit.h:142
int homecity
Definition unit.h:148
enum universals_n kind
Definition fc_types.h:595
universals_u value
Definition fc_types.h:594
struct universal entries[MAX_LEN_WORKLIST]
Definition worklist.h:30
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#define TRUE
Definition support.h:46
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
bool is_future_tech(Tech_type_id tech)
Definition tech.c:281
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:300
struct advance * valid_advance_by_number(const Tech_type_id id)
Definition tech.c:176
#define A_NONE
Definition tech.h:43
const char * text_happiness_nationality(const struct city *pcity)
Definition text.c:1881
const char * text_happiness_wonders(const struct city *pcity)
Definition text.c:1923
const char * text_happiness_units(const struct city *pcity)
Definition text.c:2087
const char * text_happiness_luxuries(const struct city *pcity)
Definition text.c:2126
const char * text_happiness_buildings(const struct city *pcity)
Definition text.c:1853
const char * unit_description(struct unit *punit)
Definition text.c:528
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_terrain(_tile)
Definition tile.h:115
int tileset_hex_width(const struct tileset *t)
Definition tilespec.c:747
struct sprite * get_building_sprite(const struct tileset *t, const struct impr_type *pimprove)
Definition tilespec.c:7023
int tileset_unit_width(const struct tileset *t)
Definition tilespec.c:823
int tileset_unit_height(const struct tileset *t)
Definition tilespec.c:831
int tileset_small_sprite_width(const struct tileset *t)
Definition tilespec.c:927
struct tileset * get_tileset(void)
Definition tilespec.c:718
struct tileset * unscaled_tileset
Definition tilespec.c:592
int tileset_unit_layout_offset_y(const struct tileset *t)
Definition tilespec.c:908
bool tileset_is_isometric(const struct tileset *t)
Definition tilespec.c:738
int tileset_small_sprite_height(const struct tileset *t)
Definition tilespec.c:963
struct sprite * get_icon_sprite(const struct tileset *t, enum icon_type icon)
Definition tilespec.c:7227
int tileset_unit_with_upkeep_height(const struct tileset *t)
Definition tilespec.c:885
int tileset_hex_height(const struct tileset *t)
Definition tilespec.c:756
struct sprite * get_citizen_sprite(const struct tileset *t, enum citizen_category type, int citizen_index, const struct city *pcity)
Definition tilespec.c:6962
struct sprite * get_unittype_sprite(const struct tileset *t, const struct unit_type *punittype, enum unit_activity activity, enum direction8 facing)
Definition tilespec.c:7045
struct sprite * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:6996
struct sprite * get_tech_sprite(const struct tileset *t, Tech_type_id tech)
Definition tilespec.c:7014
@ ICON_CITYDLG
Definition tilespec.h:316
const struct unit_type * utype
Definition fc_types.h:536
const struct impr_type * building
Definition fc_types.h:529
bool can_unit_change_homecity(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:524
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:402
#define unit_tile(_pu)
Definition unit.h:407
#define unit_owner(_pu)
Definition unit.h:406
bool units_are_occupied(const struct unit_list *punits)
Definition unitlist.c:275
bool units_can_unload(const struct civ_map *nmap, const struct unit_list *punits)
Definition unitlist.c:303
bool units_can_upgrade(const struct civ_map *nmap, const struct unit_list *punits)
Definition unitlist.c:337
bool units_can_load(const struct unit_list *punits)
Definition unitlist.c:289
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
int utype_build_shield_cost_base(const struct unit_type *punittype)
Definition unittype.c:1493
bool utype_is_consumed_by_action_result(enum action_result result, const struct unit_type *utype)
Definition unittype.c:1254
struct advance * utype_primary_tech_req(const struct unit_type *ptype)
Definition unittype.c:2742
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:412
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1463
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1586
const char * utype_values_translation(const struct unit_type *punittype)
Definition unittype.c:1643
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:773
#define utype_class(_t_)
Definition unittype.h:756
#define utype_fuel(ptype)
Definition unittype.h:847
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:624
void worklist_init(struct worklist *pwl)
Definition worklist.c:38
bool worklist_peek_ith(const struct worklist *pwl, struct universal *prod, int idx)
Definition worklist.c:86
bool worklist_insert(struct worklist *pwl, const struct universal *prod, int idx)
Definition worklist.c:167
void worklist_remove(struct worklist *pwl, int idx)
Definition worklist.c:122
int worklist_length(const struct worklist *pwl)
Definition worklist.c:57