File indexing completed on 2024-12-22 04:13:18
0001 /* This file is part of the KDE project 0002 * Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr) 0003 * SPDX-FileCopyrightText: 2012 Jean-Nicolas Artaud <jeannicolasartaud@gmail.com> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef FILLCONFIGWIDGET_H 0009 #define FILLCONFIGWIDGET_H 0010 0011 #include "kritaui_export.h" 0012 0013 #include <QWidget> 0014 #include <QSharedPointer> 0015 #include <KoFlake.h> 0016 #include <KoFlakeTypes.h> 0017 #include <SvgMeshGradient.h> 0018 0019 class KoShapeFillWrapper; 0020 class KoCanvasBase; 0021 class KoShapeBackground; 0022 class KoShape; 0023 class KoColor; 0024 0025 /// A widget for configuring the fill of a shape 0026 class KRITAUI_EXPORT KoFillConfigWidget : public QWidget 0027 { 0028 Q_OBJECT 0029 enum StyleButton { 0030 None = 0, 0031 Solid, 0032 Gradient, 0033 Pattern, 0034 MeshGradient 0035 }; 0036 0037 public: 0038 0039 /** 0040 * @param trackShapeSelection controls if the widget connects to the canvas's selectionChanged signal. 0041 * If you decide to pass 'false', then don't forget to call 0042 * forceUpdateOnSelectionChanged() manually of every selectionChanged() and 0043 * selectionContentChanged() signals. 0044 */ 0045 explicit KoFillConfigWidget(KoCanvasBase *canvas, KoFlake::FillVariant fillVariant, bool trackShapeSelection, QWidget *parent); 0046 ~KoFillConfigWidget() override; 0047 0048 void setNoSelectionTrackingMode(bool value); 0049 0050 /// Returns the list of the selected shape 0051 /// If you need to use only one shape, call currentShape() 0052 QList<KoShape*> currentShapes(); 0053 0054 /// returns the selected index of the fill type 0055 int selectedFillIndex(); 0056 0057 KoShapeStrokeSP createShapeStroke(); 0058 0059 void activate(); 0060 void deactivate(); 0061 0062 void forceUpdateOnSelectionChanged(); 0063 0064 void setSelectedMeshGradientHandle(const SvgMeshPosition &position); 0065 0066 private Q_SLOTS: 0067 void styleButtonPressed(int buttonId); 0068 0069 void noColorSelected(); 0070 void shapeChanged(); 0071 0072 /// apply color changes to the selected shape 0073 void colorChanged(std::pair<QColor, KoFlake::FillVariant> resource); 0074 0075 /// the pattern of the fill changed, apply the changes 0076 void patternChanged(QSharedPointer<KoShapeBackground> background); 0077 0078 0079 0080 void slotUpdateFillTitle(); 0081 0082 void slotCanvasResourceChanged(int key, const QVariant &value); 0083 0084 void slotSavePredefinedGradientClicked(); 0085 0086 void activeGradientChanged(); 0087 void gradientResourceChanged(); 0088 0089 void slotGradientTypeChanged(); 0090 void slotGradientRepeatChanged(); 0091 0092 void slotProposeCurrentColorToResourceManager(); 0093 void slotRecoverColorInResourceManager(); 0094 0095 /// this won't preserve the rows and columns 0096 void slotMeshGradientChanged(); 0097 void slotMeshGradientShadingChanged(int index); 0098 void slotMeshHandleColorChanged(const KoColor &c); 0099 0100 Q_SIGNALS: 0101 void sigFillChanged(); 0102 0103 void sigInternalRequestColorToResourceManager(); 0104 void sigInternalRecoverColorInResourceManager(); 0105 void sigMeshGradientResetted(); 0106 0107 private: 0108 void updateGradientUi(const QGradient *gradient); 0109 void setNewGradientBackgroundToShape(); 0110 void updateGradientSaveButtonAvailability(); 0111 void loadCurrentFillFromResourceServer(); 0112 0113 /// sets the active gradient either from the shape (if present) or creates a new one 0114 void createNewMeshGradientBackground(); 0115 void createNewDefaultMeshGradientBackground(); 0116 void setNewMeshGradientBackgroundToShape(); 0117 void updateMeshGradientUI(); 0118 0119 void updateWidgetComponentVisibility(); 0120 0121 /// updates the UI based on KoFlake::FillType it gets from the shape. 0122 void updateUiFromFillType(KoShape *shape); 0123 0124 class Private; 0125 Private * const d {nullptr}; 0126 }; 0127 0128 #endif // FILLCONFIGWIDGET_H