• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • krita API Reference
  • KDE Home
  • Contact Us
 

KritaWidgets

  • sources
  • kfour-appscomplete
  • krita
  • libs
  • widgets
KoShadowConfigWidget.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  * SPDX-FileCopyrightText: 2012 C. Boemann <[email protected]>
3  * SPDX-FileCopyrightText: 2008 Jan Hambrecht <[email protected]>
4  *
5  * SPDX-License-Identifier: LGPL-2.0-or-later
6  */
7 
8 #include "KoShadowConfigWidget.h"
9 #include "ui_KoShadowConfigWidget.h"
10 
11 #include <KoIcon.h>
12 #include <KoUnit.h>
13 #include <KoColorPopupAction.h>
14 #include <KoCanvasBase.h>
15 #include <KoCanvasResourceProvider.h>
16 #include <KoSelection.h>
17 #include <KoShapeShadow.h>
18 #include <KoShapeShadowCommand.h>
19 #include <KoSelectedShapesProxy.h>
20 
21 #include <klocalizedstring.h>
22 
23 #include <QCheckBox>
24 
25 #include <math.h>
26 
27 class Q_DECL_HIDDEN KoShadowConfigWidget::Private
28 {
29 public:
30  Private()
31  {
32  }
33  Ui_KoShadowConfigWidget widget;
34  KoColorPopupAction *actionShadowColor;
35  KoCanvasBase *canvas;
36 };
37 
38 KoShadowConfigWidget::KoShadowConfigWidget(QWidget *parent)
39  : QWidget(parent)
40  , d(new Private())
41 {
42  d->widget.setupUi(this);
43  d->widget.shadowOffset->setValue(8.0);
44  d->widget.shadowBlur->setValue(8.0);
45  d->widget.shadowBlur->setMinimum(0.0);
46  d->widget.shadowAngle->setValue(315.0);
47  d->widget.shadowAngle->setMinimum(0.0);
48  d->widget.shadowAngle->setMaximum(360.0);
49  d->widget.shadowVisible->setChecked(false);
50  visibilityChanged();
51 
52  d->actionShadowColor = new KoColorPopupAction(this);
53  d->actionShadowColor->setCurrentColor(QColor(0, 0, 0, 192)); // some reasonable default for shadow
54  d->actionShadowColor->setIcon(koIcon("format-stroke-color"));
55  d->actionShadowColor->setToolTip(i18n("Change the color of the shadow"));
56  d->widget.shadowColor->setDefaultAction(d->actionShadowColor);
57 
58  connect(d->widget.shadowVisible, SIGNAL(toggled(bool)), this, SLOT(applyChanges()));
59  connect(d->widget.shadowVisible, SIGNAL(toggled(bool)), this, SLOT(visibilityChanged()));
60  connect(d->actionShadowColor, SIGNAL(colorChanged(KoColor)), this, SLOT(applyChanges()));
61  connect(d->widget.shadowAngle, SIGNAL(valueChanged(int)), this, SLOT(applyChanges()));
62  connect(d->widget.shadowOffset, SIGNAL(valueChangedPt(qreal)), this, SLOT(applyChanges()));
63  connect(d->widget.shadowBlur, SIGNAL(valueChangedPt(qreal)), this, SLOT(applyChanges()));
64 }
65 
66 KoShadowConfigWidget::~KoShadowConfigWidget()
67 {
68  delete d;
69 }
70 
71 void KoShadowConfigWidget::setShadowColor(const QColor &color)
72 {
73  d->widget.shadowColor->blockSignals(true);
74  d->actionShadowColor->blockSignals(true);
75 
76  d->actionShadowColor->setCurrentColor( color );
77 
78  d->actionShadowColor->blockSignals(false);
79  d->widget.shadowColor->blockSignals(false);
80 }
81 
82 QColor KoShadowConfigWidget::shadowColor() const
83 {
84  return d->actionShadowColor->currentColor();
85 }
86 
87 void KoShadowConfigWidget::setShadowOffset(const QPointF &offset)
88 {
89  qreal length = sqrt(offset.x()*offset.x() + offset.y()*offset.y());
90  qreal angle = atan2(-offset.y(), offset.x());
91  if (angle < 0.0) {
92  angle += 2*M_PI;
93  }
94 
95  d->widget.shadowAngle->blockSignals(true);
96  d->widget.shadowAngle->setValue(-90 - angle * 180.0 / M_PI);
97  d->widget.shadowAngle->blockSignals(false);
98 
99  d->widget.shadowOffset->blockSignals(true);
100  d->widget.shadowOffset->changeValue(length);
101  d->widget.shadowOffset->blockSignals(false);
102 }
103 
104 QPointF KoShadowConfigWidget::shadowOffset() const
105 {
106  QPointF offset(d->widget.shadowOffset->value(), 0);
107  QTransform m;
108  m.rotate(d->widget.shadowAngle->value() + 90);
109  return m.map(offset);
110 }
111 
112 void KoShadowConfigWidget::setShadowBlur(const qreal &blur)
113 {
114  d->widget.shadowBlur->blockSignals(true);
115  d->widget.shadowBlur->changeValue(blur);
116  d->widget.shadowBlur->blockSignals(false);
117 }
118 
119 qreal KoShadowConfigWidget::shadowBlur() const
120 {
121  return d->widget.shadowBlur->value();
122 }
123 
124 void KoShadowConfigWidget::setShadowVisible(bool visible)
125 {
126  d->widget.shadowVisible->blockSignals(true);
127  d->widget.shadowVisible->setChecked(visible);
128  d->widget.shadowVisible->blockSignals(false);
129  visibilityChanged();
130 }
131 
132 bool KoShadowConfigWidget::shadowVisible() const
133 {
134  return d->widget.shadowVisible->isChecked();
135 }
136 
137 void KoShadowConfigWidget::visibilityChanged()
138 {
139  d->widget.shadowAngle->setEnabled( d->widget.shadowVisible->isChecked() );
140  d->widget.shadowBlur->setEnabled( d->widget.shadowVisible->isChecked() );
141  d->widget.shadowColor->setEnabled( d->widget.shadowVisible->isChecked() );
142  d->widget.shadowOffset->setEnabled( d->widget.shadowVisible->isChecked() );
143 }
144 
145 void KoShadowConfigWidget::applyChanges()
146 {
147  if (d->canvas) {
148  KoSelection *selection = d->canvas->selectedShapesProxy()->selection();
149  KoShape * shape = selection->firstSelectedShape();
150  if (! shape) {
151  return;
152  }
153 
154  KoShapeShadow *newShadow = new KoShapeShadow();
155  newShadow->setVisible(shadowVisible());
156  newShadow->setColor(shadowColor());
157  newShadow->setOffset(shadowOffset());
158  newShadow->setBlur(shadowBlur());
159  d->canvas->addCommand(new KoShapeShadowCommand(selection->selectedShapes(), newShadow));
160  }
161 }
162 
163 void KoShadowConfigWidget::selectionChanged()
164 {
165  if (! d->canvas) {
166  return;
167  }
168 
169  KoSelection *selection = d->canvas->selectedShapesProxy()->selection();
170  KoShape * shape = selection->firstSelectedShape();
171 
172  setEnabled(shape != 0);
173 
174  if (! shape) {
175  setShadowVisible(false);
176  return;
177  }
178 
179  KoShapeShadow * shadow = shape->shadow();
180  if (! shadow) {
181  setShadowVisible(false);
182  return;
183  }
184 
185  setShadowVisible(shadow->isVisible());
186  setShadowOffset(shadow->offset());
187  setShadowColor(shadow->color());
188  setShadowBlur(shadow->blur());
189 }
190 
191 void KoShadowConfigWidget::setCanvas(KoCanvasBase *canvas)
192 {
193  d->canvas = canvas;
194  connect(canvas->selectedShapesProxy(), SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
195  connect(canvas->selectedShapesProxy(), SIGNAL(selectionContentChanged()), this, SLOT(selectionChanged()));
196 
197  setUnit(canvas->unit());
198 
199  connect( d->canvas->resourceManager(), SIGNAL(canvasResourceChanged(int,QVariant)),
200  this, SLOT(resourceChanged(int,QVariant)) );
201 }
202 
203 void KoShadowConfigWidget::setUnitManagers(KisSpinBoxUnitManager* managerBlur, KisSpinBoxUnitManager *managerOffset)
204 {
205  d->widget.shadowOffset->blockSignals(true);
206  d->widget.shadowBlur->blockSignals(true);
207  d->widget.shadowOffset->setUnitManager(managerOffset);
208  d->widget.shadowBlur->setUnitManager(managerBlur);
209  d->widget.shadowOffset->blockSignals(false);
210  d->widget.shadowBlur->blockSignals(false);
211 }
212 
213 void KoShadowConfigWidget::setUnit(const KoUnit &unit)
214 {
215  d->widget.shadowOffset->blockSignals(true);
216  d->widget.shadowBlur->blockSignals(true);
217  d->widget.shadowOffset->setUnit(unit);
218  d->widget.shadowBlur->setUnit(unit);
219  d->widget.shadowOffset->blockSignals(false);
220  d->widget.shadowBlur->blockSignals(false);
221 }
222 
223 void KoShadowConfigWidget::resourceChanged( int key, const QVariant & res )
224 {
225  if( key == KoCanvasResource::Unit ) {
226  setUnit(res.value<KoUnit>());
227  }
228 }
QTransform::map
QPoint map(const QPoint &point) const
QColor
QTransform::rotate
QTransform & rotate(qreal angle, Qt::Axis axis)
QVariant::value
T value() const
QWidget
QPointF
QWidget::setupUi
void setupUi(QWidget *widget)
QTransform
KoColorPopupAction
KoColorPopupAction makes use of KoColorSetWidget to show a widget for for choosing a color (colormana...
Definition: KoColorPopupAction.h:22
QPointF::x
qreal x() const
QPointF::y
qreal y() const
KoShadowConfigWidget.h
Private
QVariant
KoColorPopupAction.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Jan 19 2021 23:44:00 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KritaWidgets

Skip menu "KritaWidgets"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

krita API Reference

Skip menu "krita API Reference"
  • libs
  •   KritaBasicFlakes
  •   brush
  •   KritaUndo2
  •   KritaFlake
  •   image
  •   KritaPlugin
  •   Krita
  •   KritaPigment
  •   KritaResources
  •   KritaStore
  •   ui
  •   KritaWidgets
  •   KritaWidgetUtils
  • plugins
  •   Assitants
  •   Extensions
  •   Filters
  •   Generators
  •   Formats
  •           src
  •   PaintOps
  •     libpaintop

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal