Freeciv-3.4
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 != nullptr) {
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/************************************************************************/
904{
905 focus = true;
906 update();
907 QWidget::enterEvent(event);
908}
909
910/************************************************************************/
916
917/************************************************************************/
921{
922 gui()->menu_bar->execute_shortcut(action_shortcut);
923}
924
925/************************************************************************/
929{
930 layout = new QHBoxLayout(this);
931 layout->setSpacing(3);
932 layout->setContentsMargins(0, 0, 0, 0);
934 init_layout();
935 setFocusPolicy(Qt::ClickFocus);
936}
937
938/************************************************************************/
946
947/************************************************************************/
951{
952 QSizePolicy size_fixed_policy(QSizePolicy::MinimumExpanding,
953 QSizePolicy::Fixed,
954 QSizePolicy::Frame);
956 layout->setSpacing(0);
958}
959
960/************************************************************************/
964{
965 hud_action *a;
966
968
969 if (current_unit == nullptr) {
970 clear_layout();
971 hide();
972 return 0;
973 }
974 /* HACK prevent crash with active goto when leaving widget,
975 * just skip update because with active goto actions shouldn't change */
976 if (goto_is_active() ) {
977 return actions.count();
978 }
979 hide();
980 clear_layout();
981 setUpdatesEnabled(false);
982
983
984 foreach (a, actions) {
985 delete a;
986 }
988 actions.clear();
989
990 // Create possible actions
991
993 a = new hud_action(this);
995 a->set_pixmap(fc_icons::instance()->get_pixmap("home"));
996 actions.append(a);
997 }
998
999
1001 a = new hud_action(this);
1003 a->set_pixmap(fc_icons::instance()->get_pixmap("mine"));
1004 actions.append(a);
1005 }
1006
1008 a = new hud_action(this);
1010 a->set_pixmap(fc_icons::instance()->get_pixmap("plantforest"));
1011 actions.append(a);
1012 }
1013
1015 a = new hud_action(this);
1017 a->set_pixmap(fc_icons::instance()->get_pixmap("irrigation"));
1018 actions.append(a);
1019 }
1020
1022 a = new hud_action(this);
1024 a->set_pixmap(fc_icons::instance()->get_pixmap("chopchop"));
1025 actions.append(a);
1026 }
1027
1029 a = new hud_action(this);
1031 a->set_pixmap(fc_icons::instance()->get_pixmap("transform"));
1032 actions.append(a);
1033 }
1034
1035 // Road
1036 {
1037 bool ok = false;
1038
1040 struct road_type *proad = extra_road_get(pextra);
1041
1043 ok = true;
1044 }
1046 if (ok) {
1047 a = new hud_action(this);
1049 a->set_pixmap(fc_icons::instance()->get_pixmap("buildroad"));
1050 actions.append(a);
1051 }
1052 }
1053 // Goto
1054 a = new hud_action(this);
1056 a->set_pixmap(fc_icons::instance()->get_pixmap("goto"));
1057 actions.append(a);
1058
1059
1061 a = new hud_action(this);
1063 a->set_pixmap(fc_icons::instance()->get_pixmap("fortify"));
1064 actions.append(a);
1065 }
1066
1067
1069 a = new hud_action(this);
1071 a->set_pixmap(fc_icons::instance()->get_pixmap("sentry"));
1072 actions.append(a);
1073 }
1074
1075 // Board
1077 a = new hud_action(this);
1079 a->set_pixmap(fc_icons::instance()->get_pixmap("load"));
1080 actions.append(a);
1081 }
1082
1083 // Set homecity
1087 a = new hud_action(this);
1089 a->set_pixmap(fc_icons::instance()->get_pixmap("set_homecity"));
1090 actions.append(a);
1091 }
1092 }
1093
1094 // Upgrade
1096 a = new hud_action(this);
1098 a->set_pixmap(fc_icons::instance()->get_pixmap("upgrade"));
1099 actions.append(a);
1100 }
1101
1102 // Automate
1104 a = new hud_action(this);
1106 a->set_pixmap(fc_icons::instance()->get_pixmap("automate"));
1107 actions.append(a);
1108 }
1109
1110 // Paradrop
1112 a = new hud_action(this);
1114 a->set_pixmap(fc_icons::instance()->get_pixmap("paradrop"));
1115 actions.append(a);
1116 }
1117
1118 // Clean
1120 a = new hud_action(this);
1122 a->set_pixmap(fc_icons::instance()->get_pixmap("clean"));
1123 actions.append(a);
1124 }
1125
1126 // Deboard
1131 a = new hud_action(this);
1133 a->set_pixmap(fc_icons::instance()->get_pixmap("unload"));
1134 actions.append(a);
1135 }
1136
1137 // Nuke
1139 a = new hud_action(this);
1141 a->set_pixmap(fc_icons::instance()->get_pixmap("nuke"));
1142 actions.append(a);
1143 }
1144
1145 // Wait
1146 a = new hud_action(this);
1148 a->set_pixmap(fc_icons::instance()->get_pixmap("wait"));
1149 actions.append(a);
1150
1151 // Done moving
1152 a = new hud_action(this);
1154 a->set_pixmap(fc_icons::instance()->get_pixmap("done"));
1155 actions.append(a);
1156
1157
1158 foreach (a, actions) {
1159 a->setToolTip(gui()->menu_bar->shortcut_2_menustring(a->action_shortcut));
1160 a->setFixedHeight(height());
1161 a->setFixedWidth(height());
1162 layout->addWidget(a);
1163 }
1164
1165 setFixedWidth(actions.count() * height());
1166 setUpdatesEnabled(true);
1167 show();
1168 layout->update();
1170 return actions.count();
1171}
1172
1173/************************************************************************/
1177{
1178 int i = actions.count();
1179 hud_action *ui;
1180 int j;
1181
1182 setUpdatesEnabled(false);
1183 for (j = 0; j < i; j++) {
1184 ui = actions[j];
1185 layout->removeWidget(ui);
1186 delete ui;
1187 }
1188 while (!actions.empty()) {
1189 actions.removeFirst();
1190 }
1191 setUpdatesEnabled(true);
1192}
1193
1194/************************************************************************/
1198{
1199 setProperty("showGrid", "false");
1200 setProperty("selectionBehavior", "SelectRows");
1201 setEditTriggers(QAbstractItemView::NoEditTriggers);
1202 setSelectionMode(QAbstractItemView::SingleSelection);
1203 verticalHeader()->setVisible(false);
1204 horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
1205 horizontalHeader()->setVisible(false);
1206 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1207 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
1208 connect(selectionModel(),
1210 const QItemSelection &)), this,
1212 const QItemSelection &)));
1213 cargo = pcargo;
1214 qtile = ptile;
1215
1216}
1217
1218/************************************************************************/
1224
1225/************************************************************************/
1230{
1232 int max_size = 0;
1233 int i, j;
1234 int w,h;
1235 sprite *spite;
1236
1241 transports.append(ptransport);
1242 max_size = qMax(max_size, get_transporter_occupancy(ptransport));
1243 }
1245
1246 setRowCount(transports.count());
1247 setColumnCount(max_size + 1);
1248 for (i = 0 ; i < transports.count(); i++) {
1249 QString str;
1250 struct unit *tp = transports.at(i);
1251
1252 spite = get_unittype_sprite(tileset, tp->utype, tp->activity,
1254 str = utype_rule_name(transports.at(i)->utype);
1255 // TRANS: MP - just movement points
1256 str = str + " ("
1257 + QString(move_points_text(transports.at(i)->moves_left, false))
1258 + _("MP") + ")";
1259 new_item = new QTableWidgetItem(QIcon(*spite->pm), str);
1260 setItem(i, 0, new_item);
1261 j = 1;
1262 unit_list_iterate(transports.at(i)->transporting, tunit) {
1263 spite = get_unittype_sprite(tileset, tunit->utype, tunit->activity,
1265 new_item = new QTableWidgetItem(QIcon(*spite->pm), "");
1266 setItem(i, j, new_item);
1267 j++;
1269 }
1270
1271 w = verticalHeader()->width() + 4;
1272 for (i = 0; i < columnCount(); i++) {
1273 w += columnWidth(i);
1274 }
1275 h = horizontalHeader()->height() + 4;
1276 for (i = 0; i < rowCount(); i++) {
1277 h += rowHeight(i);
1278 }
1279
1280 resize(w, h);
1281 setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Dialog
1282 | Qt::FramelessWindowHint);
1283 show();
1284}
1285
1286/************************************************************************/
1290 const QItemSelection& s2)
1291{
1292 int curr_row;
1293
1294 curr_row = s1.indexes().at(0).row();
1295 request_unit_load(cargo, transports.at(curr_row), qtile);
1296 close();
1297}
1298
1299/************************************************************************/
1303{
1308
1309 hide();
1310 struct unit *punit = head_of_units_in_focus();
1311
1312 setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Dialog
1313 | Qt::FramelessWindowHint);
1314 main_layout = new QVBoxLayout(this);
1315
1316 unit_sel_type = new QComboBox();
1317
1318 unit_type_iterate(utype) {
1319 utype_id = utype_index(utype);
1322 }
1323 }
1325
1326 if (punit) {
1327 int i;
1329 unit_sel_type->setCurrentIndex(i);
1330 }
1331 no_name = new QGroupBox();
1332 no_name->setTitle(_("Unit type"));
1333 this_type = new QRadioButton(_("Selected type"), no_name);
1334 this_type->setChecked(true);
1335 any_type = new QRadioButton(_("All types"), no_name);
1336 connect(unit_sel_type, SIGNAL(currentIndexChanged(int)), this,
1337 SLOT(select_units(int)));
1338 connect(this_type, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1339 connect(any_type, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1341 groupbox_layout->addWidget(unit_sel_type);
1342 groupbox_layout->addWidget(this_type);
1343 groupbox_layout->addWidget(any_type);
1344 no_name->setLayout(groupbox_layout);
1345 hibox = new QHBoxLayout;
1346 hibox->addWidget(no_name);
1347
1348 no_name = new QGroupBox();
1349 no_name->setTitle(_("Unit activity"));
1350 any_activity = new QRadioButton(_("Any activity"), no_name);
1351 any_activity->setChecked(true);
1352 fortified = new QRadioButton(_("Fortified"), no_name);
1353 idle = new QRadioButton(_("Idle"), no_name);
1354 sentried = new QRadioButton(_("Sentried"), no_name);
1355 connect(any_activity, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1356 connect(idle, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1357 connect(fortified, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1358 connect(sentried, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1360 groupbox_layout->addWidget(any_activity);
1361 groupbox_layout->addWidget(idle);
1362 groupbox_layout->addWidget(fortified);
1363 groupbox_layout->addWidget(sentried);
1364 no_name->setLayout(groupbox_layout);
1365 hibox->addWidget(no_name);
1366 main_layout->addLayout(hibox);
1367
1368 no_name = new QGroupBox();
1369 no_name->setTitle(_("Unit HP and MP"));
1370 any = new QRadioButton(_("Any unit"), no_name);
1371 full_hp = new QRadioButton(_("Full HP"), no_name);
1372 full_mp = new QRadioButton(_("Full MP"), no_name);
1373 full_hp_mp = new QRadioButton(_("Full HP and MP"), no_name);
1374 full_hp_mp->setChecked(true);
1375 connect(any, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1376 connect(full_hp, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1377 connect(full_mp, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1378 connect(full_hp_mp, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1380 groupbox_layout->addWidget(any);
1381 groupbox_layout->addWidget(full_hp);
1382 groupbox_layout->addWidget(full_mp);
1383 groupbox_layout->addWidget(full_hp_mp);
1384 no_name->setLayout(groupbox_layout);
1385 hibox = new QHBoxLayout;
1386 hibox->addWidget(no_name);
1387
1388 no_name = new QGroupBox();
1389 no_name->setTitle(_("Location"));
1390 anywhere = new QRadioButton(_("Anywhere"), no_name);
1391 this_tile = new QRadioButton(_("Current tile"), no_name);
1392 this_continent = new QRadioButton(_("Current continent"), no_name);
1393 main_continent = new QRadioButton(_("Main continent"), no_name);
1395
1396 if (punit) {
1397 this_tile->setChecked(true);
1398 } else {
1399 this_tile->setDisabled(true);
1400 this_continent->setDisabled(true);
1401 main_continent->setChecked(true);
1402 }
1403
1404 groupbox_layout->addWidget(this_tile);
1405 groupbox_layout->addWidget(this_continent);
1406 groupbox_layout->addWidget(main_continent);
1407 groupbox_layout->addWidget(anywhere);
1408
1409 no_name->setLayout(groupbox_layout);
1410 hibox->addWidget(no_name);
1411 main_layout->addLayout(hibox);
1412
1413 select = new QPushButton(_("Select"));
1414 cancel = new QPushButton(_("Cancel"));
1415 connect(anywhere, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1416 connect(this_tile, SIGNAL(toggled(bool)), this, SLOT(select_units(bool)));
1417 connect(this_continent, SIGNAL(toggled(bool)), this,
1418 SLOT(select_units(bool)));
1419 connect(main_continent, SIGNAL(toggled(bool)), this,
1420 SLOT(select_units(bool)));
1421 connect(select, &QAbstractButton::clicked, this, &unit_hud_selector::uhs_select);
1422 connect(cancel, &QAbstractButton::clicked, this, &unit_hud_selector::uhs_cancel);
1423 hbox = new QHBoxLayout;
1424 hbox->addWidget(cancel);
1425 hbox->addWidget(select);
1426
1427 result_label.setAlignment(Qt::AlignCenter);
1428 main_layout->addWidget(&result_label, Qt::AlignHCenter);
1429 main_layout->addLayout(hbox);
1431
1432}
1433
1434/************************************************************************/
1438{
1439 QPoint p;
1440
1441 p = QPoint((parentWidget()->width() - sizeHint().width()) / 2,
1442 (parentWidget()->height() - sizeHint().height()) / 2);
1443 p = parentWidget()->mapToGlobal(p);
1444 move(p);
1445 setVisible(true);
1446 show();
1447 select_units();
1448}
1449
1450/************************************************************************/
1456
1457/************************************************************************/
1461{
1462 const struct player *pplayer;
1463
1464 pplayer = client_player();
1465
1466 unit_list_iterate(pplayer->units, punit) {
1470 }
1472 close();
1473}
1474
1475/************************************************************************/
1479{
1480 close();
1481}
1482
1483/************************************************************************/
1487{
1488 int num = 0;
1489 const struct player *pplayer;
1490
1491 pplayer = client_player();
1492
1493 unit_list_iterate(pplayer->units, punit) {
1496 num++;
1497 }
1499 result_label.setText(QString(PL_("%1 unit", "%1 units", num)).arg(num));
1500}
1501
1502/************************************************************************/
1506{
1507 select_units(0);
1508}
1509
1510/************************************************************************/
1514{
1515 if ((event->key() == Qt::Key_Return)
1516 || (event->key() == Qt::Key_Enter)) {
1517 uhs_select();
1518 }
1519 if (event->key() == Qt::Key_Escape) {
1520 close();
1521 event->accept();
1522 }
1523 QWidget::keyPressEvent(event);
1524}
1525
1526/************************************************************************/
1530{
1531 if ((punit->activity == ACTIVITY_FORTIFIED && fortified->isChecked())
1532 || (punit->activity == ACTIVITY_SENTRY && sentried->isChecked())
1533 || (punit->activity == ACTIVITY_IDLE && idle->isChecked())
1534 || any_activity->isChecked()) {
1535 return true;
1536 }
1537 return false;
1538}
1539
1540/************************************************************************/
1544{
1545 if ((any->isChecked()
1546 || (full_mp->isChecked()
1548 || (full_hp->isChecked() && punit->hp >= punit->utype->hp)
1549 || (full_hp_mp->isChecked() && punit->hp >= punit->utype->hp
1550 && punit->moves_left >= punit->utype->move_rate))) {
1551 return true;
1552 }
1553 return false;
1554}
1555
1556/************************************************************************/
1560{
1561 int island = -1;
1562 struct unit *cunit = head_of_units_in_focus();
1563
1564 if (this_tile->isChecked() && cunit) {
1565 if (punit->tile == cunit->tile) {
1566 return true;
1567 }
1568 }
1569
1570 if (main_continent->isChecked()
1573 } else if (this_continent->isChecked() && cunit) {
1574 island = cunit->tile->continent;
1575 }
1576
1577 if (island > -1) {
1578 if (punit->tile->continent == island) {
1579 return true;
1580 }
1581 }
1582
1583 if (anywhere->isChecked()) {
1584 return true;
1585 }
1586 return false;
1587}
1588
1589/************************************************************************/
1593{
1594 QVariant qvar;
1596
1597 if (this_type->isChecked()) {
1598 qvar = unit_sel_type->currentData();
1599 utype_id = qvar.toInt();
1600 if (utype_id == utype_index(punit->utype)) {
1601 return true;
1602 } else {
1603 return false;
1604 }
1605 }
1606 if (any_type->isChecked()) {
1607 return true;
1608 }
1609 return false;
1610}
1611
1612/************************************************************************/
1616{
1617 int movement_cost;
1618 struct terrain *terr;
1619 QString ret, t, move_text;
1620 bool has_road = false;
1621
1622 terr = ptile->terrain;
1623 ret = QString(_("Terrain: %1\n")).arg(tile_get_info_text(ptile, TRUE, 0));
1624 ret = ret + QString(_("Food/Prod/Trade: %1\n"))
1625 .arg(get_tile_output_text(ptile));
1626 t = get_infrastructure_text(ptile->extras);
1627 if (t != "") {
1628 ret = ret + QString(_("Infrastructure: %1\n")).arg(t);
1629 }
1630 ret = ret + QString(_("Defense bonus: %1%\n")).arg(terr->defense_bonus);
1631 movement_cost = terr->movement_cost;
1632
1634 struct road_type *proad = extra_road_get(pextra);
1635
1636 if (tile_has_road(ptile, proad)) {
1637 if (proad->move_cost <= movement_cost) {
1638 has_road = true;
1639 move_text = move_points_text(proad->move_cost, TRUE);
1640 movement_cost = proad->move_cost;
1641 }
1642 }
1644
1645 if (has_road) {
1646 ret = ret + QString(_("Movement cost: %1")).arg(move_text);
1647 } else {
1648 ret = ret + QString(_("Movement cost: %1")).arg(movement_cost);
1649 }
1650
1651 return ret;
1652}
1653
1654/************************************************************************/
1658{
1659 QString s;
1660 hud_text *ht;
1662 struct research *research;
1663 int i;
1664 char buf[25];
1665
1666 if (!client_has_player()
1667 || !gui()->qt_settings.show_new_turn_text) {
1668 return;
1669 }
1670 close_list = gui()->mapview_wdg->findChildren<hud_text *>();
1671 for (i = 0; i < close_list.size(); ++i) {
1672 close_list.at(i)->close();
1673 close_list.at(i)->deleteLater();
1674 }
1676 s = QString(_("Year: %1 (Turn: %2)"))
1677 .arg(calendar_text()).arg(game.info.turn) + "\n";
1679 if (client_is_observer()) {
1680 s += QString(_(" (observer)"));
1681 }
1682 s += " - " + QString(_("Population: %1"))
1686 && research->researching != A_NONE) {
1689 " (" + QString::number(research->bulbs_researched) + "/"
1690 + QString::number(research->client.researching_cost) + ")";
1691 }
1692 s = s + "\n" + science_dialog_text() + "\n";
1693
1694 // Can't use QString().sprintf() as msys libintl.h defines sprintf() as a macro
1696
1697 // TRANS: current gold, then loss/gain per turn
1698 s = s + QString(_("Gold: %1 (%2)"))
1700 .arg(buf);
1701 ht = new hud_text(s, 5, gui()->mapview_wdg);
1702 ht->show_me();
1703}
1704
1705/************************************************************************/
1708hud_unit_combat::hud_unit_combat(int attacker_unit_id, int defender_unit_id,
1709 int attacker_hp, int defender_hp,
1710 bool make_att_veteran, bool make_def_veteran,
1711 float scale, QWidget *parent) : QWidget(parent)
1712{
1713 hud_scale = scale;
1714 att_hp = attacker_hp;
1715 def_hp = defender_hp;
1716
1717 attacker = game_unit_by_number(attacker_unit_id);
1718 defender = game_unit_by_number(defender_unit_id);
1721 att_veteran = make_att_veteran;
1722 def_veteran = make_def_veteran;
1725 if (defender_hp <= 0) {
1727 } else {
1729 }
1730 init_images();
1731}
1732
1733/************************************************************************/
1737{
1739 QRect dr, ar;
1740 QPainter p;
1741 struct canvas *defender_pixmap;
1742 struct canvas *attacker_pixmap;
1743 int w;
1744
1745 focus = false;
1746 w = 3 * hud_scale * tileset_unit_height(tileset) / 2;
1747 setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
1748 setFixedSize(2 * w, w);
1751 defender_pixmap->map_pixmap.fill(Qt::transparent);
1752 if (defender != nullptr) {
1753 if (!redraw) {
1754 put_unit(defender, defender_pixmap, 1.0, 0, 0);
1755 } else {
1757 }
1758 dimg = defender_pixmap->map_pixmap.toImage();
1760 crdimg = dimg.copy(dr);
1761 dimg = crdimg.scaledToHeight(w, Qt::SmoothTransformation);
1762 }
1763 if (dimg.width() < w) {
1764 dt = QImage(w, dimg.height(), QImage::Format_ARGB32_Premultiplied);
1765 dt.fill(Qt::transparent);
1766 p.begin(&dt);
1767 p.drawImage(w / 2 - dimg.width() / 2, 0, dimg);
1768 p.end();
1769 dimg = dt;
1770 }
1771 dimg = dimg.scaled(w, w, Qt::IgnoreAspectRatio,
1772 Qt::SmoothTransformation);
1775 attacker_pixmap->map_pixmap.fill(Qt::transparent);
1776 if (attacker != nullptr) {
1777 if (!redraw) {
1779 } else {
1781 }
1782 aimg = attacker_pixmap->map_pixmap.toImage();
1784 acrimg = aimg.copy(ar);
1785 aimg = acrimg.scaledToHeight(w, Qt::SmoothTransformation);
1786 }
1787 if (aimg.width() < w) {
1788 at = QImage(w, dimg.height(), QImage::Format_ARGB32_Premultiplied);
1789 at.fill(Qt::transparent);
1790 p.begin(&at);
1791 p.drawImage(w / 2 - aimg.width() / 2, 0, aimg);
1792 p.end();
1793 aimg = at;
1794 }
1795 aimg = aimg.scaled(w, w, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
1796 delete defender_pixmap;
1797 delete attacker_pixmap;
1798}
1799
1800/************************************************************************/
1804{
1805 hud_scale = scale;
1806 init_images(true);
1807}
1808
1809/************************************************************************/
1815
1816/************************************************************************/
1820{
1821 fading = fade;
1822 update();
1823}
1824
1825/************************************************************************/
1829{
1830 return focus;
1831}
1832
1833/************************************************************************/
1837{
1838 QPainter p;
1839 QRect left, right;
1840 QColor c1, c2;
1841 QPen pen;
1844
1845 if (att_hp_loss > 0) {
1846 ahploss = "-" + QString::number(att_hp_loss);
1847 } else {
1848 ahploss = "0";
1849 }
1850 if (def_hp_loss > 0) {
1851 dhploss = "-" + QString::number(def_hp_loss);
1852 } else {
1853 dhploss = "0";
1854 }
1855 f.setBold(true);
1856
1857 if (def_hp == 0) {
1858 c1 = QColor(25, 125, 25, 175);
1859 c2 = QColor(125, 25, 25, 175);
1860 } else {
1861 c1 = QColor(125, 25, 25, 175);
1862 c2 = QColor(25, 125, 25, 175);
1863 }
1864 int w = 3 * tileset_unit_height(tileset) / 2 * hud_scale;
1865
1866 left = QRect(0 , 0, w , w);
1867 right = QRect(w, 0, w , w);
1868 pen = QPen(QColor(palette().color(QPalette::AlternateBase)), 2.0);
1869 p.begin(this);
1870 if (fading < 1.0) {
1871 p.setOpacity(fading);
1872 }
1873 if (focus) {
1874 p.fillRect(left, QColor(palette().color(QPalette::Highlight)));
1875 p.fillRect(right, QColor(palette().color(QPalette::Highlight)));
1876 c1.setAlpha(110);
1877 c2.setAlpha(110);
1878 }
1879 p.fillRect(left, c1);
1880 p.fillRect(right, c2);
1881 p.setPen(pen);
1882 p.drawRect(1, 1, width() - 2 , height() - 2);
1883 p.drawImage(left, aimg);
1884 p.setFont(f);
1885 p.setPen(QColor(Qt::white));
1886 if (def_veteran) {
1887 p.drawText(right, Qt::AlignHCenter | Qt::AlignJustify
1888 | Qt::AlignAbsolute, "*");
1889 }
1890 if (att_veteran) {
1891 p.drawText(left, Qt::AlignHCenter | Qt::AlignJustify
1892 | Qt::AlignAbsolute, "*");
1893 }
1894 p.drawText(left, Qt::AlignHorizontal_Mask, ahploss);
1895 p.drawImage(right, dimg);
1896 p.drawText(right, Qt::AlignHorizontal_Mask, dhploss);
1897 p.end();
1898}
1899
1900/************************************************************************/
1907
1908/************************************************************************/
1912{
1913 focus = false;
1914 update();
1915}
1916
1917/************************************************************************/
1921{
1922 focus = true;
1923 update();
1924}
1925
1926
1927/************************************************************************/
1930scale_widget::scale_widget(QRubberBand::Shape s,
1931 QWidget* p) : QRubberBand(s, p)
1932{
1933 QPixmap *pix;
1934
1935 size = 12;
1936 pix = fc_icons::instance()->get_pixmap("plus");
1937 plus = pix->scaledToWidth(size);
1938 delete pix;
1939 pix = fc_icons::instance()->get_pixmap("minus");
1940 minus = plus = pix->scaledToWidth(size);
1941 delete pix;
1942 setFixedSize(2 * size, size);
1943 scale = 1.0f;
1944 setAttribute(Qt::WA_TransparentForMouseEvents, false);
1945}
1946
1947/************************************************************************/
1951{
1952 QRubberBand::paintEvent(event);
1953 QPainter p;
1954
1955 p.begin(this);
1956 p.drawPixmap(0, 0, minus);
1957 p.drawPixmap(size, 0, plus);
1958 p.end();
1959}
1960
1961/************************************************************************/
1965{
1966 if (event->button() == Qt::LeftButton) {
1967 if (event->position().x() <= size) {
1968 scale = scale / 1.2;
1969 } else {
1970 scale = scale * 1.2;
1971 }
1972 parentWidget()->update();
1973 }
1974}
1975
1976/************************************************************************/
1980{
1981 setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
1982 main_layout = new QVBoxLayout(this);
1983 mw = new move_widget(this);
1984 setContentsMargins(0, 0, 0, 0);
1985 main_layout->setContentsMargins(0, 0, 0, 0);
1986 sw = new scale_widget(QRubberBand::Rectangle, this);
1987 sw->show();
1988}
1989
1990/************************************************************************/
1994{
1995 delete sw;
1996 delete mw;
1997}
1998
1999/************************************************************************/
2003{
2005 int w = 3 * tileset_unit_height(tileset) / 2 * scale;
2006
2007 gui()->qt_settings.battlelog_scale = scale;
2008 delete layout();
2010 foreach (hudc, lhuc) {
2011 hudc->set_scale(scale);
2012 main_layout->addWidget(hudc);
2013 hudc->set_fading(1.0);
2014 }
2015 setFixedSize(2 * w + 10, lhuc.count() * w + 10);
2017
2018 update();
2019 show();
2020 m_timer.restart();
2021 startTimer(50);
2022}
2023
2024/************************************************************************/
2028{
2029 scale = s;
2030 sw->scale = s;
2031}
2032
2033/************************************************************************/
2037{
2039 int w = 3 * tileset_unit_height(tileset) / 2 * scale;
2040
2041 delete layout();
2043 lhuc.prepend(huc);
2044 while (lhuc.count() > 5) {
2045 hudc = lhuc.takeLast();
2046 delete hudc;
2047 }
2048 foreach (hudc, lhuc) {
2049 main_layout->addWidget(hudc);
2050 hudc->set_fading(1.0);
2051 }
2052 setFixedSize(2 * w + 10, lhuc.count() * w + 10);
2054
2055 update();
2056 show();
2057 m_timer.restart();
2058 startTimer(50);
2059}
2060
2061/************************************************************************/
2065{
2066 if (scale != sw->scale) {
2067 scale = sw->scale;
2068 update_size();
2069 }
2070 mw->put_to_corner();
2071 sw->move(width() - sw->width(), 0);
2072}
2073
2074/************************************************************************/
2078{
2079 QPoint p;
2080
2081 p = pos();
2082 gui()->qt_settings.battlelog_x = static_cast<float>(p.x()) / mapview.width;
2083 gui()->qt_settings.battlelog_y = static_cast<float>(p.y())
2084 / mapview.height;
2085 m_timer.restart();
2086}
2087
2088/************************************************************************/
2094{
2096
2097 foreach (hupdate, lhuc) {
2098 hupdate->set_fading(1.0);
2099 }
2100}
2101
2102/************************************************************************/
2106{
2108
2109 if (m_timer.elapsed() > 4000 && m_timer.elapsed() < 5000) {
2110 foreach (hudc, lhuc) {
2111 if (hudc->get_focus()) {
2112 m_timer.restart();
2113 te_inner();
2114 return;
2115 }
2116 hudc->set_fading((5000.0 - m_timer.elapsed()) / 1000);
2117 }
2118 }
2119 if (m_timer.elapsed() >= 5000) {
2120 hide();
2121 }
2122}
2123
2124/************************************************************************/
2128{
2130
2131 foreach (hupdate, lhuc) {
2132 hupdate->set_fading(1.0);
2133 }
2134 m_timer.restart();
2135 setVisible(true);
2136}
#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:369
QList< hud_unit_combat * > lhuc
Definition hudwidget.h:352
QElapsedTimer m_timer
Definition hudwidget.h:370
void add_combat_info(hud_unit_combat *huc)
hud_battle_log(QWidget *parent)
QVBoxLayout * main_layout
Definition hudwidget.h:351
void moveEvent(QMoveEvent *event)
void timerEvent(QTimerEvent *event)
scale_widget * sw
Definition hudwidget.h:368
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:316
void leaveEvent(QEvent *event)
void mousePressEvent(QMouseEvent *e)
void paintEvent(QPaintEvent *event)
void init_images(bool redraw=false)
struct unit * attacker
Definition hudwidget.h:315
const struct unit_type * type_attacker
Definition hudwidget.h:317
void set_scale(float scale)
struct tile * center_tile
Definition hudwidget.h:319
const struct unit_type * type_defender
Definition hudwidget.h:318
void enterEvent(QEnterEvent *event)
hud_unit_loader(struct unit *pcargo, struct tile *ptile)
struct tile * qtile
Definition hudwidget.h:237
struct unit * cargo
Definition hudwidget.h:236
void selection_changed(const QItemSelection &, const QItemSelection &)
QList< unit * > transports
Definition hudwidget.h:227
QLabel text_label
Definition hudwidget.h:206
void update_actions(unit_list *punits)
hud_units(QWidget *parent)
void moveEvent(QMoveEvent *event)
click_label unit_label
Definition hudwidget.h:204
click_label tile_label
Definition hudwidget.h:205
move_widget * mw
Definition hudwidget.h:217
QHBoxLayout * main_layout
Definition hudwidget.h:208
unit_actions * unit_icons
Definition hudwidget.h:209
void put_to_corner()
Definition mapview.cpp:399
void paintEvent(QPaintEvent *event)
void mousePressEvent(QMouseEvent *event)
QPixmap minus
Definition hudwidget.h:341
QPixmap plus
Definition hudwidget.h:340
scale_widget(Shape s, QWidget *p=0)
unit_actions(QWidget *parent, unit *punit)
void clear_layout()
QList< hud_action * > actions
Definition hudwidget.h:193
void init_layout()
unit * current_unit
Definition hudwidget.h:195
int update_actions()
QHBoxLayout * layout
Definition hudwidget.h:192
QRadioButton * this_continent
Definition hudwidget.h:278
QComboBox * unit_sel_type
Definition hudwidget.h:247
QRadioButton * sentried
Definition hudwidget.h:270
void keyPressEvent(QKeyEvent *event)
QVBoxLayout * main_layout
Definition hudwidget.h:246
QRadioButton * anywhere
Definition hudwidget.h:280
QRadioButton * main_continent
Definition hudwidget.h:279
QRadioButton * full_hp_mp
Definition hudwidget.h:275
QPushButton * cancel
Definition hudwidget.h:249
bool island_filter(struct unit *punit)
bool type_filter(struct unit *punit)
unit_hud_selector(QWidget *parent)
QRadioButton * full_mp
Definition hudwidget.h:273
void select_units(int x=0)
QRadioButton * fortified
Definition hudwidget.h:268
QRadioButton * this_tile
Definition hudwidget.h:277
QRadioButton * any_type
Definition hudwidget.h:283
QRadioButton * any_activity
Definition hudwidget.h:267
QPushButton * select
Definition hudwidget.h:248
QRadioButton * any
Definition hudwidget.h:272
bool activity_filter(struct unit *punit)
bool hp_filter(struct unit *punit)
QRadioButton * full_hp
Definition hudwidget.h:274
QRadioButton * this_type
Definition hudwidget.h:282
QRadioButton * idle
Definition hudwidget.h:269
bool client_is_observer(void)
struct civclient client
bool client_has_player(void)
#define client_player()
char * incite_cost
Definition comments.c:76
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
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
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:242
#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:742
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:1070
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:142
bool has_player_unit_type(Unit_type_id utype)
Definition hudwidget.cpp:60
bool goto_is_active(void)
Definition goto.c:1070
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:1048
bool can_unit_exist_at_tile(const struct civ_map *nmap, const struct unit *punit, const struct tile *ptile)
Definition movement.c:350
bool unit_can_load(const struct unit *punit)
Definition movement.c:916
bool can_unit_transport(const struct unit *transporter, const struct unit *transported)
Definition movement.c:888
#define SINGLE_MOVE
Definition movement.h:26
static mpgui * gui
Definition mpgui_qt.cpp:53
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:794
int player_get_expected_income(const struct player *pplayer)
Definition player.c:1294
struct city * player_city_by_number(const struct player *pplayer, int city_id)
Definition player.c:1211
struct city * player_primary_capital(const struct player *pplayer)
Definition player.c:1345
const char * research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Definition research.c:276
struct research * research_get(const struct player *pplayer)
Definition research.c:130
bool can_build_road(const struct civ_map *nmap, struct road_type *proad, const struct unit *punit, const struct tile *ptile)
Definition road.c:301
@ 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:318
struct tile * tile
Definition city.h:320
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:282
struct player_economic economic
Definition player.h:284
Tech_type_id researching
Definition research.h:52
struct research::@79::@81 client
int researching_cost
Definition research.h:96
int bulbs_researched
Definition research.h:53
int movement_cost
Definition terrain.h:92
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:524
Definition unit.h:140
enum unit_activity activity
Definition unit.h:159
int moves_left
Definition unit.h:152
int hp
Definition unit.h:153
int fuel
Definition unit.h:155
struct tile * tile
Definition unit.h:142
int homecity
Definition unit.h:148
const struct unit_type * utype
Definition unit.h:141
struct player * owner
Definition unit.h:145
int height
int width
struct civ_map map
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#define TRUE
Definition support.h:46
#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:512
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:845
const char * tile_get_info_text(const struct tile *ptile, bool include_nuisances, int linebreaks)
Definition tile.c:772
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
int tileset_unit_width(const struct tileset *t)
Definition tilespec.c:823
int tileset_unit_height(const struct tileset *t)
Definition tilespec.c:831
struct tileset * unscaled_tileset
Definition tilespec.c:592
bool tileset_is_isometric(const struct tileset *t)
Definition tilespec.c:738
int tileset_tile_height(const struct tileset *t)
Definition tilespec.c:791
int tileset_full_tile_width(const struct tileset *t)
Definition tilespec.c:802
struct sprite * get_unittype_sprite(const struct tileset *t, const struct unit_type *punittype, enum unit_activity activity, enum direction8 facing)
Definition tilespec.c:7045
int get_transporter_occupancy(const struct unit *ptrans)
Definition unit.c:1847
bool can_unit_change_homecity_to(const struct civ_map *nmap, const struct unit *punit, const struct city *pcity)
Definition unit.c:508
bool unit_can_add_or_build_city(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:491
struct unit * unit_transport_get(const struct unit *pcargo)
Definition unit.c:2545
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Definition unit.c:402
bool can_unit_do_autoworker(const struct unit *punit)
Definition unit.c:649
int get_transporter_capacity(const struct unit *punit)
Definition unit.c:316
bool can_unit_paradrop(const struct civ_map *nmap, const struct unit *punit)
Definition unit.c:865
enum unit_upgrade_result unit_upgrade_test(const struct civ_map *nmap, const struct unit *punit, bool is_free)
Definition unit.c:2052
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2529
bool can_unit_unload(const struct unit *pcargo, const struct unit *ptrans)
Definition unit.c:795
#define unit_tile(_pu)
Definition unit.h:407
@ UU_OK
Definition unit.h:62
#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:126
const char * unit_name_translation(const struct unit *punit)
Definition unittype.c:1595
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1604
Unit_type_id utype_number(const struct unit_type *punittype)
Definition unittype.c:102
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:93
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1586
#define utype_fuel(ptype)
Definition unittype.h:847
#define unit_type_iterate(_p)
Definition unittype.h:863
#define unit_type_iterate_end
Definition unittype.h:870