Freeciv-3.2
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 "options.h"
48#include "sprite.h"
49#include "svgflag.h"
50#include "themes_common.h"
51#include "tilespec.h"
52
53// gui-qt
54#include "fc_client.h"
55#include "fonts.h"
56#include "gui_main.h"
57#include "helpdlg.h"
58#include "hudwidget.h"
59#include "qtg_cxxside.h"
60
61extern "C" {
63}
64extern void restart_notify_dialogs();
65extern void city_font_update();
66
67const bool gui_use_transliteration = false;
68const char * const gui_character_encoding = "UTF-8";
69const char *client_string = "gui-qt";
71static QApplication *qapp = nullptr;
72
73void reset_unit_table(void);
74static void apply_font(struct option *poption);
75static void apply_help_font(struct option *poption);
76static void apply_notify_font(struct option *poption);
77static void apply_sidebar(struct option *poption);
78static void apply_titlebar(struct option *poption);
79static void apply_fullscreen(struct option *poption);
80
81/**********************************************************************/
84class fc_client *gui()
85{
86 return freeciv_qt;
87}
88
89/**********************************************************************/
93{}
94
95/**********************************************************************/
98int main(int argc, char **argv)
99{
101
102 return client_main(argc, argv, TRUE);
103}
104
105/**********************************************************************/
109static void print_usage()
110{
111 // Add client-specific usage information here
113 _("This client accepts the standard Qt command-line options\n"
114 "after '--'. See the Qt documentation.\n\n"));
115
117 _("Other gui-specific options are:\n"));
118
120 _("-s, --shortcutreset\tReset shortcut keys to "
121 "default values\n"));
122
123 fc_fprintf(stderr, "\n");
124
125 // TRANS: No full stop after the URL, could cause confusion.
126 fc_fprintf(stderr, _("Report bugs at %s\n"), BUG_URL);
127}
128
129/**********************************************************************/
134static bool parse_options(int argc, char **argv)
135{
136 int i = 1;
137
138 while (i < argc) {
139 if (is_option("--help", argv[i])) {
140 print_usage();
141 return false;
142 }
143 if (is_option("--shortcutreset", argv[i])) {
145 }
146 // Can't check against unknown options, as those might be Qt options
147
148 i++;
149 }
150
151 return true;
152}
153
154/**********************************************************************/
158{
159 log_normal(_("Migrating Qt-client options from freeciv-2.5 options."));
160
162
164}
165
166/**********************************************************************/
170int qtg_ui_main(int argc, char *argv[])
171{
172 if (parse_options(argc, argv)) {
173 qapp = new QApplication(argc, argv);
174 QPixmap *qpm;
176 int tsret;
177
179 if (tsret != EXIT_SUCCESS) {
180 return tsret;
181 }
182
184#ifdef FREECIV_SVG_FLAGS
186#else // FREECIV_SVG_FLAGS
187 fc_fprintf(stderr, _("svg flags not enabled in this freeciv build."));
188#endif // FREECIV_SVG_FLAGS
189 }
190
194 app_icon = ::QIcon(*qpm);
195 qapp->setWindowIcon(app_icon);
197 /* We're using fresh defaults for this version of this client,
198 * so prevent any future migrations from other versions */
202 }
205 }
206 freeciv_qt = new fc_client();
207
211 }
212
213 // Initial fonts setup by forcing running change-callback for each
215 if (OT_FONT == option_type(poption)) {
217 }
219
221 }
222
223 return EXIT_SUCCESS;
224}
225
226/**********************************************************************/
230{
231 return qapp;
232}
233
234/**********************************************************************/
238{
239 struct option *poption;
240
241#define option_var_set_callback(var, callback) \
242 if ((poption = optset_option_by_name(client_optset, #var))) { \
243 option_set_changed_callback(poption, callback); \
244 } else { \
245 log_error("Didn't find option %s!", #var); \
246 }
247 option_var_set_callback(gui_qt_font_city_names,
248 apply_font);
249 option_var_set_callback(gui_qt_font_city_productions,
250 apply_font);
251 option_var_set_callback(gui_qt_font_reqtree_text,
252 apply_font);
253 option_var_set_callback(gui_qt_font_default,
254 apply_font);
255 option_var_set_callback(gui_qt_font_help_text,
257 option_var_set_callback(gui_qt_font_chatline,
258 apply_font);
259 option_var_set_callback(gui_qt_font_notify_label,
261 option_var_set_callback(gui_qt_show_titlebar,
263 option_var_set_callback(gui_qt_sidebar_left,
265 option_var_set_callback(gui_qt_fullscreen,
267#undef option_var_set_callback
268}
269
270/**********************************************************************/
274{
275 delete freeciv_qt;
276 delete qapp;
277 qapp = nullptr;
278}
279
280/**********************************************************************/
290
291/**********************************************************************/
296{
297 QApplication::beep();
298 QApplication::alert(gui()->central_wdg);
299}
300
301/**********************************************************************/
308void qtg_add_net_input(int sock)
309{
310 gui()->add_server_source(sock);
311}
312
313/**********************************************************************/
322
323/**********************************************************************/
334void qtg_set_unit_icon(int idx, struct unit *punit)
335{
336 // PORTME
337}
338
339/**********************************************************************/
347{
348 // PORTME
349}
350
351/**********************************************************************/
357{
358 if (gui()->unit_sel != nullptr && gui()->unit_sel->isVisible()) {
360 }
361
362 if (gui()->gtd != nullptr && gui()->gtd->isVisible()) {
363 gui()->gtd->update_dlg();
364 }
365}
366
367/**********************************************************************/
372void qtg_add_idle_callback(void (callback)(void *), void *data)
373{
374 call_me_back *cb = new call_me_back; // Removed in mr_idler:idling()
375
376 cb->callback = callback;
377 cb->data = data;
379}
380
381/**********************************************************************/
385{
386 bool val;
387 QWidget *w;
388 Qt::WindowFlags flags = Qt::Window;
390
391 if (gui()->current_page() < PAGE_GAME) {
392 return;
393 }
394
395 if (val) {
396 w = new QWidget();
397 gui()->setWindowFlags(flags);
398 delete gui()->corner_wid;
399 gui()->corner_wid = nullptr;
400 gui()->menu_bar->setCornerWidget(w);
401 } else {
402 flags |= Qt::CustomizeWindowHint;
403 gui()->setWindowFlags(flags);
404 gui()->corner_wid = new fc_corner(gui());
405 gui()->menu_bar->setCornerWidget(gui()->corner_wid);
406 }
407 gui()->show();
408}
409
410/**********************************************************************/
414{
416}
417
418/**********************************************************************/
421static void apply_font(struct option *poption)
422{
423 QFont *f;
425 QString s;
426
427 if (gui()) {
428 // FIXME: All this should be within gui()->update_fonts()
429 f = new QFont;
431 f->fromString(s);
432 s = option_name(poption);
434 delete remove_old;
438 QApplication::setFont(*fc_font::instance()->get_font(fonts::default_font));
441 gui()->update_fonts();
442 }
443
445}
446
447/**********************************************************************/
450static void apply_help_font(struct option *poption)
451{
452 QFont *f;
454 QString s;
455
456 if (gui()) {
457 f = new QFont;
459 f->fromString(s);
460 s = option_name(poption);
462 delete remove_old;
465 }
466}
467
468/**********************************************************************/
471static void apply_notify_font(struct option *poption)
472{
473 if (gui()) {
476 }
480 }
481}
482
483/**********************************************************************/
486static void apply_fullscreen(struct option *poption)
487{
489}
490
491/**********************************************************************/
496
497/**********************************************************************/
502
503/**********************************************************************/
506void qtg_editgui_popup_properties(const struct tile_list *tiles, int objtype)
507{}
508
509/**********************************************************************/
514
515/**********************************************************************/
519 bool removal)
520{}
521
522/**********************************************************************/
526{}
527
528/**********************************************************************/
531void qtg_gui_update_font(const char *font_name, const char *font_value)
532{
533 QFont *f;
536
537 fname = "gui_qt_font_" + QString(font_name);
538 f = new QFont;
539 f->fromString(font_value);
541 delete remove_old;
544}
545
546/**********************************************************************/
549enum gui_type qtg_get_gui_type()
550{
551 return GUI_QT;
552}
553
554/**********************************************************************/
558{
559 // FIXME
560}
561
562/**********************************************************************/
566{
567 hud_message_box *ask = new hud_message_box(gui()->central_wdg);
568
569 ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
570 ask->setDefaultButton(QMessageBox::Cancel);
571 ask->set_text_title(_("Are you sure you want to quit?"), _("Quit?"));
572 ask->setAttribute(Qt::WA_DeleteOnClose);
573 QObject::connect(ask, &hud_message_box::accepted, [=]() {
575 if (client.conn.used) {
577 }
578 gui()->write_settings();
579 qapp->quit();
580 });
581 ask->show();
582}
583
584/**********************************************************************/
588{
589 // There's also an separate entry about Qt in help menu.
590
591 QByteArray ver = QLibraryInfo::version().toString().toUtf8();
592
593 cat_snprintf(outbuf, outlen, _("\nBuilt against Qt %s, using %s"),
594 QT_VERSION_STR, ver.data());
595
596#ifndef FC_QT5_MODE
597 cat_snprintf(outbuf, outlen, _("\nBuilt in Qt6 mode."));
598#else // FC_QT5_MODE
599 cat_snprintf(outbuf, outlen, _("\nBuilt in Qt5 mode."));
600#endif // FC_QT5_MODE
601}
static QFont * get_font(enum client_font font)
Definition canvas.cpp:379
void update_font()
Definition chatline.cpp:348
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:2304
void update_start_page()
Definition pages.cpp:1677
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:236
chatwdg * chtwdg
Definition messagewin.h:79
void add_callback(call_me_back *cb)
Definition mapview.cpp:188
void update_units()
Definition dialogs.cpp:4761
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:75
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:69
#define option_var_set_callback(var, callback)
void qtg_ui_init()
Definition gui_main.cpp:92
void qtg_editgui_popup_properties(const struct tile_list *tiles, int objtype)
Definition gui_main.cpp:506
void qtg_remove_net_input()
Definition gui_main.cpp:318
static void apply_notify_font(struct option *poption)
Definition gui_main.cpp:471
void popup_quit_dialog()
Definition gui_main.cpp:565
int main(int argc, char **argv)
Definition gui_main.cpp:98
void qtg_options_extra_init()
Definition gui_main.cpp:237
static QApplication * qapp
Definition gui_main.cpp:71
static void print_usage()
Definition gui_main.cpp:109
void qtg_editgui_refresh()
Definition gui_main.cpp:500
class fc_client * gui()
Definition gui_main.cpp:84
void city_font_update()
Definition citydlg.cpp:3882
void reset_unit_table(void)
Definition gui_main.cpp:557
static void apply_fullscreen(struct option *poption)
Definition gui_main.cpp:486
int qtg_ui_main(int argc, char *argv[])
Definition gui_main.cpp:170
void qtg_editgui_popdown_all()
Definition gui_main.cpp:512
QApplication * current_app()
Definition gui_main.cpp:229
void qtg_real_conn_list_dialog_update(void *unused)
Definition gui_main.cpp:283
static fc_client * freeciv_qt
Definition gui_main.cpp:70
static void apply_help_font(struct option *poption)
Definition gui_main.cpp:450
void qtg_editgui_tileset_changed()
Definition gui_main.cpp:494
void qtg_editgui_notify_object_created(int tag, int id)
Definition gui_main.cpp:525
void qtg_add_net_input(int sock)
Definition gui_main.cpp:308
static void apply_titlebar(struct option *poption)
Definition gui_main.cpp:384
static void apply_sidebar(struct option *poption)
Definition gui_main.cpp:413
void real_science_report_dialog_update(void *)
Definition repodlgs.c:751
void qtg_editgui_notify_object_changed(int objtype, int object_id, bool removal)
Definition gui_main.cpp:518
void qtg_gui_update_font(const char *font_name, const char *font_value)
Definition gui_main.cpp:531
void qtg_set_unit_icon(int idx, struct unit *punit)
Definition gui_main.cpp:334
void qtg_ui_exit()
Definition gui_main.cpp:273
void qtg_real_focus_units_changed(void)
Definition gui_main.cpp:356
void qtg_insert_client_build_info(char *outbuf, size_t outlen)
Definition gui_main.cpp:587
void qtg_set_unit_icons_more_arrow(bool onoff)
Definition gui_main.cpp:346
const char *const gui_character_encoding
Definition gui_main.cpp:68
void qtg_add_idle_callback(void(callback)(void *), void *data)
Definition gui_main.cpp:372
enum gui_type qtg_get_gui_type()
Definition gui_main.cpp:549
static void migrate_options_from_2_5()
Definition gui_main.cpp:157
static bool parse_options(int argc, char **argv)
Definition gui_main.cpp:134
void restart_notify_dialogs()
Definition dialogs.cpp:4048
const bool gui_use_transliteration
Definition gui_main.cpp:67
static void apply_font(struct option *poption)
Definition gui_main.cpp:421
void qtg_sound_bell()
Definition gui_main.cpp:295
const char * font_name
Definition gui_main_g.h:43
void update_help_fonts()
Definition helpdlg.cpp:113
#define log_normal(message,...)
Definition log.h:107
const char *const default_font
Definition fonts.h:27
void option_changed(struct option *poption)
Definition options.c:748
const struct option_set * client_optset
Definition options.c:1280
const char * option_name(const struct option *poption)
Definition options.c:628
bool option_bool_get(const struct option *poption)
Definition options.c:797
enum option_type option_type(const struct option *poption)
Definition options.c:658
struct client_options gui_options
Definition options.c:71
const char * option_font_get(const struct option *poption)
Definition options.c:1141
#define options_iterate(poptset, poption)
Definition options.h:550
#define options_iterate_end
Definition options.h:555
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 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:405
char gui_qt_default_theme_name[512]
Definition options.h:409
bool gui_qt_svgflags
Definition options.h:423
bool first_boot
Definition options.h:128
bool gui_qt_migrated_from_2_5
Definition options.h:140
bool migrate_fullscreen
Definition options.h:145
bool gui_qt_default_fonts_set
Definition options.h:141
QPixmap * pm
Definition sprite.h:25
Definition unit.h:138
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:1000
#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:3628
struct sprite * get_icon_sprite(const struct tileset *t, enum icon_type icon)
Definition tilespec.c:6979
void tileset_init(struct tileset *t)
Definition tilespec.c:7126
@ ICON_FREECIV
Definition tilespec.h:313