QetShapeItem can be edited via the properties editor dock

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4024 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2015-06-21 20:16:41 +00:00
parent 33b637e6bf
commit 9c6d362637
11 changed files with 575 additions and 107 deletions

View File

@@ -21,6 +21,8 @@
#include "element.h"
#include "diagramimageitem.h"
#include "imagepropertieswidget.h"
#include "qetshapeitem.h"
#include "shapegraphicsitempropertieswidget.h"
/**
* @brief DiagramPropertiesEditorDockWidget::DiagramPropertiesEditorDockWidget
@@ -108,6 +110,18 @@ void DiagramPropertiesEditorDockWidget::selectionChanged()
addEditor(new ImagePropertiesWidget(static_cast<DiagramImageItem*>(item), this));
break; }
case QetShapeItem::Type: {
if (m_edited_qgi_type == type_)
{
static_cast<ShapeGraphicsItemPropertiesWidget*>(editors().first())->setItem(static_cast<QetShapeItem*>(item));
return;
}
clear();
m_edited_qgi_type = type_;
addEditor(new ShapeGraphicsItemPropertiesWidget(static_cast<QetShapeItem*>(item), this));
break; }
default:
m_edited_qgi_type = -1;
clear();

View File

@@ -0,0 +1,181 @@
/*
Copyright 2006-2015 The QElectroTech Team
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/>.
*/
#include "shapegraphicsitempropertieswidget.h"
#include "ui_shapegraphicsitempropertieswidget.h"
#include "qetshapeitem.h"
#include "diagram.h"
#include "itemresizercommand.h"
#include "changeshapestylecommand.h"
/**
* @brief ShapeGraphicsItemPropertiesWidget::ShapeGraphicsItemPropertiesWidget
* Constructor
* @param item : shape to edit
* @param parent : parent widget
*/
ShapeGraphicsItemPropertiesWidget::ShapeGraphicsItemPropertiesWidget(QetShapeItem *item, QWidget *parent) :
PropertiesEditorWidget(parent),
ui(new Ui::ShapeGraphicsItemPropertiesWidget),
m_shape(nullptr)
{
ui->setupUi(this);
setItem(item);
}
/**
* @brief ShapeGraphicsItemPropertiesWidget::~ShapeGraphicsItemPropertiesWidget
* Destructor
*/
ShapeGraphicsItemPropertiesWidget::~ShapeGraphicsItemPropertiesWidget()
{
delete ui;
}
/**
* @brief ShapeGraphicsItemPropertiesWidget::setItem
* Set @shape as the current edited item
* @param shape
*/
void ShapeGraphicsItemPropertiesWidget::setItem(QetShapeItem *shape)
{
if (!shape) return;
if (shape == m_shape) return;
if (m_shape)
{
disconnect(m_shape, &QGraphicsObject::scaleChanged, this, &ShapeGraphicsItemPropertiesWidget::updateUi);
disconnect(m_shape, &QetShapeItem::styleChanged, this, &ShapeGraphicsItemPropertiesWidget::updateUi);
}
m_shape = shape;
connect(m_shape, &QGraphicsObject::scaleChanged, this, &ShapeGraphicsItemPropertiesWidget::updateUi);
connect(m_shape, &QetShapeItem::styleChanged, this, &ShapeGraphicsItemPropertiesWidget::updateUi);
m_old_pen_style = m_shape->penStyle();
m_old_scale = m_shape->scale();
updateUi();
}
/**
* @brief ShapeGraphicsItemPropertiesWidget::apply
* Apply the current change, by pushing an undo command to the
* undo stack of the shape diagram.
*/
void ShapeGraphicsItemPropertiesWidget::apply()
{
if (m_live_edit)
{
disconnect(m_shape, &QGraphicsObject::scaleChanged, this, &ShapeGraphicsItemPropertiesWidget::updateUi);
disconnect(m_shape, &QetShapeItem::styleChanged, this, &ShapeGraphicsItemPropertiesWidget::updateUi);
}
if (m_shape->diagram())
if (QUndoCommand *undo = associatedUndo())
m_shape->diagram()->undoStack().push(undo);
m_old_pen_style = m_shape->penStyle();
m_old_scale = m_shape->scale();
if (m_live_edit)
{
connect(m_shape, &QGraphicsObject::scaleChanged, this, &ShapeGraphicsItemPropertiesWidget::updateUi);
connect(m_shape, &QetShapeItem::styleChanged, this, &ShapeGraphicsItemPropertiesWidget::updateUi);
}
}
/**
* @brief ShapeGraphicsItemPropertiesWidget::reset
* Reset the change
*/
void ShapeGraphicsItemPropertiesWidget::reset()
{
m_shape->setStyle(m_old_pen_style);
m_shape->setScale(m_old_scale);
updateUi();
}
/**
* @brief ShapeGraphicsItemPropertiesWidget::associatedUndo
* @return an undo command that represent the change edited by this widget.
* The returned undo command can be a ChangeShapeStyleCommand, ItemResizerCommand or
* a ChangeShapeStyleCommand with a ItemResizerCommand as child.
* If there isn't change, return nullptr
*/
QUndoCommand* ShapeGraphicsItemPropertiesWidget::associatedUndo() const
{
QUndoCommand *undo = nullptr;
Qt::PenStyle new_style = Qt::PenStyle(ui->m_style_cb->currentIndex() + 1);
if (new_style != m_old_pen_style) undo = new ChangeShapeStyleCommand(m_shape, m_old_pen_style, new_style);
qreal value = ui->m_scale_slider->value();
value /= 100;
if (value != m_old_scale)
{
if (undo)
new ItemResizerCommand(m_shape, m_old_scale, value, tr("une shape"), undo);
else
undo = new ItemResizerCommand(m_shape, m_old_scale, value, tr("une shape"));
}
return undo;
}
/**
* @brief ShapeGraphicsItemPropertiesWidget::updateUi
*/
void ShapeGraphicsItemPropertiesWidget::updateUi()
{
ui->m_style_cb->setCurrentIndex(static_cast<int>(m_shape->penStyle()) - 1);
ui->m_lock_pos_cb->setChecked(!m_shape->isMovable());
ui->m_scale_slider->setValue(m_shape->scale() * 100);
}
/**
* @brief ShapeGraphicsItemPropertiesWidget::setLiveEdit
* @param live_edit
* @return always true
*/
bool ShapeGraphicsItemPropertiesWidget::setLiveEdit(bool live_edit)
{
if (live_edit == m_live_edit) return true;
m_live_edit = live_edit;
if (m_live_edit)
{
connect (ui->m_scale_slider, &QSlider::sliderReleased, this, &ShapeGraphicsItemPropertiesWidget::apply);
connect (ui->m_scale_sb, &QSpinBox::editingFinished, this, &ShapeGraphicsItemPropertiesWidget::apply);
connect (ui->m_style_cb, SIGNAL(activated(int)), this, SLOT(apply()));
}
else
{
disconnect (ui->m_scale_slider, &QSlider::sliderReleased, this, &ShapeGraphicsItemPropertiesWidget::apply);
disconnect (ui->m_scale_sb, &QSpinBox::editingFinished, this, &ShapeGraphicsItemPropertiesWidget::apply);
disconnect (ui->m_style_cb, SIGNAL(activated(int)), this, SLOT(apply()));
}
return true;
}
void ShapeGraphicsItemPropertiesWidget::on_m_scale_slider_valueChanged(int value) {
qreal scale = value;
m_shape->setScale(scale / 100);
}
void ShapeGraphicsItemPropertiesWidget::on_m_lock_pos_cb_clicked() {
m_shape->setMovable(!ui->m_lock_pos_cb->isChecked());
}

