9 #include "ui_KoShadowConfigWidget.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>
21 #include <klocalizedstring.h>
27 class Q_DECL_HIDDEN KoShadowConfigWidget::
Private
33 Ui_KoShadowConfigWidget widget;
38 KoShadowConfigWidget::KoShadowConfigWidget(
QWidget *parent)
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);
53 d->actionShadowColor->setCurrentColor(
QColor(0, 0, 0, 192));
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);
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()));
66 KoShadowConfigWidget::~KoShadowConfigWidget()
71 void KoShadowConfigWidget::setShadowColor(
const QColor &color)
73 d->widget.shadowColor->blockSignals(
true);
74 d->actionShadowColor->blockSignals(
true);
76 d->actionShadowColor->setCurrentColor( color );
78 d->actionShadowColor->blockSignals(
false);
79 d->widget.shadowColor->blockSignals(
false);
82 QColor KoShadowConfigWidget::shadowColor()
const
84 return d->actionShadowColor->currentColor();
87 void KoShadowConfigWidget::setShadowOffset(
const QPointF &offset)
89 qreal length = sqrt(offset.
x()*offset.
x() + offset.
y()*offset.
y());
90 qreal angle = atan2(-offset.
y(), offset.
x());
95 d->widget.shadowAngle->blockSignals(
true);
96 d->widget.shadowAngle->setValue(-90 - angle * 180.0 / M_PI);
97 d->widget.shadowAngle->blockSignals(
false);
99 d->widget.shadowOffset->blockSignals(
true);
100 d->widget.shadowOffset->changeValue(length);
101 d->widget.shadowOffset->blockSignals(
false);
104 QPointF KoShadowConfigWidget::shadowOffset()
const
106 QPointF offset(d->widget.shadowOffset->value(), 0);
108 m.
rotate(d->widget.shadowAngle->value() + 90);
109 return m.
map(offset);
112 void KoShadowConfigWidget::setShadowBlur(
const qreal &blur)
114 d->widget.shadowBlur->blockSignals(
true);
115 d->widget.shadowBlur->changeValue(blur);
116 d->widget.shadowBlur->blockSignals(
false);
119 qreal KoShadowConfigWidget::shadowBlur()
const
121 return d->widget.shadowBlur->value();
124 void KoShadowConfigWidget::setShadowVisible(
bool visible)
126 d->widget.shadowVisible->blockSignals(
true);
127 d->widget.shadowVisible->setChecked(visible);
128 d->widget.shadowVisible->blockSignals(
false);
132 bool KoShadowConfigWidget::shadowVisible()
const
134 return d->widget.shadowVisible->isChecked();
137 void KoShadowConfigWidget::visibilityChanged()
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() );
145 void KoShadowConfigWidget::applyChanges()
148 KoSelection *selection = d->canvas->selectedShapesProxy()->selection();
149 KoShape * shape = selection->firstSelectedShape();
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));
163 void KoShadowConfigWidget::selectionChanged()
169 KoSelection *selection = d->canvas->selectedShapesProxy()->selection();
170 KoShape * shape = selection->firstSelectedShape();
172 setEnabled(shape != 0);
175 setShadowVisible(
false);
179 KoShapeShadow * shadow = shape->shadow();
181 setShadowVisible(
false);
185 setShadowVisible(shadow->isVisible());
186 setShadowOffset(shadow->offset());
187 setShadowColor(shadow->color());
188 setShadowBlur(shadow->blur());
191 void KoShadowConfigWidget::setCanvas(KoCanvasBase *canvas)
194 connect(canvas->selectedShapesProxy(), SIGNAL(selectionChanged()),
this, SLOT(selectionChanged()));
195 connect(canvas->selectedShapesProxy(), SIGNAL(selectionContentChanged()),
this, SLOT(selectionChanged()));
197 setUnit(canvas->unit());
199 connect( d->canvas->resourceManager(), SIGNAL(canvasResourceChanged(
int,
QVariant)),
200 this, SLOT(resourceChanged(
int,
QVariant)) );
203 void KoShadowConfigWidget::setUnitManagers(KisSpinBoxUnitManager* managerBlur, KisSpinBoxUnitManager *managerOffset)
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);
213 void KoShadowConfigWidget::setUnit(
const KoUnit &unit)
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);
223 void KoShadowConfigWidget::resourceChanged(
int key,
const QVariant & res )
225 if( key == KoCanvasResource::Unit ) {
226 setUnit(res.
value<KoUnit>());