Added translator comment about government overthrown message.
[freeciv.git] / client / gui-qt / spaceshipdlg.cpp
blob5e950cb1a545d2b409af5652e3868f6d95955bf6
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.
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 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 /* common */
19 #include "game.h"
20 #include "victory.h"
22 // gui-qt
23 #include "canvas.h"
24 #include "qtg_cxxside.h"
25 #include "spaceshipdlg.h"
28 class QGridLayout;
30 /****************************************************************************
31 Constructor for spaceship report
32 ****************************************************************************/
33 ss_report::ss_report(struct player *pplayer)
35 int w, h;
36 QSize size;
38 setAttribute(Qt::WA_DeleteOnClose);
39 player = pplayer;
40 get_spaceship_dimensions(&w, &h);
41 can = qtg_canvas_create(w, h);
43 QGridLayout *layout = new QGridLayout;
44 ss_pix_label = new QLabel;
45 ss_pix_label->setPixmap(can->map_pixmap);
46 layout->addWidget(ss_pix_label, 0, 0, 3, 3);
47 ss_label = new QLabel;
48 layout->addWidget(ss_label, 0, 3, 3, 1);
49 launch_button = new QPushButton(_("Launch"));
50 connect(launch_button, SIGNAL(clicked()), SLOT(launch()));
51 layout->addWidget(launch_button, 4, 3, 1, 1);
52 setLayout(layout);
53 update_report();
56 /****************************************************************************
57 Destructor for spaceship report
58 ****************************************************************************/
59 ss_report::~ss_report()
61 gui()->remove_repo_dlg("SPS");
62 qtg_canvas_free(can);
65 /****************************************************************************
66 Initializes widget on game_tab_widget
67 ****************************************************************************/
68 void ss_report::init()
70 int index;
71 gui()->gimme_place(this, "SPS");
72 index = gui()->add_game_tab(this);
73 gui()->game_tab_widget->setCurrentIndex(index);
74 update_report();
77 /****************************************************************************
78 Updates spaceship report
79 ****************************************************************************/
80 void ss_report::update_report()
82 const char *ch;
83 struct player_spaceship *pship;
85 pship = &(player->spaceship);
87 if (victory_enabled(VC_SPACERACE) && player == client.conn.playing
88 && pship->state == SSHIP_STARTED && pship->success_rate > 0.0) {
89 launch_button->setEnabled(true);
90 } else {
91 launch_button->setEnabled(false);
93 ch = get_spaceship_descr(&player->spaceship);
94 ss_label->setText(ch);
95 put_spaceship(can, 0, 0, player);
96 ss_pix_label->setPixmap(can->map_pixmap);
97 update();
100 /****************************************************************************
101 Launch spaceship
102 ****************************************************************************/
103 void ss_report::launch()
105 send_packet_spaceship_launch(&client.conn);
109 /**************************************************************************
110 Popup (or raise) the spaceship dialog for the given player.
111 **************************************************************************/
112 void popup_spaceship_dialog(struct player *pplayer)
114 ss_report *ss_rep;
115 int i;
116 QWidget *w;
118 if (client_is_global_observer()) {
119 return;
121 if (!gui()->is_repo_dlg_open("SPS")) {
122 ss_rep = new ss_report(pplayer);
123 ss_rep->init();
124 } else {
125 i = gui()->gimme_index_of("SPS");
126 fc_assert(i != -1);
127 if (gui()->game_tab_widget->currentIndex() == i) {
128 return;
130 w = gui()->game_tab_widget->widget(i);
131 ss_rep = reinterpret_cast<ss_report *>(w);
132 gui()->game_tab_widget->setCurrentWidget(ss_rep);
136 /**************************************************************************
137 Close the spaceship dialog for the given player.
138 **************************************************************************/
139 void popdown_spaceship_dialog(struct player *pplayer)
141 /* PORTME */
144 /**************************************************************************
145 Refresh (update) the spaceship dialog for the given player.
146 **************************************************************************/
147 void refresh_spaceship_dialog(struct player *pplayer)
149 int i;
150 ss_report *ss_rep;
151 QWidget *w;
153 if (!gui()->is_repo_dlg_open("SPS")) {
154 return;
156 else {
157 i = gui()->gimme_index_of("SPS");
158 fc_assert(i != -1);
159 w = gui()->game_tab_widget->widget(i);
160 ss_rep = reinterpret_cast<ss_report*>(w);
161 gui()->game_tab_widget->setCurrentWidget(ss_rep);
162 ss_rep->update_report();
166 /**************************************************************************
167 Close all spaceships dialogs
168 **************************************************************************/
169 void popdown_all_spaceships_dialogs()
171 int i;
172 ss_report *ss_rep;
173 QWidget *w;
175 if (!gui()->is_repo_dlg_open("SPS")) {
176 return;
178 else {
179 i = gui()->gimme_index_of("SPS");
180 fc_assert(i != -1);
181 w = gui()->game_tab_widget->widget(i);
182 ss_rep = reinterpret_cast<ss_report*>(w);
183 ss_rep->deleteLater();