19#include <QApplication>
21#include <QColorDialog>
23#include <QDialogButtonBox>
65 QString st,
str, result;
69 sl = text.split(
"\n");
70 foreach (
const QString &s, sl) {
72 while (st.length() >= 80) {
74 i =
str.lastIndexOf(
' ');
78 result = result +
str.left(i) +
'\n';
88 if (
str.left(
str.length()) !=
"") {
89 result = result +
str.left(
str.length()) +
'\n';
93 result = result +
_(
"... read more in help") +
"\n";
97 result.remove(result.lastIndexOf(
'\n'), 1);
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';
118 ret_str = ret_str + s +
'\n';
130 :
qfc_dialog(parent), client_settings(client_set)
135 setWindowTitle(
name);
139 but =
new QPushButton(style()->standardIcon(QStyle::SP_DialogCancelButton),
141 button_box->addButton(but, QDialogButtonBox::ActionRole);
142 QObject::connect(but, &QPushButton::clicked, [
this]() {
146 but =
new QPushButton(style()->standardIcon(QStyle::SP_DialogResetButton),
148 button_box->addButton(but, QDialogButtonBox::ResetRole);
149 QObject::connect(but, &QPushButton::clicked, [
this]() {
153 but =
new QPushButton(QIcon::fromTheme(
"view-refresh"),
_(
"Refresh"));
154 button_box->addButton(but, QDialogButtonBox::ActionRole);
155 QObject::connect(but, &QPushButton::clicked, [
this]() {
159 but =
new QPushButton(style()->standardIcon(QStyle::SP_DialogApplyButton),
161 button_box->addButton(but, QDialogButtonBox::ActionRole);
162 QObject::connect(but, &QPushButton::clicked, [
this]() {
166 but =
new QPushButton(style()->standardIcon(QStyle::SP_DialogSaveButton),
168 button_box->addButton(but, QDialogButtonBox::ActionRole);
169 QObject::connect(but, &QPushButton::clicked, [
this]() {
173 but =
new QPushButton(style()->standardIcon(QStyle::SP_DialogOkButton),
175 button_box->addButton(but, QDialogButtonBox::ActionRole);
176 QObject::connect(but, &QPushButton::clicked, [
this]() {
187 setAttribute(Qt::WA_DeleteOnClose);
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();
286 log_error(
"Option type %s (%d) not supported yet.",
304 c->setCheckState(Qt::Checked);
306 c->setCheckState(Qt::Unchecked);
318 if (c->checkState() == Qt::Checked) {
349 qApp->processEvents();
353 qp->setText(ql[0] +
" " + ql[1]);
380 i = cb->findText(
string);
382 cb->setCurrentIndex(i);
400 return cb->currentText().toUtf8();
403 return le->displayText().toUtf8();
415 cb->setCurrentIndex(index);
426 return cb->currentIndex();
436 QList <QCheckBox *> check_buttons;
439 check_buttons = gb->findChildren <QCheckBox *>();
441 for (i = 0; i < check_buttons.count(); i++) {
442 if (value & (1 << i)) {
443 check_buttons[i]->setCheckState(Qt::Checked);
445 check_buttons[i]->setCheckState(Qt::Unchecked);
457 unsigned int value = 0;
458 QList <QCheckBox *> check_buttons;
461 check_buttons = gb->findChildren <QCheckBox *>();
463 for (i = 0; i < check_buttons.count(); i++) {
464 if (check_buttons[i]->checkState() == Qt::Checked) {
475 const char *colorname)
477 if (button !=
nullptr && colorname != NULL && colorname[0] !=
'\0') {
478 QString s1 =
"QPushButton { background-color: ";
482 col.setNamedColor(colorname);
483 button->setStyleSheet(s1 + col.name() + s2);
496 but = w->findChild<QPushButton *>(
"text_color");
499 but = w->findChild<QPushButton *>(
"text_background");
531 log_error(
"Option type %s (%d) not supported yet.",
585 log_error(
"Option type %s (%d) not supported yet.",
609 QString category_name, description, qstr;
610 QStringList qlist, qlist2;
612 const struct strvec *values;
613 QVBoxLayout *twidget_layout;
614 QHBoxLayout *hbox_layout;
615 QVBoxLayout *vbox_layout;
635 twidget =
new QWidget();
636 twidget->setProperty(
"doomed",
true);
637 scroll =
new QScrollArea();
638 scroll->setProperty(
"doomed",
true);
639 scroll->setWidgetResizable(
true);
640 twidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
641 twidget_layout =
new QVBoxLayout();
642 twidget_layout->setSpacing(0);
643 twidget->setLayout(twidget_layout);
644 scroll->setWidget(twidget);
661 spin =
new QSpinBox();
662 spin->setMinimum(min);
663 spin->setMaximum(max);
664 spin->setSingleStep(
MAX((max - min) / 50, 1));
670 if (NULL != values) {
671 combo =
new QComboBox();
673 combo->addItem(value);
677 edit =
new QLineEdit();
683 combo =
new QComboBox();
687 combo->addItem(
_(
str), i);
693 group =
new QGroupBox();
695 vbox_layout =
new QVBoxLayout();
698 vbox_layout->addWidget(check);
700 group->setLayout(vbox_layout);
705 button =
new QPushButton();
708 qstr = qf.toString();
709 qlist = qstr.split(
",");
711 button->setText(qlist[0] +
" " + qlist[1]);
712 connect(button, SIGNAL(clicked()),
this, SLOT(
select_font()));
718 button =
new QPushButton();
719 button->setToolTip(
_(
"Select the text color"));
720 button->setObjectName(
"text_color");
721 button->setAutoFillBackground(
true);
722 button->setAutoDefault(
false);
724 pal = button->palette();
725 pal.setColor(QPalette::Button, c);
726 button->setPalette(pal);
727 connect(button, SIGNAL(clicked()),
this, SLOT(
select_color()));
728 hbox_layout =
new QHBoxLayout();
729 hbox_layout->addWidget(button);
730 button =
new QPushButton();
731 button->setToolTip(
_(
"Select the background color"));
732 button->setObjectName(
"text_background");
733 button->setAutoFillBackground(
true);
734 button->setAutoDefault(
false);
736 pal = button->palette();
737 pal.setColor(QPalette::Button, c);
738 button->setPalette(pal);
739 connect(button, SIGNAL(clicked()),
this, SLOT(
select_color()));
740 hbox_layout->addWidget(button);
743 widget->setLayout(hbox_layout);
747 log_error(
"Option type %s (%d) not supported yet.",
753 hbox_layout =
new QHBoxLayout();
754 hbox_layout->setAlignment(Qt::AlignRight);
755 label =
new QLabel(description);
757 hbox_layout->addWidget(label, 1, Qt::AlignLeft);
758 hbox_layout->addStretch();
759 hbox_layout->addWidget(
widget, 1, Qt::AlignRight);
760 lwidget =
new QWidget();
761 lwidget->setLayout(hbox_layout);
762 twidget_layout = qobject_cast < QVBoxLayout * >(twidget->layout());
763 twidget_layout->addWidget(lwidget);
803 pb = (QPushButton *) QObject::sender();
805 qf = QFontDialog::getFont(&ok, qf,
this,
808 ql = qf.toString().split(
",");
809 pb->setText(ql[0] +
" " + ql[1]);
836 return f.toString().toUtf8();
848 but = qobject_cast<QPushButton *>(QObject::sender());
850 pal = but->palette();
851 color = QColorDialog::getColor(pal.color(QPalette::Button),
this,
853 if (
color.isValid()) {
854 pal.setColor(QPalette::Button,
color);
855 but->setPalette(pal);
869 if (!
gui()->qt_settings.options_client_geometry.isNull()) {
870 restoreGeometry(
gui()->qt_settings.options_client_geometry);
873 if (!
gui()->qt_settings.options_server_geometry.isNull()) {
874 restoreGeometry(
gui()->qt_settings.options_server_geometry);
885 gui()->qt_settings.options_client_geometry = saveGeometry();
887 gui()->qt_settings.options_server_geometry = saveGeometry();
897 gui()->qt_settings.options_client_geometry = saveGeometry();
899 gui()->qt_settings.options_server_geometry = saveGeometry();
930 if (strcmp(
option_name(poption),
"nationset") == 0) {
QString split_text(QString text, bool cut)
void update_nationset_combo()
static struct ft_color ft_color_construct(const char *foreground, const char *background)
static struct dialog_list * dialog_list
#define log_error(message,...)
void option_gui_remove(struct option *poption)
void option_dialog_popdown(const struct option_set *poptset)
QString split_text(QString text, bool cut)
void option_gui_add(struct option *poption)
QMap< const struct option_set *, option_dialog * > dialog_list
void option_gui_update(struct option *poption)
void option_dialog_popup(QString name, const struct option_set *poptset, bool client_set)
QString cut_helptext(QString text)
const struct strvec * option_str_values(const struct option *poption)
unsigned option_bitwise_def(const struct option *poption)
int option_int_min(const struct option *poption)
bool option_bool_def(const struct option *poption)
const char * option_font_def(const struct option *poption)
const struct option_set * server_optset
const char * option_description(const struct option *poption)
const char * option_help_text(const struct option *poption)
struct ft_color option_color_get(const struct option *poption)
int option_enum_get_int(const struct option *poption)
bool option_str_set(struct option *poption, const char *str)
const char * option_name(const struct option *poption)
int option_int_get(const struct option *poption)
bool option_color_set(struct option *poption, struct ft_color color)
bool option_bool_set(struct option *poption, bool val)
bool option_is_changeable(const struct option *poption)
void option_set_gui_data(struct option *poption, void *data)
const char * option_str_get(const struct option *poption)
void * option_get_gui_data(const struct option *poption)
bool option_enum_set_int(struct option *poption, int val)
bool option_bool_get(const struct option *poption)
enum option_type option_type(const struct option *poption)
const char * option_enum_int_to_str(const struct option *poption, int val)
const struct option_set * option_optset(const struct option *poption)
const char * option_str_def(const struct option *poption)
int option_int_max(const struct option *poption)
bool option_font_set(struct option *poption, const char *font)
void options_save(option_save_log_callback log_cb)
const struct strvec * option_bitwise_values(const struct option *poption)
bool option_bitwise_set(struct option *poption, unsigned val)
const char * option_font_get(const struct option *poption)
void desired_settable_options_update(void)
struct ft_color option_color_def(const struct option *poption)
unsigned option_bitwise_get(const struct option *poption)
int option_enum_def_int(const struct option *poption)
bool option_int_set(struct option *poption, int val)
const char * option_category_name(const struct option *poption)
int option_int_def(const struct option *poption)
#define options_iterate(poptset, poption)
#define options_iterate_end
const char * strvec_get(const struct strvec *psv, size_t svindex)
size_t strvec_size(const struct strvec *psv)
#define strvec_iterate(psv, str)
#define strvec_iterate_end
unsigned get_bitwise(struct option *poption)
const option_set * curr_options
void hideEvent(QHideEvent *event)
QMap< QString, QWidget * > widget_map
QByteArray get_button_font(struct option *poption)
void get_color(struct option *poption, QByteArray &a1, QByteArray &a2)
bool get_bool(struct option *poption)
QDialogButtonBox * button_box
void set_string(struct option *poption, const char *string)
void set_int(struct option *poption, int value)
QList< QString > categories
void showEvent(QShowEvent *event)
QByteArray get_string(struct option *poption)
int get_enum(struct option *poption)
void add_option(struct option *poption)
void set_bool(struct option *poption, bool value)
void set_enum(struct option *poption, int index)
void apply_option(int response)
void closeEvent(QCloseEvent *event)
QVBoxLayout * main_layout
void set_font(struct option *poption, QString s)
QFont get_font(struct option *poption)
const struct option_set * poptset
void option_dialog_reset(struct option *poption)
void set_color(struct option *poption, struct ft_color color)
void fill(const struct option_set *poptset)
void option_dialog_refresh(struct option *poption)
int get_int(struct option *poption)
void set_button_color(QPushButton *button, const char *colorname)
void set_bitwise(struct option *poption, unsigned value)
option_dialog(const QString &name, const option_set *options, bool client_set, QWidget *parent=nullptr)