diff --git a/krita/plugins/extensions/modify_selection/dlg_feather_selection.cc b/krita/plugins/extensions/modify_selection/dlg_feather_selection.cc index 5d209113b5..c0a5706de1 100644 --- a/krita/plugins/extensions/modify_selection/dlg_feather_selection.cc +++ b/krita/plugins/extensions/modify_selection/dlg_feather_selection.cc @@ -1,104 +1,104 @@ /* * dlg_feather_selection.cc - part of Krita * * Copyright (c) 2009 Edward Apap * Copyright (c) 2013 Juan Palacios * * 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 "dlg_feather_selection.h" #include #include #include #include #include WdgFeatherSelection::WdgFeatherSelection(QWidget* parent, KisViewManager* view) : KisOperationUIWidget(i18n("Feather Selection"), parent) , m_radius(5) { Q_ASSERT(view); KisImageWSP image = view->image(); Q_ASSERT(image); m_resolution = image->yRes(); setupUi(this); spbRadius->setValue(m_radius); spbRadius->setFocus(); spbRadius->setVisible(true); spbRadiusDouble->setVisible(false); cmbUnit->addItems(KoUnit::listOfUnitNameForUi()); cmbUnit->setCurrentIndex(KoUnit(KoUnit::Pixel).indexInListForUi()); // ensure that both spinboxes request the same horizontal size KisSizeGroup *spbGroup = new KisSizeGroup(this); spbGroup->addWidget(spbRadius); spbGroup->addWidget(spbRadiusDouble); - connect(spbRadius, SIGNAL(valueChanged(int)), this, SLOT(slotRadiusChanged(int))); + connect(spbRadius, SIGNAL(valueChanged(double)), this, SLOT(slotRadiusChanged(double))); connect(spbRadiusDouble, SIGNAL(valueChanged(double)), this, SLOT(slotRadiusChanged(double))); connect(cmbUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUnitChanged(int))); } void WdgFeatherSelection::slotRadiusChanged(int radius) { slotRadiusChanged((double) radius); } void WdgFeatherSelection::slotRadiusChanged(double radius) { const KoUnit selectedUnit = KoUnit::fromListForUi(cmbUnit->currentIndex()); const double resRadius = (selectedUnit == KoUnit(KoUnit::Pixel)) ? radius : (radius * m_resolution); m_radius = qRound(selectedUnit.fromUserValue(resRadius)); } void WdgFeatherSelection::slotUnitChanged(int index) { updateRadiusUIValue(m_radius); const KoUnit selectedUnit = KoUnit::fromListForUi(index); if (selectedUnit != KoUnit(KoUnit::Pixel)) { spbRadius->setVisible(false); spbRadiusDouble->setVisible(true); } else { spbRadius->setVisible(true); spbRadiusDouble->setVisible(false); } } void WdgFeatherSelection::updateRadiusUIValue(double value) { const KoUnit selectedUnit = KoUnit::fromListForUi(cmbUnit->currentIndex()); if (selectedUnit != KoUnit(KoUnit::Pixel)) { spbRadiusDouble->blockSignals(true); spbRadiusDouble->setValue(selectedUnit.toUserValue(value / m_resolution)); spbRadiusDouble->blockSignals(false); } else { const int finalValue = (selectedUnit == KoUnit(KoUnit::Point)) ? qRound(value / m_resolution) : value; spbRadius->blockSignals(true); spbRadius->setValue(selectedUnit.toUserValue(finalValue)); spbRadius->blockSignals(false); } } void WdgFeatherSelection::getConfiguration(KisOperationConfiguration* config) { config->setProperty("radius", m_radius); } diff --git a/krita/plugins/tools/defaulttools/kis_tool_move.cc b/krita/plugins/tools/defaulttools/kis_tool_move.cc index b5ffa0b22b..04559d69f1 100644 --- a/krita/plugins/tools/defaulttools/kis_tool_move.cc +++ b/krita/plugins/tools/defaulttools/kis_tool_move.cc @@ -1,439 +1,387 @@ /* * Copyright (c) 1999 Matthias Elter * 1999 Michael Koch * 2002 Patrick Julien * 2004 Boudewijn Rempt * 2016 Michael Abrahams * * 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.h" #include -#include #include "kis_cursor.h" #include "kis_selection.h" #include "kis_canvas2.h" #include "kis_image.h" #include "kis_tool_utils.h" #include "kis_paint_layer.h" #include "strokes/move_stroke_strategy.h" #include "kis_tool_movetooloptionswidget.h" #include "strokes/move_selection_stroke_strategy.h" #include "kis_resources_snapshot.h" #include "kis_action_registry.h" KisToolMove::KisToolMove(KoCanvasBase * canvas) : KisTool(canvas, KisCursor::moveCursor()) { setObjectName("tool_move"); m_optionsWidget = 0; - m_moveToolMode = MoveSelectedLayer; m_moveInProgress = false; KisActionRegistry *actionRegistry = KisActionRegistry::instance(); m_actionMoveUp = actionRegistry->makeQAction("movetool-move-up", this); addAction("movetool-move-up", m_actionMoveUp); connect(m_actionMoveUp, &QAction::triggered, [&](){moveDiscrete(MoveDirection::Up);}); m_actionMoveDown = actionRegistry->makeQAction("movetool-move-down", this); addAction("movetool-move-down", m_actionMoveDown); connect(m_actionMoveDown, &QAction::triggered, [&](){moveDiscrete(MoveDirection::Down);}); m_actionMoveLeft = actionRegistry->makeQAction("movetool-move-left", this); addAction("movetool-move-left", m_actionMoveLeft); connect(m_actionMoveLeft, &QAction::triggered, [&](){moveDiscrete(MoveDirection::Left);}); m_actionMoveRight = actionRegistry->makeQAction("movetool-move-right", this); addAction("movetool-move-right", m_actionMoveRight); connect(m_actionMoveRight, &QAction::triggered, [&](){moveDiscrete(MoveDirection::Right);}); } KisToolMove::~KisToolMove() { endStroke(); } void KisToolMove::resetCursorStyle() { KisTool::resetCursorStyle(); overrideCursorIfNotEditable(); } void KisToolMove::moveDiscrete(MoveDirection direction) { if (mode() == KisTool::PAINT_MODE) return; // Don't interact with dragging setMode(KisTool::PAINT_MODE); KisNodeSP node; KisImageSP image = this->image(); KisResourcesSnapshotSP resources = new KisResourcesSnapshot(image, currentNode(), 0, this->canvas()->resourceManager()); KisSelectionSP selection = resources->activeSelection(); // Move current layer by default. if ((!node && !(node = resources->currentNode())) || !node->isEditable()) { return; } // If node has changed, end current stroke. if (m_strokeId && (node != m_currentlyProcessingNode)) { endStroke(); } /** * Begin a new stroke if necessary. */ if (!m_strokeId) { KisStrokeStrategy *strategy; KisPaintLayerSP paintLayer = dynamic_cast(node.data()); if (paintLayer && selection && !selection->isTotallyUnselected(image->bounds())) { strategy = new MoveSelectionStrokeStrategy(paintLayer, selection, image.data(), image->postExecutionUndoAdapter()); } else { strategy = new MoveStrokeStrategy(node, image.data(), image->postExecutionUndoAdapter()); } m_strokeId = image->startStroke(strategy); m_currentlyProcessingNode = node; m_accumulatedOffset = QPoint(); } - QPoint offset = direction == Up ? QPoint( 0, -m_moveStep) : - direction == Down ? QPoint( 0, m_moveStep) : - direction == Left ? QPoint(-m_moveStep, 0) : - QPoint( m_moveStep, 0) ; + int moveStep = m_optionsWidget->moveStep(); + QPoint offset = direction == Up ? QPoint( 0, -moveStep) : + direction == Down ? QPoint( 0, moveStep) : + direction == Left ? QPoint(-moveStep, 0) : + QPoint( moveStep, 0) ; image->addJob(m_strokeId, new MoveStrokeStrategy::Data(m_accumulatedOffset + offset)); m_accumulatedOffset += offset; m_moveInProgress = false; emit moveInProgressChanged(); setMode(KisTool::HOVER_MODE); } void KisToolMove::activate(ToolActivation toolActivation, const QSet &shapes) { KisTool::activate(toolActivation, shapes); - configGroup = KSharedConfig::openConfig()->group(toolId()); } void KisToolMove::paint(QPainter& gc, const KoViewConverter &converter) { Q_UNUSED(gc); Q_UNUSED(converter); } void KisToolMove::deactivate() { endStroke(); KisTool::deactivate(); } void KisToolMove::requestStrokeEnd() { endStroke(); } void KisToolMove::requestStrokeCancellation() { cancelStroke(); } void KisToolMove::beginPrimaryAction(KoPointerEvent *event) { - startAction(event, m_moveToolMode); + startAction(event, moveToolMode()); } void KisToolMove::continuePrimaryAction(KoPointerEvent *event) { continueAction(event); } void KisToolMove::endPrimaryAction(KoPointerEvent *event) { endAction(event); } void KisToolMove::beginAlternateAction(KoPointerEvent *event, AlternateAction action) { if (action == PickFgNode) { - MoveToolMode mode = m_moveToolMode; + MoveToolMode mode = moveToolMode(); if (mode == MoveSelectedLayer || mode == MoveGroup) { mode = MoveFirstLayer; } else if (mode == MoveFirstLayer) { mode = MoveSelectedLayer; } startAction(event, mode); } else if (action == PickFgImage) { startAction(event, MoveGroup); } else { KisTool::beginAlternateAction(event, action); } } void KisToolMove::continueAlternateAction(KoPointerEvent *event, AlternateAction action) { if (action == PickFgNode || action == PickFgImage) { continueAction(event); } else { KisTool::continueAlternateAction(event, action); } } void KisToolMove::endAlternateAction(KoPointerEvent *event, AlternateAction action) { if (action == PickFgNode || action == PickFgImage) { endAction(event); } else { KisTool::endAlternateAction(event, action); } } void KisToolMove::startAction(KoPointerEvent *event, MoveToolMode mode) { QPoint pos = convertToPixelCoord(event).toPoint(); m_dragStart = pos; m_moveInProgress = true; emit moveInProgressChanged(); KisNodeSP node; KisImageSP image = this->image(); KisResourcesSnapshotSP resources = new KisResourcesSnapshot(image, currentNode(), 0, this->canvas()->resourceManager()); KisSelectionSP selection = resources->activeSelection(); if (mode != MoveSelectedLayer) { bool wholeGroup = !selection && mode == MoveGroup; node = KisToolUtils::findNode(image->root(), pos, wholeGroup); } if ((!node && !(node = resources->currentNode())) || !node->isEditable()) { event->ignore(); return; } setMode(KisTool::PAINT_MODE); /** * If the target node has changed, the stroke should be * restarted. Otherwise just continue processing current node. */ if (m_strokeId) { if (node == m_currentlyProcessingNode) { return; } else { endStroke(); } } KisStrokeStrategy *strategy; KisPaintLayerSP paintLayer = dynamic_cast(node.data()); if (paintLayer && selection && !selection->isTotallyUnselected(image->bounds())) { strategy = new MoveSelectionStrokeStrategy(paintLayer, selection, image.data(), image->postExecutionUndoAdapter()); } else { strategy = new MoveStrokeStrategy(node, image.data(), image->postExecutionUndoAdapter()); } m_strokeId = image->startStroke(strategy); m_currentlyProcessingNode = node; m_accumulatedOffset = QPoint(); } void KisToolMove::continueAction(KoPointerEvent *event) { CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE); if (!m_strokeId) return; QPoint pos = convertToPixelCoord(event).toPoint(); pos = applyModifiers(event->modifiers(), pos); drag(pos); } void KisToolMove::endAction(KoPointerEvent *event) { CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE); setMode(KisTool::HOVER_MODE); if (!m_strokeId) return; QPoint pos = convertToPixelCoord(event).toPoint(); pos = applyModifiers(event->modifiers(), pos); drag(pos); m_accumulatedOffset += pos - m_dragStart; } void KisToolMove::drag(const QPoint& newPos) { KisImageWSP image = currentImage(); QPoint offset = m_accumulatedOffset + newPos - m_dragStart; image->addJob(m_strokeId, new MoveStrokeStrategy::Data(offset)); } void KisToolMove::endStroke() { if (!m_strokeId) return; KisImageWSP image = currentImage(); image->endStroke(m_strokeId); m_strokeId.clear(); m_currentlyProcessingNode.clear(); m_moveInProgress = false; emit moveInProgressChanged(); } void KisToolMove::cancelStroke() { if (!m_strokeId) return; KisImageWSP image = currentImage(); image->cancelStroke(m_strokeId); m_strokeId.clear(); m_currentlyProcessingNode.clear(); m_moveInProgress = false; emit moveInProgressChanged(); } QWidget* KisToolMove::createOptionWidget() { - m_optionsWidget = new MoveToolOptionsWidget(0); + if (!currentImage()) + return 0; + + m_optionsWidget = new MoveToolOptionsWidget(0, currentImage()->xRes(), toolId()); // See https://bugs.kde.org/show_bug.cgi?id=316896 QWidget *specialSpacer = new QWidget(m_optionsWidget); specialSpacer->setObjectName("SpecialSpacer"); specialSpacer->setFixedSize(0, 0); m_optionsWidget->layout()->addWidget(specialSpacer); m_optionsWidget->setFixedHeight(m_optionsWidget->sizeHint().height()); - - connect(m_optionsWidget->radioSelectedLayer, SIGNAL(toggled(bool)), - this, SLOT(slotWidgetRadioToggled(bool))); - connect(m_optionsWidget->radioFirstLayer, SIGNAL(toggled(bool)), - this, SLOT(slotWidgetRadioToggled(bool))); - connect(m_optionsWidget->radioGroup, SIGNAL(toggled(bool)), - this, SLOT(slotWidgetRadioToggled(bool))); - - connect(m_optionsWidget->sliderMoveStep, SIGNAL(valueChanged(int)), - this, SLOT(slotSetMoveStep(int))); - - - - // load config for correct radio button - MoveToolMode newMode = static_cast(configGroup.readEntry("moveToolMode", 0)); - if(newMode == MoveSelectedLayer) - m_optionsWidget->radioSelectedLayer->setChecked(true); - else if (newMode == MoveFirstLayer) - m_optionsWidget->radioFirstLayer->setChecked(true); - else - m_optionsWidget->radioGroup->setChecked(true); - - m_moveToolMode = newMode; // set the internal variable for calculations - - - // Keyboard shortcut move step - m_optionsWidget->sliderMoveStep->setRange(1, 50); - int moveStep = configGroup.readEntry("moveToolStep", 5); - m_optionsWidget->sliderMoveStep->setValue(moveStep); - m_moveStep = moveStep; - return m_optionsWidget; } -void KisToolMove::setMoveToolMode(KisToolMove::MoveToolMode newMode) -{ - m_moveToolMode = newMode; - configGroup.writeEntry("moveToolMode", static_cast(newMode)); -} - -void KisToolMove::slotSetMoveStep(int newMoveStep) -{ - m_moveStep = newMoveStep; - configGroup.writeEntry("moveToolStep", newMoveStep); -} - KisToolMove::MoveToolMode KisToolMove::moveToolMode() const { - return m_moveToolMode; + if (m_optionsWidget) + return m_optionsWidget->mode(); + return MoveSelectedLayer; } bool KisToolMove::moveInProgress() const { return m_moveInProgress; } -void KisToolMove::slotWidgetRadioToggled(bool checked) -{ - Q_UNUSED(checked); - QObject* from = sender(); - if(from == m_optionsWidget->radioSelectedLayer) - setMoveToolMode(MoveSelectedLayer); - else if(from == m_optionsWidget->radioFirstLayer) - setMoveToolMode(MoveFirstLayer); - else if(from == m_optionsWidget->radioGroup) - setMoveToolMode(MoveGroup); -} - QPoint KisToolMove::applyModifiers(Qt::KeyboardModifiers modifiers, QPoint pos) { QPoint adjustedPos = pos; if (modifiers & Qt::AltModifier || modifiers & Qt::ControlModifier) { if (qAbs(pos.x() - m_dragStart.x()) > qAbs(pos.y() - m_dragStart.y())) adjustedPos.setY(m_dragStart.y()); else adjustedPos.setX(m_dragStart.x()); } return adjustedPos; } diff --git a/krita/plugins/tools/defaulttools/kis_tool_move.h b/krita/plugins/tools/defaulttools/kis_tool_move.h index 239b445871..31aaa9ee8a 100644 --- a/krita/plugins/tools/defaulttools/kis_tool_move.h +++ b/krita/plugins/tools/defaulttools/kis_tool_move.h @@ -1,156 +1,150 @@ /* * Copyright (c) 1999 Matthias Elter * 1999 Michael Koch * 2003 Patrick Julien * * 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 #include #include #include #include #include #include #include #include -#include -#include class KoCanvasBase; class MoveToolOptionsWidget; class KisToolMove : public KisTool { Q_OBJECT Q_ENUMS(MoveToolMode); - Q_PROPERTY(MoveToolMode moveToolMode READ moveToolMode WRITE setMoveToolMode NOTIFY moveToolModeChanged); Q_PROPERTY(bool moveInProgress READ moveInProgress NOTIFY moveInProgressChanged); public: KisToolMove(KoCanvasBase * canvas); virtual ~KisToolMove(); public Q_SLOTS: virtual void activate(ToolActivation toolActivation, const QSet &shapes); void deactivate(); public Q_SLOTS: void requestStrokeEnd(); void requestStrokeCancellation(); protected Q_SLOTS: virtual void resetCursorStyle(); public: enum MoveToolMode { MoveSelectedLayer, MoveFirstLayer, MoveGroup }; enum MoveDirection { Up, Down, Left, Right }; void beginPrimaryAction(KoPointerEvent *event); void continuePrimaryAction(KoPointerEvent *event); void endPrimaryAction(KoPointerEvent *event); void beginAlternateAction(KoPointerEvent *event, AlternateAction action); void continueAlternateAction(KoPointerEvent *event, AlternateAction action); void endAlternateAction(KoPointerEvent *event, AlternateAction action); void startAction(KoPointerEvent *event, MoveToolMode mode); void continueAction(KoPointerEvent *event); void endAction(KoPointerEvent *event); virtual void paint(QPainter& gc, const KoViewConverter &converter); virtual QWidget* createOptionWidget(); + void updateUIUnit(int newUnit); MoveToolMode moveToolMode() const; bool moveInProgress() const; public Q_SLOTS: - void setMoveToolMode(MoveToolMode newMode); - void slotWidgetRadioToggled(bool checked); void moveDiscrete(MoveDirection direction); - void slotSetMoveStep(int newMoveStep); Q_SIGNALS: void moveToolModeChanged(); void moveInProgressChanged(); private: void drag(const QPoint& newPos); void cancelStroke(); QPoint applyModifiers(Qt::KeyboardModifiers modifiers, QPoint pos); private Q_SLOTS: void endStroke(); private: MoveToolOptionsWidget* m_optionsWidget; QPoint m_dragStart; QPoint m_accumulatedOffset; KisStrokeId m_strokeId; - MoveToolMode m_moveToolMode; bool m_moveInProgress; KisNodeSP m_currentlyProcessingNode; - KConfigGroup configGroup; - int m_moveStep; + + int m_resolution; QAction * m_actionMoveUp; QAction * m_actionMoveDown; QAction * m_actionMoveLeft; QAction * m_actionMoveRight; }; class KisToolMoveFactory : public KoToolFactoryBase { public: KisToolMoveFactory() : KoToolFactoryBase("KritaTransform/KisToolMove") { setToolTip(i18n("Move Tool")); setToolType(TOOL_TYPE_TRANSFORM); setActivationShapeId(KRITA_TOOL_ACTIVATION_ID); setPriority(11); setIconName(koIconNameCStr("krita_tool_move")); setShortcut(QKeySequence( Qt::Key_T)); } virtual ~KisToolMoveFactory() {} virtual KoToolBase * createTool(KoCanvasBase *canvas) { return new KisToolMove(canvas); } }; #endif // KIS_TOOL_MOVE_H_ diff --git a/krita/plugins/tools/defaulttools/kis_tool_movetooloptionswidget.cpp b/krita/plugins/tools/defaulttools/kis_tool_movetooloptionswidget.cpp index 603e4577ee..d02945d6ea 100644 --- a/krita/plugins/tools/defaulttools/kis_tool_movetooloptionswidget.cpp +++ b/krita/plugins/tools/defaulttools/kis_tool_movetooloptionswidget.cpp @@ -1,24 +1,119 @@ /* Copyright (C) 2012 Dan Leinir Turthra Jensen 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_movetooloptionswidget.h" +#include +#include -MoveToolOptionsWidget::MoveToolOptionsWidget(QWidget *parent) : QWidget(parent) { + +MoveToolOptionsWidget::MoveToolOptionsWidget(QWidget *parent, int resolution, QString toolId) + : QWidget(parent) + , m_resolution(resolution) +{ setupUi(this); + m_configGroup = KSharedConfig::openConfig()->group(toolId); + + + // load radio button + m_moveToolMode = static_cast(m_configGroup.readEntry("moveToolMode", 0)); + if(m_moveToolMode == KisToolMove::MoveSelectedLayer) + radioSelectedLayer->setChecked(true); + else if (m_moveToolMode == KisToolMove::MoveFirstLayer) + radioFirstLayer->setChecked(true); + else + radioGroup->setChecked(true); + + // Keyboard shortcut move step + m_moveStep = m_configGroup.readEntry("moveToolStep", 1); + m_moveStepUnit = m_configGroup.readEntry("moveToolUnit", KoUnit(KoUnit::Pixel).indexInListForUi()); + cmbUnit->addItems(KoUnit::listOfUnitNameForUi()); + cmbUnit->setCurrentIndex(m_moveStepUnit); + updateUIUnit(m_moveStepUnit); +} + +void MoveToolOptionsWidget::updateUIUnit(int newUnit) +{ + const KoUnit selectedUnit = KoUnit::fromListForUi(newUnit); + qreal valueForUI; + if (selectedUnit != KoUnit(KoUnit::Pixel)) { + spinMoveStep->setRange(0.0001, 10000.000); + spinMoveStep->setSingleStep(.1); + spinMoveStep->setDecimals(4); + valueForUI = selectedUnit.toUserValue((qreal)m_moveStep / (qreal)m_resolution); + } else { + spinMoveStep->setRange(1, 10000); + spinMoveStep->setSingleStep(1); + spinMoveStep->setDecimals(0); + valueForUI = m_moveStep; + } + + spinMoveStep->blockSignals(true); + spinMoveStep->setValue(valueForUI); + spinMoveStep->blockSignals(false); +} + +void MoveToolOptionsWidget::on_spinMoveStep_valueChanged(double UIMoveStep) +{ + const KoUnit selectedUnit = KoUnit::fromListForUi(m_moveStepUnit); + const double scaledUiMoveStep = (selectedUnit == KoUnit(KoUnit::Pixel)) ? + UIMoveStep : selectedUnit.fromUserValue(UIMoveStep * m_resolution); + m_moveStep = qRound(scaledUiMoveStep); + m_configGroup.writeEntry("moveToolStep", m_moveStep); +} + +void MoveToolOptionsWidget::on_cmbUnit_currentIndexChanged(int newUnit) +{ + m_moveStepUnit = newUnit; + updateUIUnit(newUnit); + m_configGroup.writeEntry("moveToolUnit", newUnit); +} + +void MoveToolOptionsWidget::on_radioSelectedLayer_toggled(bool checked) +{ + Q_UNUSED(checked); + setMoveToolMode(KisToolMove::MoveSelectedLayer); +} + +void MoveToolOptionsWidget::on_radioFirstLayer_toggled(bool checked) +{ + Q_UNUSED(checked); + setMoveToolMode(KisToolMove::MoveFirstLayer); +} + +void MoveToolOptionsWidget::on_radioGroup_toggled(bool checked) +{ + Q_UNUSED(checked); + setMoveToolMode(KisToolMove::MoveGroup); +} + +void MoveToolOptionsWidget::setMoveToolMode(KisToolMove::MoveToolMode newMode) +{ + m_moveToolMode = newMode; + m_configGroup.writeEntry("moveToolMode", static_cast(newMode)); +} + +KisToolMove::MoveToolMode MoveToolOptionsWidget::mode() +{ + return m_moveToolMode; +} + +int MoveToolOptionsWidget::moveStep() +{ + return m_moveStep; } diff --git a/krita/plugins/tools/defaulttools/kis_tool_movetooloptionswidget.h b/krita/plugins/tools/defaulttools/kis_tool_movetooloptionswidget.h index eff696658e..f9bb160c0e 100644 --- a/krita/plugins/tools/defaulttools/kis_tool_movetooloptionswidget.h +++ b/krita/plugins/tools/defaulttools/kis_tool_movetooloptionswidget.h @@ -1,32 +1,57 @@ /* Copyright (C) 2012 Dan Leinir Turthra Jensen 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_MOVETOOLOPTIONSWIDGET_H #define KIS_TOOL_MOVETOOLOPTIONSWIDGET_H #include "ui_wdgmovetool.h" +#include +#include "kis_tool_move.h" class MoveToolOptionsWidget : public QWidget, public Ui::WdgMoveTool { Q_OBJECT public: - MoveToolOptionsWidget(QWidget *parent); + MoveToolOptionsWidget(QWidget *parent, int resolution, QString toolId); + int moveStep(); + KisToolMove::MoveToolMode mode(); + +private Q_SLOTS: + void on_spinMoveStep_valueChanged(double UIMoveStep); + + void on_cmbUnit_currentIndexChanged(int newUnit); + + void on_radioSelectedLayer_toggled(bool checked); + + void on_radioFirstLayer_toggled(bool checked); + + void on_radioGroup_toggled(bool checked); + +private: + void updateUIUnit(int newUnit); + void setMoveToolMode(KisToolMove::MoveToolMode newMode); + int m_resolution; + int m_moveStep; + int m_moveStepUnit; + KisToolMove::MoveToolMode m_moveToolMode; + + KConfigGroup m_configGroup; }; #endif // KIS_TOOL_MOVETOOLOPTIONSWIDGET_H diff --git a/krita/plugins/tools/defaulttools/wdgmovetool.ui b/krita/plugins/tools/defaulttools/wdgmovetool.ui index 1c39e69c08..8357df5f89 100644 --- a/krita/plugins/tools/defaulttools/wdgmovetool.ui +++ b/krita/plugins/tools/defaulttools/wdgmovetool.ui @@ -1,90 +1,102 @@ WdgMoveTool 0 0 246 130 Selection Mode Move the layer that you have currently selected in the layerbox with its masks. Shortcut: ctrl-click. Move current layer true Move the first layer with visible content at the place where you click. This will also select that layer in the layerbox. Move layer with content false Move the group containing the first layer that contains visible content. Shortcut: ctrl-shift-click. Move the whole group Shortcut Move Distance - - - - Number of pixels to move after move shortcut keypress. - - + + + + 1 + + + 100000 + + + 1 + + + Number of pixels to move after move shortcut keypress. + + + + + KisSliderSpinBox QWidget
kis_slider_spin_box.h
1