File indexing completed on 2024-05-12 04:21:15
0001 0002 /* 0003 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org> 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 #ifndef kpToolEnvironment_H 0030 #define kpToolEnvironment_H 0031 0032 0033 #include "environments/kpEnvironmentBase.h" 0034 0035 0036 class QActionGroup; 0037 class QPoint; 0038 class QRect; 0039 class QString; 0040 0041 class KActionCollection; 0042 0043 class kpColor; 0044 class kpCommandHistory; 0045 class kpToolToolBar; 0046 0047 0048 // Facade for kpTool clients. 0049 class kpToolEnvironment : public kpEnvironmentBase 0050 { 0051 Q_OBJECT 0052 0053 public: 0054 // Note: Our interface must never publicly leak <mainWindow> or any other 0055 // classes we are trying to hide as that would defeat the point of 0056 // the facade. 0057 explicit kpToolEnvironment (kpMainWindow *mainWindow); 0058 ~kpToolEnvironment () override; 0059 0060 0061 KActionCollection *actionCollection () const; 0062 0063 kpCommandHistory *commandHistory () const; 0064 0065 QActionGroup *toolsActionGroup () const; 0066 kpToolToolBar *toolToolBar () const; 0067 void hideAllToolWidgets () const; 0068 bool selectPreviousTool () const; 0069 0070 kpColor color (int which) const; 0071 double colorSimilarity () const; 0072 int processedColorSimilarity () const; 0073 0074 // (only valid in kpTool::slotForegroundColorChanged()) 0075 kpColor oldForegroundColor () const; 0076 // (only valid in kpTool::slotBackgroundColorChanged()) 0077 kpColor oldBackgroundColor () const; 0078 0079 // (only valid in kpTool::slotColorSimilarityChanged()) 0080 double oldColorSimilarity () const; 0081 0082 // Flashes the Color Similarity Tool Bar Item to highlight to the user, 0083 // the existence of the Color Similarity feature. 0084 // 0085 // This should be used in only 3 circumstances: 0086 // 0087 // 1. Tools not acting on the selection but using Color Similarity 0088 // e.g. Color Eraser, Flood Fill, Auto Crop. Note that Auto Crop 0089 // becomes Remove Internal Border when a selection is active but 0090 // the flashing still occurs because the extent of the effect is 0091 // directly dependent on Color Similarity. 0092 // 0093 // 2. A change to selection transparency (background color, color similarity 0094 // percentage, change from opaque to transparent). 0095 // 0096 // It is not used when the transparency is opaque or when changing from 0097 // transparent to opaque, as you're not using Color Similarity in these 0098 // cases. 0099 // 0100 // Similarly, it is not used when there is no image selection or the 0101 // image selection is just a border, as changing the selection 0102 // transparency also does nothing in these cases. 0103 // 0104 // 3. Pulling a selection from the document, when selection transparency 0105 // is transparent. 0106 // 0107 // Except for any pulling phase, it is not used for effects that use 0108 // the "transparent image" of a selection (e.g. smearing a transparent 0109 // selection). This is to minimize distractions and because the flashing 0110 // has already been done by pulling. 0111 // 0112 // This should always be called _before_ an operation related to Color 0113 // Similarity, to indicate that the Color Similarity was applied throughout 0114 // the operation -- not at the end. This aspect is most noticeable for 0115 // the time-consuming Autocrop feature, which may fail with a dialog -- 0116 // it would look wrong to only flash the Color Similarity Tool Bar Item when 0117 // the dialog comes up after the failed operation, as it implies that Color 0118 // Similarity was not used during the operation. Having said all this, 0119 // currently the flashing still happens afterwards because the flashing is 0120 // not done in a separate thread. However, assume that the implementation 0121 // will be fixed later. 0122 // 0123 // It is tempting to simply disable the Color Similarity Tool Bar Item 0124 // if the current tool does not use Color Similarity - this change in 0125 // enabled state would be enough to highlight the existence of Color 0126 // Similarity, without the need for this flashing. However, Auto Crop 0127 // is always available - independent of the current tool - and it uses 0128 // Color Similarity, so we can never disable the Tool Bar Item. 0129 // 0130 // We flash in tools but not commands as else it would be very distracting 0131 // Undo/Redo - this flashing in the tools is distracting enough already :) 0132 void flashColorSimilarityToolBarItem () const; 0133 0134 void setColor (int which, const kpColor &color) const; 0135 0136 void deleteSelection () const; 0137 void pasteTextAt (const QString &text, const QPoint &point, 0138 // Allow tiny adjustment of <point> so that mouse 0139 // pointer is not exactly on top of the topLeft of 0140 // any new text selection (so that it doesn't look 0141 // weird by being on top of a resize handle just after 0142 // a paste). 0143 bool allowNewTextSelectionPointShift = false) const; 0144 0145 void zoomIn (bool centerUnderCursor = false) const; 0146 void zoomOut (bool centerUnderCursor = false) const; 0147 0148 void zoomToRect (const QRect &normalizedDocRect, 0149 bool accountForGrips, 0150 bool careAboutWidth, bool careAboutHeight) const; 0151 0152 void fitToPage () const; 0153 0154 static bool drawAntiAliased; 0155 0156 0157 private: 0158 struct kpToolEnvironmentPrivate * const d; 0159 }; 0160 0161 0162 #endif // kpToolEnvironment_H 0163