diff --git a/dialogs/imagelib/transforms/kpTransformRotateDialog.cpp b/dialogs/imagelib/transforms/kpTransformRotateDialog.cpp index da33f14c..a82fb4fa 100644 --- a/dialogs/imagelib/transforms/kpTransformRotateDialog.cpp +++ b/dialogs/imagelib/transforms/kpTransformRotateDialog.cpp @@ -1,310 +1,310 @@ /* Copyright (c) 2003-2007 Clarence Dang All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define DEBUG_KP_TOOL_ROTATE 0 #include "kpTransformRotateDialog.h" #include "kpDefs.h" #include "document/kpDocument.h" #include "pixmapfx/kpPixmapFX.h" #include "tools/kpTool.h" #include "environments/dialogs/imagelib/transforms/kpTransformDialogEnvironment.h" #include "views/manager/kpViewManager.h" #include "kpLogCategories.h" #include #include #include #include #include #include #include #include #include #include #include #include #include // private static int kpTransformRotateDialog::s_lastWidth = -1, kpTransformRotateDialog::s_lastHeight = -1; // private static bool kpTransformRotateDialog::s_lastIsClockwise = true; int kpTransformRotateDialog::s_lastAngleCustom = 0; kpTransformRotateDialog::kpTransformRotateDialog (bool actOnSelection, kpTransformDialogEnvironment *_env, QWidget *parent) : kpTransformPreviewDialog (kpTransformPreviewDialog::AllFeatures, false/*don't reserve top row*/, actOnSelection ? i18nc ("@title:window", "Rotate Selection") : i18nc ("@title:window", "Rotate Image"), i18n ("After rotate:"), actOnSelection, _env, parent) { s_lastAngleCustom = 0; createDirectionGroupBox (); createAngleGroupBox (); if (s_lastWidth > 0 && s_lastHeight > 0) resize (s_lastWidth, s_lastHeight); slotAngleCustomRadioButtonToggled (m_angleCustomRadioButton->isChecked ()); slotUpdate (); } kpTransformRotateDialog::~kpTransformRotateDialog () { s_lastWidth = width (), s_lastHeight = height (); } // private void kpTransformRotateDialog::createDirectionGroupBox () { QGroupBox *directionGroupBox = new QGroupBox (i18n ("Direction"), mainWidget ()); addCustomWidget (directionGroupBox); QLabel *antiClockwisePixmapLabel = new QLabel (directionGroupBox); antiClockwisePixmapLabel->setPixmap (UserIcon ("image_rotate_anticlockwise")); QLabel *clockwisePixmapLabel = new QLabel (directionGroupBox); clockwisePixmapLabel->setPixmap (UserIcon ("image_rotate_clockwise")); m_antiClockwiseRadioButton = new QRadioButton (i18n ("Cou&nterclockwise"), directionGroupBox); m_clockwiseRadioButton = new QRadioButton (i18n ("C&lockwise"), directionGroupBox); m_antiClockwiseRadioButton->setChecked (!s_lastIsClockwise); m_clockwiseRadioButton->setChecked (s_lastIsClockwise); QGridLayout *directionLayout = new QGridLayout (directionGroupBox ); directionLayout->addWidget (antiClockwisePixmapLabel, 0, 0, Qt::AlignCenter); directionLayout->addWidget (clockwisePixmapLabel, 0, 1, Qt::AlignCenter); directionLayout->addWidget (m_antiClockwiseRadioButton, 1, 0, Qt::AlignCenter); directionLayout->addWidget (m_clockwiseRadioButton, 1, 1, Qt::AlignCenter); connect (m_antiClockwiseRadioButton, SIGNAL (toggled (bool)), this, SLOT (slotUpdate ())); connect (m_clockwiseRadioButton, SIGNAL (toggled (bool)), this, SLOT (slotUpdate ())); } // private void kpTransformRotateDialog::createAngleGroupBox () { QGroupBox *angleGroupBox = new QGroupBox (i18n ("Angle"), mainWidget ()); addCustomWidget (angleGroupBox); m_angle90RadioButton = new QRadioButton (i18n ("90 °rees"), angleGroupBox); m_angle180RadioButton = new QRadioButton (i18n ("180 d&egrees"), angleGroupBox); m_angle270RadioButton = new QRadioButton (i18n ("270 de&grees"), angleGroupBox); m_angleCustomRadioButton = new QRadioButton (i18n ("C&ustom:"), angleGroupBox); m_angleCustomInput = new QSpinBox; m_angleCustomInput->setMinimum(-359); m_angleCustomInput->setMaximum(+359); m_angleCustomInput->setValue(s_lastAngleCustom); QLabel *degreesLabel = new QLabel (i18n ("degrees"), angleGroupBox); m_angleCustomRadioButton->setChecked (true); QGridLayout *angleLayout = new QGridLayout (angleGroupBox ); angleLayout->addWidget (m_angle90RadioButton, 0, 0, 1, 3); angleLayout->addWidget (m_angle180RadioButton, 1, 0, 1, 3); angleLayout->addWidget (m_angle270RadioButton, 2, 0, 1, 3); angleLayout->addWidget (m_angleCustomRadioButton, 3, 0); angleLayout->addWidget (m_angleCustomInput, 3, 1); angleLayout->addWidget (degreesLabel, 3, 2); angleLayout->setColumnStretch (1, 2); // Stretch Custom Angle Input connect (m_angle90RadioButton, SIGNAL (toggled (bool)), this, SLOT (slotUpdate ())); connect (m_angle180RadioButton, SIGNAL (toggled (bool)), this, SLOT (slotUpdate ())); connect (m_angle270RadioButton, SIGNAL (toggled (bool)), this, SLOT (slotUpdate ())); connect (m_angleCustomRadioButton, SIGNAL (toggled (bool)), this, SLOT (slotAngleCustomRadioButtonToggled (bool))); connect (m_angleCustomRadioButton, SIGNAL (toggled (bool)), this, SLOT (slotUpdate ())); connect (m_angleCustomInput, SIGNAL (valueChanged (int)), this, SLOT (slotUpdate ())); } // public virtual [base kpTransformPreviewDialog] bool kpTransformRotateDialog::isNoOp () const { return (angle () == 0); } // public int kpTransformRotateDialog::angle () const { int retAngle; if (m_angle90RadioButton->isChecked ()) retAngle = 90; else if (m_angle180RadioButton->isChecked ()) retAngle = 180; else if (m_angle270RadioButton->isChecked ()) retAngle = 270; else // if (m_angleCustomRadioButton->isChecked ()) retAngle = m_angleCustomInput->value (); if (m_antiClockwiseRadioButton->isChecked ()) retAngle *= -1; if (retAngle < 0) retAngle += ((0 - retAngle) / 360 + 1) * 360; if (retAngle >= 360) retAngle -= ((retAngle - 360) / 360 + 1) * 360; return retAngle; } // private virtual [base kpTransformPreviewDialog] QSize kpTransformRotateDialog::newDimensions () const { QMatrix matrix = kpPixmapFX::rotateMatrix (m_oldWidth, m_oldHeight, angle ()); QRect rect = matrix.mapRect (QRect (0, 0, m_oldWidth, m_oldHeight)); return rect.size (); } // private virtual [base kpTransformPreviewDialog] QImage kpTransformRotateDialog::transformPixmap (const QImage &image, int targetWidth, int targetHeight) const { return kpPixmapFX::rotate (image, angle (), m_environ->backgroundColor (m_actOnSelection), targetWidth, targetHeight); } // private slot void kpTransformRotateDialog::slotAngleCustomRadioButtonToggled (bool isChecked) { m_angleCustomInput->setEnabled (isChecked); if (isChecked) m_angleCustomInput->setFocus(); } // private slot virtual [base kpTransformPreviewDialog] void kpTransformRotateDialog::slotUpdate () { s_lastIsClockwise = m_clockwiseRadioButton->isChecked (); s_lastAngleCustom = m_angleCustomInput->value (); kpTransformPreviewDialog::slotUpdate (); } // private slot virtual [base QDialog] void kpTransformRotateDialog::accept () { KLocalizedString message; QString caption, continueButtonText; if (document ()->selection ()) { if (!document ()->textSelection ()) { message = ki18n ("

