mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
The Diagram class now renders its usual inset with a template.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1130 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
e11acf7b57
commit
d17d6c492e
11
insets/default.inset
Normal file
11
insets/default.inset
Normal file
@ -0,0 +1,11 @@
|
||||
<insettemplate name="default">
|
||||
<informations>Author: The QElectroTech team
|
||||
License: see http://qelectrotech.org/wiki/doc/elements_license</informations>
|
||||
<grid rows="25px;25px" cols="t22%;r100%;t22%">
|
||||
<field row="0" col="0" name="author" label="Auteur" displaylabel="true" align="left" rowspan="0" value="%author" />
|
||||
<field row="1" col="0" name="date" label="Date" displaylabel="true" align="left" rowspan="0" value="%date" />
|
||||
<field row="0" col="1" name="title" label="Titre" displaylabel="false" align="center" rowspan="1" value="%title" />
|
||||
<field row="0" col="2" name="file" label="Fichier" displaylabel="true" align="left" rowspan="0" value="%filename" />
|
||||
<field row="1" col="2" name="folio" label="Folio" displaylabel="true" align="left" rowspan="0" value="%{folio-id}/%{folio-total}" />
|
||||
</grid>
|
||||
</insettemplate>
|
@ -180,6 +180,7 @@
|
||||
<file>ico/oxygen-icons/48x48/apps/qelectrotech.png</file>
|
||||
<file>ico/oxygen-icons/64x64/apps/qelectrotech.png</file>
|
||||
<file>ico/splash.png</file>
|
||||
<file>insets/default.inset</file>
|
||||
<file>LICENSE</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -16,6 +16,9 @@
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <QPainter>
|
||||
#include "insettemplate.h"
|
||||
#include "insettemplaterenderer.h"
|
||||
#include "diagramcontext.h"
|
||||
#include "borderinset.h"
|
||||
#include "diagramposition.h"
|
||||
#include "qetapp.h"
|
||||
@ -26,16 +29,19 @@
|
||||
dans la configuration de l'application.
|
||||
@param parent QObject parent de ce BorderInset
|
||||
*/
|
||||
BorderInset::BorderInset(QObject *parent) : QObject(parent) {
|
||||
BorderInset::BorderInset(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
// at first, the internal inset template renderer uses the default inset template
|
||||
inset_template_renderer = new InsetTemplateRenderer(this);
|
||||
inset_template_renderer -> setInsetTemplate(QETApp::defaultInsetTemplate());
|
||||
|
||||
// dimensions par defaut du schema
|
||||
importBorder(BorderProperties());
|
||||
|
||||
// contenu par defaut du cartouche
|
||||
importInset(InsetProperties());
|
||||
|
||||
// hauteur du cartouche
|
||||
inset_height = 50.0;
|
||||
|
||||
display_inset = true;
|
||||
display_border = true;
|
||||
setFolioData(1, 1);
|
||||
@ -48,6 +54,13 @@ BorderInset::BorderInset(QObject *parent) : QObject(parent) {
|
||||
BorderInset::~BorderInset() {
|
||||
}
|
||||
|
||||
/**
|
||||
@return la hauteur du cartouche
|
||||
*/
|
||||
qreal BorderInset::insetHeight() const {
|
||||
return(inset_template_renderer -> height());
|
||||
}
|
||||
|
||||
/**
|
||||
@return Le nombre minimum de colonnes qu'un schema doit comporter
|
||||
*/
|
||||
@ -98,6 +111,7 @@ void BorderInset::importInset(const InsetProperties &ip) {
|
||||
setTitle(ip.title);
|
||||
bi_folio = ip.folio;
|
||||
bi_filename = ip.filename;
|
||||
updateDiagramContextForInset();
|
||||
emit(needFolioData());
|
||||
}
|
||||
|
||||
@ -131,6 +145,22 @@ void BorderInset::importBorder(const BorderProperties &bp) {
|
||||
displayRows(bp.display_rows);
|
||||
}
|
||||
|
||||
/**
|
||||
@return the inset template used to render the inset
|
||||
@see InsetTemplateRenderer::insetTemplate()
|
||||
*/
|
||||
const InsetTemplate *BorderInset::insetTemplate() {
|
||||
return(inset_template_renderer -> insetTemplate());
|
||||
}
|
||||
|
||||
/**
|
||||
@param inset_template The new inset template to use to render the inset
|
||||
@see InsetTemplateRenderer::setInsetTemplate()
|
||||
*/
|
||||
void BorderInset::setInsetTemplate(const InsetTemplate *inset_template) {
|
||||
inset_template_renderer -> setInsetTemplate(inset_template);
|
||||
}
|
||||
|
||||
/**
|
||||
@param di true pour afficher le cartouche, false sinon
|
||||
*/
|
||||
@ -180,12 +210,7 @@ void BorderInset::updateRectangles() {
|
||||
if (diagram != previous_diagram) emit(borderChanged(previous_diagram, diagram));
|
||||
|
||||
// rectangles relatifs au cartouche
|
||||
inset = QRectF(diagram.bottomLeft().x(), diagram.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());
|
||||
inset = QRectF(diagram.bottomLeft().x(), diagram.bottomLeft().y(), insetWidth(), insetHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -198,11 +223,6 @@ void BorderInset::draw(QPainter *qp, qreal x, qreal y) {
|
||||
// translate tous les rectangles
|
||||
diagram .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();
|
||||
@ -256,25 +276,11 @@ void BorderInset::draw(QPainter *qp, qreal x, qreal y) {
|
||||
}
|
||||
}
|
||||
|
||||
// dessine le cartouche
|
||||
// render the inset, using the InsetTemplate object
|
||||
if (display_inset) {
|
||||
qp -> setBrush(Qt::white);
|
||||
qp -> drawRect(inset);
|
||||
|
||||
qp -> drawRect(inset_author);
|
||||
qp -> drawText(inset_author, Qt::AlignVCenter | Qt::AlignLeft, QString(tr(" Auteur : %1", "inset content")).arg(bi_author));
|
||||
|
||||
qp -> drawRect(inset_date);
|
||||
qp -> drawText(inset_date, Qt::AlignVCenter | Qt::AlignLeft, QString(tr(" Date : %1", "inset content")).arg(bi_date.toString("dd/MM/yyyy")));
|
||||
|
||||
qp -> drawRect(inset_title);
|
||||
qp -> drawText(inset_title, Qt::AlignVCenter | Qt::AlignCenter, QString("%1").arg(bi_title));
|
||||
|
||||
qp -> drawRect(inset_file);
|
||||
qp -> drawText(inset_file, Qt::AlignVCenter | Qt::AlignLeft, QString(tr(" Fichier : %1", "inset content")).arg(bi_filename));
|
||||
|
||||
qp -> drawRect(inset_folio);
|
||||
qp -> drawText(inset_folio, Qt::AlignVCenter | Qt::AlignLeft, QString(tr(" Folio : %1", "inset content")).arg(bi_final_folio));
|
||||
qp -> translate(inset.topLeft());
|
||||
inset_template_renderer -> render(qp, inset.width());
|
||||
qp -> translate(-inset.topLeft());
|
||||
}
|
||||
|
||||
qp -> restore();
|
||||
@ -282,11 +288,6 @@ void BorderInset::draw(QPainter *qp, qreal x, qreal y) {
|
||||
// annule la translation des rectangles
|
||||
diagram .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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -410,14 +411,6 @@ void BorderInset::setInsetWidth(const qreal &new_iw) {
|
||||
updateRectangles();
|
||||
}
|
||||
|
||||
/**
|
||||
Change la hauteur du cartouche. Cette hauteur doit rester comprise entre
|
||||
20px et la hauteur du schema.
|
||||
*/
|
||||
void BorderInset::setInsetHeight(const qreal &new_ih) {
|
||||
inset_height = qMax(qreal(20.0), qMin(diagramHeight(), new_ih));
|
||||
updateRectangles();
|
||||
}
|
||||
|
||||
/**
|
||||
Ajuste la largeur du cartouche de facon a ce que celui-ci soit aussi large
|
||||
@ -457,6 +450,23 @@ DiagramPosition BorderInset::convertPosition(const QPointF &pos) {
|
||||
return(DiagramPosition(letter, row_number));
|
||||
}
|
||||
|
||||
/**
|
||||
Update the informations given to the inset template by regenerating a
|
||||
DiagramContext object.
|
||||
*/
|
||||
void BorderInset::updateDiagramContextForInset() {
|
||||
DiagramContext context;
|
||||
context.addValue("author", bi_author);
|
||||
context.addValue("date", bi_date.toString("dd/MM/yyyy"));
|
||||
context.addValue("title", bi_title);
|
||||
context.addValue("filename", bi_filename);
|
||||
context.addValue("folio", bi_final_folio);
|
||||
context.addValue("folio-id", folio_index_);
|
||||
context.addValue("folio-total", folio_total_);
|
||||
|
||||
inset_template_renderer -> setContext(context);
|
||||
}
|
||||
|
||||
QString BorderInset::incrementLetters(const QString &string) {
|
||||
if (string.isEmpty()) {
|
||||
return("A");
|
||||
@ -489,4 +499,6 @@ void BorderInset::setFolioData(int index, int total) {
|
||||
bi_final_folio = bi_folio;
|
||||
bi_final_folio.replace("%id", QString::number(folio_index_));
|
||||
bi_final_folio.replace("%total", QString::number(folio_total_));
|
||||
|
||||
updateDiagramContextForInset();
|
||||
}
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include <QDate>
|
||||
class QPainter;
|
||||
class DiagramPosition;
|
||||
class InsetTemplate;
|
||||
class InsetTemplateRenderer;
|
||||
/**
|
||||
Cette classe represente l'ensemble bordure + cartouche qui encadre le
|
||||
schema electrique.
|
||||
@ -78,8 +80,7 @@ class BorderInset : public QObject {
|
||||
// cartouche
|
||||
/// @return la largeur du cartouche
|
||||
qreal insetWidth() const { return(inset_width); }
|
||||
/// @return la hauteur du cartouche
|
||||
qreal insetHeight() const { return(inset_height); }
|
||||
qreal insetHeight() const;
|
||||
|
||||
// cadre avec le cartouche
|
||||
/// @return la hauteur de la bordure
|
||||
@ -122,7 +123,6 @@ class BorderInset : public QObject {
|
||||
void setRowsHeaderWidth (const qreal &);
|
||||
void setDiagramHeight (const qreal &);
|
||||
void setInsetWidth (const qreal &);
|
||||
void setInsetHeight (const qreal &);
|
||||
void adjustInsetToColumns ();
|
||||
|
||||
DiagramPosition convertPosition(const QPointF &);
|
||||
@ -150,6 +150,9 @@ class BorderInset : public QObject {
|
||||
BorderProperties exportBorder();
|
||||
void importBorder(const BorderProperties &);
|
||||
|
||||
const InsetTemplate *insetTemplate();
|
||||
void setInsetTemplate(const InsetTemplate *);
|
||||
|
||||
// methodes d'acces en ecriture aux options
|
||||
void displayInset(bool);
|
||||
void displayColumns(bool);
|
||||
@ -158,6 +161,7 @@ class BorderInset : public QObject {
|
||||
|
||||
private:
|
||||
void updateRectangles();
|
||||
void updateDiagramContextForInset();
|
||||
QString incrementLetters(const QString &);
|
||||
|
||||
// signaux
|
||||
@ -214,16 +218,12 @@ class BorderInset : public QObject {
|
||||
// rectangles utilises pour le dessin
|
||||
QRectF diagram;
|
||||
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_rows;
|
||||
bool display_border;
|
||||
InsetTemplateRenderer *inset_template_renderer;
|
||||
};
|
||||
#endif
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "qetelementeditor.h"
|
||||
#include "elementscollectionitem.h"
|
||||
#include "fileelementscollection.h"
|
||||
#include "insettemplate.h"
|
||||
#include "qetproject.h"
|
||||
#include "qtextorientationspinboxwidget.h"
|
||||
#include "recentfiles.h"
|
||||
@ -45,6 +46,7 @@ uint QETApp::next_project_id = 0;
|
||||
RecentFiles *QETApp::projects_recent_files_ = 0;
|
||||
RecentFiles *QETApp::elements_recent_files_ = 0;
|
||||
AboutQET *QETApp::about_dialog_ = 0;
|
||||
InsetTemplate *QETApp::default_inset_template_ = 0;
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@ -527,6 +529,21 @@ QTextOrientationSpinBoxWidget *QETApp::createTextOrientationSpinBoxWidget() {
|
||||
);
|
||||
return(widget);
|
||||
}
|
||||
|
||||
/**
|
||||
@return the default inset template for diagrams
|
||||
*/
|
||||
InsetTemplate *QETApp::defaultInsetTemplate() {
|
||||
if (!QETApp::default_inset_template_) {
|
||||
InsetTemplate *inset_template = new InsetTemplate(QETApp::instance());
|
||||
if (inset_template -> loadFromXmlFile(":/insets/default.inset")) {
|
||||
QETApp::default_inset_template_ = inset_template;
|
||||
}
|
||||
}
|
||||
return(default_inset_template_);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@param project un projet
|
||||
@return les editeurs d'elements editant un element appartenant au projet
|
||||
|
@ -30,6 +30,7 @@ class ElementsCollectionItem;
|
||||
class FileElementsCollection;
|
||||
class ElementsCategory;
|
||||
class ElementDefinition;
|
||||
class InsetTemplate;
|
||||
class QETProject;
|
||||
class QTextOrientationSpinBoxWidget;
|
||||
class RecentFiles;
|
||||
@ -98,6 +99,7 @@ class QETApp : public QETSingleApplication {
|
||||
static QList<QETElementEditor *> elementEditors();
|
||||
static QList<QETElementEditor *> elementEditors(QETProject *);
|
||||
static QTextOrientationSpinBoxWidget *createTextOrientationSpinBoxWidget();
|
||||
static InsetTemplate *defaultInsetTemplate();
|
||||
|
||||
protected:
|
||||
#ifdef Q_OS_DARWIN
|
||||
@ -140,6 +142,7 @@ class QETApp : public QETSingleApplication {
|
||||
static RecentFiles *projects_recent_files_;
|
||||
static RecentFiles *elements_recent_files_;
|
||||
static AboutQET *about_dialog_;
|
||||
static InsetTemplate *default_inset_template_;
|
||||
|
||||
public slots:
|
||||
void systray(QSystemTrayIcon::ActivationReason);
|
||||
|
Loading…
x
Reference in New Issue
Block a user