Freeciv-3.3: /fast/freeciv/nightly/main/client/gui-qt/optiondlg.cpp Source File

Freeciv-3.3

Loading...
Searching...
No Matches
optiondlg.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 <QApplication>
20#include <QCheckBox>
21#include <QColorDialog>
22#include <QComboBox>
23#include <QDialogButtonBox>
24#include <QFontDialog>
25#include <QGroupBox>
26#include <QHBoxLayout>
27#include <QLabel>
28#include <QLineEdit>
29#include <QPainter>
30#include <QPushButton>
31#include <QScrollArea>
32#include <QSpinBox>
33
34// utility
35#include "log.h"
36#include "string_vector.h"
37
38// client
39#include "options.h"
40#include "client_main.h"
41
42// gui-qt
43#include "fc_client.h"
44
45#include "optiondlg.h"
46
47enum {
48 RESPONSE_CANCEL,
49 RESPONSE_OK,
50 RESPONSE_APPLY,
51 RESPONSE_RESET,
52 RESPONSE_REFRESH,
53 RESPONSE_SAVE
54};
55
56// Global value to store pointers to opened config dialogs
57 QMap<const struct option_set *, option_dialog *> dialog_list;
58
59/************************************************************************/
62 QString split_text(QString text, bool cut)
63{
64 QStringList sl;
65 QString st, str, result;
66 int i;
67 int j = 0;
68
69 sl = text.split("\n");
70 foreach (const QString &s, sl) {
71 st = s;
72 while (st.length() >= 80) {
73 str = st.left(80);
74 i = str.lastIndexOf(' ');
75 if (i == -1) {
76 i = 80;
77 }
78 result = result + str.left(i) + '\n';
79 /* Skip last space - at (i + 1)
80 unless there there was no space */
81 if (i != 80) {
82 st.remove(0, i + 1);
83 } else {
84 st.remove(0, i);
85 }
86 }
87 str = st;
88 if (str.left(str.length()) != "") {
89 result = result + str.left(str.length()) + '\n';
90 }
91 j++;
92 if (j >= 12 && cut) {
93 result = result + _("... read more in help") + "\n";
94 break;
95 }
96 }
97 result.remove(result.lastIndexOf('\n'), 1);
98
99 return result;
100}
101
102/************************************************************************/
105 QString cut_helptext(QString text)
106{
107 QStringList sl;
108 QString ret_str;
109
110 // Remove all lines from help which has '*' in first 3 chars
111 sl = text.split('\n');
112 foreach (const QString &s, sl) {
113 if (s.length() > 2) {
114 if (s.at(0) != '*' && s.at(1) != '*' && s.at(2) != '*') {
115 ret_str = ret_str + s + '\n';
116 }
117 } else {
118 ret_str = ret_str + s + '\n';
119 }
120 }
121 return ret_str;
122}
123
124/************************************************************************/
127option_dialog::option_dialog(const QString &name,
128 const option_set *options, bool client_set,
129 QWidget *parent)
130 : qfc_dialog(parent), client_settings(client_set)
131{
132 QPushButton *but;
133
134 curr_options = options;
135 setWindowTitle(name);
136 tab_widget = new QTabWidget;
137
138 button_box = new QDialogButtonBox();
139 but = new QPushButton(style()->standardIcon(QStyle::SP_DialogCancelButton),
140 _("Cancel"));
141 button_box->addButton(but, QDialogButtonBox::ActionRole);
142 QObject::connect(but, &QPushButton::clicked, [this]() {
143 apply_option(RESPONSE_CANCEL);
144 });
145
146 but = new QPushButton(style()->standardIcon(QStyle::SP_DialogResetButton),
147 _("Reset"));
148 button_box->addButton(but, QDialogButtonBox::ResetRole);
149 QObject::connect(but, &QPushButton::clicked, [this]() {
150 apply_option(RESPONSE_RESET);
151 });
152
153 but = new QPushButton(QIcon::fromTheme("view-refresh"), _("Refresh"));
154 button_box->addButton(but, QDialogButtonBox::ActionRole);
155 QObject::connect(but, &QPushButton::clicked, [this]() {
156 apply_option(RESPONSE_REFRESH);
157 });
158
159 but = new QPushButton(style()->standardIcon(QStyle::SP_DialogApplyButton),
160 _("Apply"));
161 button_box->addButton(but, QDialogButtonBox::ActionRole);
162 QObject::connect(but, &QPushButton::clicked, [this]() {
163 apply_option(RESPONSE_APPLY);
164 });
165
166 but = new QPushButton(style()->standardIcon(QStyle::SP_DialogSaveButton),
167 _("Save"));
168 button_box->addButton(but, QDialogButtonBox::ActionRole);
169 QObject::connect(but, &QPushButton::clicked, [this]() {
170 apply_option(RESPONSE_SAVE);
171 });
172
173 but = new QPushButton(style()->standardIcon(QStyle::SP_DialogOkButton),
174 _("Ok"));
175 button_box->addButton(but, QDialogButtonBox::ActionRole);
176 QObject::connect(but, &QPushButton::clicked, [this]() {
177 apply_option(RESPONSE_OK);
178 });
179
180 main_layout = new QVBoxLayout;
181 main_layout->addWidget(tab_widget);
182 categories.clear();
183 fill(options);
184 main_layout->addWidget(button_box);
185 setLayout(main_layout);
186
187 setAttribute(Qt::WA_DeleteOnClose);
188}
189
190/************************************************************************/
193option_dialog::~option_dialog()
194{
195 while (::dialog_list.contains(curr_options)) {
196 ::dialog_list.remove(curr_options);
197 }
198 destroy();
199}
200
201/************************************************************************/
204 void option_dialog::apply_option(int response)
205{
206 switch (response) {
207 case RESPONSE_APPLY:
208 apply_options();
209 break;
210 case RESPONSE_CANCEL:
211 ::dialog_list.remove(curr_options);
212 close();
213 break;
214 case RESPONSE_OK:
215 apply_options();
216 ::dialog_list.remove(curr_options);
217 close();
218 break;
219 case RESPONSE_SAVE:
220 desired_settable_options_update();
221 options_save(nullptr);
222 break;
223 case RESPONSE_RESET:
224 full_reset();
225 break;
226 case RESPONSE_REFRESH:
227 full_refresh();
228 break;
229 }
230}
231
232/************************************************************************/
235 void option_dialog::get_color(struct option *poption, QByteArray &a1,
236 QByteArray &a2)
237{
238 QPalette pal;
239 QColor col1, col2;
240 QWidget *w;
241 QPushButton *but;
242
243 w = reinterpret_cast<QPushButton *>(option_get_gui_data(poption));
244 but = w->findChild<QPushButton *>("text_color");
245 pal = but->palette();
246 col1 = pal.color(QPalette::Button);
247 but = w->findChild<QPushButton *>("text_background");
248 pal = but->palette();
249 col2 = pal.color(QPalette::Button);
250 a1 = col1.name().toUtf8();
251 a2 = col2.name().toUtf8();
252}
253
254/************************************************************************/
257 void option_dialog::apply_options()
258{
259 QByteArray ba1, ba2;
260
261 options_iterate(curr_options, poption) {
262 switch (option_type(poption)) {
263 case OT_BOOLEAN:
264 option_bool_set(poption, get_bool(poption));
265 break;
266 case OT_INTEGER:
267 option_int_set(poption, get_int(poption));
268 break;
269 case OT_STRING:
270 option_str_set(poption, get_string(poption).constData());
271 break;
272 case OT_ENUM:
273 option_enum_set_int(poption, get_enum(poption));
274 break;
275 case OT_BITWISE:
276 option_bitwise_set(poption, get_bitwise(poption));
277 break;
278 case OT_FONT:
279 option_font_set(poption, get_button_font(poption).constData());
280 break;
281 case OT_COLOR:
282 get_color(poption, ba1, ba2);
283 option_color_set(poption, ft_color_construct(ba1.data(), ba2.data()));
284 break;
285 case OT_VIDEO_MODE:
286 log_error("Option type %s (%d) not supported yet.",
287 option_type_name(option_type(poption)),
288 option_type(poption));
289 break;
290 }
291 } options_iterate_end;
292}
293
294
295/************************************************************************/
298 void option_dialog::set_bool(struct option *poption, bool value)
299{
300 QCheckBox *c;
301
302 c = reinterpret_cast< QCheckBox *>(option_get_gui_data(poption));
303 if (value) {
304 c->setCheckState(Qt::Checked);
305 } else {
306 c->setCheckState(Qt::Unchecked);
307 }
308}
309
310/************************************************************************/
313 bool option_dialog::get_bool(struct option *poption)
314{
315 QCheckBox *c;
316
317 c = reinterpret_cast< QCheckBox *>(option_get_gui_data(poption));
318 if (c->checkState() == Qt::Checked) {
319 return true;
320 } else {
321 return false;
322 }
323}
324
325/************************************************************************/
328 void option_dialog::set_int(struct option *poption, int value)
329{
330 QSpinBox *s;
331
332 s = reinterpret_cast< QSpinBox *>(option_get_gui_data(poption));
333 s->setValue(value);
334}
335
336/************************************************************************/
341 void option_dialog::set_font(struct option *poption, QString s)
342{
343 QStringList ql;
344 QPushButton *qp;
345 QFont *fp;
346
347 fp = new QFont();
348 fp->fromString(s);
349 qApp->processEvents();
350 qp = reinterpret_cast<QPushButton *>(option_get_gui_data(poption));
351 ql = s.split(",");
352 if (!s.isEmpty()) {
353 qp->setText(ql[0] + " " + ql[1]);
354 qp->setFont(*fp);
355 }
356}
357
358/************************************************************************/
361 int option_dialog::get_int(struct option *poption)
362{
363 QSpinBox *s;
364
365 s = reinterpret_cast< QSpinBox *>(option_get_gui_data(poption));
366 return s->value();
367}
368
369/************************************************************************/
372 void option_dialog::set_string(struct option *poption, const char *string)
373{
374 int i;
375 QComboBox *cb;
376 QLineEdit *le;
377
378 if (option_str_values(poption) != nullptr) {
379 cb = reinterpret_cast< QComboBox *>(option_get_gui_data(poption));
380 i = cb->findText(string);
381 if (i != -1) {
382 cb->setCurrentIndex(i);
383 }
384 } else {
385 le = reinterpret_cast<QLineEdit *>(option_get_gui_data(poption));
386 le->setText(string);
387 }
388}
389
390/************************************************************************/
393 QByteArray option_dialog::get_string(struct option *poption)
394{
395 QComboBox *cb;
396 QLineEdit *le;
397
398 if (option_str_values(poption) != nullptr) {
399 cb = reinterpret_cast< QComboBox *>(option_get_gui_data(poption));
400 return cb->currentText().toUtf8();
401 } else {
402 le = reinterpret_cast<QLineEdit *>(option_get_gui_data(poption));
403 return le->displayText().toUtf8();
404 }
405}
406
407/************************************************************************/
410 void option_dialog::set_enum(struct option *poption, int index)
411{
412 QComboBox *cb;
413
414 cb = reinterpret_cast< QComboBox *>(option_get_gui_data(poption));
415 cb->setCurrentIndex(index);
416}
417
418/************************************************************************/
421 int option_dialog::get_enum(struct option *poption)
422{
423 QComboBox *cb;
424
425 cb = reinterpret_cast< QComboBox *>(option_get_gui_data(poption));
426 return cb->currentIndex();
427}
428
429/************************************************************************/
432 void option_dialog::set_bitwise(struct option *poption, unsigned int value)
433{
434 QGroupBox *gb;
435 int i;
436 QList <QCheckBox *> check_buttons;
437
438 gb = reinterpret_cast< QGroupBox *>(option_get_gui_data(poption));
439 check_buttons = gb->findChildren <QCheckBox *>();
440
441 for (i = 0; i < check_buttons.count(); i++) {
442 if (value & (1 << i)) {
443 check_buttons[i]->setCheckState(Qt::Checked);
444 } else {
445 check_buttons[i]->setCheckState(Qt::Unchecked);
446 }
447 }
448}
449
450/************************************************************************/
453 unsigned int option_dialog::get_bitwise(struct option *poption)
454{
455 QGroupBox *gb;
456 int i;
457 unsigned int value = 0;
458 QList <QCheckBox *> check_buttons;
459
460 gb = reinterpret_cast< QGroupBox *>(option_get_gui_data(poption));
461 check_buttons = gb->findChildren <QCheckBox *>();
462
463 for (i = 0; i < check_buttons.count(); i++) {
464 if (check_buttons[i]->checkState() == Qt::Checked) {
465 value |= 1 << i;
466 }
467 }
468 return value;
469}
470
471/************************************************************************/
474 void option_dialog::set_button_color(QPushButton *button,
475 const char *colorname)
476{
477 if (button != nullptr && colorname != nullptr && colorname[0] != '\0') {
478 QString s1 = "QPushButton { background-color: ";
479 QString s2 = ";}";
480 QColor col;
481
482#ifdef FC_QT6X_MODE
483 col = QColor::fromString(colorname);
484#else // FC_QT6X_MODE
485 col.setNamedColor(colorname);
486#endif // FC_QT6X_MODE
487 button->setStyleSheet(s1 + col.name() + s2);
488 }
489}
490
491/************************************************************************/
494 void option_dialog::set_color(struct option *poption, struct ft_color color)
495{
496 QWidget *w;
497 QPushButton *but;
498
499 w = reinterpret_cast<QPushButton *>(option_get_gui_data(poption));
500 but = w->findChild<QPushButton *>("text_color");
501 set_button_color(but, color.foreground);
502
503 but = w->findChild<QPushButton *>("text_background");
504 set_button_color(but, color.background);
505}
506
507/************************************************************************/
510 void option_dialog::option_dialog_refresh(struct option *poption)
511{
512 switch (option_type(poption)) {
513 case OT_BOOLEAN:
514 set_bool(poption, option_bool_get(poption));
515 break;
516 case OT_INTEGER:
517 set_int(poption, option_int_get(poption));
518 break;
519 case OT_STRING:
520 set_string(poption, option_str_get(poption));
521 break;
522 case OT_ENUM:
523 set_enum(poption, option_enum_get_int(poption));
524 break;
525 case OT_BITWISE:
526 set_bitwise(poption, option_bitwise_get(poption));
527 break;
528 case OT_FONT:
529 set_font(poption, option_font_get(poption));
530 break;
531 case OT_COLOR:
532 set_color(poption, option_color_get(poption));
533 break;
534 case OT_VIDEO_MODE:
535 log_error("Option type %s (%d) not supported yet.",
536 option_type_name(option_type(poption)), option_type(poption));
537 break;
538 }
539}
540
541/************************************************************************/
544 void option_dialog::full_refresh()
545{
546 options_iterate(curr_options, poption) {
547 option_dialog_refresh(poption);
548 } options_iterate_end;
549}
550
551/************************************************************************/
554 void option_dialog::full_reset()
555{
556 options_iterate(curr_options, poption) {
557 option_dialog_reset(poption);
558 } options_iterate_end;
559}
560
561/************************************************************************/
564 void option_dialog::option_dialog_reset(struct option *poption)
565{
566 switch (option_type(poption)) {
567 case OT_BOOLEAN:
568 set_bool(poption, option_bool_def(poption));
569 break;
570 case OT_INTEGER:
571 set_int(poption, option_int_def(poption));
572 break;
573 case OT_STRING:
574 set_string(poption, option_str_def(poption));
575 break;
576 case OT_ENUM:
577 set_enum(poption, option_enum_def_int(poption));
578 break;
579 case OT_BITWISE:
580 set_bitwise(poption, option_bitwise_def(poption));
581 break;
582 case OT_FONT:
583 set_font(poption, option_font_def(poption));
584 break;
585 case OT_COLOR:
586 set_color(poption, option_color_def(poption));
587 break;
588 case OT_VIDEO_MODE:
589 log_error("Option type %s (%d) not supported yet.",
590 option_type_name(option_type(poption)), option_type(poption));
591 break;
592 }
593}
594
595/************************************************************************/
598 void option_dialog::fill(const struct option_set *poptset)
599{
600 options_iterate(poptset, poption) {
601 add_option(poption);
602 } options_iterate_end;
603}
604
605/************************************************************************/
608 void option_dialog::add_option(struct option *poption)
609{
610 QWidget *widget;
611 QWidget *lwidget;
612 QWidget *twidget;
613 QString category_name, description, qstr;
614 QStringList qlist, qlist2;
615 const char *str;
616 const struct strvec *values;
617 QVBoxLayout *twidget_layout;
618 QHBoxLayout *hbox_layout;
619 QVBoxLayout *vbox_layout;
620 QLabel *label;
621 QScrollArea *scroll;
622 QSpinBox *spin;
623 QComboBox *combo;
624 QLineEdit *edit;
625 QGroupBox *group;
626 QCheckBox *check;
627 QPushButton *button;
628 QFont qf;
629 QPalette pal;
630 int min, max, i;
631 unsigned int j;
632 struct ft_color ft_color;
633 QColor c;
634
635 category_name = option_category_name(poption);
636 widget = nullptr;
637
638 if (!categories.contains(category_name)) {
639 twidget = new QWidget();
640 twidget->setProperty("doomed", true);
641 scroll = new QScrollArea();
642 scroll->setProperty("doomed", true);
643 scroll->setWidgetResizable(true);
644 twidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
645 twidget_layout = new QVBoxLayout();
646 twidget_layout->setSpacing(0);
647 twidget->setLayout(twidget_layout);
648 scroll->setWidget(twidget);
649 tab_widget->addTab(scroll, category_name);
650 categories.append(category_name);
651 widget_map[category_name] = twidget;
652 } else {
653 twidget = widget_map[category_name];
654 }
655
656 description = option_description(poption);
657 switch (option_type(poption)) {
658 case OT_BOOLEAN:
659 widget = new QCheckBox();
660 break;
661
662 case OT_INTEGER:
663 min = option_int_min(poption);
664 max = option_int_max(poption);
665 spin = new QSpinBox();
666 spin->setMinimum(min);
667 spin->setMaximum(max);
668 spin->setSingleStep(MAX((max - min) / 50, 1));
669 widget = spin;
670 break;
671
672 case OT_STRING:
673 values = option_str_values(poption);
674 if (values != nullptr) {
675 combo = new QComboBox();
676 strvec_iterate(values, value) {
677 combo->addItem(value);
678 } strvec_iterate_end;
679 widget = combo;
680 } else {
681 edit = new QLineEdit();
682 widget = edit;
683 }
684 break;
685
686 case OT_ENUM:
687 combo = new QComboBox();
688
689 for (i = 0; (str = option_enum_int_to_str(poption, i)); i++) {
690 // We store enum value in QVariant
691 combo->addItem(_(str), i);
692 }
693 widget = combo;
694 break;
695
696 case OT_BITWISE:
697 group = new QGroupBox();
698 values = option_bitwise_values(poption);
699 vbox_layout = new QVBoxLayout();
700 for (j = 0; j < strvec_size(values); j++) {
701 check = new QCheckBox(_(strvec_get(values, j)));
702 vbox_layout->addWidget(check);
703 }
704 group->setLayout(vbox_layout);
705 widget = group;
706 break;
707
708 case OT_FONT:
709 button = new QPushButton();
710 qf = get_font(poption);
711 qstr = option_font_get(poption);
712 qstr = qf.toString();
713 qlist = qstr.split(",");
714 button->setFont(qf);
715 button->setText(qlist[0] + " " + qlist[1]);
716 connect(button, SIGNAL(clicked()), this, SLOT(select_font()));
717 widget = button;
718 break;
719
720 case OT_COLOR:
721 ft_color = option_color_get(poption);
722 button = new QPushButton();
723 button->setToolTip(_("Select the text color"));
724 button->setObjectName("text_color");
725 button->setAutoFillBackground(true);
726 button->setAutoDefault(false);
727#ifdef FC_QT6X_MODE
728 c = QColor::fromString(ft_color.foreground);
729#else // FC_QT6X_MODE
730 c.setNamedColor(ft_color.foreground);
731#endif // FC_QT6X_MODE
732 pal = button->palette();
733 pal.setColor(QPalette::Button, c);
734 button->setPalette(pal);
735 connect(button, SIGNAL(clicked()), this, SLOT(select_color()));
736 hbox_layout = new QHBoxLayout();
737 hbox_layout->addWidget(button);
738 button = new QPushButton();
739 button->setToolTip(_("Select the background color"));
740 button->setObjectName("text_background");
741 button->setAutoFillBackground(true);
742 button->setAutoDefault(false);
743#ifdef FC_QT6X_MODE
744 c = QColor::fromString(ft_color.background);
745#else // FC_QT6X_MODE
746 c.setNamedColor(ft_color.background);
747#endif // FC_QT6X_MODE
748 pal = button->palette();
749 pal.setColor(QPalette::Button, c);
750 button->setPalette(pal);
751 connect(button, SIGNAL(clicked()), this, SLOT(select_color()));
752 hbox_layout->addWidget(button);
753 widget = new QWidget();
754 widget->setObjectName(option_name(poption));
755 widget->setLayout(hbox_layout);
756 break;
757
758 case OT_VIDEO_MODE:
759 log_error("Option type %s (%d) not supported yet.",
760 option_type_name(option_type(poption)), option_type(poption));
761 break;
762 }
763
764 if (widget != nullptr) {
765 hbox_layout = new QHBoxLayout();
766 hbox_layout->setAlignment(Qt::AlignRight);
767 label = new QLabel(description);
768 label->setToolTip(split_text(option_help_text(poption), false));
769 hbox_layout->addWidget(label, 1, Qt::AlignLeft);
770 hbox_layout->addStretch();
771 hbox_layout->addWidget(widget, 1, Qt::AlignRight);
772 lwidget = new QWidget();
773 lwidget->setLayout(hbox_layout);
774 twidget_layout = qobject_cast < QVBoxLayout * >(twidget->layout());
775 twidget_layout->addWidget(lwidget);
776
777 widget->setEnabled(option_is_changeable(poption));
778 widget->setToolTip(split_text(option_help_text(poption), false));
779 }
780
781 option_set_gui_data(poption, widget); // May set nullptr as the gui_data
782 option_dialog_refresh(poption);
783}
784
785/************************************************************************/
788 void option_dialog_popup(QString name, const struct option_set *poptset,
789 bool client_set)
790{
791 option_dialog *opt_dialog;
792
793 if (::dialog_list.contains(poptset)) {
794 opt_dialog = dialog_list[poptset];
795 opt_dialog->reactivate();
796 opt_dialog->show();
797 } else {
798 opt_dialog = new option_dialog(name, poptset, client_set,
799 gui()->central_wdg);
800 ::dialog_list.insert(poptset, opt_dialog);
801 opt_dialog->show();
802 }
803}
804
805/************************************************************************/
808 void option_dialog::select_font()
809{
810 QStringList ql;
811 bool ok;
812 QFont qf;
813 QPushButton *pb;
814
815 pb = (QPushButton *) QObject::sender();
816 qf = pb->font();
817 qf = QFontDialog::getFont(&ok, qf, this,
818 _("Select Font"));
819 pb->setFont(qf);
820 ql = qf.toString().split(",");
821 pb->setText(ql[0] + " " + ql[1]);
822 raise();
823}
824
825/************************************************************************/
828 QFont option_dialog::get_font(struct option *poption)
829{
830 QFont f;
831 QString s;
832
833 s = option_font_get(poption);
834 f.fromString(s);
835 return f;
836}
837
838/************************************************************************/
841 QByteArray option_dialog::get_button_font(struct option *poption)
842{
843 QPushButton *qp;
844 QFont f;
845
846 qp = reinterpret_cast<QPushButton *>(option_get_gui_data(poption));
847 f = qp->font();
848 return f.toString().toUtf8();
849}
850
851/************************************************************************/
854 void option_dialog::select_color()
855{
856 QPushButton *but;
857 QColor color;
858 QPalette pal;
859
860 but = qobject_cast<QPushButton *>(QObject::sender());
861
862 pal = but->palette();
863 color = QColorDialog::getColor(pal.color(QPalette::Button), this,
864 _("Select Color"));
865 if (color.isValid()) {
866 pal.setColor(QPalette::Button, color);
867 but->setPalette(pal);
868
869 set_button_color(but, color.name().toUtf8());
870 }
871
872 raise();
873}
874
875/************************************************************************/
878 void option_dialog::showEvent(QShowEvent *event)
879{
880 if (client_settings) {
881 if (!gui()->qt_settings.options_client_geometry.isNull()) {
882 restoreGeometry(gui()->qt_settings.options_client_geometry);
883 }
884 } else {
885 if (!gui()->qt_settings.options_server_geometry.isNull()) {
886 restoreGeometry(gui()->qt_settings.options_server_geometry);
887 }
888 }
889}
890
891/************************************************************************/
894 void option_dialog::hideEvent(QHideEvent *event)
895{
896 if (client_settings) {
897 gui()->qt_settings.options_client_geometry = saveGeometry();
898 } else {
899 gui()->qt_settings.options_server_geometry = saveGeometry();
900 }
901}
902
903/************************************************************************/
906 void option_dialog::closeEvent(QCloseEvent *event)
907{
908 if (client_settings) {
909 gui()->qt_settings.options_client_geometry = saveGeometry();
910 } else {
911 gui()->qt_settings.options_server_geometry = saveGeometry();
912 }
913}
914
915/************************************************************************/
918 void option_dialog_popdown(const struct option_set *poptset)
919{
920 option_dialog *opt_dialog;
921
922 while (::dialog_list.contains(poptset)) {
923 opt_dialog =::dialog_list[poptset];
924 opt_dialog->close();
925 ::dialog_list.remove(poptset);
926 }
927}
928
929/************************************************************************/
932 void option_gui_update(struct option *poption)
933{
934 option_dialog *dial;
935
936 if (::dialog_list.contains(option_optset(poption))) {
937 dial =::dialog_list[option_optset(poption)];
938 dial->option_dialog_refresh(poption);
939 }
940
941 if (option_optset(poption) == server_optset) {
942 if (strcmp(option_name(poption), "nationset") == 0) {
943 update_nationset_combo();
944 }
945 if (strcmp(option_name(poption), "aifill") == 0) {
946 gui()->pr_options->set_aifill(option_int_get(poption));
947 }
948 }
949}
950
951/************************************************************************/
954 void option_gui_add(struct option *poption)
955{
960}
961
962/************************************************************************/
965 void option_gui_remove(struct option *poption)
966{
971}
str
#define str
Definition astring.c:76
split_text
QString split_text(QString text, bool cut)
Definition optiondlg.cpp:62
qfc_dialog
Definition dialogs.h:74
qfc_dialog::reactivate
void reactivate()
Definition dialogs.cpp:340
client_main.h
incite_cost
char * incite_cost
Definition comments.c:74
update_nationset_combo
void update_nationset_combo()
Definition dialogs.cpp:1273
event
enum event_type event
Definition events.c:81
fc_client.h
_
#define _(String)
Definition fcintl.h:67
ft_color_construct
static struct ft_color ft_color_construct(const char *foreground, const char *background)
Definition featured_text.h:149
dialog_list
static struct dialog_list * dialog_list
Definition citizensinfo.c:92
RESPONSE_SAVE
@ RESPONSE_SAVE
Definition optiondlg.c:66
RESPONSE_APPLY
@ RESPONSE_APPLY
Definition optiondlg.c:63
RESPONSE_CANCEL
@ RESPONSE_CANCEL
Definition optiondlg.c:61
RESPONSE_OK
@ RESPONSE_OK
Definition optiondlg.c:62
RESPONSE_RESET
@ RESPONSE_RESET
Definition optiondlg.c:64
RESPONSE_REFRESH
@ RESPONSE_REFRESH
Definition optiondlg.c:65
edit
#define edit(pedit)
Definition widget_edit.h:34
optiondlg.h
name
const char * name
Definition inputfile.c:127
log.h
log_error
#define log_error(message,...)
Definition log.h:103
gui
static mpgui * gui
Definition mpgui_qt.cpp:52
option_gui_remove
void option_gui_remove(struct option *poption)
Definition optiondlg.cpp:965
option_dialog_popdown
void option_dialog_popdown(const struct option_set *poptset)
Definition optiondlg.cpp:918
split_text
QString split_text(QString text, bool cut)
Definition optiondlg.cpp:62
RESPONSE_SAVE
@ RESPONSE_SAVE
Definition optiondlg.cpp:53
RESPONSE_APPLY
@ RESPONSE_APPLY
Definition optiondlg.cpp:50
RESPONSE_CANCEL
@ RESPONSE_CANCEL
Definition optiondlg.cpp:48
RESPONSE_OK
@ RESPONSE_OK
Definition optiondlg.cpp:49
RESPONSE_RESET
@ RESPONSE_RESET
Definition optiondlg.cpp:51
RESPONSE_REFRESH
@ RESPONSE_REFRESH
Definition optiondlg.cpp:52
option_gui_add
void option_gui_add(struct option *poption)
Definition optiondlg.cpp:954
dialog_list
QMap< const struct option_set *, option_dialog * > dialog_list
Definition optiondlg.cpp:57
option_gui_update
void option_gui_update(struct option *poption)
Definition optiondlg.cpp:932
option_dialog_popup
void option_dialog_popup(QString name, const struct option_set *poptset, bool client_set)
Definition optiondlg.cpp:788
cut_helptext
QString cut_helptext(QString text)
Definition optiondlg.cpp:105
option_str_values
const struct strvec * option_str_values(const struct option *poption)
Definition options.c:950
option_bitwise_def
unsigned option_bitwise_def(const struct option *poption)
Definition options.c:1120
option_int_min
int option_int_min(const struct option *poption)
Definition options.c:891
option_bool_def
bool option_bool_def(const struct option *poption)
Definition options.c:843
option_font_def
const char * option_font_def(const struct option *poption)
Definition options.c:1187
server_optset
const struct option_set * server_optset
Definition options.c:4281
option_description
const char * option_description(const struct option *poption)
Definition options.c:673
option_help_text
const char * option_help_text(const struct option *poption)
Definition options.c:683
option_color_get
struct ft_color option_color_get(const struct option *poption)
Definition options.c:1225
option_enum_get_int
int option_enum_get_int(const struct option *poption)
Definition options.c:1015
option_str_set
bool option_str_set(struct option *poption, const char *str)
Definition options.c:961
option_name
const char * option_name(const struct option *poption)
Definition options.c:663
option_int_get
int option_int_get(const struct option *poption)
Definition options.c:869
option_color_set
bool option_color_set(struct option *poption, struct ft_color color)
Definition options.c:1248
option_bool_set
bool option_bool_set(struct option *poption, bool val)
Definition options.c:854
option_is_changeable
bool option_is_changeable(const struct option *poption)
Definition options.c:724
option_set_gui_data
void option_set_gui_data(struct option *poption, void *data)
Definition options.c:802
option_str_get
const char * option_str_get(const struct option *poption)
Definition options.c:928
option_get_gui_data
void * option_get_gui_data(const struct option *poption)
Definition options.c:812
option_enum_set_int
bool option_enum_set_int(struct option *poption, int val)
Definition options.c:1075
option_bool_get
bool option_bool_get(const struct option *poption)
Definition options.c:832
option_type
enum option_type option_type(const struct option *poption)
Definition options.c:693
option_enum_int_to_str
const char * option_enum_int_to_str(const struct option *poption, int val)
Definition options.c:1000
option_optset
const struct option_set * option_optset(const struct option *poption)
Definition options.c:643
option_str_def
const char * option_str_def(const struct option *poption)
Definition options.c:939
option_int_max
int option_int_max(const struct option *poption)
Definition options.c:902
option_font_set
bool option_font_set(struct option *poption, const char *font)
Definition options.c:1209
options_save
void options_save(option_save_log_callback log_cb)
Definition options.c:6341
option_bitwise_values
const struct strvec * option_bitwise_values(const struct option *poption)
Definition options.c:1148
option_bitwise_set
bool option_bitwise_set(struct option *poption, unsigned val)
Definition options.c:1159
option_font_get
const char * option_font_get(const struct option *poption)
Definition options.c:1176
desired_settable_options_update
void desired_settable_options_update(void)
Definition options.c:5793
option_color_def
struct ft_color option_color_def(const struct option *poption)
Definition options.c:1236
option_bitwise_get
unsigned option_bitwise_get(const struct option *poption)
Definition options.c:1109
option_enum_def_int
int option_enum_def_int(const struct option *poption)
Definition options.c:1039
option_int_set
bool option_int_set(struct option *poption, int val)
Definition options.c:913
option_category_name
const char * option_category_name(const struct option *poption)
Definition options.c:713
option_int_def
int option_int_def(const struct option *poption)
Definition options.c:880
options.h
options_iterate
#define options_iterate(poptset, poption)
Definition options.h:588
options_iterate_end
#define options_iterate_end
Definition options.h:593
MAX
#define MAX(x, y)
Definition shared.h:54
strvec_get
const char * strvec_get(const struct strvec *psv, size_t svindex)
Definition string_vector.c:389
strvec_size
size_t strvec_size(const struct strvec *psv)
Definition string_vector.c:344
string_vector.h
strvec_iterate
#define strvec_iterate(psv, str)
Definition string_vector.h:61
strvec_iterate_end
#define strvec_iterate_end
Definition string_vector.h:68
color
Definition colors.h:21
ft_color
Definition featured_text.h:141
ft_color::background
const char * background
Definition featured_text.h:143
ft_color::foreground
const char * foreground
Definition featured_text.h:142
option_dialog
Definition optiondlg.c:41
option_dialog::get_bitwise
unsigned get_bitwise(struct option *poption)
Definition optiondlg.cpp:453
option_dialog::curr_options
const option_set * curr_options
Definition optiondlg.h:66
option_dialog::select_color
void select_color()
Definition optiondlg.cpp:854
option_dialog::hideEvent
void hideEvent(QHideEvent *event)
Definition optiondlg.cpp:894
option_dialog::tab_widget
QTabWidget * tab_widget
Definition optiondlg.h:48
option_dialog::widget_map
QMap< QString, QWidget * > widget_map
Definition optiondlg.h:51
option_dialog::get_button_font
QByteArray get_button_font(struct option *poption)
Definition optiondlg.cpp:841
option_dialog::get_color
void get_color(struct option *poption, QByteArray &a1, QByteArray &a2)
Definition optiondlg.cpp:235
option_dialog::get_bool
bool get_bool(struct option *poption)
Definition optiondlg.cpp:313
option_dialog::button_box
QDialogButtonBox * button_box
Definition optiondlg.h:49
option_dialog::set_string
void set_string(struct option *poption, const char *string)
Definition optiondlg.cpp:372
option_dialog::set_int
void set_int(struct option *poption, int value)
Definition optiondlg.cpp:328
option_dialog::full_reset
void full_reset()
Definition optiondlg.cpp:554
option_dialog::categories
QList< QString > categories
Definition optiondlg.h:50
option_dialog::showEvent
void showEvent(QShowEvent *event)
Definition optiondlg.cpp:878
option_dialog::get_string
QByteArray get_string(struct option *poption)
Definition optiondlg.cpp:393
option_dialog::~option_dialog
~option_dialog()
Definition optiondlg.cpp:193
option_dialog::get_enum
int get_enum(struct option *poption)
Definition optiondlg.cpp:421
option_dialog::select_font
void select_font()
Definition optiondlg.cpp:808
option_dialog::add_option
void add_option(struct option *poption)
Definition optiondlg.cpp:608
option_dialog::set_bool
void set_bool(struct option *poption, bool value)
Definition optiondlg.cpp:298
option_dialog::set_enum
void set_enum(struct option *poption, int index)
Definition optiondlg.cpp:410
option_dialog::apply_option
void apply_option(int response)
Definition optiondlg.cpp:204
option_dialog::closeEvent
void closeEvent(QCloseEvent *event)
Definition optiondlg.cpp:906
option_dialog::main_layout
QVBoxLayout * main_layout
Definition optiondlg.h:47
option_dialog::apply_options
void apply_options()
Definition optiondlg.cpp:257
option_dialog::full_refresh
void full_refresh()
Definition optiondlg.cpp:544
option_dialog::set_font
void set_font(struct option *poption, QString s)
Definition optiondlg.cpp:341
option_dialog::get_font
QFont get_font(struct option *poption)
Definition optiondlg.cpp:828
option_dialog::poptset
const struct option_set * poptset
Definition optiondlg.c:42
option_dialog::option_dialog_reset
void option_dialog_reset(struct option *poption)
Definition optiondlg.cpp:564
option_dialog::set_color
void set_color(struct option *poption, struct ft_color color)
Definition optiondlg.cpp:494
option_dialog::fill
void fill(const struct option_set *poptset)
Definition optiondlg.cpp:598
option_dialog::option_dialog_refresh
void option_dialog_refresh(struct option *poption)
Definition optiondlg.cpp:510
option_dialog::get_int
int get_int(struct option *poption)
Definition optiondlg.cpp:361
option_dialog::set_button_color
void set_button_color(QPushButton *button, const char *colorname)
Definition optiondlg.cpp:474
option_dialog::set_bitwise
void set_bitwise(struct option *poption, unsigned value)
Definition optiondlg.cpp:432
option_dialog::option_dialog
option_dialog(const QString &name, const option_set *options, bool client_set, QWidget *parent=nullptr)
Definition optiondlg.cpp:127
option_dialog::client_settings
bool client_settings
Definition optiondlg.h:65
option_set
Definition options.c:444
option
Definition options.c:514
strvec
Definition string_vector.c:29
widget
Definition widget.h:112