mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-21 08:40:53 +01:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4d5a4fdf4f |
6
CREDIT
6
CREDIT
@@ -7,11 +7,8 @@ project ( http://www.kde.org/ ).
|
|||||||
Thanks to Loic for his mathematics-related explanations.
|
Thanks to Loic for his mathematics-related explanations.
|
||||||
Thanks to Nicolas for the Mac OS X experimentations.
|
Thanks to Nicolas for the Mac OS X experimentations.
|
||||||
Thanks to Remi Collet for the Fedora packaging.
|
Thanks to Remi Collet for the Fedora packaging.
|
||||||
Thanks to Piotr SQLek Skólski for the Debian packaging.
|
|
||||||
Thanks to `trem' for the Mandriva packaging.
|
|
||||||
Thanks to TuxFamily ( http://tuxfamily.org ) for hosting the project.
|
Thanks to TuxFamily ( http://tuxfamily.org ) for hosting the project.
|
||||||
Thanks to `Nishiki' for his elements and his support.
|
Thanks to `Nishiki' for his elements and his support.
|
||||||
Thanks to qtcentre.org for their SingleApplication class.
|
|
||||||
|
|
||||||
[fr]
|
[fr]
|
||||||
Merci à Trolltech pour la bibliothèque Qt ( http://trolltech.com/ ), sous
|
Merci à Trolltech pour la bibliothèque Qt ( http://trolltech.com/ ), sous
|
||||||
@@ -22,8 +19,5 @@ http://www.kde.org/ ).
|
|||||||
Merci à Loic pour ses explications d'ordre mathématique.
|
Merci à Loic pour ses explications d'ordre mathématique.
|
||||||
Merci à Nicolas pour les expérimentations Mac OS X.
|
Merci à Nicolas pour les expérimentations Mac OS X.
|
||||||
Merci à Remi Collet pour les paquets Fedora.
|
Merci à Remi Collet pour les paquets Fedora.
|
||||||
Merci à Piotr SQLek Skólski pour les paquets Debian.
|
|
||||||
Merci à `trem' pour les paquets Mandriva.
|
|
||||||
Merci à TuxFamily ( http://tuxfamily.org ) pour l'hébergement du projet.
|
Merci à TuxFamily ( http://tuxfamily.org ) pour l'hébergement du projet.
|
||||||
Merci à `Nishiki' pour ses éléments et son soutien.
|
Merci à `Nishiki' pour ses éléments et son soutien.
|
||||||
Merci à qtcentre.org pour leur classe SingleApplication.
|
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
[fr]
|
|
||||||
La collection d'éléments fournie avec QElectroTech est fournie telle quelle et
|
|
||||||
sans la moindre garantie qu'elle convienne à votre utilisation ou qu'elle
|
|
||||||
fonctionne.
|
|
||||||
L'utilisation, la modification et l'intégration des éléments dans des schémas
|
|
||||||
électriques est autorisée sans conditions, quelque soit la licence finale des
|
|
||||||
schémas.
|
|
||||||
Si vous redistribuez tout ou partie de la collection QElectroTech, avec ou sans
|
|
||||||
modification, en dehors d'un schéma électrique, vous devrez respecter les
|
|
||||||
conditions de la licence CC-BY :
|
|
||||||
Cette création est mise à disposition selon le Contrat Paternité 2.0 France
|
|
||||||
disponible en ligne http://creativecommons.org/licenses/by/2.0/fr/ ou par
|
|
||||||
courrier postal à Creative Commons, 171 Second Street, Suite 300, San Francisco,
|
|
||||||
California 94105, USA.
|
|
||||||
|
|
||||||
[en]
|
|
||||||
The elements collection provided along with QElectroTech is provided as is and
|
|
||||||
without any warranty of fitness for your purpose or working.
|
|
||||||
The usage, the modification and the integration of the elements into electric
|
|
||||||
diagrams is allowed without any condition, whatever the final license of the
|
|
||||||
diagrams is.
|
|
||||||
If you redistribute all or a part of the QElectroTech collection, with or
|
|
||||||
without any modification, out of an electric diagram, you must respect the
|
|
||||||
conditions of the CC-BY license:
|
|
||||||
This work is licensed under the Creative Commons Attribution 2.0 France License.
|
|
||||||
To view a copy of this license, visit
|
|
||||||
http://creativecommons.org/licenses/by/2.0/fr/ or send a letter to Creative
|
|
||||||
Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
|
|
||||||
|
|
||||||
[es]
|
|
||||||
La colección de elementos QElectrotech es distruibida tal cual y sin ninguna
|
|
||||||
garantía a la conveniencia de su uso y sin garantía de que funciona.
|
|
||||||
Se permite sin condicione alguna, cualquiera que sea la licencia final, usar,
|
|
||||||
editar, e incluir estos elementos en esquemas eléctricos.
|
|
||||||
Si usted redistribuye una parte de la colección o toda la collección de
|
|
||||||
QElectrotech, con o sin ediciones, fuera de un esquema eléctrico, tiene que
|
|
||||||
respetar las condiciones de la licencia CC-BY:
|
|
||||||
Esta obra está bajo una licencia Reconocimiento 2.0 Francia de Creative Commons.
|
|
||||||
Para ver una copia de esta licencia, visite
|
|
||||||
http://creativecommons.org/licenses/by/2.0/fr/ o envie una carta a Creative
|
|
||||||
Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA.
|
|
||||||
2
INSTALL
2
INSTALL
@@ -6,7 +6,6 @@ cupsys-bsd for printing
|
|||||||
Howto compile :
|
Howto compile :
|
||||||
$ qmake (qmake-qt4 for Debian-based systems)
|
$ qmake (qmake-qt4 for Debian-based systems)
|
||||||
$ make
|
$ make
|
||||||
# umask 0022
|
|
||||||
# make install
|
# make install
|
||||||
|
|
||||||
[fr]
|
[fr]
|
||||||
@@ -17,5 +16,4 @@ cupsys-bsd pour l'impression
|
|||||||
Comment compiler :
|
Comment compiler :
|
||||||
$ qmake (qmake-qt4 pour les systèmes basés sur Debian)
|
$ qmake (qmake-qt4 pour les systèmes basés sur Debian)
|
||||||
$ make
|
$ make
|
||||||
# umask 0022
|
|
||||||
# make install
|
# make install
|
||||||
|
|||||||
138
aboutqet.cpp
Normal file
138
aboutqet.cpp
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2008 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "aboutqet.h"
|
||||||
|
#include "qet.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructeur
|
||||||
|
@param parent Le QWidget parent de la boite de dialogue
|
||||||
|
*/
|
||||||
|
AboutQET::AboutQET(QWidget *parent) : QDialog(parent) {
|
||||||
|
// Titre, taille, comportement...
|
||||||
|
setWindowTitle(tr("\300 propos de QElectrotech"));
|
||||||
|
setMinimumWidth(680);
|
||||||
|
setMinimumHeight(350);
|
||||||
|
setModal(true);
|
||||||
|
|
||||||
|
// Trois onglets
|
||||||
|
QTabWidget *onglets = new QTabWidget(this);
|
||||||
|
onglets -> addTab(ongletAPropos(), tr("\300 &propos"));
|
||||||
|
onglets -> addTab(ongletAuteurs(), tr("A&uteurs"));
|
||||||
|
onglets -> addTab(ongletLicence(), tr("&Accord de licence"));
|
||||||
|
|
||||||
|
// Un bouton pour fermer la boite de dialogue
|
||||||
|
QDialogButtonBox *boutons = new QDialogButtonBox(QDialogButtonBox::Close);
|
||||||
|
connect(boutons, SIGNAL(accepted()), this, SLOT(accept()));
|
||||||
|
connect(boutons, SIGNAL(rejected()), this, SLOT(accept()));
|
||||||
|
|
||||||
|
// Le tout dans une disposition verticale
|
||||||
|
QVBoxLayout *disposition = new QVBoxLayout();
|
||||||
|
disposition -> addWidget(titre());
|
||||||
|
disposition -> addWidget(onglets);
|
||||||
|
disposition -> addWidget(boutons);
|
||||||
|
setLayout(disposition);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Destructeur
|
||||||
|
*/
|
||||||
|
AboutQET::~AboutQET() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return Le titre QElectroTech avec son icone
|
||||||
|
*/
|
||||||
|
QWidget *AboutQET::titre() const {
|
||||||
|
QWidget *icone_et_titre = new QWidget();
|
||||||
|
// icone
|
||||||
|
QLabel *icone = new QLabel();
|
||||||
|
icone -> setPixmap(QIcon(":/ico/qelectrotech.png").pixmap(48, 48));
|
||||||
|
// label "QElectroTech"
|
||||||
|
QLabel *titre = new QLabel("<span style=\"font-weight:0;font-size:16pt;\">QElectroTech v" + QET::version + "</span>");
|
||||||
|
titre -> setTextFormat(Qt::RichText);
|
||||||
|
// le tout dans une grille
|
||||||
|
QGridLayout *dispo_horiz = new QGridLayout();
|
||||||
|
dispo_horiz -> addWidget(icone, 0, 0);
|
||||||
|
dispo_horiz -> addWidget(titre, 0, 1);
|
||||||
|
dispo_horiz -> setColumnStretch(0, 1);
|
||||||
|
dispo_horiz -> setColumnStretch(1, 100);
|
||||||
|
icone_et_titre -> setLayout(dispo_horiz);
|
||||||
|
return(icone_et_titre);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return Le widget contenu par l'onglet « A propos »
|
||||||
|
*/
|
||||||
|
QWidget *AboutQET::ongletAPropos() const {
|
||||||
|
QLabel *apropos = new QLabel(
|
||||||
|
tr("QElectroTech, une application de r\351alisation de sch\351mas \351lectriques.") +
|
||||||
|
"<br><br>" +
|
||||||
|
tr("\251 2006-2008 Les d\351veloppeurs de QElectroTech") +
|
||||||
|
"<br><br>"
|
||||||
|
"<a href=\"http://qelectrotech.tuxfamily.org/\">"
|
||||||
|
"http://qelectrotech.tuxfamily.org/</a>"
|
||||||
|
);
|
||||||
|
apropos -> setAlignment(Qt::AlignCenter);
|
||||||
|
apropos -> setOpenExternalLinks(true);
|
||||||
|
apropos -> setTextFormat(Qt::RichText);
|
||||||
|
return(apropos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return Le widget contenu par l'onglet « Auteurs »
|
||||||
|
*/
|
||||||
|
QWidget *AboutQET::ongletAuteurs() const {
|
||||||
|
QLabel *auteurs = new QLabel(
|
||||||
|
"<span style=\"text-decoration: underline;\">" +
|
||||||
|
tr("Id\351e originale") +
|
||||||
|
"</span> : Beno\356t Ansieau "
|
||||||
|
"<<a href=\"mailto:benoit.ansieau@gmail.com\">"
|
||||||
|
"benoit.ansieau@gmail.com</a>>"
|
||||||
|
"<br><br>"
|
||||||
|
"<span style=\"text-decoration: underline;\">" +
|
||||||
|
tr("Programmation") +
|
||||||
|
"</span> : Xavier Guerrin "
|
||||||
|
"<<a href=\"mailto:xavier.guerrin@gmail.com\">"
|
||||||
|
"xavier.guerrin@gmail.com</a>>"
|
||||||
|
);
|
||||||
|
auteurs -> setAlignment(Qt::AlignCenter);
|
||||||
|
auteurs -> setOpenExternalLinks(true);
|
||||||
|
auteurs -> setTextFormat(Qt::RichText);
|
||||||
|
return(auteurs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return Le widget contenu par l'onglet « Accord de Licence »
|
||||||
|
*/
|
||||||
|
QWidget *AboutQET::ongletLicence() const {
|
||||||
|
QWidget *licence = new QWidget();
|
||||||
|
// label
|
||||||
|
QLabel *titre_licence = new QLabel(tr("Ce programme est sous licence GNU/GPL."));
|
||||||
|
|
||||||
|
// texte de la GNU/GPL dans une zone de texte scrollable non editable
|
||||||
|
QTextEdit *texte_licence = new QTextEdit();
|
||||||
|
texte_licence -> setPlainText(QET::license());
|
||||||
|
texte_licence -> setReadOnly(true);
|
||||||
|
|
||||||
|
// le tout dans une disposition verticale
|
||||||
|
QVBoxLayout *dispo_licence = new QVBoxLayout();
|
||||||
|
dispo_licence -> addWidget(titre_licence);
|
||||||
|
dispo_licence -> addWidget(texte_licence);
|
||||||
|
licence -> setLayout(dispo_licence);
|
||||||
|
return(licence);
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -17,11 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef ABOUTQET_H
|
#ifndef ABOUTQET_H
|
||||||
#define ABOUTQET_H
|
#define ABOUTQET_H
|
||||||
#include <QDialog>
|
#include <QtGui>
|
||||||
class QLabel;
|
|
||||||
/**
|
/**
|
||||||
Cette classe represente la boite de dialogue
|
Cette classe represente la boite de dialogue
|
||||||
"A propos de QElectroTech".
|
« A propos de QElectroTech »
|
||||||
*/
|
*/
|
||||||
class AboutQET : public QDialog {
|
class AboutQET : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -36,10 +35,9 @@ class AboutQET : public QDialog {
|
|||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
private:
|
private:
|
||||||
QWidget *title() const;
|
QWidget *titre() const;
|
||||||
QWidget *aboutTab() const;
|
QWidget *ongletAPropos() const;
|
||||||
QWidget *authorsTab() const;
|
QWidget *ongletAuteurs() const;
|
||||||
QWidget *licenseTab() const;
|
QWidget *ongletLicence() const;
|
||||||
void addAuthor(QLabel *, const QString &, const QString &, const QString &) const;
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
231
borderinset.cpp
Normal file
231
borderinset.cpp
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2008 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "borderinset.h"
|
||||||
|
#include "qetapp.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructeur simple : construit une bordure de 15 colonnes de 50x500 avec
|
||||||
|
un cartouche de 400x50.
|
||||||
|
@param parent QObject parent de ce BorderInset
|
||||||
|
*/
|
||||||
|
BorderInset::BorderInset(QObject *parent) : QObject(parent) {
|
||||||
|
nb_columns = qMax(3, QETApp::settings().value("diagrameditor/defaultcols", 15).toInt());
|
||||||
|
min_nb_columns = 3;
|
||||||
|
columns_width = QETApp::settings().value("diagrameditor/defaultcolsize", 50.0).toDouble();
|
||||||
|
columns_height = QETApp::settings().value("diagrameditor/defaultheight", 500.0).toDouble();
|
||||||
|
min_columns_height = 80.0;
|
||||||
|
inset_width = nb_columns * columns_width;
|
||||||
|
inset_height = 50.0;
|
||||||
|
columns_header_height = 20.0;
|
||||||
|
display_inset = true;
|
||||||
|
display_columns = true;
|
||||||
|
display_border = true;
|
||||||
|
updateRectangles();
|
||||||
|
|
||||||
|
bi_author = QETApp::settings().value("diagrameditor/defaultauthor").toString();
|
||||||
|
bi_title = QETApp::settings().value("diagrameditor/defaulttitle").toString();
|
||||||
|
bi_folio = QETApp::settings().value("diagrameditor/defaultfolio").toString();
|
||||||
|
bi_filename = QETApp::settings().value("diagrameditor/defaultfilename").toString();
|
||||||
|
QString settings_date = QETApp::settings().value("diagrameditor/defaultdate").toString();
|
||||||
|
if (settings_date == "now") bi_date = QDate::currentDate();
|
||||||
|
else if (settings_date.isEmpty() || settings_date == "null") bi_date = QDate();
|
||||||
|
else bi_date = QDate::fromString(settings_date, "yyyyMMdd");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Destructeur - ne fait rien
|
||||||
|
*/
|
||||||
|
BorderInset::~BorderInset() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Methode recalculant les rectangles composant le cadre et le cartouche en
|
||||||
|
fonction des attributs de taille
|
||||||
|
*/
|
||||||
|
void BorderInset::updateRectangles() {
|
||||||
|
// rectangle delimitant le schema
|
||||||
|
QRectF previous_border = border;
|
||||||
|
border = QRectF(0, 0, nb_columns * columns_width, columns_height);
|
||||||
|
if (border != previous_border) emit(borderChanged(previous_border, border));
|
||||||
|
|
||||||
|
// rectangles relatifs au cartouche
|
||||||
|
inset = QRectF(border.bottomLeft().x(), border.bottomLeft().y(), inset_width, inset_height);
|
||||||
|
inset_author = QRectF(inset.topLeft(), QSizeF(2.0 * inset_width / 9.0, 0.5 * inset_height));
|
||||||
|
inset_date = QRectF(inset_author.bottomLeft(), inset_author.size());
|
||||||
|
inset_title = QRectF(inset_author.topRight(), QSizeF(5.0 * inset_width / 9.0, inset_height));
|
||||||
|
inset_file = QRectF(inset_title.topRight(), inset_author.size());
|
||||||
|
inset_folio = QRectF(inset_file.bottomLeft(), inset_author.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Dessine le cadre et le cartouche
|
||||||
|
@param qp QPainter a utiliser pour dessiner le cadre et le cartouche
|
||||||
|
@param x Abscisse du cadre
|
||||||
|
@param y Ordonnee du cadre
|
||||||
|
*/
|
||||||
|
void BorderInset::draw(QPainter *qp, qreal x, qreal y) {
|
||||||
|
// translate tous les rectangles
|
||||||
|
border .translate(x, y);
|
||||||
|
inset .translate(x, y);
|
||||||
|
inset_author.translate(x, y);
|
||||||
|
inset_date .translate(x, y);
|
||||||
|
inset_title .translate(x, y);
|
||||||
|
inset_file .translate(x, y);
|
||||||
|
inset_folio .translate(x, y);
|
||||||
|
|
||||||
|
// prepare le QPainter
|
||||||
|
qp -> save();
|
||||||
|
qp -> setPen(Qt::black);
|
||||||
|
qp -> setBrush(Qt::NoBrush);
|
||||||
|
|
||||||
|
// dessine le cadre
|
||||||
|
if (display_border) qp -> drawRect(border);
|
||||||
|
|
||||||
|
// dessine la numerotation des colonnes
|
||||||
|
if (display_columns) {
|
||||||
|
qp -> setBrush(Qt::white);
|
||||||
|
for (int i = 1 ; i <= nb_columns ; ++ i) {
|
||||||
|
QRectF numbered_rectangle = QRectF(
|
||||||
|
border.topLeft().x() + ((i - 1) * columns_width),
|
||||||
|
border.topLeft().y(),
|
||||||
|
columns_width,
|
||||||
|
columns_header_height
|
||||||
|
);
|
||||||
|
qp -> drawRect(numbered_rectangle);
|
||||||
|
qp -> drawText(numbered_rectangle, Qt::AlignVCenter | Qt::AlignCenter, QString("%1").arg(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// dessine le cartouche
|
||||||
|
if (display_inset) {
|
||||||
|
qp -> setBrush(Qt::white);
|
||||||
|
qp -> drawRect(inset);
|
||||||
|
|
||||||
|
qp -> drawRect(inset_author);
|
||||||
|
qp -> drawText(inset_author, Qt::AlignVCenter | Qt::AlignLeft, tr(" Auteur : ") + bi_author);
|
||||||
|
|
||||||
|
qp -> drawRect(inset_date);
|
||||||
|
qp -> drawText(inset_date, Qt::AlignVCenter | Qt::AlignLeft, tr(" Date : ") + bi_date.toString("dd/MM/yyyy"));
|
||||||
|
|
||||||
|
qp -> drawRect(inset_title);
|
||||||
|
qp -> drawText(inset_title, Qt::AlignVCenter | Qt::AlignCenter, tr("Titre du document : ") + bi_title);
|
||||||
|
|
||||||
|
qp -> drawRect(inset_file);
|
||||||
|
qp -> drawText(inset_file, Qt::AlignVCenter | Qt::AlignLeft, tr(" Fichier : ") + bi_filename);
|
||||||
|
|
||||||
|
qp -> drawRect(inset_folio);
|
||||||
|
qp -> drawText(inset_folio, Qt::AlignVCenter | Qt::AlignLeft, tr(" Folio : ") + bi_folio);
|
||||||
|
}
|
||||||
|
|
||||||
|
qp -> restore();
|
||||||
|
|
||||||
|
// annule la translation des rectangles
|
||||||
|
border .translate(-x, -y);
|
||||||
|
inset .translate(-x, -y);
|
||||||
|
inset_author.translate(-x, -y);
|
||||||
|
inset_date .translate(-x, -y);
|
||||||
|
inset_title .translate(-x, -y);
|
||||||
|
inset_file .translate(-x, -y);
|
||||||
|
inset_folio .translate(-x, -y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Ajoute une colonne.
|
||||||
|
*/
|
||||||
|
void BorderInset::addColumn() {
|
||||||
|
++ nb_columns;
|
||||||
|
setInsetWidth(nb_columns * columns_width);
|
||||||
|
updateRectangles();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Enleve une colonne. Il doit rester au moins 3 colonnes.
|
||||||
|
*/
|
||||||
|
void BorderInset::removeColumn() {
|
||||||
|
if (nb_columns == min_nb_columns) return;
|
||||||
|
-- nb_columns;
|
||||||
|
setInsetWidth(nb_columns * columns_width);
|
||||||
|
updateRectangles();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Permet de changer le nombre de colonnes.
|
||||||
|
Si ce nombre de colonnes est inferieur au minimum requis, cette fonction ne
|
||||||
|
fait rien
|
||||||
|
@param nb_c nouveau nombre de colonnes
|
||||||
|
@see minNbColumns()
|
||||||
|
*/
|
||||||
|
void BorderInset::setNbColumns(int nb_c) {
|
||||||
|
if (nb_c < min_nb_columns) return;
|
||||||
|
nb_columns = nb_c;
|
||||||
|
setInsetWidth(nb_columns * columns_width);
|
||||||
|
updateRectangles();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Change la largeur des colonnes ; celle-ci doit rester comprise entre 10 et
|
||||||
|
200px.
|
||||||
|
*/
|
||||||
|
void BorderInset::setColumnsWidth(const qreal &new_cw) {
|
||||||
|
columns_width = qBound(10.0, new_cw, 200.0);
|
||||||
|
updateRectangles();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Change la hauteur des en-tetes contenant les numeros de colonnes. Celle-ci
|
||||||
|
doit rester comprise entre 5 et 50 px.
|
||||||
|
*/
|
||||||
|
void BorderInset::setColumnsHeaderHeight(const qreal &new_chh) {
|
||||||
|
columns_header_height = qBound(5.0, new_chh, 50.0);
|
||||||
|
updateRectangles();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Change la hauteur des colonnes (et donc du cadre). Cette hauteur doit
|
||||||
|
rester superieure a la hauteur des en-tetes de colonnes + 20px.
|
||||||
|
*/
|
||||||
|
void BorderInset::setColumnsHeight(const qreal &new_ch) {
|
||||||
|
columns_height = qMax(columns_header_height + min_columns_height, new_ch);
|
||||||
|
updateRectangles();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Change la largeur du cartouche. Cette largeur doit rester comprise entre
|
||||||
|
100px et la largeur du cartouche
|
||||||
|
*/
|
||||||
|
void BorderInset::setInsetWidth(const qreal &new_iw) {
|
||||||
|
inset_width = qMax(100.0, qMin(nb_columns * columns_width, new_iw));
|
||||||
|
updateRectangles();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Change la hauteur du cartouche. Cette largeur doit rester comprise entre
|
||||||
|
20px et la hauteur du cartouche.
|
||||||
|
*/
|
||||||
|
void BorderInset::setInsetHeight(const qreal &new_ih) {
|
||||||
|
inset_height = qMax(20.0, qMin(columns_height, new_ih));
|
||||||
|
updateRectangles();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Ajuste la largeur du cartouche de facon a ce que celui-ci soit aussi large
|
||||||
|
que le schema
|
||||||
|
*/
|
||||||
|
void BorderInset::adjustInsetToColumns() {
|
||||||
|
setInsetWidth(nbColumn() * columnsWidth());
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -18,11 +18,10 @@
|
|||||||
#ifndef BORDERINSET_H
|
#ifndef BORDERINSET_H
|
||||||
#define BORDERINSET_H
|
#define BORDERINSET_H
|
||||||
#include "insetproperties.h"
|
#include "insetproperties.h"
|
||||||
#include "borderproperties.h"
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QRectF>
|
#include <QRectF>
|
||||||
|
#include <QPainter>
|
||||||
#include <QDate>
|
#include <QDate>
|
||||||
class QPainter;
|
|
||||||
/**
|
/**
|
||||||
Cette classe represente l'ensemble bordure + cartouche qui encadre le
|
Cette classe represente l'ensemble bordure + cartouche qui encadre le
|
||||||
schema electrique.
|
schema electrique.
|
||||||
@@ -40,51 +39,29 @@ class BorderInset : public QObject {
|
|||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
public:
|
public:
|
||||||
static int minNbColumns();
|
|
||||||
static qreal minColumnsWidth();
|
|
||||||
static int minNbRows();
|
|
||||||
static qreal minRowsHeight();
|
|
||||||
|
|
||||||
void draw(QPainter *, qreal = 0.0, qreal = 0.0);
|
void draw(QPainter *, qreal = 0.0, qreal = 0.0);
|
||||||
|
|
||||||
// methodes d'acces en lecture aux dimensions
|
// methodes d'acces en lecture aux dimensions
|
||||||
// colonnes
|
|
||||||
/// @return le nombre de colonnes du schema
|
/// @return le nombre de colonnes du schema
|
||||||
int nbColumns() const { return(nb_columns); }
|
int nbColumn() const { return(nb_columns); }
|
||||||
/// @return la largeur des colonnes en pixels
|
/// @return la taille des colonnes en pixels
|
||||||
qreal columnsWidth() const { return(columns_width); }
|
qreal columnsWidth() const { return(columns_width); }
|
||||||
/// @return la taille de l'ensemble des colonnes, en-tete des lignes non inclus
|
|
||||||
qreal columnsTotalWidth() const { return(nb_columns * columns_width); }
|
|
||||||
/// @return la hauteur, en pixels, des en-tetes des colonnes
|
/// @return la hauteur, en pixels, des en-tetes des colonnes
|
||||||
qreal columnsHeaderHeight() const { return(columns_header_height); }
|
qreal columnsHeaderHeight() const { return(columns_header_height); }
|
||||||
|
/// @return la hauteur des colonnes, en-tetes inclus
|
||||||
// lignes
|
qreal columnsHeight() const { return(columns_height); }
|
||||||
/// @return le nombre de lignes du schema
|
/// @return la largeur de la bordure
|
||||||
int nbRows() const { return(nb_rows); }
|
qreal borderWidth() const { return(nb_columns * columns_width); }
|
||||||
/// @return la hauteur des lignes en pixels
|
/// @return la hauteur de la bordure
|
||||||
qreal rowsHeight() const { return(rows_height); }
|
qreal borderHeight() const { return(columns_height + inset_height); }
|
||||||
/// @return la taille de l'ensemble des lignes, en-tete des colonnes non inclus
|
|
||||||
qreal rowsTotalHeight() const { return(nb_rows * rows_height); }
|
|
||||||
/// @return la largeur, en pixels, des en-tetes des lignes
|
|
||||||
qreal rowsHeaderWidth() const { return(rows_header_width); }
|
|
||||||
|
|
||||||
// cadre sans le cartouche = schema
|
|
||||||
/// @return la largeur du schema, c'est-a-dire du cadre sans le cartouche
|
|
||||||
qreal diagramWidth() const { return(columnsTotalWidth() + rowsHeaderWidth()); }
|
|
||||||
/// @return la hauteurdu schema, c'est-a-dire du cadre sans le cartouche
|
|
||||||
qreal diagramHeight() const { return(rowsTotalHeight() + columnsHeaderHeight()); }
|
|
||||||
|
|
||||||
// cartouche
|
|
||||||
/// @return la largeur du cartouche
|
/// @return la largeur du cartouche
|
||||||
qreal insetWidth() const { return(inset_width); }
|
qreal insetWidth() const { return(inset_width); }
|
||||||
/// @return la hauteur du cartouche
|
/// @return la hauteur du cartouche
|
||||||
qreal insetHeight() const { return(inset_height); }
|
qreal insetHeight() const { return(inset_height); }
|
||||||
|
/// @return la hauteur minimale acceptee des colonnes
|
||||||
// cadre avec le cartouche
|
qreal minColumnsHeight() const { return(min_columns_height); }
|
||||||
/// @return la hauteur de la bordure
|
/// @return le nombre minimum accepte de colonnes
|
||||||
qreal borderWidth() const { return(diagramWidth()); }
|
int minNbColumns() const { return(min_nb_columns); }
|
||||||
/// @return la hauteur de la bordure
|
|
||||||
qreal borderHeight() const { return(diagramHeight() + insetHeight()); }
|
|
||||||
|
|
||||||
// methodes d'acces en lecture aux informations du cartouche
|
// methodes d'acces en lecture aux informations du cartouche
|
||||||
/// @return le champ "Auteur" du cartouche
|
/// @return le champ "Auteur" du cartouche
|
||||||
@@ -103,23 +80,16 @@ class BorderInset : public QObject {
|
|||||||
bool insetIsDisplayed() const { return(display_inset); }
|
bool insetIsDisplayed() const { return(display_inset); }
|
||||||
/// @return true si les entetes des colonnes sont affiches, false sinon
|
/// @return true si les entetes des colonnes sont affiches, false sinon
|
||||||
bool columnsAreDisplayed() const { return(display_columns); }
|
bool columnsAreDisplayed() const { return(display_columns); }
|
||||||
/// @return true si les entetes des lignes sont affiches, false sinon
|
|
||||||
bool rowsAreDisplayed() const { return(display_rows); }
|
|
||||||
/// @return true si la bordure est affichee, false sinon
|
/// @return true si la bordure est affichee, false sinon
|
||||||
bool borderIsDisplayed() const { return(display_border); }
|
bool borderIsDisplayed() const { return(display_border); }
|
||||||
|
|
||||||
// methodes d'acces en ecriture aux dimensions
|
// methodes d'acces en ecriture aux dimensions
|
||||||
void addColumn ();
|
void addColumn ();
|
||||||
void addRow ();
|
|
||||||
void removeColumn ();
|
void removeColumn ();
|
||||||
void removeRow ();
|
|
||||||
void setNbColumns (int);
|
void setNbColumns (int);
|
||||||
void setNbRows (int);
|
|
||||||
void setColumnsWidth (const qreal &);
|
void setColumnsWidth (const qreal &);
|
||||||
void setRowsHeight (const qreal &);
|
|
||||||
void setColumnsHeaderHeight(const qreal &);
|
void setColumnsHeaderHeight(const qreal &);
|
||||||
void setRowsHeaderWidth (const qreal &);
|
void setColumnsHeight (const qreal &);
|
||||||
void setDiagramHeight (const qreal &);
|
|
||||||
void setInsetWidth (const qreal &);
|
void setInsetWidth (const qreal &);
|
||||||
void setInsetHeight (const qreal &);
|
void setInsetHeight (const qreal &);
|
||||||
void adjustInsetToColumns ();
|
void adjustInsetToColumns ();
|
||||||
@@ -130,32 +100,42 @@ class BorderInset : public QObject {
|
|||||||
/// @param date le nouveau contenu du champ "Date"
|
/// @param date le nouveau contenu du champ "Date"
|
||||||
void setDate (const QDate &date) { bi_date = date; }
|
void setDate (const QDate &date) { bi_date = date; }
|
||||||
/// @param title le nouveau contenu du champ "Titre"
|
/// @param title le nouveau contenu du champ "Titre"
|
||||||
void setTitle (const QString &title) {
|
void setTitle (const QString &title) { bi_title = title; }
|
||||||
if (bi_title != title) {
|
|
||||||
bi_title = title;
|
|
||||||
emit(diagramTitleChanged(title));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// @param folio le nouveau contenu du champ "Folio"
|
/// @param folio le nouveau contenu du champ "Folio"
|
||||||
void setFolio (const QString &folio) { bi_folio = folio; }
|
void setFolio (const QString &folio) { bi_folio = folio; }
|
||||||
void setFolioData(int, int);
|
|
||||||
/// @param filename le nouveau contenu du champ "Fichier"
|
/// @param filename le nouveau contenu du champ "Fichier"
|
||||||
void setFileName (const QString &filename) { bi_filename = filename; }
|
void setFileName (const QString &filename) { bi_filename = filename; }
|
||||||
|
|
||||||
InsetProperties exportInset();
|
/// @return les proprietes du cartouches
|
||||||
void importInset(const InsetProperties &);
|
InsetProperties exportInset() {
|
||||||
BorderProperties exportBorder();
|
InsetProperties ip;
|
||||||
void importBorder(const BorderProperties &);
|
ip.author = bi_author;
|
||||||
|
ip.date = bi_date;
|
||||||
|
ip.title = bi_title;
|
||||||
|
ip.folio = bi_folio;
|
||||||
|
ip.filename = bi_filename;
|
||||||
|
return(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @param ip les nouvelles proprietes du cartouche
|
||||||
|
void importInset(const InsetProperties &ip) {
|
||||||
|
bi_author = ip.author;
|
||||||
|
bi_date = ip.date;
|
||||||
|
bi_title = ip.title;
|
||||||
|
bi_folio = ip.folio;
|
||||||
|
bi_filename = ip.filename;
|
||||||
|
}
|
||||||
|
|
||||||
// methodes d'acces en ecriture aux options
|
// methodes d'acces en ecriture aux options
|
||||||
void displayInset(bool);
|
/// @param di true pour afficher le cartouche, false sinon
|
||||||
void displayColumns(bool);
|
void displayInset (bool di) { display_inset = di; }
|
||||||
void displayRows(bool);
|
/// @param dc true pour afficher les entetes des colonnes, false sinon
|
||||||
void displayBorder(bool);
|
void displayColumns (bool dc) { display_columns = dc; }
|
||||||
|
/// @param db true pour afficher la bordure du schema, false sinon
|
||||||
|
void displayBorder (bool db) { display_border = db; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateRectangles();
|
void updateRectangles();
|
||||||
QString incrementLetters(const QString &);
|
|
||||||
|
|
||||||
// signaux
|
// signaux
|
||||||
signals:
|
signals:
|
||||||
@@ -165,21 +145,6 @@ class BorderInset : public QObject {
|
|||||||
@param new_border Nouvelle bordure
|
@param new_border Nouvelle bordure
|
||||||
*/
|
*/
|
||||||
void borderChanged(QRectF old_border, QRectF new_border);
|
void borderChanged(QRectF old_border, QRectF new_border);
|
||||||
/**
|
|
||||||
Signal emise lorsque des options d'affichage change
|
|
||||||
*/
|
|
||||||
void displayChanged();
|
|
||||||
|
|
||||||
/**
|
|
||||||
Signal emis lorsque le titre du schema change
|
|
||||||
*/
|
|
||||||
void diagramTitleChanged(const QString &);
|
|
||||||
|
|
||||||
/**
|
|
||||||
Signal emis lorsque le cartouche requiert une mise a jour des donnees
|
|
||||||
utilisees pour generer le folio.
|
|
||||||
*/
|
|
||||||
void needFolioData();
|
|
||||||
|
|
||||||
// attributs
|
// attributs
|
||||||
private:
|
private:
|
||||||
@@ -188,28 +153,20 @@ class BorderInset : public QObject {
|
|||||||
QDate bi_date;
|
QDate bi_date;
|
||||||
QString bi_title;
|
QString bi_title;
|
||||||
QString bi_folio;
|
QString bi_folio;
|
||||||
QString bi_final_folio;
|
|
||||||
int folio_index_;
|
|
||||||
int folio_total_;
|
|
||||||
QString bi_filename;
|
QString bi_filename;
|
||||||
|
|
||||||
// dimensions du cadre (lignes et colonnes)
|
// dimensions du cadre et du cartouche
|
||||||
// colonnes : nombres et dimensions
|
|
||||||
int nb_columns;
|
int nb_columns;
|
||||||
|
int min_nb_columns;
|
||||||
qreal columns_width;
|
qreal columns_width;
|
||||||
qreal columns_header_height;
|
qreal columns_header_height;
|
||||||
|
qreal columns_height;
|
||||||
// lignes : nombres et dimensions
|
qreal min_columns_height;
|
||||||
int nb_rows;
|
|
||||||
qreal rows_height;
|
|
||||||
qreal rows_header_width;
|
|
||||||
|
|
||||||
// dimensions du cartouche
|
|
||||||
qreal inset_width;
|
qreal inset_width;
|
||||||
qreal inset_height;
|
qreal inset_height;
|
||||||
|
|
||||||
// rectangles utilises pour le dessin
|
// rectangles utilises pour le dessin
|
||||||
QRectF diagram;
|
QRectF border;
|
||||||
QRectF inset;
|
QRectF inset;
|
||||||
QRectF inset_author;
|
QRectF inset_author;
|
||||||
QRectF inset_date;
|
QRectF inset_date;
|
||||||
@@ -220,7 +177,6 @@ class BorderInset : public QObject {
|
|||||||
// booleens pour les options de dessin
|
// booleens pour les options de dessin
|
||||||
bool display_inset;
|
bool display_inset;
|
||||||
bool display_columns;
|
bool display_columns;
|
||||||
bool display_rows;
|
|
||||||
bool display_border;
|
bool display_border;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -16,11 +16,9 @@
|
|||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
#include <limits>
|
|
||||||
#include "conductor.h"
|
#include "conductor.h"
|
||||||
#include "conductorsegment.h"
|
#include "conductorsegment.h"
|
||||||
#include "conductorsegmentprofile.h"
|
#include "conductorsegmentprofile.h"
|
||||||
#include "diagramtextitem.h"
|
|
||||||
#include "element.h"
|
#include "element.h"
|
||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
#include "diagramcommands.h"
|
#include "diagramcommands.h"
|
||||||
@@ -38,7 +36,6 @@ QBrush Conductor::square_brush = QBrush(Qt::darkGreen);
|
|||||||
@param scene QGraphicsScene a laquelle appartient le conducteur
|
@param scene QGraphicsScene a laquelle appartient le conducteur
|
||||||
*/
|
*/
|
||||||
Conductor::Conductor(Terminal *p1, Terminal* p2, Element *parent, QGraphicsScene *scene) :
|
Conductor::Conductor(Terminal *p1, Terminal* p2, Element *parent, QGraphicsScene *scene) :
|
||||||
QObject(),
|
|
||||||
QGraphicsPathItem(parent, scene),
|
QGraphicsPathItem(parent, scene),
|
||||||
terminal1(p1),
|
terminal1(p1),
|
||||||
terminal2(p2),
|
terminal2(p2),
|
||||||
@@ -88,12 +85,6 @@ Conductor::Conductor(Terminal *p1, Terminal* p2, Element *parent, QGraphicsScene
|
|||||||
text_item -> previous_text = properties_.text;
|
text_item -> previous_text = properties_.text;
|
||||||
calculateTextItemPosition();
|
calculateTextItemPosition();
|
||||||
text_item -> setParentItem(this);
|
text_item -> setParentItem(this);
|
||||||
connect(
|
|
||||||
text_item,
|
|
||||||
SIGNAL(diagramTextChanged(DiagramTextItem *, const QString &, const QString &)),
|
|
||||||
this,
|
|
||||||
SLOT(displayedTextChanged())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -361,40 +352,40 @@ void Conductor::priv_calculeConductor(const QPointF &p1, QET::Orientation o1, co
|
|||||||
if (depart.y() < arrivee.y()) {
|
if (depart.y() < arrivee.y()) {
|
||||||
// trajet descendant
|
// trajet descendant
|
||||||
if ((ori_depart == QET::North && (ori_arrivee == QET::South || ori_arrivee == QET::West)) || (ori_depart == QET::East && ori_arrivee == QET::West)) {
|
if ((ori_depart == QET::North && (ori_arrivee == QET::South || ori_arrivee == QET::West)) || (ori_depart == QET::East && ori_arrivee == QET::West)) {
|
||||||
// cas "3"
|
// cas « 3 »
|
||||||
int ligne_inter_x = qRound(depart.x() + arrivee.x()) / 2;
|
int ligne_inter_x = qRound(depart.x() + arrivee.x()) / 2;
|
||||||
while (ligne_inter_x % Diagram::xGrid) -- ligne_inter_x;
|
while (ligne_inter_x % Diagram::xGrid) -- ligne_inter_x;
|
||||||
points << QPointF(ligne_inter_x, depart.y());
|
points << QPointF(ligne_inter_x, depart.y());
|
||||||
points << QPointF(ligne_inter_x, arrivee.y());
|
points << QPointF(ligne_inter_x, arrivee.y());
|
||||||
} else if ((ori_depart == QET::South && (ori_arrivee == QET::North || ori_arrivee == QET::East)) || (ori_depart == QET::West && ori_arrivee == QET::East)) {
|
} else if ((ori_depart == QET::South && (ori_arrivee == QET::North || ori_arrivee == QET::East)) || (ori_depart == QET::West && ori_arrivee == QET::East)) {
|
||||||
// cas "4"
|
// cas « 4 »
|
||||||
int ligne_inter_y = qRound(depart.y() + arrivee.y()) / 2;
|
int ligne_inter_y = qRound(depart.y() + arrivee.y()) / 2;
|
||||||
while (ligne_inter_y % Diagram::yGrid) -- ligne_inter_y;
|
while (ligne_inter_y % Diagram::yGrid) -- ligne_inter_y;
|
||||||
points << QPointF(depart.x(), ligne_inter_y);
|
points << QPointF(depart.x(), ligne_inter_y);
|
||||||
points << QPointF(arrivee.x(), ligne_inter_y);
|
points << QPointF(arrivee.x(), ligne_inter_y);
|
||||||
} else if ((ori_depart == QET::North || ori_depart == QET::East) && (ori_arrivee == QET::North || ori_arrivee == QET::East)) {
|
} else if ((ori_depart == QET::North || ori_depart == QET::East) && (ori_arrivee == QET::North || ori_arrivee == QET::East)) {
|
||||||
points << QPointF(arrivee.x(), depart.y()); // cas "2"
|
points << QPointF(arrivee.x(), depart.y()); // cas « 2 »
|
||||||
} else {
|
} else {
|
||||||
points << QPointF(depart.x(), arrivee.y()); // cas "1"
|
points << QPointF(depart.x(), arrivee.y()); // cas « 1 »
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// trajet montant
|
// trajet montant
|
||||||
if ((ori_depart == QET::West && (ori_arrivee == QET::East || ori_arrivee == QET::South)) || (ori_depart == QET::North && ori_arrivee == QET::South)) {
|
if ((ori_depart == QET::West && (ori_arrivee == QET::East || ori_arrivee == QET::South)) || (ori_depart == QET::North && ori_arrivee == QET::South)) {
|
||||||
// cas "3"
|
// cas « 3 »
|
||||||
int ligne_inter_y = qRound(depart.y() + arrivee.y()) / 2;
|
int ligne_inter_y = qRound(depart.y() + arrivee.y()) / 2;
|
||||||
while (ligne_inter_y % Diagram::yGrid) -- ligne_inter_y;
|
while (ligne_inter_y % Diagram::yGrid) -- ligne_inter_y;
|
||||||
points << QPointF(depart.x(), ligne_inter_y);
|
points << QPointF(depart.x(), ligne_inter_y);
|
||||||
points << QPointF(arrivee.x(), ligne_inter_y);
|
points << QPointF(arrivee.x(), ligne_inter_y);
|
||||||
} else if ((ori_depart == QET::East && (ori_arrivee == QET::West || ori_arrivee == QET::North)) || (ori_depart == QET::South && ori_arrivee == QET::North)) {
|
} else if ((ori_depart == QET::East && (ori_arrivee == QET::West || ori_arrivee == QET::North)) || (ori_depart == QET::South && ori_arrivee == QET::North)) {
|
||||||
// cas "4"
|
// cas « 4 »
|
||||||
int ligne_inter_x = qRound(depart.x() + arrivee.x()) / 2;
|
int ligne_inter_x = qRound(depart.x() + arrivee.x()) / 2;
|
||||||
while (ligne_inter_x % Diagram::xGrid) -- ligne_inter_x;
|
while (ligne_inter_x % Diagram::xGrid) -- ligne_inter_x;
|
||||||
points << QPointF(ligne_inter_x, depart.y());
|
points << QPointF(ligne_inter_x, depart.y());
|
||||||
points << QPointF(ligne_inter_x, arrivee.y());
|
points << QPointF(ligne_inter_x, arrivee.y());
|
||||||
} else if ((ori_depart == QET::West || ori_depart == QET::North) && (ori_arrivee == QET::West || ori_arrivee == QET::North)) {
|
} else if ((ori_depart == QET::West || ori_depart == QET::North) && (ori_arrivee == QET::West || ori_arrivee == QET::North)) {
|
||||||
points << QPointF(depart.x(), arrivee.y()); // cas "2"
|
points << QPointF(depart.x(), arrivee.y()); // cas « 2 »
|
||||||
} else {
|
} else {
|
||||||
points << QPointF(arrivee.x(), depart.y()); // cas "1"
|
points << QPointF(arrivee.x(), depart.y()); // cas « 1 »
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,13 +452,6 @@ void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWi
|
|||||||
qp -> setPen(tmp);
|
qp -> setPen(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// utilisation d'un trait "cosmetique" en-dessous d'un certain zoom
|
|
||||||
if (options && options -> levelOfDetail < 1.0) {
|
|
||||||
QPen tmp = qp -> pen();
|
|
||||||
tmp.setCosmetic(true);
|
|
||||||
qp -> setPen(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// dessin du conducteur
|
// dessin du conducteur
|
||||||
qp -> drawPath(path());
|
qp -> drawPath(path());
|
||||||
if (properties_.type == ConductorProperties::Single) {
|
if (properties_.type == ConductorProperties::Single) {
|
||||||
@@ -595,9 +579,6 @@ void Conductor::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
QGraphicsPathItem::mousePressEvent(e);
|
QGraphicsPathItem::mousePressEvent(e);
|
||||||
if (e -> modifiers() & Qt::ControlModifier) {
|
|
||||||
setSelected(!isSelected());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -664,9 +645,7 @@ void Conductor::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
has_to_save_profile = false;
|
has_to_save_profile = false;
|
||||||
}
|
}
|
||||||
setZValue(previous_z_value);
|
setZValue(previous_z_value);
|
||||||
if (!(e -> modifiers() & Qt::ControlModifier)) {
|
QGraphicsPathItem::mouseReleaseEvent(e);
|
||||||
QGraphicsPathItem::mouseReleaseEvent(e);
|
|
||||||
}
|
|
||||||
calculateTextItemPosition();
|
calculateTextItemPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -943,13 +922,13 @@ QDomElement Conductor::toXml(QDomDocument &d, QHash<Terminal *, int> &table_adr_
|
|||||||
foreach(ConductorSegment *segment, segmentsList()) {
|
foreach(ConductorSegment *segment, segmentsList()) {
|
||||||
current_segment = d.createElement("segment");
|
current_segment = d.createElement("segment");
|
||||||
current_segment.setAttribute("orientation", segment -> isHorizontal() ? "horizontal" : "vertical");
|
current_segment.setAttribute("orientation", segment -> isHorizontal() ? "horizontal" : "vertical");
|
||||||
current_segment.setAttribute("length", QString("%1").arg(segment -> length()));
|
current_segment.setAttribute("length", segment -> length());
|
||||||
e.appendChild(current_segment);
|
e.appendChild(current_segment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// exporte la "configuration" du conducteur
|
// exporte la "configuration" du conducteur
|
||||||
properties_.toXml(e);
|
properties_.toXml(d, e);
|
||||||
return(e);
|
return(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1103,25 +1082,6 @@ void Conductor::readProperties() {
|
|||||||
text_item -> setVisible(properties_.type == ConductorProperties::Multi);
|
text_item -> setVisible(properties_.type == ConductorProperties::Multi);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Met a jour les proprietes du conducteur apres modification du champ de texte affiche
|
|
||||||
*/
|
|
||||||
void Conductor::displayedTextChanged() {
|
|
||||||
// verifie que le texte a reellement change
|
|
||||||
if (text_item -> toPlainText() == properties_.text) return;
|
|
||||||
|
|
||||||
// initialise l'objet UndoCommand correspondant
|
|
||||||
if (Diagram *my_diagram = diagram()) {
|
|
||||||
ConductorProperties new_properties(properties_);
|
|
||||||
new_properties.text = text_item -> toPlainText();
|
|
||||||
|
|
||||||
ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(this);
|
|
||||||
ccpc -> setOldSettings(properties_);
|
|
||||||
ccpc -> setNewSettings(new_properties);
|
|
||||||
my_diagram -> undoStack().push(ccpc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return les conducteurs avec lesquels ce conducteur partage des bornes
|
@return les conducteurs avec lesquels ce conducteur partage des bornes
|
||||||
communes
|
communes
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -21,17 +21,15 @@
|
|||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
#include "conductorprofile.h"
|
#include "conductorprofile.h"
|
||||||
#include "conductorproperties.h"
|
#include "conductorproperties.h"
|
||||||
|
#include "diagramtextitem.h"
|
||||||
class ConductorSegment;
|
class ConductorSegment;
|
||||||
class DiagramTextItem;
|
|
||||||
class Element;
|
class Element;
|
||||||
typedef QPair<QPointF, Qt::Corner> ConductorBend;
|
typedef QPair<QPointF, Qt::Corner> ConductorBend;
|
||||||
typedef QHash<Qt::Corner, ConductorProfile> ConductorProfilesGroup;
|
typedef QHash<Qt::Corner, ConductorProfile> ConductorProfilesGroup;
|
||||||
/**
|
/**
|
||||||
Cette classe represente un conducteur. Un conducteur relie deux bornes d'element.
|
Cette classe represente un conducteur. Un conducteur relie deux bornes d'element.
|
||||||
*/
|
*/
|
||||||
class Conductor : public QObject, public QGraphicsPathItem {
|
class Conductor : public QGraphicsPathItem {
|
||||||
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
// constructeurs, destructeur
|
// constructeurs, destructeur
|
||||||
public:
|
public:
|
||||||
@@ -83,9 +81,6 @@ class Conductor : public QObject, public QGraphicsPathItem {
|
|||||||
ConductorProfilesGroup profiles() const;
|
ConductorProfilesGroup profiles() const;
|
||||||
void readProperties();
|
void readProperties();
|
||||||
|
|
||||||
public slots:
|
|
||||||
void displayedTextChanged();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
||||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -159,18 +159,19 @@ void SingleLineProperties::drawNeutral(QPainter *painter, QET::ConductorSegmentT
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Exporte les parametres du conducteur unifilaire sous formes d'attributs XML
|
exporte les parametres du conducteur unifilaire sous formes d'attributs XML
|
||||||
ajoutes a l'element e.
|
ajoutes a l'element e.
|
||||||
|
@param d Document XML ; utilise pour ajouter (potentiellement) des elements XML
|
||||||
@param e Element XML auquel seront ajoutes des attributs
|
@param e Element XML auquel seront ajoutes des attributs
|
||||||
*/
|
*/
|
||||||
void SingleLineProperties::toXml(QDomElement &e) const {
|
void SingleLineProperties::toXml(QDomDocument &, QDomElement &e) const {
|
||||||
e.setAttribute("ground", hasGround ? "true" : "false");
|
e.setAttribute("ground", hasGround ? "true" : "false");
|
||||||
e.setAttribute("neutral", hasNeutral ? "true" : "false");
|
e.setAttribute("neutral", hasNeutral ? "true" : "false");
|
||||||
e.setAttribute("phase", phases);
|
e.setAttribute("phase", phases);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Importe les parametres du conducteur unifilaire a partir des attributs XML
|
importe les parametres du conducteur unifilaire a partir des attributs XML
|
||||||
de l'element e
|
de l'element e
|
||||||
@param e Element XML dont les attributs seront lus
|
@param e Element XML dont les attributs seront lus
|
||||||
*/
|
*/
|
||||||
@@ -181,21 +182,22 @@ void SingleLineProperties::fromXml(QDomElement &e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Exporte les parametres du conducteur sous formes d'attributs XML
|
exporte les parametres du conducteur sous formes d'attributs XML
|
||||||
ajoutes a l'element e.
|
ajoutes a l'element e.
|
||||||
|
@param d Document XML ; utilise pour ajouter (potentiellement) des elements XML
|
||||||
@param e Element XML auquel seront ajoutes des attributs
|
@param e Element XML auquel seront ajoutes des attributs
|
||||||
*/
|
*/
|
||||||
void ConductorProperties::toXml(QDomElement &e) const {
|
void ConductorProperties::toXml(QDomDocument &d, QDomElement &e) const {
|
||||||
e.setAttribute("type", typeToString(type));
|
e.setAttribute("type", typeToString(type));
|
||||||
if (type == Single) {
|
if (type == Single) {
|
||||||
singleLineProperties.toXml(e);
|
singleLineProperties.toXml(d, e);
|
||||||
} else if (type == Multi) {
|
} else if (type == Multi) {
|
||||||
e.setAttribute("num", text);
|
e.setAttribute("num", text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Importe les parametres du conducteur unifilaire a partir des attributs XML
|
importe les parametres du conducteur unifilaire a partir des attributs XML
|
||||||
de l'element e
|
de l'element e
|
||||||
@param e Element XML dont les attributs seront lus
|
@param e Element XML dont les attributs seront lus
|
||||||
*/
|
*/
|
||||||
@@ -215,7 +217,7 @@ void ConductorProperties::fromXml(QDomElement &e) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
@param settings Parametres a ecrire
|
@param settings Parametres a ecrire
|
||||||
@param prefix prefixe a ajouter devant les noms des parametres
|
@param prefix prefix a ajouter devant les noms des parametres
|
||||||
*/
|
*/
|
||||||
void ConductorProperties::toSettings(QSettings &settings, const QString &prefix) const {
|
void ConductorProperties::toSettings(QSettings &settings, const QString &prefix) const {
|
||||||
settings.setValue(prefix + "type", typeToString(type));
|
settings.setValue(prefix + "type", typeToString(type));
|
||||||
@@ -225,7 +227,7 @@ void ConductorProperties::toSettings(QSettings &settings, const QString &prefix)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
@param settings Parametres a lire
|
@param settings Parametres a lire
|
||||||
@param prefix prefixe a ajouter devant les noms des parametres
|
@param prefix prefix a ajouter devant les noms des parametres
|
||||||
*/
|
*/
|
||||||
void ConductorProperties::fromSettings(QSettings &settings, const QString &prefix) {
|
void ConductorProperties::fromSettings(QSettings &settings, const QString &prefix) {
|
||||||
QString setting_type = settings.value(prefix + "type", typeToString(Multi)).toString();
|
QString setting_type = settings.value(prefix + "type", typeToString(Multi)).toString();
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -31,7 +31,7 @@ class SingleLineProperties {
|
|||||||
void setPhasesCount(int);
|
void setPhasesCount(int);
|
||||||
unsigned short int phasesCount();
|
unsigned short int phasesCount();
|
||||||
void draw(QPainter *, QET::ConductorSegmentType, const QRectF &);
|
void draw(QPainter *, QET::ConductorSegmentType, const QRectF &);
|
||||||
void toXml(QDomElement &) const;
|
void toXml(QDomDocument &, QDomElement &) const;
|
||||||
void fromXml(QDomElement &);
|
void fromXml(QDomElement &);
|
||||||
void toSettings(QSettings &, const QString & = QString()) const;
|
void toSettings(QSettings &, const QString & = QString()) const;
|
||||||
void fromSettings(QSettings &, const QString & = QString());
|
void fromSettings(QSettings &, const QString & = QString());
|
||||||
@@ -87,7 +87,7 @@ class ConductorProperties {
|
|||||||
SingleLineProperties singleLineProperties;
|
SingleLineProperties singleLineProperties;
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
void toXml(QDomElement &) const;
|
void toXml(QDomDocument &, QDomElement &) const;
|
||||||
void fromXml(QDomElement &);
|
void fromXml(QDomElement &);
|
||||||
void toSettings(QSettings &, const QString & = QString()) const;
|
void toSettings(QSettings &, const QString & = QString()) const;
|
||||||
void fromSettings(QSettings &, const QString & = QString());
|
void fromSettings(QSettings &, const QString & = QString());
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "conductorpropertieswidget.h"
|
#include "conductorpropertieswidget.h"
|
||||||
#include <QtGui>
|
|
||||||
#include "conductor.h"
|
#include "conductor.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,7 +46,6 @@ void ConductorPropertiesWidget::buildInterface() {
|
|||||||
setMinimumSize(380, 280);
|
setMinimumSize(380, 280);
|
||||||
|
|
||||||
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||||
main_layout -> setContentsMargins(0, 0, 0, 0);
|
|
||||||
|
|
||||||
QGroupBox *groupbox = new QGroupBox(tr("Type de conducteur"));
|
QGroupBox *groupbox = new QGroupBox(tr("Type de conducteur"));
|
||||||
main_layout -> addWidget(groupbox);
|
main_layout -> addWidget(groupbox);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -17,8 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef CONDUCTOR_PROPERTIES_WIDGET_H
|
#ifndef CONDUCTOR_PROPERTIES_WIDGET_H
|
||||||
#define CONDUCTOR_PROPERTIES_WIDGET_H
|
#define CONDUCTOR_PROPERTIES_WIDGET_H
|
||||||
#include "conductorproperties.h"
|
#include "conductor.h"
|
||||||
#include <QWidget>
|
#include <QtGui>
|
||||||
/**
|
/**
|
||||||
Ce widget permet a l utilisateur d'editer les proprietes d'un conducteur.
|
Ce widget permet a l utilisateur d'editer les proprietes d'un conducteur.
|
||||||
Par proprietes, on entend non pas le trajet effectue par le conducteur mais
|
Par proprietes, on entend non pas le trajet effectue par le conducteur mais
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -24,12 +24,12 @@
|
|||||||
*/
|
*/
|
||||||
ConfigDialog::ConfigDialog(QWidget *parent) : QDialog(parent) {
|
ConfigDialog::ConfigDialog(QWidget *parent) : QDialog(parent) {
|
||||||
|
|
||||||
setWindowTitle(tr("Configurer QElectroTech", "window title"));
|
setWindowTitle(tr("Configurer QElectroTech"));
|
||||||
|
|
||||||
// liste des pages
|
// liste des pages
|
||||||
pages_list = new QListWidget();
|
pages_list = new QListWidget();
|
||||||
pages_list -> setViewMode(QListView::IconMode);
|
pages_list -> setViewMode(QListView::IconMode);
|
||||||
pages_list -> setIconSize(QSize(110, 110));
|
pages_list -> setIconSize(QSize(48, 48));
|
||||||
pages_list -> setMovement(QListView::Static);
|
pages_list -> setMovement(QListView::Static);
|
||||||
pages_list -> setMinimumWidth(135);
|
pages_list -> setMinimumWidth(135);
|
||||||
pages_list -> setMaximumWidth(135);
|
pages_list -> setMaximumWidth(135);
|
||||||
@@ -37,7 +37,6 @@ ConfigDialog::ConfigDialog(QWidget *parent) : QDialog(parent) {
|
|||||||
|
|
||||||
// pages
|
// pages
|
||||||
pages_widget = new QStackedWidget();
|
pages_widget = new QStackedWidget();
|
||||||
addPage(new GeneralConfigurationPage());
|
|
||||||
addPage(new NewDiagramPage());
|
addPage(new NewDiagramPage());
|
||||||
buildPagesList();
|
buildPagesList();
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
136
configpages.cpp
Normal file
136
configpages.cpp
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2008 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "configpages.h"
|
||||||
|
#include "qetapp.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructeur
|
||||||
|
@param parent QWidget parent
|
||||||
|
*/
|
||||||
|
NewDiagramPage::NewDiagramPage(QWidget *parent) : ConfigPage(parent) {
|
||||||
|
|
||||||
|
// acces a la configuration de QElectroTech
|
||||||
|
QSettings &settings = QETApp::settings();
|
||||||
|
|
||||||
|
// recupere les dimensions du schema
|
||||||
|
int columns_count_value = settings.value("diagrameditor/defaultcols", 15).toInt();
|
||||||
|
int columns_width_value = qRound(settings.value("diagrameditor/defaultcolsize", 50.0).toDouble());
|
||||||
|
int columns_height_value = qRound(settings.value("diagrameditor/defaultheight", 500.0).toDouble());
|
||||||
|
|
||||||
|
QVBoxLayout *vlayout1 = new QVBoxLayout();
|
||||||
|
|
||||||
|
QLabel *title = new QLabel(tr("Nouveau sch\351ma"));
|
||||||
|
vlayout1 -> addWidget(title);
|
||||||
|
|
||||||
|
QFrame *horiz_line = new QFrame();
|
||||||
|
horiz_line -> setFrameShape(QFrame::HLine);
|
||||||
|
vlayout1 -> addWidget(horiz_line);
|
||||||
|
|
||||||
|
QHBoxLayout *hlayout1 = new QHBoxLayout();
|
||||||
|
QVBoxLayout *vlayout2 = new QVBoxLayout();
|
||||||
|
|
||||||
|
QGroupBox *diagram_size_box = new QGroupBox(tr("Dimensions du sch\351ma"));
|
||||||
|
diagram_size_box -> setMinimumWidth(300);
|
||||||
|
QGridLayout *diagram_size_box_layout = new QGridLayout(diagram_size_box);
|
||||||
|
|
||||||
|
QLabel *ds1 = new QLabel(tr("Colonnes :"));
|
||||||
|
|
||||||
|
columns_count = new QSpinBox(diagram_size_box);
|
||||||
|
columns_count -> setMinimum(3); /// @todo methode statique pour recuperer ca
|
||||||
|
columns_count -> setValue(columns_count_value);
|
||||||
|
|
||||||
|
columns_width = new QSpinBox(diagram_size_box);
|
||||||
|
columns_width -> setMinimum(1);
|
||||||
|
columns_width -> setSingleStep(10);
|
||||||
|
columns_width -> setValue(columns_width_value);
|
||||||
|
columns_width -> setPrefix(tr("\327"));
|
||||||
|
columns_width -> setSuffix(tr("px"));
|
||||||
|
|
||||||
|
QLabel *ds2 = new QLabel(tr("Hauteur :"));
|
||||||
|
|
||||||
|
columns_height = new QSpinBox(diagram_size_box);
|
||||||
|
columns_height -> setRange(80, 10000); /// @todo methode statique pour recuperer ca
|
||||||
|
columns_height -> setSingleStep(80);
|
||||||
|
columns_height -> setValue(columns_height_value);
|
||||||
|
|
||||||
|
diagram_size_box_layout -> addWidget(ds1, 0, 0);
|
||||||
|
diagram_size_box_layout -> addWidget(columns_count, 0, 1);
|
||||||
|
diagram_size_box_layout -> addWidget(columns_width, 0, 2);
|
||||||
|
diagram_size_box_layout -> addWidget(ds2, 1, 0);
|
||||||
|
diagram_size_box_layout -> addWidget(columns_height, 1, 1);
|
||||||
|
|
||||||
|
ipw = new InsetPropertiesWidget(QETDiagramEditor::defaultInsetProperties(), true, this);
|
||||||
|
|
||||||
|
// proprietes par defaut des conducteurs
|
||||||
|
ConductorProperties cp;
|
||||||
|
cp.fromSettings(settings, "diagrameditor/defaultconductor");
|
||||||
|
cpw = new ConductorPropertiesWidget(cp);
|
||||||
|
|
||||||
|
vlayout2 -> addWidget(diagram_size_box);
|
||||||
|
vlayout2 -> addWidget(ipw);
|
||||||
|
hlayout1 -> addLayout(vlayout2);
|
||||||
|
hlayout1 -> addWidget(cpw);
|
||||||
|
vlayout1 -> addLayout(hlayout1);
|
||||||
|
vlayout1 -> addStretch(1);
|
||||||
|
hlayout1 -> setAlignment(cpw, Qt::AlignTop);
|
||||||
|
setLayout(vlayout1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Destructeur
|
||||||
|
NewDiagramPage::~NewDiagramPage() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Applique la configuration de cette page
|
||||||
|
*/
|
||||||
|
void NewDiagramPage::applyConf() {
|
||||||
|
QSettings &settings = QETApp::settings();
|
||||||
|
|
||||||
|
// dimensions des nouveaux schemas
|
||||||
|
settings.setValue("diagrameditor/defaultcols", columns_count -> value());
|
||||||
|
settings.setValue("diagrameditor/defaultcolsize", columns_width -> value());
|
||||||
|
settings.setValue("diagrameditor/defaultheight", columns_height -> value());
|
||||||
|
|
||||||
|
// proprietes du cartouche
|
||||||
|
InsetProperties inset = ipw-> insetProperties();
|
||||||
|
settings.setValue("diagrameditor/defaulttitle", inset.title);
|
||||||
|
settings.setValue("diagrameditor/defaultauthor", inset.author);
|
||||||
|
settings.setValue("diagrameditor/defaultfilename", inset.filename);
|
||||||
|
settings.setValue("diagrameditor/defaultfolio", inset.folio);
|
||||||
|
QString date_setting_value;
|
||||||
|
if (inset.useDate == InsetProperties::UseDateValue) {
|
||||||
|
if (inset.date.isNull()) date_setting_value = "null";
|
||||||
|
else date_setting_value = inset.date.toString("yyyyMMdd");
|
||||||
|
} else {
|
||||||
|
date_setting_value = "now";
|
||||||
|
}
|
||||||
|
settings.setValue("diagrameditor/defaultdate", date_setting_value);
|
||||||
|
|
||||||
|
// proprietes par defaut des conducteurs
|
||||||
|
cpw -> conductorProperties().toSettings(settings, "diagrameditor/defaultconductor");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @return l'icone de cette page
|
||||||
|
QIcon NewDiagramPage::icon() const {
|
||||||
|
return(QIcon(":/ico/conf_new_diagram.png"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @return le titre de cette page
|
||||||
|
QString NewDiagramPage::title() const {
|
||||||
|
return(tr("Nouveau sch\351ma"));
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -18,9 +18,9 @@
|
|||||||
#ifndef CONFIG_PAGES_H
|
#ifndef CONFIG_PAGES_H
|
||||||
#define CONFIG_PAGES_H
|
#define CONFIG_PAGES_H
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
class BorderPropertiesWidget;
|
#include "conductorpropertieswidget.h"
|
||||||
class ConductorPropertiesWidget;
|
#include "insetpropertieswidget.h"
|
||||||
class InsetPropertiesWidget;
|
|
||||||
/**
|
/**
|
||||||
Cette classe abstraite contient les methodes que toutes les pages de
|
Cette classe abstraite contient les methodes que toutes les pages de
|
||||||
configuration doivent implementer.
|
configuration doivent implementer.
|
||||||
@@ -63,38 +63,10 @@ class NewDiagramPage : public ConfigPage {
|
|||||||
|
|
||||||
// attributs
|
// attributs
|
||||||
public:
|
public:
|
||||||
BorderPropertiesWidget *bpw; ///< Widget d'edition des dimensions du schema
|
QSpinBox *columns_count; ///< Widget d'edition du nombre par defaut de colonnes
|
||||||
|
QSpinBox *columns_width; ///< Widget d'edition de la largeur par defaut des colonnes
|
||||||
|
QSpinBox *columns_height; ///< Widget d'edition de la hauteur par defaut des colonnes
|
||||||
InsetPropertiesWidget *ipw; ///< Widget d'edition des proprietes par defaut du cartouche
|
InsetPropertiesWidget *ipw; ///< Widget d'edition des proprietes par defaut du cartouche
|
||||||
ConductorPropertiesWidget *cpw; ///< Widget d'edition des proprietes par defaut des conducteurs
|
ConductorPropertiesWidget *cpw; ///< Widget d'edition des proprietes par defaut des conducteurs
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
Cette classe represente la page de configuration generale.
|
|
||||||
*/
|
|
||||||
class GeneralConfigurationPage : public ConfigPage {
|
|
||||||
Q_OBJECT
|
|
||||||
// constructeurs, destructeur
|
|
||||||
public:
|
|
||||||
GeneralConfigurationPage(QWidget * = 0);
|
|
||||||
virtual ~GeneralConfigurationPage();
|
|
||||||
private:
|
|
||||||
GeneralConfigurationPage(const GeneralConfigurationPage &);
|
|
||||||
|
|
||||||
// methodes
|
|
||||||
public:
|
|
||||||
void applyConf();
|
|
||||||
QString title() const;
|
|
||||||
QIcon icon() const;
|
|
||||||
|
|
||||||
// attributs
|
|
||||||
public:
|
|
||||||
QLabel *title_label_;
|
|
||||||
QFrame *horiz_line_;
|
|
||||||
QGroupBox *projects_view_mode_;
|
|
||||||
QRadioButton *windowed_mode_;
|
|
||||||
QRadioButton *tabbed_mode_;
|
|
||||||
QLabel *warning_view_mode_;
|
|
||||||
QGroupBox *elements_management_;
|
|
||||||
QCheckBox *integrate_elements_;
|
|
||||||
};
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -19,151 +19,119 @@
|
|||||||
#include "elementtextitem.h"
|
#include "elementtextitem.h"
|
||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
#include "qetapp.h"
|
#include "qetapp.h"
|
||||||
#include "partline.h"
|
|
||||||
#include "elementdefinition.h"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur de la classe CustomElement. Permet d'instancier un element
|
Constructeur de la classe ElementPerso. Permet d'instancier un element
|
||||||
utilisable comme un element fixe a la difference que l'element perso est
|
utilisable comme un element fixe a la difference que l'element perso lit
|
||||||
construit a partir d'une description au format XML. Celle-ci est recuperee
|
sa description (noms, dessin, comportement) dans un fichier XML a fournir
|
||||||
a l'emplacement indique.
|
en parametre.
|
||||||
@param location Emplacement de la definition d'element a utiliser
|
@param nom_fichier Le chemin du fichier XML decrivant l'element
|
||||||
@param qgi Le QGraphicsItem parent de cet element
|
@param qgi Le QGraphicsItem parent de cet element
|
||||||
@param s Le Schema affichant cet element
|
@param s Le Schema affichant cet element
|
||||||
@param state Un pointeur facultatif vers un entier. La valeur de cet entier
|
@param etat Un pointeur facultatif vers un entier. La valeur de cet entier
|
||||||
sera changee de maniere a refleter le deroulement de l'instanciation :
|
sera changee de maniere a refleter le deroulement de l'instanciation :
|
||||||
- 0 : L'instanciation a reussi
|
- 0 : L'instanciation a reussi
|
||||||
- 1 : l'emplacement n'a pas permis d'acceder a une definition d'element
|
- 1 : Le fichier n'existe pas
|
||||||
- 2 : la definition n'etait pas lisible
|
- 2 : Le fichier n'a pu etre ouvert
|
||||||
- 3 : la definition n'etait pas valide / exploitable / utilisable
|
- 3 : Le fichier n'est pas un document XML
|
||||||
- 4 : Le document XML n'est pas un element "definition"
|
- 4 : Le document XML n'a pas une "definition" comme racine
|
||||||
- 5 : Les attributs de la definition ne sont pas presents et / ou valides
|
- 5 : Les attributs de la definition ne sont pas presents et / ou valides
|
||||||
- 6 : La definition est vide
|
- 6 : La definition est vide
|
||||||
- 7 : L'analyse d'un element XML decrivant une partie du dessin de l'element a echoue
|
- 7 : L'analyse d'un element XML decrivant une partie du dessin de l'element a echoue
|
||||||
- 8 : Aucune partie du dessin n'a pu etre chargee
|
- 8 : Aucune partie du dessin n'a pu etre chargee
|
||||||
*/
|
*/
|
||||||
CustomElement::CustomElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) :
|
CustomElement::CustomElement(QString &nom_fichier, QGraphicsItem *qgi, Diagram *s, int *etat) : FixedElement(qgi, s) {
|
||||||
FixedElement(qgi, s),
|
nomfichier = nom_fichier;
|
||||||
elmt_state(-1),
|
// pessimisme inside : par defaut, ca foire
|
||||||
location_(location),
|
elmt_etat = -1;
|
||||||
forbid_antialiasing(false)
|
|
||||||
{
|
// le fichier doit exister
|
||||||
// recupere la definition de l'element
|
QFileInfo infos_file(nomfichier);
|
||||||
ElementsCollectionItem *element_item = QETApp::collectionItem(location);
|
if (!infos_file.exists() || !infos_file.isFile()) {
|
||||||
ElementDefinition *element_definition;
|
if (etat != NULL) *etat = 1;
|
||||||
if (
|
elmt_etat = 1;
|
||||||
!element_item ||\
|
|
||||||
!element_item -> isElement() ||\
|
|
||||||
!(element_definition = qobject_cast<ElementDefinition *>(element_item))
|
|
||||||
) {
|
|
||||||
if (state) *state = 1;
|
|
||||||
elmt_state = 1;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!element_definition -> isReadable()) {
|
// le fichier doit etre lisible
|
||||||
if (state) *state = 2;
|
QFile fichier(nomfichier);
|
||||||
elmt_state = 2;
|
if (!fichier.open(QIODevice::ReadOnly)) {
|
||||||
|
if (etat != NULL) *etat = 2;
|
||||||
|
elmt_etat = 2;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element_definition -> isNull()) {
|
// le fichier doit etre un document XML
|
||||||
if (state) *state = 3;
|
QDomDocument document_xml;
|
||||||
elmt_state = 3;
|
if (!document_xml.setContent(&fichier)) {
|
||||||
|
if (etat != NULL) *etat = 3;
|
||||||
|
elmt_etat = 3;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
buildFromXml(element_definition -> xml(), &elmt_state);
|
// la racine est supposee etre une definition d'element
|
||||||
if (state) *state = elmt_state;
|
QDomElement racine = document_xml.documentElement();
|
||||||
if (elmt_state) return;
|
if (racine.tagName() != "definition" || racine.attribute("type") != "element") {
|
||||||
|
if (etat != NULL) *etat = 4;
|
||||||
if (state) *state = 0;
|
elmt_etat = 4;
|
||||||
elmt_state = 0;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CustomElement::CustomElement(const QDomElement &xml_def_elmt, QGraphicsItem *qgi, Diagram *s, int *state) : FixedElement(qgi, s) {
|
|
||||||
int elmt_state = -1;
|
|
||||||
buildFromXml(xml_def_elmt, &elmt_state);
|
|
||||||
if (state) *state = elmt_state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Construit l'element personnalise a partir d'un element XML representant sa
|
|
||||||
definition.
|
|
||||||
@param xml_def_elmt
|
|
||||||
@param state Un pointeur facultatif vers un entier. La valeur de cet entier
|
|
||||||
sera changee de maniere a refleter le deroulement de l'instanciation :
|
|
||||||
- 0 : La construction s'est bien passee
|
|
||||||
- 4 : Le document XML n'est pas un element "definition"
|
|
||||||
- 5 : Les attributs de la definition ne sont pas presents et / ou valides
|
|
||||||
- 6 : La definition est vide
|
|
||||||
- 7 : L'analyse d'un element XML decrivant une partie du dessin de l'element a echoue
|
|
||||||
- 8 : Aucune partie du dessin n'a pu etre chargee
|
|
||||||
@return true si le chargement a reussi, false sinon
|
|
||||||
*/
|
|
||||||
bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state) {
|
|
||||||
|
|
||||||
if (xml_def_elmt.tagName() != "definition" || xml_def_elmt.attribute("type") != "element") {
|
|
||||||
if (state) *state = 4;
|
|
||||||
return(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// verifie basiquement que la version actuelle est capable de lire ce fichier
|
// verifie basiquement que la version actuelle est capable de lire ce fichier
|
||||||
if (xml_def_elmt.hasAttribute("version")) {
|
if (racine.hasAttribute("version")) {
|
||||||
bool conv_ok;
|
bool conv_ok;
|
||||||
qreal element_version = xml_def_elmt.attribute("version").toDouble(&conv_ok);
|
qreal element_version = racine.attribute("version").toDouble(&conv_ok);
|
||||||
if (conv_ok && QET::version.toDouble() < element_version) {
|
if (conv_ok && QET::version.toDouble() < element_version) {
|
||||||
std::cerr << qPrintable(
|
std::cerr << qPrintable(
|
||||||
QObject::tr("Avertissement : l'\351l\351ment "
|
QObject::tr("Avertissement : l'\351l\351ment ") + nom_fichier
|
||||||
" a \351t\351 enregistr\351 avec une version"
|
+ QObject::tr(" a \351t\351 enregistr\351 avec une version"
|
||||||
" ult\351rieure de QElectroTech.")
|
" ult\351rieure de QElectroTech.")
|
||||||
) << std::endl;
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ces attributs doivent etre presents et valides
|
// ces attributs doivent etre presents et valides
|
||||||
int w, h, hot_x, hot_y;
|
int w, h, hot_x, hot_y;
|
||||||
if (
|
if (
|
||||||
!QET::attributeIsAnInteger(xml_def_elmt, QString("width"), &w) ||\
|
!QET::attributeIsAnInteger(racine, QString("width"), &w) ||\
|
||||||
!QET::attributeIsAnInteger(xml_def_elmt, QString("height"), &h) ||\
|
!QET::attributeIsAnInteger(racine, QString("height"), &h) ||\
|
||||||
!QET::attributeIsAnInteger(xml_def_elmt, QString("hotspot_x"), &hot_x) ||\
|
!QET::attributeIsAnInteger(racine, QString("hotspot_x"), &hot_x) ||\
|
||||||
!QET::attributeIsAnInteger(xml_def_elmt, QString("hotspot_y"), &hot_y) ||\
|
!QET::attributeIsAnInteger(racine, QString("hotspot_y"), &hot_y) ||\
|
||||||
!validOrientationAttribute(xml_def_elmt)
|
!validOrientationAttribute(racine)
|
||||||
) {
|
) {
|
||||||
if (state) *state = 5;
|
if (etat != NULL) *etat = 5;
|
||||||
return(false);
|
elmt_etat = 5;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// on peut d'ores et deja specifier la taille et le hotspot
|
// on peut d'ores et deja specifier la taille et le hotspot
|
||||||
setSize(w, h);
|
setSize(w, h);
|
||||||
setHotspot(QPoint(hot_x, hot_y));
|
setHotspot(QPoint(hot_x, hot_y));
|
||||||
setInternalConnections(xml_def_elmt.attribute("ic") == "true");
|
setInternalConnections(racine.attribute("ic") == "true");
|
||||||
|
|
||||||
// la definition est supposee avoir des enfants
|
// la definition est supposee avoir des enfants
|
||||||
if (xml_def_elmt.firstChild().isNull()) {
|
if (racine.firstChild().isNull()) {
|
||||||
if (state) *state = 6;
|
if (etat != NULL) *etat = 6;
|
||||||
return(false);
|
elmt_etat = 6;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialisation du QPainter (pour dessiner l'element)
|
// initialisation du QPainter (pour dessiner l'element)
|
||||||
QPainter qp;
|
QPainter qp;
|
||||||
qp.begin(&drawing);
|
qp.begin(&dessin);
|
||||||
|
QPen t;
|
||||||
QPainter low_zoom_qp;
|
t.setColor(Qt::black);
|
||||||
low_zoom_qp.begin(&low_zoom_drawing);
|
t.setWidthF(1.0);
|
||||||
QPen tmp;
|
t.setJoinStyle(Qt::BevelJoin);
|
||||||
tmp.setWidthF(1.0); // ligne vaudou pour prise en compte du setCosmetic - ne pas enlever
|
qp.setPen(t);
|
||||||
tmp.setCosmetic(true);
|
|
||||||
low_zoom_qp.setPen(tmp);
|
|
||||||
|
|
||||||
// extrait les noms de la definition XML
|
// extrait les noms de la definition XML
|
||||||
names.fromXml(xml_def_elmt);
|
names.fromXml(racine);
|
||||||
setToolTip(name());
|
setToolTip(nom());
|
||||||
|
|
||||||
// parcours des enfants de la definition : parties du dessin
|
// parcours des enfants de la definition : parties du dessin
|
||||||
int parsed_elements_count = 0;
|
int nb_elements_parses = 0;
|
||||||
for (QDomNode node = xml_def_elmt.firstChild() ; !node.isNull() ; node = node.nextSibling()) {
|
for (QDomNode node = racine.firstChild() ; !node.isNull() ; node = node.nextSibling()) {
|
||||||
QDomElement elmts = node.toElement();
|
QDomElement elmts = node.toElement();
|
||||||
if (elmts.isNull()) continue;
|
if (elmts.isNull()) continue;
|
||||||
if (elmts.tagName() == "description") {
|
if (elmts.tagName() == "description") {
|
||||||
@@ -172,17 +140,11 @@ bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state) {
|
|||||||
for (QDomNode n = node.firstChild() ; !n.isNull() ; n = n.nextSibling()) {
|
for (QDomNode n = node.firstChild() ; !n.isNull() ; n = n.nextSibling()) {
|
||||||
QDomElement qde = n.toElement();
|
QDomElement qde = n.toElement();
|
||||||
if (qde.isNull()) continue;
|
if (qde.isNull()) continue;
|
||||||
if (parseElement(qde, qp)) {
|
if (parseElement(qde, qp)) ++ nb_elements_parses;
|
||||||
++ parsed_elements_count;
|
else {
|
||||||
QString current_tag = qde.tagName();
|
if (etat != NULL) *etat = 7;
|
||||||
if (current_tag != "terminal" && current_tag != "input") {
|
elmt_etat = 7;
|
||||||
forbid_antialiasing = true;
|
return;
|
||||||
parseElement(qde, low_zoom_qp);
|
|
||||||
forbid_antialiasing = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (state) *state = 7;
|
|
||||||
return(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -190,16 +152,19 @@ bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state) {
|
|||||||
|
|
||||||
// fin du dessin
|
// fin du dessin
|
||||||
qp.end();
|
qp.end();
|
||||||
low_zoom_qp.end();
|
|
||||||
|
|
||||||
// il doit y avoir au moins un element charge
|
// il doit y avoir au moins un element charge
|
||||||
if (!parsed_elements_count) {
|
if (!nb_elements_parses) {
|
||||||
if (state) *state = 8;
|
if (etat != NULL) *etat = 8;
|
||||||
return(false);
|
elmt_etat = 8;
|
||||||
} else {
|
return;
|
||||||
if (state) *state = 0;
|
|
||||||
return(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fermeture du fichier
|
||||||
|
fichier.close();
|
||||||
|
|
||||||
|
if (etat != NULL) *etat = 0;
|
||||||
|
elmt_etat = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -220,15 +185,10 @@ QList<Conductor *> CustomElement::conductors() const {
|
|||||||
return(conductors);
|
return(conductors);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return la liste des textes de cet element
|
|
||||||
QList<ElementTextItem *> CustomElement::texts() const {
|
|
||||||
return(list_texts_);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return Le nombre de bornes que l'element possede
|
@return Le nombre de bornes que l'element possede
|
||||||
*/
|
*/
|
||||||
int CustomElement::terminalsCount() const {
|
int CustomElement::nbTerminals() const {
|
||||||
return(list_terminals.size());
|
return(list_terminals.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,12 +197,8 @@ int CustomElement::terminalsCount() const {
|
|||||||
@param qp Le QPainter a utiliser pour dessiner l'element
|
@param qp Le QPainter a utiliser pour dessiner l'element
|
||||||
@param options Les options graphiques
|
@param options Les options graphiques
|
||||||
*/
|
*/
|
||||||
void CustomElement::paint(QPainter *qp, const QStyleOptionGraphicsItem *options) {
|
void CustomElement::paint(QPainter *qp, const QStyleOptionGraphicsItem *) {
|
||||||
if (options && options -> levelOfDetail < 1.0) {
|
dessin.play(qp);
|
||||||
low_zoom_drawing.play(qp);
|
|
||||||
} else {
|
|
||||||
drawing.play(qp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -261,7 +217,6 @@ void CustomElement::paint(QPainter *qp, const QStyleOptionGraphicsItem *options)
|
|||||||
bool CustomElement::parseElement(QDomElement &e, QPainter &qp) {
|
bool CustomElement::parseElement(QDomElement &e, QPainter &qp) {
|
||||||
if (e.tagName() == "terminal") return(parseTerminal(e));
|
if (e.tagName() == "terminal") return(parseTerminal(e));
|
||||||
else if (e.tagName() == "line") return(parseLine(e, qp));
|
else if (e.tagName() == "line") return(parseLine(e, qp));
|
||||||
else if (e.tagName() == "rect") return(parseRect(e, qp));
|
|
||||||
else if (e.tagName() == "ellipse") return(parseEllipse(e, qp));
|
else if (e.tagName() == "ellipse") return(parseEllipse(e, qp));
|
||||||
else if (e.tagName() == "circle") return(parseCircle(e, qp));
|
else if (e.tagName() == "circle") return(parseCircle(e, qp));
|
||||||
else if (e.tagName() == "arc") return(parseArc(e, qp));
|
else if (e.tagName() == "arc") return(parseArc(e, qp));
|
||||||
@@ -289,124 +244,9 @@ bool CustomElement::parseLine(QDomElement &e, QPainter &qp) {
|
|||||||
if (!QET::attributeIsAReal(e, QString("y1"), &y1)) return(false);
|
if (!QET::attributeIsAReal(e, QString("y1"), &y1)) return(false);
|
||||||
if (!QET::attributeIsAReal(e, QString("x2"), &x2)) return(false);
|
if (!QET::attributeIsAReal(e, QString("x2"), &x2)) return(false);
|
||||||
if (!QET::attributeIsAReal(e, QString("y2"), &y2)) return(false);
|
if (!QET::attributeIsAReal(e, QString("y2"), &y2)) return(false);
|
||||||
|
|
||||||
QET::EndType first_end = QET::endTypeFromString(e.attribute("end1"));
|
|
||||||
QET::EndType second_end = QET::endTypeFromString(e.attribute("end2"));
|
|
||||||
qreal length1, length2;
|
|
||||||
if (!QET::attributeIsAReal(e, QString("length1"), &length1)) length1 = 1.5;
|
|
||||||
if (!QET::attributeIsAReal(e, QString("length2"), &length2)) length2 = 1.5;
|
|
||||||
|
|
||||||
qp.save();
|
qp.save();
|
||||||
setPainterStyle(e, qp);
|
setPainterStyle(e, qp);
|
||||||
QPen t = qp.pen();
|
qp.drawLine(QLineF(x1, y1, x2, y2));
|
||||||
t.setJoinStyle(Qt::MiterJoin);
|
|
||||||
qp.setPen(t);
|
|
||||||
|
|
||||||
QLineF line(x1, y1, x2, y2);
|
|
||||||
QPointF point1(line.p1());
|
|
||||||
QPointF point2(line.p2());
|
|
||||||
|
|
||||||
qreal line_length(line.length());
|
|
||||||
qreal pen_width = qp.pen().widthF();
|
|
||||||
|
|
||||||
// determine s'il faut dessiner les extremites
|
|
||||||
bool draw_1st_end, draw_2nd_end;
|
|
||||||
qreal reduced_line_length = line_length - (length1 * PartLine::requiredLengthForEndType(first_end));
|
|
||||||
draw_1st_end = first_end && reduced_line_length >= 0;
|
|
||||||
if (draw_1st_end) {
|
|
||||||
reduced_line_length -= (length2 * PartLine::requiredLengthForEndType(second_end));
|
|
||||||
} else {
|
|
||||||
reduced_line_length = line_length - (length2 * PartLine::requiredLengthForEndType(second_end));
|
|
||||||
}
|
|
||||||
draw_2nd_end = second_end && reduced_line_length >= 0;
|
|
||||||
|
|
||||||
// dessine la premiere extremite
|
|
||||||
QPointF start_point, stop_point;
|
|
||||||
if (draw_1st_end) {
|
|
||||||
QList<QPointF> four_points1(PartLine::fourEndPoints(point1, point2, length1));
|
|
||||||
if (first_end == QET::Circle) {
|
|
||||||
qp.drawEllipse(QRectF(four_points1[0] - QPointF(length1, length1), QSizeF(length1 * 2.0, length1 * 2.0)));
|
|
||||||
start_point = four_points1[1];
|
|
||||||
} else if (first_end == QET::Diamond) {
|
|
||||||
qp.drawPolygon(QPolygonF() << four_points1[1] << four_points1[2] << point1 << four_points1[3]);
|
|
||||||
start_point = four_points1[1];
|
|
||||||
} else if (first_end == QET::Simple) {
|
|
||||||
qp.drawPolyline(QPolygonF() << four_points1[3] << point1 << four_points1[2]);
|
|
||||||
start_point = point1;
|
|
||||||
|
|
||||||
} else if (first_end == QET::Triangle) {
|
|
||||||
qp.drawPolygon(QPolygonF() << four_points1[0] << four_points1[2] << point1 << four_points1[3]);
|
|
||||||
start_point = four_points1[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// ajuste le depart selon l'epaisseur du trait
|
|
||||||
if (pen_width && (first_end == QET::Simple || first_end == QET::Circle)) {
|
|
||||||
start_point = QLineF(start_point, point2).pointAt(pen_width / 2.0 / line_length);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
start_point = point1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// dessine la seconde extremite
|
|
||||||
if (draw_2nd_end) {
|
|
||||||
QList<QPointF> four_points2(PartLine::fourEndPoints(point2, point1, length2));
|
|
||||||
if (second_end == QET::Circle) {
|
|
||||||
qp.drawEllipse(QRectF(four_points2[0] - QPointF(length2, length2), QSizeF(length2 * 2.0, length2 * 2.0)));
|
|
||||||
stop_point = four_points2[1];
|
|
||||||
} else if (second_end == QET::Diamond) {
|
|
||||||
qp.drawPolygon(QPolygonF() << four_points2[2] << point2 << four_points2[3] << four_points2[1]);
|
|
||||||
stop_point = four_points2[1];
|
|
||||||
} else if (second_end == QET::Simple) {
|
|
||||||
qp.drawPolyline(QPolygonF() << four_points2[3] << point2 << four_points2[2]);
|
|
||||||
stop_point = point2;
|
|
||||||
} else if (second_end == QET::Triangle) {
|
|
||||||
qp.drawPolygon(QPolygonF() << four_points2[0] << four_points2[2] << point2 << four_points2[3] << four_points2[0]);
|
|
||||||
stop_point = four_points2[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// ajuste l'arrivee selon l'epaisseur du trait
|
|
||||||
if (pen_width && (second_end == QET::Simple || second_end == QET::Circle)) {
|
|
||||||
stop_point = QLineF(point1, stop_point).pointAt((line_length - (pen_width / 2.0)) / line_length);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
stop_point = point2;
|
|
||||||
}
|
|
||||||
|
|
||||||
qp.drawLine(start_point, stop_point);
|
|
||||||
|
|
||||||
qp.restore();
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Analyse un element XML suppose representer un rectangle. Si l'analyse
|
|
||||||
reussit, le rectangle est ajoute au dessin.
|
|
||||||
Le rectangle est defini par les attributs suivants :
|
|
||||||
- x : abscisse du coin superieur gauche du rectangle
|
|
||||||
- y : ordonnee du coin superieur gauche du rectangle
|
|
||||||
- width : largeur du rectangle
|
|
||||||
- height : hauteur du rectangle
|
|
||||||
|
|
||||||
@param e L'element XML a analyser
|
|
||||||
@param qp Le QPainter a utiliser pour dessiner l'element perso
|
|
||||||
@return true si l'analyse reussit, false sinon
|
|
||||||
*/
|
|
||||||
bool CustomElement::parseRect(QDomElement &e, QPainter &qp) {
|
|
||||||
// verifie la presence des attributs obligatoires
|
|
||||||
double rect_x, rect_y, rect_w, rect_h;
|
|
||||||
if (!QET::attributeIsAReal(e, QString("x"), &rect_x)) return(false);
|
|
||||||
if (!QET::attributeIsAReal(e, QString("y"), &rect_y)) return(false);
|
|
||||||
if (!QET::attributeIsAReal(e, QString("width"), &rect_w)) return(false);
|
|
||||||
if (!QET::attributeIsAReal(e, QString("height"), &rect_h)) return(false);
|
|
||||||
qp.save();
|
|
||||||
setPainterStyle(e, qp);
|
|
||||||
|
|
||||||
// force le type de jointures pour les rectangles
|
|
||||||
QPen p = qp.pen();
|
|
||||||
p.setJoinStyle(Qt::MiterJoin);
|
|
||||||
qp.setPen(p);
|
|
||||||
|
|
||||||
qp.drawRect(QRectF(rect_x, rect_y, rect_w, rect_h));
|
|
||||||
qp.restore();
|
qp.restore();
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
@@ -422,6 +262,7 @@ bool CustomElement::parseRect(QDomElement &e, QPainter &qp) {
|
|||||||
@param e L'element XML a analyser
|
@param e L'element XML a analyser
|
||||||
@param qp Le QPainter a utiliser pour dessiner l'element perso
|
@param qp Le QPainter a utiliser pour dessiner l'element perso
|
||||||
@return true si l'analyse reussit, false sinon
|
@return true si l'analyse reussit, false sinon
|
||||||
|
@todo utiliser des attributs plus coherents : x et y = centre, rayon = vrai rayon
|
||||||
*/
|
*/
|
||||||
bool CustomElement::parseCircle(QDomElement &e, QPainter &qp) {
|
bool CustomElement::parseCircle(QDomElement &e, QPainter &qp) {
|
||||||
// verifie la presence des attributs obligatoires
|
// verifie la presence des attributs obligatoires
|
||||||
@@ -448,6 +289,7 @@ bool CustomElement::parseCircle(QDomElement &e, QPainter &qp) {
|
|||||||
@param e L'element XML a analyser
|
@param e L'element XML a analyser
|
||||||
@param qp Le QPainter a utiliser pour dessiner l'element perso
|
@param qp Le QPainter a utiliser pour dessiner l'element perso
|
||||||
@return true si l'analyse reussit, false sinon
|
@return true si l'analyse reussit, false sinon
|
||||||
|
@todo utiliser des attributs plus coherents : x et y = centre
|
||||||
*/
|
*/
|
||||||
bool CustomElement::parseEllipse(QDomElement &e, QPainter &qp) {
|
bool CustomElement::parseEllipse(QDomElement &e, QPainter &qp) {
|
||||||
// verifie la presence des attributs obligatoires
|
// verifie la presence des attributs obligatoires
|
||||||
@@ -563,26 +405,24 @@ bool CustomElement::parseText(QDomElement &e, QPainter &qp) {
|
|||||||
- une taille
|
- une taille
|
||||||
- le fait de subir les rotations de l'element ou non
|
- le fait de subir les rotations de l'element ou non
|
||||||
@param e L'element XML a analyser
|
@param e L'element XML a analyser
|
||||||
@return Un pointeur vers l'objet ElementTextItem ainsi cree si l'analyse reussit, 0 sinon
|
@param s Le schema sur lequel l'element perso sera affiche
|
||||||
|
@return true si l'analyse reussit, false sinon
|
||||||
*/
|
*/
|
||||||
ElementTextItem *CustomElement::parseInput(QDomElement &e) {
|
bool CustomElement::parseInput(QDomElement &e) {
|
||||||
qreal pos_x, pos_y;
|
qreal pos_x, pos_y;
|
||||||
int size;
|
int size;
|
||||||
if (
|
if (
|
||||||
!QET::attributeIsAReal(e, "x", &pos_x) ||\
|
!QET::attributeIsAReal(e, "x", &pos_x) ||\
|
||||||
!QET::attributeIsAReal(e, "y", &pos_y) ||\
|
!QET::attributeIsAReal(e, "y", &pos_y) ||\
|
||||||
!QET::attributeIsAnInteger(e, "size", &size)
|
!QET::attributeIsAnInteger(e, "size", &size)
|
||||||
) return(0);
|
) return(false);
|
||||||
|
|
||||||
ElementTextItem *eti = new ElementTextItem(e.attribute("text"), this);
|
ElementTextItem *eti = new ElementTextItem(e.attribute("text"), this);
|
||||||
eti -> setFont(QFont(QETApp::diagramTextsFont(), size));
|
eti -> setFont(QFont(QETApp::diagramTextsFont(), size));
|
||||||
eti -> setPos(pos_x, pos_y);
|
eti -> setPos(pos_x, pos_y);
|
||||||
eti -> setOriginalPos(QPointF(pos_x, pos_y));
|
eti -> setOriginalPos(QPointF(pos_x, pos_y));
|
||||||
if (e.attribute("rotate") == "true") eti -> setFollowParentRotations(true);
|
if (e.attribute("rotate") == "true") eti -> setFollowParentRotations(true);
|
||||||
|
return(true);
|
||||||
list_texts_ << eti;
|
|
||||||
|
|
||||||
return(eti);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -593,23 +433,23 @@ ElementTextItem *CustomElement::parseInput(QDomElement &e) {
|
|||||||
- orientation : orientation de la borne = Nord (n), Sud (s), Est (e) ou Ouest (w)
|
- orientation : orientation de la borne = Nord (n), Sud (s), Est (e) ou Ouest (w)
|
||||||
|
|
||||||
@param e L'element XML a analyser
|
@param e L'element XML a analyser
|
||||||
@return Un pointeur vers l'objet Terminal ainsi cree, 0 sinon
|
@param s Le schema sur lequel l'element perso sera affiche
|
||||||
|
@return true si l'analyse reussit, false sinon
|
||||||
*/
|
*/
|
||||||
Terminal *CustomElement::parseTerminal(QDomElement &e) {
|
bool CustomElement::parseTerminal(QDomElement &e) {
|
||||||
// verifie la presence et la validite des attributs obligatoires
|
// verifie la presence et la validite des attributs obligatoires
|
||||||
double terminalx, terminaly;
|
double terminalx, terminaly;
|
||||||
QET::Orientation terminalo;
|
QET::Orientation terminalo;
|
||||||
if (!QET::attributeIsAReal(e, QString("x"), &terminalx)) return(0);
|
if (!QET::attributeIsAReal(e, QString("x"), &terminalx)) return(false);
|
||||||
if (!QET::attributeIsAReal(e, QString("y"), &terminaly)) return(0);
|
if (!QET::attributeIsAReal(e, QString("y"), &terminaly)) return(false);
|
||||||
if (!e.hasAttribute("orientation")) return(0);
|
if (!e.hasAttribute("orientation")) return(false);
|
||||||
if (e.attribute("orientation") == "n") terminalo = QET::North;
|
if (e.attribute("orientation") == "n") terminalo = QET::North;
|
||||||
else if (e.attribute("orientation") == "s") terminalo = QET::South;
|
else if (e.attribute("orientation") == "s") terminalo = QET::South;
|
||||||
else if (e.attribute("orientation") == "e") terminalo = QET::East;
|
else if (e.attribute("orientation") == "e") terminalo = QET::East;
|
||||||
else if (e.attribute("orientation") == "w") terminalo = QET::West;
|
else if (e.attribute("orientation") == "w") terminalo = QET::West;
|
||||||
else return(0);
|
else return(false);
|
||||||
Terminal *new_terminal = new Terminal(terminalx, terminaly, terminalo, this, qobject_cast<Diagram *>(scene()));
|
list_terminals << new Terminal(terminalx, terminaly, terminalo, this, qobject_cast<Diagram *>(scene()));
|
||||||
list_terminals << new_terminal;
|
return(true);
|
||||||
return(new_terminal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -618,7 +458,6 @@ Terminal *CustomElement::parseTerminal(QDomElement &e) {
|
|||||||
@param aa Booleen a true pour activer l'antialiasing, a false pour le desactiver
|
@param aa Booleen a true pour activer l'antialiasing, a false pour le desactiver
|
||||||
*/
|
*/
|
||||||
void CustomElement::setQPainterAntiAliasing(QPainter &qp, bool aa) {
|
void CustomElement::setQPainterAntiAliasing(QPainter &qp, bool aa) {
|
||||||
if (forbid_antialiasing) aa = false;
|
|
||||||
qp.setRenderHint(QPainter::Antialiasing, aa);
|
qp.setRenderHint(QPainter::Antialiasing, aa);
|
||||||
qp.setRenderHint(QPainter::TextAntialiasing, aa);
|
qp.setRenderHint(QPainter::TextAntialiasing, aa);
|
||||||
qp.setRenderHint(QPainter::SmoothPixmapTransform, aa);
|
qp.setRenderHint(QPainter::SmoothPixmapTransform, aa);
|
||||||
@@ -643,7 +482,7 @@ void CustomElement::setQPainterAntiAliasing(QPainter &qp, bool aa) {
|
|||||||
@param e Element XML
|
@param e Element XML
|
||||||
@return true si l'attribut "orientation" est valide, false sinon
|
@return true si l'attribut "orientation" est valide, false sinon
|
||||||
*/
|
*/
|
||||||
bool CustomElement::validOrientationAttribute(const QDomElement &e) {
|
bool CustomElement::validOrientationAttribute(QDomElement &e) {
|
||||||
return(ori.fromString(e.attribute("orientation")));
|
return(ori.fromString(e.attribute("orientation")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -15,14 +15,13 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#ifndef CUSTOM_ELEMENT_H
|
#ifndef ELEMENTPERSO_H
|
||||||
#define CUSTOM_ELEMENT_H
|
#define ELEMENTPERSO_H
|
||||||
#include "fixedelement.h"
|
#include "fixedelement.h"
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include "nameslist.h"
|
#include "nameslist.h"
|
||||||
#include "elementslocation.h"
|
class CustomElementPart;
|
||||||
class ElementTextItem;
|
|
||||||
class Terminal;
|
|
||||||
/**
|
/**
|
||||||
Cette classe represente un element electrique. Elle est utilisable
|
Cette classe represente un element electrique. Elle est utilisable
|
||||||
comme un element fixe. La difference est que l'element perso lit
|
comme un element fixe. La difference est que l'element perso lit
|
||||||
@@ -30,73 +29,65 @@ class Terminal;
|
|||||||
en parametre.
|
en parametre.
|
||||||
*/
|
*/
|
||||||
class CustomElement : public FixedElement {
|
class CustomElement : public FixedElement {
|
||||||
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
// constructeurs, destructeur
|
// constructeurs, destructeur
|
||||||
public:
|
public:
|
||||||
CustomElement(const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0);
|
CustomElement(QString &, QGraphicsItem * = 0, Diagram * = 0, int * = NULL);
|
||||||
CustomElement(const QDomElement &, QGraphicsItem * = 0, Diagram * = 0, int * = 0);
|
|
||||||
virtual ~CustomElement();
|
virtual ~CustomElement();
|
||||||
|
|
||||||
|
friend class CustomElementPart;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CustomElement(const CustomElement &);
|
CustomElement(const CustomElement &);
|
||||||
|
|
||||||
// attributs
|
// attributs
|
||||||
protected:
|
private:
|
||||||
int elmt_state; // contient le code d'erreur si l'instanciation a echoue ou 0 si l'instanciation s'est bien passe
|
int elmt_etat; // contient le code d'erreur si l'instanciation a echoue ou 0 si l'instanciation s'est bien passe
|
||||||
NamesList names;
|
NamesList names;
|
||||||
ElementsLocation location_;
|
QString nomfichier;
|
||||||
QPicture drawing;
|
QPicture dessin;
|
||||||
QPicture low_zoom_drawing;
|
|
||||||
QList<Terminal *> list_terminals;
|
QList<Terminal *> list_terminals;
|
||||||
QList<ElementTextItem *> list_texts_;
|
|
||||||
bool forbid_antialiasing;
|
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
public:
|
public:
|
||||||
virtual QList<Terminal *> terminals() const;
|
virtual QList<Terminal *> terminals() const;
|
||||||
virtual QList<Conductor *> conductors() const;
|
virtual QList<Conductor *> conductors() const;
|
||||||
virtual QList<ElementTextItem *> texts() const;
|
virtual int nbTerminals() const;
|
||||||
virtual int terminalsCount() const;
|
|
||||||
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *);
|
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *);
|
||||||
QString typeId() const;
|
QString typeId() const;
|
||||||
ElementsLocation location() const;
|
QString fichier() const;
|
||||||
bool isNull() const;
|
bool isNull() const;
|
||||||
int state() const;
|
int etat() const;
|
||||||
QString name() const;
|
QString nom() const;
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
virtual bool buildFromXml(const QDomElement &, int * = 0);
|
bool parseElement(QDomElement &, QPainter &);
|
||||||
virtual bool parseElement(QDomElement &, QPainter &);
|
bool parseLine(QDomElement &, QPainter &);
|
||||||
virtual bool parseLine(QDomElement &, QPainter &);
|
bool parseEllipse(QDomElement &, QPainter &);
|
||||||
virtual bool parseRect(QDomElement &, QPainter &);
|
bool parseCircle(QDomElement &, QPainter &);
|
||||||
virtual bool parseEllipse(QDomElement &, QPainter &);
|
bool parseArc(QDomElement &, QPainter &);
|
||||||
virtual bool parseCircle(QDomElement &, QPainter &);
|
bool parsePolygon(QDomElement &, QPainter &);
|
||||||
virtual bool parseArc(QDomElement &, QPainter &);
|
bool parseText(QDomElement &, QPainter &);
|
||||||
virtual bool parsePolygon(QDomElement &, QPainter &);
|
bool parseInput(QDomElement &);
|
||||||
virtual bool parseText(QDomElement &, QPainter &);
|
bool parseTerminal(QDomElement &);
|
||||||
virtual ElementTextItem *parseInput(QDomElement &);
|
void setQPainterAntiAliasing(QPainter &, bool);
|
||||||
virtual Terminal *parseTerminal(QDomElement &);
|
bool validOrientationAttribute(QDomElement &);
|
||||||
virtual void setQPainterAntiAliasing(QPainter &, bool);
|
void setPainterStyle(QDomElement &, QPainter &);
|
||||||
virtual bool validOrientationAttribute(const QDomElement &);
|
|
||||||
virtual void setPainterStyle(QDomElement &, QPainter &);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return L'ID du type de l'element ; pour un CustomElement, cela revient au
|
@return L'ID du type de l'element ; pour un CustomElement, cela revient au
|
||||||
nom du fichier
|
nom du fichier
|
||||||
@see location()
|
@see fichier()
|
||||||
*/
|
*/
|
||||||
inline QString CustomElement::typeId() const {
|
inline QString CustomElement::typeId() const {
|
||||||
return(location_.path());
|
return(nomfichier);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return L'adresse du fichier contenant la description XML de cet element
|
@return L'adresse du fichier contenant la description XML de cet element
|
||||||
*/
|
*/
|
||||||
inline ElementsLocation CustomElement::location() const {
|
inline QString CustomElement::fichier() const {
|
||||||
return(location_);
|
return(nomfichier);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,7 +95,7 @@ inline ElementsLocation CustomElement::location() const {
|
|||||||
description XML a echoue
|
description XML a echoue
|
||||||
*/
|
*/
|
||||||
inline bool CustomElement::isNull() const {
|
inline bool CustomElement::isNull() const {
|
||||||
return(elmt_state);
|
return(elmt_etat != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -119,15 +110,15 @@ inline bool CustomElement::isNull() const {
|
|||||||
- 7 : L'analyse d'un element XML decrivant une partie du dessin de l'element a echoue
|
- 7 : L'analyse d'un element XML decrivant une partie du dessin de l'element a echoue
|
||||||
- 8 : Aucune partie du dessin n'a pu etre chargee
|
- 8 : Aucune partie du dessin n'a pu etre chargee
|
||||||
*/
|
*/
|
||||||
inline int CustomElement::state() const {
|
inline int CustomElement::etat() const {
|
||||||
return(elmt_state);
|
return(elmt_etat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return Le nom de l'element
|
@return Le nom de l'element
|
||||||
*/
|
*/
|
||||||
inline QString CustomElement::name() const {
|
inline QString CustomElement::nom() const {
|
||||||
return(names.name(location_.baseName()));
|
return(names.name(QFileInfo(nomfichier).baseName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -20,9 +20,7 @@
|
|||||||
#include "conductor.h"
|
#include "conductor.h"
|
||||||
#include "customelement.h"
|
#include "customelement.h"
|
||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
#include "elementtextitem.h"
|
|
||||||
#include "exportdialog.h"
|
#include "exportdialog.h"
|
||||||
#include "ghostelement.h"
|
|
||||||
#include "diagramcommands.h"
|
#include "diagramcommands.h"
|
||||||
#include "diagramcontent.h"
|
#include "diagramcontent.h"
|
||||||
|
|
||||||
@@ -39,12 +37,9 @@ Diagram::Diagram(QObject *parent) :
|
|||||||
draw_grid(true),
|
draw_grid(true),
|
||||||
use_border(true),
|
use_border(true),
|
||||||
moved_elements_fetched(false),
|
moved_elements_fetched(false),
|
||||||
draw_terminals(true),
|
qgi_manager(this),
|
||||||
project_(0),
|
draw_terminals(true)
|
||||||
read_only_(false)
|
|
||||||
{
|
{
|
||||||
undo_stack = new QUndoStack();
|
|
||||||
qgi_manager = new QGIManager(this);
|
|
||||||
setBackgroundBrush(Qt::white);
|
setBackgroundBrush(Qt::white);
|
||||||
conductor_setter = new QGraphicsLineItem(0, 0);
|
conductor_setter = new QGraphicsLineItem(0, 0);
|
||||||
conductor_setter -> setZValue(1000000);
|
conductor_setter -> setZValue(1000000);
|
||||||
@@ -55,30 +50,17 @@ Diagram::Diagram(QObject *parent) :
|
|||||||
conductor_setter -> setPen(t);
|
conductor_setter -> setPen(t);
|
||||||
conductor_setter -> setLine(QLineF(QPointF(0.0, 0.0), QPointF(0.0, 0.0)));
|
conductor_setter -> setLine(QLineF(QPointF(0.0, 0.0), QPointF(0.0, 0.0)));
|
||||||
connect(this, SIGNAL(selectionChanged()), this, SLOT(slot_checkSelectionEmptinessChange()));
|
connect(this, SIGNAL(selectionChanged()), this, SLOT(slot_checkSelectionEmptinessChange()));
|
||||||
|
|
||||||
|
// lit les caracteristiques des conducteurs par defaut dans la configuration
|
||||||
|
defaultConductorProperties.fromSettings(QETApp::settings(), "diagrameditor/defaultconductor");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Destructeur
|
Destructeur
|
||||||
*/
|
*/
|
||||||
Diagram::~Diagram() {
|
Diagram::~Diagram() {
|
||||||
// suppression de la liste des annulations - l'undo stack fait appel au qgimanager pour supprimer certains elements
|
if (conductor_setter -> scene()) removeItem(conductor_setter);
|
||||||
delete undo_stack;
|
delete conductor_setter;
|
||||||
// suppression du QGIManager - tous les elements qu'il connait sont supprimes
|
|
||||||
delete qgi_manager;
|
|
||||||
|
|
||||||
// recense les items supprimables
|
|
||||||
QList<QGraphicsItem *> deletable_items;
|
|
||||||
foreach(QGraphicsItem *qgi, items()) {
|
|
||||||
if (qgi -> parentItem()) continue;
|
|
||||||
if (qgraphicsitem_cast<Conductor *>(qgi)) continue;
|
|
||||||
deletable_items << qgi;
|
|
||||||
}
|
|
||||||
|
|
||||||
// suppression des items supprimables
|
|
||||||
foreach(QGraphicsItem *qgi_d, deletable_items) {
|
|
||||||
delete qgi_d;
|
|
||||||
}
|
|
||||||
// qDebug() << "Suppression du schema" << ((void*)this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,17 +109,15 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) {
|
|||||||
@param e QKeyEvent decrivant l'evenement clavier
|
@param e QKeyEvent decrivant l'evenement clavier
|
||||||
*/
|
*/
|
||||||
void Diagram::keyPressEvent(QKeyEvent *e) {
|
void Diagram::keyPressEvent(QKeyEvent *e) {
|
||||||
if (!isReadOnly()) {
|
QPointF movement;
|
||||||
QPointF movement;
|
switch(e -> key()) {
|
||||||
switch(e -> key()) {
|
case Qt::Key_Left: movement = QPointF(-xGrid, 0.0); break;
|
||||||
case Qt::Key_Left: movement = QPointF(-xGrid, 0.0); break;
|
case Qt::Key_Right: movement = QPointF(+xGrid, 0.0); break;
|
||||||
case Qt::Key_Right: movement = QPointF(+xGrid, 0.0); break;
|
case Qt::Key_Up: movement = QPointF(0.0, -yGrid); break;
|
||||||
case Qt::Key_Up: movement = QPointF(0.0, -yGrid); break;
|
case Qt::Key_Down: movement = QPointF(0.0, +yGrid); break;
|
||||||
case Qt::Key_Down: movement = QPointF(0.0, +yGrid); break;
|
}
|
||||||
}
|
if (!movement.isNull() && !focusItem()) {
|
||||||
if (!movement.isNull() && !focusItem()) {
|
moveElements(movement);
|
||||||
moveElements(movement);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
QGraphicsScene::keyPressEvent(e);
|
QGraphicsScene::keyPressEvent(e);
|
||||||
}
|
}
|
||||||
@@ -147,18 +127,16 @@ void Diagram::keyPressEvent(QKeyEvent *e) {
|
|||||||
@param e QKeyEvent decrivant l'evenement clavier
|
@param e QKeyEvent decrivant l'evenement clavier
|
||||||
*/
|
*/
|
||||||
void Diagram::keyReleaseEvent(QKeyEvent *e) {
|
void Diagram::keyReleaseEvent(QKeyEvent *e) {
|
||||||
if (!isReadOnly()) {
|
// detecte le relachement d'une touche de direction ( = deplacement d'elements)
|
||||||
// detecte le relachement d'une touche de direction ( = deplacement d'elements)
|
if (
|
||||||
if (
|
(e -> key() == Qt::Key_Left || e -> key() == Qt::Key_Right ||\
|
||||||
(e -> key() == Qt::Key_Left || e -> key() == Qt::Key_Right ||\
|
e -> key() == Qt::Key_Up || e -> key() == Qt::Key_Down) &&\
|
||||||
e -> key() == Qt::Key_Up || e -> key() == Qt::Key_Down) &&\
|
!current_movement.isNull() && !e -> isAutoRepeat()
|
||||||
!current_movement.isNull() && !e -> isAutoRepeat()
|
) {
|
||||||
) {
|
// cree un objet d'annulation pour le mouvement qui vient de se finir
|
||||||
// cree un objet d'annulation pour le mouvement qui vient de se finir
|
undoStack().push(new MoveElementsCommand(this, selectedContent(), current_movement));
|
||||||
undoStack().push(new MoveElementsCommand(this, selectedContent(), current_movement));
|
invalidateMovedElements();
|
||||||
invalidateMovedElements();
|
current_movement = QPointF();
|
||||||
current_movement = QPointF();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
QGraphicsScene::keyReleaseEvent(e);
|
QGraphicsScene::keyReleaseEvent(e);
|
||||||
}
|
}
|
||||||
@@ -233,14 +211,6 @@ QSize Diagram::imageSize() const {
|
|||||||
return(QSizeF(image_width, image_height).toSize());
|
return(QSizeF(image_width, image_height).toSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
@return true si le schema est considere comme vide, false sinon.
|
|
||||||
Un schema vide ne contient ni element, ni conducteur, ni champ de texte
|
|
||||||
*/
|
|
||||||
bool Diagram::isEmpty() const {
|
|
||||||
return(!items().count());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Exporte tout ou partie du schema
|
Exporte tout ou partie du schema
|
||||||
@param diagram Booleen (a vrai par defaut) indiquant si le XML genere doit
|
@param diagram Booleen (a vrai par defaut) indiquant si le XML genere doit
|
||||||
@@ -261,18 +231,13 @@ QDomDocument Diagram::toXml(bool diagram) {
|
|||||||
if (!border_and_inset.title().isNull()) racine.setAttribute("title", border_and_inset.title());
|
if (!border_and_inset.title().isNull()) racine.setAttribute("title", border_and_inset.title());
|
||||||
if (!border_and_inset.fileName().isNull()) racine.setAttribute("filename", border_and_inset.fileName());
|
if (!border_and_inset.fileName().isNull()) racine.setAttribute("filename", border_and_inset.fileName());
|
||||||
if (!border_and_inset.folio().isNull()) racine.setAttribute("folio", border_and_inset.folio());
|
if (!border_and_inset.folio().isNull()) racine.setAttribute("folio", border_and_inset.folio());
|
||||||
racine.setAttribute("cols", border_and_inset.nbColumns());
|
racine.setAttribute("cols", border_and_inset.nbColumn());
|
||||||
racine.setAttribute("colsize", QString("%1").arg(border_and_inset.columnsWidth()));
|
racine.setAttribute("colsize", border_and_inset.columnsWidth());
|
||||||
racine.setAttribute("rows", border_and_inset.nbRows());
|
racine.setAttribute("height", border_and_inset.columnsHeight());
|
||||||
racine.setAttribute("rowsize", QString("%1").arg(border_and_inset.rowsHeight()));
|
|
||||||
// attribut datant de la version 0.1 - laisse pour retrocompatibilite
|
|
||||||
racine.setAttribute("height", QString("%1").arg(border_and_inset.diagramHeight()));
|
|
||||||
racine.setAttribute("displaycols", border_and_inset.columnsAreDisplayed() ? "true" : "false");
|
|
||||||
racine.setAttribute("displayrows", border_and_inset.rowsAreDisplayed() ? "true" : "false");
|
|
||||||
|
|
||||||
// type de conducteur par defaut
|
// type de conducteur par defaut
|
||||||
QDomElement default_conductor = document.createElement("defaultconductor");
|
QDomElement default_conductor = document.createElement("defaultconductor");
|
||||||
defaultConductorProperties.toXml(default_conductor);
|
defaultConductorProperties.toXml(document, default_conductor);
|
||||||
racine.appendChild(default_conductor);
|
racine.appendChild(default_conductor);
|
||||||
}
|
}
|
||||||
document.appendChild(racine);
|
document.appendChild(racine);
|
||||||
@@ -285,7 +250,7 @@ QDomDocument Diagram::toXml(bool diagram) {
|
|||||||
QList<Conductor *> list_conductors;
|
QList<Conductor *> list_conductors;
|
||||||
QList<DiagramTextItem *> list_texts;
|
QList<DiagramTextItem *> list_texts;
|
||||||
|
|
||||||
// Determine les elements a "XMLiser"
|
// Determine les elements a « XMLiser »
|
||||||
foreach(QGraphicsItem *qgi, items()) {
|
foreach(QGraphicsItem *qgi, items()) {
|
||||||
if (Element *elmt = qgraphicsitem_cast<Element *>(qgi)) {
|
if (Element *elmt = qgraphicsitem_cast<Element *>(qgi)) {
|
||||||
if (diagram) list_elements << elmt;
|
if (diagram) list_elements << elmt;
|
||||||
@@ -338,38 +303,20 @@ QDomDocument Diagram::toXml(bool diagram) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Importe le schema decrit dans un document XML. Si une position est
|
Importe le diagram decrit dans un document XML. Si une position est
|
||||||
precisee, les elements importes sont positionnes de maniere a ce que le
|
precisee, les elements importes sont positionnes de maniere a ce que le
|
||||||
coin superieur gauche du plus petit rectangle pouvant les entourant tous
|
coin superieur gauche du plus petit rectangle pouvant les entourant tous
|
||||||
(le bounding rect) soit a cette position.
|
(le bounding rect) soit a cette position.
|
||||||
@param document Le document XML a analyser
|
@param document Le document XML a analyser
|
||||||
@param position La position du schema importe
|
@param position La position du diagram importe
|
||||||
@param consider_informations Si vrai, les informations complementaires
|
@param consider_informations Si vrai, les informations complementaires
|
||||||
(auteur, titre, ...) seront prises en compte
|
(auteur, titre, ...) seront prises en compte
|
||||||
@param content_ptr si ce pointeur vers un DiagramContent n'est pas NULL, il
|
@param content_ptr si ce pointeur vers un DiagramContentn'est pas NULL, il
|
||||||
sera rempli avec le contenu ajoute au schema par le fromXml
|
sera rempli avec le contenu ajoute au schema par le fromXml
|
||||||
@return true si l'import a reussi, false sinon
|
@return true si l'import a reussi, false sinon
|
||||||
*/
|
*/
|
||||||
bool Diagram::fromXml(QDomDocument &document, QPointF position, bool consider_informations, DiagramContent *content_ptr) {
|
bool Diagram::fromXml(QDomDocument &document, QPointF position, bool consider_informations, DiagramContent *content_ptr) {
|
||||||
QDomElement root = document.documentElement();
|
QDomElement root = document.documentElement();
|
||||||
return(fromXml(root, position, consider_informations, content_ptr));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Importe le schema decrit dans un element XML. Si une position est
|
|
||||||
precisee, les elements importes sont positionnes de maniere a ce que le
|
|
||||||
coin superieur gauche du plus petit rectangle pouvant les entourant tous
|
|
||||||
(le bounding rect) soit a cette position.
|
|
||||||
@param document Le document XML a analyser
|
|
||||||
@param position La position du schema importe
|
|
||||||
@param consider_informations Si vrai, les informations complementaires
|
|
||||||
(auteur, titre, ...) seront prises en compte
|
|
||||||
@param content_ptr si ce pointeur vers un DiagramContent n'est pas NULL, il
|
|
||||||
sera rempli avec le contenu ajoute au schema par le fromXml
|
|
||||||
@return true si l'import a reussi, false sinon
|
|
||||||
*/
|
|
||||||
bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_informations, DiagramContent *content_ptr) {
|
|
||||||
QDomElement root = document;
|
|
||||||
// le premier element doit etre un schema
|
// le premier element doit etre un schema
|
||||||
if (root.tagName() != "diagram") return(false);
|
if (root.tagName() != "diagram") return(false);
|
||||||
|
|
||||||
@@ -390,24 +337,9 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
double col_size = root.attribute("colsize").toDouble(&ok);
|
double col_size = root.attribute("colsize").toDouble(&ok);
|
||||||
if (ok) border_and_inset.setColumnsWidth(col_size);
|
if (ok) border_and_inset.setColumnsWidth(col_size);
|
||||||
|
|
||||||
// retrocompatibilite : les schemas enregistres avec la 0.1 ont un attribut "height"
|
// hauteur du schema
|
||||||
if (root.hasAttribute("rows") && root.hasAttribute("rowsize")) {
|
double height = root.attribute("height").toDouble(&ok);
|
||||||
// nombre de lignes
|
if (ok) border_and_inset.setColumnsHeight(height);
|
||||||
int nb_rows = root.attribute("rows").toInt(&ok);
|
|
||||||
if (ok) border_and_inset.setNbRows(nb_rows);
|
|
||||||
|
|
||||||
// taille des lignes
|
|
||||||
double row_size = root.attribute("rowsize").toDouble(&ok);
|
|
||||||
if (ok) border_and_inset.setRowsHeight(row_size);
|
|
||||||
} else {
|
|
||||||
// hauteur du schema
|
|
||||||
double height = root.attribute("height").toDouble(&ok);
|
|
||||||
if (ok) border_and_inset.setDiagramHeight(height);
|
|
||||||
}
|
|
||||||
|
|
||||||
// affichage des lignes et colonnes
|
|
||||||
border_and_inset.displayColumns(root.attribute("displaycols") != "false");
|
|
||||||
border_and_inset.displayRows(root.attribute("displayrows") != "false");
|
|
||||||
|
|
||||||
border_and_inset.adjustInsetToColumns();
|
border_and_inset.adjustInsetToColumns();
|
||||||
|
|
||||||
@@ -422,10 +354,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
}
|
}
|
||||||
|
|
||||||
// si la racine n'a pas d'enfant : le chargement est fini (schema vide)
|
// si la racine n'a pas d'enfant : le chargement est fini (schema vide)
|
||||||
if (root.firstChild().isNull()) {
|
if (root.firstChild().isNull()) return(true);
|
||||||
write(document);
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// chargement de tous les elements du fichier XML
|
// chargement de tous les elements du fichier XML
|
||||||
QList<Element *> added_elements;
|
QList<Element *> added_elements;
|
||||||
@@ -435,23 +364,19 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
|
|
||||||
// cree un element dont le type correspond a l'id type
|
// cree un element dont le type correspond a l'id type
|
||||||
QString type_id = e.attribute("type");
|
QString type_id = e.attribute("type");
|
||||||
ElementsLocation element_location = ElementsLocation(type_id);
|
QString chemin_fichier = QETApp::realPath(type_id);
|
||||||
if (type_id.startsWith("embed://")) element_location.setProject(project_);
|
CustomElement *nvel_elmt = new CustomElement(chemin_fichier);
|
||||||
|
|
||||||
CustomElement *nvel_elmt = new CustomElement(element_location);
|
|
||||||
if (nvel_elmt -> isNull()) {
|
if (nvel_elmt -> isNull()) {
|
||||||
QString debug_message = QString("Le chargement de la description de l'element %1 a echoue avec le code d'erreur %2").arg(element_location.path()).arg(nvel_elmt -> state());
|
QString debug_message = QString("Le chargement de la description de l'element %1 a echoue avec le code d'erreur %2").arg(chemin_fichier).arg(nvel_elmt -> etat());
|
||||||
qDebug() << debug_message;
|
|
||||||
delete nvel_elmt;
|
delete nvel_elmt;
|
||||||
|
qDebug(debug_message.toLatin1().data());
|
||||||
qDebug() << "Utilisation d'un GhostElement en lieu et place de cet element.";
|
continue;
|
||||||
nvel_elmt = new GhostElement(element_location);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// charge les caracteristiques de l'element
|
// charge les caracteristiques de l'element
|
||||||
if (nvel_elmt -> fromXml(e, table_adr_id)) {
|
if (nvel_elmt -> fromXml(e, table_adr_id)) {
|
||||||
// ajout de l'element au schema et a la liste des elements ajoutes
|
// ajout de l'element au schema et a la liste des elements ajoutes
|
||||||
addElement(nvel_elmt);
|
addItem(nvel_elmt);
|
||||||
added_elements << nvel_elmt;
|
added_elements << nvel_elmt;
|
||||||
} else {
|
} else {
|
||||||
delete nvel_elmt;
|
delete nvel_elmt;
|
||||||
@@ -464,7 +389,6 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
foreach (QDomElement f, QET::findInDomElement(root, "inputs", "input")) {
|
foreach (QDomElement f, QET::findInDomElement(root, "inputs", "input")) {
|
||||||
DiagramTextItem *dti = new DiagramTextItem(0, this);
|
DiagramTextItem *dti = new DiagramTextItem(0, this);
|
||||||
dti -> fromXml(f);
|
dti -> fromXml(f);
|
||||||
addDiagramTextItem(dti);
|
|
||||||
added_texts << dti;
|
added_texts << dti;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,7 +448,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
added_conductors << c;
|
added_conductors << c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else qDebug() << "Le chargement du conducteur" << id_p1 << id_p2 << "a echoue";
|
} else qDebug() << "Le chargement du conductor" << id_p1 << id_p2 << "a echoue";
|
||||||
}
|
}
|
||||||
|
|
||||||
// remplissage des listes facultatives
|
// remplissage des listes facultatives
|
||||||
@@ -534,178 +458,9 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf
|
|||||||
content_ptr -> textFields = added_texts;
|
content_ptr -> textFields = added_texts;
|
||||||
}
|
}
|
||||||
|
|
||||||
write(document);
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Enregistre le schema XML dans son document XML interne et emet le signal
|
|
||||||
written().
|
|
||||||
*/
|
|
||||||
void Diagram::write() {
|
|
||||||
qDebug() << qPrintable(QString("Diagram::write() : saving changes from diagram \"%1\" [%2]").arg(title()).arg(QET::pointerString(this)));
|
|
||||||
write(toXml().documentElement());
|
|
||||||
undoStack().setClean();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Enregistre un element XML dans son document XML interne et emet le signal
|
|
||||||
written().
|
|
||||||
@param element xml a enregistrer
|
|
||||||
*/
|
|
||||||
void Diagram::write(const QDomElement &element) {
|
|
||||||
xml_document.clear();
|
|
||||||
xml_document.appendChild(xml_document.importNode(element, true));
|
|
||||||
emit(written());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return true si la fonction write a deja ete appele (pour etre plus exact :
|
|
||||||
si le document XML utilise en interne n'est pas vide), false sinon
|
|
||||||
*/
|
|
||||||
bool Diagram::wasWritten() const {
|
|
||||||
return(!xml_document.isNull());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return le schema en XML tel qu'il doit etre enregistre dans le fichier projet
|
|
||||||
@param xml_doc document XML a utiliser pour creer l'element
|
|
||||||
*/
|
|
||||||
QDomElement Diagram::writeXml(QDomDocument &xml_doc) const {
|
|
||||||
// si le schema n'a pas ete enregistre explicitement, on n'ecrit rien
|
|
||||||
if (!wasWritten()) return(QDomElement());
|
|
||||||
|
|
||||||
QDomElement diagram_elmt = xml_document.documentElement();
|
|
||||||
QDomNode new_node = xml_doc.importNode(diagram_elmt, true);
|
|
||||||
return(new_node.toElement());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Ajoute un element sur le schema
|
|
||||||
@param element Element a ajouter
|
|
||||||
*/
|
|
||||||
void Diagram::addElement(Element *element) {
|
|
||||||
if (!element || isReadOnly()) return;
|
|
||||||
|
|
||||||
// ajoute l'element au schema
|
|
||||||
if (element -> scene() != this) {
|
|
||||||
addItem(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
// surveille les modifications de ses champs de texte
|
|
||||||
foreach(ElementTextItem *eti, element -> texts()) {
|
|
||||||
connect(
|
|
||||||
eti,
|
|
||||||
SIGNAL(diagramTextChanged(DiagramTextItem *, const QString &, const QString &)),
|
|
||||||
this,
|
|
||||||
SLOT(diagramTextChanged(DiagramTextItem *, const QString &, const QString &))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Ajoute un conducteur sur le schema
|
|
||||||
@param conductor Conducteur a ajouter
|
|
||||||
*/
|
|
||||||
void Diagram::addConductor(Conductor *conductor) {
|
|
||||||
if (!conductor || isReadOnly()) return;
|
|
||||||
|
|
||||||
// ajoute le conducteur au schema
|
|
||||||
if (conductor -> scene() != this) {
|
|
||||||
addItem(conductor);
|
|
||||||
conductor -> terminal1 -> addConductor(conductor);
|
|
||||||
conductor -> terminal2 -> addConductor(conductor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Aoute un champ de texte independant sur le schema
|
|
||||||
@param dti Champ de texte a ajouter
|
|
||||||
*/
|
|
||||||
void Diagram::addDiagramTextItem(DiagramTextItem *dti) {
|
|
||||||
if (!dti || isReadOnly()) return;
|
|
||||||
|
|
||||||
// ajoute le champ de texte au schema
|
|
||||||
if (dti -> scene() != this) {
|
|
||||||
addItem(dti);
|
|
||||||
}
|
|
||||||
|
|
||||||
// surveille les modifications apportees au champ de texte
|
|
||||||
connect(
|
|
||||||
dti,
|
|
||||||
SIGNAL(diagramTextChanged(DiagramTextItem *, const QString &, const QString &)),
|
|
||||||
this,
|
|
||||||
SLOT(diagramTextChanged(DiagramTextItem *, const QString &, const QString &))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Enleve un element du schema
|
|
||||||
@param element Element a enlever
|
|
||||||
*/
|
|
||||||
void Diagram::removeElement(Element *element) {
|
|
||||||
if (!element || isReadOnly()) return;
|
|
||||||
|
|
||||||
// enleve l'element au schema
|
|
||||||
removeItem(element);
|
|
||||||
|
|
||||||
// arrete la surveillance des modifications de ses champs de texte
|
|
||||||
foreach(ElementTextItem *eti, element -> texts()) {
|
|
||||||
disconnect(
|
|
||||||
eti,
|
|
||||||
SIGNAL(diagramTextChanged(DiagramTextItem *, const QString &, const QString &)),
|
|
||||||
this,
|
|
||||||
SLOT(diagramTextChanged(DiagramTextItem *, const QString &, const QString &))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Enleve un conducteur du schema
|
|
||||||
@param conductor Conducteur a enlever
|
|
||||||
*/
|
|
||||||
void Diagram::removeConductor(Conductor *conductor) {
|
|
||||||
if (!conductor || isReadOnly()) return;
|
|
||||||
|
|
||||||
// detache le conducteur sans le detruire
|
|
||||||
conductor -> terminal1 -> removeConductor(conductor);
|
|
||||||
conductor -> terminal2 -> removeConductor(conductor);
|
|
||||||
|
|
||||||
// enleve le conducteur du schema
|
|
||||||
removeItem(conductor);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Enleve un champ de texte independant du schema
|
|
||||||
@param dti Champ de texte a enlever
|
|
||||||
*/
|
|
||||||
void Diagram::removeDiagramTextItem(DiagramTextItem *dti) {
|
|
||||||
if (!dti || isReadOnly()) return;
|
|
||||||
|
|
||||||
// enleve le champ de texte au schema
|
|
||||||
removeItem(dti);
|
|
||||||
|
|
||||||
// arrete la surveillance des modifications apportees au champ de texte
|
|
||||||
disconnect(
|
|
||||||
dti,
|
|
||||||
SIGNAL(diagramTextChanged(DiagramTextItem *, const QString &, const QString &)),
|
|
||||||
this,
|
|
||||||
SLOT(diagramTextChanged(DiagramTextItem *, const QString &, const QString &))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Gere le fait qu'un texte du schema ait ete modifie
|
|
||||||
@param text_item Texte modifie
|
|
||||||
@param old_text Ancien texte
|
|
||||||
@param new_text Nouveau texte
|
|
||||||
*/
|
|
||||||
void Diagram::diagramTextChanged(DiagramTextItem *text_item, const QString &old_text, const QString &new_text) {
|
|
||||||
if (!text_item) return;
|
|
||||||
undo_stack -> push(new ChangeDiagramTextCommand(text_item, old_text, new_text));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Verifie si la selection est passe d'un etat ou elle est vide a un etat ou
|
Verifie si la selection est passe d'un etat ou elle est vide a un etat ou
|
||||||
elle ne l'est pas, et inversement. Si c'est le cas, le signal
|
elle ne l'est pas, et inversement. Si c'est le cas, le signal
|
||||||
@@ -734,26 +489,6 @@ QRectF Diagram::border() const {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
@return le titre du cartouche
|
|
||||||
*/
|
|
||||||
QString Diagram::title() const {
|
|
||||||
return(border_and_inset.title());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return la liste des elements de ce schema
|
|
||||||
*/
|
|
||||||
QList<CustomElement *> Diagram::customElements() const {
|
|
||||||
QList<CustomElement *> elements_list;
|
|
||||||
foreach(QGraphicsItem *qgi, items()) {
|
|
||||||
if (CustomElement *elmt = qgraphicsitem_cast<CustomElement *>(qgi)) {
|
|
||||||
elements_list << elmt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return(elements_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// oublie la liste des elements et conducteurs en mouvement
|
/// oublie la liste des elements et conducteurs en mouvement
|
||||||
void Diagram::invalidateMovedElements() {
|
void Diagram::invalidateMovedElements() {
|
||||||
if (!moved_elements_fetched) return;
|
if (!moved_elements_fetched) return;
|
||||||
@@ -835,20 +570,6 @@ void Diagram::moveElements(const QPointF &diff, QGraphicsItem *dontmove) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Permet de savoir si un element est utilise sur un schema
|
|
||||||
@param location Emplacement d'un element
|
|
||||||
@return true si l'element location est utilise sur ce schema, false sinon
|
|
||||||
*/
|
|
||||||
bool Diagram::usesElement(const ElementsLocation &location) {
|
|
||||||
foreach(CustomElement *element, customElements()) {
|
|
||||||
if (element -> location() == location) {
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Definit s'il faut afficher ou non les bornes
|
Definit s'il faut afficher ou non les bornes
|
||||||
@param dt true pour afficher les bornes, false sinon
|
@param dt true pour afficher les bornes, false sinon
|
||||||
@@ -881,39 +602,6 @@ bool Diagram::clipboardMayContainDiagram() {
|
|||||||
return(may_be_diagram);
|
return(may_be_diagram);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
@return le projet auquel ce schema appartient ou 0 s'il s'agit d'un schema
|
|
||||||
independant.
|
|
||||||
*/
|
|
||||||
QETProject *Diagram::project() const {
|
|
||||||
return(project_);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@param project le nouveau projet auquel ce schema appartient ou 0 s'il
|
|
||||||
s'agit d'un schema independant. Indiquer 0 pour rendre ce schema independant.
|
|
||||||
*/
|
|
||||||
void Diagram::setProject(QETProject *project) {
|
|
||||||
project_ = project;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return true si le schema est en lecture seule
|
|
||||||
*/
|
|
||||||
bool Diagram::isReadOnly() const {
|
|
||||||
return(read_only_);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@param read_only true pour passer le schema en lecture seule, false sinon
|
|
||||||
*/
|
|
||||||
void Diagram::setReadOnly(bool read_only) {
|
|
||||||
if (read_only_ != read_only) {
|
|
||||||
read_only_ = read_only;
|
|
||||||
emit(readOnlyChanged(read_only_));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return Le contenu du schema. Les conducteurs sont tous places dans
|
@return Le contenu du schema. Les conducteurs sont tous places dans
|
||||||
conductorsToMove.
|
conductorsToMove.
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -19,17 +19,15 @@
|
|||||||
#define SCHEMA_H
|
#define SCHEMA_H
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include <QtXml>
|
#include <QtXml>
|
||||||
|
#include "qetdiagrameditor.h"
|
||||||
#include "borderinset.h"
|
#include "borderinset.h"
|
||||||
#include "qgimanager.h"
|
#include "qgimanager.h"
|
||||||
#include "conductorproperties.h"
|
#include "conductorproperties.h"
|
||||||
class Element;
|
class Element;
|
||||||
class CustomElement;
|
|
||||||
class Terminal;
|
class Terminal;
|
||||||
class Conductor;
|
class Conductor;
|
||||||
class DiagramTextItem;
|
class DiagramTextItem;
|
||||||
class DiagramContent;
|
class DiagramContent;
|
||||||
class QETProject;
|
|
||||||
class ElementsLocation;
|
|
||||||
/**
|
/**
|
||||||
Cette classe represente un schema electrique.
|
Cette classe represente un schema electrique.
|
||||||
Elle gere les differents elements et conducteurs qui le composent
|
Elle gere les differents elements et conducteurs qui le composent
|
||||||
@@ -77,12 +75,9 @@ class Diagram : public QGraphicsScene {
|
|||||||
QSet<Conductor *> conductors_to_move;
|
QSet<Conductor *> conductors_to_move;
|
||||||
QHash<Conductor *, Terminal *> conductors_to_update;
|
QHash<Conductor *, Terminal *> conductors_to_update;
|
||||||
QSet<DiagramTextItem *> texts_to_move;
|
QSet<DiagramTextItem *> texts_to_move;
|
||||||
QGIManager *qgi_manager;
|
QGIManager qgi_manager;
|
||||||
QUndoStack *undo_stack;
|
QUndoStack undo_stack;
|
||||||
bool draw_terminals;
|
bool draw_terminals;
|
||||||
QDomDocument xml_document;
|
|
||||||
QETProject *project_;
|
|
||||||
bool read_only_;
|
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
protected:
|
protected:
|
||||||
@@ -93,14 +88,6 @@ class Diagram : public QGraphicsScene {
|
|||||||
public:
|
public:
|
||||||
static bool clipboardMayContainDiagram();
|
static bool clipboardMayContainDiagram();
|
||||||
|
|
||||||
// fonctions relatives au projet parent
|
|
||||||
QETProject *project() const;
|
|
||||||
void setProject(QETProject *);
|
|
||||||
|
|
||||||
// fonctions relatives a la lecture seule
|
|
||||||
bool isReadOnly() const;
|
|
||||||
void setReadOnly(bool);
|
|
||||||
|
|
||||||
// fonctions relatives a la pose de conducteurs
|
// fonctions relatives a la pose de conducteurs
|
||||||
void setConductor(bool);
|
void setConductor(bool);
|
||||||
void setConductorStart (QPointF);
|
void setConductorStart (QPointF);
|
||||||
@@ -109,20 +96,6 @@ class Diagram : public QGraphicsScene {
|
|||||||
// fonctions relatives a l'import / export XML
|
// fonctions relatives a l'import / export XML
|
||||||
QDomDocument toXml(bool = true);
|
QDomDocument toXml(bool = true);
|
||||||
bool fromXml(QDomDocument &, QPointF = QPointF(), bool = true, DiagramContent * = NULL);
|
bool fromXml(QDomDocument &, QPointF = QPointF(), bool = true, DiagramContent * = NULL);
|
||||||
bool fromXml(QDomElement &, QPointF = QPointF(), bool = true, DiagramContent * = NULL);
|
|
||||||
void write();
|
|
||||||
void write(const QDomElement &);
|
|
||||||
bool wasWritten() const;
|
|
||||||
QDomElement writeXml(QDomDocument &) const;
|
|
||||||
|
|
||||||
// fonctions relative a l'ajout et a l'enlevement d'elements graphiques sur le schema
|
|
||||||
void addElement(Element *);
|
|
||||||
void addConductor(Conductor *);
|
|
||||||
void addDiagramTextItem(DiagramTextItem *);
|
|
||||||
|
|
||||||
void removeElement(Element *);
|
|
||||||
void removeConductor(Conductor *);
|
|
||||||
void removeDiagramTextItem(DiagramTextItem *);
|
|
||||||
|
|
||||||
// fonctions relatives aux options graphiques
|
// fonctions relatives aux options graphiques
|
||||||
void setDisplayGrid(bool);
|
void setDisplayGrid(bool);
|
||||||
@@ -136,13 +109,9 @@ class Diagram : public QGraphicsScene {
|
|||||||
void setDrawTerminals(bool);
|
void setDrawTerminals(bool);
|
||||||
|
|
||||||
QRectF border() const;
|
QRectF border() const;
|
||||||
QString title() const;
|
|
||||||
bool toPaintDevice(QPaintDevice &, int = -1, int = -1, Qt::AspectRatioMode = Qt::KeepAspectRatio);
|
bool toPaintDevice(QPaintDevice &, int = -1, int = -1, Qt::AspectRatioMode = Qt::KeepAspectRatio);
|
||||||
QSize imageSize() const;
|
QSize imageSize() const;
|
||||||
|
|
||||||
bool isEmpty() const;
|
|
||||||
|
|
||||||
QList<CustomElement *> customElements() const;
|
|
||||||
void invalidateMovedElements();
|
void invalidateMovedElements();
|
||||||
void fetchMovedElements();
|
void fetchMovedElements();
|
||||||
const QSet<Element *> &elementsToMove();
|
const QSet<Element *> &elementsToMove();
|
||||||
@@ -153,14 +122,10 @@ class Diagram : public QGraphicsScene {
|
|||||||
DiagramContent content() const;
|
DiagramContent content() const;
|
||||||
DiagramContent selectedContent();
|
DiagramContent selectedContent();
|
||||||
void moveElements(const QPointF &, QGraphicsItem * = NULL);
|
void moveElements(const QPointF &, QGraphicsItem * = NULL);
|
||||||
bool usesElement(const ElementsLocation &);
|
|
||||||
|
|
||||||
QUndoStack &undoStack();
|
QUndoStack &undoStack();
|
||||||
QGIManager &qgiManager();
|
QGIManager &qgiManager();
|
||||||
|
|
||||||
public slots:
|
|
||||||
void diagramTextChanged(DiagramTextItem *, const QString &, const QString &);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slot_checkSelectionEmptinessChange();
|
void slot_checkSelectionEmptinessChange();
|
||||||
|
|
||||||
@@ -171,12 +136,10 @@ class Diagram : public QGraphicsScene {
|
|||||||
vice-versa.
|
vice-versa.
|
||||||
*/
|
*/
|
||||||
void selectionEmptinessChanged();
|
void selectionEmptinessChanged();
|
||||||
void written();
|
|
||||||
void readOnlyChanged(bool);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Permet d'ajouter ou enlever le "poseur de conducteur", c'est-a-dire la
|
Permet d'ajouter ou enlever le « poseur de conducteur », c'est-a-dire la
|
||||||
droite en pointilles qui apparait lorsqu'on pose un conducteur entre deux
|
droite en pointilles qui apparait lorsqu'on pose un conducteur entre deux
|
||||||
bornes.
|
bornes.
|
||||||
@param pf true pour ajouter le poseur de conducteur, false pour l'enlever
|
@param pf true pour ajouter le poseur de conducteur, false pour l'enlever
|
||||||
@@ -287,12 +250,12 @@ inline const QSet<DiagramTextItem *> &Diagram::textsToMove() {
|
|||||||
|
|
||||||
/// @return la pile d'annulations de ce schema
|
/// @return la pile d'annulations de ce schema
|
||||||
inline QUndoStack &Diagram::undoStack() {
|
inline QUndoStack &Diagram::undoStack() {
|
||||||
return(*undo_stack);
|
return(undo_stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return le egstionnaire de QGraphicsItem de ce schema
|
/// @return le egstionnaire de QGraphicsItem de ce schema
|
||||||
inline QGIManager &Diagram::qgiManager() {
|
inline QGIManager &Diagram::qgiManager() {
|
||||||
return(*qgi_manager);
|
return(qgi_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return true si les bornes sont affichees, false sinon
|
/// @return true si les bornes sont affichees, false sinon
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -33,7 +33,7 @@ AddElementCommand::AddElementCommand(
|
|||||||
const QPointF &p,
|
const QPointF &p,
|
||||||
QUndoCommand *parent
|
QUndoCommand *parent
|
||||||
) :
|
) :
|
||||||
QUndoCommand(QString(QObject::tr("ajouter 1 %1", "undo caption - %1 is an element name")).arg(elmt -> name()), parent),
|
QUndoCommand(QObject::tr("ajouter 1 ") + elmt -> nom(), parent),
|
||||||
element(elmt),
|
element(elmt),
|
||||||
diagram(d),
|
diagram(d),
|
||||||
position(p)
|
position(p)
|
||||||
@@ -48,12 +48,12 @@ AddElementCommand::~AddElementCommand() {
|
|||||||
|
|
||||||
/// Annule l'ajout
|
/// Annule l'ajout
|
||||||
void AddElementCommand::undo() {
|
void AddElementCommand::undo() {
|
||||||
diagram -> removeElement(element);
|
diagram -> removeItem(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Refait l'ajout
|
/// Refait l'ajout
|
||||||
void AddElementCommand::redo() {
|
void AddElementCommand::redo() {
|
||||||
diagram -> addElement(element);
|
diagram -> addItem(element);
|
||||||
element -> setPos(position);
|
element -> setPos(position);
|
||||||
element -> setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
element -> setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ void AddElementCommand::redo() {
|
|||||||
@param parent QUndoCommand parent
|
@param parent QUndoCommand parent
|
||||||
*/
|
*/
|
||||||
AddTextCommand::AddTextCommand(Diagram *dia, DiagramTextItem *text, const QPointF &pos, QUndoCommand *parent) :
|
AddTextCommand::AddTextCommand(Diagram *dia, DiagramTextItem *text, const QPointF &pos, QUndoCommand *parent) :
|
||||||
QUndoCommand(QObject::tr("Ajouter un champ de texte", "undo caption"), parent),
|
QUndoCommand(QObject::tr("Ajouter un champ de texte"), parent),
|
||||||
textitem(text),
|
textitem(text),
|
||||||
diagram(dia),
|
diagram(dia),
|
||||||
position(pos)
|
position(pos)
|
||||||
@@ -81,12 +81,12 @@ AddTextCommand::~AddTextCommand() {
|
|||||||
|
|
||||||
/// Annule l'ajout
|
/// Annule l'ajout
|
||||||
void AddTextCommand::undo() {
|
void AddTextCommand::undo() {
|
||||||
diagram -> removeDiagramTextItem(textitem);
|
diagram -> removeItem(textitem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Refait l'ajour
|
/// Refait l'ajour
|
||||||
void AddTextCommand::redo() {
|
void AddTextCommand::redo() {
|
||||||
diagram -> addDiagramTextItem(textitem);
|
diagram -> addItem(textitem);
|
||||||
textitem -> setPos(position);
|
textitem -> setPos(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ AddConductorCommand::AddConductorCommand(
|
|||||||
Conductor *c,
|
Conductor *c,
|
||||||
QUndoCommand *parent
|
QUndoCommand *parent
|
||||||
) :
|
) :
|
||||||
QUndoCommand(QObject::tr("ajouter un conducteur", "undo caption"), parent),
|
QUndoCommand(QObject::tr("ajouter un conducteur"), parent),
|
||||||
conductor(c),
|
conductor(c),
|
||||||
diagram(d)
|
diagram(d)
|
||||||
{
|
{
|
||||||
@@ -115,12 +115,15 @@ AddConductorCommand::~AddConductorCommand() {
|
|||||||
|
|
||||||
/// Annule l'ajout
|
/// Annule l'ajout
|
||||||
void AddConductorCommand::undo() {
|
void AddConductorCommand::undo() {
|
||||||
diagram -> removeConductor(conductor);
|
// detache le conducteur sans le detruire
|
||||||
|
conductor -> terminal1 -> removeConductor(conductor);
|
||||||
|
conductor -> terminal2 -> removeConductor(conductor);
|
||||||
|
diagram -> removeItem(conductor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Refait l'ajout
|
/// Refait l'ajout
|
||||||
void AddConductorCommand::redo() {
|
void AddConductorCommand::redo() {
|
||||||
diagram -> addConductor(conductor);
|
diagram -> addItem(conductor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,14 +141,7 @@ DeleteElementsCommand::DeleteElementsCommand(
|
|||||||
removed_content(content),
|
removed_content(content),
|
||||||
diagram(dia)
|
diagram(dia)
|
||||||
{
|
{
|
||||||
setText(
|
setText(QObject::tr("supprimer ") + removed_content.sentence(DiagramContent::All));
|
||||||
QString(
|
|
||||||
QObject::tr(
|
|
||||||
"supprimer %1",
|
|
||||||
"undo caption - %1 is a sentence listing the removed content"
|
|
||||||
)
|
|
||||||
).arg(removed_content.sentence(DiagramContent::All))
|
|
||||||
);
|
|
||||||
diagram -> qgiManager().manage(removed_content.items(DiagramContent::All));
|
diagram -> qgiManager().manage(removed_content.items(DiagramContent::All));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,17 +154,19 @@ DeleteElementsCommand::~DeleteElementsCommand() {
|
|||||||
void DeleteElementsCommand::undo() {
|
void DeleteElementsCommand::undo() {
|
||||||
// remet les elements
|
// remet les elements
|
||||||
foreach(Element *e, removed_content.elements) {
|
foreach(Element *e, removed_content.elements) {
|
||||||
diagram -> addElement(e);
|
diagram -> addItem(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remet les conducteurs
|
// remet les conducteurs
|
||||||
foreach(Conductor *c, removed_content.conductors(DiagramContent::AnyConductor)) {
|
foreach(Conductor *c, removed_content.conductors(DiagramContent::AnyConductor)) {
|
||||||
diagram -> addConductor(c);
|
diagram -> addItem(c);
|
||||||
|
c -> terminal1 -> addConductor(c);
|
||||||
|
c -> terminal2 -> addConductor(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remet les textes
|
// remet les textes
|
||||||
foreach(DiagramTextItem *t, removed_content.textFields) {
|
foreach(DiagramTextItem *t, removed_content.textFields) {
|
||||||
diagram -> addDiagramTextItem(t);
|
diagram -> addItem(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,17 +174,19 @@ void DeleteElementsCommand::undo() {
|
|||||||
void DeleteElementsCommand::redo() {
|
void DeleteElementsCommand::redo() {
|
||||||
// enleve les conducteurs
|
// enleve les conducteurs
|
||||||
foreach(Conductor *c, removed_content.conductors(DiagramContent::AnyConductor)) {
|
foreach(Conductor *c, removed_content.conductors(DiagramContent::AnyConductor)) {
|
||||||
diagram -> removeConductor(c);
|
c -> terminal1 -> removeConductor(c);
|
||||||
|
c -> terminal2 -> removeConductor(c);
|
||||||
|
diagram -> removeItem(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
// enleve les elements
|
// enleve les elements
|
||||||
foreach(Element *e, removed_content.elements) {
|
foreach(Element *e, removed_content.elements) {
|
||||||
diagram -> removeElement(e);
|
diagram -> removeItem(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// enleve les textes
|
// enleve les textes
|
||||||
foreach(DiagramTextItem *t, removed_content.textFields) {
|
foreach(DiagramTextItem *t, removed_content.textFields) {
|
||||||
diagram -> removeDiagramTextItem(t);
|
diagram -> removeItem(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,14 +208,7 @@ PasteDiagramCommand::PasteDiagramCommand(
|
|||||||
first_redo(true)
|
first_redo(true)
|
||||||
{
|
{
|
||||||
|
|
||||||
setText(
|
setText(QObject::tr("coller ") + content.sentence(filter));
|
||||||
QString(
|
|
||||||
QObject::tr(
|
|
||||||
"coller %1",
|
|
||||||
"undo caption - %1 is a sentence listing the content to paste"
|
|
||||||
).arg(content.sentence(filter))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
diagram -> qgiManager().manage(content.items(filter));
|
diagram -> qgiManager().manage(content.items(filter));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,13 +220,17 @@ PasteDiagramCommand::~PasteDiagramCommand() {
|
|||||||
/// annule le coller
|
/// annule le coller
|
||||||
void PasteDiagramCommand::undo() {
|
void PasteDiagramCommand::undo() {
|
||||||
// enleve les conducteurs
|
// enleve les conducteurs
|
||||||
foreach(Conductor *c, content.conductorsToMove) diagram -> removeConductor(c);
|
foreach(Conductor *c, content.conductorsToMove) {
|
||||||
|
c -> terminal1 -> removeConductor(c);
|
||||||
|
c -> terminal2 -> removeConductor(c);
|
||||||
|
diagram -> removeItem(c);
|
||||||
|
}
|
||||||
|
|
||||||
// enleve les elements
|
// enleve les elements
|
||||||
foreach(Element *e, content.elements) diagram -> removeElement(e);
|
foreach(Element *e, content.elements) diagram -> removeItem(e);
|
||||||
|
|
||||||
// enleve les textes
|
// enleve les textes
|
||||||
foreach(DiagramTextItem *t, content.textFields) diagram -> removeDiagramTextItem(t);
|
foreach(DiagramTextItem *t, content.textFields) diagram -> removeItem(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// refait le coller
|
/// refait le coller
|
||||||
@@ -241,13 +238,17 @@ void PasteDiagramCommand::redo() {
|
|||||||
if (first_redo) first_redo = false;
|
if (first_redo) first_redo = false;
|
||||||
else {
|
else {
|
||||||
// pose les elements
|
// pose les elements
|
||||||
foreach(Element *e, content.elements) diagram -> addElement(e);
|
foreach(Element *e, content.elements) diagram -> addItem(e);
|
||||||
|
|
||||||
// pose les conducteurs
|
// pose les conducteurs
|
||||||
foreach(Conductor *c, content.conductorsToMove) diagram -> addConductor(c);
|
foreach(Conductor *c, content.conductorsToMove) {
|
||||||
|
diagram -> addItem(c);
|
||||||
|
c -> terminal1 -> addConductor(c);
|
||||||
|
c -> terminal2 -> addConductor(c);
|
||||||
|
}
|
||||||
|
|
||||||
// pose les textes
|
// pose les textes
|
||||||
foreach(DiagramTextItem *t, content.textFields) diagram -> addDiagramTextItem(t);
|
foreach(DiagramTextItem *t, content.textFields) diagram -> addItem(t);
|
||||||
}
|
}
|
||||||
foreach(Element *e, content.elements) e -> setSelected(true);
|
foreach(Element *e, content.elements) e -> setSelected(true);
|
||||||
foreach(Conductor *c, content.conductorsToMove) c -> setSelected(true);
|
foreach(Conductor *c, content.conductorsToMove) c -> setSelected(true);
|
||||||
@@ -267,14 +268,7 @@ CutDiagramCommand::CutDiagramCommand(
|
|||||||
) :
|
) :
|
||||||
DeleteElementsCommand(dia, content, parent)
|
DeleteElementsCommand(dia, content, parent)
|
||||||
{
|
{
|
||||||
setText(
|
setText(QObject::tr("couper ") + content.sentence(DiagramContent::All));
|
||||||
QString(
|
|
||||||
QObject::tr(
|
|
||||||
"couper %1",
|
|
||||||
"undo caption - %1 is a sentence listing the content to cut"
|
|
||||||
).arg(content.sentence(DiagramContent::All))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
@@ -300,21 +294,7 @@ MoveElementsCommand::MoveElementsCommand(
|
|||||||
movement(m),
|
movement(m),
|
||||||
first_redo(true)
|
first_redo(true)
|
||||||
{
|
{
|
||||||
QString moved_content_sentence = content_to_move.sentence(
|
setText(QObject::tr("d\351placer ") + content_to_move.sentence(DiagramContent::Elements|DiagramContent::TextFields|DiagramContent::ConductorsToUpdate|DiagramContent::ConductorsToMove));
|
||||||
DiagramContent::Elements |
|
|
||||||
DiagramContent::TextFields |
|
|
||||||
DiagramContent::ConductorsToUpdate |
|
|
||||||
DiagramContent::ConductorsToMove
|
|
||||||
);
|
|
||||||
|
|
||||||
setText(
|
|
||||||
QString(
|
|
||||||
QObject::tr(
|
|
||||||
"d\351placer %1",
|
|
||||||
"undo caption - %1 is a sentence listing the moved content"
|
|
||||||
).arg(moved_content_sentence)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
@@ -375,7 +355,7 @@ ChangeDiagramTextCommand::ChangeDiagramTextCommand(
|
|||||||
const QString &after,
|
const QString &after,
|
||||||
QUndoCommand *parent
|
QUndoCommand *parent
|
||||||
) :
|
) :
|
||||||
QUndoCommand(QObject::tr("modifier le texte", "undo caption"), parent),
|
QUndoCommand(QObject::tr("modifier le texte"), parent),
|
||||||
text_item(dti),
|
text_item(dti),
|
||||||
text_before(before),
|
text_before(before),
|
||||||
text_after(after),
|
text_after(after),
|
||||||
@@ -408,17 +388,9 @@ void ChangeDiagramTextCommand::redo() {
|
|||||||
@param parent QUndoCommand parent
|
@param parent QUndoCommand parent
|
||||||
*/
|
*/
|
||||||
RotateElementsCommand::RotateElementsCommand(const QHash<Element *, QET::Orientation> &elements, QUndoCommand *parent) :
|
RotateElementsCommand::RotateElementsCommand(const QHash<Element *, QET::Orientation> &elements, QUndoCommand *parent) :
|
||||||
QUndoCommand(parent),
|
QUndoCommand(QObject::tr("pivoter ") + QET::ElementsAndConductorsSentence(elements.count(), 0), parent),
|
||||||
elements_to_rotate(elements)
|
elements_to_rotate(elements)
|
||||||
{
|
{
|
||||||
setText(
|
|
||||||
QString(
|
|
||||||
QObject::tr(
|
|
||||||
"pivoter %1",
|
|
||||||
"undo caption - %1 is a sentence listing the rotated content"
|
|
||||||
)
|
|
||||||
).arg(QET::ElementsAndConductorsSentence(elements.count(), 0))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
@@ -455,7 +427,7 @@ ChangeConductorCommand::ChangeConductorCommand(
|
|||||||
Qt::Corner path_t,
|
Qt::Corner path_t,
|
||||||
QUndoCommand *parent
|
QUndoCommand *parent
|
||||||
) :
|
) :
|
||||||
QUndoCommand(QObject::tr("modifier un conducteur", "undo caption"), parent),
|
QUndoCommand(QObject::tr("modifier un conducteur"), parent),
|
||||||
conductor(c),
|
conductor(c),
|
||||||
old_profile(old_p),
|
old_profile(old_p),
|
||||||
new_profile(new_p),
|
new_profile(new_p),
|
||||||
@@ -488,15 +460,9 @@ ResetConductorCommand::ResetConductorCommand(
|
|||||||
const QHash<Conductor *, ConductorProfilesGroup> &cp,
|
const QHash<Conductor *, ConductorProfilesGroup> &cp,
|
||||||
QUndoCommand *parent
|
QUndoCommand *parent
|
||||||
) :
|
) :
|
||||||
QUndoCommand(parent),
|
QUndoCommand(QObject::tr("R\351initialiser ") + QET::ElementsAndConductorsSentence(0, cp.count()), parent),
|
||||||
conductors_profiles(cp)
|
conductors_profiles(cp)
|
||||||
{
|
{
|
||||||
setText(
|
|
||||||
QObject::tr(
|
|
||||||
"R\351initialiser %1",
|
|
||||||
"undo caption - %1 is a sentence listing the reset content"
|
|
||||||
).arg(QET::ElementsAndConductorsSentence(0, cp.count()))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
@@ -530,7 +496,7 @@ ChangeInsetCommand::ChangeInsetCommand(
|
|||||||
const InsetProperties &new_ip,
|
const InsetProperties &new_ip,
|
||||||
QUndoCommand *parent
|
QUndoCommand *parent
|
||||||
) :
|
) :
|
||||||
QUndoCommand(QObject::tr("modifier le cartouche", "undo caption"), parent),
|
QUndoCommand(QObject::tr("modifier le cartouche"), parent),
|
||||||
diagram(d),
|
diagram(d),
|
||||||
old_inset(old_ip),
|
old_inset(old_ip),
|
||||||
new_inset(new_ip)
|
new_inset(new_ip)
|
||||||
@@ -558,11 +524,13 @@ void ChangeInsetCommand::redo() {
|
|||||||
@param dia Schema modifie
|
@param dia Schema modifie
|
||||||
@param parent QUndoCommand parent
|
@param parent QUndoCommand parent
|
||||||
*/
|
*/
|
||||||
ChangeBorderCommand::ChangeBorderCommand(Diagram *dia, const BorderProperties &old_bp, const BorderProperties &new_bp, QUndoCommand *parent) :
|
ChangeBorderCommand::ChangeBorderCommand(Diagram *dia, QUndoCommand *parent) :
|
||||||
QUndoCommand(QObject::tr("modifier les dimensions du sch\351ma", "undo caption"), parent),
|
QUndoCommand(QObject::tr("modifier les dimensions du sch\351ma"), parent),
|
||||||
diagram(dia),
|
diagram(dia),
|
||||||
old_properties(old_bp),
|
columnsCountDifference(0),
|
||||||
new_properties(new_bp)
|
columnsHeightDifference(0.0),
|
||||||
|
columnsWidthDifference(0.0),
|
||||||
|
headersHeightDifference(0.0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -570,14 +538,39 @@ ChangeBorderCommand::ChangeBorderCommand(Diagram *dia, const BorderProperties &o
|
|||||||
ChangeBorderCommand::~ChangeBorderCommand() {
|
ChangeBorderCommand::~ChangeBorderCommand() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Applique les changements au schema
|
||||||
|
@param coeff comme les changements s'expriment sous forme de nombres dont
|
||||||
|
il suffit d'inverser le signe pour les annuler, ces valeurs sont ici
|
||||||
|
multipliees par le coefficient passe en parametre avant d'etre appliquees.
|
||||||
|
Pour resumer : 1 pour refaire, -1 pour annuler.
|
||||||
|
*/
|
||||||
|
void ChangeBorderCommand::applyChanges(int coeff) {
|
||||||
|
// reference vers l'objet border_and_inset du schema
|
||||||
|
BorderInset &border = diagram -> border_and_inset;
|
||||||
|
if (columnsCountDifference) {
|
||||||
|
border.setNbColumns(border.nbColumn() + (columnsCountDifference * coeff));
|
||||||
|
}
|
||||||
|
if (columnsHeightDifference) {
|
||||||
|
border.setColumnsHeight(border.columnsHeight() + (columnsHeightDifference * coeff));
|
||||||
|
}
|
||||||
|
if (columnsWidthDifference) {
|
||||||
|
border.setColumnsWidth(border.columnsWidth() + (columnsWidthDifference * coeff));
|
||||||
|
}
|
||||||
|
if (headersHeightDifference) {
|
||||||
|
border.setColumnsHeaderHeight(border.columnsHeaderHeight() + (headersHeightDifference * coeff));
|
||||||
|
}
|
||||||
|
border.adjustInsetToColumns();
|
||||||
|
}
|
||||||
|
|
||||||
/// Annule les changements apportes au schema
|
/// Annule les changements apportes au schema
|
||||||
void ChangeBorderCommand::undo() {
|
void ChangeBorderCommand::undo() {
|
||||||
diagram -> border_and_inset.importBorder(old_properties);
|
applyChanges(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Refait les changements apportes au schema
|
/// Refait les changements apportes au schema
|
||||||
void ChangeBorderCommand::redo() {
|
void ChangeBorderCommand::redo() {
|
||||||
diagram -> border_and_inset.importBorder(new_properties);
|
applyChanges(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -586,7 +579,7 @@ void ChangeBorderCommand::redo() {
|
|||||||
@param parent QUndoCommand parent
|
@param parent QUndoCommand parent
|
||||||
*/
|
*/
|
||||||
ChangeConductorPropertiesCommand::ChangeConductorPropertiesCommand(Conductor *c, QUndoCommand *parent) :
|
ChangeConductorPropertiesCommand::ChangeConductorPropertiesCommand(Conductor *c, QUndoCommand *parent) :
|
||||||
QUndoCommand(QObject::tr("modifier les propri\351t\351s d'un conducteur", "undo caption"), parent),
|
QUndoCommand(QObject::tr("modifier les propri\351t\351s d'un conducteur"), parent),
|
||||||
conductor(c),
|
conductor(c),
|
||||||
old_settings_set(false),
|
old_settings_set(false),
|
||||||
new_settings_set(false)
|
new_settings_set(false)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -22,9 +22,7 @@
|
|||||||
#include "diagramcontent.h"
|
#include "diagramcontent.h"
|
||||||
#include "diagramtextitem.h"
|
#include "diagramtextitem.h"
|
||||||
#include "conductor.h"
|
#include "conductor.h"
|
||||||
#include "borderproperties.h"
|
|
||||||
#include "conductorproperties.h"
|
#include "conductorproperties.h"
|
||||||
#include "insetproperties.h"
|
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
/**
|
/**
|
||||||
Cette classe represente l'action d'ajouter un element au schema
|
Cette classe represente l'action d'ajouter un element au schema
|
||||||
@@ -327,12 +325,16 @@ class ChangeInsetCommand : public QUndoCommand {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Cette classe represente l'action de modifier les dimensions d'un schema
|
Cette classe represente l'action de modifier :
|
||||||
|
-le nombre de colonnes d'un schema
|
||||||
|
-la hauteur des colonnes
|
||||||
|
-la largeur des colonnes
|
||||||
|
-la hauteur des en-tetes des colonnes
|
||||||
*/
|
*/
|
||||||
class ChangeBorderCommand : public QUndoCommand {
|
class ChangeBorderCommand : public QUndoCommand {
|
||||||
// constructeurs, destructeur
|
// constructeurs, destructeur
|
||||||
public:
|
public:
|
||||||
ChangeBorderCommand(Diagram *, const BorderProperties &, const BorderProperties &, QUndoCommand * = 0);
|
ChangeBorderCommand(Diagram *, QUndoCommand * = 0);
|
||||||
virtual ~ChangeBorderCommand();
|
virtual ~ChangeBorderCommand();
|
||||||
private:
|
private:
|
||||||
ChangeBorderCommand(const ChangeBorderCommand &);
|
ChangeBorderCommand(const ChangeBorderCommand &);
|
||||||
@@ -341,16 +343,22 @@ class ChangeBorderCommand : public QUndoCommand {
|
|||||||
public:
|
public:
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
virtual void redo();
|
virtual void redo();
|
||||||
|
private:
|
||||||
|
virtual void applyChanges(int = 1);
|
||||||
|
|
||||||
// attributs
|
// attributs
|
||||||
private:
|
private:
|
||||||
/// schema modifie
|
/// schema modifie
|
||||||
Diagram *diagram;
|
Diagram *diagram;
|
||||||
public:
|
public:
|
||||||
/// anciennes dimensions du schema
|
/// nombre de colonnes ajoutees / enlevees
|
||||||
BorderProperties old_properties;
|
int columnsCountDifference;
|
||||||
/// nouvelles dimensions du schema
|
/// delta pour la hauteur des colonnes
|
||||||
BorderProperties new_properties;
|
qreal columnsHeightDifference;
|
||||||
|
/// delta pour la largeur des colonnes
|
||||||
|
qreal columnsWidthDifference;
|
||||||
|
/// delta pour la hauteur des entetes des colonnes
|
||||||
|
qreal headersHeightDifference;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -119,15 +119,12 @@ QString DiagramContent::sentence(int filter) const {
|
|||||||
@param d Object QDebug a utiliser pour l'affichage des informations de debug
|
@param d Object QDebug a utiliser pour l'affichage des informations de debug
|
||||||
@param c Contenu de schema a debugger
|
@param c Contenu de schema a debugger
|
||||||
*/
|
*/
|
||||||
QDebug &operator<<(QDebug d, DiagramContent &) {
|
QDebug &operator<<(QDebug d, DiagramContent &c) {
|
||||||
d << "DiagramContent {" << "\n";
|
d << "DiagramContent {" << "\n";
|
||||||
/*
|
|
||||||
FIXME Le double-heritage QObject / QGraphicsItem a casse cet operateur
|
|
||||||
d << " elements :" << c.elements << "\n";
|
d << " elements :" << c.elements << "\n";
|
||||||
d << " conductorsToUpdate :" << c.conductorsToUpdate.keys() << "\n";
|
d << " conductorsToUpdate :" << c.conductorsToUpdate.keys() << "\n";
|
||||||
d << " conductorsToMove :" << c.conductorsToMove << "\n";
|
d << " conductorsToMove :" << c.conductorsToMove << "\n";
|
||||||
d << " otherConductors :" << c.otherConductors << "\n";
|
d << " otherConductors :" << c.otherConductors << "\n";
|
||||||
*/
|
|
||||||
d << "}";
|
d << "}";
|
||||||
return(d.space());
|
return(d.space());
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
302
diagramprintdialog.cpp
Normal file
302
diagramprintdialog.cpp
Normal file
@@ -0,0 +1,302 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2007 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "diagramprintdialog.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructeur
|
||||||
|
@param dia Schema a imprimer
|
||||||
|
@param printer Imprimante a utiliser
|
||||||
|
@param parent Widget parent du dialogue
|
||||||
|
*/
|
||||||
|
DiagramPrintDialog::DiagramPrintDialog(Diagram *dia, QWidget *parent) :
|
||||||
|
QWidget(parent),
|
||||||
|
diagram(dia),
|
||||||
|
dialog(0)
|
||||||
|
{
|
||||||
|
// initialise l'imprimante
|
||||||
|
printer = new QPrinter();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Destructeur
|
||||||
|
*/
|
||||||
|
DiagramPrintDialog::~DiagramPrintDialog() {
|
||||||
|
delete dialog;
|
||||||
|
delete printer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Definit le nom du PDF si l'utilisateur choisit une sortie vers un PDF
|
||||||
|
*/
|
||||||
|
void DiagramPrintDialog::setPDFName(const QString &name) {
|
||||||
|
pdf_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return le nom du PDF
|
||||||
|
*/
|
||||||
|
QString DiagramPrintDialog::PDFName() const {
|
||||||
|
return(pdf_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Execute le dialogue d'impression
|
||||||
|
*/
|
||||||
|
void DiagramPrintDialog::exec() {
|
||||||
|
|
||||||
|
// affichage du dialogue d'impression standard
|
||||||
|
QPrintDialog print_dialog(printer);
|
||||||
|
print_dialog.setEnabledOptions(QAbstractPrintDialog::PrintToFile);
|
||||||
|
#ifndef Q_OS_WIN32
|
||||||
|
if (!pdf_name.isEmpty()) printer -> setOutputFileName(pdf_name);
|
||||||
|
#endif
|
||||||
|
if (print_dialog.exec() == QDialog::Rejected) return;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Apres l'execution de ce premier dialogue, on connait le format papier a
|
||||||
|
utiliser, son orientation et on est sur que tout cela est supporte par
|
||||||
|
l'imprimante.
|
||||||
|
On peut donc en deduire le nombre de pages a imprimer
|
||||||
|
*/
|
||||||
|
|
||||||
|
// affichage d'un second dialogue, non standard, pour connaitre les pages a imprimer
|
||||||
|
buildDialog();
|
||||||
|
if (dialog -> exec() == QDialog::Rejected) return;
|
||||||
|
|
||||||
|
// effectue l'impression en elle-meme
|
||||||
|
print();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@param fullPage true pour utiliser toute la feuille dans le calcul
|
||||||
|
@return Le nombre de pages necessaires pour imprimer le schema
|
||||||
|
avec l'orientation et le format papier utilise dans l'imprimante en cours.
|
||||||
|
*/
|
||||||
|
int DiagramPrintDialog::pagesCount(bool fullpage) const {
|
||||||
|
return(horizontalPagesCount(fullpage) * verticalPagesCount(fullpage));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@param fullPage true pour utiliser toute la feuille dans le calcul
|
||||||
|
@return La largeur du "poster" en nombre de pages pour imprimer le schema
|
||||||
|
avec l'orientation et le format papier utilise dans l'imprimante en cours.
|
||||||
|
*/
|
||||||
|
int DiagramPrintDialog::horizontalPagesCount(bool fullpage) const {
|
||||||
|
// note : pageRect et Paper Rect tiennent compte de l'orientation du papier
|
||||||
|
QRect printable_area = fullpage ? printer -> paperRect() : printer -> pageRect();
|
||||||
|
QRect diagram_rect = diagram -> border().toRect();
|
||||||
|
|
||||||
|
int h_pages_count = int(ceil(qreal(diagram_rect.width()) / qreal(printable_area.width())));
|
||||||
|
return(h_pages_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@param fullPage true pour utiliser toute la feuille dans le calcul
|
||||||
|
@return La largeur du "poster" en nombre de pages pour imprimer le schema
|
||||||
|
avec l'orientation et le format papier utilise dans l'imprimante en cours.
|
||||||
|
*/
|
||||||
|
int DiagramPrintDialog::verticalPagesCount(bool fullpage) const {
|
||||||
|
// note : pageRect et Paper Rect tiennent compte de l'orientation du papier
|
||||||
|
QRect printable_area = fullpage ? printer -> paperRect() : printer -> pageRect();
|
||||||
|
QRect diagram_rect = diagram -> border().toRect();
|
||||||
|
|
||||||
|
int v_pages_count = int(ceil(qreal(diagram_rect.height()) / qreal(printable_area.height())));
|
||||||
|
return(v_pages_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Construit un dialogue non standard pour demander les pages a imprimer a l'utilisateur
|
||||||
|
*/
|
||||||
|
void DiagramPrintDialog::buildDialog() {
|
||||||
|
dialog = new QDialog();
|
||||||
|
dialog -> setWindowTitle(tr("Options d'impression"));
|
||||||
|
options_label = new QLabel();
|
||||||
|
use_full_page = new QCheckBox(tr("Utiliser toute la feuille"));
|
||||||
|
fit_diagram_to_page = new QCheckBox(tr("Adapter le sch\351ma \340 la page"));
|
||||||
|
range_from_label = new QLabel(tr("Plage de "));
|
||||||
|
start_page = new QSpinBox();
|
||||||
|
to_label = new QLabel(tr(" \340 "));
|
||||||
|
end_page = new QSpinBox();
|
||||||
|
buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
|
|
||||||
|
QHBoxLayout *pages_layout = new QHBoxLayout();
|
||||||
|
pages_layout -> addWidget(range_from_label);
|
||||||
|
pages_layout -> addWidget(start_page);
|
||||||
|
pages_layout -> addWidget(to_label);
|
||||||
|
pages_layout -> addWidget(end_page);
|
||||||
|
|
||||||
|
QVBoxLayout *dialog_layout = new QVBoxLayout(dialog);
|
||||||
|
dialog_layout -> addWidget(options_label);
|
||||||
|
dialog_layout -> addWidget(use_full_page);
|
||||||
|
dialog_layout -> addWidget(fit_diagram_to_page);
|
||||||
|
dialog_layout -> addLayout(pages_layout);
|
||||||
|
dialog_layout -> addStretch();
|
||||||
|
dialog_layout -> addWidget(buttons);
|
||||||
|
|
||||||
|
connect(use_full_page, SIGNAL(stateChanged(int)), this, SLOT(updateDialog()));
|
||||||
|
connect(fit_diagram_to_page, SIGNAL(stateChanged(int)), this, SLOT(updateDialog()));
|
||||||
|
connect(start_page, SIGNAL(valueChanged(int)), this, SLOT(checkStartPage()));
|
||||||
|
connect(end_page, SIGNAL(valueChanged(int)), this, SLOT(checkEndPage()));
|
||||||
|
connect(buttons, SIGNAL(accepted()), dialog, SLOT(accept()));
|
||||||
|
connect(buttons, SIGNAL(rejected()), dialog, SLOT(reject()));
|
||||||
|
|
||||||
|
updateDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Assure la coherence du dialogue
|
||||||
|
*/
|
||||||
|
void DiagramPrintDialog::updateDialog() {
|
||||||
|
int pages_count;
|
||||||
|
// si on adapte le schema a la page, alors il n'y a qu'une page a imprimer
|
||||||
|
if (fit_diagram_to_page -> isChecked()) {
|
||||||
|
pages_count = 1;
|
||||||
|
} else {
|
||||||
|
pages_count = pagesCount(use_full_page -> isChecked());
|
||||||
|
}
|
||||||
|
options_label -> setText(tr("Nombre total de pages : ") + QString("%1").arg(pages_count));
|
||||||
|
setPagesRangeVisible(pages_count > 1);
|
||||||
|
start_page -> setRange(1, pages_count);
|
||||||
|
end_page -> setRange(1, pages_count);
|
||||||
|
end_page -> setValue(pages_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
S'assure que la premiere page ne soit pas superieure a la derniere page
|
||||||
|
*/
|
||||||
|
void DiagramPrintDialog::checkStartPage() {
|
||||||
|
if (start_page -> value() > end_page -> value()) {
|
||||||
|
start_page -> blockSignals(true);
|
||||||
|
start_page -> setValue(end_page -> value());
|
||||||
|
start_page -> blockSignals(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
S'assure que la derniere page ne soit pas inferieure a la premiere page
|
||||||
|
*/
|
||||||
|
void DiagramPrintDialog::checkEndPage() {
|
||||||
|
if (end_page -> value() < start_page -> value()) {
|
||||||
|
end_page -> blockSignals(true);
|
||||||
|
end_page -> setValue(start_page -> value());
|
||||||
|
end_page -> blockSignals(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@param visible true pour afficher les pages, false sinon
|
||||||
|
*/
|
||||||
|
void DiagramPrintDialog::setPagesRangeVisible(bool visible) {
|
||||||
|
range_from_label -> setVisible(visible);
|
||||||
|
start_page -> setVisible(visible);
|
||||||
|
to_label -> setVisible(visible);
|
||||||
|
end_page -> setVisible(visible);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Effectue l'impression elle-meme
|
||||||
|
*/
|
||||||
|
void DiagramPrintDialog::print() {
|
||||||
|
// recupere les informations collectees dans le second dialogue
|
||||||
|
bool full_page = use_full_page -> isChecked();
|
||||||
|
bool fit_page = fit_diagram_to_page -> isChecked();
|
||||||
|
int first_page = start_page -> value();
|
||||||
|
int last_page = end_page -> value();
|
||||||
|
|
||||||
|
// parametre l'imprimante
|
||||||
|
printer -> setFullPage(full_page);
|
||||||
|
|
||||||
|
// QPainter utiliser pour effectuer le rendu
|
||||||
|
QPainter qp(printer);
|
||||||
|
|
||||||
|
// impression physique (!= fichier PDF)
|
||||||
|
if (printer -> outputFileName().isEmpty()) {
|
||||||
|
// lorsqu'on imprime en paysage sur imprimante reelle, il faut pivoter soi-meme le rendu
|
||||||
|
if (printer -> orientation() == QPrinter::Landscape) {
|
||||||
|
qp.rotate(90.0);
|
||||||
|
qp.translate(0.0, -printer -> pageRect().height());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
diagram -> setDisplayGrid(false);
|
||||||
|
diagram -> setDrawTerminals(false);
|
||||||
|
|
||||||
|
if (fit_page) {
|
||||||
|
// impression adaptee sur une seule page
|
||||||
|
diagram -> render(&qp, QRectF(), diagram -> border(), Qt::KeepAspectRatio);
|
||||||
|
} else {
|
||||||
|
// impression sur une ou plusieurs pages
|
||||||
|
QRect diagram_rect = diagram -> border().toRect();
|
||||||
|
QRect printed_area = full_page ? printer -> paperRect() : printer -> pageRect();
|
||||||
|
int used_width = printed_area.width();
|
||||||
|
int used_height = printed_area.height();
|
||||||
|
int h_pages_count = horizontalPagesCount(full_page);
|
||||||
|
int v_pages_count = verticalPagesCount(full_page);
|
||||||
|
|
||||||
|
QVector< QVector< QRect > > pages_grid;
|
||||||
|
// le schema est imprime sur une matrice de feuilles
|
||||||
|
// parcourt les lignes de la matrice
|
||||||
|
int y_offset = 0;
|
||||||
|
for (int i = 0 ; i < v_pages_count ; ++ i) {
|
||||||
|
pages_grid << QVector< QRect >();
|
||||||
|
|
||||||
|
// parcourt les feuilles de la ligne
|
||||||
|
int x_offset = 0;
|
||||||
|
for (int j = 0 ; j < h_pages_count ; ++ j) {
|
||||||
|
pages_grid.last() << QRect(
|
||||||
|
QPoint(x_offset, y_offset),
|
||||||
|
QSize(
|
||||||
|
qMin(used_width, diagram_rect.width() - x_offset),
|
||||||
|
qMin(used_height, diagram_rect.height() - y_offset)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
x_offset += used_width;
|
||||||
|
}
|
||||||
|
|
||||||
|
y_offset += used_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ne retient que les pages a imprimer
|
||||||
|
QVector<QRect> pages_to_print;
|
||||||
|
for (int i = 0 ; i < v_pages_count ; ++ i) {
|
||||||
|
for (int j = 0 ; j < h_pages_count ; ++ j) {
|
||||||
|
int page_number = (i * h_pages_count) + j + 1;
|
||||||
|
if (page_number >= first_page && page_number <= last_page) {
|
||||||
|
pages_to_print << pages_grid.at(i).at(j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// parcourt les pages pour impression
|
||||||
|
for (int i = 0 ; i < pages_to_print.count() ; ++ i) {
|
||||||
|
QRect current_rect(pages_to_print.at(i));
|
||||||
|
diagram -> render(
|
||||||
|
&qp,
|
||||||
|
QRect(QPoint(0,0), current_rect.size()),
|
||||||
|
current_rect.translated(diagram_rect.topLeft()),
|
||||||
|
Qt::KeepAspectRatio
|
||||||
|
);
|
||||||
|
if (i != pages_to_print.count() - 1) {
|
||||||
|
printer -> newPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
diagram -> setDrawTerminals(true);
|
||||||
|
diagram -> setDisplayGrid(true);
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -14,11 +14,11 @@
|
|||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
#ifndef DIAGRAM_PRINT_DIALOG_H
|
#ifndef DIAGRAM_PRINT_DIALOG_H
|
||||||
#define DIAGRAM_PRINT_DIALOG_H
|
#define DIAGRAM_PRINT_DIALOG_H
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include "qetproject.h"
|
|
||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
/**
|
/**
|
||||||
Cette classe represente le dialogue de configuration de l'impression d'un
|
Cette classe represente le dialogue de configuration de l'impression d'un
|
||||||
@@ -29,55 +29,43 @@ class DiagramPrintDialog : public QWidget {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
// Constructeurs, destructeur
|
// Constructeurs, destructeur
|
||||||
public:
|
public:
|
||||||
DiagramPrintDialog(QETProject *, QWidget * = 0);
|
DiagramPrintDialog(Diagram *, QWidget * = 0);
|
||||||
virtual ~DiagramPrintDialog();
|
virtual ~DiagramPrintDialog();
|
||||||
private:
|
private:
|
||||||
DiagramPrintDialog(const DiagramPrintDialog &);
|
DiagramPrintDialog(const DiagramPrintDialog &);
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
public:
|
public:
|
||||||
void setFileName(const QString &);
|
void setPDFName(const QString &);
|
||||||
QString fileName() const;
|
QString PDFName() const;
|
||||||
void setDocName(const QString &);
|
int pagesCount(bool = false) const;
|
||||||
QString docName() const;
|
int horizontalPagesCount(bool = false) const;
|
||||||
int pagesCount(Diagram *, bool = false) const;
|
int verticalPagesCount(bool = false) const;
|
||||||
int horizontalPagesCount(Diagram *, bool = false) const;
|
|
||||||
int verticalPagesCount(Diagram *, bool = false) const;
|
|
||||||
void exec();
|
void exec();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void buildPrintTypeDialog();
|
|
||||||
void buildDialog();
|
void buildDialog();
|
||||||
|
void print();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void print(const QList<Diagram *> &, bool, QPrinter *);
|
void updateDialog();
|
||||||
void printDiagram(Diagram *, bool, QPainter *, QPrinter * = 0);
|
void checkStartPage();
|
||||||
void updatePrintTypeDialog();
|
void checkEndPage();
|
||||||
void acceptPrintTypeDialog();
|
void setPagesRangeVisible(bool);
|
||||||
void browseFilePrintTypeDialog();
|
|
||||||
|
|
||||||
// attributs
|
// attributs
|
||||||
private:
|
private:
|
||||||
QETProject *project_;
|
Diagram *diagram;
|
||||||
QPrinter *printer_;
|
QPrinter *printer;
|
||||||
QString doc_name_;
|
QString pdf_name;
|
||||||
QString file_name_;
|
QDialog *dialog;
|
||||||
|
QLabel *options_label;
|
||||||
/// Attributs relatifs au 1er dialogue
|
QLabel *range_from_label;
|
||||||
QDialog *dialog_;
|
QLabel *to_label;
|
||||||
QLabel *printtype_label_;
|
QCheckBox *use_full_page;
|
||||||
QGridLayout *glayout0_;
|
QCheckBox *fit_diagram_to_page;
|
||||||
QVBoxLayout *vlayout0_;
|
QSpinBox *start_page;
|
||||||
QHBoxLayout *hlayout0_;
|
QSpinBox *end_page;
|
||||||
QLabel *printer_icon_;
|
QDialogButtonBox *buttons;
|
||||||
QLabel *pdf_icon_;
|
|
||||||
QLabel *ps_icon_;
|
|
||||||
QButtonGroup *printtype_choice_;
|
|
||||||
QRadioButton *printer_choice_;
|
|
||||||
QRadioButton *pdf_choice_;
|
|
||||||
QRadioButton *ps_choice_;
|
|
||||||
QLineEdit *filepath_field_;
|
|
||||||
QPushButton *browse_button_;
|
|
||||||
QDialogButtonBox *buttons_;
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
#include "diagramtextitem.h"
|
#include "diagramtextitem.h"
|
||||||
#include "diagramcommands.h"
|
#include "diagramcommands.h"
|
||||||
#include "qetapp.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@@ -28,7 +27,6 @@ DiagramTextItem::DiagramTextItem(QGraphicsItem *parent, QGraphicsScene *scene) :
|
|||||||
QGraphicsTextItem(parent, scene)
|
QGraphicsTextItem(parent, scene)
|
||||||
{
|
{
|
||||||
setDefaultTextColor(Qt::black);
|
setDefaultTextColor(Qt::black);
|
||||||
setFont(QFont(QETApp::diagramTextsFont(), QETApp::diagramTextsSize()));
|
|
||||||
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
|
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
|
||||||
connect(this, SIGNAL(lostFocus()), this, SLOT(setNonFocusable()));
|
connect(this, SIGNAL(lostFocus()), this, SLOT(setNonFocusable()));
|
||||||
}
|
}
|
||||||
@@ -44,7 +42,6 @@ DiagramTextItem::DiagramTextItem(const QString &text, QGraphicsItem *parent, QGr
|
|||||||
previous_text(text)
|
previous_text(text)
|
||||||
{
|
{
|
||||||
setDefaultTextColor(Qt::black);
|
setDefaultTextColor(Qt::black);
|
||||||
setFont(QFont(QETApp::diagramTextsFont(), QETApp::diagramTextsSize()));
|
|
||||||
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
|
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemIsMovable);
|
||||||
connect(this, SIGNAL(lostFocus()), this, SLOT(setNonFocusable()));
|
connect(this, SIGNAL(lostFocus()), this, SLOT(setNonFocusable()));
|
||||||
}
|
}
|
||||||
@@ -63,10 +60,12 @@ Diagram *DiagramTextItem::diagram() const {
|
|||||||
*/
|
*/
|
||||||
void DiagramTextItem::focusOutEvent(QFocusEvent *e) {
|
void DiagramTextItem::focusOutEvent(QFocusEvent *e) {
|
||||||
QGraphicsTextItem::focusOutEvent(e);
|
QGraphicsTextItem::focusOutEvent(e);
|
||||||
// signale la modification du texte si besoin
|
// si le texte a ete modifie
|
||||||
if (toPlainText() != previous_text) {
|
if (toPlainText() != previous_text) {
|
||||||
emit(diagramTextChanged(this, previous_text, toPlainText()));
|
if (Diagram *dia = diagram()) {
|
||||||
previous_text = toPlainText();
|
dia -> undoStack().push(new ChangeDiagramTextCommand(this, previous_text, toPlainText()));
|
||||||
|
previous_text = toPlainText();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// deselectionne le texte
|
// deselectionne le texte
|
||||||
@@ -99,8 +98,8 @@ void DiagramTextItem::fromXml(const QDomElement &e) {
|
|||||||
*/
|
*/
|
||||||
QDomElement DiagramTextItem::toXml(QDomDocument &document) const {
|
QDomElement DiagramTextItem::toXml(QDomDocument &document) const {
|
||||||
QDomElement result = document.createElement("input");
|
QDomElement result = document.createElement("input");
|
||||||
result.setAttribute("x", QString("%1").arg(pos().x()));
|
result.setAttribute("x", pos().x());
|
||||||
result.setAttribute("y", QString("%1").arg(pos().y()));
|
result.setAttribute("y", pos().y());
|
||||||
result.setAttribute("text", toPlainText());
|
result.setAttribute("text", toPlainText());
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
@@ -131,16 +130,6 @@ void DiagramTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Gere le clic sur le champ de texte
|
|
||||||
*/
|
|
||||||
void DiagramTextItem::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
|
||||||
if (e -> modifiers() & Qt::ControlModifier) {
|
|
||||||
setSelected(!isSelected());
|
|
||||||
}
|
|
||||||
QGraphicsTextItem::mousePressEvent(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Gere les mouvements de souris lies au champ de texte
|
Gere les mouvements de souris lies au champ de texte
|
||||||
*/
|
*/
|
||||||
@@ -175,9 +164,7 @@ void DiagramTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
}
|
}
|
||||||
diagram_ptr -> invalidateMovedElements();
|
diagram_ptr -> invalidateMovedElements();
|
||||||
}
|
}
|
||||||
if (!(e -> modifiers() & Qt::ControlModifier)) {
|
QGraphicsTextItem::mouseReleaseEvent(e);
|
||||||
QGraphicsTextItem::mouseReleaseEvent(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -52,7 +52,6 @@ class DiagramTextItem : public QGraphicsTextItem {
|
|||||||
protected:
|
protected:
|
||||||
virtual void focusOutEvent(QFocusEvent *);
|
virtual void focusOutEvent(QFocusEvent *);
|
||||||
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *);
|
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *);
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
|
|
||||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
||||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
||||||
|
|
||||||
@@ -60,8 +59,6 @@ class DiagramTextItem : public QGraphicsTextItem {
|
|||||||
signals:
|
signals:
|
||||||
/// signal emis lorsque le champ de texte perd le focus
|
/// signal emis lorsque le champ de texte perd le focus
|
||||||
void lostFocus();
|
void lostFocus();
|
||||||
/// signal emis lorsque le champ de texte a ete modifie
|
|
||||||
void diagramTextChanged(DiagramTextItem *, const QString &, const QString &);
|
|
||||||
|
|
||||||
// slots
|
// slots
|
||||||
public slots:
|
public slots:
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -18,53 +18,45 @@
|
|||||||
#include "diagramview.h"
|
#include "diagramview.h"
|
||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
#include "customelement.h"
|
#include "customelement.h"
|
||||||
|
#include "exportdialog.h"
|
||||||
|
#include "diagramprintdialog.h"
|
||||||
#include "conductor.h"
|
#include "conductor.h"
|
||||||
#include "diagramcommands.h"
|
#include "diagramcommands.h"
|
||||||
#include "conductorpropertieswidget.h"
|
#include "conductorpropertieswidget.h"
|
||||||
#include "insetpropertieswidget.h"
|
#include "insetpropertieswidget.h"
|
||||||
#include "qetapp.h"
|
|
||||||
#include "qetproject.h"
|
|
||||||
#include "borderpropertieswidget.h"
|
|
||||||
#include "integrationmoveelementshandler.h"
|
|
||||||
#include "qetdiagrameditor.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@param parent Le QWidget parent de cette vue de schema
|
@param parent Le QWidegt parent de cette vue de schema
|
||||||
*/
|
*/
|
||||||
DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : QGraphicsView(parent), is_adding_text(false) {
|
DiagramView::DiagramView(QWidget *parent) : QGraphicsView(parent), is_adding_text(false) {
|
||||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
|
||||||
setInteractive(true);
|
setInteractive(true);
|
||||||
setCacheMode(QGraphicsView::CacheBackground);
|
setCacheMode(QGraphicsView::CacheBackground);
|
||||||
|
setOptimizationFlags(QGraphicsView::DontSavePainterState|QGraphicsView::DontAdjustForAntialiasing);
|
||||||
|
|
||||||
// active l'antialiasing
|
// active l'antialiasing
|
||||||
setRenderHint(QPainter::Antialiasing, true);
|
setRenderHint(QPainter::Antialiasing, true);
|
||||||
setRenderHint(QPainter::TextAntialiasing, true);
|
setRenderHint(QPainter::TextAntialiasing, true);
|
||||||
setRenderHint(QPainter::SmoothPixmapTransform, true);
|
setRenderHint(QPainter::SmoothPixmapTransform, true);
|
||||||
|
|
||||||
scene = diagram ? diagram : new Diagram(this);
|
setScene(scene = new Diagram(this));
|
||||||
setScene(scene);
|
|
||||||
scene -> undoStack().setClean();
|
scene -> undoStack().setClean();
|
||||||
|
setDragMode(RubberBandDrag);
|
||||||
|
setAcceptDrops(true);
|
||||||
setWindowIcon(QIcon(":/ico/qet-16.png"));
|
setWindowIcon(QIcon(":/ico/qet-16.png"));
|
||||||
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||||
setResizeAnchor(QGraphicsView::AnchorUnderMouse);
|
setResizeAnchor(QGraphicsView::AnchorUnderMouse);
|
||||||
setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||||
setSelectionMode();
|
|
||||||
adjustSceneRect();
|
adjustSceneRect();
|
||||||
updateWindowTitle();
|
updateWindowTitle();
|
||||||
|
|
||||||
context_menu = new QMenu(this);
|
context_menu = new QMenu(this);
|
||||||
paste_here = new QAction(QIcon(":/ico/paste.png"), tr("Coller ici", "context menu action"), this);
|
paste_here = new QAction(QIcon(":/ico/paste.png"), tr("Coller ici"), this);
|
||||||
connect(paste_here, SIGNAL(triggered()), this, SLOT(pasteHere()));
|
connect(paste_here, SIGNAL(triggered()), this, SLOT(pasteHere()));
|
||||||
|
|
||||||
connect(scene, SIGNAL(selectionEmptinessChanged()), this, SIGNAL(selectionChanged()));
|
connect(scene, SIGNAL(selectionEmptinessChanged()), this, SIGNAL(selectionChanged()));
|
||||||
connect(scene, SIGNAL(readOnlyChanged(bool)), this, SLOT(applyReadOnly()));
|
|
||||||
connect(&(scene -> border_and_inset), SIGNAL(borderChanged(QRectF, QRectF)), this, SLOT(adjustSceneRect()));
|
connect(&(scene -> border_and_inset), SIGNAL(borderChanged(QRectF, QRectF)), this, SLOT(adjustSceneRect()));
|
||||||
connect(&(scene -> border_and_inset), SIGNAL(displayChanged()), this, SLOT(adjustSceneRect()));
|
|
||||||
connect(&(scene -> border_and_inset), SIGNAL(diagramTitleChanged(const QString &)), this, SLOT(updateWindowTitle()));
|
|
||||||
connect(&(scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(updateWindowTitle()));
|
connect(&(scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(updateWindowTitle()));
|
||||||
|
|
||||||
connect(this, SIGNAL(aboutToAddElement()), this, SLOT(addDroppedElement()), Qt::QueuedConnection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,7 +66,7 @@ DiagramView::~DiagramView() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Appelle la methode select sur tous les elements de la liste d'elements
|
appelle la methode select sur tous les elements de la liste d'elements
|
||||||
*/
|
*/
|
||||||
void DiagramView::selectAll() {
|
void DiagramView::selectAll() {
|
||||||
if (scene -> items().isEmpty()) return;
|
if (scene -> items().isEmpty()) return;
|
||||||
@@ -103,7 +95,6 @@ void DiagramView::selectInvert() {
|
|||||||
Supprime les composants selectionnes
|
Supprime les composants selectionnes
|
||||||
*/
|
*/
|
||||||
void DiagramView::deleteSelection() {
|
void DiagramView::deleteSelection() {
|
||||||
if (scene -> isReadOnly()) return;
|
|
||||||
DiagramContent removed_content = scene -> selectedContent();
|
DiagramContent removed_content = scene -> selectedContent();
|
||||||
scene -> clearSelection();
|
scene -> clearSelection();
|
||||||
scene -> undoStack().push(new DeleteElementsCommand(scene, removed_content));
|
scene -> undoStack().push(new DeleteElementsCommand(scene, removed_content));
|
||||||
@@ -114,7 +105,6 @@ void DiagramView::deleteSelection() {
|
|||||||
Pivote les composants selectionnes
|
Pivote les composants selectionnes
|
||||||
*/
|
*/
|
||||||
void DiagramView::rotateSelection() {
|
void DiagramView::rotateSelection() {
|
||||||
if (scene -> isReadOnly()) return;
|
|
||||||
QHash<Element *, QET::Orientation> elements_to_rotate;
|
QHash<Element *, QET::Orientation> elements_to_rotate;
|
||||||
foreach (QGraphicsItem *item, scene -> selectedItems()) {
|
foreach (QGraphicsItem *item, scene -> selectedItems()) {
|
||||||
if (Element *e = qgraphicsitem_cast<Element *>(item)) {
|
if (Element *e = qgraphicsitem_cast<Element *>(item)) {
|
||||||
@@ -126,26 +116,23 @@ void DiagramView::rotateSelection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Accepte ou refuse le drag'n drop en fonction du type de donnees entrant
|
accepte ou refuse le drag'n drop en fonction du type de donnees entrant
|
||||||
@param e le QDragEnterEvent correspondant au drag'n drop tente
|
@param e le QDragEnterEvent correspondant au drag'n drop tente
|
||||||
*/
|
*/
|
||||||
void DiagramView::dragEnterEvent(QDragEnterEvent *e) {
|
void DiagramView::dragEnterEvent(QDragEnterEvent *e) {
|
||||||
if (e -> mimeData() -> hasFormat("application/x-qet-element-uri")) {
|
if (e -> mimeData() -> hasFormat("text/plain")) e -> acceptProposedAction();
|
||||||
e -> acceptProposedAction();
|
else e-> ignore();
|
||||||
} else {
|
|
||||||
e -> ignore();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Gere les dragleaveevent
|
gere les dragleaveevent
|
||||||
@param e le QDragEnterEvent correspondant au drag'n drop sortant
|
@param e le QDragEnterEvent correspondant au drag'n drop sortant
|
||||||
*/
|
*/
|
||||||
void DiagramView::dragLeaveEvent(QDragLeaveEvent *) {
|
void DiagramView::dragLeaveEvent(QDragLeaveEvent *) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Accepte ou refuse le drag'n drop en fonction du type de donnees entrant
|
accepte ou refuse le drag'n drop en fonction du type de donnees entrant
|
||||||
@param e le QDragMoveEvent correspondant au drag'n drop tente
|
@param e le QDragMoveEvent correspondant au drag'n drop tente
|
||||||
*/
|
*/
|
||||||
void DiagramView::dragMoveEvent(QDragMoveEvent *e) {
|
void DiagramView::dragMoveEvent(QDragMoveEvent *e) {
|
||||||
@@ -154,23 +141,18 @@ void DiagramView::dragMoveEvent(QDragMoveEvent *e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Gere les depots (drop) acceptes sur le schema. Cette methode emet le signal
|
gere les depots (drop) acceptes sur le Diagram
|
||||||
aboutToAddElement si l'element depose est accessible.
|
|
||||||
@param e le QDropEvent correspondant au drag'n drop effectue
|
@param e le QDropEvent correspondant au drag'n drop effectue
|
||||||
*/
|
*/
|
||||||
void DiagramView::dropEvent(QDropEvent *e) {
|
void DiagramView::dropEvent(QDropEvent *e) {
|
||||||
// recupere l'emplacement de l'element depuis le drag'n drop
|
QString fichier = e -> mimeData() -> text();
|
||||||
QString elmt_path = e -> mimeData() -> text();
|
int etat;
|
||||||
ElementsLocation location(ElementsLocation::locationFromString(elmt_path));
|
Element *el = new CustomElement(fichier, 0, 0, &etat);
|
||||||
|
if (etat) delete el;
|
||||||
// verifie qu'il existe un element correspondant a cet emplacement
|
else {
|
||||||
ElementsCollectionItem *dropped_item = QETApp::collectionItem(location);
|
diagram() -> undoStack().push(new AddElementCommand(diagram(), el, mapToScene(e -> pos())));
|
||||||
if (!dropped_item) return;
|
adjustSceneRect();
|
||||||
|
}
|
||||||
next_location_ = location;
|
|
||||||
next_position_ = e-> pos();
|
|
||||||
|
|
||||||
emit(aboutToAddElement());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,7 +160,6 @@ void DiagramView::dropEvent(QDropEvent *e) {
|
|||||||
*/
|
*/
|
||||||
void DiagramView::setVisualisationMode() {
|
void DiagramView::setVisualisationMode() {
|
||||||
setDragMode(ScrollHandDrag);
|
setDragMode(ScrollHandDrag);
|
||||||
applyReadOnly();
|
|
||||||
setInteractive(false);
|
setInteractive(false);
|
||||||
emit(modeChanged());
|
emit(modeChanged());
|
||||||
}
|
}
|
||||||
@@ -189,7 +170,6 @@ void DiagramView::setVisualisationMode() {
|
|||||||
void DiagramView::setSelectionMode() {
|
void DiagramView::setSelectionMode() {
|
||||||
setDragMode(RubberBandDrag);
|
setDragMode(RubberBandDrag);
|
||||||
setInteractive(true);
|
setInteractive(true);
|
||||||
applyReadOnly();
|
|
||||||
emit(modeChanged());
|
emit(modeChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +209,7 @@ void DiagramView::zoomReset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Copie les elements selectionnes du schema dans le presse-papier puis les supprime
|
copie les elements selectionnes du schema dans le presse-papier puis les supprime
|
||||||
*/
|
*/
|
||||||
void DiagramView::cut() {
|
void DiagramView::cut() {
|
||||||
copy();
|
copy();
|
||||||
@@ -239,7 +219,7 @@ void DiagramView::cut() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Copie les elements selectionnes du schema dans le presse-papier
|
copie les elements selectionnes du schema dans le presse-papier
|
||||||
*/
|
*/
|
||||||
void DiagramView::copy() {
|
void DiagramView::copy() {
|
||||||
QClipboard *presse_papier = QApplication::clipboard();
|
QClipboard *presse_papier = QApplication::clipboard();
|
||||||
@@ -255,8 +235,6 @@ void DiagramView::copy() {
|
|||||||
@param clipboard_mode Type de presse-papier a prendre en compte
|
@param clipboard_mode Type de presse-papier a prendre en compte
|
||||||
*/
|
*/
|
||||||
void DiagramView::paste(const QPointF &pos, QClipboard::Mode clipboard_mode) {
|
void DiagramView::paste(const QPointF &pos, QClipboard::Mode clipboard_mode) {
|
||||||
if (scene -> isReadOnly()) return;
|
|
||||||
|
|
||||||
QString texte_presse_papier = QApplication::clipboard() -> text(clipboard_mode);
|
QString texte_presse_papier = QApplication::clipboard() -> text(clipboard_mode);
|
||||||
if ((texte_presse_papier).isEmpty()) return;
|
if ((texte_presse_papier).isEmpty()) return;
|
||||||
|
|
||||||
@@ -281,22 +259,220 @@ void DiagramView::pasteHere() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Gere les clics et plus particulierement :
|
gere les clics et plus particulierement le clic du milieu (= coller pour X11)
|
||||||
* le clic du milieu (= coller pour X11)
|
|
||||||
* le clic pour ajouter un champ de texte independant
|
|
||||||
*/
|
*/
|
||||||
void DiagramView::mousePressEvent(QMouseEvent *e) {
|
void DiagramView::mousePressEvent(QMouseEvent *e) {
|
||||||
if (e -> buttons() == Qt::MidButton) {
|
if (e -> buttons() == Qt::MidButton) {
|
||||||
paste(mapToScene(e -> pos()), QClipboard::Selection);
|
paste(mapToScene(e -> pos()), QClipboard::Selection);
|
||||||
} else {
|
} else {
|
||||||
if (!scene -> isReadOnly() && is_adding_text && e -> buttons() == Qt::LeftButton) {
|
if (is_adding_text && e -> buttons() == Qt::LeftButton) {
|
||||||
addDiagramTextAtPos(mapToScene(e -> pos()));
|
DiagramTextItem *dti = new DiagramTextItem();
|
||||||
|
dti -> setPlainText("_");
|
||||||
|
dti -> previous_text = "_";
|
||||||
|
scene -> undoStack().push(new AddTextCommand(scene, dti, e -> pos()));
|
||||||
|
adjustSceneRect();
|
||||||
is_adding_text = false;
|
is_adding_text = false;
|
||||||
|
emit(textAdded(false));
|
||||||
}
|
}
|
||||||
QGraphicsView::mousePressEvent(e);
|
QGraphicsView::mousePressEvent(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Ouvre un fichier *.qet dans cette DiagramView
|
||||||
|
@param n_fichier Nom du fichier a ouvrir
|
||||||
|
@param erreur Si le pointeur est specifie, cet entier est mis a 0 en cas de reussite de l'ouverture, 1 si le fichier n'existe pas, 2 si le fichier n'est pas lisible, 3 si le fichier n'est pas un element XML, 4 si l'ouverture du fichier a echoue pour une autre raison (c'est pas ca qui manque ^^)
|
||||||
|
@return true si l'ouverture a reussi, false sinon
|
||||||
|
*/
|
||||||
|
bool DiagramView::open(QString n_fichier, int *erreur) {
|
||||||
|
// verifie l'existence du fichier
|
||||||
|
if (!QFileInfo(n_fichier).exists()) {
|
||||||
|
if (erreur != NULL) *erreur = 1;
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ouvre le fichier
|
||||||
|
QFile fichier(n_fichier);
|
||||||
|
if (!fichier.open(QIODevice::ReadOnly)) {
|
||||||
|
if (erreur != NULL) *erreur = 2;
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// lit son contenu dans un QDomDocument
|
||||||
|
QDomDocument document;
|
||||||
|
if (!document.setContent(&fichier)) {
|
||||||
|
if (erreur != NULL) *erreur = 3;
|
||||||
|
fichier.close();
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
fichier.close();
|
||||||
|
|
||||||
|
/**
|
||||||
|
La notion de projet (ensemble de documents [schemas, nomenclatures,
|
||||||
|
...] et d'elements) n'est pas encore geree.
|
||||||
|
Toutefois, pour gerer au mieux la transition de la 0.1 a la 0.2,
|
||||||
|
les schemas enregistres (element XML "diagram") sont integres dans un
|
||||||
|
pseudo projet (element XML "project").
|
||||||
|
S'il y a plusieurs schemas dans un projet, tous les schemas seront
|
||||||
|
ouverts comme etant des fichiers separes
|
||||||
|
*/
|
||||||
|
// repere les schemas dans le fichier
|
||||||
|
QDomElement root = document.documentElement();
|
||||||
|
// cas 1 : l'element racine est un "diagram" : un seul schema, pas de probleme
|
||||||
|
if (root.tagName() == "diagram") {
|
||||||
|
// construit le schema a partir du QDomDocument
|
||||||
|
QDomDocument &doc = document;
|
||||||
|
if (scene -> fromXml(doc)) {
|
||||||
|
if (erreur != NULL) *erreur = 0;
|
||||||
|
file_name = n_fichier;
|
||||||
|
scene -> undoStack().setClean();
|
||||||
|
updateWindowTitle();
|
||||||
|
return(true);
|
||||||
|
} else {
|
||||||
|
if (erreur != NULL) *erreur = 4;
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
// cas 2 : l'element racine est un "project"
|
||||||
|
} else if (root.tagName() == "project") {
|
||||||
|
// verifie basiquement que la version actuelle est capable de lire ce fichier
|
||||||
|
if (root.hasAttribute("version")) {
|
||||||
|
bool conv_ok;
|
||||||
|
qreal diagram_version = root.attribute("version").toDouble(&conv_ok);
|
||||||
|
if (conv_ok && QET::version.toDouble() < diagram_version) {
|
||||||
|
QMessageBox::warning(
|
||||||
|
0,
|
||||||
|
tr("Avertissement"),
|
||||||
|
tr("Ce document semble avoir \351t\351 enregistr\351 avec une "
|
||||||
|
"version ult\351rieure de QElectroTech. Il est possible que "
|
||||||
|
"l'ouverture de tout ou partie de ce document \351choue.")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// compte le nombre de schemas dans le projet
|
||||||
|
QList<QDomElement> diagrams;
|
||||||
|
|
||||||
|
QDomNodeList diagram_nodes = root.elementsByTagName("diagram");
|
||||||
|
for (uint i = 0 ; i < diagram_nodes.length() ; ++ i) {
|
||||||
|
if (diagram_nodes.at(i).isElement()) {
|
||||||
|
diagrams << diagram_nodes.at(i).toElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// il n'y aucun schema la-dedans
|
||||||
|
if (!diagrams.count()) {
|
||||||
|
if (erreur != NULL) *erreur = 4;
|
||||||
|
return(false);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
bool keep_doc_name = diagrams.count() == 1;
|
||||||
|
bool current_dv_loaded = false;
|
||||||
|
for (int i = 0 ; i < diagrams.count() ; ++ i) {
|
||||||
|
// cree un QDomDocument representant le schema
|
||||||
|
QDomDocument diagram_doc;
|
||||||
|
diagram_doc.appendChild(diagram_doc.importNode(diagrams[i], true));
|
||||||
|
|
||||||
|
// charge le premier schema valide et cree de nouveau DiagramView pour les suivants
|
||||||
|
if (!current_dv_loaded) {
|
||||||
|
if (scene -> fromXml(diagram_doc)) {
|
||||||
|
if (keep_doc_name) file_name = n_fichier;
|
||||||
|
scene -> undoStack().setClean();
|
||||||
|
updateWindowTitle();
|
||||||
|
current_dv_loaded = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DiagramView *new_dv = new DiagramView(parentWidget());
|
||||||
|
if (new_dv -> scene -> fromXml(diagram_doc)) {
|
||||||
|
if (keep_doc_name) new_dv -> file_name = n_fichier;
|
||||||
|
new_dv -> scene -> undoStack().setClean();
|
||||||
|
new_dv -> updateWindowTitle();
|
||||||
|
diagramEditor() -> addDiagramView(new_dv);
|
||||||
|
} else {
|
||||||
|
delete(new_dv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (erreur != NULL) *erreur = 4;
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Gere la fermeture du schema.
|
||||||
|
@param event Le QCloseEvent decrivant l'evenement
|
||||||
|
*/
|
||||||
|
void DiagramView::closeEvent(QCloseEvent *event) {
|
||||||
|
bool retour;
|
||||||
|
// si le schema est modifie
|
||||||
|
if (!isWindowModified()) {
|
||||||
|
retour = true;
|
||||||
|
} else {
|
||||||
|
// demande d'abord a l'utilisateur s'il veut enregistrer le schema en cours
|
||||||
|
QMessageBox::StandardButton reponse = QMessageBox::question(
|
||||||
|
this,
|
||||||
|
tr("Enregistrer le sch\351ma en cours ?"),
|
||||||
|
tr("Voulez-vous enregistrer le sch\351ma ") + windowTitle() + tr(" ?"),
|
||||||
|
QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel,
|
||||||
|
QMessageBox::Cancel
|
||||||
|
);
|
||||||
|
switch(reponse) {
|
||||||
|
case QMessageBox::Cancel: retour = false; break; // l'utilisateur annule : echec de la fermeture
|
||||||
|
case QMessageBox::Yes: retour = save(); break; // l'utilisateur dit oui : la reussite depend de l'enregistrement
|
||||||
|
default: retour = true; // l'utilisateur dit non ou ferme le dialogue: c'est reussi
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (retour) {
|
||||||
|
event -> accept();
|
||||||
|
delete this;
|
||||||
|
} else event -> ignore();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Methode enregistrant le schema dans le dernier nom de fichier connu.
|
||||||
|
Si aucun nom de fichier n'est connu, cette methode appelle la methode saveAs
|
||||||
|
@return true si l'enregistrement a reussi, false sinon
|
||||||
|
*/
|
||||||
|
bool DiagramView::save() {
|
||||||
|
if (file_name.isEmpty()) return(saveAs());
|
||||||
|
else return(saveDiagramToFile(file_name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Cette methode demande un nom de fichier a l'utilisateur pour enregistrer le schema
|
||||||
|
Si aucun nom n'est entre, elle renvoie faux.
|
||||||
|
Si le nom ne se termine pas par l'extension .qet, celle-ci est ajoutee.
|
||||||
|
Si l'enregistrement reussit, le nom du fichier est conserve et la fonction renvoie true.
|
||||||
|
Sinon, faux est renvoye.
|
||||||
|
@return true si l'enregistrement a reussi, false sinon
|
||||||
|
*/
|
||||||
|
bool DiagramView::saveAs() {
|
||||||
|
// demande un nom de fichier a l'utilisateur pour enregistrer le schema
|
||||||
|
QString n_fichier = QFileDialog::getSaveFileName(
|
||||||
|
this,
|
||||||
|
tr("Enregistrer sous"),
|
||||||
|
(file_name.isEmpty() ? QDir::homePath() : QDir(file_name)).absolutePath(),
|
||||||
|
tr("Sch\351ma QElectroTech (*.qet)")
|
||||||
|
);
|
||||||
|
// si aucun nom n'est entre, renvoie faux.
|
||||||
|
if (n_fichier.isEmpty()) return(false);
|
||||||
|
// si le nom ne se termine pas par l'extension .qet, celle-ci est ajoutee
|
||||||
|
if (!n_fichier.endsWith(".qet", Qt::CaseInsensitive)) n_fichier += ".qet";
|
||||||
|
// tente d'enregistrer le fichier
|
||||||
|
bool resultat_enregistrement = saveDiagramToFile(n_fichier);
|
||||||
|
// si l'enregistrement reussit, le nom du fichier est conserve
|
||||||
|
if (resultat_enregistrement) {
|
||||||
|
file_name = n_fichier;
|
||||||
|
updateWindowTitle();
|
||||||
|
}
|
||||||
|
// retourne un booleen representatif de la reussite de l'enregistrement
|
||||||
|
return(resultat_enregistrement);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Gere les actions liees a la rollette de la souris
|
Gere les actions liees a la rollette de la souris
|
||||||
@param e QWheelEvent decrivant l'evenement rollette
|
@param e QWheelEvent decrivant l'evenement rollette
|
||||||
@@ -315,39 +491,113 @@ void DiagramView::wheelEvent(QWheelEvent *e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return le titre de cette vue ; cela correspond au titre du schema
|
Methode privee gerant l'enregistrement du fichier XML. S'il n'est pas possible
|
||||||
visualise precede de la mention "Schema". Si le titre du schema est vide,
|
d'ecrire dans le fichier, cette fonction affiche un message d'erreur et renvoie false.
|
||||||
la mention "Schema sans titre" est utilisee
|
Autrement, elle renvoie true.
|
||||||
@see Diagram::title()
|
@param n_fichier Nom du fichier dans lequel l'arbre XML doit etre ecrit
|
||||||
|
@return true si l'enregistrement a reussi, false sinon
|
||||||
*/
|
*/
|
||||||
QString DiagramView::title() const {
|
bool DiagramView::saveDiagramToFile(QString &n_fichier) {
|
||||||
QString view_title;
|
QFile fichier(n_fichier);
|
||||||
QString diagram_title(scene -> title());
|
if (!fichier.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
if (diagram_title.isEmpty()) {
|
QMessageBox::warning(this, tr("Erreur"), tr("Impossible d'ecrire dans ce fichier"));
|
||||||
view_title = tr("Sch\351ma sans titre");
|
return(false);
|
||||||
} else {
|
|
||||||
view_title = QString(tr("Sch\351ma %1", "%1 is a diagram title")).arg(diagram_title);
|
|
||||||
}
|
}
|
||||||
return(view_title);
|
QTextStream out(&fichier);
|
||||||
|
out.setCodec("UTF-8");
|
||||||
|
|
||||||
|
// l'export XML du schema est encapsule dans un pseudo-projet
|
||||||
|
QDomDocument final_document;
|
||||||
|
QDomElement project_root = final_document.createElement("project");
|
||||||
|
project_root.setAttribute("version", QET::version);
|
||||||
|
project_root.appendChild(final_document.importNode(scene -> toXml().documentElement(), true));
|
||||||
|
final_document.appendChild(project_root);
|
||||||
|
|
||||||
|
out << final_document.toString(4);
|
||||||
|
fichier.close();
|
||||||
|
scene -> undoStack().setClean();
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Exporte le schema.
|
||||||
|
*/
|
||||||
|
void DiagramView::dialogExport() {
|
||||||
|
ExportDialog ed(scene, this);
|
||||||
|
ed.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Imprime le schema.
|
||||||
|
*/
|
||||||
|
void DiagramView::dialogPrint() {
|
||||||
|
|
||||||
|
// determine un nom possible pour le pdf
|
||||||
|
QString pdf_file_name;
|
||||||
|
if (!file_name.isEmpty()) {
|
||||||
|
pdf_file_name = file_name;
|
||||||
|
pdf_file_name.replace(QRegExp("\\.qet$", Qt::CaseInsensitive), "");
|
||||||
|
} else {
|
||||||
|
pdf_file_name = QDir::homePath() + tr("schema");
|
||||||
|
}
|
||||||
|
pdf_file_name += ".pdf";
|
||||||
|
|
||||||
|
DiagramPrintDialog print_dialog(scene, this);
|
||||||
|
print_dialog.setPDFName(pdf_file_name);
|
||||||
|
print_dialog.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Edite les informations du schema.
|
Edite les informations du schema.
|
||||||
*/
|
*/
|
||||||
void DiagramView::editDiagramProperties() {
|
void DiagramView::dialogEditInfos() {
|
||||||
if (scene -> isReadOnly()) return;
|
// recupere le cartouche du schema
|
||||||
|
InsetProperties inset = scene -> border_and_inset.exportInset();
|
||||||
|
|
||||||
// recupere le cartouche et les dimensions du schema
|
// recupere les dimensions du schema
|
||||||
InsetProperties inset = scene -> border_and_inset.exportInset();
|
int columns_count_value = scene -> border_and_inset.nbColumn();
|
||||||
BorderProperties border = scene -> border_and_inset.exportBorder();
|
int columns_width_value = qRound(scene -> border_and_inset.columnsWidth());
|
||||||
|
int columns_height_value = qRound(scene -> border_and_inset.columnsHeight());
|
||||||
|
|
||||||
// construit le dialogue
|
// construit le dialogue
|
||||||
QDialog popup(diagramEditor());
|
QDialog popup;
|
||||||
popup.setMinimumWidth(400);
|
popup.setMinimumWidth(400);
|
||||||
popup.setWindowTitle(tr("Propri\351t\351s du sch\351ma", "window title"));
|
popup.setWindowTitle(tr("Propri\351t\351s du sch\351ma"));
|
||||||
|
|
||||||
BorderPropertiesWidget *border_infos = new BorderPropertiesWidget(border, &popup);
|
QGroupBox *diagram_size_box = new QGroupBox(tr("Dimensions du sch\351ma"), &popup);
|
||||||
InsetPropertiesWidget *inset_infos = new InsetPropertiesWidget(inset, false, &popup);
|
QGridLayout diagram_size_box_layout(diagram_size_box);
|
||||||
|
|
||||||
|
QLabel *ds1 = new QLabel(tr("Colonnes :"));
|
||||||
|
|
||||||
|
QSpinBox *columns_count = new QSpinBox(diagram_size_box);
|
||||||
|
columns_count -> setMinimum(scene -> border_and_inset.minNbColumns());
|
||||||
|
columns_count -> setValue(columns_count_value);
|
||||||
|
|
||||||
|
QSpinBox *columns_width = new QSpinBox(diagram_size_box);
|
||||||
|
columns_width -> setMinimum(1);
|
||||||
|
columns_width -> setSingleStep(10);
|
||||||
|
columns_width -> setValue(columns_width_value);
|
||||||
|
columns_width -> setPrefix(tr("\327"));
|
||||||
|
columns_width -> setSuffix(tr("px"));
|
||||||
|
|
||||||
|
QLabel *ds2 = new QLabel(tr("Hauteur :"));
|
||||||
|
|
||||||
|
QSpinBox *columns_height = new QSpinBox(diagram_size_box);
|
||||||
|
columns_height -> setRange(qRound(scene -> border_and_inset.minColumnsHeight()), 10000);
|
||||||
|
columns_height -> setSingleStep(80);
|
||||||
|
columns_height -> setValue(columns_height_value);
|
||||||
|
|
||||||
|
diagram_size_box_layout.addWidget(ds1, 0, 0);
|
||||||
|
diagram_size_box_layout.addWidget(columns_count, 0, 1);
|
||||||
|
diagram_size_box_layout.addWidget(columns_width, 0, 2);
|
||||||
|
diagram_size_box_layout.addWidget(ds2, 1, 0);
|
||||||
|
diagram_size_box_layout.addWidget(columns_height, 1, 1);
|
||||||
|
diagram_size_box_layout.setColumnStretch(0, 1);
|
||||||
|
diagram_size_box_layout.setColumnStretch(1, 1);
|
||||||
|
diagram_size_box_layout.setColumnStretch(2, 1);
|
||||||
|
diagram_size_box_layout.setColumnStretch(3, 500);
|
||||||
|
|
||||||
|
InsetPropertiesWidget *inset_infos = new InsetPropertiesWidget(inset, false, &popup);
|
||||||
|
|
||||||
// boutons
|
// boutons
|
||||||
QDialogButtonBox boutons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
QDialogButtonBox boutons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
@@ -356,22 +606,30 @@ void DiagramView::editDiagramProperties() {
|
|||||||
|
|
||||||
// ajout dans une disposition verticale
|
// ajout dans une disposition verticale
|
||||||
QVBoxLayout layout_v(&popup);
|
QVBoxLayout layout_v(&popup);
|
||||||
layout_v.addWidget(border_infos);
|
layout_v.addWidget(diagram_size_box);
|
||||||
layout_v.addWidget(inset_infos);
|
layout_v.addWidget(inset_infos);
|
||||||
layout_v.addStretch();
|
layout_v.addStretch();
|
||||||
layout_v.addWidget(&boutons);
|
layout_v.addWidget(&boutons);
|
||||||
// si le dialogue est accepte
|
// si le dialogue est accepte
|
||||||
if (popup.exec() == QDialog::Accepted) {
|
if (popup.exec() == QDialog::Accepted) {
|
||||||
InsetProperties new_inset = inset_infos -> insetProperties();
|
InsetProperties new_inset = inset_infos -> insetProperties();
|
||||||
BorderProperties new_border = border_infos -> borderProperties();
|
|
||||||
// s'il y a des modifications au cartouche
|
// s'il y a des modifications au cartouche
|
||||||
if (new_inset != inset) {
|
if (new_inset != inset) {
|
||||||
scene -> undoStack().push(new ChangeInsetCommand(scene, inset, new_inset));
|
scene -> undoStack().push(new ChangeInsetCommand(scene, inset, new_inset));
|
||||||
}
|
}
|
||||||
|
|
||||||
// s'il y a des modifications aux dimensions du schema
|
// s'il y a des modifications aux dimensions du schema
|
||||||
if (new_border != border) {
|
if (
|
||||||
scene -> undoStack().push(new ChangeBorderCommand(scene, border, new_border));
|
columns_count_value != columns_count -> value() ||\
|
||||||
|
columns_width_value != columns_width -> value() ||\
|
||||||
|
columns_height_value != columns_height -> value()
|
||||||
|
) {
|
||||||
|
ChangeBorderCommand *cbc = new ChangeBorderCommand(scene);
|
||||||
|
cbc -> columnsCountDifference = columns_count -> value() - columns_count_value;
|
||||||
|
cbc -> columnsWidthDifference = columns_width -> value() - columns_width_value;
|
||||||
|
cbc -> columnsHeightDifference = columns_height -> value() - columns_height_value;
|
||||||
|
scene -> undoStack().push(cbc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -387,44 +645,36 @@ bool DiagramView::hasSelectedItems() {
|
|||||||
Ajoute une colonne au schema.
|
Ajoute une colonne au schema.
|
||||||
*/
|
*/
|
||||||
void DiagramView::addColumn() {
|
void DiagramView::addColumn() {
|
||||||
if (scene -> isReadOnly()) return;
|
ChangeBorderCommand *cbc = new ChangeBorderCommand(scene);
|
||||||
BorderProperties old_bp = scene -> border_and_inset.exportBorder();
|
cbc -> columnsCountDifference = 1;
|
||||||
BorderProperties new_bp = scene -> border_and_inset.exportBorder();
|
scene -> undoStack().push(cbc);
|
||||||
new_bp.columns_count += 1;
|
|
||||||
scene -> undoStack().push(new ChangeBorderCommand(scene, old_bp, new_bp));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Enleve une colonne au schema.
|
Enleve une colonne au schema.
|
||||||
*/
|
*/
|
||||||
void DiagramView::removeColumn() {
|
void DiagramView::removeColumn() {
|
||||||
if (scene -> isReadOnly()) return;
|
ChangeBorderCommand *cbc = new ChangeBorderCommand(scene);
|
||||||
BorderProperties old_bp = scene -> border_and_inset.exportBorder();
|
cbc -> columnsCountDifference = -1;
|
||||||
BorderProperties new_bp = scene -> border_and_inset.exportBorder();
|
scene -> undoStack().push(cbc);
|
||||||
new_bp.columns_count -= 1;
|
|
||||||
scene -> undoStack().push(new ChangeBorderCommand(scene, old_bp, new_bp));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Agrandit le schema en hauteur
|
Agrandit le schema en hauteur
|
||||||
*/
|
*/
|
||||||
void DiagramView::addRow() {
|
void DiagramView::expand() {
|
||||||
if (scene -> isReadOnly()) return;
|
ChangeBorderCommand *cbc = new ChangeBorderCommand(scene);
|
||||||
BorderProperties old_bp = scene -> border_and_inset.exportBorder();
|
cbc -> columnsHeightDifference = 80.0;
|
||||||
BorderProperties new_bp = scene -> border_and_inset.exportBorder();
|
scene -> undoStack().push(cbc);
|
||||||
new_bp.rows_count += 1;
|
|
||||||
scene -> undoStack().push(new ChangeBorderCommand(scene, old_bp, new_bp));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Retrecit le schema en hauteur
|
Retrecit le schema en hauteur
|
||||||
*/
|
*/
|
||||||
void DiagramView::removeRow() {
|
void DiagramView::shrink() {
|
||||||
if (scene -> isReadOnly()) return;
|
ChangeBorderCommand *cbc = new ChangeBorderCommand(scene);
|
||||||
BorderProperties old_bp = scene -> border_and_inset.exportBorder();
|
cbc -> columnsHeightDifference = -80.0;
|
||||||
BorderProperties new_bp = scene -> border_and_inset.exportBorder();
|
scene -> undoStack().push(cbc);
|
||||||
new_bp.rows_count -= 1;
|
|
||||||
scene -> undoStack().push(new ChangeBorderCommand(scene, old_bp, new_bp));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -453,19 +703,12 @@ void DiagramView::adjustSceneRect() {
|
|||||||
Met a jour le titre du widget
|
Met a jour le titre du widget
|
||||||
*/
|
*/
|
||||||
void DiagramView::updateWindowTitle() {
|
void DiagramView::updateWindowTitle() {
|
||||||
QString view_title(title());
|
QString window_title;
|
||||||
|
if (file_name.isNull()) window_title += tr("nouveau sch\351ma");
|
||||||
// verifie si le document a ete modifie
|
else window_title += file_name;
|
||||||
bool modified_diagram = !(scene -> undoStack().isClean());
|
window_title += "[*]";
|
||||||
|
setWindowTitle(window_title);
|
||||||
// specifie le titre du widget
|
setWindowModified(!(scene -> undoStack().isClean()));
|
||||||
setWindowTitle(view_title + " [*]");
|
|
||||||
setWindowModified(modified_diagram);
|
|
||||||
|
|
||||||
// emet le signal titleChanged en ajoutant manuellement [*] si le schema a ete modifie
|
|
||||||
QString emitted_title = view_title;
|
|
||||||
if (modified_diagram) emitted_title += " [*]";
|
|
||||||
emit(titleChanged(this, emitted_title));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -494,63 +737,6 @@ QRectF DiagramView::viewedSceneRect() const {
|
|||||||
return(QRectF(scene_left_top, scene_right_bottom));
|
return(QRectF(scene_left_top, scene_right_bottom));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Cette methode permet de determiner s'il faut ou non integrer au projet un
|
|
||||||
element dont on connait l'emplacement.
|
|
||||||
L'element droppe est integre a la collection du projet :
|
|
||||||
* s'il appartient a un autre projet, quelque soit la specification de
|
|
||||||
l'utilisateur a ce propos ;
|
|
||||||
* s'il appartient a la collection commune ou a la collection
|
|
||||||
personnelle ET que l'utilisateur a autorise l'integration automatique
|
|
||||||
des elements dans les projets.
|
|
||||||
@param location Emplacement de l'element
|
|
||||||
@return true si l'element doit etre integre, false sinon
|
|
||||||
|
|
||||||
*/
|
|
||||||
bool DiagramView::mustIntegrateElement(const ElementsLocation &location) const {
|
|
||||||
// l'utilisateur a-t-il autorise l'integration automatique des elements dans les projets ?
|
|
||||||
bool auto_integration_enabled = QETApp::settings().value("diagrameditor/integrate-elements", true).toBool();
|
|
||||||
|
|
||||||
// l'element appartient-il a un projet et si oui, est-ce un autre projet ?
|
|
||||||
bool elmt_from_project = location.project();
|
|
||||||
bool elmt_from_another_project = elmt_from_project && location.project() != scene -> project();
|
|
||||||
|
|
||||||
// faut-il integrer l'element ?
|
|
||||||
bool must_integrate_element = (elmt_from_another_project || (auto_integration_enabled && !elmt_from_project));
|
|
||||||
|
|
||||||
return(must_integrate_element);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@param location Emplacement de l'element a ajouter sur le schema
|
|
||||||
@param pos Position (dans les coordonnees de la vue) a laquelle l'element sera ajoute
|
|
||||||
*/
|
|
||||||
bool DiagramView::addElementAtPos(const ElementsLocation &location, const QPoint &pos) {
|
|
||||||
// construit une instance de l'element correspondant a l'emplacement
|
|
||||||
int etat;
|
|
||||||
Element *el = new CustomElement(location, 0, 0, &etat);
|
|
||||||
if (etat) {
|
|
||||||
delete el;
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// pose de l'element sur le schema
|
|
||||||
diagram() -> undoStack().push(new AddElementCommand(diagram(), el, mapToScene(pos)));
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Fait en sorte que le schema ne soit editable que s'il n'est pas en lecture
|
|
||||||
seule
|
|
||||||
*/
|
|
||||||
void DiagramView::applyReadOnly() {
|
|
||||||
if (!scene) return;
|
|
||||||
|
|
||||||
bool is_writable = !scene -> isReadOnly();
|
|
||||||
setInteractive(is_writable);
|
|
||||||
setAcceptDrops(is_writable);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Affiche un dialogue permettant d'editer le conducteur selectionne.
|
Affiche un dialogue permettant d'editer le conducteur selectionne.
|
||||||
Ne fait rien s'il y a 0 ou plusieurs conducteurs selectionnes.
|
Ne fait rien s'il y a 0 ou plusieurs conducteurs selectionnes.
|
||||||
@@ -570,7 +756,6 @@ void DiagramView::editConductor() {
|
|||||||
@param edited_conductor Conducteur a editer
|
@param edited_conductor Conducteur a editer
|
||||||
*/
|
*/
|
||||||
void DiagramView::editConductor(Conductor *edited_conductor) {
|
void DiagramView::editConductor(Conductor *edited_conductor) {
|
||||||
if (scene -> isReadOnly()) return;
|
|
||||||
if (!edited_conductor) return;
|
if (!edited_conductor) return;
|
||||||
|
|
||||||
// initialise l'editeur de proprietes pour le conducteur
|
// initialise l'editeur de proprietes pour le conducteur
|
||||||
@@ -578,8 +763,8 @@ void DiagramView::editConductor(Conductor *edited_conductor) {
|
|||||||
ConductorPropertiesWidget *cpw = new ConductorPropertiesWidget(old_properties);
|
ConductorPropertiesWidget *cpw = new ConductorPropertiesWidget(old_properties);
|
||||||
|
|
||||||
// l'insere dans un dialogue
|
// l'insere dans un dialogue
|
||||||
QDialog conductor_dialog(diagramEditor());
|
QDialog conductor_dialog;
|
||||||
conductor_dialog.setWindowTitle(tr("\311diter les propri\351t\351s d'un conducteur", "window title"));
|
conductor_dialog.setWindowTitle(tr("\311diter les propri\351t\351s d'un conducteur"));
|
||||||
QVBoxLayout *dialog_layout = new QVBoxLayout(&conductor_dialog);
|
QVBoxLayout *dialog_layout = new QVBoxLayout(&conductor_dialog);
|
||||||
dialog_layout -> addWidget(cpw);
|
dialog_layout -> addWidget(cpw);
|
||||||
dialog_layout -> addStretch();
|
dialog_layout -> addStretch();
|
||||||
@@ -607,7 +792,6 @@ void DiagramView::editConductor(Conductor *edited_conductor) {
|
|||||||
Reinitialise le profil des conducteurs selectionnes
|
Reinitialise le profil des conducteurs selectionnes
|
||||||
*/
|
*/
|
||||||
void DiagramView::resetConductors() {
|
void DiagramView::resetConductors() {
|
||||||
if (scene -> isReadOnly()) return;
|
|
||||||
// recupere les conducteurs selectionnes
|
// recupere les conducteurs selectionnes
|
||||||
QSet<Conductor *> selected_conductors = scene -> selectedConductors();
|
QSet<Conductor *> selected_conductors = scene -> selectedConductors();
|
||||||
|
|
||||||
@@ -634,13 +818,12 @@ void DiagramView::resetConductors() {
|
|||||||
futurs nouveaux conducteurs
|
futurs nouveaux conducteurs
|
||||||
*/
|
*/
|
||||||
void DiagramView::editDefaultConductorProperties() {
|
void DiagramView::editDefaultConductorProperties() {
|
||||||
if (scene -> isReadOnly()) return;
|
|
||||||
// initialise l'editeur de proprietes pour le conducteur
|
// initialise l'editeur de proprietes pour le conducteur
|
||||||
ConductorPropertiesWidget *cpw = new ConductorPropertiesWidget(scene -> defaultConductorProperties);
|
ConductorPropertiesWidget *cpw = new ConductorPropertiesWidget(scene -> defaultConductorProperties);
|
||||||
|
|
||||||
// l'insere dans un dialogue
|
// l'insere dans un dialogue
|
||||||
QDialog conductor_dialog(diagramEditor());
|
QDialog conductor_dialog;
|
||||||
conductor_dialog.setWindowTitle(tr("\311diter les propri\351t\351s par d\351faut des conducteurs", "window title"));
|
conductor_dialog.setWindowTitle(tr("\311diter les propri\351t\351s par d\351faut des conducteurs"));
|
||||||
QVBoxLayout *dialog_layout = new QVBoxLayout(&conductor_dialog);
|
QVBoxLayout *dialog_layout = new QVBoxLayout(&conductor_dialog);
|
||||||
dialog_layout -> addWidget(cpw);
|
dialog_layout -> addWidget(cpw);
|
||||||
QDialogButtonBox *dbb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
QDialogButtonBox *dbb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
@@ -673,32 +856,9 @@ bool DiagramView::event(QEvent *e) {
|
|||||||
nouveau champ de texte.
|
nouveau champ de texte.
|
||||||
*/
|
*/
|
||||||
void DiagramView::addText() {
|
void DiagramView::addText() {
|
||||||
if (scene -> isReadOnly()) return;
|
|
||||||
is_adding_text = true;
|
is_adding_text = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Cree un nouveau champ de texte et le place a la position pos
|
|
||||||
en gerant l'annulation ; enfin, le signal textAdded est emis.
|
|
||||||
@param pos Position du champ de texte ajoute
|
|
||||||
@return le champ de texte ajoute
|
|
||||||
*/
|
|
||||||
DiagramTextItem *DiagramView::addDiagramTextAtPos(const QPointF &pos) {
|
|
||||||
// cree un nouveau champ de texte
|
|
||||||
DiagramTextItem *dti = new DiagramTextItem();
|
|
||||||
dti -> setPlainText("_");
|
|
||||||
dti -> previous_text = "_";
|
|
||||||
|
|
||||||
// le place a la position pos en gerant l'annulation
|
|
||||||
scene -> undoStack().push(new AddTextCommand(scene, dti, pos));
|
|
||||||
adjustSceneRect();
|
|
||||||
|
|
||||||
// emet le signal textAdded
|
|
||||||
emit(textAdded(false));
|
|
||||||
|
|
||||||
return(dti);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Gere le menu contextuel
|
Gere le menu contextuel
|
||||||
@param e Evenement decrivant la demande de menu contextuel
|
@param e Evenement decrivant la demande de menu contextuel
|
||||||
@@ -719,8 +879,8 @@ void DiagramView::contextMenuEvent(QContextMenuEvent *e) {
|
|||||||
context_menu -> addAction(qde -> infos_diagram);
|
context_menu -> addAction(qde -> infos_diagram);
|
||||||
context_menu -> addAction(qde -> add_column);
|
context_menu -> addAction(qde -> add_column);
|
||||||
context_menu -> addAction(qde -> remove_column);
|
context_menu -> addAction(qde -> remove_column);
|
||||||
context_menu -> addAction(qde -> add_row);
|
context_menu -> addAction(qde -> expand_diagram);
|
||||||
context_menu -> addAction(qde -> remove_row);
|
context_menu -> addAction(qde -> shrink_diagram);
|
||||||
} else {
|
} else {
|
||||||
context_menu -> addAction(qde -> cut);
|
context_menu -> addAction(qde -> cut);
|
||||||
context_menu -> addAction(qde -> copy);
|
context_menu -> addAction(qde -> copy);
|
||||||
@@ -758,7 +918,7 @@ void DiagramView::mouseDoubleClickEvent(QMouseEvent *e) {
|
|||||||
// recupere le rectangle corespondant au cartouche
|
// recupere le rectangle corespondant au cartouche
|
||||||
QRectF inset_rect(
|
QRectF inset_rect(
|
||||||
Diagram::margin,
|
Diagram::margin,
|
||||||
Diagram::margin + bi.diagramHeight(),
|
Diagram::margin + bi.columnsHeight(),
|
||||||
bi.insetWidth(),
|
bi.insetWidth(),
|
||||||
bi.insetHeight()
|
bi.insetHeight()
|
||||||
);
|
);
|
||||||
@@ -771,14 +931,6 @@ void DiagramView::mouseDoubleClickEvent(QMouseEvent *e) {
|
|||||||
bi.columnsHeaderHeight()
|
bi.columnsHeaderHeight()
|
||||||
);
|
);
|
||||||
|
|
||||||
// recupere le rectangle correspondant aux en-tetes des lignes
|
|
||||||
QRectF rows_rect(
|
|
||||||
Diagram::margin,
|
|
||||||
Diagram::margin,
|
|
||||||
bi.rowsHeaderWidth(),
|
|
||||||
bi.diagramHeight()
|
|
||||||
);
|
|
||||||
|
|
||||||
// coordonnees du clic par rapport au schema
|
// coordonnees du clic par rapport au schema
|
||||||
QPointF click_pos = viewportTransform().inverted().map(e -> pos());
|
QPointF click_pos = viewportTransform().inverted().map(e -> pos());
|
||||||
|
|
||||||
@@ -789,38 +941,10 @@ void DiagramView::mouseDoubleClickEvent(QMouseEvent *e) {
|
|||||||
} else {
|
} else {
|
||||||
QGraphicsView::mouseDoubleClickEvent(e);
|
QGraphicsView::mouseDoubleClickEvent(e);
|
||||||
}
|
}
|
||||||
} else if (inset_rect.contains(click_pos) || columns_rect.contains(click_pos) || rows_rect.contains(click_pos)) {
|
} else if (inset_rect.contains(click_pos) || columns_rect.contains(click_pos)) {
|
||||||
// edite les proprietes du schema
|
// edite les proprietes du schema
|
||||||
editDiagramProperties();
|
dialogEditInfos();
|
||||||
} else {
|
} else {
|
||||||
QGraphicsView::mouseDoubleClickEvent(e);
|
QGraphicsView::mouseDoubleClickEvent(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Cette methode ajoute l'element deisgne par l'emplacement location a la
|
|
||||||
position pos. Si necessaire, elle demande l'integration de l'element au
|
|
||||||
projet.
|
|
||||||
@param location emplacement d'un element a ajouter sur le schema
|
|
||||||
@param pos position voulue de l'element sur le schema
|
|
||||||
@see mustIntegrateElement
|
|
||||||
*/
|
|
||||||
void DiagramView::addDroppedElement() {
|
|
||||||
ElementsLocation location = next_location_;
|
|
||||||
QPoint pos = next_position_;
|
|
||||||
|
|
||||||
if (!mustIntegrateElement(location)) {
|
|
||||||
addElementAtPos(location, pos);
|
|
||||||
} else {
|
|
||||||
QString error_msg;
|
|
||||||
IntegrationMoveElementsHandler *integ_handler = new IntegrationMoveElementsHandler(this);
|
|
||||||
QString integ_path = scene -> project() -> integrateElement(location.toString(), integ_handler, error_msg);
|
|
||||||
delete integ_handler;
|
|
||||||
if (integ_path.isEmpty()) {
|
|
||||||
qDebug() << error_msg;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
addElementAtPos(ElementsLocation::locationFromString(integ_path), pos);
|
|
||||||
}
|
|
||||||
adjustSceneRect();
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -18,9 +18,7 @@
|
|||||||
#ifndef DIAGRAMVIEW_H
|
#ifndef DIAGRAMVIEW_H
|
||||||
#define DIAGRAMVIEW_H
|
#define DIAGRAMVIEW_H
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include "elementslocation.h"
|
|
||||||
class Diagram;
|
class Diagram;
|
||||||
class DiagramTextItem;
|
|
||||||
class QETDiagramEditor;
|
class QETDiagramEditor;
|
||||||
class Conductor;
|
class Conductor;
|
||||||
/**
|
/**
|
||||||
@@ -31,36 +29,42 @@ class DiagramView : public QGraphicsView {
|
|||||||
|
|
||||||
// constructeurs, destructeur
|
// constructeurs, destructeur
|
||||||
public:
|
public:
|
||||||
DiagramView(Diagram * = 0, QWidget * = 0);
|
DiagramView(QWidget * = 0);
|
||||||
virtual ~DiagramView();
|
virtual ~DiagramView();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DiagramView(const DiagramView &);
|
DiagramView(const DiagramView &);
|
||||||
|
|
||||||
// attributs
|
// attributs
|
||||||
|
public:
|
||||||
|
/// Nom de fichier du schema edite
|
||||||
|
QString file_name;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Diagram *scene;
|
Diagram *scene;
|
||||||
QMenu *context_menu;
|
QMenu *context_menu;
|
||||||
QAction *paste_here;
|
QAction *paste_here;
|
||||||
QPoint paste_here_pos;
|
QPoint paste_here_pos;
|
||||||
bool is_adding_text;
|
bool is_adding_text;
|
||||||
ElementsLocation next_location_;
|
|
||||||
QPoint next_position_;
|
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
public:
|
public:
|
||||||
QString title() const;
|
bool open(QString, int * = NULL);
|
||||||
void editDiagramProperties();
|
void closeEvent(QCloseEvent *);
|
||||||
|
bool save();
|
||||||
|
bool saveAs();
|
||||||
|
void dialogExport();
|
||||||
|
void dialogEditInfos();
|
||||||
|
void dialogPrint();
|
||||||
void addColumn();
|
void addColumn();
|
||||||
void removeColumn();
|
void removeColumn();
|
||||||
void addRow();
|
void expand();
|
||||||
void removeRow();
|
void shrink();
|
||||||
/// @return Le schema visualise par ce DiagramView
|
/// @return Le schema visualise par ce DiagramView
|
||||||
Diagram *diagram() { return(scene); }
|
Diagram *diagram() { return(scene); }
|
||||||
QETDiagramEditor *diagramEditor() const;
|
QETDiagramEditor *diagramEditor() const;
|
||||||
bool hasSelectedItems();
|
bool hasSelectedItems();
|
||||||
void addText();
|
void addText();
|
||||||
DiagramTextItem *addDiagramTextAtPos(const QPointF &);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void mouseDoubleClickEvent(QMouseEvent *);
|
virtual void mouseDoubleClickEvent(QMouseEvent *);
|
||||||
@@ -69,14 +73,13 @@ class DiagramView : public QGraphicsView {
|
|||||||
virtual bool event(QEvent *);
|
virtual bool event(QEvent *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool saveDiagramToFile(QString &);
|
||||||
void mousePressEvent(QMouseEvent *);
|
void mousePressEvent(QMouseEvent *);
|
||||||
void dragEnterEvent(QDragEnterEvent *);
|
void dragEnterEvent(QDragEnterEvent *);
|
||||||
void dragLeaveEvent(QDragLeaveEvent *);
|
void dragLeaveEvent(QDragLeaveEvent *);
|
||||||
void dragMoveEvent(QDragMoveEvent *);
|
void dragMoveEvent(QDragMoveEvent *);
|
||||||
void dropEvent(QDropEvent *);
|
void dropEvent(QDropEvent *);
|
||||||
QRectF viewedSceneRect() const;
|
QRectF viewedSceneRect() const;
|
||||||
bool mustIntegrateElement(const ElementsLocation &) const;
|
|
||||||
bool addElementAtPos(const ElementsLocation &, const QPoint &);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/// Signal emis lorsque la selection change
|
/// Signal emis lorsque la selection change
|
||||||
@@ -85,10 +88,6 @@ class DiagramView : public QGraphicsView {
|
|||||||
void modeChanged();
|
void modeChanged();
|
||||||
/// Signal emis lorsqu'un texte a ete pose
|
/// Signal emis lorsqu'un texte a ete pose
|
||||||
void textAdded(bool);
|
void textAdded(bool);
|
||||||
/// Signal emis lorsque le titre du schema change
|
|
||||||
void titleChanged(DiagramView *, const QString &);
|
|
||||||
/// Signal emis avant l'integration d'un element
|
|
||||||
void aboutToAddElement();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void selectNothing();
|
void selectNothing();
|
||||||
@@ -114,8 +113,6 @@ class DiagramView : public QGraphicsView {
|
|||||||
void editDefaultConductorProperties();
|
void editDefaultConductorProperties();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void addDroppedElement();
|
|
||||||
void adjustGridToZoom();
|
void adjustGridToZoom();
|
||||||
void applyReadOnly();
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -74,7 +74,6 @@ class CustomElementGraphicPart : public CustomElementPart {
|
|||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
virtual ~CustomElementGraphicPart() {
|
virtual ~CustomElementGraphicPart() {
|
||||||
if (style_editor -> parentWidget()) return; // l'editeur de style sera supprime par son parent
|
|
||||||
delete style_editor;
|
delete style_editor;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -29,7 +29,7 @@ DeletePartsCommand::DeletePartsCommand(
|
|||||||
const QList<QGraphicsItem *> parts,
|
const QList<QGraphicsItem *> parts,
|
||||||
QUndoCommand *parent
|
QUndoCommand *parent
|
||||||
) :
|
) :
|
||||||
QUndoCommand(QObject::tr("suppression", "undo caption"), parent),
|
QUndoCommand(QObject::tr("suppression"), parent),
|
||||||
deleted_parts(parts),
|
deleted_parts(parts),
|
||||||
editor_scene(scene)
|
editor_scene(scene)
|
||||||
{
|
{
|
||||||
@@ -59,94 +59,6 @@ void DeletePartsCommand::redo() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** CutPartsCommand ***/
|
|
||||||
/**
|
|
||||||
Constructeur
|
|
||||||
@param scene ElementScene concernee
|
|
||||||
@param parts Liste des parties collees
|
|
||||||
@param parent QUndoCommand parent
|
|
||||||
*/
|
|
||||||
PastePartsCommand::PastePartsCommand(
|
|
||||||
ElementView *view,
|
|
||||||
const ElementContent &c,
|
|
||||||
QUndoCommand *parent
|
|
||||||
) :
|
|
||||||
QUndoCommand(parent),
|
|
||||||
content_(c),
|
|
||||||
editor_view_(view),
|
|
||||||
editor_scene_(view -> scene()),
|
|
||||||
uses_offset(false),
|
|
||||||
first_redo(true)
|
|
||||||
{
|
|
||||||
setText(QObject::tr("coller"));
|
|
||||||
editor_scene_ -> qgiManager().manage(content_);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Destructeur
|
|
||||||
PastePartsCommand::~PastePartsCommand() {
|
|
||||||
editor_scene_ -> qgiManager().release(content_);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// annule le coller
|
|
||||||
void PastePartsCommand::undo() {
|
|
||||||
// enleve les parties
|
|
||||||
foreach(QGraphicsItem *part, content_) editor_scene_ -> removeItem(part);
|
|
||||||
if (uses_offset) {
|
|
||||||
editor_view_ -> offset_paste_count_ = old_offset_paste_count_;
|
|
||||||
editor_view_ -> start_top_left_corner_ = old_start_top_left_corner_;
|
|
||||||
}
|
|
||||||
editor_view_ -> adjustSceneRect();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// refait le coller
|
|
||||||
void PastePartsCommand::redo() {
|
|
||||||
if (first_redo) first_redo = false;
|
|
||||||
else {
|
|
||||||
// pose les parties
|
|
||||||
foreach(QGraphicsItem *part, content_) editor_scene_ -> addItem(part);
|
|
||||||
if (uses_offset) {
|
|
||||||
editor_view_ -> offset_paste_count_ = new_offset_paste_count_;
|
|
||||||
editor_view_ -> start_top_left_corner_ = new_start_top_left_corner_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach(QGraphicsItem *part, content_) part -> setSelected(true);
|
|
||||||
editor_view_ -> adjustSceneRect();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Indique a cet objet d'annulation que le c/c a annuler ou refaire etait un
|
|
||||||
c/c avec decalage ; il faut plus d'informations pour annuler ce type de
|
|
||||||
collage.
|
|
||||||
*/
|
|
||||||
void PastePartsCommand::setOffset(int old_offset_pc, const QPointF &old_start_tlc, int new_offset_pc, const QPointF &new_start_tlc) {
|
|
||||||
old_offset_paste_count_ = old_offset_pc;
|
|
||||||
old_start_top_left_corner_ = old_start_tlc;
|
|
||||||
new_offset_paste_count_ = new_offset_pc;
|
|
||||||
new_start_top_left_corner_ = new_start_tlc;
|
|
||||||
uses_offset = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** CutPartsCommand ***/
|
|
||||||
/**
|
|
||||||
Constructeur
|
|
||||||
@param scene ElementScene concernee
|
|
||||||
@param parts Liste des parties coupees
|
|
||||||
@param parent QUndoCommand parent
|
|
||||||
*/
|
|
||||||
CutPartsCommand::CutPartsCommand(
|
|
||||||
ElementScene *scene,
|
|
||||||
const QList<QGraphicsItem *> parts,
|
|
||||||
QUndoCommand *parent
|
|
||||||
) :
|
|
||||||
DeletePartsCommand(scene, parts, parent)
|
|
||||||
{
|
|
||||||
setText(QString(QObject::tr("couper des parties", "undo caption")));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Destructeur
|
|
||||||
CutPartsCommand::~CutPartsCommand() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** MovePartsCommand ***/
|
/*** MovePartsCommand ***/
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@@ -161,7 +73,7 @@ MovePartsCommand::MovePartsCommand(
|
|||||||
const QList<QGraphicsItem *> parts,
|
const QList<QGraphicsItem *> parts,
|
||||||
QUndoCommand *parent
|
QUndoCommand *parent
|
||||||
) :
|
) :
|
||||||
QUndoCommand(QObject::tr("d\351placement", "undo caption"), parent),
|
QUndoCommand(QObject::tr("d\351placement"), parent),
|
||||||
movement(m),
|
movement(m),
|
||||||
first_redo(true)
|
first_redo(true)
|
||||||
{
|
{
|
||||||
@@ -202,7 +114,7 @@ AddPartCommand::AddPartCommand(
|
|||||||
QGraphicsItem *p,
|
QGraphicsItem *p,
|
||||||
QUndoCommand *parent
|
QUndoCommand *parent
|
||||||
) :
|
) :
|
||||||
QUndoCommand(QString(QObject::tr("ajout %1", "undo caption")).arg(name), parent),
|
QUndoCommand(QObject::tr("ajout ") + name, parent),
|
||||||
part(p),
|
part(p),
|
||||||
editor_scene(scene),
|
editor_scene(scene),
|
||||||
first_redo(true)
|
first_redo(true)
|
||||||
@@ -249,7 +161,7 @@ ChangePartCommand::ChangePartCommand(
|
|||||||
const QVariant &new_v,
|
const QVariant &new_v,
|
||||||
QUndoCommand *parent
|
QUndoCommand *parent
|
||||||
) :
|
) :
|
||||||
QUndoCommand(QString(QObject::tr("modification %1", "undo caption")).arg(name), parent),
|
QUndoCommand(QObject::tr("modification ") + name, parent),
|
||||||
cep(part),
|
cep(part),
|
||||||
property(prop),
|
property(prop),
|
||||||
old_value(old_v),
|
old_value(old_v),
|
||||||
@@ -284,7 +196,7 @@ ChangePolygonPointsCommand::ChangePolygonPointsCommand(
|
|||||||
const QVector<QPointF> &n_points,
|
const QVector<QPointF> &n_points,
|
||||||
QUndoCommand *parent
|
QUndoCommand *parent
|
||||||
) :
|
) :
|
||||||
QUndoCommand(QObject::tr("modification points polygone", "undo caption"), parent),
|
QUndoCommand(QObject::tr("modification points polygone"), parent),
|
||||||
polygon(p),
|
polygon(p),
|
||||||
old_points(o_points),
|
old_points(o_points),
|
||||||
new_points(n_points)
|
new_points(n_points)
|
||||||
@@ -324,7 +236,7 @@ ChangeHotspotCommand::ChangeHotspotCommand(
|
|||||||
const QPoint &o,
|
const QPoint &o,
|
||||||
QUndoCommand *parent
|
QUndoCommand *parent
|
||||||
) :
|
) :
|
||||||
QUndoCommand(QObject::tr("modification dimensions/hotspot", "undo caption"), parent),
|
QUndoCommand(QObject::tr("modification dimensions/hotspot"), parent),
|
||||||
element(element_scene),
|
element(element_scene),
|
||||||
size_before(size_1),
|
size_before(size_1),
|
||||||
size_after(size_2),
|
size_after(size_2),
|
||||||
@@ -385,7 +297,7 @@ ChangeNamesCommand::ChangeNamesCommand(
|
|||||||
const NamesList &after,
|
const NamesList &after,
|
||||||
QUndoCommand *parent
|
QUndoCommand *parent
|
||||||
) :
|
) :
|
||||||
QUndoCommand(QObject::tr("modification noms", "undo caption"), parent),
|
QUndoCommand(QObject::tr("modification noms"), parent),
|
||||||
names_before(before),
|
names_before(before),
|
||||||
names_after(after),
|
names_after(after),
|
||||||
element(element_scene)
|
element(element_scene)
|
||||||
@@ -419,7 +331,7 @@ ChangeOrientationsCommand::ChangeOrientationsCommand(
|
|||||||
const OrientationSet &after,
|
const OrientationSet &after,
|
||||||
QUndoCommand *parent
|
QUndoCommand *parent
|
||||||
) :
|
) :
|
||||||
QUndoCommand(QObject::tr("modification orientations", "undo caption"), parent),
|
QUndoCommand(QObject::tr("modification orientations"), parent),
|
||||||
ori_before(before),
|
ori_before(before),
|
||||||
ori_after(after),
|
ori_after(after),
|
||||||
element(element_scene)
|
element(element_scene)
|
||||||
@@ -463,16 +375,16 @@ ChangeZValueCommand::ChangeZValueCommand(
|
|||||||
|
|
||||||
// choisit le nom en fonction du traitement
|
// choisit le nom en fonction du traitement
|
||||||
if (option == BringForward) {
|
if (option == BringForward) {
|
||||||
setText(QObject::tr("amener au premier plan", "undo caption"));
|
setText(QObject::tr("amener au premier plan"));
|
||||||
applyBringForward(items_list);
|
applyBringForward(items_list);
|
||||||
} else if (option == Raise) {
|
} else if (option == Raise) {
|
||||||
setText(QObject::tr("rapprocher", "undo caption"));
|
setText(QObject::tr("rapprocher"));
|
||||||
applyRaise(items_list);
|
applyRaise(items_list);
|
||||||
} else if (option == Lower) {
|
} else if (option == Lower) {
|
||||||
setText(QObject::tr("\351loigner", "undo caption"));
|
setText(QObject::tr("\351loigner"));
|
||||||
applyLower(items_list);
|
applyLower(items_list);
|
||||||
} else if (option == SendBackward) {
|
} else if (option == SendBackward) {
|
||||||
setText(QObject::tr("envoyer au fond", "undo caption"));
|
setText(QObject::tr("envoyer au fond"));
|
||||||
applySendBackward(items_list);
|
applySendBackward(items_list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -571,7 +483,7 @@ void ChangeZValueCommand::applySendBackward(const QList<QGraphicsItem *> &items_
|
|||||||
@param parent QUndoCommand parent
|
@param parent QUndoCommand parent
|
||||||
*/
|
*/
|
||||||
AllowInternalConnectionsCommand::AllowInternalConnectionsCommand(ElementScene *elmt, bool allow, QUndoCommand *parent) :
|
AllowInternalConnectionsCommand::AllowInternalConnectionsCommand(ElementScene *elmt, bool allow, QUndoCommand *parent) :
|
||||||
QUndoCommand(QObject::tr("modification connexions internes", "undo caption"), parent),
|
QUndoCommand(QObject::tr("modification connexions internes"), parent),
|
||||||
element(elmt),
|
element(elmt),
|
||||||
ic(allow)
|
ic(allow)
|
||||||
{
|
{
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -19,9 +19,7 @@
|
|||||||
#define EDITOR_COMMANDS_H
|
#define EDITOR_COMMANDS_H
|
||||||
#include "customelementpart.h"
|
#include "customelementpart.h"
|
||||||
#include "partpolygon.h"
|
#include "partpolygon.h"
|
||||||
#include "elementview.h"
|
|
||||||
#include "elementscene.h"
|
#include "elementscene.h"
|
||||||
#include "elementcontent.h"
|
|
||||||
#include "qgimanager.h"
|
#include "qgimanager.h"
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
/**
|
/**
|
||||||
@@ -49,52 +47,6 @@ class DeletePartsCommand : public QUndoCommand {
|
|||||||
ElementScene *editor_scene;
|
ElementScene *editor_scene;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
Cette classe represente l'action de coller quelque chose dans un element
|
|
||||||
*/
|
|
||||||
class PastePartsCommand : public QUndoCommand {
|
|
||||||
// constructeurs, destructeur
|
|
||||||
public:
|
|
||||||
PastePartsCommand(ElementView *, const ElementContent &, QUndoCommand * = 0);
|
|
||||||
virtual ~PastePartsCommand();
|
|
||||||
private:
|
|
||||||
PastePartsCommand(const PastePartsCommand &);
|
|
||||||
|
|
||||||
// methodes
|
|
||||||
public:
|
|
||||||
virtual void undo();
|
|
||||||
virtual void redo();
|
|
||||||
virtual void setOffset(int, const QPointF &, int, const QPointF &);
|
|
||||||
|
|
||||||
// attributs
|
|
||||||
private:
|
|
||||||
/// contenu ajoute
|
|
||||||
ElementContent content_;
|
|
||||||
/// schema sur lequel on colle les elements et conducteurs
|
|
||||||
ElementView *editor_view_;
|
|
||||||
ElementScene *editor_scene_;
|
|
||||||
/// Informations pour annuler un c/c avec decalage
|
|
||||||
int old_offset_paste_count_;
|
|
||||||
QPointF old_start_top_left_corner_;
|
|
||||||
int new_offset_paste_count_;
|
|
||||||
QPointF new_start_top_left_corner_;
|
|
||||||
bool uses_offset;
|
|
||||||
/// booleen pour empecher le premier appel a redo
|
|
||||||
bool first_redo;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
Cette classe represente l'action de supprimer des parties d'un element
|
|
||||||
*/
|
|
||||||
class CutPartsCommand : public DeletePartsCommand {
|
|
||||||
// constructeurs, destructeur
|
|
||||||
public:
|
|
||||||
CutPartsCommand(ElementScene *, const QList<QGraphicsItem *>, QUndoCommand * = 0);
|
|
||||||
virtual ~CutPartsCommand();
|
|
||||||
private:
|
|
||||||
CutPartsCommand(const CutPartsCommand &);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Cette classe represente l'action de deplacer une ou plusieurs
|
Cette classe represente l'action de deplacer une ou plusieurs
|
||||||
parties lors de l'edition d'un element
|
parties lors de l'edition d'un element
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -22,7 +22,7 @@ class QETElementEditor;
|
|||||||
class ElementScene;
|
class ElementScene;
|
||||||
class CustomElementPart;
|
class CustomElementPart;
|
||||||
/**
|
/**
|
||||||
Cette classe est la classe de base pour les editeurs de parties dans
|
Cette classe est la classe de base pour les editeurs de aprties dans
|
||||||
l'editeur d'element. Elle fournit des methodes pour acceder facilement
|
l'editeur d'element. Elle fournit des methodes pour acceder facilement
|
||||||
a l'editeur, a la pile d'annulation, a la scene d'edition ou encore pour
|
a l'editeur, a la pile d'annulation, a la scene d'edition ou encore pour
|
||||||
ajouter facilement une annulation de type ChangePartCommand.
|
ajouter facilement une annulation de type ChangePartCommand.
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
#include "qetelementeditor.h"
|
#include "qetelementeditor.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "partline.h"
|
#include "partline.h"
|
||||||
#include "partrectangle.h"
|
|
||||||
#include "partellipse.h"
|
#include "partellipse.h"
|
||||||
#include "partcircle.h"
|
#include "partcircle.h"
|
||||||
#include "partpolygon.h"
|
#include "partpolygon.h"
|
||||||
@@ -29,7 +28,9 @@
|
|||||||
#include "partarc.h"
|
#include "partarc.h"
|
||||||
#include "hotspoteditor.h"
|
#include "hotspoteditor.h"
|
||||||
#include "editorcommands.h"
|
#include "editorcommands.h"
|
||||||
#include "elementcontent.h"
|
|
||||||
|
const int ElementScene::xGrid = 10;
|
||||||
|
const int ElementScene::yGrid = 10;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@@ -46,8 +47,6 @@ ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) :
|
|||||||
element_editor(editor)
|
element_editor(editor)
|
||||||
{
|
{
|
||||||
current_polygon = NULL;
|
current_polygon = NULL;
|
||||||
setGrid(1, 1);
|
|
||||||
initPasteArea();
|
|
||||||
undo_stack.setClean();
|
undo_stack.setClean();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,13 +68,6 @@ void ElementScene::slot_addLine() {
|
|||||||
behavior = Line;
|
behavior = Line;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Passe la scene en mode "ajout de rectangle"
|
|
||||||
*/
|
|
||||||
void ElementScene::slot_addRectangle() {
|
|
||||||
behavior = Rectangle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Passe la scene en mode "ajout de cercle"
|
Passe la scene en mode "ajout de cercle"
|
||||||
*/
|
*/
|
||||||
@@ -112,6 +104,7 @@ void ElementScene::slot_addTerminal() {
|
|||||||
behavior = Terminal;
|
behavior = Terminal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Passe la scene en mode "ajout d'arc de cercle"
|
Passe la scene en mode "ajout d'arc de cercle"
|
||||||
*/
|
*/
|
||||||
@@ -131,17 +124,7 @@ void ElementScene::slot_addTextField() {
|
|||||||
@param e objet decrivant l'evenement
|
@param e objet decrivant l'evenement
|
||||||
*/
|
*/
|
||||||
void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
||||||
QPointF event_pos = e -> scenePos();
|
|
||||||
if (mustSnapToGrid(e)) snapToGrid(event_pos);
|
|
||||||
|
|
||||||
if (behavior != Polygon && current_polygon != NULL) current_polygon = NULL;
|
if (behavior != Polygon && current_polygon != NULL) current_polygon = NULL;
|
||||||
if (behavior == PasteArea) {
|
|
||||||
QRectF current_rect(paste_area_ -> rect());
|
|
||||||
current_rect.moveCenter(event_pos);
|
|
||||||
paste_area_ -> setRect(current_rect);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QRectF temp_rect;
|
QRectF temp_rect;
|
||||||
qreal radius;
|
qreal radius;
|
||||||
QPointF temp_point;
|
QPointF temp_point;
|
||||||
@@ -149,26 +132,21 @@ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
if (e -> buttons() & Qt::LeftButton) {
|
if (e -> buttons() & Qt::LeftButton) {
|
||||||
switch(behavior) {
|
switch(behavior) {
|
||||||
case Line:
|
case Line:
|
||||||
current_line -> setLine(QLineF(current_line -> line().p1(), event_pos));
|
current_line -> setLine(QLineF(current_line -> line().p1(), e -> scenePos()));
|
||||||
break;
|
|
||||||
case Rectangle:
|
|
||||||
temp_rect = current_rectangle -> rect();
|
|
||||||
temp_rect.setBottomRight(event_pos);
|
|
||||||
current_rectangle -> setRect(temp_rect);
|
|
||||||
break;
|
break;
|
||||||
case Ellipse:
|
case Ellipse:
|
||||||
temp_rect = current_ellipse -> rect();
|
temp_rect = current_ellipse -> rect();
|
||||||
temp_rect.setBottomRight(event_pos);
|
temp_rect.setBottomRight(e -> scenePos());
|
||||||
current_ellipse -> setRect(temp_rect);
|
current_ellipse -> setRect(temp_rect);
|
||||||
break;
|
break;
|
||||||
case Arc:
|
case Arc:
|
||||||
temp_rect = current_arc -> rect();
|
temp_rect = current_arc -> rect();
|
||||||
temp_rect.setBottomRight(event_pos);
|
temp_rect.setBottomRight(e -> scenePos());
|
||||||
current_arc -> setRect(temp_rect);
|
current_arc -> setRect(temp_rect);
|
||||||
break;
|
break;
|
||||||
case Circle:
|
case Circle:
|
||||||
temp_rect = current_circle -> rect();
|
temp_rect = current_circle -> rect();
|
||||||
temp_point = event_pos - current_circle -> mapToScene(temp_rect.center());
|
temp_point = e -> scenePos() - current_circle -> mapToScene(temp_rect.center());
|
||||||
radius = sqrt(pow(temp_point.x(), 2) + pow(temp_point.y(), 2));
|
radius = sqrt(pow(temp_point.x(), 2) + pow(temp_point.y(), 2));
|
||||||
temp_rect = QRectF(
|
temp_rect = QRectF(
|
||||||
temp_rect.center() - QPointF(radius, radius),
|
temp_rect.center() - QPointF(radius, radius),
|
||||||
@@ -180,35 +158,17 @@ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
if (current_polygon == NULL) break;
|
if (current_polygon == NULL) break;
|
||||||
temp_polygon = current_polygon -> polygon();
|
temp_polygon = current_polygon -> polygon();
|
||||||
temp_polygon.pop_back();
|
temp_polygon.pop_back();
|
||||||
temp_polygon << event_pos;
|
temp_polygon << e -> scenePos();
|
||||||
current_polygon -> setPolygon(temp_polygon);
|
current_polygon -> setPolygon(temp_polygon);
|
||||||
break;
|
break;
|
||||||
case Normal:
|
case Normal:
|
||||||
default:
|
default:
|
||||||
QList<QGraphicsItem *> selected_items = selectedItems();
|
QGraphicsScene::mouseMoveEvent(e);
|
||||||
if (!selected_items.isEmpty()) {
|
|
||||||
// mouvement de souris realise depuis le dernier press event
|
|
||||||
QPointF mouse_movement = e -> scenePos() - moving_press_pos;
|
|
||||||
|
|
||||||
// application de ce mouvement a la fsi_pos enregistre dans le dernier press event
|
|
||||||
QPointF new_fsi_pos = fsi_pos + mouse_movement;
|
|
||||||
|
|
||||||
// snap eventuel de la nouvelle fsi_pos
|
|
||||||
if (mustSnapToGrid(e)) snapToGrid(new_fsi_pos);
|
|
||||||
|
|
||||||
// difference entre la fsi_pos finale et la fsi_pos courante = mouvement a appliquer
|
|
||||||
|
|
||||||
QPointF current_fsi_pos = selected_items.first() -> scenePos();
|
|
||||||
QPointF final_movement = new_fsi_pos - current_fsi_pos;
|
|
||||||
foreach(QGraphicsItem *qgi, selected_items) {
|
|
||||||
qgi -> moveBy(final_movement.x(), final_movement.y());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (behavior == Polygon && current_polygon != NULL) {
|
} else if (behavior == Polygon && current_polygon != NULL) {
|
||||||
temp_polygon = current_polygon -> polygon();
|
temp_polygon = current_polygon -> polygon();
|
||||||
temp_polygon.pop_back();
|
temp_polygon.pop_back();
|
||||||
temp_polygon << event_pos;
|
temp_polygon << e -> scenePos();
|
||||||
current_polygon -> setPolygon(temp_polygon);
|
current_polygon -> setPolygon(temp_polygon);
|
||||||
} else QGraphicsScene::mouseMoveEvent(e);
|
} else QGraphicsScene::mouseMoveEvent(e);
|
||||||
}
|
}
|
||||||
@@ -218,34 +178,27 @@ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
@param e objet decrivant l'evenement
|
@param e objet decrivant l'evenement
|
||||||
*/
|
*/
|
||||||
void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||||
QPointF event_pos = e -> scenePos();
|
|
||||||
if (mustSnapToGrid(e)) snapToGrid(event_pos);
|
|
||||||
|
|
||||||
if (behavior != Polygon && current_polygon != NULL) current_polygon = NULL;
|
if (behavior != Polygon && current_polygon != NULL) current_polygon = NULL;
|
||||||
QPolygonF temp_polygon;
|
QPolygonF temp_polygon;
|
||||||
if (e -> button() & Qt::LeftButton) {
|
if (e -> button() & Qt::LeftButton) {
|
||||||
switch(behavior) {
|
switch(behavior) {
|
||||||
case Line:
|
case Line:
|
||||||
current_line = new PartLine(element_editor, 0, this);
|
current_line = new PartLine(element_editor, 0, this);
|
||||||
current_line -> setLine(QLineF(event_pos, event_pos));
|
current_line -> setLine(QLineF(e -> scenePos(), e -> scenePos()));
|
||||||
break;
|
|
||||||
case Rectangle:
|
|
||||||
current_rectangle = new PartRectangle(element_editor, 0, this);
|
|
||||||
current_rectangle -> setRect(QRectF(event_pos, QSizeF(0.0, 0.0)));
|
|
||||||
break;
|
break;
|
||||||
case Ellipse:
|
case Ellipse:
|
||||||
current_ellipse = new PartEllipse(element_editor, 0, this);
|
current_ellipse = new PartEllipse(element_editor, 0, this);
|
||||||
current_ellipse -> setRect(QRectF(event_pos, QSizeF(0.0, 0.0)));
|
current_ellipse -> setRect(QRectF(e -> scenePos(), QSizeF(0.0, 0.0)));
|
||||||
current_ellipse -> setProperty("antialias", true);
|
current_ellipse -> setProperty("antialias", true);
|
||||||
break;
|
break;
|
||||||
case Arc:
|
case Arc:
|
||||||
current_arc = new PartArc(element_editor, 0, this);
|
current_arc = new PartArc(element_editor, 0, this);
|
||||||
current_arc -> setRect(QRectF(event_pos, QSizeF(0.0, 0.0)));
|
current_arc -> setRect(QRectF(e -> scenePos(), QSizeF(0.0, 0.0)));
|
||||||
current_arc -> setProperty("antialias", true);
|
current_arc -> setProperty("antialias", true);
|
||||||
break;
|
break;
|
||||||
case Circle:
|
case Circle:
|
||||||
current_circle = new PartCircle(element_editor, 0, this);
|
current_circle = new PartCircle(element_editor, 0, this);
|
||||||
current_circle -> setRect(QRectF(event_pos, QSizeF(0.0, 0.0)));
|
current_circle -> setRect(QRectF(e -> scenePos(), QSizeF(0.0, 0.0)));
|
||||||
current_circle -> setProperty("antialias", true);
|
current_circle -> setProperty("antialias", true);
|
||||||
break;
|
break;
|
||||||
case Polygon:
|
case Polygon:
|
||||||
@@ -254,23 +207,14 @@ void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
temp_polygon = QPolygonF(0);
|
temp_polygon = QPolygonF(0);
|
||||||
} else temp_polygon = current_polygon -> polygon();
|
} else temp_polygon = current_polygon -> polygon();
|
||||||
// au debut, on insere deux points
|
// au debut, on insere deux points
|
||||||
if (!temp_polygon.count()) temp_polygon << event_pos;
|
if (!temp_polygon.count()) temp_polygon << e -> scenePos();
|
||||||
temp_polygon << event_pos;
|
temp_polygon << e -> scenePos();
|
||||||
current_polygon -> setPolygon(temp_polygon);
|
current_polygon -> setPolygon(temp_polygon);
|
||||||
break;
|
break;
|
||||||
case Normal:
|
case Normal:
|
||||||
default:
|
default:
|
||||||
QGraphicsScene::mousePressEvent(e);
|
QGraphicsScene::mousePressEvent(e);
|
||||||
// gestion des deplacements de parties
|
if (!selectedItems().isEmpty()) fsi_pos = selectedItems().first() -> scenePos();
|
||||||
if (!selectedItems().isEmpty()) {
|
|
||||||
fsi_pos = selectedItems().first() -> scenePos();
|
|
||||||
moving_press_pos = e -> scenePos();
|
|
||||||
moving_parts_ = true;
|
|
||||||
} else {
|
|
||||||
fsi_pos = QPoint();
|
|
||||||
moving_press_pos = QPoint();
|
|
||||||
moving_parts_ = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else QGraphicsScene::mousePressEvent(e);
|
} else QGraphicsScene::mousePressEvent(e);
|
||||||
}
|
}
|
||||||
@@ -280,97 +224,71 @@ void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
@param e objet decrivant l'evenement
|
@param e objet decrivant l'evenement
|
||||||
*/
|
*/
|
||||||
void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
||||||
QPointF event_pos = e -> scenePos();
|
|
||||||
if (mustSnapToGrid(e)) snapToGrid(event_pos);
|
|
||||||
|
|
||||||
PartTerminal *terminal;
|
PartTerminal *terminal;
|
||||||
PartText *text;
|
PartText *text;
|
||||||
PartTextField *textfield;
|
PartTextField *textfield;
|
||||||
if (behavior != Polygon && current_polygon != NULL) current_polygon = NULL;
|
if (behavior != Polygon && current_polygon != NULL) current_polygon = NULL;
|
||||||
|
|
||||||
if (behavior == PasteArea) {
|
|
||||||
defined_paste_area_ = paste_area_ -> rect();
|
|
||||||
removeItem(paste_area_);
|
|
||||||
emit(pasteAreaDefined(defined_paste_area_));
|
|
||||||
behavior = Normal;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e -> button() & Qt::LeftButton) {
|
if (e -> button() & Qt::LeftButton) {
|
||||||
switch(behavior) {
|
switch(behavior) {
|
||||||
case Line:
|
case Line:
|
||||||
if (qgiManager().manages(current_line)) break;
|
if (qgiManager().manages(current_line)) break;
|
||||||
undo_stack.push(new AddPartCommand(tr("ligne"), this, current_line));
|
undo_stack.push(new AddPartCommand(tr("ligne"), this, current_line));
|
||||||
emit(partsAdded());
|
emit(partsAdded());
|
||||||
endCurrentBehavior(e);
|
|
||||||
break;
|
|
||||||
case Rectangle:
|
|
||||||
if (qgiManager().manages(current_rectangle)) break;
|
|
||||||
current_rectangle -> setRect(current_rectangle -> rect().normalized());
|
|
||||||
undo_stack.push(new AddPartCommand(tr("rectangle"), this, current_rectangle));
|
|
||||||
emit(partsAdded());
|
|
||||||
endCurrentBehavior(e);
|
|
||||||
break;
|
break;
|
||||||
case Ellipse:
|
case Ellipse:
|
||||||
if (qgiManager().manages(current_ellipse)) break;
|
if (qgiManager().manages(current_ellipse)) break;
|
||||||
current_ellipse -> setRect(current_ellipse -> rect().normalized());
|
current_ellipse -> setRect(current_ellipse -> rect().normalized());
|
||||||
undo_stack.push(new AddPartCommand(tr("ellipse"), this, current_ellipse));
|
undo_stack.push(new AddPartCommand(tr("ellipse"), this, current_ellipse));
|
||||||
emit(partsAdded());
|
emit(partsAdded());
|
||||||
endCurrentBehavior(e);
|
|
||||||
break;
|
break;
|
||||||
case Arc:
|
case Arc:
|
||||||
if (qgiManager().manages(current_arc)) break;
|
if (qgiManager().manages(current_arc)) break;
|
||||||
current_arc-> setRect(current_arc -> rect().normalized());
|
current_arc-> setRect(current_arc -> rect().normalized());
|
||||||
undo_stack.push(new AddPartCommand(tr("arc"), this, current_arc));
|
undo_stack.push(new AddPartCommand(tr("arc"), this, current_arc));
|
||||||
emit(partsAdded());
|
emit(partsAdded());
|
||||||
endCurrentBehavior(e);
|
|
||||||
break;
|
break;
|
||||||
case Circle:
|
case Circle:
|
||||||
if (qgiManager().manages(current_circle)) break;
|
if (qgiManager().manages(current_circle)) break;
|
||||||
current_circle -> setRect(current_circle -> rect().normalized());
|
current_circle -> setRect(current_circle -> rect().normalized());
|
||||||
undo_stack.push(new AddPartCommand(tr("cercle"), this, current_circle));
|
undo_stack.push(new AddPartCommand(tr("cercle"), this, current_circle));
|
||||||
emit(partsAdded());
|
emit(partsAdded());
|
||||||
endCurrentBehavior(e);
|
|
||||||
break;
|
break;
|
||||||
case Terminal:
|
case Terminal:
|
||||||
terminal = new PartTerminal(element_editor, 0, this);
|
terminal = new PartTerminal(element_editor, 0, this);
|
||||||
terminal -> setPos(event_pos);
|
terminal -> setPos(e -> scenePos());
|
||||||
undo_stack.push(new AddPartCommand(tr("borne"), this, terminal));
|
undo_stack.push(new AddPartCommand(tr("borne"), this, terminal));
|
||||||
emit(partsAdded());
|
emit(partsAdded());
|
||||||
endCurrentBehavior(e);
|
|
||||||
break;
|
break;
|
||||||
case Text:
|
case Text:
|
||||||
text = new PartText(element_editor, 0, this);
|
text = new PartText(element_editor, 0, this);
|
||||||
text -> setPos(event_pos);
|
text -> setPos(e -> scenePos());
|
||||||
undo_stack.push(new AddPartCommand(tr("texte"), this, text));
|
undo_stack.push(new AddPartCommand(tr("texte"), this, text));
|
||||||
emit(partsAdded());
|
emit(partsAdded());
|
||||||
endCurrentBehavior(e);
|
|
||||||
break;
|
break;
|
||||||
case TextField:
|
case TextField:
|
||||||
textfield = new PartTextField(element_editor, 0, this);
|
textfield = new PartTextField(element_editor, 0, this);
|
||||||
textfield -> setPos(event_pos);
|
textfield -> setPos(e -> scenePos());
|
||||||
undo_stack.push(new AddPartCommand(tr("champ de texte"), this, textfield));
|
undo_stack.push(new AddPartCommand(tr("champ de texte"), this, textfield));
|
||||||
emit(partsAdded());
|
emit(partsAdded());
|
||||||
endCurrentBehavior(e);
|
|
||||||
break;
|
break;
|
||||||
case Normal:
|
case Normal:
|
||||||
default:
|
default:
|
||||||
|
QGraphicsScene::mouseReleaseEvent(e);
|
||||||
// detecte les deplacements de parties
|
// detecte les deplacements de parties
|
||||||
if (!selectedItems().isEmpty() && moving_parts_) {
|
if (!selectedItems().isEmpty()) {
|
||||||
QPointF movement = selectedItems().first() -> scenePos() - fsi_pos;
|
QPointF movement = selectedItems().first() -> scenePos() - fsi_pos;
|
||||||
if (!movement.isNull()) {
|
if (!movement.isNull()) {
|
||||||
undo_stack.push(new MovePartsCommand(movement, this, selectedItems()));
|
undo_stack.push(new MovePartsCommand(movement, this, selectedItems()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QGraphicsScene::mouseReleaseEvent(e);
|
|
||||||
moving_parts_ = false;
|
|
||||||
}
|
}
|
||||||
} else if (e -> button() & Qt::RightButton) {
|
} else if (e -> button() & Qt::RightButton) {
|
||||||
if (behavior == Polygon && current_polygon != NULL) {
|
if (behavior == Polygon && current_polygon != NULL) {
|
||||||
|
behavior = Normal;
|
||||||
undo_stack.push(new AddPartCommand(tr("polygone"), this, current_polygon));
|
undo_stack.push(new AddPartCommand(tr("polygone"), this, current_polygon));
|
||||||
current_polygon = NULL;
|
current_polygon = NULL;
|
||||||
emit(partsAdded());
|
emit(partsAdded());
|
||||||
endCurrentBehavior(e);
|
emit(needNormalMode());
|
||||||
} else QGraphicsScene::mouseReleaseEvent(e);
|
} else QGraphicsScene::mouseReleaseEvent(e);
|
||||||
} else QGraphicsScene::mouseReleaseEvent(e);
|
} else QGraphicsScene::mouseReleaseEvent(e);
|
||||||
}
|
}
|
||||||
@@ -399,10 +317,6 @@ void ElementScene::drawBackground(QPainter *p, const QRectF &r) {
|
|||||||
p -> setBrush(Qt::NoBrush);
|
p -> setBrush(Qt::NoBrush);
|
||||||
p -> drawRect(drawable_area);
|
p -> drawRect(drawable_area);
|
||||||
|
|
||||||
// on dessine un point de la grille sur 10
|
|
||||||
int drawn_x_grid = x_grid * 10;
|
|
||||||
int drawn_y_grid = y_grid * 10;
|
|
||||||
|
|
||||||
if (r.width() < 2500 && r.height() < 2500) {
|
if (r.width() < 2500 && r.height() < 2500) {
|
||||||
// dessine les points de la grille
|
// dessine les points de la grille
|
||||||
p -> setPen(Qt::black);
|
p -> setPen(Qt::black);
|
||||||
@@ -411,12 +325,12 @@ void ElementScene::drawBackground(QPainter *p, const QRectF &r) {
|
|||||||
qreal limite_y = r.y() + r.height();
|
qreal limite_y = r.y() + r.height();
|
||||||
|
|
||||||
int g_x = (int)ceil(r.x());
|
int g_x = (int)ceil(r.x());
|
||||||
while (g_x % drawn_x_grid) ++ g_x;
|
while (g_x % xGrid) ++ g_x;
|
||||||
int g_y = (int)ceil(r.y());
|
int g_y = (int)ceil(r.y());
|
||||||
while (g_y % drawn_y_grid) ++ g_y;
|
while (g_y % yGrid) ++ g_y;
|
||||||
|
|
||||||
for (int gx = g_x ; gx < limite_x ; gx += drawn_x_grid) {
|
for (int gx = g_x ; gx < limite_x ; gx += xGrid) {
|
||||||
for (int gy = g_y ; gy < limite_y ; gy += drawn_y_grid) {
|
for (int gy = g_y ; gy < limite_y ; gy += yGrid) {
|
||||||
p -> drawPoint(gx, gy);
|
p -> drawPoint(gx, gy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -444,50 +358,11 @@ void ElementScene::drawForeground(QPainter *p, const QRectF &) {
|
|||||||
p -> restore();
|
p -> restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
A partir d'un evenement souris, cette methode regarde si la touche shift est
|
|
||||||
enfoncee ou non. Si oui, elle laisse le comportement en cours (cercle,
|
|
||||||
texte, polygone, ...). Si non, elle repasse en mode normal / selection.
|
|
||||||
@param e objet decrivant l'evenement souris
|
|
||||||
*/
|
|
||||||
void ElementScene::endCurrentBehavior(const QGraphicsSceneMouseEvent *event) {
|
|
||||||
if (!(event -> modifiers() & Qt::ShiftModifier)) {
|
|
||||||
// la touche Shift n'est pas enfoncee : on demande le mode normal
|
|
||||||
behavior = Normal;
|
|
||||||
emit(needNormalMode());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return la taille horizontale de la grille
|
|
||||||
*/
|
|
||||||
int ElementScene::xGrid() const {
|
|
||||||
return(x_grid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return la taille verticale de la grille
|
|
||||||
*/
|
|
||||||
int ElementScene::yGrid() const {
|
|
||||||
return(y_grid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@param x_grid Taille horizontale de la grille
|
|
||||||
@param y_grid Taille verticale de la grille
|
|
||||||
*/
|
|
||||||
void ElementScene::setGrid(int x_g, int y_g) {
|
|
||||||
x_grid = x_g ? x_g : 1;
|
|
||||||
y_grid = y_g ? y_g : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Exporte l'element en XML
|
Exporte l'element en XML
|
||||||
@param diagram Booleen (a vrai par defaut) indiquant si le XML genere doit
|
|
||||||
representer tout l'element ou seulement les elements selectionnes
|
|
||||||
@return un document XML decrivant l'element
|
@return un document XML decrivant l'element
|
||||||
*/
|
*/
|
||||||
const QDomDocument ElementScene::toXml(bool all_parts) const {
|
const QDomDocument ElementScene::toXml() const {
|
||||||
// document XML
|
// document XML
|
||||||
QDomDocument xml_document;
|
QDomDocument xml_document;
|
||||||
|
|
||||||
@@ -508,8 +383,6 @@ const QDomDocument ElementScene::toXml(bool all_parts) const {
|
|||||||
QDomElement description = xml_document.createElement("description");
|
QDomElement description = xml_document.createElement("description");
|
||||||
// description de l'element
|
// description de l'element
|
||||||
foreach(QGraphicsItem *qgi, zItems(true)) {
|
foreach(QGraphicsItem *qgi, zItems(true)) {
|
||||||
// si l'export ne concerne que la selection, on ignore les parties non selectionnees
|
|
||||||
if (!all_parts && !qgi -> isSelected()) continue;
|
|
||||||
if (CustomElementPart *ce = dynamic_cast<CustomElementPart *>(qgi)) {
|
if (CustomElementPart *ce = dynamic_cast<CustomElementPart *>(qgi)) {
|
||||||
if (ce -> isUseless()) continue;
|
if (ce -> isUseless()) continue;
|
||||||
description.appendChild(ce -> toXml(xml_document));
|
description.appendChild(ce -> toXml(xml_document));
|
||||||
@@ -522,90 +395,91 @@ const QDomDocument ElementScene::toXml(bool all_parts) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@param xml_document un document XML decrivant un element
|
Lit un element depuis un document XML
|
||||||
@return le boundingRect du contenu de l'element
|
|
||||||
*/
|
|
||||||
QRectF ElementScene::boundingRectFromXml(const QDomDocument &xml_document) {
|
|
||||||
// charge les parties depuis le document XML
|
|
||||||
ElementContent loaded_content = loadContent(xml_document);
|
|
||||||
if (loaded_content.isEmpty()) return(QRectF());
|
|
||||||
|
|
||||||
// calcule le boundingRect
|
|
||||||
QRectF bounding_rect = elementContentBoundingRect(loaded_content);
|
|
||||||
|
|
||||||
// detruit les parties chargees
|
|
||||||
qDeleteAll(loaded_content);
|
|
||||||
|
|
||||||
return(bounding_rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Importe l'element decrit dans un document XML. Si une position est
|
|
||||||
precisee, les elements importes sont positionnes de maniere a ce que le
|
|
||||||
coin superieur gauche du plus petit rectangle pouvant les entourant tous
|
|
||||||
(le bounding rect) soit a cette position.
|
|
||||||
@param xml_document un document XML decrivant l'element
|
@param xml_document un document XML decrivant l'element
|
||||||
@param position La position des parties importees
|
|
||||||
@param consider_informations Si vrai, les informations complementaires
|
|
||||||
(dimensions, hotspot, etc.) seront prises en compte
|
|
||||||
@param content_ptr si ce pointeur vers un ElementContent est different de 0,
|
|
||||||
il sera rempli avec le contenu ajoute a l'element par le fromXml
|
|
||||||
@return true si l'import a reussi, false sinon
|
|
||||||
*/
|
*/
|
||||||
void ElementScene::fromXml(
|
void ElementScene::fromXml(const QDomDocument &xml_document) {
|
||||||
const QDomDocument &xml_document,
|
|
||||||
const QPointF &position,
|
|
||||||
bool consider_informations,
|
|
||||||
ElementContent *content_ptr
|
|
||||||
) {
|
|
||||||
QString error_message;
|
QString error_message;
|
||||||
bool state = true;
|
bool state = true;
|
||||||
|
|
||||||
// prend en compte les informations de l'element
|
// la racine est supposee etre une definition d'element
|
||||||
if (consider_informations) {
|
QDomElement root = xml_document.documentElement();
|
||||||
state = applyInformations(xml_document, &error_message);
|
if (root.tagName() != "definition" || root.attribute("type") != "element") {
|
||||||
|
state = false;
|
||||||
|
error_message = tr("Ce document XML n'est pas une definition d'\351l\351ment.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// dimensions et hotspot
|
||||||
|
if (state) {
|
||||||
|
// ces attributs doivent etre presents et valides
|
||||||
|
int w, h, hot_x, hot_y;
|
||||||
|
if (
|
||||||
|
!QET::attributeIsAnInteger(root, QString("width"), &w) ||\
|
||||||
|
!QET::attributeIsAnInteger(root, QString("height"), &h) ||\
|
||||||
|
!QET::attributeIsAnInteger(root, QString("hotspot_x"), &hot_x) ||\
|
||||||
|
!QET::attributeIsAnInteger(root, QString("hotspot_y"), &hot_y)
|
||||||
|
) {
|
||||||
|
state = false;
|
||||||
|
error_message = tr("Les dimensions ou le point de saisie ne sont pas valides.");
|
||||||
|
} else {
|
||||||
|
setWidth(w);
|
||||||
|
setHeight(h);
|
||||||
|
setHotspot(QPoint(hot_x, hot_y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// orientations et connexions internes
|
||||||
|
if (state) {
|
||||||
|
internal_connections = (root.attribute("ic") == "true");
|
||||||
|
|
||||||
|
if (!ori.fromString(root.attribute("orientation"))) {
|
||||||
|
state = false;
|
||||||
|
error_message = tr("Les orientations ne sont pas valides.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// extrait les noms de la definition XML
|
||||||
|
if (state) {
|
||||||
|
_names.fromXml(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
// parcours des enfants de la definition : parties de l'element
|
// parcours des enfants de la definition : parties de l'element
|
||||||
if (state) {
|
if (state) {
|
||||||
ElementContent loaded_content = loadContent(xml_document, &error_message);
|
for (QDomNode node = root.firstChild() ; !node.isNull() ; node = node.nextSibling()) {
|
||||||
if (position != QPointF()) {
|
QDomElement elmts = node.toElement();
|
||||||
addContentAtPos(loaded_content, position, &error_message);
|
if (elmts.isNull()) continue;
|
||||||
} else {
|
if (elmts.tagName() == "description") {
|
||||||
addContent(loaded_content, &error_message);
|
// gestion de la description graphique de l'element
|
||||||
}
|
// = parcours des differentes parties du dessin
|
||||||
|
int z = 1;
|
||||||
// renvoie le contenu ajoute a l'element
|
for (QDomNode n = node.firstChild() ; !n.isNull() ; n = n.nextSibling()) {
|
||||||
if (content_ptr) {
|
QDomElement qde = n.toElement();
|
||||||
*content_ptr = loaded_content;
|
if (qde.isNull()) continue;
|
||||||
|
CustomElementPart *cep;
|
||||||
|
if (qde.tagName() == "line") cep = new PartLine (element_editor, 0, this);
|
||||||
|
else if (qde.tagName() == "ellipse") cep = new PartEllipse (element_editor, 0, this);
|
||||||
|
else if (qde.tagName() == "circle") cep = new PartCircle (element_editor, 0, this);
|
||||||
|
else if (qde.tagName() == "polygon") cep = new PartPolygon (element_editor, 0, this);
|
||||||
|
else if (qde.tagName() == "terminal") cep = new PartTerminal (element_editor, 0, this);
|
||||||
|
else if (qde.tagName() == "text") cep = new PartText (element_editor, 0, this);
|
||||||
|
else if (qde.tagName() == "input") cep = new PartTextField(element_editor, 0, this);
|
||||||
|
else if (qde.tagName() == "arc") cep = new PartArc (element_editor, 0, this);
|
||||||
|
else continue;
|
||||||
|
if (QGraphicsItem *qgi = dynamic_cast<QGraphicsItem *>(cep)) qgi -> setZValue(z++);
|
||||||
|
cep -> fromXml(qde);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
@return le rectangle representant les limites de l'element.
|
|
||||||
Ce rectangle a pour dimensions la taille de l'element et pour coin
|
|
||||||
superieur gauche les coordonnees opposees du hotspot.
|
|
||||||
*/
|
|
||||||
QRectF ElementScene::borderRect() const {
|
|
||||||
return(QRectF(-_hotspot, QSizeF(width(), height())));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return un rectangle englobant toutes les parties ainsi que le
|
@return un rectangle englobant toutes les parties ainsi que le
|
||||||
"bounding rect" de l'element
|
"bounding rect" de l'element
|
||||||
*/
|
*/
|
||||||
QRectF ElementScene::sceneContent() const {
|
QRectF ElementScene::sceneContent() const {
|
||||||
return(itemsBoundingRect().unite(borderRect()));
|
return(itemsBoundingRect().unite(QRectF(-_hotspot, QSizeF(width(), height()))));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return true si toutes les parties graphiques composant l'element sont
|
|
||||||
integralement contenues dans le rectangle representant les limites de
|
|
||||||
l'element.
|
|
||||||
*/
|
|
||||||
bool ElementScene::borderContainsEveryParts() const {
|
|
||||||
return(borderRect().contains(itemsBoundingRect()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -622,64 +496,6 @@ QGIManager &ElementScene::qgiManager() {
|
|||||||
return(qgi_manager);
|
return(qgi_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
@return true si le presse-papier semble contenir un element
|
|
||||||
*/
|
|
||||||
bool ElementScene::clipboardMayContainElement() {
|
|
||||||
QString clipboard_text = QApplication::clipboard() -> text().trimmed();
|
|
||||||
bool may_be_element = clipboard_text.startsWith("<definition") && clipboard_text.endsWith("</definition>");
|
|
||||||
return(may_be_element);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@param clipboard_content chaine de caractere, provenant vraisemblablement du
|
|
||||||
presse-papier.
|
|
||||||
@return true si clipboard_content a ete copie depuis cet element.
|
|
||||||
*/
|
|
||||||
bool ElementScene::wasCopiedFromThisElement(const QString &clipboard_content) {
|
|
||||||
return(clipboard_content == last_copied_);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Gere le fait de couper la selection = l'exporter en XML dans le
|
|
||||||
presse-papier puis la supprimer.
|
|
||||||
*/
|
|
||||||
void ElementScene::cut() {
|
|
||||||
copy();
|
|
||||||
QList<QGraphicsItem *> cut_content = selectedItems();
|
|
||||||
clearSelection();
|
|
||||||
undoStack().push(new CutPartsCommand(this, cut_content));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Gere le fait de copier la selection = l'exporter en XML dans le
|
|
||||||
presse-papier.
|
|
||||||
*/
|
|
||||||
void ElementScene::copy() {
|
|
||||||
// accede au presse-papier
|
|
||||||
QClipboard *clipboard = QApplication::clipboard();
|
|
||||||
|
|
||||||
// genere la description XML de la selection
|
|
||||||
QString clipboard_content = toXml(false).toString(4);
|
|
||||||
|
|
||||||
// met la description XML dans le presse-papier
|
|
||||||
if (clipboard -> supportsSelection()) {
|
|
||||||
clipboard -> setText(clipboard_content, QClipboard::Selection);
|
|
||||||
}
|
|
||||||
clipboard -> setText(clipboard_content);
|
|
||||||
|
|
||||||
// retient le dernier contenu copie
|
|
||||||
last_copied_ = clipboard_content;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Gere le fait de coller le contenu du presse-papier = l'importer dans le
|
|
||||||
presse-papier a une position donnee.
|
|
||||||
*/
|
|
||||||
void ElementScene::paste() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Selectionne tout
|
Selectionne tout
|
||||||
*/
|
*/
|
||||||
@@ -720,9 +536,10 @@ void ElementScene::slot_delete() {
|
|||||||
*/
|
*/
|
||||||
void ElementScene::slot_editSizeHotSpot() {
|
void ElementScene::slot_editSizeHotSpot() {
|
||||||
// cree un dialogue
|
// cree un dialogue
|
||||||
QDialog dialog_sh(element_editor);
|
QDialog dialog_sh;
|
||||||
dialog_sh.setModal(true);
|
dialog_sh.setModal(true);
|
||||||
dialog_sh.setWindowTitle(tr("\311diter la taille et le point de saisie", "window title"));
|
dialog_sh.setMinimumSize(400, 230);
|
||||||
|
dialog_sh.setWindowTitle(tr("\311diter la taille et le point de saisie"));
|
||||||
QVBoxLayout *dialog_layout = new QVBoxLayout(&dialog_sh);
|
QVBoxLayout *dialog_layout = new QVBoxLayout(&dialog_sh);
|
||||||
|
|
||||||
// ajoute un HotspotEditor au dialogue
|
// ajoute un HotspotEditor au dialogue
|
||||||
@@ -759,10 +576,10 @@ void ElementScene::slot_editSizeHotSpot() {
|
|||||||
void ElementScene::slot_editOrientations() {
|
void ElementScene::slot_editOrientations() {
|
||||||
|
|
||||||
// cree un dialogue
|
// cree un dialogue
|
||||||
QDialog dialog_ori(element_editor);
|
QDialog dialog_ori;
|
||||||
dialog_ori.setModal(true);
|
dialog_ori.setModal(true);
|
||||||
dialog_ori.setMinimumSize(400, 260);
|
dialog_ori.setMinimumSize(400, 260);
|
||||||
dialog_ori.setWindowTitle(tr("\311diter les orientations", "window title"));
|
dialog_ori.setWindowTitle(tr("\311diter les orientations"));
|
||||||
QVBoxLayout *dialog_layout = new QVBoxLayout(&dialog_ori);
|
QVBoxLayout *dialog_layout = new QVBoxLayout(&dialog_ori);
|
||||||
|
|
||||||
// ajoute un champ explicatif au dialogue
|
// ajoute un champ explicatif au dialogue
|
||||||
@@ -805,10 +622,10 @@ void ElementScene::slot_editOrientations() {
|
|||||||
void ElementScene::slot_editNames() {
|
void ElementScene::slot_editNames() {
|
||||||
|
|
||||||
// cree un dialogue
|
// cree un dialogue
|
||||||
QDialog dialog(element_editor);
|
QDialog dialog;
|
||||||
dialog.setModal(true);
|
dialog.setModal(true);
|
||||||
dialog.setMinimumSize(400, 330);
|
dialog.setMinimumSize(400, 330);
|
||||||
dialog.setWindowTitle(tr("\311diter les noms", "window title"));
|
dialog.setWindowTitle(tr("\311diter les noms"));
|
||||||
QVBoxLayout *dialog_layout = new QVBoxLayout(&dialog);
|
QVBoxLayout *dialog_layout = new QVBoxLayout(&dialog);
|
||||||
|
|
||||||
// ajoute un champ explicatif au dialogue
|
// ajoute un champ explicatif au dialogue
|
||||||
@@ -900,30 +717,6 @@ QList<QGraphicsItem *> ElementScene::zItems(bool include_terminals) const {
|
|||||||
return(all_items_list);
|
return(all_items_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
@return les parties graphiques selectionnees
|
|
||||||
*/
|
|
||||||
ElementContent ElementScene::selectedContent() const {
|
|
||||||
ElementContent content;
|
|
||||||
foreach(QGraphicsItem *qgi, zItems(true)) {
|
|
||||||
if (qgi -> isSelected()) content << qgi;
|
|
||||||
}
|
|
||||||
return(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@param to_paste Rectangle englobant les parties a coller
|
|
||||||
@return le rectangle ou il faudra coller ces parties
|
|
||||||
*/
|
|
||||||
void ElementScene::getPasteArea(const QRectF &to_paste) {
|
|
||||||
// on le dessine sur la scene
|
|
||||||
paste_area_ -> setRect(to_paste);
|
|
||||||
addItem(paste_area_);
|
|
||||||
|
|
||||||
// on passe la scene en mode "recherche de zone pour copier/coller"
|
|
||||||
behavior = PasteArea;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Supprime les parties de l'element et les objets d'annulations.
|
Supprime les parties de l'element et les objets d'annulations.
|
||||||
Les autres caracteristiques sont conservees.
|
Les autres caracteristiques sont conservees.
|
||||||
@@ -937,200 +730,3 @@ void ElementScene::reset() {
|
|||||||
qgiManager().release(qgi);
|
qgiManager().release(qgi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
@param content Contenu ( = parties) d'un element
|
|
||||||
@return le boundingRect de ces parties, exprime dans les coordonnes de la
|
|
||||||
scene
|
|
||||||
*/
|
|
||||||
QRectF ElementScene::elementContentBoundingRect(const ElementContent &content) {
|
|
||||||
QRectF bounding_rect;
|
|
||||||
foreach(QGraphicsItem *qgi, content) {
|
|
||||||
bounding_rect |= qgi -> sceneBoundingRect();
|
|
||||||
}
|
|
||||||
return(bounding_rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Applique les informations (dimensions, hostpot, orientations, connexions
|
|
||||||
internes et noms) contenu dans un document XML.
|
|
||||||
@param xml_document Document XML a analyser
|
|
||||||
@param error_message pointeur vers une QString ; si error_message est
|
|
||||||
different de 0, un message d'erreur sera stocke dedans si necessaire
|
|
||||||
@return true si la lecture et l'application des informations s'est bien
|
|
||||||
passee, false sinon.
|
|
||||||
*/
|
|
||||||
bool ElementScene::applyInformations(const QDomDocument &xml_document, QString *error_message) {
|
|
||||||
// la racine est supposee etre une definition d'element
|
|
||||||
QDomElement root = xml_document.documentElement();
|
|
||||||
if (root.tagName() != "definition" || root.attribute("type") != "element") {
|
|
||||||
if (error_message) {
|
|
||||||
*error_message = tr("Ce document XML n'est pas une d\351finition d'\351l\351ment.", "error message");
|
|
||||||
}
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// dimensions et hotspot : ces attributs doivent etre presents et valides
|
|
||||||
int w, h, hot_x, hot_y;
|
|
||||||
if (
|
|
||||||
!QET::attributeIsAnInteger(root, QString("width"), &w) ||\
|
|
||||||
!QET::attributeIsAnInteger(root, QString("height"), &h) ||\
|
|
||||||
!QET::attributeIsAnInteger(root, QString("hotspot_x"), &hot_x) ||\
|
|
||||||
!QET::attributeIsAnInteger(root, QString("hotspot_y"), &hot_y)
|
|
||||||
) {
|
|
||||||
if (error_message) {
|
|
||||||
*error_message = tr("Les dimensions ou le point de saisie ne sont pas valides.", "error message");
|
|
||||||
}
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
setWidth(w);
|
|
||||||
setHeight(h);
|
|
||||||
setHotspot(QPoint(hot_x, hot_y));
|
|
||||||
|
|
||||||
// orientations
|
|
||||||
internal_connections = (root.attribute("ic") == "true");
|
|
||||||
|
|
||||||
// connexions internes
|
|
||||||
if (!ori.fromString(root.attribute("orientation"))) {
|
|
||||||
if (error_message) {
|
|
||||||
*error_message = tr("Les orientations ne sont pas valides.", "error message");
|
|
||||||
}
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// extrait les noms de la definition XML
|
|
||||||
_names.fromXml(root);
|
|
||||||
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Par le document XML xml_document et retourne le contenu ( = liste de
|
|
||||||
parties) correspondant.
|
|
||||||
@param xml_document Document XML a analyser
|
|
||||||
@param error_message pointeur vers une QString ; si error_message est
|
|
||||||
different de 0, un message d'erreur sera stocke dedans si necessaire
|
|
||||||
*/
|
|
||||||
ElementContent ElementScene::loadContent(const QDomDocument &xml_document, QString *error_message) {
|
|
||||||
ElementContent loaded_parts;
|
|
||||||
|
|
||||||
// la racine est supposee etre une definition d'element
|
|
||||||
QDomElement root = xml_document.documentElement();
|
|
||||||
if (root.tagName() != "definition" || root.attribute("type") != "element") {
|
|
||||||
if (error_message) {
|
|
||||||
*error_message = tr("Ce document XML n'est pas une d\351finition d'\351l\351ment.", "error message");
|
|
||||||
}
|
|
||||||
return(loaded_parts);
|
|
||||||
}
|
|
||||||
|
|
||||||
// chargement de la description graphique de l'element
|
|
||||||
for (QDomNode node = root.firstChild() ; !node.isNull() ; node = node.nextSibling()) {
|
|
||||||
QDomElement elmts = node.toElement();
|
|
||||||
if (elmts.isNull()) continue;
|
|
||||||
if (elmts.tagName() == "description") {
|
|
||||||
|
|
||||||
// = parcours des differentes parties du dessin
|
|
||||||
int z = 1;
|
|
||||||
for (QDomNode n = node.firstChild() ; !n.isNull() ; n = n.nextSibling()) {
|
|
||||||
QDomElement qde = n.toElement();
|
|
||||||
if (qde.isNull()) continue;
|
|
||||||
CustomElementPart *cep;
|
|
||||||
if (qde.tagName() == "line") cep = new PartLine (element_editor, 0, 0);
|
|
||||||
else if (qde.tagName() == "rect") cep = new PartRectangle(element_editor, 0, 0);
|
|
||||||
else if (qde.tagName() == "ellipse") cep = new PartEllipse (element_editor, 0, 0);
|
|
||||||
else if (qde.tagName() == "circle") cep = new PartCircle (element_editor, 0, 0);
|
|
||||||
else if (qde.tagName() == "polygon") cep = new PartPolygon (element_editor, 0, 0);
|
|
||||||
else if (qde.tagName() == "terminal") cep = new PartTerminal (element_editor, 0, 0);
|
|
||||||
else if (qde.tagName() == "text") cep = new PartText (element_editor, 0, 0);
|
|
||||||
else if (qde.tagName() == "input") cep = new PartTextField(element_editor, 0, 0);
|
|
||||||
else if (qde.tagName() == "arc") cep = new PartArc (element_editor, 0, 0);
|
|
||||||
else continue;
|
|
||||||
if (QGraphicsItem *qgi = dynamic_cast<QGraphicsItem *>(cep)) {
|
|
||||||
qgi -> setZValue(z++);
|
|
||||||
loaded_parts << qgi;
|
|
||||||
}
|
|
||||||
cep -> fromXml(qde);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return(loaded_parts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Ajoute le contenu content a cet element
|
|
||||||
@param content contenu ( = liste de parties) a charger
|
|
||||||
@param error_message pointeur vers une QString ; si error_message est
|
|
||||||
different de 0, un message d'erreur sera stocke dedans si necessaire
|
|
||||||
@return Le contenu ajoute
|
|
||||||
*/
|
|
||||||
ElementContent ElementScene::addContent(const ElementContent &content, QString */*error_message*/) {
|
|
||||||
foreach(QGraphicsItem *part, content) {
|
|
||||||
addItem(part);
|
|
||||||
}
|
|
||||||
return(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Ajoute le contenu content a cet element
|
|
||||||
@param content contenu ( = liste de parties) a charger
|
|
||||||
@param pos Position du coin superieur gauche du contenu apres avoir ete ajoute
|
|
||||||
@param error_message pointeur vers une QString ; si error_message est
|
|
||||||
different de 0, un message d'erreur sera stocke dedans si necessaire
|
|
||||||
@return Le contenu ajoute
|
|
||||||
*/
|
|
||||||
ElementContent ElementScene::addContentAtPos(const ElementContent &content, const QPointF &pos, QString */*error_message*/) {
|
|
||||||
// calcule le boundingRect du contenu a ajouter
|
|
||||||
QRectF bounding_rect = elementContentBoundingRect(content);
|
|
||||||
|
|
||||||
// en deduit le decalage a appliquer aux parties pour les poser au point demander
|
|
||||||
QPointF offset = pos - bounding_rect.topLeft();
|
|
||||||
|
|
||||||
// ajoute les parties avec le decalage adequat
|
|
||||||
foreach(QGraphicsItem *part, content) {
|
|
||||||
part -> setPos(part -> pos() + offset);
|
|
||||||
addItem(part);
|
|
||||||
}
|
|
||||||
return(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Initialise la zone de collage
|
|
||||||
*/
|
|
||||||
void ElementScene::initPasteArea() {
|
|
||||||
paste_area_ = new QGraphicsRectItem();
|
|
||||||
paste_area_ -> setZValue(1000000);
|
|
||||||
|
|
||||||
QPen paste_area_pen;
|
|
||||||
paste_area_pen.setStyle(Qt::DashDotLine);
|
|
||||||
paste_area_pen.setColor(QColor(30, 56, 86, 255));
|
|
||||||
|
|
||||||
QBrush paste_area_brush;
|
|
||||||
paste_area_brush.setStyle(Qt::SolidPattern);
|
|
||||||
paste_area_brush.setColor(QColor(90, 167, 255, 64));
|
|
||||||
|
|
||||||
paste_area_ -> setPen(paste_area_pen);
|
|
||||||
paste_area_ -> setBrush(paste_area_brush);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Arrondit les coordonnees du point passees en parametre de facon a ce que ce
|
|
||||||
point soit aligne sur la grille.
|
|
||||||
@param point une reference vers un QPointF. Cet objet sera modifie.
|
|
||||||
|
|
||||||
*/
|
|
||||||
void ElementScene::snapToGrid(QPointF &point) {
|
|
||||||
point.rx() = qRound(point.x() / x_grid) * x_grid;
|
|
||||||
point.ry() = qRound(point.y() / y_grid) * y_grid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@param e Evenement souris
|
|
||||||
@return true s'il faut utiliser le snap-to-grid
|
|
||||||
Typiquement, cette methode retourne true si l'evenement souris se produit
|
|
||||||
sans la touche Ctrl enfoncee.
|
|
||||||
*/
|
|
||||||
bool ElementScene::mustSnapToGrid(QGraphicsSceneMouseEvent *e) {
|
|
||||||
return(!(e -> modifiers() & Qt::ControlModifier));
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -22,10 +22,8 @@
|
|||||||
#include "nameslistwidget.h"
|
#include "nameslistwidget.h"
|
||||||
#include "orientationsetwidget.h"
|
#include "orientationsetwidget.h"
|
||||||
#include "qgimanager.h"
|
#include "qgimanager.h"
|
||||||
#include "elementcontent.h"
|
|
||||||
class QETElementEditor;
|
class QETElementEditor;
|
||||||
class PartLine;
|
class PartLine;
|
||||||
class PartRectangle;
|
|
||||||
class PartEllipse;
|
class PartEllipse;
|
||||||
class PartCircle;
|
class PartCircle;
|
||||||
class PartPolygon;
|
class PartPolygon;
|
||||||
@@ -40,7 +38,7 @@ class ElementScene : public QGraphicsScene {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
// enum
|
// enum
|
||||||
enum Behavior { Normal, Line, Rectangle, Circle, Ellipse, Polygon, Text, Terminal, Arc, TextField, PasteArea };
|
enum Behavior { Normal, Line, Circle, Ellipse, Polygon, Text, Terminal, Arc, TextField };
|
||||||
|
|
||||||
// constructeurs, destructeur
|
// constructeurs, destructeur
|
||||||
public:
|
public:
|
||||||
@@ -51,6 +49,10 @@ class ElementScene : public QGraphicsScene {
|
|||||||
ElementScene(const ElementScene &);
|
ElementScene(const ElementScene &);
|
||||||
|
|
||||||
// attributs
|
// attributs
|
||||||
|
public:
|
||||||
|
static const int xGrid; ///< Taille horizontale de la grille
|
||||||
|
static const int yGrid; ///< Taille verticale de la grille
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// longueur de l'element en dizaines de pixels
|
/// longueur de l'element en dizaines de pixels
|
||||||
uint _width;
|
uint _width;
|
||||||
@@ -70,31 +72,16 @@ class ElementScene : public QGraphicsScene {
|
|||||||
QUndoStack undo_stack;
|
QUndoStack undo_stack;
|
||||||
/// Position du premier item selectionne (utilise pour annuler les deplacements)
|
/// Position du premier item selectionne (utilise pour annuler les deplacements)
|
||||||
QPointF fsi_pos;
|
QPointF fsi_pos;
|
||||||
QPointF moving_press_pos;
|
|
||||||
bool moving_parts_;
|
|
||||||
|
|
||||||
/// Variables relatives a la gestion du dessin des parties sur la scene
|
/// Variables relatives a la gestion du dessin des parties sur la scene
|
||||||
Behavior behavior;
|
Behavior behavior;
|
||||||
PartLine *current_line;
|
PartLine *current_line;
|
||||||
PartRectangle *current_rectangle;
|
|
||||||
PartEllipse *current_ellipse;
|
PartEllipse *current_ellipse;
|
||||||
PartCircle *current_circle;
|
PartCircle *current_circle;
|
||||||
PartPolygon *current_polygon;
|
PartPolygon *current_polygon;
|
||||||
PartArc *current_arc;
|
PartArc *current_arc;
|
||||||
QETElementEditor *element_editor;
|
QETElementEditor *element_editor;
|
||||||
|
|
||||||
/// Variables relatives a la gestion de la zone de collage sur la scene
|
|
||||||
QGraphicsRectItem *paste_area_;
|
|
||||||
QRectF defined_paste_area_;
|
|
||||||
|
|
||||||
/// Variables relatives au copier-coller avec decalage
|
|
||||||
QString last_copied_;
|
|
||||||
|
|
||||||
///< Taille horizontale de la grille
|
|
||||||
int x_grid;
|
|
||||||
///< Taille verticale de la grille
|
|
||||||
int y_grid;
|
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
public:
|
public:
|
||||||
void setWidth(const uint &);
|
void setWidth(const uint &);
|
||||||
@@ -109,26 +96,13 @@ class ElementScene : public QGraphicsScene {
|
|||||||
void setOrientations(const OrientationSet &);
|
void setOrientations(const OrientationSet &);
|
||||||
bool internalConnections();
|
bool internalConnections();
|
||||||
void setInternalConnections(bool);
|
void setInternalConnections(bool);
|
||||||
virtual int xGrid() const;
|
virtual const QDomDocument toXml() const;
|
||||||
virtual int yGrid() const;
|
virtual void fromXml(const QDomDocument &);
|
||||||
virtual void setGrid(int, int);
|
|
||||||
virtual const QDomDocument toXml(bool = true) const;
|
|
||||||
virtual QRectF boundingRectFromXml(const QDomDocument &);
|
|
||||||
virtual void fromXml(const QDomDocument &, const QPointF & = QPointF(), bool = true, ElementContent * = 0);
|
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
virtual QList<QGraphicsItem *> zItems(bool = false) const;
|
virtual QList<QGraphicsItem *> zItems(bool = false) const;
|
||||||
virtual ElementContent selectedContent() const;
|
|
||||||
virtual void getPasteArea(const QRectF &);
|
|
||||||
QRectF borderRect() const;
|
|
||||||
QRectF sceneContent() const;
|
QRectF sceneContent() const;
|
||||||
bool borderContainsEveryParts() const;
|
|
||||||
QUndoStack &undoStack();
|
QUndoStack &undoStack();
|
||||||
QGIManager &qgiManager();
|
QGIManager &qgiManager();
|
||||||
static bool clipboardMayContainElement();
|
|
||||||
bool wasCopiedFromThisElement(const QString &);
|
|
||||||
void cut();
|
|
||||||
void copy();
|
|
||||||
void paste();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *);
|
||||||
@@ -136,22 +110,10 @@ class ElementScene : public QGraphicsScene {
|
|||||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *);
|
||||||
virtual void drawBackground(QPainter *, const QRectF &);
|
virtual void drawBackground(QPainter *, const QRectF &);
|
||||||
virtual void drawForeground(QPainter *, const QRectF &);
|
virtual void drawForeground(QPainter *, const QRectF &);
|
||||||
virtual void endCurrentBehavior(const QGraphicsSceneMouseEvent *);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QRectF elementContentBoundingRect(const ElementContent &);
|
|
||||||
bool applyInformations(const QDomDocument &, QString * = 0);
|
|
||||||
ElementContent loadContent(const QDomDocument &, QString * = 0);
|
|
||||||
ElementContent addContent(const ElementContent &, QString * = 0);
|
|
||||||
ElementContent addContentAtPos(const ElementContent &, const QPointF &, QString * = 0);
|
|
||||||
void initPasteArea();
|
|
||||||
void snapToGrid(QPointF &);
|
|
||||||
bool mustSnapToGrid(QGraphicsSceneMouseEvent *);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void slot_move();
|
void slot_move();
|
||||||
void slot_addLine();
|
void slot_addLine();
|
||||||
void slot_addRectangle();
|
|
||||||
void slot_addCircle();
|
void slot_addCircle();
|
||||||
void slot_addEllipse();
|
void slot_addEllipse();
|
||||||
void slot_addPolygon();
|
void slot_addPolygon();
|
||||||
@@ -183,8 +145,6 @@ class ElementScene : public QGraphicsScene {
|
|||||||
void partsRemoved();
|
void partsRemoved();
|
||||||
/// Signal emis lorsque la zValue d'une ou plusieurs parties change
|
/// Signal emis lorsque la zValue d'une ou plusieurs parties change
|
||||||
void partsZValueChanged();
|
void partsZValueChanged();
|
||||||
/// Signal emis lorsque l'utilisateur a fini de choisir une zone pour un copier/coller
|
|
||||||
void pasteAreaDefined(const QRectF &);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
128
editor/elementview.cpp
Normal file
128
editor/elementview.cpp
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2007 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "elementview.h"
|
||||||
|
/**
|
||||||
|
Constructeur
|
||||||
|
@param scene ElementScene visualisee par cette ElementView
|
||||||
|
@param parent QWidget parent de cette ElementView
|
||||||
|
*/
|
||||||
|
ElementView::ElementView(ElementScene *scene, QWidget *parent) :
|
||||||
|
QGraphicsView(scene, parent),
|
||||||
|
scene_(scene)
|
||||||
|
{
|
||||||
|
setInteractive(true);
|
||||||
|
setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||||
|
setResizeAnchor(QGraphicsView::AnchorUnderMouse);
|
||||||
|
zoomReset();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Destructeur
|
||||||
|
ElementView::~ElementView() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @return l'ElementScene visualisee par cette ElementView
|
||||||
|
ElementScene *ElementView::scene() const {
|
||||||
|
return(scene_);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Definit l'ElementScene visualisee par cette ElementView
|
||||||
|
@param s l'ElementScene visualisee par cette ElementView
|
||||||
|
*/
|
||||||
|
void ElementView::setScene(ElementScene *s) {
|
||||||
|
QGraphicsView::setScene(s);
|
||||||
|
scene_ = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Gere les evenements envoyes a la vue.
|
||||||
|
Methode reimplentee pour gerer le conflit de raccourcis avec Suppr
|
||||||
|
(supprimer une partie ou supprimer le caractere suivant)
|
||||||
|
@param e evenement a gerer
|
||||||
|
*/
|
||||||
|
bool ElementView::event(QEvent *e) {
|
||||||
|
if (e -> type() == QEvent::ShortcutOverride && scene_ -> focusItem()) {
|
||||||
|
e -> accept();
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
return(QGraphicsView::event(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Agrandit le schema (+33% = inverse des -25 % de zoomMoins())
|
||||||
|
*/
|
||||||
|
void ElementView::zoomIn() {
|
||||||
|
scale(4.0/3.0, 4.0/3.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Retrecit le schema (-25% = inverse des +33 % de zoomPlus())
|
||||||
|
*/
|
||||||
|
void ElementView::zoomOut() {
|
||||||
|
scale(0.75, 0.75);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Agrandit ou rectrecit le schema de facon a ce que tous les elements du
|
||||||
|
schema soient visibles a l'ecran. S'il n'y a aucun element sur le schema,
|
||||||
|
le zoom est reinitialise
|
||||||
|
*/
|
||||||
|
void ElementView::zoomFit() {
|
||||||
|
adjustSceneRect();
|
||||||
|
fitInView(sceneRect(), Qt::KeepAspectRatio);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Reinitialise le zoom
|
||||||
|
*/
|
||||||
|
void ElementView::zoomReset() {
|
||||||
|
resetMatrix();
|
||||||
|
scale(4.0, 4.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Ajuste le sceneRect (zone du schema visualisee par l'ElementView) afin que
|
||||||
|
celui inclut a la fois les parties dans et en dehors du cadre et le cadre
|
||||||
|
lui-meme.
|
||||||
|
*/
|
||||||
|
void ElementView::adjustSceneRect() {
|
||||||
|
QRectF old_scene_rect = scene_ -> sceneRect();
|
||||||
|
QRectF new_scene_rect = scene_ -> sceneContent();
|
||||||
|
setSceneRect(new_scene_rect);
|
||||||
|
|
||||||
|
// met a jour la scene
|
||||||
|
scene_ -> update(old_scene_rect.united(new_scene_rect));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Gere les actions liees a la rollette de la souris
|
||||||
|
@param e QWheelEvent decrivant l'evenement rollette
|
||||||
|
*/
|
||||||
|
void ElementView::wheelEvent(QWheelEvent *e) {
|
||||||
|
// si la touche Ctrl est enfoncee, on zoome / dezoome
|
||||||
|
if (e -> modifiers() & Qt::ControlModifier) {
|
||||||
|
if (e -> delta() > 0) {
|
||||||
|
zoomIn();
|
||||||
|
} else {
|
||||||
|
zoomOut();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
QAbstractScrollArea::wheelEvent(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -25,8 +25,6 @@
|
|||||||
*/
|
*/
|
||||||
class ElementView : public QGraphicsView {
|
class ElementView : public QGraphicsView {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
friend class PastePartsCommand;
|
|
||||||
|
|
||||||
// constructeurs, destructeur
|
// constructeurs, destructeur
|
||||||
public:
|
public:
|
||||||
ElementView(ElementScene *, QWidget * = 0);
|
ElementView(ElementScene *, QWidget * = 0);
|
||||||
@@ -39,16 +37,9 @@ class ElementView : public QGraphicsView {
|
|||||||
public:
|
public:
|
||||||
ElementScene *scene() const;
|
ElementScene *scene() const;
|
||||||
void setScene(ElementScene *);
|
void setScene(ElementScene *);
|
||||||
QRectF viewedSceneRect() const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool event(QEvent *);
|
bool event(QEvent *);
|
||||||
void mousePressEvent(QMouseEvent *);
|
|
||||||
void wheelEvent(QWheelEvent *);
|
void wheelEvent(QWheelEvent *);
|
||||||
virtual void drawBackground(QPainter *, const QRectF &);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QRectF applyMovement(const QRectF &, const QET::OrientedMovement &, const QPointF &);
|
|
||||||
|
|
||||||
// slots
|
// slots
|
||||||
public slots:
|
public slots:
|
||||||
@@ -57,23 +48,9 @@ class ElementView : public QGraphicsView {
|
|||||||
void zoomFit();
|
void zoomFit();
|
||||||
void zoomReset();
|
void zoomReset();
|
||||||
void adjustSceneRect();
|
void adjustSceneRect();
|
||||||
void cut();
|
|
||||||
void copy();
|
|
||||||
void paste();
|
|
||||||
void pasteInArea();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void getPasteArea(const QRectF &);
|
|
||||||
ElementContent pasteAreaDefined(const QRectF &);
|
|
||||||
ElementContent paste(const QPointF &);
|
|
||||||
ElementContent paste(const QDomDocument &, const QPointF &);
|
|
||||||
ElementContent pasteWithOffset(const QDomDocument &);
|
|
||||||
|
|
||||||
//attributs
|
//attributs
|
||||||
private:
|
private:
|
||||||
ElementScene *scene_;
|
ElementScene *scene_;
|
||||||
QString to_paste_in_area_;
|
|
||||||
int offset_paste_count_;
|
|
||||||
QPointF start_top_left_corner_;
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -63,9 +63,9 @@ EllipseEditor::~EllipseEditor() {
|
|||||||
*/
|
*/
|
||||||
void EllipseEditor::updateEllipse() {
|
void EllipseEditor::updateEllipse() {
|
||||||
part -> setProperty("x", x -> text().toDouble());
|
part -> setProperty("x", x -> text().toDouble());
|
||||||
part -> setProperty("y", y -> text().toDouble());
|
part -> setProperty("y", x -> text().toDouble());
|
||||||
part -> setProperty("diameter_h", h -> text().toDouble());
|
part -> setProperty("diameter_h", x -> text().toDouble());
|
||||||
part -> setProperty("diameter_v", v -> text().toDouble());
|
part -> setProperty("diameter_v", x -> text().toDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Met a jour l'abscisse du centre de l'ellipse et cree un objet d'annulation
|
/// Met a jour l'abscisse du centre de l'ellipse et cree un objet d'annulation
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
115
editor/lineeditor.cpp
Normal file
115
editor/lineeditor.cpp
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2007 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "lineeditor.h"
|
||||||
|
#include "partline.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructeur
|
||||||
|
@param editor L'editeur d'element concerne
|
||||||
|
@param line La ligne a editer
|
||||||
|
@param parent le Widget parent
|
||||||
|
*/
|
||||||
|
LineEditor::LineEditor(QETElementEditor *editor, PartLine *line, QWidget *parent) : ElementItemEditor(editor, parent) {
|
||||||
|
|
||||||
|
part = line;
|
||||||
|
|
||||||
|
x1 = new QLineEdit();
|
||||||
|
y1 = new QLineEdit();
|
||||||
|
x2 = new QLineEdit();
|
||||||
|
y2 = new QLineEdit();
|
||||||
|
|
||||||
|
x1 -> setValidator(new QDoubleValidator(x1));
|
||||||
|
y1 -> setValidator(new QDoubleValidator(y1));
|
||||||
|
x2 -> setValidator(new QDoubleValidator(x2));
|
||||||
|
y2 -> setValidator(new QDoubleValidator(y2));
|
||||||
|
|
||||||
|
QGridLayout *grid = new QGridLayout(this);
|
||||||
|
grid -> addWidget(new QLabel("x1"), 0, 0);
|
||||||
|
grid -> addWidget(x1, 0, 1);
|
||||||
|
grid -> addWidget(new QLabel("y1"), 0, 2);
|
||||||
|
grid -> addWidget(y1, 0, 3);
|
||||||
|
grid -> addWidget(new QLabel("x2"), 1, 0);
|
||||||
|
grid -> addWidget(x2, 1, 1);
|
||||||
|
grid -> addWidget(new QLabel("y2"), 1, 2);
|
||||||
|
grid -> addWidget(y2, 1, 3);
|
||||||
|
|
||||||
|
updateForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Destructeur
|
||||||
|
LineEditor::~LineEditor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Met a jour la ligne a partir des donnees du formulaire
|
||||||
|
*/
|
||||||
|
void LineEditor::updateLine() {
|
||||||
|
part -> setLine(
|
||||||
|
QLineF(
|
||||||
|
part -> mapFromScene(
|
||||||
|
x1 -> text().toDouble(),
|
||||||
|
y1 -> text().toDouble()
|
||||||
|
),
|
||||||
|
part -> mapFromScene(
|
||||||
|
x2 -> text().toDouble(),
|
||||||
|
y2 -> text().toDouble()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Met a jour l'abscisse du premier point de la ligne et cree un objet d'annulation
|
||||||
|
void LineEditor::updateLineX1() { addChangePartCommand(tr("abscisse point 1"), part, "x1", x1 -> text().toDouble()); }
|
||||||
|
/// Met a jour l'ordonnee du premier point de la ligne et cree un objet d'annulation
|
||||||
|
void LineEditor::updateLineY1() { addChangePartCommand(tr("ordonn\351e point 1"), part, "y1", y1 -> text().toDouble()); }
|
||||||
|
/// Met a jour l'abscisse du second point de la ligne et cree un objet d'annulation
|
||||||
|
void LineEditor::updateLineX2() { addChangePartCommand(tr("abscisse point 2"), part, "x2", x2 -> text().toDouble()); }
|
||||||
|
/// Met a jour l'ordonnee du second point de la ligne et cree un objet d'annulation
|
||||||
|
void LineEditor::updateLineY2() { addChangePartCommand(tr("ordonn\351e point 2"), part, "y2", y2 -> text().toDouble()); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
Met a jour le formulaire d'edition
|
||||||
|
*/
|
||||||
|
void LineEditor::updateForm() {
|
||||||
|
activeConnections(false);
|
||||||
|
QPointF p1(part -> sceneP1());
|
||||||
|
QPointF p2(part -> sceneP2());
|
||||||
|
x1 -> setText(QString("%1").arg(p1.x()));
|
||||||
|
y1 -> setText(QString("%1").arg(p1.y()));
|
||||||
|
x2 -> setText(QString("%1").arg(p2.x()));
|
||||||
|
y2 -> setText(QString("%1").arg(p2.y()));
|
||||||
|
activeConnections(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Active ou desactive les connexionx signaux/slots entre les widgets internes.
|
||||||
|
@param active true pour activer les connexions, false pour les desactiver
|
||||||
|
*/
|
||||||
|
void LineEditor::activeConnections(bool active) {
|
||||||
|
if (active) {
|
||||||
|
connect(x1, SIGNAL(editingFinished()), this, SLOT(updateLineX1()));
|
||||||
|
connect(y1, SIGNAL(editingFinished()), this, SLOT(updateLineY1()));
|
||||||
|
connect(x2, SIGNAL(editingFinished()), this, SLOT(updateLineX2()));
|
||||||
|
connect(y2, SIGNAL(editingFinished()), this, SLOT(updateLineY2()));
|
||||||
|
} else {
|
||||||
|
connect(x1, SIGNAL(editingFinished()), this, SLOT(updateLineX1()));
|
||||||
|
connect(y1, SIGNAL(editingFinished()), this, SLOT(updateLineY1()));
|
||||||
|
connect(x2, SIGNAL(editingFinished()), this, SLOT(updateLineX2()));
|
||||||
|
connect(y2, SIGNAL(editingFinished()), this, SLOT(updateLineY2()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -37,8 +37,6 @@ class LineEditor : public ElementItemEditor {
|
|||||||
private:
|
private:
|
||||||
PartLine *part;
|
PartLine *part;
|
||||||
QLineEdit *x1, *y1, *x2, *y2;
|
QLineEdit *x1, *y1, *x2, *y2;
|
||||||
QComboBox *end1_type, *end2_type;
|
|
||||||
QLineEdit *end1_length, *end2_length;
|
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
public slots:
|
public slots:
|
||||||
@@ -47,10 +45,6 @@ class LineEditor : public ElementItemEditor {
|
|||||||
void updateLineY1();
|
void updateLineY1();
|
||||||
void updateLineX2();
|
void updateLineX2();
|
||||||
void updateLineY2();
|
void updateLineY2();
|
||||||
void updateLineEndType1();
|
|
||||||
void updateLineEndLength1();
|
|
||||||
void updateLineEndType2();
|
|
||||||
void updateLineEndLength2();
|
|
||||||
void updateForm();
|
void updateForm();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -80,12 +80,12 @@ void PartArc::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget
|
|||||||
const QDomElement PartArc::toXml(QDomDocument &xml_document) const {
|
const QDomElement PartArc::toXml(QDomDocument &xml_document) const {
|
||||||
QDomElement xml_element = xml_document.createElement("arc");
|
QDomElement xml_element = xml_document.createElement("arc");
|
||||||
QPointF top_left(sceneTopLeft());
|
QPointF top_left(sceneTopLeft());
|
||||||
xml_element.setAttribute("x", QString("%1").arg(top_left.x()));
|
xml_element.setAttribute("x", top_left.x());
|
||||||
xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
|
xml_element.setAttribute("y", top_left.y());
|
||||||
xml_element.setAttribute("width", QString("%1").arg(rect().width()));
|
xml_element.setAttribute("width", rect().width());
|
||||||
xml_element.setAttribute("height", QString("%1").arg(rect().height()));
|
xml_element.setAttribute("height", rect().height());
|
||||||
xml_element.setAttribute("start", QString("%1").arg(start_angle));
|
xml_element.setAttribute("start", start_angle);
|
||||||
xml_element.setAttribute("angle", QString("%1").arg(_angle));
|
xml_element.setAttribute("angle", _angle);
|
||||||
stylesToXml(xml_element);
|
stylesToXml(xml_element);
|
||||||
return(xml_element);
|
return(xml_element);
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,6 @@ void PartArc::setProperty(const QString &property, const QVariant &value) {
|
|||||||
} else if (property == "angle") {
|
} else if (property == "angle") {
|
||||||
setAngle(value.toInt());
|
setAngle(value.toInt());
|
||||||
}
|
}
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -48,7 +48,7 @@ class PartArc : public QGraphicsEllipseItem, public CustomElementGraphicPart {
|
|||||||
*/
|
*/
|
||||||
virtual int type() const { return Type; }
|
virtual int type() const { return Type; }
|
||||||
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0);
|
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0);
|
||||||
virtual QString name() const { return(QObject::tr("arc", "element part name")); }
|
virtual QString name() const { return(QObject::tr("arc")); }
|
||||||
virtual const QDomElement toXml(QDomDocument &) const;
|
virtual const QDomElement toXml(QDomDocument &) const;
|
||||||
virtual void fromXml(const QDomElement &);
|
virtual void fromXml(const QDomElement &);
|
||||||
virtual QPointF sceneTopLeft() const;
|
virtual QPointF sceneTopLeft() const;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -68,9 +68,9 @@ void PartCircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWid
|
|||||||
const QDomElement PartCircle::toXml(QDomDocument &xml_document) const {
|
const QDomElement PartCircle::toXml(QDomDocument &xml_document) const {
|
||||||
QDomElement xml_element = xml_document.createElement("circle");
|
QDomElement xml_element = xml_document.createElement("circle");
|
||||||
QPointF top_left(sceneTopLeft());
|
QPointF top_left(sceneTopLeft());
|
||||||
xml_element.setAttribute("x", QString("%1").arg(top_left.x()));
|
xml_element.setAttribute("x", top_left.x());
|
||||||
xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
|
xml_element.setAttribute("y", top_left.y());
|
||||||
xml_element.setAttribute("diameter", QString("%1").arg(rect().width()));
|
xml_element.setAttribute("diameter", rect().width());
|
||||||
stylesToXml(xml_element);
|
stylesToXml(xml_element);
|
||||||
return(xml_element);
|
return(xml_element);
|
||||||
}
|
}
|
||||||
@@ -125,7 +125,6 @@ void PartCircle::setProperty(const QString &property, const QVariant &value) {
|
|||||||
current_rect.setSize(QSizeF(new_diameter, new_diameter));
|
current_rect.setSize(QSizeF(new_diameter, new_diameter));
|
||||||
setRect(current_rect);
|
setRect(current_rect);
|
||||||
}
|
}
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -46,7 +46,7 @@ class PartCircle : public QGraphicsEllipseItem, public CustomElementGraphicPart
|
|||||||
*/
|
*/
|
||||||
virtual int type() const { return Type; }
|
virtual int type() const { return Type; }
|
||||||
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0);
|
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0);
|
||||||
virtual QString name() const { return(QObject::tr("cercle", "element part name")); }
|
virtual QString name() const { return(QObject::tr("cercle")); }
|
||||||
virtual const QDomElement toXml(QDomDocument &) const;
|
virtual const QDomElement toXml(QDomDocument &) const;
|
||||||
virtual void fromXml(const QDomElement &);
|
virtual void fromXml(const QDomElement &);
|
||||||
virtual QPointF sceneTopLeft() const;
|
virtual QPointF sceneTopLeft() const;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -68,10 +68,10 @@ void PartEllipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWi
|
|||||||
const QDomElement PartEllipse::toXml(QDomDocument &xml_document) const {
|
const QDomElement PartEllipse::toXml(QDomDocument &xml_document) const {
|
||||||
QDomElement xml_element = xml_document.createElement("ellipse");
|
QDomElement xml_element = xml_document.createElement("ellipse");
|
||||||
QPointF top_left(sceneTopLeft());
|
QPointF top_left(sceneTopLeft());
|
||||||
xml_element.setAttribute("x", QString("%1").arg(top_left.x()));
|
xml_element.setAttribute("x", top_left.x());
|
||||||
xml_element.setAttribute("y", QString("%1").arg(top_left.y()));
|
xml_element.setAttribute("y", top_left.y());
|
||||||
xml_element.setAttribute("width", QString("%1").arg(rect().width()));
|
xml_element.setAttribute("width", rect().width());
|
||||||
xml_element.setAttribute("height", QString("%1").arg(rect().height()));
|
xml_element.setAttribute("height", rect().height());
|
||||||
stylesToXml(xml_element);
|
stylesToXml(xml_element);
|
||||||
return(xml_element);
|
return(xml_element);
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,6 @@ void PartEllipse::setProperty(const QString &property, const QVariant &value) {
|
|||||||
current_rect.setHeight(new_height);
|
current_rect.setHeight(new_height);
|
||||||
setRect(current_rect);
|
setRect(current_rect);
|
||||||
}
|
}
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -46,7 +46,7 @@ class PartEllipse : public QGraphicsEllipseItem, public CustomElementGraphicPart
|
|||||||
*/
|
*/
|
||||||
virtual int type() const { return Type; }
|
virtual int type() const { return Type; }
|
||||||
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0);
|
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0);
|
||||||
virtual QString name() const { return(QObject::tr("ellipse", "element part name")); }
|
virtual QString name() const { return(QObject::tr("ellipse")); }
|
||||||
virtual const QDomElement toXml(QDomDocument &) const;
|
virtual const QDomElement toXml(QDomDocument &) const;
|
||||||
virtual void fromXml(const QDomElement &);
|
virtual void fromXml(const QDomElement &);
|
||||||
virtual QPointF sceneTopLeft() const;
|
virtual QPointF sceneTopLeft() const;
|
||||||
253
editor/partline.cpp
Normal file
253
editor/partline.cpp
Normal file
@@ -0,0 +1,253 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2007 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "partline.h"
|
||||||
|
#include "lineeditor.h"
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructeur
|
||||||
|
@param editor L'editeur d'element concerne
|
||||||
|
@param parent Le QGraphicsItem parent de cette ligne
|
||||||
|
@param scene La scene sur laquelle figure cette ligne
|
||||||
|
*/
|
||||||
|
PartLine::PartLine(QETElementEditor *editor, QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsLineItem(parent, scene), CustomElementGraphicPart(editor) {
|
||||||
|
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||||
|
setAcceptedMouseButtons(Qt::LeftButton);
|
||||||
|
informations = new LineEditor(elementEditor(), this);
|
||||||
|
informations -> setElementTypeName(name());
|
||||||
|
style_editor -> appendWidget(informations);
|
||||||
|
style_editor -> setElementTypeName(name());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Destructeur
|
||||||
|
PartLine::~PartLine() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Dessine la ligne
|
||||||
|
@param painter QPainter a utiliser pour rendre le dessin
|
||||||
|
@param options Options pour affiner le rendu
|
||||||
|
@param widget Widget sur lequel le rendu est effectue
|
||||||
|
*/
|
||||||
|
void PartLine::paint(QPainter *painter, const QStyleOptionGraphicsItem */*q*/, QWidget */*w*/) {
|
||||||
|
applyStylesToQPainter(*painter);
|
||||||
|
QPen t = painter -> pen();
|
||||||
|
if (isSelected()) {
|
||||||
|
t.setColor(Qt::red);
|
||||||
|
painter -> setPen(t);
|
||||||
|
}
|
||||||
|
painter -> setBrush(Qt::NoBrush);
|
||||||
|
painter -> drawLine(line());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Exporte la ligne en XML
|
||||||
|
@param xml_document Document XML a utiliser pour creer l'element XML
|
||||||
|
@return un element XML decrivant la ligne
|
||||||
|
*/
|
||||||
|
const QDomElement PartLine::toXml(QDomDocument &xml_document) const {
|
||||||
|
|
||||||
|
QPointF p1(sceneP1());
|
||||||
|
QPointF p2(sceneP2());
|
||||||
|
|
||||||
|
QDomElement xml_element = xml_document.createElement("line");
|
||||||
|
xml_element.setAttribute("x1", p1.x());
|
||||||
|
xml_element.setAttribute("y1", p1.y());
|
||||||
|
xml_element.setAttribute("x2", p2.x());
|
||||||
|
xml_element.setAttribute("y2", p2.y());
|
||||||
|
stylesToXml(xml_element);
|
||||||
|
return(xml_element);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Importe les proprietes d'une ligne depuis un element XML
|
||||||
|
@param qde Element XML a lire
|
||||||
|
*/
|
||||||
|
void PartLine::fromXml(const QDomElement &qde) {
|
||||||
|
stylesFromXml(qde);
|
||||||
|
setLine(
|
||||||
|
QLineF(
|
||||||
|
mapFromScene(
|
||||||
|
qde.attribute("x1", "0").toDouble(),
|
||||||
|
qde.attribute("y1", "0").toDouble()
|
||||||
|
),
|
||||||
|
mapFromScene(
|
||||||
|
qde.attribute("x2", "0").toDouble(),
|
||||||
|
qde.attribute("y2", "0").toDouble()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Specifie la valeur d'une propriete donnee de la ligne
|
||||||
|
@param property propriete a modifier. Valeurs acceptees :
|
||||||
|
* x1 : abscisse du premier point
|
||||||
|
* y1 : ordonnee du second point
|
||||||
|
* x2 : abscisse du premier point
|
||||||
|
* y2 : ordonnee du second point
|
||||||
|
@param value Valeur a attribuer a la propriete
|
||||||
|
*/
|
||||||
|
void PartLine::setProperty(const QString &property, const QVariant &value) {
|
||||||
|
CustomElementGraphicPart::setProperty(property, value);
|
||||||
|
if (!value.canConvert(QVariant::Double)) return;
|
||||||
|
QPointF new_p1(sceneP1()), new_p2(sceneP2());
|
||||||
|
bool setline = true;
|
||||||
|
if (property == "x1") {
|
||||||
|
new_p1.setX(value.toDouble());
|
||||||
|
} else if (property == "y1") {
|
||||||
|
new_p1.setY(value.toDouble());
|
||||||
|
} else if (property == "x2") {
|
||||||
|
new_p2.setX(value.toDouble());
|
||||||
|
} else if (property == "y2") {
|
||||||
|
new_p2.setY(value.toDouble());
|
||||||
|
} else setline = false;
|
||||||
|
setLine(QLineF(mapFromScene(new_p1), mapFromScene(new_p2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Permet d'acceder a la valeur d'une propriete donnee de la ligne
|
||||||
|
@param property propriete lue. Valeurs acceptees :
|
||||||
|
* x1 : abscisse du premier point
|
||||||
|
* y1 : ordonnee du second point
|
||||||
|
* x2 : abscisse du premier point
|
||||||
|
* y2 : ordonnee du second point
|
||||||
|
@return La valeur de la propriete property
|
||||||
|
*/
|
||||||
|
QVariant PartLine::property(const QString &property) {
|
||||||
|
// appelle la methode property de CustomElementGraphicpart pour les styles
|
||||||
|
QVariant style_property = CustomElementGraphicPart::property(property);
|
||||||
|
if (style_property != QVariant()) return(style_property);
|
||||||
|
|
||||||
|
if (property == "x1") {
|
||||||
|
return(sceneP1().x());
|
||||||
|
} else if (property == "y1") {
|
||||||
|
return(sceneP1().y());
|
||||||
|
} else if (property == "x2") {
|
||||||
|
return(sceneP2().x());
|
||||||
|
} else if (property == "y2") {
|
||||||
|
return(sceneP2().y());
|
||||||
|
}
|
||||||
|
return(QVariant());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Gere les changements intervenant sur cette partie
|
||||||
|
@param change Type de changement
|
||||||
|
@param value Valeur numerique relative au changement
|
||||||
|
*/
|
||||||
|
QVariant PartLine::itemChange(GraphicsItemChange change, const QVariant &value) {
|
||||||
|
if (scene()) {
|
||||||
|
if (change == QGraphicsItem::ItemPositionChange || change == QGraphicsItem::ItemSelectedChange) {
|
||||||
|
informations -> updateForm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(QGraphicsLineItem::itemChange(change, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return le premier point, dans les coordonnees de la scene.
|
||||||
|
*/
|
||||||
|
QPointF PartLine::sceneP1() const {
|
||||||
|
return(mapToScene(line().p1()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return le second point, dans les coordonnees de la scene.
|
||||||
|
*/
|
||||||
|
QPointF PartLine::sceneP2() const {
|
||||||
|
return(mapToScene(line().p2()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return la forme selectionnable de la ligne
|
||||||
|
*/
|
||||||
|
QPainterPath PartLine::shape() const {
|
||||||
|
QList<QPointF> points = fourShapePoints();
|
||||||
|
QPainterPath t;
|
||||||
|
t.setFillRule(Qt::WindingFill);
|
||||||
|
t.moveTo(points.at(0));
|
||||||
|
t.lineTo(points.at(1));
|
||||||
|
t.lineTo(points.at(2));
|
||||||
|
t.lineTo(points.at(3));
|
||||||
|
t.lineTo(points.at(0));
|
||||||
|
return(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return une liste contenant les deux points de la droite + les 4 points entourant ces deux points
|
||||||
|
*/
|
||||||
|
QList<QPointF> PartLine::fourShapePoints() const {
|
||||||
|
const qreal marge = 2.0;
|
||||||
|
// on a donc A(xa , ya) et B(xb, yb)
|
||||||
|
QPointF a = line().p1();
|
||||||
|
QPointF b = line().p2();
|
||||||
|
|
||||||
|
QList<QPointF> result;
|
||||||
|
|
||||||
|
// cas particulier : la droite se ramene a un point
|
||||||
|
if (a == b) {
|
||||||
|
result << QPointF(a.x() - marge, a.y() - marge);
|
||||||
|
result << QPointF(a.x() - marge, a.y() + marge);
|
||||||
|
result << QPointF(a.x() + marge, a.y() + marge);
|
||||||
|
result << QPointF(a.x() + marge, a.y() - marge);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// on calcule le vecteur AB : (xb-xa, yb-ya)
|
||||||
|
QPointF v_ab = b - a;
|
||||||
|
|
||||||
|
// et la distance AB : racine des coordonnees du vecteur au carre
|
||||||
|
qreal ab = sqrt(pow(v_ab.x(), 2) + pow(v_ab.y(), 2));
|
||||||
|
|
||||||
|
// ensuite on definit le vecteur u(a, b) qui est egal au vecteur AB divise
|
||||||
|
// par sa longueur et multiplie par la longueur de la marge que tu veux
|
||||||
|
// laisser
|
||||||
|
QPointF u = v_ab / ab * marge;
|
||||||
|
|
||||||
|
// on definit le vecteur v(-b , a) qui est perpendiculaire a AB
|
||||||
|
QPointF v(-u.y(), u.x());
|
||||||
|
QPointF m = -u + v; // on a le vecteur M = -u + v
|
||||||
|
QPointF n = -u - v; // et le vecteur N=-u-v
|
||||||
|
QPointF h = a + m; // H = A + M
|
||||||
|
QPointF k = a + n; // K = A + N
|
||||||
|
QPointF i = b - n; // I = B - N
|
||||||
|
QPointF j = b - m; // J = B - M
|
||||||
|
|
||||||
|
result << h << i << j << k;
|
||||||
|
}
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return le rectangle delimitant cette partie.
|
||||||
|
*/
|
||||||
|
QRectF PartLine::boundingRect() const {
|
||||||
|
qreal adjust = 1.5;
|
||||||
|
QRectF r(QGraphicsLineItem::boundingRect());
|
||||||
|
r.adjust(-adjust, -adjust, adjust, adjust);
|
||||||
|
return(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return true si cette partie n'est pas pertinente et ne merite pas d'etre
|
||||||
|
conservee / enregistree.
|
||||||
|
Une ligne est pertinente des lors que ses deux points sont differents
|
||||||
|
*/
|
||||||
|
bool PartLine::isUseless() const {
|
||||||
|
return(sceneP1() == sceneP2());
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -15,41 +15,43 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#ifndef PART_RECTANGLE_H
|
#ifndef PART_LINE_H
|
||||||
#define PART_RECTANGLE_H
|
#define PART_LINE_H
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include "customelementgraphicpart.h"
|
#include "customelementgraphicpart.h"
|
||||||
class RectangleEditor;
|
class LineEditor;
|
||||||
/**
|
/**
|
||||||
Cette classe represente un rectangle pouvant etre utilise pour composer le
|
Cette classe represente une ligne pouvant etre utilisee pour composer le
|
||||||
dessin d'un element dans l'editeur d'element.
|
dessin d'un element dans l'editeur d'element.
|
||||||
*/
|
*/
|
||||||
class PartRectangle : public QGraphicsRectItem, public CustomElementGraphicPart {
|
class PartLine : public QGraphicsLineItem, public CustomElementGraphicPart {
|
||||||
// constructeurs, destructeur
|
// constructeurs, destructeur
|
||||||
public:
|
public:
|
||||||
PartRectangle(QETElementEditor *, QGraphicsItem * = 0, QGraphicsScene * = 0);
|
PartLine(QETElementEditor *, QGraphicsItem * = 0, QGraphicsScene * = 0);
|
||||||
virtual ~PartRectangle();
|
virtual ~PartLine();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PartRectangle(const PartRectangle &);
|
PartLine(const PartLine &);
|
||||||
|
|
||||||
// attributs
|
// attributs
|
||||||
private:
|
private:
|
||||||
RectangleEditor *informations;
|
LineEditor *informations;
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
public:
|
public:
|
||||||
enum { Type = UserType + 1109 };
|
enum { Type = UserType + 1104 };
|
||||||
/**
|
/**
|
||||||
permet de caster un QGraphicsItem en PartRectangle avec qgraphicsitem_cast
|
permet de caster un QGraphicsItem en PartLine avec qgraphicsitem_cast
|
||||||
@return le type de QGraphicsItem
|
@return le type de QGraphicsItem
|
||||||
*/
|
*/
|
||||||
virtual int type() const { return Type; }
|
virtual int type() const { return Type; }
|
||||||
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0);
|
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0);
|
||||||
virtual QString name() const { return(QObject::tr("rectangle", "element part name")); }
|
virtual QString name() const { return(QObject::tr("ligne")); }
|
||||||
virtual const QDomElement toXml(QDomDocument &) const;
|
virtual const QDomElement toXml(QDomDocument &) const;
|
||||||
virtual void fromXml(const QDomElement &);
|
virtual void fromXml(const QDomElement &);
|
||||||
virtual QPointF sceneTopLeft() const;
|
virtual QPointF sceneP1() const;
|
||||||
|
virtual QPointF sceneP2() const;
|
||||||
|
virtual QPainterPath shape() const;
|
||||||
virtual QRectF boundingRect() const;
|
virtual QRectF boundingRect() const;
|
||||||
virtual void setProperty(const QString &, const QVariant &);
|
virtual void setProperty(const QString &, const QVariant &);
|
||||||
virtual QVariant property(const QString &);
|
virtual QVariant property(const QString &);
|
||||||
@@ -57,5 +59,8 @@ class PartRectangle : public QGraphicsRectItem, public CustomElementGraphicPart
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
QVariant itemChange(GraphicsItemChange, const QVariant &);
|
QVariant itemChange(GraphicsItemChange, const QVariant &);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<QPointF> fourShapePoints() const;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -114,7 +114,6 @@ void PartPolygon::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWi
|
|||||||
void PartPolygon::setProperty(const QString &property, const QVariant &value) {
|
void PartPolygon::setProperty(const QString &property, const QVariant &value) {
|
||||||
CustomElementGraphicPart::setProperty(property, value);
|
CustomElementGraphicPart::setProperty(property, value);
|
||||||
if (property == "closed") closed = value.toBool();
|
if (property == "closed") closed = value.toBool();
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -58,7 +58,7 @@ class PartPolygon : public QGraphicsPolygonItem, public CustomElementGraphicPart
|
|||||||
@return le type de QGraphicsItem
|
@return le type de QGraphicsItem
|
||||||
*/
|
*/
|
||||||
virtual int type() const { return Type; }
|
virtual int type() const { return Type; }
|
||||||
virtual QString name() const { return(QObject::tr("polygone", "element part name")); }
|
virtual QString name() const { return(QObject::tr("polygone")); }
|
||||||
void fromXml(const QDomElement &);
|
void fromXml(const QDomElement &);
|
||||||
const QDomElement toXml(QDomDocument &) const;
|
const QDomElement toXml(QDomDocument &) const;
|
||||||
virtual QRectF boundingRect() const;
|
virtual QRectF boundingRect() const;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -39,7 +39,6 @@ PartTerminal::PartTerminal(QETElementEditor *editor, QGraphicsItem *parent, QGra
|
|||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
PartTerminal::~PartTerminal() {
|
PartTerminal::~PartTerminal() {
|
||||||
if (informations -> parentWidget()) return; // le widget sera supprime par son parent
|
|
||||||
delete informations;
|
delete informations;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -48,7 +48,7 @@ class PartTerminal : public CustomElementPart, public QGraphicsItem {
|
|||||||
@return le type de QGraphicsItem
|
@return le type de QGraphicsItem
|
||||||
*/
|
*/
|
||||||
virtual int type() const { return Type; }
|
virtual int type() const { return Type; }
|
||||||
virtual QString name() const { return(QObject::tr("borne", "element part name")); }
|
virtual QString name() const { return(QObject::tr("borne")); }
|
||||||
virtual void fromXml(const QDomElement &);
|
virtual void fromXml(const QDomElement &);
|
||||||
virtual const QDomElement toXml(QDomDocument &) const;
|
virtual const QDomElement toXml(QDomDocument &) const;
|
||||||
virtual QWidget *elementInformations();
|
virtual QWidget *elementInformations();
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -33,14 +33,14 @@ PartText::PartText(QETElementEditor *editor, QGraphicsItem *parent, ElementScene
|
|||||||
{
|
{
|
||||||
setDefaultTextColor(Qt::black);
|
setDefaultTextColor(Qt::black);
|
||||||
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||||
setPlainText(QObject::tr("T", "default text when adding a text in the element editor"));
|
setPlainText(QObject::tr("T"));
|
||||||
infos = new TextEditor(elementEditor(), this);
|
infos = new TextEditor(elementEditor(), this);
|
||||||
infos -> setElementTypeName(name());
|
infos -> setElementTypeName(name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
PartText::~PartText() {
|
PartText::~PartText() {
|
||||||
if (infos -> parentWidget()) return; // le widget sera supprime par son parent
|
|
||||||
delete infos;
|
delete infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +130,7 @@ void PartText::focusOutEvent(QFocusEvent *e) {
|
|||||||
if (previous_text != toPlainText()) {
|
if (previous_text != toPlainText()) {
|
||||||
undoStack().push(
|
undoStack().push(
|
||||||
new ChangePartCommand(
|
new ChangePartCommand(
|
||||||
TextEditor::tr("contenu") + " " + name(),
|
TextEditor::tr("texte") + " " + name(),
|
||||||
this,
|
this,
|
||||||
"text",
|
"text",
|
||||||
previous_text,
|
previous_text,
|
||||||
@@ -139,13 +139,6 @@ void PartText::focusOutEvent(QFocusEvent *e) {
|
|||||||
);
|
);
|
||||||
previous_text = toPlainText();
|
previous_text = toPlainText();
|
||||||
}
|
}
|
||||||
|
|
||||||
// deselectionne le texte
|
|
||||||
QTextCursor qtc = textCursor();
|
|
||||||
qtc.clearSelection();
|
|
||||||
setTextCursor(qtc);
|
|
||||||
|
|
||||||
setTextInteractionFlags(Qt::NoTextInteraction);
|
|
||||||
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +176,6 @@ void PartText::setProperty(const QString &property, const QVariant &value) {
|
|||||||
} else if (property == "text") {
|
} else if (property == "text") {
|
||||||
setPlainText(value.toString());
|
setPlainText(value.toString());
|
||||||
}
|
}
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -44,7 +44,7 @@ class PartText : public QGraphicsTextItem, public CustomElementPart {
|
|||||||
@return le type de QGraphicsItem
|
@return le type de QGraphicsItem
|
||||||
*/
|
*/
|
||||||
virtual int type() const { return Type; }
|
virtual int type() const { return Type; }
|
||||||
virtual QString name() const { return(QObject::tr("texte", "element part name")); }
|
virtual QString name() const { return(QObject::tr("texte")); }
|
||||||
void fromXml(const QDomElement &);
|
void fromXml(const QDomElement &);
|
||||||
const QDomElement toXml(QDomDocument &) const;
|
const QDomElement toXml(QDomDocument &) const;
|
||||||
QWidget *elementInformations();
|
QWidget *elementInformations();
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -33,14 +33,13 @@ PartTextField::PartTextField(QETElementEditor *editor, QGraphicsItem *parent, QG
|
|||||||
{
|
{
|
||||||
setDefaultTextColor(Qt::black);
|
setDefaultTextColor(Qt::black);
|
||||||
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||||
setPlainText(QObject::tr("_", "default text when adding a textfield in the element editor"));
|
setPlainText(QObject::tr("_"));
|
||||||
infos = new TextFieldEditor(elementEditor(), this);
|
infos = new TextFieldEditor(elementEditor(), this);
|
||||||
infos -> setElementTypeName(name());
|
infos -> setElementTypeName(name());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
PartTextField::~PartTextField() {
|
PartTextField::~PartTextField() {
|
||||||
if (infos -> parentWidget()) return; // le widget sera supprime par son parent
|
|
||||||
delete infos;
|
delete infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +148,7 @@ void PartTextField::focusOutEvent(QFocusEvent *e) {
|
|||||||
if (previous_text != toPlainText()) {
|
if (previous_text != toPlainText()) {
|
||||||
undoStack().push(
|
undoStack().push(
|
||||||
new ChangePartCommand(
|
new ChangePartCommand(
|
||||||
TextFieldEditor::tr("contenu") + " " + name(),
|
TextFieldEditor::tr("texte") + " " + name(),
|
||||||
this,
|
this,
|
||||||
"text",
|
"text",
|
||||||
previous_text,
|
previous_text,
|
||||||
@@ -158,13 +157,6 @@ void PartTextField::focusOutEvent(QFocusEvent *e) {
|
|||||||
);
|
);
|
||||||
previous_text = toPlainText();
|
previous_text = toPlainText();
|
||||||
}
|
}
|
||||||
|
|
||||||
// deselectionne le texte
|
|
||||||
QTextCursor qtc = textCursor();
|
|
||||||
qtc.clearSelection();
|
|
||||||
setTextCursor(qtc);
|
|
||||||
|
|
||||||
setTextInteractionFlags(Qt::NoTextInteraction);
|
|
||||||
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +197,6 @@ void PartTextField::setProperty(const QString &property, const QVariant &value)
|
|||||||
} else if (property == "rotate") {
|
} else if (property == "rotate") {
|
||||||
follow_parent_rotations = value.toBool();
|
follow_parent_rotations = value.toBool();
|
||||||
}
|
}
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -48,7 +48,7 @@ class PartTextField : public QGraphicsTextItem, public CustomElementPart {
|
|||||||
@return le type de QGraphicsItem
|
@return le type de QGraphicsItem
|
||||||
*/
|
*/
|
||||||
virtual int type() const { return Type; }
|
virtual int type() const { return Type; }
|
||||||
virtual QString name() const { return(QObject::tr("champ de texte", "element part name")); }
|
virtual QString name() const { return(QObject::tr("champ de texte")); }
|
||||||
void fromXml(const QDomElement &);
|
void fromXml(const QDomElement &);
|
||||||
const QDomElement toXml(QDomDocument &) const;
|
const QDomElement toXml(QDomDocument &) const;
|
||||||
QWidget *elementInformations();
|
QWidget *elementInformations();
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -69,8 +69,8 @@ void PolygonEditor::updatePolygonPoints() {
|
|||||||
if (points.count() < 2) {
|
if (points.count() < 2) {
|
||||||
QMessageBox::warning(
|
QMessageBox::warning(
|
||||||
this,
|
this,
|
||||||
tr("Erreur", "message box title"),
|
tr("Erreur"),
|
||||||
tr("Le polygone doit comporter au moins deux points.", "message box content")
|
tr("Le polygone doit comporter au moins deux points.")
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ void PolygonEditor::updatePolygonClosedState() {
|
|||||||
*/
|
*/
|
||||||
void PolygonEditor::updateForm() {
|
void PolygonEditor::updateForm() {
|
||||||
activeConnections(false);
|
activeConnections(false);
|
||||||
while(points_list.takeTopLevelItem(0)) {}
|
while(points_list.takeTopLevelItem(0));
|
||||||
foreach(QPointF point, part -> polygon()) {
|
foreach(QPointF point, part -> polygon()) {
|
||||||
point = part -> mapToScene(point);
|
point = part -> mapToScene(point);
|
||||||
QStringList qsl;
|
QStringList qsl;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -22,9 +22,6 @@
|
|||||||
#include "customelementpart.h"
|
#include "customelementpart.h"
|
||||||
#include "newelementwizard.h"
|
#include "newelementwizard.h"
|
||||||
#include "elementitemeditor.h"
|
#include "elementitemeditor.h"
|
||||||
#include "elementdefinition.h"
|
|
||||||
#include "elementdialog.h"
|
|
||||||
#include "recentfiles.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@@ -33,8 +30,8 @@
|
|||||||
QETElementEditor::QETElementEditor(QWidget *parent) :
|
QETElementEditor::QETElementEditor(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
read_only(false),
|
read_only(false),
|
||||||
min_title(tr("QElectroTech - \311diteur d'\351l\351ment", "window title")),
|
min_title(tr("QElectroTech - \311diteur d'\351l\351ment")),
|
||||||
opened_from_file(false)
|
_filename(QString())
|
||||||
{
|
{
|
||||||
setWindowTitle(min_title);
|
setWindowTitle(min_title);
|
||||||
setWindowIcon(QIcon(":/ico/qet.png"));
|
setWindowIcon(QIcon(":/ico/qet.png"));
|
||||||
@@ -49,7 +46,6 @@ QETElementEditor::QETElementEditor(QWidget *parent) :
|
|||||||
|
|
||||||
// lecture des parametres
|
// lecture des parametres
|
||||||
readSettings();
|
readSettings();
|
||||||
slot_updateMenus();
|
|
||||||
|
|
||||||
// affichage
|
// affichage
|
||||||
show();
|
show();
|
||||||
@@ -57,12 +53,6 @@ QETElementEditor::QETElementEditor(QWidget *parent) :
|
|||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
QETElementEditor::~QETElementEditor() {
|
QETElementEditor::~QETElementEditor() {
|
||||||
/*
|
|
||||||
retire le widget d'edition de partie affiche par le dock
|
|
||||||
cela evite qu'il ne soit supprime avant que la partie a laquelle il est
|
|
||||||
rattache ne le supprime une fois de trop
|
|
||||||
*/
|
|
||||||
clearToolsDock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,18 +61,12 @@ QETElementEditor::~QETElementEditor() {
|
|||||||
void QETElementEditor::setupActions() {
|
void QETElementEditor::setupActions() {
|
||||||
new_element = new QAction(QIcon(":/ico/new.png"), tr("&Nouveau"), this);
|
new_element = new QAction(QIcon(":/ico/new.png"), tr("&Nouveau"), this);
|
||||||
open = new QAction(QIcon(":/ico/open.png"), tr("&Ouvrir"), this);
|
open = new QAction(QIcon(":/ico/open.png"), tr("&Ouvrir"), this);
|
||||||
open_file = new QAction(QIcon(":/ico/open.png"), tr("&Ouvrir depuis un fichier"), this);
|
|
||||||
save = new QAction(QIcon(":/ico/save.png"), tr("&Enregistrer"), this);
|
save = new QAction(QIcon(":/ico/save.png"), tr("&Enregistrer"), this);
|
||||||
save_as = new QAction(QIcon(":/ico/saveas.png"), tr("Enregistrer sous"), this);
|
save_as = new QAction(QIcon(":/ico/saveas.png"), tr("Enregistrer sous"), this);
|
||||||
save_as_file = new QAction(QIcon(":/ico/saveas.png"), tr("Enregistrer dans un fichier"), this);
|
|
||||||
reload = new QAction(QIcon(":/ico/reload.png"), tr("Recharger"), this);
|
reload = new QAction(QIcon(":/ico/reload.png"), tr("Recharger"), this);
|
||||||
quit = new QAction(QIcon(":/ico/exit.png"), tr("&Quitter"), this);
|
quit = new QAction(QIcon(":/ico/exit.png"), tr("&Quitter"), this);
|
||||||
selectall = new QAction( tr("Tout s\351lectionner"), this);
|
selectall = new QAction( tr("Tout s\351lectionner"), this);
|
||||||
deselectall = new QAction( tr("D\351s\351lectionner tout"), this);
|
deselectall = new QAction( tr("D\351s\351lectionner tout"), this);
|
||||||
cut = new QAction(QIcon(":/ico/cut.png"), tr("Co&uper"), this);
|
|
||||||
copy = new QAction(QIcon(":/ico/copy.png"), tr("Cop&ier"), this);
|
|
||||||
paste = new QAction(QIcon(":/ico/paste.png"), tr("C&oller"), this);
|
|
||||||
paste_in_area = new QAction(QIcon(":/ico/paste.png"), tr("C&oller dans la zone..."), this);
|
|
||||||
inv_select = new QAction( tr("Inverser la s\351lection"), this);
|
inv_select = new QAction( tr("Inverser la s\351lection"), this);
|
||||||
edit_delete = new QAction(QIcon(":/ico/delete.png"), tr("&Supprimer"), this);
|
edit_delete = new QAction(QIcon(":/ico/delete.png"), tr("&Supprimer"), this);
|
||||||
zoom_in = new QAction(QIcon(":/ico/viewmag+.png"), tr("Zoom avant"), this);
|
zoom_in = new QAction(QIcon(":/ico/viewmag+.png"), tr("Zoom avant"), this);
|
||||||
@@ -98,7 +82,6 @@ void QETElementEditor::setupActions() {
|
|||||||
edit_forward = new QAction(QIcon(":/ico/bring_forward.png"),tr("Amener au premier plan"), this);
|
edit_forward = new QAction(QIcon(":/ico/bring_forward.png"),tr("Amener au premier plan"), this);
|
||||||
move = new QAction(QIcon(":/ico/select.png"), tr("D\351placer un objet"), this);
|
move = new QAction(QIcon(":/ico/select.png"), tr("D\351placer un objet"), this);
|
||||||
add_line = new QAction(QIcon(":/ico/line.png"), tr("Ajouter une ligne"), this);
|
add_line = new QAction(QIcon(":/ico/line.png"), tr("Ajouter une ligne"), this);
|
||||||
add_rectangle = new QAction(QIcon(":/ico/rectangle.png"), tr("Ajouter un rectangle"), this);
|
|
||||||
add_ellipse = new QAction(QIcon(":/ico/ellipse.png"), tr("Ajouter une ellipse"), this);
|
add_ellipse = new QAction(QIcon(":/ico/ellipse.png"), tr("Ajouter une ellipse"), this);
|
||||||
add_circle = new QAction(QIcon(":/ico/circle.png"), tr("Ajouter un cercle"), this);
|
add_circle = new QAction(QIcon(":/ico/circle.png"), tr("Ajouter un cercle"), this);
|
||||||
add_polygon = new QAction(QIcon(":/ico/polygon.png"), tr("Ajouter un polygone"), this);
|
add_polygon = new QAction(QIcon(":/ico/polygon.png"), tr("Ajouter un polygone"), this);
|
||||||
@@ -107,17 +90,6 @@ void QETElementEditor::setupActions() {
|
|||||||
add_terminal = new QAction(QIcon(":/ico/terminal.png"), tr("Ajouter une borne"), this);
|
add_terminal = new QAction(QIcon(":/ico/terminal.png"), tr("Ajouter une borne"), this);
|
||||||
add_textfield = new QAction(QIcon(":/ico/textfield.png"), tr("Ajouter un champ de texte"), this);
|
add_textfield = new QAction(QIcon(":/ico/textfield.png"), tr("Ajouter un champ de texte"), this);
|
||||||
|
|
||||||
QString add_status_tip = tr("Maintenez la touche Shift enfonc\351e pour effectuer plusieurs ajouts d'affil\351e");
|
|
||||||
add_line -> setStatusTip(add_status_tip);
|
|
||||||
add_rectangle -> setStatusTip(add_status_tip);
|
|
||||||
add_ellipse -> setStatusTip(add_status_tip);
|
|
||||||
add_circle -> setStatusTip(add_status_tip);
|
|
||||||
add_text -> setStatusTip(add_status_tip);
|
|
||||||
add_arc -> setStatusTip(add_status_tip);
|
|
||||||
add_terminal -> setStatusTip(add_status_tip);
|
|
||||||
add_textfield -> setStatusTip(add_status_tip);
|
|
||||||
add_polygon -> setStatusTip(tr("Utilisez le bouton droit de la souris pour poser le dernier point du polygone"));
|
|
||||||
|
|
||||||
undo = ce_scene -> undoStack().createUndoAction(this, tr("Annuler"));
|
undo = ce_scene -> undoStack().createUndoAction(this, tr("Annuler"));
|
||||||
redo = ce_scene -> undoStack().createRedoAction(this, tr("Refaire"));
|
redo = ce_scene -> undoStack().createRedoAction(this, tr("Refaire"));
|
||||||
undo -> setIcon(QIcon(":/ico/undo.png"));
|
undo -> setIcon(QIcon(":/ico/undo.png"));
|
||||||
@@ -127,18 +99,12 @@ void QETElementEditor::setupActions() {
|
|||||||
|
|
||||||
new_element -> setShortcut(QKeySequence::New);
|
new_element -> setShortcut(QKeySequence::New);
|
||||||
open -> setShortcut(QKeySequence::Open);
|
open -> setShortcut(QKeySequence::Open);
|
||||||
open_file -> setShortcut(tr("Ctrl+Shift+O"));
|
|
||||||
save -> setShortcut(QKeySequence::Save);
|
save -> setShortcut(QKeySequence::Save);
|
||||||
save_as_file -> setShortcut(tr("Ctrl+Shift+S"));
|
|
||||||
reload -> setShortcut(Qt::Key_F5);
|
reload -> setShortcut(Qt::Key_F5);
|
||||||
quit -> setShortcut(QKeySequence(tr("Ctrl+Q")));
|
quit -> setShortcut(QKeySequence(tr("Ctrl+Q")));
|
||||||
selectall -> setShortcut(QKeySequence::SelectAll);
|
selectall -> setShortcut(QKeySequence::SelectAll);
|
||||||
deselectall -> setShortcut(QKeySequence(tr("Ctrl+Shift+A")));
|
deselectall -> setShortcut(QKeySequence(tr("Ctrl+Shift+A")));
|
||||||
inv_select -> setShortcut(QKeySequence(tr("Ctrl+I")));
|
inv_select -> setShortcut(QKeySequence(tr("Ctrl+I")));
|
||||||
cut -> setShortcut(QKeySequence::Cut);
|
|
||||||
copy -> setShortcut(QKeySequence::Copy);
|
|
||||||
paste -> setShortcut(QKeySequence::Paste);
|
|
||||||
paste_in_area -> setShortcut(tr("Ctrl+Shift+V"));
|
|
||||||
edit_delete -> setShortcut(QKeySequence(tr("Suppr")));
|
edit_delete -> setShortcut(QKeySequence(tr("Suppr")));
|
||||||
|
|
||||||
zoom_in -> setShortcut(QKeySequence::ZoomIn);
|
zoom_in -> setShortcut(QKeySequence::ZoomIn);
|
||||||
@@ -157,19 +123,13 @@ void QETElementEditor::setupActions() {
|
|||||||
|
|
||||||
connect(new_element, SIGNAL(triggered()), this, SLOT(slot_new()));
|
connect(new_element, SIGNAL(triggered()), this, SLOT(slot_new()));
|
||||||
connect(open, SIGNAL(triggered()), this, SLOT(slot_open()));
|
connect(open, SIGNAL(triggered()), this, SLOT(slot_open()));
|
||||||
connect(open_file, SIGNAL(triggered()), this, SLOT(slot_openFile()));
|
|
||||||
connect(save, SIGNAL(triggered()), this, SLOT(slot_save()));
|
connect(save, SIGNAL(triggered()), this, SLOT(slot_save()));
|
||||||
connect(save_as, SIGNAL(triggered()), this, SLOT(slot_saveAs()));
|
connect(save_as, SIGNAL(triggered()), this, SLOT(slot_saveAs()));
|
||||||
connect(save_as_file, SIGNAL(triggered()), this, SLOT(slot_saveAsFile()));
|
|
||||||
connect(reload, SIGNAL(triggered()), this, SLOT(slot_reload()));
|
connect(reload, SIGNAL(triggered()), this, SLOT(slot_reload()));
|
||||||
connect(quit, SIGNAL(triggered()), this, SLOT(close()));
|
connect(quit, SIGNAL(triggered()), this, SLOT(close()));
|
||||||
connect(selectall, SIGNAL(triggered()), ce_scene, SLOT(slot_selectAll()));
|
connect(selectall, SIGNAL(triggered()), ce_scene, SLOT(slot_selectAll()));
|
||||||
connect(deselectall, SIGNAL(triggered()), ce_scene, SLOT(slot_deselectAll()));
|
connect(deselectall, SIGNAL(triggered()), ce_scene, SLOT(slot_deselectAll()));
|
||||||
connect(inv_select, SIGNAL(triggered()), ce_scene, SLOT(slot_invertSelection()));
|
connect(inv_select, SIGNAL(triggered()), ce_scene, SLOT(slot_invertSelection()));
|
||||||
connect(cut, SIGNAL(triggered()), ce_view, SLOT(cut()));
|
|
||||||
connect(copy, SIGNAL(triggered()), ce_view, SLOT(copy()));
|
|
||||||
connect(paste, SIGNAL(triggered()), ce_view, SLOT(paste()));
|
|
||||||
connect(paste_in_area, SIGNAL(triggered()), ce_view, SLOT(pasteInArea()));
|
|
||||||
connect(zoom_in, SIGNAL(triggered()), ce_view, SLOT(zoomIn()));
|
connect(zoom_in, SIGNAL(triggered()), ce_view, SLOT(zoomIn()));
|
||||||
connect(zoom_out, SIGNAL(triggered()), ce_view, SLOT(zoomOut()));
|
connect(zoom_out, SIGNAL(triggered()), ce_view, SLOT(zoomOut()));
|
||||||
connect(zoom_fit, SIGNAL(triggered()), ce_view, SLOT(zoomFit()));
|
connect(zoom_fit, SIGNAL(triggered()), ce_view, SLOT(zoomFit()));
|
||||||
@@ -184,7 +144,6 @@ void QETElementEditor::setupActions() {
|
|||||||
connect(edit_backward, SIGNAL(triggered()), ce_scene, SLOT(slot_sendBackward()));
|
connect(edit_backward, SIGNAL(triggered()), ce_scene, SLOT(slot_sendBackward()));
|
||||||
connect(move, SIGNAL(triggered()), ce_scene, SLOT(slot_move()));
|
connect(move, SIGNAL(triggered()), ce_scene, SLOT(slot_move()));
|
||||||
connect(add_line, SIGNAL(triggered()), ce_scene, SLOT(slot_addLine()));
|
connect(add_line, SIGNAL(triggered()), ce_scene, SLOT(slot_addLine()));
|
||||||
connect(add_rectangle, SIGNAL(triggered()), ce_scene, SLOT(slot_addRectangle()));
|
|
||||||
connect(add_ellipse, SIGNAL(triggered()), ce_scene, SLOT(slot_addEllipse()));
|
connect(add_ellipse, SIGNAL(triggered()), ce_scene, SLOT(slot_addEllipse()));
|
||||||
connect(add_circle, SIGNAL(triggered()), ce_scene, SLOT(slot_addCircle()));
|
connect(add_circle, SIGNAL(triggered()), ce_scene, SLOT(slot_addCircle()));
|
||||||
connect(add_polygon, SIGNAL(triggered()), ce_scene, SLOT(slot_addPolygon()));
|
connect(add_polygon, SIGNAL(triggered()), ce_scene, SLOT(slot_addPolygon()));
|
||||||
@@ -195,7 +154,6 @@ void QETElementEditor::setupActions() {
|
|||||||
|
|
||||||
connect(move, SIGNAL(triggered()), this, SLOT(slot_setRubberBandToView()));
|
connect(move, SIGNAL(triggered()), this, SLOT(slot_setRubberBandToView()));
|
||||||
connect(add_line, SIGNAL(triggered()), this, SLOT(slot_setNoDragToView()));
|
connect(add_line, SIGNAL(triggered()), this, SLOT(slot_setNoDragToView()));
|
||||||
connect(add_rectangle, SIGNAL(triggered()), this, SLOT(slot_setNoDragToView()));
|
|
||||||
connect(add_ellipse, SIGNAL(triggered()), this, SLOT(slot_setNoDragToView()));
|
connect(add_ellipse, SIGNAL(triggered()), this, SLOT(slot_setNoDragToView()));
|
||||||
connect(add_circle, SIGNAL(triggered()), this, SLOT(slot_setNoDragToView()));
|
connect(add_circle, SIGNAL(triggered()), this, SLOT(slot_setNoDragToView()));
|
||||||
connect(add_polygon, SIGNAL(triggered()), this, SLOT(slot_setNoDragToView()));
|
connect(add_polygon, SIGNAL(triggered()), this, SLOT(slot_setNoDragToView()));
|
||||||
@@ -208,7 +166,6 @@ void QETElementEditor::setupActions() {
|
|||||||
|
|
||||||
move -> setCheckable(true);
|
move -> setCheckable(true);
|
||||||
add_line -> setCheckable(true);
|
add_line -> setCheckable(true);
|
||||||
add_rectangle -> setCheckable(true);
|
|
||||||
add_ellipse -> setCheckable(true);
|
add_ellipse -> setCheckable(true);
|
||||||
add_circle -> setCheckable(true);
|
add_circle -> setCheckable(true);
|
||||||
add_polygon -> setCheckable(true);
|
add_polygon -> setCheckable(true);
|
||||||
@@ -220,17 +177,16 @@ void QETElementEditor::setupActions() {
|
|||||||
parts = new QActionGroup(this);
|
parts = new QActionGroup(this);
|
||||||
parts -> addAction(move);
|
parts -> addAction(move);
|
||||||
parts -> addAction(add_line);
|
parts -> addAction(add_line);
|
||||||
parts -> addAction(add_rectangle);
|
|
||||||
parts -> addAction(add_ellipse);
|
parts -> addAction(add_ellipse);
|
||||||
parts -> addAction(add_circle);
|
parts -> addAction(add_circle);
|
||||||
parts -> addAction(add_polygon);
|
parts -> addAction(add_polygon);
|
||||||
parts -> addAction(add_arc);
|
|
||||||
parts -> addAction(add_text);
|
parts -> addAction(add_text);
|
||||||
|
parts -> addAction(add_arc);
|
||||||
parts -> addAction(add_textfield);
|
parts -> addAction(add_textfield);
|
||||||
parts -> addAction(add_terminal);
|
parts -> addAction(add_terminal);
|
||||||
parts -> setExclusive(true);
|
parts -> setExclusive(true);
|
||||||
|
|
||||||
parts_toolbar = new QToolBar(tr("Parties", "toolbar title"), this);
|
parts_toolbar = new QToolBar(tr("Parties"), this);
|
||||||
parts_toolbar -> setObjectName("parts");
|
parts_toolbar -> setObjectName("parts");
|
||||||
foreach (QAction *action, parts -> actions()) parts_toolbar -> addAction(action);
|
foreach (QAction *action, parts -> actions()) parts_toolbar -> addAction(action);
|
||||||
move -> setChecked(true);
|
move -> setChecked(true);
|
||||||
@@ -242,13 +198,13 @@ void QETElementEditor::setupActions() {
|
|||||||
parts_toolbar -> addAction(xml_preview);
|
parts_toolbar -> addAction(xml_preview);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
main_toolbar = new QToolBar(tr("Outils", "toolbar title"), this);
|
main_toolbar = new QToolBar(tr("Outils"), this);
|
||||||
main_toolbar -> setObjectName("main_toolbar");
|
main_toolbar -> setObjectName("main_toolbar");
|
||||||
view_toolbar = new QToolBar(tr("Affichage", "toolbar title"), this);
|
view_toolbar = new QToolBar(tr("Affichage"), this);
|
||||||
view_toolbar -> setObjectName("display");
|
view_toolbar -> setObjectName("display");
|
||||||
element_toolbar = new QToolBar(tr("\311l\351ment", "toolbar title"), this);
|
element_toolbar = new QToolBar(tr("\311l\351ment"), this);
|
||||||
element_toolbar -> setObjectName("element_toolbar");
|
element_toolbar -> setObjectName("element_toolbar");
|
||||||
depth_toolbar = new QToolBar(tr("Profondeur", "toolbar title"), this);
|
depth_toolbar = new QToolBar(tr("Profondeur"), this);
|
||||||
depth_toolbar -> setObjectName("depth_toolbar");
|
depth_toolbar -> setObjectName("depth_toolbar");
|
||||||
|
|
||||||
main_toolbar -> addAction(new_element);
|
main_toolbar -> addAction(new_element);
|
||||||
@@ -281,7 +237,6 @@ void QETElementEditor::setupActions() {
|
|||||||
|
|
||||||
connect(ce_scene, SIGNAL(selectionChanged()), this, SLOT(slot_updateInformations()));
|
connect(ce_scene, SIGNAL(selectionChanged()), this, SLOT(slot_updateInformations()));
|
||||||
connect(ce_scene, SIGNAL(selectionChanged()), this, SLOT(slot_updateMenus()));
|
connect(ce_scene, SIGNAL(selectionChanged()), this, SLOT(slot_updateMenus()));
|
||||||
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(slot_updateMenus()));
|
|
||||||
connect(&(ce_scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(slot_updateMenus()));
|
connect(&(ce_scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(slot_updateMenus()));
|
||||||
connect(&(ce_scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(slot_updateTitle()));
|
connect(&(ce_scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(slot_updateTitle()));
|
||||||
connect(&(ce_scene -> undoStack()), SIGNAL(indexChanged(int)), this, SLOT(slot_updatePartsList()));
|
connect(&(ce_scene -> undoStack()), SIGNAL(indexChanged(int)), this, SLOT(slot_updatePartsList()));
|
||||||
@@ -305,12 +260,8 @@ void QETElementEditor::setupMenus() {
|
|||||||
|
|
||||||
file_menu -> addAction(new_element);
|
file_menu -> addAction(new_element);
|
||||||
file_menu -> addAction(open);
|
file_menu -> addAction(open);
|
||||||
file_menu -> addAction(open_file);
|
|
||||||
file_menu -> addMenu(QETApp::elementsRecentFiles() -> menu());
|
|
||||||
connect(QETApp::elementsRecentFiles(), SIGNAL(fileOpeningRequested(const QString &)), this, SLOT(openRecentFile(const QString &)));
|
|
||||||
file_menu -> addAction(save);
|
file_menu -> addAction(save);
|
||||||
file_menu -> addAction(save_as);
|
file_menu -> addAction(save_as);
|
||||||
file_menu -> addAction(save_as_file);
|
|
||||||
file_menu -> addSeparator();
|
file_menu -> addSeparator();
|
||||||
file_menu -> addAction(reload);
|
file_menu -> addAction(reload);
|
||||||
file_menu -> addSeparator();
|
file_menu -> addSeparator();
|
||||||
@@ -323,11 +274,6 @@ void QETElementEditor::setupMenus() {
|
|||||||
edit_menu -> addAction(deselectall);
|
edit_menu -> addAction(deselectall);
|
||||||
edit_menu -> addAction(inv_select);
|
edit_menu -> addAction(inv_select);
|
||||||
edit_menu -> addSeparator();
|
edit_menu -> addSeparator();
|
||||||
edit_menu -> addAction(cut);
|
|
||||||
edit_menu -> addAction(copy);
|
|
||||||
edit_menu -> addAction(paste);
|
|
||||||
edit_menu -> addAction(paste_in_area);
|
|
||||||
edit_menu -> addSeparator();
|
|
||||||
edit_menu -> addAction(edit_delete);
|
edit_menu -> addAction(edit_delete);
|
||||||
edit_menu -> addSeparator();
|
edit_menu -> addSeparator();
|
||||||
edit_menu -> addAction(edit_names);
|
edit_menu -> addAction(edit_names);
|
||||||
@@ -360,13 +306,6 @@ void QETElementEditor::setupMenus() {
|
|||||||
*/
|
*/
|
||||||
void QETElementEditor::slot_updateMenus() {
|
void QETElementEditor::slot_updateMenus() {
|
||||||
bool selected_items = !ce_scene -> selectedItems().isEmpty();
|
bool selected_items = !ce_scene -> selectedItems().isEmpty();
|
||||||
bool clipboard_elmt = ElementScene::clipboardMayContainElement();
|
|
||||||
|
|
||||||
deselectall -> setEnabled(selected_items);
|
|
||||||
cut -> setEnabled(selected_items);
|
|
||||||
copy -> setEnabled(selected_items);
|
|
||||||
paste -> setEnabled(clipboard_elmt);
|
|
||||||
paste_in_area -> setEnabled(clipboard_elmt);
|
|
||||||
edit_delete -> setEnabled(selected_items);
|
edit_delete -> setEnabled(selected_items);
|
||||||
edit_forward -> setEnabled(selected_items);
|
edit_forward -> setEnabled(selected_items);
|
||||||
edit_raise -> setEnabled(selected_items);
|
edit_raise -> setEnabled(selected_items);
|
||||||
@@ -381,10 +320,10 @@ void QETElementEditor::slot_updateMenus() {
|
|||||||
void QETElementEditor::slot_updateTitle() {
|
void QETElementEditor::slot_updateTitle() {
|
||||||
QString title = min_title;
|
QString title = min_title;
|
||||||
title += " - " + ce_scene -> names().name() + " ";
|
title += " - " + ce_scene -> names().name() + " ";
|
||||||
if (!filename_.isEmpty() || !location_.isNull()) {
|
if (_filename != QString()) {
|
||||||
if (!ce_scene -> undoStack().isClean()) title += tr("[Modifi\351]", "window title tag");
|
if (!ce_scene -> undoStack().isClean()) title += tr("[Modifi\351]");
|
||||||
|
if (isReadOnly()) title += tr(" [lecture seule]");
|
||||||
}
|
}
|
||||||
if (isReadOnly()) title += tr(" [lecture seule]", "window title tag");
|
|
||||||
setWindowTitle(title);
|
setWindowTitle(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,25 +341,19 @@ void QETElementEditor::setupInterface() {
|
|||||||
// widget par defaut dans le QDockWidget
|
// widget par defaut dans le QDockWidget
|
||||||
default_informations = new QLabel();
|
default_informations = new QLabel();
|
||||||
|
|
||||||
// ScrollArea pour accueillir un widget d'edition (change a la volee)
|
|
||||||
tools_dock_scroll_area_ = new QScrollArea();
|
|
||||||
|
|
||||||
// Pile de widgets pour accueillir les deux widgets precedents
|
|
||||||
tools_dock_stack_ = new QStackedWidget();
|
|
||||||
tools_dock_stack_ -> insertWidget(0, default_informations);
|
|
||||||
tools_dock_stack_ -> insertWidget(1, tools_dock_scroll_area_);
|
|
||||||
|
|
||||||
// panel sur le cote pour editer les parties
|
// panel sur le cote pour editer les parties
|
||||||
tools_dock = new QDockWidget(tr("Informations", "dock title"), this);
|
tools_dock = new QDockWidget(tr("Informations"), this);
|
||||||
tools_dock -> setObjectName("informations");
|
tools_dock -> setObjectName("informations");
|
||||||
tools_dock -> setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
tools_dock -> setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
||||||
tools_dock -> setFeatures(QDockWidget::AllDockWidgetFeatures);
|
tools_dock -> setFeatures(QDockWidget::AllDockWidgetFeatures);
|
||||||
tools_dock -> setMinimumWidth(380);
|
tools_dock -> setMinimumWidth(290);
|
||||||
addDockWidget(Qt::RightDockWidgetArea, tools_dock);
|
addDockWidget(Qt::RightDockWidgetArea, tools_dock);
|
||||||
tools_dock -> setWidget(tools_dock_stack_);
|
QWidget *info_widget = new QWidget();
|
||||||
|
info_widget -> setLayout(new QVBoxLayout(info_widget));
|
||||||
|
tools_dock -> setWidget(info_widget);
|
||||||
|
|
||||||
// panel sur le cote pour les annulations
|
// panel sur le cote pour les annulations
|
||||||
undo_dock = new QDockWidget(tr("Annulations", "dock title"), this);
|
undo_dock = new QDockWidget(tr("Annulations"), this);
|
||||||
undo_dock -> setObjectName("undo");
|
undo_dock -> setObjectName("undo");
|
||||||
undo_dock -> setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
undo_dock -> setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
||||||
undo_dock -> setFeatures(QDockWidget::AllDockWidgetFeatures);
|
undo_dock -> setFeatures(QDockWidget::AllDockWidgetFeatures);
|
||||||
@@ -438,7 +371,7 @@ void QETElementEditor::setupInterface() {
|
|||||||
connect(ce_scene, SIGNAL(partsZValueChanged()), this, SLOT(slot_createPartsList()));
|
connect(ce_scene, SIGNAL(partsZValueChanged()), this, SLOT(slot_createPartsList()));
|
||||||
connect(ce_scene, SIGNAL(selectionChanged()), this, SLOT(slot_updatePartsList()));
|
connect(ce_scene, SIGNAL(selectionChanged()), this, SLOT(slot_updatePartsList()));
|
||||||
connect(parts_list, SIGNAL(itemSelectionChanged()), this, SLOT(slot_updateSelectionFromPartsList()));
|
connect(parts_list, SIGNAL(itemSelectionChanged()), this, SLOT(slot_updateSelectionFromPartsList()));
|
||||||
parts_dock = new QDockWidget(tr("Parties", "dock title"), this);
|
parts_dock = new QDockWidget(tr("Parties"), this);
|
||||||
parts_dock -> setObjectName("parts_list");
|
parts_dock -> setObjectName("parts_list");
|
||||||
parts_dock -> setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
parts_dock -> setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
||||||
parts_dock -> setFeatures(QDockWidget::AllDockWidgetFeatures);
|
parts_dock -> setFeatures(QDockWidget::AllDockWidgetFeatures);
|
||||||
@@ -450,7 +383,7 @@ void QETElementEditor::setupInterface() {
|
|||||||
slot_createPartsList();
|
slot_createPartsList();
|
||||||
|
|
||||||
// barre d'etat
|
// barre d'etat
|
||||||
statusBar() -> showMessage(tr("\311diteur d'\351l\351ments", "status bar message"));
|
statusBar() -> showMessage(tr("\311diteur d'\351l\351ments"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -492,23 +425,31 @@ void QETElementEditor::slot_updateInformations() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearToolsDock();
|
// recupere le layout
|
||||||
|
QLayout *layout = tools_dock -> widget() -> layout();
|
||||||
|
|
||||||
|
// enleve les widgets deja presents
|
||||||
|
QLayoutItem *qli;
|
||||||
|
while ((qli = layout -> takeAt(0)) != 0) {
|
||||||
|
if (QWidget *w = qli -> widget()) {
|
||||||
|
layout -> removeWidget(w);
|
||||||
|
w -> setParent(0);
|
||||||
|
w -> hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (selected_parts.size() == 1) {
|
if (selected_parts.size() == 1) {
|
||||||
// recupere le premier CustomElementPart et en ajoute le widget d'edition
|
// recupere le premier CustomElementPart et en ajoute le widget d'edition
|
||||||
QWidget *edit_widget = selected_parts.first() -> elementInformations();
|
QWidget *edit_widget = selected_parts.first() -> elementInformations();
|
||||||
tools_dock_scroll_area_ -> setWidget(edit_widget);
|
layout -> addWidget(edit_widget);
|
||||||
tools_dock_stack_ -> setCurrentIndex(1);
|
edit_widget -> show();
|
||||||
} else {
|
} else {
|
||||||
default_informations -> setText(
|
default_informations -> setText(
|
||||||
tr(
|
selected_parts.size() ?
|
||||||
"%n partie(s) s\351lectionn\351e(s).",
|
QString("%1").arg(selected_parts.size()) + tr(" parties s\351lectionn\351es.") :
|
||||||
"",
|
tr("Aucune partie s\351lectionn\351e.")
|
||||||
selected_parts.size()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
default_informations -> setAlignment(Qt::AlignHCenter | Qt::AlignTop);
|
layout -> addWidget(default_informations);
|
||||||
tools_dock_stack_ -> setCurrentIndex(0);
|
default_informations -> show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,33 +465,6 @@ void QETElementEditor::xmlPreview() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Verifie si l'ensemble des parties graphiques consituant l'element en cours
|
|
||||||
d'edition est bien contenu dans le rectangle representant les limites de
|
|
||||||
l'element. Si ce n'est pas le cas, l'utilisateur en est informe.
|
|
||||||
@return true si la situation est ok, false sinon
|
|
||||||
*/
|
|
||||||
bool QETElementEditor::checkElementSize() {
|
|
||||||
if (ce_scene -> borderContainsEveryParts()) {
|
|
||||||
return(true);
|
|
||||||
} else {
|
|
||||||
QMessageBox::warning(
|
|
||||||
this,
|
|
||||||
tr("Dimensions de l'\351l\351ment", "messagebox title"),
|
|
||||||
tr(
|
|
||||||
"Attention : certaines parties graphiques (textes, cercles, "
|
|
||||||
"lignes...) semblent d\351border du cadre de l'\351l\351ment. Cela"
|
|
||||||
" risque de g\351n\351rer des bugs graphiques lors de leur "
|
|
||||||
"manipulation sur un sch\351ma. Vous pouvez corriger cela soit "
|
|
||||||
"en d\351pla\347ant ces parties, soit en vous rendant dans "
|
|
||||||
"\311dition > \311diter la taille et le point de saisie."
|
|
||||||
, "messagebox content"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Charge un fichier
|
Charge un fichier
|
||||||
@param filepath Chemin du fichier a charger
|
@param filepath Chemin du fichier a charger
|
||||||
@@ -563,7 +477,7 @@ void QETElementEditor::fromFile(const QString &filepath) {
|
|||||||
QFileInfo infos_file(filepath);
|
QFileInfo infos_file(filepath);
|
||||||
if (!infos_file.exists() || !infos_file.isFile()) {
|
if (!infos_file.exists() || !infos_file.isFile()) {
|
||||||
state = false;
|
state = false;
|
||||||
error_message = QString(tr("Le fichier %1 n'existe pas.", "message box content")).arg(filepath);
|
error_message = tr("Le fichier ") + filepath + tr(" n'existe pas.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// le fichier doit etre lisible
|
// le fichier doit etre lisible
|
||||||
@@ -571,7 +485,7 @@ void QETElementEditor::fromFile(const QString &filepath) {
|
|||||||
if (state) {
|
if (state) {
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
state = false;
|
state = false;
|
||||||
error_message = QString(tr("Impossible d'ouvrir le fichier %1.", "message box content")).arg(filepath);
|
error_message = tr("Impossible d'ouvrir le fichier ") + filepath + ".";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -580,13 +494,13 @@ void QETElementEditor::fromFile(const QString &filepath) {
|
|||||||
if (state) {
|
if (state) {
|
||||||
if (!document_xml.setContent(&file)) {
|
if (!document_xml.setContent(&file)) {
|
||||||
state = false;
|
state = false;
|
||||||
error_message = tr("Ce fichier n'est pas un document XML valide", "message box content");
|
error_message = tr("Ce fichier n'est pas un document XML valide");
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!state) {
|
if (!state) {
|
||||||
QMessageBox::critical(this, tr("Erreur", "toolbar title"), error_message);
|
QMessageBox::critical(this, tr("Erreur"), error_message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -598,18 +512,18 @@ void QETElementEditor::fromFile(const QString &filepath) {
|
|||||||
if (!infos_file.isWritable()) {
|
if (!infos_file.isWritable()) {
|
||||||
QMessageBox::warning(
|
QMessageBox::warning(
|
||||||
this,
|
this,
|
||||||
tr("\311dition en lecture seule", "message box title"),
|
tr("\311dition en lecture seule"),
|
||||||
tr("Vous n'avez pas les privil\350ges n\351cessaires pour modifier cet \351lement. Il sera donc ouvert en lecture seule.", "message box content")
|
tr("Vous n'avez pas les privil\350ges n\351cessaires pour modifier cet \351lement. Il sera donc ouvert en lecture seule.")
|
||||||
);
|
);
|
||||||
setReadOnly(true);
|
setReadOnly(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// memorise le fichier
|
// memorise le fichier
|
||||||
setFileName(filepath);
|
setFileName(filepath);
|
||||||
QETApp::elementsRecentFiles() -> fileWasOpened(filepath);
|
|
||||||
slot_updateMenus();
|
slot_updateMenus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Enregistre l'element vers un fichier
|
Enregistre l'element vers un fichier
|
||||||
@param fn Chemin du fichier a enregistrer
|
@param fn Chemin du fichier a enregistrer
|
||||||
@@ -618,7 +532,7 @@ void QETElementEditor::fromFile(const QString &filepath) {
|
|||||||
bool QETElementEditor::toFile(const QString &fn) {
|
bool QETElementEditor::toFile(const QString &fn) {
|
||||||
QFile file(fn);
|
QFile file(fn);
|
||||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
QMessageBox::warning(this, tr("Erreur", "message box title"), tr("Impossible d'\351crire dans ce fichier", "message box content"));
|
QMessageBox::warning(this, tr("Erreur"), tr("Impossible d'ecrire dans ce fichier"));
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
QTextStream out(&file);
|
QTextStream out(&file);
|
||||||
@@ -628,45 +542,6 @@ bool QETElementEditor::toFile(const QString &fn) {
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Enregistre l'element vers un emplacement
|
|
||||||
@param location Emplacement de l'element a enregistrer
|
|
||||||
@return true en cas de reussite, false sinon
|
|
||||||
*/
|
|
||||||
bool QETElementEditor::toLocation(const ElementsLocation &location) {
|
|
||||||
ElementsCollectionItem *item = QETApp::collectionItem(location);
|
|
||||||
ElementDefinition *element;
|
|
||||||
if (item) {
|
|
||||||
// l'element existe deja
|
|
||||||
element = qobject_cast<ElementDefinition *>(item);
|
|
||||||
} else {
|
|
||||||
// l'element n'existe pas encore, on demande sa creation
|
|
||||||
element = QETApp::createElement(location);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!element) {
|
|
||||||
QMessageBox::critical(
|
|
||||||
this,
|
|
||||||
tr("Erreur", "message box title"),
|
|
||||||
tr("Impossible d'atteindre l'\351l\351ment", "message box content")
|
|
||||||
);
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// enregistre l'element
|
|
||||||
element -> setXml(ce_scene -> toXml().documentElement());
|
|
||||||
if (!element -> write()) {
|
|
||||||
QMessageBox::critical(
|
|
||||||
this,
|
|
||||||
tr("Erreur", "message box title"),
|
|
||||||
tr("Impossible d'enregistrer l'\351l\351ment", "message box content")
|
|
||||||
);
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
specifie si l'editeur d'element doit etre en mode lecture seule
|
specifie si l'editeur d'element doit etre en mode lecture seule
|
||||||
@param ro true pour activer le mode lecture seule, false pour le desactiver
|
@param ro true pour activer le mode lecture seule, false pour le desactiver
|
||||||
@@ -680,9 +555,6 @@ void QETElementEditor::setReadOnly(bool ro) {
|
|||||||
ce_view -> setInteractive(!ro);
|
ce_view -> setInteractive(!ro);
|
||||||
|
|
||||||
// active / desactive l'edition de la taille, du hotspot, des noms et des orientations
|
// active / desactive l'edition de la taille, du hotspot, des noms et des orientations
|
||||||
cut -> setEnabled(!ro);
|
|
||||||
copy -> setEnabled(!ro);
|
|
||||||
paste -> setEnabled(!ro);
|
|
||||||
selectall -> setEnabled(!ro);
|
selectall -> setEnabled(!ro);
|
||||||
deselectall -> setEnabled(!ro);
|
deselectall -> setEnabled(!ro);
|
||||||
inv_select -> setEnabled(!ro);
|
inv_select -> setEnabled(!ro);
|
||||||
@@ -706,63 +578,24 @@ bool QETElementEditor::isReadOnly() const {
|
|||||||
Lance l'assistant de creation d'un nouvel element.
|
Lance l'assistant de creation d'un nouvel element.
|
||||||
*/
|
*/
|
||||||
void QETElementEditor::slot_new() {
|
void QETElementEditor::slot_new() {
|
||||||
NewElementWizard new_element_wizard(this);
|
NewElementWizard new_element_wizard;
|
||||||
new_element_wizard.exec();
|
new_element_wizard.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Ouvre un element
|
Ouvre un fichier
|
||||||
*/
|
*/
|
||||||
void QETElementEditor::slot_open() {
|
void QETElementEditor::slot_open() {
|
||||||
// demande le chemin virtuel de l'element a ouvrir a l'utilisateur
|
|
||||||
ElementsLocation location = ElementDialog::getOpenElementLocation();
|
|
||||||
if (location.isNull()) return;
|
|
||||||
QETElementEditor *cee = new QETElementEditor();
|
|
||||||
cee -> fromLocation(location);
|
|
||||||
cee -> show();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Ouvre un fichier
|
|
||||||
Demande un fichier a l'utilisateur et ouvre ce fichier
|
|
||||||
*/
|
|
||||||
void QETElementEditor::slot_openFile() {
|
|
||||||
// demande un nom de fichier a ouvrir a l'utilisateur
|
// demande un nom de fichier a ouvrir a l'utilisateur
|
||||||
QString user_filename = QFileDialog::getOpenFileName(
|
QString user_filename = QFileDialog::getOpenFileName(
|
||||||
this,
|
this,
|
||||||
tr("Ouvrir un fichier", "dialog title"),
|
tr("Ouvrir un fichier"),
|
||||||
filename_.isEmpty() ? QETApp::customElementsDir() : QDir(filename_).absolutePath(),
|
_filename.isEmpty() ? QETApp::customElementsDir() : QDir(_filename).absolutePath(),
|
||||||
tr(
|
tr("\311l\351ments QElectroTech (*.elmt);;Fichiers XML (*.xml);;Tous les fichiers (*)")
|
||||||
"\311l\351ments QElectroTech (*.elmt);;"
|
|
||||||
"Fichiers XML (*.xml);;"
|
|
||||||
"Tous les fichiers (*)",
|
|
||||||
"filetypes allowed when opening an element file"
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
openElement(user_filename);
|
if (user_filename.isEmpty()) return;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Slot utilise pour ouvrir un fichier recent.
|
|
||||||
Transfere filepath au slot openElement seulement si cet editeur est actif
|
|
||||||
@param filepath Fichier a ouvrir
|
|
||||||
@see openElement
|
|
||||||
*/
|
|
||||||
void QETElementEditor::openRecentFile(const QString &filepath) {
|
|
||||||
if (qApp -> activeWindow() != this) return;
|
|
||||||
openElement(filepath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Ouvre un fichier element dans un nouvel editeur
|
|
||||||
Cette methode ne controle pas si le fichier est deja ouvert
|
|
||||||
@param filepath Fichier a ouvrir
|
|
||||||
@see fromFile
|
|
||||||
*/
|
|
||||||
void QETElementEditor::openElement(const QString &filepath) {
|
|
||||||
if (filepath.isEmpty()) return;
|
|
||||||
QETElementEditor *cee = new QETElementEditor();
|
QETElementEditor *cee = new QETElementEditor();
|
||||||
cee -> fromFile(filepath);
|
cee -> fromFile(user_filename);
|
||||||
cee -> show();
|
cee -> show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -770,13 +603,16 @@ void QETElementEditor::openElement(const QString &filepath) {
|
|||||||
Recharge l'element edite
|
Recharge l'element edite
|
||||||
*/
|
*/
|
||||||
void QETElementEditor::slot_reload() {
|
void QETElementEditor::slot_reload() {
|
||||||
|
// impossible de recharger un element non enregistre
|
||||||
|
if (_filename.isEmpty()) return;
|
||||||
|
|
||||||
// s'il ya des modifications, on demande a l'utilisateur s'il est certain
|
// s'il ya des modifications, on demande a l'utilisateur s'il est certain
|
||||||
// de vouloir recharger
|
// de vouloir recharger
|
||||||
if (!ce_scene -> undoStack().isClean()) {
|
if (!ce_scene -> undoStack().isClean()) {
|
||||||
QMessageBox::StandardButton answer = QMessageBox::question(
|
QMessageBox::StandardButton answer = QMessageBox::question(
|
||||||
this,
|
this,
|
||||||
tr("Recharger l'\351l\351ment", "dialog title"),
|
tr("Recharger l'\351l\351ment"),
|
||||||
tr("Vous avez efffectu\351 des modifications sur cet \351l\351ment. Si vous le rechargez, ces modifications seront perdues. Voulez-vous vraiment recharger l'\351l\351ment ?", "dialog content"),
|
tr("Vous avez efffectu\351 des modifications sur cet \351l\351ment. Si vous le rechargez, ces modifications seront perdues. Voulez-vous vraiment recharger l'\351l\351ment ?"),
|
||||||
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
|
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
|
||||||
QMessageBox::Cancel
|
QMessageBox::Cancel
|
||||||
);
|
);
|
||||||
@@ -784,19 +620,8 @@ void QETElementEditor::slot_reload() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// recharge l'element
|
// recharge l'element
|
||||||
if (opened_from_file) {
|
ce_scene -> reset();
|
||||||
// l'element a ete ouvert a partir d'un chemin de fichier
|
fromFile(_filename);
|
||||||
ce_scene -> reset();
|
|
||||||
fromFile(filename_);
|
|
||||||
} else {
|
|
||||||
// l'element a ete ouvert a partir d'un emplacement (ElementsLocation)
|
|
||||||
// il peut s'agir aussi bien d'un fichier que d'un element XML
|
|
||||||
if (ElementsCollectionItem *item = QETApp::collectionItem(location_)) {
|
|
||||||
item -> reload();
|
|
||||||
ce_scene -> reset();
|
|
||||||
fromLocation(location_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -806,57 +631,24 @@ void QETElementEditor::slot_reload() {
|
|||||||
@see slot_saveAs()
|
@see slot_saveAs()
|
||||||
*/
|
*/
|
||||||
bool QETElementEditor::slot_save() {
|
bool QETElementEditor::slot_save() {
|
||||||
// verification avant d'enregistrer le fichier
|
|
||||||
checkElementSize();
|
|
||||||
|
|
||||||
// si on ne connait pas le nom du fichier en cours, enregistrer revient a enregistrer sous
|
// si on ne connait pas le nom du fichier en cours, enregistrer revient a enregistrer sous
|
||||||
if (opened_from_file) {
|
if (_filename.isEmpty()) return(slot_saveAs());
|
||||||
if (filename_.isEmpty()) return(slot_saveAsFile());
|
// sinon on enregistre dans le nom de fichier connu
|
||||||
// sinon on enregistre dans le nom de fichier connu
|
bool result_save = toFile(_filename);
|
||||||
bool result_save = toFile(filename_);
|
if (result_save) ce_scene -> undoStack().setClean();
|
||||||
if (result_save) ce_scene -> undoStack().setClean();
|
|
||||||
return(result_save);
|
|
||||||
} else {
|
|
||||||
if (location_.isNull()) return(slot_saveAs());
|
|
||||||
// sinon on enregistre a l'emplacement connu
|
|
||||||
bool result_save = toLocation(location_);
|
|
||||||
if (result_save) ce_scene -> undoStack().setClean();
|
|
||||||
return(result_save);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Demande une localisation a l'utilisateur et enregistre l'element
|
|
||||||
*/
|
|
||||||
bool QETElementEditor::slot_saveAs() {
|
|
||||||
// demande une localisation a l'utilisateur
|
|
||||||
ElementsLocation location = ElementDialog::getSaveElementLocation();
|
|
||||||
if (location.isNull()) return(false);
|
|
||||||
|
|
||||||
// tente l'enregistrement
|
|
||||||
bool result_save = toLocation(location);
|
|
||||||
if (result_save) {
|
|
||||||
setLocation(location);
|
|
||||||
ce_scene -> undoStack().setClean();
|
|
||||||
}
|
|
||||||
|
|
||||||
// retourne un booleen representatif de la reussite de l'enregistrement
|
|
||||||
return(result_save);
|
return(result_save);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Demande un nom de fichier a l'utilisateur et enregistre l'element
|
Demande un nom de fichier a l'utilisateur et enregistre l'element
|
||||||
*/
|
*/
|
||||||
bool QETElementEditor::slot_saveAsFile() {
|
bool QETElementEditor::slot_saveAs() {
|
||||||
// demande un nom de fichier a l'utilisateur pour enregistrer l'element
|
// demande un nom de fichier a l'utilisateur pour enregistrer l'element
|
||||||
QString fn = QFileDialog::getSaveFileName(
|
QString fn = QFileDialog::getSaveFileName(
|
||||||
this,
|
this,
|
||||||
tr("Enregistrer sous", "dialog title"),
|
tr("Enregistrer sous"),
|
||||||
filename_.isEmpty() ? QETApp::customElementsDir() : QDir(filename_).absolutePath(),
|
_filename.isEmpty() ? QETApp::customElementsDir() : QDir(_filename).absolutePath(),
|
||||||
tr(
|
tr("\311l\351ments QElectroTech (*.elmt)")
|
||||||
"\311l\351ments QElectroTech (*.elmt)",
|
|
||||||
"filetypes allowed when saving an element file"
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
// si aucun nom n'est entre, renvoie faux.
|
// si aucun nom n'est entre, renvoie faux.
|
||||||
if (fn.isEmpty()) return(false);
|
if (fn.isEmpty()) return(false);
|
||||||
@@ -867,7 +659,6 @@ bool QETElementEditor::slot_saveAsFile() {
|
|||||||
// si l'enregistrement reussit, le nom du fichier est conserve
|
// si l'enregistrement reussit, le nom du fichier est conserve
|
||||||
if (result_save) {
|
if (result_save) {
|
||||||
setFileName(fn);
|
setFileName(fn);
|
||||||
QETApp::elementsRecentFiles() -> fileWasOpened(fn);
|
|
||||||
ce_scene -> undoStack().setClean();
|
ce_scene -> undoStack().setClean();
|
||||||
}
|
}
|
||||||
// retourne un booleen representatif de la reussite de l'enregistrement
|
// retourne un booleen representatif de la reussite de l'enregistrement
|
||||||
@@ -885,14 +676,9 @@ bool QETElementEditor::canClose() {
|
|||||||
// demande d'abord a l'utilisateur s'il veut enregistrer l'element en cours
|
// demande d'abord a l'utilisateur s'il veut enregistrer l'element en cours
|
||||||
QMessageBox::StandardButton answer = QMessageBox::question(
|
QMessageBox::StandardButton answer = QMessageBox::question(
|
||||||
this,
|
this,
|
||||||
tr("Enregistrer l'\351l\351ment en cours ?", "dialog title"),
|
tr("Enregistrer l'\351l\351ment en cours ?"),
|
||||||
QString(
|
tr("Voulez-vous enregistrer l'\351l\351ment ") + ce_scene -> names().name() + tr(" ?"),
|
||||||
tr(
|
QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel,
|
||||||
"Voulez-vous enregistrer l'\351l\351ment %1 ?",
|
|
||||||
"dialog content - %1 is an element name"
|
|
||||||
)
|
|
||||||
).arg(ce_scene -> names().name()),
|
|
||||||
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
|
|
||||||
QMessageBox::Cancel
|
QMessageBox::Cancel
|
||||||
);
|
);
|
||||||
bool result;
|
bool result;
|
||||||
@@ -904,20 +690,6 @@ bool QETElementEditor::canClose() {
|
|||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Enleve et cache le widget affiche par le dock permettant d'editer les
|
|
||||||
parties.
|
|
||||||
@return le widget enleve, ou 0 s'il n'y avait pas de widget a enlever
|
|
||||||
*/
|
|
||||||
QWidget *QETElementEditor::clearToolsDock() {
|
|
||||||
if (QWidget *previous_widget = tools_dock_scroll_area_ -> takeWidget()) {
|
|
||||||
previous_widget -> setParent(0);
|
|
||||||
previous_widget -> hide();
|
|
||||||
return(previous_widget);
|
|
||||||
}
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Permet de quitter l'editeur lors de la fermeture de la fenetre principale
|
Permet de quitter l'editeur lors de la fermeture de la fenetre principale
|
||||||
@param qce Le QCloseEvent correspondant a l'evenement de fermeture
|
@param qce Le QCloseEvent correspondant a l'evenement de fermeture
|
||||||
@@ -989,7 +761,6 @@ void QETElementEditor::slot_updateSelectionFromPartsList() {
|
|||||||
parts_list -> blockSignals(false);
|
parts_list -> blockSignals(false);
|
||||||
ce_scene -> blockSignals(false);
|
ce_scene -> blockSignals(false);
|
||||||
slot_updateInformations();
|
slot_updateInformations();
|
||||||
slot_updateMenus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Lit les parametres de l'editeur d'element
|
/// Lit les parametres de l'editeur d'element
|
||||||
@@ -1011,70 +782,3 @@ void QETElementEditor::writeSettings() {
|
|||||||
settings.setValue("elementeditor/geometry", saveGeometry());
|
settings.setValue("elementeditor/geometry", saveGeometry());
|
||||||
settings.setValue("elementeditor/state", saveState());
|
settings.setValue("elementeditor/state", saveState());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
@return les decalages horizontaux et verticaux (sous la forme d'un point) a
|
|
||||||
utiliser lors d'un copier/coller avec decalage.
|
|
||||||
*/
|
|
||||||
QPointF QETElementEditor::pasteOffset() {
|
|
||||||
QPointF paste_offset(5.0, 0.0);
|
|
||||||
return(paste_offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return Le type de mouvement a effectuer lors d'un copier/coller avec
|
|
||||||
decalage.
|
|
||||||
*/
|
|
||||||
QET::OrientedMovement QETElementEditor::pasteMovement() {
|
|
||||||
return(QET::ToEast);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@param location Emplacement de l'element a editer
|
|
||||||
*/
|
|
||||||
void QETElementEditor::fromLocation(const ElementsLocation &location) {
|
|
||||||
|
|
||||||
// l'element doit exister
|
|
||||||
ElementsCollectionItem *item = QETApp::collectionItem(location);
|
|
||||||
ElementDefinition *element = 0;
|
|
||||||
if (!item) {
|
|
||||||
QMessageBox::critical(
|
|
||||||
this,
|
|
||||||
tr("\311l\351ment inexistant.", "message box title"),
|
|
||||||
tr("L'\351l\351ment n'existe pas.", "message box content")
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!item -> isElement() || !(element = qobject_cast<ElementDefinition *>(item)) || element -> isNull()) {
|
|
||||||
QMessageBox::critical(
|
|
||||||
this,
|
|
||||||
tr("\311l\351ment inexistant.", "message box title"),
|
|
||||||
tr("Le chemin virtuel choisi ne correspond pas \340 un \351l\351ment.", "message box content")
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// le fichier doit etre un document XML
|
|
||||||
QDomDocument document_xml;
|
|
||||||
QDomNode node = document_xml.importNode(element -> xml(), true);
|
|
||||||
document_xml.appendChild(node);
|
|
||||||
|
|
||||||
// chargement de l'element
|
|
||||||
ce_scene -> fromXml(document_xml);
|
|
||||||
slot_createPartsList();
|
|
||||||
|
|
||||||
// gestion de la lecture seule
|
|
||||||
if (!element -> isWritable()) {
|
|
||||||
QMessageBox::warning(
|
|
||||||
this,
|
|
||||||
tr("\311dition en lecture seule", "message box title"),
|
|
||||||
tr("Vous n'avez pas les privil\350ges n\351cessaires pour modifier cet \351lement. Il sera donc ouvert en lecture seule.", "message box content")
|
|
||||||
);
|
|
||||||
setReadOnly(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// memorise le fichier
|
|
||||||
setLocation(location);
|
|
||||||
slot_updateMenus();
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -18,10 +18,8 @@
|
|||||||
#ifndef CUSTOM_ELEMENT_EDITOR_H
|
#ifndef CUSTOM_ELEMENT_EDITOR_H
|
||||||
#define CUSTOM_ELEMENT_EDITOR_H
|
#define CUSTOM_ELEMENT_EDITOR_H
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include "qet.h"
|
|
||||||
#include "elementscene.h"
|
#include "elementscene.h"
|
||||||
#include "orientationset.h"
|
#include "orientationset.h"
|
||||||
#include "elementslocation.h"
|
|
||||||
class ElementView;
|
class ElementView;
|
||||||
/**
|
/**
|
||||||
Cette classe represente un editeur d'element. Elle permet a l'utilisateur
|
Cette classe represente un editeur d'element. Elle permet a l'utilisateur
|
||||||
@@ -50,12 +48,6 @@ class QETElementEditor : public QMainWindow {
|
|||||||
ElementScene *ce_scene;
|
ElementScene *ce_scene;
|
||||||
/// container pour les widgets d'edition des parties
|
/// container pour les widgets d'edition des parties
|
||||||
QDockWidget *tools_dock;
|
QDockWidget *tools_dock;
|
||||||
/// Pile de widgets pour tools_dock
|
|
||||||
QStackedWidget *tools_dock_stack_;
|
|
||||||
/// label affiche lors de la selection de plusieurs elements
|
|
||||||
QLabel *default_informations;
|
|
||||||
/// ScrollArea pour le DockWidget affichant des infos sur la partie selectionnee
|
|
||||||
QScrollArea *tools_dock_scroll_area_;
|
|
||||||
/// container pour la liste des annulations
|
/// container pour la liste des annulations
|
||||||
QDockWidget *undo_dock;
|
QDockWidget *undo_dock;
|
||||||
/// Container pour la liste des parties
|
/// Container pour la liste des parties
|
||||||
@@ -63,10 +55,9 @@ class QETElementEditor : public QMainWindow {
|
|||||||
/// Liste des parties
|
/// Liste des parties
|
||||||
QListWidget *parts_list;
|
QListWidget *parts_list;
|
||||||
/// actions du menu fichier
|
/// actions du menu fichier
|
||||||
QAction *new_element, *open, *open_file, *save, *save_as, *save_as_file, *reload, *quit;
|
QAction *new_element, *open, *save, *save_as, *reload, *quit;
|
||||||
/// actions du menu edition
|
/// actions du menu edition
|
||||||
QAction *selectall, *deselectall, *inv_select;
|
QAction *selectall, *deselectall, *inv_select;
|
||||||
QAction *cut, *copy, *paste, *paste_in_area;
|
|
||||||
QAction *undo, *redo;
|
QAction *undo, *redo;
|
||||||
QAction *zoom_in, *zoom_out, *zoom_fit, *zoom_reset;
|
QAction *zoom_in, *zoom_out, *zoom_fit, *zoom_reset;
|
||||||
QAction *edit_delete, *edit_size_hs, *edit_names, *edit_ori;
|
QAction *edit_delete, *edit_size_hs, *edit_names, *edit_ori;
|
||||||
@@ -75,16 +66,14 @@ class QETElementEditor : public QMainWindow {
|
|||||||
QToolBar *parts_toolbar, *main_toolbar, *view_toolbar, *depth_toolbar, *element_toolbar;
|
QToolBar *parts_toolbar, *main_toolbar, *view_toolbar, *depth_toolbar, *element_toolbar;
|
||||||
/// actions de la barre d'outils
|
/// actions de la barre d'outils
|
||||||
QActionGroup *parts;
|
QActionGroup *parts;
|
||||||
QAction *move, *add_line, *add_circle, *add_rectangle, *add_ellipse, *add_polygon, *add_text;
|
QAction *move, *add_line, *add_circle, *add_ellipse, *add_polygon, *add_text;
|
||||||
QAction *add_arc, *add_terminal, *add_textfield;
|
QAction *add_arc, *add_terminal, *add_textfield;
|
||||||
|
/// label affiche lors de la selection de plusieurs elements
|
||||||
|
QLabel *default_informations;
|
||||||
/// titre minimal
|
/// titre minimal
|
||||||
QString min_title;
|
QString min_title;
|
||||||
/// Nom de fichier de l'element edite
|
/// Nom de fichier
|
||||||
QString filename_;
|
QString _filename;
|
||||||
/// Emplacement de l'element edite
|
|
||||||
ElementsLocation location_;
|
|
||||||
/// booleen indiquant si l'element en cours d'edition provient d'un fichier ou d'un emplacement
|
|
||||||
bool opened_from_file;
|
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
public:
|
public:
|
||||||
@@ -95,21 +84,15 @@ class QETElementEditor : public QMainWindow {
|
|||||||
void setNames(const NamesList &);
|
void setNames(const NamesList &);
|
||||||
void setOrientations(const OrientationSet &orientation_set);
|
void setOrientations(const OrientationSet &orientation_set);
|
||||||
OrientationSet orientations() const;
|
OrientationSet orientations() const;
|
||||||
void setLocation(const ElementsLocation &);
|
|
||||||
ElementsLocation location() const;
|
|
||||||
void setFileName(const QString &);
|
void setFileName(const QString &);
|
||||||
QString fileName() const;
|
QString fileName() const;
|
||||||
void setReadOnly(bool);
|
void setReadOnly(bool);
|
||||||
bool isReadOnly() const;
|
bool isReadOnly() const;
|
||||||
void fromFile(const QString &);
|
void fromFile(const QString &);
|
||||||
void fromLocation(const ElementsLocation &);
|
|
||||||
bool toFile(const QString &);
|
bool toFile(const QString &);
|
||||||
bool toLocation(const ElementsLocation &);
|
|
||||||
ElementScene *elementScene() const;
|
ElementScene *elementScene() const;
|
||||||
void readSettings();
|
void readSettings();
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
static QPointF pasteOffset();
|
|
||||||
static QET::OrientedMovement pasteMovement();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *);
|
void closeEvent(QCloseEvent *);
|
||||||
@@ -119,18 +102,13 @@ class QETElementEditor : public QMainWindow {
|
|||||||
void setupMenus();
|
void setupMenus();
|
||||||
void setupInterface();
|
void setupInterface();
|
||||||
bool canClose();
|
bool canClose();
|
||||||
QWidget *clearToolsDock();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void slot_new();
|
void slot_new();
|
||||||
void slot_open();
|
void slot_open();
|
||||||
void slot_openFile();
|
|
||||||
void openRecentFile(const QString &);
|
|
||||||
void openElement(const QString &);
|
|
||||||
void slot_reload();
|
void slot_reload();
|
||||||
bool slot_save();
|
bool slot_save();
|
||||||
bool slot_saveAs();
|
bool slot_saveAs();
|
||||||
bool slot_saveAsFile();
|
|
||||||
void slot_setRubberBandToView();
|
void slot_setRubberBandToView();
|
||||||
void slot_setNoDragToView();
|
void slot_setNoDragToView();
|
||||||
void slot_setNormalMode();
|
void slot_setNormalMode();
|
||||||
@@ -141,7 +119,6 @@ class QETElementEditor : public QMainWindow {
|
|||||||
void slot_updatePartsList();
|
void slot_updatePartsList();
|
||||||
void slot_updateSelectionFromPartsList();
|
void slot_updateSelectionFromPartsList();
|
||||||
void xmlPreview();
|
void xmlPreview();
|
||||||
bool checkElementSize();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -199,36 +176,19 @@ inline OrientationSet QETElementEditor::orientations() const {
|
|||||||
return(ce_scene -> orientations());
|
return(ce_scene -> orientations());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
@param el Le nouvel emplacement de l'element edite
|
|
||||||
*/
|
|
||||||
inline void QETElementEditor::setLocation(const ElementsLocation &el) {
|
|
||||||
location_ = el;
|
|
||||||
opened_from_file = false;
|
|
||||||
slot_updateTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
@return l'emplacement de l'element edite
|
|
||||||
*/
|
|
||||||
inline ElementsLocation QETElementEditor::location() const {
|
|
||||||
return(location_);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@param fn Le nouveau nom de fichier de l'element edite
|
@param fn Le nouveau nom de fichier de l'element edite
|
||||||
*/
|
*/
|
||||||
inline void QETElementEditor::setFileName(const QString &fn) {
|
inline void QETElementEditor::setFileName(const QString &fn) {
|
||||||
filename_ = fn;
|
_filename = fn;
|
||||||
opened_from_file = true;
|
|
||||||
slot_updateTitle();
|
slot_updateTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@return le nom de fichier de l'element edite
|
@return le nomde fichier de l'element edite
|
||||||
*/
|
*/
|
||||||
inline QString QETElementEditor::fileName() const {
|
inline QString QETElementEditor::fileName() const {
|
||||||
return(filename_);
|
return(_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -27,26 +27,26 @@
|
|||||||
StyleEditor::StyleEditor(QETElementEditor *editor, CustomElementGraphicPart *p, QWidget *parent) : ElementItemEditor(editor, parent), part(p) {
|
StyleEditor::StyleEditor(QETElementEditor *editor, CustomElementGraphicPart *p, QWidget *parent) : ElementItemEditor(editor, parent), part(p) {
|
||||||
// couleur
|
// couleur
|
||||||
color = new QButtonGroup(this);
|
color = new QButtonGroup(this);
|
||||||
color -> addButton(black_color = new QRadioButton(tr("Noir", "element part color")), CustomElementGraphicPart::BlackColor);
|
color -> addButton(black_color = new QRadioButton(tr("Noir")), CustomElementGraphicPart::BlackColor);
|
||||||
color -> addButton(white_color = new QRadioButton(tr("Blanc", "element part color")), CustomElementGraphicPart::WhiteColor);
|
color -> addButton(white_color = new QRadioButton(tr("Blanc")), CustomElementGraphicPart::WhiteColor);
|
||||||
|
|
||||||
// style
|
// style
|
||||||
style = new QButtonGroup(this);
|
style = new QButtonGroup(this);
|
||||||
style -> addButton(normal_style = new QRadioButton(tr("Normal", "element part line style")), CustomElementGraphicPart::NormalStyle);
|
style -> addButton(normal_style = new QRadioButton(tr("Normal")), CustomElementGraphicPart::NormalStyle);
|
||||||
style -> addButton(dashed_style = new QRadioButton(tr("Pointill\351", "element part line style")), CustomElementGraphicPart::DashedStyle);
|
style -> addButton(dashed_style = new QRadioButton(tr("Pointill\351")), CustomElementGraphicPart::DashedStyle);
|
||||||
style -> button(part -> lineStyle()) -> setChecked(true);
|
style -> button(part -> lineStyle()) -> setChecked(true);
|
||||||
|
|
||||||
// epaisseur
|
// epaisseur
|
||||||
weight = new QButtonGroup(this);
|
weight = new QButtonGroup(this);
|
||||||
weight -> addButton(none_weight = new QRadioButton(tr("Nulle", "element part weight")), CustomElementGraphicPart::NoneWeight);
|
weight -> addButton(none_weight = new QRadioButton(tr("Nulle")), CustomElementGraphicPart::NoneWeight);
|
||||||
weight -> addButton(thin_weight = new QRadioButton(tr("Fine", "element part weight")), CustomElementGraphicPart::ThinWeight);
|
weight -> addButton(thin_weight = new QRadioButton(tr("Fine")), CustomElementGraphicPart::ThinWeight);
|
||||||
weight -> addButton(normal_weight = new QRadioButton(tr("Normale", "element part weight")), CustomElementGraphicPart::NormalWeight);
|
weight -> addButton(normal_weight = new QRadioButton(tr("Normale")), CustomElementGraphicPart::NormalWeight);
|
||||||
|
|
||||||
// remplissage
|
// remplissage
|
||||||
filling = new QButtonGroup(this);
|
filling = new QButtonGroup(this);
|
||||||
filling -> addButton(no_filling = new QRadioButton(tr("Aucun", "element part filling")), CustomElementGraphicPart::NoneFilling );
|
filling -> addButton(no_filling = new QRadioButton(tr("Aucun")), CustomElementGraphicPart::NoneFilling );
|
||||||
filling -> addButton(black_filling = new QRadioButton(tr("Noir", "element part filling")), CustomElementGraphicPart::BlackFilling);
|
filling -> addButton(black_filling = new QRadioButton(tr("Noir")), CustomElementGraphicPart::BlackFilling);
|
||||||
filling -> addButton(white_filling = new QRadioButton(tr("Blanc", "element part filling")), CustomElementGraphicPart::WhiteFilling);
|
filling -> addButton(white_filling = new QRadioButton(tr("Blanc")), CustomElementGraphicPart::WhiteFilling);
|
||||||
|
|
||||||
// antialiasing
|
// antialiasing
|
||||||
antialiasing = new QCheckBox(tr("Antialiasing"));
|
antialiasing = new QCheckBox(tr("Antialiasing"));
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -81,7 +81,7 @@ void TextEditor::updateTextX() { addChangePartCommand(tr("abscisse"), part, "
|
|||||||
/// Met a jour l'ordonnee de la position du texte et cree un objet d'annulation
|
/// Met a jour l'ordonnee de la position du texte et cree un objet d'annulation
|
||||||
void TextEditor::updateTextY() { addChangePartCommand(tr("ordonn\351e"), part, "y", qle_y -> text().toDouble()); updateForm(); }
|
void TextEditor::updateTextY() { addChangePartCommand(tr("ordonn\351e"), part, "y", qle_y -> text().toDouble()); updateForm(); }
|
||||||
/// Met a jour le texte et cree un objet d'annulation
|
/// Met a jour le texte et cree un objet d'annulation
|
||||||
void TextEditor::updateTextT() { addChangePartCommand(tr("contenu"), part, "text", qle_text -> text()); }
|
void TextEditor::updateTextT() { addChangePartCommand(tr("texte"), part, "text", qle_text -> text()); }
|
||||||
/// Met a jour la taille du texte et cree un objet d'annulation
|
/// Met a jour la taille du texte et cree un objet d'annulation
|
||||||
void TextEditor::updateTextS() { addChangePartCommand(tr("taille"), part, "size", font_size -> value()); }
|
void TextEditor::updateTextS() { addChangePartCommand(tr("taille"), part, "size", font_size -> value()); }
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -86,7 +86,7 @@ void TextFieldEditor::updateTextFieldX() { addChangePartCommand(tr("abscisse"),
|
|||||||
/// Met a jour l'ordonnee de la position du champ de texte et cree un objet d'annulation
|
/// Met a jour l'ordonnee de la position du champ de texte et cree un objet d'annulation
|
||||||
void TextFieldEditor::updateTextFieldY() { addChangePartCommand(tr("ordonn\351e"), part, "y", qle_y -> text().toDouble()); updateForm(); }
|
void TextFieldEditor::updateTextFieldY() { addChangePartCommand(tr("ordonn\351e"), part, "y", qle_y -> text().toDouble()); updateForm(); }
|
||||||
/// Met a jour le texte du champ de texte et cree un objet d'annulation
|
/// Met a jour le texte du champ de texte et cree un objet d'annulation
|
||||||
void TextFieldEditor::updateTextFieldT() { addChangePartCommand(tr("contenu"), part, "text", qle_text -> text()); }
|
void TextFieldEditor::updateTextFieldT() { addChangePartCommand(tr("texte"), part, "text", qle_text -> text()); }
|
||||||
/// Met a jour la taille du champ de texte et cree un objet d'annulation
|
/// Met a jour la taille du champ de texte et cree un objet d'annulation
|
||||||
void TextFieldEditor::updateTextFieldS() { addChangePartCommand(tr("taille"), part, "size", font_size -> value()); }
|
void TextFieldEditor::updateTextFieldS() { addChangePartCommand(tr("taille"), part, "size", font_size -> value()); }
|
||||||
/// Met a jour la taille du champ de texte et cree un objet d'annulation
|
/// Met a jour la taille du champ de texte et cree un objet d'annulation
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2007 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -27,7 +27,6 @@
|
|||||||
Constructeur pour un element sans scene ni parent
|
Constructeur pour un element sans scene ni parent
|
||||||
*/
|
*/
|
||||||
Element::Element(QGraphicsItem *parent, Diagram *scene) :
|
Element::Element(QGraphicsItem *parent, Diagram *scene) :
|
||||||
QObject(),
|
|
||||||
QGraphicsItem(parent, scene),
|
QGraphicsItem(parent, scene),
|
||||||
internal_connections(false)
|
internal_connections(false)
|
||||||
{
|
{
|
||||||
@@ -50,7 +49,7 @@ void Element::paint(QPainter *painter, const QStyleOptionGraphicsItem *options,
|
|||||||
|
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
// corrige un bug de rendu ne se produisant que lors du rendu sur QGraphicsScene sous X11 au zoom par defaut
|
// corrige un bug de rendu ne se produisant que lors du rendu sur QGraphicsScene sous X11 au zoom par defaut
|
||||||
static bool must_correct_rendering_bug = QETApp::settings().value("correct-rendering", false).toBool();
|
static bool must_correct_rendering_bug = QETApp::settings().value("correct-rendering", true).toBool();
|
||||||
if (must_correct_rendering_bug) {
|
if (must_correct_rendering_bug) {
|
||||||
Diagram *dia = diagram();
|
Diagram *dia = diagram();
|
||||||
if (dia && options -> levelOfDetail == 1.0 && widget) {
|
if (dia && options -> levelOfDetail == 1.0 && widget) {
|
||||||
@@ -138,8 +137,8 @@ void Element::deselect() {
|
|||||||
@return La pixmap de l'element
|
@return La pixmap de l'element
|
||||||
*/
|
*/
|
||||||
QPixmap Element::pixmap() {
|
QPixmap Element::pixmap() {
|
||||||
if (preview.isNull()) updatePixmap(); // on genere la pixmap si ce n'est deja fait
|
if (apercu.isNull()) updatePixmap(); // on genere la pixmap si ce n'est deja fait
|
||||||
return(preview);
|
return(apercu);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -156,7 +155,7 @@ bool Element::setOrientation(QET::Orientation o) {
|
|||||||
rotate(rotation_value);
|
rotate(rotation_value);
|
||||||
ori.setCurrent(o);
|
ori.setCurrent(o);
|
||||||
update();
|
update();
|
||||||
foreach(QGraphicsItem *qgi, childItems()) {
|
foreach(QGraphicsItem *qgi, children()) {
|
||||||
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) p -> updateConductor();
|
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) p -> updateConductor();
|
||||||
else if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(qgi)) {
|
else if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(qgi)) {
|
||||||
// applique une rotation contraire si besoin
|
// applique une rotation contraire si besoin
|
||||||
@@ -220,10 +219,10 @@ void Element::drawSelection(QPainter *painter, const QStyleOptionGraphicsItem *)
|
|||||||
*/
|
*/
|
||||||
void Element::updatePixmap() {
|
void Element::updatePixmap() {
|
||||||
// Pixmap transparente faisant la taille de base de l'element
|
// Pixmap transparente faisant la taille de base de l'element
|
||||||
preview = QPixmap(dimensions);
|
apercu = QPixmap(dimensions);
|
||||||
preview.fill(QColor(255, 255, 255, 0));
|
apercu.fill(QColor(255, 255, 255, 0));
|
||||||
// QPainter sur la pixmap, avec antialiasing
|
// QPainter sur la pixmap, avec antialiasing
|
||||||
QPainter p(&preview);
|
QPainter p(&apercu);
|
||||||
p.setRenderHint(QPainter::Antialiasing, true);
|
p.setRenderHint(QPainter::Antialiasing, true);
|
||||||
p.setRenderHint(QPainter::SmoothPixmapTransform, true);
|
p.setRenderHint(QPainter::SmoothPixmapTransform, true);
|
||||||
// Translation de l'origine du repere de la pixmap
|
// Translation de l'origine du repere de la pixmap
|
||||||
@@ -263,8 +262,8 @@ void Element::setPos(qreal x, qreal y) {
|
|||||||
Gere l'enfoncement d'un bouton de la souris
|
Gere l'enfoncement d'un bouton de la souris
|
||||||
*/
|
*/
|
||||||
void Element::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
void Element::mousePressEvent(QGraphicsSceneMouseEvent *e) {
|
||||||
if (e -> modifiers() & Qt::ControlModifier) {
|
if (!isSelected() && e -> modifiers() & Qt::ControlModifier) {
|
||||||
setSelected(!isSelected());
|
setSelected(true);
|
||||||
}
|
}
|
||||||
QGraphicsItem::mousePressEvent(e);
|
QGraphicsItem::mousePressEvent(e);
|
||||||
}
|
}
|
||||||
@@ -302,9 +301,7 @@ void Element::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
|
|||||||
}
|
}
|
||||||
diagram_ptr -> invalidateMovedElements();
|
diagram_ptr -> invalidateMovedElements();
|
||||||
}
|
}
|
||||||
if (!(e -> modifiers() & Qt::ControlModifier)) {
|
QGraphicsItem::mouseReleaseEvent(e);
|
||||||
QGraphicsItem::mouseReleaseEvent(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -357,7 +354,7 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr) {
|
|||||||
|
|
||||||
QHash<int, Terminal *> priv_id_adr;
|
QHash<int, Terminal *> priv_id_adr;
|
||||||
int terminals_non_trouvees = 0;
|
int terminals_non_trouvees = 0;
|
||||||
foreach(QGraphicsItem *qgi, childItems()) {
|
foreach(QGraphicsItem *qgi, children()) {
|
||||||
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) {
|
if (Terminal *p = qgraphicsitem_cast<Terminal *>(qgi)) {
|
||||||
bool terminal_trouvee = false;
|
bool terminal_trouvee = false;
|
||||||
foreach(QDomElement qde, liste_terminals) {
|
foreach(QDomElement qde, liste_terminals) {
|
||||||
@@ -389,7 +386,7 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr) {
|
|||||||
|
|
||||||
// importe les valeurs des champs de texte
|
// importe les valeurs des champs de texte
|
||||||
QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input");
|
QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input");
|
||||||
foreach(QGraphicsItem *qgi, childItems()) {
|
foreach(QGraphicsItem *qgi, children()) {
|
||||||
if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(qgi)) {
|
if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(qgi)) {
|
||||||
foreach(QDomElement input, inputs) eti -> fromXml(input);
|
foreach(QDomElement input, inputs) eti -> fromXml(input);
|
||||||
}
|
}
|
||||||
@@ -418,11 +415,13 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
|||||||
QDomElement element = document.createElement("element");
|
QDomElement element = document.createElement("element");
|
||||||
|
|
||||||
// type
|
// type
|
||||||
element.setAttribute("type", typeId());
|
QString chemin_elmt = typeId();
|
||||||
|
QString type_elmt = QETApp::symbolicPath(chemin_elmt);
|
||||||
|
element.setAttribute("type", type_elmt);
|
||||||
|
|
||||||
// position, selection et orientation
|
// position, selection et orientation
|
||||||
element.setAttribute("x", QString("%1").arg(pos().x()));
|
element.setAttribute("x", pos().x());
|
||||||
element.setAttribute("y", QString("%1").arg(pos().y()));
|
element.setAttribute("y", pos().y());
|
||||||
element.setAttribute("orientation", QString("%1").arg(ori.current()));
|
element.setAttribute("orientation", QString("%1").arg(ori.current()));
|
||||||
|
|
||||||
/* recupere le premier id a utiliser pour les bornes de cet element */
|
/* recupere le premier id a utiliser pour les bornes de cet element */
|
||||||
@@ -437,21 +436,29 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
|||||||
}
|
}
|
||||||
|
|
||||||
// enregistrement des bornes de l'appareil
|
// enregistrement des bornes de l'appareil
|
||||||
QDomElement xml_terminals = document.createElement("terminals");
|
QDomElement terminals = document.createElement("terminals");
|
||||||
// pour chaque enfant de l'element
|
// pour chaque enfant de l'element
|
||||||
foreach(Terminal *t, terminals()) {
|
foreach(QGraphicsItem *child, children()) {
|
||||||
// alors on enregistre la borne
|
// si cet enfant est une borne
|
||||||
QDomElement terminal = t -> toXml(document);
|
if (Terminal *t = qgraphicsitem_cast<Terminal *>(child)) {
|
||||||
terminal.setAttribute("id", id_terminal);
|
// alors on enregistre la borne
|
||||||
table_adr_id.insert(t, id_terminal ++);
|
QDomElement terminal = t -> toXml(document);
|
||||||
xml_terminals.appendChild(terminal);
|
terminal.setAttribute("id", id_terminal);
|
||||||
|
table_adr_id.insert(t, id_terminal ++);
|
||||||
|
terminals.appendChild(terminal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
element.appendChild(xml_terminals);
|
element.appendChild(terminals);
|
||||||
|
|
||||||
// enregistrement des champ de texte de l'appareil
|
// enregistrement des champ de texte de l'appareil
|
||||||
QDomElement inputs = document.createElement("inputs");
|
QDomElement inputs = document.createElement("inputs");
|
||||||
foreach(ElementTextItem *eti, texts()) {
|
// pour chaque enfant de l'element
|
||||||
inputs.appendChild(eti -> toXml(document));
|
foreach(QGraphicsItem *child, children()) {
|
||||||
|
// si cet enfant est un champ de texte
|
||||||
|
if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(child)) {
|
||||||
|
// alors on enregistre le champ de texte
|
||||||
|
inputs.appendChild(eti -> toXml(document));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
element.appendChild(inputs);
|
element.appendChild(inputs);
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -21,13 +21,10 @@
|
|||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
#include "orientationset.h"
|
#include "orientationset.h"
|
||||||
class Diagram;
|
class Diagram;
|
||||||
class ElementTextItem;
|
|
||||||
/**
|
/**
|
||||||
Cette classe abstraite represente un element electrique.
|
Cette classe abstraite represente un element electrique.
|
||||||
*/
|
*/
|
||||||
class Element : public QObject, public QGraphicsItem {
|
class Element : public QGraphicsItem {
|
||||||
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
// constructeurs, destructeur
|
// constructeurs, destructeur
|
||||||
public:
|
public:
|
||||||
@@ -54,7 +51,7 @@ class Element : public QObject, public QGraphicsItem {
|
|||||||
private:
|
private:
|
||||||
QSize dimensions;
|
QSize dimensions;
|
||||||
QPoint hotspot_coord;
|
QPoint hotspot_coord;
|
||||||
QPixmap preview;
|
QPixmap apercu;
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
public:
|
public:
|
||||||
@@ -69,14 +66,12 @@ class Element : public QObject, public QGraphicsItem {
|
|||||||
virtual QList<Terminal *> terminals() const = 0;
|
virtual QList<Terminal *> terminals() const = 0;
|
||||||
/// @return la liste des conducteurs relies a cet element
|
/// @return la liste des conducteurs relies a cet element
|
||||||
virtual QList<Conductor *> conductors() const = 0;
|
virtual QList<Conductor *> conductors() const = 0;
|
||||||
/// @return la liste des champs de textes de cet element
|
|
||||||
virtual QList<ElementTextItem *> texts() const = 0;
|
|
||||||
/// @return le nombre de bornes actuel de cet element
|
/// @return le nombre de bornes actuel de cet element
|
||||||
virtual int terminalsCount() const = 0;
|
virtual int nbTerminals() const = 0;
|
||||||
/// @return le nombre de bornes minimum de cet element
|
/// @return le nombre de bornes minimum de cet element
|
||||||
virtual int minTerminalsCount() const = 0;
|
virtual int nbTerminalsMin() const = 0;
|
||||||
/// @return le nombre de bornes maximum de cet element
|
/// @return le nombre de bornes maximum de cet element
|
||||||
virtual int maxTerminalsCount() const = 0;
|
virtual int nbTerminalsMax() const = 0;
|
||||||
/**
|
/**
|
||||||
Dessine l'element
|
Dessine l'element
|
||||||
*/
|
*/
|
||||||
@@ -84,7 +79,7 @@ class Element : public QObject, public QGraphicsItem {
|
|||||||
/// @return L'ID du type de l'element
|
/// @return L'ID du type de l'element
|
||||||
virtual QString typeId() const = 0;
|
virtual QString typeId() const = 0;
|
||||||
/// @return Le nom de l'element
|
/// @return Le nom de l'element
|
||||||
virtual QString name() const = 0;
|
virtual QString nom() const = 0;
|
||||||
Diagram *diagram() const;
|
Diagram *diagram() const;
|
||||||
|
|
||||||
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -16,25 +16,16 @@
|
|||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "elementdeleter.h"
|
#include "elementdeleter.h"
|
||||||
#include "qetapp.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@param elmt_path Chemin virtuel du fichier representant l'element a supprimer
|
@param elmt_path Chemin du fichier representant l'element a supprimer
|
||||||
@param parent QWidget parent
|
@param parent QWidget parent
|
||||||
*/
|
*/
|
||||||
ElementDeleter::ElementDeleter(const ElementsLocation &elmt_path, QWidget *parent) :
|
ElementDeleter::ElementDeleter(const QString &elmt_path, QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
element(0)
|
element_path(elmt_path)
|
||||||
{
|
{
|
||||||
// recupere l'element a supprimer
|
|
||||||
ElementsCollectionItem *element_item = QETApp::collectionItem(elmt_path);
|
|
||||||
if (!element_item) return;
|
|
||||||
|
|
||||||
// on exige un element
|
|
||||||
if (!element_item -> isElement()) return;
|
|
||||||
|
|
||||||
element = element_item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
@@ -45,31 +36,27 @@ ElementDeleter::~ElementDeleter() {
|
|||||||
Supprime l'element : verifie l'existence du fichier, demande confirmation a
|
Supprime l'element : verifie l'existence du fichier, demande confirmation a
|
||||||
l'utilisateur et avertit ce dernier si la suppression a echoue.
|
l'utilisateur et avertit ce dernier si la suppression a echoue.
|
||||||
*/
|
*/
|
||||||
bool ElementDeleter::exec() {
|
void ElementDeleter::exec() {
|
||||||
// verifie l'existence de l'element
|
// verifie l'existence de l'element
|
||||||
if (!element || !element -> isElement()) return(false);
|
QFile elmt_file(element_path);
|
||||||
|
if (!elmt_file.exists()) return;
|
||||||
|
|
||||||
// confirmation #1
|
// confirmation #1
|
||||||
QMessageBox::StandardButton answer_1 = QMessageBox::question(
|
QMessageBox::StandardButton answer_1 = QMessageBox::question(
|
||||||
this,
|
this,
|
||||||
tr("Supprimer l'\351l\351ment ?", "message box title"),
|
tr("Supprimer l'\351l\351ment ?"),
|
||||||
tr("\312tes-vous s\373r de vouloir supprimer cet \351l\351ment ?\n", "message box content"),
|
tr("\312tes-vous s\373r de vouloir supprimer cet \351l\351ment ?\n"),
|
||||||
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel
|
QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel
|
||||||
);
|
);
|
||||||
if (answer_1 != QMessageBox::Yes) return(false);
|
if (answer_1 != QMessageBox::Yes) return;
|
||||||
|
|
||||||
/**
|
|
||||||
@todo Regression : rafficher le chemin de l'element
|
|
||||||
*/
|
|
||||||
|
|
||||||
// supprime l'element
|
// supprime l'element
|
||||||
if (!element -> remove()) {
|
if (!elmt_file.remove()) {
|
||||||
QMessageBox::warning(
|
QMessageBox::warning(
|
||||||
this,
|
this,
|
||||||
tr("Suppression de l'\351l\351ment", "message box title"),
|
tr("Suppression de l'\351l\351ment"),
|
||||||
tr("La suppression de l'\351l\351ment a \351chou\351.", "message box content")
|
tr("La suppression de l'\351l\351ment a \351chou\351.\n"
|
||||||
|
"V\351rifiez vos droits sur le fichier ") + element_path + tr(".")
|
||||||
);
|
);
|
||||||
return(false);
|
|
||||||
}
|
}
|
||||||
return(true);
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2009 Xavier Guerrin
|
Copyright 2006-2008 Xavier Guerrin
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
@@ -18,28 +18,27 @@
|
|||||||
#ifndef ELEMENT_DELETER_H
|
#ifndef ELEMENT_DELETER_H
|
||||||
#define ELEMENT_DELETER_H
|
#define ELEMENT_DELETER_H
|
||||||
#include "elementscategory.h"
|
#include "elementscategory.h"
|
||||||
#include "elementslocation.h"
|
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
/**
|
/**
|
||||||
Cette classe represente une couche d'abstraction pour supprimer
|
Cette classe represente une couche d'abstraction pour supprimer
|
||||||
un element de la collection d'elements.
|
un element de la collection d'elements.
|
||||||
Elle demande notamment confirmation a l'utilisateur.
|
Elle demande notamment confirmation a l'utilisateur
|
||||||
*/
|
*/
|
||||||
class ElementDeleter : public QWidget {
|
class ElementDeleter : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
// constructeurs, destructeur
|
// constructeurs, destructeur
|
||||||
public:
|
public:
|
||||||
ElementDeleter(const ElementsLocation &, QWidget * = 0);
|
ElementDeleter(const QString &, QWidget * = 0);
|
||||||
virtual ~ElementDeleter();
|
virtual ~ElementDeleter();
|
||||||
private:
|
private:
|
||||||
ElementDeleter(const ElementsCategory &);
|
ElementDeleter(const ElementsCategory &);
|
||||||
|
|
||||||
// methodes
|
// methodes
|
||||||
public slots:
|
public slots:
|
||||||
bool exec();
|
void exec();
|
||||||
|
|
||||||
// attributs
|
// attributs
|
||||||
private:
|
private:
|
||||||
ElementsCollectionItem *element;
|
QString element_path;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
<names>
|
<names>
|
||||||
<name lang="en" >Input</name>
|
<name lang="en" >Input</name>
|
||||||
<name lang="fr" >Entrée</name>
|
<name lang="fr" >Entrée</name>
|
||||||
<name lang="es" >Entrada</name>
|
|
||||||
</names>
|
</names>
|
||||||
<description>
|
<description>
|
||||||
<input x="-18" y="-10" size="9" rotate="true" text="_" />
|
<input x="-18" y="-10" size="9" rotate="true" text="_" />
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
<names>
|
<names>
|
||||||
<name lang="en" >Input (down front)</name>
|
<name lang="en" >Input (down front)</name>
|
||||||
<name lang="fr" >Entrée (front descendant)</name>
|
<name lang="fr" >Entrée (front descendant)</name>
|
||||||
<name lang="es" >Entrada (front descendant)</name>
|
|
||||||
</names>
|
</names>
|
||||||
<description>
|
<description>
|
||||||
<text x="-4.25" y="5.25" size="9" text="N" />
|
<text x="-4.25" y="5.25" size="9" text="N" />
|
||||||
|
|||||||
@@ -2,6 +2,5 @@
|
|||||||
<names>
|
<names>
|
||||||
<name lang="en" >Inputs</name>
|
<name lang="en" >Inputs</name>
|
||||||
<name lang="fr" >Entrées</name>
|
<name lang="fr" >Entrées</name>
|
||||||
<name lang="es" >Entradas</name>
|
|
||||||
</names>
|
</names>
|
||||||
</qet-directory>
|
</qet-directory>
|
||||||
|
|||||||
@@ -2,6 +2,5 @@
|
|||||||
<names>
|
<names>
|
||||||
<name lang="en" >Outputs</name>
|
<name lang="en" >Outputs</name>
|
||||||
<name lang="fr" >Sorties</name>
|
<name lang="fr" >Sorties</name>
|
||||||
<name lang="es" >Salidas</name>
|
|
||||||
</names>
|
</names>
|
||||||
</qet-directory>
|
</qet-directory>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
<names>
|
<names>
|
||||||
<name lang="en" >Output</name>
|
<name lang="en" >Output</name>
|
||||||
<name lang="fr" >Sortie</name>
|
<name lang="fr" >Sortie</name>
|
||||||
<name lang="es" >Salida</name>
|
|
||||||
</names>
|
</names>
|
||||||
<description>
|
<description>
|
||||||
<arc width="4" x="6" y="-5" antialias="true" height="10" style="line-style:normal;line-weight:normal;filling:none;color:black" start="80" angle="-160" />
|
<arc width="4" x="6" y="-5" antialias="true" height="10" style="line-style:normal;line-weight:normal;filling:none;color:black" start="80" angle="-160" />
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
<names>
|
<names>
|
||||||
<name lang="en" >Output (reset)</name>
|
<name lang="en" >Output (reset)</name>
|
||||||
<name lang="fr" >Sortie (reset)</name>
|
<name lang="fr" >Sortie (reset)</name>
|
||||||
<name lang="es" >Salida (reset)</name>
|
|
||||||
</names>
|
</names>
|
||||||
<description>
|
<description>
|
||||||
<text x="-4.25" y="5.25" size="9" text="R" />
|
<text x="-4.25" y="5.25" size="9" text="R" />
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
<names>
|
<names>
|
||||||
<name lang="en" >Output (set)</name>
|
<name lang="en" >Output (set)</name>
|
||||||
<name lang="fr" >Sortie (set)</name>
|
<name lang="fr" >Sortie (set)</name>
|
||||||
<name lang="es" >Salida (set)</name>
|
|
||||||
</names>
|
</names>
|
||||||
<description>
|
<description>
|
||||||
<arc width="4" x="6" y="-5" antialias="true" height="10" style="line-style:normal;line-weight:normal;filling:none;color:black" start="80" angle="-160" />
|
<arc width="4" x="6" y="-5" antialias="true" height="10" style="line-style:normal;line-weight:normal;filling:none;color:black" start="80" angle="-160" />
|
||||||
|
|||||||
@@ -2,6 +2,5 @@
|
|||||||
<names>
|
<names>
|
||||||
<name lang="fr">Ladder</name>
|
<name lang="fr">Ladder</name>
|
||||||
<name lang="en">Ladder</name>
|
<name lang="en">Ladder</name>
|
||||||
<name lang="es">Ladder</name>
|
|
||||||
</names>
|
</names>
|
||||||
</qet-directory>
|
</qet-directory>
|
||||||
|
|||||||
@@ -2,6 +2,5 @@
|
|||||||
<names>
|
<names>
|
||||||
<name lang="fr">Automatisme</name>
|
<name lang="fr">Automatisme</name>
|
||||||
<name lang="en">Automatism</name>
|
<name lang="en">Automatism</name>
|
||||||
<name lang="es">Automática</name>
|
|
||||||
</names>
|
</names>
|
||||||
</qet-directory>
|
</qet-directory>
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
<definition width="50" version="0.2" hotspot_x="25" hotspot_y="15" height="30" type="element" orientation="dnnn" >
|
|
||||||
<names>
|
|
||||||
<name lang="en" >Horizontal ammeter</name>
|
|
||||||
<name lang="fr" >Ampèremètre horizontal</name>
|
|
||||||
<name lang="es" >Amperímetro horizontal</name>
|
|
||||||
</names>
|
|
||||||
<description>
|
|
||||||
<line length1="1.5" length2="1.5" antialias="false" end1="none" end2="none" style="line-style:normal;line-weight:normal;filling:none;color:black" y1="0" x1="-1.75" y2="0" x2="1.75" />
|
|
||||||
<line length1="1.5" length2="1.5" antialias="false" end1="none" end2="none" style="line-style:normal;line-weight:normal;filling:none;color:black" y1="0" x1="10" y2="0" x2="21" />
|
|
||||||
<line length1="1.5" length2="1.5" antialias="false" end1="none" end2="none" style="line-style:normal;line-weight:normal;filling:none;color:black" y1="0" x1="-21" y2="0" x2="-10" />
|
|
||||||
<polygon antialias="true" style="line-style:normal;line-weight:normal;filling:none;color:black" closed="false" y1="6" x1="-5" y2="-6" x2="0" y3="6" x3="5" />
|
|
||||||
<circle x="-10" y="-10" antialias="true" style="line-style:normal;line-weight:normal;filling:none;color:black" diameter="20" />
|
|
||||||
<terminal x="-21" y="0" orientation="w" />
|
|
||||||
<terminal x="21" y="0" orientation="e" />
|
|
||||||
</description>
|
|
||||||
</definition>
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<definition width="30" version="0.2" hotspot_x="15" hotspot_y="25" height="50" type="element" orientation="dnnn" >
|
|
||||||
<names>
|
|
||||||
<name lang="en" >Vertical ammeter</name>
|
|
||||||
<name lang="fr" >Ampèremètre vertical</name>
|
|
||||||
<name lang="es" >Amperímetro vertical</name>
|
|
||||||
</names>
|
|
||||||
<description>
|
|
||||||
<line length1="1.5" length2="1.5" antialias="false" end1="none" end2="none" style="line-style:normal;line-weight:normal;filling:none;color:black" y1="0" x1="-1.75" y2="0" x2="1.75" />
|
|
||||||
<line length1="1.5" length2="1.5" antialias="false" end1="none" end2="none" style="line-style:normal;line-weight:normal;filling:none;color:black" y1="10" x1="0" y2="21" x2="0" />
|
|
||||||
<line length1="1.5" length2="1.5" antialias="false" end1="none" end2="none" style="line-style:normal;line-weight:normal;filling:none;color:black" y1="-21" x1="0" y2="-10" x2="0" />
|
|
||||||
<polygon antialias="true" style="line-style:normal;line-weight:normal;filling:none;color:black" closed="false" y1="6" x1="-5" y2="-6" x2="0" y3="6" x3="5" />
|
|
||||||
<circle x="-10" y="-10" antialias="true" style="line-style:normal;line-weight:normal;filling:none;color:black" diameter="20" />
|
|
||||||
<terminal x="0" y="-21" orientation="n" />
|
|
||||||
<terminal x="0" y="21" orientation="s" />
|
|
||||||
</description>
|
|
||||||
</definition>
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user