mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-20 16:20:52 +01:00
Amelioration de la gestion de la scene (prise en compte du cadre et de ses modifications)
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@74 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -7,8 +7,10 @@
|
||||
*/
|
||||
BorderInset::BorderInset(QObject *parent) : QObject(parent) {
|
||||
nb_columns = 15;
|
||||
min_nb_columns = 3;
|
||||
columns_width = 50.0;
|
||||
columns_height = 500.0;
|
||||
min_columns_height = 20.0;
|
||||
inset_width = nb_columns * columns_width;
|
||||
inset_height = 50.0;
|
||||
columns_header_height = 20.0;
|
||||
@@ -126,14 +128,14 @@ void BorderInset::addColumn() {
|
||||
Enleve une colonne. Il doit rester au moins 3 colonnes.
|
||||
*/
|
||||
void BorderInset::removeColumn() {
|
||||
if (nb_columns == 3) return;
|
||||
if (nb_columns == min_nb_columns) return;
|
||||
-- nb_columns;
|
||||
setInsetWidth(nb_columns * columns_width);
|
||||
updateRectangles();
|
||||
}
|
||||
|
||||
void BorderInset::setNbColumns(int nb_c) {
|
||||
if (nb_c < 3) return;
|
||||
if (nb_c < min_nb_columns) return;
|
||||
nb_columns = nb_c;
|
||||
setInsetWidth(nb_columns * columns_width);
|
||||
updateRectangles();
|
||||
@@ -162,7 +164,7 @@ void BorderInset::setColumnsHeaderHeight(const qreal &new_chh) {
|
||||
rester superieure a la hauteur des en-tetes de colonnes + 20px.
|
||||
*/
|
||||
void BorderInset::setColumnsHeight(const qreal &new_ch) {
|
||||
columns_height = qMax(columns_header_height + 20.0, new_ch);
|
||||
columns_height = qMax(columns_header_height + min_columns_height, new_ch);
|
||||
updateRectangles();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
qreal borderHeight() const { return(columns_height + inset_height); }
|
||||
qreal insetWidth() const { return(inset_width); }
|
||||
qreal insetHeight() const { return(inset_height); }
|
||||
qreal minColumnsHeight() const { return(min_columns_height); }
|
||||
int minNbColumns() const { return(min_nb_columns); }
|
||||
|
||||
// methodes d'acces en lecture aux informations du cartouche
|
||||
QString author() const { return(bi_author); }
|
||||
@@ -69,9 +71,11 @@
|
||||
|
||||
// dimensions du cadre et du cartouche
|
||||
int nb_columns;
|
||||
int min_nb_columns;
|
||||
qreal columns_width;
|
||||
qreal columns_header_height;
|
||||
qreal columns_height;
|
||||
qreal min_columns_height;
|
||||
qreal inset_width;
|
||||
qreal inset_height;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ void DiagramView::initialise() {
|
||||
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));
|
||||
adjustSceneRect();
|
||||
connect(scene, SIGNAL(selectionEmptinessChanged()), this, SLOT(slot_selectionChanged()));
|
||||
}
|
||||
|
||||
@@ -233,13 +233,8 @@ void DiagramView::zoomFit() {
|
||||
zoomReset();
|
||||
return;
|
||||
}
|
||||
QRectF vue = scene -> itemsBoundingRect();
|
||||
// la marge = 5 % de la longueur necessaire
|
||||
qreal marge = 0.05 * vue.width();
|
||||
vue.translate(-marge, -marge);
|
||||
vue.setWidth(vue.width() + 2.0 * marge);
|
||||
vue.setHeight(vue.height() + 2.0 * marge);
|
||||
fitInView(vue, Qt::KeepAspectRatio);
|
||||
adjustSceneRect();
|
||||
fitInView(sceneRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -495,9 +490,7 @@ void DiagramView::addColumn() {
|
||||
scene -> border_and_inset.addColumn();
|
||||
|
||||
// met a jour la zone affichee par la vue
|
||||
QRectF sr = sceneRect();
|
||||
sr.setWidth(5.0 + scene -> border_and_inset.borderWidth());
|
||||
setSceneRect(sr);
|
||||
adjustSceneRect();
|
||||
|
||||
// rafraichit la vue
|
||||
scene -> update(sceneRect());
|
||||
@@ -506,29 +499,59 @@ void DiagramView::addColumn() {
|
||||
void DiagramView::removeColumn() {
|
||||
scene -> border_and_inset.removeColumn();
|
||||
|
||||
// on pourrait mettre a jour la zone affichee par la vue
|
||||
// met a jour la zone affichee par la vue
|
||||
QRectF old_sr = sceneRect();
|
||||
adjustSceneRect();
|
||||
|
||||
// rafraichit la vue
|
||||
scene -> update(sceneRect());
|
||||
scene -> update(old_sr);
|
||||
}
|
||||
|
||||
void DiagramView::expand() {
|
||||
// ajoute 10 pixels
|
||||
scene -> border_and_inset.setColumnsHeight(scene -> border_and_inset.columnsHeight() + 20.0);
|
||||
|
||||
// met a jour la zone affichee par la vue
|
||||
QRectF sr = sceneRect();
|
||||
sr.setHeight(20.0 + sr.height());
|
||||
setSceneRect(sr);
|
||||
|
||||
// rafraichit la vue
|
||||
scene -> update(sceneRect());
|
||||
adjustHeight(20.0);
|
||||
}
|
||||
|
||||
void DiagramView::shrink() {
|
||||
// enleve 10 pixels
|
||||
scene -> border_and_inset.setColumnsHeight(scene -> border_and_inset.columnsHeight() - 20.0);
|
||||
adjustHeight(-20.0);
|
||||
}
|
||||
|
||||
/**
|
||||
Change la hauteur du schema
|
||||
@param height_change Le changement de hauteur ; exemple : -5.0 retrecit
|
||||
le cadre de 5 pixels
|
||||
*/
|
||||
void DiagramView::adjustHeight(qreal height_change) {
|
||||
// reference vers le "border and inset" du schema
|
||||
BorderInset &border = scene -> border_and_inset;
|
||||
|
||||
// calcule la nouvelle hauteur des colonnes
|
||||
qreal new_height = border.columnsHeight() + height_change;
|
||||
if (new_height <= border.minColumnsHeight()) return;
|
||||
|
||||
// applique la reduction
|
||||
border.setColumnsHeight(new_height);
|
||||
|
||||
// met a jour la zone affichee par la vue
|
||||
QRectF old_sr = sceneRect();
|
||||
adjustSceneRect();
|
||||
QRectF new_sr = sceneRect();
|
||||
|
||||
// rafraichit la vue
|
||||
scene -> update(sceneRect());
|
||||
scene -> update(height_change < 0 ? old_sr : new_sr);
|
||||
}
|
||||
|
||||
/**
|
||||
Ajuste le sceneRect (zone du schema visualisee par le DiagramView) afin que
|
||||
celui inclut a la fois les elements dans et en dehors du cadre et le cadre
|
||||
lui-meme.
|
||||
*/
|
||||
void DiagramView::adjustSceneRect() {
|
||||
// rectangle delimitant l'ensemble des elements
|
||||
QRectF elements_bounding_rect = scene -> itemsBoundingRect();
|
||||
|
||||
// rectangle contenant le cadre = colonnes + cartouche
|
||||
QRectF border_bounding_rect = scene -> border().adjusted(-MARGIN, -MARGIN, MARGIN, MARGIN);
|
||||
|
||||
// ajuste la sceneRect
|
||||
setSceneRect(elements_bounding_rect.united(border_bounding_rect));
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
class Diagram;
|
||||
#include "element.h"
|
||||
#include "conducer.h"
|
||||
#define TAILLE_GRILLE 10
|
||||
/**
|
||||
Classe representant graphiquement un schema electrique
|
||||
*/
|
||||
@@ -29,6 +28,8 @@
|
||||
void dialogPrint();
|
||||
void addColumn();
|
||||
void removeColumn();
|
||||
void adjustHeight(qreal);
|
||||
void adjustSceneRect();
|
||||
void expand();
|
||||
void shrink();
|
||||
Diagram *diagram() { return(scene); }
|
||||
|
||||
Reference in New Issue
Block a user