Warning, file /graphics/krita/plugins/flake/pathshapes/ellipse/EllipseShapeConfigWidget.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2007 Jan Hambrecht <jaham@gmx.net> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "EllipseShapeConfigWidget.h" 0008 #include "EllipseShapeConfigCommand.h" 0009 #include <klocalizedstring.h> 0010 #include <kis_signals_blocker.h> 0011 #include "kis_assert.h" 0012 0013 EllipseShapeConfigWidget::EllipseShapeConfigWidget() 0014 : m_ellipse(0) 0015 { 0016 widget.setupUi(this); 0017 0018 widget.ellipseType->clear(); 0019 widget.ellipseType->addItem(i18n("Arc")); 0020 widget.ellipseType->addItem(i18n("Pie")); 0021 widget.ellipseType->addItem(i18n("Chord")); 0022 0023 widget.startAngle->setFlipOptionsMode(KisAngleSelector::FlipOptionsMode_MenuButton); 0024 0025 widget.endAngle->setFlipOptionsMode(KisAngleSelector::FlipOptionsMode_MenuButton); 0026 0027 connect(widget.ellipseType, SIGNAL(currentIndexChanged(int)), this, SIGNAL(propertyChanged())); 0028 connect(widget.startAngle, SIGNAL(angleChanged(qreal)), this, SIGNAL(propertyChanged())); 0029 connect(widget.endAngle, SIGNAL(angleChanged(qreal)), this, SIGNAL(propertyChanged())); 0030 connect(widget.closeEllipse, SIGNAL(clicked(bool)), this, SLOT(closeEllipse())); 0031 } 0032 0033 void EllipseShapeConfigWidget::open(KoShape *shape) 0034 { 0035 if (m_ellipse) { 0036 m_ellipse->removeShapeChangeListener(this); 0037 } 0038 0039 m_ellipse = dynamic_cast<EllipseShape *>(shape); 0040 if (!m_ellipse) return; 0041 0042 loadPropertiesFromShape(m_ellipse); 0043 0044 m_ellipse->addShapeChangeListener(this); 0045 } 0046 0047 void EllipseShapeConfigWidget::loadPropertiesFromShape(EllipseShape *shape) 0048 { 0049 KisSignalsBlocker b(widget.ellipseType, widget.startAngle, widget.endAngle); 0050 0051 widget.ellipseType->setCurrentIndex(shape->type()); 0052 widget.startAngle->setAngle(shape->startAngle()); 0053 widget.endAngle->setAngle(shape->endAngle()); 0054 } 0055 0056 0057 void EllipseShapeConfigWidget::save() 0058 { 0059 if (!m_ellipse) { 0060 return; 0061 } 0062 0063 m_ellipse->setType(static_cast<EllipseShape::EllipseType>(widget.ellipseType->currentIndex())); 0064 m_ellipse->setStartAngle(widget.startAngle->angle()); 0065 m_ellipse->setEndAngle(widget.endAngle->angle()); 0066 } 0067 0068 KUndo2Command *EllipseShapeConfigWidget::createCommand() 0069 { 0070 if (!m_ellipse) { 0071 return 0; 0072 } else { 0073 EllipseShape::EllipseType type = static_cast<EllipseShape::EllipseType>(widget.ellipseType->currentIndex()); 0074 return new EllipseShapeConfigCommand(m_ellipse, type, widget.startAngle->angle(), widget.endAngle->angle()); 0075 } 0076 } 0077 0078 void EllipseShapeConfigWidget::notifyShapeChanged(KoShape::ChangeType type, KoShape *shape) 0079 { 0080 KIS_SAFE_ASSERT_RECOVER_RETURN(m_ellipse && shape == m_ellipse); 0081 0082 if (type == KoShape::ParameterChanged) { 0083 open(m_ellipse); 0084 } 0085 } 0086 0087 void EllipseShapeConfigWidget::closeEllipse() 0088 { 0089 widget.startAngle->blockSignals(true); 0090 widget.endAngle->blockSignals(true); 0091 0092 widget.startAngle->setAngle(0.0); 0093 widget.endAngle->setAngle(360.0); 0094 0095 widget.startAngle->blockSignals(false); 0096 widget.endAngle->blockSignals(false); 0097 0098 emit propertyChanged(); 0099 }