Commit 70988929 authored by Silvio Heinrich's avatar Silvio Heinrich

Added a slider for the "flow" option next to the opacity slider.

Also made sure that the contol elements in the toolbar get disabled when there is no use for them.
For example when a selection tool is used the preset buttons get disabled but
get enabled again when a painting tool is used.
parent 7239fea8
......@@ -73,6 +73,11 @@ KisToolLine::~KisToolLine()
{
}
int KisToolLine::flags() const
{
return KisTool::FLAG_USES_CUSTOM_COMPOSITEOP|KisTool::FLAG_USES_CUSTOM_PRESET;
}
QWidget* KisToolLine::createOptionWidget()
{
QWidget* widget = KisToolPaint::createOptionWidget();
......
......@@ -45,6 +45,8 @@ class KisToolLine : public KisToolPaint
public:
KisToolLine(KoCanvasBase * canvas);
virtual ~KisToolLine();
virtual int flags() const;
virtual void mousePressEvent(KoPointerEvent *event);
virtual void mouseMoveEvent(KoPointerEvent *event);
......
......@@ -149,6 +149,11 @@ KisToolMultihand::~KisToolMultihand()
{
}
int KisToolMultihand::flags() const
{
return KisTool::FLAG_USES_CUSTOM_COMPOSITEOP|KisTool::FLAG_USES_CUSTOM_PRESET;
}
void KisToolMultihand::initTransformations()
{
// mirror mode decide own number of brushes
......
......@@ -59,7 +59,7 @@ public:
KisToolMultihand(KoCanvasBase * canvas, const QCursor & cursor, const QString & transactionText);
virtual ~KisToolMultihand();
virtual int flags() const;
virtual void setDirty(const QRegion& region);
protected:
......
......@@ -165,6 +165,7 @@ set(kritaui_LIB_SRCS
widgets/kis_workspace_chooser.cpp
widgets/squeezedcombobox.cpp
widgets/kis_categorized_list_view.cpp
widgets/kis_widget_chooser.cpp
)
if(HAVE_OPENGL)
......
This diff is collapsed.
......@@ -41,6 +41,7 @@ class KoColorSpace;
class KoResourceSelector;
class KoResource;
class KoCompositeOp;
class KoCanvasController;
class KisView2;
class KisCanvasResourceProvider;
......@@ -49,8 +50,8 @@ class KisPaintOpPresetsPopup;
class KisPaintOpPresetsChooserPopup;
class KisPaintOpSettingsWidget;
class KisPaintOpListWidget;
class KisDoubleSliderSpinBox;
class KisCompositeOpComboBox;
class KisWidgetChooser;
/**
......@@ -66,6 +67,19 @@ class KisCompositeOpComboBox;
class KisPaintopBox : public QWidget
{
Q_OBJECT
enum {
ENABLE_PRESETS = 0x0001,
DISABLE_PRESETS = 0x0002,
ENABLE_COMPOSITEOP = 0x0004,
DISABLE_COMPOSITEOP = 0x0008,
ENABLE_OPACITY = 0x0010,
DISABLE_OPACITY = 0x0020,
ENABLE_FLOW = 0x0040,
DISABLE_FLOW = 0x0080,
ENABLE_ALL = 0x5555,
DISABLE_ALL = 0xAAAA
};
public:
KisPaintopBox(KisView2* view, QWidget* parent, const char* name);
......@@ -93,7 +107,10 @@ private:
KisPaintOpPresetSP activePreset(const KoID& paintOp);
void updateCompositeOp(QString compositeOpID);
void updatePaintops(const KoColorSpace* colorSpace);
void setWidgetState(int flags);
void setSliderValue(const QString& sliderID, qreal value);
void sliderChanged(int n);
private slots:
void slotNodeChanged(const KisNodeSP node);
void slotToggleEraseMode(bool checked);
......@@ -103,7 +120,9 @@ private slots:
void slotWatchPresetNameLineEdit(const QString& text);
void slotHorizontalMirrorChanged(bool value);
void slotVerticalMirrorChanged(bool value);
void slotOpacityChanged(qreal value);
void slotSlider1Changed();
void slotSlider2Changed();
void slotToolChanged(KoCanvasController* canvas, int toolId);
private:
KisCanvasResourceProvider* m_resourceProvider;
......@@ -120,7 +139,7 @@ private:
KisView2* m_view;
QPushButton* m_paletteButton;
KisPopupButton* m_workspaceWidget;
KisDoubleSliderSpinBox* m_sliderOpacity;
KisWidgetChooser* m_sliderChooser[2];
QMap<KoID,KisPaintOpSettingsWidget*> m_paintopOptionWidgets;
KisPaintOpPresetSP m_activePreset;
......
......@@ -364,6 +364,9 @@ KisView2::KisView2(KisDoc2 * doc, QWidget * parent)
connect(KoToolManager::instance(), SIGNAL(inputDeviceChanged(const KoInputDevice &)),
m_d->controlFrame->paintopBox(), SLOT(slotInputDeviceChanged(const KoInputDevice &)));
connect(KoToolManager::instance(), SIGNAL(changedTool(KoCanvasController*,int)),
m_d->controlFrame->paintopBox(), SLOT(slotToolChanged(KoCanvasController*,int)));
show();
......
......@@ -82,23 +82,22 @@ class KRITAUI_EXPORT KisTool
Q_OBJECT
public:
enum { FLAG_USES_CUSTOM_PRESET=0x01, FLAG_USES_CUSTOM_COMPOSITEOP=0x02 };
KisTool(KoCanvasBase * canvas, const QCursor & cursor);
virtual ~KisTool();
virtual int flags() const { return 0; }
void deleteSelection();
// KoToolBase Implementation.
public slots:
virtual void activate(ToolActivation toolActivation, const QSet<KoShape*> &shapes);
virtual void deactivate();
virtual void resourceChanged(int key, const QVariant & res);
protected:
virtual void mousePressEvent(KoPointerEvent *event);
virtual void mouseMoveEvent(KoPointerEvent *event);
virtual void mouseReleaseEvent(KoPointerEvent *event);
......@@ -139,6 +138,7 @@ protected:
/// Convert a pixel path into a view path
QPainterPath pixelToView(const QPainterPath &pixelPath) const;
/// Convert a pixel polygon into a view path
QPolygonF pixelToView(const QPolygonF &pixelPolygon) const;
/// Update the canvas for the given rectangle in image pixel coordinates.
......@@ -155,7 +155,6 @@ protected:
}
protected:
bool specialModifierActive();
virtual void gesture(const QPointF &offsetInDocPixels,
const QPointF &initialDocPoint);
......@@ -223,7 +222,6 @@ protected slots:
virtual void resetCursorStyle();
private slots:
void slotToggleFgBg();
void slotResetFgBg();
......
......@@ -109,6 +109,11 @@ KisToolFreehand::~KisToolFreehand()
delete m_painter;
}
int KisToolFreehand::flags() const
{
return KisTool::FLAG_USES_CUSTOM_COMPOSITEOP|KisTool::FLAG_USES_CUSTOM_PRESET;
}
void KisToolFreehand::deactivate()
{
if(mode() == PAINT_MODE)
......
......@@ -52,7 +52,7 @@ public:
KisToolFreehand(KoCanvasBase * canvas, const QCursor & cursor, const QString & transactionText);
virtual ~KisToolFreehand();
virtual int flags() const;
virtual void setDirty(const QRegion& region);
protected:
......
......@@ -107,6 +107,11 @@ KisToolPaint::~KisToolPaint()
{
}
int KisToolPaint::flags() const
{
return KisTool::FLAG_USES_CUSTOM_COMPOSITEOP;
}
void KisToolPaint::resourceChanged(int key, const QVariant& v)
{
KisTool::resourceChanged(key, v);
......
......@@ -68,6 +68,7 @@ class KRITAUI_EXPORT KisToolPaint
public:
KisToolPaint(KoCanvasBase * canvas, const QCursor & cursor);
virtual ~KisToolPaint();
virtual int flags() const;
protected:
......
......@@ -47,6 +47,11 @@ KisToolShape::~KisToolShape()
{
}
int KisToolShape::flags() const
{
return KisTool::FLAG_USES_CUSTOM_COMPOSITEOP|KisTool::FLAG_USES_CUSTOM_PRESET;
}
QWidget * KisToolShape::createOptionWidget()
{
QWidget * optionWidget = KisToolPaint::createOptionWidget();
......
......@@ -51,9 +51,9 @@ class KRITAUI_EXPORT KisToolShape : public KisToolPaint
public:
KisToolShape(KoCanvasBase * canvas, const QCursor & cursor);
virtual ~KisToolShape();
virtual int flags() const;
protected:
virtual QWidget * createOptionWidget();
KisPainter::FillStyle fillStyle();
......
/*
* Copyright (c) 2011 Silvio Heinrich <plassy@web.de>
*
* 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_widget_chooser.h"
#include <QGridLayout>
#include <QHBoxLayout>
#include <QToolButton>
#include <QApplication>
#include <QDesktopWidget>
#include <QFrame>
#include <QLabel>
#include <QButtonGroup>
#include <QStylePainter>
#include <QStyleOption>
KisWidgetChooser::KisWidgetChooser(QWidget* parent):
QFrame(parent)
{
QFrame::setFrameShape(QFrame::Panel);
QFrame::setFrameShadow(QFrame::Raised);
QFrame::setContentsMargins(1, 1, 1, 1);
m_acceptIcon = QIcon::fromTheme("list-add");
m_buttons = new QButtonGroup();
m_popup = new QFrame(0, Qt::Popup);
m_arrowButton = new QToolButton();
m_arrowButton->setIcon(arrowIcon());
m_arrowButton->setAutoRaise(true);
connect(m_arrowButton, SIGNAL(clicked(bool)), SLOT(slotButtonPressed()));
}
KisWidgetChooser::~KisWidgetChooser()
{
delete m_buttons;
}
QIcon KisWidgetChooser::arrowIcon()
{
QImage image(16, 16, QImage::Format_ARGB32);
image.fill(0);
QStylePainter painter(&image, this);
QStyleOption option;
option.rect = image.rect();
option.palette = palette();
option.state = QStyle::State_Enabled;
option.palette.setBrush(QPalette::ButtonText, Qt::black); // Force color to black
painter.setBrush(Qt::black);
painter.setPen(Qt::black);
painter.drawPrimitive(QStyle::PE_IndicatorArrowDown, option);
return QIcon(QPixmap::fromImage(image));
}
void KisWidgetChooser::addWidget(const QString& id, const QString& label, QWidget* widget)
{
if(id.isEmpty()) {
delete widget;
return;
}
removeWidget(id);
m_widgets.push_back(Data(id, widget, new QLabel(label)));
delete m_popup->layout();
m_popup->setLayout(createPopupLayout());
m_popup->adjustSize();
delete QWidget::layout();
QWidget::setLayout(createLayout());
}
QLayout* KisWidgetChooser::createLayout()
{
QHBoxLayout* layout = new QHBoxLayout();
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
for(Iterator i=m_widgets.begin(); i!=m_widgets.end(); ++i) {
if(i->choosen) {
layout->addWidget(i->label);
layout->addWidget(i->widget);
break;
}
}
layout->addWidget(m_arrowButton);
return layout;
}
QLayout* KisWidgetChooser::createPopupLayout()
{
QGridLayout* layout = new QGridLayout();
int row = 0;
int idx = 0;
QButtonGroup* group = new QButtonGroup();
QList<QAbstractButton*> buttons = m_buttons->buttons();
for(Iterator i=m_widgets.begin(); i!=m_widgets.end(); ++i) {
if(!i->choosen) {
if(row == buttons.size()) {
QToolButton* bn = new QToolButton();
bn->setIcon(m_acceptIcon);
bn->setAutoRaise(true);
buttons.push_back(bn);
}
layout->addWidget(i->label , row, 0);
layout->addWidget(i->widget , row, 1);
layout->addWidget(buttons[row], row, 2);
group->addButton(buttons[row], idx);
++row;
}
++idx;
}
for(int i=row; i<buttons.size(); ++i)
delete buttons[i];
delete m_buttons;
m_buttons = group;
connect(m_buttons, SIGNAL(buttonClicked(int)), SLOT(slotWidgetChoosen(int)));
return layout;
}
void KisWidgetChooser::removeWidget(const QString& id)
{
Q_ASSERT(m_widgets.contains(id));
Iterator data = qFind(m_widgets.begin(), m_widgets.end(), Data(id));
if(data != m_widgets.end()) {
if(!data->choosen) {
delete m_popup->layout();
m_popup->setLayout(createPopupLayout());
m_popup->adjustSize();
}
else delete QWidget::layout();
delete data->label;
delete data->widget;
m_widgets.erase(data);
}
}
QWidget* KisWidgetChooser::chooseWidget(const QString& id)
{
QWidget* choosenWidget = 0;
for(Iterator i=m_widgets.begin(); i!=m_widgets.end(); ++i) {
if(i->id == id) {
choosenWidget = i->widget;
i->choosen = true;
}
else i->choosen = false;
}
delete m_popup->layout();
m_popup->setLayout(createPopupLayout());
m_popup->adjustSize();
delete QWidget::layout();
QWidget::setLayout(createLayout());
return choosenWidget;
}
QWidget* KisWidgetChooser::getWidget(const QString& id) const
{
ConstIterator data = qFind(m_widgets.begin(), m_widgets.end(), Data(id));
if(data != m_widgets.end())
return data->widget;
return 0;
}
void KisWidgetChooser::showPopupWidget()
{
QSize popSize = m_popup->size();
QRect popupRect(QFrame::mapToGlobal(QPoint(0, QFrame::height())), popSize);
// Get the available geometry of the screen which contains this KisPopupButton
QRect screenRect = QApplication::desktop()->availableGeometry(this);
// Make sure the popup is not drawn outside the screen area
if(popupRect.right() > screenRect.right())
popupRect.translate(screenRect.right() - popupRect.right(), 0);
if(popupRect.left() < screenRect.left())
popupRect.translate(screenRect.left() - popupRect.left(), 0);
if(popupRect.bottom() > screenRect.bottom())
popupRect.translate(0, -popupRect.height());
m_popup->setGeometry(popupRect);
m_popup->show();
}
void KisWidgetChooser::slotButtonPressed()
{
showPopupWidget();
}
void KisWidgetChooser::slotWidgetChoosen(int index)
{
chooseWidget(m_widgets[index].id);
m_popup->hide();
}
/*
* Copyright (c) 2011 Silvio Heinrich <plassy@web.de>
*
* 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 H_KIS_WIDGET_CHOOSER_H_
#define H_KIS_WIDGET_CHOOSER_H_
#include <krita_export.h>
#include <QWidget>
#include <QList>
#include <QIcon>
#include <QFrame>
class QGridLayout;
class QHBoxLayout;
class QToolButton;
class QLabel;
class QButtonGroup;
class KRITAUI_EXPORT KisWidgetChooser: public QFrame
{
Q_OBJECT
struct Data
{
Data(const QString& ID):
id(ID), widget(0), label(0), choosen(false) { }
Data(const Data& d):
id(d.id), widget(d.widget), label(d.label), choosen(d.choosen) { }
Data(const QString& ID, QWidget* w, QLabel* l):
id(ID), widget(w), label(l), choosen(false) { }
friend bool operator == (const Data& a, const Data& b) {
return a.id == b.id;
}
QString id;
QWidget* widget;
QLabel* label;
bool choosen;
};
typedef QList<Data>::iterator Iterator;
typedef QList<Data>::const_iterator ConstIterator;
public:
KisWidgetChooser(QWidget* parent=0);
~KisWidgetChooser();
QWidget* chooseWidget(const QString& id);
void addWidget(const QString& id, const QString& label, QWidget* widget);
QWidget* getWidget(const QString& id) const;
template<class TWidget>
TWidget* addWidget(const QString& id, const QString& label) {
TWidget* widget = new TWidget();
addWidget(id, label, widget);
return widget;
}
template<class TWidget>
TWidget* getWidget(const QString& id) const {
return dynamic_cast<TWidget*>(getWidget(id));
}
void showPopupWidget();
private:
void removeWidget(const QString& id);
QLayout* createPopupLayout();
QLayout* createLayout();
QIcon arrowIcon();
protected slots:
void slotButtonPressed();
void slotWidgetChoosen(int index);
private:
QIcon m_acceptIcon;
QToolButton* m_arrowButton;
QButtonGroup* m_buttons;
QWidget* m_popup;
QString m_choosenID;
QList<Data> m_widgets;
};
#endif // H_KIS_WIDGET_CHOOSER_H_
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