File indexing completed on 2024-06-23 04:27:05
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 "StarShapeConfigWidget.h" 0008 #include "StarShape.h" 0009 #include "StarShapeConfigCommand.h" 0010 0011 #include "kis_document_aware_spin_box_unit_manager.h" 0012 0013 StarShapeConfigWidget::StarShapeConfigWidget() 0014 { 0015 widget.setupUi(this); 0016 0017 connect(widget.corners, SIGNAL(valueChanged(int)), this, SIGNAL(propertyChanged())); 0018 connect(widget.innerRadius, SIGNAL(editingFinished()), this, SIGNAL(propertyChanged())); 0019 connect(widget.outerRadius, SIGNAL(editingFinished()), this, SIGNAL(propertyChanged())); 0020 connect(widget.convex, SIGNAL(stateChanged(int)), this, SIGNAL(propertyChanged())); 0021 connect(widget.convex, SIGNAL(clicked()), this, SLOT(typeChanged())); 0022 } 0023 0024 void StarShapeConfigWidget::setUnit(const KoUnit &unit) 0025 { 0026 widget.innerRadius->setUnit(unit); 0027 widget.outerRadius->setUnit(unit); 0028 } 0029 0030 void StarShapeConfigWidget::open(KoShape *shape) 0031 { 0032 m_star = dynamic_cast<StarShape *>(shape); 0033 if (!m_star) { 0034 return; 0035 } 0036 0037 widget.corners->blockSignals(true); 0038 widget.innerRadius->blockSignals(true); 0039 widget.outerRadius->blockSignals(true); 0040 widget.convex->blockSignals(true); 0041 0042 widget.corners->setValue(m_star->cornerCount()); 0043 widget.innerRadius->changeValue(m_star->baseRadius()); 0044 widget.outerRadius->changeValue(m_star->tipRadius()); 0045 widget.convex->setCheckState(m_star->convex() ? Qt::Checked : Qt::Unchecked); 0046 typeChanged(); 0047 0048 widget.corners->blockSignals(false); 0049 widget.innerRadius->blockSignals(false); 0050 widget.outerRadius->blockSignals(false); 0051 widget.convex->blockSignals(false); 0052 } 0053 0054 void StarShapeConfigWidget::save() 0055 { 0056 if (!m_star) { 0057 return; 0058 } 0059 0060 m_star->setCornerCount(widget.corners->value()); 0061 m_star->setBaseRadius(widget.innerRadius->value()); 0062 m_star->setTipRadius(widget.outerRadius->value()); 0063 m_star->setConvex(widget.convex->checkState() == Qt::Checked); 0064 } 0065 0066 KUndo2Command *StarShapeConfigWidget::createCommand() 0067 { 0068 if (!m_star) { 0069 return 0; 0070 } else 0071 return new StarShapeConfigCommand(m_star, widget.corners->value(), widget.innerRadius->value(), 0072 widget.outerRadius->value(), widget.convex->checkState() == Qt::Checked); 0073 } 0074 0075 void StarShapeConfigWidget::typeChanged() 0076 { 0077 if (widget.convex->checkState() == Qt::Checked) { 0078 widget.innerRadius->setEnabled(false); 0079 } else { 0080 widget.innerRadius->setEnabled(true); 0081 } 0082 }