2007-12-01 10:47:15 +00:00
|
|
|
/*
|
2010-01-03 16:25:37 +00:00
|
|
|
Copyright 2006-2010 Xavier Guerrin
|
2007-12-01 10:47:15 +00:00
|
|
|
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/>.
|
|
|
|
*/
|
2008-07-30 12:44:57 +00:00
|
|
|
#include <QPainter>
|
2010-12-20 02:45:36 +00:00
|
|
|
#include "titleblocktemplate.h"
|
|
|
|
#include "titleblocktemplaterenderer.h"
|
2010-12-19 18:12:56 +00:00
|
|
|
#include "diagramcontext.h"
|
2010-12-20 02:45:36 +00:00
|
|
|
#include "bordertitleblock.h"
|
2009-05-20 21:29:17 +00:00
|
|
|
#include "diagramposition.h"
|
2007-11-14 20:27:45 +00:00
|
|
|
#include "qetapp.h"
|
2008-08-10 15:07:59 +00:00
|
|
|
#include "math.h"
|
2007-01-28 00:53:17 +00:00
|
|
|
|
|
|
|
/**
|
2008-08-10 15:07:59 +00:00
|
|
|
Constructeur simple : construit une bordure en recuperant les dimensions
|
|
|
|
dans la configuration de l'application.
|
2010-12-20 02:45:36 +00:00
|
|
|
@param parent QObject parent de ce BorderTitleBlock
|
2007-01-28 00:53:17 +00:00
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
BorderTitleBlock::BorderTitleBlock(QObject *parent) :
|
2010-12-19 18:12:56 +00:00
|
|
|
QObject(parent)
|
|
|
|
{
|
2010-12-20 02:45:36 +00:00
|
|
|
// at first, the internal titleblock template renderer uses the default titleblock template
|
|
|
|
titleblock_template_renderer = new TitleBlockTemplateRenderer(this);
|
|
|
|
titleblock_template_renderer -> setTitleBlockTemplate(QETApp::defaultTitleBlockTemplate());
|
2010-12-19 18:12:56 +00:00
|
|
|
|
2008-08-14 22:51:08 +00:00
|
|
|
// dimensions par defaut du schema
|
2009-04-03 19:30:25 +00:00
|
|
|
importBorder(BorderProperties());
|
2008-08-10 15:07:59 +00:00
|
|
|
|
2008-08-15 12:46:22 +00:00
|
|
|
// contenu par defaut du cartouche
|
2010-12-20 02:45:36 +00:00
|
|
|
importTitleBlock(TitleBlockProperties());
|
2008-08-15 12:46:22 +00:00
|
|
|
|
2010-12-20 02:45:36 +00:00
|
|
|
display_titleblock = true;
|
2007-02-01 01:07:26 +00:00
|
|
|
display_border = true;
|
2009-04-03 19:30:25 +00:00
|
|
|
setFolioData(1, 1);
|
2007-01-28 00:53:17 +00:00
|
|
|
updateRectangles();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructeur - ne fait rien
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
BorderTitleBlock::~BorderTitleBlock() {
|
2007-01-28 00:53:17 +00:00
|
|
|
}
|
|
|
|
|
2010-12-19 18:12:56 +00:00
|
|
|
/**
|
|
|
|
@return la hauteur du cartouche
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
qreal BorderTitleBlock::titleBlockHeight() const {
|
|
|
|
return(titleblock_template_renderer -> height());
|
2010-12-19 18:12:56 +00:00
|
|
|
}
|
|
|
|
|
2008-08-10 15:07:59 +00:00
|
|
|
/**
|
|
|
|
@return Le nombre minimum de colonnes qu'un schema doit comporter
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
int BorderTitleBlock::minNbColumns() {
|
2008-08-10 15:07:59 +00:00
|
|
|
return(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return la largeur minimale d'une colonne de schema
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
qreal BorderTitleBlock::minColumnsWidth() {
|
2008-08-10 15:07:59 +00:00
|
|
|
return(5.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return Le nombre minimum de lignes qu'un schema doit comporter
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
int BorderTitleBlock::minNbRows() {
|
2008-08-10 15:07:59 +00:00
|
|
|
return(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return la hauteur minimale d'une ligne de schema
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
qreal BorderTitleBlock::minRowsHeight() {
|
2008-08-10 15:07:59 +00:00
|
|
|
return(5.0);
|
|
|
|
}
|
|
|
|
|
2008-08-14 22:51:08 +00:00
|
|
|
/**
|
|
|
|
@return les proprietes du cartouches
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
TitleBlockProperties BorderTitleBlock::exportTitleBlock() {
|
|
|
|
TitleBlockProperties ip;
|
2008-08-14 22:51:08 +00:00
|
|
|
ip.author = bi_author;
|
|
|
|
ip.date = bi_date;
|
|
|
|
ip.title = bi_title;
|
|
|
|
ip.folio = bi_folio;
|
|
|
|
ip.filename = bi_filename;
|
2010-12-24 23:35:40 +00:00
|
|
|
ip.template_name = titleBlockTemplateName();
|
2008-08-14 22:51:08 +00:00
|
|
|
return(ip);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param ip les nouvelles proprietes du cartouche
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::importTitleBlock(const TitleBlockProperties &ip) {
|
2008-08-14 22:51:08 +00:00
|
|
|
bi_author = ip.author;
|
|
|
|
bi_date = ip.date;
|
2009-04-03 19:30:25 +00:00
|
|
|
setTitle(ip.title);
|
2008-08-14 22:51:08 +00:00
|
|
|
bi_folio = ip.folio;
|
|
|
|
bi_filename = ip.filename;
|
2010-12-20 02:45:36 +00:00
|
|
|
updateDiagramContextForTitleBlock();
|
2009-04-03 19:30:25 +00:00
|
|
|
emit(needFolioData());
|
2010-12-24 23:35:40 +00:00
|
|
|
emit(needTitleBlockTemplate(ip.template_name));
|
2008-08-14 22:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@return les proprietes de la bordure
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
BorderProperties BorderTitleBlock::exportBorder() {
|
2008-08-14 22:51:08 +00:00
|
|
|
BorderProperties bp;
|
|
|
|
bp.columns_count = nbColumns();
|
|
|
|
bp.columns_width = columnsWidth();
|
|
|
|
bp.columns_header_height = columnsHeaderHeight();
|
|
|
|
bp.display_columns = columnsAreDisplayed();
|
|
|
|
bp.rows_count = nbRows();
|
|
|
|
bp.rows_height = rowsHeight();
|
|
|
|
bp.rows_header_width = rowsHeaderWidth();
|
|
|
|
bp.display_rows = rowsAreDisplayed();
|
|
|
|
return(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-11-22 16:12:22 +00:00
|
|
|
@param bp les nouvelles proprietes de la bordure
|
2008-08-14 22:51:08 +00:00
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::importBorder(const BorderProperties &bp) {
|
2008-08-14 22:51:08 +00:00
|
|
|
setColumnsHeaderHeight(bp.columns_header_height);
|
|
|
|
setNbColumns(bp.columns_count);
|
|
|
|
setColumnsWidth(bp.columns_width);
|
|
|
|
displayColumns(bp.display_columns);
|
|
|
|
setRowsHeaderWidth(bp.rows_header_width);
|
|
|
|
setNbRows(bp.rows_count);
|
|
|
|
setRowsHeight(bp.rows_height);
|
|
|
|
displayRows(bp.display_rows);
|
|
|
|
}
|
|
|
|
|
2010-12-19 18:12:56 +00:00
|
|
|
/**
|
2010-12-20 02:45:36 +00:00
|
|
|
@return the titleblock template used to render the titleblock
|
|
|
|
@see TitleBlockTemplateRenderer::titleBlockTemplate()
|
2010-12-19 18:12:56 +00:00
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
const TitleBlockTemplate *BorderTitleBlock::titleBlockTemplate() {
|
|
|
|
return(titleblock_template_renderer -> titleBlockTemplate());
|
2010-12-19 18:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-12-20 02:45:36 +00:00
|
|
|
@param titleblock_template The new titleblock template to use to render the titleblock
|
|
|
|
@see TitleBlockTemplateRenderer::setTitleBlockTemplate()
|
2010-12-19 18:12:56 +00:00
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::setTitleBlockTemplate(const TitleBlockTemplate *titleblock_template) {
|
|
|
|
titleblock_template_renderer -> setTitleBlockTemplate(titleblock_template);
|
2010-12-19 18:12:56 +00:00
|
|
|
}
|
|
|
|
|
2010-12-24 23:35:40 +00:00
|
|
|
/**
|
|
|
|
@return The name of the template used to render the titleblock.
|
|
|
|
*/
|
|
|
|
QString BorderTitleBlock::titleBlockTemplateName() const {
|
|
|
|
QString tbt_name = titleblock_template_renderer -> titleBlockTemplate() -> name();
|
|
|
|
return((tbt_name == "default") ? "" : tbt_name);
|
|
|
|
}
|
|
|
|
|
2010-12-24 21:00:11 +00:00
|
|
|
/**
|
|
|
|
This slot may be used to inform this class that the given title block
|
|
|
|
template has changed. The title block-dedicated rendering cache will thus be
|
|
|
|
flushed.
|
|
|
|
@param template_name Name of the title block template that has changed
|
|
|
|
*/
|
|
|
|
void BorderTitleBlock::titleBlockTemplateChanged(const QString &template_name) {
|
2010-12-24 23:35:40 +00:00
|
|
|
if (titleBlockTemplateName() != template_name) return;
|
2010-12-24 21:00:11 +00:00
|
|
|
titleblock_template_renderer -> invalidateRenderedTemplate();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
This slot has to be used to inform this class that the given title block
|
|
|
|
template is about to be removed and is no longer accessible. This class
|
|
|
|
will either use the provided optional TitleBlockTemplate or the default
|
|
|
|
title block provided by QETApp::defaultTitleBlockTemplate()
|
|
|
|
@param template_name Name of the title block template that has changed
|
|
|
|
@param new_template (Optional) title block template to use instead
|
|
|
|
*/
|
|
|
|
void BorderTitleBlock::titleBlockTemplateRemoved(const QString &removed_template_name, const TitleBlockTemplate *new_template) {
|
2010-12-24 23:35:40 +00:00
|
|
|
if (titleBlockTemplateName() != removed_template_name) return;
|
2010-12-24 21:00:11 +00:00
|
|
|
|
|
|
|
if (new_template) {
|
|
|
|
setTitleBlockTemplate(new_template);
|
|
|
|
} else {
|
|
|
|
setTitleBlockTemplate(QETApp::defaultTitleBlockTemplate());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-15 12:46:22 +00:00
|
|
|
/**
|
|
|
|
@param di true pour afficher le cartouche, false sinon
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::displayTitleBlock(bool di) {
|
|
|
|
bool change = (di != display_titleblock);
|
|
|
|
display_titleblock = di;
|
2008-08-15 12:46:22 +00:00
|
|
|
if (change) emit(displayChanged());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param dc true pour afficher les entetes des colonnes, false sinon
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::displayColumns(bool dc) {
|
2008-08-15 12:46:22 +00:00
|
|
|
bool change = (dc != display_columns);
|
|
|
|
display_columns = dc;
|
|
|
|
if (change) emit(displayChanged());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param dr true pour afficher les entetes des lignes, false sinon
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::displayRows(bool dr) {
|
2008-08-15 12:46:22 +00:00
|
|
|
bool change = (dr != display_rows);
|
|
|
|
display_rows = dr;
|
|
|
|
if (change) emit(displayChanged());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@param db true pour afficher la bordure du schema, false sinon
|
2009-04-03 19:30:25 +00:00
|
|
|
Note : si l'affichage de la bordure est ainsi desactivee, les lignes et
|
|
|
|
colonnes ne seront pas dessinees.
|
2008-08-15 12:46:22 +00:00
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::displayBorder(bool db) {
|
2008-08-15 12:46:22 +00:00
|
|
|
bool change = (db != display_border);
|
|
|
|
display_border = db;
|
|
|
|
if (change) emit(displayChanged());
|
|
|
|
}
|
|
|
|
|
2007-01-28 00:53:17 +00:00
|
|
|
/**
|
|
|
|
Methode recalculant les rectangles composant le cadre et le cartouche en
|
|
|
|
fonction des attributs de taille
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::updateRectangles() {
|
2007-01-28 00:53:17 +00:00
|
|
|
// rectangle delimitant le schema
|
2008-08-10 15:07:59 +00:00
|
|
|
QRectF previous_diagram = diagram;
|
|
|
|
diagram = QRectF(0, 0, diagramWidth(), diagramHeight());
|
|
|
|
if (diagram != previous_diagram) emit(borderChanged(previous_diagram, diagram));
|
2007-01-28 00:53:17 +00:00
|
|
|
|
|
|
|
// rectangles relatifs au cartouche
|
2010-12-20 02:45:36 +00:00
|
|
|
titleblock = QRectF(diagram.bottomLeft().x(), diagram.bottomLeft().y(), titleBlockWidth(), titleBlockHeight());
|
2007-01-28 00:53:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
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
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::draw(QPainter *qp, qreal x, qreal y) {
|
2007-01-28 00:53:17 +00:00
|
|
|
// translate tous les rectangles
|
2008-08-10 15:07:59 +00:00
|
|
|
diagram .translate(x, y);
|
2010-12-20 02:45:36 +00:00
|
|
|
titleblock .translate(x, y);
|
2007-01-28 00:53:17 +00:00
|
|
|
|
|
|
|
// prepare le QPainter
|
|
|
|
qp -> save();
|
|
|
|
qp -> setPen(Qt::black);
|
|
|
|
qp -> setBrush(Qt::NoBrush);
|
|
|
|
|
|
|
|
// dessine le cadre
|
2008-08-10 15:07:59 +00:00
|
|
|
if (display_border) qp -> drawRect(diagram);
|
2007-01-28 00:53:17 +00:00
|
|
|
|
2009-04-12 17:21:19 +00:00
|
|
|
qp -> setFont(QETApp::diagramTextsFont());
|
2008-07-08 18:27:07 +00:00
|
|
|
|
2008-08-10 15:07:59 +00:00
|
|
|
// dessine la case vide qui apparait des qu'il y a un entete
|
2009-04-03 19:30:25 +00:00
|
|
|
if (display_border && (display_columns || display_rows)) {
|
2008-08-10 15:07:59 +00:00
|
|
|
qp -> setBrush(Qt::white);
|
|
|
|
QRectF first_rectangle(
|
|
|
|
diagram.topLeft().x(),
|
|
|
|
diagram.topLeft().y(),
|
|
|
|
rows_header_width,
|
|
|
|
columns_header_height
|
|
|
|
);
|
|
|
|
qp -> drawRect(first_rectangle);
|
|
|
|
}
|
|
|
|
|
2007-01-28 00:53:17 +00:00
|
|
|
// dessine la numerotation des colonnes
|
2009-04-03 19:30:25 +00:00
|
|
|
if (display_border && display_columns) {
|
2007-02-01 01:07:26 +00:00
|
|
|
for (int i = 1 ; i <= nb_columns ; ++ i) {
|
|
|
|
QRectF numbered_rectangle = QRectF(
|
2008-08-10 15:07:59 +00:00
|
|
|
diagram.topLeft().x() + (rows_header_width + ((i - 1) * columns_width)),
|
|
|
|
diagram.topLeft().y(),
|
2007-02-01 01:07:26 +00:00
|
|
|
columns_width,
|
|
|
|
columns_header_height
|
|
|
|
);
|
|
|
|
qp -> drawRect(numbered_rectangle);
|
|
|
|
qp -> drawText(numbered_rectangle, Qt::AlignVCenter | Qt::AlignCenter, QString("%1").arg(i));
|
|
|
|
}
|
2007-01-28 00:53:17 +00:00
|
|
|
}
|
|
|
|
|
2008-08-10 15:07:59 +00:00
|
|
|
// dessine la numerotation des lignes
|
2009-04-03 19:30:25 +00:00
|
|
|
if (display_border && display_rows) {
|
2008-08-10 15:07:59 +00:00
|
|
|
QString row_string("A");
|
|
|
|
for (int i = 1 ; i <= nb_rows ; ++ i) {
|
|
|
|
QRectF lettered_rectangle = QRectF(
|
|
|
|
diagram.topLeft().x(),
|
|
|
|
diagram.topLeft().y() + (columns_header_height + ((i - 1) * rows_height)),
|
|
|
|
rows_header_width,
|
|
|
|
rows_height
|
|
|
|
);
|
|
|
|
qp -> drawRect(lettered_rectangle);
|
|
|
|
qp -> drawText(lettered_rectangle, Qt::AlignVCenter | Qt::AlignCenter, row_string);
|
|
|
|
row_string = incrementLetters(row_string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-20 02:45:36 +00:00
|
|
|
// render the titleblock, using the TitleBlockTemplate object
|
|
|
|
if (display_titleblock) {
|
|
|
|
qp -> translate(titleblock.topLeft());
|
|
|
|
titleblock_template_renderer -> render(qp, titleblock.width());
|
|
|
|
qp -> translate(-titleblock.topLeft());
|
2007-02-01 01:07:26 +00:00
|
|
|
}
|
2007-02-02 17:40:07 +00:00
|
|
|
|
|
|
|
qp -> restore();
|
|
|
|
|
2007-01-28 00:53:17 +00:00
|
|
|
// annule la translation des rectangles
|
2008-08-10 15:07:59 +00:00
|
|
|
diagram .translate(-x, -y);
|
2010-12-20 02:45:36 +00:00
|
|
|
titleblock .translate(-x, -y);
|
2007-01-28 00:53:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Ajoute une colonne.
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::addColumn() {
|
2008-08-10 15:07:59 +00:00
|
|
|
setNbColumns(nbColumns() + 1);
|
2007-01-28 00:53:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-08-10 15:07:59 +00:00
|
|
|
Enleve une colonne sans passer sous le minimum requis.
|
|
|
|
@see minNbColumns()
|
2007-01-28 00:53:17 +00:00
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::removeColumn() {
|
2008-08-10 15:07:59 +00:00
|
|
|
setNbColumns(nbColumns() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Ajoute une ligne.
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::addRow() {
|
2008-08-10 15:07:59 +00:00
|
|
|
setNbRows(nbRows() + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Enleve une ligne sans passer sous le minimum requis.
|
|
|
|
@see minNbRows()
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::removeRow() {
|
2008-08-10 15:07:59 +00:00
|
|
|
setNbRows(nbRows() - 1);
|
2007-01-28 00:53:17 +00:00
|
|
|
}
|
|
|
|
|
2007-04-09 02:56:47 +00:00
|
|
|
/**
|
|
|
|
Permet de changer le nombre de colonnes.
|
2008-08-10 15:07:59 +00:00
|
|
|
Si ce nombre de colonnes est inferieur au minimum requis, c'est ce minimum
|
|
|
|
qui est utilise.
|
2007-04-09 02:56:47 +00:00
|
|
|
@param nb_c nouveau nombre de colonnes
|
|
|
|
@see minNbColumns()
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::setNbColumns(int nb_c) {
|
2008-08-10 15:07:59 +00:00
|
|
|
if (nb_c == nbColumns()) return;
|
|
|
|
nb_columns = qMax(minNbColumns(), nb_c);
|
2010-12-20 02:45:36 +00:00
|
|
|
setTitleBlockWidth(diagramWidth());
|
2007-02-28 20:48:11 +00:00
|
|
|
}
|
|
|
|
|
2007-01-28 00:53:17 +00:00
|
|
|
/**
|
2008-08-10 15:07:59 +00:00
|
|
|
Change la largeur des colonnes.
|
|
|
|
Si la largeur indiquee est inferieure au minimum requis, c'est ce minimum
|
|
|
|
qui est utilise.
|
|
|
|
@param new_cw nouvelle largeur des colonnes
|
|
|
|
@see minColumnsWidth()
|
2007-01-28 00:53:17 +00:00
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::setColumnsWidth(const qreal &new_cw) {
|
2008-08-10 15:07:59 +00:00
|
|
|
if (new_cw == columnsWidth()) return;
|
|
|
|
columns_width = qMax(minColumnsWidth(), new_cw);
|
2010-12-20 02:45:36 +00:00
|
|
|
setTitleBlockWidth(diagramWidth());
|
2007-01-28 00:53:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Change la hauteur des en-tetes contenant les numeros de colonnes. Celle-ci
|
|
|
|
doit rester comprise entre 5 et 50 px.
|
2008-08-10 15:07:59 +00:00
|
|
|
@param new_chh nouvelle hauteur des en-tetes de colonnes
|
2007-01-28 00:53:17 +00:00
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::setColumnsHeaderHeight(const qreal &new_chh) {
|
2009-09-12 10:17:44 +00:00
|
|
|
columns_header_height = qBound(qreal(5.0), new_chh, qreal(50.0));
|
2007-01-28 00:53:17 +00:00
|
|
|
updateRectangles();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-08-10 15:07:59 +00:00
|
|
|
Permet de changer le nombre de lignes.
|
|
|
|
Si ce nombre de lignes est inferieur au minimum requis, cette fonction ne
|
|
|
|
fait rien
|
|
|
|
@param nb_r nouveau nombre de lignes
|
|
|
|
@see minNbRows()
|
2007-01-28 00:53:17 +00:00
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::setNbRows(int nb_r) {
|
2008-08-10 15:07:59 +00:00
|
|
|
if (nb_r == nbRows()) return;
|
|
|
|
nb_rows = qMax(minNbRows(), nb_r);
|
2010-12-20 02:45:36 +00:00
|
|
|
setTitleBlockWidth(diagramWidth());
|
2007-01-28 00:53:17 +00:00
|
|
|
updateRectangles();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-08-10 15:07:59 +00:00
|
|
|
Change la hauteur des lignes.
|
|
|
|
Si la hauteur indiquee est inferieure au minimum requis, c'est ce minimum
|
|
|
|
qui est utilise.
|
2009-11-22 16:12:22 +00:00
|
|
|
@param new_rh nouvelle hauteur des lignes
|
2008-08-10 15:07:59 +00:00
|
|
|
@see minRowsHeight()
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::setRowsHeight(const qreal &new_rh) {
|
2008-08-10 15:07:59 +00:00
|
|
|
if (new_rh == rowsHeight()) return;
|
|
|
|
rows_height = qMax(minRowsHeight(), new_rh);
|
|
|
|
updateRectangles();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Change la largeur des en-tetes contenant les numeros de lignes. Celle-ci
|
|
|
|
doit rester comprise entre 5 et 50 px.
|
|
|
|
@param new_rhw nouvelle largeur des en-tetes des lignes
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::setRowsHeaderWidth(const qreal &new_rhw) {
|
2009-09-12 10:17:44 +00:00
|
|
|
rows_header_width = qBound(qreal(5.0), new_rhw, qreal(50.0));
|
2008-08-10 15:07:59 +00:00
|
|
|
updateRectangles();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Cette methode essaye de se rapprocher le plus possible de la hauteur donnee
|
|
|
|
en parametre en modifiant le nombre de lignes en cours.
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::setDiagramHeight(const qreal &height) {
|
2008-08-10 15:07:59 +00:00
|
|
|
// taille des lignes a utiliser = rows_height
|
2008-08-10 18:53:31 +00:00
|
|
|
setNbRows(qRound(ceil(height / rows_height)));
|
2008-08-10 15:07:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Change la largeur du cartouche. Cette largeur sera restreinte a celle du
|
|
|
|
schema.
|
2007-01-28 00:53:17 +00:00
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::setTitleBlockWidth(const qreal &new_iw) {
|
|
|
|
titleblock_width = qMin(diagramWidth(), new_iw);
|
2007-01-28 00:53:17 +00:00
|
|
|
updateRectangles();
|
|
|
|
}
|
|
|
|
|
2007-10-12 12:54:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Ajuste la largeur du cartouche de facon a ce que celui-ci soit aussi large
|
|
|
|
que le schema
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::adjustTitleBlockToColumns() {
|
|
|
|
setTitleBlockWidth(diagramWidth());
|
2008-08-10 15:07:59 +00:00
|
|
|
}
|
|
|
|
|
2009-05-20 21:29:17 +00:00
|
|
|
/**
|
|
|
|
@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
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
DiagramPosition BorderTitleBlock::convertPosition(const QPointF &pos) {
|
2009-05-20 21:29:17 +00:00
|
|
|
// 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();
|
2009-07-30 20:48:19 +00:00
|
|
|
int row_number = int(ceil(relative_pos.x() / columnsWidth()));
|
|
|
|
int column_number = int(ceil(relative_pos.y() / rowsHeight()));
|
2009-05-20 21:29:17 +00:00
|
|
|
|
|
|
|
QString letter = "A";
|
|
|
|
for (int i = 1 ; i < column_number ; ++ i) {
|
|
|
|
letter = incrementLetters(letter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(DiagramPosition(letter, row_number));
|
|
|
|
}
|
|
|
|
|
2010-12-19 18:12:56 +00:00
|
|
|
/**
|
2010-12-20 02:45:36 +00:00
|
|
|
Update the informations given to the titleblock template by regenerating a
|
2010-12-19 18:12:56 +00:00
|
|
|
DiagramContext object.
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::updateDiagramContextForTitleBlock() {
|
2010-12-19 18:12:56 +00:00
|
|
|
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_);
|
|
|
|
|
2010-12-20 02:45:36 +00:00
|
|
|
titleblock_template_renderer -> setContext(context);
|
2010-12-19 18:12:56 +00:00
|
|
|
}
|
|
|
|
|
2010-12-20 02:45:36 +00:00
|
|
|
QString BorderTitleBlock::incrementLetters(const QString &string) {
|
2008-08-10 15:07:59 +00:00
|
|
|
if (string.isEmpty()) {
|
|
|
|
return("A");
|
|
|
|
} else {
|
|
|
|
// separe les digits precedents du dernier digit
|
|
|
|
QString first_digits(string.left(string.count() - 1));
|
|
|
|
QChar last_digit(string.at(string.count() - 1));
|
|
|
|
if (last_digit != 'Z') {
|
|
|
|
// incremente le dernier digit
|
|
|
|
last_digit = last_digit.toAscii() + 1;
|
|
|
|
return(first_digits + QString(last_digit));
|
|
|
|
} else {
|
|
|
|
return(incrementLetters(first_digits) + "A");
|
|
|
|
}
|
|
|
|
}
|
2007-10-12 12:54:25 +00:00
|
|
|
}
|
2009-04-03 19:30:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
@param index numero du schema (de 1 a total)
|
|
|
|
@param total nombre total de schemas dans le projet
|
|
|
|
*/
|
2010-12-20 02:45:36 +00:00
|
|
|
void BorderTitleBlock::setFolioData(int index, int total) {
|
2009-04-03 19:30:25 +00:00
|
|
|
if (index < 1 || total < 1 || index > total) return;
|
|
|
|
|
|
|
|
// memorise les informations
|
|
|
|
folio_index_ = index;
|
|
|
|
folio_total_ = total;
|
|
|
|
|
|
|
|
// regenere le contenu du champ folio
|
|
|
|
bi_final_folio = bi_folio;
|
|
|
|
bi_final_folio.replace("%id", QString::number(folio_index_));
|
|
|
|
bi_final_folio.replace("%total", QString::number(folio_total_));
|
2010-12-19 18:12:56 +00:00
|
|
|
|
2010-12-20 02:45:36 +00:00
|
|
|
updateDiagramContextForTitleBlock();
|
2009-04-03 19:30:25 +00:00
|
|
|
}
|