diff --git a/libs/ui/input/kis_abstract_input_action.cpp b/libs/ui/input/kis_abstract_input_action.cpp index 149233dd50..561d327436 100644 --- a/libs/ui/input/kis_abstract_input_action.cpp +++ b/libs/ui/input/kis_abstract_input_action.cpp @@ -1,223 +1,223 @@ /* This file is part of the KDE project * Copyright (C) 2012 Arjen Hiemstra * * 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_abstract_input_action.h" #include #include #include #include class Q_DECL_HIDDEN KisAbstractInputAction::Private { public: QString id; QString name; QString description; QHash indexes; QPointF lastCursorPosition; - static KisInputManager* inputManager; + static KisInputManager *inputManager; }; KisInputManager *KisAbstractInputAction::Private::inputManager = 0; -KisAbstractInputAction::KisAbstractInputAction(const QString & id) +KisAbstractInputAction::KisAbstractInputAction(const QString &id) : d(new Private) { d->id = id; d->indexes.insert(i18n("Activate"), 0); } KisAbstractInputAction::~KisAbstractInputAction() { delete d; } void KisAbstractInputAction::activate(int shortcut) { Q_UNUSED(shortcut); } void KisAbstractInputAction::deactivate(int shortcut) { Q_UNUSED(shortcut); } void KisAbstractInputAction::begin(int shortcut, QEvent *event) { Q_UNUSED(shortcut); if (event) { d->lastCursorPosition = eventPosF(event); } } -void KisAbstractInputAction::inputEvent(QEvent* event) +void KisAbstractInputAction::inputEvent(QEvent *event) { if (event) { QPointF newPosition = eventPosF(event); cursorMoved(d->lastCursorPosition, newPosition); d->lastCursorPosition = newPosition; } } void KisAbstractInputAction::end(QEvent *event) { Q_UNUSED(event); } void KisAbstractInputAction::cursorMoved(const QPointF &lastPos, const QPointF &pos) { Q_UNUSED(lastPos); Q_UNUSED(pos); } bool KisAbstractInputAction::supportsHiResInputEvents() const { return false; } KisInputActionGroup KisAbstractInputAction::inputActionGroup(int shortcut) const { Q_UNUSED(shortcut); return ModifyingActionGroup; } KisInputManager* KisAbstractInputAction::inputManager() const { return Private::inputManager; } QString KisAbstractInputAction::name() const { return d->name; } QString KisAbstractInputAction::description() const { return d->description; } int KisAbstractInputAction::priority() const { return 0; } bool KisAbstractInputAction::canIgnoreModifiers() const { return false; } QHash< QString, int > KisAbstractInputAction::shortcutIndexes() const { return d->indexes; } QString KisAbstractInputAction::id() const { return d->id; } -void KisAbstractInputAction::setName(const QString& name) +void KisAbstractInputAction::setName(const QString &name) { d->name = name; } -void KisAbstractInputAction::setDescription(const QString& description) +void KisAbstractInputAction::setDescription(const QString &description) { d->description = description; } -void KisAbstractInputAction::setShortcutIndexes(const QHash< QString, int >& indexes) +void KisAbstractInputAction::setShortcutIndexes(const QHash< QString, int > &indexes) { d->indexes = indexes; } void KisAbstractInputAction::setInputManager(KisInputManager *manager) { Private::inputManager = manager; } bool KisAbstractInputAction::isShortcutRequired(int shortcut) const { Q_UNUSED(shortcut); return false; } - -QPoint KisAbstractInputAction::eventPos(const QEvent *event) { - +QPoint KisAbstractInputAction::eventPos(const QEvent *event) +{ if(!event) { return QPoint(); } switch (event->type()) { case QEvent::MouseMove: case QEvent::MouseButtonPress: + case QEvent::MouseButtonDblClick: case QEvent::MouseButtonRelease: return static_cast(event)->pos(); case QEvent::TabletMove: case QEvent::TabletPress: case QEvent::TabletRelease: return static_cast(event)->pos(); case QEvent::Wheel: return static_cast(event)->pos(); case QEvent::NativeGesture: return static_cast(event)->pos(); default: warnInput << "KisAbstractInputAction" << d->name << "tried to process event data from an unhandled event type" << event->type(); return QPoint(); } } - QPointF KisAbstractInputAction::eventPosF(const QEvent *event) { switch (event->type()) { case QEvent::MouseMove: case QEvent::MouseButtonPress: + case QEvent::MouseButtonDblClick: case QEvent::MouseButtonRelease: return static_cast(event)->localPos(); case QEvent::TabletMove: case QEvent::TabletPress: case QEvent::TabletRelease: return static_cast(event)->posF(); case QEvent::Wheel: return static_cast(event)->posF(); case QEvent::NativeGesture: return QPointF(static_cast(event)->pos()); default: warnInput << "KisAbstractInputAction" << d->name << "tried to process event data from an unhandled event type" << event->type(); return QPointF(); } } bool KisAbstractInputAction::isAvailable() const { return true; } diff --git a/libs/ui/input/kis_alternate_invocation_action.cpp b/libs/ui/input/kis_alternate_invocation_action.cpp index 0cb11249c3..e4d0064989 100644 --- a/libs/ui/input/kis_alternate_invocation_action.cpp +++ b/libs/ui/input/kis_alternate_invocation_action.cpp @@ -1,163 +1,162 @@ /* This file is part of the KDE project * Copyright (C) 2012 Arjen Hiemstra * * 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_alternate_invocation_action.h" #include #include #include #include #include "kis_input_manager.h" #include "kis_cursor.h" struct KisAlternateInvocationAction::Private { KisTool::ToolAction savedAction; }; KisAlternateInvocationAction::KisAlternateInvocationAction() : KisAbstractInputAction("Alternate Invocation") , m_d(new Private) { setName(i18n("Alternate Invocation")); setDescription(i18n("The Alternate Invocation action performs an alternate action with the current tool. For example, using the brush tool it picks a color from the canvas.")); QHash shortcuts; shortcuts.insert(i18n("Primary Mode"), PrimaryAlternateModeShortcut); shortcuts.insert(i18n("Secondary Mode"), SecondaryAlternateModeShortcut); shortcuts.insert(i18n("Tertiary Mode"), TertiaryAlternateModeShortcut); shortcuts.insert(i18n("Pick Foreground Color from Current Layer"), PickColorFgLayerModeShortcut); shortcuts.insert(i18n("Pick Background Color from Current Layer"), PickColorBgLayerModeShortcut); shortcuts.insert(i18n("Pick Foreground Color from Merged Image"), PickColorFgImageModeShortcut); shortcuts.insert(i18n("Pick Background Color from Merged Image"), PickColorBgImageModeShortcut); setShortcutIndexes(shortcuts); } KisAlternateInvocationAction::~KisAlternateInvocationAction() { } KisTool::ToolAction KisAlternateInvocationAction::shortcutToToolAction(int shortcut) { KisTool::ToolAction action = KisTool::Alternate_NONE; switch ((Shortcut)shortcut) { case PickColorFgLayerModeShortcut: action = KisTool::AlternatePickFgNode; break; case PickColorBgLayerModeShortcut: action = KisTool::AlternatePickBgNode; break; case PickColorFgImageModeShortcut: action = KisTool::AlternatePickFgImage; break; case PickColorBgImageModeShortcut: action = KisTool::AlternatePickBgImage; break; case PrimaryAlternateModeShortcut: action = KisTool::AlternateSecondary; break; case SecondaryAlternateModeShortcut: action = KisTool::AlternateThird; break; case TertiaryAlternateModeShortcut: action = KisTool::AlternateFourth; break; } return action; } void KisAlternateInvocationAction::activate(int shortcut) { KisTool::ToolAction action = shortcutToToolAction(shortcut); inputManager()->toolProxy()->activateToolAction(action); } void KisAlternateInvocationAction::deactivate(int shortcut) { KisTool::ToolAction action = shortcutToToolAction(shortcut); inputManager()->toolProxy()->deactivateToolAction(action); } int KisAlternateInvocationAction::priority() const { return 9; } void KisAlternateInvocationAction::begin(int shortcut, QEvent *event) { if (!event) return; KisAbstractInputAction::begin(shortcut, event); QMouseEvent targetEvent(QEvent::MouseButtonPress, eventPosF(event), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier); // There must be a better way m_d->savedAction = shortcutToToolAction(shortcut); inputManager()->toolProxy()->forwardEvent(KisToolProxy::BEGIN, m_d->savedAction, &targetEvent, event); } void KisAlternateInvocationAction::end(QEvent *event) { if (!event) return; Qt::KeyboardModifiers modifiers; switch (m_d->savedAction) { case KisTool::AlternatePickFgNode: modifiers = Qt::ControlModifier; break; case KisTool::AlternateThird: modifiers = Qt::ControlModifier | Qt::AltModifier; break; default: ; } QMouseEvent targetEvent = QMouseEvent(QEvent::MouseButtonRelease, eventPosF(event), Qt::LeftButton, Qt::LeftButton, modifiers); inputManager()->toolProxy()->forwardEvent(KisToolProxy::END, m_d->savedAction, &targetEvent, event); KisAbstractInputAction::end(event); } void KisAlternateInvocationAction::inputEvent(QEvent* event) { if (event && ((event->type() == QEvent::MouseMove) || (event->type() == QEvent::TabletMove))) { Qt::KeyboardModifiers modifiers; switch (m_d->savedAction) { case KisTool::AlternatePickFgNode: modifiers = Qt::ControlModifier; break; case KisTool::AlternateThird: modifiers = Qt::ControlModifier | Qt::AltModifier; break; default: modifiers = Qt::ShiftModifier; } QMouseEvent targetEvent(QEvent::MouseMove, eventPosF(event), Qt::LeftButton, Qt::LeftButton, modifiers); inputManager()->toolProxy()->forwardEvent(KisToolProxy::CONTINUE, m_d->savedAction, &targetEvent, event); } - }