Mod TextEditor

the ui file is written in the TextEditor class
    Add switch for KF5 (QT6)
This commit is contained in:
Simon De Backer
2020-12-18 17:39:00 +01:00
parent 2e543dd1f7
commit 0cc3099908
4 changed files with 135 additions and 173 deletions

View File

@@ -51,7 +51,6 @@ set(QET_RES_FILES
${QET_DIR}/sources/editor/ui/lineeditor.ui
${QET_DIR}/sources/editor/ui/polygoneditor.ui
${QET_DIR}/sources/editor/ui/rectangleeditor.ui
${QET_DIR}/sources/editor/ui/texteditor.ui
${QET_DIR}/sources/ElementsCollection/ui/renamedialog.ui
${QET_DIR}/sources/factory/ui/addtabledialog.ui
${QET_DIR}/sources/NameList/ui/namelistdialog.ui

View File

@@ -19,7 +19,6 @@
#include "../../QPropertyUndoCommand/qpropertyundocommand.h"
#include "../graphicspart/parttext.h"
#include "ui_texteditor.h"
#include <cassert>
@@ -31,9 +30,8 @@
@param parent : the parent widget
*/
TextEditor::TextEditor(QETElementEditor *editor, PartText *text, QWidget *parent) :
ElementItemEditor(editor, parent),
ui(new Ui::TextEditor) {
ui -> setupUi(this);
ElementItemEditor(editor, parent){
setUpWidget(parent);
setUpEditConnection();
if (text) {
setPart(text);
@@ -44,10 +42,7 @@ TextEditor::TextEditor(QETElementEditor *editor, PartText *text, QWidget *paren
/**
@brief TextEditor::~TextEditor
*/
TextEditor::~TextEditor()
{
delete ui;
}
TextEditor::~TextEditor() {}
/**
@brief TextEditor::updateForm
@@ -61,13 +56,16 @@ void TextEditor::updateForm()
disconnectEditConnection();
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());
m_line_edit -> setText(m_text -> toPlainText());
m_x_sb -> setValue(m_text -> pos().x());
m_y_sb -> setValue(m_text -> pos().y());
m_rotation_sb -> setValue(m_text -> rotation());
m_size_sb -> setValue(m_text -> font().pointSize());
m_font_pb -> setText(m_text -> font().family());
#ifdef BUILD_WITHOUT_KF5
#else
m_color_pb -> setColor(m_text -> defaultTextColor());
#endif
setUpEditConnection();
}
@@ -178,8 +176,8 @@ void TextEditor::setUpEditConnection()
{
disconnectEditConnection();
m_edit_connection << connect(ui -> m_line_edit, &QLineEdit::editingFinished, [this]() {
QString text_ = ui -> m_line_edit -> text();
m_edit_connection << connect(m_line_edit, &QLineEdit::editingFinished, [this]() {
QString text_ = m_line_edit -> text();
for (int i=0; i < m_parts.length(); i++) {
PartText* partText = m_parts[i];
if (text_ != partText -> toPlainText()) {
@@ -189,8 +187,8 @@ void TextEditor::setUpEditConnection()
}
}
});
m_edit_connection << connect(ui->m_x_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]() {
QPointF pos(ui -> m_x_sb -> value(), 0);
m_edit_connection << connect(m_x_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]() {
QPointF pos(m_x_sb -> value(), 0);
for (int i=0; i < m_parts.length(); i++) {
PartText* partText = m_parts[i];
pos.setY(partText -> pos().y());
@@ -202,8 +200,8 @@ void TextEditor::setUpEditConnection()
}
}
});
m_edit_connection << connect(ui -> m_y_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]() {
QPointF pos(0, ui -> m_y_sb -> value());
m_edit_connection << connect(m_y_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]() {
QPointF pos(0, m_y_sb -> value());
for (int i=0; i < m_parts.length(); i++) {
PartText* partText = m_parts[i];
pos.setX(partText -> pos().x());
@@ -215,24 +213,24 @@ void TextEditor::setUpEditConnection()
}
}
});
m_edit_connection << connect(ui -> m_rotation_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]() {
m_edit_connection << connect(m_rotation_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]() {
for (int i=0; i < m_parts.length(); i++) {
PartText* partText = m_parts[i];
if (ui -> m_rotation_sb -> value() != partText -> rotation()) {
if (m_rotation_sb -> value() != partText -> rotation()) {
QPropertyUndoCommand *undo = new QPropertyUndoCommand(
partText, "rotation", partText -> rotation(), ui -> m_rotation_sb -> value());
partText, "rotation", partText -> rotation(), 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]() {
m_edit_connection << connect(m_size_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]() {
for (int i=0; i < m_parts.length(); i++) {
PartText* partText = m_parts[i];
if (partText -> font().pointSize() != ui -> m_size_sb -> value()) {
if (partText -> font().pointSize() !=m_size_sb -> value()) {
QFont font_ = partText -> font();
font_.setPointSize(ui -> m_size_sb -> value());
font_.setPointSize(m_size_sb -> value());
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "font", partText -> font(), font_);
undo -> setText(tr("Modifier la police d'un texte"));
undoStack().push(undo);
@@ -250,11 +248,11 @@ void TextEditor::on_m_font_pb_clicked()
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);
m_size_sb -> blockSignals(true);
m_size_sb -> setValue(font_.pointSize());
m_size_sb -> blockSignals(false);
ui -> m_font_pb -> setText(font_.family());
m_font_pb -> setText(font_.family());
}
for (int i=0; i < m_parts.length(); i++) {
@@ -282,3 +280,89 @@ void TextEditor::on_m_color_pb_changed(const QColor &newColor) {
}
}
}
void TextEditor::setUpWidget(QWidget *parent)
{
setWindowTitle(tr("Form"));
resize(378, 133);
QGridLayout *gridLayout = new QGridLayout(parent);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
m_y_sb = new QSpinBox(parent);
m_y_sb->setObjectName(QString::fromUtf8("m_y_sb"));
m_y_sb->setMinimum(-10000);
m_y_sb->setMaximum(10000);
gridLayout->addWidget(m_y_sb, 1, 3, 1, 1);
QLabel*label_2 = new QLabel(tr("Y :"),parent);
gridLayout->addWidget(label_2, 1, 2, 1, 1);
QLabel*label_4 = new QLabel(tr("Police :"),parent);
gridLayout->addWidget(label_4, 2, 0, 1, 1);
m_rotation_sb = new QSpinBox(parent);
m_rotation_sb->setSuffix(tr("\302\260"));
m_rotation_sb->setWrapping(true);
m_rotation_sb->setMaximum(360);
gridLayout->addWidget(m_rotation_sb, 1, 5, 1, 1);
QLabel *label_3 = new QLabel(tr("Rotation :"),parent);
gridLayout->addWidget(label_3, 1, 4, 1, 1);
m_x_sb = new QSpinBox(parent);
m_x_sb->setObjectName(QString::fromUtf8("m_x_sb"));
m_x_sb->setMinimum(-10000);
m_x_sb->setMaximum(10000);
gridLayout->addWidget(m_x_sb, 1, 1, 1, 1);
QLabel *label = new QLabel(tr("X :"),parent);
gridLayout->addWidget(label, 1, 0, 1, 1);
m_size_sb = new QSpinBox(parent);
m_size_sb->setObjectName(QString::fromUtf8("m_size_sb"));
gridLayout->addWidget(m_size_sb, 2, 1, 1, 1);
m_line_edit = new QLineEdit(parent);
m_line_edit->setObjectName(QString::fromUtf8("m_line_edit"));
m_line_edit->setClearButtonEnabled(true);
m_line_edit->setPlaceholderText(tr("Entrer votre texte ici"));
gridLayout->addWidget(m_line_edit, 0, 0, 1, 6);
#ifdef BUILD_WITHOUT_KF5
#else
m_color_pb = new KColorButton(parent);
m_color_pb->setObjectName(QString::fromUtf8("m_color_pb"));
connect(
m_color_pb,
&KColorButton::changed,
this,
&TextEditor::on_m_color_pb_changed);
gridLayout->addWidget(m_color_pb, 2, 5, 1, 1);
#endif
QLabel *label_5 = new QLabel(parent);
label_5->setObjectName(QString::fromUtf8("label_5"));
gridLayout->addWidget(label_5, 2, 4, 1, 1);
m_font_pb = new QPushButton(tr("Couleur :"),parent);
connect(m_font_pb,
&QPushButton::pressed,
this,
&TextEditor::on_m_font_pb_clicked);
gridLayout->addWidget(m_font_pb, 2, 2, 1, 2);
QSpacerItem *verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
gridLayout->addItem(verticalSpacer, 3, 2, 1, 1);
setLayout(gridLayout);
}

View File

@@ -22,13 +22,15 @@
#include <QPointer>
#include <QWidget>
#include <QSpinBox>
#include <QLineEdit>
#include <QPushButton>
#ifdef BUILD_WITHOUT_KF5
#else
#include <KColorButton>
#endif
class PartText;
namespace Ui {
class TextEditor;
}
class TextEditor : public ElementItemEditor {
Q_OBJECT
@@ -46,18 +48,27 @@ class TextEditor : public ElementItemEditor {
void on_m_font_pb_clicked();
void on_m_color_pb_changed(const QColor &newColor);
private:
void setUpWidget(QWidget* parent = nullptr);
void setUpEditConnection();
void setUpChangeConnection(QPointer<PartText> part);
void disconnectChangeConnection();
void disconnectEditConnection();
private:
Ui::TextEditor *ui;
QPointer <PartText> m_text;
QList<PartText*> m_parts;
QList <QMetaObject::Connection> m_edit_connection;
QList <QMetaObject::Connection> m_change_connection;
QSpinBox *m_y_sb;
QSpinBox *m_rotation_sb;
QSpinBox *m_x_sb;
QSpinBox *m_size_sb;
QLineEdit *m_line_edit;
QPushButton *m_font_pb;
#ifdef BUILD_WITHOUT_KF5
#else
KColorButton *m_color_pb;
#endif
};
#endif // TEXTEDITOR_H

View File

@@ -1,132 +0,0 @@
<?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>