File indexing completed on 2024-12-22 04:13:05
0001 /* 0002 * KDE. Krita Project. 0003 * 0004 * SPDX-FileCopyrightText: 2020 Deif Lou <ginoba@gmail.com> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KISGENERICGRADIENTEDITOR_H 0010 #define KISGENERICGRADIENTEDITOR_H 0011 0012 #include <QWidget> 0013 #include <QScopedPointer> 0014 0015 #include <kritaui_export.h> 0016 #include <KoAbstractGradient.h> 0017 #include <KoCanvasResourcesInterface.h> 0018 0019 /** 0020 * @brief This is a generic gradient editor widget 0021 * 0022 * This widget makes use of other gradient related widgets and puts them 0023 * together in one place to ease the edition of gradients. 0024 * 0025 * It supports loading/saving from/to resources and conversion between 0026 * the different types of gradients 0027 */ 0028 class KRITAUI_EXPORT KisGenericGradientEditor : public QWidget 0029 { 0030 Q_OBJECT 0031 public: 0032 /** 0033 * @brief Construct a new KisGenericGradientEditor widget 0034 * @param parent the parent widget 0035 */ 0036 KisGenericGradientEditor(QWidget* parent = 0); 0037 ~KisGenericGradientEditor() override; 0038 0039 /** 0040 * @brief Load the ui settings from the configuration 0041 * @param prefix string prepended to the settings names 0042 * @see saveUISettings(const QString &) 0043 */ 0044 void loadUISettings(const QString &prefix = QString()); 0045 /** 0046 * @brief Save the ui settings to the configuration 0047 * @param prefix string prepended to the settings names 0048 * @see loadUISettings(const QString &) 0049 */ 0050 void saveUISettings(const QString &prefix = QString()); 0051 0052 /** 0053 * @brief Get the current gradient 0054 * 0055 * A clone is returned so that any changes in the returned gradient 0056 * won't change the editor gradient and viceversa 0057 * @return A clone of the current gradient 0058 * @see setGradient(KoAbstractGradientSP) 0059 */ 0060 KoAbstractGradientSP gradient() const; 0061 /** 0062 * @brief Get the current Canvas Resources Interface 0063 * @return The current Canvas Resources Interface 0064 * @see setCanvasResourcesInterface(KoCanvasResourcesInterfaceSP) 0065 */ 0066 KoCanvasResourcesInterfaceSP canvasResourcesInterface() const; 0067 /** 0068 * @brief Tell if the compact mode is being used 0069 * @return true if the compact mode is being used, false otherwise 0070 * @see setCompactMode(bool) 0071 */ 0072 bool compactMode() const; 0073 /** 0074 * @brief Tell if the convert gradient button is being shown 0075 * @return true if the convert gradient button is being shown, false otherwise 0076 * @see setConvertGradientButtonVisible(bool) 0077 */ 0078 bool isConvertGradientButtonVisible() const; 0079 /** 0080 * @brief Tell if the update gradient button is being shown 0081 * @return true if the update gradient button is being shown, false otherwise 0082 * @see setUpdateGradientButtonVisible(bool) 0083 */ 0084 bool isUpdateGradientButtonVisible() const; 0085 /** 0086 * @brief Tell if the add gradient button is being shown 0087 * @return true if the add gradient button is being shown, false otherwise 0088 * @see setAddGradientButtonVisible(bool) 0089 */ 0090 bool isAddGradientButtonVisible() const; 0091 /** 0092 * @brief Tell if the gradient preset chooser is being shown 0093 * @return true if the gradient preset chooser is being shown, false otherwise 0094 * @see setGradientPresetChooserVisible(bool) 0095 */ 0096 bool isGradientPresetChooserVisible() const; 0097 /** 0098 * @brief Tell if the button for the gradient preset chooser options is being shown 0099 * @return true if the button for the gradient preset chooser options is being shown, false otherwise 0100 * @see setGradientPresetChooserOptionsButtonVisible(bool) 0101 */ 0102 bool isGradientPresetChooserOptionsButtonVisible() const; 0103 /** 0104 * @brief Tell if the gradient preset chooser is being shown as a pop-up 0105 * clicking a button or embedded in the widget ui 0106 * @return true if the gradient preset chooser is being shown as a pop-up, false otherwise 0107 * @see setGradientPresetChooserVisible(bool) 0108 */ 0109 bool useGradientPresetChooserPopUp() const; 0110 /** 0111 * @brief Tell if the gradient preset chooser is being shown without any 0112 * controls other than the list view 0113 * @return true if the gradient preset chooser is being shown without any 0114 * controls other than the list view, false otherwise 0115 * @see setCompactGradientPresetChooserMode(bool) 0116 */ 0117 bool compactGradientPresetChooserMode() const; 0118 /** 0119 * @brief Tell if the internal gradient editor is using the compact mode 0120 * @return true if the internal gradient editor is using the compact mode, false otherwise 0121 * @see setCompactGradientEditorMode(bool) 0122 */ 0123 bool compactGradientEditorMode() const; 0124 0125 QSize sizeHint() const override; 0126 QSize minimumSizeHint() const override; 0127 0128 bool event(QEvent *e) override; 0129 0130 public Q_SLOTS: 0131 /** 0132 * @brief Set the gradient 0133 * 0134 * This editor makes a clone os the gradient passed so that any changes 0135 * made in the editor won't change the passed gradient and viceversa 0136 * @param newGradient The new gradient 0137 * @see gradient() 0138 */ 0139 void setGradient(KoAbstractGradientSP newGradient); 0140 /** 0141 * @brief Set the canvas resources interface 0142 * 0143 * the canvas resources interface is used to get the 0144 * current foreground and background colors 0145 * 0146 * @param newCanvasResourcesInterface the new canvas resources interface 0147 * @see canvasResourcesInterface() 0148 */ 0149 void setCanvasResourcesInterface(KoCanvasResourcesInterfaceSP newCanvasResourcesInterface); 0150 /** 0151 * @brief Set if the editor must show a reduced ui 0152 * 0153 * If the compact mode is set, only the gradient editors will be visible 0154 * 0155 * @param compact true if the compact mode must be used, false otherwise 0156 * @see compactMode() 0157 */ 0158 void setCompactMode(bool compact); 0159 /** 0160 * @brief Set if the convert gradient button must be shown 0161 * @param visible true if the convert gradient button must be shown, false otherwise 0162 * @see isConvertGradientButtonVisible() 0163 */ 0164 void setConvertGradientButtonVisible(bool visible); 0165 /** 0166 * @brief Set if the update gradient button must be shown 0167 * @param visible true if the update gradient button must be shown, false otherwise 0168 * @see isUpdateGradientButtonVisible() 0169 */ 0170 void setUpdateGradientButtonVisible(bool visible); 0171 /** 0172 * @brief Set if the add gradient button must be shown 0173 * @param visible true if the add gradient button must be shown, false otherwise 0174 * @see isAddGradientButtonVisible() 0175 */ 0176 void setAddGradientButtonVisible(bool visible); 0177 /** 0178 * @brief Set if the gradient preset chooser must be shown 0179 * @param visible true if the gradient preset chooser must be shown, false otherwise 0180 * @see isSaveGradientButtonVisible() 0181 */ 0182 void setGradientPresetChooserVisible(bool visible); 0183 /** 0184 * @brief Set if the button for the gradient preset chooser options must be shown 0185 * @param visible true if the button for the gradient preset chooser options must be shown, false otherwise 0186 * @see isGradientPresetChooserOptionsButtonVisible() 0187 */ 0188 void setGradientPresetChooserOptionsButtonVisible(bool visible); 0189 /** 0190 * @brief Set if the gradient preset chooser must be shown as a pop-up 0191 * clicking a button or embedded in the widget ui 0192 * @param use true if the gradient preset chooser must be shown as a pop-up, false otherwise 0193 * @see useGradientPresetChooserPopUp() 0194 */ 0195 void setUseGradientPresetChooserPopUp(bool use); 0196 /** 0197 * @brief Set if the gradient preset chooser must be shown without any 0198 * controls other than the list view 0199 * @param compact true if the gradient preset chooser must be shown without any 0200 * controls other than the list view, false otherwise 0201 * @see compactGradientPresetChooserMode() 0202 */ 0203 void setCompactGradientPresetChooserMode(bool compact); 0204 /** 0205 * @brief Set if the internal gradient editor must use the compact mode 0206 * @param compact true if the internal gradient editor must use the compact mode, false otherwise 0207 * @see compactGradientEditorMode() 0208 */ 0209 void setCompactGradientEditorMode(bool compact); 0210 0211 Q_SIGNALS: 0212 /** 0213 * @brief signal emitted when the gradient changes 0214 */ 0215 void sigGradientChanged(); 0216 0217 private: 0218 class Private; 0219 QScopedPointer<Private> m_d; 0220 0221 void updateConvertGradientButton(); 0222 void updateUpdateGradientButton(); 0223 void updateAddGradientButton(); 0224 void updateGradientPresetChooser(); 0225 void updateGradientEditor(); 0226 0227 private Q_SLOTS: 0228 void on_buttonConvertGradient_clicked(); 0229 void on_buttonUpdateGradient_clicked(); 0230 void on_buttonAddGradient_clicked(); 0231 void on_widgetGradientPresetChooser_resourceClicked(KoResourceSP resource); 0232 void on_widgetGradientEditor_sigGradientChanged(); 0233 }; 0234 0235 #endif