Commit 851b8fce authored by Halla Rempt's avatar Halla Rempt
Browse files

Yay! The base class for three-quarters of Krita's tools compiles again -- and I

don't think I've lost much functionality along the way. (Although, see 
http://wiki.koffice.org/index.php?title=Krita/ToolRefactor).

svn path=/trunk/koffice/; revision=603111
parent 1fb31db2
......@@ -75,7 +75,7 @@ set(kritaui_LIB_SRCS
# kis_paintop_box.cc # Needs to know about the active input device a lot
# kis_tool_freehand.cc
#kis_tool_non_paint.cc
#kis_tool_paint.cc
kis_tool_paint.cc
# kis_tool_shape.cc
# kis_birdeye_box.cc
# kis_selection_manager.cc
......
......@@ -29,27 +29,34 @@
#include <QGridLayout>
#include <QKeyEvent>
#include <QEvent>
#include <QVariant>
#include <kdebug.h>
#include <klocale.h>
#include <knuminput.h>
#include <kiconloader.h>
#include "KoColorSpace.h"
#include <KoShape.h>
#include <KoShapeManager.h>
#include <KoCanvasResourceProvider.h>
#include <KoColorSpace.h>
#include <KoPointerEvent.h>
#include <KoCanvasBase.h>
#include <kis_types.h>
#include <kis_global.h>
#include <kis_image.h>
#include "kis_global.h"
#include "kis_config.h"
#include "kis_cursor.h"
#include "kis_cmb_composite.h"
#include "kis_image.h"
#include "kis_int_spinbox.h"
#include "kis_paint_device.h"
#include "kis_dummy_shape.h"
KisToolPaint::KisToolPaint(KoCanvasBase * canvas)
: KoTool(canvas)
{
m_resourceProvider = 0;
m_optionWidget = 0;
m_optionWidgetLayout = 0;
......@@ -62,13 +69,11 @@ KisToolPaint::KisToolPaint(KoCanvasBase * canvas)
m_compositeOp = 0;
}
KisToolPaint::~KisToolPaint()
{
}
void KisToolPaint::paint(QPainter&, KoViewConverter &)
{
}
void KisToolPaint::activate(bool )
{
......@@ -83,10 +88,36 @@ void KisToolPaint::deactivate()
{
}
QWidget* KisToolPaint::createOptionWidget(QWidget* parent)
void KisToolPaint::resourceChanged( const KoCanvasResource & res )
{
if ( res.key == CURRENT_KIS_LAYER ) updateCompositeOpComboBox();
}
void KisToolPaint::paint(QPainter&, KoViewConverter &)
{
}
void KisToolPaint::mouseReleaseEvent( KoPointerEvent *e )
{
if(e->button() == Qt::MidButton)
{
KoCanvasResourceProvider * resourceProvider = 0;
if ( m_canvas && ( resourceProvider = m_canvas->resourceProvider() ) ) {
QVariant fg = resourceProvider->resource( FOREGROUND_COLOR );
if ( !fg.isValid() ) return;
QVariant bg = resourceProvider->resource( BACKGROUND_COLOR );
if ( !bg.isValid() ) return;
resourceProvider->setResource( FOREGROUND_COLOR, bg );
resourceProvider->setResource( BACKGROUND_COLOR, fg );
}
}
}
void KisToolPaint::createOptionWidget(QWidget* parent)
{
m_optionWidget = new QWidget(parent);
m_optionWidget->setWindowTitle(m_UIName);
m_lbOpacity = new QLabel(i18n("Opacity: "), m_optionWidget);
m_slOpacity = new KisIntSpinbox( m_optionWidget, "int_m_optionwidget");
......@@ -123,13 +154,8 @@ QWidget* KisToolPaint::createOptionWidget(QWidget* parent)
hLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed));
verticalLayout->addLayout(hLayout);
}
return m_optionWidget;
}
QWidget* KisToolPaint::optionWidget()
{
return m_optionWidget;
}
void KisToolPaint::addOptionWidgetLayout(QLayout *layout)
{
......@@ -161,48 +187,43 @@ void KisToolPaint::slotSetCompositeMode(const KoCompositeOp* compositeOp)
m_compositeOp = compositeOp;
}
QCursor KisToolPaint::cursor()
KisImageSP KisToolPaint::image() const
{
return m_cursor;
}
KoShapeManager * shapeManager = m_canvas->shapeManager();
if ( !shapeManager ) return 0;
void KisToolPaint::setCursor(const QCursor& cursor)
{
m_cursor = cursor;
KisDummyShape * imageShape = dynamic_cast<KisDummyShape *>( shapeManager->shapeAt(QPointF( 0, 0 )) );
kDebug() << "Current shape: " << imageShape << endl;
if ( !imageShape ) return 0;
// if (m_subject) {
// KisToolControllerInterface *controller = m_subject->toolController();
KisImageSP img = imageShape->image();
return img;
// if (controller && controller->currentTool() == this) {
// m_subject->canvasController()->setCanvasCursor(m_cursor);
// }
// }
}
void KisToolPaint::notifyModified() const
{
if (m_subject && m_subject->currentImg()) {
m_subject->currentImg()->setModified();
KisImageSP img = image();
if ( img ) {
img->setModified();
}
}
void KisToolPaint::updateCompositeOpComboBox()
{
if (m_optionWidget && m_subject) {
KisImageSP img = m_subject->currentImg();
if (img) {
KisPaintDeviceSP device = img->activeDevice();
KisImageSP img = image();
if (m_optionWidget && img) {
KisPaintDeviceSP device = img->activeDevice();
if (device) {
KoCompositeOpList compositeOps = device->colorSpace()->userVisiblecompositeOps();
m_cmbComposite->setCompositeOpList(compositeOps);
if (device) {
KoCompositeOpList compositeOps = device->colorSpace()->userVisiblecompositeOps();
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);
if (m_compositeOp == 0 || compositeOps.indexOf(const_cast<KoCompositeOp*>(m_compositeOp)) < 0) {
m_compositeOp = device->colorSpace()->compositeOp(COMPOSITE_OVER);
}
m_cmbComposite->setCurrent(m_compositeOp);
}
}
}
......
......@@ -32,6 +32,9 @@
#include <krita_export.h>
#include <kis_types.h>
#include <kis_image.h>
#include "kis_tool.h"
#include "KoCompositeOp.h"
......@@ -60,7 +63,8 @@ enum enumBrushMode {
};
class KRITAUI_EXPORT KisToolPaint
: public KoTool {
: public KoTool
{
Q_OBJECT
......@@ -68,35 +72,35 @@ public:
KisToolPaint(KoCanvasBase * canvas);
virtual ~KisToolPaint();
// KoTool Implementation.
public slots:
virtual void activate(bool temporary = false);
virtual void deactivate();
virtual void resourceChanged( const KoCanvasResource & res );
public:
virtual void paint(QPainter& gc, KoViewConverter &converter);
virtual void mousePressEvent( KoPointerEvent *event );
virtual void mouseDoubleClickEvent( KoPointerEvent *event );
virtual void mouseMoveEvent( KoPointerEvent *event );
virtual void mouseReleaseEvent( KoPointerEvent *event );
virtual void keyPressEvent(QKeyEvent *event);
virtual void keyReleaseEvent(QKeyEvent *event);
virtual void wheelEvent ( KoPointerEvent * event );
virtual QCursor cursor();
virtual void setCursor(const QCursor& cursor);
virtual void addOptionWidgetOption(QWidget *control, QWidget *label = 0);
protected:
/// @return the image wrapped in the dummy shape in the shape
/// manager. XXX: This is probably wrong!
KisImageSP image() const;
protected:
/// Call this to set the document modified
void notifyModified() const;
// Add the tool-specific layout to the default option widget's layout.
/// Add the tool-specific layout to the default option widget layout.
void addOptionWidgetLayout(QLayout *layout);
/// Add a widget and a label to the current option widget layout.
virtual void addOptionWidgetOption(QWidget *control, QWidget *label = 0);
virtual void createOptionWidget(QWidget* parent);
private:
......@@ -118,6 +122,7 @@ protected:
bool m_paintOutline;
private:
QCursor m_cursor;
QGridLayout *m_optionWidgetLayout;
......@@ -126,7 +131,6 @@ private:
KisIntSpinbox *m_slOpacity;
QLabel *m_lbComposite;
KisCmbComposite *m_cmbComposite;
KoCanvasResourceProvider * m_resourceProvider;
};
#endif // KIS_TOOL_PAINT_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