[kde-doc-english] [konsole] src: Transform ColorSchemeEditor class from QWidget to KDialog
Kurt Hindenburg
kurt.hindenburg at gmail.com
Wed May 22 13:36:23 UTC 2013
Git commit 2b8d43ef48d572ee7a64725bd08cfd0447d3be33 by Kurt Hindenburg.
Committed on 22/05/2013 at 15:23.
Pushed by hindenburg into branch 'master'.
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 at gmail.com
REVIEW: 110560
GUI:
M +21 -8 src/ColorSchemeEditor.cpp
M +12 -2 src/ColorSchemeEditor.h
M +31 -25 src/EditProfileDialog.cpp
M +6 -0 src/EditProfileDialog.h
http://commits.kde.org/konsole/2b8d43ef48d572ee7a64725bd08cfd0447d3be33
diff --git a/src/ColorSchemeEditor.cpp b/src/ColorSchemeEditor.cpp
index 8ccbd7f..afe13c3 100644
--- a/src/ColorSchemeEditor.cpp
+++ b/src/ColorSchemeEditor.cpp
@@ -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"
diff --git a/src/ColorSchemeEditor.h b/src/ColorSchemeEditor.h
index 11090d4..9e67849 100644
--- a/src/ColorSchemeEditor.h
+++ b/src/ColorSchemeEditor.h
@@ -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);
diff --git a/src/EditProfileDialog.cpp b/src/EditProfileDialog.cpp
index 98ae2e7..33bb87e 100644
--- a/src/EditProfileDialog.cpp
+++ b/src/EditProfileDialog.cpp
@@ -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();
diff --git a/src/EditProfileDialog.h b/src/EditProfileDialog.h
index 1f752af..1f401af 100644
--- a/src/EditProfileDialog.h
+++ b/src/EditProfileDialog.h
@@ -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;
};
/**
More information about the kde-doc-english
mailing list