mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 23:20:52 +01:00
Simplification du code gerant la mise a jour du sceneRect en cas de modification de la bordure du schema
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@142 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -33,7 +33,9 @@ BorderInset::~BorderInset() {
|
|||||||
*/
|
*/
|
||||||
void BorderInset::updateRectangles() {
|
void BorderInset::updateRectangles() {
|
||||||
// rectangle delimitant le schema
|
// rectangle delimitant le schema
|
||||||
|
QRectF previous_border = border;
|
||||||
border = QRectF(0, 0, nb_columns * columns_width, columns_height);
|
border = QRectF(0, 0, nb_columns * columns_width, columns_height);
|
||||||
|
if (border != previous_border) emit(borderChanged(previous_border, border));
|
||||||
|
|
||||||
// rectangles relatifs au cartouche
|
// rectangles relatifs au cartouche
|
||||||
inset = QRectF(border.bottomLeft().x(), border.bottomLeft().y(), inset_width, inset_height);
|
inset = QRectF(border.bottomLeft().x(), border.bottomLeft().y(), inset_width, inset_height);
|
||||||
|
|||||||
@@ -89,6 +89,15 @@ class BorderInset : public QObject {
|
|||||||
private:
|
private:
|
||||||
void updateRectangles();
|
void updateRectangles();
|
||||||
|
|
||||||
|
// signaux
|
||||||
|
signals:
|
||||||
|
/**
|
||||||
|
Signal emis lorsque la bordure change
|
||||||
|
@param old_border Ancienne bordure
|
||||||
|
@param new_border Nouvelle bordure
|
||||||
|
*/
|
||||||
|
void borderChanged(QRectF old_border, QRectF new_border);
|
||||||
|
|
||||||
// attributs
|
// attributs
|
||||||
private:
|
private:
|
||||||
// informations du cartouche
|
// informations du cartouche
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ void DiagramView::initialise() {
|
|||||||
setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||||
adjustSceneRect();
|
adjustSceneRect();
|
||||||
connect(scene, SIGNAL(selectionEmptinessChanged()), this, SLOT(slot_selectionChanged()));
|
connect(scene, SIGNAL(selectionEmptinessChanged()), this, SLOT(slot_selectionChanged()));
|
||||||
|
connect(&(scene -> border_and_inset), SIGNAL(borderChanged(QRectF, QRectF)), this, SLOT(adjustSceneRect()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -523,14 +524,7 @@ bool DiagramView::hasSelectedItems() {
|
|||||||
Ajoute une colonne au schema.
|
Ajoute une colonne au schema.
|
||||||
*/
|
*/
|
||||||
void DiagramView::addColumn() {
|
void DiagramView::addColumn() {
|
||||||
// ajoute la colonne
|
|
||||||
scene -> border_and_inset.addColumn();
|
scene -> border_and_inset.addColumn();
|
||||||
|
|
||||||
// met a jour la zone affichee par la vue
|
|
||||||
adjustSceneRect();
|
|
||||||
|
|
||||||
// rafraichit la vue
|
|
||||||
scene -> update(sceneRect());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -538,52 +532,22 @@ void DiagramView::addColumn() {
|
|||||||
*/
|
*/
|
||||||
void DiagramView::removeColumn() {
|
void DiagramView::removeColumn() {
|
||||||
scene -> border_and_inset.removeColumn();
|
scene -> border_and_inset.removeColumn();
|
||||||
|
|
||||||
// met a jour la zone affichee par la vue
|
|
||||||
QRectF old_sr = sceneRect();
|
|
||||||
adjustSceneRect();
|
|
||||||
|
|
||||||
// rafraichit la vue
|
|
||||||
scene -> update(old_sr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Agrandit le schema en hauteur
|
Agrandit le schema en hauteur
|
||||||
*/
|
*/
|
||||||
void DiagramView::expand() {
|
void DiagramView::expand() {
|
||||||
adjustHeight(20.0);
|
qreal new_height = scene -> border_and_inset.columnsHeight() + 20.0;
|
||||||
|
scene -> border_and_inset.setColumnsHeight(new_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Retrecit le schema en hauteur
|
Retrecit le schema en hauteur
|
||||||
*/
|
*/
|
||||||
void DiagramView::shrink() {
|
void DiagramView::shrink() {
|
||||||
adjustHeight(-20.0);
|
qreal new_height = scene -> border_and_inset.columnsHeight() - 20.0;
|
||||||
}
|
scene -> border_and_inset.setColumnsHeight(new_height);
|
||||||
|
|
||||||
/**
|
|
||||||
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(height_change < 0 ? old_sr : new_sr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -592,6 +556,8 @@ void DiagramView::adjustHeight(qreal height_change) {
|
|||||||
lui-meme.
|
lui-meme.
|
||||||
*/
|
*/
|
||||||
void DiagramView::adjustSceneRect() {
|
void DiagramView::adjustSceneRect() {
|
||||||
|
QRectF old_scene_rect = sceneRect();
|
||||||
|
|
||||||
// rectangle delimitant l'ensemble des elements
|
// rectangle delimitant l'ensemble des elements
|
||||||
QRectF elements_bounding_rect = scene -> itemsBoundingRect();
|
QRectF elements_bounding_rect = scene -> itemsBoundingRect();
|
||||||
|
|
||||||
@@ -599,7 +565,11 @@ void DiagramView::adjustSceneRect() {
|
|||||||
QRectF border_bounding_rect = scene -> border().adjusted(-MARGIN, -MARGIN, MARGIN, MARGIN);
|
QRectF border_bounding_rect = scene -> border().adjusted(-MARGIN, -MARGIN, MARGIN, MARGIN);
|
||||||
|
|
||||||
// ajuste la sceneRect
|
// ajuste la sceneRect
|
||||||
setSceneRect(elements_bounding_rect.united(border_bounding_rect));
|
QRectF new_scene_rect = elements_bounding_rect.united(border_bounding_rect);
|
||||||
|
setSceneRect(new_scene_rect);
|
||||||
|
|
||||||
|
// met a jour la scene
|
||||||
|
scene -> update(old_scene_rect.united(new_scene_rect));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiagramView::adjustGridToZoom() {
|
void DiagramView::adjustGridToZoom() {
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ class DiagramView : public QGraphicsView {
|
|||||||
void dialogPrint();
|
void dialogPrint();
|
||||||
void addColumn();
|
void addColumn();
|
||||||
void removeColumn();
|
void removeColumn();
|
||||||
void adjustHeight(qreal);
|
|
||||||
void adjustSceneRect();
|
|
||||||
void expand();
|
void expand();
|
||||||
void shrink();
|
void shrink();
|
||||||
Diagram *diagram() { return(scene); }
|
Diagram *diagram() { return(scene); }
|
||||||
@@ -71,6 +69,7 @@ class DiagramView : public QGraphicsView {
|
|||||||
void couper();
|
void couper();
|
||||||
void copier();
|
void copier();
|
||||||
void coller();
|
void coller();
|
||||||
|
void adjustSceneRect();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slot_selectionChanged();
|
void slot_selectionChanged();
|
||||||
|
|||||||
@@ -378,6 +378,6 @@ void ExportDialog::slot_refreshPreview() {
|
|||||||
// ajoute le nouvel apercu
|
// ajoute le nouvel apercu
|
||||||
QGraphicsPixmapItem *qgpi = new QGraphicsPixmapItem(QPixmap::fromImage(preview_image));
|
QGraphicsPixmapItem *qgpi = new QGraphicsPixmapItem(QPixmap::fromImage(preview_image));
|
||||||
preview_scene -> addItem(qgpi);
|
preview_scene -> addItem(qgpi);
|
||||||
preview_scene -> setSceneRect(QRectF(0.0, 0.0, preview_image.width() + 15.0, preview_image.height() + 15.0));
|
preview_scene -> setSceneRect(QRectF(0.0, 0.0, preview_image.width(), preview_image.height()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user