ModulePreferencesScrollArea::ModulePreferencesScrollArea(module_t *module, QWidget *parent) : QScrollArea(parent), ui(new Ui::ModulePreferencesScrollArea), module_(module) { ui->setupUi(this); if (!module) return; /* Add items for each of the preferences */ prefs_pref_foreach(module, pref_show, (gpointer) ui->verticalLayout); foreach (QLineEdit *le, findChildren<QLineEdit *>()) { pref_t *pref = le->property(pref_prop_).value<pref_t *>(); if (!pref) continue; switch (pref->type) { case PREF_UINT: connect(le, SIGNAL(textEdited(QString)), this, SLOT(uintLineEditTextEdited(QString))); break; case PREF_STRING: case PREF_FILENAME: case PREF_DIRNAME: connect(le, SIGNAL(textEdited(QString)), this, SLOT(stringLineEditTextEdited(QString))); break; case PREF_RANGE: connect(le, SIGNAL(textEdited(QString)), this, SLOT(rangeSyntaxLineEditTextEdited(QString))); break; default: break; } }
ModulePreferencesScrollArea::ModulePreferencesScrollArea(module_t *module, QWidget *parent) : QScrollArea(parent), ui(new Ui::ModulePreferencesScrollArea), module_(module) { ui->setupUi(this); if (!module) return; /* Show the preference's description at the top of the page */ QFont font; font.setBold(TRUE); QLabel *label = new QLabel(module->description); label->setFont(font); ui->verticalLayout->addWidget(label); /* Add items for each of the preferences */ prefs_pref_foreach(module, pref_show, (gpointer) ui->verticalLayout); foreach (QLineEdit *le, findChildren<QLineEdit *>()) { pref_t *pref = VariantPointer<pref_t>::asPtr(le->property(pref_prop_)); if (!pref) continue; switch (prefs_get_type(pref)) { case PREF_DECODE_AS_UINT: connect(le, SIGNAL(textEdited(QString)), this, SLOT(uintLineEditTextEdited(QString))); break; case PREF_UINT: connect(le, SIGNAL(textEdited(QString)), this, SLOT(uintLineEditTextEdited(QString))); break; case PREF_STRING: case PREF_SAVE_FILENAME: case PREF_OPEN_FILENAME: case PREF_DIRNAME: connect(le, SIGNAL(textEdited(QString)), this, SLOT(stringLineEditTextEdited(QString))); break; case PREF_RANGE: case PREF_DECODE_AS_RANGE: connect(le, SIGNAL(textEdited(QString)), this, SLOT(rangeSyntaxLineEditTextEdited(QString))); break; default: break; } }
void PreferenceEditorFrame::editPreference(preference *pref, pref_module *module) { pref_ = pref; module_ = module; if (!pref || !module) { hide(); return; } ui->modulePreferencesToolButton->setText(tr("Open %1 preferences").arg(module_->title)); pref_stash(pref_, NULL); ui->preferenceTitleLabel->setText(pref->title); // Convert the pref description from plain text to rich text. QString description; #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) description = Qt::escape(pref->description); #else description = QString(pref->description).toHtmlEscaped(); #endif description.replace('\n', "<br>"); QString tooltip = QString("<span>%1</span>").arg(description); ui->preferenceTitleLabel->setToolTip(tooltip); ui->preferenceLineEdit->setToolTip(tooltip); ui->preferenceLineEdit->clear(); ui->preferenceLineEdit->setSyntaxState(SyntaxLineEdit::Empty); disconnect(ui->preferenceLineEdit); bool show = false; switch (pref_->type) { case PREF_UINT: new_uint_ = pref->stashed_val.uint; connect(ui->preferenceLineEdit, SIGNAL(textEdited(QString)), this, SLOT(uintLineEditTextEdited(QString))); show = true; break; case PREF_STRING: new_str_ = pref->stashed_val.string; connect(ui->preferenceLineEdit, SIGNAL(textEdited(QString)), this, SLOT(stringLineEditTextEdited(QString))); show = true; break; case PREF_RANGE: g_free(new_range_); new_range_ = range_copy(pref->stashed_val.range); connect(ui->preferenceLineEdit, SIGNAL(textEdited(QString)), this, SLOT(rangeLineEditTextEdited(QString))); show = true; break; default: break; } if (show) { ui->preferenceLineEdit->setText(gchar_free_to_qstring(prefs_pref_to_str(pref_, pref_stashed)).remove(QRegExp("\n\t"))); animatedShow(); } }