2019-03-04 15:34:42 +00:00
|
|
|
|
/*
|
2025-01-04 13:37:40 +01:00
|
|
|
|
Copyright 2006-2025 The QElectroTech Team
|
2015-06-21 20:16:41 +00:00
|
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2020-09-21 21:19:50 +02:00
|
|
|
|
|
2015-06-21 20:16:41 +00:00
|
|
|
|
#include "shapegraphicsitempropertieswidget.h"
|
2020-12-08 19:57:35 +01:00
|
|
|
|
|
|
|
|
|
#include "../QPropertyUndoCommand/qpropertyundocommand.h"
|
|
|
|
|
#include "../diagram.h"
|
2020-12-10 21:19:45 +01:00
|
|
|
|
#include "../qetgraphicsitem/qetshapeitem.h"
|
2020-12-08 19:57:35 +01:00
|
|
|
|
#include "../ui_shapegraphicsitempropertieswidget.h"
|
|
|
|
|
|
|
|
|
|
#include <QHash>
|
2015-06-21 20:16:41 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
|
@brief ShapeGraphicsItemPropertiesWidget::ShapeGraphicsItemPropertiesWidget
|
|
|
|
|
Constructor
|
|
|
|
|
@param item : shape to edit
|
|
|
|
|
@param parent : parent widget
|
|
|
|
|
*/
|
2015-06-21 20:16:41 +00:00
|
|
|
|
ShapeGraphicsItemPropertiesWidget::ShapeGraphicsItemPropertiesWidget(QetShapeItem *item, QWidget *parent) :
|
|
|
|
|
PropertiesEditorWidget(parent),
|
|
|
|
|
ui(new Ui::ShapeGraphicsItemPropertiesWidget),
|
|
|
|
|
m_shape(nullptr)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
setItem(item);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 15:34:42 +00:00
|
|
|
|
ShapeGraphicsItemPropertiesWidget::ShapeGraphicsItemPropertiesWidget(QList<QetShapeItem *> items_list, QWidget *parent) :
|
|
|
|
|
PropertiesEditorWidget (parent),
|
|
|
|
|
ui(new Ui::ShapeGraphicsItemPropertiesWidget)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
setItems(items_list);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-21 20:16:41 +00:00
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
|
@brief ShapeGraphicsItemPropertiesWidget::~ShapeGraphicsItemPropertiesWidget
|
|
|
|
|
Destructor
|
|
|
|
|
*/
|
2015-06-21 20:16:41 +00:00
|
|
|
|
ShapeGraphicsItemPropertiesWidget::~ShapeGraphicsItemPropertiesWidget()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
|
@brief ShapeGraphicsItemPropertiesWidget::setItem
|
2020-08-18 21:28:52 +02:00
|
|
|
|
Set shape as the current edited item
|
2020-08-16 11:19:36 +02:00
|
|
|
|
@param shape
|
|
|
|
|
*/
|
2015-06-21 20:16:41 +00:00
|
|
|
|
void ShapeGraphicsItemPropertiesWidget::setItem(QetShapeItem *shape)
|
|
|
|
|
{
|
2024-04-24 18:02:00 +02:00
|
|
|
|
if (m_shape != shape) {
|
|
|
|
|
clearEditConnection();
|
2019-03-04 15:34:42 +00:00
|
|
|
|
}
|
|
|
|
|
if (!shape) {
|
|
|
|
|
return;
|
2016-01-12 14:02:34 +00:00
|
|
|
|
}
|
2015-06-21 20:16:41 +00:00
|
|
|
|
|
|
|
|
|
m_shape = shape;
|
2016-01-12 14:02:34 +00:00
|
|
|
|
ui->m_close_polygon->setVisible(m_shape->shapeType() == QetShapeItem::Polygon);
|
2016-02-15 16:15:05 +00:00
|
|
|
|
ui->m_filling_gb->setHidden(m_shape->shapeType() == QetShapeItem::Line);
|
2015-12-30 13:47:21 +00:00
|
|
|
|
|
2024-04-24 18:02:00 +02:00
|
|
|
|
updateUi();
|
2019-03-04 15:34:42 +00:00
|
|
|
|
setUpEditConnection();
|
2015-06-21 20:16:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 15:34:42 +00:00
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
|
@brief ShapeGraphicsItemPropertiesWidget::setItems
|
|
|
|
|
Set a list of shapes to be edited
|
|
|
|
|
@param shapes_list
|
|
|
|
|
*/
|
2019-03-04 15:34:42 +00:00
|
|
|
|
void ShapeGraphicsItemPropertiesWidget::setItems(QList<QetShapeItem *> shapes_list)
|
|
|
|
|
{
|
2024-04-24 18:02:00 +02:00
|
|
|
|
clearEditConnection();
|
2019-03-04 15:34:42 +00:00
|
|
|
|
m_shapes_list.clear();
|
|
|
|
|
m_shape = nullptr;
|
|
|
|
|
|
2024-04-24 18:02:00 +02:00
|
|
|
|
if (shapes_list.isEmpty()) {
|
2019-03-04 15:34:42 +00:00
|
|
|
|
updateUi();
|
|
|
|
|
}
|
|
|
|
|
else if (shapes_list.size() == 1)
|
|
|
|
|
{
|
|
|
|
|
setItem(shapes_list.first());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (QetShapeItem *shape : shapes_list) {
|
|
|
|
|
m_shapes_list.append(QPointer<QetShapeItem>(shape));
|
|
|
|
|
}
|
|
|
|
|
updateUi();
|
|
|
|
|
}
|
|
|
|
|
setUpEditConnection();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-21 20:16:41 +00:00
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
|
@brief ShapeGraphicsItemPropertiesWidget::apply
|
|
|
|
|
Apply the current change, by pushing an undo command to the
|
|
|
|
|
undo stack of the shape diagram.
|
|
|
|
|
*/
|
2015-06-21 20:16:41 +00:00
|
|
|
|
void ShapeGraphicsItemPropertiesWidget::apply()
|
2019-03-04 15:34:42 +00:00
|
|
|
|
{
|
|
|
|
|
Diagram *d = nullptr;
|
|
|
|
|
|
|
|
|
|
if (m_shape && m_shape->diagram()) {
|
|
|
|
|
d = m_shape->diagram();
|
|
|
|
|
}
|
|
|
|
|
else if (!m_shapes_list.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
for (QPointer<QetShapeItem> qsi : m_shapes_list)
|
|
|
|
|
{
|
|
|
|
|
if (qsi->diagram()) {
|
|
|
|
|
d = qsi->diagram();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d)
|
|
|
|
|
{
|
|
|
|
|
QUndoCommand *undo = associatedUndo();
|
|
|
|
|
if (undo) {
|
|
|
|
|
d->undoStack().push(undo);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-21 20:16:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
|
@brief ShapeGraphicsItemPropertiesWidget::reset
|
|
|
|
|
Reset the change
|
|
|
|
|
*/
|
2020-09-07 22:03:40 +02:00
|
|
|
|
void ShapeGraphicsItemPropertiesWidget::reset()
|
|
|
|
|
{
|
2015-06-21 20:16:41 +00:00
|
|
|
|
updateUi();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
|
@brief ShapeGraphicsItemPropertiesWidget::associatedUndo
|
|
|
|
|
@return an undo command that represent the change edited by this widget.
|
|
|
|
|
The returned undo command is a QPropertyUndoCommand with the properties "pen".
|
|
|
|
|
If there isn't change, return nullptr
|
|
|
|
|
*/
|
2015-06-21 20:16:41 +00:00
|
|
|
|
QUndoCommand* ShapeGraphicsItemPropertiesWidget::associatedUndo() const
|
|
|
|
|
{
|
2019-03-04 15:34:42 +00:00
|
|
|
|
if (m_live_edit)
|
2016-01-12 14:02:34 +00:00
|
|
|
|
{
|
2019-03-04 15:34:42 +00:00
|
|
|
|
//One shape is edited
|
|
|
|
|
if (m_shapes_list.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
QPropertyUndoCommand *undo = nullptr;
|
|
|
|
|
|
|
|
|
|
QPen old_pen = m_shape->pen();
|
|
|
|
|
QPen new_pen = old_pen;
|
|
|
|
|
|
|
|
|
|
new_pen.setStyle(Qt::PenStyle(ui->m_style_cb->currentIndex() + 1));
|
|
|
|
|
new_pen.setWidthF(ui->m_size_dsb->value());
|
|
|
|
|
|
|
|
|
|
if (ui->m_style_cb->currentIndex() ==5) {
|
|
|
|
|
new_pen.setDashPattern( QVector<qreal>() << 10 << 10 );
|
|
|
|
|
new_pen.setStyle( Qt::CustomDashLine );
|
|
|
|
|
}
|
|
|
|
|
//painter.setPen( new_pen );
|
2019-03-15 18:07:57 +00:00
|
|
|
|
new_pen.setColor(ui->m_color_kpb->color());
|
2019-03-04 15:34:42 +00:00
|
|
|
|
|
|
|
|
|
if (new_pen != old_pen)
|
|
|
|
|
{
|
|
|
|
|
undo = new QPropertyUndoCommand(m_shape, "pen", old_pen, new_pen);
|
|
|
|
|
undo->setText(tr("Modifier le trait d'une forme"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QBrush old_brush = m_shape->brush();
|
|
|
|
|
QBrush new_brush = old_brush;
|
|
|
|
|
new_brush.setStyle(Qt::BrushStyle(ui->m_brush_style_cb->currentIndex()));
|
2019-03-15 18:07:57 +00:00
|
|
|
|
new_brush.setColor(ui->m_brush_color_kpb->color());
|
2019-03-04 15:34:42 +00:00
|
|
|
|
|
|
|
|
|
if (new_brush != old_brush)
|
|
|
|
|
{
|
|
|
|
|
if (undo)
|
|
|
|
|
new QPropertyUndoCommand(m_shape, "brush", old_brush, new_brush, undo);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
undo = new QPropertyUndoCommand(m_shape, "brush", old_brush, new_brush);
|
|
|
|
|
undo->setText(tr("Modifier le remplissage d'une forme"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ui->m_close_polygon->isChecked() != m_shape->isClosed())
|
|
|
|
|
{
|
|
|
|
|
if (undo)
|
|
|
|
|
new QPropertyUndoCommand(m_shape, "close", m_shape->isClosed(), ui->m_close_polygon->isChecked(), undo);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
undo = new QPropertyUndoCommand(m_shape, "close", m_shape->isClosed(), ui->m_close_polygon->isChecked(), undo);
|
|
|
|
|
undo->setText(tr("Fermer le polygone"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return undo;
|
|
|
|
|
}
|
|
|
|
|
else if (!m_shapes_list.isEmpty()) //seberal shapes are edited
|
|
|
|
|
{
|
|
|
|
|
QUndoCommand *parent_undo = nullptr;
|
|
|
|
|
QetShapeItem *shape_ = m_shapes_list.first().data();
|
|
|
|
|
|
|
|
|
|
//Pen
|
|
|
|
|
QHash <QetShapeItem *, QPen> pen_H;
|
|
|
|
|
|
|
|
|
|
if (ui->m_style_cb->currentIndex() != -1 &&
|
|
|
|
|
Qt::PenStyle(ui->m_style_cb->currentIndex() + 1) != shape_->pen().style())
|
|
|
|
|
{
|
|
|
|
|
for (QPointer<QetShapeItem> qsi : m_shapes_list)
|
|
|
|
|
{
|
|
|
|
|
QPen pen = qsi->pen();
|
|
|
|
|
|
|
|
|
|
if (ui->m_style_cb->currentIndex() ==5) {
|
|
|
|
|
pen.setDashPattern( QVector<qreal>() << 10 << 10 );
|
|
|
|
|
pen.setStyle( Qt::CustomDashLine );
|
|
|
|
|
} else {
|
|
|
|
|
pen.setStyle(Qt::PenStyle(ui->m_style_cb->currentIndex() + 1));
|
|
|
|
|
}
|
|
|
|
|
pen_H.insert(qsi, pen);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ui->m_size_dsb->value() > 0 &&
|
|
|
|
|
ui->m_size_dsb->value() != shape_->pen().widthF())
|
|
|
|
|
{
|
|
|
|
|
for (QPointer<QetShapeItem> qsi : m_shapes_list)
|
|
|
|
|
{
|
|
|
|
|
QPen pen = pen_H.contains(qsi) ? pen_H.value(qsi) : qsi->pen();
|
|
|
|
|
pen.setWidthF(ui->m_size_dsb->value());
|
|
|
|
|
pen_H.insert(qsi, pen);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-15 18:07:57 +00:00
|
|
|
|
QColor c =ui->m_color_kpb->color();
|
2019-03-04 15:34:42 +00:00
|
|
|
|
if (c != QPalette().color(QPalette::Button) && shape_->pen().color() != c)
|
|
|
|
|
{
|
|
|
|
|
for (QPointer<QetShapeItem> qsi : m_shapes_list)
|
|
|
|
|
{
|
|
|
|
|
QPen pen = pen_H.contains(qsi) ? pen_H.value(qsi) : qsi->pen();
|
|
|
|
|
pen.setColor(c);
|
|
|
|
|
pen_H.insert(qsi, pen);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (QPointer<QetShapeItem> qsi : pen_H.keys())
|
|
|
|
|
{
|
|
|
|
|
if (!parent_undo) {
|
|
|
|
|
parent_undo = new QUndoCommand(tr("Modifier une forme simple"));
|
|
|
|
|
}
|
|
|
|
|
new QPropertyUndoCommand(qsi, "pen", qsi->pen(), pen_H.value(qsi), parent_undo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Brush
|
|
|
|
|
QHash <QetShapeItem *, QBrush> brush_H;
|
|
|
|
|
if (ui->m_brush_style_cb->currentIndex() != -1 &&
|
|
|
|
|
shape_->brush().style() != Qt::BrushStyle(ui->m_brush_style_cb->currentIndex()))
|
|
|
|
|
{
|
|
|
|
|
for (QPointer<QetShapeItem> qsi : m_shapes_list)
|
|
|
|
|
{
|
|
|
|
|
QBrush brush = qsi->brush();
|
|
|
|
|
brush.setStyle(Qt::BrushStyle(ui->m_brush_style_cb->currentIndex()));
|
|
|
|
|
brush_H.insert(qsi, brush);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-15 18:07:57 +00:00
|
|
|
|
c = ui->m_brush_color_kpb->color();
|
2019-03-04 15:34:42 +00:00
|
|
|
|
if (c != QPalette().color(QPalette::Button) && shape_->brush().color() != c)
|
|
|
|
|
{
|
|
|
|
|
for (QPointer<QetShapeItem> qsi : m_shapes_list)
|
|
|
|
|
{
|
|
|
|
|
QBrush brush = brush_H.contains(qsi) ? brush_H.value(qsi) : qsi->brush();
|
|
|
|
|
brush.setColor(c);
|
|
|
|
|
brush_H.insert(qsi, brush);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (QPointer<QetShapeItem> qsi : brush_H.keys())
|
|
|
|
|
{
|
|
|
|
|
if (!parent_undo) {
|
|
|
|
|
parent_undo = new QUndoCommand(tr("Modifier une forme simple"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new QPropertyUndoCommand(qsi, "brush", qsi->brush(), brush_H.value(qsi), parent_undo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return parent_undo;
|
|
|
|
|
}
|
2016-01-12 14:02:34 +00:00
|
|
|
|
}
|
2019-03-04 15:34:42 +00:00
|
|
|
|
//In mode not live edit, only one shape can be edited
|
|
|
|
|
else if (m_shapes_list.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
QUndoCommand *undo = new QUndoCommand(tr("Modifier les propriétés d'une forme simple"));
|
|
|
|
|
QPen old_pen = m_shape->pen();
|
|
|
|
|
QPen new_pen = old_pen;
|
2016-01-12 14:02:34 +00:00
|
|
|
|
|
2019-03-04 15:34:42 +00:00
|
|
|
|
new_pen.setStyle(Qt::PenStyle(ui->m_style_cb->currentIndex() + 1));
|
|
|
|
|
new_pen.setWidthF(ui->m_size_dsb->value());
|
2016-01-12 14:02:34 +00:00
|
|
|
|
|
2019-03-04 15:34:42 +00:00
|
|
|
|
if (ui->m_style_cb->currentIndex() ==5) {
|
|
|
|
|
new_pen.setDashPattern( QVector<qreal>() << 10 << 10 );
|
|
|
|
|
new_pen.setStyle( Qt::CustomDashLine );
|
|
|
|
|
}
|
|
|
|
|
//painter.setPen( new_pen );
|
2019-03-15 18:07:57 +00:00
|
|
|
|
new_pen.setColor(ui->m_color_kpb->color());
|
2019-03-04 15:34:42 +00:00
|
|
|
|
|
|
|
|
|
if (new_pen != old_pen) {
|
|
|
|
|
new QPropertyUndoCommand(m_shape, "pen", old_pen, new_pen, undo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QBrush old_brush = m_shape->brush();
|
|
|
|
|
QBrush new_brush = old_brush;
|
|
|
|
|
new_brush.setStyle(Qt::BrushStyle(ui->m_brush_style_cb->currentIndex()));
|
2019-03-15 18:07:57 +00:00
|
|
|
|
new_brush.setColor(ui->m_brush_color_kpb->color());
|
2019-03-04 15:34:42 +00:00
|
|
|
|
|
|
|
|
|
if (new_brush != old_brush) {
|
2016-01-12 14:02:34 +00:00
|
|
|
|
new QPropertyUndoCommand(m_shape, "brush", old_brush, new_brush, undo);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 15:34:42 +00:00
|
|
|
|
if (ui->m_close_polygon->isChecked() != m_shape->isClosed()) {
|
|
|
|
|
QPropertyUndoCommand(m_shape, "close", m_shape->isClosed(), ui->m_close_polygon->isChecked(), undo);
|
2016-01-12 14:02:34 +00:00
|
|
|
|
}
|
2015-08-06 16:34:38 +00:00
|
|
|
|
|
2019-03-04 15:34:42 +00:00
|
|
|
|
if (undo->childCount()) {
|
|
|
|
|
return undo;
|
|
|
|
|
} else {
|
|
|
|
|
delete undo;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-12 05:45:41 +00:00
|
|
|
|
return nullptr;
|
2015-06-21 20:16:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
|
@brief ShapeGraphicsItemPropertiesWidget::updateUi
|
|
|
|
|
*/
|
2015-06-21 20:16:41 +00:00
|
|
|
|
void ShapeGraphicsItemPropertiesWidget::updateUi()
|
|
|
|
|
{
|
2019-03-04 15:34:42 +00:00
|
|
|
|
if (!m_shape && m_shapes_list.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Disconnect every connections of editor widgets
|
|
|
|
|
//to avoid an unwanted edition (QSpinBox emit valueChanged no matter if changer by user or by program)
|
2024-04-24 18:02:00 +02:00
|
|
|
|
clearEditConnection();
|
2019-03-04 15:34:42 +00:00
|
|
|
|
|
|
|
|
|
if (m_shape)
|
|
|
|
|
{
|
2016-01-12 14:02:34 +00:00
|
|
|
|
//Pen
|
2019-03-04 15:34:42 +00:00
|
|
|
|
ui->m_style_cb->setCurrentIndex(static_cast<int>(m_shape->pen().style()) - 1);
|
|
|
|
|
ui->m_size_dsb ->setValue(m_shape->pen().widthF());
|
2019-03-15 18:07:57 +00:00
|
|
|
|
ui->m_color_kpb->setColor(m_shape->pen().color());
|
2019-03-04 15:42:53 +00:00
|
|
|
|
ui->m_color_kpb->setColor(m_shape->pen().color());
|
2016-02-15 16:15:05 +00:00
|
|
|
|
|
2016-01-12 14:02:34 +00:00
|
|
|
|
//Brush
|
2019-03-04 15:34:42 +00:00
|
|
|
|
if (m_shape->shapeType() == QetShapeItem::Polygon)
|
|
|
|
|
ui->m_filling_gb->setVisible(m_shape->isClosed());
|
2016-02-15 16:15:05 +00:00
|
|
|
|
|
2019-03-04 15:34:42 +00:00
|
|
|
|
ui->m_brush_style_cb->setCurrentIndex(static_cast<int>(m_shape->brush().style()));
|
2019-03-15 18:07:57 +00:00
|
|
|
|
ui->m_brush_color_kpb->setColor(m_shape->brush().color());
|
2016-01-12 14:02:34 +00:00
|
|
|
|
|
2019-03-04 15:34:42 +00:00
|
|
|
|
ui->m_lock_pos_cb->setChecked(!m_shape->isMovable());
|
|
|
|
|
ui->m_close_polygon->setChecked(m_shape->isClosed());
|
|
|
|
|
}
|
|
|
|
|
else if (m_shapes_list.size() >= 2)
|
|
|
|
|
{
|
|
|
|
|
ui->m_close_polygon->setHidden(true);
|
|
|
|
|
bool same = true;
|
|
|
|
|
//Pen
|
|
|
|
|
Qt::PenStyle ps = m_shapes_list.first()->pen().style();
|
|
|
|
|
for (QetShapeItem *qsi : m_shapes_list) {
|
|
|
|
|
if (qsi->pen().style() != ps) {
|
|
|
|
|
same = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ui->m_style_cb->setCurrentIndex(same ? static_cast<int>(ps) - 1 : -1);
|
|
|
|
|
|
|
|
|
|
same = true;
|
|
|
|
|
qreal pw = m_shapes_list.first()->pen().widthF();
|
|
|
|
|
for (QetShapeItem *qsi : m_shapes_list) {
|
|
|
|
|
if (qsi->pen().widthF() != pw) {
|
|
|
|
|
same = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ui->m_size_dsb->setValue(same ? pw : 0);
|
|
|
|
|
|
|
|
|
|
same = true;
|
|
|
|
|
QColor pc = m_shapes_list.first()->pen().color();
|
|
|
|
|
for (QetShapeItem *qsi : m_shapes_list) {
|
|
|
|
|
if (qsi->pen().color() != pc) {
|
|
|
|
|
same = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-04 15:42:53 +00:00
|
|
|
|
ui->m_color_kpb->setColor(same ? pc : QColor());
|
2019-03-04 15:34:42 +00:00
|
|
|
|
|
|
|
|
|
//Brush
|
|
|
|
|
ui->m_filling_gb->setVisible(true);
|
|
|
|
|
|
|
|
|
|
same = true;
|
|
|
|
|
Qt::BrushStyle bs = m_shapes_list.first()->brush().style();
|
|
|
|
|
for (QetShapeItem *qsi : m_shapes_list) {
|
|
|
|
|
if (qsi->brush().style() != bs) {
|
|
|
|
|
same = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ui->m_brush_style_cb->setCurrentIndex(same ? static_cast<int>(bs) : -1);
|
|
|
|
|
|
|
|
|
|
same = true;
|
|
|
|
|
QColor bc = m_shapes_list.first()->brush().color();
|
|
|
|
|
for (QetShapeItem *qsi : m_shapes_list) {
|
|
|
|
|
if (qsi->brush().color() != bc) {
|
|
|
|
|
same = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-15 18:07:57 +00:00
|
|
|
|
ui->m_brush_color_kpb->setColor(same ? bc : QColor());
|
2019-03-04 15:34:42 +00:00
|
|
|
|
|
|
|
|
|
ui->m_lock_pos_cb->setChecked(false);
|
|
|
|
|
ui->m_close_polygon->setChecked(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setUpEditConnection();
|
2015-06-21 20:16:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
|
@brief ShapeGraphicsItemPropertiesWidget::setLiveEdit
|
|
|
|
|
@param live_edit
|
|
|
|
|
@return always true
|
|
|
|
|
*/
|
2015-06-21 20:16:41 +00:00
|
|
|
|
bool ShapeGraphicsItemPropertiesWidget::setLiveEdit(bool live_edit)
|
|
|
|
|
{
|
2019-03-04 15:34:42 +00:00
|
|
|
|
if (live_edit == m_live_edit) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-06-21 20:16:41 +00:00
|
|
|
|
m_live_edit = live_edit;
|
|
|
|
|
|
2019-03-04 15:34:42 +00:00
|
|
|
|
if (m_live_edit) {
|
|
|
|
|
setUpEditConnection();
|
2024-04-24 18:02:00 +02:00
|
|
|
|
} else {
|
|
|
|
|
clearEditConnection();
|
2016-01-03 13:45:30 +00:00
|
|
|
|
}
|
2015-06-21 20:16:41 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 15:34:42 +00:00
|
|
|
|
/**
|
2023-02-24 19:08:10 +01:00
|
|
|
|
* @brief ShapeGraphicsItemPropertiesWidget::setUpEditConnection
|
|
|
|
|
* Disconnect the previous connection, and reconnect the connection between
|
|
|
|
|
* the editors widgets and void ShapeGraphicsItemPropertiesWidget::apply function
|
2020-08-16 11:19:36 +02:00
|
|
|
|
*/
|
2019-03-04 15:34:42 +00:00
|
|
|
|
void ShapeGraphicsItemPropertiesWidget::setUpEditConnection()
|
|
|
|
|
{
|
2024-04-24 18:02:00 +02:00
|
|
|
|
clearEditConnection();
|
2019-03-04 15:34:42 +00:00
|
|
|
|
|
|
|
|
|
if (m_shape || !m_shapes_list.isEmpty())
|
|
|
|
|
{
|
2024-04-24 18:02:00 +02:00
|
|
|
|
m_edit_connection << connect (ui->m_style_cb, QOverload<int>::of(&QComboBox::activated),
|
|
|
|
|
this, &ShapeGraphicsItemPropertiesWidget::apply);
|
2023-02-24 19:08:10 +01:00
|
|
|
|
|
2024-04-24 18:02:00 +02:00
|
|
|
|
m_edit_connection << connect (ui->m_size_dsb, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
|
|
|
|
|
this, &ShapeGraphicsItemPropertiesWidget::apply);
|
2023-02-24 19:08:10 +01:00
|
|
|
|
|
2024-04-24 18:02:00 +02:00
|
|
|
|
m_edit_connection << connect (ui->m_color_kpb, &KColorButton::changed,
|
|
|
|
|
this, &ShapeGraphicsItemPropertiesWidget::apply);
|
2023-02-24 19:08:10 +01:00
|
|
|
|
|
2024-04-24 18:02:00 +02:00
|
|
|
|
m_edit_connection << connect (ui->m_brush_style_cb, QOverload<int>::of(&QComboBox::activated),
|
|
|
|
|
this, &ShapeGraphicsItemPropertiesWidget::apply);
|
2023-02-24 19:08:10 +01:00
|
|
|
|
|
2024-04-24 18:02:00 +02:00
|
|
|
|
m_edit_connection << connect (ui->m_brush_color_kpb, &KColorButton::changed,
|
|
|
|
|
this, &ShapeGraphicsItemPropertiesWidget::apply);
|
2023-02-24 19:08:10 +01:00
|
|
|
|
|
2024-04-24 18:02:00 +02:00
|
|
|
|
m_edit_connection << connect (ui->m_close_polygon, &QCheckBox::clicked,
|
|
|
|
|
this, &ShapeGraphicsItemPropertiesWidget::apply);
|
2023-02-24 19:08:10 +01:00
|
|
|
|
|
2024-04-24 18:02:00 +02:00
|
|
|
|
m_edit_connection << connect (m_shape, &QetShapeItem::penChanged,
|
|
|
|
|
this, &ShapeGraphicsItemPropertiesWidget::updateUi);
|
2023-02-24 19:08:10 +01:00
|
|
|
|
|
2024-04-24 18:02:00 +02:00
|
|
|
|
m_edit_connection << connect (m_shape, &QetShapeItem::closeChanged,
|
|
|
|
|
this, &ShapeGraphicsItemPropertiesWidget::updateUi);
|
2023-02-24 19:08:10 +01:00
|
|
|
|
|
2024-04-24 18:02:00 +02:00
|
|
|
|
m_edit_connection << connect (m_shape, &QetShapeItem::brushChanged,
|
|
|
|
|
this, &ShapeGraphicsItemPropertiesWidget::updateUi);
|
2023-02-24 19:08:10 +01:00
|
|
|
|
|
2024-04-24 18:02:00 +02:00
|
|
|
|
}
|
2023-02-24 19:08:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShapeGraphicsItemPropertiesWidget::clearEditConnection()
|
|
|
|
|
{
|
2024-04-24 18:02:00 +02:00
|
|
|
|
for (const auto &c : qAsConst(m_edit_connection)) {
|
|
|
|
|
disconnect(c);
|
|
|
|
|
}
|
|
|
|
|
m_edit_connection.clear();
|
2019-03-04 15:34:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShapeGraphicsItemPropertiesWidget::on_m_lock_pos_cb_clicked()
|
|
|
|
|
{
|
|
|
|
|
if (m_shape) {
|
|
|
|
|
m_shape->setMovable(!ui->m_lock_pos_cb->isChecked());
|
|
|
|
|
}
|
|
|
|
|
else if (!m_shapes_list.isEmpty()) {
|
|
|
|
|
for (QPointer<QetShapeItem> qsi : m_shapes_list) {
|
|
|
|
|
qsi->setMovable(!ui->m_lock_pos_cb->isChecked());
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-21 20:16:41 +00:00
|
|
|
|
}
|