[qet] [1130] The Diagram class now renders its usual inset with a template.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 1130
Author:   xavier
Date:     2010-12-19 19:12:56 +0100 (Sun, 19 Dec 2010)
Log Message:
-----------
The Diagram class now renders its usual inset with a template.

Modified Paths:
--------------
    branches/0.3/qelectrotech.qrc
    branches/0.3/sources/borderinset.cpp
    branches/0.3/sources/borderinset.h
    branches/0.3/sources/qetapp.cpp
    branches/0.3/sources/qetapp.h

Added Paths:
-----------
    branches/0.3/insets/
    branches/0.3/insets/default.inset

Added: branches/0.3/insets/default.inset
===================================================================
--- branches/0.3/insets/default.inset	                        (rev 0)
+++ branches/0.3/insets/default.inset	2010-12-19 18:12:56 UTC (rev 1130)
@@ -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>

Modified: branches/0.3/qelectrotech.qrc
===================================================================
--- branches/0.3/qelectrotech.qrc	2010-12-19 18:08:08 UTC (rev 1129)
+++ branches/0.3/qelectrotech.qrc	2010-12-19 18:12:56 UTC (rev 1130)
@@ -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>

Modified: branches/0.3/sources/borderinset.cpp
===================================================================
--- branches/0.3/sources/borderinset.cpp	2010-12-19 18:08:08 UTC (rev 1129)
+++ branches/0.3/sources/borderinset.cpp	2010-12-19 18:12:56 UTC (rev 1130)
@@ -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);
@@ -49,6 +55,13 @@
 }
 
 /**
+	@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
 */
 int BorderInset::minNbColumns() {
@@ -98,6 +111,7 @@
 	setTitle(ip.title);
 	bi_folio = ip.folio;
 	bi_filename = ip.filename;
+	updateDiagramContextForInset();
 	emit(needFolioData());
 }
 
@@ -132,6 +146,22 @@
 }
 
 /**
+	@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
 */
 void BorderInset::displayInset(bool di) {
@@ -180,12 +210,7 @@
 	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 @@
 	// 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 @@
 		}
 	}
 	
-	// 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 @@
 	// 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 @@
 	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 @@
 	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 @@
 	bi_final_folio = bi_folio;
 	bi_final_folio.replace("%id",    QString::number(folio_index_));
 	bi_final_folio.replace("%total", QString::number(folio_total_));
+	
+	updateDiagramContextForInset();
 }

Modified: branches/0.3/sources/borderinset.h
===================================================================
--- branches/0.3/sources/borderinset.h	2010-12-19 18:08:08 UTC (rev 1129)
+++ branches/0.3/sources/borderinset.h	2010-12-19 18:12:56 UTC (rev 1130)
@@ -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 @@
 	// 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 @@
 	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 @@
 	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 @@
 	
 	private:
 	void updateRectangles();
+	void updateDiagramContextForInset();
 	QString incrementLetters(const QString &);
 	
 	// signaux
@@ -214,16 +218,12 @@
 	// 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

Modified: branches/0.3/sources/qetapp.cpp
===================================================================
--- branches/0.3/sources/qetapp.cpp	2010-12-19 18:08:08 UTC (rev 1129)
+++ branches/0.3/sources/qetapp.cpp	2010-12-19 18:12:56 UTC (rev 1130)
@@ -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 @@
 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,7 +529,22 @@
 	);
 	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
 	project

Modified: branches/0.3/sources/qetapp.h
===================================================================
--- branches/0.3/sources/qetapp.h	2010-12-19 18:08:08 UTC (rev 1129)
+++ branches/0.3/sources/qetapp.h	2010-12-19 18:12:56 UTC (rev 1130)
@@ -30,6 +30,7 @@
 class FileElementsCollection;
 class ElementsCategory;
 class ElementDefinition;
+class InsetTemplate;
 class QETProject;
 class QTextOrientationSpinBoxWidget;
 class RecentFiles;
@@ -98,6 +99,7 @@
 	static QList<QETElementEditor *> elementEditors();
 	static QList<QETElementEditor *> elementEditors(QETProject *);
 	static QTextOrientationSpinBoxWidget *createTextOrientationSpinBoxWidget();
+	static InsetTemplate *defaultInsetTemplate();
 	
 	protected:
 #ifdef Q_OS_DARWIN
@@ -140,6 +142,7 @@
 	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);


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/