Krita Source Code Documentation
Loading...
Searching...
No Matches
PathToolOptionWidget.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2007 Thomas Zander <zander@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
8#include "KoPathTool.h"
9#include <QAction>
10
11#include <KoPathShape.h>
12#include <KoParameterShape.h>
14#include <QVBoxLayout>
15#include <KoCanvasBase.h>
16#include <KoShapeRegistry.h>
17#include <KoShapeFactoryBase.h>
18#include <KoUnit.h>
19#include "kis_assert.h"
20
22 : QWidget(parent),
23 m_currentShape(0),
24 m_currentPanel(0),
25 m_canvas(tool->canvas())
26
27{
28 widget.setupUi(this);
29 widget.corner->setDefaultAction(tool->action("pathpoint-corner"));
30 widget.smooth->setDefaultAction(tool->action("pathpoint-smooth"));
31 widget.symmetric->setDefaultAction(tool->action("pathpoint-symmetric"));
32 widget.lineSegment->setDefaultAction(tool->action("pathsegment-line"));
33 widget.curveSegment->setDefaultAction(tool->action("pathsegment-curve"));
34 widget.linePoint->setDefaultAction(tool->action("pathpoint-line"));
35 widget.curvePoint->setDefaultAction(tool->action("pathpoint-curve"));
36 widget.addPoint->setDefaultAction(tool->action("pathpoint-insert"));
37 widget.removePoint->setDefaultAction(tool->action("pathpoint-remove"));
38 widget.breakPoint->setDefaultAction(tool->action("path-break-point"));
39 widget.breakSegment->setDefaultAction(tool->action("path-break-segment"));
40 widget.joinSegment->setDefaultAction(tool->action("pathpoint-join"));
41 widget.mergePoints->setDefaultAction(tool->action("pathpoint-merge"));
42
43 widget.wdgShapeProperties->setVisible(false);
44 widget.lineShapeProperties->setVisible(false);
45
46 connect(widget.convertToPath, SIGNAL(released()), tool->action("convert-to-path"), SLOT(trigger()));
47}
48
52
54{
55 const bool plain = type & PlainPath;
56 if (plain)
57 widget.stackedWidget->setCurrentIndex(0);
58 else
59 widget.stackedWidget->setCurrentIndex(1);
60}
61
62QString shapeIdFromShape(KoPathShape *pathShape)
63{
64 if (!pathShape) return QString();
65
66 QString shapeId = pathShape->pathShapeId();
67
68 KoParameterShape *paramShape = dynamic_cast<KoParameterShape *>(pathShape);
69 if (paramShape && !paramShape->isParametricShape()) {
70 shapeId = paramShape->shapeId();
71 }
72
73 return shapeId;
74}
75
77{
78 const QString newShapeId = shapeIdFromShape(pathShape);
79 if (pathShape == m_currentShape && m_currentShapeId == newShapeId) return;
80
81 if (m_currentShape) {
83 if (m_currentPanel) {
84 m_currentPanel->deleteLater();
86 m_currentShapeId.clear();
87 }
88 }
89
90 if (pathShape) {
91 m_currentShape = pathShape;
92 m_currentShapeId = newShapeId;
93
96
98 if (!panels.isEmpty()) {
99 KoShapeConfigWidgetBase *activePanel = 0;
100
101 Q_FOREACH (KoShapeConfigWidgetBase *panel, panels) {
102 if (!activePanel && panel->showOnShapeSelect()) {
103 activePanel = panel;
104 } else {
105 delete panel;
106 }
107 }
108
109 if (activePanel) {
111 m_currentPanel = activePanel;
113
114 QLayout *baseLayout = widget.wdgShapeProperties->layout();
115 QVBoxLayout *layout = dynamic_cast<QVBoxLayout*>(widget.wdgShapeProperties->layout());
116
117 if (!layout) {
118 KIS_SAFE_ASSERT_RECOVER(!baseLayout) {
119 delete baseLayout;
120 }
121 layout = new QVBoxLayout(widget.wdgShapeProperties);
122 }
123
124
125 KIS_ASSERT_RECOVER_RETURN(widget.wdgShapeProperties->layout());
126 layout->addWidget(m_currentPanel);
127 connect(m_currentPanel, SIGNAL(propertyChanged()), SLOT(slotShapePropertyChanged()));
129 }
130 }
131 }
132
133 widget.wdgShapeProperties->setVisible(m_currentPanel);
134 widget.lineShapeProperties->setVisible(m_currentPanel);
135}
136
146
147void PathToolOptionWidget::showEvent(QShowEvent *event)
148{
150 QWidget::showEvent(event);
151}
QString shapeIdFromShape(KoPathShape *pathShape)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
virtual KoUnit unit() const =0
virtual void addCommand(KUndo2Command *command)=0
const T value(const QString &id) const
bool isParametricShape() const
Check if object is a parametric shape.
The position of a path point within a path shape.
Definition KoPathShape.h:63
virtual QString pathShapeId() const
virtual void open(KoShape *shape)=0
virtual void setUnit(const KoUnit &unit)
virtual bool showOnShapeSelect()
Return true if the shape config panel should be shown when the shape is selected.
virtual KUndo2Command * createCommand()
Creates a command which applies all changes to the opened shape.
virtual QList< KoShapeConfigWidgetBase * > createShapeOptionPanels()
static KoShapeRegistry * instance()
QString shapeId() const
Definition KoShape.cpp:1057
QAction * action(const QString &name) const
PathToolOptionWidget(KoPathTool *tool, QWidget *parent=0)
void sigRequestUpdateActions()
KoShapeConfigWidgetBase * m_currentPanel
void setCurrentShape(KoPathShape *pathShape)
Ui::PathToolOptionWidgetBase widget
void showEvent(QShowEvent *event) override
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75