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}
2056
2057/************************************************************************/
2061{
2062
2063 cid cprod;
2064 int i, pos;
2065 int item, targets_used;
2067 QString str;
2068 struct item items[MAX_NUM_PRODUCTION_TARGETS];
2069 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
2070 struct universal univ;
2071
2072 pos = 0;
2075 name_and_sort_items(targets, targets_used, items, false, dlgcity);
2076
2077 for (item = 0; item < targets_used; item++) {
2078 if (can_city_build_now(&(wld.map), dlgcity, &items[item].item)) {
2079 prod_list << cid_encode(items[item].item);
2080 }
2081 }
2082
2083 for (i = 0; i < prod_list.size(); i++) {
2084 if (prod_list.at(i) == cprod) {
2085 if (next) {
2086 pos = i + 1;
2087 } else {
2088 pos = i - 1;
2089 }
2090 }
2091 }
2092 if (pos == prod_list.size()) {
2093 pos = 0;
2094 }
2095 if (pos == - 1) {
2096 pos = prod_list.size() - 1;
2097 }
2098 univ = cid_decode(static_cast<cid>(prod_list.at(pos)));
2100}
2101
2102/************************************************************************/
2106{
2107 if (current_tab == happiness) {
2108 happiness_button->setToolTip(_("Show city production"));
2109 counterss_button->setToolTip(_("Show counters information"));
2110
2111 } else {
2112 happiness_button->setToolTip(_("Show happiness information"));
2113
2114 if (current_tab == counters) {
2115 counterss_button->setToolTip(_("Show city production"));
2116 }
2117 else {
2118 counterss_button->setToolTip(_("Show counters information"));
2119 }
2120 }
2121}
2122
2123/************************************************************************/
2127{
2129 setUpdatesEnabled(false);
2130
2131
2132 if (current_tab != happiness) {
2133 leftbot_layout->replaceWidget(active_tab,
2135 Qt::FindDirectChildrenOnly);
2136 active_tab->hide();
2137 happiness_widget->show();
2138 happiness_widget->updateGeometry();
2140 } else {
2141 /* We do not change prod_unit_splitter to current_tab,
2142 * because happiness is active tab and clicked -
2143 * switching to default */
2144 leftbot_layout->replaceWidget(happiness_widget,
2146 Qt::FindDirectChildrenOnly);
2147 prod_unit_splitter->show();
2148 prod_unit_splitter->updateGeometry();
2149 happiness_widget->hide();
2151 }
2152
2153 setUpdatesEnabled(true);
2154 update();
2155 update_tabs();
2156}
2157
2158/************************************************************************/
2162{
2164 setUpdatesEnabled(false);
2165
2166
2167 if (current_tab != counters) {
2168 leftbot_layout->replaceWidget(active_tab,
2170 Qt::FindDirectChildrenOnly);
2171 active_tab->hide();
2172 counterss_frame->show();
2173 counterss_frame->updateGeometry();
2175 } else {
2176 /* We do not change prod_unit_splitter to current_tab,
2177 * because counters is active tab and clicked -
2178 * switching to default */
2179 leftbot_layout->replaceWidget(counterss_frame,
2181 Qt::FindDirectChildrenOnly);
2182 prod_unit_splitter->show();
2183 prod_unit_splitter->updateGeometry();
2184 counterss_frame->hide();
2186 }
2187
2188 setUpdatesEnabled(true);
2189 update();
2190 update_tabs();
2191}
2192
2193/************************************************************************/
2197{
2198 struct player *pplayer = client_player();
2199
2200 if (pplayer == nullptr
2201 || city_owner(dlgcity) != pplayer) {
2202 prev_city_but->setDisabled(true);
2203 next_city_but->setDisabled(true);
2204 buy_button->setDisabled(true);
2205 cma_enable_but->setDisabled(true);
2206 production_combo_p->setDisabled(true);
2207 current_units->setDisabled(true);
2208 supported_units->setDisabled(true);
2209 view->setDisabled(true);
2210 } else {
2211 prev_city_but->setEnabled(true);
2212 next_city_but->setEnabled(true);
2213 buy_button->setEnabled(true);
2214 cma_enable_but->setEnabled(true);
2215 production_combo_p->setEnabled(true);
2216 current_units->setEnabled(true);
2217 supported_units->setEnabled(true);
2218 view->setEnabled(true);
2219 }
2220
2222 cma_enable_but->setEnabled(true);
2223 } else {
2224 cma_enable_but->setDisabled(true);
2225 }
2226
2228}
2229
2230/************************************************************************/
2234{
2235 struct player *pplayer = client_player();
2236
2237 work_next_but->setDisabled(true);
2238 work_prev_but->setDisabled(true);
2239 work_add_but->setDisabled(true);
2240 work_rem_but->setDisabled(true);
2241
2242 if (pplayer != nullptr
2243 && city_owner(dlgcity) == pplayer) {
2244 work_add_but->setEnabled(true);
2245
2246 if (selected_row_p >= 0 && selected_row_p < p_table_p->rowCount()) {
2247 work_rem_but->setEnabled(true);
2248 }
2249
2250 if (selected_row_p >= 0 && selected_row_p < p_table_p->rowCount() - 1) {
2251 work_next_but->setEnabled(true);
2252 }
2253
2254 if (selected_row_p > 0 && selected_row_p < p_table_p->rowCount()) {
2255 work_prev_but->setEnabled(true);
2256 }
2257 }
2258}
2259
2260/************************************************************************/
2264{
2265 if (citizen_pixmap) {
2266 citizen_pixmap->detach();
2267 delete citizen_pixmap;
2268 }
2269
2270 cma_table->clear();
2271 p_table_p->clear();
2272 nationality_table->clear();
2274 supported_units->clear_layout();
2275 removeEventFilter(this);
2276 ::city_dlg_created = false;
2277
2278 // Delete the one widget that currently does NOT have a parent
2279 if (current_tab == common) {
2280 delete happiness_widget;
2281 delete counterss_frame;
2282 }
2283 else if (current_tab == counters) {
2284 delete happiness_widget;
2285 delete prod_unit_splitter;
2286 }else {
2287 delete counterss_frame;
2288 delete prod_unit_splitter;
2289 }
2290}
2291
2292/************************************************************************/
2296{
2297 gui()->qt_settings.city_geometry = saveGeometry();
2298 gui()->qt_settings.city_splitter1 = prod_unit_splitter->saveState();
2299 gui()->qt_settings.city_splitter2 = central_left_splitter->saveState();
2300 gui()->qt_settings.city_splitter3 = central_splitter->saveState();
2301}
2302
2303/************************************************************************/
2307{
2308 if (!gui()->qt_settings.city_geometry.isNull()) {
2309 restoreGeometry(gui()->qt_settings.city_geometry);
2310 prod_unit_splitter->restoreState(gui()->qt_settings.city_splitter1);
2311 central_left_splitter->restoreState(gui()->qt_settings.city_splitter2);
2312 central_splitter->restoreState(gui()->qt_settings.city_splitter3);
2313 } else {
2314 QRect rect = QApplication::primaryScreen()->availableGeometry();
2315
2316 resize((rect.width() * 4) / 5, (rect.height() * 5) / 6);
2317 }
2318}
2319
2320/************************************************************************/
2324{
2325 gui()->qt_settings.city_geometry = saveGeometry();
2326 gui()->qt_settings.city_splitter1 = prod_unit_splitter->saveState();
2327 gui()->qt_settings.city_splitter2 = central_left_splitter->saveState();
2328 gui()->qt_settings.city_splitter3 = central_splitter->saveState();
2329}
2330
2331/************************************************************************/
2334bool city_dialog::eventFilter(QObject *obj, QEvent *event)
2335{
2336
2337 if (obj == this) {
2338 if (event->type() == QEvent::KeyPress) {
2339 }
2340
2341 if (event->type() == QEvent::ShortcutOverride) {
2342 QKeyEvent *key_event = static_cast<QKeyEvent *>(event);
2343 if (key_event->key() == Qt::Key_Right) {
2344 next_city();
2345 event->setAccepted(true);
2346 return true;
2347 }
2348 if (key_event->key() == Qt::Key_Left) {
2349 prev_city();
2350 event->setAccepted(true);
2351 return true;
2352 }
2353 if (key_event->key() == Qt::Key_Up) {
2354 change_production(true);
2355 event->setAccepted(true);
2356 return true;
2357 }
2358 if (key_event->key() == Qt::Key_Down) {
2359 change_production(false);
2360 event->setAccepted(true);
2361 return true;
2362 }
2363 }
2364 }
2365 return QObject::eventFilter(obj, event);
2366}
2367
2368/************************************************************************/
2372{
2374 const int city_id = dlgcity->id;
2375
2376 if (!can_client_issue_orders()) {
2377 return;
2378 }
2379
2380 ask = new hud_input_box(gui()->central_wdg);
2381 ask->set_text_title_definput(_("What should we rename the city to?"),
2382 _("Rename City"), city_name_get(dlgcity));
2383 ask->setAttribute(Qt::WA_DeleteOnClose);
2384 connect(ask, &hud_message_box::accepted, this, [=]() {
2385 struct city *pcity = game_city_by_number(city_id);
2387
2388 if (!pcity) {
2389 return;
2390 }
2391
2392 ask_bytes = ask->input_edit.text().toUtf8();
2393 ::city_rename(pcity, ask_bytes.data());
2394 });
2395 ask->show();
2396}
2397
2398/************************************************************************/
2402{
2403 zoom = zoom * 1.2;
2404 if (dlgcity) {
2405 view->set_pixmap(dlgcity, zoom);
2406 }
2408 left_layout->update();
2409}
2410
2411/************************************************************************/
2415{
2416 zoom = zoom / 1.2;
2417 if (dlgcity) {
2418 view->set_pixmap(dlgcity, zoom);
2419 }
2421 left_layout->update();
2422}
2423
2424/************************************************************************/
2428{
2429 hud_input_box *ask = new hud_input_box(gui()->central_wdg);
2430
2431 ask->set_text_title_definput(_("What should we name the preset?"),
2432 _("Name new preset"),
2433 _("new preset"));
2434 ask->setAttribute(Qt::WA_DeleteOnClose);
2435 connect(ask, &hud_message_box::accepted, this,
2437 struct cm_parameter param;
2438 QByteArray ask_bytes = ask->input_edit.text().toUtf8();
2439 QString text = ask_bytes.data();
2440 if (!text.isEmpty()) {
2441 param.allow_disorder = false;
2442 param.allow_specialists = true;
2443 param.require_happy = cma_celeb_checkbox->isChecked();
2444 param.max_growth = cma_max_growth->isChecked();
2445 param.happy_factor = slider_tab[2 * O_LAST + 1]->value();
2446
2447 for (int i = O_FOOD; i < O_LAST; i++) {
2448 param.minimal_surplus[i] = slider_tab[2 * i]->value();
2449 param.factor[i] = slider_tab[2 * i + 1]->value();
2450 }
2451
2452 ask_bytes = text.toUtf8();
2453 cmafec_preset_add(ask_bytes.data(), &param);
2455 }
2456 });
2457 ask->show();
2458}
2459
2460/************************************************************************/
2464{
2465 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2467
2468 return;
2469 }
2470
2471 cma_changed();
2473}
2474
2475/************************************************************************/
2479{
2480 struct cm_parameter param;
2481
2482 param.allow_disorder = false;
2483 param.allow_specialists = true;
2484 param.require_happy = cma_celeb_checkbox->isChecked();
2485 param.max_growth = cma_max_growth->isChecked();
2486 param.happy_factor = slider_tab[2 * O_LAST + 1]->value();
2487
2488 for (int i = O_FOOD; i < O_LAST; i++) {
2489 param.minimal_surplus[i] = slider_tab[2 * i]->value();
2490 param.factor[i] = slider_tab[2 * i + 1]->value();
2491 }
2492
2494}
2495
2496/************************************************************************/
2500{
2501 const struct cm_parameter *param;
2502
2503 if (!can_client_issue_orders()) {
2504 return;
2505 }
2507 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2509 }
2510
2513}
2514
2515/************************************************************************/
2519 const QItemSelection &ds)
2520{
2521 const struct cm_parameter *param;
2522 QModelIndex index;
2523 QModelIndexList indexes = sl.indexes();
2524
2525 if (indexes.isEmpty() || cma_table->signalsBlocked()) {
2526 return;
2527 }
2528
2529 index = indexes.at(0);
2530 int ind = index.row();
2531
2532 if (cma_table->currentRow() == -1 || cmafec_preset_num() == 0) {
2533 return;
2534 }
2535
2538
2539 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2542 }
2543}
2544
2545/************************************************************************/
2549{
2550 struct cm_parameter param;
2551 const struct cm_parameter *cparam;
2552 int output;
2553 QVariant qvar;
2554 QLabel *label;
2555
2556 if (!cma_is_city_under_agent(dlgcity, &param)) {
2557 if (cma_table->currentRow() == -1 || cmafec_preset_num() == 0) {
2558 return;
2559 }
2561 cm_copy_parameter(&param, cparam);
2562 }
2563
2564 for (output = O_FOOD; output < 2 * O_LAST; output++) {
2565 slider_tab[output]->blockSignals(true);
2566 }
2567
2568 for (output = O_FOOD; output < O_LAST; output++) {
2569 qvar = slider_tab[2 * output + 1]->property("FC");
2570 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2571 label->setText(QString::number(param.factor[output]));
2572 slider_tab[2 * output + 1]->setValue(param.factor[output]);
2573 qvar = slider_tab[2 * output]->property("FC");
2574 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2575 label->setText(QString::number(param.minimal_surplus[output]));
2576 slider_tab[2 * output]->setValue(param.minimal_surplus[output]);
2577 }
2578
2579 slider_tab[2 * O_LAST + 1]->blockSignals(true);
2580 qvar = slider_tab[2 * O_LAST + 1]->property("FC");
2581 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2582 label->setText(QString::number(param.happy_factor));
2583 slider_tab[2 * O_LAST + 1]->setValue(param.happy_factor);
2584 slider_tab[2 * O_LAST + 1]->blockSignals(false);
2585 cma_celeb_checkbox->blockSignals(true);
2586 cma_celeb_checkbox->setChecked(param.require_happy);
2587 cma_celeb_checkbox->blockSignals(false);
2588 cma_max_growth->blockSignals(true);
2589 cma_max_growth->setChecked(param.max_growth);
2590 cma_max_growth->blockSignals(false);
2591
2592 for (output = O_FOOD; output < 2 * O_LAST; output++) {
2593 slider_tab[output]->blockSignals(false);
2594 }
2595}
2596
2597/************************************************************************/
2601{
2602 QString s;
2604 struct cm_parameter param;
2605 QPixmap pix;
2606 int i;
2607
2608 cma_table->clear();
2609 cma_table->setRowCount(0);
2610
2611 for (i = 0; i < cmafec_preset_num(); i++) {
2612 item = new QTableWidgetItem;
2613 item->setText(cmafec_preset_get_descr(i));
2614 cma_table->insertRow(i);
2615 cma_table->setItem(i, 0, item);
2616 }
2617
2618 if (cmafec_preset_num() == 0) {
2619 cma_table->insertRow(0);
2620 item = new QTableWidgetItem;
2621 item->setText(_("No governor defined"));
2622 cma_table->setItem(0, 0, item);
2623 }
2624
2625 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2626 view->update();
2628 pix = style()->standardPixmap(QStyle::SP_DialogApplyButton);
2629 pix = pix.scaled(2 * pix.width(), 2 * pix.height(),
2630 Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
2631 cma_result_pix->setPixmap(pix);
2632 cma_result_pix->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
2633 // TRANS: %1 is custom string chosen by player
2634 cma_result->setText(QString(_("<h3>Governor Enabled<br>(%1)</h3>"))
2635 .arg(s.toHtmlEscaped()));
2636 cma_result->setAlignment(Qt::AlignCenter);
2637 } else {
2638 pix = style()->standardPixmap(QStyle::SP_DialogCancelButton);
2639 pix = pix.scaled(1.6 * pix.width(), 1.6 * pix.height(),
2640 Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
2641 cma_result_pix->setPixmap(pix);
2642 cma_result_pix->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
2643 cma_result->setText(QString(_("<h3>Governor Disabled</h3>")));
2644 cma_result->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
2645 }
2646
2647 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2650 cm_parameter *const >(&param));
2651 if (i >= 0 && i < cma_table->rowCount()) {
2652 cma_table->blockSignals(true);
2653 cma_table->setCurrentCell(i, 0);
2654 cma_table->blockSignals(false);
2655 }
2656
2657 cma_enable_but->setText(_("Disable"));
2658 } else {
2659 cma_enable_but->setText(_("Enable"));
2660 }
2662}
2663
2664/************************************************************************/
2668{
2669 int i;
2671
2672 i = cma_table->currentRow();
2673
2674 if (i == -1 || cmafec_preset_num() == 0) {
2675 return;
2676 }
2677
2679 ask->set_text_title(_("Remove this preset?"), cmafec_preset_get_descr(i));
2680 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
2681 ask->setDefaultButton(QMessageBox::Cancel);
2682 ask->setAttribute(Qt::WA_DeleteOnClose);
2683 connect(ask, &hud_message_box::accepted, this,
2687 });
2688 ask->show();
2689}
2690
2691/************************************************************************/
2694void city_dialog::cma_toggle_changed(Qt::CheckState state)
2695{
2696 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2697 cma_changed();
2699 }
2700}
2701
2702/************************************************************************/
2707{
2708 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2709 cma_changed();
2711 }
2712}
2713
2714/************************************************************************/
2718{
2719 QVariant qvar;
2720 QSlider *slider;
2721 QLabel *label;
2722
2724 qvar = slider->property("FC");
2725
2726 if (qvar.isNull() || !qvar.isValid()) {
2727 return;
2728 }
2729
2730 label = reinterpret_cast<QLabel *>(qvar.value<void *>());
2731 label->setText(QString::number(value));
2732
2733 if (cma_is_city_under_agent(dlgcity, nullptr)) {
2734 cma_changed();
2736 }
2737}
2738
2739/************************************************************************/
2759
2760/************************************************************************/
2764{
2765 QMenu *cma_menu = new QMenu(this);
2767
2768 cma_menu->setAttribute(Qt::WA_DeleteOnClose);
2769 cma_del_item = cma_menu->addAction(_("Remove Governor"));
2770 connect(cma_menu, &QMenu::triggered, this,
2772 if (act == cma_del_item) {
2773 cma_remove();
2774 }
2775 });
2776
2777 cma_menu->popup(QCursor::pos());
2778}
2779
2780/************************************************************************/
2784{
2785 QAction *action;
2786 QAction *disband;
2791 QMap<QString, cid>::const_iterator map_iter;
2792 QMenu *change_menu;
2793 QMenu *insert_menu;
2794 QMenu *list_menu;
2795 QMenu *options_menu;
2796 int city_id = dlgcity->id;
2797
2798 if (!can_client_issue_orders()) {
2799 return;
2800 }
2801 list_menu = new QMenu(this);
2802 change_menu = list_menu->addMenu(_("Change worklist"));
2803 insert_menu = list_menu->addMenu(_("Insert worklist"));
2804 wl_clear = list_menu->addAction(_("Clear"));
2805 connect(wl_clear, &QAction::triggered, this, &city_dialog::clear_worklist);
2806 list.clear();
2807
2811
2812 if (list.count() == 0) {
2813 wl_empty = change_menu->addAction(_("(no worklists defined)"));
2814 insert_menu->addAction(wl_empty);
2815 }
2816
2817 map_iter = list.constBegin();
2818
2819 while (map_iter != list.constEnd()) {
2820 action = change_menu->addAction(map_iter.key());
2821 action->setData(map_iter.value());
2822
2823 action = insert_menu->addAction(map_iter.key());
2824 action->setData(map_iter.value());
2825
2826 map_iter++;
2827 }
2828
2829 wl_save = list_menu->addAction(_("Save worklist"));
2830 connect(wl_save, &QAction::triggered, this, &city_dialog::save_worklist);
2831 options_menu = list_menu->addMenu(_("Options"));
2832 disband = options_menu->addAction(_("Allow disbanding city"));
2833 disband->setCheckable(true);
2834 disband->setChecked(is_city_option_set(dlgcity, CITYO_DISBAND));
2835 connect(disband, &QAction::triggered, this,
2837
2838 connect(change_menu, &QMenu::triggered, this, [=](QAction *act) {
2839 QVariant id = act->data();
2840 struct city *pcity = game_city_by_number(city_id);
2841 const struct worklist *worklist;
2842
2843 if (!pcity) {
2844 return;
2845 }
2846
2847#ifndef FC_QT5_MODE
2848 fc_assert_ret(id.typeId() == QMetaType::Int);
2849#else // FC_QT5_MODE
2850 fc_assert_ret(id.type() == QVariant::Int);
2851#endif // FC_QT5_MODE
2852
2855 });
2856
2857 connect(insert_menu, &QMenu::triggered, this,
2859 QVariant id = act->data();
2860 struct city *pcity = game_city_by_number(city_id);
2861 const struct worklist *worklist;
2862
2863 if (!pcity) {
2864 return;
2865 }
2866
2867#ifndef FC_QT5_MODE
2868 fc_assert_ret(id.typeId() == QMetaType::Int);
2869#else // FC_QT5_MODE
2870 fc_assert_ret(id.type() == QVariant::Int);
2871#endif // FC_QT5_MODE
2872
2875 });
2876
2877 list_menu->popup(QCursor::pos());
2878}
2879
2880/************************************************************************/
2884{
2885 QString str;
2886 int value;
2887 struct player *pplayer = client_player();
2888
2889 buy_button->setDisabled(true);
2890
2891 if (!client_is_observer() && pplayer != nullptr) {
2892 value = dlgcity->client.buy_cost;
2893 str = QString(PL_("Buy (%1 gold)", "Buy (%1 gold)",
2894 value)).arg(QString::number(value));
2895
2896 if (pplayer->economic.gold >= value && value != 0) {
2897 buy_button->setEnabled(true);
2898 }
2899 } else {
2900 str = QString(_("Buy"));
2901 }
2902
2903 buy_button->setText(str);
2904}
2905
2906/************************************************************************/
2910{
2911 enum citizen_category categories[MAX_CITY_SIZE];
2912 int i, j, width, height;
2913 QPainter p;
2914 QPixmap *pix;
2916 int w = tileset_small_sprite_width(tileset) / gui()->map_scale;
2917 int h = tileset_small_sprite_height(tileset) / gui()->map_scale;
2918
2919 i = 1 + (num_citizens * 5 / 200);
2920 w = w / i;
2921 QRect source_rect(0, 0, w, h);
2922 QRect dest_rect(0, 0, w, h);
2923 width = w * num_citizens;
2924 height = h;
2925
2926 if (citizen_pixmap) {
2927 citizen_pixmap->detach();
2928 delete citizen_pixmap;
2929 }
2930
2932
2933 for (j = 0, i = 0; i < num_citizens; i++, j++) {
2934 dest_rect.moveTo(i * w, 0);
2935 pix = get_citizen_sprite(tileset, categories[j], j, dlgcity)->pm;
2936 p.begin(citizen_pixmap);
2937 p.drawPixmap(dest_rect, *pix, source_rect);
2938 p.end();
2939 }
2940
2942 citizens_label->setPixmap(*citizen_pixmap);
2943
2946
2947 for (int k = 0; k < FEELING_LAST - 1; k++) {
2950 static_cast<citizen_feeling>(k),
2951 categories);
2952
2953 for (j = 0, i = 0; i < num_citizens; i++, j++) {
2954 dest_rect.moveTo(i * w, 0);
2955 pix = get_citizen_sprite(tileset, categories[j], j, dlgcity)->pm;
2956 p.begin(citizen_pixmap);
2957 p.drawPixmap(dest_rect, *pix, source_rect);
2958 p.end();
2959 }
2960
2961 lab_table[k]->setPixmap(*citizen_pixmap);
2962
2963 switch (k) {
2964 case FEELING_BASE:
2965 lab_table[k]->setToolTip(text_happiness_cities(dlgcity));
2966 break;
2967
2968 case FEELING_LUXURY:
2969 lab_table[k]->setToolTip(text_happiness_luxuries(dlgcity));
2970 break;
2971
2972 case FEELING_EFFECT :
2974 break;
2975
2978 break;
2979
2980 case FEELING_MARTIAL:
2981 lab_table[k]->setToolTip(text_happiness_units(dlgcity));
2982 break;
2983
2984 default:
2985 break;
2986 }
2987 }
2988}
2989
2990/************************************************************************/
2994{
2995 setUpdatesEnabled(false);
2996 production_combo_p->blockSignals(true);
2997
2998 if (dlgcity) {
2999 view->set_pixmap(dlgcity, zoom);
3000 view->update();
3001 update_title();
3008 update_units();
3012 } else {
3014 }
3015
3016 production_combo_p->blockSignals(false);
3017 setUpdatesEnabled(true);
3019 update();
3020}
3021
3022/************************************************************************/
3026{
3027 QFont *small_font;
3028
3030
3031 qDeleteAll(counterss_frame->findChildren<QWidget*>("", Qt::FindDirectChildrenOnly));
3033 QString helptext;
3034 char buf[1024];
3035 QLabel *name, *value, *activated, *help;
3036
3037 name = new QLabel(name_translation_get(&pcount->name));
3038 fc_snprintf(buf, sizeof(buf), _("Current value is: %d"),
3040 value = new QLabel(buf);
3041 fc_snprintf(buf, sizeof(buf), _("Activated once value equal "
3042 "or higher than: %d"),
3043 pcount->checkpoint);
3044 activated = new QLabel(buf);
3045 if (pcount->helptext != nullptr) {
3046 strvec_iterate(pcount->helptext, text_) {
3047 helptext += text_;
3049 }
3050 help = new QLabel(helptext);
3051
3052 name->setFont(*small_font);
3053 value->setFont(*small_font);
3054 activated->setFont(*small_font);
3055 help->setFont(*small_font);
3056
3057 counterss_layout->addWidget(name);
3058 counterss_layout->addWidget(value);
3059 counterss_layout->addWidget(activated);
3060 counterss_layout->addWidget(help);
3062}
3063
3064/************************************************************************/
3068{
3069 QFont f = QApplication::font();
3070 QFontMetrics fm(f);
3071 QPixmap *pix = nullptr;
3073 QString str;
3076 char buf[8];
3078 int h;
3079 int i = 0;
3080 struct sprite *sprite;
3081
3082 h = fm.height() + 6;
3083 nationality_table->clear();
3084 nationality_table->setRowCount(0);
3085 info_list.clear();
3086 info_list << _("#") << _("Flag") << _("Nation");
3087 nationality_table->setHorizontalHeaderLabels(info_list);
3088
3089 citizens_iterate(dlgcity, pslot, nationality) {
3090 nationality_table->insertRow(i);
3091
3092 for (int j = 0; j < nationality_table->columnCount(); j++) {
3093 item = new QTableWidgetItem;
3094
3095 switch (j) {
3096 case 0:
3098
3099 if (nationality_i == 0) {
3100 str = "-";
3101 } else {
3102 fc_snprintf(buf, sizeof(buf), "%d", nationality_i);
3103 str = QString(buf);
3104 }
3105
3106 item->setText(str);
3107 break;
3108
3109 case 1:
3112 (player_slot_get_player(pslot)));
3113
3114 if (sprite != nullptr) {
3115 pix = sprite->pm;
3116 pix_scaled = pix->scaledToHeight(h);
3117 item->setData(Qt::DecorationRole, pix_scaled);
3118 } else {
3119 item->setText("FLAG MISSING");
3120 }
3121 break;
3122
3123 case 2:
3125 (player_slot_get_player(pslot)));
3126 break;
3127
3128 default:
3129 break;
3130 }
3131 nationality_table->setItem(i, j, item);
3132 }
3133 i++;
3135 nationality_table->horizontalHeader()->setStretchLastSection(false);
3136 nationality_table->resizeColumnsToContents();
3137 nationality_table->resizeRowsToContents();
3138 nationality_table->horizontalHeader()->setStretchLastSection(true);
3139}
3140
3141/************************************************************************/
3145{
3146 int illness = 0;
3147 char buffer[512];
3148 char buf_info[NUM_INFO_FIELDS][512];
3149 char buf_tooltip[NUM_INFO_FIELDS][512];
3150 int granaryturns;
3151 int spec;
3152
3153 for (int i = 0; i < NUM_INFO_FIELDS; i++) {
3154 buf_info[i][0] = '\0';
3155 buf_tooltip[i][0] = '\0';
3156 }
3157
3158 // Fill the buffers with the necessary info
3159 spec = city_specialists(dlgcity);
3161 "%3d (%4d)", dlgcity->size, spec);
3163 _("Population: %d, Specialists: %d"),
3164 dlgcity->size, spec);
3165 fc_snprintf(buf_info[INFO_FOOD], sizeof(buf_info[INFO_FOOD]), "%3d (%+4d)",
3168 "%3d (%+4d)", dlgcity->prod[O_SHIELD] + dlgcity->waste[O_SHIELD],
3170 fc_snprintf(buf_info[INFO_TRADE], sizeof(buf_info[INFO_TRADE]), "%3d (%+4d)",
3173 fc_snprintf(buf_info[INFO_GOLD], sizeof(buf_info[INFO_GOLD]), "%3d (%+4d)",
3180 "%4d/%-4d", dlgcity->food_stock,
3182
3184 sizeof(buf_tooltip[INFO_FOOD]));
3186 sizeof(buf_tooltip[INFO_SHIELD]));
3188 sizeof(buf_tooltip[INFO_TRADE]));
3190 sizeof(buf_tooltip[INFO_GOLD]));
3192 sizeof(buf_tooltip[INFO_SCIENCE]));
3194 sizeof(buf_tooltip[INFO_LUXURY]));
3196 sizeof(buf_tooltip[INFO_CULTURE]));
3198 sizeof(buf_tooltip[INFO_POLLUTION]));
3200 sizeof(buf_tooltip[INFO_ILLNESS]));
3201
3203
3204 if (granaryturns == 0) {
3205 // TRANS: city growth is blocked. Keep short.
3206 fc_snprintf(buf_info[INFO_GROWTH], sizeof(buf_info[INFO_GROWTH]), _("blocked"));
3207 } else if (granaryturns == FC_INFINITY) {
3208 // TRANS: city is not growing. Keep short.
3209 fc_snprintf(buf_info[INFO_GROWTH], sizeof(buf_info[INFO_GROWTH]), _("never"));
3210 } else {
3211 /* A negative value means we'll have famine in that many turns.
3212 But that's handled down below. */
3213 // TRANS: city growth turns. Keep short.
3215 PL_("%d turn", "%d turns", abs(granaryturns)),
3216 abs(granaryturns));
3217 }
3218
3220 "%4d", dlgcity->waste[O_TRADE]);
3227
3228 if (!game.info.illness_on) {
3230 " -.-");
3231 } else {
3232 illness = city_illness_calc(dlgcity, nullptr, nullptr, nullptr, nullptr);
3233 // Illness is in tenth of percent
3235 "%5.1f%%", (float) illness / 10.0);
3236 }
3237 if (dlgcity->steal) {
3239 PL_("%d time", "%d times", dlgcity->steal), dlgcity->steal);
3240 } else {
3242 _("Not stolen"));
3243 }
3244
3246 sizeof(buf_info[INFO_AIRLIFT]));
3248 sizeof(buf_tooltip[INFO_AIRLIFT]));
3249
3250 get_city_dialog_output_text(dlgcity, O_FOOD, buffer, sizeof(buffer));
3251
3252 for (int i = 0; i < NUM_INFO_FIELDS; i++) {
3253 qlt[i]->setText(QString(buf_info[i]));
3254
3255 if (buf_tooltip[i][0]) {
3256 qlt[i]->setToolTip("<pre>" + QString(buf_tooltip[i]).toHtmlEscaped()
3257 + "</pre>");
3258 }
3259 }
3260}
3261
3262/************************************************************************/
3266{
3269
3270 setContentsMargins(0, 0 ,0 ,0);
3272 dlgcity = qcity;
3273 production_combo_p->blockSignals(true);
3274 refresh();
3275 production_combo_p->blockSignals(false);
3276}
3277
3278/************************************************************************/
3282{
3283 struct worklist queue;
3284
3285 city_get_queue(dlgcity, &queue);
3286
3288 return;
3289 }
3290
3292 city_set_queue(dlgcity, &queue);
3293}
3294
3295/************************************************************************/
3299{
3300 unit_item *ui;
3301 struct unit_list *units;
3302 char buf[256];
3303 int n;
3304 int happy_cost;
3306 struct player *pplayer = client_player();
3307 const struct civ_map *nmap = &(wld.map);
3308
3309 supported_units->setUpdatesEnabled(false);
3310 supported_units->clear_layout();
3311
3312 if (pplayer != nullptr
3313 && city_owner(dlgcity) != pplayer) {
3315 } else {
3316 units = dlgcity->units_supported;
3317 }
3318
3319 unit_list_iterate(units, punit) {
3321 ui = new unit_item(this, punit, true, happy_cost);
3322 ui->init_pix();
3323 supported_units->add_item(ui);
3325 n = unit_list_size(units);
3326 fc_snprintf(buf, sizeof(buf), _("Supported units %d"), n);
3327 supp_units->setText(QString(buf));
3328 supported_units->update_units();
3329 supported_units->setUpdatesEnabled(true);
3330 current_units->setUpdatesEnabled(true);
3332
3333 if (pplayer != nullptr
3334 && city_owner(dlgcity) != pplayer) {
3336 } else {
3337 units = dlgcity->tile->units;
3338 }
3339
3340 unit_list_iterate(units, punit) {
3341 ui = new unit_item(this , punit, false);
3342 ui->init_pix();
3345
3346 n = unit_list_size(units);
3347 fc_snprintf(buf, sizeof(buf), _("Present units %d"), n);
3348 curr_units->setText(QString(buf));
3349
3351 current_units->setUpdatesEnabled(true);
3352}
3353
3354/************************************************************************/
3358 const QItemSelection &ds)
3359{
3360 QModelIndex index;
3361 QModelIndexList indexes = sl.indexes();
3362
3363 if (indexes.isEmpty()) {
3364 return;
3365 }
3366
3367 index = indexes.at(0);
3368 selected_row_p = index.row();
3370}
3371
3372/************************************************************************/
3376{
3377 int size, i;
3378 struct city *other_pcity = nullptr;
3379 struct player *pplayer = client_player();
3380
3381 if (pplayer == nullptr) {
3382 return;
3383 }
3384
3385 size = city_list_size(pplayer->cities);
3386
3387 if (size <= 1) {
3388 return;
3389 }
3390
3391 for (i = 0; i < size; i++) {
3392 if (dlgcity == city_list_get(pplayer->cities, i)) {
3393 break;
3394 }
3395 }
3396
3397 if (i >= size - 1) {
3398 // Current city last in the list (size - 1) or disappeared (size)
3399 other_pcity = city_list_get(pplayer->cities, 0);
3400 } else {
3401 other_pcity = city_list_get(pplayer->cities, i + 1);
3402 }
3403
3406}
3407
3408/************************************************************************/
3412{
3413 int size, i;
3414 struct city *other_pcity = nullptr;
3415 struct player *pplayer = client_player();
3416
3417 if (pplayer == nullptr) {
3418 return;
3419 }
3420
3421 size = city_list_size(pplayer->cities);
3422
3423 if (size <= 1) {
3424 return;
3425 }
3426
3427 for (i = 0; i < size; i++) {
3428 if (dlgcity == city_list_get(pplayer->cities, i)) {
3429 break;
3430 }
3431 }
3432
3433 if (i == 0 || i == size) {
3434 // Current city in the beginning of the list or disappeared
3435 other_pcity = city_list_get(pplayer->cities, size - 1);
3436 } else {
3437 other_pcity = city_list_get(pplayer->cities, i - 1);
3438 }
3439
3442}
3443
3444/************************************************************************/
3448{
3449 char buf[32];
3450 QString str;
3452
3454 production_combo_p->setRange(0, cost);
3456 if (dlgcity->shield_stock >= cost) {
3457 production_combo_p->setValue(cost);
3458 } else {
3460 }
3461 production_combo_p->setAlignment(Qt::AlignCenter);
3462 str = QString(buf);
3463 str = str.simplified();
3464
3465 production_combo_p->setFormat(QString("(%p%) %2\n%1")
3467 str));
3468
3469 production_combo_p->updateGeometry();
3470
3471}
3472
3473/************************************************************************/
3477{
3478 char buf[1024], buf2[1024];
3480 int value = dlgcity->client.buy_cost;
3482 int city_id = dlgcity->id;
3483
3484 if (!can_client_issue_orders()) {
3485 return;
3486 }
3487
3489 fc_snprintf(buf2, ARRAY_SIZE(buf2), PL_("Treasury contains %d gold.",
3490 "Treasury contains %d gold.",
3491 client_player()->economic.gold),
3492 client_player()->economic.gold);
3493 fc_snprintf(buf, ARRAY_SIZE(buf), PL_("Buy %s for %d gold?",
3494 "Buy %s for %d gold?", value),
3495 name, value);
3496 ask->set_text_title(buf, buf2);
3497 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
3498 ask->setDefaultButton(QMessageBox::Cancel);
3499 ask->setAttribute(Qt::WA_DeleteOnClose);
3500 connect(ask, &hud_message_box::accepted, this, [=]() {
3501 struct city *pcity = game_city_by_number(city_id);
3502
3503 if (!pcity) {
3504 return;
3505 }
3506
3508 });
3509 ask->show();
3510}
3511
3512/************************************************************************/
3516{
3517 QFont f = QApplication::font();
3518 QFontMetrics fm(f);
3519 QPixmap *pix = nullptr;
3523 struct sprite *sprite;
3524 int h, cost, item, targets_used, col, upkeep;
3525 struct item items[MAX_NUM_PRODUCTION_TARGETS];
3526 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
3527 struct worklist queue;
3528 impr_item *ui;
3529
3530 upkeep = 0;
3531 city_buildings->setUpdatesEnabled(false);
3533
3534 h = fm.height() + 6;
3536 name_and_sort_items(targets, targets_used, items, false, dlgcity);
3537
3538 for (item = 0; item < targets_used; item++) {
3539 struct universal target = items[item].item;
3540
3541 ui = new impr_item(this, target.value.building, dlgcity);
3542 ui->init_pix();
3544
3545 fc_assert_action(VUT_IMPROVEMENT == target.kind, continue);
3547 upkeep = upkeep + city_improvement_upkeep(dlgcity, target.value.building);
3548 if (sprite != nullptr) {
3549 pix = sprite->pm;
3550 pix_scaled = pix->scaledToHeight(h);
3551 }
3552 }
3553
3554 city_get_queue(dlgcity, &queue);
3555 p_table_p->setRowCount(worklist_length(&queue));
3556
3557 for (int i = 0; i < worklist_length(&queue); i++) {
3558 struct universal target = queue.entries[i];
3559
3560 tooltip = "";
3561
3562 if (VUT_UTYPE == target.kind) {
3564 cost = utype_build_shield_cost(dlgcity, nullptr, target.value.utype);
3565 tooltip = get_tooltip_unit(target.value.utype, true).trimmed();
3569 } else {
3573 dlgcity, true).trimmed();
3574
3576 cost = -1;
3577 } else {
3579 }
3580 }
3581
3582 for (col = 0; col < 3; col++) {
3583 qitem = new QTableWidgetItem();
3584 qitem->setToolTip(tooltip);
3585
3586 switch (col) {
3587 case 0:
3588 if (sprite) {
3589 pix = sprite->pm;
3590 pix_scaled = pix->scaledToHeight(h);
3591 qitem->setData(Qt::DecorationRole, pix_scaled);
3592 }
3593 break;
3594
3595 case 1:
3596 if (str.contains('[') && str.contains(']')) {
3597 int ii, ij;
3598
3599 ii = str.lastIndexOf('[');
3600 ij = str.lastIndexOf(']');
3601 if (ij > ii) {
3602 str = str.remove(ii, ij - ii + 1);
3603 }
3604 }
3605 qitem->setText(str);
3606 break;
3607
3608 case 2:
3609 qitem->setTextAlignment(Qt::AlignRight);
3610 qitem->setText(QString::number(cost));
3611 break;
3612 }
3613 p_table_p->setItem(i, col, qitem);
3614 }
3615 }
3616
3617 p_table_p->horizontalHeader()->setStretchLastSection(false);
3618 p_table_p->resizeColumnsToContents();
3619 p_table_p->resizeRowsToContents();
3620 p_table_p->horizontalHeader()->setStretchLastSection(true);
3621
3623 city_buildings->setUpdatesEnabled(true);
3624 city_buildings->setUpdatesEnabled(true);
3625
3626 curr_impr->setText(QString(_("Improvements - upkeep %1")).arg(upkeep));
3627}
3628
3629/************************************************************************/
3633{
3634 cid id;
3635 QVariant qvar;
3636
3638 struct universal univ;
3639
3640 id = qvar.toInt();
3641 univ = cid_production(id);
3643 }
3644}
3645
3646/************************************************************************/
3651{
3653 int when = 1;
3654
3655 pw = new production_widget(this, dlgcity, future_targets->isChecked(),
3656 when, selected_row_p, show_units->isChecked(),
3657 false, show_wonders->isChecked(),
3658 show_buildings->isChecked());
3659 pw->show();
3660}
3661
3662/************************************************************************/
3667{
3669 int when = 4;
3670
3671 pw = new production_widget(this, dlgcity, future_targets->isChecked(),
3672 when, selected_row_p, show_units->isChecked(),
3673 false, show_wonders->isChecked(),
3674 show_buildings->isChecked());
3675 pw->show();
3676}
3677
3678/************************************************************************/
3682{
3683 struct worklist empty;
3684
3685 if (!can_client_issue_orders()) {
3686 return;
3687 }
3688
3691}
3692
3693/************************************************************************/
3697{
3698 QModelIndex index;
3699 struct worklist queue;
3700 struct universal *target;
3701
3703 return;
3704 }
3705
3706 target = new universal;
3707 city_get_queue(dlgcity, &queue);
3708 worklist_peek_ith(&queue, target, selected_row_p);
3710 worklist_insert(&queue, target, selected_row_p - 1);
3711 city_set_queue(dlgcity, &queue);
3712 index = p_table_p->model()->index(selected_row_p - 1, 0);
3713 p_table_p->setCurrentIndex(index);
3714 delete target;
3715
3716}
3717
3718/************************************************************************/
3722{
3724
3725 if (selected_row_p < 0
3726 || selected_row_p >= p_table_p->rowCount()) {
3727 return;
3728 }
3729
3733}
3734
3735/************************************************************************/
3739{
3740 QModelIndex index;
3741 struct worklist queue;
3742 struct universal *target;
3743
3745 return;
3746 }
3747
3748 target = new universal;
3749 city_get_queue(dlgcity, &queue);
3750 worklist_peek_ith(&queue, target, selected_row_p);
3752 worklist_insert(&queue, target, selected_row_p + 1);
3753 city_set_queue(dlgcity, &queue);
3754 index = p_table_p->model()->index(selected_row_p + 1, 0);
3755 p_table_p->setCurrentIndex(index);
3756 delete target;
3757}
3758
3759/************************************************************************/
3763{
3764 hud_input_box *ask = new hud_input_box(gui()->central_wdg);
3765 int city_id = dlgcity->id;
3766
3767 ask->set_text_title_definput(_("What should we name new worklist?"),
3768 _("Save current worklist"),
3769 _("New worklist"));
3770 ask->setAttribute(Qt::WA_DeleteOnClose);
3771 connect(ask, &hud_message_box::accepted, [=]() {
3772 struct global_worklist *gw;
3773 struct worklist queue;
3775 QString text;
3776 struct city *pcity = game_city_by_number(city_id);
3777
3778 ask_bytes = ask->input_edit.text().toUtf8();
3779 text = ask_bytes.data();
3780 if (!text.isEmpty()) {
3781 ask_bytes = text.toUtf8();
3783 city_get_queue(pcity, &queue);
3784 global_worklist_set(gw, &queue);
3785 }
3786 });
3787 ask->show();
3788}
3789
3790/************************************************************************/
3794{
3795 QString buf;
3796
3797 // Defeat keyboard shortcut mnemonics
3799 .replace("&", "&&"));
3800
3801 if (city_unhappy(dlgcity)) {
3802 // TRANS: city dialog title
3803 buf = QString(_("%1 - %2 citizens - DISORDER")).arg(city_name_get(dlgcity),
3805 } else if (city_celebrating(dlgcity)) {
3806 // TRANS: city dialog title
3807 buf = QString(_("%1 - %2 citizens - celebrating")).arg(city_name_get(dlgcity),
3809 } else if (city_happy(dlgcity)) {
3810 // TRANS: city dialog title
3811 buf = QString(_("%1 - %2 citizens - happy")).arg(city_name_get(dlgcity),
3813 } else {
3814 // TRANS: city dialog title
3815 buf = QString(_("%1 - %2 citizens")).arg(city_name_get(dlgcity),
3817 }
3818
3820}
3821
3822/************************************************************************/
3827{
3828 if (!::city_dlg_created) {
3829 ::city_dlg = new city_dialog(gui()->mapview_wdg);
3830 }
3831
3833 city_dlg->show();
3834 city_dlg->activateWindow();
3835 city_dlg->raise();
3836}
3837
3838/************************************************************************/
3842{
3843 if (!::city_dlg_created) {
3844 return;
3845 }
3846
3847 city_dlg->close();
3848 ::city_dlg_created = false;
3849}
3850
3851/************************************************************************/
3855{
3856 if (!::city_dlg_created) {
3857 return;
3858 }
3859
3861}
3862
3863/************************************************************************/
3870
3871/************************************************************************/
3875{
3876 if (!::city_dlg_created) {
3877 return;
3878 }
3879
3881 city_dlg->refresh();
3882 }
3883}
3884
3885/************************************************************************/
3889{
3891 QFont *f;
3892
3893 if (!::city_dlg_created) {
3894 return;
3895 }
3896
3897 l = city_dlg->findChildren<QLabel *>();
3898
3900
3901 for (int i = 0; i < l.size(); ++i) {
3902 if (l.at(i)->property(fonts::notify_label).isValid()) {
3903 l.at(i)->setFont(*f);
3904 }
3905 }
3906}
3907
3908/************************************************************************/
3925
3926/************************************************************************/
3930{
3931 if (!::city_dlg_created) {
3932 return false;
3933 }
3934
3935 if (city_dlg->dlgcity == pcity && city_dlg->isVisible()) {
3936 return true;
3937 }
3938
3939 return false;
3940}
3941
3942/************************************************************************/
3945bool fc_tooltip::eventFilter(QObject *obj, QEvent *ev)
3946{
3949 QRect rect;
3950
3951 if (ev->type() == QEvent::ToolTip) {
3953
3954 if (!view) {
3955 return false;
3956 }
3957
3958 help_event = static_cast<QHelpEvent *>(ev);
3959 QPoint pos = help_event->pos();
3960 QModelIndex index = view->indexAt(pos);
3961 QPoint hpos;
3962
3963 if (!index.isValid()) {
3964 return false;
3965 }
3966
3967 item_tooltip = view->model()->data(index, Qt::ToolTipRole).toString();
3968 rect = view->visualRect(index);
3969
3970 hpos = help_event->globalPos();
3971
3972 rect.setX(rect.x() + hpos.x());
3973 rect.setY(rect.y() + hpos.y());
3974
3975 if (!item_tooltip.isEmpty()) {
3976 QToolTip::showText(help_event->globalPos(), item_tooltip, view, rect);
3977 } else {
3978 QToolTip::hideText();
3979 }
3980
3981 return true;
3982 }
3983
3984 return false;
3985}
3986
3987/************************************************************************/
3991{
3992 return QString("<b>" + text + "</b>");
3993}
3994
3995/************************************************************************/
4000 bool ext)
4001{
4003 QString upkeep;
4004 QString s1, s2, str;
4005 const char *req = skip_intl_qualifier_prefix(_("?tech:None"));
4006 struct player *pplayer = client_player();
4007
4008 if (pcity != nullptr) {
4009 upkeep = QString::number(city_improvement_upkeep(pcity, building));
4010 } else {
4011 upkeep = QString::number(building->upkeep);
4012 }
4014 if (pobs->source.kind == VUT_ADVANCE) {
4015 req = advance_name_translation(pobs->source.value.advance);
4016 break;
4017 }
4019 s2 = QString(req);
4020 str = _("Obsolete by:");
4021 str = str + " " + s2;
4022 def_str = "<p style='white-space:pre'><b>"
4023 + QString(improvement_name_translation(building)).toHtmlEscaped()
4024 + "</b>\n";
4025 if (pcity != nullptr) {
4026 def_str += QString(_("Cost: %1, Upkeep: %2\n"))
4027 .arg(impr_build_shield_cost(pcity, building))
4028 .arg(upkeep).toHtmlEscaped();
4029 } else {
4031 nullptr, building);
4032
4033 def_str += QString(_("Cost Estimate: %1, Upkeep: %2\n"))
4034 .arg(cost_est)
4035 .arg(upkeep).toHtmlEscaped();
4036 }
4037 if (s1.compare(s2) != 0) {
4038 def_str = def_str + str.toHtmlEscaped() + "\n";
4039 }
4040 def_str = def_str + "\n";
4041 if (ext) {
4042 char buffer[8192];
4043
4044 str = helptext_building(buffer, sizeof(buffer), pplayer,
4045 nullptr, building);
4046 str = cut_helptext(str);
4047 str = split_text(str, true);
4048 str = str.trimmed();
4049 def_str = def_str + str.toHtmlEscaped();
4050 }
4051 return def_str;
4052}
4053
4054/************************************************************************/
4058QString get_tooltip_unit(const struct unit_type *utype, bool ext)
4059{
4062 QString str;
4063 const struct unit_type *obsolete;
4064 struct advance *tech;
4065
4066 def_str = "<b>"
4067 + QString(utype_name_translation(utype)).toHtmlEscaped()
4068 + "</b>\n";
4069 obsolete = utype->obsoleted_by;
4070 if (obsolete) {
4071 // FIXME: Don't give the impression that primary tech is (always) the only one.
4073 obsolete_str = QString("</td></tr><tr><td colspan=\"3\">");
4074 if (tech && tech != advance_by_number(A_NONE)) {
4075 /* TRANS: this and nearby literal strings are interpreted
4076 * as (Qt) HTML */
4077 obsolete_str = obsolete_str + QString(_("Obsoleted by %1 (%2)."))
4079 .arg(advance_name_translation(tech)).toHtmlEscaped();
4080 } else {
4081 obsolete_str = obsolete_str + QString(_("Obsoleted by %1."))
4082 .arg(utype_name_translation(obsolete)).toHtmlEscaped();
4083 }
4084 }
4085 def_str += "<table width=\"100\%\"><tr><td>"
4086 + bold(QString(_("Attack:"))) + " "
4087 + QString::number(utype->attack_strength).toHtmlEscaped()
4088 + QString("</td><td>") + bold(QString(_("Defense:"))) + " "
4089 + QString::number(utype->defense_strength).toHtmlEscaped()
4090 + QString("</td><td>") + bold(QString(_("Move:"))) + " "
4091 + QString(move_points_text(utype->move_rate, TRUE)).toHtmlEscaped()
4092 + QString("</td></tr><tr><td>")
4093 + bold(QString(_("Cost:"))) + " "
4094 + QString::number(utype_build_shield_cost_base(utype))
4095 .toHtmlEscaped()
4096 + QString("</td><td colspan=\"2\">")
4097 + bold(QString(_("Basic Upkeep:")))
4098 + " " + QString(helptext_unit_upkeep_str(utype)).toHtmlEscaped()
4099 + QString("</td></tr><tr><td>")
4100 + bold(QString(_("Hitpoints:"))) + " "
4101 + QString::number(utype->hp).toHtmlEscaped()
4102 + QString("</td><td>") + bold(QString(_("Firepower:"))) + " "
4103 + QString::number(utype->firepower).toHtmlEscaped()
4104 + QString("</td><td>") + bold(QString(_("Vision:"))) + " "
4105 + QString::number((int) sqrt((double) utype->vision_radius_sq))
4106 .toHtmlEscaped()
4107 + obsolete_str
4108 + QString("</td></tr></table><p style='white-space:pre'>");
4109 if (ext) {
4110 char buffer[8192];
4111 char buf2[1];
4112
4113 buf2[0] = '\0';
4114 str = helptext_unit(buffer, sizeof(buffer), client_player(),
4115 buf2, utype, TRUE);
4116 str = cut_helptext(str);
4117 str = split_text(str, true);
4118 str = str.trimmed().toHtmlEscaped();
4119 def_str = def_str + str;
4120 }
4121
4122 return def_str;
4123};
4124
4125/************************************************************************/
4129{
4132 char buffer[8192];
4133 char buf2[1];
4134 struct universal *target;
4135 struct player *pplayer = client_player();
4136
4137 buf2[0] = '\0';
4138 target = reinterpret_cast<universal *>(qvar.value<void *>());
4139
4140 if (target == nullptr) {
4141 } else if (VUT_UTYPE == target->kind) {
4143 str = helptext_unit(buffer, sizeof(buffer), pplayer,
4144 buf2, target->value.utype, TRUE);
4145 } else {
4146 if (!is_convert_improvement(target->value.building)) {
4148 }
4149
4150 str = helptext_building(buffer, sizeof(buffer), pplayer,
4151 nullptr, target->value.building);
4152 }
4153
4154 // Remove all lines from help which has '*' in first 3 chars
4156 ret_str = split_text(ret_str, true);
4157 ret_str = ret_str.trimmed();
4158 ret_str = def_str + ret_str.toHtmlEscaped();
4159
4160 return ret_str;
4161}
4162
4163/************************************************************************/
4167 QObject *parent,
4168 struct city *city)
4169 : QItemDelegate(parent)
4170{
4171 pd = sh;
4172 item_height = sh.y();
4173 pcity = city;
4174}
4175
4176/************************************************************************/
4181 const QModelIndex &index) const
4182{
4183 struct universal *target;
4184 QString name;
4185 QVariant qvar;
4186 QPixmap *pix;
4188 QRect rect1;
4189 QRect rect2;
4190 struct sprite *sprite;
4191 bool useless = false;
4192 bool is_convert = false;
4193 bool is_neutral = false;
4194 bool is_sea = false;
4195 bool is_flying = false;
4196 bool is_unit = true;
4197 QPixmap pix_dec(option.rect.width(), option.rect.height());
4199 color col;
4200 QIcon icon = current_app()->style()->standardIcon(QStyle::SP_DialogCancelButton);
4201 bool free_sprite = false;
4202 struct unit_class *pclass;
4203
4204 if (!option.rect.isValid()) {
4205 return;
4206 }
4207
4208 qvar = index.data();
4209
4210 if (!qvar.isValid()) {
4211 return;
4212 }
4213
4214 target = reinterpret_cast<universal *>(qvar.value<void *>());
4215
4216 if (target == nullptr) {
4217 col.qcolor = Qt::white;
4218 sprite = qtg_create_sprite(100, 100, &col);
4219 free_sprite = true;
4220 *sprite->pm = icon.pixmap(100, 100);
4221 name = _("Cancel");
4222 is_unit = false;
4223 } else if (VUT_UTYPE == target->kind) {
4226 pclass = utype_class(target->value.utype);
4230 is_sea = true;
4231 }
4232
4233 if ((utype_fuel(target->value.utype)
4238 /* FIXME: Assumed to be flying since only missiles can do suicide
4239 * attacks in classic-like rulesets. This isn't true for all
4240 * rulesets. Not a high priority to fix since all is_flying and
4241 * is_sea is used for is to set a color. */
4243 target->value.utype)) {
4244 if (is_sea) {
4245 is_sea = false;
4246 }
4247 is_flying = true;
4248 }
4249
4253 } else {
4254 is_unit = false;
4257 useless = is_improvement_redundant(pcity, target->value.building);
4258 is_convert = (target->value.building->genus == IG_CONVERT);
4259 }
4260
4261 if (sprite != nullptr) {
4262 pix = sprite->pm;
4263 pix_scaled = pix->scaledToHeight(item_height - 2, Qt::SmoothTransformation);
4264
4265 if (useless) {
4267 }
4268 }
4269
4270 opt = QItemDelegate::setOptions(index, option);
4271 painter->save();
4272 opt.displayAlignment = Qt::AlignLeft;
4273 opt.textElideMode = Qt::ElideMiddle;
4274 QItemDelegate::drawBackground(painter, opt, index);
4275 rect1 = option.rect;
4276 rect1.setWidth(pix_scaled.width() + 4);
4277 rect2 = option.rect;
4278 rect2.setLeft(option.rect.left() + rect1.width());
4279 rect2.setTop(rect2.top() + (rect2.height()
4280 - painter->fontMetrics().height()) / 2);
4281 QItemDelegate::drawDisplay(painter, opt, rect2, name);
4282
4283 if (is_unit) {
4284 if (is_sea) {
4285 pix_dec.fill(QColor(0, 0, 255, 80));
4286 } else if (is_flying) {
4287 pix_dec.fill(QColor(220, 0, 0, 80));
4288 } else if (is_neutral) {
4289 pix_dec.fill(QColor(0, 120, 0, 40));
4290 } else {
4291 pix_dec.fill(QColor(0, 0, 150, 40));
4292 }
4293
4294 QItemDelegate::drawDecoration(painter, option, option.rect, pix_dec);
4295 }
4296
4297 if (is_convert) {
4298 pix_dec.fill(QColor(255, 255, 0, 70));
4299 QItemDelegate::drawDecoration(painter, option, option.rect, pix_dec);
4300 }
4301
4302 if (!pix_scaled.isNull()) {
4303 QItemDelegate::drawDecoration(painter, opt, rect1, pix_scaled);
4304 }
4305
4306 drawFocus(painter, opt, option.rect);
4307
4308 painter->restore();
4309
4310 if (free_sprite) {
4312 }
4313}
4314
4315/************************************************************************/
4320 const QRect &rect) const
4321{
4322 QPixmap pix(option.rect.width(), option.rect.height());
4323
4324 if ((option.state & QStyle::State_MouseOver) == 0 || !rect.isValid()) {
4325 return;
4326 }
4327
4328 pix.fill(QColor(50, 50, 50, 50));
4329 QItemDelegate::drawDecoration(painter, option, option.rect, pix);
4330}
4331
4332/************************************************************************/
4336 const QModelIndex &index) const
4337{
4338 QSize s;
4339
4340 s.setWidth(pd.x());
4341 s.setHeight(pd.y());
4342 return s;
4343}
4344
4345/************************************************************************/
4349 QObject *parent): QObject()
4350{
4352 target = ptarget;
4353}
4354
4355/************************************************************************/
4359{
4360 // Allocated as renegade in model
4361 if (target != nullptr) {
4362 delete target;
4363 }
4364}
4365
4366/************************************************************************/
4370{
4371 return QVariant::fromValue((void *)target);
4372}
4373
4374/************************************************************************/
4378{
4379 return false;
4380}
4381
4382/************************************************************************/
4386 bool su, bool sw, bool sb,
4387 QObject *parent)
4388 : QAbstractListModel(parent)
4389{
4390 show_units = su;
4391 show_wonders = sw;
4393 mcity = pcity;
4394 future_t = f;
4395 populate();
4396}
4397
4398/************************************************************************/
4406
4407/************************************************************************/
4411{
4412 if (!index.isValid()) {
4413 return QVariant();
4414 }
4415
4416 if (index.row() >= 0 && index.row() < rowCount() && index.column() >= 0
4417 && index.column() < columnCount()
4418 && (index.column() + index.row() * 3 < city_target_list.count())) {
4419 int r, c, t, new_index;
4420
4421 r = index.row();
4422 c = index.column();
4423 t = r * 3 + c;
4424 new_index = t / 3 + rowCount() * c;
4425 // Exception, shift whole column
4426 if ((c == 2) && city_target_list.count() % 3 == 1) {
4427 new_index = t / 3 + rowCount() * c - 1;
4428 }
4429 if (role == Qt::ToolTipRole) {
4431 }
4432
4433 return city_target_list[new_index]->data();
4434 }
4435
4436 return QVariant();
4437}
4438
4439/************************************************************************/
4443{
4445 struct universal targets[MAX_NUM_PRODUCTION_TARGETS];
4446 struct item items[MAX_NUM_PRODUCTION_TARGETS];
4447 struct universal *renegade;
4448 int item, targets_used;
4449 QString str;
4451 QFontMetrics fm(f);
4452
4453 sh.setY(fm.height() * 2);
4454 sh.setX(0);
4455
4457 city_target_list.clear();
4458
4460 future_t);
4461 name_and_sort_items(targets, targets_used, items, false, mcity);
4462
4463 for (item = 0; item < targets_used; item++) {
4464 if (future_t || can_city_build_now(&(wld.map), mcity, &items[item].item)) {
4465 renegade = new universal(items[item].item);
4466
4467 // Renegade deleted in production_item destructor
4468 if (VUT_UTYPE == renegade->kind) {
4469 str = utype_name_translation(renegade->value.utype);
4470 sh.setX(qMax(sh.x(), fm.horizontalAdvance(str)));
4471
4472 if (show_units) {
4473 pi = new production_item(renegade, this);
4475 } else {
4476 delete renegade;
4477 }
4478 } else {
4479 str = improvement_name_translation(renegade->value.building);
4480 sh.setX(qMax(sh.x(), fm.horizontalAdvance(str)));
4481
4482 if ((is_wonder(renegade->value.building) && show_wonders)
4483 || (is_improvement(renegade->value.building) && show_buildings)
4484 || (is_convert_improvement(renegade->value.building))
4485 || (is_special_improvement(renegade->value.building)
4486 && show_buildings)) {
4487 pi = new production_item(renegade, this);
4489 } else {
4490 delete renegade;
4491 }
4492 }
4493 }
4494 }
4495
4496 pi = new production_item(nullptr, this);
4498 sh.setX(2 * sh.y() + sh.x());
4499 sh.setX(qMin(sh.x(), 250));
4500}
4501
4502/************************************************************************/
4506 const QVariant &value, int role)
4507{
4508 if (!index.isValid() || role != Qt::DisplayRole || role != Qt::ToolTipRole)
4509 return false;
4510
4511 if (index.row() >= 0 && index.row() < rowCount() && index.column() >= 0
4512 && index.column() < columnCount()) {
4513 bool change = city_target_list[index.row()]->setData();
4514 return change;
4515 }
4516
4517 return false;
4518}
4519
4520/************************************************************************/
4529 bool future, int when, int curr,
4530 bool show_units, bool buy,
4531 bool show_wonders,
4532 bool show_buildings): QTableView()
4533{
4534 QPoint pos, sh;
4535 QRect rect = QApplication::primaryScreen()->availableGeometry();
4536 int desk_width = rect.width();
4537 int desk_height = rect.height();
4538 fc_tt = new fc_tooltip(this);
4539 setAttribute(Qt::WA_DeleteOnClose);
4540 setWindowFlags(Qt::Popup);
4541 verticalHeader()->setVisible(false);
4542 horizontalHeader()->setVisible(false);
4543 setProperty("showGrid", false);
4545 sh_units = show_units;
4546 pw_city = pcity;
4547 buy_it = buy;
4548 when_change = when;
4549 list_model = new city_production_model(pw_city, future, show_units,
4550 show_wonders, show_buildings, this);
4551 sh = list_model->sh;
4552 c_p_d = new city_production_delegate(sh, this, pw_city);
4555 viewport()->installEventFilter(fc_tt);
4556 installEventFilter(this);
4558 const QItemSelection &)),
4560 const QItemSelection &)));
4563 setFixedWidth(3 * sh.x() + 6);
4564 setFixedHeight(list_model->rowCount()*sh.y() + 6);
4565
4566 if (width() > desk_width) {
4568 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
4569 } else {
4570 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
4571 }
4572
4573 if (height() > desk_height) {
4575 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
4576 } else {
4577 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
4578 }
4579
4580 pos = QCursor::pos();
4581
4582 if (pos.x() + width() > desk_width) {
4583 pos.setX(desk_width - width());
4584 } else if (pos.x() - width() < 0) {
4585 pos.setX(0);
4586 }
4587
4588 if (pos.y() + height() > desk_height) {
4589 pos.setY(desk_height - height());
4590 } else if (pos.y() - height() < 0) {
4591 pos.setY(0);
4592 }
4593
4594 move(pos);
4595 setMouseTracking(true);
4596 setFocus();
4597}
4598
4599/************************************************************************/
4603{
4604 if (event->button() == Qt::RightButton) {
4605 close();
4606 return;
4607 }
4608
4609 QAbstractItemView::mousePressEvent(event);
4610}
4611
4612/************************************************************************/
4616{
4617 QRect pw_rect;
4618 QPoint br;
4619
4620 if (obj != this)
4621 return false;
4622
4623 if (ev->type() == QEvent::MouseButtonPress) {
4624 pw_rect.setTopLeft(pos());
4625 br.setX(pos().x() + width());
4626 br.setY(pos().y() + height());
4627 pw_rect.setBottomRight(br);
4628
4629 if (!pw_rect.contains(QCursor::pos())) {
4630 close();
4631 }
4632 }
4633
4634 return false;
4635}
4636
4637/************************************************************************/
4641 const QItemSelection &ds)
4642{
4643 QModelIndexList indexes = selectionModel()->selectedIndexes();
4644 QModelIndex index;
4645 QVariant qvar;
4646 struct worklist queue;
4647 struct universal *target;
4648
4649 if (indexes.isEmpty() || client_is_observer()) {
4650 return;
4651 }
4652 index = indexes.at(0);
4653 qvar = index.data(Qt::UserRole);
4654 if (!qvar.isValid()) {
4655 return;
4656 }
4657 target = reinterpret_cast<universal *>(qvar.value<void *>());
4658 if (target != nullptr) {
4659 city_get_queue(pw_city, &queue);
4660 switch (when_change) {
4661 case 0: // Change current target
4663 if (city_can_buy(pw_city) && buy_it) {
4665 }
4666 break;
4667
4668 case 1: // Change current (selected on list)
4671 } else {
4673 worklist_insert(&queue, target, curr_selection);
4674 city_set_queue(pw_city, &queue);
4675 }
4676 break;
4677
4678 case 2: // Insert before
4680 curr_selection = 0;
4681 }
4684 worklist_insert(&queue, target, curr_selection);
4685 city_set_queue(pw_city, &queue);
4686 break;
4687
4688 case 3: // Insert after
4690 city_queue_insert(pw_city, -1, target);
4691 break;
4692 }
4694 worklist_insert(&queue, target, curr_selection);
4695 city_set_queue(pw_city, &queue);
4696 break;
4697
4698 case 4: // Add last
4699 city_queue_insert(pw_city, -1, target);
4700 break;
4701
4702 default:
4703 break;
4704 }
4705 }
4706 close();
4707 destroy();
4708}
4709
4710/************************************************************************/
4714{
4715 delete c_p_d;
4716 delete list_model;
4717 viewport()->removeEventFilter(fc_tt);
4718 removeEventFilter(this);
4719}
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:3854
void qtg_real_city_dialog_refresh(struct city *pcity)
Definition citydlg.cpp:3874
QString split_text(QString text, bool cut)
Definition optiondlg.cpp:62
void city_font_update()
Definition citydlg.cpp:3888
bool qtg_city_dialog_is_open(struct city *pcity)
Definition citydlg.cpp:3929
QString get_tooltip(QVariant qvar)
Definition citydlg.cpp:4128
void qtg_popdown_all_city_dialogs()
Definition citydlg.cpp:3866
static city_dialog * city_dlg
Definition citydlg.cpp:75
void qtg_refresh_unit_city_dialogs(struct unit *punit)
Definition citydlg.cpp:3913
static QString bold(QString text)
Definition citydlg.cpp:3990
void qtg_real_city_dialog_popup(struct city *pcity)
Definition citydlg.cpp:3826
QString get_tooltip_improvement(const impr_type *building, struct city *pcity, bool ext)
Definition citydlg.cpp:3999
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:4058
void destroy_city_dialog()
Definition citydlg.cpp:3841
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:4166
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition citydlg.cpp:4179
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition citydlg.cpp:4335
struct city * pcity
Definition citydlg.h:319
void drawFocus(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect) const
Definition citydlg.cpp:4318
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:4505
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:4385
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition citydlg.cpp:4410
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:3945
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:4369
production_item(struct universal *ptarget, QObject *parent)
Definition citydlg.cpp:4348
bool eventFilter(QObject *obj, QEvent *ev)
Definition citydlg.cpp:4615
void prod_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:4640
void mousePressEvent(QMouseEvent *event)
Definition citydlg.cpp:4602
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:4528
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:247
#define EC_NONE
Definition fc_types.h:821
@ TR_SUCCESS
Definition fc_types.h:954
#define ERM_NONE
Definition fc_types.h:844
@ O_SHIELD
Definition fc_types.h:101
@ O_FOOD
Definition fc_types.h:101
@ O_TRADE
Definition fc_types.h:101
@ O_SCIENCE
Definition fc_types.h:101
@ O_LUXURY
Definition fc_types.h:101
@ O_GOLD
Definition fc_types.h:101
@ O_LAST
Definition fc_types.h:101
const char * skip_intl_qualifier_prefix(const char *str)
Definition fcintl.c:48
#define Q_(String)
Definition fcintl.h:70
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
const char * population_to_text(int thousand_citizen)
Definition game.c:739
struct civ_game game
Definition game.c:61
struct world wld
Definition game.c:62
struct city * game_city_by_number(int id)
Definition game.c:106
struct global_worklist * global_worklist_by_id(int id)
bool global_worklist_set(struct global_worklist *pgwl, const struct worklist *pwl)
const char * global_worklist_name(const struct global_worklist *pgwl)
int global_worklist_id(const struct global_worklist *pgwl)
const struct worklist * global_worklist_get(const struct global_worklist *pgwl)
struct global_worklist * global_worklist_new(const char *name)
#define global_worklists_iterate(pgwl)
#define global_worklists_iterate_end
void canvas_free(struct canvas *store)
Definition canvas.c:44
@ INFO_LUXURY
Definition citydlg.c:120
@ INFO_STEAL
Definition citydlg.c:122
@ INFO_CORRUPTION
Definition citydlg.c:121
@ NUM_INFO_FIELDS
Definition citydlg.c:123
@ INFO_ILLNESS
Definition citydlg.c:122
@ INFO_WASTE
Definition citydlg.c:121
@ INFO_GROWTH
Definition citydlg.c:120
@ INFO_SHIELD
Definition citydlg.c:119
@ INFO_CULTURE
Definition citydlg.c:121
@ INFO_GOLD
Definition citydlg.c:119
@ INFO_SCIENCE
Definition citydlg.c:120
@ INFO_POLLUTION
Definition citydlg.c:121
@ INFO_TRADE
Definition citydlg.c:119
@ INFO_AIRLIFT
Definition citydlg.c:122
@ INFO_GRANARY
Definition citydlg.c:120
@ INFO_FOOD
Definition citydlg.c:119
void popup_upgrade_dialog(struct unit_list *punits)
Definition dialogs.c:1435
void popup_disband_dialog(struct unit_list *punits)
Definition dialogs.c:1473
static struct tile * pos
Definition finddlg.c:53
const char * tooltip
Definition repodlgs.c:1315
GType type
Definition repodlgs.c:1313
void free_sprite(struct sprite *s)
Definition sprite.c:278
static GMenu * change_menu
Definition cityrep.c:126
static GMenu * options_menu
Definition menu.c:83
QString get_tooltip_improvement(const impr_type *building, struct city *pcity=nullptr, bool ext=false)
Definition citydlg.cpp:3999
QString get_tooltip(QVariant qvar)
Definition citydlg.cpp:4128
#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:1048
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:3265
int current_building
Definition citydlg.h:513
void worklist_up()
Definition citydlg.cpp:3696
city_label * citizens_label
Definition citydlg.h:456
QPushButton * lcity_name
Definition citydlg.h:499
void show_happiness()
Definition citydlg.cpp:2126
void closeEvent(QCloseEvent *event)
Definition citydlg.cpp:2323
void show_counters()
Definition citydlg.cpp:2161
void update_nation_table()
Definition citydlg.cpp:3067
void hideEvent(QHideEvent *event)
Definition citydlg.cpp:2295
void cma_toggle_changed_depr(int state)
Definition citydlg.cpp:2706
QPushButton * work_next_but
Definition citydlg.h:487
void next_city()
Definition citydlg.cpp:3375
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:2306
QPushButton * happiness_button
Definition citydlg.h:491
void cma_double_clicked(int row, int column)
Definition citydlg.cpp:2499
void display_worklist_menu(const QPoint &p)
Definition citydlg.cpp:2783
void update_disabled()
Definition citydlg.cpp:2196
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:2883
int selected_row_p
Definition citydlg.h:500
QHBoxLayout * leftbot_layout
Definition citydlg.h:451
void update_building()
Definition citydlg.cpp:3447
QPushButton * zoom_in_button
Definition citydlg.h:493
void save_worklist()
Definition citydlg.cpp:3762
void worklist_del()
Definition citydlg.cpp:3721
QGridLayout * info_grid_layout
Definition citydlg.h:458
void clear_worklist()
Definition citydlg.cpp:3681
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:2414
void zoom_in()
Definition citydlg.cpp:2401
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:3144
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:2742
void update_citizens()
Definition citydlg.cpp:2909
QRadioButton * r1
Definition citydlg.h:481
void cma_slider(int val)
Definition citydlg.cpp:2717
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:3738
void update_title()
Definition citydlg.cpp:3793
QLabel * cma_info_text
Definition citydlg.h:465
void dbl_click_p(QTableWidgetItem *item)
Definition citydlg.cpp:3281
QPushButton * cma_enable_but
Definition citydlg.h:484
QLabel * cma_result
Definition citydlg.h:466
void cma_remove()
Definition citydlg.cpp:2667
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:2334
QSplitter * prod_unit_splitter
Definition citydlg.h:448
QVBoxLayout * left_layout
Definition citydlg.h:454
void prev_city()
Definition citydlg.cpp:3411
void city_rename()
Definition citydlg.cpp:2371
void refresh()
Definition citydlg.cpp:2993
void update_cma_tab()
Definition citydlg.cpp:2600
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:3650
city_dialog(QWidget *parent=nullptr)
Definition citydlg.cpp:1482
void cma_toggle_changed(Qt::CheckState state)
Definition citydlg.cpp:2694
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:2105
QPushButton * prev_city_but
Definition citydlg.h:486
void cma_enable()
Definition citydlg.cpp:2463
QLabel * cma_result_pix
Definition citydlg.h:467
struct city * dlgcity
Definition citydlg.h:508
void update_counters_table()
Definition citydlg.cpp:3025
void update_sliders()
Definition citydlg.cpp:2548
void update_improvements()
Definition citydlg.cpp:3515
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:2060
void cma_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:2518
QCheckBox * cma_max_growth
Definition citydlg.h:476
void item_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition citydlg.cpp:3357
void show_targets_worklist()
Definition citydlg.cpp:3666
QCheckBox * show_wonders
Definition citydlg.h:480
void cma_context_menu(const QPoint &p)
Definition citydlg.cpp:2763
void cma_changed()
Definition citydlg.cpp:2478
QPushButton * buy_button
Definition citydlg.h:483
QRadioButton * r4
Definition citydlg.h:481
struct city_dialog::@149 counters
void update_units()
Definition citydlg.cpp:3298
QRadioButton * r2
Definition citydlg.h:481
QTableWidget * p_table_p
Definition citydlg.h:472
void save_cma()
Definition citydlg.cpp:2427
QPixmap * citizen_pixmap
Definition citydlg.h:495
void production_changed(int index)
Definition citydlg.cpp:3632
void update_prod_buttons()
Definition citydlg.cpp:2233
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:608
universals_u value
Definition fc_types.h:607
struct universal entries[MAX_LEN_WORKLIST]
Definition worklist.h:30
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#define TRUE
Definition support.h:46
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:107
bool is_future_tech(Tech_type_id tech)
Definition tech.c:281
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:300
struct advance * valid_advance_by_number(const Tech_type_id id)
Definition tech.c:176
#define A_NONE
Definition tech.h:43
const char * text_happiness_nationality(const struct city *pcity)
Definition text.c: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:553
const struct impr_type * building
Definition fc_types.h:546
bool can_unit_change_homecity(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c: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