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

0001 /*
0002    Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
0003    All rights reserved.
0004 
0005    Redistribution and use in source and binary forms, with or without
0006    modification, are permitted provided that the following conditions
0007    are met:
0008 
0009    1. Redistributions of source code must retain the above copyright
0010       notice, this list of conditions and the following disclaimer.
0011    2. Redistributions in binary form must reproduce the above copyright
0012       notice, this list of conditions and the following disclaimer in the
0013       documentation and/or other materials provided with the distribution.
0014 
0015    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0016    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0017    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0018    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0019    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0020    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0021    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0022    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0023    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0024    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0025 */
0026 
0027 //
0028 // Tools' statusbar updates.
0029 //
0030 
0031 #include "tools/kpTool.h"
0032 #include "kpToolPrivate.h"
0033 
0034 #include <KLocalizedString>
0035 
0036 //---------------------------------------------------------------------
0037 
0038 // public static
0039 QString kpTool::cancelUserMessage (int mouseButton)
0040 {
0041     if (mouseButton == 0) {
0042         return i18n ("Right click to cancel.");
0043     }
0044 
0045     return i18n ("Left click to cancel.");
0046 }
0047 
0048 //---------------------------------------------------------------------
0049 
0050 // public
0051 QString kpTool::cancelUserMessage () const
0052 {
0053     return cancelUserMessage (d->mouseButton);
0054 }
0055 
0056 //---------------------------------------------------------------------
0057 
0058 // public
0059 QString kpTool::userMessage () const
0060 {
0061     return d->userMessage;
0062 }
0063 
0064 //---------------------------------------------------------------------
0065 
0066 // public
0067 void kpTool::setUserMessage (const QString &userMessage)
0068 {
0069     d->userMessage = userMessage;
0070 
0071     if (d->userMessage.isEmpty ()) {
0072         d->userMessage = text ();
0073     }
0074     else {
0075         d->userMessage.prepend (i18n ("%1: ", text ()));
0076     }
0077 
0078     Q_EMIT userMessageChanged (d->userMessage);
0079 }
0080 
0081 //---------------------------------------------------------------------
0082 
0083 // public
0084 QPoint kpTool::userShapeStartPoint () const
0085 {
0086     return d->userShapeStartPoint;
0087 }
0088 
0089 //---------------------------------------------------------------------
0090 
0091 // public
0092 QPoint kpTool::userShapeEndPoint () const
0093 {
0094     return d->userShapeEndPoint;
0095 }
0096 
0097 //---------------------------------------------------------------------
0098 
0099 // public
0100 void kpTool::setUserShapePoints (const QPoint &startPoint,
0101                                  const QPoint &endPoint,
0102                                  bool setSize)
0103 {
0104     d->userShapeStartPoint = startPoint;
0105     d->userShapeEndPoint = endPoint;
0106     Q_EMIT userShapePointsChanged (d->userShapeStartPoint, d->userShapeEndPoint);
0107 
0108     if (setSize)
0109     {
0110         if (startPoint != KP_INVALID_POINT &&
0111             endPoint != KP_INVALID_POINT)
0112         {
0113             setUserShapeSize (calculateLength (startPoint.x (), endPoint.x ()),
0114                               calculateLength (startPoint.y (), endPoint.y ()));
0115         }
0116         else
0117         {
0118             setUserShapeSize ();
0119         }
0120     }
0121 }
0122 
0123 //---------------------------------------------------------------------
0124 
0125 // public
0126 QSize kpTool::userShapeSize () const
0127 {
0128     return d->userShapeSize;
0129 }
0130 
0131 //---------------------------------------------------------------------
0132 
0133 // public
0134 int kpTool::userShapeWidth () const
0135 {
0136     return d->userShapeSize.width ();
0137 }
0138 
0139 //---------------------------------------------------------------------
0140 
0141 // public
0142 int kpTool::userShapeHeight () const
0143 {
0144     return d->userShapeSize.height ();
0145 }
0146 
0147 //---------------------------------------------------------------------
0148 
0149 // public
0150 void kpTool::setUserShapeSize (const QSize &size)
0151 {
0152     d->userShapeSize = size;
0153 
0154     Q_EMIT userShapeSizeChanged (d->userShapeSize);
0155 }
0156 
0157 //---------------------------------------------------------------------
0158 
0159 // public
0160 void kpTool::setUserShapeSize (int width, int height)
0161 {
0162     setUserShapeSize (QSize (width, height));
0163 }
0164 
0165 //---------------------------------------------------------------------