Bring back mouse wheel zooming.
authorMilian Wolff <milian.wolff@kdab.com>
Wed, 2 Sep 2015 15:09:36 +0000 (17:09 +0200)
committerMilian Wolff <milian.wolff@kdab.com>
Wed, 2 Sep 2015 15:09:36 +0000 (17:09 +0200)
Works fine when removing the ItemIgnoresTransformations flag,
which apparently isn't required after all.

gui/flamegraph.cpp

index 170805a..7f22f4b 100644 (file)
@@ -42,8 +42,6 @@ public:
     FrameGraphicsItem(const QRectF& rect, const quint64 cost, const QString& function, FrameGraphicsItem* parent = nullptr)
         : QGraphicsRectItem(rect, parent)
     {
-        setFlag(QGraphicsItem::ItemIgnoresTransformations);
-
         static const QString emptyLabel = QStringLiteral("???");
 
         m_label = i18nc("%1: number of allocations, %2: function label",
@@ -181,7 +179,15 @@ bool FlameGraph::eventFilter(QObject* object, QEvent* event)
         return QObject::eventFilter(object, event);
     }
 
-    if (event->type() == QEvent::MouseButtonRelease) {
+    if (event->type() == QEvent::Wheel) {
+        QWheelEvent* wheelEvent = static_cast<QWheelEvent*>(event);
+        if (wheelEvent->modifiers() == Qt::ControlModifier) {
+            // zoom view with Ctrl + mouse wheel
+            qreal scale = pow(1.1, double(wheelEvent->delta()) / (120.0 * 2.));
+            m_view->scale(scale, scale);
+            return true;
+        }
+    } else if (event->type() == QEvent::MouseButtonRelease) {
         QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
         if (mouseEvent->button() == Qt::LeftButton) {
             auto item = dynamic_cast<FrameGraphicsItem*>(m_view->itemAt(mouseEvent->pos()));