File indexing completed on 2024-04-28 04:20:21

0001 /*
0002    Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
0003    Copyright (c) 2011 Martin Koller <kollix@aon.at>
0004    All rights reserved.
0005 
0006    Redistribution and use in source and binary forms, with or without
0007    modification, are permitted provided that the following conditions
0008    are met:
0009 
0010    1. Redistributions of source code must retain the above copyright
0011       notice, this list of conditions and the following disclaimer.
0012    2. Redistributions in binary form must reproduce the above copyright
0013       notice, this list of conditions and the following disclaimer in the
0014       documentation and/or other materials provided with the distribution.
0015 
0016    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0017    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0018    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0019    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0020    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0021    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0022    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0023    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0024    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0025    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0026 */
0027 
0028 
0029 #include "mainWindow/kpMainWindow.h"
0030 #include "kpMainWindowPrivate.h"
0031 
0032 #include <QActionGroup>
0033 
0034 #include <KActionCollection>
0035 #include <KSharedConfig>
0036 #include <KConfigGroup>
0037 #include "kpLogCategories.h"
0038 #include <KLocalizedString>
0039 
0040 #include "widgets/toolbars/kpColorToolBar.h"
0041 #include "commands/kpCommandHistory.h"
0042 #include "document/kpDocument.h"
0043 #include "layers/selections/image/kpImageSelectionTransparency.h"
0044 #include "tools/kpTool.h"
0045 #include "tools/flow/kpToolBrush.h"
0046 #include "tools/flow/kpToolColorEraser.h"
0047 #include "tools/kpToolColorPicker.h"
0048 #include "tools/polygonal/kpToolCurve.h"
0049 #include "tools/selection/image/kpToolEllipticalSelection.h"
0050 #include "tools/rectangular/kpToolEllipse.h"
0051 #include "tools/flow/kpToolEraser.h"
0052 #include "tools/kpToolFloodFill.h"
0053 #include "tools/selection/image/kpToolFreeFormSelection.h"
0054 #include "tools/polygonal/kpToolLine.h"
0055 #include "tools/flow/kpToolPen.h"
0056 #include "tools/polygonal/kpToolPolygon.h"
0057 #include "tools/polygonal/kpToolPolyline.h"
0058 #include "tools/rectangular/kpToolRectangle.h"
0059 #include "tools/selection/image/kpToolRectSelection.h"
0060 #include "tools/rectangular/kpToolRoundedRectangle.h"
0061 #include "environments/tools/selection/kpToolSelectionEnvironment.h"
0062 #include "tools/flow/kpToolSpraycan.h"
0063 #include "tools/selection/text/kpToolText.h"
0064 #include "widgets/toolbars/kpToolToolBar.h"
0065 #include "widgets/toolbars/options/kpToolWidgetOpaqueOrTransparent.h"
0066 #include "tools/kpToolZoom.h"
0067 #include "commands/imagelib/transforms/kpTransformResizeScaleCommand.h"
0068 #include "kpViewScrollableContainer.h"
0069 #include "views/kpZoomedView.h"
0070 
0071 //---------------------------------------------------------------------
0072 
0073 // private
0074 kpToolSelectionEnvironment *kpMainWindow::toolSelectionEnvironment ()
0075 {
0076     if (!d->toolSelectionEnvironment) {
0077         d->toolSelectionEnvironment = new kpToolSelectionEnvironment (this);
0078     }
0079 
0080     return d->toolSelectionEnvironment;
0081 }
0082 
0083 //---------------------------------------------------------------------
0084 
0085 // private
0086 kpToolEnvironment *kpMainWindow::toolEnvironment ()
0087 {
0088     // It's fine to return a more complex environment than required.
0089     return toolSelectionEnvironment ();
0090 }
0091 
0092 //---------------------------------------------------------------------
0093 
0094 // private
0095 void kpMainWindow::setupToolActions ()
0096 {
0097     kpToolSelectionEnvironment *toolSelEnv = toolSelectionEnvironment ();
0098     kpToolEnvironment *toolEnv = toolEnvironment ();
0099 
0100     d->tools.append (d->toolFreeFormSelection = new kpToolFreeFormSelection (toolSelEnv, this));
0101     d->tools.append (d->toolRectSelection = new kpToolRectSelection (toolSelEnv, this));
0102 
0103     d->tools.append (d->toolEllipticalSelection = new kpToolEllipticalSelection (toolSelEnv, this));
0104     d->tools.append (d->toolText = new kpToolText (toolSelEnv, this));
0105 
0106     d->tools.append (d->toolLine = new kpToolLine (toolEnv, this));
0107     d->tools.append (d->toolPen = new kpToolPen (toolEnv, this));
0108 
0109     d->tools.append (d->toolEraser = new kpToolEraser (toolEnv, this));
0110     d->tools.append (d->toolBrush = new kpToolBrush (toolEnv, this));
0111 
0112     d->tools.append (d->toolFloodFill = new kpToolFloodFill (toolEnv, this));
0113     d->tools.append (d->toolColorPicker = new kpToolColorPicker (toolEnv, this));
0114 
0115     d->tools.append (d->toolColorEraser = new kpToolColorEraser (toolEnv, this));
0116     d->tools.append (d->toolSpraycan = new kpToolSpraycan (toolEnv, this));
0117 
0118     d->tools.append (d->toolRoundedRectangle = new kpToolRoundedRectangle (toolEnv, this));
0119     d->tools.append (d->toolRectangle = new kpToolRectangle (toolEnv, this));
0120 
0121     d->tools.append (d->toolPolygon = new kpToolPolygon (toolEnv, this));
0122     d->tools.append (d->toolEllipse = new kpToolEllipse (toolEnv, this));
0123 
0124     d->tools.append (d->toolPolyline = new kpToolPolyline (toolEnv, this));
0125     d->tools.append (d->toolCurve = new kpToolCurve (toolEnv, this));
0126 
0127     d->tools.append (d->toolZoom = new kpToolZoom (toolEnv, this));
0128 
0129 
0130     KActionCollection *ac = actionCollection ();
0131 
0132     d->actionPrevToolOptionGroup1 = ac->addAction (QStringLiteral("prev_tool_option_group_1"));
0133     d->actionPrevToolOptionGroup1->setText (i18n ("Previous Tool Option (Group #1)"));
0134     ac->setDefaultShortcuts (d->actionPrevToolOptionGroup1, kpTool::shortcutForKey (Qt::Key_1));
0135     connect (d->actionPrevToolOptionGroup1, &QAction::triggered,
0136              this, &kpMainWindow::slotActionPrevToolOptionGroup1);
0137 
0138     d->actionNextToolOptionGroup1 = ac->addAction (QStringLiteral("next_tool_option_group_1"));
0139     d->actionNextToolOptionGroup1->setText (i18n ("Next Tool Option (Group #1)"));
0140     ac->setDefaultShortcuts (d->actionNextToolOptionGroup1, kpTool::shortcutForKey (Qt::Key_2));
0141     connect (d->actionNextToolOptionGroup1, &QAction::triggered,
0142              this, &kpMainWindow::slotActionNextToolOptionGroup1);
0143 
0144     d->actionPrevToolOptionGroup2 = ac->addAction (QStringLiteral("prev_tool_option_group_2"));
0145     d->actionPrevToolOptionGroup2->setText (i18n ("Previous Tool Option (Group #2)"));
0146     ac->setDefaultShortcuts (d->actionPrevToolOptionGroup2, kpTool::shortcutForKey (Qt::Key_3));
0147     connect (d->actionPrevToolOptionGroup2, &QAction::triggered,
0148              this, &kpMainWindow::slotActionPrevToolOptionGroup2);
0149 
0150     d->actionNextToolOptionGroup2 = ac->addAction (QStringLiteral("next_tool_option_group_2"));
0151     d->actionNextToolOptionGroup2->setText (i18n ("Next Tool Option (Group #2)"));
0152     ac->setDefaultShortcuts (d->actionNextToolOptionGroup2, kpTool::shortcutForKey (Qt::Key_4));
0153     connect (d->actionNextToolOptionGroup2, &QAction::triggered,
0154              this, &kpMainWindow::slotActionNextToolOptionGroup2);
0155 
0156 
0157     //
0158     // Implemented in this file (kpMainWindow_Tools.cpp), not
0159     // kpImageWindow_Image.cpp since they're really setting tool options.
0160     //
0161 
0162     d->actionDrawOpaque = ac->add <KToggleAction> (QStringLiteral("image_draw_opaque"));
0163     d->actionDrawOpaque->setText (i18n ("&Draw Opaque"));
0164     connect (d->actionDrawOpaque, &QAction::triggered,
0165              this, &kpMainWindow::slotActionDrawOpaqueToggled);
0166 
0167     d->actionDrawColorSimilarity = ac->addAction (QStringLiteral("image_draw_color_similarity"));
0168     d->actionDrawColorSimilarity->setText (i18n ("Draw With Color Similarity..."));
0169     connect (d->actionDrawColorSimilarity, &QAction::triggered,
0170              this, &kpMainWindow::slotActionDrawColorSimilarity);
0171 }
0172 
0173 //---------------------------------------------------------------------
0174 
0175 // private
0176 void kpMainWindow::createToolBox ()
0177 {
0178     d->toolToolBar = new kpToolToolBar(QStringLiteral("Tool Box"), 2/*columns/rows*/, this);
0179     d->toolToolBar->setWindowTitle(i18n("Tool Box"));
0180 
0181     connect (d->toolToolBar, &kpToolToolBar::sigToolSelected,
0182              this, &kpMainWindow::slotToolSelected);
0183 
0184     connect (d->toolToolBar, &kpToolToolBar::toolWidgetOptionSelected,
0185              this, &kpMainWindow::updateToolOptionPrevNextActionsEnabled);
0186 
0187     connect (d->toolToolBar->toolWidgetOpaqueOrTransparent(),
0188              &kpToolWidgetOpaqueOrTransparent::isOpaqueChanged,
0189              this, &kpMainWindow::updateActionDrawOpaqueChecked);
0190 
0191     updateActionDrawOpaqueChecked ();
0192 
0193     for (auto *tool : d->tools) {
0194       d->toolToolBar->registerTool(tool);
0195     }
0196 
0197     // (from config file)
0198     readLastTool ();
0199 }
0200 
0201 //---------------------------------------------------------------------
0202 
0203 // private
0204 void kpMainWindow::enableToolsDocumentActions (bool enable)
0205 {
0206 #if DEBUG_KP_MAIN_WINDOW
0207     qCDebug(kpLogMainWindow) << "kpMainWindow::enableToolsDocumentsAction(" << enable << ")";
0208 #endif
0209 
0210     d->toolActionsEnabled = enable;
0211 
0212     if (enable && !d->toolToolBar->isEnabled ())
0213     {
0214         kpTool *previousTool = d->toolToolBar->previousTool ();
0215 
0216         // select tool for enabled Tool Box
0217 
0218         if (previousTool) {
0219             d->toolToolBar->selectPreviousTool ();
0220         }
0221         else
0222         {
0223             if (d->lastToolNumber >= 0 && d->lastToolNumber < d->tools.count ()) {
0224                 d->toolToolBar->selectTool (d->tools.at (d->lastToolNumber));
0225             }
0226             else {
0227                 d->toolToolBar->selectTool (d->toolPen);
0228             }
0229         }
0230     }
0231     else if (!enable && d->toolToolBar->isEnabled ())
0232     {
0233         // don't have a disabled Tool Box with a checked Tool
0234         d->toolToolBar->selectTool (nullptr);
0235     }
0236 
0237 
0238     d->toolToolBar->setEnabled (enable);
0239 
0240 
0241     for (auto *tool : d->tools)
0242     {
0243       KToggleAction *action = tool->action();
0244       if (!enable && action->isChecked()) {
0245           action->setChecked(false);
0246       }
0247 
0248       action->setEnabled(enable);
0249     }
0250 
0251 
0252     updateToolOptionPrevNextActionsEnabled ();
0253     updateActionDrawOpaqueEnabled ();
0254 }
0255 
0256 //---------------------------------------------------------------------
0257 
0258 // private slot
0259 void kpMainWindow::updateToolOptionPrevNextActionsEnabled ()
0260 {
0261     const bool enable = d->toolActionsEnabled;
0262 
0263 
0264     d->actionPrevToolOptionGroup1->setEnabled (enable &&
0265         d->toolToolBar->shownToolWidget (0) &&
0266         d->toolToolBar->shownToolWidget (0)->hasPreviousOption ());
0267     d->actionNextToolOptionGroup1->setEnabled (enable &&
0268         d->toolToolBar->shownToolWidget (0) &&
0269         d->toolToolBar->shownToolWidget (0)->hasNextOption ());
0270 
0271     d->actionPrevToolOptionGroup2->setEnabled (enable &&
0272         d->toolToolBar->shownToolWidget (1) &&
0273         d->toolToolBar->shownToolWidget (1)->hasPreviousOption ());
0274     d->actionNextToolOptionGroup2->setEnabled (enable &&
0275         d->toolToolBar->shownToolWidget (1) &&
0276         d->toolToolBar->shownToolWidget (1)->hasNextOption ());
0277 }
0278 
0279 //---------------------------------------------------------------------
0280 
0281 // private slot
0282 void kpMainWindow::updateActionDrawOpaqueChecked ()
0283 {
0284 #if DEBUG_KP_MAIN_WINDOW
0285     qCDebug(kpLogMainWindow) << "kpMainWindow::updateActionDrawOpaqueChecked()";
0286 #endif
0287 
0288     const bool drawOpaque =
0289         (d->toolToolBar->toolWidgetOpaqueOrTransparent ()->selectedRow () == 0);
0290 #if DEBUG_KP_MAIN_WINDOW
0291     qCDebug(kpLogMainWindow) << "\tdrawOpaque=" << drawOpaque;
0292 #endif
0293 
0294     d->actionDrawOpaque->setChecked (drawOpaque);
0295 }
0296 
0297 //---------------------------------------------------------------------
0298 
0299 // private
0300 void kpMainWindow::updateActionDrawOpaqueEnabled ()
0301 {
0302 #if DEBUG_KP_MAIN_WINDOW
0303     qCDebug(kpLogMainWindow) << "kpMainWindow::updateActionDrawOpaqueEnabled()";
0304 #endif
0305 
0306     const bool enable = d->toolActionsEnabled;
0307 
0308 #if DEBUG_KP_MAIN_WINDOW
0309     qCDebug(kpLogMainWindow) << "\tenable=" << enable
0310               << " tool=" << (tool () ? tool ()->objectName () : nullptr)
0311               << " (is selection=" << toolIsASelectionTool () << ")";
0312 #endif
0313 
0314     d->actionDrawOpaque->setEnabled (enable && toolIsASelectionTool ());
0315 }
0316 
0317 //---------------------------------------------------------------------
0318 
0319 // public
0320 QActionGroup *kpMainWindow::toolsActionGroup ()
0321 {
0322     if (!d->toolsActionGroup) {
0323         d->toolsActionGroup = new QActionGroup (this);
0324     }
0325 
0326     return d->toolsActionGroup;
0327 }
0328 
0329 //---------------------------------------------------------------------
0330 
0331 // public
0332 kpTool *kpMainWindow::tool () const
0333 {
0334     return d->toolToolBar ? d->toolToolBar->tool () : nullptr;
0335 }
0336 
0337 //---------------------------------------------------------------------
0338 
0339 // public
0340 bool kpMainWindow::toolHasBegunShape () const
0341 {
0342     kpTool *currentTool = tool ();
0343     return (currentTool && currentTool->hasBegunShape ());
0344 }
0345 
0346 //---------------------------------------------------------------------
0347 
0348 // public
0349 bool kpMainWindow::toolIsASelectionTool (bool includingTextTool) const
0350 {
0351     kpTool *currentTool = tool ();
0352 
0353     return ((currentTool == d->toolFreeFormSelection) ||
0354             (currentTool == d->toolRectSelection) ||
0355             (currentTool == d->toolEllipticalSelection) ||
0356             (currentTool == d->toolText && includingTextTool));
0357 }
0358 
0359 //---------------------------------------------------------------------
0360 
0361 // public
0362 bool kpMainWindow::toolIsTextTool () const
0363 {
0364     return (tool () == d->toolText);
0365 }
0366 
0367 //---------------------------------------------------------------------
0368 
0369 
0370 // private
0371 void kpMainWindow::toolEndShape ()
0372 {
0373     if (toolHasBegunShape ()) {
0374         tool ()->endShapeInternal ();
0375     }
0376 }
0377 
0378 //---------------------------------------------------------------------
0379 
0380 // public
0381 kpImageSelectionTransparency kpMainWindow::imageSelectionTransparency () const
0382 {
0383     kpToolWidgetOpaqueOrTransparent *oot = d->toolToolBar->toolWidgetOpaqueOrTransparent ();
0384     Q_ASSERT (oot);
0385 
0386     return kpImageSelectionTransparency (oot->isOpaque (), backgroundColor (), d->colorToolBar->colorSimilarity ());
0387 }
0388 
0389 //---------------------------------------------------------------------
0390 
0391 // public
0392 void kpMainWindow::setImageSelectionTransparency (const kpImageSelectionTransparency &transparency, bool forceColorChange)
0393 {
0394 #if DEBUG_KP_MAIN_WINDOW && 1
0395     qCDebug(kpLogMainWindow) << "kpMainWindow::setImageSelectionTransparency() isOpaque=" << transparency.isOpaque ()
0396                << " color=" << (transparency.transparentColor ().isValid () ? (int *) transparency.transparentColor ().toQRgb () : nullptr)
0397                << " forceColorChange=" << forceColorChange;
0398 #endif
0399 
0400     kpToolWidgetOpaqueOrTransparent *oot = d->toolToolBar->toolWidgetOpaqueOrTransparent ();
0401     Q_ASSERT (oot);
0402 
0403     d->settingImageSelectionTransparency++;
0404 
0405     oot->setOpaque (transparency.isOpaque ());
0406     if (transparency.isTransparent () || forceColorChange)
0407     {
0408         d->colorToolBar->setColor (1, transparency.transparentColor ());
0409         d->colorToolBar->setColorSimilarity (transparency.colorSimilarity ());
0410     }
0411 
0412     d->settingImageSelectionTransparency--;
0413 }
0414 
0415 //---------------------------------------------------------------------
0416 
0417 // public
0418 int kpMainWindow::settingImageSelectionTransparency () const
0419 {
0420     return d->settingImageSelectionTransparency;
0421 }
0422 
0423 //---------------------------------------------------------------------
0424 
0425 // private slot
0426 void kpMainWindow::slotToolSelected (kpTool *tool)
0427 {
0428 #if DEBUG_KP_MAIN_WINDOW
0429     qCDebug(kpLogMainWindow) << "kpMainWindow::slotToolSelected (" << tool << ")";
0430 #endif
0431 
0432     kpTool *previousTool = d->toolToolBar ? d->toolToolBar->previousTool () : nullptr;
0433 
0434     if (previousTool)
0435     {
0436         disconnect (previousTool, &kpTool::movedAndAboutToDraw,
0437                     this, &kpMainWindow::slotDragScroll);
0438 
0439         disconnect (previousTool, &kpTool::endedDraw,
0440                     this, &kpMainWindow::slotEndDragScroll);
0441 
0442         disconnect (previousTool, &kpTool::cancelledShape,
0443                     this, &kpMainWindow::slotEndDragScroll);
0444 
0445         disconnect (previousTool, &kpTool::userMessageChanged,
0446                     this, &kpMainWindow::recalculateStatusBarMessage);
0447 
0448         disconnect (previousTool, &kpTool::userShapePointsChanged,
0449                     this, &kpMainWindow::recalculateStatusBarShape);
0450 
0451         disconnect (previousTool, &kpTool::userShapeSizeChanged,
0452                     this, &kpMainWindow::recalculateStatusBarShape);
0453 
0454 
0455         disconnect (d->colorToolBar, &kpColorToolBar::colorsSwapped,
0456                     previousTool, &kpTool::slotColorsSwappedInternal);
0457 
0458         disconnect (d->colorToolBar, &kpColorToolBar::foregroundColorChanged,
0459                     previousTool, &kpTool::slotForegroundColorChangedInternal);
0460 
0461         disconnect (d->colorToolBar, &kpColorToolBar::backgroundColorChanged,
0462                     previousTool, &kpTool::slotBackgroundColorChangedInternal);
0463 
0464 
0465         disconnect (d->colorToolBar, &kpColorToolBar::colorSimilarityChanged,
0466                     previousTool, &kpTool::slotColorSimilarityChangedInternal);
0467     }
0468 
0469     if (tool)
0470     {
0471         connect (tool, &kpTool::movedAndAboutToDraw,
0472                  this, &kpMainWindow::slotDragScroll);
0473 
0474         connect (tool, &kpTool::endedDraw,
0475                  this, &kpMainWindow::slotEndDragScroll);
0476 
0477         connect (tool, &kpTool::cancelledShape,
0478                  this, &kpMainWindow::slotEndDragScroll);
0479 
0480         connect (tool, &kpTool::userMessageChanged,
0481                  this, &kpMainWindow::recalculateStatusBarMessage);
0482 
0483         connect (tool, &kpTool::userShapePointsChanged,
0484                  this, &kpMainWindow::recalculateStatusBarShape);
0485 
0486         connect (tool, &kpTool::userShapeSizeChanged,
0487                  this, &kpMainWindow::recalculateStatusBarShape);
0488 
0489         recalculateStatusBar ();
0490 
0491 
0492         connect (d->colorToolBar, &kpColorToolBar::colorsSwapped,
0493                  tool, &kpTool::slotColorsSwappedInternal);
0494 
0495         connect (d->colorToolBar, &kpColorToolBar::foregroundColorChanged,
0496                  tool, &kpTool::slotForegroundColorChangedInternal);
0497 
0498         connect (d->colorToolBar, &kpColorToolBar::backgroundColorChanged,
0499                  tool, &kpTool::slotBackgroundColorChangedInternal);
0500 
0501         connect (d->colorToolBar, &kpColorToolBar::colorSimilarityChanged,
0502                  tool, &kpTool::slotColorSimilarityChangedInternal);
0503 
0504 
0505         saveLastTool ();
0506     }
0507 
0508     updateToolOptionPrevNextActionsEnabled ();
0509     updateActionDrawOpaqueEnabled ();
0510 }
0511 
0512 //---------------------------------------------------------------------
0513 
0514 // private
0515 void kpMainWindow::readLastTool ()
0516 {
0517     KConfigGroup cfg (KSharedConfig::openConfig (), QStringLiteral(kpSettingsGroupTools));
0518 
0519     d->lastToolNumber = cfg.readEntry (kpSettingLastTool, -1);
0520 }
0521 
0522 //---------------------------------------------------------------------
0523 
0524 // private
0525 int kpMainWindow::toolNumber() const
0526 {
0527     for (int i = 0; i < d->tools.count(); i++)
0528       if ( d->tools[i] == tool() )
0529         return i;
0530 
0531     return -1;
0532 }
0533 
0534 //---------------------------------------------------------------------
0535 
0536 // private
0537 void kpMainWindow::saveLastTool ()
0538 {
0539     int number = toolNumber ();
0540     if ( (number < 0) || (number >= d->tools.count()) )
0541       return;
0542 
0543     KConfigGroup cfg (KSharedConfig::openConfig (), QStringLiteral(kpSettingsGroupTools));
0544 
0545     cfg.writeEntry (kpSettingLastTool, number);
0546     cfg.sync ();
0547 }
0548 
0549 //---------------------------------------------------------------------
0550 
0551 // private
0552 bool kpMainWindow::maybeDragScrollingMainView () const
0553 {
0554     return (tool () && d->mainView &&
0555             tool ()->viewUnderStartPoint () == d->mainView);
0556 }
0557 
0558 //---------------------------------------------------------------------
0559 
0560 // private slot
0561 bool kpMainWindow::slotDragScroll (const QPoint &docPoint,
0562                                    const QPoint &docLastPoint,
0563                                    int zoomLevel,
0564                                    bool *scrolled)
0565 {
0566   Q_UNUSED(docPoint)
0567   Q_UNUSED(docLastPoint)
0568 
0569 #if DEBUG_KP_MAIN_WINDOW
0570     qCDebug(kpLogMainWindow) << "kpMainWindow::slotDragScroll() maybeDragScrolling="
0571                << maybeDragScrollingMainView ();
0572 #endif
0573 
0574     if (maybeDragScrollingMainView ())
0575     {
0576         return d->scrollView->beginDragScroll(zoomLevel, scrolled);
0577     }
0578 
0579     return false;
0580 }
0581 
0582 //---------------------------------------------------------------------
0583 
0584 // private slot
0585 bool kpMainWindow::slotEndDragScroll ()
0586 {
0587     // (harmless if haven't started drag scroll)
0588     return d->scrollView->endDragScroll ();
0589 }
0590 
0591 //---------------------------------------------------------------------
0592 
0593 
0594 // private slot
0595 void kpMainWindow::slotBeganDocResize ()
0596 {
0597     toolEndShape ();
0598 
0599     recalculateStatusBarShape ();
0600 }
0601 
0602 //---------------------------------------------------------------------
0603 
0604 // private slot
0605 void kpMainWindow::slotContinuedDocResize (const QSize &)
0606 {
0607     recalculateStatusBarShape ();
0608 }
0609 
0610 //---------------------------------------------------------------------
0611 
0612 // private slot
0613 void kpMainWindow::slotCancelledDocResize ()
0614 {
0615     recalculateStatusBar ();
0616 }
0617 
0618 //---------------------------------------------------------------------
0619 
0620 // private slot
0621 void kpMainWindow::slotEndedDocResize (const QSize &size)
0622 {
0623 #define DOC_RESIZE_COMPLETED()           \
0624 {                                        \
0625     d->docResizeToBeCompleted = false;    \
0626     recalculateStatusBar ();             \
0627 }
0628 
0629     // Prevent statusbar updates
0630     d->docResizeToBeCompleted = true;
0631 
0632     d->docResizeWidth = (size.width () > 0 ? size.width () : 1);
0633     d->docResizeHeight = (size.height () > 0 ? size.height () : 1);
0634 
0635     if (d->docResizeWidth == d->document->width () &&
0636         d->docResizeHeight == d->document->height ())
0637     {
0638         DOC_RESIZE_COMPLETED ();
0639         return;
0640     }
0641 
0642 
0643     // Blank status to avoid confusion if dialog comes up
0644     setStatusBarMessage ();
0645     setStatusBarShapePoints ();
0646     setStatusBarShapeSize ();
0647 
0648 
0649     if (kpTool::warnIfBigImageSize (d->document->width (),
0650             d->document->height (),
0651             d->docResizeWidth, d->docResizeHeight,
0652             i18n ("<qt><p>Resizing the image to"
0653                     " %1x%2 may take a substantial amount of memory."
0654                     " This can reduce system"
0655                     " responsiveness and cause other application resource"
0656                     " problems.</p>"
0657 
0658                     "<p>Are you sure you want to resize the"
0659                     " image?</p></qt>",
0660                   d->docResizeWidth,
0661                   d->docResizeHeight),
0662             i18nc ("@title:window", "Resize Image?"),
0663             i18n ("R&esize Image"),
0664             this))
0665     {
0666         d->commandHistory->addCommand (
0667             new kpTransformResizeScaleCommand (
0668                 false/*doc, not sel*/,
0669                 d->docResizeWidth, d->docResizeHeight,
0670                 kpTransformResizeScaleCommand::Resize,
0671                 commandEnvironment ()));
0672 
0673         saveDefaultDocSize (QSize (d->docResizeWidth, d->docResizeHeight));
0674     }
0675 
0676 
0677     DOC_RESIZE_COMPLETED ();
0678 
0679 #undef DOC_RESIZE_COMPLETED
0680 }
0681 
0682 //---------------------------------------------------------------------
0683 
0684 // private slot
0685 void kpMainWindow::slotDocResizeMessageChanged (const QString &string)
0686 {
0687 #if DEBUG_KP_MAIN_WINDOW
0688     qCDebug(kpLogMainWindow) << "kpMainWindow::slotDocResizeMessageChanged(" << string
0689                << ") docResizeToBeCompleted=" << d->docResizeToBeCompleted;
0690 #else
0691     (void) string;
0692 #endif
0693 
0694     if (d->docResizeToBeCompleted) {
0695         return;
0696     }
0697 
0698     recalculateStatusBarMessage ();
0699 }
0700 
0701 //---------------------------------------------------------------------
0702 
0703 
0704 // private slot
0705 void kpMainWindow::slotActionPrevToolOptionGroup1 ()
0706 {
0707     if (!d->toolToolBar->shownToolWidget (0)) {
0708         return;
0709     }
0710 
0711     // We don't call toolEndShape() here because we want #23 in the file BUGS
0712     // to later work.
0713 
0714     d->toolToolBar->shownToolWidget (0)->selectPreviousOption ();
0715     updateToolOptionPrevNextActionsEnabled ();
0716 }
0717 
0718 //---------------------------------------------------------------------
0719 
0720 // private slot
0721 void kpMainWindow::slotActionNextToolOptionGroup1 ()
0722 {
0723     if (!d->toolToolBar->shownToolWidget (0)) {
0724         return;
0725     }
0726 
0727     // We don't call toolEndShape() here because we want #23 in the file BUGS
0728     // to later work.
0729 
0730     d->toolToolBar->shownToolWidget (0)->selectNextOption ();
0731     updateToolOptionPrevNextActionsEnabled ();
0732 }
0733 
0734 //---------------------------------------------------------------------
0735 
0736 
0737 // private slot
0738 void kpMainWindow::slotActionPrevToolOptionGroup2 ()
0739 {
0740     if (!d->toolToolBar->shownToolWidget (1)) {
0741         return;
0742     }
0743 
0744     // We don't call toolEndShape() here because we want #23 in the file BUGS
0745     // to later work.
0746 
0747     d->toolToolBar->shownToolWidget (1)->selectPreviousOption ();
0748     updateToolOptionPrevNextActionsEnabled ();
0749 }
0750 
0751 //---------------------------------------------------------------------
0752 
0753 // private slot
0754 void kpMainWindow::slotActionNextToolOptionGroup2 ()
0755 {
0756     if (!d->toolToolBar->shownToolWidget (1)) {
0757         return;
0758     }
0759 
0760     // We don't call toolEndShape() here because we want #23 in the file BUGS
0761     // to later work.
0762 
0763     d->toolToolBar->shownToolWidget (1)->selectNextOption ();
0764     updateToolOptionPrevNextActionsEnabled ();
0765 }
0766 
0767 //---------------------------------------------------------------------
0768 
0769 // private slot
0770 void kpMainWindow::slotActionDrawOpaqueToggled ()
0771 {
0772 #if DEBUG_KP_MAIN_WINDOW
0773     qCDebug(kpLogMainWindow) << "kpMainWindow::slotActionDrawOpaqueToggled()";
0774 #endif
0775     toolEndShape ();
0776 
0777     // TODO: How does this differ to setImageSelectionTransparency()?
0778 
0779     // ("kpToolWidgetBase::" is to access one overload shadowed by the override
0780     //  of the other overload)
0781     d->toolToolBar->toolWidgetOpaqueOrTransparent ()->kpToolWidgetBase::setSelected (
0782         (d->actionDrawOpaque->isChecked () ?
0783             0/*row 0 = opaque*/ :
0784             1/*row 1 = transparent*/),
0785         0/*column*/);
0786 }
0787 
0788 //---------------------------------------------------------------------
0789 
0790 // private slot
0791 void kpMainWindow::slotActionDrawColorSimilarity ()
0792 {
0793 #if DEBUG_KP_MAIN_WINDOW
0794     qCDebug(kpLogMainWindow) << "kpMainWindow::slotActionDrawColorSimilarity()";
0795 #endif
0796     toolEndShape ();
0797 
0798     d->colorToolBar->openColorSimilarityDialog ();
0799 }
0800 
0801 //---------------------------------------------------------------------
0802 
0803 
0804 // public slots
0805 
0806 #define SLOT_TOOL(toolName)                       \
0807 void kpMainWindow::slotTool##toolName ()          \
0808 {                                                 \
0809     if (!d->toolToolBar)                           \
0810         return;                                   \
0811                                                   \
0812     if (tool () == d->tool##toolName)              \
0813         return;                                   \
0814                                                   \
0815     d->toolToolBar->selectTool (d->tool##toolName); \
0816 }
0817 
0818 
0819 SLOT_TOOL (RectSelection)
0820 SLOT_TOOL (EllipticalSelection)
0821 SLOT_TOOL (FreeFormSelection)
0822 SLOT_TOOL (Text)