Rotating the selection to %1x%2" " may take a substantial amount of memory." " This can reduce system" " responsiveness and cause other application resource" " problems.

" - "

Are you sure want to rotate the selection?

"); + "

Are you sure you want to rotate the selection?

"); caption = i18nc ("@title:window", "Rotate Selection?"); continueButtonText = i18n ("Rotat&e Selection"); } } else { message = ki18n ("

Rotating the image to %1x%2" " may take a substantial amount of memory." " This can reduce system" " responsiveness and cause other application resource" " problems.

" - "

Are you sure want to rotate the image?

"); + "

Are you sure you want to rotate the image?

"); caption = i18nc ("@title:window", "Rotate Image?"); continueButtonText = i18n ("Rotat&e Image"); } const int newWidth = newDimensions ().width (); const int newHeight = newDimensions ().height (); if (kpTool::warnIfBigImageSize (m_oldWidth, m_oldHeight, newWidth, newHeight, message.subs (newWidth).subs (newHeight).toString (), caption, continueButtonText, this)) { QDialog::accept (); } } diff --git a/dialogs/imagelib/transforms/kpTransformSkewDialog.cpp b/dialogs/imagelib/transforms/kpTransformSkewDialog.cpp index 81f2d884..440c9021 100644 --- a/dialogs/imagelib/transforms/kpTransformSkewDialog.cpp +++ b/dialogs/imagelib/transforms/kpTransformSkewDialog.cpp @@ -1,293 +1,293 @@ /* Copyright (c) 2003-2007 Clarence Dang All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define DEBUG_KP_TOOL_SKEW 0 #define DEBUG_KP_TOOL_SKEW_DIALOG 0 #include "dialogs/imagelib/transforms/kpTransformSkewDialog.h" #include #include #include #include #include #include #include #include #include #include "kpLogCategories.h" #include #include #include "kpDefs.h" #include "document/kpDocument.h" #include "pixmapfx/kpPixmapFX.h" #include "tools/kpTool.h" #include "environments/dialogs/imagelib/transforms/kpTransformDialogEnvironment.h" // private static int kpTransformSkewDialog::s_lastWidth = -1, kpTransformSkewDialog::s_lastHeight = -1; // private static int kpTransformSkewDialog::s_lastHorizontalAngle = 0, kpTransformSkewDialog::s_lastVerticalAngle = 0; kpTransformSkewDialog::kpTransformSkewDialog (bool actOnSelection, kpTransformDialogEnvironment *_env, QWidget *parent) : kpTransformPreviewDialog (kpTransformPreviewDialog::AllFeatures, false/*don't reserve top row*/, actOnSelection ? i18nc ("@title:window", "Skew Selection") : i18nc ("@title:window", "Skew Image"), i18n ("After skew:"), actOnSelection, _env, parent) { // Too confusing - disable for now s_lastHorizontalAngle = s_lastVerticalAngle = 0; createAngleGroupBox (); if (s_lastWidth > 0 && s_lastHeight > 0) resize (s_lastWidth, s_lastHeight); slotUpdate (); m_horizontalSkewInput->setFocus (); } kpTransformSkewDialog::~kpTransformSkewDialog () { s_lastWidth = width (), s_lastHeight = height (); } // private void kpTransformSkewDialog::createAngleGroupBox () { QGroupBox *angleGroupBox = new QGroupBox (i18n ("Angle"), mainWidget ()); addCustomWidget (angleGroupBox); QLabel *horizontalSkewPixmapLabel = new QLabel (angleGroupBox); horizontalSkewPixmapLabel->setPixmap (UserIcon ("image_skew_horizontal")); QLabel *horizontalSkewLabel = new QLabel (i18n ("&Horizontal:"), angleGroupBox); m_horizontalSkewInput = new QSpinBox; m_horizontalSkewInput->setValue(s_lastHorizontalAngle); m_horizontalSkewInput->setMinimum(-89); m_horizontalSkewInput->setMaximum(+89); QLabel *horizontalSkewDegreesLabel = new QLabel (i18n ("degrees"), angleGroupBox); QLabel *verticalSkewPixmapLabel = new QLabel (angleGroupBox); verticalSkewPixmapLabel->setPixmap (UserIcon ("image_skew_vertical")); QLabel *verticalSkewLabel = new QLabel (i18n ("&Vertical:"), angleGroupBox); m_verticalSkewInput = new QSpinBox; m_verticalSkewInput->setValue(s_lastVerticalAngle); m_verticalSkewInput->setMinimum(-89); m_verticalSkewInput->setMaximum(+89); QLabel *verticalSkewDegreesLabel = new QLabel (i18n ("degrees"), angleGroupBox); horizontalSkewLabel->setBuddy (m_horizontalSkewInput); verticalSkewLabel->setBuddy (m_verticalSkewInput); QGridLayout *angleLayout = new QGridLayout (angleGroupBox); angleLayout->addWidget (horizontalSkewPixmapLabel, 0, 0); angleLayout->addWidget (horizontalSkewLabel, 0, 1); angleLayout->addWidget (m_horizontalSkewInput, 0, 2, Qt::AlignVCenter); angleLayout->addWidget (horizontalSkewDegreesLabel, 0, 3); angleLayout->addWidget (verticalSkewPixmapLabel, 1, 0); angleLayout->addWidget (verticalSkewLabel, 1, 1); angleLayout->addWidget (m_verticalSkewInput, 1, 2, Qt::AlignVCenter); angleLayout->addWidget (verticalSkewDegreesLabel, 1, 3); connect (m_horizontalSkewInput, SIGNAL (valueChanged (int)), this, SLOT (slotUpdate ())); connect (m_verticalSkewInput, SIGNAL (valueChanged (int)), this, SLOT (slotUpdate ())); } // private virtual [base kpTransformPreviewDialog] QSize kpTransformSkewDialog::newDimensions () const { kpDocument *doc = document (); Q_ASSERT (doc); QMatrix skewMatrix = kpPixmapFX::skewMatrix (doc->image (), horizontalAngleForPixmapFX (), verticalAngleForPixmapFX ()); QRect skewRect = skewMatrix.mapRect (doc->rect (m_actOnSelection)); return QSize (skewRect.width (), skewRect.height ()); } // private virtual [base kpTransformPreviewDialog] QImage kpTransformSkewDialog::transformPixmap (const QImage &image, int targetWidth, int targetHeight) const { return kpPixmapFX::skew (image, horizontalAngleForPixmapFX (), verticalAngleForPixmapFX (), m_environ->backgroundColor (m_actOnSelection), targetWidth, targetHeight); } // private void kpTransformSkewDialog::updateLastAngles () { s_lastHorizontalAngle = horizontalAngle (); s_lastVerticalAngle = verticalAngle (); } // private slot virtual [base kpTransformPreviewDialog] void kpTransformSkewDialog::slotUpdate () { updateLastAngles (); kpTransformPreviewDialog::slotUpdate (); } // public int kpTransformSkewDialog::horizontalAngle () const { return m_horizontalSkewInput->value (); } // public int kpTransformSkewDialog::verticalAngle () const { return m_verticalSkewInput->value (); } // public static int kpTransformSkewDialog::horizontalAngleForPixmapFX (int hangle) { return -hangle; } // public static int kpTransformSkewDialog::verticalAngleForPixmapFX (int vangle) { return -vangle; } // public int kpTransformSkewDialog::horizontalAngleForPixmapFX () const { return kpTransformSkewDialog::horizontalAngleForPixmapFX (horizontalAngle ()); } // public int kpTransformSkewDialog::verticalAngleForPixmapFX () const { return kpTransformSkewDialog::verticalAngleForPixmapFX (verticalAngle ()); } // public virtual [base kpTransformPreviewDialog] bool kpTransformSkewDialog::isNoOp () const { return (horizontalAngle () == 0) && (verticalAngle () == 0); } // private slot virtual [base QDialog] void kpTransformSkewDialog::accept () { KLocalizedString message; QString caption, continueButtonText; if (document ()->selection ()) { if (!document ()->textSelection ()) { message = ki18n ("

