Commit 2b8d43ef authored by Kurt Hindenburg's avatar Kurt Hindenburg

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:
parent fae004a8
......@@ -46,12 +46,18 @@ const int COLOR_COLUMN = 1; // column 1 : actual colors
const int INTENSE_COLOR_COLUMN = 2; // column 2 : intense colors
ColorSchemeEditor::ColorSchemeEditor(QWidget* aParent)
: QWidget(aParent)
: KDialog(aParent)
, _isNewScheme(false)
, _colors(0)
{
// Kdialog buttons
setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply);
connect(this, SIGNAL(applyClicked()), this, SLOT(saveColorScheme()));
connect(this, SIGNAL(okClicked()), this, SLOT(saveColorScheme()));
// ui
_ui = new Ui::ColorSchemeEditor();
_ui->setupUi(this);
_ui->setupUi(mainWidget());
// description edit
_ui->descriptionEdit->setClearButtonShown(true);
......@@ -191,14 +197,17 @@ void ColorSchemeEditor::setup(const ColorScheme* scheme, bool isNewScheme)
{
_isNewScheme = isNewScheme;
if (_isNewScheme) {
setDescription(i18n("New Color Scheme"));
}
delete _colors;
_colors = new ColorScheme(*scheme);
if (_isNewScheme) {
setCaption(i18n("New Color Scheme"));
setDescription(i18n("New Color Scheme"));
} else {
setCaption(i18n("Edit Color Scheme"));
}
// setup description edit
_ui->descriptionEdit->setText(_colors->description());
......@@ -246,13 +255,17 @@ void ColorSchemeEditor::setupColorTable(const ColorScheme* colors)
_ui->colorTable->setFixedHeight(_ui->colorTable->verticalHeader()->length() + _ui->colorTable->horizontalHeader()->height() + 2);
}
ColorScheme* ColorSchemeEditor::colorScheme() const
ColorScheme& ColorSchemeEditor::colorScheme() const
{
return _colors;
return *_colors;
}
bool ColorSchemeEditor::isNewScheme() const
{
return _isNewScheme;
}
void ColorSchemeEditor::saveColorScheme()
{
emit colorSchemeSaveRequested(colorScheme(), _isNewScheme);
}
#include "ColorSchemeEditor.moc"
......@@ -23,6 +23,12 @@
// Qt
#include <QWidget>
// KDE
#include <KDialog>
// Konsole
#include "Profile.h"
class QTableWidgetItem;
namespace Ui
......@@ -46,7 +52,7 @@ class ColorScheme;
*
* When changes are made the colorsChanged() signal is emitted.
*/
class ColorSchemeEditor : public QWidget
class KONSOLEPRIVATE_EXPORT ColorSchemeEditor : public KDialog
{
Q_OBJECT
......@@ -58,12 +64,14 @@ public:
/** Initializes the dialog with the properties of the specified color scheme. */
void setup(const ColorScheme* scheme, bool isNewScheme);
/** Returns the modified color scheme. */
ColorScheme* colorScheme() const;
ColorScheme& colorScheme() const;
bool isNewScheme() const;
signals:
/** Emitted when the colors in the color scheme change. */
void colorsChanged(ColorScheme* scheme);
/** Used to send back colorscheme changes into the profile edited */
void colorSchemeSaveRequested(const ColorScheme& scheme,bool isNewScheme);
public slots:
/** Sets the text displayed in the description edit field. */
......@@ -75,6 +83,8 @@ private slots:
void editColorItem(QTableWidgetItem* item);
void wallpaperPathChanged(const QString& path);
void selectWallpaper();
/** Triggered by apply/ok buttons */
void saveColorScheme();
private:
void setupColorTable(const ColorScheme* table);
......
......@@ -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);
// close any running ColorSchemeEditor
if (_colorDialog) {
closeColorSchemeEditor();
}
_colorDialog = new ColorSchemeEditor(this);
updateColorSchemeList(true);
connect(_colorDialog, SIGNAL(colorSchemeSaveRequested(const ColorScheme&, bool)),
this, SLOT(saveColorScheme(const ColorScheme&,bool)));
_colorDialog->setup(colors, isNewScheme);
preview(Profile::ColorScheme, newScheme->name());
_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();
......
......@@ -31,6 +31,8 @@
// Konsole
#include "Profile.h"
#include "Enumeration.h"
#include "ColorScheme.h"
#include "ColorSchemeEditor.h"
class QAbstractButton;
class QItemSelectionModel;
......@@ -126,6 +128,7 @@ private slots:
void showFontDialog();
void newColorScheme();
void editColorScheme();
void saveColorScheme(const ColorScheme& scheme, bool isNewScheme);
void removeColorScheme();
void colorSchemeSelected();
void previewColorScheme(const QModelIndex& index);
......@@ -196,6 +199,7 @@ private:
void updateKeyBindingsButtons();
void showColorSchemeEditor(bool isNewScheme);
void closeColorSchemeEditor();
void showKeyBindingEditor(bool newTranslator);
void preview(int property , const QVariant& value);
......@@ -250,6 +254,8 @@ private:
QHash<int, QVariant> _delayedPreviewProperties;
QTimer* _delayedPreviewTimer;
ColorSchemeEditor* _colorDialog;
};
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment