diff --git a/sources/qetgraphicsitem/diagramimageitem.cpp b/sources/qetgraphicsitem/diagramimageitem.cpp
index f3bd1ae72..9413a58bb 100644
--- a/sources/qetgraphicsitem/diagramimageitem.cpp
+++ b/sources/qetgraphicsitem/diagramimageitem.cpp
@@ -16,8 +16,8 @@
along with QElectroTech. If not, see .
*/
#include "diagramimageitem.h"
-#include "diagramcommands.h"
#include "diagram.h"
+#include "imagepropertiesdialog.h"
/**
* @brief DiagramImageItem::DiagramImageItem
@@ -27,10 +27,7 @@
DiagramImageItem::DiagramImageItem(QetGraphicsItem *parent_item):
QetGraphicsItem(parent_item)
{
- setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
-#if QT_VERSION >= 0x040600
- setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
-#endif
+ setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemSendsGeometryChanges);
}
/**
@@ -44,10 +41,7 @@ DiagramImageItem::DiagramImageItem(const QPixmap &pixmap, QetGraphicsItem *paren
pixmap_(pixmap)
{
setTransformOriginPoint(boundingRect().center());
- setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
-#if QT_VERSION >= 0x040600
- setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
-#endif
+ setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemSendsGeometryChanges);
}
/**
@@ -85,76 +79,14 @@ void DiagramImageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
}
/**
- * @brief DiagramImageItem::setScale
- * @param scale the value of @scale must be betwen 1 and 200
+ * @brief DiagramImageItem::editProperty
+ * Open the approriate dialog to edit this image
*/
-void DiagramImageItem::PreviewScale(int scale) {
- if (scale >= 1 && scale <= 200) {
- qreal new_scale = scale;
- new_scale /= 100;
- setScale(new_scale);
- }
-}
-
-/**
- * @brief Edit the image with ....
- */
-void DiagramImageItem::editProperty() {
+void DiagramImageItem::editProperty()
+{
if (diagram() -> isReadOnly()) return;
- //the range for scale image and divisor factor
- int min_range = 1;
- int max_range = 200;
- int factor_range = 100;
-
- //the dialog
- QDialog property_dialog(diagram()->views().at(0));
- property_dialog.setWindowTitle(tr("Éditer les propriétés d'une image", "window title"));
- //the main layout
- QVBoxLayout dialog_layout(&property_dialog);
-
- //GroupBox for resizer image
- QGroupBox resize_groupe(tr("Dimension de l'image", "image size"));
- dialog_layout.addWidget(&resize_groupe);
- QHBoxLayout resize_layout(&resize_groupe);
-
- //slider
- QSlider slider(Qt::Horizontal, &property_dialog);
- slider.setRange(min_range, max_range);
- qreal scale_= scale();
- slider.setValue(scale_*factor_range);
- //spinbox
- QSpinBox spin_box(&property_dialog);
- spin_box.setRange(min_range, max_range);
- spin_box.setValue(scale_*factor_range);
- spin_box.setSuffix(" %");
- //synchro slider with spinbox
- connect(&slider, SIGNAL(valueChanged(int)), &spin_box, SLOT(setValue(int)));
- connect(&slider, SIGNAL(valueChanged(int)), this, SLOT(PreviewScale(int)));
- connect(&spin_box, SIGNAL(valueChanged(int)), &slider, SLOT(setValue(int)));
- //add slider and spinbox to layout
- resize_layout.addWidget(&slider);
- resize_layout.addWidget(&spin_box);
- //check box for disable move
- QCheckBox cb(tr("Verrouiller la position"), &property_dialog);
- cb.setChecked(!is_movable_);
- dialog_layout.addWidget(&cb);
-
- //dialog button, box
- QDialogButtonBox dbb(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
- dialog_layout.addWidget(&dbb);
- connect(&dbb, SIGNAL(accepted()), &property_dialog, SLOT(accept()));
- connect(&dbb, SIGNAL(rejected()), &property_dialog, SLOT(reject()));
-
- //dialog is accepted...
- if (property_dialog.exec() == QDialog::Accepted) {
- cb.isChecked() ? is_movable_=false : is_movable_=true;
- qreal new_scale = slider.value();
- new_scale /= factor_range;
- if (scale_ != new_scale) diagram()->undoStack().push(new ItemResizerCommand(this, scale_, new_scale, tr("une image")));
- }
- //...or not
- else setScale(scale_);
- return;
+ ImagePropertiesDialog dialog(this, QApplication::activeWindow());
+ dialog.exec();
}
/**
diff --git a/sources/qetgraphicsitem/diagramimageitem.h b/sources/qetgraphicsitem/diagramimageitem.h
index 63eaea207..26e60b25d 100644
--- a/sources/qetgraphicsitem/diagramimageitem.h
+++ b/sources/qetgraphicsitem/diagramimageitem.h
@@ -60,11 +60,6 @@ class DiagramImageItem : public QetGraphicsItem {
protected:
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
- signals:
-
- private slots:
- void PreviewScale(int);
-
protected:
QPixmap pixmap_;
};
diff --git a/sources/qetgraphicsitem/qetgraphicsitem.h b/sources/qetgraphicsitem/qetgraphicsitem.h
index 01ade637e..7510b92a9 100644
--- a/sources/qetgraphicsitem/qetgraphicsitem.h
+++ b/sources/qetgraphicsitem/qetgraphicsitem.h
@@ -32,11 +32,15 @@ class QetGraphicsItem : public QGraphicsObject
virtual ~QetGraphicsItem() = 0;
//public methode
- Diagram *diagram () const;
+ Diagram *diagram () const;
virtual void setPos (const QPointF &p);
virtual void setPos (qreal x, qreal y);
virtual void rotateBy (const qreal &);
virtual void applyRotation (const qreal &);
+
+ virtual bool isMovable () const {return is_movable_;}
+ virtual void setMovable (bool movable) { is_movable_ = movable;}
+
virtual void editProperty () {}
virtual QString name ()const {return QString("");}
diff --git a/sources/ui/diagrampropertieseditordockwidget.cpp b/sources/ui/diagrampropertieseditordockwidget.cpp
index 6851ed1d3..1f158580e 100644
--- a/sources/ui/diagrampropertieseditordockwidget.cpp
+++ b/sources/ui/diagrampropertieseditordockwidget.cpp
@@ -19,6 +19,8 @@
#include "elementpropertieswidget.h"
#include "diagram.h"
#include "element.h"
+#include "diagramimageitem.h"
+#include "imagepropertieswidget.h"
/**
* @brief DiagramPropertiesEditorDockWidget::DiagramPropertiesEditorDockWidget
@@ -69,11 +71,15 @@ void DiagramPropertiesEditorDockWidget::selectionChanged()
{
if (!m_diagram) return;
clear();
+
if (m_diagram->selectedItems().size() == 1)
{
QGraphicsItem *item = m_diagram->selectedItems().first();
+
if (Element *elmt = dynamic_cast(item))
addEditor(new ElementPropertiesWidget(elmt, this));
+ else if (DiagramImageItem *image = dynamic_cast(item))
+ addEditor(new ImagePropertiesWidget(image, this));
}
}
diff --git a/sources/ui/imagepropertiesdialog.cpp b/sources/ui/imagepropertiesdialog.cpp
new file mode 100644
index 000000000..acb0f0c96
--- /dev/null
+++ b/sources/ui/imagepropertiesdialog.cpp
@@ -0,0 +1,29 @@
+#include "imagepropertiesdialog.h"
+#include "ui_imagepropertiesdialog.h"
+#include "imagepropertieswidget.h"
+#include "diagramimageitem.h"
+
+ImagePropertiesDialog::ImagePropertiesDialog(DiagramImageItem *image, QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::ImagePropertiesDialog)
+{
+ ui->setupUi(this);
+ m_editor = new ImagePropertiesWidget(image, this);
+ ui->verticalLayout->insertWidget(0, m_editor);
+}
+
+ImagePropertiesDialog::~ImagePropertiesDialog() {
+ delete ui;
+}
+
+void ImagePropertiesDialog::setImageItem(DiagramImageItem *image) {
+ m_editor->setImageItem(image);
+}
+
+void ImagePropertiesDialog::on_buttonBox_accepted() {
+ m_editor->apply();
+}
+
+void ImagePropertiesDialog::on_buttonBox_rejected() {
+ m_editor->reset();
+}
diff --git a/sources/ui/imagepropertiesdialog.h b/sources/ui/imagepropertiesdialog.h
new file mode 100644
index 000000000..6f750c236
--- /dev/null
+++ b/sources/ui/imagepropertiesdialog.h
@@ -0,0 +1,31 @@
+#ifndef IMAGEPROPERTIESDIALOG_H
+#define IMAGEPROPERTIESDIALOG_H
+
+#include
+
+class ImagePropertiesWidget;
+class DiagramImageItem;
+
+namespace Ui {
+ class ImagePropertiesDialog;
+}
+
+class ImagePropertiesDialog : public QDialog
+{
+ Q_OBJECT
+
+ public:
+ explicit ImagePropertiesDialog(DiagramImageItem *image = nullptr, QWidget *parent = 0);
+ ~ImagePropertiesDialog();
+ void setImageItem (DiagramImageItem *image);
+
+ private slots:
+ void on_buttonBox_accepted();
+ void on_buttonBox_rejected();
+
+ private:
+ Ui::ImagePropertiesDialog *ui;
+ ImagePropertiesWidget *m_editor;
+};
+
+#endif // IMAGEPROPERTIESDIALOG_H
diff --git a/sources/ui/imagepropertiesdialog.ui b/sources/ui/imagepropertiesdialog.ui
new file mode 100644
index 000000000..3023b647a
--- /dev/null
+++ b/sources/ui/imagepropertiesdialog.ui
@@ -0,0 +1,67 @@
+
+
+ ImagePropertiesDialog
+
+
+
+ 0
+ 0
+ 194
+ 52
+
+
+
+ Éditer les propriétés de image
+
+
+
+ QLayout::SetMinimumSize
+
+ -
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+
+
+
+
+
+
+
+ buttonBox
+ accepted()
+ ImagePropertiesDialog
+ accept()
+
+
+ 248
+ 254
+
+
+ 157
+ 274
+
+
+
+
+ buttonBox
+ rejected()
+ ImagePropertiesDialog
+ reject()
+
+
+ 316
+ 260
+
+
+ 286
+ 274
+
+
+
+
+
diff --git a/sources/ui/imagepropertieswidget.cpp b/sources/ui/imagepropertieswidget.cpp
new file mode 100644
index 000000000..3d7de8353
--- /dev/null
+++ b/sources/ui/imagepropertieswidget.cpp
@@ -0,0 +1,137 @@
+/*
+ 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 .
+*/
+#include "imagepropertieswidget.h"
+#include "ui_imagepropertieswidget.h"
+#include "diagramimageitem.h"
+#include "diagramcommands.h"
+#include
+
+/**
+ * @brief ImagePropertiesWidget::ImagePropertiesWidget
+ * Constructor
+ * @param image : image to edit properties
+ * @param parent : parent widget
+ */
+ImagePropertiesWidget::ImagePropertiesWidget(DiagramImageItem *image, QWidget *parent) :
+ PropertiesEditorWidget(parent),
+ ui(new Ui::ImagePropertiesWidget),
+ m_image(nullptr)
+{
+ ui->setupUi(this);
+ this->setDisabled(true);
+ setImageItem(image);
+}
+
+/**
+ * @brief ImagePropertiesWidget::~ImagePropertiesWidget
+ * Destructor
+ */
+ImagePropertiesWidget::~ImagePropertiesWidget() {
+ delete ui;
+}
+
+/**
+ * @brief ImagePropertiesWidget::setImageItem
+ * Set the image to edit properties
+ * @param image : image to edit
+ */
+void ImagePropertiesWidget::setImageItem(DiagramImageItem *image)
+{
+ if(!image) return;
+ this->setEnabled(true);
+ if (m_image == image) return;
+ if (m_image)
+ disconnect(m_image, SIGNAL(destroyed()), this, SLOT(imageWasDeleted()));
+
+ m_image = image;
+ connect(m_image, SIGNAL(destroyed()), this, SLOT(imageWasDeleted()));
+ m_movable = image->isMovable();
+ m_scale = m_image->scale();
+ updateUi();
+}
+
+/**
+ * @brief ImagePropertiesWidget::apply
+ * Apply the change
+ */
+void ImagePropertiesWidget::apply()
+{
+ if(!m_image) return;
+
+ if (m_image->diagram())
+ m_image->diagram()->undoStack().push(associatedUndo());
+
+ m_scale = m_image->scale();
+}
+
+/**
+ * @brief ImagePropertiesWidget::reset
+ * Reset the change
+ */
+void ImagePropertiesWidget::reset()
+{
+ if(!m_image) return;
+
+ m_image->setScale(m_scale);
+ m_image->setMovable(m_movable);
+ updateUi();
+}
+
+/**
+ * @brief ImagePropertiesWidget::associatedUndo
+ * @return the change in an undo command (ItemResizerCommand)
+ */
+QUndoCommand* ImagePropertiesWidget::associatedUndo()
+{
+ qreal value = ui->m_scale_slider->value();
+ value /= 100;
+ return new ItemResizerCommand(m_image, m_scale, value, tr("une image"));
+}
+
+/**
+ * @brief ImagePropertiesWidget::updateUi
+ * Udpdate the ui, notably when the image to edit change
+ */
+void ImagePropertiesWidget::updateUi()
+{
+ ui->m_scale_slider->setValue(m_scale * 100);
+ ui->m_lock_pos_cb->setChecked(!m_movable);
+}
+
+/**
+ * @brief ImagePropertiesWidget::on_m_scale_slider_valueChanged
+ * Update the size of image when move slider.
+ * @param value
+ */
+void ImagePropertiesWidget::on_m_scale_slider_valueChanged(int value)
+{
+ qreal scale = value;
+ m_image->setScale(scale / 100);
+}
+
+void ImagePropertiesWidget::imageWasDeleted() {
+ m_image = nullptr;
+}
+
+/**
+ * @brief ImagePropertiesWidget::on_m_lock_pos_cb_clicked
+ * Set movable or not the image according to corresponding check box
+ */
+void ImagePropertiesWidget::on_m_lock_pos_cb_clicked() {
+ m_image->setMovable(!ui->m_lock_pos_cb->isChecked());
+}
diff --git a/sources/ui/imagepropertieswidget.h b/sources/ui/imagepropertieswidget.h
new file mode 100644
index 000000000..b5e7288e9
--- /dev/null
+++ b/sources/ui/imagepropertieswidget.h
@@ -0,0 +1,63 @@
+/*
+ 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 .
+*/
+#ifndef IMAGEPROPERTIESWIDGET_H
+#define IMAGEPROPERTIESWIDGET_H
+
+#include
+#include "PropertiesEditor/propertieseditorwidget.h"
+
+class DiagramImageItem;
+
+namespace Ui {
+ class ImagePropertiesWidget;
+}
+
+/**
+ * @brief The ImagePropertiesWidget class
+ * This class provide a widget to edit the propertie of a DiagramImageItem
+ */
+class ImagePropertiesWidget : public PropertiesEditorWidget
+{
+ Q_OBJECT
+
+ public:
+ explicit ImagePropertiesWidget(DiagramImageItem *image = nullptr, QWidget *parent = 0);
+ ~ImagePropertiesWidget();
+ void setImageItem (DiagramImageItem *image);
+
+ void apply();
+ void reset();
+ QUndoCommand* associatedUndo();
+
+ private:
+ void updateUi();
+
+ private slots:
+ void on_m_scale_slider_valueChanged(int value);
+ void imageWasDeleted();
+
+ void on_m_lock_pos_cb_clicked();
+
+ private:
+ Ui::ImagePropertiesWidget *ui;
+ DiagramImageItem *m_image;
+ bool m_movable;
+ qreal m_scale;
+};
+
+#endif // IMAGEPROPERTIESWIDGET_H
diff --git a/sources/ui/imagepropertieswidget.ui b/sources/ui/imagepropertieswidget.ui
new file mode 100644
index 000000000..2f0de4440
--- /dev/null
+++ b/sources/ui/imagepropertieswidget.ui
@@ -0,0 +1,110 @@
+
+
+ ImagePropertiesWidget
+
+
+
+ 0
+ 0
+ 231
+ 94
+
+
+
+ Form
+
+
+
+ QLayout::SetMinimumSize
+
+ -
+
+
+ Verrouiller la position
+
+
+
+ -
+
+
+ Dimension de l'image
+
+
+
+ -
+
+
+ 1
+
+
+ 200
+
+
+ Qt::Horizontal
+
+
+
+ -
+
+
+ %
+
+
+ 1
+
+
+ 200
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+
+
+
+
+
+ m_scale_slider
+ valueChanged(int)
+ m_scale_sb
+ setValue(int)
+
+
+ 81
+ 40
+
+
+ 190
+ 40
+
+
+
+
+ m_scale_sb
+ valueChanged(int)
+ m_scale_slider
+ setValue(int)
+
+
+ 190
+ 40
+
+
+ 81
+ 40
+
+
+
+
+