1 /* 2 * Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com> 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_GRADIENT_CHOOSER_H_ 19 #define KIS_GRADIENT_CHOOSER_H_ 20 21 #include <KoDialog.h> 22 #include <KoColor.h> 23 24 #include <QFrame> 25 #include <QScopedPointer> 26 27 #include <kritaui_export.h> 28 29 class KoAbstractGradient; 30 class KoResource; 31 class KoResourceItemChooser; 32 33 class KRITAUI_EXPORT KisGradientChooser : public QFrame 34 { 35 Q_OBJECT 36 37 public: 38 /** 39 * @brief View modes 40 */ 41 enum ViewMode 42 { 43 /** 44 * @brief Show the items as a grid of icons 45 */ 46 ViewMode_Icon, 47 /** 48 * @brief Show the items as a list 49 */ 50 ViewMode_List 51 }; 52 53 /** 54 * @brief Item sizes 55 */ 56 enum ItemSize 57 { 58 /** 59 * @brief Show small items 60 */ 61 ItemSize_Small, 62 /** 63 * @brief Show medium size items 64 */ 65 ItemSize_Medium, 66 /** 67 * @brief Show large items 68 */ 69 ItemSize_Large, 70 /** 71 * @brief Show items with a custom size 72 * @see itemSizeCustom() 73 * @see setItemSizeCustom(int) 74 */ 75 ItemSize_Custom 76 }; 77 78 KisGradientChooser(QWidget *parent = 0, const char *name = 0, bool useGlobalViewOptions = true); 79 ~KisGradientChooser() override; 80 81 /// Gets the currently selected resource 82 /// @returns the selected resource, 0 is no resource is selected 83 KoResource *currentResource(); 84 void setCurrentResource(KoResource *resource); 85 86 void setCurrentItem(int row, int column); 87 88 /** 89 * @brief Load the view settings from the configuration 90 * @param prefix string prepended to the settings names 91 * @see saveViewSettings(const QString &) 92 */ 93 void loadViewSettings(const QString &prefix = QString()); 94 /** 95 * @brief Save the view settings to the configuration 96 * @param prefix string prepended to the settings names 97 * @see loadViewSettings(const QString &) 98 */ 99 void saveViewSettings(const QString &prefix = QString()); 100 101 /** 102 * @brief Tell if the gradient preset chooser is showing the items as a 103 * grid of icons or as a list 104 * @return KisGradientChooser::ViewMode_Icon if the gradient preset 105 * chooser is showing the items as a grid of icons 106 * @return KisGradientChooser::ViewMode_List if the gradient preset 107 * chooser is showing the items as a list 108 * @see ViewMode 109 * @see setViewMode(ViewMode) 110 */ 111 ViewMode viewMode() const; 112 /** 113 * @brief Tell the size of the gradient preset chooser items 114 * @return KisGradientChooser::ItemSize_Small 115 * if the items are being shown with the small size 116 * @return KisGradientChooser::ItemSize_Medium 117 * if the items are being shown with the medium size 118 * @return KisGradientChooser::ItemSize_Large 119 * if the items are being shown with the large size 120 * @return KisGradientChooser::ItemSize_Custom 121 * if the items are being shown with the custom size 122 * @see ItemSize 123 * @see setItemSize(ItemSize) 124 */ 125 ItemSize itemSize() const; 126 /** 127 * @brief Tell the size (height) in pixels used when 128 * KisGradientChooser::ItemSize_Custom is 129 * used as the item size 130 * 131 * The default value is 32 132 * @return the custom size in pixels 133 * @see setItemSizeCustom(int) 134 */ 135 int itemSizeCustom() const; 136 137 /** 138 * @brief Get a pointer to the item chooser being used 139 * @return A pointer to the item chooser being used 140 */ 141 KoResourceItemChooser* resourceItemChooser() const; 142 143 /** 144 * @brief Get if the label showing the gradient name is visible 145 * @return true if the label is visible, false otherwise 146 * @see setNameLabelVisible(bool) 147 */ 148 bool isNameLabelVisible() const; 149 /** 150 * @brief Get if the widgets with options to edit the gradient are visible 151 * @return true if the edit widgets are visible, false otherwise 152 * @see setEditOptionsVisible(bool) 153 */ 154 bool areEditOptionsVisible() const; 155 156 public Q_SLOTS: 157 void slotUpdateIcons(); 158 void setForegroundColor(KoColor); 159 void setBackgroundColor(KoColor); 160 161 /** 162 * @brief Set if the gradient preset chooser must show the items as a 163 * grid of icons or as a list 164 * @param newViewMode ViewMode field indicating 165 * if the gradient preset chooser must show the items as a 166 * grid of icons or as a list 167 * @see ViewMode 168 * @see viewMode() 169 */ 170 void setViewMode(ViewMode newViewMode); 171 /** 172 * @brief Set the size of the gradient preset chooser items 173 * @param newItemSize ItemSize field indicating 174 * the size of the gradient preset chooser items 175 * @see ItemSize 176 * @see itemSize() 177 */ 178 void setItemSize(ItemSize newItemSize); 179 /** 180 * @brief Set the size (height) in pixels used when 181 * KisGradientChooser::ItemSize_Custom is 182 * used as the item size 183 * @param newSize the new custom size 184 * @see itemSizeCustom() 185 */ 186 void setItemSizeCustom(int newSize); 187 188 /** 189 * @brief Set if the label showing the gradient name is visible 190 * @param newNameLabelVisible true if the label must be visible, 191 * false otherwise 192 * @see isNameLabelVisible() const 193 */ 194 void setNameLabelVisible(bool newNameLabelVisible); 195 /** 196 * @brief Set if the widgets with options to edit the gradient are visible 197 * @param newNameLabelVisible true if the edit widgets must be visible, 198 * false otherwise 199 * @see areEditOptionsVisible() const 200 */ 201 void setEditOptionsVisible(bool newEditOptionsVisible); 202 203 Q_SIGNALS: 204 /// Emitted when a resource was selected 205 void resourceSelected(KoResource * resource); 206 /// Emitted when a resource was clicked 207 void resourceClicked(KoResource * resource); 208 209 private: 210 class Private; 211 QScopedPointer<Private> m_d; 212 213 bool event(QEvent *e) override; 214 }; 215 216 #endif // KIS_GRADIENT_CHOOSER_H_ 217 218