mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-02-18 09:39:58 +01:00
Image can be edited in the dock widget
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3944 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -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<Element*>(item))
|
||||
addEditor(new ElementPropertiesWidget(elmt, this));
|
||||
else if (DiagramImageItem *image = dynamic_cast<DiagramImageItem *>(item))
|
||||
addEditor(new ImagePropertiesWidget(image, this));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
29
sources/ui/imagepropertiesdialog.cpp
Normal file
29
sources/ui/imagepropertiesdialog.cpp
Normal file
@@ -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();
|
||||
}
|
||||
31
sources/ui/imagepropertiesdialog.h
Normal file
31
sources/ui/imagepropertiesdialog.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef IMAGEPROPERTIESDIALOG_H
|
||||
#define IMAGEPROPERTIESDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
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
|
||||
67
sources/ui/imagepropertiesdialog.ui
Normal file
67
sources/ui/imagepropertiesdialog.ui
Normal file
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ImagePropertiesDialog</class>
|
||||
<widget class="QDialog" name="ImagePropertiesDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>194</width>
|
||||
<height>52</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Éditer les propriétés de image</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ImagePropertiesDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ImagePropertiesDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
137
sources/ui/imagepropertieswidget.cpp
Normal file
137
sources/ui/imagepropertieswidget.cpp
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "imagepropertieswidget.h"
|
||||
#include "ui_imagepropertieswidget.h"
|
||||
#include "diagramimageitem.h"
|
||||
#include "diagramcommands.h"
|
||||
#include <QUndoCommand>
|
||||
|
||||
/**
|
||||
* @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());
|
||||
}
|
||||
63
sources/ui/imagepropertieswidget.h
Normal file
63
sources/ui/imagepropertieswidget.h
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef IMAGEPROPERTIESWIDGET_H
|
||||
#define IMAGEPROPERTIESWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#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
|
||||
110
sources/ui/imagepropertieswidget.ui
Normal file
110
sources/ui/imagepropertieswidget.ui
Normal file
@@ -0,0 +1,110 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ImagePropertiesWidget</class>
|
||||
<widget class="QWidget" name="ImagePropertiesWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>231</width>
|
||||
<height>94</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="m_lock_pos_cb">
|
||||
<property name="text">
|
||||
<string>Verrouiller la position</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Dimension de l'image</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<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 row="1" column="1">
|
||||
<widget class="QSpinBox" name="m_scale_sb">
|
||||
<property name="suffix">
|
||||
<string>%</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>200</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<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>81</x>
|
||||
<y>40</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>190</x>
|
||||
<y>40</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>190</x>
|
||||
<y>40</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>81</x>
|
||||
<y>40</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user