Commit a58c0cad authored by Sven Langkamp's avatar Sven Langkamp

moved composite ops to toolbar, added shortcut for eraser

svn path=/trunk/koffice/; revision=1137656
parent a7c83289
......@@ -281,6 +281,9 @@ void KisCanvasResourceProvider::slotResourceChanged(int key, const QVariant & re
break;
case(CurrentKritaNode) :
emit sigNodeChanged(currentNode());
break;
case(CurrentCompositeOp) :
emit sigCompositeOpChanged(currentCompositeOp());
default:
;
// Do nothing
......@@ -326,6 +329,19 @@ const KoColorProfile *KisCanvasResourceProvider::getScreenProfile(int screen)
#endif
}
void KisCanvasResourceProvider::setCurrentCompositeOp(const QString& compositeOp)
{
QVariant v;
v.setValue(compositeOp);
m_resourceManager->setResource(CurrentCompositeOp, v);
emit sigCompositeOpChanged(compositeOp);
}
QString KisCanvasResourceProvider::currentCompositeOp() const
{
return m_resourceManager->resource(CurrentCompositeOp).value<QString>();
}
void KisCanvasResourceProvider::slotPainting()
{
......
......@@ -56,7 +56,8 @@ public:
CurrentImage,
CurrentKritaNode,
CurrentPaintOpPreset,
CurrentGeneratorConfiguration
CurrentGeneratorConfiguration,
CurrentCompositeOp
};
......@@ -92,6 +93,9 @@ public:
KisFilterConfiguration* currentGeneratorConfiguration() const;
static const KoColorProfile* getScreenProfile(int screen = -1);
void setCurrentCompositeOp(const QString& compositeOp);
QString currentCompositeOp() const;
public slots:
......@@ -134,6 +138,7 @@ signals:
void sigDisplayProfileChanged(const KoColorProfile *);
void sigGeneratorConfigurationChanged(KisFilterConfiguration * generatorConfiguration);
void sigFGColorUsed(const KoColor&);
void sigCompositeOpChanged(const QString &);
private:
......
......@@ -40,6 +40,8 @@
#include <KoResourceSelector.h>
#include <KoResourceServerAdapter.h>
#include <kis_paint_device.h>
#include <kis_cmb_composite.h>
#include <kis_paintop_registry.h>
#include <kis_canvas_resource_provider.h>
#include <kis_painter.h>
......@@ -62,6 +64,7 @@
#include "ko_favorite_resource_manager.h"
#include <kis_paintop_presets_chooser_popup.h>
#include <QLabel>
KisPaintopBox::KisPaintopBox(KisView2 * view, QWidget *parent, const char * name)
: QWidget(parent)
......@@ -71,6 +74,8 @@ KisPaintopBox::KisPaintopBox(KisView2 * view, QWidget *parent, const char * name
, m_presetWidget(0)
, m_view(view)
, m_activePreset(0)
, m_compositeOp(0)
, m_previousNode(0)
{
Q_ASSERT(view != 0);
......@@ -101,12 +106,30 @@ KisPaintopBox::KisPaintopBox(KisView2 * view, QWidget *parent, const char * name
m_presetWidget->setIcon(KIcon("paintop_settings_01"));
m_presetWidget->setToolTip(i18n("Choose brush preset"));
m_presetWidget->setFixedSize(32, 32);
m_eraseModeButton = new QPushButton(this);
m_eraseModeButton->setIcon(KIcon("draw-eraser"));
m_eraseModeButton->setToolTip(i18n("Set eraser mode"));
m_eraseModeButton->setFixedSize(32, 32);
m_eraseModeButton->setCheckable(true);
m_eraseModeButton->setShortcut(Qt::Key_E);
connect(m_eraseModeButton, SIGNAL(toggled(bool)), this, SLOT(eraseModeToggled(bool)));
QLabel* labelMode = new QLabel(i18n("Mode: "), this);
labelMode->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
m_cmbComposite = new KisCmbComposite(this);
updateCompositeOpComboBox();
connect(m_cmbComposite, SIGNAL(activated(const QString&)), this, SLOT(slotSetCompositeMode(const QString&)));
m_layout = new QHBoxLayout(this);
m_layout->addWidget(m_cmbPaintops);
m_layout->addWidget(m_settingsWidget);
m_layout->addWidget(m_presetWidget);
m_layout->addWidget(labelMode);
m_layout->addWidget(m_cmbComposite);
m_layout->addWidget(m_eraseModeButton);
m_presetsPopup = new KisPaintOpPresetsPopup(m_resourceProvider);
m_settingsWidget->setPopupWidget(m_presetsPopup);
m_presetsPopup->switchDetached();
......@@ -131,6 +154,9 @@ KisPaintopBox::KisPaintopBox(KisView2 * view, QWidget *parent, const char * name
connect(m_presetsChooserPopup, SIGNAL(resourceSelected(KoResource*)),
this, SLOT(resourceSelected(KoResource*)));
connect(m_resourceProvider, SIGNAL(sigNodeChanged(const KisNodeSP)),
this, SLOT(nodeChanged(const KisNodeSP)));
}
KisPaintopBox::~KisPaintopBox()
......@@ -391,7 +417,7 @@ void KisPaintopBox::slotSaveActivePreset()
void KisPaintopBox::slotUpdatePreset()
{
m_optionWidget->writeConfiguration(const_cast<KisPaintOpSettings*>(m_activePreset->settings().data()));
m_optionWidget->writeConfiguration(const_cast<KisPaintOpSettings*>(m_activePreset->settings().data()));
}
void KisPaintopBox::slotSetupDefaultPreset(){
......@@ -411,4 +437,55 @@ void KisPaintopBox::slotSetupDefaultPreset(){
m_optionWidget->writeConfiguration(const_cast<KisPaintOpSettings*>( preset->settings().data() ));
}
void KisPaintopBox::nodeChanged(const KisNodeSP node)
{
// Deconnect colorspace change of previous node
if (m_previousNode) {
if (m_previousNode->paintDevice()) {
disconnect(m_previousNode->paintDevice().data(), SIGNAL(colorSpaceChanged(const KoColorSpace*)), this, SLOT(updateCompositeOpComboBox()));
}
}
// Reconnect colorspace change of node
m_previousNode = node;
if (m_previousNode && m_previousNode->paintDevice()) {
connect(m_previousNode->paintDevice().data(), SIGNAL(colorSpaceChanged(const KoColorSpace*)), SLOT(updateCompositeOpComboBox()));
}
updateCompositeOpComboBox();
}
void KisPaintopBox::eraseModeToggled(bool toggle)
{
if(toggle) {
m_resourceProvider->setCurrentCompositeOp(COMPOSITE_ERASE);
m_cmbComposite->setEnabled(false);
} else {
m_resourceProvider->setCurrentCompositeOp(m_cmbComposite->currentItem());
m_cmbComposite->setEnabled(true);
}
}
void KisPaintopBox::updateCompositeOpComboBox()
{
KisNodeSP node = m_resourceProvider->currentNode();
if (m_cmbComposite && node) {
KisPaintDeviceSP device = node->paintDevice();
if (device) {
QList<KoCompositeOp*> compositeOps = device->colorSpace()->compositeOps();
m_cmbComposite->setCompositeOpList(compositeOps);
if(m_cmbComposite->currentItem().isEmpty()){
}
if (m_compositeOp == 0 || compositeOps.indexOf(const_cast<KoCompositeOp*>(m_compositeOp)) < 0) {
m_compositeOp = device->colorSpace()->compositeOp(COMPOSITE_OVER);
}
m_cmbComposite->setCurrent(m_compositeOp);
m_cmbComposite->setEnabled(true);
} else {
m_cmbComposite->setEnabled(false);
}
}
}
#include "kis_paintop_box.moc"
......@@ -33,6 +33,7 @@
#include <kis_types.h>
#include <kis_paintop_settings.h>
class QPushButton;
class QString;
class QHBoxLayout;
......@@ -40,6 +41,7 @@ class KoID;
class KoColorSpace;
class KoResourceSelector;
class KoResource;
class KoCompositeOp;
class KisView2;
class KisCanvasResourceProvider;
......@@ -47,6 +49,7 @@ class KisPopupButton;
class KisPaintOpPresetsPopup;
class KisPaintOpPresetsChooserPopup;
class KisPaintOpSettingsWidget;
class KisCmbComposite;
/**
* This widget presents all paintops that a user can paint with.
......@@ -89,10 +92,14 @@ private:
KoID defaultPaintop(const KoInputDevice & inputDevice);
KisPaintOpPresetSP activePreset(const KoID & paintop, const KoInputDevice & inputDevice);
void updateCompositeOpComboBox();
private slots:
void updatePaintops();
void resourceSelected( KoResource * resource );
void nodeChanged(const KisNodeSP node);
void eraseModeToggled(bool toggle);
private:
......@@ -105,6 +112,8 @@ private:
KisPaintOpSettingsWidget* m_optionWidget;
KisPopupButton* m_settingsWidget;
KisPopupButton* m_presetWidget;
KisCmbComposite* m_cmbComposite;
QPushButton* m_eraseModeButton;
KisPaintOpPresetsPopup* m_presetsPopup;
KisPaintOpPresetsChooserPopup* m_presetsChooserPopup;
KisView2* m_view;
......@@ -113,6 +122,8 @@ private:
QList<KoID> m_paintops;
QList<KoID> m_displayedOps;
KisPaintOpPresetSP m_activePreset;
const KoCompositeOp* m_compositeOp;
KisNodeSP m_previousNode;
typedef QHash<KoInputDevice, KoID> InputDevicePaintopMap;
InputDevicePaintopMap m_currentID;
......
......@@ -68,14 +68,12 @@
KisToolPaint::KisToolPaint(KoCanvasBase * canvas, const QCursor & cursor)
: KisTool(canvas, cursor), m_previousNode(0)
: KisTool(canvas, cursor)
{
m_optionWidgetLayout = 0;
m_lbOpacity = 0;
m_slOpacity = 0;
m_lbComposite = 0;
m_cmbComposite = 0;
m_opacity = OPACITY_OPAQUE_U8;
m_compositeOp = 0;
......@@ -92,23 +90,8 @@ void KisToolPaint::resourceChanged(int key, const QVariant & v)
{
KisTool::resourceChanged(key, v);
switch (key) {
case(KisCanvasResourceProvider::CurrentKritaNode):
updateCompositeOpComboBox();
// Deconnect colorspace change of previous node
if (m_previousNode) {
if (m_previousNode->paintDevice()) {
disconnect(m_previousNode->paintDevice().data(), SIGNAL(colorSpaceChanged(const KoColorSpace*)), this, SLOT(updateCompositeOpComboBox()));
}
}
// Reconnect colorspace change of node
m_previousNode = currentNode();
if (m_previousNode && m_previousNode->paintDevice()) {
connect(m_previousNode->paintDevice().data(), SIGNAL(colorSpaceChanged(const KoColorSpace*)), SLOT(updateCompositeOpComboBox()));
}
break;
default:
; // Do nothing
if(KisCanvasResourceProvider::CurrentCompositeOp){
slotSetCompositeMode(v.toString());
}
connect(KisConfigNotifier::instance(), SIGNAL(configChanged()), SLOT(resetCursorStyle()));
......@@ -153,12 +136,6 @@ QWidget * KisToolPaint::createOptionWidget()
QWidget * optionWidget = new QWidget();
optionWidget->setObjectName(toolId());
m_lbComposite = new QLabel(i18n("Mode: "), optionWidget);
m_lbComposite->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
m_cmbComposite = new KisCmbComposite(optionWidget);
updateCompositeOpComboBox();
connect(m_cmbComposite, SIGNAL(activated(const QString&)), this, SLOT(slotSetCompositeMode(const QString&)));
m_lbOpacity = new QLabel(i18n("Opacity: "), optionWidget);
m_lbOpacity->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
m_slOpacity = new KisSliderSpinBox(optionWidget);
......@@ -176,9 +153,6 @@ QWidget * KisToolPaint::createOptionWidget()
m_optionWidgetLayout->setSpacing(1);
m_optionWidgetLayout->setMargin(0);
m_optionWidgetLayout->addWidget(m_lbComposite, 0, 0);
m_optionWidgetLayout->addWidget(m_cmbComposite, 0, 1);
m_optionWidgetLayout->addWidget(m_lbOpacity, 1, 0);
m_optionWidgetLayout->addWidget(m_slOpacity, 1, 1);
......@@ -238,27 +212,6 @@ void KisToolPaint::slotSetCompositeMode(const QString& compositeOp)
}
}
void KisToolPaint::updateCompositeOpComboBox()
{
if (m_cmbComposite && currentNode()) {
KisPaintDeviceSP device = currentNode()->paintDevice();
if (device) {
QList<KoCompositeOp*> compositeOps = device->colorSpace()->compositeOps();
m_cmbComposite->setCompositeOpList(compositeOps);
if (m_compositeOp == 0 || compositeOps.indexOf(const_cast<KoCompositeOp*>(m_compositeOp)) < 0) {
m_compositeOp = device->colorSpace()->compositeOp(COMPOSITE_OVER);
}
m_cmbComposite->setCurrent(m_compositeOp);
m_cmbComposite->setEnabled(true);
} else {
m_cmbComposite->setEnabled(false);
}
}
}
void KisToolPaint::slotPopupQuickHelp()
{
QWhatsThis::showText(QCursor::pos(), quickHelp());
......
......@@ -52,7 +52,6 @@ class QPoint;
class KoCanvasBase;
class KisCmbComposite;
class KisSliderSpinBox;
enum enumBrushMode {
......@@ -113,7 +112,6 @@ public slots:
private slots:
void updateCompositeOpComboBox();
void slotPopupQuickHelp();
void slotSetOpacity(int opacityPerCent);
void slotSetCompositeMode(const QString& compositeOp);
......@@ -134,9 +132,6 @@ private:
QLabel *m_lbOpacity;
KisSliderSpinBox *m_slOpacity;
QLabel *m_lbComposite;
KisCmbComposite *m_cmbComposite;
KisNodeSP m_previousNode;
bool m_supportOutline;
......
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