Freeciv-3.2
Loading...
Searching...
No Matches
hudwidget.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 <QAction>
20#include <QApplication>
21#include <QComboBox>
22#include <QDialogButtonBox>
23#include <QGridLayout>
24#include <QGroupBox>
25#include <QHBoxLayout>
26#include <QHeaderView>
27#include <QLineEdit>
28#include <QPainter>
29#include <QPaintEvent>
30#include <QRadioButton>
31#include <QSpacerItem>
32#include <QVBoxLayout>
33
34// common
35#include "movement.h"
36#include "research.h"
37#include "tile.h"
38#include "unit.h"
39#include "unitlist.h"
40
41// client
42#include "client_main.h"
43#include "text.h"
44
45// gui-qt
46#include "fc_client.h"
47#include "fonts.h"
48#include "hudwidget.h"
49#include "sprite.h"
50
51extern "C" {
52 const char *calendar_text(void);
53 bool goto_is_active(void);
54}
55static QString popup_terrain_info(struct tile *ptile);
56
57/************************************************************************/
61{
63 if (utype_number(punit->utype) == utype) {
64 return true;
65 }
67
68 return false;
69}
70
71/************************************************************************/
75{
76 int size;
77 setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Dialog
78 | Qt::FramelessWindowHint);
81
82 size = f_text.pointSize();
83 if (size > 0) {
84 f_text.setPointSize(size * 4 / 3);
85 f_title.setPointSize(size * 3 / 2);
86 } else {
87 size = f_text.pixelSize();
88 f_text.setPixelSize(size * 4 / 3);
89 f_title.setPointSize(size * 3 / 2);
90 }
91 f_title.setBold(true);
92 f_title.setCapitalization(QFont::SmallCaps);
95 top = 0;
97 hide();
98 mult = 1;
99}
100
101/************************************************************************/
105{
106 delete fm_text;
107 delete fm_title;
108}
109
110/************************************************************************/
114{
115 if (event->key() == Qt::Key_Escape) {
116 close();
117 destroy();
118 event->accept();
119 }
120 QWidget::keyPressEvent(event);
121}
122
123/************************************************************************/
127{
130 int w, w2, h;
131 QPoint p;
132
133 if (s1.contains('\n')) {
134 int i;
135
136 i = s1.indexOf('\n');
137 cs1 = s1.left(i);
138 cs2 = s1.right(s1.length() - i);
139 mult = 2;
140 w2 = qMax(fm_text->horizontalAdvance(cs1),
141 fm_text->horizontalAdvance(cs2));
142 w = qMax(w2, fm_title->horizontalAdvance(s2));
143 } else {
144 w = qMax(fm_text->horizontalAdvance(s1),
145 fm_title->horizontalAdvance(s2));
146 }
147 w = w + 20;
148 h = mult * (fm_text->height() * 3 / 2) + 2 * fm_title->height();
149 top = 2 * fm_title->height();
150 spacer = new QSpacerItem(w, 0, QSizePolicy::Minimum,
151 QSizePolicy::Expanding);
152 layout = (QGridLayout *)this->layout();
153 layout->addItem(spacer, layout->rowCount(), 0, 1, layout->columnCount());
154 spacer = new QSpacerItem(0, h, QSizePolicy::Expanding,
155 QSizePolicy::Minimum);
156 layout->addItem(spacer, 0, 0, 1, layout->columnCount());
157
158 text = s1;
159 title = s2;
160
161 p = QPoint((parentWidget()->width() - w) / 2,
162 (parentWidget()->height() - h) / 2);
163 p = parentWidget()->mapToGlobal(p);
164 move(p);
165 if (!return_exec) {
166 show ();
167 }
168 m_timer.start();
169 startTimer(45);
170 return (return_exec) ? exec () : 0;
171}
172
173/************************************************************************/
177{
178 m_animate_step = m_timer.elapsed() / 40;
179 update();
180}
181
182/************************************************************************/
186{
187 QPainter p;
188 QRect rx, ry, rfull;
190 QColor c1;
191 QColor c2;
192 int step;
193
194 step = m_animate_step % 300;
195 if (step > 150) {
196 step = step - 150;
197 step = 150 - step;
198 }
199 step = step + 30;
200
201 rfull = QRect(2 , 2, width() - 4 , height() - 4);
202 rx = QRect(2 , 2, width() - 4 , top);
203 ry = QRect(2 , top, width() - 4, height() - top - 4);
204
205 c1 = QColor(palette().color(QPalette::Highlight));
206 c2 = QColor(palette().color(QPalette::AlternateBase));
207 step = qMax(0, step);
208 step = qMin(255, step);
209 c1.setAlpha(step);
210 c2.setAlpha(step);
211
212 g = QLinearGradient(0 , 0, width(), height());
213 g.setColorAt(0, c1);
214 g.setColorAt(1, c2);
215
216 p.begin(this);
217 p.fillRect(rx, QColor(palette().color(QPalette::Highlight)));
218 p.fillRect(ry, QColor(palette().color(QPalette::AlternateBase)));
219 p.fillRect(rfull, g);
220 p.setFont(f_title);
221 p.drawText((width() - fm_title->horizontalAdvance(title)) / 2,
222 fm_title->height() * 4 / 3, title);
223 p.setFont(f_text);
224 if (mult == 1) {
225 p.drawText((width() - fm_text->horizontalAdvance(text)) / 2,
226 2 * fm_title->height() + fm_text->height() * 4 / 3, text);
227 } else {
228 p.drawText((width() - fm_text->horizontalAdvance(cs1)) / 2,
229 2 * fm_title->height() + fm_text->height() * 4 / 3, cs1);
230 p.drawText((width() - fm_text->horizontalAdvance(cs2)) / 2,
231 2 * fm_title->height() + fm_text->height() * 8 / 3, cs2);
232 }
233 p.end();
234 event->accept();
235}
236
237/************************************************************************/
241 QWidget *parent) : QWidget(parent)
242{
243 int size;
244
245 text = s;
247
248 setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
250 f_text.setBold(true);
251 f_text.setCapitalization(QFont::SmallCaps);
252 size = f_text.pointSize();
253 if (size > 0) {
254 f_text.setPointSize(size * 2);
255 } else {
256 size = f_text.pixelSize();
257 f_text.setPixelSize(size * 2);
258 }
260 m_animate_step = 0;
261 m_timer.start();
262 startTimer(46);
263 setAttribute(Qt::WA_TranslucentBackground);
264 setAttribute(Qt::WA_ShowWithoutActivating);
265 setAttribute(Qt::WA_TransparentForMouseEvents);
266 setFocusPolicy(Qt::NoFocus);
267}
268
269/************************************************************************/
273{
274 show();
275 center_me();
276}
277
278/************************************************************************/
282{
283 int w;
284 QPoint p;
285
286 w = width();
287 if (!bound_rect.isEmpty()) {
288 setFixedSize(bound_rect.width(), bound_rect.height());
289 }
290 p = QPoint((parentWidget()->width() - w) / 2,
291 parentWidget()->height() / 20);
292 move(p);
293}
294
295/************************************************************************/
299{
300 delete fm_text;
301}
302
303/************************************************************************/
307{
308 m_animate_step = m_timer.elapsed() / 40;
309 if (m_timer.elapsed() > timeout * 1000) {
310 close();
311 deleteLater();
312 }
313 update();
314}
315
316/************************************************************************/
320{
321 QPainter p;
322 QRect rfull;
323 QColor c1;
324 QColor c2;
325 float opacity;
326
327 center_me();
328 if (m_timer.elapsed() < timeout * 500) {
329 opacity = static_cast<float>(m_timer.elapsed())/(timeout * 300);
330 } else {
331 opacity = static_cast<float>(5000 - m_timer.elapsed())/(timeout * 200);
332 }
333 opacity = qMin(1.0f, opacity);
334 opacity = qMax(0.0f, opacity);
335 rfull = QRect(0 , 0, width(), height());
336 c1 = QColor(Qt::white);
337 c2 = QColor(35, 35, 35, 175);
338 c1.setAlphaF(c1.alphaF() * opacity);
339 c2.setAlphaF(c2.alphaF() * opacity);
340 p.begin(this);
341 p.setBrush(c2);
342 p.setPen(QColor(0, 0, 0, 0));
343 p.drawRoundedRect(rfull, height() / 6 , height() / 6);
344 p.setFont(f_text);
345 p.setPen(c1);
346 p.drawText(rfull, Qt::AlignCenter, text, &bound_rect);
347
348 p.end();
349}
350
351/************************************************************************/
355{
356 int size;
357
358 setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Dialog
359 | Qt::FramelessWindowHint);
360
363
364 size = f_text.pointSize();
365 if (size > 0) {
366 f_text.setPointSize(size * 4 / 3);
367 f_title.setPointSize(size * 3 / 2);
368 } else {
369 size = f_text.pixelSize();
370 f_text.setPixelSize(size * 4 / 3);
371 f_title.setPointSize(size * 3 / 2);
372 }
373 f_title.setBold(true);
374 f_title.setCapitalization(QFont::SmallCaps);
377 top = 0;
378 m_animate_step = 0;
379 hide();
380 mult = 1;
381}
382
383/************************************************************************/
387{
388 delete fm_text;
389 delete fm_title;
390}
391
392/************************************************************************/
397{
400 int w, w2, h;
401 QDialogButtonBox *button_box;
402 QPoint p;
403
404 button_box = new QDialogButtonBox(QDialogButtonBox::Ok
405 | QDialogButtonBox::Cancel,
406 Qt::Horizontal, this);
407 layout = new QVBoxLayout;
408 if (s1.contains('\n')) {
409 int i;
410
411 i = s1.indexOf('\n');
412 cs1 = s1.left(i);
413 cs2 = s1.right(s1.length() - i);
414 mult = 2;
415 w2 = qMax(fm_text->horizontalAdvance(cs1),
416 fm_text->horizontalAdvance(cs2));
417 w = qMax(w2, fm_title->horizontalAdvance(s2));
418 } else {
419 w = qMax(fm_text->horizontalAdvance(s1),
420 fm_title->horizontalAdvance(s2));
421 }
422 w = w + 20;
423 h = mult * (fm_text->height() * 3 / 2) + 2 * fm_title->height();
424 top = 2 * fm_title->height();
425
426 spacer = new QSpacerItem(w, h, QSizePolicy::Expanding,
427 QSizePolicy::Minimum);
428 layout->addItem(spacer);
429 layout->addWidget(&input_edit);
430 layout->addWidget(button_box);
431 input_edit.setFont(f_text);
432 input_edit.setText(def_input);
434 QObject::connect(button_box, &QDialogButtonBox::accepted, this, &QDialog::accept);
435 QObject::connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
436
437 text = s1;
438 title = s2;
439 p = QPoint((parentWidget()->width() - w) / 2,
440 (parentWidget()->height() - h) / 2);
441 p = parentWidget()->mapToGlobal(p);
442 move(p);
443 input_edit.activateWindow();
444 input_edit.setFocus();
445 m_timer.start();
446 startTimer(41);
447 show();
448 update();
449}
450
451/************************************************************************/
455{
456 m_animate_step = m_timer.elapsed() / 40;
457 update();
458}
459
460/************************************************************************/
464{
465 QPainter p;
466 QRect rx, ry;
468 QColor c1;
469 QColor c2;
470 QColor c3;
471 int step;
472 float fstep;
473
474
475 step = m_animate_step % 300;
476 if (step > 150) {
477 step = step - 150;
478 step = 150 - step;
479 }
480 step = step + 10;
481 rx = QRect(2 , 2, width() - 4 , top);
482 ry = QRect(2 , top, width() - 4, height() - top - 4);
483
484 c1 = QColor(palette().color(QPalette::Highlight));
485 c2 = QColor(Qt::transparent);
486 c3 = QColor(palette().color(QPalette::Highlight)).lighter(145);
487 step = qMax(0, step);
488 step = qMin(255, step);
489 c1.setAlpha(step);
490 c2.setAlpha(step);
491 c3.setAlpha(step);
492
493 fstep = static_cast<float>(step) / 400;
494 g = QLinearGradient(0 , 0, width(), height());
495 g.setColorAt(0, c2);
496 g.setColorAt(fstep, c3);
497 g.setColorAt(1, c2);
498
499 p.begin(this);
500 p.fillRect(rx, QColor(palette().color(QPalette::Highlight)));
501 p.fillRect(ry, QColor(palette().color(QPalette::AlternateBase)));
502 p.fillRect(rx, g);
503 p.setFont(f_title);
504 p.drawText((width() - fm_title->horizontalAdvance(title)) / 2,
505 fm_title->height() * 4 / 3, title);
506 p.setFont(f_text);
507 if (mult == 1) {
508 p.drawText((width() - fm_text->horizontalAdvance(text)) / 2,
509 2 * fm_title->height() + fm_text->height() * 4 / 3, text);
510 } else {
511 p.drawText((width() - fm_text->horizontalAdvance(cs1)) / 2,
512 2 * fm_title->height() + fm_text->height() * 4 / 3, cs1);
513 p.drawText((width() - fm_text->horizontalAdvance(cs2)) / 2,
514 2 * fm_title->height() + fm_text->height() * 8 / 3, cs2);
515 }
516 p.end();
517 event->accept();
518}
519
520/************************************************************************/
524{
525 QVBoxLayout *vbox;
529
531 sp = new QSpacerItem(50, 2);
532 vbox = new QVBoxLayout;
533 unit_lab = new QVBoxLayout;
534 unit_lab->setContentsMargins(6, 9, 0, 3);
535 vbox->setSpacing(0);
536 unit_lab->addWidget(&unit_label);
537 main_layout->addLayout(unit_lab);
538 main_layout->addWidget(&tile_label);
539 unit_icons = new unit_actions(this, nullptr);
540 vbox->addSpacerItem(sp);
541 vbox->addWidget(&text_label);
542 vbox->addWidget(unit_icons);
543 main_layout->addLayout(vbox);
544 main_layout->setSpacing(0);
545 main_layout->setSpacing(3);
546 main_layout->setContentsMargins(0, 0, 0, 0);
547 vbox->setSpacing(3);
548 vbox->setContentsMargins(0, 0, 0, 0);
550 mw = new move_widget(this);
551 setFocusPolicy(Qt::ClickFocus);
552
553}
554
555/************************************************************************/
561
562/************************************************************************/
566{
567 gui()->qt_settings.unit_info_pos_fx = static_cast<float>(event->pos().x())
568 / gui()->mapview_wdg->width();
569 gui()->qt_settings.unit_info_pos_fy = static_cast<float>(event->pos().y())
570 / gui()->mapview_wdg->height();
571}
572
573/************************************************************************/
577{
578 int num;
579 int wwidth;
580 int font_width;
585 QImage img;
586 QPainter p;
587 QPixmap pix, pix2;
589 QString mp;
593 struct canvas *tile_pixmap;
594 struct canvas *unit_pixmap;
595 struct city *pcity;
596 struct player *owner;
597 struct tileset *tmp;
598 struct unit *punit;
599
601 if (punit == nullptr) {
602 hide();
603 return;
604 }
605
606 font.setCapitalization(QFont::AllUppercase);
607 font.setBold(true);
609 text_label.setFixedHeight((height() * 2) / 10);
610
611 move(qRound(gui()->mapview_wdg->width()
612 * gui()->qt_settings.unit_info_pos_fx),
613 qRound((gui()->mapview_wdg->height()
614 * gui()->qt_settings.unit_info_pos_fy)));
615 unit_icons->setFixedHeight((height() * 8) / 10);
616
617 setUpdatesEnabled(false);
618
619 tmp = nullptr;
620 if (unscaled_tileset) {
621 tmp = tileset;
623 }
625 owner = punit->owner;
627 if (pcity != NULL) {
628 text_str = QString(("%1(%2)"))
630 }
631 text_str = text_str + " ";
635 unit_type_get(punit)->move_rate
636 * ((punit->fuel) - 1)
637 + punit->moves_left), false))
638 + QString(")");
639 }
640 // TRANS: MP = Movement points
641 mp = QString(_("MP: ")) + mp;
642 text_str = text_str + mp + " ";
643 text_str += QString(_("HP:%1/%2")).arg(
644 QString::number(punit->hp),
645 QString::number(unit_type_get(punit)->hp));
647 snum = QString::number(unit_list_size(punit->tile->units) - 1);
650
651 // TRANS: preserve leading space; always at least 2
652 text_str = text_str + QString(PL_(" (Selected %1 unit)",
653 " (Selected %1 units)", n))
654 .arg(n);
655 } else if (num > 1) {
657
658 ut_bytes = snum.toUtf8();
659 // TRANS: preserve leading space
660 text_str = text_str + QString(PL_(" +%1 unit",
661 " +%1 units", num-1))
662 .arg(ut_bytes.data());
663 }
664 text_label.setTextFormat(Qt::PlainText);
665 text_label.setText(text_str);
666 font.setPixelSize((text_label.height() * 9) / 10);
667 text_label.setFont(font);
668 fm = new QFontMetrics(font);
669 text_label.setFixedWidth(fm->horizontalAdvance(text_str) + 20);
670 delete fm;
671
674 unit_pixmap->map_pixmap.fill(Qt::transparent);
675 put_unit(punit, unit_pixmap, 1, 0, 0);
676 img = unit_pixmap->map_pixmap.toImage();
678 cropped_img = img.copy(crop);
679 img = cropped_img.scaledToHeight(height(), Qt::SmoothTransformation);
681 ((height() + 0.0) / tileset_unit_height(tileset));
682 pix = QPixmap::fromImage(img);
683 /* add transparent borders if image is too slim, accounting for the
684 * scaledToHeight() we've applied */
685 if (pix.width() < expanded_unit_width) {
686 pix2 = QPixmap(expanded_unit_width, pix.height());
687 pix2.fill(Qt::transparent);
688 p.begin(&pix2);
689 p.drawPixmap(expanded_unit_width / 2 - pix.width() / 2, 0, pix);
690 p.end();
691 pix = pix2;
692 }
693
694 // Draw movement points
696 if (move_pt_text.contains('/')) {
697 fraction2 = move_pt_text.right(1);
698 move_pt_text.remove(move_pt_text.length() - 2, 2);
699 fraction1 = move_pt_text.right(1);
700 move_pt_text.remove(move_pt_text.length() - 1, 1);
701 }
702 crop = QRect(5, 5, pix.width() - 5, pix.height() - 5);
703 font.setCapitalization(QFont::Capitalize);
704 font.setPointSize((pix.height() * 2) / 5);
705 p.begin(&pix);
706 p.setFont(font);
707 p.setPen(Qt::white);
708 p.drawText(crop, Qt::AlignLeft | Qt::AlignBottom, move_pt_text,
710
711 bounding_rect.adjust(bounding_rect.width(), 0 ,
712 bounding_rect.width() * 2, 0);
713 if (punit->fuel > 1) {
714 QString s;
715 int fuel;
716
717 font.setPointSize(pix.height() / 4);
718 p.setFont(font);
719 fuel = punit->fuel - 1;
720 fuel = fuel * punit->utype->move_rate / SINGLE_MOVE;
721 p.drawText(bounding_rect, Qt::AlignCenter,
722 QString("+") + QString::number(fuel));
723 }
724
725 if (move_pt_text.isEmpty()) {
726 move_pt_text = " ";
727 }
728 bounding_rect = p.boundingRect(crop, Qt::AlignLeft | Qt::AlignBottom,
730 font.setPointSize(pix.height() / 5);
731 fm = new QFontMetrics(font);
732 font_width = (fm->horizontalAdvance(move_pt_text) * 3) / 5;
733 delete fm;
734 p.setFont(font);
735 if (!fraction1.isNull()) {
736 int t = 2 * font.pointSize();
737
739 bounding_rect.top(), t, (t / 5) * 4);
740 p.drawText(crop, Qt::AlignLeft | Qt::AlignBottom, fraction1);
742 (bounding_rect.bottom() + bounding_rect.top()) / 2,
743 t, (t / 5) * 4);
744 p.drawText(crop, Qt::AlignLeft | Qt::AlignTop, fraction2);
746 (bounding_rect.bottom() + bounding_rect.top()) / 2 - t / 16,
747 (t * 2) / 5, t / 8);
748 p.fillRect(crop, Qt::white);
749 }
750 p.end();
751 wwidth = 2 * 3 + pix.width();
752 unit_label.setPixmap(pix);
756 } else {
759 }
760 tile_pixmap->map_pixmap.fill(QColor(0 , 0 , 0 , 0));
761 put_terrain(punit->tile, tile_pixmap, 1.0, 0, 0);
762 img = tile_pixmap->map_pixmap.toImage();
764 cropped_img = img.copy(crop);
765 img = cropped_img.scaledToHeight(height() - 5, Qt::SmoothTransformation);
766 pix = QPixmap::fromImage(img);
767 tile_label.setPixmap(pix);
768 unit_label.setToolTip(popup_info_text(punit->tile));
770 wwidth = wwidth + pix.width();
773
775 / 10, text_label.width()));
776 mw->put_to_corner();
777 if (tmp != nullptr) {
778 tileset = tmp;
779 }
780 setUpdatesEnabled(true);
782 update();
783
784 show();
785}
786
787/************************************************************************/
791{
793}
794
795/************************************************************************/
799{
800 if (e->button() == Qt::LeftButton) {
802 }
803}
804
805/************************************************************************/
809{
810 gui()->game_tab_widget->setCurrentIndex(0);
812}
813
814/************************************************************************/
818{
819 connect(this, &hud_action::left_clicked, this, &hud_action::on_clicked);
820 setFocusPolicy(Qt::StrongFocus);
821 setMouseTracking(true);
822 focus = false;
823 action_pixmap = nullptr;
824}
825
826/************************************************************************/
830{
831 action_pixmap = p;
832}
833
834/************************************************************************/
838{
839 QRect rx, ry, rz;
840 QPainter p;
841
842 rx = QRect(0, 0, width(), height());
843 ry = QRect(0, 0, action_pixmap->width(), action_pixmap->height());
844 rz = QRect(0, 0, width() - 1, height() - 3);
845 p.begin(this);
846 p.setCompositionMode(QPainter::CompositionMode_Source);
847 p.setRenderHint(QPainter::SmoothPixmapTransform);
848 p.drawPixmap(rx, *action_pixmap, ry);
849 p.setPen(QColor(palette().color(QPalette::Text)));
850 p.drawRect(rz);
851 if (focus) {
852 p.setCompositionMode(QPainter::CompositionMode_DestinationOver);
853 p.fillRect(rx, QColor(palette().color(QPalette::Highlight)));
854 }
855 p.end();
856
857}
858
859/************************************************************************/
863{
864 if (action_pixmap) {
865 delete action_pixmap;
866 }
867}
868
869/************************************************************************/
873{
874 if (e->button() == Qt::RightButton) {
876 } else if (e->button() == Qt::LeftButton) {
878 }
879}
880
881/************************************************************************/
885{
886 focus = true;
887 update();
888}
889
890/************************************************************************/
894{
895 focus = false;
896 update();
897 QWidget::leaveEvent(event);
898}
899
900/************************************************************************/
903#ifndef FC_QT5_MODE
905#else // FC_QT5_MODE
906void hud_action::enterEvent(QEvent *event)
907#endif // FC_QT5_MODE
908{
909 focus = true;
910 update();
911 QWidget::enterEvent(event);
912}
913
914/************************************************************************/
920
921/************************************************************************/
925{
926 gui()->menu_bar->execute_shortcut(action_shortcut);
927}
928
929/************************************************************************/
933{
934 layout = new QHBoxLayout(this);
935 layout->setSpacing(3);
936 layout->setContentsMargins(0, 0, 0, 0);
938 init_layout();
939 setFocusPolicy(Qt::ClickFocus);
940}
941
942/************************************************************************/
950
951/************************************************************************/
955{
956 QSizePolicy size_fixed_policy(QSizePolicy::MinimumExpanding,
957 QSizePolicy::Fixed,
958 QSizePolicy::Frame);
960 layout->setSpacing(0);
962}
963
964/************************************************************************/
968{
969 hud_action *a;
970
972
973 if (current_unit == nullptr) {
974 clear_layout();
975 hide();
976 return 0;
977 }
978 /* HACK prevent crash with active goto when leaving widget,
979 * just skip update because with active goto actions shouldn't change */
980 if (goto_is_active() ) {
981 return actions.count();
982 }
983 hide();
984 clear_layout();
985 setUpdatesEnabled(false);
986
987
988 foreach (a, actions) {
989 delete a;
990 }
992 actions.clear();
993
994 // Create possible actions
995
997 a = new hud_action(this);
999 a->set_pixmap(fc_icons::instance()->get_pixmap("home"));
1000 actions.append(a);
1001 }
1002
1003
1005 a = new hud_action(this);
1007 a->set_pixmap(fc_icons::instance()->get_pixmap("mine"));
1008 actions.append(a);
1009 }
1010
1012 a = new hud_action(this);
1014 a->set_pixmap(fc_icons::instance()->get_pixmap("plantforest"));
1015 actions.append(a);
1016 }
1017
1019 a = new hud_action(this);
1021 a->set_pixmap(fc_icons::instance()->get_pixmap("irrigation"));
1022 actions.append(a);
1023 }
1024
1026 a = new hud_action(this);
1028 a->set_pixmap(fc_icons::instance()->get_pixmap("chopchop"));
1029 actions.append(a);
1030 }
1031
1033 a = new hud_action(this);
1035 a->set_pixmap(fc_icons::instance()->get_pixmap("transform"));
1036 actions.append(a);
1037 }
1038
1039 // Road
1040 {
1041 bool ok = false;
1042
1044 struct road_type *proad = extra_road_get(pextra);
1045
1047 ok = true;
1048 }
1050 if (ok) {
1051 a = new hud_action(this);
1053 a->set_pixmap(fc_icons::instance()->get_pixmap("buildroad"));
1054 actions.append(a);
1055 }
1056 }
1057 // Goto
1058 a = new hud_action(this);
1060 a->set_pixmap(fc_icons::instance()->get_pixmap("goto"));
1061 actions.append(a);
1062
1063
1065 a = new hud_action(this);
1067 a->set_pixmap(fc_icons::instance()->get_pixmap("fortify"));
1068 actions.append(a);
1069 }
1070
1071
1073 a = new hud_action(this);
1075 a->set_pixmap(fc_icons::instance()->get_pixmap("sentry"));
1076 actions.append(a);
1077 }
1078
1079 // Board
1081 a = new hud_action(this);
1083 a->set_pixmap(fc_icons::instance()->get_pixmap("load"));
1084 actions.append(a);
1085 }
1086
1087 // Set homecity
1091 a = new hud_action(this);
1093 a->set_pixmap(fc_icons::instance()->get_pixmap("set_homecity"));
1094 actions.append(a);
1095 }
1096 }
1097
1098 // Upgrade
1100 a = new hud_action(this);
1102 a->set_pixmap(fc_icons::instance()->get_pixmap("upgrade"));
1103 actions.append(a);
1104 }
1105
1106 // Automate
1108 a = new hud_action(this);
1110 a->set_pixmap(fc_icons::instance()->get_pixmap("automate"));
1111 actions.append(a);
1112 }
1113
1114 // Paradrop
1116 a = new hud_action(this);
1118 a->set_pixmap(fc_icons::instance()->get_pixmap("paradrop"));
1119 actions.append(a);
1120 }
1121
1122 // Clean
1124 a = new hud_action(this);
1126 a->set_pixmap(fc_icons::instance()->get_pixmap("clean"));
1127 actions.append(a);
1128 }
1129
1130 // Deboard
1135 a = new hud_action(this);
1137 a->set_pixmap(fc_icons::instance()->get_pixmap("unload"));
1138 actions.append(a);
1139 }
1140
1141 // Nuke
1143 a = new hud_action(this);
1145 a->set_pixmap(fc_icons::instance()->get_pixmap("nuke"));
1146 actions.append(a);
1147 }
1148
1149 // Wait
1150 a = new hud_action(this);
1152 a->set_pixmap(fc_icons::instance()->get_pixmap("wait"));
1153 actions.append(a);
1154
1155 // Done moving
1156 a = new hud_action(this);
1158 a->set_pixmap(fc_icons::instance()->get_pixmap("done"));
1159 actions.append(a);
1160
1161
1162 foreach (a, actions) {
1163 a->setToolTip(gui()->menu_bar->shortcut_2_menustring(a->action_shortcut));
1164 a->setFixedHeight(height());
1165 a->setFixedWidth(height());
1166 layout->addWidget(a);
1167 }
1168
1169 setFixedWidth(actions.count() * height());
1170 setUpdatesEnabled(true);
1171 show();
1172 layout->update();
1174 return actions.count();
1175}
1176
1177/************************************************************************/
1181{
1182 int i = actions.count();
1183 hud_action *ui;
1184 int j;
1185
1186 setUpdatesEnabled(false);
1187 for (j = 0; j < i; j++) {
1188 ui = actions[j];
1189 layout->removeWidget(ui);
1190 delete ui;
1191 }
1192 while (!actions.empty()) {
1193 actions.removeFirst();
1194 }
1195 setUpdatesEnabled(true);
1196}
1197
1198/************************************************************************/
1202{
1203 setProperty("showGrid", "false");
1204 setProperty("selectionBehavior", "SelectRows");
1205 setEditTriggers(QAbstractItemView::NoEditTriggers);
1206 setSelectionMode(QAbstractItemView::SingleSelection);
1207 verticalHeader()->setVisible(false);
1208 horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
1209 horizontalHeader()->setVisible(false);
1210 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1211 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1212 connect(selectionModel(),
1214 const QItemSelection &)), this,
1216 const QItemSelection &)));
1217 cargo = pcargo;
1218 qtile = ptile;
1219
1220}
1221
1222/************************************************************************/
1228
1229/************************************************************************/
1234{
1236 int max_size = 0;
1237 int i, j;
1238 int w,h;
1239 sprite *spite;
1240
1245 transports.append(ptransport);
1246 max_size = qMax(max_size, get_transporter_occupancy(ptransport));
1247 }
1249
1250 setRowCount(transports.count());
1251 setColumnCount(max_size + 1);
1252 for (i = 0 ; i < transports.count(); i++) {
1253 QString str;
1254 struct unit *tp = transports.at(i);
1255
1256 spite = get_unittype_sprite(tileset, tp->utype, tp->activity,
1258 str = utype_rule_name(transports.at(i)->utype);
1259 // TRANS: MP - just movement points
1260 str = str + " ("
1261 + QString(move_points_text(transports.at(i)->moves_left, false))
1262 + _("MP") + ")";
1263 new_item = new QTableWidgetItem(QIcon(*spite->pm), str);
1264 setItem(i, 0, new_item);
1265 j = 1;
1266 unit_list_iterate(transports.at(i)->transporting, tunit) {
1267 spite = get_unittype_sprite(tileset, tunit->utype, tunit->activity,
1269 new_item = new QTableWidgetItem(QIcon(*spite->pm), "");
1270 setItem(i, j, new_item);
1271 j++;
1273 }
1274
1275 w = verticalHeader()->width() + 4;
1276 for (i = 0; i < columnCount(); i++) {
1277 w += columnWidth(i);
1278 }
1279 h = horizontalHeader()->height() + 4;
1280 for (i = 0; i < rowCount(); i++) {
1281 h += rowHeight(i);
1282 }
1283
1284 resize(w, h);
1285 setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Dialog
1286 | Qt::FramelessWindowHint);
1287 show();
1288}
1289
1290/************************************************************************/
1294 const QItemSelection& s2)
1295{
1296 int curr_row;
1297
1298 curr_row = s1.indexes().at(0).row();
1299 request_unit_load(cargo, transports.at(curr_row), qtile);
1300 close();
1301}
1302
1303/************************************************************************/
1307{
1312
1313 hide();
1314 struct unit *punit = head_of_units_in_focus();
1315
1316 setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Dialog
1317 | Qt::FramelessWindowHint);
1318 main_layout = new QVBoxLayout(this);
1319
1320 unit_sel_type = new QComboBox();
1321
1322 unit_type_iterate(utype) {
1323 utype_id = utype_index(utype);
1326 }
1327 }
1329
1330 if (punit) {
1331 int i;
1333 unit_sel_type->setCurrentIndex(i);
1334 }
1335 no_name = new QGroupBox();
1336 no_name->setTitle(_("Unit type"));
1337 this_type = new QRadioButton(_("Selected type"), no_name);
1338 this_type->setChecked(true);
1339 any_type = new QRadioButton(_("All types"), no_name);
1340 connect(unit_sel_type, SIGNAL(currentIndexChanged(int)), this,
1341 SLOT(select_units(int)));
1342 connect(this_type, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1343 connect(any_type, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1345 groupbox_layout->addWidget(unit_sel_type);
1346 groupbox_layout->addWidget(this_type);
1347 groupbox_layout->addWidget(any_type);
1348 no_name->setLayout(groupbox_layout);
1349 hibox = new QHBoxLayout;
1350 hibox->addWidget(no_name);
1351
1352 no_name = new QGroupBox();
1353 no_name->setTitle(_("Unit activity"));
1354 any_activity = new QRadioButton(_("Any activity"), no_name);
1355 any_activity->setChecked(true);
1356 fortified = new QRadioButton(_("Fortified"), no_name);
1357 idle = new QRadioButton(_("Idle"), no_name);
1358 sentried = new QRadioButton(_("Sentried"), no_name);
1359 connect(any_activity, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1360 connect(idle, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1361 connect(fortified, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1362 connect(sentried, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1364 groupbox_layout->addWidget(any_activity);
1365 groupbox_layout->addWidget(idle);
1366 groupbox_layout->addWidget(fortified);
1367 groupbox_layout->addWidget(sentried);
1368 no_name->setLayout(groupbox_layout);
1369 hibox->addWidget(no_name);
1370 main_layout->addLayout(hibox);
1371
1372 no_name = new QGroupBox();
1373 no_name->setTitle(_("Unit HP and MP"));
1374 any = new QRadioButton(_("Any unit"), no_name);
1375 full_hp = new QRadioButton(_("Full HP"), no_name);
1376 full_mp = new QRadioButton(_("Full MP"), no_name);
1377 full_hp_mp = new QRadioButton(_("Full HP and MP"), no_name);
1378 full_hp_mp->setChecked(true);
1379 connect(any, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1380 connect(full_hp, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1381 connect(full_mp, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1382 connect(full_hp_mp, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1384 groupbox_layout->addWidget(any);
1385 groupbox_layout->addWidget(full_hp);
1386 groupbox_layout->addWidget(full_mp);
1387 groupbox_layout->addWidget(full_hp_mp);
1388 no_name->setLayout(groupbox_layout);
1389 hibox = new QHBoxLayout;
1390 hibox->addWidget(no_name);
1391
1392 no_name = new QGroupBox();
1393 no_name->setTitle(_("Location"));
1394 anywhere = new QRadioButton(_("Anywhere"), no_name);
1395 this_tile = new QRadioButton(_("Current tile"), no_name);
1396 this_continent = new QRadioButton(_("Current continent"), no_name);
1397 main_continent = new QRadioButton(_("Main continent"), no_name);
1399
1400 if (punit) {
1401 this_tile->setChecked(true);
1402 } else {
1403 this_tile->setDisabled(true);
1404 this_continent->setDisabled(true);
1405 main_continent->setChecked(true);
1406 }
1407
1408 groupbox_layout->addWidget(this_tile);
1409 groupbox_layout->addWidget(this_continent);
1410 groupbox_layout->addWidget(main_continent);
1411 groupbox_layout->addWidget(anywhere);
1412
1413 no_name->setLayout(groupbox_layout);
1414 hibox->addWidget(no_name);
1415 main_layout->addLayout(hibox);
1416
1417 select = new QPushButton(_("Select"));
1418 cancel = new QPushButton(_("Cancel"));
1419 connect(anywhere, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1420 connect(this_tile, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1421 connect(this_continent, SIGNAL(toggled(bool)), this,
1422 SLOT(select_units(bool)));
1423 connect(main_continent, SIGNAL(toggled(bool)), this,
1424 SLOT(select_units(bool)));
1425 connect(select, &QAbstractButton::clicked, this, &unit_hud_selector::uhs_select);
1426 connect(cancel, &QAbstractButton::clicked, this, &unit_hud_selector::uhs_cancel);
1427 hbox = new QHBoxLayout;
1428 hbox->addWidget(cancel);
1429 hbox->addWidget(select);
1430
1431 result_label.setAlignment(Qt::AlignCenter);
1432 main_layout->addWidget(&result_label, Qt::AlignHCenter);
1433 main_layout->addLayout(hbox);
1435
1436}
1437
1438/************************************************************************/
1442{
1443 QPoint p;
1444
1445 p = QPoint((parentWidget()->width() - sizeHint().width()) / 2,
1446 (parentWidget()->height() - sizeHint().height()) / 2);
1447 p = parentWidget()->mapToGlobal(p);
1448 move(p);
1449 setVisible(true);
1450 show();
1451 select_units();
1452}
1453
1454/************************************************************************/
1460
1461/************************************************************************/
1465{
1466 const struct player *pplayer;
1467
1468 pplayer = client_player();
1469
1470 unit_list_iterate(pplayer->units, punit) {
1474 }
1476 close();
1477}
1478
1479/************************************************************************/
1483{
1484 close();
1485}
1486
1487/************************************************************************/
1491{
1492 int num = 0;
1493 const struct player *pplayer;
1494
1495 pplayer = client_player();
1496
1497 unit_list_iterate(pplayer->units, punit) {
1500 num++;
1501 }
1503 result_label.setText(QString(PL_("%1 unit", "%1 units", num)).arg(num));
1504}
1505
1506/************************************************************************/
1510{
1511 select_units(0);
1512}
1513
1514/************************************************************************/
1518{
1519 if ((event->key() == Qt::Key_Return)
1520 || (event->key() == Qt::Key_Enter)) {
1521 uhs_select();
1522 }
1523 if (event->key() == Qt::Key_Escape) {
1524 close();
1525 event->accept();
1526 }
1527 QWidget::keyPressEvent(event);
1528}
1529
1530/************************************************************************/
1534{
1535 if ((punit->activity == ACTIVITY_FORTIFIED && fortified->isChecked())
1536 || (punit->activity == ACTIVITY_SENTRY && sentried->isChecked())
1537 || (punit->activity == ACTIVITY_IDLE && idle->isChecked())
1538 || any_activity->isChecked()) {
1539 return true;
1540 }
1541 return false;
1542}
1543
1544/************************************************************************/
1548{
1549 if ((any->isChecked()
1550 || (full_mp->isChecked()
1552 || (full_hp->isChecked() && punit->hp >= punit->utype->hp)
1553 || (full_hp_mp->isChecked() && punit->hp >= punit->utype->hp
1554 && punit->moves_left >= punit->utype->move_rate))) {
1555 return true;
1556 }
1557 return false;
1558}
1559
1560/************************************************************************/
1564{
1565 int island = -1;
1566 struct unit *cunit = head_of_units_in_focus();
1567
1568 if (this_tile->isChecked() && cunit) {
1569 if (punit->tile == cunit->tile) {
1570 return true;
1571 }
1572 }
1573
1574 if (main_continent->isChecked()
1577 } else if (this_continent->isChecked() && cunit) {
1578 island = cunit->tile->continent;
1579 }
1580
1581 if (island > -1) {
1582 if (punit->tile->continent == island) {
1583 return true;
1584 }
1585 }
1586
1587 if (anywhere->isChecked()) {
1588 return true;
1589 }
1590 return false;
1591}
1592
1593/************************************************************************/
1597{
1598 QVariant qvar;
1600
1601 if (this_type->isChecked()) {
1602 qvar = unit_sel_type->currentData();
1603 utype_id = qvar.toInt();
1604 if (utype_id == utype_index(punit->utype)) {
1605 return true;
1606 } else {
1607 return false;
1608 }
1609 }
1610 if (any_type->isChecked()) {
1611 return true;
1612 }
1613 return false;
1614}
1615
1616/************************************************************************/
1620{
1621 int movement_cost;
1622 struct terrain *terr;
1623 QString ret, t, move_text;
1624 bool has_road = false;
1625
1626 terr = ptile->terrain;
1627 ret = QString(_("Terrain: %1\n")).arg(tile_get_info_text(ptile, TRUE, 0));
1628 ret = ret + QString(_("Food/Prod/Trade: %1\n"))
1629 .arg(get_tile_output_text(ptile));
1630 t = get_infrastructure_text(ptile->extras);
1631 if (t != "") {
1632 ret = ret + QString(_("Infrastructure: %1\n")).arg(t);
1633 }
1634 ret = ret + QString(_("Defense bonus: %1%\n")).arg(terr->defense_bonus);
1635 movement_cost = terr->movement_cost;
1636
1638 struct road_type *proad = extra_road_get(pextra);
1639
1640 if (tile_has_road(ptile, proad)) {
1641 if (proad->move_cost <= movement_cost) {
1642 has_road = true;
1643 move_text = move_points_text(proad->move_cost, TRUE);
1644 movement_cost = proad->move_cost;
1645 }
1646 }
1648
1649 if (has_road) {
1650 ret = ret + QString(_("Movement cost: %1")).arg(move_text);
1651 } else {
1652 ret = ret + QString(_("Movement cost: %1")).arg(movement_cost);
1653 }
1654
1655 return ret;
1656}
1657
1658/************************************************************************/
1662{
1663 QString s;
1664 hud_text *ht;
1666 struct research *research;
1667 int i;
1668 char buf[25];
1669
1670 if (!client_has_player()
1671 || !gui()->qt_settings.show_new_turn_text) {
1672 return;
1673 }
1674 close_list = gui()->mapview_wdg->findChildren<hud_text *>();
1675 for (i = 0; i < close_list.size(); ++i) {
1676 close_list.at(i)->close();
1677 close_list.at(i)->deleteLater();
1678 }
1680 s = QString(_("Year: %1 (Turn: %2)"))
1681 .arg(calendar_text()).arg(game.info.turn) + "\n";
1683 if (client_is_observer()) {
1684 s += QString(_(" (observer)"));
1685 }
1686 s += " - " + QString(_("Population: %1"))
1690 && research->researching != A_NONE) {
1693 " (" + QString::number(research->bulbs_researched) + "/"
1694 + QString::number(research->client.researching_cost) + ")";
1695 }
1696 s = s + "\n" + science_dialog_text() + "\n";
1697
1698 // Can't use QString().sprintf() as msys libintl.h defines sprintf() as a macro
1700
1701 // TRANS: current gold, then loss/gain per turn
1702 s = s + QString(_("Gold: %1 (%2)"))
1704 .arg(buf);
1705 ht = new hud_text(s, 5, gui()->mapview_wdg);
1706 ht->show_me();
1707}
1708
1709/************************************************************************/
1712hud_unit_combat::hud_unit_combat(int attacker_unit_id, int defender_unit_id,
1713 int attacker_hp, int defender_hp,
1714 bool make_att_veteran, bool make_def_veteran,
1715 float scale, QWidget *parent) : QWidget(parent)
1716{
1717 hud_scale = scale;
1718 att_hp = attacker_hp;
1719 def_hp = defender_hp;
1720
1721 attacker = game_unit_by_number(attacker_unit_id);
1722 defender = game_unit_by_number(defender_unit_id);
1725 att_veteran = make_att_veteran;
1726 def_veteran = make_def_veteran;
1729 if (defender_hp <= 0) {
1731 } else {
1733 }
1734 init_images();
1735}
1736
1737/************************************************************************/
1741{
1743 QRect dr, ar;
1744 QPainter p;
1745 struct canvas *defender_pixmap;
1746 struct canvas *attacker_pixmap;
1747 int w;
1748
1749 focus = false;
1750 w = 3 * hud_scale * tileset_unit_height(tileset) / 2;
1751 setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
1752 setFixedSize(2 * w, w);
1755 defender_pixmap->map_pixmap.fill(Qt::transparent);
1756 if (defender != nullptr) {
1757 if (!redraw) {
1758 put_unit(defender, defender_pixmap, 1.0, 0, 0);
1759 } else {
1761 }
1762 dimg = defender_pixmap->map_pixmap.toImage();
1764 crdimg = dimg.copy(dr);
1765 dimg = crdimg.scaledToHeight(w, Qt::SmoothTransformation);
1766 }
1767 if (dimg.width() < w) {
1768 dt = QImage(w, dimg.height(), QImage::Format_ARGB32_Premultiplied);
1769 dt.fill(Qt::transparent);
1770 p.begin(&dt);
1771 p.drawImage(w / 2 - dimg.width() / 2, 0, dimg);
1772 p.end();
1773 dimg = dt;
1774 }
1775 dimg = dimg.scaled(w, w, Qt::IgnoreAspectRatio,
1776 Qt::SmoothTransformation);
1779 attacker_pixmap->map_pixmap.fill(Qt::transparent);
1780 if (attacker != nullptr) {
1781 if (!redraw) {
1783 } else {
1785 }
1786 aimg = attacker_pixmap->map_pixmap.toImage();
1788 acrimg = aimg.copy(ar);
1789 aimg = acrimg.scaledToHeight(w, Qt::SmoothTransformation);
1790 }
1791 if (aimg.width() < w) {
1792 at = QImage(w, dimg.height(), QImage::Format_ARGB32_Premultiplied);
1793 at.fill(Qt::transparent);
1794 p.begin(&at);
1795 p.drawImage(w / 2 - aimg.width() / 2, 0, aimg);
1796 p.end();
1797 aimg = at;
1798 }
1799 aimg = aimg.scaled(w, w, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
1800 delete defender_pixmap;
1801 delete attacker_pixmap;
1802}
1803
1804/************************************************************************/
1808{
1809 hud_scale = scale;
1810 init_images(true);
1811}
1812
1813/************************************************************************/
1819
1820/************************************************************************/
1824{
1825 fading = fade;
1826 update();
1827}
1828
1829/************************************************************************/
1833{
1834 return focus;
1835}
1836
1837/************************************************************************/
1841{
1842 QPainter p;
1843 QRect left, right;
1844 QColor c1, c2;
1845 QPen pen;
1848
1849 if (att_hp_loss > 0) {
1850 ahploss = "-" + QString::number(att_hp_loss);
1851 } else {
1852 ahploss = "0";
1853 }
1854 if (def_hp_loss > 0) {
1855 dhploss = "-" + QString::number(def_hp_loss);
1856 } else {
1857 dhploss = "0";
1858 }
1859 f.setBold(true);
1860
1861 if (def_hp == 0) {
1862 c1 = QColor(25, 125, 25, 175);
1863 c2 = QColor(125, 25, 25, 175);
1864 } else {
1865 c1 = QColor(125, 25, 25, 175);
1866 c2 = QColor(25, 125, 25, 175);
1867 }
1868 int w = 3 * tileset_unit_height(tileset) / 2 * hud_scale;
1869
1870 left = QRect(0 , 0, w , w);
1871 right = QRect(w, 0, w , w);
1872 pen = QPen(QColor(palette().color(QPalette::AlternateBase)), 2.0);
1873 p.begin(this);
1874 if (fading < 1.0) {
1875 p.setOpacity(fading);
1876 }
1877 if (focus) {
1878 p.fillRect(left, QColor(palette().color(QPalette::Highlight)));
1879 p.fillRect(right, QColor(palette().color(QPalette::Highlight)));
1880 c1.setAlpha(110);
1881 c2.setAlpha(110);
1882 }
1883 p.fillRect(left, c1);
1884 p.fillRect(right, c2);
1885 p.setPen(pen);
1886 p.drawRect(1, 1, width() - 2 , height() - 2);
1887 p.drawImage(left, aimg);
1888 p.setFont(f);
1889 p.setPen(QColor(Qt::white));
1890 if (def_veteran) {
1891 p.drawText(right, Qt::AlignHCenter | Qt::AlignJustify
1892 | Qt::AlignAbsolute, "*");
1893 }
1894 if (att_veteran) {
1895 p.drawText(left, Qt::AlignHCenter | Qt::AlignJustify
1896 | Qt::AlignAbsolute, "*");
1897 }
1898 p.drawText(left, Qt::AlignHorizontal_Mask, ahploss);
1899 p.drawImage(right, dimg);
1900 p.drawText(right, Qt::AlignHorizontal_Mask, dhploss);
1901 p.end();
1902}
1903
1904/************************************************************************/
1911
1912/************************************************************************/
1916{
1917 focus = false;
1918 update();
1919}
1920
1921/************************************************************************/
1924#ifndef FC_QT5_MODE
1926#else // FC_QT5_MODE
1928#endif // FC_QT5_MODE
1929{
1930 focus = true;
1931 update();
1932}
1933
1934
1935/************************************************************************/
1938scale_widget::scale_widget(QRubberBand::Shape s,
1939 QWidget* p) : QRubberBand(s, p)
1940{
1941 QPixmap *pix;
1942
1943 size = 12;
1944 pix = fc_icons::instance()->get_pixmap("plus");
1945 plus = pix->scaledToWidth(size);
1946 delete pix;
1947 pix = fc_icons::instance()->get_pixmap("minus");
1948 minus = plus = pix->scaledToWidth(size);
1949 delete pix;
1950 setFixedSize(2 * size, size);
1951 scale = 1.0f;
1952 setAttribute(Qt::WA_TransparentForMouseEvents, false);
1953}
1954
1955/************************************************************************/
1959{
1960 QRubberBand::paintEvent(event);
1961 QPainter p;
1962
1963 p.begin(this);
1964 p.drawPixmap(0, 0, minus);
1965 p.drawPixmap(size, 0, plus);
1966 p.end();
1967}
1968
1969/************************************************************************/
1973{
1974 if (event->button() == Qt::LeftButton) {
1975#ifndef FC_QT5_MODE
1976 if (event->position().x() <= size) {
1977#else /* FC_QT5_MODE */
1978 if (event->localPos().x() <= size) {
1979#endif /* FC_QT5_MODE */
1980 scale = scale / 1.2;
1981 } else {
1982 scale = scale * 1.2;
1983 }
1984 parentWidget()->update();
1985 }
1986}
1987
1988/************************************************************************/
1992{
1993 setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
1994 main_layout = new QVBoxLayout(this);
1995 mw = new move_widget(this);
1996 setContentsMargins(0, 0, 0, 0);
1997 main_layout->setContentsMargins(0, 0, 0, 0);
1998 sw = new scale_widget(QRubberBand::Rectangle, this);
1999 sw->show();
2000}
2001
2002/************************************************************************/
2006{
2007 delete sw;
2008 delete mw;
2009}
2010
2011/************************************************************************/
2015{
2017 int w = 3 * tileset_unit_height(tileset) / 2 * scale;
2018
2019 gui()->qt_settings.battlelog_scale = scale;
2020 delete layout();
2022 foreach (hudc, lhuc) {
2023 hudc->set_scale(scale);
2024 main_layout->addWidget(hudc);
2025 hudc->set_fading(1.0);
2026 }
2027 setFixedSize(2 * w + 10, lhuc.count() * w + 10);
2029
2030 update();
2031 show();
2032 m_timer.restart();
2033 startTimer(50);
2034}
2035
2036/************************************************************************/
2040{
2041 scale = s;
2042 sw->scale = s;
2043}
2044
2045/************************************************************************/
2049{
2051 int w = 3 * tileset_unit_height(tileset) / 2 * scale;
2052
2053 delete layout();
2055 lhuc.prepend(huc);
2056 while (lhuc.count() > 5) {
2057 hudc = lhuc.takeLast();
2058 delete hudc;
2059 }
2060 foreach (hudc, lhuc) {
2061 main_layout->addWidget(hudc);
2062 hudc->set_fading(1.0);
2063 }
2064 setFixedSize(2 * w + 10, lhuc.count() * w + 10);
2066
2067 update();
2068 show();
2069 m_timer.restart();
2070 startTimer(50);
2071}
2072
2073/************************************************************************/
2077{
2078 if (scale != sw->scale) {
2079 scale = sw->scale;
2080 update_size();
2081 }
2082 mw->put_to_corner();
2083 sw->move(width() - sw->width(), 0);
2084}
2085
2086/************************************************************************/
2090{
2091 QPoint p;
2092
2093 p = pos();
2094 gui()->qt_settings.battlelog_x = static_cast<float>(p.x()) / mapview.width;
2095 gui()->qt_settings.battlelog_y = static_cast<float>(p.y())
2096 / mapview.height;
2097 m_timer.restart();
2098}
2099
2100/************************************************************************/
2106{
2108
2109 foreach (hupdate, lhuc) {
2110 hupdate->set_fading(1.0);
2111 }
2112}
2113
2114/************************************************************************/
2118{
2120
2121 if (m_timer.elapsed() > 4000 && m_timer.elapsed() < 5000) {
2122 foreach (hudc, lhuc) {
2123 if (hudc->get_focus()) {
2124 m_timer.restart();
2125 te_inner();
2126 return;
2127 }
2128 hudc->set_fading((5000.0 - m_timer.elapsed()) / 1000);
2129 }
2130 }
2131 if (m_timer.elapsed() >= 5000) {
2132 hide();
2133 }
2134}
2135
2136/************************************************************************/
2140{
2142
2143 foreach (hupdate, lhuc) {
2144 hupdate->set_fading(1.0);
2145 }
2146 m_timer.restart();
2147 setVisible(true);
2148}
#define str
Definition astring.c:76
#define n
Definition astring.c:77
QRect zealous_crop_rect(QImage &p)
Definition canvas.cpp:419
void qtg_canvas_free(struct canvas *store)
Definition canvas.cpp:48
struct canvas * qtg_canvas_create(int width, int height)
Definition canvas.cpp:36
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
void left_clicked()
void mousePressEvent(QMouseEvent *e)
void on_clicked()
static fc_font * instance()
Definition fonts.cpp:41
QFont * get_font(QString name)
Definition fonts.cpp:63
QPixmap * get_pixmap(const QString &id)
static fc_icons * instance()
void paintEvent(QPaintEvent *event)
void leaveEvent(QEvent *event)
void mousePressEvent(QMouseEvent *e)
void on_clicked()
void mouseMoveEvent(QMouseEvent *event)
void right_clicked()
QPixmap * action_pixmap
Definition hudwidget.h:159
hud_action(QWidget *parent)
void on_right_clicked()
void enterEvent(QEnterEvent *event)
shortcut_id action_shortcut
Definition hudwidget.h:165
void left_clicked()
void set_pixmap(QPixmap *p)
move_widget * mw
Definition hudwidget.h:377
QList< hud_unit_combat * > lhuc
Definition hudwidget.h:360
QElapsedTimer m_timer
Definition hudwidget.h:378
void add_combat_info(hud_unit_combat *huc)
hud_battle_log(QWidget *parent)
QVBoxLayout * main_layout
Definition hudwidget.h:359
void moveEvent(QMoveEvent *event)
void timerEvent(QTimerEvent *event)
scale_widget * sw
Definition hudwidget.h:376
void paintEvent(QPaintEvent *event)
void set_scale(float s)
void showEvent(QShowEvent *event)
QString cs1
Definition hudwidget.h:131
void set_text_title_definput(QString s1, QString s2, QString def_input)
void paintEvent(QPaintEvent *event)
QElapsedTimer m_timer
Definition hudwidget.h:113
QString cs2
Definition hudwidget.h:131
void timerEvent(QTimerEvent *event)
QFontMetrics * fm_text
Definition hudwidget.h:128
hud_input_box(QWidget *parent)
QLineEdit input_edit
Definition hudwidget.h:119
QFontMetrics * fm_title
Definition hudwidget.h:129
QString text
Definition hudwidget.h:126
QString title
Definition hudwidget.h:127
QFontMetrics * fm_text
Definition hudwidget.h:73
QString title
Definition hudwidget.h:72
QElapsedTimer m_timer
Definition hudwidget.h:58
void timerEvent(QTimerEvent *event)
void paintEvent(QPaintEvent *event)
int set_text_title(QString s1, QString s2, bool return_exec=false)
hud_message_box(QWidget *parent)
Definition hudwidget.cpp:74
void keyPressEvent(QKeyEvent *event)
QFontMetrics * fm_title
Definition hudwidget.h:74
QElapsedTimer m_timer
Definition hudwidget.h:101
QString text
Definition hudwidget.h:100
void timerEvent(QTimerEvent *event)
QFont f_text
Definition hudwidget.h:103
int timeout
Definition hudwidget.h:98
void center_me()
hud_text(QString s, int time_secs, QWidget *parent)
QRect bound_rect
Definition hudwidget.h:97
void show_me()
void paintEvent(QPaintEvent *event)
QFontMetrics * fm_text
Definition hudwidget.h:102
int m_animate_step
Definition hudwidget.h:99
void set_fading(float fade)
hud_unit_combat(int attacker_unit_id, int defender_unit_id, int attacker_hp, int defender_hp, bool make_att_veteran, bool make_def_veteran, float scale, QWidget *parent)
struct unit * defender
Definition hudwidget.h:324
void leaveEvent(QEvent *event)
void mousePressEvent(QMouseEvent *e)
void paintEvent(QPaintEvent *event)
void init_images(bool redraw=false)
struct unit * attacker
Definition hudwidget.h:323
const struct unit_type * type_attacker
Definition hudwidget.h:325
void set_scale(float scale)
struct tile * center_tile
Definition hudwidget.h:327
const struct unit_type * type_defender
Definition hudwidget.h:326
void enterEvent(QEnterEvent *event)
hud_unit_loader(struct unit *pcargo, struct tile *ptile)
struct tile * qtile
Definition hudwidget.h:241
struct unit * cargo
Definition hudwidget.h:240
void selection_changed(const QItemSelection &, const QItemSelection &)
QList< unit * > transports
Definition hudwidget.h:231
QLabel text_label
Definition hudwidget.h:210
void update_actions(unit_list *punits)
hud_units(QWidget *parent)
void moveEvent(QMoveEvent *event)
click_label unit_label
Definition hudwidget.h:208
click_label tile_label
Definition hudwidget.h:209
move_widget * mw
Definition hudwidget.h:221
QHBoxLayout * main_layout
Definition hudwidget.h:212
unit_actions * unit_icons
Definition hudwidget.h:213
void put_to_corner()
Definition mapview.cpp:399
void paintEvent(QPaintEvent *event)
void mousePressEvent(QMouseEvent *event)
QPixmap minus
Definition hudwidget.h:349
QPixmap plus
Definition hudwidget.h:348
scale_widget(Shape s, QWidget *p=0)
unit_actions(QWidget *parent, unit *punit)
void clear_layout()
QList< hud_action * > actions
Definition hudwidget.h:197
void init_layout()
unit * current_unit
Definition hudwidget.h:199
int update_actions()
QHBoxLayout * layout
Definition hudwidget.h:196
QRadioButton * this_continent
Definition hudwidget.h:282
QComboBox * unit_sel_type
Definition hudwidget.h:251
QRadioButton * sentried
Definition hudwidget.h:274
void keyPressEvent(QKeyEvent *event)
QVBoxLayout * main_layout
Definition hudwidget.h:250
QRadioButton * anywhere
Definition hudwidget.h:284
QRadioButton * main_continent
Definition hudwidget.h:283
QRadioButton * full_hp_mp
Definition hudwidget.h:279
QPushButton * cancel
Definition hudwidget.h:253
bool island_filter(struct unit *punit)
bool type_filter(struct unit *punit)
unit_hud_selector(QWidget *parent)
QRadioButton * full_mp
Definition hudwidget.h:277
void select_units(int x=0)
QRadioButton * fortified
Definition hudwidget.h:272
QRadioButton * this_tile
Definition hudwidget.h:281
QRadioButton * any_type
Definition hudwidget.h:287
QRadioButton * any_activity
Definition hudwidget.h:271
QPushButton * select
Definition hudwidget.h:252
QRadioButton * any
Definition hudwidget.h:276
bool activity_filter(struct unit *punit)
bool hp_filter(struct unit *punit)
QRadioButton * full_hp
Definition hudwidget.h:278
QRadioButton * this_type
Definition hudwidget.h:286
QRadioButton * idle
Definition hudwidget.h:273
bool client_is_observer(void)
struct civclient client
bool client_has_player(void)
#define client_player()
char * incite_cost
Definition comments.c:75
void request_unit_load(struct unit *pcargo, struct unit *ptrans, struct tile *ptile)
Definition control.c:2156
void unit_focus_add(struct unit *punit)
Definition control.c:561
struct unit_list * get_units_in_focus(void)
Definition control.c:177
void request_center_focus_unit(void)
Definition control.c:2750
struct unit * head_of_units_in_focus(void)
Definition control.c:410
#define can_unit_do_activity_client(_punit_, _act_)
Definition control.h:41
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
enum event_type event
Definition events.c:81
#define extra_road_get(_e_)
Definition extras.h:191
#define extra_type_by_cause_iterate_end
Definition extras.h:339
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
int Unit_type_id
Definition fc_types.h:382
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
const char * population_to_text(int thousand_citizen)
Definition game.c:734
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
struct unit * game_unit_by_number(int id)
Definition game.c:116
int civ_population(const struct player *pplayer)
Definition game.c:74
bool goto_is_active(void)
Definition goto.c:1059
static PangoLayout * layout
Definition canvas.c:325
struct city * owner
Definition citydlg.c:226
static struct tile * pos
Definition finddlg.c:53
#define show(id)
Definition widget.h:235
#define hide(id)
Definition widget.h:238
static QString popup_terrain_info(struct tile *ptile)
const char * calendar_text(void)
Definition calendar.c:141
bool has_player_unit_type(Unit_type_id utype)
Definition hudwidget.cpp:60
bool goto_is_active(void)
Definition goto.c:1059
void show_new_turn_info()
bool has_player_unit_type(Unit_type_id utype)
Definition hudwidget.cpp:60
void put_terrain(struct tile *ptile, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
struct view mapview
void put_unit(const struct unit *punit, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
void put_unittype(const struct unit_type *putype, struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y)
void center_tile_mapcanvas(const struct tile *ptile)
const char * move_points_text(int mp, bool reduce)
Definition movement.c:1015
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:319
bool unit_can_load(const struct unit *punit)
Definition movement.c:883
bool can_unit_transport(const struct unit *transporter, const struct unit *transported)
Definition movement.c:855
#define SINGLE_MOVE
Definition movement.h:26
static mpgui * gui
Definition mpgui_qt.cpp:52
const char *const default_font
Definition fonts.h:27
const char *const notify_label
Definition fonts.h:28
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:178
const char * science_dialog_text(void)
Definition text.c:741
int player_get_expected_income(const struct player *pplayer)
Definition player.c:1286
struct city * player_city_by_number(const struct player *pplayer, int city_id)
Definition player.c:1203
struct city * player_primary_capital(const struct player *pplayer)
Definition player.c:1337
const char * research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Definition research.c:273
struct research * research_get(const struct player *pplayer)
Definition research.c:128
bool can_build_road(const struct civ_map *nmap, struct road_type *proad, const struct unit *punit, const struct tile *ptile)
Definition road.c:295
@ SC_PARADROP
Definition shortcuts.h:95
@ SC_UPGRADE_UNIT
Definition shortcuts.h:63
@ SC_BUILDIRRIGATION
Definition shortcuts.h:67
@ SC_BUILDCITY
Definition shortcuts.h:70
@ SC_DONE_MOVING
Definition shortcuts.h:57
@ SC_BUILDROAD
Definition shortcuts.h:69
@ SC_CULTIVATE
Definition shortcuts.h:68
@ SC_SENTRY
Definition shortcuts.h:71
@ SC_NUKE
Definition shortcuts.h:76
@ SC_SETHOME
Definition shortcuts.h:64
@ SC_PLANT
Definition shortcuts.h:66
@ SC_BUILDMINE
Definition shortcuts.h:65
@ SC_TRANSFORM
Definition shortcuts.h:75
@ SC_FORTIFY
Definition shortcuts.h:72
@ SC_GOTO
Definition shortcuts.h:73
@ SC_WAIT
Definition shortcuts.h:74
@ SC_DEBOARD
Definition shortcuts.h:78
@ SC_AUTOMATE
Definition shortcuts.h:81
@ SC_BOARD
Definition shortcuts.h:77
@ SC_CLEAN
Definition shortcuts.h:82
int step
Definition specpq.h:92
size_t size
Definition specvec.h:72
struct sprite int int int int struct sprite int int float scale
Definition sprite_g.h:33
struct sprite int x
Definition sprite_g.h:31
Definition city.h:320
struct tile * tile
Definition city.h:322
struct packet_game_info info
Definition game.h:89
struct connection conn
Definition client_main.h:96
Definition colors.h:21
struct player * playing
Definition connection.h:151
Definition mapimg.c:367
struct unit_list * units
Definition player.h:280
struct player_economic economic
Definition player.h:282
Tech_type_id researching
Definition research.h:52
struct research::@76::@78 client
int researching_cost
Definition research.h:96
int bulbs_researched
Definition research.h:53
int movement_cost
Definition terrain.h:199
Definition tile.h:50
bv_extras extras
Definition tile.h:55
struct unit_list * units
Definition tile.h:58
struct terrain * terrain
Definition tile.h:57
Continent_id continent
Definition tile.h:54
int move_rate
Definition unittype.h:517
Definition unit.h:138
enum unit_activity activity
Definition unit.h:157
int moves_left
Definition unit.h:150
int hp
Definition unit.h:151
int fuel
Definition unit.h:153
struct tile * tile
Definition unit.h:140
int homecity
Definition unit.h:146
const struct unit_type * utype
Definition unit.h:139
struct player * owner
Definition unit.h:143
int height
int width
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
#define A_NONE
Definition tech.h:43
#define A_UNSET
Definition tech.h:48
#define A_UNKNOWN
Definition tech.h:49
const char * get_infrastructure_text(bv_extras extras)
Definition terrain.c:508
const char * popup_info_text(struct tile *ptile)
Definition text.c:147
const char * get_tile_output_text(const struct tile *ptile)
Definition text.c:63
bool tile_has_road(const struct tile *ptile, const struct road_type *proad)
Definition tile.c:844
const char * tile_get_info_text(const struct tile *ptile, bool include_nuisances, int linebreaks)
Definition tile.c:771
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
int tileset_unit_width(const struct tileset *t)
Definition tilespec.c:797
int tileset_unit_height(const struct tileset *t)
Definition tilespec.c:805
struct tileset * unscaled_tileset
Definition tilespec.c:568
bool tileset_is_isometric(const struct tileset *t)
Definition tilespec.c:712
int tileset_tile_height(const struct tileset *t)
Definition tilespec.c:765
int tileset_full_tile_width(const struct tileset *t)
Definition tilespec.c:776
struct sprite * get_unittype_sprite(const struct tileset *t, const struct unit_type *punittype, enum unit_activity activity, enum direction8 facing)
Definition tilespec.c:6805
int get_transporter_occupancy(const struct unit *ptrans)
Definition unit.c:1783
bool can_unit_change_homecity_to(const struct civ_map *nmap, const struct unit *punit, const struct city *pcity)
Definition unit.c:465
bool unit_can_add_or_build_city(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:448
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2441
bool can_unit_do_autosettlers(const struct unit *punit)
Definition unit.c:606
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:359
int get_transporter_capacity(const struct unit *punit)
Definition unit.c:297
bool can_unit_paradrop(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:822
enum unit_upgrade_result unit_upgrade_test(const struct civ_map *nmap, const struct unit *punit, bool is_free)
Definition unit.c:1988
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2425
bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:752
#define unit_tile(_pu)
Definition unit.h:397
@ UU_OK
Definition unit.h:61
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
const char * unit_name_translation(const struct unit *punit)
Definition unittype.c:1569
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
Unit_type_id utype_number(const struct unit_type *punittype)
Definition unittype.c:100
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1560
#define utype_fuel(ptype)
Definition unittype.h:839
#define unit_type_iterate(_p)
Definition unittype.h:855
#define unit_type_iterate_end
Definition unittype.h:862