mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-01-03 11:00:53 +01:00
Element editor :
The font of the dynamic text field can be edited. The font of the static text field can be edited. The color of the static text field can be edited. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5775 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -73,7 +73,7 @@ bool DynamicTextFieldEditor::setPart(CustomElementPart *part)
|
||||
|
||||
//Setup the connection
|
||||
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::colorChanged, [this](){this->updateForm();});
|
||||
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::fontSizeChanged, [this](){this->updateForm();});
|
||||
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::fontChanged, [this](){this->updateForm();});
|
||||
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::taggChanged, [this](){this->updateForm();});
|
||||
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textFromChanged, [this](){this->updateForm();});
|
||||
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textChanged, [this](){this->updateForm();});
|
||||
@@ -104,9 +104,10 @@ void DynamicTextFieldEditor::updateForm()
|
||||
ui->m_rotation_sb->setValue(QET::correctAngle(m_text_field.data()->rotation()));
|
||||
ui->m_frame_cb->setChecked(m_text_field.data()->frame());
|
||||
ui->m_user_text_le->setText(m_text_field.data()->text());
|
||||
ui->m_size_sb->setValue(m_text_field.data()->fontSize());
|
||||
ui->m_size_sb->setValue(m_text_field.data()->font().pointSize());
|
||||
setColorPushButton(m_text_field.data()->color());
|
||||
ui->m_width_sb->setValue(m_text_field.data()->textWidth());
|
||||
ui->m_font_pb->setText(m_text_field->font().family());
|
||||
|
||||
switch (m_text_field.data()->textFrom())
|
||||
{
|
||||
@@ -117,12 +118,10 @@ void DynamicTextFieldEditor::updateForm()
|
||||
{
|
||||
ui->m_text_from_cb->setCurrentIndex(1);
|
||||
ui->m_elmt_info_cb->setCurrentIndex(ui->m_elmt_info_cb->findData(m_text_field.data()->infoName()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DynamicElementTextItem::CompositeText:
|
||||
ui->m_text_from_cb->setCurrentIndex(2);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
on_m_text_from_cb_activated(ui->m_text_from_cb->currentIndex()); //For enable the good widget
|
||||
@@ -195,9 +194,10 @@ void DynamicTextFieldEditor::on_m_user_text_le_editingFinished()
|
||||
|
||||
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"));
|
||||
undo->enableAnimation(true);
|
||||
QFont font_ = m_text_field->font();
|
||||
font_.setPointSize(ui->m_size_sb->value());
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "font", m_text_field.data()->font(), font_);
|
||||
undo->setText(tr("Modifier la police d'un champ texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
|
||||
@@ -306,3 +306,18 @@ void DynamicTextFieldEditor::on_m_alignment_pb_clicked()
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicTextFieldEditor::on_m_font_pb_clicked()
|
||||
{
|
||||
bool ok;
|
||||
QFont font_ = QFontDialog::getFont(&ok, m_text_field->font(), this);
|
||||
if (ok && font_ != this->font())
|
||||
{
|
||||
ui->m_font_pb->setText(font_.family());
|
||||
ui->m_size_sb->setValue(font_.pointSize());
|
||||
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field.data(), "font", m_text_field->font(), font_);
|
||||
undo->setText(tr("Modifier la police d'un champ texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,8 +58,9 @@ class DynamicTextFieldEditor : public ElementItemEditor
|
||||
void on_m_text_from_cb_activated(int index);
|
||||
void on_m_composite_text_pb_clicked();
|
||||
void on_m_alignment_pb_clicked();
|
||||
|
||||
private:
|
||||
void on_m_font_pb_clicked();
|
||||
|
||||
private:
|
||||
Ui::DynamicTextFieldEditor *ui;
|
||||
QPointer<PartDynamicTextField> m_text_field;
|
||||
QList<QMetaObject::Connection> m_connection_list;
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>299</width>
|
||||
<height>332</height>
|
||||
<width>344</width>
|
||||
<height>285</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -76,13 +76,10 @@
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Taille</string>
|
||||
<string>Police</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1" colspan="2">
|
||||
<widget class="QSpinBox" name="m_size_sb"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
@@ -206,6 +203,16 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QSpinBox" name="m_size_sb"/>
|
||||
</item>
|
||||
<item row="6" column="2">
|
||||
<widget class="QPushButton" name="m_font_pb">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
||||
224
sources/editor/ui/texteditor.cpp
Normal file
224
sources/editor/ui/texteditor.cpp
Normal file
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
Copyright 2006-2019 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 "texteditor.h"
|
||||
#include "ui_texteditor.h"
|
||||
#include "parttext.h"
|
||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
|
||||
/**
|
||||
* @brief TextEditor::TextEditor
|
||||
* Default constructor
|
||||
* @param editor : the element editor who use this editor
|
||||
* @param text : the text to edit
|
||||
* @param parent : the parent widget
|
||||
*/
|
||||
TextEditor::TextEditor(QETElementEditor *editor, PartText *text, QWidget *parent) :
|
||||
ElementItemEditor(editor, parent),
|
||||
ui(new Ui::TextEditor)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setUpEditConnection();
|
||||
if (text)
|
||||
{
|
||||
setPart(text);
|
||||
updateForm();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TextEditor::~TextEditor
|
||||
*/
|
||||
TextEditor::~TextEditor() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TextEditor::updateForm
|
||||
* Update the gui
|
||||
*/
|
||||
void TextEditor::updateForm()
|
||||
{
|
||||
if (m_text.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (QMetaObject::Connection c : m_edit_connection) {
|
||||
disconnect(c);
|
||||
}
|
||||
m_edit_connection.clear();
|
||||
|
||||
ui->m_line_edit->setText(m_text->toPlainText());
|
||||
ui->m_x_sb->setValue(m_text->pos().x());
|
||||
ui->m_y_sb->setValue(m_text->pos().y());
|
||||
ui->m_rotation_sb->setValue(m_text->rotation());
|
||||
ui->m_size_sb->setValue(m_text->font().pointSize());
|
||||
ui->m_font_pb->setText(m_text->font().family());
|
||||
ui->m_color_pb->setColor(m_text->defaultTextColor());
|
||||
|
||||
setUpEditConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TextEditor::setPart
|
||||
* Set the current text to edit.
|
||||
* Set @part to nullptr to clear the current text.
|
||||
* @param part : part to edit
|
||||
* @return : return if @part is a partext or nullptr, else return false
|
||||
*/
|
||||
bool TextEditor::setPart(CustomElementPart *part)
|
||||
{
|
||||
if (!part)
|
||||
{
|
||||
m_text = nullptr;
|
||||
for (QMetaObject::Connection c : m_change_connection) {
|
||||
disconnect(c);
|
||||
}
|
||||
m_change_connection.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (PartText *part_text = dynamic_cast<PartText *>(part))
|
||||
{
|
||||
if (part_text == m_text) {
|
||||
return true;
|
||||
}
|
||||
m_text = part_text;
|
||||
|
||||
m_change_connection.clear();
|
||||
m_change_connection << connect(part_text, &PartText::plainTextChanged, this, &TextEditor::updateForm);
|
||||
m_change_connection << connect(part_text, &PartText::xChanged, this, &TextEditor::updateForm);
|
||||
m_change_connection << connect(part_text, &PartText::yChanged, this, &TextEditor::updateForm);
|
||||
m_change_connection << connect(part_text, &PartText::rotationChanged, this, &TextEditor::updateForm);
|
||||
m_change_connection << connect(part_text, &PartText::fontChanged, this, &TextEditor::updateForm);
|
||||
m_change_connection << connect(part_text, &PartText::colorChanged, this, &TextEditor::updateForm);
|
||||
|
||||
updateForm();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TextEditor::currentPart
|
||||
* @return The current part
|
||||
*/
|
||||
CustomElementPart *TextEditor::currentPart() const {
|
||||
return m_text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TextEditor::setUpEditConnection
|
||||
* Setup the connection between the widgets of this editor and the undo command
|
||||
* use to apply the change to the edited text.
|
||||
*/
|
||||
void TextEditor::setUpEditConnection()
|
||||
{
|
||||
for (QMetaObject::Connection c : m_edit_connection) {
|
||||
disconnect(c);
|
||||
}
|
||||
m_edit_connection.clear();
|
||||
|
||||
m_edit_connection << connect(ui->m_line_edit, &QLineEdit::textEdited, [this]()
|
||||
{
|
||||
QString text_ = ui->m_line_edit->text();
|
||||
if (text_ != m_text->toPlainText())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "text", m_text->toPlainText(), text_);
|
||||
undo->setText(tr("Modifier le contenu d'un champ texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
});
|
||||
m_edit_connection << connect(ui->m_x_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
|
||||
{
|
||||
QPointF pos(ui->m_x_sb->value(), ui->m_y_sb->value());
|
||||
if (pos != m_text->pos())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "pos", m_text->pos(), pos);
|
||||
undo->setText(tr("Déplacer un champ texte"));
|
||||
undo->setAnimated(true, false);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
});
|
||||
m_edit_connection << connect(ui->m_y_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
|
||||
{
|
||||
QPointF pos(ui->m_x_sb->value(), ui->m_y_sb->value());
|
||||
if (pos != m_text->pos())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "pos", m_text->pos(), pos);
|
||||
undo->setText(tr("Déplacer un champ texte"));
|
||||
undo->setAnimated(true, false);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
});
|
||||
m_edit_connection << connect(ui->m_rotation_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
|
||||
{
|
||||
if (ui->m_rotation_sb->value() != m_text->rotation())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "rotation", m_text->rotation(), ui->m_rotation_sb->value());
|
||||
undo->setText(tr("Pivoter un champ texte"));
|
||||
undo->setAnimated(true, false);
|
||||
undoStack().push(undo);
|
||||
}
|
||||
});
|
||||
m_edit_connection << connect(ui->m_size_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
|
||||
{
|
||||
if (m_text->font().pointSize() != ui->m_size_sb->value())
|
||||
{
|
||||
QFont font_ = m_text->font();
|
||||
font_.setPointSize(ui->m_size_sb->value());
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "font", m_text->font(), font_);
|
||||
undo->setText(tr("Modifier la police d'un texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TextEditor::on_m_font_pb_clicked
|
||||
*/
|
||||
void TextEditor::on_m_font_pb_clicked()
|
||||
{
|
||||
bool ok;
|
||||
QFont font_ = QFontDialog::getFont(&ok, m_text->font(), this);
|
||||
|
||||
if (ok && font_ != m_text->font())
|
||||
{
|
||||
ui->m_size_sb->blockSignals(true);
|
||||
ui->m_size_sb->setValue(font_.pointSize());
|
||||
ui->m_size_sb->blockSignals(false);
|
||||
|
||||
ui->m_font_pb->setText(font_.family());
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "font", m_text->font(), font_);
|
||||
undo->setText(tr("Modifier la police d'un texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TextEditor::on_m_color_pb_changed
|
||||
* @param newColor
|
||||
*/
|
||||
void TextEditor::on_m_color_pb_changed(const QColor &newColor)
|
||||
{
|
||||
if (newColor != m_text->defaultTextColor())
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "color", m_text->defaultTextColor(), newColor);
|
||||
undo->setText(tr("Modifier la couleur d'un texte"));
|
||||
undoStack().push(undo);
|
||||
}
|
||||
}
|
||||
58
sources/editor/ui/texteditor.h
Normal file
58
sources/editor/ui/texteditor.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
Copyright 2006-2019 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 TEXTEDITOR_H
|
||||
#define TEXTEDITOR_H
|
||||
|
||||
#include "elementitemeditor.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPointer>
|
||||
|
||||
class PartText;
|
||||
|
||||
namespace Ui {
|
||||
class TextEditor;
|
||||
}
|
||||
|
||||
class TextEditor : public ElementItemEditor
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TextEditor(QETElementEditor *editor, PartText *text = nullptr, QWidget *parent = nullptr);
|
||||
~TextEditor() override;
|
||||
|
||||
void updateForm() override;
|
||||
bool setPart(CustomElementPart *part) override;
|
||||
CustomElementPart *currentPart() const override;
|
||||
|
||||
private slots:
|
||||
void on_m_font_pb_clicked();
|
||||
void on_m_color_pb_changed(const QColor &newColor);
|
||||
private:
|
||||
void setUpEditConnection();
|
||||
|
||||
private:
|
||||
Ui::TextEditor *ui;
|
||||
|
||||
QPointer <PartText> m_text;
|
||||
QList <QMetaObject::Connection> m_edit_connection;
|
||||
QList <QMetaObject::Connection> m_change_connection;
|
||||
};
|
||||
|
||||
#endif // TEXTEDITOR_H
|
||||
132
sources/editor/ui/texteditor.ui
Normal file
132
sources/editor/ui/texteditor.ui
Normal file
@@ -0,0 +1,132 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TextEditor</class>
|
||||
<widget class="QWidget" name="TextEditor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>378</width>
|
||||
<height>133</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="3">
|
||||
<widget class="QSpinBox" name="m_y_sb">
|
||||
<property name="minimum">
|
||||
<number>-10000</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Y :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Police :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="5">
|
||||
<widget class="QSpinBox" name="m_rotation_sb">
|
||||
<property name="wrapping">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string>°</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>360</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Rotation :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSpinBox" name="m_x_sb">
|
||||
<property name="minimum">
|
||||
<number>-10000</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>X :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="m_size_sb"/>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="6">
|
||||
<widget class="QLineEdit" name="m_line_edit">
|
||||
<property name="placeholderText">
|
||||
<string>Entrer votre texte ici</string>
|
||||
</property>
|
||||
<property name="clearButtonEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="5">
|
||||
<widget class="KColorButton" name="m_color_pb"/>
|
||||
</item>
|
||||
<item row="2" column="4">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Couleur :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2" colspan="2">
|
||||
<widget class="QPushButton" name="m_font_pb">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<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>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>KColorButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>kcolorbutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user