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 // Qt-6.7
1951 connect(cma_celeb_checkbox,
1952 &QCheckBox::checkStateChanged, this, &city_dialog::cma_toggle_changed);
1953#else // FC_QT6X_MODE
1954 connect(cma_celeb_checkbox,
1955 &QCheckBox::stateChanged, this, &city_dialog::cma_toggle_changed_depr);
1956#endif // FC_QT6X_MODE
1957 } else {
1958 fc_assert(i == list_size - 1);
1959
1961 slider_grid->addWidget(cma_max_growth, i + 1, 2 , 1 , 1);
1962#ifdef FC_QT6X_MODE
1963 // Qt-6.7
1964 connect(cma_max_growth,
1965 &QCheckBox::checkStateChanged, this, &city_dialog::cma_toggle_changed);
1966#else // FC_QT6X_MODE
1967 connect(cma_max_growth,
1968 &QCheckBox::stateChanged, this, &city_dialog::cma_toggle_changed_depr);
1969#endif // FC_QT6X_MODE
1970 }
1971
1972 if (i <= list_size - 2) {
1973 some_label = new QLabel("0");
1974 some_label->setMinimumWidth(25);
1975 slider = new QSlider(Qt::Horizontal);
1976 slider->setFocusPolicy(Qt::TabFocus);
1977 slider->setRange(0, 25);
1978 slider_tab[2 * i + 1] = slider;
1979 slider->setProperty("FC", QVariant::fromValue((void *)some_label));
1980 slider_grid->addWidget(some_label, i + 1, 3, 1, 1);
1981 slider_grid->addWidget(slider, i + 1, 4, 1, 1);
1982 connect(slider, &QAbstractSlider::valueChanged, this, &city_dialog::cma_slider);
1983 }
1984 }
1985
1986 cma_enable_but = new QPushButton();
1987 cma_enable_but->setFocusPolicy(Qt::TabFocus);
1988 connect(cma_enable_but, &QAbstractButton::pressed, this, &city_dialog::cma_enable);
1989 slider_grid->addWidget(cma_enable_but, O_LAST + 4, 0, 1, 3);
1990 slider_grid->addWidget(qpush2, O_LAST + 4, 3, 1, 2);
1991
1992 qsliderbox->setLayout(slider_grid);
1993 cma_result = new QLabel;
1994 cma_result_pix = new QLabel;
1995
1996 hbox = new QHBoxLayout;
1997 QScrollArea *govA = new QScrollArea();
1998 hbox->addWidget(cma_result_pix);
1999 hbox->addWidget(cma_result);
2000 hbox->addStretch(10);
2001 govA->setWidget(qsliderbox);
2002 govA->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
2003 right_layout->addWidget(qgbox);
2004 right_layout->addLayout(hbox);
2005 right_layout->addWidget(govA);
2006
2007 split_widget1 = new QWidget;
2008 split_widget1->setLayout(worklist_layout);
2009 split_widget2 = new QWidget;
2010 split_widget2->setLayout(units_layout);
2013 prod_unit_splitter->setStretchFactor(0, 3);
2014 prod_unit_splitter->setStretchFactor(1, 97);
2015 prod_unit_splitter->setOrientation(Qt::Horizontal);
2017 top_widget = new QWidget;
2018 top_widget->setLayout(lefttop_layout);
2019 top_widget->setSizePolicy(QSizePolicy::Minimum,
2020 QSizePolicy::Minimum);
2021 scroll_info = new QScrollArea();
2022 scroll_info->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
2023 scroll_unit = new QScrollArea();
2024 scroll_info->setWidget(top_widget);
2025 scroll_info->setWidgetResizable(true);
2026 prod_happ_widget = new QWidget;
2027 prod_happ_widget->setLayout(leftbot_layout);
2028 prod_happ_widget->setSizePolicy(QSizePolicy::MinimumExpanding,
2029 QSizePolicy::MinimumExpanding);
2030 scroll_unit->setWidget(prod_happ_widget);
2031 scroll_unit->setWidgetResizable(true);
2034 central_left_splitter->setStretchFactor(0, 40);
2035 central_left_splitter->setStretchFactor(1, 60);
2036 central_left_splitter->setOrientation(Qt::Vertical);
2038
2039 split_widget1 = new QWidget(this);
2040 split_widget2 = new QWidget(this);
2041 split_widget1->setLayout(left_layout);
2042 split_widget2->setLayout(right_layout);
2043 central_splitter->addWidget(split_widget1);
2044 central_splitter->addWidget(split_widget2);
2045 central_splitter->setStretchFactor(0, 99);
2046 central_splitter->setStretchFactor(1, 1);
2047 central_splitter->setOrientation(Qt::Horizontal);
2049 setSizeGripEnabled(true);
2051
2052 installEventFilter(this);
2053
2054 ::city_dlg_created = true;
2055
2057}
2058
2059/************************************************************************/
2063{
2064
2065 cid cprod;
2066 int i, pos;
2067 int item, targets_used;
2069 QString str;
2070 struct item items[MAX_NUM_PRODUCTION_TARGETS];
2071 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
2072 struct universal univ;
2073
2074 pos = 0;
2077 name_and_sort_items(targets, targets_used, items, false, dlgcity);
2078
2079 for (item = 0; item < targets_used; item++) {
2080 if (can_city_build_now(&(wld.map), dlgcity, &items[item].item)) {
2081 prod_list << cid_encode(items[item].item);
2082 }
2083 }
2084
2085 for (i = 0; i < prod_list.size(); i++) {
2086 if (prod_list.at(i) == cprod) {
2087 if (next) {
2088 pos = i + 1;
2089 } else {
2090 pos = i - 1;
2091 }
2092 }
2093 }
2094 if (pos == prod_list.size()) {
2095 pos = 0;
2096 }
2097 if (pos == - 1) {
2098 pos = prod_list.size() - 1;
2099 }
2100 univ = cid_decode(static_cast<cid>(prod_list.at(pos)));
2102}
2103
2104/************************************************************************/
2108{
2109 if (current_tab == happiness) {
2110 happiness_button->setToolTip(_("Show city production"));
2111 counterss_button->setToolTip(_("Show counters information"));
2112
2113 } else {
2114 happiness_button->setToolTip(_("Show happiness information"));
2115
2116 if (current_tab == counters) {
2117 counterss_button->setToolTip(_("Show city production"));
2118 }
2119 else {
2120 counterss_button->setToolTip(_("Show counters information"));
2121 }
2122 }
2123}
2124
2125/************************************************************************/
2129{
2131 setUpdatesEnabled(false);
2132
2133
2134 if (current_tab != happiness) {
2135 leftbot_layout->replaceWidget(active_tab,
2137 Qt::FindDirectChildrenOnly);
2138 active_tab->hide();
2139 happiness_widget->show();
2140 happiness_widget->updateGeometry();
2142 } else {
2143 /* We do not change prod_unit_splitter to current_tab,
2144 * because happiness is active tab and clicked -
2145 * switching to default */
2146 leftbot_layout->replaceWidget(happiness_widget,
2148 Qt::FindDirectChildrenOnly);
2149 prod_unit_splitter->show();
2150 prod_unit_splitter->updateGeometry();
2151 happiness_widget->hide();
2153 }
2154
2155 setUpdatesEnabled(true);
2156 update();
2157 update_tabs();
2158}
2159
2160/************************************************************************/
2164{
2166 setUpdatesEnabled(false);
2167
2168
2169 if (current_tab != counters) {
2170 leftbot_layout->replaceWidget(active_tab,
2172 Qt::FindDirectChildrenOnly);
2173 active_tab->hide();
2174 counterss_frame->show();
2175 counterss_frame->updateGeometry();
2177 } else {
2178 /* We do not change prod_unit_splitter to current_tab,
2179 * because counters is active tab and clicked -
2180 * switching to default */
2181 leftbot_layout->replaceWidget(counterss_frame,
2183 Qt::FindDirectChildrenOnly);
2184 prod_unit_splitter->show();
2185 prod_unit_splitter->updateGeometry();
2186 counterss_frame->hide();
2188 }
2189
2190 setUpdatesEnabled(true);
2191 update();
2192 update_tabs();
2193}
2194
2195/************************************************************************/
2199{
2200 struct player *pplayer = client_player();
2201
2202 if (pplayer == nullptr
2203 || city_owner(dlgcity) != pplayer) {
2204 prev_city_but->setDisabled(true);
2205 next_city_but->setDisabled(true);
2206 buy_button->setDisabled(true);
2207 cma_enable_but->setDisabled(true);
2208 production_combo_p->setDisabled(true);
2209 current_units->setDisabled(true);
2210 supported_units->setDisabled(true);
2211 view->setDisabled(true);
2212 } else {
2213 prev_city_but->setEnabled(true);
2214 next_city_but->setEnabled(true);
2215 buy_button->setEnabled(true);
2216 cma_enable_but->setEnabled(true);
2217 production_combo_p->setEnabled(true);
2218 current_units->setEnabled(true);
2219 supported_units->setEnabled(true);
2220 view->setEnabled(true);
2221 }
2222
2224 cma_enable_but->setEnabled(true);
2225 } else {
2226 cma_enable_but->setDisabled(true);
2227 }
2228
2230}
2231
2232/************************************************************************/
2236{
2237 struct player *pplayer = client_player();
2238
2239 work_next_but->setDisabled(true);
2240 work_prev_but->setDisabled(true);
2241 work_add_but->setDisabled(true);
2242 work_rem_but->setDisabled(true);
2243
2244 if (pplayer != nullptr
2245 && city_owner(dlgcity) == pplayer) {
2246 work_add_but->setEnabled(true);
2247
2248 if (selected_row_p >= 0 && selected_row_p < p_table_p->rowCount()) {
2249 work_rem_but->setEnabled(true);
2250 }
2251
2252 if (selected_row_p >= 0 && selected_row_p < p_table_p->rowCount() - 1) {
2253 work_next_but->setEnabled(true);
2254 }
2255
2256 if (selected_row_p > 0 && selected_row_p < p_table_p->rowCount()) {
2257 work_prev_but->setEnabled(true);
2258 }
2259 }
2260}
2261
2262/************************************************************************/
2266{
2267 if (citizen_pixmap) {
2268 citizen_pixmap->detach();
2269 delete citizen_pixmap;
2270 }
2271
2272 cma_table->clear();
2273 p_table_p->clear();
2274 nationality_table->clear();
2276 supported_units->clear_layout();
2277 removeEventFilter(this);
2278 ::city_dlg_created = false;
2279
2280 // Delete the one widget that currently does NOT have a parent
2281 if (current_tab == common) {
2282 delete happiness_widget;
2283 delete counterss_frame;
2284 }
2285 else if (current_tab == counters) {
2286 delete happiness_widget;
2287 delete prod_unit_splitter;
2288 }else {
2289 delete counterss_frame;
2290 delete prod_unit_splitter;
2291 }
2292}
2293
2294/************************************************************************/
2298{
2299 gui()->qt_settings.city_geometry = saveGeometry();
2300 gui()->qt_settings.city_splitter1 = prod_unit_splitter->saveState();
2301 gui()->qt_settings.city_splitter2 = central_left_splitter->saveState();
2302 gui()->qt_settings.city_splitter3 = central_splitter->saveState();
2303}
2304
2305/************************************************************************/
2309{
2310 if (!gui()->qt_settings.city_geometry.isNull()) {
2311 restoreGeometry(gui()->qt_settings.city_geometry);
2312 prod_unit_splitter->restoreState(gui()->qt_settings.city_splitter1);
2313 central_left_splitter->restoreState(gui()->qt_settings.city_splitter2);
2314 central_splitter->restoreState(gui()->qt_settings.city_splitter3);
2315 } else {
2316 QRect rect = QApplication::primaryScreen()->availableGeometry();
2317
2318 resize((rect.width() * 4) / 5, (rect.height() * 5) / 6);
2319 }
2320}
2321
2322/************************************************************************/
2326{
2327 gui()->qt_settings.city_geometry = saveGeometry();
2328 gui()->qt_settings.city_splitter1 = prod_unit_splitter->saveState();
2329 gui()->qt_settings.city_splitter2 = central_left_splitter->saveState();
2330 gui()->qt_settings.city_splitter3 = central_splitter->saveState();
2331}
2332
2333/************************************************************************/
2336bool city_dialog::eventFilter(QObject *obj, QEvent *event)
2337{
2338
2339 if (obj == this) {
2340 if (event->type() == QEvent::KeyPress) {
2341 }
2342
2343 if (event->type() == QEvent::ShortcutOverride) {
2344 QKeyEvent *key_event = static_cast<QKeyEvent *>(event);
2345 if (key_event->key() == Qt::Key_Right) {
2346 next_city();
2347 event->setAccepted(true);
2348 return true;
2349 }
2350 if (key_event->key() == Qt::Key_Left) {
2351 prev_city();
2352 event->setAccepted(true);
2353 return true;
2354 }
2355 if (key_event->key() == Qt::Key_Up) {
2356 change_production(true);
2357 event->setAccepted(true);
2358 return true;
2359 }
2360 if (key_event->key() == Qt::Key_Down) {
2361 change_production(false);
2362 event->setAccepted(true);
2363 return true;
2364 }
2365 }
2366 }
2367 return QObject::eventFilter(obj, event);
2368}
2369
2370/************************************************************************/
2374{
2376 const int city_id = dlgcity->id;
2377
2378 if (!can_client_issue_orders()) {
2379 return;
2380 }
2381
2382 ask = new hud_input_box(gui()->central_wdg);
2383 ask->set_text_title_definput(_("What should we rename the city to?"),
2384 _("Rename City"), city_name_get(dlgcity));
2385 ask->setAttribute(Qt::WA_DeleteOnClose);
2386 connect(ask, &hud_message_box::accepted, this, [=]() {
2387 struct city *pcity = game_city_by_number(city_id);
2389
2390 if (!pcity) {
2391 return;
2392 }
2393
2394 ask_bytes = ask->input_edit.text().toUtf8();
2395 ::city_rename(pcity, ask_bytes.data());
2396 });
2397 ask->show();
2398}
2399
2400/************************************************************************/
2404{
2405 zoom = zoom * 1.2;
2406 if (dlgcity) {
2407 view->set_pixmap(dlgcity, zoom);
2408 }
2410 left_layout->update();
2411}
2412
2413/************************************************************************/
2417{
2418 zoom = zoom / 1.2;
2419 if (dlgcity) {
2420 view->set_pixmap(dlgcity, zoom);
2421 }
2423 left_layout->update();
2424}
2425
2426/************************************************************************/
2430{
2431 hud_input_box *ask = new hud_input_box(gui()->central_wdg);
2432
2433 ask->set_text_title_definput(_("What should we name the preset?"),
2434 _("Name new preset"),
2435 _("new preset"));
2436 ask->setAttribute(Qt::WA_DeleteOnClose);
2437 connect(ask, &hud_message_box::accepted, this,
2439 struct cm_parameter param;
2440 QByteArray ask_bytes = ask->input_edit.text().toUtf8();
2441 QString text = ask_bytes.data();
2442 if (!text.isEmpty()) {
2443 param.allow_disorder = false;
2444 param.allow_specialists = true;
2445 param.require_happy = cma_celeb_checkbox->isChecked();
2446 param.max_growth = cma_max_growth->isChecked();
2447 param.happy_factor = slider_tab[2 * O_LAST + 1]->value();
2448
2449 for (int i = O_FOOD; i < O_LAST; i++) {
2450 param.minimal_surplus[i] = slider_tab[2 * i]->value();
2451 param.factor[i] = slider_tab[2 * i + 1]->value();
2452 }
2453
2454 ask_bytes = text.toUtf8();
2455 cmafec_preset_add(ask_bytes.data(), &param);
2457 }
2458 });
2459 ask->show();
2460}
2461
2462/************************************************************************/
2466{
2467 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2469
2470 return;
2471 }
2472
2473 cma_changed();
2475}
2476
2477/************************************************************************/
2481{
2482 struct cm_parameter param;
2483
2484 param.allow_disorder = false;
2485 param.allow_specialists = true;
2486 param.require_happy = cma_celeb_checkbox->isChecked();
2487 param.max_growth = cma_max_growth->isChecked();
2488 param.happy_factor = slider_tab[2 * O_LAST + 1]->value();
2489
2490 for (int i = O_FOOD; i < O_LAST; i++) {
2491 param.minimal_surplus[i] = slider_tab[2 * i]->value();
2492 param.factor[i] = slider_tab[2 * i + 1]->value();
2493 }
2494
2496}
2497
2498/************************************************************************/
2502{
2503 const struct cm_parameter *param;
2504
2505 if (!can_client_issue_orders()) {
2506 return;
2507 }
2509 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2511 }
2512
2515}
2516
2517/************************************************************************/
2521 const QItemSelection &ds)
2522{
2523 const struct cm_parameter *param;
2524 QModelIndex index;
2525 QModelIndexList indexes = sl.indexes();
2526
2527 if (indexes.isEmpty() || cma_table->signalsBlocked()) {
2528 return;
2529 }
2530
2531 index = indexes.at(0);
2532 int ind = index.row();
2533
2534 if (cma_table->currentRow() == -1 || cmafec_preset_num() == 0) {
2535 return;
2536 }
2537
2540
2541 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2544 }
2545}
2546
2547/************************************************************************/
2551{
2552 struct cm_parameter param;
2553 const struct cm_parameter *cparam;
2554 int output;
2555 QVariant qvar;
2556 QLabel *label;
2557
2558 if (!cma_is_city_under_agent(dlgcity, &param)) {
2559 if (cma_table->currentRow() == -1 || cmafec_preset_num() == 0) {
2560 return;
2561 }
2563 cm_copy_parameter(&param, cparam);
2564 }
2565
2566 for (output = O_FOOD; output < 2 * O_LAST; output++) {
2567 slider_tab[output]->blockSignals(true);
2568 }
2569
2570 for (output = O_FOOD; output < O_LAST; output++) {
2571 qvar = slider_tab[2 * output + 1]->property("FC");
2572 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2573 label->setText(QString::number(param.factor[output]));
2574 slider_tab[2 * output + 1]->setValue(param.factor[output]);
2575 qvar = slider_tab[2 * output]->property("FC");
2576 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2577 label->setText(QString::number(param.minimal_surplus[output]));
2578 slider_tab[2 * output]->setValue(param.minimal_surplus[output]);
2579 }
2580
2581 slider_tab[2 * O_LAST + 1]->blockSignals(true);
2582 qvar = slider_tab[2 * O_LAST + 1]->property("FC");
2583 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2584 label->setText(QString::number(param.happy_factor));
2585 slider_tab[2 * O_LAST + 1]->setValue(param.happy_factor);
2586 slider_tab[2 * O_LAST + 1]->blockSignals(false);
2587 cma_celeb_checkbox->blockSignals(true);
2588 cma_celeb_checkbox->setChecked(param.require_happy);
2589 cma_celeb_checkbox->blockSignals(false);
2590 cma_max_growth->blockSignals(true);
2591 cma_max_growth->setChecked(param.max_growth);
2592 cma_max_growth->blockSignals(false);
2593
2594 for (output = O_FOOD; output < 2 * O_LAST; output++) {
2595 slider_tab[output]->blockSignals(false);
2596 }
2597}
2598
2599/************************************************************************/
2603{
2604 QString s;
2606 struct cm_parameter param;
2607 QPixmap pix;
2608 int i;
2609
2610 cma_table->clear();
2611 cma_table->setRowCount(0);
2612
2613 for (i = 0; i < cmafec_preset_num(); i++) {
2614 item = new QTableWidgetItem;
2615 item->setText(cmafec_preset_get_descr(i));
2616 cma_table->insertRow(i);
2617 cma_table->setItem(i, 0, item);
2618 }
2619
2620 if (cmafec_preset_num() == 0) {
2621 cma_table->insertRow(0);
2622 item = new QTableWidgetItem;
2623 item->setText(_("No governor defined"));
2624 cma_table->setItem(0, 0, item);
2625 }
2626
2627 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2628 view->update();
2630 pix = style()->standardPixmap(QStyle::SP_DialogApplyButton);
2631 pix = pix.scaled(2 * pix.width(), 2 * pix.height(),
2632 Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
2633 cma_result_pix->setPixmap(pix);
2634 cma_result_pix->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
2635 // TRANS: %1 is custom string chosen by player
2636 cma_result->setText(QString(_("<h3>Governor Enabled<br>(%1)</h3>"))
2637 .arg(s.toHtmlEscaped()));
2638 cma_result->setAlignment(Qt::AlignCenter);
2639 } else {
2640 pix = style()->standardPixmap(QStyle::SP_DialogCancelButton);
2641 pix = pix.scaled(1.6 * pix.width(), 1.6 * pix.height(),
2642 Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
2643 cma_result_pix->setPixmap(pix);
2644 cma_result_pix->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
2645 cma_result->setText(QString(_("<h3>Governor Disabled</h3>")));
2646 cma_result->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
2647 }
2648
2649 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2652 cm_parameter *const >(&param));
2653 if (i >= 0 && i < cma_table->rowCount()) {
2654 cma_table->blockSignals(true);
2655 cma_table->setCurrentCell(i, 0);
2656 cma_table->blockSignals(false);
2657 }
2658
2659 cma_enable_but->setText(_("Disable"));
2660 } else {
2661 cma_enable_but->setText(_("Enable"));
2662 }
2664}
2665
2666/************************************************************************/
2670{
2671 int i;
2673
2674 i = cma_table->currentRow();
2675
2676 if (i == -1 || cmafec_preset_num() == 0) {
2677 return;
2678 }
2679
2681 ask->set_text_title(_("Remove this preset?"), cmafec_preset_get_descr(i));
2682 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
2683 ask->setDefaultButton(QMessageBox::Cancel);
2684 ask->setAttribute(Qt::WA_DeleteOnClose);
2685 connect(ask, &hud_message_box::accepted, this,
2689 });
2690 ask->show();
2691}
2692
2693/************************************************************************/
2696void city_dialog::cma_toggle_changed(Qt::CheckState state)
2697{
2698 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2699 cma_changed();
2701 }
2702}
2703
2704/************************************************************************/
2709{
2710 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2711 cma_changed();
2713 }
2714}
2715
2716/************************************************************************/
2720{
2721 QVariant qvar;
2722 QSlider *slider;
2723 QLabel *label;
2724
2726 qvar = slider->property("FC");
2727
2728 if (qvar.isNull() || !qvar.isValid()) {
2729 return;
2730 }
2731
2732 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2733 label->setText(QString::number(value));
2734
2735 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2736 cma_changed();
2738 }
2739}
2740
2741/************************************************************************/
2761
2762/************************************************************************/
2766{
2767 QMenu *cma_menu = new QMenu(this);
2769
2770 cma_menu->setAttribute(Qt::WA_DeleteOnClose);
2771 cma_del_item = cma_menu->addAction(_("Remove Governor"));
2772 connect(cma_menu, &QMenu::triggered, this,
2774 if (act == cma_del_item) {
2775 cma_remove();
2776 }
2777 });
2778
2779 cma_menu->popup(QCursor::pos());
2780}
2781
2782/************************************************************************/
2786{
2787 QAction *action;
2788 QAction *disband;
2793 QMap<QString, cid>::const_iterator map_iter;
2794 QMenu *change_menu;
2795 QMenu *insert_menu;
2796 QMenu *list_menu;
2797 QMenu *options_menu;
2798 int city_id = dlgcity->id;
2799
2800 if (!can_client_issue_orders()) {
2801 return;
2802 }
2803 list_menu = new QMenu(this);
2804 change_menu = list_menu->addMenu(_("Change worklist"));
2805 insert_menu = list_menu->addMenu(_("Insert worklist"));
2806 wl_clear = list_menu->addAction(_("Clear"));
2807 connect(wl_clear, &QAction::triggered, this, &city_dialog::clear_worklist);
2808 list.clear();
2809
2813
2814 if (list.count() == 0) {
2815 wl_empty = change_menu->addAction(_("(no worklists defined)"));
2816 insert_menu->addAction(wl_empty);
2817 }
2818
2819 map_iter = list.constBegin();
2820
2821 while (map_iter != list.constEnd()) {
2822 action = change_menu->addAction(map_iter.key());
2823 action->setData(map_iter.value());
2824
2825 action = insert_menu->addAction(map_iter.key());
2826 action->setData(map_iter.value());
2827
2828 map_iter++;
2829 }
2830
2831 wl_save = list_menu->addAction(_("Save worklist"));
2832 connect(wl_save, &QAction::triggered, this, &city_dialog::save_worklist);
2833 options_menu = list_menu->addMenu(_("Options"));
2834 disband = options_menu->addAction(_("Allow disbanding city"));
2835 disband->setCheckable(true);
2836 disband->setChecked(is_city_option_set(dlgcity, CITYO_DISBAND));
2837 connect(disband, &QAction::triggered, this,
2839
2840 connect(change_menu, &QMenu::triggered, this, [=](QAction *act) {
2841 QVariant id = act->data();
2842 struct city *pcity = game_city_by_number(city_id);
2843 const struct worklist *worklist;
2844
2845 if (!pcity) {
2846 return;
2847 }
2848
2849#ifndef FC_QT5_MODE
2850 fc_assert_ret(id.typeId() == QMetaType::Int);
2851#else // FC_QT5_MODE
2852 fc_assert_ret(id.type() == QVariant::Int);
2853#endif // FC_QT5_MODE
2854
2857 });
2858
2859 connect(insert_menu, &QMenu::triggered, this,
2861 QVariant id = act->data();
2862 struct city *pcity = game_city_by_number(city_id);
2863 const struct worklist *worklist;
2864
2865 if (!pcity) {
2866 return;
2867 }
2868
2869#ifndef FC_QT5_MODE
2870 fc_assert_ret(id.typeId() == QMetaType::Int);
2871#else // FC_QT5_MODE
2872 fc_assert_ret(id.type() == QVariant::Int);
2873#endif // FC_QT5_MODE
2874
2877 });
2878
2879 list_menu->popup(QCursor::pos());
2880}
2881
2882/************************************************************************/
2886{
2887 QString str;
2888 int value;
2889 struct player *pplayer = client_player();
2890
2891 buy_button->setDisabled(true);
2892
2893 if (!client_is_observer() && pplayer != nullptr) {
2894 value = dlgcity->client.buy_cost;
2895 str = QString(PL_("Buy (%1 gold)", "Buy (%1 gold)",
2896 value)).arg(QString::number(value));
2897
2898 if (pplayer->economic.gold >= value && value != 0) {
2899 buy_button->setEnabled(true);
2900 }
2901 } else {
2902 str = QString(_("Buy"));
2903 }
2904
2905 buy_button->setText(str);
2906}
2907
2908/************************************************************************/
2912{
2913 enum citizen_category categories[MAX_CITY_SIZE];
2914 int i, j, width, height;
2915 QPainter p;
2916 QPixmap *pix;
2918 int w = tileset_small_sprite_width(tileset) / gui()->map_scale;
2919 int h = tileset_small_sprite_height(tileset) / gui()->map_scale;
2920
2921 i = 1 + (num_citizens * 5 / 200);
2922 w = w / i;
2923 QRect source_rect(0, 0, w, h);
2924 QRect dest_rect(0, 0, w, h);
2925 width = w * num_citizens;
2926 height = h;
2927
2928 if (citizen_pixmap) {
2929 citizen_pixmap->detach();
2930 delete citizen_pixmap;
2931 }
2932
2934
2935 for (j = 0, i = 0; i < num_citizens; i++, j++) {
2936 dest_rect.moveTo(i * w, 0);
2937 pix = get_citizen_sprite(tileset, categories[j], j, dlgcity)->pm;
2938 p.begin(citizen_pixmap);
2939 p.drawPixmap(dest_rect, *pix, source_rect);
2940 p.end();
2941 }
2942
2944 citizens_label->setPixmap(*citizen_pixmap);
2945
2948
2949 for (int k = 0; k < FEELING_LAST - 1; k++) {
2952 static_cast<citizen_feeling>(k),
2953 categories);
2954
2955 for (j = 0, i = 0; i < num_citizens; i++, j++) {
2956 dest_rect.moveTo(i * w, 0);
2957 pix = get_citizen_sprite(tileset, categories[j], j, dlgcity)->pm;
2958 p.begin(citizen_pixmap);
2959 p.drawPixmap(dest_rect, *pix, source_rect);
2960 p.end();
2961 }
2962
2963 lab_table[k]->setPixmap(*citizen_pixmap);
2964
2965 switch (k) {
2966 case FEELING_BASE:
2967 lab_table[k]->setToolTip(text_happiness_cities(dlgcity));
2968 break;
2969
2970 case FEELING_LUXURY:
2971 lab_table[k]->setToolTip(text_happiness_luxuries(dlgcity));
2972 break;
2973
2974 case FEELING_EFFECT :
2976 break;
2977
2980 break;
2981
2982 case FEELING_MARTIAL:
2983 lab_table[k]->setToolTip(text_happiness_units(dlgcity));
2984 break;
2985
2986 default:
2987 break;
2988 }
2989 }
2990}
2991
2992/************************************************************************/
2996{
2997 setUpdatesEnabled(false);
2998 production_combo_p->blockSignals(true);
2999
3000 if (dlgcity) {
3001 view->set_pixmap(dlgcity, zoom);
3002 view->update();
3003 update_title();
3010 update_units();
3014 } else {
3016 }
3017
3018 production_combo_p->blockSignals(false);
3019 setUpdatesEnabled(true);
3021 update();
3022}
3023
3024/************************************************************************/
3028{
3029 QFont *small_font;
3030
3032
3033 qDeleteAll(counterss_frame->findChildren<QWidget*>("", Qt::FindDirectChildrenOnly));
3035 QString helptext;
3036 char buf[1024];
3037 QLabel *name, *value, *activated, *help;
3038
3039 name = new QLabel(name_translation_get(&pcount->name));
3040 fc_snprintf(buf, sizeof(buf), _("Current value is: %d"),
3042 value = new QLabel(buf);
3043 fc_snprintf(buf, sizeof(buf), _("Activated once value equal "
3044 "or higher than: %d"),
3045 pcount->checkpoint);
3046 activated = new QLabel(buf);
3047 if (pcount->helptext != nullptr) {
3048 strvec_iterate(pcount->helptext, text_) {
3049 helptext += text_;
3051 }
3052 help = new QLabel(helptext);
3053
3054 name->setFont(*small_font);
3055 value->setFont(*small_font);
3056 activated->setFont(*small_font);
3057 help->setFont(*small_font);
3058
3059 counterss_layout->addWidget(name);
3060 counterss_layout->addWidget(value);
3061 counterss_layout->addWidget(activated);
3062 counterss_layout->addWidget(help);
3064}
3065
3066/************************************************************************/
3070{
3071 QFont f = QApplication::font();
3072 QFontMetrics fm(f);
3073 QPixmap *pix = nullptr;
3075 QString str;
3078 char buf[8];
3080 int h;
3081 int i = 0;
3082 struct sprite *sprite;
3083
3084 h = fm.height() + 6;
3085 nationality_table->clear();
3086 nationality_table->setRowCount(0);
3087 info_list.clear();
3088 info_list << _("#") << _("Flag") << _("Nation");
3089 nationality_table->setHorizontalHeaderLabels(info_list);
3090
3091 citizens_iterate(dlgcity, pslot, nationality) {
3092 nationality_table->insertRow(i);
3093
3094 for (int j = 0; j < nationality_table->columnCount(); j++) {
3095 item = new QTableWidgetItem;
3096
3097 switch (j) {
3098 case 0:
3100
3101 if (nationality_i == 0) {
3102 str = "-";
3103 } else {
3104 fc_snprintf(buf, sizeof(buf), "%d", nationality_i);
3105 str = QString(buf);
3106 }
3107
3108 item->setText(str);
3109 break;
3110
3111 case 1:
3114 (player_slot_get_player(pslot)));
3115
3116 if (sprite != nullptr) {
3117 pix = sprite->pm;
3118 pix_scaled = pix->scaledToHeight(h);
3119 item->setData(Qt::DecorationRole, pix_scaled);
3120 } else {
3121 item->setText("FLAG MISSING");
3122 }
3123 break;
3124
3125 case 2:
3127 (player_slot_get_player(pslot)));
3128 break;
3129
3130 default:
3131 break;
3132 }
3133 nationality_table->setItem(i, j, item);
3134 }
3135 i++;
3137 nationality_table->horizontalHeader()->setStretchLastSection(false);
3138 nationality_table->resizeColumnsToContents();
3139 nationality_table->resizeRowsToContents();
3140 nationality_table->horizontalHeader()->setStretchLastSection(true);
3141}
3142
3143/************************************************************************/
3147{
3148 int illness = 0;
3149 char buffer[512];
3150 char buf_info[NUM_INFO_FIELDS][512];
3151 char buf_tooltip[NUM_INFO_FIELDS][512];
3152 int granaryturns;
3153 int spec;
3154
3155 for (int i = 0; i < NUM_INFO_FIELDS; i++) {
3156 buf_info[i][0] = '\0';
3157 buf_tooltip[i][0] = '\0';
3158 }
3159
3160 // Fill the buffers with the necessary info
3161 spec = city_specialists(dlgcity);
3163 "%3d (%4d)", dlgcity->size, spec);
3165 _("Population: %d, Specialists: %d"),
3166 dlgcity->size, spec);
3167 fc_snprintf(buf_info[INFO_FOOD], sizeof(buf_info[INFO_FOOD]), "%3d (%+4d)",
3170 "%3d (%+4d)", dlgcity->prod[O_SHIELD] + dlgcity->waste[O_SHIELD],
3172 fc_snprintf(buf_info[INFO_TRADE], sizeof(buf_info[INFO_TRADE]), "%3d (%+4d)",
3175 fc_snprintf(buf_info[INFO_GOLD], sizeof(buf_info[INFO_GOLD]), "%3d (%+4d)",
3182 "%4d/%-4d", dlgcity->food_stock,
3184
3186 sizeof(buf_tooltip[INFO_FOOD]));
3188 sizeof(buf_tooltip[INFO_SHIELD]));
3190 sizeof(buf_tooltip[INFO_TRADE]));
3192 sizeof(buf_tooltip[INFO_GOLD]));
3194 sizeof(buf_tooltip[INFO_SCIENCE]));
3196 sizeof(buf_tooltip[INFO_LUXURY]));
3198 sizeof(buf_tooltip[INFO_CULTURE]));
3200 sizeof(buf_tooltip[INFO_POLLUTION]));
3202 sizeof(buf_tooltip[INFO_ILLNESS]));
3203
3205
3206 if (granaryturns == 0) {
3207 // TRANS: city growth is blocked. Keep short.
3208 fc_snprintf(buf_info[INFO_GROWTH], sizeof(buf_info[INFO_GROWTH]), _("blocked"));
3209 } else if (granaryturns == FC_INFINITY) {
3210 // TRANS: city is not growing. Keep short.
3211 fc_snprintf(buf_info[INFO_GROWTH], sizeof(buf_info[INFO_GROWTH]), _("never"));
3212 } else {
3213 /* A negative value means we'll have famine in that many turns.
3214 But that's handled down below. */
3215 // TRANS: city growth turns. Keep short.
3217 PL_("%d turn", "%d turns", abs(granaryturns)),
3218 abs(granaryturns));
3219 }
3220
3222 "%4d", dlgcity->waste[O_TRADE]);
3229
3230 if (!game.info.illness_on) {
3232 " -.-");
3233 } else {
3234 illness = city_illness_calc(dlgcity, nullptr, nullptr, nullptr, nullptr);
3235 // Illness is in tenth of percent
3237 "%5.1f%%", (float) illness / 10.0);
3238 }
3239 if (dlgcity->steal) {
3241 PL_("%d time", "%d times", dlgcity->steal), dlgcity->steal);
3242 } else {
3244 _("Not stolen"));
3245 }
3246
3248 sizeof(buf_info[INFO_AIRLIFT]));
3250 sizeof(buf_tooltip[INFO_AIRLIFT]));
3251
3252 get_city_dialog_output_text(dlgcity, O_FOOD, buffer, sizeof(buffer));
3253
3254 for (int i = 0; i < NUM_INFO_FIELDS; i++) {
3255 qlt[i]->setText(QString(buf_info[i]));
3256
3257 if (buf_tooltip[i][0]) {
3258 qlt[i]->setToolTip("<pre>" + QString(buf_tooltip[i]).toHtmlEscaped()
3259 + "</pre>");
3260 }
3261 }
3262}
3263
3264/************************************************************************/
3268{
3271
3272 setContentsMargins(0, 0 ,0 ,0);
3274 dlgcity = qcity;
3275 production_combo_p->blockSignals(true);
3276 refresh();
3277 production_combo_p->blockSignals(false);
3278}
3279
3280/************************************************************************/
3284{
3285 struct worklist queue;
3286
3287 city_get_queue(dlgcity, &queue);
3288
3290 return;
3291 }
3292
3294 city_set_queue(dlgcity, &queue);
3295}
3296
3297/************************************************************************/
3301{
3302 unit_item *ui;
3303 struct unit_list *units;
3304 char buf[256];
3305 int n;
3306 int happy_cost;
3308 struct player *pplayer = client_player();
3309 const struct civ_map *nmap = &(wld.map);
3310
3311 supported_units->setUpdatesEnabled(false);
3312 supported_units->clear_layout();
3313
3314 if (pplayer != nullptr
3315 && city_owner(dlgcity) != pplayer) {
3317 } else {
3318 units = dlgcity->units_supported;
3319 }
3320
3321 unit_list_iterate(units, punit) {
3323 ui = new unit_item(this, punit, true, happy_cost);
3324 ui->init_pix();
3325 supported_units->add_item(ui);
3327 n = unit_list_size(units);
3328 fc_snprintf(buf, sizeof(buf), _("Supported units %d"), n);
3329 supp_units->setText(QString(buf));
3330 supported_units->update_units();
3331 supported_units->setUpdatesEnabled(true);
3332 current_units->setUpdatesEnabled(true);
3334
3335 if (pplayer != nullptr
3336 && city_owner(dlgcity) != pplayer) {
3338 } else {
3339 units = dlgcity->tile->units;
3340 }
3341
3342 unit_list_iterate(units, punit) {
3343 ui = new unit_item(this , punit, false);
3344 ui->init_pix();
3347
3348 n = unit_list_size(units);
3349 fc_snprintf(buf, sizeof(buf), _("Present units %d"), n);
3350 curr_units->setText(QString(buf));
3351
3353 current_units->setUpdatesEnabled(true);
3354}
3355
3356/************************************************************************/
3360 const QItemSelection &ds)
3361{
3362 QModelIndex index;
3363 QModelIndexList indexes = sl.indexes();
3364
3365 if (indexes.isEmpty()) {
3366 return;
3367 }
3368
3369 index = indexes.at(0);
3370 selected_row_p = index.row();
3372}
3373
3374/************************************************************************/
3378{
3379 int size, i;
3380 struct city *other_pcity = nullptr;
3381 struct player *pplayer = client_player();
3382
3383 if (pplayer == nullptr) {
3384 return;
3385 }
3386
3387 size = city_list_size(pplayer->cities);
3388
3389 if (size <= 1) {
3390 return;
3391 }
3392
3393 for (i = 0; i < size; i++) {
3394 if (dlgcity == city_list_get(pplayer->cities, i)) {
3395 break;
3396 }
3397 }
3398
3399 if (i >= size - 1) {
3400 // Current city last in the list (size - 1) or disappeared (size)
3401 other_pcity = city_list_get(pplayer->cities, 0);
3402 } else {
3403 other_pcity = city_list_get(pplayer->cities, i + 1);
3404 }
3405
3408}
3409
3410/************************************************************************/
3414{
3415 int size, i;
3416 struct city *other_pcity = nullptr;
3417 struct player *pplayer = client_player();
3418
3419 if (pplayer == nullptr) {
3420 return;
3421 }
3422
3423 size = city_list_size(pplayer->cities);
3424
3425 if (size <= 1) {
3426 return;
3427 }
3428
3429 for (i = 0; i < size; i++) {
3430 if (dlgcity == city_list_get(pplayer->cities, i)) {
3431 break;
3432 }
3433 }
3434
3435 if (i == 0 || i == size) {
3436 // Current city in the beginning of the list or disappeared
3437 other_pcity = city_list_get(pplayer->cities, size - 1);
3438 } else {
3439 other_pcity = city_list_get(pplayer->cities, i - 1);
3440 }
3441
3444}
3445
3446/************************************************************************/
3450{
3451 char buf[32];
3452 QString str;
3454
3456 production_combo_p->setRange(0, cost);
3458 if (dlgcity->shield_stock >= cost) {
3459 production_combo_p->setValue(cost);
3460 } else {
3462 }
3463 production_combo_p->setAlignment(Qt::AlignCenter);
3464 str = QString(buf);
3465 str = str.simplified();
3466
3467 production_combo_p->setFormat(QString("(%p%) %2\n%1")
3469 str));
3470
3471 production_combo_p->updateGeometry();
3472
3473}
3474
3475/************************************************************************/
3479{
3480 char buf[1024], buf2[1024];
3482 int value = dlgcity->client.buy_cost;
3484 int city_id = dlgcity->id;
3485
3486 if (!can_client_issue_orders()) {
3487 return;
3488 }
3489
3491 fc_snprintf(buf2, ARRAY_SIZE(buf2), PL_("Treasury contains %d gold.",
3492 "Treasury contains %d gold.",
3493 client_player()->economic.gold),
3494 client_player()->economic.gold);
3495 fc_snprintf(buf, ARRAY_SIZE(buf), PL_("Buy %s for %d gold?",
3496 "Buy %s for %d gold?", value),
3497 name, value);
3498 ask->set_text_title(buf, buf2);
3499 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
3500 ask->setDefaultButton(QMessageBox::Cancel);
3501 ask->setAttribute(Qt::WA_DeleteOnClose);
3502 connect(ask, &hud_message_box::accepted, this, [=]() {
3503 struct city *pcity = game_city_by_number(city_id);
3504
3505 if (!pcity) {
3506 return;
3507 }
3508
3510 });
3511 ask->show();
3512}
3513
3514/************************************************************************/
3518{
3519 QFont f = QApplication::font();
3520 QFontMetrics fm(f);
3521 QPixmap *pix = nullptr;
3525 struct sprite *sprite;
3526 int h, cost, item, targets_used, col, upkeep;
3527 struct item items[MAX_NUM_PRODUCTION_TARGETS];
3528 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
3529 struct worklist queue;
3530 impr_item *ui;
3531
3532 upkeep = 0;
3533 city_buildings->setUpdatesEnabled(false);
3535
3536 h = fm.height() + 6;
3538 name_and_sort_items(targets, targets_used, items, false, dlgcity);
3539
3540 for (item = 0; item < targets_used; item++) {
3541 struct universal target = items[item].item;
3542
3543 ui = new impr_item(this, target.value.building, dlgcity);
3544 ui->init_pix();
3546
3547 fc_assert_action(VUT_IMPROVEMENT == target.kind, continue);
3549 upkeep = upkeep + city_improvement_upkeep(dlgcity, target.value.building);
3550 if (sprite != nullptr) {
3551 pix = sprite->pm;
3552 pix_scaled = pix->scaledToHeight(h);
3553 }
3554 }
3555
3556 city_get_queue(dlgcity, &queue);
3557 p_table_p->setRowCount(worklist_length(&queue));
3558
3559 for (int i = 0; i < worklist_length(&queue); i++) {
3560 struct universal target = queue.entries[i];
3561
3562 tooltip = "";
3563
3564 if (VUT_UTYPE == target.kind) {
3566 cost = utype_build_shield_cost(dlgcity, nullptr, target.value.utype);
3567 tooltip = get_tooltip_unit(target.value.utype, true).trimmed();
3571 } else {
3575 dlgcity, true).trimmed();
3576
3578 cost = -1;
3579 } else {
3581 }
3582 }
3583
3584 for (col = 0; col < 3; col++) {
3585 qitem = new QTableWidgetItem();
3586 qitem->setToolTip(tooltip);
3587
3588 switch (col) {
3589 case 0:
3590 if (sprite) {
3591 pix = sprite->pm;
3592 pix_scaled = pix->scaledToHeight(h);
3593 qitem->setData(Qt::DecorationRole, pix_scaled);
3594 }
3595 break;
3596
3597 case 1:
3598 if (str.contains('[') && str.contains(']')) {
3599 int ii, ij;
3600
3601 ii = str.lastIndexOf('[');
3602 ij = str.lastIndexOf(']');
3603 if (ij > ii) {
3604 str = str.remove(ii, ij - ii + 1);
3605 }
3606 }
3607 qitem->setText(str);
3608 break;
3609
3610 case 2:
3611 qitem->setTextAlignment(Qt::AlignRight);
3612 qitem->setText(QString::number(cost));
3613 break;
3614 }
3615 p_table_p->setItem(i, col, qitem);
3616 }
3617 }
3618
3619 p_table_p->horizontalHeader()->setStretchLastSection(false);
3620 p_table_p->resizeColumnsToContents();
3621 p_table_p->resizeRowsToContents();
3622 p_table_p->horizontalHeader()->setStretchLastSection(true);
3623
3625 city_buildings->setUpdatesEnabled(true);
3626 city_buildings->setUpdatesEnabled(true);
3627
3628 curr_impr->setText(QString(_("Improvements - upkeep %1")).arg(upkeep));
3629}
3630
3631/************************************************************************/
3635{
3636 cid id;
3637 QVariant qvar;
3638
3640 struct universal univ;
3641
3642 id = qvar.toInt();
3643 univ = cid_production(id);
3645 }
3646}
3647
3648/************************************************************************/
3653{
3655 int when = 1;
3656
3657 pw = new production_widget(this, dlgcity, future_targets->isChecked(),
3658 when, selected_row_p, show_units->isChecked(),
3659 false, show_wonders->isChecked(),
3660 show_buildings->isChecked());
3661 pw->show();
3662}
3663
3664/************************************************************************/
3669{
3671 int when = 4;
3672
3673 pw = new production_widget(this, dlgcity, future_targets->isChecked(),
3674 when, selected_row_p, show_units->isChecked(),
3675 false, show_wonders->isChecked(),
3676 show_buildings->isChecked());
3677 pw->show();
3678}
3679
3680/************************************************************************/
3684{
3685 struct worklist empty;
3686
3687 if (!can_client_issue_orders()) {
3688 return;
3689 }
3690
3693}
3694
3695/************************************************************************/
3699{
3700 QModelIndex index;
3701 struct worklist queue;
3702 struct universal *target;
3703
3705 return;
3706 }
3707
3708 target = new universal;
3709 city_get_queue(dlgcity, &queue);
3710 worklist_peek_ith(&queue, target, selected_row_p);
3712 worklist_insert(&queue, target, selected_row_p - 1);
3713 city_set_queue(dlgcity, &queue);
3714 index = p_table_p->model()->index(selected_row_p - 1, 0);
3715 p_table_p->setCurrentIndex(index);
3716 delete target;
3717
3718}
3719
3720/************************************************************************/
3724{
3726
3727 if (selected_row_p < 0
3728 || selected_row_p >= p_table_p->rowCount()) {
3729 return;
3730 }
3731
3735}
3736
3737/************************************************************************/
3741{
3742 QModelIndex index;
3743 struct worklist queue;
3744 struct universal *target;
3745
3747 return;
3748 }
3749
3750 target = new universal;
3751 city_get_queue(dlgcity, &queue);
3752 worklist_peek_ith(&queue, target, selected_row_p);
3754 worklist_insert(&queue, target, selected_row_p + 1);
3755 city_set_queue(dlgcity, &queue);
3756 index = p_table_p->model()->index(selected_row_p + 1, 0);
3757 p_table_p->setCurrentIndex(index);
3758 delete target;
3759}
3760
3761/************************************************************************/
3765{
3766 hud_input_box *ask = new hud_input_box(gui()->central_wdg);
3767 int city_id = dlgcity->id;
3768
3769 ask->set_text_title_definput(_("What should we name new worklist?"),
3770 _("Save current worklist"),
3771 _("New worklist"));
3772 ask->setAttribute(Qt::WA_DeleteOnClose);
3773 connect(ask, &hud_message_box::accepted, [=]() {
3774 struct global_worklist *gw;
3775 struct worklist queue;
3777 QString text;
3778 struct city *pcity = game_city_by_number(city_id);
3779
3780 ask_bytes = ask->input_edit.text().toUtf8();
3781 text = ask_bytes.data();
3782 if (!text.isEmpty()) {
3783 ask_bytes = text.toUtf8();
3785 city_get_queue(pcity, &queue);
3786 global_worklist_set(gw, &queue);
3787 }
3788 });
3789 ask->show();
3790}
3791
3792/************************************************************************/
3796{
3797 QString buf;
3798
3799 // Defeat keyboard shortcut mnemonics
3801 .replace("&", "&&"));
3802
3803 if (city_unhappy(dlgcity)) {
3804 // TRANS: city dialog title
3805 buf = QString(_("%1 - %2 citizens - DISORDER")).arg(city_name_get(dlgcity),
3807 } else if (city_celebrating(dlgcity)) {
3808 // TRANS: city dialog title
3809 buf = QString(_("%1 - %2 citizens - celebrating")).arg(city_name_get(dlgcity),
3811 } else if (city_happy(dlgcity)) {
3812 // TRANS: city dialog title
3813 buf = QString(_("%1 - %2 citizens - happy")).arg(city_name_get(dlgcity),
3815 } else {
3816 // TRANS: city dialog title
3817 buf = QString(_("%1 - %2 citizens")).arg(city_name_get(dlgcity),
3819 }
3820
3822}
3823
3824/************************************************************************/
3829{
3830 if (!::city_dlg_created) {
3831 ::city_dlg = new city_dialog(gui()->mapview_wdg);
3832 }
3833
3835 city_dlg->show();
3836 city_dlg->activateWindow();
3837 city_dlg->raise();
3838}
3839
3840/************************************************************************/
3844{
3845 if (!::city_dlg_created) {
3846 return;
3847 }
3848
3849 city_dlg->close();
3850 ::city_dlg_created = false;
3851}
3852
3853/************************************************************************/
3857{
3858 if (!::city_dlg_created) {
3859 return;
3860 }
3861
3863}
3864
3865/************************************************************************/
3872
3873/************************************************************************/
3877{
3878 if (!::city_dlg_created) {
3879 return;
3880 }
3881
3883 city_dlg->refresh();
3884 }
3885}
3886
3887/************************************************************************/
3891{
3893 QFont *f;
3894
3895 if (!::city_dlg_created) {
3896 return;
3897 }
3898
3899 l = city_dlg->findChildren<QLabel *>();
3900
3902
3903 for (int i = 0; i < l.size(); ++i) {
3904 if (l.at(i)->property(fonts::notify_label).isValid()) {
3905 l.at(i)->setFont(*f);
3906 }
3907 }
3908}
3909
3910/************************************************************************/
3927
3928/************************************************************************/
3932{
3933 if (!::city_dlg_created) {
3934 return false;
3935 }
3936
3937 if (city_dlg->dlgcity == pcity && city_dlg->isVisible()) {
3938 return true;
3939 }
3940
3941 return false;
3942}
3943
3944/************************************************************************/
3947bool fc_tooltip::eventFilter(QObject *obj, QEvent *ev)
3948{
3951 QRect rect;
3952
3953 if (ev->type() == QEvent::ToolTip) {
3955
3956 if (!view) {
3957 return false;
3958 }
3959
3960 help_event = static_cast<QHelpEvent *>(ev);
3961 QPoint pos = help_event->pos();
3962 QModelIndex index = view->indexAt(pos);
3963 QPoint hpos;
3964
3965 if (!index.isValid()) {
3966 return false;
3967 }
3968
3969 item_tooltip = view->model()->data(index, Qt::ToolTipRole).toString();
3970 rect = view->visualRect(index);
3971
3972 hpos = help_event->globalPos();
3973
3974 rect.setX(rect.x() + hpos.x());
3975 rect.setY(rect.y() + hpos.y());
3976
3977 if (!item_tooltip.isEmpty()) {
3978 QToolTip::showText(help_event->globalPos(), item_tooltip, view, rect);
3979 } else {
3980 QToolTip::hideText();
3981 }
3982
3983 return true;
3984 }
3985
3986 return false;
3987}
3988
3989/************************************************************************/
3993{
3994 return QString("<b>" + text + "</b>");
3995}
3996
3997/************************************************************************/
4002 bool ext)
4003{
4005 QString upkeep;
4006 QString s1, s2, str;
4007 const char *req = skip_intl_qualifier_prefix(_("?tech:None"));
4008 struct player *pplayer = client_player();
4009
4010 if (pcity != nullptr) {
4011 upkeep = QString::number(city_improvement_upkeep(pcity, building));
4012 } else {
4013 upkeep = QString::number(building->upkeep);
4014 }
4016 if (pobs->source.kind == VUT_ADVANCE) {
4017 req = advance_name_translation(pobs->source.value.advance);
4018 break;
4019 }
4021 s2 = QString(req);
4022 str = _("Obsolete by:");
4023 str = str + " " + s2;
4024 def_str = "<p style='white-space:pre'><b>"
4025 + QString(improvement_name_translation(building)).toHtmlEscaped()
4026 + "</b>\n";
4027 if (pcity != nullptr) {
4028 def_str += QString(_("Cost: %1, Upkeep: %2\n"))
4029 .arg(impr_build_shield_cost(pcity, building))
4030 .arg(upkeep).toHtmlEscaped();
4031 } else {
4033 nullptr, building);
4034
4035 def_str += QString(_("Cost Estimate: %1, Upkeep: %2\n"))
4036 .arg(cost_est)
4037 .arg(upkeep).toHtmlEscaped();
4038 }
4039 if (s1.compare(s2) != 0) {
4040 def_str = def_str + str.toHtmlEscaped() + "\n";
4041 }
4042 def_str = def_str + "\n";
4043 if (ext) {
4044 char buffer[8192];
4045
4046 str = helptext_building(buffer, sizeof(buffer), pplayer,
4047 nullptr, building);
4048 str = cut_helptext(str);
4049 str = split_text(str, true);
4050 str = str.trimmed();
4051 def_str = def_str + str.toHtmlEscaped();
4052 }
4053 return def_str;
4054}
4055
4056/************************************************************************/
4060QString get_tooltip_unit(const struct unit_type *utype, bool ext)
4061{
4064 QString str;
4065 const struct unit_type *obsolete;
4066 struct advance *tech;
4067
4068 def_str = "<b>"
4069 + QString(utype_name_translation(utype)).toHtmlEscaped()
4070 + "</b>\n";
4071 obsolete = utype->obsoleted_by;
4072 if (obsolete) {
4073 // FIXME: Don't give the impression that primary tech is (always) the only one.
4075 obsolete_str = QString("</td></tr><tr><td colspan=\"3\">");
4076 if (tech && tech != advance_by_number(A_NONE)) {
4077 /* TRANS: this and nearby literal strings are interpreted
4078 * as (Qt) HTML */
4079 obsolete_str = obsolete_str + QString(_("Obsoleted by %1 (%2)."))
4081 .arg(advance_name_translation(tech)).toHtmlEscaped();
4082 } else {
4083 obsolete_str = obsolete_str + QString(_("Obsoleted by %1."))
4084 .arg(utype_name_translation(obsolete)).toHtmlEscaped();
4085 }
4086 }
4087 def_str += "<table width=\"100\%\"><tr><td>"
4088 + bold(QString(_("Attack:"))) + " "
4089 + QString::number(utype->attack_strength).toHtmlEscaped()
4090 + QString("</td><td>") + bold(QString(_("Defense:"))) + " "
4091 + QString::number(utype->defense_strength).toHtmlEscaped()
4092 + QString("</td><td>") + bold(QString(_("Move:"))) + " "
4093 + QString(move_points_text(utype->move_rate, TRUE)).toHtmlEscaped()
4094 + QString("</td></tr><tr><td>")
4095 + bold(QString(_("Cost:"))) + " "
4096 + QString::number(utype_build_shield_cost_base(utype))
4097 .toHtmlEscaped()
4098 + QString("</td><td colspan=\"2\">")
4099 + bold(QString(_("Basic Upkeep:")))
4100 + " " + QString(helptext_unit_upkeep_str(utype)).toHtmlEscaped()
4101 + QString("</td></tr><tr><td>")
4102 + bold(QString(_("Hitpoints:"))) + " "
4103 + QString::number(utype->hp).toHtmlEscaped()
4104 + QString("</td><td>") + bold(QString(_("Firepower:"))) + " "
4105 + QString::number(utype->firepower).toHtmlEscaped()
4106 + QString("</td><td>") + bold(QString(_("Vision:"))) + " "
4107 + QString::number((int) sqrt((double) utype->vision_radius_sq))
4108 .toHtmlEscaped()
4109 + obsolete_str
4110 + QString("</td></tr></table><p style='white-space:pre'>");
4111 if (ext) {
4112 char buffer[8192];
4113 char buf2[1];
4114
4115 buf2[0] = '\0';
4116 str = helptext_unit(buffer, sizeof(buffer), client_player(),
4117 buf2, utype, TRUE);
4118 str = cut_helptext(str);
4119 str = split_text(str, true);
4120 str = str.trimmed().toHtmlEscaped();
4121 def_str = def_str + str;
4122 }
4123
4124 return def_str;
4125};
4126
4127/************************************************************************/
4131{
4134 char buffer[8192];
4135 char buf2[1];
4136 struct universal *target;
4137 struct player *pplayer = client_player();
4138
4139 buf2[0] = '\0';
4140 target = reinterpret_cast<universal *>(qvar.value<void *>());
4141
4142 if (target == nullptr) {
4143 } else if (VUT_UTYPE == target->kind) {
4145 str = helptext_unit(buffer, sizeof(buffer), pplayer,
4146 buf2, target->value.utype, TRUE);
4147 } else {
4148 if (!is_convert_improvement(target->value.building)) {
4150 }
4151
4152 str = helptext_building(buffer, sizeof(buffer), pplayer,
4153 nullptr, target->value.building);
4154 }
4155
4156 // Remove all lines from help which has '*' in first 3 chars
4158 ret_str = split_text(ret_str, true);
4159 ret_str = ret_str.trimmed();
4160 ret_str = def_str + ret_str.toHtmlEscaped();
4161
4162 return ret_str;
4163}
4164
4165/************************************************************************/
4169 QObject *parent,
4170 struct city *city)
4171 : QItemDelegate(parent)
4172{
4173 pd = sh;
4174 item_height = sh.y();
4175 pcity = city;
4176}
4177
4178/************************************************************************/
4183 const QModelIndex &index) const
4184{
4185 struct universal *target;
4186 QString name;
4187 QVariant qvar;
4188 QPixmap *pix;
4190 QRect rect1;
4191 QRect rect2;
4192 struct sprite *sprite;
4193 bool useless = false;
4194 bool is_convert = false;
4195 bool is_neutral = false;
4196 bool is_sea = false;
4197 bool is_flying = false;
4198 bool is_unit = true;
4199 QPixmap pix_dec(option.rect.width(), option.rect.height());
4201 color col;
4202 QIcon icon = current_app()->style()->standardIcon(QStyle::SP_DialogCancelButton);
4203 bool free_sprite = false;
4204 struct unit_class *pclass;
4205
4206 if (!option.rect.isValid()) {
4207 return;
4208 }
4209
4210 qvar = index.data();
4211
4212 if (!qvar.isValid()) {
4213 return;
4214 }
4215
4216 target = reinterpret_cast<universal *>(qvar.value<void *>());
4217
4218 if (target == nullptr) {
4219 col.qcolor = Qt::white;
4220 sprite = qtg_create_sprite(100, 100, &col);
4221 free_sprite = true;
4222 *sprite->pm = icon.pixmap(100, 100);
4223 name = _("Cancel");
4224 is_unit = false;
4225 } else if (VUT_UTYPE == target->kind) {
4228 pclass = utype_class(target->value.utype);
4232 is_sea = true;
4233 }
4234
4235 if ((utype_fuel(target->value.utype)
4240 /* FIXME: Assumed to be flying since only missiles can do suicide
4241 * attacks in classic-like rulesets. This isn't true for all
4242 * rulesets. Not a high priority to fix since all is_flying and
4243 * is_sea is used for is to set a color. */
4245 target->value.utype)) {
4246 if (is_sea) {
4247 is_sea = false;
4248 }
4249 is_flying = true;
4250 }
4251
4255 } else {
4256 is_unit = false;
4260 is_convert = (target->value.building->genus == IG_CONVERT);
4261 }
4262
4263 if (sprite != nullptr) {
4264 pix = sprite->pm;
4265 pix_scaled = pix->scaledToHeight(item_height - 2, Qt::SmoothTransformation);
4266
4267 if (useless) {
4269 }
4270 }
4271
4272 opt = QItemDelegate::setOptions(index, option);
4273 painter->save();
4274 opt.displayAlignment = Qt::AlignLeft;
4275 opt.textElideMode = Qt::ElideMiddle;
4276 QItemDelegate::drawBackground(painter, opt, index);
4277 rect1 = option.rect;
4278 rect1.setWidth(pix_scaled.width() + 4);
4279 rect2 = option.rect;
4280 rect2.setLeft(option.rect.left() + rect1.width());
4281 rect2.setTop(rect2.top() + (rect2.height()
4282 - painter->fontMetrics().height()) / 2);
4283 QItemDelegate::drawDisplay(painter, opt, rect2, name);
4284
4285 if (is_unit) {
4286 if (is_sea) {
4287 pix_dec.fill(QColor(0, 0, 255, 80));
4288 } else if (is_flying) {
4289 pix_dec.fill(QColor(220, 0, 0, 80));
4290 } else if (is_neutral) {
4291 pix_dec.fill(QColor(0, 120, 0, 40));
4292 } else {
4293 pix_dec.fill(QColor(0, 0, 150, 40));
4294 }
4295
4296 QItemDelegate::drawDecoration(painter, option, option.rect, pix_dec);
4297 }
4298
4299 if (is_convert) {
4300 pix_dec.fill(QColor(255, 255, 0, 70));
4301 QItemDelegate::drawDecoration(painter, option, option.rect, pix_dec);
4302 }
4303
4304 if (!pix_scaled.isNull()) {
4305 QItemDelegate::drawDecoration(painter, opt, rect1, pix_scaled);
4306 }
4307
4308 drawFocus(painter, opt, option.rect);
4309
4310 painter->restore();
4311
4312 if (free_sprite) {
4314 }
4315}
4316
4317/************************************************************************/
4322 const QRect &rect) const
4323{
4324 QPixmap pix(option.rect.width(), option.rect.height());
4325
4326 if ((option.state & QStyle::State_MouseOver) == 0 || !rect.isValid()) {
4327 return;
4328 }
4329
4330 pix.fill(QColor(50, 50, 50, 50));
4331 QItemDelegate::drawDecoration(painter, option, option.rect, pix);
4332}
4333
4334/************************************************************************/
4338 const QModelIndex &index) const
4339{
4340 QSize s;
4341
4342 s.setWidth(pd.x());
4343 s.setHeight(pd.y());
4344 return s;
4345}
4346
4347/************************************************************************/
4351 QObject *parent): QObject()
4352{
4354 target = ptarget;
4355}
4356
4357/************************************************************************/
4361{
4362 // Allocated as renegade in model
4363 if (target != nullptr) {
4364 delete target;
4365 }
4366}
4367
4368/************************************************************************/
4372{
4373 return QVariant::fromValue((void *)target);
4374}
4375
4376/************************************************************************/
4380{
4381 return false;
4382}
4383
4384/************************************************************************/
4388 bool su, bool sw, bool sb,
4389 QObject *parent)
4390 : QAbstractListModel(parent)
4391{
4392 show_units = su;
4393 show_wonders = sw;
4395 mcity = pcity;
4396 future_t = f;
4397 populate();
4398}
4399
4400/************************************************************************/
4408
4409/************************************************************************/
4413{
4414 if (!index.isValid()) {
4415 return QVariant();
4416 }
4417
4418 if (index.row() >= 0 && index.row() < rowCount() && index.column() >= 0
4419 && index.column() < columnCount()
4420 && (index.column() + index.row() * 3 < city_target_list.count())) {
4421 int r, c, t, new_index;
4422
4423 r = index.row();
4424 c = index.column();
4425 t = r * 3 + c;
4426 new_index = t / 3 + rowCount() * c;
4427 // Exception, shift whole column
4428 if ((c == 2) && city_target_list.count() % 3 == 1) {
4429 new_index = t / 3 + rowCount() * c - 1;
4430 }
4431 if (role == Qt::ToolTipRole) {
4433 }
4434
4435 return city_target_list[new_index]->data();
4436 }
4437
4438 return QVariant();
4439}
4440
4441/************************************************************************/
4445{
4447 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
4448 struct item items[MAX_NUM_PRODUCTION_TARGETS];
4449 struct universal *renegade;
4450 int item, targets_used;
4451 QString str;
4453 QFontMetrics fm(f);
4454
4455 sh.setY(fm.height() * 2);
4456 sh.setX(0);
4457
4459 city_target_list.clear();
4460
4462 future_t);
4463 name_and_sort_items(targets, targets_used, items, false, mcity);
4464
4465 for (item = 0; item < targets_used; item++) {
4466 if (future_t || can_city_build_now(&(wld.map), mcity, &items[item].item)) {
4467 renegade = new universal(items[item].item);
4468
4469 // Renegade deleted in production_item destructor
4470 if (VUT_UTYPE == renegade->kind) {
4471 str = utype_name_translation(renegade->value.utype);
4472 sh.setX(qMax(sh.x(), fm.horizontalAdvance(str)));
4473
4474 if (show_units) {
4475 pi = new production_item(renegade, this);
4477 } else {
4478 delete renegade;
4479 }
4480 } else {
4481 str = improvement_name_translation(renegade->value.building);
4482 sh.setX(qMax(sh.x(), fm.horizontalAdvance(str)));
4483
4484 if ((is_wonder(renegade->value.building) && show_wonders)
4485 || (is_improvement(renegade->value.building) && show_buildings)
4486 || (is_convert_improvement(renegade->value.building))
4487 || (is_special_improvement(renegade->value.building)
4488 && show_buildings)) {
4489 pi = new production_item(renegade, this);
4491 } else {
4492 delete renegade;
4493 }
4494 }
4495 }
4496 }
4497
4498 pi = new production_item(nullptr, this);
4500 sh.setX(2 * sh.y() + sh.x());
4501 sh.setX(qMin(sh.x(), 250));
4502}
4503
4504/************************************************************************/
4508 const QVariant &value, int role)
4509{
4510 if (!index.isValid() || role != Qt::DisplayRole || role != Qt::ToolTipRole)
4511 return false;
4512
4513 if (index.row() >= 0 && index.row() < rowCount() && index.column() >= 0
4514 && index.column() < columnCount()) {
4515 bool change = city_target_list[index.row()]->setData();
4516 return change;
4517 }
4518
4519 return false;
4520}
4521
4522/************************************************************************/
4531 bool future, int when, int curr,
4532 bool show_units, bool buy,
4533 bool show_wonders,
4534 bool show_buildings): QTableView()
4535{
4536 QPoint pos, sh;
4537 QRect rect = QApplication::primaryScreen()->availableGeometry();
4538 int desk_width = rect.width();
4539 int desk_height = rect.height();
4540 fc_tt = new fc_tooltip(this);
4541 setAttribute(Qt::WA_DeleteOnClose);
4542 setWindowFlags(Qt::Popup);
4543 verticalHeader()->setVisible(false);
4544 horizontalHeader()->setVisible(false);
4545 setProperty("showGrid", false);
4547 sh_units = show_units;
4548 pw_city = pcity;
4549 buy_it = buy;
4550 when_change = when;
4551 list_model = new city_production_model(pw_city, future, show_units,
4552 show_wonders, show_buildings, this);
4553 sh = list_model->sh;
4554 c_p_d = new city_production_delegate(sh, this, pw_city);
4557 viewport()->installEventFilter(fc_tt);
4558 installEventFilter(this);
4560 const QItemSelection &)),
4562 const QItemSelection &)));
4565 setFixedWidth(3 * sh.x() + 6);
4566 setFixedHeight(list_model->rowCount()*sh.y() + 6);
4567
4568 if (width() > desk_width) {
4570 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
4571 } else {
4572 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
4573 }
4574
4575 if (height() > desk_height) {
4577 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
4578 } else {
4579 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
4580 }
4581
4582 pos = QCursor::pos();
4583
4584 if (pos.x() + width() > desk_width) {
4585 pos.setX(desk_width - width());
4586 } else if (pos.x() - width() < 0) {
4587 pos.setX(0);
4588 }
4589
4590 if (pos.y() + height() > desk_height) {
4591 pos.setY(desk_height - height());
4592 } else if (pos.y() - height() < 0) {
4593 pos.setY(0);
4594 }
4595
4596 move(pos);
4597 setMouseTracking(true);
4598 setFocus();
4599}
4600
4601/************************************************************************/
4605{
4606 if (event->button() == Qt::RightButton) {
4607 close();
4608 return;
4609 }
4610
4611 QAbstractItemView::mousePressEvent(event);
4612}
4613
4614/************************************************************************/
4618{
4619 QRect pw_rect;
4620 QPoint br;
4621
4622 if (obj != this)
4623 return false;
4624
4625 if (ev->type() == QEvent::MouseButtonPress) {
4626 pw_rect.setTopLeft(pos());
4627 br.setX(pos().x() + width());
4628 br.setY(pos().y() + height());
4629 pw_rect.setBottomRight(br);
4630
4631 if (!pw_rect.contains(QCursor::pos())) {
4632 close();
4633 }
4634 }
4635
4636 return false;
4637}
4638
4639/************************************************************************/
4643 const QItemSelection &ds)
4644{
4645 QModelIndexList indexes = selectionModel()->selectedIndexes();
4646 QModelIndex index;
4647 QVariant qvar;
4648 struct worklist queue;
4649 struct universal *target;
4650
4651 if (indexes.isEmpty() || client_is_observer()) {
4652 return;
4653 }
4654 index = indexes.at(0);
4655 qvar = index.data(Qt::UserRole);
4656 if (!qvar.isValid()) {
4657 return;
4658 }
4659 target = reinterpret_cast<universal *>(qvar.value<void *>());
4660 if (target != nullptr) {
4661 city_get_queue(pw_city, &queue);
4662 switch (when_change) {
4663 case 0: // Change current target
4665 if (city_can_buy(pw_city) && buy_it) {
4667 }
4668 break;
4669
4670 case 1: // Change current (selected on list)
4673 } else {
4675 worklist_insert(&queue, target, curr_selection);
4676 city_set_queue(pw_city, &queue);
4677 }
4678 break;
4679
4680 case 2: // Insert before
4682 curr_selection = 0;
4683 }
4686 worklist_insert(&queue, target, curr_selection);
4687 city_set_queue(pw_city, &queue);
4688 break;
4689
4690 case 3: // Insert after
4692 city_queue_insert(pw_city, -1, target);
4693 break;
4694 }
4696 worklist_insert(&queue, target, curr_selection);
4697 city_set_queue(pw_city, &queue);
4698 break;
4699
4700 case 4: // Add last
4701 city_queue_insert(pw_city, -1, target);
4702 break;
4703
4704 default:
4705 break;
4706 }
4707 }
4708 close();
4709 destroy();
4710}
4711
4712/************************************************************************/
4716{
4717 delete c_p_d;
4718 delete list_model;
4719 viewport()->removeEventFilter(fc_tt);
4720 removeEventFilter(this);
4721}
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:714
#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:3856
void qtg_real_city_dialog_refresh(struct city *pcity)
Definition citydlg.cpp:3876
QString split_text(QString text, bool cut)
Definition optiondlg.cpp:62
void city_font_update()
Definition citydlg.cpp:3890
bool qtg_city_dialog_is_open(struct city *pcity)
Definition citydlg.cpp:3931
QString get_tooltip(QVariant qvar)
Definition citydlg.cpp:4130
void qtg_popdown_all_city_dialogs()
Definition citydlg.cpp:3868
static city_dialog * city_dlg
Definition citydlg.cpp:75
void qtg_refresh_unit_city_dialogs(struct unit *punit)
Definition citydlg.cpp:3915
static QString bold(QString text)
Definition citydlg.cpp:3992
void qtg_real_city_dialog_popup(struct city *pcity)
Definition citydlg.cpp:3828
QString get_tooltip_improvement(const impr_type *building, struct city *pcity, bool ext)
Definition citydlg.cpp:4001
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:4060
void destroy_city_dialog()
Definition citydlg.cpp:3843
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:4168
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition citydlg.cpp:4181
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition citydlg.cpp:4337
struct city * pcity
Definition citydlg.h:319
void drawFocus(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect) const
Definition citydlg.cpp:4320
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:4507
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:4387
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition citydlg.cpp:4412
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:3947
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:4371
production_item(struct universal *ptarget, QObject *parent)
Definition citydlg.cpp:4350
bool eventFilter(QObject *obj, QEvent *ev)
Definition citydlg.cpp:4617
void prod_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:4642
void mousePressEvent(QMouseEvent *event)
Definition citydlg.cpp:4604
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:4530
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:4947
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int cost
Definition dialogs_g.h:74
int int id
Definition editgui_g.h:28
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:842
enum event_type event
Definition events.c:81
struct extra_type * next_extra_for_tile(const struct tile *ptile, enum extra_cause cause, const struct player *pplayer, const struct unit *punit)
Definition extras.c:779
struct extra_type * prev_extra_in_tile(const struct tile *ptile, enum extra_rmcause rmcause, const struct player *pplayer, const struct unit *punit)
Definition extras.c:804
enum extra_cause activity_to_extra_cause(enum unit_activity act)
Definition extras.c:1090
enum extra_rmcause activity_to_extra_rmcause(enum unit_activity act)
Definition extras.c:1111
#define extra_index(_e_)
Definition extras.h:183
unsigned char citizens
Definition fc_types.h:248
#define EC_NONE
Definition fc_types.h:820
@ TR_SUCCESS
Definition fc_types.h:953
#define ERM_NONE
Definition fc_types.h:843
@ O_SHIELD
Definition fc_types.h:102
@ O_FOOD
Definition fc_types.h:102
@ O_TRADE
Definition fc_types.h:102
@ O_SCIENCE
Definition fc_types.h:102
@ O_LUXURY
Definition fc_types.h:102
@ O_GOLD
Definition fc_types.h:102
@ O_LAST
Definition fc_types.h:102
const char * skip_intl_qualifier_prefix(const char *str)
Definition fcintl.c:48
#define Q_(String)
Definition fcintl.h:70
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
const char * population_to_text(int thousand_citizen)
Definition game.c: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:4001
QString get_tooltip(QVariant qvar)
Definition citydlg.cpp:4130
void set_theme_style()
Definition themes.cpp:107
#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:1992
char * helptext_unit_upkeep_str(const struct unit_type *utype)
Definition helpdata.c:5049
char * helptext_building(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, const struct impr_type *pimprove)
Definition helpdata.c:1439
int impr_sell_gold(const struct impr_type *pimprove)
enum test_result test_player_sell_building_now(struct player *pplayer, struct city *pcity, const struct impr_type *pimprove)
bool is_special_improvement(const struct impr_type *pimprove)
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
bool is_improvement(const struct impr_type *pimprove)
Impr_type_id improvement_number(const struct impr_type *pimprove)
int impr_build_shield_cost(const struct city *pcity, const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool is_convert_improvement(const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
int impr_estimate_build_shield_cost(const struct player *pplayer, const struct tile *ptile, const struct impr_type *pimprove)
const char * name
Definition inputfile.c:127
#define fc_assert_ret(condition)
Definition log.h:192
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_action(condition, action)
Definition log.h:188
void put_unit(const struct unit *punit, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
void put_unit_city_overlays(struct unit *punit, struct canvas *pcanvas, int canvas_x, int canvas_y, int *upkeep_cost, int happy_cost)
void center_tile_mapcanvas(const struct tile *ptile)
const char * move_points_text(int mp, bool reduce)
Definition movement.c:1066
static mpgui * gui
Definition mpgui_qt.cpp: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:1953
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:3267
int current_building
Definition citydlg.h:513
void worklist_up()
Definition citydlg.cpp:3698
city_label * citizens_label
Definition citydlg.h:456
QPushButton * lcity_name
Definition citydlg.h:499
void show_happiness()
Definition citydlg.cpp:2128
void closeEvent(QCloseEvent *event)
Definition citydlg.cpp:2325
void show_counters()
Definition citydlg.cpp:2163
void update_nation_table()
Definition citydlg.cpp:3069
void hideEvent(QHideEvent *event)
Definition citydlg.cpp:2297
void cma_toggle_changed_depr(int state)
Definition citydlg.cpp:2708
QPushButton * work_next_but
Definition citydlg.h:487
void next_city()
Definition citydlg.cpp:3377
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:2308
QPushButton * happiness_button
Definition citydlg.h:491
void cma_double_clicked(int row, int column)
Definition citydlg.cpp:2501
void display_worklist_menu(const QPoint &p)
Definition citydlg.cpp:2785
void update_disabled()
Definition citydlg.cpp:2198
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:2885
int selected_row_p
Definition citydlg.h:500
QHBoxLayout * leftbot_layout
Definition citydlg.h:451
void update_building()
Definition citydlg.cpp:3449
QPushButton * zoom_in_button
Definition citydlg.h:493
void save_worklist()
Definition citydlg.cpp:3764
void worklist_del()
Definition citydlg.cpp:3723
QGridLayout * info_grid_layout
Definition citydlg.h:458
void clear_worklist()
Definition citydlg.cpp:3683
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:2416
void zoom_in()
Definition citydlg.cpp:2403
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:3146
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:2744
void update_citizens()
Definition citydlg.cpp:2911
QRadioButton * r1
Definition citydlg.h:481
void cma_slider(int val)
Definition citydlg.cpp:2719
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:3740
void update_title()
Definition citydlg.cpp:3795
QLabel * cma_info_text
Definition citydlg.h:465
void dbl_click_p(QTableWidgetItem *item)
Definition citydlg.cpp:3283
QPushButton * cma_enable_but
Definition citydlg.h:484
QLabel * cma_result
Definition citydlg.h:466
void cma_remove()
Definition citydlg.cpp:2669
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:2336
QSplitter * prod_unit_splitter
Definition citydlg.h:448
QVBoxLayout * left_layout
Definition citydlg.h:454
void prev_city()
Definition citydlg.cpp:3413
void city_rename()
Definition citydlg.cpp:2373
void refresh()
Definition citydlg.cpp:2995
void update_cma_tab()
Definition citydlg.cpp:2602
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:3652
city_dialog(QWidget *parent=nullptr)
Definition citydlg.cpp:1482
void cma_toggle_changed(Qt::CheckState state)
Definition citydlg.cpp:2696
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:2107
QPushButton * prev_city_but
Definition citydlg.h:486
void cma_enable()
Definition citydlg.cpp:2465
QLabel * cma_result_pix
Definition citydlg.h:467
struct city * dlgcity
Definition citydlg.h:508
void update_counters_table()
Definition citydlg.cpp:3027
void update_sliders()
Definition citydlg.cpp:2550
void update_improvements()
Definition citydlg.cpp:3517
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:2062
void cma_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:2520
QCheckBox * cma_max_growth
Definition citydlg.h:476
void item_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:3359
void show_targets_worklist()
Definition citydlg.cpp:3668
QCheckBox * show_wonders
Definition citydlg.h:480
void cma_context_menu(const QPoint &p)
Definition citydlg.cpp:2765
void cma_changed()
Definition citydlg.cpp:2480
QPushButton * buy_button
Definition citydlg.h:483
QRadioButton * r4
Definition citydlg.h:481
struct city_dialog::@149 counters
void update_units()
Definition citydlg.cpp:3300
QRadioButton * r2
Definition citydlg.h:481
QTableWidget * p_table_p
Definition citydlg.h:472
void save_cma()
Definition citydlg.cpp:2429
QPixmap * citizen_pixmap
Definition citydlg.h:495
void production_changed(int index)
Definition citydlg.cpp:3634
void update_prod_buttons()
Definition citydlg.cpp:2235
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:521
int firepower
Definition unittype.h:530
const struct unit_type * obsoleted_by
Definition unittype.h:534
int vision_radius_sq
Definition unittype.h:527
int move_rate
Definition unittype.h:522
int attack_strength
Definition unittype.h:520
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:609
universals_u value
Definition fc_types.h:608
struct universal entries[MAX_LEN_WORKLIST]
Definition worklist.h:30
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#define TRUE
Definition support.h:46
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
bool is_future_tech(Tech_type_id tech)
Definition tech.c:281
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:300
struct advance * valid_advance_by_number(const Tech_type_id id)
Definition tech.c:176
#define A_NONE
Definition tech.h:43
const char * text_happiness_nationality(const struct city *pcity)
Definition text.c:1881
const char * text_happiness_wonders(const struct city *pcity)
Definition text.c:1923
const char * text_happiness_units(const struct city *pcity)
Definition text.c:2087
const char * text_happiness_luxuries(const struct city *pcity)
Definition text.c:2126
const char * text_happiness_buildings(const struct city *pcity)
Definition text.c:1853
const char * unit_description(struct unit *punit)
Definition text.c:528
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_terrain(_tile)
Definition tile.h:115
int tileset_hex_width(const struct tileset *t)
Definition tilespec.c:747
struct sprite * get_building_sprite(const struct tileset *t, const struct impr_type *pimprove)
Definition tilespec.c:7020
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:7224
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:6959
struct sprite * get_unittype_sprite(const struct tileset *t, const struct unit_type *punittype, enum unit_activity activity, enum direction8 facing)
Definition tilespec.c:7042
struct sprite * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:6993
struct sprite * get_tech_sprite(const struct tileset *t, Tech_type_id tech)
Definition tilespec.c:7011
@ ICON_CITYDLG
Definition tilespec.h:314
const struct unit_type * utype
Definition fc_types.h:554
const struct impr_type * building
Definition fc_types.h:547
bool can_unit_change_homecity(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:523
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:401
#define unit_tile(_pu)
Definition unit.h:407
#define unit_owner(_pu)
Definition unit.h:406
bool units_are_occupied(const struct unit_list *punits)
Definition unitlist.c:275
bool units_can_unload(const struct civ_map *nmap, const struct unit_list *punits)
Definition unitlist.c:303
bool units_can_upgrade(const struct civ_map *nmap, const struct unit_list *punits)
Definition unitlist.c:337
bool units_can_load(const struct unit_list *punits)
Definition unitlist.c:289
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
int utype_build_shield_cost_base(const struct unit_type *punittype)
Definition unittype.c:1472
bool utype_is_consumed_by_action_result(enum action_result result, const struct unit_type *utype)
Definition unittype.c:1233
struct advance * utype_primary_tech_req(const struct unit_type *ptype)
Definition unittype.c:2714
bool utype_can_do_action_result(const struct unit_type *putype, enum action_result result)
Definition unittype.c:391
int utype_build_shield_cost(const struct city *pcity, const struct player *pplayer, const struct unit_type *punittype)
Definition unittype.c:1442
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1564
const char * utype_values_translation(const struct unit_type *punittype)
Definition unittype.c:1621
static bool uclass_has_flag(const struct unit_class *punitclass, enum unit_class_flag_id flag)
Definition unittype.h:771
#define utype_class(_t_)
Definition unittype.h:754
#define utype_fuel(ptype)
Definition unittype.h:844
static bool utype_has_flag(const struct unit_type *punittype, int flag)
Definition unittype.h:622
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