12 #include <QApplication>
14 #include <QColorDialog>
16 #include <QDialogButtonBox>
17 #include <QFontDialog>
19 #include <QHBoxLayout>
20 #include <QScrollArea>
40 QHash<const struct option_set *, option_dialog *>
dialog_list;
48 QString st, str, result;
52 sl = text.split(QStringLiteral(
"\n"));
53 for (
const QString &s : qAsConst(sl)) {
55 while (st.count() >= 80) {
57 i = str.lastIndexOf(
' ');
61 result = result + str.left(i) +
'\n';
71 if (str.left(str.count()) != QLatin1String(
"")) {
72 result = result + str.left(str.count()) +
'\n';
76 result = result +
_(
"... read more in help") +
"\n";
80 result.remove(result.lastIndexOf(
'\n'), 1);
93 sl = text.split(
'\n');
94 for (
const QString &s : qAsConst(sl)) {
96 if (s.at(0) !=
'*' && s.at(1) !=
'*' && s.at(2) !=
'*') {
97 ret_str = ret_str + s +
'\n';
100 ret_str = ret_str + s +
'\n';
113 setWindowFlag(Qt::Tool);
118 setWindowTitle(
name);
122 but =
new QPushButton(style()->standardIcon(QStyle::SP_DialogCancelButton),
124 button_box->addButton(but, QDialogButtonBox::ActionRole);
125 QObject::connect(but, &QPushButton::clicked,
128 but =
new QPushButton(style()->standardIcon(QStyle::SP_DialogResetButton),
130 button_box->addButton(but, QDialogButtonBox::ResetRole);
131 QObject::connect(but, &QPushButton::clicked,
134 but =
new QPushButton(QIcon::fromTheme(QStringLiteral(
"view-refresh")),
136 button_box->addButton(but, QDialogButtonBox::ActionRole);
137 QObject::connect(but, &QPushButton::clicked,
140 but =
new QPushButton(style()->standardIcon(QStyle::SP_DialogApplyButton),
142 button_box->addButton(but, QDialogButtonBox::ActionRole);
143 QObject::connect(but, &QPushButton::clicked,
146 but =
new QPushButton(style()->standardIcon(QStyle::SP_DialogSaveButton),
148 button_box->addButton(but, QDialogButtonBox::ActionRole);
149 QObject::connect(but, &QPushButton::clicked,
152 but =
new QPushButton(style()->standardIcon(QStyle::SP_DialogOkButton),
154 button_box->addButton(but, QDialogButtonBox::ActionRole);
155 QObject::connect(but, &QPushButton::clicked,
167 setAttribute(Qt::WA_DeleteOnClose);
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();
280 c->setCheckState(Qt::Checked);
282 c->setCheckState(Qt::Unchecked);
294 return c->checkState() == Qt::Checked;
315 qApp->processEvents();
318 QStringLiteral(
"%1 %2").arg(font.family()).arg(font.pointSize()));
344 i = cb->findText(
string);
346 cb->setCurrentIndex(i);
364 return cb->currentText().toUtf8();
367 return le->displayText().toUtf8();
379 cb->setCurrentIndex(index);
390 return cb->currentIndex();
400 QList<QCheckBox *> check_buttons;
403 check_buttons = gb->findChildren<QCheckBox *>();
405 for (i = 0; i < check_buttons.count(); i++) {
406 if (value & (1 << i)) {
407 check_buttons[i]->setCheckState(Qt::Checked);
409 check_buttons[i]->setCheckState(Qt::Unchecked);
421 unsigned int value = 0;
422 QList<QCheckBox *> check_buttons;
425 check_buttons = gb->findChildren<QCheckBox *>();
427 for (i = 0; i < check_buttons.count(); i++) {
428 if (check_buttons[i]->checkState() == Qt::Checked) {
458 QString s1 = QStringLiteral(
"QPushButton { background-color: ");
459 QString s2 = QStringLiteral(
";}");
462 but = w->findChild<QPushButton *>(QStringLiteral(
"text_color"));
463 if (
nullptr != but &&
nullptr != color.
foreground
466 but->setStyleSheet(s1 + col.name() + s2);
468 but = w->findChild<QPushButton *>(QStringLiteral(
"text_background"));
469 if (
nullptr != but &&
nullptr != color.
background
472 but->setStyleSheet(s1 + col.name() + s2);
571 QString category_name, description, qstr;
573 QVBoxLayout *twidget_layout;
574 QHBoxLayout *hbox_layout;
575 QVBoxLayout *vbox_layout;
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);
611 widget =
new QCheckBox();
617 spin =
new QSpinBox();
618 spin->setMinimum(min);
619 spin->setMaximum(max);
620 spin->setSingleStep(
MAX((max - min) / 50, 1));
626 if (
nullptr != values) {
627 combo =
new QComboBox();
628 for (
const auto &value : *values) {
629 combo->addItem(value);
633 edit =
new QLineEdit();
639 combo =
new QComboBox();
647 combo->addItem(
_(qUtf8Printable(s)), i);
654 group =
new QGroupBox();
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);
661 group->setLayout(vbox_layout);
666 button =
new QPushButton();
668 button->setFont(font);
670 QStringLiteral(
"%1 %2").arg(font.family()).arg(font.pointSize()));
671 connect(button, &QAbstractButton::clicked,
this,
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,
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,
693 hbox_layout->addWidget(button);
694 widget =
new QWidget();
695 widget->setLayout(hbox_layout);
699 if (widget !=
nullptr) {
700 hbox_layout =
new QHBoxLayout();
701 hbox_layout->setAlignment(Qt::AlignRight);
702 label =
new QLabel(description);
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);
746 pb = (QPushButton *) QObject::sender();
748 qf = QFontDialog::getFont(&ok, qf,
this);
750 ql = qf.toString().split(QStringLiteral(
","));
751 pb->setText(ql[0] +
" " + ql[1]);
770 struct option *color_option;
776 but = qobject_cast<QPushButton *>(QObject::sender());
778 if (but->objectName() == QLatin1String(
"text_color")) {
780 color = QColorDialog::getColor(c,
this);
781 if (color.isValid()) {
782 pal.setColor(QPalette::Button, color);
783 but->setPalette(pal);
785 }
else if (but->objectName() == QLatin1String(
"text_background")) {
787 color = QColorDialog::getColor(c,
this);
788 if (color.isValid()) {
789 pal.setColor(QPalette::Button, color);
790 but->setPalette(pal);
822 if (strcmp(
option_name(poption),
"nationset") == 0) {
unsigned get_bitwise(struct option *poption)
Return the enum value from groupbox.
const option_set * curr_options
struct option * get_color_option()
Find option indicating colors.
QMap< QString, QWidget * > widget_map
void set_font()
Sets font and text in pushbutton (user just chosen font)
void get_color(struct option *poption, QByteArray &a1, QByteArray &a2)
Return selected colors (for highlighting chat).
bool get_bool(struct option *poption)
Get the boolean value from checkbox.
QDialogButtonBox * button_box
void set_string(struct option *poption, const char *string)
Set the string value of the option.
void set_int(struct option *poption, int value)
Set the integer value of the option.
void full_reset()
Reset all options.
~option_dialog() override
Destructor for options dialog.
QList< QString > categories
QByteArray get_string(struct option *poption)
Get string for desired option from combobox or lineedit.
int get_enum(struct option *poption)
Get indexed value from combobox.
void add_option(struct option *poption)
Create widget for option.
void set_bool(struct option *poption, bool value)
Set the boolean value of the option.
void set_enum(struct option *poption, int index)
Set desired index(text) in combobox.
void apply_option(int response)
Apply desired action depending on user's request (clicked button).
QVBoxLayout * main_layout
void apply_options()
Apply all options.
option_dialog(const QString &name, const option_set *options, QWidget *parent=0)
Constructor for options dialog.
void full_refresh()
Refresh all options.
QFont get_button_font(struct option *poption)
Get font from pushbutton.
void option_dialog_reset(struct option *poption)
Reset one option.
void fill(const struct option_set *poptset)
Create all widgets.
void option_dialog_refresh(struct option *poption)
Refresh one given option for option dialog.
int get_int(struct option *poption)
Get int value from spinbox.
void set_bitwise(struct option *poption, unsigned value)
Set the enum value of the option.
void set_color()
Set color of buttons (user just changed colors).
void update_nationset_combo()
Updates nationset combobox.
class fc_client * king()
Return fc_client instance.
static struct ft_color ft_color_construct(const char *foreground, const char *background)
void option_dialog_popdown(const struct option_set *poptset)
Popdown the option dialog for the option set.
QString cut_helptext(const QString &text)
Remove some text from given text(help text) to show as tooltip.
QString split_text(const QString &text, bool cut)
Splits long text to 80 characters.
void option_gui_update(struct option *poption)
Update the GUI for the option.
QHash< const struct option_set *, option_dialog * > dialog_list
void option_dialog_popup(const char *name, const struct option_set *poptset)
Popup the option dialog for the option set.
void desired_settable_options_update()
Update the desired settable options hash table from the current setting configuration.
const char * option_str_def(const struct option *poption)
Returns the default value of this string option.
unsigned option_bitwise_def(const struct option *poption)
Returns the default value of this bitwise option.
int option_int_min(const struct option *poption)
Returns the minimal value of this integer option.
bool option_bool_def(const struct option *poption)
Returns the default value of this boolean option.
const char * option_name(const struct option *poption)
Returns the name of the option.
const struct option_set * server_optset
const char * option_str_get(const struct option *poption)
Returns the current value of this string option.
const QVector< QString > * option_str_values(const struct option *poption)
Returns the possible string values of this string option.
struct ft_color option_color_get(const struct option *poption)
Returns the current value of this color option.
int option_enum_get_int(const struct option *poption)
Returns the current value of this enum option (as an integer).
bool option_str_set(struct option *poption, const char *str)
Sets the value of this string option.
int option_int_get(const struct option *poption)
Returns the current value of this integer option.
bool option_font_set(struct option *poption, const QFont &font)
Sets the value of this font option.
bool option_color_set(struct option *poption, struct ft_color color)
Sets the value of this color option.
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.
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...
bool option_bool_set(struct option *poption, bool val)
Sets the value of this boolean option.
bool option_is_changeable(const struct option *poption)
Returns TRUE if this option can be modified.
void option_set_gui_data(struct option *poption, void *data)
Set the gui data for this option.
const char * option_description(const struct option *poption)
Returns the description (translated) of the option.
bool option_enum_set_int(struct option *poption, int val)
Sets the value of this enum option.
bool option_bool_get(const struct option *poption)
Returns the current value of this boolean option.
enum option_type option_type(const struct option *poption)
Returns the type of the option.
int option_int_max(const struct option *poption)
Returns the maximal value of this integer option.
QString option_category_name(const struct option *poption)
Returns the name (translated) of the category of the option.
void * option_get_gui_data(const struct option *poption)
Returns the gui data of this option.
void options_save(option_save_log_callback log_cb)
Save all options.
QFont option_font_get(const struct option *poption)
Returns the current value of this font option.
bool option_bitwise_set(struct option *poption, unsigned val)
Sets the value of this bitwise option.
QString option_help_text(const struct option *poption)
Returns the help text (translated) of the option.
struct ft_color option_color_def(const struct option *poption)
Returns the default value of this color option.
unsigned option_bitwise_get(const struct option *poption)
Returns the current value of this bitwise option.
int option_enum_def_int(const struct option *poption)
Returns the default value of this enum option (as an integer).
bool option_int_set(struct option *poption, int val)
Sets the value of this integer option.
QFont option_font_def(const struct option *poption)
Returns the default value of this font option.
const struct option_set * option_optset(const struct option *poption)
Returns the option set owner of this option.
int option_int_def(const struct option *poption)
Returns the default value of this integer option.
#define options_iterate(poptset, poption)
#define options_iterate_end
The base class for options.
const struct option_set * poptset