1 /* 2 * Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 */ 18 #ifndef KIS_SELECTION_MANAGER_ 19 #define KIS_SELECTION_MANAGER_ 20 21 #include <QObject> 22 #include <QList> 23 #include <QPointer> 24 25 #include <kis_image.h> 26 #include "KisView.h" 27 #include <KisSelectionTags.h> 28 29 #include <kritaui_export.h> 30 31 class KisActionManager; 32 class KisAction; 33 class QAction; 34 class KisDocument; 35 36 class KisViewManager; 37 class KisClipboard; 38 class KisNodeCommandsAdapter; 39 class KisView; 40 41 class KisSelectionFilter; 42 class KisSelectionDecoration; 43 44 /** 45 * The selection manager is responsible selections 46 * and the clipboard. 47 */ 48 class KRITAUI_EXPORT KisSelectionManager : public QObject 49 { 50 51 Q_OBJECT 52 Q_PROPERTY(bool displaySelection READ displaySelection NOTIFY displaySelectionChanged); 53 Q_PROPERTY(bool havePixelsSelected READ havePixelsSelected NOTIFY currentSelectionChanged); 54 public: 55 56 KisSelectionManager(KisViewManager * view); 57 ~KisSelectionManager() override; 58 59 void setup(KisActionManager* actionManager); 60 61 void setView(QPointer<KisView>imageView); 62 63 public: 64 /** 65 * This function return if the selection should be displayed 66 */ 67 bool displaySelection(); 68 69 bool showSelectionAsMask() const; 70 71 public Q_SLOTS: 72 73 void updateGUI(); 74 void selectionChanged(); 75 void clipboardDataChanged(); 76 77 void cut(); 78 void copy(); 79 80 void cutSharp(); 81 void copySharp(); 82 83 void copyMerged(); 84 void paste(); 85 void pasteNew(); 86 void pasteAt(); 87 void pasteAsReference(); 88 void pasteShapeStyle(); 89 void cutToNewLayer(); 90 void selectAll(); 91 void deselect(); 92 void invert(); 93 void clear(); 94 void fillForegroundColor(); 95 void fillBackgroundColor(); 96 void fillPattern(); 97 void fillForegroundColorOpacity(); 98 void fillBackgroundColorOpacity(); 99 void fillPatternOpacity(); 100 void reselect(); 101 void editSelection(); 102 void convertToVectorSelection(); 103 void convertToRasterSelection(); 104 void convertShapesToVectorSelection(); 105 void convertToShape(); 106 107 void copySelectionToNewLayer(); 108 void toggleDisplaySelection(); 109 110 void shapeSelectionChanged(); 111 void imageResizeToSelection(); 112 void paintSelectedShapes(); 113 114 void slotToggleSelectionDecoration(); 115 116 void slotStrokeSelection(); 117 118 void selectOpaqueOnNode(KisNodeSP node, SelectionAction action); 119 120 Q_SIGNALS: 121 void currentSelectionChanged(); 122 void signalUpdateGUI(); 123 void displaySelectionChanged(); 124 void strokeSelected(); 125 126 public: 127 bool havePixelsSelected(); 128 bool havePixelsInClipboard(); 129 bool haveShapesSelected(); 130 bool haveShapesInClipboard(); 131 132 /// Checks if the current selection is editable and has some pixels selected in the pixel selection 133 bool haveAnySelectionWithPixels(); 134 bool haveShapeSelectionWithShapes(); 135 bool haveRasterSelectionWithPixels(); 136 137 private: 138 void fill(const KoColor& color, bool fillWithPattern, const QString& transactionText); 139 void updateStatusBar(); 140 141 KisViewManager * m_view {0}; 142 KisDocument * m_doc {0}; 143 QPointer<KisView>m_imageView {0}; 144 KisClipboard * m_clipboard {0}; 145 146 KisNodeCommandsAdapter* m_adapter {0}; 147 148 KisAction *m_copy {0}; 149 KisAction *m_copyMerged {0}; 150 KisAction *m_cut {0}; 151 KisAction *m_paste {0}; 152 KisAction *m_pasteAt {0}; 153 KisAction *m_pasteAsReference {0}; 154 KisAction *m_pasteNew {0}; 155 KisAction *m_pasteShapeStyle {0}; 156 KisAction *m_cutToNewLayer {0}; 157 KisAction *m_selectAll {0}; 158 KisAction *m_deselect {0}; 159 KisAction *m_clear {0}; 160 KisAction *m_reselect {0}; 161 KisAction *m_invert {0}; 162 KisAction *m_copyToNewLayer {0}; 163 KisAction *m_fillForegroundColor {0}; 164 KisAction *m_fillBackgroundColor {0}; 165 KisAction *m_fillPattern {0}; 166 KisAction *m_fillForegroundColorOpacity {0}; 167 KisAction *m_fillBackgroundColorOpacity {0}; 168 KisAction *m_fillPatternOpacity {0}; 169 KisAction *m_imageResizeToSelection {0}; 170 KisAction *m_strokeShapes {0}; 171 KisAction *m_toggleDisplaySelection {0}; 172 KisAction *m_toggleSelectionOverlayMode {0}; 173 KisAction *m_strokeSelected {0}; 174 175 176 QList<QAction*> m_pluginActions; 177 QPointer<KisSelectionDecoration> m_selectionDecoration; 178 179 }; 180 181 #endif // KIS_SELECTION_MANAGER_ 182