Skewing the selection to %1x%2" " may take a substantial amount of memory." " This can reduce system" " responsiveness and cause other application resource" " problems.

" - "

Are you sure want to skew the selection?

"); + "

Are you sure you want to skew the selection?

"); caption = i18nc ("@title:window", "Skew Selection?"); continueButtonText = i18n ("Sk&ew Selection"); } } else { message = ki18n ("

Skewing the image to %1x%2" " may take a substantial amount of memory." " This can reduce system" " responsiveness and cause other application resource" " problems.

" - "

Are you sure want to skew the image?

"); + "

Are you sure you want to skew the image?

"); caption = i18nc ("@title:window", "Skew Image?"); continueButtonText = i18n ("Sk&ew Image"); } const int newWidth = newDimensions ().width (); const int newHeight = newDimensions ().height (); if (kpTool::warnIfBigImageSize (m_oldWidth, m_oldHeight, newWidth, newHeight, message.subs (newWidth).subs (newHeight).toString (), caption, continueButtonText, this)) { QDialog::accept (); } } diff --git a/mainWindow/kpMainWindow_Tools.cpp b/mainWindow/kpMainWindow_Tools.cpp index e8356cd3..270786e7 100644 --- a/mainWindow/kpMainWindow_Tools.cpp +++ b/mainWindow/kpMainWindow_Tools.cpp @@ -1,806 +1,806 @@ /* Copyright (c) 2003-2007 Clarence Dang Copyright (c) 2011 Martin Koller All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "mainWindow/kpMainWindow.h" #include "kpMainWindowPrivate.h" #include #include #include #include #include #include #include "kpLogCategories.h" #include #include "widgets/toolbars/kpColorToolBar.h" #include "commands/kpCommandHistory.h" #include "document/kpDocument.h" #include "layers/selections/image/kpImageSelectionTransparency.h" #include "tools/kpTool.h" #include "tools/kpToolAction.h" #include "tools/flow/kpToolBrush.h" #include "tools/flow/kpToolColorEraser.h" #include "tools/kpToolColorPicker.h" #include "tools/polygonal/kpToolCurve.h" #include "tools/selection/image/kpToolEllipticalSelection.h" #include "tools/rectangular/kpToolEllipse.h" #include "tools/flow/kpToolEraser.h" #include "tools/kpToolFloodFill.h" #include "tools/selection/image/kpToolFreeFormSelection.h" #include "tools/polygonal/kpToolLine.h" #include "tools/flow/kpToolPen.h" #include "tools/polygonal/kpToolPolygon.h" #include "tools/polygonal/kpToolPolyline.h" #include "tools/rectangular/kpToolRectangle.h" #include "tools/selection/image/kpToolRectSelection.h" #include "tools/rectangular/kpToolRoundedRectangle.h" #include "environments/tools/selection/kpToolSelectionEnvironment.h" #include "tools/flow/kpToolSpraycan.h" #include "tools/selection/text/kpToolText.h" #include "widgets/toolbars/kpToolToolBar.h" #include "widgets/toolbars/options/kpToolWidgetOpaqueOrTransparent.h" #include "tools/kpToolZoom.h" #include "commands/imagelib/transforms/kpTransformResizeScaleCommand.h" #include "kpViewScrollableContainer.h" #include "views/kpZoomedView.h" //--------------------------------------------------------------------- // private kpToolSelectionEnvironment *kpMainWindow::toolSelectionEnvironment () { if (!d->toolSelectionEnvironment) d->toolSelectionEnvironment = new kpToolSelectionEnvironment (this); return d->toolSelectionEnvironment; } //--------------------------------------------------------------------- // private kpToolEnvironment *kpMainWindow::toolEnvironment () { // It's fine to return a more complex environment than required. return toolSelectionEnvironment (); } //--------------------------------------------------------------------- // private void kpMainWindow::setupToolActions () { kpToolSelectionEnvironment *toolSelEnv = toolSelectionEnvironment (); kpToolEnvironment *toolEnv = toolEnvironment (); d->tools.append (d->toolFreeFormSelection = new kpToolFreeFormSelection (toolSelEnv, this)); d->tools.append (d->toolRectSelection = new kpToolRectSelection (toolSelEnv, this)); d->tools.append (d->toolEllipticalSelection = new kpToolEllipticalSelection (toolSelEnv, this)); d->tools.append (d->toolText = new kpToolText (toolSelEnv, this)); d->tools.append (d->toolLine = new kpToolLine (toolEnv, this)); d->tools.append (d->toolPen = new kpToolPen (toolEnv, this)); d->tools.append (d->toolEraser = new kpToolEraser (toolEnv, this)); d->tools.append (d->toolBrush = new kpToolBrush (toolEnv, this)); d->tools.append (d->toolFloodFill = new kpToolFloodFill (toolEnv, this)); d->tools.append (d->toolColorPicker = new kpToolColorPicker (toolEnv, this)); d->tools.append (d->toolColorEraser = new kpToolColorEraser (toolEnv, this)); d->tools.append (d->toolSpraycan = new kpToolSpraycan (toolEnv, this)); d->tools.append (d->toolRoundedRectangle = new kpToolRoundedRectangle (toolEnv, this)); d->tools.append (d->toolRectangle = new kpToolRectangle (toolEnv, this)); d->tools.append (d->toolPolygon = new kpToolPolygon (toolEnv, this)); d->tools.append (d->toolEllipse = new kpToolEllipse (toolEnv, this)); d->tools.append (d->toolPolyline = new kpToolPolyline (toolEnv, this)); d->tools.append (d->toolCurve = new kpToolCurve (toolEnv, this)); d->tools.append (d->toolZoom = new kpToolZoom (toolEnv, this)); KActionCollection *ac = actionCollection (); d->actionPrevToolOptionGroup1 = ac->addAction ("prev_tool_option_group_1"); d->actionPrevToolOptionGroup1->setText (i18n ("Previous Tool Option (Group #1)")); ac->setDefaultShortcuts (d->actionPrevToolOptionGroup1, kpTool::shortcutForKey (Qt::Key_1)); connect (d->actionPrevToolOptionGroup1, SIGNAL (triggered (bool)), SLOT (slotActionPrevToolOptionGroup1 ())); d->actionNextToolOptionGroup1 = ac->addAction ("next_tool_option_group_1"); d->actionNextToolOptionGroup1->setText (i18n ("Next Tool Option (Group #1)")); ac->setDefaultShortcuts (d->actionNextToolOptionGroup1, kpTool::shortcutForKey (Qt::Key_2)); connect (d->actionNextToolOptionGroup1, SIGNAL (triggered (bool)), SLOT (slotActionNextToolOptionGroup1 ())); d->actionPrevToolOptionGroup2 = ac->addAction ("prev_tool_option_group_2"); d->actionPrevToolOptionGroup2->setText (i18n ("Previous Tool Option (Group #2)")); ac->setDefaultShortcuts (d->actionPrevToolOptionGroup2, kpTool::shortcutForKey (Qt::Key_3)); connect (d->actionPrevToolOptionGroup2, SIGNAL (triggered (bool)), SLOT (slotActionPrevToolOptionGroup2 ())); d->actionNextToolOptionGroup2 = ac->addAction ("next_tool_option_group_2"); d->actionNextToolOptionGroup2->setText (i18n ("Next Tool Option (Group #2)")); ac->setDefaultShortcuts (d->actionNextToolOptionGroup2, kpTool::shortcutForKey (Qt::Key_4)); connect (d->actionNextToolOptionGroup2, SIGNAL (triggered (bool)), SLOT (slotActionNextToolOptionGroup2 ())); // // Implemented in this file (kpMainWindow_Tools.cpp), not // kpImageWindow_Image.cpp since they're really setting tool options. // d->actionDrawOpaque = ac->add ("image_draw_opaque"); d->actionDrawOpaque->setText (i18n ("&Draw Opaque")); connect (d->actionDrawOpaque, SIGNAL (triggered (bool)), SLOT (slotActionDrawOpaqueToggled ())); d->actionDrawColorSimilarity = ac->addAction ("image_draw_color_similarity"); d->actionDrawColorSimilarity->setText (i18n ("Draw With Color Similarity...")); connect (d->actionDrawColorSimilarity, SIGNAL (triggered (bool)), SLOT (slotActionDrawColorSimilarity ())); } //--------------------------------------------------------------------- // private void kpMainWindow::createToolBox () { d->toolToolBar = new kpToolToolBar(QLatin1String("Tool Box"), 2/*columns/rows*/, this); d->toolToolBar->setWindowTitle(i18n("Tool Box")); connect (d->toolToolBar, SIGNAL (sigToolSelected (kpTool *)), this, SLOT (slotToolSelected (kpTool *))); connect (d->toolToolBar, SIGNAL (toolWidgetOptionSelected ()), this, SLOT (updateToolOptionPrevNextActionsEnabled ())); connect (d->toolToolBar->toolWidgetOpaqueOrTransparent (), SIGNAL (isOpaqueChanged (bool)), SLOT (updateActionDrawOpaqueChecked ())); updateActionDrawOpaqueChecked (); foreach (kpTool *tool, d->tools) d->toolToolBar->registerTool(tool); // (from config file) readLastTool (); } //--------------------------------------------------------------------- // private void kpMainWindow::enableToolsDocumentActions (bool enable) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::enableToolsDocumentsAction(" << enable << ")"; #endif d->toolActionsEnabled = enable; if (enable && !d->toolToolBar->isEnabled ()) { kpTool *previousTool = d->toolToolBar->previousTool (); // select tool for enabled Tool Box if (previousTool) d->toolToolBar->selectPreviousTool (); else { if (d->lastToolNumber >= 0 && d->lastToolNumber < (int) d->tools.count ()) d->toolToolBar->selectTool (d->tools.at (d->lastToolNumber)); else d->toolToolBar->selectTool (d->toolPen); } } else if (!enable && d->toolToolBar->isEnabled ()) { // don't have a disabled Tool Box with a checked Tool d->toolToolBar->selectTool (0); } d->toolToolBar->setEnabled (enable); foreach (kpTool *tool, d->tools) { kpToolAction *action = tool->action(); if (!enable && action->isChecked()) action->setChecked(false); action->setEnabled(enable); } updateToolOptionPrevNextActionsEnabled (); updateActionDrawOpaqueEnabled (); } //--------------------------------------------------------------------- // private slot void kpMainWindow::updateToolOptionPrevNextActionsEnabled () { const bool enable = d->toolActionsEnabled; d->actionPrevToolOptionGroup1->setEnabled (enable && d->toolToolBar->shownToolWidget (0) && d->toolToolBar->shownToolWidget (0)->hasPreviousOption ()); d->actionNextToolOptionGroup1->setEnabled (enable && d->toolToolBar->shownToolWidget (0) && d->toolToolBar->shownToolWidget (0)->hasNextOption ()); d->actionPrevToolOptionGroup2->setEnabled (enable && d->toolToolBar->shownToolWidget (1) && d->toolToolBar->shownToolWidget (1)->hasPreviousOption ()); d->actionNextToolOptionGroup2->setEnabled (enable && d->toolToolBar->shownToolWidget (1) && d->toolToolBar->shownToolWidget (1)->hasNextOption ()); } //--------------------------------------------------------------------- // private slot void kpMainWindow::updateActionDrawOpaqueChecked () { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::updateActionDrawOpaqueChecked()"; #endif const bool drawOpaque = (d->toolToolBar->toolWidgetOpaqueOrTransparent ()->selectedRow () == 0); #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\tdrawOpaque=" << drawOpaque; #endif d->actionDrawOpaque->setChecked (drawOpaque); } //--------------------------------------------------------------------- // private void kpMainWindow::updateActionDrawOpaqueEnabled () { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::updateActionDrawOpaqueEnabled()"; #endif const bool enable = d->toolActionsEnabled; #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\tenable=" << enable << " tool=" << (tool () ? tool ()->objectName () : 0) << " (is selection=" << toolIsASelectionTool () << ")" << endl; #endif d->actionDrawOpaque->setEnabled (enable && toolIsASelectionTool ()); } //--------------------------------------------------------------------- // public QActionGroup *kpMainWindow::toolsActionGroup () { if (!d->toolsActionGroup) d->toolsActionGroup = new QActionGroup (this); return d->toolsActionGroup; } //--------------------------------------------------------------------- // public kpTool *kpMainWindow::tool () const { return d->toolToolBar ? d->toolToolBar->tool () : 0; } //--------------------------------------------------------------------- // public bool kpMainWindow::toolHasBegunShape () const { kpTool *currentTool = tool (); return (currentTool && currentTool->hasBegunShape ()); } //--------------------------------------------------------------------- // public bool kpMainWindow::toolIsASelectionTool (bool includingTextTool) const { kpTool *currentTool = tool (); return ((currentTool == d->toolFreeFormSelection) || (currentTool == d->toolRectSelection) || (currentTool == d->toolEllipticalSelection) || (currentTool == d->toolText && includingTextTool)); } //--------------------------------------------------------------------- // public bool kpMainWindow::toolIsTextTool () const { return (tool () == d->toolText); } //--------------------------------------------------------------------- // private void kpMainWindow::toolEndShape () { if (toolHasBegunShape ()) tool ()->endShapeInternal (); } //--------------------------------------------------------------------- // public kpImageSelectionTransparency kpMainWindow::imageSelectionTransparency () const { kpToolWidgetOpaqueOrTransparent *oot = d->toolToolBar->toolWidgetOpaqueOrTransparent (); Q_ASSERT (oot); return kpImageSelectionTransparency (oot->isOpaque (), backgroundColor (), d->colorToolBar->colorSimilarity ()); } //--------------------------------------------------------------------- // public void kpMainWindow::setImageSelectionTransparency (const kpImageSelectionTransparency &transparency, bool forceColorChange) { #if DEBUG_KP_MAIN_WINDOW && 1 qCDebug(kpLogMainWindow) << "kpMainWindow::setImageSelectionTransparency() isOpaque=" << transparency.isOpaque () << " color=" << (transparency.transparentColor ().isValid () ? (int *) transparency.transparentColor ().toQRgb () : 0) << " forceColorChange=" << forceColorChange << endl; #endif kpToolWidgetOpaqueOrTransparent *oot = d->toolToolBar->toolWidgetOpaqueOrTransparent (); Q_ASSERT (oot); d->settingImageSelectionTransparency++; oot->setOpaque (transparency.isOpaque ()); if (transparency.isTransparent () || forceColorChange) { d->colorToolBar->setColor (1, transparency.transparentColor ()); d->colorToolBar->setColorSimilarity (transparency.colorSimilarity ()); } d->settingImageSelectionTransparency--; } //--------------------------------------------------------------------- // public int kpMainWindow::settingImageSelectionTransparency () const { return d->settingImageSelectionTransparency; } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotToolSelected (kpTool *tool) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::slotToolSelected (" << tool << ")"; #endif kpTool *previousTool = d->toolToolBar ? d->toolToolBar->previousTool () : 0; if (previousTool) { disconnect (previousTool, SIGNAL (movedAndAboutToDraw (const QPoint &, const QPoint &, int, bool *)), this, SLOT (slotDragScroll (const QPoint &, const QPoint &, int, bool *))); disconnect (previousTool, SIGNAL (endedDraw (const QPoint &)), this, SLOT (slotEndDragScroll ())); disconnect (previousTool, SIGNAL (cancelledShape (const QPoint &)), this, SLOT (slotEndDragScroll ())); disconnect (previousTool, SIGNAL (userMessageChanged (const QString &)), this, SLOT (recalculateStatusBarMessage ())); disconnect (previousTool, SIGNAL (userShapePointsChanged (const QPoint &, const QPoint &)), this, SLOT (recalculateStatusBarShape ())); disconnect (previousTool, SIGNAL (userShapeSizeChanged (const QSize &)), this, SLOT (recalculateStatusBarShape ())); disconnect (d->colorToolBar, SIGNAL (colorsSwapped (const kpColor &, const kpColor &)), previousTool, SLOT (slotColorsSwappedInternal (const kpColor &, const kpColor &))); disconnect (d->colorToolBar, SIGNAL (foregroundColorChanged (const kpColor &)), previousTool, SLOT (slotForegroundColorChangedInternal (const kpColor &))); disconnect (d->colorToolBar, SIGNAL (backgroundColorChanged (const kpColor &)), previousTool, SLOT (slotBackgroundColorChangedInternal (const kpColor &))); disconnect (d->colorToolBar, SIGNAL (colorSimilarityChanged (double, int)), previousTool, SLOT (slotColorSimilarityChangedInternal (double, int))); } if (tool) { connect (tool, SIGNAL (movedAndAboutToDraw (const QPoint &, const QPoint &, int, bool *)), this, SLOT (slotDragScroll (const QPoint &, const QPoint &, int, bool *))); connect (tool, SIGNAL (endedDraw (const QPoint &)), this, SLOT (slotEndDragScroll ())); connect (tool, SIGNAL (cancelledShape (const QPoint &)), this, SLOT (slotEndDragScroll ())); connect (tool, SIGNAL (userMessageChanged (const QString &)), this, SLOT (recalculateStatusBarMessage ())); connect (tool, SIGNAL (userShapePointsChanged (const QPoint &, const QPoint &)), this, SLOT (recalculateStatusBarShape ())); connect (tool, SIGNAL (userShapeSizeChanged (const QSize &)), this, SLOT (recalculateStatusBarShape ())); recalculateStatusBar (); connect (d->colorToolBar, SIGNAL (colorsSwapped (const kpColor &, const kpColor &)), tool, SLOT (slotColorsSwappedInternal (const kpColor &, const kpColor &))); connect (d->colorToolBar, SIGNAL (foregroundColorChanged (const kpColor &)), tool, SLOT (slotForegroundColorChangedInternal (const kpColor &))); connect (d->colorToolBar, SIGNAL (backgroundColorChanged (const kpColor &)), tool, SLOT (slotBackgroundColorChangedInternal (const kpColor &))); connect (d->colorToolBar, SIGNAL (colorSimilarityChanged (double, int)), tool, SLOT (slotColorSimilarityChangedInternal (double, int))); saveLastTool (); } updateToolOptionPrevNextActionsEnabled (); updateActionDrawOpaqueEnabled (); } //--------------------------------------------------------------------- // private void kpMainWindow::readLastTool () { KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupTools); d->lastToolNumber = cfg.readEntry (kpSettingLastTool, -1); } //--------------------------------------------------------------------- // private int kpMainWindow::toolNumber () const { int number = 0; for (QList ::const_iterator it = d->tools.constBegin (); it != d->tools.constEnd (); ++it) { if (*it == tool ()) return number; number++; } return -1; } //--------------------------------------------------------------------- // private void kpMainWindow::saveLastTool () { int number = toolNumber (); if (number < 0 || number >= (int) d->tools.count ()) return; KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupTools); cfg.writeEntry (kpSettingLastTool, number); cfg.sync (); } //--------------------------------------------------------------------- // private bool kpMainWindow::maybeDragScrollingMainView () const { return (tool () && d->mainView && tool ()->viewUnderStartPoint () == d->mainView); } //--------------------------------------------------------------------- // private slot bool kpMainWindow::slotDragScroll (const QPoint &docPoint, const QPoint &docLastPoint, int zoomLevel, bool *scrolled) { Q_UNUSED(docPoint) Q_UNUSED(docLastPoint) #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::slotDragScroll() maybeDragScrolling=" << maybeDragScrollingMainView () << endl; #endif if (maybeDragScrollingMainView ()) { return d->scrollView->beginDragScroll(zoomLevel, scrolled); } else { return false; } } //--------------------------------------------------------------------- // private slot bool kpMainWindow::slotEndDragScroll () { // (harmless if haven't started drag scroll) return d->scrollView->endDragScroll (); } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotBeganDocResize () { toolEndShape (); recalculateStatusBarShape (); } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotContinuedDocResize (const QSize &) { recalculateStatusBarShape (); } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotCancelledDocResize () { recalculateStatusBar (); } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotEndedDocResize (const QSize &size) { #define DOC_RESIZE_COMPLETED() \ { \ d->docResizeToBeCompleted = false; \ recalculateStatusBar (); \ } // Prevent statusbar updates d->docResizeToBeCompleted = true; d->docResizeWidth = (size.width () > 0 ? size.width () : 1), d->docResizeHeight = (size.height () > 0 ? size.height () : 1); if (d->docResizeWidth == d->document->width () && d->docResizeHeight == d->document->height ()) { DOC_RESIZE_COMPLETED (); return; } // Blank status to avoid confusion if dialog comes up setStatusBarMessage (); setStatusBarShapePoints (); setStatusBarShapeSize (); if (kpTool::warnIfBigImageSize (d->document->width (), d->document->height (), d->docResizeWidth, d->docResizeHeight, i18n ("

Resizing the image to" " %1x%2 may take a substantial amount of memory." " This can reduce system" " responsiveness and cause other application resource" " problems.

" - "

Are you sure want to resize the" + "

Are you sure you want to resize the" " image?

", d->docResizeWidth, d->docResizeHeight), i18nc ("@title:window", "Resize Image?"), i18n ("R&esize Image"), this)) { d->commandHistory->addCommand ( new kpTransformResizeScaleCommand ( false/*doc, not sel*/, d->docResizeWidth, d->docResizeHeight, kpTransformResizeScaleCommand::Resize, commandEnvironment ())); saveDefaultDocSize (QSize (d->docResizeWidth, d->docResizeHeight)); } DOC_RESIZE_COMPLETED (); #undef DOC_RESIZE_COMPLETED } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotDocResizeMessageChanged (const QString &string) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::slotDocResizeMessageChanged(" << string << ") docResizeToBeCompleted=" << d->docResizeToBeCompleted << endl; #else (void) string; #endif if (d->docResizeToBeCompleted) return; recalculateStatusBarMessage (); } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotActionPrevToolOptionGroup1 () { if (!d->toolToolBar->shownToolWidget (0)) return; // We don't call toolEndShape() here because we want #23 in the file BUGS // to later work. d->toolToolBar->shownToolWidget (0)->selectPreviousOption (); updateToolOptionPrevNextActionsEnabled (); } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotActionNextToolOptionGroup1 () { if (!d->toolToolBar->shownToolWidget (0)) return; // We don't call toolEndShape() here because we want #23 in the file BUGS // to later work. d->toolToolBar->shownToolWidget (0)->selectNextOption (); updateToolOptionPrevNextActionsEnabled (); } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotActionPrevToolOptionGroup2 () { if (!d->toolToolBar->shownToolWidget (1)) return; // We don't call toolEndShape() here because we want #23 in the file BUGS // to later work. d->toolToolBar->shownToolWidget (1)->selectPreviousOption (); updateToolOptionPrevNextActionsEnabled (); } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotActionNextToolOptionGroup2 () { if (!d->toolToolBar->shownToolWidget (1)) return; // We don't call toolEndShape() here because we want #23 in the file BUGS // to later work. d->toolToolBar->shownToolWidget (1)->selectNextOption (); updateToolOptionPrevNextActionsEnabled (); } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotActionDrawOpaqueToggled () { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::slotActionDrawOpaqueToggled()"; #endif toolEndShape (); // TODO: How does this differ to setImageSelectionTransparency()? // ("kpToolWidgetBase::" is to access one overload shadowed by the override // of the other overload) d->toolToolBar->toolWidgetOpaqueOrTransparent ()->kpToolWidgetBase::setSelected ( (d->actionDrawOpaque->isChecked () ? 0/*row 0 = opaque*/ : 1/*row 1 = transparent*/), 0/*column*/); } //--------------------------------------------------------------------- // private slot void kpMainWindow::slotActionDrawColorSimilarity () { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::slotActionDrawColorSimilarity()"; #endif toolEndShape (); d->colorToolBar->openColorSimilarityDialog (); } //--------------------------------------------------------------------- // public slots #define SLOT_TOOL(toolName) \ void kpMainWindow::slotTool##toolName () \ { \ if (!d->toolToolBar) \ return; \ \ if (tool () == d->tool##toolName) \ return; \ \ d->toolToolBar->selectTool (d->tool##toolName); \ } SLOT_TOOL (RectSelection) SLOT_TOOL (EllipticalSelection) SLOT_TOOL (FreeFormSelection) SLOT_TOOL (Text) diff --git a/tools/kpTool.h b/tools/kpTool.h index 7d1d8866..92f9e874 100644 --- a/tools/kpTool.h +++ b/tools/kpTool.h @@ -1,466 +1,466 @@ /* Copyright (c) 2003-2007 Clarence Dang All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef KP_TOOL_H #define KP_TOOL_H #include #include #include #include #include #include "kpDefs.h" #ifdef Q_OS_WIN #include #undef environ // macro on win32 #endif class QFocusEvent; class QIcon; class QInputMethodEvent; class QKeyEvent; class QMouseEvent; class QImage; class QWheelEvent; class kpColor; class kpCommandHistory; class kpDocument; class kpView; class kpViewManager; class kpToolAction; class kpToolEnvironment; class kpToolToolBar; struct kpToolPrivate; // Base class for all tools. // REFACTOR: rearrange method order to make sense and reflect kpTool_*.cpp split. class kpTool : public QObject { Q_OBJECT public: // = user-visible name of the tool e.g. "Color Picker" // = user-visible description used for tooltips // e.g. "Lets you select a color from the image" // = optional shortcut key for switching to the tool, or 0 otherwise // e.g. Qt::Key_C // = internal QObject name (not user-visible) e.g. "tool_color_picker" // used for fetching the icon(), the name of the action() and // debug printing. kpTool (const QString &text, const QString &description, int key, kpToolEnvironment *environ, QObject *parent, const QString &name); virtual ~kpTool (); kpToolAction *action () const; QString text () const; static QString toolTipForTextAndShortcut (const QString &text, const QList &shortcut); QString toolTip () const; // Given a single , returns a shortcut with // (disabled when the user is editing text) and as an alternate, // +. static QList shortcutForKey (int key); static QRect neededRect (const QRect &rect, int lineWidth); static QImage neededPixmap (const QImage &image, const QRect &boundingRect); bool hasCurrentPoint () const; // Returns the position of the cursor relative to the topleft point of // the current view (viewUnderStartPoint() or viewUnderCursor() otherwise). // // If neither viewUnderStartPoint() nor viewUnderCursor() // (i.e. !hasCurrentPoint()), then it returns KP_INVALID_POINT. // // If is set (default), then it returns the position in the // document. This theoretically == m_currentPoint (when m_currentPoint // is defined) but I wouldn't bet on it. This function is useful when // m_currentPoint isn't necessarily defined (outside of beginDraw(),draw() // and hover()). // // If is not set, then it returns an unzoomed view coordinate. // // Keep in mind that if viewUnderStartPoint(), this can return coordinates // outside of the document/view. QPoint calculateCurrentPoint (bool zoomToDoc = true) const; private: // Only called by ctor to create action(). void initAction (); signals: void actionToolTipChanged(); public slots: // Call this when something below the mouse cursor may have changed // and/or if the view has moved relative to the cursor (as opposed to // the cursor moving relative to the view, which would trigger a // mouseMoveEvent and all would be well without such hacks) // e.g. when zooming or scrolling the view or when deleting a selection. // // This calls hover() or draw() to let the tool know. The Brush Tool // can then update the position of the Brush Cursor. The Selection // Tool can update the real cursor. The Line Tool can update the current // line. The statubar gets correct coordinates. etc. etc. void somethingBelowTheCursorChanged (); private: // Same as above except that you claim you know better than currentPoint() void somethingBelowTheCursorChanged (const QPoint ¤tPoint_, const QPoint ¤tViewPoint_); protected: int mouseButton () const; bool shiftPressed () const; bool controlPressed () const; bool altPressed () const; QPoint startPoint () const; QPoint currentPoint () const; QPoint currentViewPoint () const; QRect normalizedRect () const; QPoint lastPoint () const; public: // for kpMainWindow kpView *viewUnderStartPoint () const; protected: kpView *viewUnderCursor () const; public: // Called when the tool is selected. virtual void begin (); // Called when the tool is deselected. virtual void end (); // Returns true after begin() has been called but returns false after end() // after end() has been called. bool hasBegun () const; bool hasBegunDraw () const; virtual bool hasBegunShape () const; // Called when user double-left-clicks on a tool in the Tool Box. virtual void globalDraw (); // Called when the user clicks on a tool in the Tool Box even though it's // already the current tool (used by the selection tools to deselect). virtual void reselect (); signals: // emitted after beginDraw() has been called void beganDraw (const QPoint &point); // Emitted just before draw() is called in mouseMoveEvent(). Slots // connected to this signal should return in whether the // mouse pos may have changed. Used by drag scrolling. void movedAndAboutToDraw (const QPoint ¤tPoint, const QPoint &lastPoint, int zoomLevel, bool *scrolled); // emitted after endDraw() has been called void endedDraw (const QPoint &point); // emitted after cancelShape() has been called void cancelledShape (const QPoint &point); signals: // User clicked on the tool's action - i.e. select this tool void actionActivated(); protected: // (this method is called by kpTool just as it is needed - its value // is not cached, so it is allowed to return different things at // different times) // REFACTOR: Misleadingly named as it's also called in cancelShapeInternal(). // And it seems to be called in endShapeInternal() as well? virtual bool returnToPreviousToolAfterEndDraw () const { return false; } virtual bool careAboutModifierState () const { return false; } virtual bool careAboutColorsSwapped () const { return false; } virtual void beginDraw (); // mouse move without button pressed // (only m_currentPoint & m_currentViewPoint is defined) virtual void hover (const QPoint &point); // this is useful for "instant" tools like the Pen & Eraser virtual void draw (const QPoint &thisPoint, const QPoint &lastPoint, const QRect &normalizedRect); private: void drawInternal (); protected: // (m_mouseButton will not change from beginDraw()) virtual void cancelShape (); virtual void releasedAllButtons (); virtual void endDraw (const QPoint &thisPoint, const QRect &normalizedRect); // TODO: I think reimplementations of this should be calling this base // implementation, so that endDraw() happens before the custom // endShape() logic of the reimplementation. virtual void endShape (const QPoint &thisPoint = QPoint (), const QRect &normalizedRect = QRect ()) { endDraw (thisPoint, normalizedRect); } kpDocument *document () const; kpViewManager *viewManager () const; kpToolToolBar *toolToolBar () const; kpCommandHistory *commandHistory () const; kpToolEnvironment *environ () const; kpColor color (int which) const; kpColor foregroundColor () const; kpColor backgroundColor () const; double colorSimilarity () const; int processedColorSimilarity () const; protected slots: void slotColorsSwappedInternal (const kpColor &newForegroundColor, const kpColor &newBackgroundColor); void slotForegroundColorChangedInternal (const kpColor &color); void slotBackgroundColorChangedInternal (const kpColor &color); void slotColorSimilarityChangedInternal (double similarity, int processedSimilarity); protected slots: // TODO: there is no reason why these should be slots virtual void slotColorsSwapped (const kpColor & /*newForegroundColor*/, const kpColor & /*newBackgroundColor*/) {} virtual void slotForegroundColorChanged (const kpColor & /*color*/) {} virtual void slotBackgroundColorChanged (const kpColor & /*color*/) {} virtual void slotColorSimilarityChanged (double /*similarity*/, int /*processedSimilarity*/) {} protected: // (only valid in slots connected to the respective signals above) kpColor oldForegroundColor () const; kpColor oldBackgroundColor () const; double oldColorSimilarity () const; protected: // returns true if m_currentPoint <= 1 pixel away from m_lastPoint // or if there was no lastPoint bool currentPointNextToLast () const; // (includes diagonal adjacency) bool currentPointCardinallyNextToLast () const; // (only cardinally adjacent i.e. horiz & vert; no diag) // TODO: We should rename these. // These are accessed from kpTool logic and our friends, kpCommandHistory, // kpMainWindow, kpToolToolBar and kpView. public: void beginInternal (); void endInternal (); void beginDrawInternal (); void endDrawInternal (const QPoint &thisPoint, const QRect &normalizedRect, bool wantEndShape = false); void cancelShapeInternal (); // TODO: Who is actually calling endShapeInternal()? // Tools seem to call endShape() directly. void endShapeInternal (const QPoint &thisPoint = QPoint (), const QRect &normalizedRect = QRect ()); // // Mouse Events // public: // Note: _All_ events are forwarded from a kpView. // The existence of a kpView implies the existence of a kpDocument. // If you're reimplementing any of these, you probably don't know what // you're doing - reimplement begin(),beginDraw(),draw(),cancelShape(), // endDraw() etc. instead. virtual void mousePressEvent (QMouseEvent *e); virtual void mouseMoveEvent (QMouseEvent *e); virtual void mouseReleaseEvent (QMouseEvent *e); virtual void wheelEvent (QWheelEvent *e); // // Keyboard Events // protected: void seeIfAndHandleModifierKey (QKeyEvent *e); void arrowKeyPressDirection (const QKeyEvent *e, int *dx, int *dy); void seeIfAndHandleArrowKeyPress (QKeyEvent *e); bool isDrawKey (int key); void seeIfAndHandleBeginDrawKeyPress (QKeyEvent *e); void seeIfAndHandleEndDrawKeyPress (QKeyEvent *e); public: virtual void keyPressEvent (QKeyEvent *e); virtual void keyReleaseEvent (QKeyEvent *e); virtual void inputMethodEvent (QInputMethodEvent *) {} private: void keyUpdateModifierState (QKeyEvent *e); void notifyModifierStateChanged (); protected: virtual void setShiftPressed (bool pressed); virtual void setControlPressed (bool pressed); virtual void setAltPressed (bool pressed); // // Other Events - 1. View Events // public: // WARNING: Do not call this "event()" as our QObject parent has a // virtual function called that, that will pass us // QObject events. We only care about events forwarded by // kpView. // REFACTOR: rename mousePressEvent() -> viewMousePressEvent() etc. // to remind us that events are coming from the view - the tool // is not a visible object. virtual bool viewEvent (QEvent *e); public: virtual void focusInEvent (QFocusEvent *e); virtual void focusOutEvent (QFocusEvent *e); public: virtual void enterEvent (QEvent *e); virtual void leaveEvent (QEvent *e); // // Other Events - 2. Non-view Events // REFACTOR: Group methods under this. // protected: // 0 = left, 1 = right, -1 = other (none, left+right, mid) static int mouseButton (Qt::MouseButtons mouseButtons); public: static int calculateLength (int start, int end); // // User Notifications (Status Bar) // public: // Returns "(Left|Right) click to cancel." where Left or Right is chosen // depending on which one is the _opposite_ of static QString cancelUserMessage (int mouseButton); QString cancelUserMessage () const; QString userMessage () const; // WARNING: setUserMessage() will store a message different to , // in unspecified ways (e.g. the name of the tool, followed // by a colon and a space, will be prepended). userMessage() // will return this different string. void setUserMessage (const QString &userMessage = QString ()); QPoint userShapeStartPoint () const; QPoint userShapeEndPoint () const; void setUserShapePoints (const QPoint &startPoint = KP_INVALID_POINT, const QPoint &endPoint = KP_INVALID_POINT, bool setSize = true); QSize userShapeSize () const; int userShapeWidth () const; int userShapeHeight () const; void setUserShapeSize (const QSize &size = KP_INVALID_SIZE); void setUserShapeSize (int width, int height); signals: void userMessageChanged (const QString &userMessage); void userShapePointsChanged (const QPoint &startPoint = KP_INVALID_POINT, const QPoint &endPoint = KP_INVALID_POINT); void userShapeSizeChanged (const QSize &size); void userShapeSizeChanged (int width, int height); public: // Call this before the user tries to cause the document or selection // to resize from x to x. // If at least one dimension increases, the new dimensions will take a // large amount of memory (which causes thrashing, instability) and // the old dimensions did not take a large amount of memory, ask the // user if s/he really wants to perform the operation. // // Returns true if the operation should proceed, false otherwise. // // In order to make the translators' lives possible, this function cannot // generate the , nor (without // concantenating sentences and words with tense). However, it is // recommended that you give them the following values: // // e.g.: // text = i18n ("

(Rotating|Skewing) the (image|selection) to" // " %1x%2 may take a substantial amount of memory." // " This can reduce system" // " responsiveness and cause other application resource" // " problems.

").arg (newWidth, newHeight) // - // "

Are you sure want to (rotate|skew) the" + // "

Are you sure you want to (rotate|skew) the" // " (image|selection)?

"); // caption = i18n ("Rotate (Image|Selection)?"); // continueButtonText = i18n ("Rotat&e (Image|Selection)"); static bool warnIfBigImageSize (int oldWidth, int oldHeight, int newWidth, int newHeight, const QString &text, const QString &caption, const QString &continueButtonText, QWidget *parent); private: kpToolPrivate *d; }; #endif // KP_TOOL_H