diff --git a/borderinset.cpp b/borderinset.cpp new file mode 100644 index 000000000..0cd75f4c5 --- /dev/null +++ b/borderinset.cpp @@ -0,0 +1,168 @@ +#include "borderinset.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 = 15; + columns_width = 50.0; + columns_height = 500.0; + inset_width = nb_columns * columns_width; + inset_height = 50.0; + columns_header_height = 20.0; + updateRectangles(); +} + +/** + 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 + border = QRectF(0, 0, nb_columns * columns_width, columns_height); + + // rectangles relatifs au cartouche + inset = QRectF(border.bottomRight().x() - inset_width, border.bottomRight().y() - inset_height, 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 + qp -> drawRect(border); + + // dessine la numerotation des colonnes + 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 + 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()); + + 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; + updateRectangles(); +} + +/** + Enleve une colonne. Il doit rester au moins 3 colonnes. +*/ +void BorderInset::removeColumn() { + if (nb_columns == 3) return; + -- nb_columns; + updateRectangles(); +} + +/** + Change la largeur des colonnes ; celle-ci doit rester comprise entre 10 et + 200px. +*/ +void BorderInset::setColumnsWidth(const qreal &new_cw) { + columns_width = qMax(10.0, qMin(200.0, new_cw)); + 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 = qMax(5.0, qMin(50.0, new_chh)); + updateRectangles(); +} + +/** + Change la hauteur des colonnes (et donc du cadre). Cette hauteur doit + rester superieure a 10px. +*/ +void BorderInset::setColumnsHeight(const qreal &new_ch) { + columns_height = qMax(10.0, 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(); +} diff --git a/borderinset.h b/borderinset.h new file mode 100644 index 000000000..2f0ee6a96 --- /dev/null +++ b/borderinset.h @@ -0,0 +1,93 @@ +#ifndef BORDERINSET_H + #define BORDERINSET_H + #include + #include + #include + #include + /** + Cette classe represente l'ensemble bordure + cartouche qui encadre le + schema electrique. + */ + class BorderInset : public QObject { + Q_OBJECT + public: + BorderInset(QObject * = 0); + ~BorderInset(); + void draw(QPainter *, qreal = 0.0, qreal = 0.0); + + // methodes d'acces en lecture aux dimensions + int nbColumn() const { return(nb_columns); } + qreal columnsWidth() const { return(columns_width); } + qreal columnsHeaderHeight() const { return(columns_header_height); } + qreal columnsHeight() const { return(columns_height); } + qreal borderWidth() const { return(nb_columns * columns_width); } + qreal borderHeight() const { return(columns_height); } + qreal insetWidth() const { return(inset_width); } + qreal insetHeight() const { return(inset_height); } + + // methodes d'acces en lecture aux informations du cartouche + QString author() const { return(bi_author); } + QDate date() const { return(bi_date); } + QString title() const { return(bi_title); } + QString folio() const { return(bi_folio); } + QString fileName() const { return(bi_filename); } + + // methodes d'acces en lecture aux options + bool insetIsDisplayed() const { return(display_inset); } + bool columnsAreDisplayed() const { return(display_columns); } + bool borderIsDisplayed() const { return(display_border); } + + // methodes d'acces en ecriture aux dimensions + void addColumn (); + void removeColumn (); + void setColumnsWidth (const qreal &); + void setColumnsHeaderHeight(const qreal &); + void setColumnsHeight (const qreal &); + void setInsetWidth (const qreal &); + void setInsetHeight (const qreal &); + + // methodes d'acces en ecriture aux informations du cartouche + void setAuthor (const QString &author) { bi_author = author; } + void setDate (const QDate &date) { bi_date = date; } + void setTitle (const QString &title) { bi_title = title; } + void setFolio (const QString &folio) { bi_folio = folio; } + void setFileName (const QString &filename) { bi_filename = filename; } + + // methodes d'acces en ecriture aux options + void displayInset (bool di) { display_inset = di; } + void displayColumns (bool dc) { display_columns = dc; } + void displayBorder (bool db) { display_border = db; } + + private: + // informations du cartouche + QString bi_author; + QDate bi_date; + QString bi_title; + QString bi_folio; // vraiment necessaire ce truc ? + QString bi_filename; // meme remarque + + // dimensions du cadre et du cartouche + int nb_columns; + qreal columns_width; + qreal columns_header_height; + qreal columns_height; + qreal inset_width; + qreal inset_height; + + // rectangles utilises pour le dessin + QRectF border; + QRectF inset; + QRectF inset_author; + QRectF inset_date; + QRectF inset_title; + QRectF inset_file; + QRectF inset_folio; + + // booleens pour les options de dessin + bool display_inset; + bool display_columns; + bool display_border; + + void updateRectangles(); + }; +#endif diff --git a/exportdialog.cpp b/exportdialog.cpp index 76b80de82..be703fb7f 100644 --- a/exportdialog.cpp +++ b/exportdialog.cpp @@ -2,14 +2,14 @@ /** Constructeur - @param schema Le schema a exporter + @param dia Le schema a exporter @param parent Le Widget parent de ce dialogue */ -ExportDialog::ExportDialog(Schema &schema, QWidget *parent) : QDialog(parent) { +ExportDialog::ExportDialog(Schema &dia, QWidget *parent) : QDialog(parent) { // recupere le schema a exporter, sa taille et ses proportions - schema_schema = &schema; - schema_size = schema_schema -> imageSize(); - schema_ratio = (qreal)schema_size.width() / (qreal)schema_size.height(); + diagram = &dia; + diagram_size = diagram -> imageSize(); + diagram_ratio = (qreal)diagram_size.width() / (qreal)diagram_size.height(); // la taille du dialogue est fixee setFixedSize(400, 310); @@ -80,7 +80,7 @@ QGroupBox *ExportDialog::setupDimensionsGroupBox() { width = new QSpinBox(groupbox_dimensions); width -> setRange(1, 10000); - width -> setValue(schema_size.width()); + width -> setValue(diagram_size.width()); gridLayout -> addWidget(width, 0, 1, 1, 1); gridLayout -> addWidget(new QLabel(tr("px"), groupbox_dimensions), 0, 2, 1, 1); @@ -90,7 +90,7 @@ QGroupBox *ExportDialog::setupDimensionsGroupBox() { height = new QSpinBox(groupbox_dimensions); height -> setRange(1, 10000); - height -> setValue(schema_size.height()); + height -> setValue(diagram_size.height()); gridLayout -> addWidget(height, 2, 1, 1, 1); gridLayout -> addWidget(new QLabel(tr("px"), groupbox_dimensions), 2, 2, 1, 1); @@ -127,14 +127,14 @@ QGroupBox *ExportDialog::setupOptionsGroupBox() { void ExportDialog::slot_correctWidth() { if (!keep_aspect_ratio -> isChecked() || dontchangewidth) return; dontchangeheight = true; - width -> setValue(qRound(height -> value() * schema_ratio)); + width -> setValue(qRound(height -> value() * diagram_ratio)); dontchangeheight = false; } void ExportDialog::slot_correctHeight() { if (!keep_aspect_ratio -> isChecked() || dontchangeheight) return; dontchangewidth = true; - height -> setValue(qRound(width -> value() / schema_ratio)); + height -> setValue(qRound(width -> value() / diagram_ratio)); dontchangewidth = false; } @@ -146,15 +146,15 @@ void ExportDialog::slot_chooseAFile() { tr("Images (*.png *.bmp *.jpg)") ); if (user_file != "") { - schema_path = user_file; - filename -> setText(schema_path); + diagram_path = user_file; + filename -> setText(diagram_path); } } void ExportDialog::slot_check() { // verifie que le fichier a ete specifie - if (schema_path == "") { + if (diagram_path == "") { QMessageBox::information( this, tr("Fichier non sp\351cifi\351"), @@ -169,10 +169,10 @@ void ExportDialog::slot_check() { QString format_extension = "." + format_acronym.toLower(); // corrige l'extension du fichier - if (!schema_path.endsWith(format_extension, Qt::CaseInsensitive)) schema_path += format_extension; + if (!diagram_path.endsWith(format_extension, Qt::CaseInsensitive)) diagram_path += format_extension; // recupere des informations sur le fichier specifie - QFileInfo file_infos(schema_path); + QFileInfo file_infos(diagram_path); // verifie qu'il est possible d'ecrire dans le fichier en question if (file_infos.exists() && !file_infos.isWritable()) { @@ -186,12 +186,12 @@ void ExportDialog::slot_check() { } // ouvre le fichier - QFile fichier(schema_path); + QFile fichier(diagram_path); // genere l'image - if (!export_grid -> isChecked()) schema_schema -> setAffichageGrille(false); - QImage image = schema_schema -> toImage(width -> value(), height -> value(), keep_aspect_ratio -> isChecked()); - if (!export_grid -> isChecked()) schema_schema -> setAffichageGrille(true); + if (!export_grid -> isChecked()) diagram -> setAffichageGrille(false); + QImage image = diagram -> toImage(width -> value(), height -> value(), keep_aspect_ratio -> isChecked()); + if (!export_grid -> isChecked()) diagram -> setAffichageGrille(true); // convertit l'image en niveaux de gris si besoin if (!keep_colors -> isChecked()) { diff --git a/exportdialog.h b/exportdialog.h index 5f6903a60..c59588255 100644 --- a/exportdialog.h +++ b/exportdialog.h @@ -28,10 +28,10 @@ bool dontchangeheight; // elements relatifs au traitement effectue par le dialogue - Schema *schema_schema; - QSize schema_size; - QString schema_path; - qreal schema_ratio; + Schema *diagram; + QSize diagram_size; + QString diagram_path; + qreal diagram_ratio; QGroupBox *setupDimensionsGroupBox(); QGroupBox *setupOptionsGroupBox(); diff --git a/qelectrotech.pro b/qelectrotech.pro index 51d15e759..4a63f1db4 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -9,6 +9,7 @@ INCLUDEPATH += . # Input HEADERS += aboutqet.h \ + borderinset.h \ borne.h \ conducteur.h \ element.h \ @@ -20,6 +21,7 @@ HEADERS += aboutqet.h \ schema.h \ schemavue.h SOURCES += aboutqet.cpp \ + borderinset.cpp \ borne.cpp \ conducteur.cpp \ element.cpp \ diff --git a/qetapp.cpp b/qetapp.cpp index 8daabe3b7..283d9d2eb 100644 --- a/qetapp.cpp +++ b/qetapp.cpp @@ -4,6 +4,7 @@ #include "panelappareils.h" #include "aboutqet.h" #include "exportdialog.h" +// #include "borderinset.h" /** constructeur @@ -227,6 +228,8 @@ void QETApp::actions() { supprimer = new QAction(QIcon(":/ico/delete.png"), tr("Supprimer"), this); pivoter = new QAction(QIcon(":/ico/pivoter.png"), tr("Pivoter"), this); infos_schema = new QAction(QIcon(":/ico/info.png"), tr("Informations sur le sch\351ma"), this); + add_column = new QAction( tr("Ajouter une colonne"), this); + remove_column = new QAction( tr("Enlever une colonne"), this); toggle_aa = new QAction( tr("D\351sactiver l'&antialiasing"), this); zoom_avant = new QAction(QIcon(":/ico/viewmag+.png"), tr("Zoom avant"), this); @@ -308,6 +311,8 @@ void QETApp::actions() { supprimer -> setStatusTip(tr("Enl\350ve les \351l\351ments s\351lectionn\351s du sch\351ma")); pivoter -> setStatusTip(tr("Pivote les \351l\351ments s\351lectionn\351s")); infos_schema -> setStatusTip(tr("\311dite les informations affich\351es par le cartouche")); + add_column -> setStatusTip(tr("Ajoute une colonne au sch\351ma")); + remove_column -> setStatusTip(tr("Enl\350ve une colonne au sch\351ma")); toggle_aa -> setStatusTip(tr("Active / d\351sactive l'antialiasing pour le rendu du sch\351ma courant")); zoom_avant -> setStatusTip(tr("Agrandit le sch\351ma")); @@ -377,6 +382,8 @@ void QETApp::actions() { connect(f_suiv, SIGNAL(triggered()), &workspace, SLOT(activateNextWindow()) ); connect(f_prec, SIGNAL(triggered()), &workspace, SLOT(activatePreviousWindow()) ); connect(infos_schema, SIGNAL(activated()), this, SLOT(editInfos()) ); + connect(add_column, SIGNAL(activated()), this, SLOT(slot_addColumn()) ); + connect(remove_column, SIGNAL(activated()), this, SLOT(slot_removeColumn()) ); } /** @@ -429,6 +436,8 @@ void QETApp::menus() { menu_edition -> addAction(pivoter); menu_edition -> addSeparator(); menu_edition -> addAction(infos_schema); + menu_edition -> addAction(add_column); + menu_edition -> addAction(remove_column); // menu Affichage > Afficher QMenu *menu_aff_aff = new QMenu(tr("Afficher")); @@ -519,21 +528,6 @@ void QETApp::dialogue_exporter() { Schema *sc = schemaEnCours() -> scene; ExportDialog ed(*sc); ed.exec(); - /* - // demande un nom de fichier - - // exporte le schema - if (nom_fichier != "") { - if (!nom_fichier.endsWith(".png", Qt::CaseInsensitive)) nom_fichier += ".png"; - QFile fichier(nom_fichier); - Schema *sc = schemaEnCours() -> scene; - sc -> setAffichageGrille(false); - QImage image = sc -> toImage(); - sc -> setAffichageGrille(true); - image.save(&fichier, "PNG"); - fichier.close(); - } - */ } /** @@ -938,25 +932,34 @@ void QETApp::editInfos() { SchemaVue *sv = schemaEnCours(); if (!sv) return; + // recupere le cartouche du schema + BorderInset *inset = &(sv -> scene -> border_and_inset); + // construit le dialogue QDialog popup; popup.setMinimumWidth(400); popup.setWindowTitle(tr("Cartouche du sch\351ma")); - QLineEdit *titre = new QLineEdit(sv -> scene -> titre); - QLineEdit *auteur = new QLineEdit(sv -> scene -> auteur); - QDate date_schema = QDate(sv -> scene -> date); + QLineEdit *titre = new QLineEdit(inset -> title(), &popup); + QLineEdit *auteur = new QLineEdit(inset -> author(), &popup); + QDate date_schema = QDate(inset -> date()); if (date_schema.isNull() || !date_schema.isValid()) date_schema = QDate::currentDate(); - QDateEdit *date = new QDateEdit(date_schema); + QDateEdit *date = new QDateEdit(date_schema, &popup); date -> setCalendarPopup(true); - QWidget bidon; + QLineEdit *fichier = new QLineEdit(inset -> fileName(), &popup); + QLineEdit *folio = new QLineEdit(inset -> folio(), &popup); + QWidget bidon(&popup); QGridLayout layout_champs(&bidon); - layout_champs.addWidget(new QLabel(tr("Titre : ")), 0, 0); - layout_champs.addWidget(titre, 0, 1); - layout_champs.addWidget(new QLabel(tr("Auteur : ")), 1, 0); - layout_champs.addWidget(auteur, 1, 1); - layout_champs.addWidget(new QLabel(tr("Date : ")), 2, 0); - layout_champs.addWidget(date, 2, 1); + layout_champs.addWidget(new QLabel(tr("Titre : ")), 0, 0); + layout_champs.addWidget(titre, 0, 1); + layout_champs.addWidget(new QLabel(tr("Auteur : ")), 1, 0); + layout_champs.addWidget(auteur, 1, 1); + layout_champs.addWidget(new QLabel(tr("Date : ")), 2, 0); + layout_champs.addWidget(date, 2, 1); + layout_champs.addWidget(new QLabel(tr("Fichier : ")), 3, 0); + layout_champs.addWidget(fichier, 3, 1); + layout_champs.addWidget(new QLabel(tr("Folio : ")), 4, 0); + layout_champs.addWidget(folio, 4, 1); // boutons QDialogButtonBox boutons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); @@ -968,9 +971,37 @@ void QETApp::editInfos() { layout_v.addWidget(&bidon); layout_v.addWidget(&boutons); if (popup.exec() == QDialog::Accepted) { - sv -> scene -> titre = titre -> text(); - sv -> scene -> auteur = auteur -> text(); - sv -> scene -> date = date -> date(); - + inset -> setTitle(titre -> text()); + inset -> setAuthor(auteur -> text()); + inset -> setDate(date -> date()); + inset -> setFileName(fichier -> text()); + inset -> setFolio(folio -> text()); } } + +void QETApp::slot_addColumn() { + SchemaVue *sv = schemaEnCours(); + if (!sv) return; + + // ajoute la colonne + sv -> scene -> border_and_inset.addColumn(); + + // met a jour la zone affichee par la vue + QRectF sr = sv -> sceneRect(); + sr.setWidth(5.0 + sv -> scene -> border_and_inset.borderWidth()); + sv -> setSceneRect(sr); + + // rafraichit la vue + sv -> scene -> update(sv -> sceneRect()); +} + +void QETApp::slot_removeColumn() { + SchemaVue *sv = schemaEnCours(); + if (!sv) return; + sv -> scene -> border_and_inset.removeColumn(); + + // on pourrait mettre a jour la zone affichee par la vue + + // rafraichit la vue + sv -> scene -> update(sv -> sceneRect()); +} diff --git a/qetapp.h b/qetapp.h index 33c2cf939..481e663d6 100644 --- a/qetapp.h +++ b/qetapp.h @@ -64,6 +64,8 @@ QAction *selectionner; QAction *pivoter; QAction *infos_schema; + QAction *add_column; + QAction *remove_column; QAction *poser_fil; QAction *masquer_appli; QAction *restaurer_appli; @@ -126,5 +128,7 @@ void slot_setVisualisationMode(); void slot_updateActions(); void slot_updateMenuFenetres(); + void slot_addColumn(); + void slot_removeColumn(); }; #endif diff --git a/schema.cpp b/schema.cpp index df925e1d1..ea3e174e1 100644 --- a/schema.cpp +++ b/schema.cpp @@ -56,10 +56,9 @@ void Schema::drawBackground(QPainter *p, const QRectF &r) { p -> drawPoint(gx, gy); } } - - p -> drawLine(0, 0, 0, 10); - p -> drawLine(0, 0, 10, 0); } + + border_and_inset.draw(p, MARGIN, MARGIN); p -> restore(); } @@ -146,9 +145,11 @@ QDomDocument Schema::toXml(bool schema) { // proprietes du schema if (schema) { - if (!auteur.isNull()) racine.setAttribute("auteur", auteur); - if (!date.isNull()) racine.setAttribute("date", date.toString("yyyyMMdd")); - if (!titre.isNull()) racine.setAttribute("titre", titre); + if (!border_and_inset.author().isNull()) racine.setAttribute("auteur", border_and_inset.author()); + if (!border_and_inset.date().isNull()) racine.setAttribute("date", border_and_inset.date().toString("yyyyMMdd")); + if (!border_and_inset.title().isNull()) racine.setAttribute("titre", border_and_inset.title()); + 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()); } document.appendChild(racine); @@ -239,16 +240,21 @@ QDomDocument Schema::toXml(bool schema) { (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 @return true si l'import a reussi, false sinon */ -bool Schema::fromXml(QDomDocument &document, QPointF position) { +bool Schema::fromXml(QDomDocument &document, QPointF position, bool consider_informations) { QDomElement racine = document.documentElement(); // le premier element doit etre un schema if (racine.tagName() != "schema") return(false); // lecture des attributs de ce schema - auteur = racine.attribute("auteur"); - titre = racine.attribute("titre"); - date = QDate::fromString(racine.attribute("date"), "yyyyMMdd"); + if (consider_informations) { + border_and_inset.setAuthor(racine.attribute("auteur")); + border_and_inset.setTitle(racine.attribute("titre")); + border_and_inset.setDate(QDate::fromString(racine.attribute("date"), "yyyyMMdd")); + border_and_inset.setFileName(racine.attribute("filename")); + border_and_inset.setFolio(racine.attribute("folio")); + } // si la racine n'a pas d'enfant : le chargement est fini (schema vide) if (racine.firstChild().isNull()) return(true); @@ -366,9 +372,27 @@ Element *Schema::elementFromXml(QDomElement &e, QHash &table_id_ad return(retour ? nvel_elmt : NULL); } +/** + Verifie si la liste des elements selectionnes a change. Si oui, le signal + selectionChanged() est emis. +*/ void Schema::slot_checkSelectionChange() { static QList cache_selecteditems = QList(); QList selecteditems = selectedItems(); if (cache_selecteditems != selecteditems) emit(selectionChanged()); cache_selecteditems = selecteditems; } + +/** + @return Le rectangle (coordonnees par rapport a la scene) delimitant le bord du schema +*/ +QRectF Schema::border() const { + return( + QRectF( + MARGIN, + MARGIN, + border_and_inset.borderWidth(), + border_and_inset.borderHeight() + ) + ); +} diff --git a/schema.h b/schema.h index b7a218a7e..37f0fdeb2 100644 --- a/schema.h +++ b/schema.h @@ -2,9 +2,11 @@ #define SCHEMA_H #define GRILLE_X 10 #define GRILLE_Y 10 + #define MARGIN 5.0 #include #include - #include + #include "qetapp.h" + #include "borderinset.h" class Element; class Borne; class Schema : public QGraphicsScene { @@ -24,15 +26,11 @@ QImage toImage(int = -1, int = -1, bool = true); QSize imageSize() const; QDomDocument toXml(bool = true); - bool fromXml(QDomDocument &, QPointF = QPointF()); + bool fromXml(QDomDocument &, QPointF = QPointF(), bool = true); QGraphicsItem *getElementById(uint id); inline void setAffichageGrille(bool ddg) { doit_dessiner_grille = ddg; } - // elements du cartouche - QString auteur; - QDate date; - QString titre; - QString folio; // vraiment necessaire ce truc ? - QString nom_fichier; // meme remarque + BorderInset border_and_inset; + QRectF border() const; private: QGraphicsLineItem *poseur_de_conducteur; diff --git a/schemavue.cpp b/schemavue.cpp index 13ac5f539..106f99495 100644 --- a/schemavue.cpp +++ b/schemavue.cpp @@ -12,6 +12,10 @@ void SchemaVue::initialise() { setDragMode(RubberBandDrag); setAcceptDrops(true); setWindowTitle(tr("Nouveau sch\351ma") + "[*]"); + setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + setResizeAnchor(QGraphicsView::AnchorUnderMouse); + setAlignment(Qt::AlignLeft | Qt::AlignTop); + setSceneRect(QRectF(0.0, 0.0, scene -> border_and_inset.borderWidth() + 10.0, scene -> border_and_inset.borderHeight() + 10.0)); connect(scene, SIGNAL(selectionChanged()), this, SLOT(slot_selectionChanged())); } @@ -165,7 +169,6 @@ void SchemaVue::pivoter() { /** accepte ou refuse le drag'n drop en fonction du type de donnees entrant @param e le QDragEnterEvent correspondant au drag'n drop tente - @todo trouver un MIME Type plus adapte */ void SchemaVue::dragEnterEvent(QDragEnterEvent *e) { if (e -> mimeData() -> hasFormat("text/plain")) e -> acceptProposedAction(); @@ -190,7 +193,6 @@ void SchemaVue::dragMoveEvent(QDragMoveEvent *e) { /** gere les depots (drop) acceptes sur le Schema @param e le QDropEvent correspondant au drag'n drop effectue - @todo Ajouter directement l'objet Element a la scene lorsque le drag'n drop aura ete ameliore */ void SchemaVue::dropEvent(QDropEvent *e) { QString fichier = e -> mimeData() -> text(); @@ -287,7 +289,7 @@ void SchemaVue::coller() { QDomDocument document_xml; if ((texte_presse_papier = QApplication::clipboard() -> text()) == QString()) return; if (!document_xml.setContent(texte_presse_papier)) return; - scene -> fromXml(document_xml); + scene -> fromXml(document_xml, QPointF(), false); } /** @@ -299,7 +301,7 @@ void SchemaVue::mousePressEvent(QMouseEvent *e) { QDomDocument document_xml; if ((texte_presse_papier = QApplication::clipboard() -> text(QClipboard::Selection)) == QString()) return; if (!document_xml.setContent(texte_presse_papier)) return; - scene -> fromXml(document_xml, mapToScene(e -> pos())); + scene -> fromXml(document_xml, mapToScene(e -> pos()), false); } QGraphicsView::mousePressEvent(e); }