void PreferencesDialog::updateItem(QTreeWidgetItem &item) { pref_t *pref = item.data(pref_ptr_col_, Qt::UserRole).value<pref_t *>(); if (!pref) return; QString cur_value = gchar_free_to_qstring(prefs_pref_to_str(pref, pref_stashed)).remove(QRegExp("\n\t")); bool is_changed = false; QFont font = item.font(0); if (pref->type == PREF_UAT || pref->type == PREF_CUSTOM) { item.setText(1, tr("Unknown")); } else if (stashedPrefIsDefault(pref)) { item.setText(1, tr("Default")); } else { item.setText(1, tr("Changed")); is_changed = true; } font.setBold(is_changed); item.setFont(0, font); item.setFont(0, font); item.setFont(1, font); item.setFont(2, font); item.setFont(3, font); item.setText(3, cur_value); }
guint fill_advanced_prefs(module_t *module, gpointer root_ptr) { QTreeWidgetItem *root_item = static_cast<QTreeWidgetItem *>(root_ptr); if (!module || !root_item) return 1; if (module->numprefs < 1 && !prefs_module_has_submodules(module)) return 0; QString module_title = module->title; QTreeWidgetItem *tl_item = new QTreeWidgetItem(root_item); tl_item->setText(0, module_title); tl_item->setToolTip(0, QString("<span>%1</span>").arg(module->description)); tl_item->setFirstColumnSpanned(true); QList<QTreeWidgetItem *>tl_children; for (GList *pref_l = module->prefs; pref_l && pref_l->data; pref_l = g_list_next(pref_l)) { pref_t *pref = (pref_t *) pref_l->data; if (pref->type == PREF_OBSOLETE || pref->type == PREF_STATIC_TEXT) continue; const char *type_name = prefs_pref_type_name(pref); if (!type_name) continue; pref_stash(pref, NULL); QTreeWidgetItem *item = new QTreeWidgetItem(); QString full_name = QString(module->name ? module->name : module->parent->name) + "." + pref->name; QString type_desc = gchar_free_to_qstring(prefs_pref_type_description(pref)); QString default_value = gchar_free_to_qstring(prefs_pref_to_str(pref, pref_stashed)); item->setData(0, Qt::UserRole, qVariantFromValue(pref)); item->setText(0, full_name); item->setToolTip(0, QString("<span>%1</span>").arg(pref->description)); item->setToolTip(1, QObject::tr("Has this preference been changed?")); item->setText(2, type_name); item->setToolTip(2, QString("<span>%1</span>").arg(type_desc)); item->setToolTip(3, QString("<span>%1</span>").arg( default_value.isEmpty() ? default_value : QObject::tr("Default value is empty"))); tl_children << item; // .uat is a void * so it wins the "useful key value" prize. if (pref->varp.uat) { pref_ptr_to_pref_[pref->varp.uat] = pref; } } tl_item->addChildren(tl_children); if(prefs_module_has_submodules(module)) return prefs_modules_foreach_submodules(module, fill_advanced_prefs, tl_item); return 0; }
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(); } }