diff --git a/CREDIT b/CREDIT index 58f16b523..f821e9e50 100644 --- a/CREDIT +++ b/CREDIT @@ -50,4 +50,4 @@ http://www.oxygen-icons.org/ ) лицензированную на услови Спасибо `trem' за пакет для Mandriva. Спасибо TuxFamily ( http://tuxfamily.org/ ) за хостинг для проекта. Спасибо `Nishiki' за элементы и поддержку. -Спасибо qtcentre.org за их класс SingleApplication. \ No newline at end of file +Спасибо qtcentre.org за их класс SingleApplication. diff --git a/ELEMENTS.LICENSE b/ELEMENTS.LICENSE index d0975b795..1b9b57487 100644 --- a/ELEMENTS.LICENSE +++ b/ELEMENTS.LICENSE @@ -52,4 +52,4 @@ Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA. Чтобы увидеть копию этой лицензии, посетите http://creativecommons.org/licenses/by/2.0/fr/ или отправте письмо в Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. -(данный перевод, на русский язык, является вольным и выполнен не юристом!) \ No newline at end of file +(данный перевод, на русский язык, является вольным и выполнен не юристом!) diff --git a/README b/README index a2531fa3a..8e920efbd 100644 --- a/README +++ b/README @@ -11,4 +11,4 @@ QET utilise le format XML pour ses éléments et ses schémas et inclut un [ru] QElectroTech - приложение написанное на Qt4 и предназначенное для разработки электрических схем. Оно использует XML-файлы для элементов и схем, и включает, как редактор схем, так и редактор -элементов. \ No newline at end of file +элементов. diff --git a/qelectrotech.pro b/qelectrotech.pro index 425d91453..52f3c2638 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -74,6 +74,7 @@ HEADERS += sources/aboutqet.h \ sources/diagram.h \ sources/diagramcommands.h \ sources/diagramcontent.h \ + sources/diagramposition.h \ sources/diagramprintdialog.h \ sources/diagramschooser.h \ sources/diagramtextitem.h \ @@ -173,6 +174,7 @@ SOURCES += sources/aboutqet.cpp \ sources/diagram.cpp \ sources/diagramcommands.cpp \ sources/diagramcontent.cpp \ + sources/diagramposition.cpp \ sources/diagramprintdialog.cpp \ sources/diagramschooser.cpp \ sources/diagramtextitem.cpp \ diff --git a/sources/borderinset.cpp b/sources/borderinset.cpp index 7aac46400..c7d28075a 100644 --- a/sources/borderinset.cpp +++ b/sources/borderinset.cpp @@ -17,6 +17,7 @@ */ #include #include "borderinset.h" +#include "diagramposition.h" #include "qetapp.h" #include "math.h" @@ -426,6 +427,36 @@ void BorderInset::adjustInsetToColumns() { setInsetWidth(diagramWidth()); } +/** + @param pos Position cartesienne (ex : 10.3, 45.2) a transformer en position + dans la grille (ex : B2) + @return la position dans la grille correspondant a pos +*/ +DiagramPosition BorderInset::convertPosition(const QPointF &pos) { + // recupere le rectangle quadrille par les en-tetes + QRectF grid_rect( + rowsHeaderWidth(), + columnsHeaderHeight(), + diagramWidth(), + diagramHeight() + ); + + if (!grid_rect.contains(pos)) { + return(DiagramPosition("", 0)); + } + + QPointF relative_pos = pos - grid_rect.topLeft(); + int row_number = ceil(relative_pos.x() / columnsWidth()); + int column_number = ceil(relative_pos.y() / rowsHeight()); + + QString letter = "A"; + for (int i = 1 ; i < column_number ; ++ i) { + letter = incrementLetters(letter); + } + + return(DiagramPosition(letter, row_number)); +} + QString BorderInset::incrementLetters(const QString &string) { if (string.isEmpty()) { return("A"); diff --git a/sources/borderinset.h b/sources/borderinset.h index 834595b7f..4f0d8d253 100644 --- a/sources/borderinset.h +++ b/sources/borderinset.h @@ -23,6 +23,7 @@ #include #include class QPainter; +class DiagramPosition; /** Cette classe represente l'ensemble bordure + cartouche qui encadre le schema electrique. @@ -124,6 +125,8 @@ class BorderInset : public QObject { void setInsetHeight (const qreal &); void adjustInsetToColumns (); + DiagramPosition convertPosition(const QPointF &); + // methodes d'acces en ecriture aux informations du cartouche /// @param author le nouveau contenu du champ "Auteur" void setAuthor (const QString &author) { bi_author = author; } diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 486b26c7d..4566d21a2 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -25,6 +25,7 @@ #include "ghostelement.h" #include "diagramcommands.h" #include "diagramcontent.h" +#include "diagramposition.h" const int Diagram::xGrid = 10; const int Diagram::yGrid = 10; @@ -896,6 +897,24 @@ bool Diagram::usesElement(const ElementsLocation &location) { return(false); } +/** + @param pos Position cartesienne (ex : 10.3, 45.2) a transformer en position + dans la grille (ex : B2) + @return la position dans la grille correspondant a pos +*/ +DiagramPosition Diagram::convertPosition(const QPointF &pos) { + // decale la position pour prendre en compte les marges en haut a gauche du schema + QPointF final_pos = pos - QPointF(margin, margin); + + // delegue le calcul au BorderInset + DiagramPosition diagram_position = border_and_inset.convertPosition(final_pos); + + // embarque la position cartesienne + diagram_position.setPosition(pos); + + return(diagram_position); +} + /** Definit s'il faut afficher ou non les bornes @param dt true pour afficher les bornes, false sinon diff --git a/sources/diagram.h b/sources/diagram.h index 0215030ca..a8d3f07fe 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -28,6 +28,7 @@ class Terminal; class Conductor; class DiagramTextItem; class DiagramContent; +class DiagramPosition; class QETProject; class ElementsLocation; /** @@ -132,6 +133,7 @@ class Diagram : public QGraphicsScene { bool useBorder(); void setBorderOptions(BorderOptions); BorderOptions borderOptions(); + DiagramPosition convertPosition(const QPointF &); bool drawTerminals() const; void setDrawTerminals(bool); diff --git a/sources/diagramposition.cpp b/sources/diagramposition.cpp new file mode 100644 index 000000000..b5e9e1858 --- /dev/null +++ b/sources/diagramposition.cpp @@ -0,0 +1,70 @@ +/* + Copyright 2006-2009 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 . +*/ +#include "diagramposition.h" + +/** + Constructeur + @param letter Lettre(s) composant la position + @param number Numero composant la position + Si une chaine entierement invalide ou vide, ou bien un 0 est passe en + parametre, il en resulte un objet DiagramPosition invalide, dont la methode + isOutOfBounds renverra true. +*/ +DiagramPosition::DiagramPosition(const QString &letter, unsigned int number) { + // purifie les lettres + letter_ = letter.toUpper(); + letter_.remove(QRegExp("[^A-Z]")); + number_ = number; +} + +/** + Destructeur +*/ +DiagramPosition::~DiagramPosition() { +} + +/** + @return les coordonnees stockees dans cet objet, ou un QPointF nul sinon. +*/ +QPointF DiagramPosition::position() const { + return(position_); +} + +/** + @param position Position a stocker dans cet objet +*/ +void DiagramPosition::setPosition(const QPointF &position) { + position_ = position; +} + +/** + @return une representation textuelle de la position +*/ +QString DiagramPosition::toString() { + if (isOutOfBounds()) { + return("-"); + } + return(QString("%1%2").arg(letter_).arg(number_)); +} + +/** + @return true si l'element est en dehors des bords du schema +*/ +bool DiagramPosition::isOutOfBounds() const { + return(letter_.isEmpty() || !number_); +} diff --git a/sources/diagramposition.h b/sources/diagramposition.h new file mode 100644 index 000000000..3dd5e4222 --- /dev/null +++ b/sources/diagramposition.h @@ -0,0 +1,48 @@ +/* + Copyright 2006-2009 Xavier Guerrin + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef DIAGRAM_POSITION_H +#define DIAGRAM_POSITION_H +#include +#include +#include +/** + Cette classe represente la position d'un element sur le schema. Il ne + s'agit pas de ses coordonnees (bien que celles-ci puissent etre embarquees + par commodite), mais du secteur du schema dans lequel il se situe, par + exemple B2 ou C4. +*/ +class DiagramPosition { + // constructeurs, destructeur + public: + DiagramPosition(const QString & = "", unsigned int = 0); + virtual ~DiagramPosition(); + + // methodes + public: + QPointF position() const; + void setPosition(const QPointF &); + QString toString(); + bool isOutOfBounds() const; + + // attributs + private: + QString letter_; + unsigned int number_; + QPointF position_; +}; +#endif diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 20a0fbf3c..67f7b6771 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -21,6 +21,7 @@ #include "ghostelement.h" #include "conductor.h" #include "diagramcommands.h" +#include "diagramposition.h" #include "conductorpropertieswidget.h" #include "insetpropertieswidget.h" #include "qetapp.h" @@ -613,6 +614,7 @@ void DiagramView::editElement(Element *element) { // nom, nombre de bornes, dimensions description_string += QString(tr("Nom\240: %1\n")).arg(element -> name()); + description_string += QString(tr("Position\240: %1\n")).arg(scene -> convertPosition(element -> scenePos()).toString()); description_string += QString(tr("Dimensions\240: %1\327%2\n")).arg(element -> size().width()).arg(element -> size().height()); description_string += QString(tr("Bornes\240: %1\n")).arg(element -> terminals().count()); description_string += QString(tr("Connexions internes\240: %1\n")).arg(element -> internalConnections() ? tr("Autoris\351es") : tr("Interdites"));