File indexing completed on 2024-06-23 04:27:04
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2007 Rob Buis <buis@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "SpiralShapeConfigWidget.h" 0008 #include "SpiralShapeConfigCommand.h" 0009 #include <klocalizedstring.h> 0010 0011 SpiralShapeConfigWidget::SpiralShapeConfigWidget() 0012 { 0013 widget.setupUi(this); 0014 0015 widget.spiralType->clear(); 0016 widget.spiralType->addItem(i18n("Curve")); 0017 widget.spiralType->addItem(i18n("Line")); 0018 0019 widget.fade->setMinimum(0.0); 0020 widget.fade->setMaximum(1.0); 0021 0022 widget.clockWise->clear(); 0023 widget.clockWise->addItem(i18n("Clockwise")); 0024 widget.clockWise->addItem(i18n("Anticlockwise")); 0025 0026 connect(widget.spiralType, SIGNAL(currentIndexChanged(int)), this, SIGNAL(propertyChanged())); 0027 connect(widget.clockWise, SIGNAL(currentIndexChanged(int)), this, SIGNAL(propertyChanged())); 0028 connect(widget.fade, SIGNAL(editingFinished()), this, SIGNAL(propertyChanged())); 0029 } 0030 0031 void SpiralShapeConfigWidget::open(KoShape *shape) 0032 { 0033 m_spiral = dynamic_cast<SpiralShape *>(shape); 0034 if (!m_spiral) { 0035 return; 0036 } 0037 0038 widget.spiralType->blockSignals(true); 0039 widget.clockWise->blockSignals(true); 0040 widget.fade->blockSignals(true); 0041 0042 widget.spiralType->setCurrentIndex(m_spiral->type()); 0043 widget.clockWise->setCurrentIndex(m_spiral->clockWise() ? 0 : 1); 0044 widget.fade->setValue(m_spiral->fade()); 0045 0046 widget.spiralType->blockSignals(false); 0047 widget.clockWise->blockSignals(false); 0048 widget.fade->blockSignals(false); 0049 } 0050 0051 void SpiralShapeConfigWidget::save() 0052 { 0053 if (!m_spiral) { 0054 return; 0055 } 0056 0057 m_spiral->setType(static_cast<SpiralShape::SpiralType>(widget.spiralType->currentIndex())); 0058 m_spiral->setClockWise(widget.clockWise->currentIndex() == 0); 0059 m_spiral->setFade(widget.fade->value()); 0060 } 0061 0062 KUndo2Command *SpiralShapeConfigWidget::createCommand() 0063 { 0064 if (!m_spiral) { 0065 return 0; 0066 } 0067 SpiralShape::SpiralType type = static_cast<SpiralShape::SpiralType>(widget.spiralType->currentIndex()); 0068 return new SpiralShapeConfigCommand(m_spiral, type, (widget.clockWise->currentIndex() == 0), widget.fade->value()); 0069 }