mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
Mac os X add QAbstractScrollArea::wheelEvent(e) only, and gestureEvent, thank Yoann
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3284 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -43,13 +43,13 @@
|
|||||||
#include "factory/elementfactory.h"
|
#include "factory/elementfactory.h"
|
||||||
#include "diagrampropertiesdialog.h"
|
#include "diagrampropertiesdialog.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@param diagram Schema a afficher ; si diagram vaut 0, un nouveau Diagram est utilise
|
@param diagram Schema a afficher ; si diagram vaut 0, un nouveau Diagram est utilise
|
||||||
@param parent Le QWidget parent de cette vue de schema
|
@param parent Le QWidget parent de cette vue de schema
|
||||||
*/
|
*/
|
||||||
DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : QGraphicsView(parent), newShapeItem(nullptr){
|
DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : QGraphicsView(parent), newShapeItem(nullptr){
|
||||||
|
grabGesture(Qt::PinchGesture);
|
||||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
setInteractive(true);
|
setInteractive(true);
|
||||||
current_behavior = noAction;
|
current_behavior = noAction;
|
||||||
@@ -355,6 +355,26 @@ void DiagramView::zoomOut() {
|
|||||||
adjustGridToZoom();
|
adjustGridToZoom();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Agrandit le schema avec le trackpad
|
||||||
|
*/
|
||||||
|
void DiagramView::zoomInSlowly() {
|
||||||
|
scale(1.02, 1.02);
|
||||||
|
adjustGridToZoom();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Retrecit le schema avec le trackpad
|
||||||
|
*/
|
||||||
|
void DiagramView::zoomOutSlowly() {
|
||||||
|
scale(0.98, 0.98);
|
||||||
|
// Interdit le dezoome plus grand que le schéma
|
||||||
|
if ((mapFromScene(0,0).rx() == 0) && (mapFromScene(0,0).ry() == 0)){
|
||||||
|
fitInView(sceneRect(), Qt::KeepAspectRatio);
|
||||||
|
}
|
||||||
|
adjustGridToZoom();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Agrandit ou rectrecit le schema de facon a ce que tous les elements du
|
Agrandit ou rectrecit le schema de facon a ce que tous les elements du
|
||||||
schema soient visibles a l'ecran. S'il n'y a aucun element sur le schema,
|
schema soient visibles a l'ecran. S'il n'y a aucun element sur le schema,
|
||||||
@@ -563,6 +583,11 @@ void DiagramView::mouseReleaseEvent(QMouseEvent *e) {
|
|||||||
void DiagramView::wheelEvent(QWheelEvent *e) {
|
void DiagramView::wheelEvent(QWheelEvent *e) {
|
||||||
//Zoom and scrolling
|
//Zoom and scrolling
|
||||||
if (e->buttons() != Qt::MidButton) {
|
if (e->buttons() != Qt::MidButton) {
|
||||||
|
|
||||||
|
#if defined(__APPLE__) && defined(__MACH__)
|
||||||
|
QAbstractScrollArea::wheelEvent(e);
|
||||||
|
#else
|
||||||
|
if (e->buttons() != Qt::MidButton) {
|
||||||
if (!(e -> modifiers() & Qt::ControlModifier)) {
|
if (!(e -> modifiers() & Qt::ControlModifier)) {
|
||||||
if (e -> delta() > 0){
|
if (e -> delta() > 0){
|
||||||
zoomIn();
|
zoomIn();
|
||||||
@@ -575,8 +600,36 @@ void DiagramView::wheelEvent(QWheelEvent *e) {
|
|||||||
QAbstractScrollArea::wheelEvent(e);
|
QAbstractScrollArea::wheelEvent(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utilise le pincement du trackpad pour zoomer
|
||||||
|
* @brief DiagramView::gestureEvent
|
||||||
|
* @param event
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
bool DiagramView::gestureEvent(QGestureEvent *event){
|
||||||
|
if (QGesture *gesture = event->gesture(Qt::PinchGesture)) {
|
||||||
|
QPinchGesture *pinch = static_cast<QPinchGesture *>(gesture);
|
||||||
|
if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged){
|
||||||
|
qreal value = gesture->property("scaleFactor").toReal();
|
||||||
|
if (value > 1){
|
||||||
|
zoomInSlowly();
|
||||||
|
}else{
|
||||||
|
zoomOutSlowly();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Handles "Focus in" events. Reimplemented here to store the fact the focus
|
Handles "Focus in" events. Reimplemented here to store the fact the focus
|
||||||
was freshly acquired again using the mouse. This information is later used
|
was freshly acquired again using the mouse. This information is later used
|
||||||
@@ -1044,6 +1097,13 @@ void DiagramView::resetConductors() {
|
|||||||
@param e Evenement
|
@param e Evenement
|
||||||
*/
|
*/
|
||||||
bool DiagramView::event(QEvent *e) {
|
bool DiagramView::event(QEvent *e) {
|
||||||
|
// By default touch events are converted to mouse events. So
|
||||||
|
// after this event we will get a mouse event also but we want
|
||||||
|
// to handle touch events as gestures only. So we need this safeguard
|
||||||
|
// to block mouse events that are actually generated from touch.
|
||||||
|
if (e->type() == QEvent::Gesture)
|
||||||
|
return gestureEvent(static_cast<QGestureEvent *>(e));
|
||||||
|
|
||||||
// fait en sorte que les raccourcis clavier arrivent prioritairement sur la
|
// fait en sorte que les raccourcis clavier arrivent prioritairement sur la
|
||||||
// vue plutot que de remonter vers les QMenu / QAction
|
// vue plutot que de remonter vers les QMenu / QAction
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ class DiagramView : public QGraphicsView {
|
|||||||
void handleElementDrop(QDropEvent *);
|
void handleElementDrop(QDropEvent *);
|
||||||
void handleTitleBlockDrop(QDropEvent *);
|
void handleTitleBlockDrop(QDropEvent *);
|
||||||
void handleTextDrop(QDropEvent *);
|
void handleTextDrop(QDropEvent *);
|
||||||
|
bool gestureEvent(QGestureEvent *event);
|
||||||
QRectF viewedSceneRect() const;
|
QRectF viewedSceneRect() const;
|
||||||
bool mustIntegrateElement(const ElementsLocation &) const;
|
bool mustIntegrateElement(const ElementsLocation &) const;
|
||||||
bool mustIntegrateTitleBlockTemplate(const TitleBlockTemplateLocation &) const;
|
bool mustIntegrateTitleBlockTemplate(const TitleBlockTemplateLocation &) const;
|
||||||
@@ -161,6 +162,8 @@ class DiagramView : public QGraphicsView {
|
|||||||
void setSelectionMode();
|
void setSelectionMode();
|
||||||
void zoomIn();
|
void zoomIn();
|
||||||
void zoomOut();
|
void zoomOut();
|
||||||
|
void zoomInSlowly();
|
||||||
|
void zoomOutSlowly();
|
||||||
void zoomFit();
|
void zoomFit();
|
||||||
void zoomContent();
|
void zoomContent();
|
||||||
void zoomReset();
|
void zoomReset();
|
||||||
|
|||||||
Reference in New Issue
Block a user