Commit 00ae167f authored by Sven Langkamp's avatar Sven Langkamp
Browse files

move color darkness and opacity controls to a new canvas controls manager,...

move color darkness and opacity controls to a new canvas controls manager, making them available globally
BUG:318494
parent 5524e7bd
......@@ -118,6 +118,7 @@ set(kritaui_LIB_SRCS
kis_action.cpp
kis_action_manager.cpp
kis_view_plugin.cpp
kis_canvas_controls_manager.cpp
kisexiv2/kis_exif_io.cpp
kisexiv2/kis_exiv2.cpp
kisexiv2/kis_iptc_io.cpp
......
/*
* Copyright (c) 2003-2009 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2014 Sven Langkamp <sven.langkamp@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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_canvas_controls_manager.h"
#include <kactioncollection.h>
#include <kaction.h>
#include <KoCanvasResourceManager.h>
#include "kis_view2.h"
#include "kis_canvas2.h"
#include "kis_canvas_resource_provider.h"
#include <klocale.h>
const int STEP = 25;
KisCanvasControlsManager::KisCanvasControlsManager(KisView2 * view) : m_view(view)
{
}
KisCanvasControlsManager::~KisCanvasControlsManager()
{
}
void KisCanvasControlsManager::setup(KActionCollection* collection)
{
KAction *lighterColor = new KAction(i18n("Make brush color lighter"), collection);
lighterColor->setShortcut(Qt::Key_L);
collection->addAction("make_brush_color_lighter", lighterColor);
connect(lighterColor, SIGNAL(triggered()), SLOT(makeColorLighter()));
KAction *darkerColor = new KAction(i18n("Make brush color darker"), collection);
darkerColor->setShortcut(Qt::Key_K);
collection->addAction("make_brush_color_darker", darkerColor);
connect(darkerColor, SIGNAL(triggered()), SLOT(makeColorDarker()));
KAction *increaseOpacity = new KAction(i18n("Increase opacity"), collection);
increaseOpacity->setShortcut(Qt::Key_O);
collection->addAction("increase_opacity", increaseOpacity);
connect(increaseOpacity, SIGNAL(triggered()), SLOT(increaseOpacity()));
KAction *decreaseOpacity = new KAction(i18n("Decrease opacity"), collection);
decreaseOpacity->setShortcut(Qt::Key_I);
collection->addAction("decrease_opacity", decreaseOpacity);
connect(decreaseOpacity, SIGNAL(triggered()), SLOT(decreaseOpacity()));
}
void KisCanvasControlsManager::transformColor(int step)
{
KoColor color = m_view->canvasBase()->resourceManager()->resource(KoCanvasResourceManager::ForegroundColor).value<KoColor>();
QColor rgb = color.toQColor();
int h = 0, s = 0, v = 0;
rgb.getHsv(&h,&s,&v);
if ((v < 255) || ((s == 0) || (s == 255))) {
v += step;
v = qBound(0,v,255);
} else {
s += -step;
s = qBound(0,s,255);
}
rgb.setHsv(h,s,v);
color.fromQColor(rgb);
m_view->canvasBase()->resourceManager()->setResource(KoCanvasResourceManager::ForegroundColor, color);
}
void KisCanvasControlsManager::makeColorDarker()
{
transformColor(-STEP);
}
void KisCanvasControlsManager::makeColorLighter()
{
transformColor(STEP);
}
void KisCanvasControlsManager::stepAlpha(float step)
{
qreal alpha = m_view->canvasBase()->resourceManager()->resource(KisCanvasResourceProvider::Opacity).toDouble();
alpha += step;
alpha = qBound<qreal>(0.0, alpha, 1.0);
m_view->canvasBase()->resourceManager ()->setResource(KisCanvasResourceProvider::Opacity, alpha);
}
void KisCanvasControlsManager::increaseOpacity()
{
stepAlpha(0.1f);
}
void KisCanvasControlsManager::decreaseOpacity()
{
stepAlpha(-0.1f);
}
\ No newline at end of file
/*
* Copyright (c) 2003-2009 Boudewijn Rempt <boud@valdyas.org>
* Copyright (c) 2014 Sven Langkamp <sven.langkamp@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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KIS_CANVAS_CONTROLS_MANAGER_H
#define KIS_CANVAS_CONTROLS_MANAGER_H
#include <QObject>
class KisView2;
class KActionCollection;
class KisCanvasControlsManager: public QObject
{
Q_OBJECT
public:
KisCanvasControlsManager(KisView2 * view);
virtual ~KisCanvasControlsManager();
void setup(KActionCollection * collection);
private slots:
void makeColorLighter();
void makeColorDarker();
void increaseOpacity();
void decreaseOpacity();
private:
void transformColor(int step);
void stepAlpha(float step);
private:
KisView2 * m_view;
};
#endif // KIS_CANVAS_CONTROLS_MANAGER_H
......@@ -125,6 +125,7 @@
#include "ko_favorite_resource_manager.h"
#include "kis_action_manager.h"
#include "input/kis_input_profile_manager.h"
#include "kis_canvas_controls_manager.h"
class BlockingUserInputEventFilter : public QObject
......@@ -186,6 +187,7 @@ public:
delete viewConverter;
delete statusBar;
delete actionManager;
delete canvasControlsManager;
}
public:
......@@ -208,6 +210,7 @@ public:
KisZoomManager *zoomManager;
KisImageManager *imageManager;
KisGridManager *gridManager;
KisCanvasControlsManager *canvasControlsManager;
KisPerspectiveGridManager * perspectiveGridManager;
KisPaintingAssistantsManager *paintingAssistantManager;
BlockingUserInputEventFilter blockingEventFilter;
......@@ -808,6 +811,9 @@ void KisView2::createManagers()
m_d->paintingAssistantManager = new KisPaintingAssistantsManager(this);
m_d->paintingAssistantManager->setup(actionCollection());
m_d->canvas->addDecoration(m_d->paintingAssistantManager);
m_d->canvasControlsManager = new KisCanvasControlsManager(this);
m_d->canvasControlsManager->setup(actionCollection());
}
void KisView2::updateGUI()
......
......@@ -70,8 +70,6 @@
#include <kis_paintop.h>
#include <kis_paintop_preset.h>
const int STEP = 25;
KisToolPaint::KisToolPaint(KoCanvasBase * canvas, const QCursor & cursor)
: KisTool(canvas, cursor)
{
......@@ -86,36 +84,6 @@ KisToolPaint::KisToolPaint(KoCanvasBase * canvas, const QCursor & cursor)
KActionCollection *collection = this->canvas()->canvasController()->actionCollection();
if (!collection->action("make_brush_color_lighter")) {
KAction *lighterColor = new KAction(i18n("Make brush color lighter"), collection);
lighterColor->setShortcut(Qt::Key_L);
collection->addAction("make_brush_color_lighter", lighterColor);
}
if (!collection->action("make_brush_color_darker")) {
KAction *darkerColor = new KAction(i18n("Make brush color darker"), collection);
darkerColor->setShortcut(Qt::Key_K);
collection->addAction("make_brush_color_darker", darkerColor);
}
addAction("make_brush_color_lighter", dynamic_cast<KAction*>(collection->action("make_brush_color_lighter")));
addAction("make_brush_color_darker", dynamic_cast<KAction*>(collection->action("make_brush_color_darker")));
if (!collection->action("increase_opacity")) {
KAction *increaseOpacity = new KAction(i18n("Increase opacity"), collection);
increaseOpacity->setShortcut(Qt::Key_O);
collection->addAction("increase_opacity", increaseOpacity);
}
if (!collection->action("decrease_opacity")) {
KAction *increaseOpacity = new KAction(i18n("Decrease opacity"), collection);
increaseOpacity->setShortcut(Qt::Key_I);
collection->addAction("decrease_opacity", increaseOpacity);
}
addAction("decrease_opacity", dynamic_cast<KAction*>(collection->action("decrease_opacity")));
addAction("increase_opacity", dynamic_cast<KAction*>(collection->action("increase_opacity")));
if (!collection->action("increase_brush_size")) {
KAction *increaseBrushSize = new KAction(i18n("Increase Brush Size"), collection);
increaseBrushSize->setShortcut(Qt::Key_BracketRight);
......@@ -167,10 +135,6 @@ void KisToolPaint::canvasResourceChanged(int key, const QVariant& v)
void KisToolPaint::activate(ToolActivation toolActivation, const QSet<KoShape*> &shapes)
{
KisTool::activate(toolActivation, shapes);
connect(actions().value("make_brush_color_lighter"), SIGNAL(triggered()), SLOT(makeColorLighter()), Qt::UniqueConnection);
connect(actions().value("make_brush_color_darker"), SIGNAL(triggered()), SLOT(makeColorDarker()), Qt::UniqueConnection);
connect(actions().value("increase_opacity"), SIGNAL(triggered()), SLOT(increaseOpacity()), Qt::UniqueConnection);
connect(actions().value("decrease_opacity"), SIGNAL(triggered()), SLOT(decreaseOpacity()), Qt::UniqueConnection);
connect(actions().value("increase_brush_size"), SIGNAL(triggered()), SLOT(increaseBrushSize()), Qt::UniqueConnection);
connect(actions().value("decrease_brush_size"), SIGNAL(triggered()), SLOT(decreaseBrushSize()), Qt::UniqueConnection);
}
......@@ -446,55 +410,6 @@ KisToolPaint::NodePaintAbility KisToolPaint::nodePaintAbility()
return NONE;
}
void KisToolPaint::transformColor(int step)
{
KoColor color = canvas()->resourceManager()->resource(KoCanvasResourceManager::ForegroundColor).value<KoColor>();
QColor rgb = color.toQColor();
int h = 0, s = 0, v = 0;
rgb.getHsv(&h,&s,&v);
if ((v < 255) || ((s == 0) || (s == 255))) {
v += step;
v = qBound(0,v,255);
} else {
s += -step;
s = qBound(0,s,255);
}
rgb.setHsv(h,s,v);
color.fromQColor(rgb);
canvas()->resourceManager()->setResource(KoCanvasResourceManager::ForegroundColor, color);
}
void KisToolPaint::makeColorDarker()
{
transformColor(-STEP);
}
void KisToolPaint::makeColorLighter()
{
transformColor(STEP);
}
void KisToolPaint::stepAlpha(float step)
{
qreal alpha = canvas()->resourceManager()->resource(KisCanvasResourceProvider::Opacity).toDouble();
alpha += step;
alpha = qBound<qreal>(0.0, alpha, 1.0);
canvas()->resourceManager ()->setResource(KisCanvasResourceProvider::Opacity, alpha);
}
void KisToolPaint::increaseOpacity()
{
stepAlpha(0.1f);
}
void KisToolPaint::decreaseOpacity()
{
stepAlpha(-0.1f);
}
void KisToolPaint::increaseBrushSize()
{
int paintopSize = currentPaintOpPreset()->settings()->paintOpSize().width();
......
......@@ -143,12 +143,6 @@ private slots:
void slotPopupQuickHelp();
void slotSetOpacity(qreal opacity);
void makeColorLighter();
void makeColorDarker();
void increaseOpacity();
void decreaseOpacity();
void increaseBrushSize();
void decreaseBrushSize();
......@@ -166,11 +160,6 @@ protected:
QRectF m_oldOutlineRect;
bool m_toForegroundColor;
private:
void transformColor(int step);
void stepAlpha(float step);
private:
bool m_specialHoverModifier;
......
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