Index: branches/koffice/1.6/koffice/krita/plugins/tools/selectiontools/selection_tools.cc =================================================================== --- branches/koffice/1.6/koffice/krita/plugins/tools/selectiontools/selection_tools.cc (revision 610887) +++ branches/koffice/1.6/koffice/krita/plugins/tools/selectiontools/selection_tools.cc (revision 610888) @@ -1,75 +1,77 @@ /* * selection_tools.cc -- Part of Krita * * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) * * 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "selection_tools.h" #include "kis_tool_select_outline.h" #include "kis_tool_select_polygonal.h" #include "kis_tool_select_rectangular.h" #include "kis_tool_select_contiguous.h" #include "kis_tool_select_elliptical.h" #include "kis_tool_select_eraser.h" #include "kis_tool_select_brush.h" +#include "kis_tool_move_selection.h" typedef KGenericFactory SelectionToolsFactory; K_EXPORT_COMPONENT_FACTORY( kritaselectiontools, SelectionToolsFactory( "krita" ) ) SelectionTools::SelectionTools(QObject *parent, const char *name, const QStringList &) : KParts::Plugin(parent, name) { setInstance(SelectionToolsFactory::instance()); if ( parent->inherits("KisToolRegistry") ) { KisToolRegistry * r = dynamic_cast(parent); r->add(new KisToolSelectOutlineFactory()); r->add(new KisToolSelectPolygonalFactory()); r->add(new KisToolSelectRectangularFactory()); r->add(new KisToolSelectBrushFactory()); r->add(new KisToolSelectContiguousFactory()); r->add(new KisToolSelectEllipticalFactory()); r->add(new KisToolSelectEraserFactory()); + r->add(new KisToolMoveSelectionFactory()); } } SelectionTools::~SelectionTools() { } #include "selection_tools.moc" Index: branches/koffice/1.6/koffice/krita/plugins/tools/selectiontools/kis_tool_move_selection.cc =================================================================== --- branches/koffice/1.6/koffice/krita/plugins/tools/selectiontools/kis_tool_move_selection.cc (nonexistent) +++ branches/koffice/1.6/koffice/krita/plugins/tools/selectiontools/kis_tool_move_selection.cc (revision 610888) @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2006 Cyrille Berger + * + * 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_tool_move_selection.h" + +#include +#include +#include +#include +#include +#include +#include "kis_canvas_subject.h" +#include "kis_cursor.h" +#include "kis_image.h" +#include "kis_layer.h" +#include "kis_paint_layer.h" +#include "kis_paint_device.h" +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_move_event.h" +#include "kis_selection.h" +#include "kis_selection_manager.h" +#include "kis_undo_adapter.h" + +KisToolMoveSelection::KisToolMoveSelection() + : super(i18n("Move Selection Tool")) +{ + setName("tool_move_selection"); + m_subject = 0; + setCursor(KisCursor::moveCursor()); +} + +KisToolMoveSelection::~KisToolMoveSelection() +{ +} + +void KisToolMoveSelection::update(KisCanvasSubject *subject) +{ + m_subject = subject; + super::update(subject); +} + +void KisToolMoveSelection::buttonPress(KisButtonPressEvent *e) +{ + m_dragging = false; + if (m_subject && e->button() == QMouseEvent::LeftButton) { + QPoint pos = e->pos().floorQPoint(); + KisImageSP img = m_subject->currentImg(); + KisPaintLayerSP dev; + + if (!img || !(dev = dynamic_cast( img->activeLayer().data() ))) + return; + + m_dragStart = pos; + + if ( !dev->visible() || !dev->paintDevice()->hasSelection()) + return; + + m_dragging = true; + m_dragStart.setX(pos.x()); + m_dragStart.setY(pos.y()); + m_layerStart.setX(dev->x()); + m_layerStart.setY(dev->y()); + m_layerPosition = m_layerStart; + + } +} + +void KisToolMoveSelection::move(KisMoveEvent *e) +{ + if (m_subject && m_dragging) { + QPoint pos = e->pos().floorQPoint(); + if((e->state() & Qt::AltButton) || (e->state() & Qt::ControlButton)) { + if(fabs(pos.x() - m_dragStart.x()) > fabs(pos.y() - m_dragStart.y())) + pos.setY(m_dragStart.y()); + else + pos.setX(m_dragStart.x()); + } + + KisImageSP img = m_subject->currentImg(); + KisPaintLayerSP lay = dynamic_cast(m_subject->currentImg()->activeLayer().data()); + if(!lay) return; + KisSelectionSP dev = lay->paintDevice()->selection(); + + QRect rc; + + pos -= m_dragStart; // convert to delta + rc = dev->selectedRect(); + dev->setX(dev->getX() + pos.x()); + dev->setY(dev->getY() + pos.y()); + rc = rc.unite(dev->selectedRect()); + + m_layerPosition = QPoint(dev->getX(), dev->getY()); + m_dragStart = e->pos().floorQPoint(); + + lay->setDirty(rc); + } + +} + +void KisToolMoveSelection::buttonRelease(KisButtonReleaseEvent *e) +{ + if (m_subject && e->button() == QMouseEvent::LeftButton && m_dragging) { + KisImageSP img = m_subject->currentImg(); + if(!img) return; + KisPaintLayerSP lay = dynamic_cast(img->activeLayer().data()); + + if (lay->paintDevice()->hasSelection()) { + KisSelectionSP dev = lay->paintDevice()->selection(); +// drag(pos); + m_dragging = false; + + if (img->undo()) { + KCommand *cmd = dev->moveCommand(m_layerPosition.x(), m_layerPosition.y()); + Q_CHECK_PTR(cmd); + + KisUndoAdapter *adapter = img->undoAdapter(); + if (adapter) { + adapter->addCommand(cmd); + } else { + delete cmd; + } + } + img->setModified(); + } + } +} + +void KisToolMoveSelection::setup(KActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + m_action = new KRadioAction(i18n("&Move selection"), + "tool_move", + Qt::SHIFT+Qt::Key_V, + this, + SLOT(activate()), + collection, + name()); + m_action->setToolTip(i18n("Move the selection")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +#include "kis_tool_move_selection.moc" Property changes on: branches/koffice/1.6/koffice/krita/plugins/tools/selectiontools/kis_tool_move_selection.cc ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/x-c++src \ No newline at end of property Index: branches/koffice/1.6/koffice/krita/plugins/tools/selectiontools/kis_tool_move_selection.h =================================================================== --- branches/koffice/1.6/koffice/krita/plugins/tools/selectiontools/kis_tool_move_selection.h (nonexistent) +++ branches/koffice/1.6/koffice/krita/plugins/tools/selectiontools/kis_tool_move_selection.h (revision 610888) @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2006 Cyrille Berger + * + * 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_TOOL_MOVE_H_ +#define KIS_TOOL_MOVE_H_ + +#include "kis_tool_non_paint.h" +#include "kis_tool_factory.h" + +// XXX: Moving is not nearly smooth enough! +class KisToolMoveSelection : public KisToolNonPaint { + + typedef KisToolNonPaint super; + Q_OBJECT + +public: + KisToolMoveSelection(); + virtual ~KisToolMoveSelection(); + +public: + virtual void update(KisCanvasSubject *subject); + +public: + virtual void setup(KActionCollection *collection); + virtual enumToolType toolType() { return TOOL_SELECT; } + virtual Q_UINT32 priority() { return 10; } + + virtual void buttonPress(KisButtonPressEvent *e); + virtual void move(KisMoveEvent *e); + virtual void buttonRelease(KisButtonReleaseEvent *e); + +private: + KisCanvasSubject *m_subject; + QPoint m_dragStart; + QPoint m_layerStart; + QPoint m_layerPosition; + bool m_dragging; +}; + + +class KisToolMoveSelectionFactory : public KisToolFactory { + typedef KisToolFactory super; +public: + KisToolMoveSelectionFactory() : super() {}; + virtual ~KisToolMoveSelectionFactory(){}; + + virtual KisTool * createTool(KActionCollection * ac) { + KisTool * t = new KisToolMoveSelection(); + Q_CHECK_PTR(t); + t->setup(ac); + return t; + } + virtual KisID id() { return KisID("moveselection", i18n("Move Selection Tool")); } +}; + + + +#endif // KIS_TOOL_MOVE_H_ + Property changes on: branches/koffice/1.6/koffice/krita/plugins/tools/selectiontools/kis_tool_move_selection.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/x-chdr \ No newline at end of property Index: branches/koffice/1.6/koffice/krita/plugins/tools/selectiontools/Makefile.am =================================================================== --- branches/koffice/1.6/koffice/krita/plugins/tools/selectiontools/Makefile.am (revision 610887) +++ branches/koffice/1.6/koffice/krita/plugins/tools/selectiontools/Makefile.am (revision 610888) @@ -1,60 +1,55 @@ kde_services_DATA = kritaselectiontools.desktop # all_includes must remain last! INCLUDES = -I$(srcdir)/../../../sdk \ -I$(srcdir)/../../../core \ -I$(srcdir)/../../../kritacolor/ \ -I$(srcdir)/../../../ui \ -I$/../../../ui \ $(KOFFICE_INCLUDES) \ $(all_includes) -kritaselectiontools_la_SOURCES = \ - selection_tools.cc \ - kis_tool_select_rectangular.cc \ - kis_tool_select_brush.cc \ - kis_tool_select_eraser.cc \ - kis_tool_select_polygonal.cc \ - kis_tool_select_elliptical.cc \ - kis_tool_select_contiguous.cc \ - kis_tool_select_outline.cc +kritaselectiontools_la_SOURCES = kis_tool_move_selection.cc \ + kis_tool_select_brush.cc kis_tool_select_contiguous.cc kis_tool_select_elliptical.cc \ + kis_tool_select_eraser.cc kis_tool_select_outline.cc kis_tool_select_polygonal.cc \ + kis_tool_select_rectangular.cc selection_tools.cc # Install this plugin in the KDE modules directory kde_module_LTLIBRARIES = kritaselectiontools.la noinst_HEADERS = \ selection_tools.h \ kis_tool_select_outline.h \ kis_tool_select_polygonal.h \ kis_tool_select_rectangular.h \ kis_tool_select_brush.h \ kis_tool_select_eraser.h \ kis_tool_select_contiguous.h \ kis_tool_select_elliptical.h kritaselectiontools_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) kritaselectiontools_la_LIBADD = ../../../libkritacommon.la kritaselectiontools_la_METASOURCES = AUTO KDE_OPTIONS = nofinal kritapics_DATA = \ tool_rect_selection.png \ tool_eraser_selection.png \ tool_brush_selection.png \ tool_contiguous_selection.png \ tool_elliptical_selection.png \ tool_outline_selection.png \ tool_polygonal_selection.png \ tool_rectangular_selection_cursor.png \ tool_eraser_selection_cursor.png \ tool_brush_selection_cursor.png \ tool_contiguous_selection_cursor.png \ tool_elliptical_selection_cursor.png \ tool_outline_selection_cursor.png \ tool_polygonal_selection_cursor.png kritapicsdir = $(kde_datadir)/krita/pics