Freeciv-3.3
Loading...
Searching...
No Matches
gui_main.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#ifdef AUDIO_SDL
19/* Though it would happily compile without this include,
20 * it is needed for sound to work.
21 * It defines "main" macro to rename our main() so that
22 * it can install SDL's own. */
23#ifdef SDL2_PLAIN_INCLUDE
24#include <SDL.h>
25#else // PLAIN_INCLUDE
26#include <SDL2/SDL.h>
27#endif // PLAIN_INCLUDE
28#endif // AUDIO_SDL
29
30#include <stdio.h>
31
32// Qt
33#include <QApplication>
34#include <QLibraryInfo>
35#include <QMessageBox>
36#include <QScrollBar>
37#include <QStyleFactory>
38
39// utility
40#include "fc_cmdline.h"
41#include "fciconv.h"
42#include "log.h"
43
44// client
45#include "client_main.h"
46#include "editgui_g.h"
47#include "gui_properties.h"
48#include "options.h"
49#include "sprite.h"
50#include "svgflag.h"
51#include "themes_common.h"
52#include "tilespec.h"
53
54// gui-qt
55#include "fc_client.h"
56#include "fonts.h"
57#include "gui_main.h"
58#include "helpdlg.h"
59#include "hudwidget.h"
60#include "qtg_cxxside.h"
61
62extern void restart_notify_dialogs();
63extern void city_font_update();
64
65const bool gui_use_transliteration = false;
66const char * const gui_character_encoding = "UTF-8";
67const char *client_string = "gui-qt";
69static QApplication *qapp = nullptr;
70
71void reset_unit_table(void);
72static void apply_font(struct option *poption);
73static void apply_help_font(struct option *poption);
74static void apply_notify_font(struct option *poption);
75static void apply_sidebar(struct option *poption);
76static void apply_titlebar(struct option *poption);
77static void apply_fullscreen(struct option *poption);
78
79/**********************************************************************/
82class fc_client *gui()
83{
84 return freeciv_qt;
85}
86
87/**********************************************************************/
91{}
92
93/**********************************************************************/
96int main(int argc, char **argv)
97{
99
100 return client_main(argc, argv, TRUE);
101}
102
103/**********************************************************************/
107static void print_usage()
108{
109 // Add client-specific usage information here
111 _("This client accepts the standard Qt command-line options\n"
112 "after '--'. See the Qt documentation.\n\n"));
113
115 _("Other gui-specific options are:\n"));
116
118 _("-s, --shortcutreset\tReset shortcut keys to "
119 "default values\n"));
120
121 fc_fprintf(stderr, "\n");
122
123 // TRANS: No full stop after the URL, could cause confusion.
124 fc_fprintf(stderr, _("Report bugs at %s\n"), BUG_URL);
125}
126
127/**********************************************************************/
132static bool parse_options(int argc, char **argv)
133{
134 int i = 1;
135
136 while (i < argc) {
137 if (is_option("--help", argv[i])) {
138 print_usage();
139 return false;
140 }
141 if (is_option("--shortcutreset", argv[i])) {
143 }
144 // Can't check against unknown options, as those might be Qt options
145
146 i++;
147 }
148
149 return true;
150}
151
152/**********************************************************************/
156{
157 log_normal(_("Migrating Qt-client options from freeciv-2.5 options."));
158
160
162}
163
164/**********************************************************************/
168int qtg_ui_main(int argc, char *argv[])
169{
170 if (parse_options(argc, argv)) {
171 qapp = new QApplication(argc, argv);
172 QPixmap *qpm;
174 int tsret;
175
177 if (tsret != EXIT_SUCCESS) {
178 return tsret;
179 }
180
182#ifdef FREECIV_SVG_FLAGS
184#else // FREECIV_SVG_FLAGS
185 fc_fprintf(stderr, _("svg flags not enabled in this freeciv build."));
186#endif // FREECIV_SVG_FLAGS
187 }
188
192 app_icon = ::QIcon(*qpm);
193 qapp->setWindowIcon(app_icon);
195 /* We're using fresh defaults for this version of this client,
196 * so prevent any future migrations from other versions */
200 }
203 }
204 freeciv_qt = new fc_client();
205
209 }
210
211 // Initial fonts setup by forcing running change-callback for each
213 if (OT_FONT == option_type(poption)) {
215 }
217
219 }
220
221 return EXIT_SUCCESS;
222}
223
224/**********************************************************************/
228{
229 return qapp;
230}
231
232/**********************************************************************/
236{
237 struct option *poption;
238
239#define option_var_set_callback(var, callback) \
240 if ((poption = optset_option_by_name(client_optset, #var))) { \
241 option_set_changed_callback(poption, callback); \
242 } else { \
243 log_error("Didn't find option %s!", #var); \
244 }
245 option_var_set_callback(gui_qt_font_city_names,
246 apply_font);
247 option_var_set_callback(gui_qt_font_city_productions,
248 apply_font);
249 option_var_set_callback(gui_qt_font_reqtree_text,
250 apply_font);
251 option_var_set_callback(gui_qt_font_default,
252 apply_font);
253 option_var_set_callback(gui_qt_font_help_text,
255 option_var_set_callback(gui_qt_font_chatline,
256 apply_font);
257 option_var_set_callback(gui_qt_font_notify_label,
259 option_var_set_callback(gui_qt_show_titlebar,
261 option_var_set_callback(gui_qt_sidebar_left,
263 option_var_set_callback(gui_qt_fullscreen,
265#undef option_var_set_callback
266}
267
268/**********************************************************************/
272{
273 delete freeciv_qt;
274 delete qapp;
275 qapp = nullptr;
276}
277
278/**********************************************************************/
288
289/**********************************************************************/
294{
295 QApplication::beep();
296 QApplication::alert(gui()->central_wdg);
297}
298
299/**********************************************************************/
306void qtg_add_net_input(int sock)
307{
308 gui()->add_server_source(sock);
309}
310
311/**********************************************************************/
320
321/**********************************************************************/
332void qtg_set_unit_icon(int idx, struct unit *punit)
333{
334 // PORTME
335}
336
337/**********************************************************************/
345{
346 // PORTME
347}
348
349/**********************************************************************/
355{
356 if (gui()->unit_sel != nullptr && gui()->unit_sel->isVisible()) {
358 }
359
360 if (gui()->gtd != nullptr && gui()->gtd->isVisible()) {
361 gui()->gtd->update_dlg();
362 }
363}
364
365/**********************************************************************/
370void qtg_add_idle_callback(void (callback)(void *), void *data)
371{
372 call_me_back *cb = new call_me_back; // Removed in mr_idler:idling()
373
374 cb->callback = callback;
375 cb->data = data;
377}
378
379/**********************************************************************/
383{
384 bool val;
385 QWidget *w;
386 Qt::WindowFlags flags = Qt::Window;
388
389 if (gui()->current_page() < PAGE_GAME) {
390 return;
391 }
392
393 if (val) {
394 w = new QWidget();
395 gui()->setWindowFlags(flags);
396 delete gui()->corner_wid;
397 gui()->corner_wid = nullptr;
398 gui()->menu_bar->setCornerWidget(w);
399 } else {
400 flags |= Qt::CustomizeWindowHint;
401 gui()->setWindowFlags(flags);
402 gui()->corner_wid = new fc_corner(gui());
403 gui()->menu_bar->setCornerWidget(gui()->corner_wid);
404 }
405 gui()->show();
406}
407
408/**********************************************************************/
412{
414}
415
416/**********************************************************************/
419static void apply_font(struct option *poption)
420{
421 QFont *f;
423 QString s;
424
425 if (gui()) {
426 // FIXME: All this should be within gui()->update_fonts()
427 f = new QFont;
429 f->fromString(s);
430 s = option_name(poption);
432 delete remove_old;
436 QApplication::setFont(*fc_font::instance()->get_font(fonts::default_font));
439 gui()->update_fonts();
440 }
441
443}
444
445/**********************************************************************/
448static void apply_help_font(struct option *poption)
449{
450 QFont *f;
452 QString s;
453
454 if (gui()) {
455 f = new QFont;
457 f->fromString(s);
458 s = option_name(poption);
460 delete remove_old;
463 }
464}
465
466/**********************************************************************/
469static void apply_notify_font(struct option *poption)
470{
471 if (gui()) {
474 }
478 }
479}
480
481/**********************************************************************/
484static void apply_fullscreen(struct option *poption)
485{
487}
488
489/**********************************************************************/
494
495/**********************************************************************/
500
501/**********************************************************************/
504void qtg_editgui_popup_properties(const struct tile_list *tiles, int objtype)
505{}
506
507/**********************************************************************/
512
513/**********************************************************************/
517 bool removal)
518{}
519
520/**********************************************************************/
524{}
525
526/**********************************************************************/
529void qtg_gui_update_font(const char *font_name, const char *font_value)
530{
531 QFont *f;
534
535 fname = "gui_qt_font_" + QString(font_name);
536 f = new QFont;
537 f->fromString(font_value);
539 delete remove_old;
542}
543
544/**********************************************************************/
547enum gui_type qtg_get_gui_type()
548{
549 return GUI_QT;
550}
551
552/**********************************************************************/
556{
557 // FIXME
558}
559
560/**********************************************************************/
564{
565 hud_message_box *ask = new hud_message_box(gui()->central_wdg);
566
567 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
568 ask->setDefaultButton(QMessageBox::Cancel);
569 ask->set_text_title(_("Are you sure you want to quit?"), _("Quit?"));
570 ask->setAttribute(Qt::WA_DeleteOnClose);
571 QObject::connect(ask, &hud_message_box::accepted, [=]() {
573 if (client.conn.used) {
575 }
576 gui()->write_settings();
577 qapp->quit();
578 });
579 ask->show();
580}
581
582/**********************************************************************/
586{
587 // There's also an separate entry about Qt in help menu.
588
589 QByteArray ver = QLibraryInfo::version().toString().toUtf8();
590
591 cat_snprintf(outbuf, outlen, _("\nBuilt against Qt %s, using %s"),
592 QT_VERSION_STR, ver.data());
593
594#ifdef FC_QT5_MODE
595 cat_snprintf(outbuf, outlen, _("\nBuilt in Qt5 mode."));
596#elif defined(FC_QT6X_MODE)
597 cat_snprintf(outbuf, outlen, _("\nBuilt in Qt6x mode."));
598#else // FC_QT5_MODE
599 cat_snprintf(outbuf, outlen, _("\nBuilt in Qt6 mode."));
600#endif // FC_QT5_MODE
601}
602
603/**********************************************************************/
static QFont * get_font(enum client_font font)
Definition canvas.cpp:379
void update_font()
Definition chatline.cpp:365
void apply_fullscreen()
goto_dialog * gtd
Definition fc_client.h:265
mr_menu * menu_bar
Definition fc_client.h:257
mr_idle mr_idler
Definition fc_client.h:255
units_select * unit_sel
Definition fc_client.h:263
void write_settings()
info_tab * infotab
Definition fc_client.h:261
void add_server_source(int)
void update_sidebar_position()
Definition pages.cpp:2332
void update_start_page()
Definition pages.cpp:1703
void update_fonts()
void fc_main(QApplication *qapp)
fc_corner * corner_wid
Definition fc_client.h:258
void remove_server_source()
static fc_font * instance()
Definition fonts.cpp:41
void set_font(QString name, QFont *qf)
Definition fonts.cpp:123
QFont * get_font(QString name)
Definition fonts.cpp:63
void get_mapfont_size()
Definition fonts.cpp:114
void update_dlg()
Definition gotodlg.cpp:250
chatwdg * chtwdg
Definition messagewin.h:79
void add_callback(call_me_back *cb)
Definition mapview.cpp:188
void update_units()
Definition dialogs.cpp:4834
int client_main(int argc, char *argv[], bool postpone_tileset)
struct civclient client
void start_quitting(void)
int default_tileset_select(void)
void disconnect_from_server(bool leaving_sound)
Definition clinet.c:306
char * incite_cost
Definition comments.c:76
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
int objtype
Definition editgui_g.h:28
bool is_option(const char *option_name, char *option)
Definition fc_cmdline.c:112
void fc_fprintf(FILE *stream, const char *format,...) fc__attribute((__format__(__printf__
#define _(String)
Definition fcintl.h:67
void configure_fonts()
Definition fonts.cpp:154
void update_city_descriptions(void)
Definition mapview.c:488
static enum client_pages current_page
Definition pages.c:78
static bool load_theme
Definition theme_dlg.c:30
const char * client_string
Definition gui_main.cpp:67
#define option_var_set_callback(var, callback)
void qtg_ui_init()
Definition gui_main.cpp:90
void qtg_editgui_popup_properties(const struct tile_list *tiles, int objtype)
Definition gui_main.cpp:504
void qtg_remove_net_input()
Definition gui_main.cpp:316
static void apply_notify_font(struct option *poption)
Definition gui_main.cpp:469
void popup_quit_dialog()
Definition gui_main.cpp:563
int main(int argc, char **argv)
Definition gui_main.cpp:96
void qtg_options_extra_init()
Definition gui_main.cpp:235
static QApplication * qapp
Definition gui_main.cpp:69
static void print_usage()
Definition gui_main.cpp:107
void qtg_editgui_refresh()
Definition gui_main.cpp:498
class fc_client * gui()
Definition gui_main.cpp:82
void city_font_update()
Definition citydlg.cpp:3886
void reset_unit_table(void)
Definition gui_main.cpp:555
static void apply_fullscreen(struct option *poption)
Definition gui_main.cpp:484
int qtg_ui_main(int argc, char *argv[])
Definition gui_main.cpp:168
void qtg_editgui_popdown_all()
Definition gui_main.cpp:510
QApplication * current_app()
Definition gui_main.cpp:227
void qtg_real_conn_list_dialog_update(void *unused)
Definition gui_main.cpp:281
static fc_client * freeciv_qt
Definition gui_main.cpp:68
static void apply_help_font(struct option *poption)
Definition gui_main.cpp:448
void qtg_editgui_tileset_changed()
Definition gui_main.cpp:492
void qtg_editgui_notify_object_created(int tag, int id)
Definition gui_main.cpp:523
void qtg_setup_gui_properties()
Definition gui_main.cpp:606
void qtg_add_net_input(int sock)
Definition gui_main.cpp:306
static void apply_titlebar(struct option *poption)
Definition gui_main.cpp:382
static void apply_sidebar(struct option *poption)
Definition gui_main.cpp:411
void qtg_editgui_notify_object_changed(int objtype, int object_id, bool removal)
Definition gui_main.cpp:516
void qtg_gui_update_font(const char *font_name, const char *font_value)
Definition gui_main.cpp:529
void qtg_set_unit_icon(int idx, struct unit *punit)
Definition gui_main.cpp:332
void qtg_ui_exit()
Definition gui_main.cpp:271
void qtg_real_focus_units_changed(void)
Definition gui_main.cpp:354
void qtg_insert_client_build_info(char *outbuf, size_t outlen)
Definition gui_main.cpp:585
void qtg_set_unit_icons_more_arrow(bool onoff)
Definition gui_main.cpp:344
const char *const gui_character_encoding
Definition gui_main.cpp:66
void qtg_add_idle_callback(void(callback)(void *), void *data)
Definition gui_main.cpp:370
enum gui_type qtg_get_gui_type()
Definition gui_main.cpp:547
static void migrate_options_from_2_5()
Definition gui_main.cpp:155
static bool parse_options(int argc, char **argv)
Definition gui_main.cpp:132
void restart_notify_dialogs()
Definition dialogs.cpp:4121
const bool gui_use_transliteration
Definition gui_main.cpp:65
static void apply_font(struct option *poption)
Definition gui_main.cpp:419
void qtg_sound_bell()
Definition gui_main.cpp:293
const char * font_name
Definition gui_main_g.h:43
struct client_properties gui_properties
void update_help_fonts()
Definition helpdlg.cpp:113
#define log_normal(message,...)
Definition log.h:108
const char *const default_font
Definition fonts.h:27
void option_changed(struct option *poption)
Definition options.c:784
const struct option_set * client_optset
Definition options.c:1316
const char * option_name(const struct option *poption)
Definition options.c:664
bool option_bool_get(const struct option *poption)
Definition options.c:833
enum option_type option_type(const struct option *poption)
Definition options.c:694
struct client_options gui_options
Definition options.c:71
const char * option_font_get(const struct option *poption)
Definition options.c:1177
#define options_iterate(poptset, poption)
Definition options.h:587
#define options_iterate_end
Definition options.h:592
void qtg_real_set_client_page(enum client_pages page)
Definition pages.cpp:104
enum client_pages qtg_get_current_client_page()
Definition pages.cpp:122
void setup_gui_funcs()
void qtg_gui_clear_theme()
Definition themes.cpp:104
void qtg_real_science_report_dialog_update(void *unused)
void shortcutreset()
void(* callback)(void *data)
Definition mapview.h:54
void * data
Definition mapview.h:55
struct connection conn
Definition client_main.h:96
bool gui_qt_fullscreen
Definition options.h:442
char gui_qt_default_theme_name[512]
Definition options.h:446
bool gui_qt_svgflags
Definition options.h:460
bool first_boot
Definition options.h:128
bool gui_qt_migrated_from_2_5
Definition options.h:141
bool migrate_fullscreen
Definition options.h:146
bool gui_qt_default_fonts_set
Definition options.h:142
QPixmap * pm
Definition sprite.h:25
Definition unit.h:140
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:986
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
bool svg_flag_enable(void)
Definition svgflag.c:39
void tileset_load_tiles(struct tileset *t)
Definition tilespec.c:3804
struct sprite * get_icon_sprite(const struct tileset *t, enum icon_type icon)
Definition tilespec.c:7203
void tileset_init(struct tileset *t)
Definition tilespec.c:7354
@ ICON_FREECIV
Definition tilespec.h:315