mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-01-05 11:50:52 +01:00
Element editor : dynamic text item can be added directly from the element editor (WIP)
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5046 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
162
sources/editor/ui/dynamictextfieldeditor.cpp
Normal file
162
sources/editor/ui/dynamictextfieldeditor.cpp
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
Copyright 2006-2017 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 "dynamictextfieldeditor.h"
|
||||
#include "ui_dynamictextfieldeditor.h"
|
||||
#include "customelementpart.h"
|
||||
#include "partdynamictextfield.h"
|
||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
|
||||
#include <QPointer>
|
||||
#include <QGraphicsItem>
|
||||
#include <QColorDialog>
|
||||
|
||||
DynamicTextFieldEditor::DynamicTextFieldEditor(QETElementEditor *editor, PartDynamicTextField *text_field, QWidget *parent) :
|
||||
ElementItemEditor(editor, parent),
|
||||
ui(new Ui::DynamicTextFieldEditor)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->m_composite_text_pb->setDisabled(true);
|
||||
ui->m_elmt_info_cb->setDisabled(true);
|
||||
if(text_field)
|
||||
setPart(text_field);
|
||||
}
|
||||
|
||||
DynamicTextFieldEditor::~DynamicTextFieldEditor()
|
||||
{
|
||||
delete ui;
|
||||
if(!m_connection_list.isEmpty())
|
||||
for(QMetaObject::Connection con : m_connection_list)
|
||||
disconnect(con);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DynamicTextFieldEditor::setPart
|
||||
* Set @part as current edited part of this widget.
|
||||
* @param part
|
||||
* @return true if @part can be edited by this widget
|
||||
*/
|
||||
bool DynamicTextFieldEditor::setPart(CustomElementPart *part)
|
||||
{
|
||||
//Remove previous connection
|
||||
if(!m_connection_list.isEmpty())
|
||||
for(QMetaObject::Connection con : m_connection_list)
|
||||
disconnect(con);
|
||||
|
||||
QGraphicsItem *qgi = part->toItem();
|
||||
if(!qgi)
|
||||
return false;
|
||||
else if (qgi->type() != PartDynamicTextField::Type)
|
||||
return false;
|
||||
|
||||
m_text_field = static_cast<PartDynamicTextField *>(qgi);
|
||||
updateForm();
|
||||
|
||||
//Setup the connection
|
||||
m_connection_list << connect(m_text_field, &PartDynamicTextField::colorChanged, [this](){this->updateForm();});
|
||||
m_connection_list << connect(m_text_field, &PartDynamicTextField::fontSizeChanged, [this](){this->updateForm();});
|
||||
m_connection_list << connect(m_text_field, &PartDynamicTextField::taggChanged, [this](){this->updateForm();});
|
||||
m_connection_list << connect(m_text_field, &PartDynamicTextField::textFromChanged, [this](){this->updateForm();});
|
||||
m_connection_list << connect(m_text_field, &PartDynamicTextField::textChanged, [this](){this->updateForm();});
|
||||
m_connection_list << connect(m_text_field, &PartDynamicTextField::infoNameChanged, [this](){this->updateForm();});
|
||||
m_connection_list << connect(m_text_field, &PartDynamicTextField::rotationChanged, [this](){this->updateForm();});
|
||||
m_connection_list << connect(m_text_field, &PartDynamicTextField::compositeTextChanged, [this]() {this->updateForm();});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DynamicTextFieldEditor::currentPart
|
||||
* @return The current edited part, note they can return nullptr if
|
||||
* there is not a currently edited part.
|
||||
*/
|
||||
CustomElementPart *DynamicTextFieldEditor::currentPart() const {
|
||||
return m_text_field.data();
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::updateForm()
|
||||
{
|
||||
if(m_text_field)
|
||||
{
|
||||
ui->m_x_sb->setValue(m_text_field.data()->x());
|
||||
ui->m_y_sb->setValue(m_text_field.data()->y());
|
||||
ui->m_rotation_sb->setValue(QET::correctAngle(m_text_field.data()->rotation()));
|
||||
ui->m_user_text_le->setText(m_text_field.data()->text());
|
||||
ui->m_size_sb->setValue(m_text_field.data()->fontSize());
|
||||
ui->m_tagg_le->setText(m_text_field.data()->tagg());
|
||||
setColorPushButton(m_text_field.data()->color());
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::setColorPushButton(QColor color)
|
||||
{
|
||||
QPalette palette;
|
||||
palette.setColor(QPalette::Button, color);
|
||||
ui->m_color_pb->setStyleSheet(QString("background-color: %1; min-height: 1.5em; border-style: outset; border-width: 2px; border-color: gray; border-radius: 4px;").arg(color.name()));
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::on_m_x_sb_editingFinished()
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "x", m_text_field.data()->x(), ui->m_x_sb->value());
|
||||
undo->setText(tr("Déplacer un champ texte dynamique"));
|
||||
undo->enableAnimation(true);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::on_m_y_sb_editingFinished()
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "y", m_text_field.data()->y(), ui->m_y_sb->value());
|
||||
undo->setText(tr("Déplacer un champ texte dynamique"));
|
||||
undo->enableAnimation(true);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::on_m_rotation_sb_editingFinished()
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "rotation", m_text_field.data()->rotation(), ui->m_rotation_sb->value());
|
||||
undo->setText(tr("Pivoter 2un champ texte dynamique"));
|
||||
undo->enableAnimation(true);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::on_m_user_text_le_editingFinished()
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "text", m_text_field.data()->text(), ui->m_user_text_le->text());
|
||||
undo->setText(tr("Modifier le texte d'un champ texte dynamique"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::on_m_size_sb_editingFinished()
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "fontSize", m_text_field.data()->fontSize(), ui->m_size_sb->value());
|
||||
undo->setText(tr("Modifier la taille d'un champ texte dynamique"));
|
||||
undo->enableAnimation(true);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::on_m_color_pb_clicked()
|
||||
{
|
||||
QColor color = QColorDialog::getColor(m_text_field.data()->color(), this, tr("Couleur du texte"));
|
||||
|
||||
if(color.isValid() && color != m_text_field.data()->color())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "color", m_text_field.data()->color(), color);
|
||||
undo->setText(tr("Modifier la couleur d'un champ texte dynamique"));
|
||||
undoStack().push(undo);
|
||||
setColorPushButton(m_text_field.data()->color());
|
||||
}
|
||||
}
|
||||
61
sources/editor/ui/dynamictextfieldeditor.h
Normal file
61
sources/editor/ui/dynamictextfieldeditor.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright 2006-2017 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 DYNAMICTEXTFIELDEDITOR_H
|
||||
#define DYNAMICTEXTFIELDEDITOR_H
|
||||
|
||||
#include "elementitemeditor.h"
|
||||
#include "partdynamictextfield.h"
|
||||
|
||||
namespace Ui {
|
||||
class DynamicTextFieldEditor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The DynamicTextFieldEditor class
|
||||
* This class provide a widget used to edit the property of a dynamic text field
|
||||
*/
|
||||
class DynamicTextFieldEditor : public ElementItemEditor
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DynamicTextFieldEditor(QETElementEditor *editor, PartDynamicTextField *text_field = nullptr, QWidget *parent = nullptr);
|
||||
~DynamicTextFieldEditor();
|
||||
|
||||
bool setPart(CustomElementPart *part) override;
|
||||
CustomElementPart *currentPart() const override;
|
||||
void updateForm() override;
|
||||
|
||||
private:
|
||||
void setColorPushButton(QColor color);
|
||||
|
||||
private slots:
|
||||
void on_m_x_sb_editingFinished();
|
||||
void on_m_y_sb_editingFinished();
|
||||
void on_m_rotation_sb_editingFinished();
|
||||
void on_m_user_text_le_editingFinished();
|
||||
void on_m_size_sb_editingFinished();
|
||||
void on_m_color_pb_clicked();
|
||||
|
||||
private:
|
||||
Ui::DynamicTextFieldEditor *ui;
|
||||
QPointer<PartDynamicTextField> m_text_field;
|
||||
QList<QMetaObject::Connection> m_connection_list;
|
||||
};
|
||||
|
||||
#endif // DYNAMICTEXTFIELDEDITOR_H
|
||||
176
sources/editor/ui/dynamictextfieldeditor.ui
Normal file
176
sources/editor/ui/dynamictextfieldeditor.ui
Normal file
@@ -0,0 +1,176 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DynamicTextFieldEditor</class>
|
||||
<widget class="QWidget" name="DynamicTextFieldEditor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>336</width>
|
||||
<height>264</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Taille</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Source du texte</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Couleur</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="6">
|
||||
<widget class="QComboBox" name="m_elmt_info_cb"/>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Tagg</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="6">
|
||||
<widget class="QComboBox" name="m_text_from_cb">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Texte utilisateur</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Information de l'élément</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Texte composé</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1" colspan="6">
|
||||
<widget class="QLineEdit" name="m_tagg_le"/>
|
||||
</item>
|
||||
<item row="5" column="1" colspan="6">
|
||||
<widget class="QSpinBox" name="m_size_sb"/>
|
||||
</item>
|
||||
<item row="4" column="1" colspan="6">
|
||||
<widget class="QPushButton" name="m_composite_text_pb">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="7">
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>X</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="m_x_sb">
|
||||
<property name="minimum">
|
||||
<double>-5000.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>5000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Y</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="m_y_sb">
|
||||
<property name="minimum">
|
||||
<double>-5000.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>5000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Rotation</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="m_rotation_sb">
|
||||
<property name="maximum">
|
||||
<number>359</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="6">
|
||||
<widget class="QLineEdit" name="m_user_text_le"/>
|
||||
</item>
|
||||
<item row="7" column="1" colspan="6">
|
||||
<widget class="QPushButton" name="m_color_pb">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<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/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user