Transform ColorSchemeEditor class from QWidget to KDialog

Move some code from EditProfileDialog::showColorSchemeEditor
* a part went in the slot EditProfileDialog::saveColorScheme
* a part becomes obsolete since ColorSchemeEditor is the whole KDialog
* a small part went into ColorSchemeEditor constructor

Make ColorSchemeEditor a non-modal dialog : The terminal is not frozen
when the dialog is open
 - The Kdialog has an Apply button
 - Some safeguard to check that there is only one ColorSchemeEditor open
 - Use reference rather than pointer in ColorSchemeEditor interface

Thanks to Renan for improving on Konsole's ColorScheme.

Patch by renan fargetton renan.fargetton@gmail.com

REVIEW: 110560
GUI:
This commit is contained in:
Kurt Hindenburg
2013-05-22 09:23:42 -04:00
parent fae004a827
commit 2b8d43ef48
4 changed files with 72 additions and 37 deletions

View File

@@ -69,6 +69,7 @@ EditProfileDialog::EditProfileDialog(QWidget* aParent)
: KDialog(aParent)
, _colorSchemeAnimationTimeLine(0)
, _delayedPreviewTimer(new QTimer(this))
, _colorDialog(0)
{
setCaption(i18n("Edit Profile"));
setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply);
@@ -697,34 +698,24 @@ void EditProfileDialog::showColorSchemeEditor(bool isNewScheme)
Q_ASSERT(colors);
// Setting up ColorSchemeEditor ui
QWeakPointer<KDialog> dialog = new KDialog(this);
if (isNewScheme)
dialog.data()->setCaption(i18n("New Color Scheme"));
else
dialog.data()->setCaption(i18n("Edit Color Scheme"));
ColorSchemeEditor* editor = new ColorSchemeEditor;
dialog.data()->setMainWidget(editor);
editor->setup(colors, isNewScheme);
if (isNewScheme)
editor->setDescription(i18n("New Color Scheme"));
if (dialog.data()->exec() == QDialog::Accepted) {
ColorScheme* newScheme = new ColorScheme(*editor->colorScheme());
// if this is a new color scheme, pick a name based on the description
if (isNewScheme)
newScheme->setName(newScheme->description());
ColorSchemeManager::instance()->addColorScheme(newScheme);
updateColorSchemeList(true);
preview(Profile::ColorScheme, newScheme->name());
// close any running ColorSchemeEditor
if (_colorDialog) {
closeColorSchemeEditor();
}
_colorDialog = new ColorSchemeEditor(this);
connect(_colorDialog, SIGNAL(colorSchemeSaveRequested(const ColorScheme&, bool)),
this, SLOT(saveColorScheme(const ColorScheme&,bool)));
_colorDialog->setup(colors, isNewScheme);
_colorDialog->show();
}
void EditProfileDialog::closeColorSchemeEditor()
{
if (_colorDialog) {
_colorDialog->close();
delete _colorDialog;
}
delete dialog.data();
}
void EditProfileDialog::newColorScheme()
{
@@ -734,6 +725,21 @@ void EditProfileDialog::editColorScheme()
{
showColorSchemeEditor(false);
}
void EditProfileDialog::saveColorScheme(const ColorScheme& scheme, bool isNewScheme)
{
ColorScheme* newScheme = new ColorScheme(scheme);
// if this is a new color scheme, pick a name based on the description
if (isNewScheme) {
newScheme->setName(newScheme->description());
}
ColorSchemeManager::instance()->addColorScheme(newScheme);
updateColorSchemeList(true);
preview(Profile::ColorScheme, newScheme->name());
}
void EditProfileDialog::colorSchemeSelected()
{
QModelIndexList selected = _ui->colorSchemeList->selectionModel()->selectedIndexes();