|
@@ -43,6 +43,7 @@ public:
|
|
|
ctkSettingsDialogPrivate(ctkSettingsDialog& object);
|
|
ctkSettingsDialogPrivate(ctkSettingsDialog& object);
|
|
|
void init();
|
|
void init();
|
|
|
|
|
|
|
|
|
|
+ QList<ctkSettingsPanel*> panels()const;
|
|
|
ctkSettingsPanel* panel(QTreeWidgetItem* item)const;
|
|
ctkSettingsPanel* panel(QTreeWidgetItem* item)const;
|
|
|
QTreeWidgetItem* item(ctkSettingsPanel* panel)const;
|
|
QTreeWidgetItem* item(ctkSettingsPanel* panel)const;
|
|
|
QTreeWidgetItem* item(const QString& label)const;
|
|
QTreeWidgetItem* item(const QString& label)const;
|
|
@@ -50,6 +51,9 @@ public:
|
|
|
void beginGroup(ctkSettingsPanel* panel);
|
|
void beginGroup(ctkSettingsPanel* panel);
|
|
|
void endGroup(ctkSettingsPanel* panel);
|
|
void endGroup(ctkSettingsPanel* panel);
|
|
|
|
|
|
|
|
|
|
+ void updatePanelTitle(ctkSettingsPanel* panel);
|
|
|
|
|
+ void updateRestartRequiredLabel();
|
|
|
|
|
+
|
|
|
QSettings* Settings;
|
|
QSettings* Settings;
|
|
|
|
|
|
|
|
protected:
|
|
protected:
|
|
@@ -88,6 +92,15 @@ void ctkSettingsDialogPrivate::init()
|
|
|
q, SLOT(onCurrentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
|
|
q, SLOT(onCurrentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
|
|
|
QObject::connect(this->SettingsButtonBox, SIGNAL(clicked(QAbstractButton*)),
|
|
QObject::connect(this->SettingsButtonBox, SIGNAL(clicked(QAbstractButton*)),
|
|
|
q, SLOT(onDialogButtonClicked(QAbstractButton*)));
|
|
q, SLOT(onDialogButtonClicked(QAbstractButton*)));
|
|
|
|
|
+
|
|
|
|
|
+ this->updateRestartRequiredLabel();
|
|
|
|
|
+ q->adjustTreeWidgetToContents();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// --------------------------------------------------------------------------
|
|
|
|
|
+QList<ctkSettingsPanel*> ctkSettingsDialogPrivate::panels()const
|
|
|
|
|
+{
|
|
|
|
|
+ return this->Panels.values();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
// --------------------------------------------------------------------------
|
|
@@ -117,6 +130,50 @@ QTreeWidgetItem* ctkSettingsDialogPrivate::item(const QString& label)const
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
+void ctkSettingsDialogPrivate::updatePanelTitle(ctkSettingsPanel* panel)
|
|
|
|
|
+{
|
|
|
|
|
+ Q_Q(ctkSettingsDialog);
|
|
|
|
|
+ QTreeWidgetItem* panelItem = this->item(panel);
|
|
|
|
|
+ QString title = panelItem->text(0);
|
|
|
|
|
+ title.replace(QRegExp("\\*$"),"");
|
|
|
|
|
+ if (!panel->changedSettings().isEmpty())
|
|
|
|
|
+ {
|
|
|
|
|
+ title.append('*');
|
|
|
|
|
+ }
|
|
|
|
|
+ panelItem->setText(0,title);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// --------------------------------------------------------------------------
|
|
|
|
|
+void ctkSettingsDialogPrivate::updateRestartRequiredLabel()
|
|
|
|
|
+{
|
|
|
|
|
+ Q_Q(ctkSettingsDialog);
|
|
|
|
|
+ QStringList restartRequiredSettings;
|
|
|
|
|
+ foreach(const ctkSettingsPanel* panel, this->panels())
|
|
|
|
|
+ {
|
|
|
|
|
+ foreach(const QString& settingKey, panel->changedSettings())
|
|
|
|
|
+ {
|
|
|
|
|
+ if (panel->settingOptions(settingKey) & ctkSettingsPanel::OptionRequireRestart)
|
|
|
|
|
+ {
|
|
|
|
|
+ restartRequiredSettings << (panel->settingLabel(settingKey).isEmpty() ?
|
|
|
|
|
+ settingKey : panel->settingLabel(settingKey));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ bool restartRequired = !restartRequiredSettings.isEmpty();
|
|
|
|
|
+ if (restartRequired)
|
|
|
|
|
+ {
|
|
|
|
|
+ QString header = q->tr(
|
|
|
|
|
+ "<b style=\"color:red\">Restart required!</b><br>\n<small>"
|
|
|
|
|
+ "The application must be restarted to take into account "
|
|
|
|
|
+ "the new values of the following properties:\n");
|
|
|
|
|
+ QString footer = q->tr("</small>");
|
|
|
|
|
+ restartRequiredSettings.push_front(QString());
|
|
|
|
|
+ this->RestartRequiredLabel->setText( header + restartRequiredSettings.join("<br> ") + footer);
|
|
|
|
|
+ }
|
|
|
|
|
+ this->RestartRequiredLabel->setVisible(restartRequired);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// --------------------------------------------------------------------------
|
|
|
ctkSettingsDialog::ctkSettingsDialog(QWidget* _parent)
|
|
ctkSettingsDialog::ctkSettingsDialog(QWidget* _parent)
|
|
|
: Superclass(_parent)
|
|
: Superclass(_parent)
|
|
|
, d_ptr(new ctkSettingsDialogPrivate(*this))
|
|
, d_ptr(new ctkSettingsDialogPrivate(*this))
|
|
@@ -231,8 +288,30 @@ ctkSettingsPanel* ctkSettingsDialog::panel(const QString& label)const
|
|
|
// --------------------------------------------------------------------------
|
|
// --------------------------------------------------------------------------
|
|
|
void ctkSettingsDialog::accept()
|
|
void ctkSettingsDialog::accept()
|
|
|
{
|
|
{
|
|
|
|
|
+ Q_D(ctkSettingsDialog);
|
|
|
|
|
+ bool emitRestartRequested = false;
|
|
|
|
|
+ if (this->isRestartRequired())
|
|
|
|
|
+ {
|
|
|
|
|
+ QMessageBox::StandardButton answer = QMessageBox::question(this,"Restart required",
|
|
|
|
|
+ "For settings to be taken into account, the application\n"
|
|
|
|
|
+ "must be restarted. Restart the application now ?\n",
|
|
|
|
|
+ QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel, QMessageBox::No);
|
|
|
|
|
+ if (answer == QMessageBox::Cancel)
|
|
|
|
|
+ {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ emitRestartRequested = (answer == QMessageBox::Yes);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
this->applySettings();
|
|
this->applySettings();
|
|
|
this->Superclass::accept();
|
|
this->Superclass::accept();
|
|
|
|
|
+ if (emitRestartRequested)
|
|
|
|
|
+ {
|
|
|
|
|
+ emit restartRequested();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
// --------------------------------------------------------------------------
|
|
@@ -287,6 +366,8 @@ void ctkSettingsDialog
|
|
|
{
|
|
{
|
|
|
Q_D(ctkSettingsDialog);
|
|
Q_D(ctkSettingsDialog);
|
|
|
d->SettingsButtonBox->button(QDialogButtonBox::Reset)->setEnabled(true);
|
|
d->SettingsButtonBox->button(QDialogButtonBox::Reset)->setEnabled(true);
|
|
|
|
|
+ d->updatePanelTitle(qobject_cast<ctkSettingsPanel*>(this->sender()));
|
|
|
|
|
+ d->updateRestartRequiredLabel();
|
|
|
emit settingChanged(key, newVal);
|
|
emit settingChanged(key, newVal);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -332,6 +413,7 @@ void ctkSettingsDialog::adjustTreeWidgetToContents()
|
|
|
|
|
|
|
|
d->SettingsTreeWidget->setFixedWidth(
|
|
d->SettingsTreeWidget->setFixedWidth(
|
|
|
d->SettingsTreeWidget->QAbstractItemView::sizeHintForColumn(0) +
|
|
d->SettingsTreeWidget->QAbstractItemView::sizeHintForColumn(0) +
|
|
|
|
|
+ d->SettingsTreeWidget->fontMetrics().width('*') +
|
|
|
2 * d->SettingsTreeWidget->indentation() +
|
|
2 * d->SettingsTreeWidget->indentation() +
|
|
|
2 * d->SettingsTreeWidget->frameWidth());
|
|
2 * d->SettingsTreeWidget->frameWidth());
|
|
|
}
|
|
}
|
|
@@ -362,3 +444,10 @@ void ctkSettingsDialog::setResetButton(bool show)
|
|
|
d->SettingsButtonBox->button(QDialogButtonBox::Reset)->setVisible(show);
|
|
d->SettingsButtonBox->button(QDialogButtonBox::Reset)->setVisible(show);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// --------------------------------------------------------------------------
|
|
|
|
|
+bool ctkSettingsDialog::isRestartRequired()const
|
|
|
|
|
+{
|
|
|
|
|
+ Q_D(const ctkSettingsDialog);
|
|
|
|
|
+ return d->RestartRequiredLabel->isVisibleTo(
|
|
|
|
|
+ const_cast<ctkSettingsDialog*>(this));
|
|
|
|
|
+}
|