View File

@@ -0,0 +1,64 @@
/*
Copyright 2006-2015 The QElectroTech Team
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/>.
*/
#ifndef SHAPEGRAPHICSITEMPROPERTIESWIDGET_H
#define SHAPEGRAPHICSITEMPROPERTIESWIDGET_H
#include "PropertiesEditor/propertieseditorwidget.h"
namespace Ui {
class ShapeGraphicsItemPropertiesWidget;
}
class QetShapeItem;
/**
* @brief The ShapeGraphicsItemPropertiesWidget class
* Provide a widget to edit the properties of a QetShapeItem
*/
class ShapeGraphicsItemPropertiesWidget : public PropertiesEditorWidget
{
Q_OBJECT
public:
explicit ShapeGraphicsItemPropertiesWidget(QetShapeItem *item, QWidget *parent = 0);
~ShapeGraphicsItemPropertiesWidget();
void setItem(QetShapeItem *shape);
public slots:
virtual void apply();
virtual void reset();
public:
virtual QUndoCommand* associatedUndo() const;
virtual QString title() const { return tr("Éditer les propriétés d'une primitive "); }
virtual void updateUi();
virtual bool setLiveEdit(bool live_edit);
private slots:
void on_m_scale_slider_valueChanged(int value);
void on_m_lock_pos_cb_clicked();
private:
Ui::ShapeGraphicsItemPropertiesWidget *ui;
QetShapeItem *m_shape;
Qt::PenStyle m_old_pen_style;
qreal m_old_scale;
};
#endif // SHAPEGRAPHICSITEMPROPERTIESWIDGET_H

View File

@@ -0,0 +1,147 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ShapeGraphicsItemPropertiesWidget</class>
<widget class="QWidget" name="ShapeGraphicsItemPropertiesWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>175</width>
<height>174</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Type de trait</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QComboBox" name="m_style_cb">
<item>
<property name="text">
<string>Normal</string>
</property>
</item>
<item>
<property name="text">
<string>Tiret</string>
</property>
</item>
<item>
<property name="text">
<string>Pointillé</string>
</property>
</item>
<item>
<property name="text">
<string>Traits et points</string>
</property>
</item>
<item>
<property name="text">
<string>Traits points points</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="m_lock_pos_cb">
<property name="text">
<string>Verrouiller la position</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Échelle</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QSlider" name="m_scale_slider">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>200</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="m_scale_sb">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>200</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>m_scale_slider</sender>
<signal>valueChanged(int)</signal>
<receiver>m_scale_sb</receiver>
<slot>setValue(int)</slot>
<hints>
<hint type="sourcelabel">
<x>174</x>
<y>234</y>
</hint>
<hint type="destinationlabel">
<x>355</x>
<y>234</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_scale_sb</sender>
<signal>valueChanged(int)</signal>
<receiver>m_scale_slider</receiver>
<slot>setValue(int)</slot>
<hints>
<hint type="sourcelabel">
<x>355</x>
<y>234</y>
</hint>
<hint type="destinationlabel">
<x>174</x>
<y>234</y>
</hint>
</hints>
</connection>
</connections>
</ui>