Commit ca4c8522 authored by José Luis Vergara's avatar José Luis Vergara
Browse files

Modify kis_dlg_layer_properties to show a preview of changes to the user

o Modify KisLayerManager and KisDlgLayerProperties to let the latter take charge of handling the changes to the layer.
o Add a ticker to keep change of changes to the configuration and show preview changes.
o Make the dialog non-modal.
o Modify wdglayerproperties.ui to give more room for widgets.
o ...Also add a preview CheckBox.

BUG:232141
parent 8be58a8e
/*
* Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2011 José Luis Vergara <pentalis@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -38,6 +39,13 @@
#include <KoColorSpace.h>
#include <KoCompositeOp.h>
#include "kis_undo_adapter.h"
#include "qtimer.h"
#include "commands/kis_layer_commands.h"
#include "kis_layer.h"
#include "kis_view2.h"
#include "kis_doc2.h"
#include "kis_cursor.h"
#include <kis_debug.h>
#include <kis_global.h>
......@@ -49,57 +57,143 @@
#include "widgets/kis_channelflags_widget.h"
#include <kis_composite_ops_model.h>
KisDlgLayerProperties::KisDlgLayerProperties(const QString& deviceName,
qint32 opacity,
const KoCompositeOp* compositeOp,
const KoColorSpace * colorSpace,
const QBitArray & channelFlags,
QWidget *parent, const char *name, Qt::WFlags f)
: KDialog(parent)
, m_colorSpace(colorSpace)
struct KisDlgLayerProperties::Private
{
QString deviceName;
const KoColorSpace *colorSpace;
const KoCompositeOp *compositeOp;
QBitArray channelFlags;
quint8 opacity;
};
KisDlgLayerProperties::KisDlgLayerProperties(KisLayerSP layer, KisView2 *view, KisDoc2 *doc, QWidget *parent, const char *name, Qt::WFlags f)
: KDialog(parent)
, m_layer(layer)
, m_view(view)
, m_doc(doc)
, d(new Private())
{
Q_UNUSED(f);
setCaption(i18n("Layer Properties"));
setButtons(Ok | Cancel);
setDefaultButton(Ok);
setModal(false);
setObjectName(name);
m_page = new WdgLayerProperties(this);
opacity = int((opacity * 100.0) / 255 + 0.5);
/*
const QString deviceName = layer->name();
const KoColorSpace *colorSpace = layer->colorSpace();
const KoCompositeOp *compositeOp = layer->compositeOp();
QBitArray channelFlags = layer->channelFlags();
quint8 opacity = layer->opacity();
*/
d->deviceName = layer->name();
d->colorSpace = layer->colorSpace();
d->compositeOp = layer->compositeOp();
d->channelFlags = layer->channelFlags();
d->opacity = layer->opacity();
quint8 sliderOpacity = int((d->opacity * 100.0) / 255 + 0.5);
setMainWidget(m_page);
m_page->editName->setText(deviceName);
m_page->editName->setText(d->deviceName);
connect(m_page->editName, SIGNAL(textChanged(const QString &)), this, SLOT(slotNameChanged(const QString &)));
m_page->lblColorSpace->setText(colorSpace->name());
m_page->lblColorSpace->setText(d->colorSpace->name());
if (const KoColorProfile* profile = colorSpace->profile()) {
if (const KoColorProfile* profile = d->colorSpace->profile()) {
m_page->lblProfile->setText(profile->name());
}
m_page->intOpacity->setRange(0, 100);
m_page->intOpacity->setValue(opacity);
m_page->intOpacity->setValue(sliderOpacity);
m_page->cmbComposite->getModel()->validateCompositeOps(colorSpace);
m_page->cmbComposite->setCurrentIndex(m_page->cmbComposite->indexOf(KoID(compositeOp->id())));
m_page->cmbComposite->getModel()->validateCompositeOps(d->colorSpace);
m_page->cmbComposite->setCurrentIndex(m_page->cmbComposite->indexOf(KoID(d->compositeOp->id())));
slotNameChanged(m_page->editName->text());
QVBoxLayout * vbox = new QVBoxLayout;
m_channelFlags = new KisChannelFlagsWidget(colorSpace);
m_channelFlags = new KisChannelFlagsWidget(d->colorSpace);
vbox->addWidget(m_channelFlags);
vbox->addStretch(1);
m_page->grpActiveChannels->setLayout(vbox);
m_channelFlags->setChannelFlags(channelFlags);
m_channelFlags->setChannelFlags(d->channelFlags);
setMinimumSize(m_page->sizeHint());
QTimer* ticker = new QTimer;
ticker->start(200);
connect(ticker, SIGNAL(timeout()), SLOT(updatePreview()));
}
KisDlgLayerProperties::~KisDlgLayerProperties()
{
if (result() == QDialog::Accepted) {
applyNewProperties();
} else { // QDialog::Rejected
cleanPreviewChanges();
m_doc->setModified(true);
m_layer->setDirty();
}
}
void KisDlgLayerProperties::updatePreview()
{
if (!m_layer) return;
if(m_page->checkBoxPreview->isChecked()) {
if ( m_layer->name() != getName()
|| m_layer->opacity() != getOpacity()
|| m_layer->compositeOp()->id() != getCompositeOp()
|| m_layer->channelFlags() != getChannelFlags() )
{
m_layer->setOpacity(getOpacity());
m_layer->setCompositeOp(getCompositeOp());
m_layer->setName(getName());
m_layer->setChannelFlags(getChannelFlags());
m_doc->setModified(true);
}
m_layer->setDirty();
}
}
void KisDlgLayerProperties::applyNewProperties()
{
if (!m_layer) return;
cleanPreviewChanges();
if ( m_layer->name() != getName()
|| m_layer->opacity() != getOpacity()
|| m_layer->compositeOp()->id() != getCompositeOp()
|| m_layer->channelFlags() != getChannelFlags() )
{
QApplication::setOverrideCursor(KisCursor::waitCursor());
KUndo2Command *change = new KisLayerPropsCommand(m_layer,
m_layer->opacity(), getOpacity(),
m_layer->compositeOpId(), getCompositeOp(),
m_layer->name(), getName(),
m_layer->channelFlags(), getChannelFlags(),
true);
m_view->undoAdapter()->addCommand(change);
QApplication::restoreOverrideCursor();
m_doc->setModified(true);
m_layer->setDirty();
}
}
void KisDlgLayerProperties::cleanPreviewChanges()
{
m_layer->setOpacity(d->opacity);
m_layer->setCompositeOp(d->compositeOp->id());
m_layer->setName(d->deviceName);
m_layer->setChannelFlags(d->channelFlags);
}
void KisDlgLayerProperties::slotNameChanged(const QString &_text)
......
/*
* Copyright (c) 2005 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2011 José Luis Vergara <pentalis@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -21,6 +22,7 @@
#include <QList>
#include <QCheckBox>
#include "kis_types.h"
#include <kdialog.h>
#include "ui_wdglayerproperties.h"
......@@ -30,6 +32,8 @@ class KoCompositeOp;
class KoColorSpace;
class QBitArray;
class KisChannelFlagsWidget;
class KisView2;
class KisDoc2;
class WdgLayerProperties : public QWidget, public Ui::WdgLayerProperties
{
......@@ -43,16 +47,10 @@ public:
class KisDlgLayerProperties : public KDialog
{
Q_OBJECT
public:
KisDlgLayerProperties(const QString& deviceName,
qint32 opacity,
const KoCompositeOp* compositeOp,
const KoColorSpace * colorSpace,
const QBitArray & channelFlags,
QWidget *parent = 0, const char *name = 0, Qt::WFlags f = 0);
KisDlgLayerProperties(KisLayerSP layer, KisView2 *view, KisDoc2 *doc, QWidget *parent = 0, const char *name = 0, Qt::WFlags f = 0);
virtual ~KisDlgLayerProperties();
......@@ -67,13 +65,23 @@ public:
*/
QBitArray getChannelFlags() const;
public slots:
void updatePreview();
protected slots:
void slotNameChanged(const QString &);
void applyNewProperties();
void cleanPreviewChanges();
private:
KisLayerSP m_layer;
KisView2 *m_view;
KisDoc2 *m_doc;
WdgLayerProperties * m_page;
KisChannelFlagsWidget * m_channelFlags;
const KoColorSpace * m_colorSpace;
struct Private;
Private * const d;
};
#endif // KIS_DLG_LAYER_PROPERTIES_H_
......
......@@ -7,9 +7,15 @@
<x>0</x>
<y>0</y>
<width>420</width>
<height>222</height>
<height>190</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>190</height>
</size>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
......@@ -85,7 +91,30 @@
</item>
</layout>
</item>
<item row="0" column="1" rowspan="2">
<item row="1" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>126</width>
<height>78</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkBoxPreview">
<property name="text">
<string>&amp;Preview</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QGroupBox" name="grpActiveChannels">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
......@@ -104,19 +133,6 @@
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>126</width>
<height>78</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
......
......@@ -285,47 +285,12 @@ void KisLayerManager::layerProperties()
}
}
} else {
KisDlgLayerProperties dlg(layer->name(),
layer->opacity(),
layer->compositeOp(),
cs,
layer->channelFlags());
dlg.resize(dlg.minimumSizeHint());
if (dlg.exec() == QDialog::Accepted) {
QBitArray newChannelFlags = dlg.getChannelFlags();
for (int i = 0; i < newChannelFlags.size(); ++i) {
dbgUI << "we got flags: " << i << " is " << newChannelFlags.testBit(i);
}
QBitArray oldChannelFlags = layer->channelFlags();
for (int i = 0; i < oldChannelFlags.size(); ++i) {
dbgUI << "the old ones were: " << i << " is " << oldChannelFlags.testBit(i);
}
dbgUI << " and are they the same: " << (oldChannelFlags == newChannelFlags);
if (layer->name() != dlg.getName() ||
layer->opacity() != dlg.getOpacity() ||
layer->compositeOp()->id() != dlg.getCompositeOp()
) {
QApplication::setOverrideCursor(KisCursor::waitCursor());
m_view->undoAdapter()->addCommand(new KisLayerPropsCommand(layer,
layer->opacity(), dlg.getOpacity(),
layer->compositeOpId(), dlg.getCompositeOp(),
layer->name(), dlg.getName(),
oldChannelFlags, newChannelFlags));
QApplication::restoreOverrideCursor();
m_doc->setModified(true);
}
if (oldChannelFlags != newChannelFlags) {
layer->setChannelFlags(newChannelFlags);
layer->setDirty();
}
}
} else { // If layer == normal painting layer, shape layer, or group layer
KisDlgLayerProperties *dialog = new KisDlgLayerProperties(layer, m_view, m_doc);
dialog->resize(dialog->minimumSizeHint());
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show();
}
}
void KisLayerManager::layerAdd()
......
Supports Markdown
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