Freeciv21
Develop your civilization from humble roots to a global empire
optiondlg.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  part of Freeciv21. Freeciv21 is free software: you can redistribute it
4  and/or modify it under the terms of the GNU General Public License as
5  published by the Free Software Foundation, either version 3 of the
6  License, or (at your option) any later version. You should have received
7  a copy of the GNU General Public License along with Freeciv21. If not,
8  see https://www.gnu.org/licenses/.
9  */
10 
11 // Qt
12 #include <QApplication>
13 #include <QCheckBox>
14 #include <QColorDialog>
15 #include <QComboBox>
16 #include <QDialogButtonBox>
17 #include <QFontDialog>
18 #include <QGroupBox>
19 #include <QHBoxLayout>
20 #include <QScrollArea>
21 #include <QSpinBox>
22 // utility
23 #include "log.h"
24 // client
25 #include "fc_client.h"
26 #include "optiondlg.h"
27 #include "options.h"
28 #include "page_pregame.h"
29 
30 enum {
37 };
38 
39 // global value to store pointers to opened config dialogs
40 QHash<const struct option_set *, option_dialog *> dialog_list;
41 
45 QString split_text(const QString &text, bool cut)
46 {
47  QStringList sl;
48  QString st, str, result;
49  int i;
50  int j = 0;
51 
52  sl = text.split(QStringLiteral("\n"));
53  for (const QString &s : qAsConst(sl)) {
54  st = s;
55  while (st.count() >= 80) {
56  str = st.left(80);
57  i = str.lastIndexOf(' ');
58  if (i == -1) {
59  i = 80;
60  }
61  result = result + str.left(i) + '\n';
62  /* Skip last space - at (i + 1)
63  unless there there was no space */
64  if (i != 80) {
65  st.remove(0, i + 1);
66  } else {
67  st.remove(0, i);
68  }
69  }
70  str = st;
71  if (str.left(str.count()) != QLatin1String("")) {
72  result = result + str.left(str.count()) + '\n';
73  }
74  j++;
75  if (j >= 12 && cut) {
76  result = result + _("... read more in help") + "\n";
77  break;
78  }
79  }
80  result.remove(result.lastIndexOf('\n'), 1);
81  return result;
82 }
83 
87 QString cut_helptext(const QString &text)
88 {
89  QStringList sl;
90  QString ret_str;
91 
92  // Remove all lines from help which has '*' in first 3 chars
93  sl = text.split('\n');
94  for (const QString &s : qAsConst(sl)) {
95  if (s.count() > 2) {
96  if (s.at(0) != '*' && s.at(1) != '*' && s.at(2) != '*') {
97  ret_str = ret_str + s + '\n';
98  }
99  } else {
100  ret_str = ret_str + s + '\n';
101  }
102  }
103  return ret_str;
104 }
105 
109 option_dialog::option_dialog(const QString &name, const option_set *options,
110  QWidget *parent)
111  : qfc_dialog(parent)
112 {
113  setWindowFlag(Qt::Tool); // Stays on top without blocking input
114 
115  QPushButton *but;
116 
117  curr_options = options;
118  setWindowTitle(name);
119  tab_widget = new QTabWidget;
120 
121  button_box = new QDialogButtonBox();
122  but = new QPushButton(style()->standardIcon(QStyle::SP_DialogCancelButton),
123  _("Cancel"));
124  button_box->addButton(but, QDialogButtonBox::ActionRole);
125  QObject::connect(but, &QPushButton::clicked,
126  [this]() { apply_option(RESPONSE_CANCEL); });
127 
128  but = new QPushButton(style()->standardIcon(QStyle::SP_DialogResetButton),
129  _("Reset"));
130  button_box->addButton(but, QDialogButtonBox::ResetRole);
131  QObject::connect(but, &QPushButton::clicked,
132  [this]() { apply_option(RESPONSE_RESET); });
133 
134  but = new QPushButton(QIcon::fromTheme(QStringLiteral("view-refresh")),
135  _("Refresh"));
136  button_box->addButton(but, QDialogButtonBox::ActionRole);
137  QObject::connect(but, &QPushButton::clicked,
138  [this]() { apply_option(RESPONSE_REFRESH); });
139 
140  but = new QPushButton(style()->standardIcon(QStyle::SP_DialogApplyButton),
141  _("Apply"));
142  button_box->addButton(but, QDialogButtonBox::ActionRole);
143  QObject::connect(but, &QPushButton::clicked,
144  [this]() { apply_option(RESPONSE_APPLY); });
145 
146  but = new QPushButton(style()->standardIcon(QStyle::SP_DialogSaveButton),
147  _("Save"));
148  button_box->addButton(but, QDialogButtonBox::ActionRole);
149  QObject::connect(but, &QPushButton::clicked,
150  [this]() { apply_option(RESPONSE_SAVE); });
151 
152  but = new QPushButton(style()->standardIcon(QStyle::SP_DialogOkButton),
153  _("Ok"));
154  button_box->addButton(but, QDialogButtonBox::ActionRole);
155  QObject::connect(but, &QPushButton::clicked,
156  [this]() { apply_option(RESPONSE_OK); });
157 
158  main_layout = new QVBoxLayout;
159  main_layout->addWidget(tab_widget);
160  categories.clear();
161  fill(options);
162  main_layout->addWidget(button_box);
163  setLayout(main_layout);
164 
165  resize(800, 700);
166 
167  setAttribute(Qt::WA_DeleteOnClose);
168 }
169 
174 {
175  while (::dialog_list.contains(curr_options)) {
176  ::dialog_list.remove(curr_options);
177  }
178  destroy();
179 }
180 
184 void option_dialog::apply_option(int response)
185 {
186  switch (response) {
187  case RESPONSE_APPLY:
188  apply_options();
189  break;
190  case RESPONSE_CANCEL:
191  ::dialog_list.remove(curr_options);
192  close();
193  break;
194  case RESPONSE_OK:
195  apply_options();
196  ::dialog_list.remove(curr_options);
197  close();
198  break;
199  case RESPONSE_SAVE:
201  options_save(nullptr);
202  break;
203  case RESPONSE_RESET:
204  full_reset();
205  break;
206  case RESPONSE_REFRESH:
207  full_refresh();
208  break;
209  }
210 }
211 
215 void option_dialog::get_color(struct option *poption, QByteArray &a1,
216  QByteArray &a2)
217 {
218  QPalette pal;
219  QColor col1, col2;
220  QWidget *w;
221  QPushButton *but;
222 
223  w = reinterpret_cast<QPushButton *>(option_get_gui_data(poption));
224  but = w->findChild<QPushButton *>(QStringLiteral("text_color"));
225  pal = but->palette();
226  col1 = pal.color(QPalette::Button);
227  but = w->findChild<QPushButton *>(QStringLiteral("text_background"));
228  pal = but->palette();
229  col2 = pal.color(QPalette::Button);
230  a1 = col1.name().toUtf8();
231  a2 = col2.name().toUtf8();
232 }
233 
238 {
239  QByteArray ba1, ba2;
240 
241  options_iterate(curr_options, poption)
242  {
243  switch (option_type(poption)) {
244  case OT_BOOLEAN:
245  option_bool_set(poption, get_bool(poption));
246  break;
247  case OT_INTEGER:
248  option_int_set(poption, get_int(poption));
249  break;
250  case OT_STRING:
251  option_str_set(poption, get_string(poption).constData());
252  break;
253  case OT_ENUM:
254  option_enum_set_int(poption, get_enum(poption));
255  break;
256  case OT_BITWISE:
257  option_bitwise_set(poption, get_bitwise(poption));
258  break;
259  case OT_FONT:
260  option_font_set(poption, get_button_font(poption));
261  break;
262  case OT_COLOR:
263  get_color(poption, ba1, ba2);
264  option_color_set(poption, ft_color_construct(ba1.data(), ba2.data()));
265  break;
266  }
267  }
269 }
270 
274 void option_dialog::set_bool(struct option *poption, bool value)
275 {
276  QCheckBox *c;
277 
278  c = reinterpret_cast<QCheckBox *>(option_get_gui_data(poption));
279  if (value) {
280  c->setCheckState(Qt::Checked);
281  } else {
282  c->setCheckState(Qt::Unchecked);
283  }
284 }
285 
289 bool option_dialog::get_bool(struct option *poption)
290 {
291  QCheckBox *c;
292 
293  c = reinterpret_cast<QCheckBox *>(option_get_gui_data(poption));
294  return c->checkState() == Qt::Checked;
295 }
296 
300 void option_dialog::set_int(struct option *poption, int value)
301 {
302  QSpinBox *s;
303 
304  s = reinterpret_cast<QSpinBox *>(option_get_gui_data(poption));
305  s->setValue(value);
306 }
307 
313 void option_dialog::set_font(struct option *poption, const QFont &font)
314 {
315  qApp->processEvents();
316  auto qp = reinterpret_cast<QPushButton *>(option_get_gui_data(poption));
317  qp->setText(
318  QStringLiteral("%1 %2").arg(font.family()).arg(font.pointSize()));
319  qp->setFont(font);
320 }
321 
325 int option_dialog::get_int(struct option *poption)
326 {
327  QSpinBox *s;
328 
329  s = reinterpret_cast<QSpinBox *>(option_get_gui_data(poption));
330  return s->value();
331 }
332 
336 void option_dialog::set_string(struct option *poption, const char *string)
337 {
338  int i;
339  QComboBox *cb;
340  QLineEdit *le;
341 
342  if (option_str_values(poption) != nullptr) {
343  cb = reinterpret_cast<QComboBox *>(option_get_gui_data(poption));
344  i = cb->findText(string);
345  if (i != -1) {
346  cb->setCurrentIndex(i);
347  }
348  } else {
349  le = reinterpret_cast<QLineEdit *>(option_get_gui_data(poption));
350  le->setText(string);
351  }
352 }
353 
357 QByteArray option_dialog::get_string(struct option *poption)
358 {
359  QComboBox *cb;
360  QLineEdit *le;
361 
362  if (option_str_values(poption) != nullptr) {
363  cb = reinterpret_cast<QComboBox *>(option_get_gui_data(poption));
364  return cb->currentText().toUtf8();
365  } else {
366  le = reinterpret_cast<QLineEdit *>(option_get_gui_data(poption));
367  return le->displayText().toUtf8();
368  }
369 }
370 
374 void option_dialog::set_enum(struct option *poption, int index)
375 {
376  QComboBox *cb;
377 
378  cb = reinterpret_cast<QComboBox *>(option_get_gui_data(poption));
379  cb->setCurrentIndex(index);
380 }
381 
385 int option_dialog::get_enum(struct option *poption)
386 {
387  QComboBox *cb;
388 
389  cb = reinterpret_cast<QComboBox *>(option_get_gui_data(poption));
390  return cb->currentIndex();
391 }
392 
396 void option_dialog::set_bitwise(struct option *poption, unsigned int value)
397 {
398  QGroupBox *gb;
399  int i;
400  QList<QCheckBox *> check_buttons;
401 
402  gb = reinterpret_cast<QGroupBox *>(option_get_gui_data(poption));
403  check_buttons = gb->findChildren<QCheckBox *>();
404 
405  for (i = 0; i < check_buttons.count(); i++) {
406  if (value & (1 << i)) {
407  check_buttons[i]->setCheckState(Qt::Checked);
408  } else {
409  check_buttons[i]->setCheckState(Qt::Unchecked);
410  }
411  }
412 }
413 
417 unsigned int option_dialog::get_bitwise(struct option *poption)
418 {
419  QGroupBox *gb;
420  int i;
421  unsigned int value = 0;
422  QList<QCheckBox *> check_buttons;
423 
424  gb = reinterpret_cast<QGroupBox *>(option_get_gui_data(poption));
425  check_buttons = gb->findChildren<QCheckBox *>();
426 
427  for (i = 0; i < check_buttons.count(); i++) {
428  if (check_buttons[i]->checkState() == Qt::Checked) {
429  value |= 1 << i;
430  }
431  }
432  return value;
433 }
434 
439 {
440  options_iterate(curr_options, poption)
441  {
442  if (option_type(poption) == OT_COLOR) {
443  return poption;
444  }
445  }
447  return nullptr;
448 }
449 
453 void option_dialog::set_color(struct option *poption, struct ft_color color)
454 {
455  QColor col;
456  QWidget *w;
457  QPushButton *but;
458  QString s1 = QStringLiteral("QPushButton { background-color: ");
459  QString s2 = QStringLiteral(";}");
460 
461  w = reinterpret_cast<QPushButton *>(option_get_gui_data(poption));
462  but = w->findChild<QPushButton *>(QStringLiteral("text_color"));
463  if (nullptr != but && nullptr != color.foreground
464  && '\0' != color.foreground[0]) {
465  col.setNamedColor(color.foreground);
466  but->setStyleSheet(s1 + col.name() + s2);
467  }
468  but = w->findChild<QPushButton *>(QStringLiteral("text_background"));
469  if (nullptr != but && nullptr != color.background
470  && '\0' != color.background[0]) {
471  col.setNamedColor(color.background);
472  but->setStyleSheet(s1 + col.name() + s2);
473  }
474 }
475 
480 {
481  switch (option_type(poption)) {
482  case OT_BOOLEAN:
483  set_bool(poption, option_bool_get(poption));
484  break;
485  case OT_INTEGER:
486  set_int(poption, option_int_get(poption));
487  break;
488  case OT_STRING:
489  set_string(poption, option_str_get(poption));
490  break;
491  case OT_ENUM:
492  set_enum(poption, option_enum_get_int(poption));
493  break;
494  case OT_BITWISE:
495  set_bitwise(poption, option_bitwise_get(poption));
496  break;
497  case OT_FONT:
498  set_font(poption, option_font_get(poption));
499  break;
500  case OT_COLOR:
501  set_color(poption, option_color_get(poption));
502  break;
503  }
504 }
505 
510 {
511  options_iterate(curr_options, poption) { option_dialog_refresh(poption); }
513 }
514 
519 {
520  options_iterate(curr_options, poption) { option_dialog_reset(poption); }
522 }
523 
528 {
529  switch (option_type(poption)) {
530  case OT_BOOLEAN:
531  set_bool(poption, option_bool_def(poption));
532  break;
533  case OT_INTEGER:
534  set_int(poption, option_int_def(poption));
535  break;
536  case OT_STRING:
537  set_string(poption, option_str_def(poption));
538  break;
539  case OT_ENUM:
540  set_enum(poption, option_enum_def_int(poption));
541  break;
542  case OT_BITWISE:
543  set_bitwise(poption, option_bitwise_def(poption));
544  break;
545  case OT_FONT:
546  set_font(poption, option_font_def(poption));
547  break;
548  case OT_COLOR:
549  set_color(poption, option_color_def(poption));
550  break;
551  }
552 }
553 
558 {
559  options_iterate(poptset, poption) { add_option(poption); }
561 }
562 
566 void option_dialog::add_option(struct option *poption)
567 {
568  QWidget *widget;
569  QWidget *lwidget;
570  QWidget *twidget;
571  QString category_name, description, qstr;
572  const QVector<QString> *values;
573  QVBoxLayout *twidget_layout;
574  QHBoxLayout *hbox_layout;
575  QVBoxLayout *vbox_layout;
576  QLabel *label;
577  QScrollArea *scroll;
578  QSpinBox *spin;
579  QComboBox *combo;
580  QLineEdit *edit;
581  QGroupBox *group;
582  QCheckBox *check;
583  QPushButton *button;
584  int min, max, i;
585  unsigned int j;
586 
587  category_name = option_category_name(poption);
588  widget = nullptr;
589 
590  if (!categories.contains(category_name)) {
591  twidget = new QWidget();
592  twidget->setProperty("doomed", true);
593  scroll = new QScrollArea();
594  scroll->setProperty("doomed", true);
595  scroll->setWidgetResizable(true);
596  twidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
597  twidget_layout = new QVBoxLayout();
598  twidget_layout->setSpacing(0);
599  twidget->setLayout(twidget_layout);
600  scroll->setWidget(twidget);
601  tab_widget->addTab(scroll, category_name);
602  categories.append(category_name);
603  widget_map[category_name] = twidget;
604  } else {
605  twidget = widget_map[category_name];
606  }
607 
608  description = option_description(poption);
609  switch (option_type(poption)) {
610  case OT_BOOLEAN:
611  widget = new QCheckBox();
612  break;
613 
614  case OT_INTEGER:
615  min = option_int_min(poption);
616  max = option_int_max(poption);
617  spin = new QSpinBox();
618  spin->setMinimum(min);
619  spin->setMaximum(max);
620  spin->setSingleStep(MAX((max - min) / 50, 1));
621  widget = spin;
622  break;
623 
624  case OT_STRING:
625  values = option_str_values(poption);
626  if (nullptr != values) {
627  combo = new QComboBox();
628  for (const auto &value : *values) {
629  combo->addItem(value);
630  }
631  widget = combo;
632  } else {
633  edit = new QLineEdit();
634  widget = edit;
635  }
636  break;
637 
638  case OT_ENUM:
639  combo = new QComboBox();
640  i = 0;
641  while (true) {
642  QString s = option_enum_int_to_str(poption, i);
643  if (s.isEmpty()) {
644  break;
645  }
646  // we store enum value in QVariant
647  combo->addItem(_(qUtf8Printable(s)), i);
648  i++;
649  }
650  widget = combo;
651  break;
652 
653  case OT_BITWISE:
654  group = new QGroupBox();
655  values = option_bitwise_values(poption);
656  vbox_layout = new QVBoxLayout();
657  for (j = 0; j < values->count(); j++) {
658  check = new QCheckBox(_(qUtf8Printable(values->at(j))));
659  vbox_layout->addWidget(check);
660  }
661  group->setLayout(vbox_layout);
662  widget = group;
663  break;
664 
665  case OT_FONT: {
666  button = new QPushButton();
667  auto font = option_font_get(poption);
668  button->setFont(font);
669  button->setText(
670  QStringLiteral("%1 %2").arg(font.family()).arg(font.pointSize()));
671  connect(button, &QAbstractButton::clicked, this,
672  QOverload<>::of(&option_dialog::set_font));
673  widget = button;
674  } break;
675 
676  case OT_COLOR:
677  button = new QPushButton();
678  button->setToolTip(_("Select the text color"));
679  button->setObjectName(QStringLiteral("text_color"));
680  button->setAutoFillBackground(true);
681  button->setAutoDefault(false);
682  connect(button, &QAbstractButton::clicked, this,
683  QOverload<>::of(&option_dialog::set_color));
684  hbox_layout = new QHBoxLayout();
685  hbox_layout->addWidget(button);
686  button = new QPushButton();
687  button->setToolTip(_("Select the background color"));
688  button->setObjectName(QStringLiteral("text_background"));
689  button->setAutoFillBackground(true);
690  button->setAutoDefault(false);
691  connect(button, &QAbstractButton::clicked, this,
692  QOverload<>::of(&option_dialog::set_color));
693  hbox_layout->addWidget(button);
694  widget = new QWidget();
695  widget->setLayout(hbox_layout);
696  break;
697  }
698 
699  if (widget != nullptr) {
700  hbox_layout = new QHBoxLayout();
701  hbox_layout->setAlignment(Qt::AlignRight);
702  label = new QLabel(description);
703  label->setToolTip(split_text(option_help_text(poption), false));
704  hbox_layout->addWidget(label, 1, Qt::AlignLeft);
705  hbox_layout->addStretch();
706  hbox_layout->addWidget(widget, 1, Qt::AlignRight);
707  lwidget = new QWidget();
708  lwidget->setLayout(hbox_layout);
709  twidget_layout = qobject_cast<QVBoxLayout *>(twidget->layout());
710  twidget_layout->addWidget(lwidget);
711  }
712 
713  widget->setEnabled(option_is_changeable(poption));
714  widget->setToolTip(split_text(option_help_text(poption), false));
715  option_set_gui_data(poption, widget);
716  option_dialog_refresh(poption);
717 }
718 
722 void option_dialog_popup(const char *name, const struct option_set *poptset)
723 {
724  option_dialog *opt_dialog;
725 
726  if (::dialog_list.contains(poptset)) {
727  opt_dialog = dialog_list[poptset];
728  opt_dialog->show();
729  } else {
730  opt_dialog = new option_dialog(name, poptset, king()->central_wdg);
731  ::dialog_list.insert(poptset, opt_dialog);
732  opt_dialog->show();
733  }
734 }
735 
740 {
741  QStringList ql;
742  bool ok;
743  QFont qf;
744  QPushButton *pb;
745 
746  pb = (QPushButton *) QObject::sender();
747  qf = pb->font();
748  qf = QFontDialog::getFont(&ok, qf, this);
749  pb->setFont(qf);
750  ql = qf.toString().split(QStringLiteral(","));
751  pb->setText(ql[0] + " " + ql[1]);
752 }
753 
758 {
759  return reinterpret_cast<QPushButton *>(option_get_gui_data(poption))
760  ->font();
761 }
762 
767 {
768  QPushButton *but;
769  QColor color, c;
770  struct option *color_option;
771  struct ft_color ft_color;
772  QPalette pal;
773 
774  color_option = get_color_option();
775  ft_color = option_color_get(color_option);
776  but = qobject_cast<QPushButton *>(QObject::sender());
777 
778  if (but->objectName() == QLatin1String("text_color")) {
779  c.setNamedColor(ft_color.foreground);
780  color = QColorDialog::getColor(c, this);
781  if (color.isValid()) {
782  pal.setColor(QPalette::Button, color);
783  but->setPalette(pal);
784  }
785  } else if (but->objectName() == QLatin1String("text_background")) {
786  c.setNamedColor(ft_color.background);
787  color = QColorDialog::getColor(c, this);
788  if (color.isValid()) {
789  pal.setColor(QPalette::Button, color);
790  but->setPalette(pal);
791  }
792  }
793 }
794 
798 void option_dialog_popdown(const struct option_set *poptset)
799 {
800  option_dialog *opt_dialog;
801 
802  while (::dialog_list.contains(poptset)) {
803  opt_dialog = ::dialog_list[poptset];
804  opt_dialog->close();
805  ::dialog_list.remove(poptset);
806  }
807 }
808 
812 void option_gui_update(struct option *poption)
813 {
814  option_dialog *dial;
815 
816  if (::dialog_list.contains(option_optset(poption))) {
817  dial = ::dialog_list[option_optset(poption)];
818  dial->option_dialog_refresh(poption);
819  }
820 
821  if (option_optset(poption) == server_optset) {
822  if (strcmp(option_name(poption), "nationset") == 0) {
824  }
825  if (strcmp(option_name(poption), "aifill") == 0) {
826  // sveinung
827  // qobject_cast<page_pregame
828  // *>(king()->pages[PAGE_START])->pr_options->set_aifill(option_int_get(poption));
829  }
830  }
831 }
unsigned get_bitwise(struct option *poption)
Return the enum value from groupbox.
Definition: optiondlg.cpp:417
const option_set * curr_options
Definition: optiondlg.h:47
struct option * get_color_option()
Find option indicating colors.
Definition: optiondlg.cpp:438
QTabWidget * tab_widget
Definition: optiondlg.h:30
QMap< QString, QWidget * > widget_map
Definition: optiondlg.h:33
void set_font()
Sets font and text in pushbutton (user just chosen font)
Definition: optiondlg.cpp:739
void get_color(struct option *poption, QByteArray &a1, QByteArray &a2)
Return selected colors (for highlighting chat).
Definition: optiondlg.cpp:215
bool get_bool(struct option *poption)
Get the boolean value from checkbox.
Definition: optiondlg.cpp:289
QDialogButtonBox * button_box
Definition: optiondlg.h:31
void set_string(struct option *poption, const char *string)
Set the string value of the option.
Definition: optiondlg.cpp:336
void set_int(struct option *poption, int value)
Set the integer value of the option.
Definition: optiondlg.cpp:300
void full_reset()
Reset all options.
Definition: optiondlg.cpp:518
~option_dialog() override
Destructor for options dialog.
Definition: optiondlg.cpp:173
QList< QString > categories
Definition: optiondlg.h:32
QByteArray get_string(struct option *poption)
Get string for desired option from combobox or lineedit.
Definition: optiondlg.cpp:357
int get_enum(struct option *poption)
Get indexed value from combobox.
Definition: optiondlg.cpp:385
void add_option(struct option *poption)
Create widget for option.
Definition: optiondlg.cpp:566
void set_bool(struct option *poption, bool value)
Set the boolean value of the option.
Definition: optiondlg.cpp:274
void set_enum(struct option *poption, int index)
Set desired index(text) in combobox.
Definition: optiondlg.cpp:374
void apply_option(int response)
Apply desired action depending on user's request (clicked button).
Definition: optiondlg.cpp:184
QVBoxLayout * main_layout
Definition: optiondlg.h:29
void apply_options()
Apply all options.
Definition: optiondlg.cpp:237
option_dialog(const QString &name, const option_set *options, QWidget *parent=0)
Constructor for options dialog.
Definition: optiondlg.cpp:109
void full_refresh()
Refresh all options.
Definition: optiondlg.cpp:509
QFont get_button_font(struct option *poption)
Get font from pushbutton.
Definition: optiondlg.cpp:757
void option_dialog_reset(struct option *poption)
Reset one option.
Definition: optiondlg.cpp:527
void fill(const struct option_set *poptset)
Create all widgets.
Definition: optiondlg.cpp:557
void option_dialog_refresh(struct option *poption)
Refresh one given option for option dialog.
Definition: optiondlg.cpp:479
int get_int(struct option *poption)
Get int value from spinbox.
Definition: optiondlg.cpp:325
void set_bitwise(struct option *poption, unsigned value)
Set the enum value of the option.
Definition: optiondlg.cpp:396
void set_color()
Set color of buttons (user just changed colors).
Definition: optiondlg.cpp:766
void update_nationset_combo()
Updates nationset combobox.
Definition: dialogs.cpp:1039
class fc_client * king()
Return fc_client instance.
Definition: gui_main.cpp:58
#define _(String)
Definition: fcintl.h:50
static struct ft_color ft_color_construct(const char *foreground, const char *background)
const char * name
Definition: inputfile.cpp:118
void option_dialog_popdown(const struct option_set *poptset)
Popdown the option dialog for the option set.
Definition: optiondlg.cpp:798
@ RESPONSE_SAVE
Definition: optiondlg.cpp:36
@ RESPONSE_APPLY
Definition: optiondlg.cpp:33
@ RESPONSE_CANCEL
Definition: optiondlg.cpp:31
@ RESPONSE_OK
Definition: optiondlg.cpp:32
@ RESPONSE_RESET
Definition: optiondlg.cpp:34
@ RESPONSE_REFRESH
Definition: optiondlg.cpp:35
QString cut_helptext(const QString &text)
Remove some text from given text(help text) to show as tooltip.
Definition: optiondlg.cpp:87
QString split_text(const QString &text, bool cut)
Splits long text to 80 characters.
Definition: optiondlg.cpp:45
void option_gui_update(struct option *poption)
Update the GUI for the option.
Definition: optiondlg.cpp:812
QHash< const struct option_set *, option_dialog * > dialog_list
Definition: optiondlg.cpp:40
void option_dialog_popup(const char *name, const struct option_set *poptset)
Popup the option dialog for the option set.
Definition: optiondlg.cpp:722
void desired_settable_options_update()
Update the desired settable options hash table from the current setting configuration.
Definition: options.cpp:4064
const char * option_str_def(const struct option *poption)
Returns the default value of this string option.
Definition: options.cpp:564
unsigned option_bitwise_def(const struct option *poption)
Returns the default value of this bitwise option.
Definition: options.cpp:693
int option_int_min(const struct option *poption)
Returns the minimal value of this integer option.
Definition: options.cpp:516
bool option_bool_def(const struct option *poption)
Returns the default value of this boolean option.
Definition: options.cpp:468
const char * option_name(const struct option *poption)
Returns the name of the option.
Definition: options.cpp:300
const struct option_set * server_optset
Definition: options.cpp:2430
const char * option_str_get(const struct option *poption)
Returns the current value of this string option.
Definition: options.cpp:553
const QVector< QString > * option_str_values(const struct option *poption)
Returns the possible string values of this string option.
Definition: options.cpp:575
struct ft_color option_color_get(const struct option *poption)
Returns the current value of this color option.
Definition: options.cpp:808
int option_enum_get_int(const struct option *poption)
Returns the current value of this enum option (as an integer).
Definition: options.cpp:645
bool option_str_set(struct option *poption, const char *str)
Sets the value of this string option.
Definition: options.cpp:586
int option_int_get(const struct option *poption)
Returns the current value of this integer option.
Definition: options.cpp:494
bool option_font_set(struct option *poption, const QFont &font)
Sets the value of this font option.
Definition: options.cpp:793
bool option_color_set(struct option *poption, struct ft_color color)
Sets the value of this color option.
Definition: options.cpp:835
QString option_enum_int_to_str(const struct option *poption, int val)
Returns the user-visible (translatable but not translated) string corresponding to the value.
Definition: options.cpp:626
const QVector< QString > * option_bitwise_values(const struct option *poption)
Returns a vector of strings describing every bit of this option, as user-visible (translatable but no...
Definition: options.cpp:721
bool option_bool_set(struct option *poption, bool val)
Sets the value of this boolean option.
Definition: options.cpp:479
bool option_is_changeable(const struct option *poption)
Returns TRUE if this option can be modified.
Definition: options.cpp:351
void option_set_gui_data(struct option *poption, void *data)
Set the gui data for this option.
Definition: options.cpp:427
const char * option_description(const struct option *poption)
Returns the description (translated) of the option.
Definition: options.cpp:310
bool option_enum_set_int(struct option *poption, int val)
Sets the value of this enum option.
Definition: options.cpp:667
bool option_bool_get(const struct option *poption)
Returns the current value of this boolean option.
Definition: options.cpp:457
enum option_type option_type(const struct option *poption)
Returns the type of the option.
Definition: options.cpp:330
int option_int_max(const struct option *poption)
Returns the maximal value of this integer option.
Definition: options.cpp:527
QString option_category_name(const struct option *poption)
Returns the name (translated) of the category of the option.
Definition: options.cpp:340
void * option_get_gui_data(const struct option *poption)
Returns the gui data of this option.
Definition: options.cpp:437
void options_save(option_save_log_callback log_cb)
Save all options.
Definition: options.cpp:4496
QFont option_font_get(const struct option *poption)
Returns the current value of this font option.
Definition: options.cpp:749
bool option_bitwise_set(struct option *poption, unsigned val)
Sets the value of this bitwise option.
Definition: options.cpp:732
QString option_help_text(const struct option *poption)
Returns the help text (translated) of the option.
Definition: options.cpp:320
struct ft_color option_color_def(const struct option *poption)
Returns the default value of this color option.
Definition: options.cpp:821
unsigned option_bitwise_get(const struct option *poption)
Returns the current value of this bitwise option.
Definition: options.cpp:682
int option_enum_def_int(const struct option *poption)
Returns the default value of this enum option (as an integer).
Definition: options.cpp:656
bool option_int_set(struct option *poption, int val)
Sets the value of this integer option.
Definition: options.cpp:538
QFont option_font_def(const struct option *poption)
Returns the default value of this font option.
Definition: options.cpp:760
const struct option_set * option_optset(const struct option *poption)
Returns the option set owner of this option.
Definition: options.cpp:280
int option_int_def(const struct option *poption)
Returns the default value of this integer option.
Definition: options.cpp:505
#define options_iterate(poptset, poption)
Definition: options.h:292
#define options_iterate_end
Definition: options.h:297
#define MAX(x, y)
Definition: shared.h:48
const char * background
const char * foreground
Option set structure.
Definition: options.cpp:88
The base class for options.
Definition: options.cpp:209
const struct option_set * poptset
Definition: options.cpp:211