Freeciv-3.3
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/************************************************************************/
415#ifndef FC_QT5_MODE
417#else // FC_QT5_MODE
418void impr_item::enterEvent(QEvent *event)
419#endif // FC_QT5_MODE
420{
421 struct sprite *sprite;
422 QPainter p;
423
424 if (impr_pixmap) {
425 canvas_free(impr_pixmap);
426 }
427
429 if (impr && sprite) {
430 impr_pixmap = qtg_canvas_create(sprite->pm->width(),
431 sprite->pm->height());
432 impr_pixmap->map_pixmap.fill(QColor(palette().color(QPalette::Highlight)));
433 pixmap_copy(&impr_pixmap->map_pixmap, sprite->pm, 0 , 0, 0, 0,
434 sprite->pm->width(), sprite->pm->height());
435 } else {
436 impr_pixmap = qtg_canvas_create(10, 10);
437 impr_pixmap->map_pixmap.fill(QColor(palette().color(QPalette::Highlight)));
438 }
439
440 init_pix();
441}
442
443/************************************************************************/
447{
448 struct sprite *sprite;
449
450 if (impr_pixmap) {
452 }
453
455 if (impr && sprite) {
457 sprite->pm->height());
458 impr_pixmap->map_pixmap.fill(Qt::transparent);
459 pixmap_copy(&impr_pixmap->map_pixmap, sprite->pm, 0 , 0, 0, 0,
460 sprite->pm->width(), sprite->pm->height());
461 } else {
463 impr_pixmap->map_pixmap.fill(Qt::red);
464 }
465
466 init_pix();
467}
468
469/************************************************************************/
473{
475 layout = new QHBoxLayout(this);
476 init_layout();
477}
478
479/************************************************************************/
483{
484 QSizePolicy size_fixed_policy(QSizePolicy::Fixed,
485 QSizePolicy::MinimumExpanding,
486 QSizePolicy::Slider);
487
490}
491
492/************************************************************************/
496{
497
498}
499
500/************************************************************************/
504{
505 impr_list.append(item);
506}
507
508/************************************************************************/
512{
513 int i = impr_list.count();
514 impr_item *ui;
515 int j;
516 setUpdatesEnabled(false);
517 setMouseTracking(false);
518
519 for (j = 0; j < i; j++) {
520 ui = impr_list[j];
521 layout->removeWidget(ui);
522 delete ui;
523 }
524
525 while (!impr_list.empty()) {
526 impr_list.removeFirst();
527 }
528
529 setMouseTracking(true);
530 setUpdatesEnabled(true);
531}
532
533/************************************************************************/
537{
538 QPoint p;
539
540 p = parentWidget()->parentWidget()->pos();
541 p = mapToGlobal(p);
542
543 QWheelEvent new_event(QPoint(5, 5), p + QPoint(5,5), event->pixelDelta(),
544 event->angleDelta(),
545 event->buttons(),
546 event->modifiers(),
547 event->phase(), false, event->source());
548
549 QApplication::sendEvent(parentWidget(), &new_event);
550}
551
552/************************************************************************/
556{
557 int i = impr_list.count();
558 int j;
559 int h = 0;
560 impr_item *ui;
561
562 setUpdatesEnabled(false);
563 hide();
564
565 for (j = 0; j < i; j++) {
566 ui = impr_list[j];
567 h = ui->height();
568 layout->addWidget(ui, 0, Qt::AlignVCenter);
569 }
570
571 if (impr_list.count() > 0) {
572 parentWidget()->parentWidget()->setFixedHeight(city_dlg->scroll_height
573 + h + 6);
574 } else {
575 parentWidget()->parentWidget()->setFixedHeight(0);
576 }
577
578 show();
579 setUpdatesEnabled(true);
580 layout->update();
582}
583
584/************************************************************************/
588{
589 QPoint p;
590
591 p = parentWidget()->parentWidget()->pos();
592 p = mapToGlobal(p);
593
594 QWheelEvent new_event(QPoint(5, 5), p + QPoint(5,5), event->pixelDelta(),
595 event->angleDelta(),
596 event->buttons(),
597 event->modifiers(),
598 event->phase(), false, event->source());
599
600 QApplication::sendEvent(parentWidget()->parentWidget(),
601 &new_event);
602}
603
604/************************************************************************/
608{
610 return;
611 }
612
613 if (event->button() == Qt::LeftButton) {
614 char buf[256];
615 int price;
616 const int impr_id = improvement_number(impr);
617 const int city_id = dlgcity->id;
619
621 impr) != TR_SUCCESS) {
622 return;
623 }
624
626
629 PL_("Sell %s for %d gold?",
630 "Sell %s for %d gold?", price),
632
633 ask->set_text_title(buf, (_("Sell improvement?")));
634 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
635 ask->setAttribute(Qt::WA_DeleteOnClose);
636 connect(ask, &hud_message_box::accepted, [=]() {
637 struct city *pcity = game_city_by_number(city_id);
638
639 if (pcity == nullptr) {
640 return;
641 }
643 });
644 ask->show();
645 }
646}
647
648/************************************************************************/
652 bool supp, int hppy_cost) : QLabel()
653{
656 QImage img;
657 QRect crop;
658 qunit = punit;
659 struct canvas *unit_pixmap;
660 struct tileset *tmp;
661 float isosize;
662
664 supported = supp;
665
666 tmp = nullptr;
667 if (unscaled_tileset) {
668 tmp = tileset;
670 }
671 isosize = 0.6;
673 isosize = 0.45;
674 }
675
676 if (punit) {
677 if (supported) {
680 } else {
683 }
684
685 unit_pixmap->map_pixmap.fill(Qt::transparent);
686 put_unit(punit, unit_pixmap, 1.0, 0, 0);
687
688 if (supported) {
692 }
693 } else {
695 unit_pixmap->map_pixmap.fill(Qt::transparent);
696 }
697
698 img = unit_pixmap->map_pixmap.toImage();
700 cropped_img = img.copy(crop);
703 * isosize, Qt::SmoothTransformation);
704 } else {
706 Qt::SmoothTransformation);
707 }
709 if (tmp != nullptr) {
710 tileset = tmp;
711 }
712
714 setFixedWidth(unit_img.width() + 4);
715 setFixedHeight(unit_img.height());
717}
718
719/************************************************************************/
723{
724 setPixmap(QPixmap::fromImage(unit_img));
725 update();
726}
727
728/************************************************************************/
734
735/************************************************************************/
739{
740 QMenu *menu;
741
743 return;
744 }
745
746 if (unit_owner(qunit) != client_player()) {
747 return;
748 }
749
750 menu = new QMenu(gui()->central_wdg);
751 menu->addAction(activate);
752 menu->addAction(activate_and_close);
753
754 if (sentry) {
755 menu->addAction(sentry);
756 }
757
758 if (fortify) {
759 menu->addAction(fortify);
760 }
761
762 if (change_home) {
763 menu->addAction(change_home);
764 }
765
766 if (load) {
767 menu->addAction(load);
768 }
769
770 if (unload) {
771 menu->addAction(unload);
772 }
773
774 if (unload_trans) {
775 menu->addAction(unload_trans);
776 }
777
778 if (disband_action) {
779 menu->addAction(disband_action);
780 }
781
782 if (upgrade) {
783 menu->addAction(upgrade);
784 }
785
786 menu->popup(event->globalPos());
787}
788
789/************************************************************************/
793{
794 struct unit_list *qunits;
795
797 return;
798 }
799
802 activate = new QAction(_("Activate unit"), this);
803 connect(activate, &QAction::triggered, this, &unit_item::activate_unit);
804 activate_and_close = new QAction(_("Activate and close dialog"), this);
805 connect(activate_and_close, &QAction::triggered, this,
807
809 sentry = new QAction(_("Sentry unit"), this);
810 connect(sentry, &QAction::triggered, this, &unit_item::sentry_unit);
811 } else {
812 sentry = nullptr;
813 }
814
816 fortify = new QAction(_("Fortify unit"), this);
817 connect(fortify, &QAction::triggered, this, &unit_item::fortify_unit);
818 } else {
819 fortify = nullptr;
820 }
822 disband_action = new QAction(_("Disband unit"), this);
823 connect(disband_action, &QAction::triggered, this, &unit_item::disband);
824 } else {
825 disband_action = nullptr;
826 }
827
830 this);
831 connect(change_home, &QAction::triggered, this, &unit_item::change_homecity);
832 } else {
833 change_home = nullptr;
834 }
835
836 if (units_can_load(qunits)) {
837 load = new QAction(_("Load"), this);
838 connect(load, &QAction::triggered, this, &unit_item::load_unit);
839 } else {
840 load = nullptr;
841 }
842
843 if (units_can_unload(&(wld.map), qunits)) {
844 unload = new QAction(_("Unload"), this);
845 connect(unload, &QAction::triggered, this, &unit_item::unload_unit);
846 } else {
847 unload = nullptr;
848 }
849
851 unload_trans = new QAction(_("Unload All From Transporter"), this);
852 connect(unload_trans, &QAction::triggered, this, &unit_item::unload_all);
853 } else {
854 unload_trans = nullptr;
855 }
856
857 if (units_can_upgrade(&(wld.map), qunits)) {
858 upgrade = new QAction(_("Upgrade Unit"), this);
859 connect(upgrade, &QAction::triggered, this, &unit_item::upgrade_unit);
860 } else {
861 upgrade = nullptr;
862 }
863
865}
866
867/************************************************************************/
871{
872 struct unit_list *punits;
874
875 if (punit == nullptr) {
876 return;
877 }
878
883}
884
885/************************************************************************/
892
893/************************************************************************/
900
901/************************************************************************/
908
909/************************************************************************/
920
921/************************************************************************/
930
931/************************************************************************/
941
942/************************************************************************/
946{
947 if (qunit) {
949 }
950}
951
952/************************************************************************/
956{
957 if (qunit) {
959 }
960}
961
962/************************************************************************/
965#ifndef FC_QT5_MODE
967#else // FC_QT5_MODE
968void unit_item::enterEvent(QEvent *event)
969#endif // FC_QT5_MODE
970{
971 QImage temp_img(unit_img.size(), QImage::Format_ARGB32_Premultiplied);
972 QPainter p;
973
974 p.begin(&temp_img);
975 p.fillRect(0, 0, unit_img.width(), unit_img.height(),
976 QColor(palette().color(QPalette::Highlight)));
977 p.drawImage(0, 0, unit_img);
978 p.end();
979
980 setPixmap(QPixmap::fromImage(temp_img));
981 update();
982}
983
984/************************************************************************/
988{
989 init_pix();
990}
991
992/************************************************************************/
996{
997 QPoint p;
998
999 p = parentWidget()->parentWidget()->pos();
1000 p = mapToGlobal(p);
1001
1002 QWheelEvent new_event(QPoint(5, 5), p + QPoint(5,5), event->pixelDelta(),
1003 event->angleDelta(),
1004 event->buttons(),
1005 event->modifiers(),
1006 event->phase(), false, event->source());
1007
1008 QApplication::sendEvent(parentWidget()->parentWidget(),
1009 &new_event);
1010}
1011
1012/************************************************************************/
1016{
1017 if (event->button() == Qt::LeftButton) {
1018 if (qunit) {
1021 }
1022 }
1023}
1024
1025/************************************************************************/
1029{
1030 if (qunit) {
1032 }
1033}
1034
1035/************************************************************************/
1039{
1040 layout = new QHBoxLayout(this);
1041 init_layout();
1042 supports = supp;
1043}
1044
1045/************************************************************************/
1049{
1051 unit_list.clear();
1052}
1053
1054/************************************************************************/
1058{
1059 unit_list.append(item);
1060}
1061
1062/************************************************************************/
1066{
1067 QSizePolicy size_fixed_policy(QSizePolicy::Fixed,
1068 QSizePolicy::MinimumExpanding,
1069 QSizePolicy::Slider);
1072}
1073
1074/************************************************************************/
1078{
1079 QPoint p;
1080
1081 p = parentWidget()->parentWidget()->pos();
1082 p = mapToGlobal(p);
1083
1084 QWheelEvent new_event(QPoint(5, 5), p + QPoint(5,5), event->pixelDelta(),
1085 event->angleDelta(),
1086 event->buttons(),
1087 event->modifiers(),
1088 event->phase(), false, event->source());
1089
1090 QApplication::sendEvent(parentWidget(), &new_event);
1091}
1092
1093/************************************************************************/
1097{
1098 int i = unit_list.count();
1099 int j;
1100 int h;
1101 float hexfix;
1102 unit_item *ui;
1103
1104 setUpdatesEnabled(false);
1105 hide();
1106
1107 for (j = 0; j < i; j++) {
1108 ui = unit_list[j];
1109 layout->addWidget(ui, 0, Qt::AlignVCenter);
1110 }
1111
1112 hexfix = 1.0;
1114 hexfix = 0.75;
1115 }
1116
1118 h = tileset_unit_width(get_tileset()) * 0.7 * hexfix + 6;
1119 } else {
1121 }
1122 if (unit_list.count() > 0) {
1123 parentWidget()->parentWidget()->setFixedHeight(city_dlg->scroll_height
1124 + h);
1125 } else {
1126 parentWidget()->parentWidget()->setFixedHeight(0);
1127 }
1128 show();
1129 setUpdatesEnabled(true);
1130 layout->update();
1132}
1133
1134/************************************************************************/
1138{
1139 int i = unit_list.count();
1140 unit_item *ui;
1141 int j;
1142 setUpdatesEnabled(false);
1143 setMouseTracking(false);
1144
1145 for (j = 0; j < i; j++) {
1146 ui = unit_list[j];
1147 layout->removeWidget(ui);
1148 delete ui;
1149 }
1150
1151 while (!unit_list.empty()) {
1152 unit_list.removeFirst();
1153 }
1154
1155 setMouseTracking(true);
1156 setUpdatesEnabled(true);
1157}
1158
1159/************************************************************************/
1163city_label::city_label(int t, QWidget *parent) : QLabel(parent)
1164{
1165 type = t;
1166}
1167
1168/************************************************************************/
1172{
1173 int citnum, i;
1174 int w = tileset_small_sprite_width(tileset) / gui()->map_scale;
1175 int num_citizens = pcity->size;
1176
1177 if (cma_is_city_under_agent(pcity, nullptr)) {
1178 return;
1179 }
1180
1181 i = 1 + (num_citizens * 5 / 200);
1182 w = w / i;
1183 citnum = event->pos().x() / w;
1184
1185 if (!can_client_issue_orders()) {
1186 return;
1187 }
1188
1190}
1191
1192/************************************************************************/
1196{
1197 pcity = pciti;
1198}
1199
1200/************************************************************************/
1204{
1206 radius = 0;
1212 view->map_pixmap.fill(Qt::black);
1214 miniview->map_pixmap.fill(Qt::black);
1215 delta_x = 0;
1216 delta_y = 0;
1217 setContextMenuPolicy(Qt::CustomContextMenu);
1218 connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
1219 this, SLOT(context_menu(const QPoint &)));
1220}
1221
1222/************************************************************************/
1230
1231/************************************************************************/
1235{
1237 QString str;
1238
1239 painter.begin(this);
1240 painter.drawPixmap(0, 0, zoomed_pixmap);
1241
1242 if (cma_is_city_under_agent(mcity, nullptr)) {
1243 painter.fillRect(0, 0, zoomed_pixmap.width(), zoomed_pixmap.height(),
1244 QBrush(QColor(60, 60 , 60 , 110)));
1245 painter.setPen(QColor(255, 255, 255));
1246 // TRANS: %1 is a custom string chosen by player.
1247 str = QString(_("Governor %1"))
1249 painter.drawText(5, zoomed_pixmap.height() - 10, str);
1250 }
1251
1252 painter.end();
1253}
1254
1255/************************************************************************/
1258void city_map::set_pixmap(struct city *pcity, float z)
1259{
1260 int r, max_r;
1261 QSize size;
1262
1263 zoom = z;
1265
1266 if (radius != r) {
1268 radius = r;
1270 cutted_width = wdth * (r + 1) / max_r;
1271 cutted_height = height * (r + 1) / max_r;
1274 delta_x = (wdth - cutted_width) / 2;
1275 delta_y = (height - cutted_height) / 2;
1277 miniview->map_pixmap.fill(Qt::black);
1278 }
1279
1283 size = miniview->map_pixmap.size();
1285 Qt::KeepAspectRatio,
1286 Qt::SmoothTransformation);
1288 mcity = pcity;
1289}
1290
1291/************************************************************************/
1295{
1296 return zoomed_pixmap.size();
1297}
1298
1299/************************************************************************/
1303{
1304 return zoomed_pixmap.size();
1305}
1306
1307/************************************************************************/
1311{
1313 QPoint pos;
1314
1315 if (!can_client_issue_orders() || event->button() != Qt::LeftButton) {
1316 return;
1317 }
1318
1319 pos = event->pos();
1320 canvas_x = pos.x() / zoom + delta_x;
1321 canvas_y = pos.y() / zoom + delta_y;
1322
1324 canvas_x, canvas_y)) {
1326 }
1327}
1328
1329/************************************************************************/
1333{
1335 QAction *con_cultivate = nullptr;
1336 QAction *con_irrig = nullptr;
1337 QAction *con_plant = nullptr;
1338 QAction *con_mine = nullptr;
1339 QAction *con_road = nullptr;
1340 QAction *con_trfrm = nullptr;
1341 QAction *con_clean = nullptr;
1342 QAction *con_clear = nullptr;
1343 QMenu *con_menu;
1345 struct terrain *pterr;
1346 struct tile *ptile;
1347 struct universal for_terr;
1348 struct worker_task *ptask;
1349 int city_id = mcity->id;
1350
1351 if (!can_client_issue_orders()) {
1352 return;
1353 }
1354
1355 canvas_x = point.x() / zoom + delta_x;
1356 canvas_y = point.y() / zoom + delta_y;
1357
1359 canvas_x, canvas_y)) {
1360 return;
1361 }
1362
1364 city_x, city_y);
1365 pterr = tile_terrain(ptile);
1366 for_terr.kind = VUT_TERRAIN;
1367 for_terr.value.terrain = pterr;
1369
1370 wid_act = new QWidgetAction(this);
1371 wid_act->setDefaultWidget(new QLabel(_("Autoworker activity:")));
1372
1373 con_menu = new QMenu(this);
1374 con_menu->addAction(wid_act);
1375
1376 if (pterr->plant_result != nullptr
1378 con_plant = con_menu->addAction(_("Plant"));
1379 }
1381 con_mine = con_menu->addAction(Q_("?act:Mine"));
1382 }
1383
1384 if (pterr->cultivate_result != nullptr
1386 con_cultivate = con_menu->addAction(_("Cultivate"));
1387 }
1389 con_irrig = con_menu->addAction(_("Irrigate"));
1390 }
1391
1392 if (pterr->transform_result != pterr && pterr->transform_result != nullptr
1394 nullptr, &for_terr)) {
1395 con_trfrm = con_menu->addAction(_("Transform"));
1396 }
1397
1398 if (next_extra_for_tile(ptile, EC_ROAD, city_owner(mcity), nullptr) != nullptr) {
1399 con_road = con_menu->addAction(_("Road"));
1400 }
1401
1402 if (prev_extra_in_tile(ptile, ERM_CLEAN,
1403 city_owner(mcity), nullptr) != nullptr) {
1404 con_clean = con_menu->addAction(_("Clean"));
1405 }
1406
1407 if (ptask != nullptr) {
1408 con_clear = con_menu->addAction(_("Clear"));
1409 }
1410
1411 con_menu->setAttribute(Qt::WA_DeleteOnClose);
1412 connect(con_menu, &QMenu::triggered,
1414 bool target = false;
1415 struct packet_worker_task task;
1416
1417 if (!act) {
1418 return;
1419 }
1420
1421 task.city_id = city_id;
1422
1423 if (act == con_road) {
1425 target = TRUE;
1426 } else if (act == con_mine) {
1427 task.activity = ACTIVITY_MINE;
1428 target = TRUE;
1429 } else if (act == con_plant) {
1430 task.activity = ACTIVITY_PLANT;
1431 } else if (act == con_irrig) {
1433 target = TRUE;
1434 } else if (act == con_cultivate) {
1436 } else if (act == con_trfrm) {
1438 } else if (act == con_clean) {
1439 task.activity = ACTIVITY_CLEAN;
1440 target = TRUE;
1441 } else if (act == con_clear) {
1442 task.activity = ACTIVITY_LAST;
1443 } else {
1444 // Closed dialog without selecting any activity entry.
1445 return;
1446 }
1447
1448 task.want = 100;
1449
1450 if (target) {
1451 enum extra_cause cause = activity_to_extra_cause(task.activity);
1453 struct extra_type *tgt;
1454
1455 if (cause != EC_NONE) {
1456 tgt = next_extra_for_tile(ptile, cause, city_owner(mcity), nullptr);
1457 } else if (rmcause != ERM_NONE) {
1458 tgt = prev_extra_in_tile(ptile, rmcause, city_owner(mcity), nullptr);
1459 } else {
1460 tgt = nullptr;
1461 }
1462
1463 if (tgt != nullptr) {
1464 task.tgt = extra_index(tgt);
1465 } else {
1466 task.tgt = -1;
1467 }
1468 } else {
1469 task.tgt = -1;
1470 }
1471
1472 task.tile_id = ptile->index;
1474 });
1475
1476 con_menu->popup(mapToGlobal(point));
1477}
1478
1479/************************************************************************/
1483{
1484 QFont f = QApplication::font();
1485 QFont *small_font;
1486 QFontMetrics fm(f);
1492 QHeaderView *header;
1493 QLabel *lab2, *label, *ql, *some_label;
1494 QPushButton *qpush2;
1496 QSizePolicy size_expanding_policy(QSizePolicy::Expanding,
1497 QSizePolicy::Expanding);
1498 QSlider *slider;
1499 QStringList info_list, str_list;
1504 int list_size;
1505 int h = 2 * fm.height() + 2;
1506
1509 zoom = 1.0;
1510
1512 central_splitter->setOpaqueResize(false);
1514 central_left_splitter->setOpaqueResize(false);
1516 prod_unit_splitter->setOpaqueResize(false);
1517
1518 setMouseTracking(true);
1519 selected_row_p = -1;
1520 dlgcity = nullptr;
1521 lcity_name = new QPushButton(this);
1522 lcity_name->setToolTip(_("Click to change city name"));
1523
1525 single_page_layout->setContentsMargins(0, 0 ,0 ,0);
1526 size_expanding_policy.setHorizontalStretch(0);
1527 size_expanding_policy.setVerticalStretch(0);
1529 current_building = 0;
1530
1531 // Map view
1532 map_box = new QGroupBox(this);
1533
1534 // City information widget texts about surpluses and so on
1535 info_wdg = new QWidget(this);
1536
1537 // Fill info_wdg with labels
1539
1540 info_wdg->setFont(*small_font);
1541 info_grid_layout->setSpacing(0);
1542 info_grid_layout->setContentsMargins(0, 0, 0, 0);
1543
1544
1545 for (enum city_info info_field = city_info_begin();
1548
1549 ql = new QLabel(_(city_info_name(info_field)), info_wdg);
1550 ql->setFont(*small_font);
1551 ql->setProperty(fonts::notify_label, "true");
1552 info_grid_layout->addWidget(ql, info_field, 0);
1553 qlt[info_field] = new QLabel(info_wdg);
1554 qlt[info_field]->setFont(*small_font);
1555 qlt[info_field]->setProperty(fonts::notify_label, "true");
1556 info_grid_layout->addWidget(qlt[info_field], info_field, 1);
1557 info_grid_layout->setRowStretch(info_field, 0);
1558 }
1559
1560 info_wdg->setLayout(info_grid_layout);
1561
1562 // Buy button
1563 buy_button = new QPushButton();
1564 buy_button->setIcon(fc_icons::instance()->get_icon("help-donate"));
1565 connect(buy_button, &QAbstractButton::clicked, this, &city_dialog::buy);
1566
1567 connect(lcity_name, &QAbstractButton::clicked, this, &city_dialog::city_rename);
1569 citizen_pixmap = nullptr;
1570 view = new city_map(this);
1571
1572 zoom_vbox = new QVBoxLayout();
1573 zoom_in_button = new QPushButton();
1574 zoom_in_button->setIcon(fc_icons::instance()->get_icon("plus"));
1575 zoom_in_button->setIconSize(QSize(16, 16));
1576 zoom_in_button->setFixedSize(QSize(20, 20));
1577 zoom_in_button->setToolTip(_("Zoom in"));
1578 connect(zoom_in_button, &QAbstractButton::clicked, this, &city_dialog::zoom_in);
1579 zoom_out_button = new QPushButton();
1580 zoom_out_button->setIcon(fc_icons::instance()->get_icon("minus"));
1581 zoom_out_button->setIconSize(QSize(16, 16));
1582 zoom_out_button->setFixedSize(QSize(20, 20));
1583 zoom_out_button->setToolTip(_("Zoom out"));
1584 connect(zoom_out_button, &QAbstractButton::clicked, this, &city_dialog::zoom_out);
1585 zoom_vbox->addWidget(zoom_in_button);
1586 zoom_vbox->addWidget(zoom_out_button);
1587
1588 // City map group box
1591 hbox_layout->addStretch(100);
1592 hbox_layout->addWidget(view);
1593 hbox_layout->addStretch(100);
1594 hbox_layout->addLayout(zoom_vbox);
1595 vbox_layout->addLayout(hbox_layout);
1596 vbox_layout->addWidget(lcity_name);
1597 map_box->setLayout(vbox_layout);
1598 map_box->setTitle(_("City map"));
1599
1600 // Current/supported units/improvements widgets
1601 supp_units = new QLabel();
1602 curr_units = new QLabel();
1603 curr_impr = new QLabel();
1604 curr_units->setAlignment(Qt::AlignLeft);
1605 curr_impr->setAlignment(Qt::AlignLeft);
1606 supp_units->setAlignment(Qt::AlignLeft);
1607 supported_units = new unit_info(true);
1608 scroll = new QScrollArea;
1609 scroll->setWidgetResizable(true);
1610 scroll->setMaximumHeight(tileset_unit_with_upkeep_height(get_tileset()) + 6
1611 + scroll->horizontalScrollBar()->height());
1612 scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1613 scroll->setWidget(supported_units);
1614 current_units = new unit_info(false);
1615 scroll2 = new QScrollArea;
1616 scroll2->setWidgetResizable(true);
1617 scroll2->setMaximumHeight(tileset_unit_height(get_tileset()) + 6
1618 + scroll2->horizontalScrollBar()->height());
1619 scroll2->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1620 scroll2->setWidget(current_units);
1621 scroll_height = scroll2->horizontalScrollBar()->height();
1622 city_buildings = new impr_info(this);
1623 scroll3 = new QScrollArea;
1624 scroll3->setWidgetResizable(true);
1625 scroll3->setMaximumHeight(tileset_unit_height(tileset) + 6
1626 + scroll3->horizontalScrollBar()->height());
1627 scroll3->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1628 scroll3->setWidget(city_buildings);
1629 scroll->setProperty("city_scroll", true);
1630 scroll2->setProperty("city_scroll", true);
1631 scroll3->setProperty("city_scroll", true);
1632
1635 right_layout = new QVBoxLayout();
1637 units_layout = new QVBoxLayout();
1638 left_layout = new QVBoxLayout();
1639
1640 /* Checkboxes to show units/wonders/imrovements
1641 * on production list */
1644 show_buildings->setToolTip(_("Show buildings"));
1645 show_buildings->setChecked(true);
1646 label = new QLabel();
1647 label->setPixmap(*fc_icons::instance()->get_pixmap("building"));
1648 label->setToolTip(_("Show buildings"));
1649 prod_option_layout->addWidget(show_buildings, Qt::AlignLeft);
1650 prod_option_layout->addWidget(label, Qt::AlignLeft);
1651 prod_option_layout->addStretch(100);
1652 label = new QLabel();
1653 label->setPixmap(*fc_icons::instance()->get_pixmap("cunits"));
1654 label->setToolTip(_("Show units"));
1655 show_units = new QCheckBox;
1656 show_units->setToolTip(_("Show units"));
1657 show_units->setChecked(true);
1658 prod_option_layout->addWidget(show_units, Qt::AlignHCenter);
1659 prod_option_layout->addWidget(label, Qt::AlignHCenter);
1660 prod_option_layout->addStretch(100);
1661 label = new QLabel();
1662 label->setPixmap(*fc_icons::instance()->get_pixmap("wonder"));
1663 label->setToolTip(_("Show wonders"));
1664 show_wonders = new QCheckBox;
1665 show_wonders->setToolTip(_("Show wonders"));
1666 show_wonders->setChecked(true);
1667 prod_option_layout->addWidget(show_wonders);
1668 prod_option_layout->addWidget(label);
1669 prod_option_layout->addStretch(100);
1670 label = new QLabel();
1671 label->setPixmap(*fc_icons::instance()->get_pixmap("future"));
1672 label->setToolTip(_("Show future targets"));
1674 future_targets->setToolTip(_("Show future targets"));
1675 future_targets->setChecked(false);
1677 prod_option_layout->addWidget(label, Qt::AlignRight);
1678 prod_options = new QGroupBox(this);
1679 prod_options->setLayout(prod_option_layout);
1680 prod_options->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
1681
1682 // Prev/next and close buttons
1683 button = new QPushButton;
1684 button->setIcon(fc_icons::instance()->get_icon("city-close"));
1685 button->setIconSize(QSize(56, 56));
1686 button->setToolTip(_("Close city dialog"));
1687 connect(button, &QAbstractButton::clicked, this, &QWidget::hide);
1688
1689 next_city_but = new QPushButton();
1690 next_city_but->setIcon(fc_icons::instance()->get_icon("city-right"));
1691 next_city_but->setIconSize(QSize(56, 56));
1692 next_city_but->setToolTip(_("Show next city"));
1693 connect(next_city_but, &QAbstractButton::clicked, this, &city_dialog::next_city);
1694
1695 prev_city_but = new QPushButton();
1696 connect(prev_city_but, &QAbstractButton::clicked, this, &city_dialog::prev_city);
1697 prev_city_but->setIcon(fc_icons::instance()->get_icon("city-left"));
1698 prev_city_but->setIconSize(QSize(56, 56));
1699 prev_city_but->setToolTip(_("Show previous city"));
1700
1701 happiness_button = new QPushButton();
1702 happiness_button->setIcon(fc_icons::instance()->get_icon("city-switch"));
1703 happiness_button->setIconSize(QSize(56, 28));
1704 connect(happiness_button, &QAbstractButton::clicked, this, &city_dialog::show_happiness);
1705
1706 button->setFixedSize(64, 64);
1707 prev_city_but->setFixedSize(64, 64);
1708 next_city_but->setFixedSize(64, 64);
1709 happiness_button->setFixedSize(64, 32);
1711 vbox_layout->addWidget(prev_city_but);
1712 vbox_layout->addWidget(next_city_but);
1713 vbox_layout->addWidget(button);
1714 vbox_layout->addWidget(happiness_button, Qt::AlignHCenter);
1715
1716 counterss_button = new QPushButton();
1717 connect(counterss_button, &QAbstractButton::clicked, this, &city_dialog::show_counters);
1718 vbox_layout->addWidget(counterss_button, Qt::AlignHCenter);
1719
1720 update_tabs();
1722
1723 hbox_layout->addLayout(vbox_layout, Qt::AlignLeft);
1724 hbox_layout->addWidget(info_wdg, Qt::AlignLeft);
1725 hbox_layout->addWidget(map_box, Qt::AlignCenter);
1726
1727 // Layout with city view and buttons
1728 lefttop_layout->addWidget(citizens_label, Qt::AlignHCenter);
1729 lefttop_layout->addStretch(0);
1730 lefttop_layout->addLayout(hbox_layout);
1731 lefttop_layout->addStretch(50);
1732
1733 // Layout for units/buildings
1734 curr_unit_wdg = new QWidget();
1735 supp_unit_wdg = new QWidget();
1736 curr_impr_wdg = new QWidget();
1737 v_layout = new QVBoxLayout;
1738 v_layout->addWidget(curr_impr);
1739 v_layout->addWidget(scroll3);
1740 v_layout->setContentsMargins(0 , 0 , 0, 0);
1741 v_layout->setSpacing(0);
1742 curr_impr_wdg->setLayout(v_layout);
1743 v_layout = new QVBoxLayout;
1744 v_layout->addWidget(curr_units);
1745 v_layout->addWidget(scroll2);
1746 v_layout->setContentsMargins(0 , 0 , 0, 0);
1747 v_layout->setSpacing(0);
1748 curr_unit_wdg->setLayout(v_layout);
1749 v_layout = new QVBoxLayout;
1750 v_layout->addWidget(supp_units);
1751 v_layout->addWidget(scroll);
1752 v_layout->setContentsMargins(0 , 0 , 0, 0);
1753 v_layout->setSpacing(0);
1754 supp_unit_wdg->setLayout(v_layout);
1755
1756 units_layout->addWidget(curr_unit_wdg);
1757 units_layout->addWidget(supp_unit_wdg);
1758 units_layout->addWidget(curr_impr_wdg);
1759 units_layout->setSpacing(0);
1760 units_layout->setContentsMargins(0 , 0 , 0, 0);
1761
1762 vbox = new QVBoxLayout;
1764 qgbprod = new QGroupBox;
1765 group_box = new QGroupBox(_("Worklist Option"));
1767 work_next_but = new QPushButton(fc_icons::instance()->get_icon(
1768 "go-down"), "");
1769 work_prev_but = new QPushButton(fc_icons::instance()->get_icon(
1770 "go-up"), "");
1771 work_add_but = new QPushButton(fc_icons::instance()->get_icon(
1772 "list-add"), "");
1773 work_rem_but = new QPushButton(style()->standardIcon(
1774 QStyle::SP_DialogDiscardButton), "");
1775 work_but_layout->addWidget(work_add_but);
1776 work_but_layout->addWidget(work_next_but);
1777 work_but_layout->addWidget(work_prev_but);
1778 work_but_layout->addWidget(work_rem_but);
1780 production_combo_p->setToolTip(_("Click to change current production"));
1781 p_table_p = new QTableWidget;
1782
1783 r1 = new QRadioButton(_("Change"));
1784 r2 = new QRadioButton(_("Insert Before"));
1785 r3 = new QRadioButton(_("Insert After"));
1786 r4 = new QRadioButton(_("Add Last"));
1787 r4->setChecked(true);
1788 group_box->setLayout(vbox);
1789
1790
1791 p_table_p->setColumnCount(3);
1792 p_table_p->setProperty("showGrid", "false");
1793 p_table_p->setProperty("selectionBehavior", "SelectRows");
1794 p_table_p->setEditTriggers(QAbstractItemView::NoEditTriggers);
1795 p_table_p->verticalHeader()->setVisible(false);
1796 p_table_p->horizontalHeader()->setVisible(false);
1797 p_table_p->setSelectionMode(QAbstractItemView::SingleSelection);
1798 production_combo_p->setFixedHeight(h);
1799 p_table_p->setMinimumWidth(200);
1800 p_table_p->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow);
1801 p_table_p->setContextMenuPolicy(Qt::CustomContextMenu);
1802 p_table_p->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
1803 header = p_table_p->horizontalHeader();
1804 header->setStretchLastSection(true);
1805
1806 qgbprod->setTitle(_("Worklist"));
1807 vbox_layout->setSpacing(0);
1808 vbox_layout->addWidget(prod_options);
1809 vbox_layout->addWidget(buy_button);
1810 vbox_layout->addWidget(production_combo_p);
1811 vbox_layout->addLayout(work_but_layout);
1812 vbox_layout->addWidget(p_table_p);
1813 qgbprod->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
1814 qgbprod->setLayout(vbox_layout);
1815
1816 worklist_layout->setSpacing(0);
1817 worklist_layout->addWidget(qgbprod);
1818 connect(p_table_p,
1819 &QWidget::customContextMenuRequested, this,
1822 connect(work_add_but, &QAbstractButton::clicked, this, &city_dialog::show_targets_worklist);
1823 connect(work_prev_but, &QAbstractButton::clicked, this, &city_dialog::worklist_up);
1824 connect(work_next_but, &QAbstractButton::clicked, this, &city_dialog::worklist_down);
1825 connect(work_rem_but, &QAbstractButton::clicked, this, &city_dialog::worklist_del);
1826 connect(p_table_p,
1827 &QTableWidget::itemDoubleClicked,
1829 connect(p_table_p->selectionModel(),
1831 const QItemSelection &)),
1833 const QItemSelection &)));
1834 happiness_group = new QGroupBox(_("Happiness"));
1835 gridl = new QGridLayout;
1836
1837 nationality_table = new QTableWidget;
1838 nationality_table->setColumnCount(3);
1839 nationality_table->setProperty("showGrid", "false");
1840 nationality_table->setProperty("selectionBehavior", "SelectRows");
1841 nationality_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
1842 nationality_table->verticalHeader()->setVisible(false);
1843 nationality_table->horizontalHeader()->setStretchLastSection(true);
1844
1845 info_list.clear();
1846 info_list << _("Cities:") << _("Luxuries:") << _("Buildings:")
1847 << _("Nationality:") << _("Units:") << _("Wonders:");
1848
1849 for (int i = 0; i < info_list.count(); i++) {
1850 lab_table[i] = new city_label(1 + i, this);
1851 gridl->addWidget(lab_table[i], i, 1, 1, 1);
1852 lab2 = new QLabel(this);
1853 lab2->setFont(*small_font);
1854 lab2->setProperty(fonts::notify_label, "true");
1855 lab2->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
1856 lab2->setText(info_list.at(i));
1857 gridl->addWidget(lab2, i, 0, 1, 1);
1858 }
1859
1860 gridl->setSpacing(0);
1861 happiness_group->setLayout(gridl);
1862
1863
1867 happiness_layout->setStretch(0, 10);
1868 happiness_widget = new QWidget();
1870 qgbox = new QGroupBox(_("Presets:"));
1871 qsliderbox = new QGroupBox(_("Governor settings"));
1872 result_box = new QGroupBox(_("Results:"));
1873 hbox = new QHBoxLayout;
1874 gridl = new QGridLayout;
1876
1878 counterss_frame = new QFrame();
1880
1881 qpush2
1882 = new QPushButton(style()->standardIcon(QStyle::SP_DialogSaveButton),
1883 _("Save"));
1884 connect(qpush2, &QAbstractButton::pressed, this, &city_dialog::save_cma);
1885
1886 cma_info_text = new QLabel;
1887 cma_info_text->setFont(*small_font);
1888 cma_info_text->setAlignment(Qt::AlignCenter);
1889 cma_table = new QTableWidget;
1890 cma_table->setColumnCount(1);
1891 cma_table->setProperty("showGrid", "false");
1892 cma_table->setProperty("selectionBehavior", "SelectRows");
1893 cma_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
1894 cma_table->setSelectionMode(QAbstractItemView::SingleSelection);
1895 cma_table->setContextMenuPolicy(Qt::CustomContextMenu);
1896 cma_table->verticalHeader()->setVisible(false);
1897 cma_table->horizontalHeader()->setVisible(false);
1898 cma_table->horizontalHeader()->setSectionResizeMode(
1899 QHeaderView::Stretch);
1900
1901 connect(cma_table->selectionModel(),
1903 const QItemSelection &)),
1905 const QItemSelection &)));
1906 connect(cma_table,
1907 &QWidget::customContextMenuRequested, this,
1909 connect(cma_table, &QTableWidget::cellDoubleClicked, this,
1911 gridl->addWidget(cma_table, 0, 0, 1, 2);
1912 qgbox->setLayout(gridl);
1913 hbox->addWidget(cma_info_text);
1914 result_box->setLayout(hbox);
1915 str_list << _("Food") << _("Shield") << _("Trade") << _("Gold")
1916 << _("Luxury") << _("Science") << _("Celebrate")
1917 << _("Maximize growth");
1918 some_label = new QLabel(_("Minimal Surplus"));
1920 some_label->setAlignment(Qt::AlignRight);
1921 slider_grid->addWidget(some_label, 0, 0, 1, 3);
1922 some_label = new QLabel(_("Priority"));
1924 some_label->setAlignment(Qt::AlignCenter);
1925 slider_grid->addWidget(some_label, 0, 3, 1, 2);
1926
1927 list_size = str_list.count();
1928 for (int i = 0; i < list_size; i++) {
1929 some_label = new QLabel(str_list.at(i));
1930 slider_grid->addWidget(some_label, i + 1, 0, 1, 1);
1931 some_label = new QLabel("0");
1932 some_label->setMinimumWidth(25);
1933
1934 if (i < list_size - 2) {
1935 slider = new QSlider(Qt::Horizontal);
1936 slider->setPageStep(1);
1937 slider->setFocusPolicy(Qt::TabFocus);
1938 slider_tab[2 * i] = slider;
1939 slider->setRange(-20, 20);
1940 slider->setSingleStep(1);
1941 slider_grid->addWidget(some_label, i + 1, 1, 1, 1);
1942 slider_grid->addWidget(slider, i + 1, 2, 1, 1);
1943 slider->setProperty("FC", QVariant::fromValue((void *)some_label));
1944
1945 connect(slider, &QAbstractSlider::valueChanged, this, &city_dialog::cma_slider);
1946 } else if (i == list_size - 2) {
1948 slider_grid->addWidget(cma_celeb_checkbox, i + 1, 2 , 1 , 1);
1949#ifdef FC_QT6X_MODE
1950 connect(cma_celeb_checkbox,
1951 &QCheckBox::checkStateChanged, this, &city_dialog::cma_toggle_changed);
1952#else // FC_QT6X_MODE
1953 connect(cma_celeb_checkbox,
1954 &QCheckBox::stateChanged, this, &city_dialog::cma_toggle_changed_depr);
1955#endif // FC_QT6X_MODE
1956 } else {
1957 fc_assert(i == list_size - 1);
1958
1960 slider_grid->addWidget(cma_max_growth, i + 1, 2 , 1 , 1);
1961#ifdef FC_QT6X_MODE
1962 connect(cma_max_growth,
1963 &QCheckBox::checkStateChanged, this, &city_dialog::cma_toggle_changed);
1964#else // FC_QT6X_MODE
1965 connect(cma_max_growth,
1966 &QCheckBox::stateChanged, this, &city_dialog::cma_toggle_changed_depr);
1967#endif // FC_QT6X_MODE
1968 }
1969
1970 if (i <= list_size - 2) {
1971 some_label = new QLabel("0");
1972 some_label->setMinimumWidth(25);
1973 slider = new QSlider(Qt::Horizontal);
1974 slider->setFocusPolicy(Qt::TabFocus);
1975 slider->setRange(0, 25);
1976 slider_tab[2 * i + 1] = slider;
1977 slider->setProperty("FC", QVariant::fromValue((void *)some_label));
1978 slider_grid->addWidget(some_label, i + 1, 3, 1, 1);
1979 slider_grid->addWidget(slider, i + 1, 4, 1, 1);
1980 connect(slider, &QAbstractSlider::valueChanged, this, &city_dialog::cma_slider);
1981 }
1982 }
1983
1984 cma_enable_but = new QPushButton();
1985 cma_enable_but->setFocusPolicy(Qt::TabFocus);
1986 connect(cma_enable_but, &QAbstractButton::pressed, this, &city_dialog::cma_enable);
1987 slider_grid->addWidget(cma_enable_but, O_LAST + 4, 0, 1, 3);
1988 slider_grid->addWidget(qpush2, O_LAST + 4, 3, 1, 2);
1989
1990 qsliderbox->setLayout(slider_grid);
1991 cma_result = new QLabel;
1992 cma_result_pix = new QLabel;
1993
1994 hbox = new QHBoxLayout;
1995 QScrollArea *govA = new QScrollArea();
1996 hbox->addWidget(cma_result_pix);
1997 hbox->addWidget(cma_result);
1998 hbox->addStretch(10);
1999 govA->setWidget(qsliderbox);
2000 govA->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
2001 right_layout->addWidget(qgbox);
2002 right_layout->addLayout(hbox);
2003 right_layout->addWidget(govA);
2004
2005 split_widget1 = new QWidget;
2006 split_widget1->setLayout(worklist_layout);
2007 split_widget2 = new QWidget;
2008 split_widget2->setLayout(units_layout);
2011 prod_unit_splitter->setStretchFactor(0, 3);
2012 prod_unit_splitter->setStretchFactor(1, 97);
2013 prod_unit_splitter->setOrientation(Qt::Horizontal);
2015 top_widget = new QWidget;
2016 top_widget->setLayout(lefttop_layout);
2017 top_widget->setSizePolicy(QSizePolicy::Minimum,
2018 QSizePolicy::Minimum);
2019 scroll_info = new QScrollArea();
2020 scroll_info->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
2021 scroll_unit = new QScrollArea();
2022 scroll_info->setWidget(top_widget);
2023 scroll_info->setWidgetResizable(true);
2024 prod_happ_widget = new QWidget;
2025 prod_happ_widget->setLayout(leftbot_layout);
2026 prod_happ_widget->setSizePolicy(QSizePolicy::MinimumExpanding,
2027 QSizePolicy::MinimumExpanding);
2028 scroll_unit->setWidget(prod_happ_widget);
2029 scroll_unit->setWidgetResizable(true);
2032 central_left_splitter->setStretchFactor(0, 40);
2033 central_left_splitter->setStretchFactor(1, 60);
2034 central_left_splitter->setOrientation(Qt::Vertical);
2036
2037 split_widget1 = new QWidget(this);
2038 split_widget2 = new QWidget(this);
2039 split_widget1->setLayout(left_layout);
2040 split_widget2->setLayout(right_layout);
2041 central_splitter->addWidget(split_widget1);
2042 central_splitter->addWidget(split_widget2);
2043 central_splitter->setStretchFactor(0, 99);
2044 central_splitter->setStretchFactor(1, 1);
2045 central_splitter->setOrientation(Qt::Horizontal);
2047 setSizeGripEnabled(true);
2049
2050 installEventFilter(this);
2051
2052 ::city_dlg_created = true;
2053}
2054
2055/************************************************************************/
2059{
2060
2061 cid cprod;
2062 int i, pos;
2063 int item, targets_used;
2065 QString str;
2066 struct item items[MAX_NUM_PRODUCTION_TARGETS];
2067 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
2068 struct universal univ;
2069
2070 pos = 0;
2073 name_and_sort_items(targets, targets_used, items, false, dlgcity);
2074
2075 for (item = 0; item < targets_used; item++) {
2076 if (can_city_build_now(&(wld.map), dlgcity, &items[item].item)) {
2077 prod_list << cid_encode(items[item].item);
2078 }
2079 }
2080
2081 for (i = 0; i < prod_list.size(); i++) {
2082 if (prod_list.at(i) == cprod) {
2083 if (next) {
2084 pos = i + 1;
2085 } else {
2086 pos = i - 1;
2087 }
2088 }
2089 }
2090 if (pos == prod_list.size()) {
2091 pos = 0;
2092 }
2093 if (pos == - 1) {
2094 pos = prod_list.size() - 1;
2095 }
2096 univ = cid_decode(static_cast<cid>(prod_list.at(pos)));
2098}
2099
2100/************************************************************************/
2104{
2105 if (current_tab == happiness) {
2106 happiness_button->setToolTip(_("Show city production"));
2107 counterss_button->setToolTip(_("Show counters information"));
2108
2109 } else {
2110 happiness_button->setToolTip(_("Show happiness information"));
2111
2112 if (current_tab == counters) {
2113 counterss_button->setToolTip(_("Show city production"));
2114 }
2115 else {
2116 counterss_button->setToolTip(_("Show counters information"));
2117 }
2118 }
2119}
2120
2121/************************************************************************/
2125{
2127 setUpdatesEnabled(false);
2128
2129
2130 if (current_tab != happiness) {
2131 leftbot_layout->replaceWidget(active_tab,
2133 Qt::FindDirectChildrenOnly);
2134 active_tab->hide();
2135 happiness_widget->show();
2136 happiness_widget->updateGeometry();
2138 } else {
2139 /* We do not change prod_unit_splitter to current_tab,
2140 * because happiness is active tab and clicked -
2141 * switching to default */
2142 leftbot_layout->replaceWidget(happiness_widget,
2144 Qt::FindDirectChildrenOnly);
2145 prod_unit_splitter->show();
2146 prod_unit_splitter->updateGeometry();
2147 happiness_widget->hide();
2149 }
2150
2151 setUpdatesEnabled(true);
2152 update();
2153 update_tabs();
2154}
2155
2156/************************************************************************/
2160{
2162 setUpdatesEnabled(false);
2163
2164
2165 if (current_tab != counters) {
2166 leftbot_layout->replaceWidget(active_tab,
2168 Qt::FindDirectChildrenOnly);
2169 active_tab->hide();
2170 counterss_frame->show();
2171 counterss_frame->updateGeometry();
2173 } else {
2174 /* We do not change prod_unit_splitter to current_tab,
2175 * because counters is active tab and clicked -
2176 * switching to default */
2177 leftbot_layout->replaceWidget(counterss_frame,
2179 Qt::FindDirectChildrenOnly);
2180 prod_unit_splitter->show();
2181 prod_unit_splitter->updateGeometry();
2182 counterss_frame->hide();
2184 }
2185
2186 setUpdatesEnabled(true);
2187 update();
2188 update_tabs();
2189}
2190
2191/************************************************************************/
2195{
2196 struct player *pplayer = client_player();
2197
2198 if (pplayer == nullptr
2199 || city_owner(dlgcity) != pplayer) {
2200 prev_city_but->setDisabled(true);
2201 next_city_but->setDisabled(true);
2202 buy_button->setDisabled(true);
2203 cma_enable_but->setDisabled(true);
2204 production_combo_p->setDisabled(true);
2205 current_units->setDisabled(true);
2206 supported_units->setDisabled(true);
2207 view->setDisabled(true);
2208 } else {
2209 prev_city_but->setEnabled(true);
2210 next_city_but->setEnabled(true);
2211 buy_button->setEnabled(true);
2212 cma_enable_but->setEnabled(true);
2213 production_combo_p->setEnabled(true);
2214 current_units->setEnabled(true);
2215 supported_units->setEnabled(true);
2216 view->setEnabled(true);
2217 }
2218
2220 cma_enable_but->setEnabled(true);
2221 } else {
2222 cma_enable_but->setDisabled(true);
2223 }
2224
2226}
2227
2228/************************************************************************/
2232{
2233 struct player *pplayer = client_player();
2234
2235 work_next_but->setDisabled(true);
2236 work_prev_but->setDisabled(true);
2237 work_add_but->setDisabled(true);
2238 work_rem_but->setDisabled(true);
2239
2240 if (pplayer != nullptr
2241 && city_owner(dlgcity) == pplayer) {
2242 work_add_but->setEnabled(true);
2243
2244 if (selected_row_p >= 0 && selected_row_p < p_table_p->rowCount()) {
2245 work_rem_but->setEnabled(true);
2246 }
2247
2248 if (selected_row_p >= 0 && selected_row_p < p_table_p->rowCount() - 1) {
2249 work_next_but->setEnabled(true);
2250 }
2251
2252 if (selected_row_p > 0 && selected_row_p < p_table_p->rowCount()) {
2253 work_prev_but->setEnabled(true);
2254 }
2255 }
2256}
2257
2258/************************************************************************/
2262{
2263 if (citizen_pixmap) {
2264 citizen_pixmap->detach();
2265 delete citizen_pixmap;
2266 }
2267
2268 cma_table->clear();
2269 p_table_p->clear();
2270 nationality_table->clear();
2272 supported_units->clear_layout();
2273 removeEventFilter(this);
2274 ::city_dlg_created = false;
2275
2276 // Delete the one widget that currently does NOT have a parent
2277 if (current_tab == common) {
2278 delete happiness_widget;
2279 delete counterss_frame;
2280 }
2281 else if (current_tab == counters) {
2282 delete happiness_widget;
2283 delete prod_unit_splitter;
2284 }else {
2285 delete counterss_frame;
2286 delete prod_unit_splitter;
2287 }
2288}
2289
2290/************************************************************************/
2294{
2295 gui()->qt_settings.city_geometry = saveGeometry();
2296 gui()->qt_settings.city_splitter1 = prod_unit_splitter->saveState();
2297 gui()->qt_settings.city_splitter2 = central_left_splitter->saveState();
2298 gui()->qt_settings.city_splitter3 = central_splitter->saveState();
2299}
2300
2301/************************************************************************/
2305{
2306 if (!gui()->qt_settings.city_geometry.isNull()) {
2307 restoreGeometry(gui()->qt_settings.city_geometry);
2308 prod_unit_splitter->restoreState(gui()->qt_settings.city_splitter1);
2309 central_left_splitter->restoreState(gui()->qt_settings.city_splitter2);
2310 central_splitter->restoreState(gui()->qt_settings.city_splitter3);
2311 } else {
2312 QRect rect = QApplication::primaryScreen()->availableGeometry();
2313
2314 resize((rect.width() * 4) / 5, (rect.height() * 5) / 6);
2315 }
2316}
2317
2318/************************************************************************/
2322{
2323 gui()->qt_settings.city_geometry = saveGeometry();
2324 gui()->qt_settings.city_splitter1 = prod_unit_splitter->saveState();
2325 gui()->qt_settings.city_splitter2 = central_left_splitter->saveState();
2326 gui()->qt_settings.city_splitter3 = central_splitter->saveState();
2327}
2328
2329/************************************************************************/
2332bool city_dialog::eventFilter(QObject *obj, QEvent *event)
2333{
2334
2335 if (obj == this) {
2336 if (event->type() == QEvent::KeyPress) {
2337 }
2338
2339 if (event->type() == QEvent::ShortcutOverride) {
2340 QKeyEvent *key_event = static_cast<QKeyEvent *>(event);
2341 if (key_event->key() == Qt::Key_Right) {
2342 next_city();
2343 event->setAccepted(true);
2344 return true;
2345 }
2346 if (key_event->key() == Qt::Key_Left) {
2347 prev_city();
2348 event->setAccepted(true);
2349 return true;
2350 }
2351 if (key_event->key() == Qt::Key_Up) {
2352 change_production(true);
2353 event->setAccepted(true);
2354 return true;
2355 }
2356 if (key_event->key() == Qt::Key_Down) {
2357 change_production(false);
2358 event->setAccepted(true);
2359 return true;
2360 }
2361 }
2362 }
2363 return QObject::eventFilter(obj, event);
2364}
2365
2366/************************************************************************/
2370{
2372 const int city_id = dlgcity->id;
2373
2374 if (!can_client_issue_orders()) {
2375 return;
2376 }
2377
2378 ask = new hud_input_box(gui()->central_wdg);
2379 ask->set_text_title_definput(_("What should we rename the city to?"),
2380 _("Rename City"), city_name_get(dlgcity));
2381 ask->setAttribute(Qt::WA_DeleteOnClose);
2382 connect(ask, &hud_message_box::accepted, this, [=]() {
2383 struct city *pcity = game_city_by_number(city_id);
2385
2386 if (!pcity) {
2387 return;
2388 }
2389
2390 ask_bytes = ask->input_edit.text().toUtf8();
2391 ::city_rename(pcity, ask_bytes.data());
2392 });
2393 ask->show();
2394}
2395
2396/************************************************************************/
2400{
2401 zoom = zoom * 1.2;
2402 if (dlgcity) {
2403 view->set_pixmap(dlgcity, zoom);
2404 }
2406 left_layout->update();
2407}
2408
2409/************************************************************************/
2413{
2414 zoom = zoom / 1.2;
2415 if (dlgcity) {
2416 view->set_pixmap(dlgcity, zoom);
2417 }
2419 left_layout->update();
2420}
2421
2422/************************************************************************/
2426{
2427 hud_input_box *ask = new hud_input_box(gui()->central_wdg);
2428
2429 ask->set_text_title_definput(_("What should we name the preset?"),
2430 _("Name new preset"),
2431 _("new preset"));
2432 ask->setAttribute(Qt::WA_DeleteOnClose);
2433 connect(ask, &hud_message_box::accepted, this,
2435 struct cm_parameter param;
2436 QByteArray ask_bytes = ask->input_edit.text().toUtf8();
2437 QString text = ask_bytes.data();
2438 if (!text.isEmpty()) {
2439 param.allow_disorder = false;
2440 param.allow_specialists = true;
2441 param.require_happy = cma_celeb_checkbox->isChecked();
2442 param.max_growth = cma_max_growth->isChecked();
2443 param.happy_factor = slider_tab[2 * O_LAST + 1]->value();
2444
2445 for (int i = O_FOOD; i < O_LAST; i++) {
2446 param.minimal_surplus[i] = slider_tab[2 * i]->value();
2447 param.factor[i] = slider_tab[2 * i + 1]->value();
2448 }
2449
2450 ask_bytes = text.toUtf8();
2451 cmafec_preset_add(ask_bytes.data(), &param);
2453 }
2454 });
2455 ask->show();
2456}
2457
2458/************************************************************************/
2462{
2463 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2465
2466 return;
2467 }
2468
2469 cma_changed();
2471}
2472
2473/************************************************************************/
2477{
2478 struct cm_parameter param;
2479
2480 param.allow_disorder = false;
2481 param.allow_specialists = true;
2482 param.require_happy = cma_celeb_checkbox->isChecked();
2483 param.max_growth = cma_max_growth->isChecked();
2484 param.happy_factor = slider_tab[2 * O_LAST + 1]->value();
2485
2486 for (int i = O_FOOD; i < O_LAST; i++) {
2487 param.minimal_surplus[i] = slider_tab[2 * i]->value();
2488 param.factor[i] = slider_tab[2 * i + 1]->value();
2489 }
2490
2492}
2493
2494/************************************************************************/
2498{
2499 const struct cm_parameter *param;
2500
2501 if (!can_client_issue_orders()) {
2502 return;
2503 }
2505 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2507 }
2508
2511}
2512
2513/************************************************************************/
2517 const QItemSelection &ds)
2518{
2519 const struct cm_parameter *param;
2520 QModelIndex index;
2521 QModelIndexList indexes = sl.indexes();
2522
2523 if (indexes.isEmpty() || cma_table->signalsBlocked()) {
2524 return;
2525 }
2526
2527 index = indexes.at(0);
2528 int ind = index.row();
2529
2530 if (cma_table->currentRow() == -1 || cmafec_preset_num() == 0) {
2531 return;
2532 }
2533
2536
2537 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2540 }
2541}
2542
2543/************************************************************************/
2547{
2548 struct cm_parameter param;
2549 const struct cm_parameter *cparam;
2550 int output;
2551 QVariant qvar;
2552 QLabel *label;
2553
2554 if (!cma_is_city_under_agent(dlgcity, &param)) {
2555 if (cma_table->currentRow() == -1 || cmafec_preset_num() == 0) {
2556 return;
2557 }
2559 cm_copy_parameter(&param, cparam);
2560 }
2561
2562 for (output = O_FOOD; output < 2 * O_LAST; output++) {
2563 slider_tab[output]->blockSignals(true);
2564 }
2565
2566 for (output = O_FOOD; output < O_LAST; output++) {
2567 qvar = slider_tab[2 * output + 1]->property("FC");
2568 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2569 label->setText(QString::number(param.factor[output]));
2570 slider_tab[2 * output + 1]->setValue(param.factor[output]);
2571 qvar = slider_tab[2 * output]->property("FC");
2572 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2573 label->setText(QString::number(param.minimal_surplus[output]));
2574 slider_tab[2 * output]->setValue(param.minimal_surplus[output]);
2575 }
2576
2577 slider_tab[2 * O_LAST + 1]->blockSignals(true);
2578 qvar = slider_tab[2 * O_LAST + 1]->property("FC");
2579 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2580 label->setText(QString::number(param.happy_factor));
2581 slider_tab[2 * O_LAST + 1]->setValue(param.happy_factor);
2582 slider_tab[2 * O_LAST + 1]->blockSignals(false);
2583 cma_celeb_checkbox->blockSignals(true);
2584 cma_celeb_checkbox->setChecked(param.require_happy);
2585 cma_celeb_checkbox->blockSignals(false);
2586 cma_max_growth->blockSignals(true);
2587 cma_max_growth->setChecked(param.max_growth);
2588 cma_max_growth->blockSignals(false);
2589
2590 for (output = O_FOOD; output < 2 * O_LAST; output++) {
2591 slider_tab[output]->blockSignals(false);
2592 }
2593}
2594
2595/************************************************************************/
2599{
2600 QString s;
2602 struct cm_parameter param;
2603 QPixmap pix;
2604 int i;
2605
2606 cma_table->clear();
2607 cma_table->setRowCount(0);
2608
2609 for (i = 0; i < cmafec_preset_num(); i++) {
2610 item = new QTableWidgetItem;
2611 item->setText(cmafec_preset_get_descr(i));
2612 cma_table->insertRow(i);
2613 cma_table->setItem(i, 0, item);
2614 }
2615
2616 if (cmafec_preset_num() == 0) {
2617 cma_table->insertRow(0);
2618 item = new QTableWidgetItem;
2619 item->setText(_("No governor defined"));
2620 cma_table->setItem(0, 0, item);
2621 }
2622
2623 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2624 view->update();
2626 pix = style()->standardPixmap(QStyle::SP_DialogApplyButton);
2627 pix = pix.scaled(2 * pix.width(), 2 * pix.height(),
2628 Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
2629 cma_result_pix->setPixmap(pix);
2630 cma_result_pix->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
2631 // TRANS: %1 is custom string chosen by player
2632 cma_result->setText(QString(_("<h3>Governor Enabled<br>(%1)</h3>"))
2633 .arg(s.toHtmlEscaped()));
2634 cma_result->setAlignment(Qt::AlignCenter);
2635 } else {
2636 pix = style()->standardPixmap(QStyle::SP_DialogCancelButton);
2637 pix = pix.scaled(1.6 * pix.width(), 1.6 * pix.height(),
2638 Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
2639 cma_result_pix->setPixmap(pix);
2640 cma_result_pix->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
2641 cma_result->setText(QString(_("<h3>Governor Disabled</h3>")));
2642 cma_result->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
2643 }
2644
2645 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2648 cm_parameter *const >(&param));
2649 if (i >= 0 && i < cma_table->rowCount()) {
2650 cma_table->blockSignals(true);
2651 cma_table->setCurrentCell(i, 0);
2652 cma_table->blockSignals(false);
2653 }
2654
2655 cma_enable_but->setText(_("Disable"));
2656 } else {
2657 cma_enable_but->setText(_("Enable"));
2658 }
2660}
2661
2662/************************************************************************/
2666{
2667 int i;
2669
2670 i = cma_table->currentRow();
2671
2672 if (i == -1 || cmafec_preset_num() == 0) {
2673 return;
2674 }
2675
2677 ask->set_text_title(_("Remove this preset?"), cmafec_preset_get_descr(i));
2678 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
2679 ask->setDefaultButton(QMessageBox::Cancel);
2680 ask->setAttribute(Qt::WA_DeleteOnClose);
2681 connect(ask, &hud_message_box::accepted, this,
2685 });
2686 ask->show();
2687}
2688
2689/************************************************************************/
2692void city_dialog::cma_toggle_changed(Qt::CheckState state)
2693{
2694 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2695 cma_changed();
2697 }
2698}
2699
2700/************************************************************************/
2705{
2706 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2707 cma_changed();
2709 }
2710}
2711
2712/************************************************************************/
2716{
2717 QVariant qvar;
2718 QSlider *slider;
2719 QLabel *label;
2720
2722 qvar = slider->property("FC");
2723
2724 if (qvar.isNull() || !qvar.isValid()) {
2725 return;
2726 }
2727
2728 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2729 label->setText(QString::number(value));
2730
2731 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2732 cma_changed();
2734 }
2735}
2736
2737/************************************************************************/
2757
2758/************************************************************************/
2762{
2763 QMenu *cma_menu = new QMenu(this);
2765
2766 cma_menu->setAttribute(Qt::WA_DeleteOnClose);
2767 cma_del_item = cma_menu->addAction(_("Remove Governor"));
2768 connect(cma_menu, &QMenu::triggered, this,
2770 if (act == cma_del_item) {
2771 cma_remove();
2772 }
2773 });
2774
2775 cma_menu->popup(QCursor::pos());
2776}
2777
2778/************************************************************************/
2782{
2783 QAction *action;
2784 QAction *disband;
2789 QMap<QString, cid>::const_iterator map_iter;
2790 QMenu *change_menu;
2791 QMenu *insert_menu;
2792 QMenu *list_menu;
2793 QMenu *options_menu;
2794 int city_id = dlgcity->id;
2795
2796 if (!can_client_issue_orders()) {
2797 return;
2798 }
2799 list_menu = new QMenu(this);
2800 change_menu = list_menu->addMenu(_("Change worklist"));
2801 insert_menu = list_menu->addMenu(_("Insert worklist"));
2802 wl_clear = list_menu->addAction(_("Clear"));
2803 connect(wl_clear, &QAction::triggered, this, &city_dialog::clear_worklist);
2804 list.clear();
2805
2809
2810 if (list.count() == 0) {
2811 wl_empty = change_menu->addAction(_("(no worklists defined)"));
2812 insert_menu->addAction(wl_empty);
2813 }
2814
2815 map_iter = list.constBegin();
2816
2817 while (map_iter != list.constEnd()) {
2818 action = change_menu->addAction(map_iter.key());
2819 action->setData(map_iter.value());
2820
2821 action = insert_menu->addAction(map_iter.key());
2822 action->setData(map_iter.value());
2823
2824 map_iter++;
2825 }
2826
2827 wl_save = list_menu->addAction(_("Save worklist"));
2828 connect(wl_save, &QAction::triggered, this, &city_dialog::save_worklist);
2829 options_menu = list_menu->addMenu(_("Options"));
2830 disband = options_menu->addAction(_("Allow disbanding city"));
2831 disband->setCheckable(true);
2832 disband->setChecked(is_city_option_set(dlgcity, CITYO_DISBAND));
2833 connect(disband, &QAction::triggered, this,
2835
2836 connect(change_menu, &QMenu::triggered, this, [=](QAction *act) {
2837 QVariant id = act->data();
2838 struct city *pcity = game_city_by_number(city_id);
2839 const struct worklist *worklist;
2840
2841 if (!pcity) {
2842 return;
2843 }
2844
2845#ifndef FC_QT5_MODE
2846 fc_assert_ret(id.typeId() == QMetaType::Int);
2847#else // FC_QT5_MODE
2848 fc_assert_ret(id.type() == QVariant::Int);
2849#endif // FC_QT5_MODE
2850
2853 });
2854
2855 connect(insert_menu, &QMenu::triggered, this,
2857 QVariant id = act->data();
2858 struct city *pcity = game_city_by_number(city_id);
2859 const struct worklist *worklist;
2860
2861 if (!pcity) {
2862 return;
2863 }
2864
2865#ifndef FC_QT5_MODE
2866 fc_assert_ret(id.typeId() == QMetaType::Int);
2867#else // FC_QT5_MODE
2868 fc_assert_ret(id.type() == QVariant::Int);
2869#endif // FC_QT5_MODE
2870
2873 });
2874
2875 list_menu->popup(QCursor::pos());
2876}
2877
2878/************************************************************************/
2882{
2883 QString str;
2884 int value;
2885 struct player *pplayer = client_player();
2886
2887 buy_button->setDisabled(true);
2888
2889 if (!client_is_observer() && pplayer != nullptr) {
2890 value = dlgcity->client.buy_cost;
2891 str = QString(PL_("Buy (%1 gold)", "Buy (%1 gold)",
2892 value)).arg(QString::number(value));
2893
2894 if (pplayer->economic.gold >= value && value != 0) {
2895 buy_button->setEnabled(true);
2896 }
2897 } else {
2898 str = QString(_("Buy"));
2899 }
2900
2901 buy_button->setText(str);
2902}
2903
2904/************************************************************************/
2908{
2909 enum citizen_category categories[MAX_CITY_SIZE];
2910 int i, j, width, height;
2911 QPainter p;
2912 QPixmap *pix;
2914 int w = tileset_small_sprite_width(tileset) / gui()->map_scale;
2915 int h = tileset_small_sprite_height(tileset) / gui()->map_scale;
2916
2917 i = 1 + (num_citizens * 5 / 200);
2918 w = w / i;
2919 QRect source_rect(0, 0, w, h);
2920 QRect dest_rect(0, 0, w, h);
2921 width = w * num_citizens;
2922 height = h;
2923
2924 if (citizen_pixmap) {
2925 citizen_pixmap->detach();
2926 delete citizen_pixmap;
2927 }
2928
2930
2931 for (j = 0, i = 0; i < num_citizens; i++, j++) {
2932 dest_rect.moveTo(i * w, 0);
2933 pix = get_citizen_sprite(tileset, categories[j], j, dlgcity)->pm;
2934 p.begin(citizen_pixmap);
2935 p.drawPixmap(dest_rect, *pix, source_rect);
2936 p.end();
2937 }
2938
2940 citizens_label->setPixmap(*citizen_pixmap);
2941
2944
2945 for (int k = 0; k < FEELING_LAST - 1; k++) {
2948 static_cast<citizen_feeling>(k),
2949 categories);
2950
2951 for (j = 0, i = 0; i < num_citizens; i++, j++) {
2952 dest_rect.moveTo(i * w, 0);
2953 pix = get_citizen_sprite(tileset, categories[j], j, dlgcity)->pm;
2954 p.begin(citizen_pixmap);
2955 p.drawPixmap(dest_rect, *pix, source_rect);
2956 p.end();
2957 }
2958
2959 lab_table[k]->setPixmap(*citizen_pixmap);
2960
2961 switch (k) {
2962 case FEELING_BASE:
2963 lab_table[k]->setToolTip(text_happiness_cities(dlgcity));
2964 break;
2965
2966 case FEELING_LUXURY:
2967 lab_table[k]->setToolTip(text_happiness_luxuries(dlgcity));
2968 break;
2969
2970 case FEELING_EFFECT :
2972 break;
2973
2976 break;
2977
2978 case FEELING_MARTIAL:
2979 lab_table[k]->setToolTip(text_happiness_units(dlgcity));
2980 break;
2981
2982 default:
2983 break;
2984 }
2985 }
2986}
2987
2988/************************************************************************/
2992{
2993 setUpdatesEnabled(false);
2994 production_combo_p->blockSignals(true);
2995
2996 if (dlgcity) {
2997 view->set_pixmap(dlgcity, zoom);
2998 view->update();
2999 update_title();
3006 update_units();
3010 } else {
3012 }
3013
3014 production_combo_p->blockSignals(false);
3015 setUpdatesEnabled(true);
3017 update();
3018}
3019
3020/************************************************************************/
3024{
3025 QFont *small_font;
3026
3028
3029 qDeleteAll(counterss_frame->findChildren<QWidget*>("", Qt::FindDirectChildrenOnly));
3031 QString helptext;
3032 char buf[1024];
3033 QLabel *name, *value, *activated, *help;
3034
3035 name = new QLabel(name_translation_get(&pcount->name));
3036 fc_snprintf(buf, sizeof(buf), _("Current value is: %d"),
3038 value = new QLabel(buf);
3039 fc_snprintf(buf, sizeof(buf), _("Activated once value equal "
3040 "or higher than: %d"),
3041 pcount->checkpoint);
3042 activated = new QLabel(buf);
3043 if (pcount->helptext != nullptr) {
3044 strvec_iterate(pcount->helptext, text_) {
3045 helptext += text_;
3047 }
3048 help = new QLabel(helptext);
3049
3050 name->setFont(*small_font);
3051 value->setFont(*small_font);
3052 activated->setFont(*small_font);
3053 help->setFont(*small_font);
3054
3055 counterss_layout->addWidget(name);
3056 counterss_layout->addWidget(value);
3057 counterss_layout->addWidget(activated);
3058 counterss_layout->addWidget(help);
3060}
3061
3062/************************************************************************/
3066{
3067 QFont f = QApplication::font();
3068 QFontMetrics fm(f);
3069 QPixmap *pix = nullptr;
3071 QString str;
3074 char buf[8];
3076 int h;
3077 int i = 0;
3078 struct sprite *sprite;
3079
3080 h = fm.height() + 6;
3081 nationality_table->clear();
3082 nationality_table->setRowCount(0);
3083 info_list.clear();
3084 info_list << _("#") << _("Flag") << _("Nation");
3085 nationality_table->setHorizontalHeaderLabels(info_list);
3086
3087 citizens_iterate(dlgcity, pslot, nationality) {
3088 nationality_table->insertRow(i);
3089
3090 for (int j = 0; j < nationality_table->columnCount(); j++) {
3091 item = new QTableWidgetItem;
3092
3093 switch (j) {
3094 case 0:
3096
3097 if (nationality_i == 0) {
3098 str = "-";
3099 } else {
3100 fc_snprintf(buf, sizeof(buf), "%d", nationality_i);
3101 str = QString(buf);
3102 }
3103
3104 item->setText(str);
3105 break;
3106
3107 case 1:
3110 (player_slot_get_player(pslot)));
3111
3112 if (sprite != nullptr) {
3113 pix = sprite->pm;
3114 pix_scaled = pix->scaledToHeight(h);
3115 item->setData(Qt::DecorationRole, pix_scaled);
3116 } else {
3117 item->setText("FLAG MISSING");
3118 }
3119 break;
3120
3121 case 2:
3123 (player_slot_get_player(pslot)));
3124 break;
3125
3126 default:
3127 break;
3128 }
3129 nationality_table->setItem(i, j, item);
3130 }
3131 i++;
3133 nationality_table->horizontalHeader()->setStretchLastSection(false);
3134 nationality_table->resizeColumnsToContents();
3135 nationality_table->resizeRowsToContents();
3136 nationality_table->horizontalHeader()->setStretchLastSection(true);
3137}
3138
3139/************************************************************************/
3143{
3144 int illness = 0;
3145 char buffer[512];
3146 char buf_info[NUM_INFO_FIELDS][512];
3147 char buf_tooltip[NUM_INFO_FIELDS][512];
3148 int granaryturns;
3149 int spec;
3150
3151 for (int i = 0; i < NUM_INFO_FIELDS; i++) {
3152 buf_info[i][0] = '\0';
3153 buf_tooltip[i][0] = '\0';
3154 }
3155
3156 // Fill the buffers with the necessary info
3157 spec = city_specialists(dlgcity);
3159 "%3d (%4d)", dlgcity->size, spec);
3161 _("Population: %d, Specialists: %d"),
3162 dlgcity->size, spec);
3163 fc_snprintf(buf_info[INFO_FOOD], sizeof(buf_info[INFO_FOOD]), "%3d (%+4d)",
3166 "%3d (%+4d)", dlgcity->prod[O_SHIELD] + dlgcity->waste[O_SHIELD],
3168 fc_snprintf(buf_info[INFO_TRADE], sizeof(buf_info[INFO_TRADE]), "%3d (%+4d)",
3171 fc_snprintf(buf_info[INFO_GOLD], sizeof(buf_info[INFO_GOLD]), "%3d (%+4d)",
3178 "%4d/%-4d", dlgcity->food_stock,
3180
3182 sizeof(buf_tooltip[INFO_FOOD]));
3184 sizeof(buf_tooltip[INFO_SHIELD]));
3186 sizeof(buf_tooltip[INFO_TRADE]));
3188 sizeof(buf_tooltip[INFO_GOLD]));
3190 sizeof(buf_tooltip[INFO_SCIENCE]));
3192 sizeof(buf_tooltip[INFO_LUXURY]));
3194 sizeof(buf_tooltip[INFO_CULTURE]));
3196 sizeof(buf_tooltip[INFO_POLLUTION]));
3198 sizeof(buf_tooltip[INFO_ILLNESS]));
3199
3201
3202 if (granaryturns == 0) {
3203 // TRANS: city growth is blocked. Keep short.
3204 fc_snprintf(buf_info[INFO_GROWTH], sizeof(buf_info[INFO_GROWTH]), _("blocked"));
3205 } else if (granaryturns == FC_INFINITY) {
3206 // TRANS: city is not growing. Keep short.
3207 fc_snprintf(buf_info[INFO_GROWTH], sizeof(buf_info[INFO_GROWTH]), _("never"));
3208 } else {
3209 /* A negative value means we'll have famine in that many turns.
3210 But that's handled down below. */
3211 // TRANS: city growth turns. Keep short.
3213 PL_("%d turn", "%d turns", abs(granaryturns)),
3214 abs(granaryturns));
3215 }
3216
3218 "%4d", dlgcity->waste[O_TRADE]);
3225
3226 if (!game.info.illness_on) {
3228 " -.-");
3229 } else {
3230 illness = city_illness_calc(dlgcity, nullptr, nullptr, nullptr, nullptr);
3231 // Illness is in tenth of percent
3233 "%5.1f%%", (float) illness / 10.0);
3234 }
3235 if (dlgcity->steal) {
3237 PL_("%d time", "%d times", dlgcity->steal), dlgcity->steal);
3238 } else {
3240 _("Not stolen"));
3241 }
3242
3244 sizeof(buf_info[INFO_AIRLIFT]));
3246 sizeof(buf_tooltip[INFO_AIRLIFT]));
3247
3248 get_city_dialog_output_text(dlgcity, O_FOOD, buffer, sizeof(buffer));
3249
3250 for (int i = 0; i < NUM_INFO_FIELDS; i++) {
3251 qlt[i]->setText(QString(buf_info[i]));
3252
3253 if (buf_tooltip[i][0]) {
3254 qlt[i]->setToolTip("<pre>" + QString(buf_tooltip[i]).toHtmlEscaped()
3255 + "</pre>");
3256 }
3257 }
3258}
3259
3260/************************************************************************/
3264{
3267
3268 setContentsMargins(0, 0 ,0 ,0);
3270 dlgcity = qcity;
3271 production_combo_p->blockSignals(true);
3272 refresh();
3273 production_combo_p->blockSignals(false);
3274}
3275
3276/************************************************************************/
3280{
3281 struct worklist queue;
3282
3283 city_get_queue(dlgcity, &queue);
3284
3286 return;
3287 }
3288
3290 city_set_queue(dlgcity, &queue);
3291}
3292
3293/************************************************************************/
3297{
3298 unit_item *ui;
3299 struct unit_list *units;
3300 char buf[256];
3301 int n;
3302 int happy_cost;
3304 struct player *pplayer = client_player();
3305 const struct civ_map *nmap = &(wld.map);
3306
3307 supported_units->setUpdatesEnabled(false);
3308 supported_units->clear_layout();
3309
3310 if (pplayer != nullptr
3311 && city_owner(dlgcity) != pplayer) {
3313 } else {
3314 units = dlgcity->units_supported;
3315 }
3316
3317 unit_list_iterate(units, punit) {
3319 ui = new unit_item(this, punit, true, happy_cost);
3320 ui->init_pix();
3321 supported_units->add_item(ui);
3323 n = unit_list_size(units);
3324 fc_snprintf(buf, sizeof(buf), _("Supported units %d"), n);
3325 supp_units->setText(QString(buf));
3326 supported_units->update_units();
3327 supported_units->setUpdatesEnabled(true);
3328 current_units->setUpdatesEnabled(true);
3330
3331 if (pplayer != nullptr
3332 && city_owner(dlgcity) != pplayer) {
3334 } else {
3335 units = dlgcity->tile->units;
3336 }
3337
3338 unit_list_iterate(units, punit) {
3339 ui = new unit_item(this , punit, false);
3340 ui->init_pix();
3343
3344 n = unit_list_size(units);
3345 fc_snprintf(buf, sizeof(buf), _("Present units %d"), n);
3346 curr_units->setText(QString(buf));
3347
3349 current_units->setUpdatesEnabled(true);
3350}
3351
3352/************************************************************************/
3356 const QItemSelection &ds)
3357{
3358 QModelIndex index;
3359 QModelIndexList indexes = sl.indexes();
3360
3361 if (indexes.isEmpty()) {
3362 return;
3363 }
3364
3365 index = indexes.at(0);
3366 selected_row_p = index.row();
3368}
3369
3370/************************************************************************/
3374{
3375 int size, i;
3376 struct city *other_pcity = nullptr;
3377 struct player *pplayer = client_player();
3378
3379 if (pplayer == nullptr) {
3380 return;
3381 }
3382
3383 size = city_list_size(pplayer->cities);
3384
3385 if (size <= 1) {
3386 return;
3387 }
3388
3389 for (i = 0; i < size; i++) {
3390 if (dlgcity == city_list_get(pplayer->cities, i)) {
3391 break;
3392 }
3393 }
3394
3395 if (i >= size - 1) {
3396 // Current city last in the list (size - 1) or disappeared (size)
3397 other_pcity = city_list_get(pplayer->cities, 0);
3398 } else {
3399 other_pcity = city_list_get(pplayer->cities, i + 1);
3400 }
3401
3404}
3405
3406/************************************************************************/
3410{
3411 int size, i;
3412 struct city *other_pcity = nullptr;
3413 struct player *pplayer = client_player();
3414
3415 if (pplayer == nullptr) {
3416 return;
3417 }
3418
3419 size = city_list_size(pplayer->cities);
3420
3421 if (size <= 1) {
3422 return;
3423 }
3424
3425 for (i = 0; i < size; i++) {
3426 if (dlgcity == city_list_get(pplayer->cities, i)) {
3427 break;
3428 }
3429 }
3430
3431 if (i == 0 || i == size) {
3432 // Current city in the beginning of the list or disappeared
3433 other_pcity = city_list_get(pplayer->cities, size - 1);
3434 } else {
3435 other_pcity = city_list_get(pplayer->cities, i - 1);
3436 }
3437
3440}
3441
3442/************************************************************************/
3446{
3447 char buf[32];
3448 QString str;
3450
3452 production_combo_p->setRange(0, cost);
3454 if (dlgcity->shield_stock >= cost) {
3455 production_combo_p->setValue(cost);
3456 } else {
3458 }
3459 production_combo_p->setAlignment(Qt::AlignCenter);
3460 str = QString(buf);
3461 str = str.simplified();
3462
3463 production_combo_p->setFormat(QString("(%p%) %2\n%1")
3465 str));
3466
3467 production_combo_p->updateGeometry();
3468
3469}
3470
3471/************************************************************************/
3475{
3476 char buf[1024], buf2[1024];
3478 int value = dlgcity->client.buy_cost;
3480 int city_id = dlgcity->id;
3481
3482 if (!can_client_issue_orders()) {
3483 return;
3484 }
3485
3487 fc_snprintf(buf2, ARRAY_SIZE(buf2), PL_("Treasury contains %d gold.",
3488 "Treasury contains %d gold.",
3489 client_player()->economic.gold),
3490 client_player()->economic.gold);
3491 fc_snprintf(buf, ARRAY_SIZE(buf), PL_("Buy %s for %d gold?",
3492 "Buy %s for %d gold?", value),
3493 name, value);
3494 ask->set_text_title(buf, buf2);
3495 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
3496 ask->setDefaultButton(QMessageBox::Cancel);
3497 ask->setAttribute(Qt::WA_DeleteOnClose);
3498 connect(ask, &hud_message_box::accepted, this, [=]() {
3499 struct city *pcity = game_city_by_number(city_id);
3500
3501 if (!pcity) {
3502 return;
3503 }
3504
3506 });
3507 ask->show();
3508}
3509
3510/************************************************************************/
3514{
3515 QFont f = QApplication::font();
3516 QFontMetrics fm(f);
3517 QPixmap *pix = nullptr;
3521 struct sprite *sprite;
3522 int h, cost, item, targets_used, col, upkeep;
3523 struct item items[MAX_NUM_PRODUCTION_TARGETS];
3524 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
3525 struct worklist queue;
3526 impr_item *ui;
3527
3528 upkeep = 0;
3529 city_buildings->setUpdatesEnabled(false);
3531
3532 h = fm.height() + 6;
3534 name_and_sort_items(targets, targets_used, items, false, dlgcity);
3535
3536 for (item = 0; item < targets_used; item++) {
3537 struct universal target = items[item].item;
3538
3539 ui = new impr_item(this, target.value.building, dlgcity);
3540 ui->init_pix();
3542
3543 fc_assert_action(VUT_IMPROVEMENT == target.kind, continue);
3545 upkeep = upkeep + city_improvement_upkeep(dlgcity, target.value.building);
3546 if (sprite != nullptr) {
3547 pix = sprite->pm;
3548 pix_scaled = pix->scaledToHeight(h);
3549 }
3550 }
3551
3552 city_get_queue(dlgcity, &queue);
3553 p_table_p->setRowCount(worklist_length(&queue));
3554
3555 for (int i = 0; i < worklist_length(&queue); i++) {
3556 struct universal target = queue.entries[i];
3557
3558 tooltip = "";
3559
3560 if (VUT_UTYPE == target.kind) {
3562 cost = utype_build_shield_cost(dlgcity, nullptr, target.value.utype);
3563 tooltip = get_tooltip_unit(target.value.utype, true).trimmed();
3567 } else {
3571 dlgcity, true).trimmed();
3572
3574 cost = -1;
3575 } else {
3577 }
3578 }
3579
3580 for (col = 0; col < 3; col++) {
3581 qitem = new QTableWidgetItem();
3582 qitem->setToolTip(tooltip);
3583
3584 switch (col) {
3585 case 0:
3586 if (sprite) {
3587 pix = sprite->pm;
3588 pix_scaled = pix->scaledToHeight(h);
3589 qitem->setData(Qt::DecorationRole, pix_scaled);
3590 }
3591 break;
3592
3593 case 1:
3594 if (str.contains('[') && str.contains(']')) {
3595 int ii, ij;
3596
3597 ii = str.lastIndexOf('[');
3598 ij = str.lastIndexOf(']');
3599 if (ij > ii) {
3600 str = str.remove(ii, ij - ii + 1);
3601 }
3602 }
3603 qitem->setText(str);
3604 break;
3605
3606 case 2:
3607 qitem->setTextAlignment(Qt::AlignRight);
3608 qitem->setText(QString::number(cost));
3609 break;
3610 }
3611 p_table_p->setItem(i, col, qitem);
3612 }
3613 }
3614
3615 p_table_p->horizontalHeader()->setStretchLastSection(false);
3616 p_table_p->resizeColumnsToContents();
3617 p_table_p->resizeRowsToContents();
3618 p_table_p->horizontalHeader()->setStretchLastSection(true);
3619
3621 city_buildings->setUpdatesEnabled(true);
3622 city_buildings->setUpdatesEnabled(true);
3623
3624 curr_impr->setText(QString(_("Improvements - upkeep %1")).arg(upkeep));
3625}
3626
3627/************************************************************************/
3631{
3632 cid id;
3633 QVariant qvar;
3634
3636 struct universal univ;
3637
3638 id = qvar.toInt();
3639 univ = cid_production(id);
3641 }
3642}
3643
3644/************************************************************************/
3649{
3651 int when = 1;
3652
3653 pw = new production_widget(this, dlgcity, future_targets->isChecked(),
3654 when, selected_row_p, show_units->isChecked(),
3655 false, show_wonders->isChecked(),
3656 show_buildings->isChecked());
3657 pw->show();
3658}
3659
3660/************************************************************************/
3665{
3667 int when = 4;
3668
3669 pw = new production_widget(this, dlgcity, future_targets->isChecked(),
3670 when, selected_row_p, show_units->isChecked(),
3671 false, show_wonders->isChecked(),
3672 show_buildings->isChecked());
3673 pw->show();
3674}
3675
3676/************************************************************************/
3680{
3681 struct worklist empty;
3682
3683 if (!can_client_issue_orders()) {
3684 return;
3685 }
3686
3689}
3690
3691/************************************************************************/
3695{
3696 QModelIndex index;
3697 struct worklist queue;
3698 struct universal *target;
3699
3701 return;
3702 }
3703
3704 target = new universal;
3705 city_get_queue(dlgcity, &queue);
3706 worklist_peek_ith(&queue, target, selected_row_p);
3708 worklist_insert(&queue, target, selected_row_p - 1);
3709 city_set_queue(dlgcity, &queue);
3710 index = p_table_p->model()->index(selected_row_p - 1, 0);
3711 p_table_p->setCurrentIndex(index);
3712 delete target;
3713
3714}
3715
3716/************************************************************************/
3720{
3722
3723 if (selected_row_p < 0
3724 || selected_row_p >= p_table_p->rowCount()) {
3725 return;
3726 }
3727
3731}
3732
3733/************************************************************************/
3737{
3738 QModelIndex index;
3739 struct worklist queue;
3740 struct universal *target;
3741
3743 return;
3744 }
3745
3746 target = new universal;
3747 city_get_queue(dlgcity, &queue);
3748 worklist_peek_ith(&queue, target, selected_row_p);
3750 worklist_insert(&queue, target, selected_row_p + 1);
3751 city_set_queue(dlgcity, &queue);
3752 index = p_table_p->model()->index(selected_row_p + 1, 0);
3753 p_table_p->setCurrentIndex(index);
3754 delete target;
3755}
3756
3757/************************************************************************/
3761{
3762 hud_input_box *ask = new hud_input_box(gui()->central_wdg);
3763 int city_id = dlgcity->id;
3764
3765 ask->set_text_title_definput(_("What should we name new worklist?"),
3766 _("Save current worklist"),
3767 _("New worklist"));
3768 ask->setAttribute(Qt::WA_DeleteOnClose);
3769 connect(ask, &hud_message_box::accepted, [=]() {
3770 struct global_worklist *gw;
3771 struct worklist queue;
3773 QString text;
3774 struct city *pcity = game_city_by_number(city_id);
3775
3776 ask_bytes = ask->input_edit.text().toUtf8();
3777 text = ask_bytes.data();
3778 if (!text.isEmpty()) {
3779 ask_bytes = text.toUtf8();
3781 city_get_queue(pcity, &queue);
3782 global_worklist_set(gw, &queue);
3783 }
3784 });
3785 ask->show();
3786}
3787
3788/************************************************************************/
3792{
3793 QString buf;
3794
3795 // Defeat keyboard shortcut mnemonics
3797 .replace("&", "&&"));
3798
3799 if (city_unhappy(dlgcity)) {
3800 // TRANS: city dialog title
3801 buf = QString(_("%1 - %2 citizens - DISORDER")).arg(city_name_get(dlgcity),
3803 } else if (city_celebrating(dlgcity)) {
3804 // TRANS: city dialog title
3805 buf = QString(_("%1 - %2 citizens - celebrating")).arg(city_name_get(dlgcity),
3807 } else if (city_happy(dlgcity)) {
3808 // TRANS: city dialog title
3809 buf = QString(_("%1 - %2 citizens - happy")).arg(city_name_get(dlgcity),
3811 } else {
3812 // TRANS: city dialog title
3813 buf = QString(_("%1 - %2 citizens")).arg(city_name_get(dlgcity),
3815 }
3816
3818}
3819
3820/************************************************************************/
3825{
3826 if (!::city_dlg_created) {
3827 ::city_dlg = new city_dialog(gui()->mapview_wdg);
3828 }
3829
3831 city_dlg->show();
3832 city_dlg->activateWindow();
3833 city_dlg->raise();
3834}
3835
3836/************************************************************************/
3840{
3841 if (!::city_dlg_created) {
3842 return;
3843 }
3844
3845 city_dlg->close();
3846 ::city_dlg_created = false;
3847}
3848
3849/************************************************************************/
3853{
3854 if (!::city_dlg_created) {
3855 return;
3856 }
3857
3859}
3860
3861/************************************************************************/
3868
3869/************************************************************************/
3873{
3874 if (!::city_dlg_created) {
3875 return;
3876 }
3877
3879 city_dlg->refresh();
3880 }
3881}
3882
3883/************************************************************************/
3887{
3889 QFont *f;
3890
3891 if (!::city_dlg_created) {
3892 return;
3893 }
3894
3895 l = city_dlg->findChildren<QLabel *>();
3896
3898
3899 for (int i = 0; i < l.size(); ++i) {
3900 if (l.at(i)->property(fonts::notify_label).isValid()) {
3901 l.at(i)->setFont(*f);
3902 }
3903 }
3904}
3905
3906/************************************************************************/
3923
3924/************************************************************************/
3928{
3929 if (!::city_dlg_created) {
3930 return false;
3931 }
3932
3933 if (city_dlg->dlgcity == pcity && city_dlg->isVisible()) {
3934 return true;
3935 }
3936
3937 return false;
3938}
3939
3940/************************************************************************/
3943bool fc_tooltip::eventFilter(QObject *obj, QEvent *ev)
3944{
3947 QRect rect;
3948
3949 if (ev->type() == QEvent::ToolTip) {
3951
3952 if (!view) {
3953 return false;
3954 }
3955
3956 help_event = static_cast<QHelpEvent *>(ev);
3957 QPoint pos = help_event->pos();
3958 QModelIndex index = view->indexAt(pos);
3959 QPoint hpos;
3960
3961 if (!index.isValid()) {
3962 return false;
3963 }
3964
3965 item_tooltip = view->model()->data(index, Qt::ToolTipRole).toString();
3966 rect = view->visualRect(index);
3967
3968 hpos = help_event->globalPos();
3969
3970 rect.setX(rect.x() + hpos.x());
3971 rect.setY(rect.y() + hpos.y());
3972
3973 if (!item_tooltip.isEmpty()) {
3974 QToolTip::showText(help_event->globalPos(), item_tooltip, view, rect);
3975 } else {
3976 QToolTip::hideText();
3977 }
3978
3979 return true;
3980 }
3981
3982 return false;
3983}
3984
3985/************************************************************************/
3989{
3990 return QString("<b>" + text + "</b>");
3991}
3992
3993/************************************************************************/
3998 bool ext)
3999{
4001 QString upkeep;
4002 QString s1, s2, str;
4003 const char *req = skip_intl_qualifier_prefix(_("?tech:None"));
4004 struct player *pplayer = client_player();
4005
4006 if (pcity != nullptr) {
4007 upkeep = QString::number(city_improvement_upkeep(pcity, building));
4008 } else {
4009 upkeep = QString::number(building->upkeep);
4010 }
4012 if (pobs->source.kind == VUT_ADVANCE) {
4013 req = advance_name_translation(pobs->source.value.advance);
4014 break;
4015 }
4017 s2 = QString(req);
4018 str = _("Obsolete by:");
4019 str = str + " " + s2;
4020 def_str = "<p style='white-space:pre'><b>"
4021 + QString(improvement_name_translation(building)).toHtmlEscaped()
4022 + "</b>\n";
4023 if (pcity != nullptr) {
4024 def_str += QString(_("Cost: %1, Upkeep: %2\n"))
4025 .arg(impr_build_shield_cost(pcity, building))
4026 .arg(upkeep).toHtmlEscaped();
4027 } else {
4029 nullptr, building);
4030
4031 def_str += QString(_("Cost Estimate: %1, Upkeep: %2\n"))
4032 .arg(cost_est)
4033 .arg(upkeep).toHtmlEscaped();
4034 }
4035 if (s1.compare(s2) != 0) {
4036 def_str = def_str + str.toHtmlEscaped() + "\n";
4037 }
4038 def_str = def_str + "\n";
4039 if (ext) {
4040 char buffer[8192];
4041
4042 str = helptext_building(buffer, sizeof(buffer), pplayer,
4043 nullptr, building);
4044 str = cut_helptext(str);
4045 str = split_text(str, true);
4046 str = str.trimmed();
4047 def_str = def_str + str.toHtmlEscaped();
4048 }
4049 return def_str;
4050}
4051
4052/************************************************************************/
4056QString get_tooltip_unit(const struct unit_type *utype, bool ext)
4057{
4060 QString str;
4061 const struct unit_type *obsolete;
4062 struct advance *tech;
4063
4064 def_str = "<b>"
4065 + QString(utype_name_translation(utype)).toHtmlEscaped()
4066 + "</b>\n";
4067 obsolete = utype->obsoleted_by;
4068 if (obsolete) {
4069 // FIXME: Don't give the impression that primary tech is (always) the only one.
4071 obsolete_str = QString("</td></tr><tr><td colspan=\"3\">");
4072 if (tech && tech != advance_by_number(A_NONE)) {
4073 /* TRANS: this and nearby literal strings are interpreted
4074 * as (Qt) HTML */
4075 obsolete_str = obsolete_str + QString(_("Obsoleted by %1 (%2)."))
4077 .arg(advance_name_translation(tech)).toHtmlEscaped();
4078 } else {
4079 obsolete_str = obsolete_str + QString(_("Obsoleted by %1."))
4080 .arg(utype_name_translation(obsolete)).toHtmlEscaped();
4081 }
4082 }
4083 def_str += "<table width=\"100\%\"><tr><td>"
4084 + bold(QString(_("Attack:"))) + " "
4085 + QString::number(utype->attack_strength).toHtmlEscaped()
4086 + QString("</td><td>") + bold(QString(_("Defense:"))) + " "
4087 + QString::number(utype->defense_strength).toHtmlEscaped()
4088 + QString("</td><td>") + bold(QString(_("Move:"))) + " "
4089 + QString(move_points_text(utype->move_rate, TRUE)).toHtmlEscaped()
4090 + QString("</td></tr><tr><td>")
4091 + bold(QString(_("Cost:"))) + " "
4092 + QString::number(utype_build_shield_cost_base(utype))
4093 .toHtmlEscaped()
4094 + QString("</td><td colspan=\"2\">")
4095 + bold(QString(_("Basic Upkeep:")))
4096 + " " + QString(helptext_unit_upkeep_str(utype)).toHtmlEscaped()
4097 + QString("</td></tr><tr><td>")
4098 + bold(QString(_("Hitpoints:"))) + " "
4099 + QString::number(utype->hp).toHtmlEscaped()
4100 + QString("</td><td>") + bold(QString(_("Firepower:"))) + " "
4101 + QString::number(utype->firepower).toHtmlEscaped()
4102 + QString("</td><td>") + bold(QString(_("Vision:"))) + " "
4103 + QString::number((int) sqrt((double) utype->vision_radius_sq))
4104 .toHtmlEscaped()
4105 + obsolete_str
4106 + QString("</td></tr></table><p style='white-space:pre'>");
4107 if (ext) {
4108 char buffer[8192];
4109 char buf2[1];
4110
4111 buf2[0] = '\0';
4112 str = helptext_unit(buffer, sizeof(buffer), client_player(),
4113 buf2, utype, TRUE);
4114 str = cut_helptext(str);
4115 str = split_text(str, true);
4116 str = str.trimmed().toHtmlEscaped();
4117 def_str = def_str + str;
4118 }
4119
4120 return def_str;
4121};
4122
4123/************************************************************************/
4127{
4130 char buffer[8192];
4131 char buf2[1];
4132 struct universal *target;
4133 struct player *pplayer = client_player();
4134
4135 buf2[0] = '\0';
4136 target = reinterpret_cast<universal *>(qvar.value<void *>());
4137
4138 if (target == nullptr) {
4139 } else if (VUT_UTYPE == target->kind) {
4141 str = helptext_unit(buffer, sizeof(buffer), pplayer,
4142 buf2, target->value.utype, TRUE);
4143 } else {
4144 if (!is_convert_improvement(target->value.building)) {
4146 }
4147
4148 str = helptext_building(buffer, sizeof(buffer), pplayer,
4149 nullptr, target->value.building);
4150 }
4151
4152 // Remove all lines from help which has '*' in first 3 chars
4154 ret_str = split_text(ret_str, true);
4155 ret_str = ret_str.trimmed();
4156 ret_str = def_str + ret_str.toHtmlEscaped();
4157
4158 return ret_str;
4159}
4160
4161/************************************************************************/
4165 QObject *parent,
4166 struct city *city)
4167 : QItemDelegate(parent)
4168{
4169 pd = sh;
4170 item_height = sh.y();
4171 pcity = city;
4172}
4173
4174/************************************************************************/
4179 const QModelIndex &index) const
4180{
4181 struct universal *target;
4182 QString name;
4183 QVariant qvar;
4184 QPixmap *pix;
4186 QRect rect1;
4187 QRect rect2;
4188 struct sprite *sprite;
4189 bool useless = false;
4190 bool is_convert = false;
4191 bool is_neutral = false;
4192 bool is_sea = false;
4193 bool is_flying = false;
4194 bool is_unit = true;
4195 QPixmap pix_dec(option.rect.width(), option.rect.height());
4197 color col;
4198 QIcon icon = current_app()->style()->standardIcon(QStyle::SP_DialogCancelButton);
4199 bool free_sprite = false;
4200 struct unit_class *pclass;
4201
4202 if (!option.rect.isValid()) {
4203 return;
4204 }
4205
4206 qvar = index.data();
4207
4208 if (!qvar.isValid()) {
4209 return;
4210 }
4211
4212 target = reinterpret_cast<universal *>(qvar.value<void *>());
4213
4214 if (target == nullptr) {
4215 col.qcolor = Qt::white;
4216 sprite = qtg_create_sprite(100, 100, &col);
4217 free_sprite = true;
4218 *sprite->pm = icon.pixmap(100, 100);
4219 name = _("Cancel");
4220 is_unit = false;
4221 } else if (VUT_UTYPE == target->kind) {
4224 pclass = utype_class(target->value.utype);
4228 is_sea = true;
4229 }
4230
4231 if ((utype_fuel(target->value.utype)
4236 /* FIXME: Assumed to be flying since only missiles can do suicide
4237 * attacks in classic-like rulesets. This isn't true for all
4238 * rulesets. Not a high priority to fix since all is_flying and
4239 * is_sea is used for is to set a color. */
4241 target->value.utype)) {
4242 if (is_sea) {
4243 is_sea = false;
4244 }
4245 is_flying = true;
4246 }
4247
4251 } else {
4252 is_unit = false;
4255 useless = is_improvement_redundant(pcity, target->value.building);
4256 is_convert = (target->value.building->genus == IG_CONVERT);
4257 }
4258
4259 if (sprite != nullptr) {
4260 pix = sprite->pm;
4261 pix_scaled = pix->scaledToHeight(item_height - 2, Qt::SmoothTransformation);
4262
4263 if (useless) {
4265 }
4266 }
4267
4268 opt = QItemDelegate::setOptions(index, option);
4269 painter->save();
4270 opt.displayAlignment = Qt::AlignLeft;
4271 opt.textElideMode = Qt::ElideMiddle;
4272 QItemDelegate::drawBackground(painter, opt, index);
4273 rect1 = option.rect;
4274 rect1.setWidth(pix_scaled.width() + 4);
4275 rect2 = option.rect;
4276 rect2.setLeft(option.rect.left() + rect1.width());
4277 rect2.setTop(rect2.top() + (rect2.height()
4278 - painter->fontMetrics().height()) / 2);
4279 QItemDelegate::drawDisplay(painter, opt, rect2, name);
4280
4281 if (is_unit) {
4282 if (is_sea) {
4283 pix_dec.fill(QColor(0, 0, 255, 80));
4284 } else if (is_flying) {
4285 pix_dec.fill(QColor(220, 0, 0, 80));
4286 } else if (is_neutral) {
4287 pix_dec.fill(QColor(0, 120, 0, 40));
4288 } else {
4289 pix_dec.fill(QColor(0, 0, 150, 40));
4290 }
4291
4292 QItemDelegate::drawDecoration(painter, option, option.rect, pix_dec);
4293 }
4294
4295 if (is_convert) {
4296 pix_dec.fill(QColor(255, 255, 0, 70));
4297 QItemDelegate::drawDecoration(painter, option, option.rect, pix_dec);
4298 }
4299
4300 if (!pix_scaled.isNull()) {
4301 QItemDelegate::drawDecoration(painter, opt, rect1, pix_scaled);
4302 }
4303
4304 drawFocus(painter, opt, option.rect);
4305
4306 painter->restore();
4307
4308 if (free_sprite) {
4310 }
4311}
4312
4313/************************************************************************/
4318 const QRect &rect) const
4319{
4320 QPixmap pix(option.rect.width(), option.rect.height());
4321
4322 if ((option.state & QStyle::State_MouseOver) == 0 || !rect.isValid()) {
4323 return;
4324 }
4325
4326 pix.fill(QColor(50, 50, 50, 50));
4327 QItemDelegate::drawDecoration(painter, option, option.rect, pix);
4328}
4329
4330/************************************************************************/
4334 const QModelIndex &index) const
4335{
4336 QSize s;
4337
4338 s.setWidth(pd.x());
4339 s.setHeight(pd.y());
4340 return s;
4341}
4342
4343/************************************************************************/
4347 QObject *parent): QObject()
4348{
4350 target = ptarget;
4351}
4352
4353/************************************************************************/
4357{
4358 // Allocated as renegade in model
4359 if (target != nullptr) {
4360 delete target;
4361 }
4362}
4363
4364/************************************************************************/
4368{
4369 return QVariant::fromValue((void *)target);
4370}
4371
4372/************************************************************************/
4376{
4377 return false;
4378}
4379
4380/************************************************************************/
4384 bool su, bool sw, bool sb,
4385 QObject *parent)
4386 : QAbstractListModel(parent)
4387{
4388 show_units = su;
4389 show_wonders = sw;
4391 mcity = pcity;
4392 future_t = f;
4393 populate();
4394}
4395
4396/************************************************************************/
4404
4405/************************************************************************/
4409{
4410 if (!index.isValid()) {
4411 return QVariant();
4412 }
4413
4414 if (index.row() >= 0 && index.row() < rowCount() && index.column() >= 0
4415 && index.column() < columnCount()
4416 && (index.column() + index.row() * 3 < city_target_list.count())) {
4417 int r, c, t, new_index;
4418
4419 r = index.row();
4420 c = index.column();
4421 t = r * 3 + c;
4422 new_index = t / 3 + rowCount() * c;
4423 // Exception, shift whole column
4424 if ((c == 2) && city_target_list.count() % 3 == 1) {
4425 new_index = t / 3 + rowCount() * c - 1;
4426 }
4427 if (role == Qt::ToolTipRole) {
4429 }
4430
4431 return city_target_list[new_index]->data();
4432 }
4433
4434 return QVariant();
4435}
4436
4437/************************************************************************/
4441{
4443 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
4444 struct item items[MAX_NUM_PRODUCTION_TARGETS];
4445 struct universal *renegade;
4446 int item, targets_used;
4447 QString str;
4449 QFontMetrics fm(f);
4450
4451 sh.setY(fm.height() * 2);
4452 sh.setX(0);
4453
4455 city_target_list.clear();
4456
4458 future_t);
4459 name_and_sort_items(targets, targets_used, items, false, mcity);
4460
4461 for (item = 0; item < targets_used; item++) {
4462 if (future_t || can_city_build_now(&(wld.map), mcity, &items[item].item)) {
4463 renegade = new universal(items[item].item);
4464
4465 // Renegade deleted in production_item destructor
4466 if (VUT_UTYPE == renegade->kind) {
4467 str = utype_name_translation(renegade->value.utype);
4468 sh.setX(qMax(sh.x(), fm.horizontalAdvance(str)));
4469
4470 if (show_units) {
4471 pi = new production_item(renegade, this);
4473 } else {
4474 delete renegade;
4475 }
4476 } else {
4477 str = improvement_name_translation(renegade->value.building);
4478 sh.setX(qMax(sh.x(), fm.horizontalAdvance(str)));
4479
4480 if ((is_wonder(renegade->value.building) && show_wonders)
4481 || (is_improvement(renegade->value.building) && show_buildings)
4482 || (is_convert_improvement(renegade->value.building))
4483 || (is_special_improvement(renegade->value.building)
4484 && show_buildings)) {
4485 pi = new production_item(renegade, this);
4487 } else {
4488 delete renegade;
4489 }
4490 }
4491 }
4492 }
4493
4494 pi = new production_item(nullptr, this);
4496 sh.setX(2 * sh.y() + sh.x());
4497 sh.setX(qMin(sh.x(), 250));
4498}
4499
4500/************************************************************************/
4504 const QVariant &value, int role)
4505{
4506 if (!index.isValid() || role != Qt::DisplayRole || role != Qt::ToolTipRole)
4507 return false;
4508
4509 if (index.row() >= 0 && index.row() < rowCount() && index.column() >= 0
4510 && index.column() < columnCount()) {
4511 bool change = city_target_list[index.row()]->setData();
4512 return change;
4513 }
4514
4515 return false;
4516}
4517
4518/************************************************************************/
4527 bool future, int when, int curr,
4528 bool show_units, bool buy,
4529 bool show_wonders,
4530 bool show_buildings): QTableView()
4531{
4532 QPoint pos, sh;
4533 QRect rect = QApplication::primaryScreen()->availableGeometry();
4534 int desk_width = rect.width();
4535 int desk_height = rect.height();
4536 fc_tt = new fc_tooltip(this);
4537 setAttribute(Qt::WA_DeleteOnClose);
4538 setWindowFlags(Qt::Popup);
4539 verticalHeader()->setVisible(false);
4540 horizontalHeader()->setVisible(false);
4541 setProperty("showGrid", false);
4543 sh_units = show_units;
4544 pw_city = pcity;
4545 buy_it = buy;
4546 when_change = when;
4547 list_model = new city_production_model(pw_city, future, show_units,
4548 show_wonders, show_buildings, this);
4549 sh = list_model->sh;
4550 c_p_d = new city_production_delegate(sh, this, pw_city);
4553 viewport()->installEventFilter(fc_tt);
4554 installEventFilter(this);
4556 const QItemSelection &)),
4558 const QItemSelection &)));
4561 setFixedWidth(3 * sh.x() + 6);
4562 setFixedHeight(list_model->rowCount()*sh.y() + 6);
4563
4564 if (width() > desk_width) {
4566 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
4567 } else {
4568 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
4569 }
4570
4571 if (height() > desk_height) {
4573 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
4574 } else {
4575 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
4576 }
4577
4578 pos = QCursor::pos();
4579
4580 if (pos.x() + width() > desk_width) {
4581 pos.setX(desk_width - width());
4582 } else if (pos.x() - width() < 0) {
4583 pos.setX(0);
4584 }
4585
4586 if (pos.y() + height() > desk_height) {
4587 pos.setY(desk_height - height());
4588 } else if (pos.y() - height() < 0) {
4589 pos.setY(0);
4590 }
4591
4592 move(pos);
4593 setMouseTracking(true);
4594 setFocus();
4595}
4596
4597/************************************************************************/
4601{
4602 if (event->button() == Qt::RightButton) {
4603 close();
4604 return;
4605 }
4606
4607 QAbstractItemView::mousePressEvent(event);
4608}
4609
4610/************************************************************************/
4614{
4615 QRect pw_rect;
4616 QPoint br;
4617
4618 if (obj != this)
4619 return false;
4620
4621 if (ev->type() == QEvent::MouseButtonPress) {
4622 pw_rect.setTopLeft(pos());
4623 br.setX(pos().x() + width());
4624 br.setY(pos().y() + height());
4625 pw_rect.setBottomRight(br);
4626
4627 if (!pw_rect.contains(QCursor::pos())) {
4628 close();
4629 }
4630 }
4631
4632 return false;
4633}
4634
4635/************************************************************************/
4639 const QItemSelection &ds)
4640{
4641 QModelIndexList indexes = selectionModel()->selectedIndexes();
4642 QModelIndex index;
4643 QVariant qvar;
4644 struct worklist queue;
4645 struct universal *target;
4646
4647 if (indexes.isEmpty() || client_is_observer()) {
4648 return;
4649 }
4650 index = indexes.at(0);
4651 qvar = index.data(Qt::UserRole);
4652 if (!qvar.isValid()) {
4653 return;
4654 }
4655 target = reinterpret_cast<universal *>(qvar.value<void *>());
4656 if (target != nullptr) {
4657 city_get_queue(pw_city, &queue);
4658 switch (when_change) {
4659 case 0: // Change current target
4661 if (city_can_buy(pw_city) && buy_it) {
4663 }
4664 break;
4665
4666 case 1: // Change current (selected on list)
4669 } else {
4671 worklist_insert(&queue, target, curr_selection);
4672 city_set_queue(pw_city, &queue);
4673 }
4674 break;
4675
4676 case 2: // Insert before
4678 curr_selection = 0;
4679 }
4682 worklist_insert(&queue, target, curr_selection);
4683 city_set_queue(pw_city, &queue);
4684 break;
4685
4686 case 3: // Insert after
4688 city_queue_insert(pw_city, -1, target);
4689 break;
4690 }
4692 worklist_insert(&queue, target, curr_selection);
4693 city_set_queue(pw_city, &queue);
4694 break;
4695
4696 case 4: // Add last
4697 city_queue_insert(pw_city, -1, target);
4698 break;
4699
4700 default:
4701 break;
4702 }
4703 }
4704 close();
4705 destroy();
4706}
4707
4708/************************************************************************/
4712{
4713 delete c_p_d;
4714 delete list_model;
4715 viewport()->removeEventFilter(fc_tt);
4716 removeEventFilter(this);
4717}
const char * action_id_name_translation(action_id act_id)
Definition actions.c:1250
#define action_id_univs_not_blocking(act_id, act_uni, tgt_uni)
Definition actions.h:710
#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
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:3413
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:3342
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:566
citizen_category
Definition city.h:264
#define city_owner(_pcity_)
Definition city.h:560
#define MAX_CITY_SIZE
Definition city.h:103
citizen_feeling
Definition city.h:275
@ FEELING_EFFECT
Definition city.h:278
@ FEELING_LUXURY
Definition city.h:277
@ FEELING_FINAL
Definition city.h:281
@ FEELING_LAST
Definition city.h:282
@ FEELING_BASE
Definition city.h:276
@ FEELING_NATIONALITY
Definition city.h:279
@ FEELING_MARTIAL
Definition city.h:280
void qtg_popdown_city_dialog(struct city *pcity)
Definition citydlg.cpp:3852
void qtg_real_city_dialog_refresh(struct city *pcity)
Definition citydlg.cpp:3872
QString split_text(QString text, bool cut)
Definition optiondlg.cpp:62
void city_font_update()
Definition citydlg.cpp:3886
bool qtg_city_dialog_is_open(struct city *pcity)
Definition citydlg.cpp:3927
QString get_tooltip(QVariant qvar)
Definition citydlg.cpp:4126
void qtg_popdown_all_city_dialogs()
Definition citydlg.cpp:3864
static city_dialog * city_dlg
Definition citydlg.cpp:75
void qtg_refresh_unit_city_dialogs(struct unit *punit)
Definition citydlg.cpp:3911
static QString bold(QString text)
Definition citydlg.cpp:3988
void qtg_real_city_dialog_popup(struct city *pcity)
Definition citydlg.cpp:3824
QString get_tooltip_improvement(const impr_type *building, struct city *pcity, bool ext)
Definition citydlg.cpp:3997
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:4056
void destroy_city_dialog()
Definition citydlg.cpp:3839
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)
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:1195
struct city * pcity
Definition citydlg.h:427
city_label(int type, QWidget *parent=nullptr)
Definition citydlg.cpp:1163
void mousePressEvent(QMouseEvent *event)
Definition citydlg.cpp:1171
int wdth
Definition citydlg.h:288
int cutted_height
Definition citydlg.h:291
QSize sizeHint() const
Definition citydlg.cpp:1294
void paintEvent(QPaintEvent *event)
Definition citydlg.cpp:1234
void mousePressEvent(QMouseEvent *event)
Definition citydlg.cpp:1310
int height
Definition citydlg.h:289
void set_pixmap(struct city *pcity, float z)
Definition citydlg.cpp:1258
void context_menu(QPoint point)
Definition citydlg.cpp:1332
canvas * miniview
Definition citydlg.h:275
struct city * mcity
Definition citydlg.h:285
QSize minimumSizeHint() const
Definition citydlg.cpp:1302
float zoom
Definition citydlg.h:287
QPixmap zoomed_pixmap
Definition citydlg.h:276
city_map(QWidget *parent)
Definition citydlg.cpp:1203
int cutted_width
Definition citydlg.h:290
int radius
Definition citydlg.h:286
int delta_y
Definition citydlg.h:293
int delta_x
Definition citydlg.h:292
city_production_delegate(QPoint sh, QObject *parent, struct city *city)
Definition citydlg.cpp:4164
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition citydlg.cpp:4177
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition citydlg.cpp:4333
struct city * pcity
Definition citydlg.h:319
void drawFocus(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect) const
Definition citydlg.cpp:4316
int rowCount(const QModelIndex &index=QModelIndex()) const
Definition citydlg.h:357
QList< production_item * > city_target_list
Definition citydlg.h:373
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole)
Definition citydlg.cpp:4503
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition citydlg.h:361
city_production_model(struct city *pcity, bool f, bool su, bool sw, bool sb, QObject *parent=nullptr)
Definition citydlg.cpp:4383
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition citydlg.cpp:4408
struct city * mcity
Definition citydlg.h:374
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:3943
void update_buildings()
Definition citydlg.cpp:555
QHBoxLayout * layout
Definition citydlg.h:261
void add_item(impr_item *item)
Definition citydlg.cpp:503
void wheelEvent(QWheelEvent *event)
Definition citydlg.cpp:536
impr_info(QWidget *parent)
Definition citydlg.cpp:472
void clear_layout()
Definition citydlg.cpp:511
void init_layout()
Definition citydlg.cpp:482
QList< impr_item * > impr_list
Definition citydlg.h:262
void mouseDoubleClickEvent(QMouseEvent *event)
Definition citydlg.cpp:607
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:416
struct canvas * impr_pixmap
Definition citydlg.h:233
struct city * dlgcity
Definition citydlg.h:234
const struct impr_type * impr
Definition citydlg.h:232
void leaveEvent(QEvent *event)
Definition citydlg.cpp:446
void wheelEvent(QWheelEvent *event)
Definition citydlg.cpp:587
struct universal * target
Definition citydlg.h:343
QVariant data() const
Definition citydlg.cpp:4367
production_item(struct universal *ptarget, QObject *parent)
Definition citydlg.cpp:4346
bool eventFilter(QObject *obj, QEvent *ev)
Definition citydlg.cpp:4613
void prod_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:4638
void mousePressEvent(QMouseEvent *event)
Definition citydlg.cpp:4600
city_production_model * list_model
Definition citydlg.h:388
struct city * pw_city
Definition citydlg.h:405
fc_tooltip * fc_tt
Definition citydlg.h:410
city_production_delegate * c_p_d
Definition citydlg.h:389
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:4526
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:1077
void init_layout()
Definition citydlg.cpp:1065
unit_info(bool supp)
Definition citydlg.cpp:1038
void add_item(unit_item *item)
Definition citydlg.cpp:1057
QHBoxLayout * layout
Definition citydlg.h:209
void update_units()
Definition citydlg.cpp:1096
void clear_layout()
Definition citydlg.cpp:1137
QList< unit_item * > unit_list
Definition citydlg.h:210
bool supports
Definition citydlg.h:213
QAction * activate
Definition citydlg.h:147
QAction * disband_action
Definition citydlg.h:145
void enterEvent(QEnterEvent *event)
Definition citydlg.cpp:966
void contextMenuEvent(QContextMenuEvent *ev)
Definition citydlg.cpp:738
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:1015
int happy_cost
Definition citydlg.h:168
void change_homecity()
Definition citydlg.cpp:924
QAction * unload
Definition citydlg.h:152
QAction * upgrade
Definition citydlg.h:153
bool supported
Definition citydlg.h:169
void fortify_unit()
Definition citydlg.cpp:955
void sentry_unit()
Definition citydlg.cpp:1028
QAction * unload_trans
Definition citydlg.h:154
void load_unit()
Definition citydlg.cpp:888
void wheelEvent(QWheelEvent *event)
Definition citydlg.cpp:995
QAction * load
Definition citydlg.h:151
void activate_unit()
Definition citydlg.cpp:945
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:792
void unload_all()
Definition citydlg.cpp:904
void disband()
Definition citydlg.cpp:870
void upgrade_unit()
Definition citydlg.cpp:912
void init_pix()
Definition citydlg.cpp:722
void leaveEvent(QEvent *event)
Definition citydlg.cpp:987
unit_item(QWidget *parent, struct unit *punit, bool supp=false, int happy_cost=0)
Definition citydlg.cpp:651
void unload_unit()
Definition citydlg.cpp:896
void activate_and_close_dialog()
Definition citydlg.cpp:934
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:2174
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:4938
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:247
#define EC_NONE
Definition fc_types.h:821
@ TR_SUCCESS
Definition fc_types.h:954
#define ERM_NONE
Definition fc_types.h:844
@ O_SHIELD
Definition fc_types.h:101
@ O_FOOD
Definition fc_types.h:101
@ O_TRADE
Definition fc_types.h:101
@ O_SCIENCE
Definition fc_types.h:101
@ O_LUXURY
Definition fc_types.h:101
@ O_GOLD
Definition fc_types.h:101
@ O_LAST
Definition fc_types.h:101
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:739
struct civ_game game
Definition game.c:61
struct world wld
Definition game.c:62
struct city * game_city_by_number(int id)
Definition game.c:106
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
GType type
Definition repodlgs.c:1313
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:83
QString get_tooltip_improvement(const impr_type *building, struct city *pcity=nullptr, bool ext=false)
Definition citydlg.cpp:3997
QString get_tooltip(QVariant qvar)
Definition citydlg.cpp:4126
#define CAPTURE_DEFAULT_THIS
Definition gui_main.h:31
#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:1932
char * helptext_unit_upkeep_str(const struct unit_type *utype)
Definition helpdata.c:4997
char * helptext_building(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, const struct impr_type *pimprove)
Definition helpdata.c:1381
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
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:1016
static mpgui * gui
Definition mpgui_qt.cpp:52
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:444
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)
const char * text_happiness_cities(const struct city *pcity)
Definition text.c:1947
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
Definition player.c:1229
struct player * player_slot_get_player(const struct player_slot *pslot)
Definition player.c:437
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:3263
int current_building
Definition citydlg.h:513
void worklist_up()
Definition citydlg.cpp:3694
city_label * citizens_label
Definition citydlg.h:456
QPushButton * lcity_name
Definition citydlg.h:499
void show_happiness()
Definition citydlg.cpp:2124
void closeEvent(QCloseEvent *event)
Definition citydlg.cpp:2321
void show_counters()
Definition citydlg.cpp:2159
void update_nation_table()
Definition citydlg.cpp:3065
void hideEvent(QHideEvent *event)
Definition citydlg.cpp:2293
void cma_toggle_changed_depr(int state)
Definition citydlg.cpp:2704
QPushButton * work_next_but
Definition citydlg.h:487
void next_city()
Definition citydlg.cpp:3373
progress_bar * production_combo_p
Definition citydlg.h:471
QTableWidget * nationality_table
Definition citydlg.h:473
QRadioButton * r3
Definition citydlg.h:481
QTableWidget * cma_table
Definition citydlg.h:474
void showEvent(QShowEvent *event)
Definition citydlg.cpp:2304
QPushButton * happiness_button
Definition citydlg.h:491
void cma_double_clicked(int row, int column)
Definition citydlg.cpp:2497
void display_worklist_menu(const QPoint &p)
Definition citydlg.cpp:2781
void update_disabled()
Definition citydlg.cpp:2194
QLabel * supp_units
Definition citydlg.h:468
QPushButton * next_city_but
Definition citydlg.h:485
QLabel * qlt[NUM_INFO_FIELDS]
Definition citydlg.h:464
QPushButton * work_prev_but
Definition citydlg.h:488
QHBoxLayout * single_page_layout
Definition citydlg.h:445
void update_buy_button()
Definition citydlg.cpp:2881
int selected_row_p
Definition citydlg.h:500
QHBoxLayout * leftbot_layout
Definition citydlg.h:451
void update_building()
Definition citydlg.cpp:3445
QPushButton * zoom_in_button
Definition citydlg.h:493
void save_worklist()
Definition citydlg.cpp:3760
void worklist_del()
Definition citydlg.cpp:3719
QGridLayout * info_grid_layout
Definition citydlg.h:458
void clear_worklist()
Definition citydlg.cpp:3679
QPushButton * counterss_button
Definition citydlg.h:492
impr_info * city_buildings
Definition citydlg.h:498
QLabel * curr_impr
Definition citydlg.h:470
city_label * lab_table[6]
Definition citydlg.h:457
int scroll_height
Definition citydlg.h:509
QLabel * curr_units
Definition citydlg.h:469
unit_info * current_units
Definition citydlg.h:496
void zoom_out()
Definition citydlg.cpp:2412
void zoom_in()
Definition citydlg.cpp:2399
struct unit_node_vector supported_units
Definition citydlg.c:163
QPushButton * zoom_out_button
Definition citydlg.h:494
struct city * pcity
Definition citydlg.c:138
struct city_dialog::@148 happiness
void update_info_label()
Definition citydlg.cpp:3142
QPushButton * work_add_but
Definition citydlg.h:489
QSplitter * central_left_splitter
Definition citydlg.h:449
void disband_state_changed(bool allow_disband)
Definition citydlg.cpp:2740
void update_citizens()
Definition citydlg.cpp:2907
QRadioButton * r1
Definition citydlg.h:481
void cma_slider(int val)
Definition citydlg.cpp:2715
QCheckBox * cma_celeb_checkbox
Definition citydlg.h:475
QCheckBox * show_units
Definition citydlg.h:478
enum city_dialog::city_dialog_tab current_tab
void worklist_down()
Definition citydlg.cpp:3736
void update_title()
Definition citydlg.cpp:3791
QLabel * cma_info_text
Definition citydlg.h:465
void dbl_click_p(QTableWidgetItem *item)
Definition citydlg.cpp:3279
QPushButton * cma_enable_but
Definition citydlg.h:484
QLabel * cma_result
Definition citydlg.h:466
void cma_remove()
Definition citydlg.cpp:2665
QSlider * slider_tab[2 *O_LAST+2]
Definition citydlg.h:501
QPushButton * button
Definition citydlg.h:482
bool eventFilter(QObject *obj, QEvent *event)
Definition citydlg.cpp:2332
QSplitter * prod_unit_splitter
Definition citydlg.h:448
QVBoxLayout * left_layout
Definition citydlg.h:454
void prev_city()
Definition citydlg.cpp:3409
void city_rename()
Definition citydlg.cpp:2369
void refresh()
Definition citydlg.cpp:2991
void update_cma_tab()
Definition citydlg.cpp:2598
QPushButton * work_rem_but
Definition citydlg.h:490
float zoom
Definition citydlg.h:510
QSplitter * central_splitter
Definition citydlg.h:450
QWidget * prod_happ_widget
Definition citydlg.h:452
void show_targets()
Definition citydlg.cpp:3648
city_dialog(QWidget *parent=nullptr)
Definition citydlg.cpp:1482
void cma_toggle_changed(Qt::CheckState state)
Definition citydlg.cpp:2692
QVBoxLayout * counterss_layout
Definition citydlg.h:447
QFrame * counterss_frame
Definition citydlg.h:462
QWidget * top_widget
Definition citydlg.h:453
void update_tabs()
Definition citydlg.cpp:2103
QPushButton * prev_city_but
Definition citydlg.h:486
void cma_enable()
Definition citydlg.cpp:2461
QLabel * cma_result_pix
Definition citydlg.h:467
struct city * dlgcity
Definition citydlg.h:508
void update_counters_table()
Definition citydlg.cpp:3023
void update_sliders()
Definition citydlg.cpp:2546
void update_improvements()
Definition citydlg.cpp:3513
GtkWidget * worklist
Definition citydlg.c:176
QHBoxLayout * happiness_layout
Definition citydlg.h:446
QCheckBox * future_targets
Definition citydlg.h:477
void change_production(bool next)
Definition citydlg.cpp:2058
void cma_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:2516
QCheckBox * cma_max_growth
Definition citydlg.h:476
void item_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:3355
void show_targets_worklist()
Definition citydlg.cpp:3664
QCheckBox * show_wonders
Definition citydlg.h:480
void cma_context_menu(const QPoint &p)
Definition citydlg.cpp:2761
void cma_changed()
Definition citydlg.cpp:2476
QPushButton * buy_button
Definition citydlg.h:483
QRadioButton * r4
Definition citydlg.h:481
struct city_dialog::@149 counters
void update_units()
Definition citydlg.cpp:3296
QRadioButton * r2
Definition citydlg.h:481
QTableWidget * p_table_p
Definition citydlg.h:472
void save_cma()
Definition citydlg.cpp:2425
QPixmap * citizen_pixmap
Definition citydlg.h:495
void production_changed(int index)
Definition citydlg.cpp:3630
void update_prod_buttons()
Definition citydlg.cpp:2231
QWidget * happiness_widget
Definition citydlg.h:461
QGroupBox * happiness_group
Definition citydlg.h:460
QCheckBox * show_buildings
Definition citydlg.h:479
Definition city.h:317
struct worker_task_list * task_reqs
Definition city.h:409
int surplus[O_LAST]
Definition city.h:352
enum city_wl_cancel_behavior wlcb
Definition city.h:401
int food_stock
Definition city.h:364
int * counter_values
Definition city.h:405
int pollution
Definition city.h:366
int id
Definition city.h:323
int waste[O_LAST]
Definition city.h:353
struct unit_list * info_units_present
Definition city.h:471
struct unit_list * info_units_supported
Definition city.h:470
struct universal production
Definition city.h:393
int steal
Definition city.h:411
citizens size
Definition city.h:329
int culture
Definition city.h:462
int buy_cost
Definition city.h:463
struct city::@18::@21 client
struct tile * tile
Definition city.h:319
int shield_stock
Definition city.h:365
int prod[O_LAST]
Definition city.h:355
struct unit_list * units_supported
Definition city.h:403
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:608
universals_u value
Definition fc_types.h:607
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:1875
const char * text_happiness_wonders(const struct city *pcity)
Definition text.c:1917
const char * text_happiness_units(const struct city *pcity)
Definition text.c:2081
const char * text_happiness_luxuries(const struct city *pcity)
Definition text.c:2120
const char * text_happiness_buildings(const struct city *pcity)
Definition text.c:1847
const char * unit_description(struct unit *punit)
Definition text.c:522
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_terrain(_tile)
Definition tile.h:111
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:7007
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:7203
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:6946
struct sprite * get_unittype_sprite(const struct tileset *t, const struct unit_type *punittype, enum unit_activity activity, enum direction8 facing)
Definition tilespec.c:7029
struct sprite * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:6980
struct sprite * get_tech_sprite(const struct tileset *t, Tech_type_id tech)
Definition tilespec.c:6998
@ ICON_CITYDLG
Definition tilespec.h:316
const struct unit_type * utype
Definition fc_types.h:553
const struct impr_type * building
Definition fc_types.h:546
bool can_unit_change_homecity(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:505
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:383
#define unit_tile(_pu)
Definition unit.h:404
#define unit_owner(_pu)
Definition unit.h:403
bool units_are_occupied(const struct unit_list *punits)
Definition unitlist.c:273
bool units_can_unload(const struct civ_map *nmap, const struct unit_list *punits)
Definition unitlist.c:301
bool units_can_upgrade(const struct civ_map *nmap, const struct unit_list *punits)
Definition unitlist.c:335
bool units_can_load(const struct unit_list *punits)
Definition unitlist.c:287
#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:1474
bool utype_is_consumed_by_action_result(enum action_result result, const struct unit_type *utype)
Definition unittype.c:1235
struct advance * utype_primary_tech_req(const struct unit_type *ptype)
Definition unittype.c:2716
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:393
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1444
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1566
const char * utype_values_translation(const struct unit_type *punittype)
Definition unittype.c:1623
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:846
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