Freeciv-3.3: /fast/freeciv/nightly/main/client/gui-qt/citydlg.cpp Source File

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