Commit 1272564e authored by Eoin O'Neill's avatar Eoin O'Neill 🍀

Changed The Properties for Generator (Fill) Layers to be Non-Modal

This change moves toward consistency with other properties windows
allowing you to move the properties window of a fill layer. The new window
can be called either as modal or non modal depending on whether or not it has
existing layer data passed into it. This means that creating a new fill layer
uses a modal window while editing allows you to move the window to the side to compare
and contrast values.
parent ef1ece55
......@@ -30,9 +30,12 @@
#include <filter/kis_filter_configuration.h>
#include <kis_paint_device.h>
#include <kis_transaction.h>
#include <commands/kis_change_filter_command.h>
#include <kis_generator_layer.h>
#include <KisViewManager.h>
#include <KisDocument.h>
KisDlgGeneratorLayer::KisDlgGeneratorLayer(const QString & name, KisViewManager *view, QWidget *parent)
KisDlgGeneratorLayer::KisDlgGeneratorLayer(const QString & defaultName, KisViewManager *view, QWidget *parent, KisGeneratorLayerSP glayer = 0, const KisFilterConfigurationSP previousConfig = 0)
: KoDialog(parent)
, m_customName(false)
, m_freezeName(false)
......@@ -40,16 +43,56 @@ KisDlgGeneratorLayer::KisDlgGeneratorLayer(const QString & name, KisViewManager
setButtons(Ok | Cancel);
setDefaultButton(Ok);
QWidget * page = new QWidget(this);
isEditing = glayer && previousConfig;
if(isEditing){
setModal(false);
layer = glayer;
configBefore = previousConfig;
}
QWidget *page = new QWidget(this);
m_view = view;
dlgWidget.setupUi(page);
dlgWidget.wdgGenerator->initialize(view);
dlgWidget.wdgGenerator->initialize(m_view);
setMainWidget(page);
dlgWidget.txtLayerName->setText(name);
dlgWidget.txtLayerName->setText( isEditing ? layer->name() : defaultName );
connect(dlgWidget.txtLayerName, SIGNAL(textChanged(QString)),
this, SLOT(slotNameChanged(QString)));
}
KisDlgGeneratorLayer::~KisDlgGeneratorLayer()
{
/*Editing a layer should be using the show function with automatic deletion on close.
*Because of this, the action should be taken care of when the window is closed and
*the user has accepted the changes.*/
if(isEditing && result() == QDialog::Accepted) {
layer->setName(layerName());
KisFilterConfigurationSP configAfter(configuration());
Q_ASSERT(configAfter);
QString xmlBefore = configBefore->toXML();
QString xmlAfter = configAfter->toXML();
if(xmlBefore != xmlAfter) {
KisChangeFilterCmd *cmd
= new KisChangeFilterCmd(layer,
configBefore->name(),
xmlBefore,
configAfter->name(),
xmlAfter,
true);
m_view->undoAdapter()->addCommand(cmd);
m_view->document()->setModified(true);
}
}
}
void KisDlgGeneratorLayer::slotNameChanged(const QString & text)
{
if (m_freezeName)
......
......@@ -43,20 +43,26 @@ public:
* @param name the proposed name for this layer
* @param view the view manager
* @param parent the widget parent of this dialog
* @param glayer optional generator layer for editing
* @param previousConfig optional configuration of layer being edited.
*/
KisDlgGeneratorLayer(const QString & name, KisViewManager *view, QWidget *parent);
KisDlgGeneratorLayer(const QString & defaultLayerName, KisViewManager *arg_view, QWidget *parent, KisGeneratorLayerSP glayer, const KisFilterConfigurationSP previousConfig);
~KisDlgGeneratorLayer() override;
void setConfiguration(const KisFilterConfigurationSP config);
KisFilterConfigurationSP configuration() const;
QString layerName() const;
protected Q_SLOTS:
void slotNameChanged(const QString &);
private:
Ui_WdgDlgGeneratorLayer dlgWidget;
KisGeneratorLayerSP layer;
KisFilterConfigurationSP configBefore;
KisViewManager *m_view;
bool isEditing;
bool m_customName;
bool m_freezeName;
};
......
......@@ -292,40 +292,21 @@ void KisLayerManager::layerProperties()
}
}
else if (glayer && !multipleLayersSelected) {
KisDlgGeneratorLayer dlg(glayer->name(), m_view, m_view->mainWindow());
dlg.setCaption(i18n("Fill Layer Properties"));
KisFilterConfigurationSP configBefore(glayer->filter());
Q_ASSERT(configBefore);
QString xmlBefore = configBefore->toXML();
dlg.setConfiguration(configBefore.data());
dlg.resize(dlg.minimumSizeHint());
KisDlgGeneratorLayer *dlg = new KisDlgGeneratorLayer(glayer->name(), m_view, m_view->mainWindow(), glayer, configBefore);
dlg->setCaption(i18n("Fill Layer Properties"));
dlg->setAttribute(Qt::WA_DeleteOnClose);
if (dlg.exec() == QDialog::Accepted) {
dlg->setConfiguration(configBefore.data());
dlg->resize(dlg->minimumSizeHint());
glayer->setName(dlg.layerName());
Qt::WindowFlags flags = dlg->windowFlags();
dlg->setWindowFlags(flags | Qt::WindowStaysOnTopHint | Qt::Dialog);
dlg->show();
KisFilterConfigurationSP configAfter(dlg.configuration());
Q_ASSERT(configAfter);
QString xmlAfter = configAfter->toXML();
if(xmlBefore != xmlAfter) {
KisChangeFilterCmd *cmd
= new KisChangeFilterCmd(glayer,
configBefore->name(),
xmlBefore,
configAfter->name(),
xmlAfter,
true);
// FIXME: check whether is needed
cmd->redo();
m_view->undoAdapter()->addCommand(cmd);
m_view->document()->setModified(true);
}
}
} else if (flayer && !multipleLayersSelected){
QString basePath = QFileInfo(m_view->document()->url().toLocalFile()).absolutePath();
QString fileNameOld = flayer->fileName();
......@@ -674,7 +655,8 @@ KisNodeSP KisLayerManager::addGeneratorLayer(KisNodeSP activeNode)
KisImageWSP image = m_view->image();
QColor currentForeground = m_view->resourceProvider()->fgColor().toQColor();
KisDlgGeneratorLayer dlg(image->nextLayerName(), m_view, m_view->mainWindow());
KisDlgGeneratorLayer dlg(image->nextLayerName(), m_view, m_view->mainWindow(), 0, 0);
KisFilterConfigurationSP defaultConfig = dlg.configuration();
defaultConfig->setProperty("color", currentForeground);
dlg.setConfiguration(defaultConfig);
......
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