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}
2048
2049/************************************************************************/
2053{
2054
2055 cid cprod;
2056 int i, pos;
2057 int item, targets_used;
2059 QString str;
2060 struct item items[MAX_NUM_PRODUCTION_TARGETS];
2061 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
2062 struct universal univ;
2063
2064 pos = 0;
2067 name_and_sort_items(targets, targets_used, items, false, dlgcity);
2068
2069 for (item = 0; item < targets_used; item++) {
2070 if (can_city_build_now(&(wld.map), dlgcity, &items[item].item)) {
2071 prod_list << cid_encode(items[item].item);
2072 }
2073 }
2074
2075 for (i = 0; i < prod_list.size(); i++) {
2076 if (prod_list.at(i) == cprod) {
2077 if (next) {
2078 pos = i + 1;
2079 } else {
2080 pos = i - 1;
2081 }
2082 }
2083 }
2084 if (pos == prod_list.size()) {
2085 pos = 0;
2086 }
2087 if (pos == - 1) {
2088 pos = prod_list.size() - 1;
2089 }
2090 univ = cid_decode(static_cast<cid>(prod_list.at(pos)));
2092}
2093
2094/************************************************************************/
2098{
2099 if (current_tab == happiness) {
2100 happiness_button->setToolTip(_("Show city production"));
2101 counterss_button->setToolTip(_("Show counters information"));
2102
2103 } else {
2104 happiness_button->setToolTip(_("Show happiness information"));
2105
2106 if (current_tab == counters) {
2107 counterss_button->setToolTip(_("Show city production"));
2108 }
2109 else {
2110 counterss_button->setToolTip(_("Show counters information"));
2111 }
2112 }
2113}
2114
2115/************************************************************************/
2119{
2121 setUpdatesEnabled(false);
2122
2123
2124 if (current_tab != happiness) {
2125 leftbot_layout->replaceWidget(active_tab,
2127 Qt::FindDirectChildrenOnly);
2128 active_tab->hide();
2129 happiness_widget->show();
2130 happiness_widget->updateGeometry();
2132 } else {
2133 /* We do not change prod_unit_splitter to current_tab,
2134 * because happiness is active tab and clicked -
2135 * switching to default */
2136 leftbot_layout->replaceWidget(happiness_widget,
2138 Qt::FindDirectChildrenOnly);
2139 prod_unit_splitter->show();
2140 prod_unit_splitter->updateGeometry();
2141 happiness_widget->hide();
2143 }
2144
2145 setUpdatesEnabled(true);
2146 update();
2147 update_tabs();
2148}
2149
2150/************************************************************************/
2154{
2156 setUpdatesEnabled(false);
2157
2158
2159 if (current_tab != counters) {
2160 leftbot_layout->replaceWidget(active_tab,
2162 Qt::FindDirectChildrenOnly);
2163 active_tab->hide();
2164 counterss_frame->show();
2165 counterss_frame->updateGeometry();
2167 } else {
2168 /* We do not change prod_unit_splitter to current_tab,
2169 * because counters is active tab and clicked -
2170 * switching to default */
2171 leftbot_layout->replaceWidget(counterss_frame,
2173 Qt::FindDirectChildrenOnly);
2174 prod_unit_splitter->show();
2175 prod_unit_splitter->updateGeometry();
2176 counterss_frame->hide();
2178 }
2179
2180 setUpdatesEnabled(true);
2181 update();
2182 update_tabs();
2183}
2184
2185/************************************************************************/
2189{
2190 struct player *pplayer = client_player();
2191
2192 if (pplayer == nullptr
2193 || city_owner(dlgcity) != pplayer) {
2194 prev_city_but->setDisabled(true);
2195 next_city_but->setDisabled(true);
2196 buy_button->setDisabled(true);
2197 cma_enable_but->setDisabled(true);
2198 production_combo_p->setDisabled(true);
2199 current_units->setDisabled(true);
2200 supported_units->setDisabled(true);
2201 view->setDisabled(true);
2202 } else {
2203 prev_city_but->setEnabled(true);
2204 next_city_but->setEnabled(true);
2205 buy_button->setEnabled(true);
2206 cma_enable_but->setEnabled(true);
2207 production_combo_p->setEnabled(true);
2208 current_units->setEnabled(true);
2209 supported_units->setEnabled(true);
2210 view->setEnabled(true);
2211 }
2212
2214 cma_enable_but->setEnabled(true);
2215 } else {
2216 cma_enable_but->setDisabled(true);
2217 }
2218
2220}
2221
2222/************************************************************************/
2226{
2227 struct player *pplayer = client_player();
2228
2229 work_next_but->setDisabled(true);
2230 work_prev_but->setDisabled(true);
2231 work_add_but->setDisabled(true);
2232 work_rem_but->setDisabled(true);
2233
2234 if (pplayer != nullptr
2235 && city_owner(dlgcity) == pplayer) {
2236 work_add_but->setEnabled(true);
2237
2238 if (selected_row_p >= 0 && selected_row_p < p_table_p->rowCount()) {
2239 work_rem_but->setEnabled(true);
2240 }
2241
2242 if (selected_row_p >= 0 && selected_row_p < p_table_p->rowCount() - 1) {
2243 work_next_but->setEnabled(true);
2244 }
2245
2246 if (selected_row_p > 0 && selected_row_p < p_table_p->rowCount()) {
2247 work_prev_but->setEnabled(true);
2248 }
2249 }
2250}
2251
2252/************************************************************************/
2256{
2257 if (citizen_pixmap) {
2258 citizen_pixmap->detach();
2259 delete citizen_pixmap;
2260 }
2261
2262 cma_table->clear();
2263 p_table_p->clear();
2264 nationality_table->clear();
2266 supported_units->clear_layout();
2267 removeEventFilter(this);
2268 ::city_dlg_created = false;
2269
2270 // Delete the one widget that currently does NOT have a parent
2271 if (current_tab == common) {
2272 delete happiness_widget;
2273 delete counterss_frame;
2274 }
2275 else if (current_tab == counters) {
2276 delete happiness_widget;
2277 delete prod_unit_splitter;
2278 }else {
2279 delete counterss_frame;
2280 delete prod_unit_splitter;
2281 }
2282}
2283
2284/************************************************************************/
2288{
2289 gui()->qt_settings.city_geometry = saveGeometry();
2290 gui()->qt_settings.city_splitter1 = prod_unit_splitter->saveState();
2291 gui()->qt_settings.city_splitter2 = central_left_splitter->saveState();
2292 gui()->qt_settings.city_splitter3 = central_splitter->saveState();
2293}
2294
2295/************************************************************************/
2299{
2300 if (!gui()->qt_settings.city_geometry.isNull()) {
2301 restoreGeometry(gui()->qt_settings.city_geometry);
2302 prod_unit_splitter->restoreState(gui()->qt_settings.city_splitter1);
2303 central_left_splitter->restoreState(gui()->qt_settings.city_splitter2);
2304 central_splitter->restoreState(gui()->qt_settings.city_splitter3);
2305 } else {
2306 QRect rect = QApplication::primaryScreen()->availableGeometry();
2307
2308 resize((rect.width() * 4) / 5, (rect.height() * 5) / 6);
2309 }
2310}
2311
2312/************************************************************************/
2316{
2317 gui()->qt_settings.city_geometry = saveGeometry();
2318 gui()->qt_settings.city_splitter1 = prod_unit_splitter->saveState();
2319 gui()->qt_settings.city_splitter2 = central_left_splitter->saveState();
2320 gui()->qt_settings.city_splitter3 = central_splitter->saveState();
2321}
2322
2323/************************************************************************/
2326bool city_dialog::eventFilter(QObject *obj, QEvent *event)
2327{
2328
2329 if (obj == this) {
2330 if (event->type() == QEvent::KeyPress) {
2331 }
2332
2333 if (event->type() == QEvent::ShortcutOverride) {
2334 QKeyEvent *key_event = static_cast<QKeyEvent *>(event);
2335 if (key_event->key() == Qt::Key_Right) {
2336 next_city();
2337 event->setAccepted(true);
2338 return true;
2339 }
2340 if (key_event->key() == Qt::Key_Left) {
2341 prev_city();
2342 event->setAccepted(true);
2343 return true;
2344 }
2345 if (key_event->key() == Qt::Key_Up) {
2346 change_production(true);
2347 event->setAccepted(true);
2348 return true;
2349 }
2350 if (key_event->key() == Qt::Key_Down) {
2351 change_production(false);
2352 event->setAccepted(true);
2353 return true;
2354 }
2355 }
2356 }
2357 return QObject::eventFilter(obj, event);
2358}
2359
2360/************************************************************************/
2364{
2366 const int city_id = dlgcity->id;
2367
2368 if (!can_client_issue_orders()) {
2369 return;
2370 }
2371
2372 ask = new hud_input_box(gui()->central_wdg);
2373 ask->set_text_title_definput(_("What should we rename the city to?"),
2374 _("Rename City"), city_name_get(dlgcity));
2375 ask->setAttribute(Qt::WA_DeleteOnClose);
2376 connect(ask, &hud_message_box::accepted, this, [=]() {
2377 struct city *pcity = game_city_by_number(city_id);
2379
2380 if (!pcity) {
2381 return;
2382 }
2383
2384 ask_bytes = ask->input_edit.text().toUtf8();
2385 ::city_rename(pcity, ask_bytes.data());
2386 });
2387 ask->show();
2388}
2389
2390/************************************************************************/
2394{
2395 zoom = zoom * 1.2;
2396 if (dlgcity) {
2397 view->set_pixmap(dlgcity, zoom);
2398 }
2400 left_layout->update();
2401}
2402
2403/************************************************************************/
2407{
2408 zoom = zoom / 1.2;
2409 if (dlgcity) {
2410 view->set_pixmap(dlgcity, zoom);
2411 }
2413 left_layout->update();
2414}
2415
2416/************************************************************************/
2420{
2421 hud_input_box *ask = new hud_input_box(gui()->central_wdg);
2422
2423 ask->set_text_title_definput(_("What should we name the preset?"),
2424 _("Name new preset"),
2425 _("new preset"));
2426 ask->setAttribute(Qt::WA_DeleteOnClose);
2427 connect(ask, &hud_message_box::accepted, this,
2429 struct cm_parameter param;
2430 QByteArray ask_bytes = ask->input_edit.text().toUtf8();
2431 QString text = ask_bytes.data();
2432 if (!text.isEmpty()) {
2433 param.allow_disorder = false;
2434 param.allow_specialists = true;
2435 param.require_happy = cma_celeb_checkbox->isChecked();
2436 param.max_growth = cma_max_growth->isChecked();
2437 param.happy_factor = slider_tab[2 * O_LAST + 1]->value();
2438
2439 for (int i = O_FOOD; i < O_LAST; i++) {
2440 param.minimal_surplus[i] = slider_tab[2 * i]->value();
2441 param.factor[i] = slider_tab[2 * i + 1]->value();
2442 }
2443
2444 ask_bytes = text.toUtf8();
2445 cmafec_preset_add(ask_bytes.data(), &param);
2447 }
2448 });
2449 ask->show();
2450}
2451
2452/************************************************************************/
2456{
2457 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2459
2460 return;
2461 }
2462
2463 cma_changed();
2465}
2466
2467/************************************************************************/
2471{
2472 struct cm_parameter param;
2473
2474 param.allow_disorder = false;
2475 param.allow_specialists = true;
2476 param.require_happy = cma_celeb_checkbox->isChecked();
2477 param.max_growth = cma_max_growth->isChecked();
2478 param.happy_factor = slider_tab[2 * O_LAST + 1]->value();
2479
2480 for (int i = O_FOOD; i < O_LAST; i++) {
2481 param.minimal_surplus[i] = slider_tab[2 * i]->value();
2482 param.factor[i] = slider_tab[2 * i + 1]->value();
2483 }
2484
2486}
2487
2488/************************************************************************/
2492{
2493 const struct cm_parameter *param;
2494
2495 if (!can_client_issue_orders()) {
2496 return;
2497 }
2499 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2501 }
2502
2505}
2506
2507/************************************************************************/
2511 const QItemSelection &ds)
2512{
2513 const struct cm_parameter *param;
2514 QModelIndex index;
2515 QModelIndexList indexes = sl.indexes();
2516
2517 if (indexes.isEmpty() || cma_table->signalsBlocked()) {
2518 return;
2519 }
2520
2521 index = indexes.at(0);
2522 int ind = index.row();
2523
2524 if (cma_table->currentRow() == -1 || cmafec_preset_num() == 0) {
2525 return;
2526 }
2527
2530
2531 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2534 }
2535}
2536
2537/************************************************************************/
2541{
2542 struct cm_parameter param;
2543 const struct cm_parameter *cparam;
2544 int output;
2545 QVariant qvar;
2546 QLabel *label;
2547
2548 if (!cma_is_city_under_agent(dlgcity, &param)) {
2549 if (cma_table->currentRow() == -1 || cmafec_preset_num() == 0) {
2550 return;
2551 }
2553 cm_copy_parameter(&param, cparam);
2554 }
2555
2556 for (output = O_FOOD; output < 2 * O_LAST; output++) {
2557 slider_tab[output]->blockSignals(true);
2558 }
2559
2560 for (output = O_FOOD; output < O_LAST; output++) {
2561 qvar = slider_tab[2 * output + 1]->property("FC");
2562 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2563 label->setText(QString::number(param.factor[output]));
2564 slider_tab[2 * output + 1]->setValue(param.factor[output]);
2565 qvar = slider_tab[2 * output]->property("FC");
2566 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2567 label->setText(QString::number(param.minimal_surplus[output]));
2568 slider_tab[2 * output]->setValue(param.minimal_surplus[output]);
2569 }
2570
2571 slider_tab[2 * O_LAST + 1]->blockSignals(true);
2572 qvar = slider_tab[2 * O_LAST + 1]->property("FC");
2573 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2574 label->setText(QString::number(param.happy_factor));
2575 slider_tab[2 * O_LAST + 1]->setValue(param.happy_factor);
2576 slider_tab[2 * O_LAST + 1]->blockSignals(false);
2577 cma_celeb_checkbox->blockSignals(true);
2578 cma_celeb_checkbox->setChecked(param.require_happy);
2579 cma_celeb_checkbox->blockSignals(false);
2580 cma_max_growth->blockSignals(true);
2581 cma_max_growth->setChecked(param.max_growth);
2582 cma_max_growth->blockSignals(false);
2583
2584 for (output = O_FOOD; output < 2 * O_LAST; output++) {
2585 slider_tab[output]->blockSignals(false);
2586 }
2587}
2588
2589/************************************************************************/
2593{
2594 QString s;
2596 struct cm_parameter param;
2597 QPixmap pix;
2598 int i;
2599
2600 cma_table->clear();
2601 cma_table->setRowCount(0);
2602
2603 for (i = 0; i < cmafec_preset_num(); i++) {
2604 item = new QTableWidgetItem;
2605 item->setText(cmafec_preset_get_descr(i));
2606 cma_table->insertRow(i);
2607 cma_table->setItem(i, 0, item);
2608 }
2609
2610 if (cmafec_preset_num() == 0) {
2611 cma_table->insertRow(0);
2612 item = new QTableWidgetItem;
2613 item->setText(_("No governor defined"));
2614 cma_table->setItem(0, 0, item);
2615 }
2616
2617 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2618 view->update();
2620 pix = style()->standardPixmap(QStyle::SP_DialogApplyButton);
2621 pix = pix.scaled(2 * pix.width(), 2 * pix.height(),
2622 Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
2623 cma_result_pix->setPixmap(pix);
2624 cma_result_pix->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
2625 // TRANS: %1 is custom string chosen by player
2626 cma_result->setText(QString(_("<h3>Governor Enabled<br>(%1)</h3>"))
2627 .arg(s.toHtmlEscaped()));
2628 cma_result->setAlignment(Qt::AlignCenter);
2629 } else {
2630 pix = style()->standardPixmap(QStyle::SP_DialogCancelButton);
2631 pix = pix.scaled(1.6 * pix.width(), 1.6 * pix.height(),
2632 Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
2633 cma_result_pix->setPixmap(pix);
2634 cma_result_pix->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
2635 cma_result->setText(QString(_("<h3>Governor Disabled</h3>")));
2636 cma_result->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
2637 }
2638
2639 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2642 cm_parameter *const >(&param));
2643 if (i >= 0 && i < cma_table->rowCount()) {
2644 cma_table->blockSignals(true);
2645 cma_table->setCurrentCell(i, 0);
2646 cma_table->blockSignals(false);
2647 }
2648
2649 cma_enable_but->setText(_("Disable"));
2650 } else {
2651 cma_enable_but->setText(_("Enable"));
2652 }
2654}
2655
2656/************************************************************************/
2660{
2661 int i;
2663
2664 i = cma_table->currentRow();
2665
2666 if (i == -1 || cmafec_preset_num() == 0) {
2667 return;
2668 }
2669
2671 ask->set_text_title(_("Remove this preset?"), cmafec_preset_get_descr(i));
2672 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
2673 ask->setDefaultButton(QMessageBox::Cancel);
2674 ask->setAttribute(Qt::WA_DeleteOnClose);
2675 connect(ask, &hud_message_box::accepted, this,
2679 });
2680 ask->show();
2681}
2682
2683/************************************************************************/
2686void city_dialog::cma_toggle_changed(Qt::CheckState state)
2687{
2688 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2689 cma_changed();
2691 }
2692}
2693
2694/************************************************************************/
2699{
2700 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2701 cma_changed();
2703 }
2704}
2705
2706/************************************************************************/
2710{
2711 QVariant qvar;
2712 QSlider *slider;
2713 QLabel *label;
2714
2716 qvar = slider->property("FC");
2717
2718 if (qvar.isNull() || !qvar.isValid()) {
2719 return;
2720 }
2721
2722 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2723 label->setText(QString::number(value));
2724
2725 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2726 cma_changed();
2728 }
2729}
2730
2731/************************************************************************/
2751
2752/************************************************************************/
2756{
2757 QMenu *cma_menu = new QMenu(this);
2759
2760 cma_menu->setAttribute(Qt::WA_DeleteOnClose);
2761 cma_del_item = cma_menu->addAction(_("Remove Governor"));
2762 connect(cma_menu, &QMenu::triggered, this,
2764 if (act == cma_del_item) {
2765 cma_remove();
2766 }
2767 });
2768
2769 cma_menu->popup(QCursor::pos());
2770}
2771
2772/************************************************************************/
2776{
2777 QAction *action;
2778 QAction *disband;
2783 QMap<QString, cid>::const_iterator map_iter;
2784 QMenu *change_menu;
2785 QMenu *insert_menu;
2786 QMenu *list_menu;
2787 QMenu *options_menu;
2788 int city_id = dlgcity->id;
2789
2790 if (!can_client_issue_orders()) {
2791 return;
2792 }
2793 list_menu = new QMenu(this);
2794 change_menu = list_menu->addMenu(_("Change worklist"));
2795 insert_menu = list_menu->addMenu(_("Insert worklist"));
2796 wl_clear = list_menu->addAction(_("Clear"));
2797 connect(wl_clear, &QAction::triggered, this, &city_dialog::clear_worklist);
2798 list.clear();
2799
2803
2804 if (list.count() == 0) {
2805 wl_empty = change_menu->addAction(_("(no worklists defined)"));
2806 insert_menu->addAction(wl_empty);
2807 }
2808
2809 map_iter = list.constBegin();
2810
2811 while (map_iter != list.constEnd()) {
2812 action = change_menu->addAction(map_iter.key());
2813 action->setData(map_iter.value());
2814
2815 action = insert_menu->addAction(map_iter.key());
2816 action->setData(map_iter.value());
2817
2818 map_iter++;
2819 }
2820
2821 wl_save = list_menu->addAction(_("Save worklist"));
2822 connect(wl_save, &QAction::triggered, this, &city_dialog::save_worklist);
2823 options_menu = list_menu->addMenu(_("Options"));
2824 disband = options_menu->addAction(_("Allow disbanding city"));
2825 disband->setCheckable(true);
2826 disband->setChecked(is_city_option_set(dlgcity, CITYO_DISBAND));
2827 connect(disband, &QAction::triggered, this,
2829
2830 connect(change_menu, &QMenu::triggered, this, [=](QAction *act) {
2831 QVariant id = act->data();
2832 struct city *pcity = game_city_by_number(city_id);
2833 const struct worklist *worklist;
2834
2835 if (!pcity) {
2836 return;
2837 }
2838
2839 fc_assert_ret(id.typeId() == QMetaType::Int);
2840
2843 });
2844
2845 connect(insert_menu, &QMenu::triggered, this,
2847 QVariant id = act->data();
2848 struct city *pcity = game_city_by_number(city_id);
2849 const struct worklist *worklist;
2850
2851 if (!pcity) {
2852 return;
2853 }
2854
2855 fc_assert_ret(id.typeId() == QMetaType::Int);
2856
2859 });
2860
2861 list_menu->popup(QCursor::pos());
2862}
2863
2864/************************************************************************/
2868{
2869 QString str;
2870 int value;
2871 struct player *pplayer = client_player();
2872
2873 buy_button->setDisabled(true);
2874
2875 if (!client_is_observer() && pplayer != nullptr) {
2876 value = dlgcity->client.buy_cost;
2877 str = QString(PL_("Buy (%1 gold)", "Buy (%1 gold)",
2878 value)).arg(QString::number(value));
2879
2880 if (pplayer->economic.gold >= value && value != 0) {
2881 buy_button->setEnabled(true);
2882 }
2883 } else {
2884 str = QString(_("Buy"));
2885 }
2886
2887 buy_button->setText(str);
2888}
2889
2890/************************************************************************/
2894{
2895 enum citizen_category categories[MAX_CITY_SIZE];
2896 int i, j, width, height;
2897 QPainter p;
2898 QPixmap *pix;
2900 int num_supers
2902 ARRAY_SIZE(categories) - num_citizens,
2903 &categories[num_citizens]);
2904
2905 int w = tileset_small_sprite_width(tileset) / gui()->map_scale;
2906 int h = tileset_small_sprite_height(tileset) / gui()->map_scale;
2907
2908 if (num_supers >= 0) {
2909 /* Just draw superspecialists in the common roster */
2911 } else {
2912 /* FIXME: show them in some compact way */
2913 num_citizens = ARRAY_SIZE(categories);
2914 }
2915 i = 1 + (num_citizens * 5 / 200);
2916 w = w / i;
2917 QRect source_rect(0, 0, w, h);
2918 QRect dest_rect(0, 0, w, h);
2919 width = w * num_citizens;
2920 height = h;
2921
2922 if (citizen_pixmap) {
2923 citizen_pixmap->detach();
2924 delete citizen_pixmap;
2925 }
2926
2928
2929 for (j = 0, i = 0; i < num_citizens; i++, j++) {
2930 dest_rect.moveTo(i * w, 0);
2931 pix = get_citizen_sprite(tileset, categories[j], j, dlgcity)->pm;
2932 p.begin(citizen_pixmap);
2933 p.drawPixmap(dest_rect, *pix, source_rect);
2934 p.end();
2935 }
2936
2938 citizens_label->setPixmap(*citizen_pixmap);
2939
2942
2943 for (int k = 0; k < FEELING_LAST - 1; k++) {
2946 static_cast<citizen_feeling>(k),
2947 categories);
2948
2949 for (j = 0, i = 0; i < num_citizens; i++, j++) {
2950 dest_rect.moveTo(i * w, 0);
2951 pix = get_citizen_sprite(tileset, categories[j], j, dlgcity)->pm;
2952 p.begin(citizen_pixmap);
2953 p.drawPixmap(dest_rect, *pix, source_rect);
2954 p.end();
2955 }
2956
2957 lab_table[k]->setPixmap(*citizen_pixmap);
2958
2959 switch (k) {
2960 case FEELING_BASE:
2961 lab_table[k]->setToolTip(text_happiness_cities(dlgcity));
2962 break;
2963
2964 case FEELING_LUXURY:
2965 lab_table[k]->setToolTip(text_happiness_luxuries(dlgcity));
2966 break;
2967
2968 case FEELING_EFFECT :
2970 break;
2971
2974 break;
2975
2976 case FEELING_MARTIAL:
2977 lab_table[k]->setToolTip(text_happiness_units(dlgcity));
2978 break;
2979
2980 default:
2981 break;
2982 }
2983 }
2984}
2985
2986/************************************************************************/
2990{
2991 setUpdatesEnabled(false);
2992 production_combo_p->blockSignals(true);
2993
2994 if (dlgcity) {
2995 view->set_pixmap(dlgcity, zoom);
2996 view->update();
2997 update_title();
3004 update_units();
3008 } else {
3010 }
3011
3012 production_combo_p->blockSignals(false);
3013 setUpdatesEnabled(true);
3015 update();
3016}
3017
3018/************************************************************************/
3022{
3023 QFont *small_font;
3024
3026
3027 qDeleteAll(counterss_frame->findChildren<QWidget*>("", Qt::FindDirectChildrenOnly));
3029 QString helptext;
3030 char buf[1024];
3031 QLabel *name, *value, *activated, *help;
3032
3033 name = new QLabel(name_translation_get(&pcount->name));
3034 fc_snprintf(buf, sizeof(buf), _("Current value is: %d"),
3036 value = new QLabel(buf);
3037 fc_snprintf(buf, sizeof(buf), _("Activated once value equal "
3038 "or higher than: %d"),
3039 pcount->checkpoint);
3040 activated = new QLabel(buf);
3041 if (pcount->helptext != nullptr) {
3042 strvec_iterate(pcount->helptext, text_) {
3043 helptext += text_;
3045 }
3046 help = new QLabel(helptext);
3047
3048 name->setFont(*small_font);
3049 value->setFont(*small_font);
3050 activated->setFont(*small_font);
3051 help->setFont(*small_font);
3052
3053 counterss_layout->addWidget(name);
3054 counterss_layout->addWidget(value);
3055 counterss_layout->addWidget(activated);
3056 counterss_layout->addWidget(help);
3058}
3059
3060/************************************************************************/
3064{
3065 QFont f = QApplication::font();
3066 QFontMetrics fm(f);
3067 QPixmap *pix = nullptr;
3069 QString str;
3072 char buf[8];
3074 int h;
3075 int i = 0;
3076 struct sprite *sprite;
3077
3078 h = fm.height() + 6;
3079 nationality_table->clear();
3080 nationality_table->setRowCount(0);
3081 info_list.clear();
3082 info_list << _("#") << _("Flag") << _("Nation");
3083 nationality_table->setHorizontalHeaderLabels(info_list);
3084
3085 citizens_iterate(dlgcity, pslot, nationality) {
3086 nationality_table->insertRow(i);
3087
3088 for (int j = 0; j < nationality_table->columnCount(); j++) {
3089 item = new QTableWidgetItem;
3090
3091 switch (j) {
3092 case 0:
3094
3095 if (nationality_i == 0) {
3096 str = "-";
3097 } else {
3098 fc_snprintf(buf, sizeof(buf), "%d", nationality_i);
3099 str = QString(buf);
3100 }
3101
3102 item->setText(str);
3103 break;
3104
3105 case 1:
3108 (player_slot_get_player(pslot)));
3109
3110 if (sprite != nullptr) {
3111 pix = sprite->pm;
3112 pix_scaled = pix->scaledToHeight(h);
3113 item->setData(Qt::DecorationRole, pix_scaled);
3114 } else {
3115 item->setText("FLAG MISSING");
3116 }
3117 break;
3118
3119 case 2:
3121 (player_slot_get_player(pslot)));
3122 break;
3123
3124 default:
3125 break;
3126 }
3127 nationality_table->setItem(i, j, item);
3128 }
3129 i++;
3131 nationality_table->horizontalHeader()->setStretchLastSection(false);
3132 nationality_table->resizeColumnsToContents();
3133 nationality_table->resizeRowsToContents();
3134 nationality_table->horizontalHeader()->setStretchLastSection(true);
3135}
3136
3137/************************************************************************/
3141{
3142 int illness = 0;
3143 char buffer[512];
3144 char buf_info[NUM_INFO_FIELDS][512];
3145 char buf_tooltip[NUM_INFO_FIELDS][512];
3146 int granaryturns;
3147 int spec, supers;
3148
3149 for (int i = 0; i < NUM_INFO_FIELDS; i++) {
3150 buf_info[i][0] = '\0';
3151 buf_tooltip[i][0] = '\0';
3152 }
3153
3154 // Fill the buffers with the necessary info
3155 spec = city_specialists(dlgcity);
3157
3159 "%3d (%4d)", dlgcity->size, spec);
3160 if (supers) {
3162 _("Population: %d, Specialists: %d + %d"),
3163 dlgcity->size, spec, supers);
3164 } else {
3166 _("Population: %d, Specialists: %d"),
3167 dlgcity->size, spec);
3168 }
3169 fc_snprintf(buf_info[INFO_FOOD], sizeof(buf_info[INFO_FOOD]), "%3d (%+4d)",
3172 "%3d (%+4d)", dlgcity->prod[O_SHIELD] + dlgcity->waste[O_SHIELD],
3174 fc_snprintf(buf_info[INFO_TRADE], sizeof(buf_info[INFO_TRADE]), "%3d (%+4d)",
3177 fc_snprintf(buf_info[INFO_GOLD], sizeof(buf_info[INFO_GOLD]), "%3d (%+4d)",
3184 "%4d/%-4d", dlgcity->food_stock,
3186
3188 sizeof(buf_tooltip[INFO_FOOD]));
3190 sizeof(buf_tooltip[INFO_SHIELD]));
3192 sizeof(buf_tooltip[INFO_TRADE]));
3194 sizeof(buf_tooltip[INFO_GOLD]));
3196 sizeof(buf_tooltip[INFO_SCIENCE]));
3198 sizeof(buf_tooltip[INFO_LUXURY]));
3200 sizeof(buf_tooltip[INFO_CULTURE]));
3202 sizeof(buf_tooltip[INFO_POLLUTION]));
3204 sizeof(buf_tooltip[INFO_ILLNESS]));
3205
3207
3208 if (granaryturns == 0) {
3209 // TRANS: city growth is blocked. Keep short.
3210 fc_snprintf(buf_info[INFO_GROWTH], sizeof(buf_info[INFO_GROWTH]), _("blocked"));
3211 } else if (granaryturns == FC_INFINITY) {
3212 // TRANS: city is not growing. Keep short.
3213 fc_snprintf(buf_info[INFO_GROWTH], sizeof(buf_info[INFO_GROWTH]), _("never"));
3214 } else {
3215 /* A negative value means we'll have famine in that many turns.
3216 But that's handled down below. */
3217 // TRANS: city growth turns. Keep short.
3219 PL_("%d turn", "%d turns", abs(granaryturns)),
3220 abs(granaryturns));
3221 }
3222
3224 "%4d", dlgcity->waste[O_TRADE]);
3231
3232 if (!game.info.illness_on) {
3234 " -.-");
3235 } else {
3236 illness = city_illness_calc(dlgcity, nullptr, nullptr, nullptr, nullptr);
3237 // Illness is in tenth of percent
3239 "%5.1f%%", (float) illness / 10.0);
3240 }
3241 if (dlgcity->steal) {
3243 PL_("%d time", "%d times", dlgcity->steal), dlgcity->steal);
3244 } else {
3246 _("Not stolen"));
3247 }
3248
3250 sizeof(buf_info[INFO_AIRLIFT]));
3252 sizeof(buf_tooltip[INFO_AIRLIFT]));
3253
3254 get_city_dialog_output_text(dlgcity, O_FOOD, buffer, sizeof(buffer));
3255
3256 for (int i = 0; i < NUM_INFO_FIELDS; i++) {
3257 qlt[i]->setText(QString(buf_info[i]));
3258
3259 if (buf_tooltip[i][0]) {
3260 qlt[i]->setToolTip("<pre>" + QString(buf_tooltip[i]).toHtmlEscaped()
3261 + "</pre>");
3262 }
3263 }
3264}
3265
3266/************************************************************************/
3270{
3273
3274 setContentsMargins(0, 0 ,0 ,0);
3276 dlgcity = qcity;
3277 production_combo_p->blockSignals(true);
3278 refresh();
3279 production_combo_p->blockSignals(false);
3280}
3281
3282/************************************************************************/
3286{
3287 struct worklist queue;
3288
3289 city_get_queue(dlgcity, &queue);
3290
3292 return;
3293 }
3294
3296 city_set_queue(dlgcity, &queue);
3297}
3298
3299/************************************************************************/
3303{
3304 unit_item *ui;
3305 struct unit_list *units;
3306 char buf[256];
3307 int n;
3308 int happy_cost;
3310 struct player *pplayer = client_player();
3311 const struct civ_map *nmap = &(wld.map);
3312
3313 supported_units->setUpdatesEnabled(false);
3314 supported_units->clear_layout();
3315
3316 if (pplayer != nullptr
3317 && city_owner(dlgcity) != pplayer) {
3319 } else {
3320 units = dlgcity->units_supported;
3321 }
3322
3323 unit_list_iterate(units, punit) {
3325 ui = new unit_item(this, punit, true, happy_cost);
3326 ui->init_pix();
3327 supported_units->add_item(ui);
3329 n = unit_list_size(units);
3330 fc_snprintf(buf, sizeof(buf), _("Supported units %d"), n);
3331 supp_units->setText(QString(buf));
3332 supported_units->update_units();
3333 supported_units->setUpdatesEnabled(true);
3334 current_units->setUpdatesEnabled(true);
3336
3337 if (pplayer != nullptr
3338 && city_owner(dlgcity) != pplayer) {
3340 } else {
3341 units = dlgcity->tile->units;
3342 }
3343
3344 unit_list_iterate(units, punit) {
3345 ui = new unit_item(this , punit, false);
3346 ui->init_pix();
3349
3350 n = unit_list_size(units);
3351 fc_snprintf(buf, sizeof(buf), _("Present units %d"), n);
3352 curr_units->setText(QString(buf));
3353
3355 current_units->setUpdatesEnabled(true);
3356}
3357
3358/************************************************************************/
3362 const QItemSelection &ds)
3363{
3364 QModelIndex index;
3365 QModelIndexList indexes = sl.indexes();
3366
3367 if (indexes.isEmpty()) {
3368 return;
3369 }
3370
3371 index = indexes.at(0);
3372 selected_row_p = index.row();
3374}
3375
3376/************************************************************************/
3380{
3381 int size, i;
3382 struct city *other_pcity = nullptr;
3383 struct player *pplayer = client_player();
3384
3385 if (pplayer == nullptr) {
3386 return;
3387 }
3388
3389 size = city_list_size(pplayer->cities);
3390
3391 if (size <= 1) {
3392 return;
3393 }
3394
3395 for (i = 0; i < size; i++) {
3396 if (dlgcity == city_list_get(pplayer->cities, i)) {
3397 break;
3398 }
3399 }
3400
3401 if (i >= size - 1) {
3402 // Current city last in the list (size - 1) or disappeared (size)
3403 other_pcity = city_list_get(pplayer->cities, 0);
3404 } else {
3405 other_pcity = city_list_get(pplayer->cities, i + 1);
3406 }
3407
3410}
3411
3412/************************************************************************/
3416{
3417 int size, i;
3418 struct city *other_pcity = nullptr;
3419 struct player *pplayer = client_player();
3420
3421 if (pplayer == nullptr) {
3422 return;
3423 }
3424
3425 size = city_list_size(pplayer->cities);
3426
3427 if (size <= 1) {
3428 return;
3429 }
3430
3431 for (i = 0; i < size; i++) {
3432 if (dlgcity == city_list_get(pplayer->cities, i)) {
3433 break;
3434 }
3435 }
3436
3437 if (i == 0 || i == size) {
3438 // Current city in the beginning of the list or disappeared
3439 other_pcity = city_list_get(pplayer->cities, size - 1);
3440 } else {
3441 other_pcity = city_list_get(pplayer->cities, i - 1);
3442 }
3443
3446}
3447
3448/************************************************************************/
3452{
3453 char buf[32];
3454 QString str;
3456
3458 production_combo_p->setRange(0, cost);
3460 if (dlgcity->shield_stock >= cost) {
3461 production_combo_p->setValue(cost);
3462 } else {
3464 }
3465 production_combo_p->setAlignment(Qt::AlignCenter);
3466 str = QString(buf);
3467 str = str.simplified();
3468
3469 production_combo_p->setFormat(QString("(%p%) %2\n%1")
3471 str));
3472
3473 production_combo_p->updateGeometry();
3474
3475}
3476
3477/************************************************************************/
3481{
3482 char buf[1024], buf2[1024];
3484 int value = dlgcity->client.buy_cost;
3486 int city_id = dlgcity->id;
3487
3488 if (!can_client_issue_orders()) {
3489 return;
3490 }
3491
3493 fc_snprintf(buf2, ARRAY_SIZE(buf2), PL_("Treasury contains %d gold.",
3494 "Treasury contains %d gold.",
3495 client_player()->economic.gold),
3496 client_player()->economic.gold);
3497 fc_snprintf(buf, ARRAY_SIZE(buf), PL_("Buy %s for %d gold?",
3498 "Buy %s for %d gold?", value),
3499 name, value);
3500 ask->set_text_title(buf, buf2);
3501 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
3502 ask->setDefaultButton(QMessageBox::Cancel);
3503 ask->setAttribute(Qt::WA_DeleteOnClose);
3504 connect(ask, &hud_message_box::accepted, this, [=]() {
3505 struct city *pcity = game_city_by_number(city_id);
3506
3507 if (!pcity) {
3508 return;
3509 }
3510
3512 });
3513 ask->show();
3514}
3515
3516/************************************************************************/
3520{
3521 QFont f = QApplication::font();
3522 QFontMetrics fm(f);
3523 QPixmap *pix = nullptr;
3527 struct sprite *sprite;
3528 int h, cost, item, targets_used, col, upkeep;
3529 struct item items[MAX_NUM_PRODUCTION_TARGETS];
3530 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
3531 struct worklist queue;
3532 impr_item *ui;
3533
3534 upkeep = 0;
3535 city_buildings->setUpdatesEnabled(false);
3537
3538 h = fm.height() + 6;
3540 name_and_sort_items(targets, targets_used, items, false, dlgcity);
3541
3542 for (item = 0; item < targets_used; item++) {
3543 struct universal target = items[item].item;
3544
3545 ui = new impr_item(this, target.value.building, dlgcity);
3546 ui->init_pix();
3548
3549 fc_assert_action(VUT_IMPROVEMENT == target.kind, continue);
3551 upkeep = upkeep + city_improvement_upkeep(dlgcity, target.value.building);
3552 if (sprite != nullptr) {
3553 pix = sprite->pm;
3554 pix_scaled = pix->scaledToHeight(h);
3555 }
3556 }
3557
3558 city_get_queue(dlgcity, &queue);
3559 p_table_p->setRowCount(worklist_length(&queue));
3560
3561 for (int i = 0; i < worklist_length(&queue); i++) {
3562 struct universal target = queue.entries[i];
3563
3564 tooltip = "";
3565
3566 if (VUT_UTYPE == target.kind) {
3568 cost = utype_build_shield_cost(dlgcity, nullptr, target.value.utype);
3569 tooltip = get_tooltip_unit(target.value.utype, true).trimmed();
3573 } else {
3577 dlgcity, true).trimmed();
3578
3580 cost = -1;
3581 } else {
3583 }
3584 }
3585
3586 for (col = 0; col < 3; col++) {
3587 qitem = new QTableWidgetItem();
3588 qitem->setToolTip(tooltip);
3589
3590 switch (col) {
3591 case 0:
3592 if (sprite) {
3593 pix = sprite->pm;
3594 pix_scaled = pix->scaledToHeight(h);
3595 qitem->setData(Qt::DecorationRole, pix_scaled);
3596 }
3597 break;
3598
3599 case 1:
3600 if (str.contains('[') && str.contains(']')) {
3601 int ii, ij;
3602
3603 ii = str.lastIndexOf('[');
3604 ij = str.lastIndexOf(']');
3605 if (ij > ii) {
3606 str = str.remove(ii, ij - ii + 1);
3607 }
3608 }
3609 qitem->setText(str);
3610 break;
3611
3612 case 2:
3613 qitem->setTextAlignment(Qt::AlignRight);
3614 qitem->setText(QString::number(cost));
3615 break;
3616 }
3617 p_table_p->setItem(i, col, qitem);
3618 }
3619 }
3620
3621 p_table_p->horizontalHeader()->setStretchLastSection(false);
3622 p_table_p->resizeColumnsToContents();
3623 p_table_p->resizeRowsToContents();
3624 p_table_p->horizontalHeader()->setStretchLastSection(true);
3625
3627 city_buildings->setUpdatesEnabled(true);
3628 city_buildings->setUpdatesEnabled(true);
3629
3630 curr_impr->setText(QString(_("Improvements - upkeep %1")).arg(upkeep));
3631}
3632
3633/************************************************************************/
3637{
3638 cid id;
3639 QVariant qvar;
3640
3642 struct universal univ;
3643
3644 id = qvar.toInt();
3645 univ = cid_production(id);
3647 }
3648}
3649
3650/************************************************************************/
3655{
3657 int when = 1;
3658
3659 pw = new production_widget(this, dlgcity, future_targets->isChecked(),
3660 when, selected_row_p, show_units->isChecked(),
3661 false, show_wonders->isChecked(),
3662 show_buildings->isChecked());
3663 pw->show();
3664}
3665
3666/************************************************************************/
3671{
3673 int when = 4;
3674
3675 pw = new production_widget(this, dlgcity, future_targets->isChecked(),
3676 when, selected_row_p, show_units->isChecked(),
3677 false, show_wonders->isChecked(),
3678 show_buildings->isChecked());
3679 pw->show();
3680}
3681
3682/************************************************************************/
3686{
3687 struct worklist empty;
3688
3689 if (!can_client_issue_orders()) {
3690 return;
3691 }
3692
3695}
3696
3697/************************************************************************/
3701{
3702 QModelIndex index;
3703 struct worklist queue;
3704 struct universal *target;
3705
3707 return;
3708 }
3709
3710 target = new universal;
3711 city_get_queue(dlgcity, &queue);
3712 worklist_peek_ith(&queue, target, selected_row_p);
3714 worklist_insert(&queue, target, selected_row_p - 1);
3715 city_set_queue(dlgcity, &queue);
3716 index = p_table_p->model()->index(selected_row_p - 1, 0);
3717 p_table_p->setCurrentIndex(index);
3718 delete target;
3719
3720}
3721
3722/************************************************************************/
3726{
3728
3729 if (selected_row_p < 0
3730 || selected_row_p >= p_table_p->rowCount()) {
3731 return;
3732 }
3733
3737}
3738
3739/************************************************************************/
3743{
3744 QModelIndex index;
3745 struct worklist queue;
3746 struct universal *target;
3747
3749 return;
3750 }
3751
3752 target = new universal;
3753 city_get_queue(dlgcity, &queue);
3754 worklist_peek_ith(&queue, target, selected_row_p);
3756 worklist_insert(&queue, target, selected_row_p + 1);
3757 city_set_queue(dlgcity, &queue);
3758 index = p_table_p->model()->index(selected_row_p + 1, 0);
3759 p_table_p->setCurrentIndex(index);
3760 delete target;
3761}
3762
3763/************************************************************************/
3767{
3768 hud_input_box *ask = new hud_input_box(gui()->central_wdg);
3769 int city_id = dlgcity->id;
3770
3771 ask->set_text_title_definput(_("What should we name new worklist?"),
3772 _("Save current worklist"),
3773 _("New worklist"));
3774 ask->setAttribute(Qt::WA_DeleteOnClose);
3775 connect(ask, &hud_message_box::accepted, [=]() {
3776 struct global_worklist *gw;
3777 struct worklist queue;
3779 QString text;
3780 struct city *pcity = game_city_by_number(city_id);
3781
3782 ask_bytes = ask->input_edit.text().toUtf8();
3783 text = ask_bytes.data();
3784 if (!text.isEmpty()) {
3785 ask_bytes = text.toUtf8();
3787 city_get_queue(pcity, &queue);
3788 global_worklist_set(gw, &queue);
3789 }
3790 });
3791 ask->show();
3792}
3793
3794/************************************************************************/
3798{
3799 QString buf;
3800
3801 // Defeat keyboard shortcut mnemonics
3803 .replace("&", "&&"));
3804
3805 if (city_unhappy(dlgcity)) {
3806 // TRANS: city dialog title
3807 buf = QString(_("%1 - %2 citizens - DISORDER")).arg(city_name_get(dlgcity),
3809 } else if (city_celebrating(dlgcity)) {
3810 // TRANS: city dialog title
3811 buf = QString(_("%1 - %2 citizens - celebrating")).arg(city_name_get(dlgcity),
3813 } else if (city_happy(dlgcity)) {
3814 // TRANS: city dialog title
3815 buf = QString(_("%1 - %2 citizens - happy")).arg(city_name_get(dlgcity),
3817 } else {
3818 // TRANS: city dialog title
3819 buf = QString(_("%1 - %2 citizens")).arg(city_name_get(dlgcity),
3821 }
3822
3824}
3825
3826/************************************************************************/
3831{
3832 if (!::city_dlg_created) {
3833 ::city_dlg = new city_dialog(gui()->mapview_wdg);
3834 }
3835
3837 city_dlg->show();
3838 city_dlg->activateWindow();
3839 city_dlg->raise();
3840}
3841
3842/************************************************************************/
3846{
3847 if (!::city_dlg_created) {
3848 return;
3849 }
3850
3851 city_dlg->close();
3852 ::city_dlg_created = false;
3853}
3854
3855/************************************************************************/
3859{
3860 if (!::city_dlg_created) {
3861 return;
3862 }
3863
3865}
3866
3867/************************************************************************/
3874
3875/************************************************************************/
3879{
3880 if (!::city_dlg_created) {
3881 return;
3882 }
3883
3885 city_dlg->refresh();
3886 }
3887}
3888
3889/************************************************************************/
3893{
3895 QFont *f;
3896
3897 if (!::city_dlg_created) {
3898 return;
3899 }
3900
3901 l = city_dlg->findChildren<QLabel *>();
3902
3904
3905 for (int i = 0; i < l.size(); ++i) {
3906 if (l.at(i)->property(fonts::notify_label).isValid()) {
3907 l.at(i)->setFont(*f);
3908 }
3909 }
3910}
3911
3912/************************************************************************/
3929
3930/************************************************************************/
3934{
3935 if (!::city_dlg_created) {
3936 return false;
3937 }
3938
3939 if (city_dlg->dlgcity == pcity && city_dlg->isVisible()) {
3940 return true;
3941 }
3942
3943 return false;
3944}
3945
3946/************************************************************************/
3949bool fc_tooltip::eventFilter(QObject *obj, QEvent *ev)
3950{
3953 QRect rect;
3954
3955 if (ev->type() == QEvent::ToolTip) {
3957
3958 if (!view) {
3959 return false;
3960 }
3961
3962 help_event = static_cast<QHelpEvent *>(ev);
3963 QPoint pos = help_event->pos();
3964 QModelIndex index = view->indexAt(pos);
3965 QPoint hpos;
3966
3967 if (!index.isValid()) {
3968 return false;
3969 }
3970
3971 item_tooltip = view->model()->data(index, Qt::ToolTipRole).toString();
3972 rect = view->visualRect(index);
3973
3974 hpos = help_event->globalPos();
3975
3976 rect.setX(rect.x() + hpos.x());
3977 rect.setY(rect.y() + hpos.y());
3978
3979 if (!item_tooltip.isEmpty()) {
3980 QToolTip::showText(help_event->globalPos(), item_tooltip, view, rect);
3981 } else {
3982 QToolTip::hideText();
3983 }
3984
3985 return true;
3986 }
3987
3988 return false;
3989}
3990
3991/************************************************************************/
3995{
3996 return QString("<b>" + text + "</b>");
3997}
3998
3999/************************************************************************/
4004 bool ext)
4005{
4007 QString upkeep;
4008 QString s1, s2, str;
4009 const char *req = skip_intl_qualifier_prefix(_("?tech:None"));
4010 struct player *pplayer = client_player();
4011
4012 if (pcity != nullptr) {
4013 upkeep = QString::number(city_improvement_upkeep(pcity, building));
4014 } else {
4015 upkeep = QString::number(building->upkeep);
4016 }
4018 if (pobs->source.kind == VUT_ADVANCE) {
4019 req = advance_name_translation(pobs->source.value.advance);
4020 break;
4021 }
4023 s2 = QString(req);
4024 str = _("Obsolete by:");
4025 str = str + " " + s2;
4026 def_str = "<p style='white-space:pre'><b>"
4027 + QString(improvement_name_translation(building)).toHtmlEscaped()
4028 + "</b>\n";
4029 if (pcity != nullptr) {
4030 def_str += QString(_("Cost: %1, Upkeep: %2\n"))
4031 .arg(impr_build_shield_cost(pcity, building))
4032 .arg(upkeep).toHtmlEscaped();
4033 } else {
4035 nullptr, building);
4036
4037 def_str += QString(_("Cost Estimate: %1, Upkeep: %2\n"))
4038 .arg(cost_est)
4039 .arg(upkeep).toHtmlEscaped();
4040 }
4041 if (s1.compare(s2) != 0) {
4042 def_str = def_str + str.toHtmlEscaped() + "\n";
4043 }
4044 def_str = def_str + "\n";
4045 if (ext) {
4046 char buffer[8192];
4047
4048 str = helptext_building(buffer, sizeof(buffer), pplayer,
4049 nullptr, building);
4050 str = cut_helptext(str);
4051 str = split_text(str, true);
4052 str = str.trimmed();
4053 def_str = def_str + str.toHtmlEscaped();
4054 }
4055 return def_str;
4056}
4057
4058/************************************************************************/
4062QString get_tooltip_unit(const struct unit_type *utype, bool ext)
4063{
4066 QString str;
4067 const struct unit_type *obsolete;
4068 struct advance *tech;
4069
4070 def_str = "<b>"
4071 + QString(utype_name_translation(utype)).toHtmlEscaped()
4072 + "</b>\n";
4073 obsolete = utype->obsoleted_by;
4074 if (obsolete) {
4075 // FIXME: Don't give the impression that primary tech is (always) the only one.
4077 obsolete_str = QString("</td></tr><tr><td colspan=\"3\">");
4078 if (tech && tech != advance_by_number(A_NONE)) {
4079 /* TRANS: this and nearby literal strings are interpreted
4080 * as (Qt) HTML */
4081 obsolete_str = obsolete_str + QString(_("Obsoleted by %1 (%2)."))
4083 .arg(advance_name_translation(tech)).toHtmlEscaped();
4084 } else {
4085 obsolete_str = obsolete_str + QString(_("Obsoleted by %1."))
4086 .arg(utype_name_translation(obsolete)).toHtmlEscaped();
4087 }
4088 }
4089 def_str += "<table width=\"100\%\"><tr><td>"
4090 + bold(QString(_("Attack:"))) + " "
4091 + QString::number(utype->attack_strength).toHtmlEscaped()
4092 + QString("</td><td>") + bold(QString(_("Defense:"))) + " "
4093 + QString::number(utype->defense_strength).toHtmlEscaped()
4094 + QString("</td><td>") + bold(QString(_("Move:"))) + " "
4095 + QString(move_points_text(utype->move_rate, TRUE)).toHtmlEscaped()
4096 + QString("</td></tr><tr><td>")
4097 + bold(QString(_("Cost:"))) + " "
4098 + QString::number(utype_build_shield_cost_base(utype))
4099 .toHtmlEscaped()
4100 + QString("</td><td colspan=\"2\">")
4101 + bold(QString(_("Basic Upkeep:")))
4102 + " " + QString(helptext_unit_upkeep_str(utype)).toHtmlEscaped()
4103 + QString("</td></tr><tr><td>")
4104 + bold(QString(_("Hitpoints:"))) + " "
4105 + QString::number(utype->hp).toHtmlEscaped()
4106 + QString("</td><td>") + bold(QString(_("Firepower:"))) + " "
4107 + QString::number(utype->firepower).toHtmlEscaped()
4108 + QString("</td><td>") + bold(QString(_("Vision:"))) + " "
4109 + QString::number((int) sqrt((double) utype->vision_radius_sq))
4110 .toHtmlEscaped()
4111 + obsolete_str
4112 + QString("</td></tr></table><p style='white-space:pre'>");
4113 if (ext) {
4114 char buffer[8192];
4115 char buf2[1];
4116
4117 buf2[0] = '\0';
4118 str = helptext_unit(buffer, sizeof(buffer), client_player(),
4119 buf2, utype, TRUE);
4120 str = cut_helptext(str);
4121 str = split_text(str, true);
4122 str = str.trimmed().toHtmlEscaped();
4123 def_str = def_str + str;
4124 }
4125
4126 return def_str;
4127};
4128
4129/************************************************************************/
4133{
4136 char buffer[8192];
4137 char buf2[1];
4138 struct universal *target;
4139 struct player *pplayer = client_player();
4140
4141 buf2[0] = '\0';
4142 target = reinterpret_cast<universal *>(qvar.value<void *>());
4143
4144 if (target == nullptr) {
4145 } else if (VUT_UTYPE == target->kind) {
4147 str = helptext_unit(buffer, sizeof(buffer), pplayer,
4148 buf2, target->value.utype, TRUE);
4149 } else {
4150 if (!is_convert_improvement(target->value.building)) {
4152 }
4153
4154 str = helptext_building(buffer, sizeof(buffer), pplayer,
4155 nullptr, target->value.building);
4156 }
4157
4158 // Remove all lines from help which has '*' in first 3 chars
4160 ret_str = split_text(ret_str, true);
4161 ret_str = ret_str.trimmed();
4162 ret_str = def_str + ret_str.toHtmlEscaped();
4163
4164 return ret_str;
4165}
4166
4167/************************************************************************/
4171 QObject *parent,
4172 struct city *city)
4173 : QItemDelegate(parent)
4174{
4175 pd = sh;
4176 item_height = sh.y();
4177 pcity = city;
4178}
4179
4180/************************************************************************/
4185 const QModelIndex &index) const
4186{
4187 struct universal *target;
4188 QString name;
4189 QVariant qvar;
4190 QPixmap *pix;
4192 QRect rect1;
4193 QRect rect2;
4194 struct sprite *sprite;
4195 bool useless = false;
4196 bool is_convert = false;
4197 bool is_neutral = false;
4198 bool is_sea = false;
4199 bool is_flying = false;
4200 bool is_unit = true;
4201 QPixmap pix_dec(option.rect.width(), option.rect.height());
4203 color col;
4204 QIcon icon = current_app()->style()->standardIcon(QStyle::SP_DialogCancelButton);
4205 bool free_sprite = false;
4206 struct unit_class *pclass;
4207
4208 if (!option.rect.isValid()) {
4209 return;
4210 }
4211
4212 qvar = index.data();
4213
4214 if (!qvar.isValid()) {
4215 return;
4216 }
4217
4218 target = reinterpret_cast<universal *>(qvar.value<void *>());
4219
4220 if (target == nullptr) {
4221 col.qcolor = Qt::white;
4222 sprite = qtg_create_sprite(100, 100, &col);
4223 free_sprite = true;
4224 *sprite->pm = icon.pixmap(100, 100);
4225 name = _("Cancel");
4226 is_unit = false;
4227 } else if (VUT_UTYPE == target->kind) {
4230 pclass = utype_class(target->value.utype);
4234 is_sea = true;
4235 }
4236
4237 if ((utype_fuel(target->value.utype)
4242 /* FIXME: Assumed to be flying since only missiles can do suicide
4243 * attacks in classic-like rulesets. This isn't true for all
4244 * rulesets. Not a high priority to fix since all is_flying and
4245 * is_sea is used for is to set a color. */
4247 target->value.utype)) {
4248 if (is_sea) {
4249 is_sea = false;
4250 }
4251 is_flying = true;
4252 }
4253
4257 } else {
4258 is_unit = false;
4261 useless = is_improvement_redundant(pcity, target->value.building);
4262 is_convert = (target->value.building->genus == IG_CONVERT);
4263 }
4264
4265 if (sprite != nullptr) {
4266 pix = sprite->pm;
4267 pix_scaled = pix->scaledToHeight(item_height - 2, Qt::SmoothTransformation);
4268
4269 if (useless) {
4271 }
4272 }
4273
4274 opt = QItemDelegate::setOptions(index, option);
4275 painter->save();
4276 opt.displayAlignment = Qt::AlignLeft;
4277 opt.textElideMode = Qt::ElideMiddle;
4278 QItemDelegate::drawBackground(painter, opt, index);
4279 rect1 = option.rect;
4280 rect1.setWidth(pix_scaled.width() + 4);
4281 rect2 = option.rect;
4282 rect2.setLeft(option.rect.left() + rect1.width());
4283 rect2.setTop(rect2.top() + (rect2.height()
4284 - painter->fontMetrics().height()) / 2);
4285 QItemDelegate::drawDisplay(painter, opt, rect2, name);
4286
4287 if (is_unit) {
4288 if (is_sea) {
4289 pix_dec.fill(QColor(0, 0, 255, 80));
4290 } else if (is_flying) {
4291 pix_dec.fill(QColor(220, 0, 0, 80));
4292 } else if (is_neutral) {
4293 pix_dec.fill(QColor(0, 120, 0, 40));
4294 } else {
4295 pix_dec.fill(QColor(0, 0, 150, 40));
4296 }
4297
4298 QItemDelegate::drawDecoration(painter, option, option.rect, pix_dec);
4299 }
4300
4301 if (is_convert) {
4302 pix_dec.fill(QColor(255, 255, 0, 70));
4303 QItemDelegate::drawDecoration(painter, option, option.rect, pix_dec);
4304 }
4305
4306 if (!pix_scaled.isNull()) {
4307 QItemDelegate::drawDecoration(painter, opt, rect1, pix_scaled);
4308 }
4309
4310 drawFocus(painter, opt, option.rect);
4311
4312 painter->restore();
4313
4314 if (free_sprite) {
4316 }
4317}
4318
4319/************************************************************************/
4324 const QRect &rect) const
4325{
4326 QPixmap pix(option.rect.width(), option.rect.height());
4327
4328 if ((option.state & QStyle::State_MouseOver) == 0 || !rect.isValid()) {
4329 return;
4330 }
4331
4332 pix.fill(QColor(50, 50, 50, 50));
4333 QItemDelegate::drawDecoration(painter, option, option.rect, pix);
4334}
4335
4336/************************************************************************/
4340 const QModelIndex &index) const
4341{
4342 QSize s;
4343
4344 s.setWidth(pd.x());
4345 s.setHeight(pd.y());
4346 return s;
4347}
4348
4349/************************************************************************/
4353 QObject *parent): QObject()
4354{
4356 target = ptarget;
4357}
4358
4359/************************************************************************/
4363{
4364 // Allocated as renegade in model
4365 if (target != nullptr) {
4366 delete target;
4367 }
4368}
4369
4370/************************************************************************/
4374{
4375 return QVariant::fromValue((void *)target);
4376}
4377
4378/************************************************************************/
4382{
4383 return false;
4384}
4385
4386/************************************************************************/
4390 bool su, bool sw, bool sb,
4391 QObject *parent)
4392 : QAbstractListModel(parent)
4393{
4394 show_units = su;
4395 show_wonders = sw;
4397 mcity = pcity;
4398 future_t = f;
4399 populate();
4400}
4401
4402/************************************************************************/
4410
4411/************************************************************************/
4415{
4416 if (!index.isValid()) {
4417 return QVariant();
4418 }
4419
4420 if (index.row() >= 0 && index.row() < rowCount() && index.column() >= 0
4421 && index.column() < columnCount()
4422 && (index.column() + index.row() * 3 < city_target_list.count())) {
4423 int r, c, t, new_index;
4424
4425 r = index.row();
4426 c = index.column();
4427 t = r * 3 + c;
4428 new_index = t / 3 + rowCount() * c;
4429 // Exception, shift whole column
4430 if ((c == 2) && city_target_list.count() % 3 == 1) {
4431 new_index = t / 3 + rowCount() * c - 1;
4432 }
4433 if (role == Qt::ToolTipRole) {
4435 }
4436
4437 return city_target_list[new_index]->data();
4438 }
4439
4440 return QVariant();
4441}
4442
4443/************************************************************************/
4447{
4449 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
4450 struct item items[MAX_NUM_PRODUCTION_TARGETS];
4451 struct universal *renegade;
4452 int item, targets_used;
4453 QString str;
4455 QFontMetrics fm(f);
4456
4457 sh.setY(fm.height() * 2);
4458 sh.setX(0);
4459
4461 city_target_list.clear();
4462
4464 future_t);
4465 name_and_sort_items(targets, targets_used, items, false, mcity);
4466
4467 for (item = 0; item < targets_used; item++) {
4468 if (future_t || can_city_build_now(&(wld.map), mcity, &items[item].item)) {
4469 renegade = new universal(items[item].item);
4470
4471 // Renegade deleted in production_item destructor
4472 if (VUT_UTYPE == renegade->kind) {
4473 str = utype_name_translation(renegade->value.utype);
4474 sh.setX(qMax(sh.x(), fm.horizontalAdvance(str)));
4475
4476 if (show_units) {
4477 pi = new production_item(renegade, this);
4479 } else {
4480 delete renegade;
4481 }
4482 } else {
4483 str = improvement_name_translation(renegade->value.building);
4484 sh.setX(qMax(sh.x(), fm.horizontalAdvance(str)));
4485
4486 if ((is_wonder(renegade->value.building) && show_wonders)
4487 || (is_improvement(renegade->value.building) && show_buildings)
4488 || (is_convert_improvement(renegade->value.building))
4489 || (is_special_improvement(renegade->value.building)
4490 && show_buildings)) {
4491 pi = new production_item(renegade, this);
4493 } else {
4494 delete renegade;
4495 }
4496 }
4497 }
4498 }
4499
4500 pi = new production_item(nullptr, this);
4502 sh.setX(2 * sh.y() + sh.x());
4503 sh.setX(qMin(sh.x(), 250));
4504}
4505
4506/************************************************************************/
4510 const QVariant &value, int role)
4511{
4512 if (!index.isValid() || role != Qt::DisplayRole || role != Qt::ToolTipRole)
4513 return false;
4514
4515 if (index.row() >= 0 && index.row() < rowCount() && index.column() >= 0
4516 && index.column() < columnCount()) {
4517 bool change = city_target_list[index.row()]->setData();
4518 return change;
4519 }
4520
4521 return false;
4522}
4523
4524/************************************************************************/
4533 bool future, int when, int curr,
4534 bool show_units, bool buy,
4535 bool show_wonders,
4536 bool show_buildings): QTableView()
4537{
4538 QPoint pos, sh;
4539 QRect rect = QApplication::primaryScreen()->availableGeometry();
4540 int desk_width = rect.width();
4541 int desk_height = rect.height();
4542 fc_tt = new fc_tooltip(this);
4543 setAttribute(Qt::WA_DeleteOnClose);
4544 setWindowFlags(Qt::Popup);
4545 verticalHeader()->setVisible(false);
4546 horizontalHeader()->setVisible(false);
4547 setProperty("showGrid", false);
4549 sh_units = show_units;
4550 pw_city = pcity;
4551 buy_it = buy;
4552 when_change = when;
4553 list_model = new city_production_model(pw_city, future, show_units,
4554 show_wonders, show_buildings, this);
4555 sh = list_model->sh;
4556 c_p_d = new city_production_delegate(sh, this, pw_city);
4559 viewport()->installEventFilter(fc_tt);
4560 installEventFilter(this);
4562 const QItemSelection &)),
4564 const QItemSelection &)));
4567 setFixedWidth(3 * sh.x() + 6);
4568 setFixedHeight(list_model->rowCount()*sh.y() + 6);
4569
4570 if (width() > desk_width) {
4572 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
4573 } else {
4574 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
4575 }
4576
4577 if (height() > desk_height) {
4579 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
4580 } else {
4581 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
4582 }
4583
4584 pos = QCursor::pos();
4585
4586 if (pos.x() + width() > desk_width) {
4587 pos.setX(desk_width - width());
4588 } else if (pos.x() - width() < 0) {
4589 pos.setX(0);
4590 }
4591
4592 if (pos.y() + height() > desk_height) {
4593 pos.setY(desk_height - height());
4594 } else if (pos.y() - height() < 0) {
4595 pos.setY(0);
4596 }
4597
4598 move(pos);
4599 setMouseTracking(true);
4600 setFocus();
4601}
4602
4603/************************************************************************/
4607{
4608 if (event->button() == Qt::RightButton) {
4609 close();
4610 return;
4611 }
4612
4613 QAbstractItemView::mousePressEvent(event);
4614}
4615
4616/************************************************************************/
4620{
4621 QRect pw_rect;
4622 QPoint br;
4623
4624 if (obj != this)
4625 return false;
4626
4627 if (ev->type() == QEvent::MouseButtonPress) {
4628 pw_rect.setTopLeft(pos());
4629 br.setX(pos().x() + width());
4630 br.setY(pos().y() + height());
4631 pw_rect.setBottomRight(br);
4632
4633 if (!pw_rect.contains(QCursor::pos())) {
4634 close();
4635 }
4636 }
4637
4638 return false;
4639}
4640
4641/************************************************************************/
4645 const QItemSelection &ds)
4646{
4647 QModelIndexList indexes = selectionModel()->selectedIndexes();
4648 QModelIndex index;
4649 QVariant qvar;
4650 struct worklist queue;
4651 struct universal *target;
4652
4653 if (indexes.isEmpty() || client_is_observer()) {
4654 return;
4655 }
4656 index = indexes.at(0);
4657 qvar = index.data(Qt::UserRole);
4658 if (!qvar.isValid()) {
4659 return;
4660 }
4661 target = reinterpret_cast<universal *>(qvar.value<void *>());
4662 if (target != nullptr) {
4663 city_get_queue(pw_city, &queue);
4664 switch (when_change) {
4665 case 0: // Change current target
4667 if (city_can_buy(pw_city) && buy_it) {
4669 }
4670 break;
4671
4672 case 1: // Change current (selected on list)
4675 } else {
4677 worklist_insert(&queue, target, curr_selection);
4678 city_set_queue(pw_city, &queue);
4679 }
4680 break;
4681
4682 case 2: // Insert before
4684 curr_selection = 0;
4685 }
4688 worklist_insert(&queue, target, curr_selection);
4689 city_set_queue(pw_city, &queue);
4690 break;
4691
4692 case 3: // Insert after
4694 city_queue_insert(pw_city, -1, target);
4695 break;
4696 }
4698 worklist_insert(&queue, target, curr_selection);
4699 city_set_queue(pw_city, &queue);
4700 break;
4701
4702 case 4: // Add last
4703 city_queue_insert(pw_city, -1, target);
4704 break;
4705
4706 default:
4707 break;
4708 }
4709 }
4710 close();
4711 destroy();
4712}
4713
4714/************************************************************************/
4718{
4719 delete c_p_d;
4720 delete list_model;
4721 viewport()->removeEventFilter(fc_tt);
4722 removeEventFilter(this);
4723}
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:3858
void qtg_real_city_dialog_refresh(struct city *pcity)
Definition citydlg.cpp:3878
QString split_text(QString text, bool cut)
Definition optiondlg.cpp:62
void city_font_update()
Definition citydlg.cpp:3892
bool qtg_city_dialog_is_open(struct city *pcity)
Definition citydlg.cpp:3933
QString get_tooltip(QVariant qvar)
Definition citydlg.cpp:4132
void qtg_popdown_all_city_dialogs()
Definition citydlg.cpp:3870
static city_dialog * city_dlg
Definition citydlg.cpp:75
void qtg_refresh_unit_city_dialogs(struct unit *punit)
Definition citydlg.cpp:3917
static QString bold(QString text)
Definition citydlg.cpp:3994
void qtg_real_city_dialog_popup(struct city *pcity)
Definition citydlg.cpp:3830
QString get_tooltip_improvement(const impr_type *building, struct city *pcity, bool ext)
Definition citydlg.cpp:4003
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:4062
void destroy_city_dialog()
Definition citydlg.cpp:3845
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:4170
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition citydlg.cpp:4183
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition citydlg.cpp:4339
struct city * pcity
Definition citydlg.h:310
void drawFocus(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect) const
Definition citydlg.cpp:4322
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:4509
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:4389
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition citydlg.cpp:4414
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:3949
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:4373
production_item(struct universal *ptarget, QObject *parent)
Definition citydlg.cpp:4352
bool eventFilter(QObject *obj, QEvent *ev)
Definition citydlg.cpp:4619
void prod_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:4644
void mousePressEvent(QMouseEvent *event)
Definition citydlg.cpp:4606
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:4532
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:76
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:248
#define EC_NONE
Definition fc_types.h:806
@ TR_SUCCESS
Definition fc_types.h:939
#define ERM_NONE
Definition fc_types.h:829
@ O_SHIELD
Definition fc_types.h:102
@ O_FOOD
Definition fc_types.h:102
@ O_TRADE
Definition fc_types.h:102
@ O_SCIENCE
Definition fc_types.h:102
@ O_LUXURY
Definition fc_types.h:102
@ O_GOLD
Definition fc_types.h:102
@ O_LAST
Definition fc_types.h:102
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:4003
QString get_tooltip(QVariant qvar)
Definition citydlg.cpp:4132
#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:1048
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:458
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:1237
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:439
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:3269
int current_building
Definition citydlg.h:504
void worklist_up()
Definition citydlg.cpp:3700
city_label * citizens_label
Definition citydlg.h:447
QPushButton * lcity_name
Definition citydlg.h:490
void show_happiness()
Definition citydlg.cpp:2118
void closeEvent(QCloseEvent *event)
Definition citydlg.cpp:2315
void show_counters()
Definition citydlg.cpp:2153
void update_nation_table()
Definition citydlg.cpp:3063
void hideEvent(QHideEvent *event)
Definition citydlg.cpp:2287
void cma_toggle_changed_depr(int state)
Definition citydlg.cpp:2698
QPushButton * work_next_but
Definition citydlg.h:478
void next_city()
Definition citydlg.cpp:3379
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:2298
QPushButton * happiness_button
Definition citydlg.h:482
void cma_double_clicked(int row, int column)
Definition citydlg.cpp:2491
void display_worklist_menu(const QPoint &p)
Definition citydlg.cpp:2775
void update_disabled()
Definition citydlg.cpp:2188
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:2867
int selected_row_p
Definition citydlg.h:491
QHBoxLayout * leftbot_layout
Definition citydlg.h:442
void update_building()
Definition citydlg.cpp:3451
QPushButton * zoom_in_button
Definition citydlg.h:484
void save_worklist()
Definition citydlg.cpp:3766
void worklist_del()
Definition citydlg.cpp:3725
QGridLayout * info_grid_layout
Definition citydlg.h:449
void clear_worklist()
Definition citydlg.cpp:3685
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:2406
void zoom_in()
Definition citydlg.cpp:2393
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:3140
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:2734
void update_citizens()
Definition citydlg.cpp:2893
QRadioButton * r1
Definition citydlg.h:472
void cma_slider(int val)
Definition citydlg.cpp:2709
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:3742
void update_title()
Definition citydlg.cpp:3797
QLabel * cma_info_text
Definition citydlg.h:456
void dbl_click_p(QTableWidgetItem *item)
Definition citydlg.cpp:3285
QPushButton * cma_enable_but
Definition citydlg.h:475
QLabel * cma_result
Definition citydlg.h:457
void cma_remove()
Definition citydlg.cpp:2659
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:2326
QSplitter * prod_unit_splitter
Definition citydlg.h:439
QVBoxLayout * left_layout
Definition citydlg.h:445
void prev_city()
Definition citydlg.cpp:3415
void city_rename()
Definition citydlg.cpp:2363
void refresh()
Definition citydlg.cpp:2989
void update_cma_tab()
Definition citydlg.cpp:2592
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:3654
city_dialog(QWidget *parent=nullptr)
Definition citydlg.cpp:1474
void cma_toggle_changed(Qt::CheckState state)
Definition citydlg.cpp:2686
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:2097
QPushButton * prev_city_but
Definition citydlg.h:477
void cma_enable()
Definition citydlg.cpp:2455
QLabel * cma_result_pix
Definition citydlg.h:458
struct city * dlgcity
Definition citydlg.h:499
void update_counters_table()
Definition citydlg.cpp:3021
void update_sliders()
Definition citydlg.cpp:2540
void update_improvements()
Definition citydlg.cpp:3519
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:2052
void cma_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:2510
QCheckBox * cma_max_growth
Definition citydlg.h:467
void item_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:3361
void show_targets_worklist()
Definition citydlg.cpp:3670
QCheckBox * show_wonders
Definition citydlg.h:471
void cma_context_menu(const QPoint &p)
Definition citydlg.cpp:2755
void cma_changed()
Definition citydlg.cpp:2470
QPushButton * buy_button
Definition citydlg.h:474
QRadioButton * r4
Definition citydlg.h:472
struct city_dialog::@149 counters
void update_units()
Definition citydlg.cpp:3302
QRadioButton * r2
Definition citydlg.h:472
QTableWidget * p_table_p
Definition citydlg.h:463
void save_cma()
Definition citydlg.cpp:2419
QPixmap * citizen_pixmap
Definition citydlg.h:486
void production_changed(int index)
Definition citydlg.cpp:3636
void update_prod_buttons()
Definition citydlg.cpp:2225
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:593
universals_u value
Definition fc_types.h:592
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:535
const struct impr_type * building
Definition fc_types.h:528
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