diff --git a/sources/editor/textfieldeditor.cpp b/sources/editor/textfieldeditor.cpp index f3f2444db..79a17a083 100644 --- a/sources/editor/textfieldeditor.cpp +++ b/sources/editor/textfieldeditor.cpp @@ -17,7 +17,7 @@ */ #include "textfieldeditor.h" #include "parttextfield.h" -#include "qtextorientationwidget.h" +#include "qtextorientationspinboxwidget.h" #include "qetapp.h" /** Constructeur @@ -35,22 +35,9 @@ TextFieldEditor::TextFieldEditor(QETElementEditor *editor, PartTextField *textfi font_size -> setRange(0, 144); rotate = new QCheckBox(tr("Ne pas subir les rotations de l'\351l\351ment parent")); rotate -> setChecked(true); - rotation_angle_ = new QDoubleSpinBox(); - rotation_angle_ -> setRange(-360.0, 360.0); - rotation_angle_ -> setSuffix("\260"); - rotation_widget_ = new QTextOrientationWidget(); - rotation_widget_ -> setFont(QETApp::diagramTextsFont()); - rotation_widget_ -> setUsableTexts(QList() - << tr("Q", "Single-letter example text - translate length, not meaning") - << tr("QET", "Small example text - translate length, not meaning") - << tr("Schema", "Normal example text - translate length, not meaning") - << tr("Electrique", "Normal example text - translate length, not meaning") - << tr("QElectroTech", "Long example text - translate length, not meaning") - ); - rotation_widget_ -> setMinimumSize(90.0, 90.0); - connect(rotation_angle_, SIGNAL(valueChanged(double)), rotation_widget_, SLOT(setOrientation(double))); - connect(rotation_widget_, SIGNAL(orientationChanged(double)), rotation_angle_, SLOT(setValue(double))); - connect(rotation_widget_, SIGNAL(orientationChanged(double)), rotation_angle_, SIGNAL(editingFinished())); + QLabel *rotation_angle_label = new QLabel(tr("Angle de rotation par d\351faut : ")); + rotation_angle_label -> setWordWrap(true); + rotation_angle_ = QETApp::createTextOrientationSpinBoxWidget(); qle_x -> setValidator(new QDoubleValidator(qle_x)); qle_y -> setValidator(new QDoubleValidator(qle_y)); @@ -76,8 +63,7 @@ TextFieldEditor::TextFieldEditor(QETElementEditor *editor, PartTextField *textfi main_layout -> addLayout(t); QHBoxLayout *rotation_angle_layout = new QHBoxLayout(); - rotation_angle_layout -> addWidget(new QLabel(tr("Angle de rotation par d\351faut : "))); - rotation_angle_layout -> addWidget(rotation_widget_); + rotation_angle_layout -> addWidget(rotation_angle_label); rotation_angle_layout -> addWidget(rotation_angle_); main_layout -> addLayout(rotation_angle_layout); @@ -128,7 +114,6 @@ void TextFieldEditor::updateForm() { font_size -> setValue(part -> property("size").toInt()); rotate -> setChecked(!part -> property("rotate").toBool()); rotation_angle_ -> setValue(part -> property("rotation angle").toDouble()); - rotation_widget_ -> setOrientation(part -> property("rotation angle").toDouble()); activeConnections(true); } diff --git a/sources/editor/textfieldeditor.h b/sources/editor/textfieldeditor.h index fbeb6cb6c..092c8f353 100644 --- a/sources/editor/textfieldeditor.h +++ b/sources/editor/textfieldeditor.h @@ -20,7 +20,7 @@ #include #include "elementitemeditor.h" class PartTextField; -class QTextOrientationWidget; +class QTextOrientationSpinBoxWidget; /** Cette classe represente un editeur de champ de texte Elle permet d'editer a travers une interface graphique les @@ -42,8 +42,7 @@ class TextFieldEditor : public ElementItemEditor { QLineEdit *qle_x, *qle_y, *qle_text; QSpinBox *font_size; QCheckBox *rotate; - QDoubleSpinBox *rotation_angle_; - QTextOrientationWidget *rotation_widget_; + QTextOrientationSpinBoxWidget *rotation_angle_; // methodes public slots: diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index dec0b8fb0..645becd1e 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -23,6 +23,7 @@ #include "elementscollectionitem.h" #include "fileelementscollection.h" #include "qetproject.h" +#include "qtextorientationspinboxwidget.h" #include "recentfiles.h" #include "qeticons.h" #include @@ -504,6 +505,28 @@ QList QETApp::elementEditors() { return(static_cast(qApp) -> detectElementEditors()); } +/** + Instancie un QTextOrientationSpinBoxWidget et configure : + * sa police de caracteres + * ses chaines de caracteres + A noter que la suppression du widget ainsi alloue est a la charge de + l'appelant. + @return un QTextOrientationSpinBoxWidget adapte pour une utilisation + "directe" dans QET. + @see QTextOrientationSpinBoxWidget +*/ +QTextOrientationSpinBoxWidget *QETApp::createTextOrientationSpinBoxWidget() { + QTextOrientationSpinBoxWidget *widget = new QTextOrientationSpinBoxWidget(); + widget -> orientationWidget() -> setFont(QETApp::diagramTextsFont()); + widget -> orientationWidget() -> setUsableTexts(QList() + << QETApp::tr("Q", "Single-letter example text - translate length, not meaning") + << QETApp::tr("QET", "Small example text - translate length, not meaning") + << QETApp::tr("Schema", "Normal example text - translate length, not meaning") + << QETApp::tr("Electrique", "Normal example text - translate length, not meaning") + << QETApp::tr("QElectroTech", "Long example text - translate length, not meaning") + ); + return(widget); +} /** @param project un projet @return les editeurs d'elements editant un element appartenant au projet diff --git a/sources/qetapp.h b/sources/qetapp.h index cf7fae04b..555b5e7c5 100644 --- a/sources/qetapp.h +++ b/sources/qetapp.h @@ -31,6 +31,7 @@ class FileElementsCollection; class ElementsCategory; class ElementDefinition; class QETProject; +class QTextOrientationSpinBoxWidget; class RecentFiles; /** Cette classe represente l'application QElectroTech. @@ -96,6 +97,7 @@ class QETApp : public QETSingleApplication { static QList diagramEditors(); static QList elementEditors(); static QList elementEditors(QETProject *); + static QTextOrientationSpinBoxWidget *createTextOrientationSpinBoxWidget(); protected: #ifdef Q_OS_DARWIN diff --git a/sources/qtextorientationspinboxwidget.cpp b/sources/qtextorientationspinboxwidget.cpp new file mode 100644 index 000000000..50fb94185 --- /dev/null +++ b/sources/qtextorientationspinboxwidget.cpp @@ -0,0 +1,116 @@ +#include "qtextorientationspinboxwidget.h" + +/** + Constructeur + @param parent QWidget parent de ce QTextOrientationSpinBoxWidget +*/ +QTextOrientationSpinBoxWidget::QTextOrientationSpinBoxWidget(QWidget *parent) : + QWidget(parent) +{ + build(); +} + +/** + Destructeur +*/ +QTextOrientationSpinBoxWidget::~QTextOrientationSpinBoxWidget() { +} + +/** + @return un pointeur vers le QTextOrientationWidget +*/ +QTextOrientationWidget *QTextOrientationSpinBoxWidget::orientationWidget() const { + return(orientation_widget_); +} + +/** + @return un pointeur vers le QSpinBox +*/ +QDoubleSpinBox *QTextOrientationSpinBoxWidget::spinBox() const { + return(spin_box_); +} + +/** + @return l'orientation en cours +*/ +double QTextOrientationSpinBoxWidget::orientation() const { + return(orientation_widget_ -> orientation()); +} + +/** + Synonyme pour orientation() + @return l'orientation en cours + @see orientation() +*/ +double QTextOrientationSpinBoxWidget::value() const { + return(orientation()); +} + +/** + @return true si le widget est en mode "lecture seule", false sinon +*/ +bool QTextOrientationSpinBoxWidget::isReadOnly() const { + return(orientation_widget_ -> isReadOnly()); +} + +/** + @param value Nouvelle valeur de l'orientation a afficher +*/ +void QTextOrientationSpinBoxWidget::setOrientation(const double &value) { + orientation_widget_ -> setOrientation(value); + spin_box_ -> setValue(value); +} + +/** + Synonyme pour setOrientation(value) + @param value Nouvelle valeur de l'orientation a afficher + @see setOrientation +*/ +void QTextOrientationSpinBoxWidget::setValue(const double &value) { + setOrientation(value); +} + +/** + @param ro true pour passer le widget en mode "lecture seule", false sinon +*/ +void QTextOrientationSpinBoxWidget::setReadOnly(bool ro) { + orientation_widget_ -> setReadOnly(ro); + spin_box_ -> setReadOnly(ro); +} + +/** + Construit le widget +*/ +void QTextOrientationSpinBoxWidget::build() { + orientation_widget_ = new QTextOrientationWidget(); + orientation_widget_ -> setMinimumSize(90.0, 90.0); + + spin_box_ = new QDoubleSpinBox(); + spin_box_ -> setRange(-360.0, 360.0); + spin_box_ -> setSuffix("\260"); + + // met en place les relations entre le SpinBox et le QTextOrientationWidget + connect(spin_box_, SIGNAL(valueChanged(double)), orientation_widget_, SLOT(setOrientation(double))); + connect(orientation_widget_, SIGNAL(orientationChanged(double)), spin_box_, SLOT(setValue(double))); + + // cliquer sur un des carres du QTextOrientationWidget revient a finir une saisie dans le SpinBox + connect(orientation_widget_, SIGNAL(orientationChanged(double)), spin_box_, SIGNAL(editingFinished())); + + // lorsque l'utilisateur a change l'orientation, on emet un signal avec la valeur de la nouvelle orientation + connect(spin_box_, SIGNAL(editingFinished()), this, SLOT(emitChangeSignals())); + + // dispose les widgets : le QTextOrientationWidget a gauche, le SpinBox a droite + QHBoxLayout *main_layout = new QHBoxLayout(); + main_layout -> addWidget(orientation_widget_); + main_layout -> addWidget(spin_box_); + setLayout(main_layout); +} + + +/** + Emet le signal orientationEditingFinished avec la valeur de l'orientation en cours +*/ +void QTextOrientationSpinBoxWidget::emitChangeSignals() { + emit(editingFinished(orientation())); + emit(editingFinished()); +} diff --git a/sources/qtextorientationspinboxwidget.h b/sources/qtextorientationspinboxwidget.h new file mode 100644 index 000000000..1fd11424d --- /dev/null +++ b/sources/qtextorientationspinboxwidget.h @@ -0,0 +1,69 @@ +/* + Copyright 2006-2010 Xavier Guerrin + 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 Q_TEXT_ORIENTATION_SPINBOX_WIDGET_H +#define Q_TEXT_ORIENTATION_SPINBOX_WIDGET_H +#include +#include "qtextorientationwidget.h" +/** + Cette classe est un widget regroupant cote a cote un QTextOrientationWidget + et un QSpinBox. + @see QTextOrientationWidget +*/ +class QTextOrientationSpinBoxWidget : public QWidget { + Q_OBJECT + + // constructeurs, destructeur + public: + QTextOrientationSpinBoxWidget(QWidget * = 0); + virtual ~QTextOrientationSpinBoxWidget(); + private: + QTextOrientationSpinBoxWidget(const QTextOrientationSpinBoxWidget &); + + // signaux + signals: + /** + Signaux emis lorsque l'utilisateur a fini d'editer l'orientation + */ + void editingFinished(double); + void editingFinished(); + + // methodes + public: + QTextOrientationWidget *orientationWidget() const; + QDoubleSpinBox *spinBox() const; + double orientation() const; + double value() const; + bool isReadOnly() const; + + public slots: + void setOrientation(const double &); + void setValue(const double &); + void setReadOnly(bool); + + private: + void build(); + + private slots: + void emitChangeSignals(); + + // attributs + private: + QTextOrientationWidget *orientation_widget_; + QDoubleSpinBox *spin_box_; +}; +#endif