[Kst] branches/work/kst/portto4/kst/src/libkstapp

Adam Treat treat at kde.org
Thu Oct 4 19:45:58 CEST 2007


SVN commit 721142 by treat:

* Add a title to the item's context menu.
* Change the names of the items to suit.
* Add zoom actions for the plotrenderitem.
* Implement triggering mechanism for items to have
shortcuts.


 M  +1 -1      boxitem.cpp  
 M  +1 -1      curvedialog.cpp  
 M  +1 -1      ellipseitem.cpp  
 M  +1 -1      labelitem.cpp  
 M  +3 -1      layoutboxitem.cpp  
 M  +1 -1      lineitem.cpp  
 M  +1 -1      pictureitem.cpp  
 M  +1 -3      plotitem.cpp  
 M  +156 -2    plotrenderitem.cpp  
 M  +38 -1     plotrenderitem.h  
 M  +1 -1      svgitem.cpp  
 M  +3 -2      vectorcurverenderitem.cpp  
 M  +1 -1      vectorcurverenderitem.h  
 M  +26 -0     view.cpp  
 M  +6 -0      view.h  
 M  +23 -2     viewitem.cpp  
 M  +1 -0      viewitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/boxitem.cpp #721141:721142
@@ -20,7 +20,7 @@
 
 BoxItem::BoxItem(View *parent)
     : ViewItem(parent) {
-  setName("BoxItem");
+  setName("Box");
   setBrush(Qt::white);
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/curvedialog.cpp #721141:721142
@@ -157,7 +157,7 @@
   KstRelationList relationList;
   relationList.append(kst_cast<KstRelation>(curve));
 
-  VectorCurveRenderItem *vectorCurve = new VectorCurveRenderItem("vectorCurve", plotItem);
+  VectorCurveRenderItem *vectorCurve = new VectorCurveRenderItem(plotItem);
   vectorCurve->setRelationList(relationList);
 
   plotItem->addRenderItem(vectorCurve);
--- branches/work/kst/portto4/kst/src/libkstapp/ellipseitem.cpp #721141:721142
@@ -19,7 +19,7 @@
 
 EllipseItem::EllipseItem(View *parent)
   : ViewItem(parent) {
-  setName("EllipseItem");
+  setName("Ellipse");
   setBrush(Qt::white);
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/labelitem.cpp #721141:721142
@@ -22,7 +22,7 @@
 
 LabelItem::LabelItem(View *parent, const QString& txt)
   : ViewItem(parent), _parsed(0), _text(txt) {
-  setName("LabelItem");
+  setName("Label");
 
   setAllowedGripModes(Move /*| Resize*/ | Rotate /*| Scale*/);
 }
--- branches/work/kst/portto4/kst/src/libkstapp/layoutboxitem.cpp #721141:721142
@@ -23,7 +23,7 @@
 
 LayoutBoxItem::LayoutBoxItem(View *parent)
     : ViewItem(parent) {
-  setName("LayoutBoxItem");
+  setName("Layout Box");
   setPen(Qt::NoPen);
   setBrush(Qt::NoBrush);
   setAllowedGripModes(Move);
@@ -88,6 +88,8 @@
 void LayoutBoxItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
   QMenu menu;
 
+  addTitle(&menu);
+
   QAction *editAction = menu.addAction(tr("Edit"));
   connect(editAction, SIGNAL(triggered()), this, SLOT(edit()));
 
--- branches/work/kst/portto4/kst/src/libkstapp/lineitem.cpp #721141:721142
@@ -21,7 +21,7 @@
 
 LineItem::LineItem(View *parent)
   : ViewItem(parent) {
-  setName("LineItem");
+  setName("Line");
   setAllowedGrips(RightMidGrip | LeftMidGrip);
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/pictureitem.cpp #721141:721142
@@ -20,7 +20,7 @@
 
 PictureItem::PictureItem(View *parent, const QImage &image)
   : ViewItem(parent), _image(QPixmap::fromImage(image)) {
-  setName("PictureItem");
+  setName("Picture");
   setLockAspectRatio(true);
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #721141:721142
@@ -29,14 +29,12 @@
 static qreal MARGIN_WIDTH = 20.0;
 static qreal MARGIN_HEIGHT = 20.0;
 
-static uint COUNT = 0;
-
 namespace Kst {
 
 PlotItem::PlotItem(View *parent)
   : ViewItem(parent), _calculatedMarginWidth(0), _calculatedMarginHeight(0) {
 
-  setName("PlotItem");
+  setName("Plot");
   setBrush(Qt::white);
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.cpp #721141:721142
@@ -12,9 +12,12 @@
 #include "plotrenderitem.h"
 
 #include <QTime>
+#include <QMenu>
 #include <QStatusBar>
 #include <QMainWindow>
 #include <QGraphicsSceneHoverEvent>
+#include <QGraphicsSceneMouseEvent>
+#include <QGraphicsSceneContextMenuEvent>
 
 #include "plotitem.h"
 #include "application.h"
@@ -23,10 +26,10 @@
 
 namespace Kst {
 
-PlotRenderItem::PlotRenderItem(const QString &name, PlotItem *parentItem)
+PlotRenderItem::PlotRenderItem(PlotItem *parentItem)
   : ViewItem(parentItem->parentView()), _zoomRect(QRectF()) {
 
-  setName(name);
+  setName(tr("Plot Render"));
   setParentItem(parentItem);
   setHasStaticGeometry(true);
   setAllowedGripModes(0);
@@ -39,6 +42,7 @@
 
   updateGeometry(); //the initial rect
   updateViewMode(); //the initial view
+  createActions();
 }
 
 
@@ -166,6 +170,95 @@
 }
 
 
+void PlotRenderItem::createActions() {
+  _zoomMaximum = new QAction(tr("Zoom Maximum"), this);
+  _zoomMaximum->setShortcut(Qt::Key_M);
+  plotItem()->parentView()->registerShortcut(_zoomMaximum);
+  connect(_zoomMaximum, SIGNAL(triggered()), this, SLOT(zoomMaximum()));
+
+  _zoomMaxSpikeInsensitive = new QAction(tr("Zoom Max Spike Insensitive"), this);
+  _zoomMaxSpikeInsensitive->setShortcut(Qt::Key_S);
+
+//   _zoomPrevious = new QAction(tr("Zoom Previous"), this);
+//   _zoomPrevious->setShortcut(Qt::Key_R);
+
+  _zoomYMeanCentered = new QAction(tr("Y-Zoom Mean-centered"), this);
+  _zoomYMeanCentered->setShortcut(Qt::Key_A);
+
+  _zoomXMaximum = new QAction(tr("X-Zoom Maximum"), this);
+  _zoomXMaximum->setShortcut(Qt::CTRL+Qt::Key_M);
+
+  _zoomXOut = new QAction(tr("X-Zoom Out"), this);
+  _zoomXOut->setShortcut(Qt::SHIFT+Qt::Key_Right);
+
+  _zoomXIn = new QAction(tr("X-Zoom In"), this);
+  _zoomXIn->setShortcut(Qt::SHIFT+Qt::Key_Left);
+
+  _zoomNormalizeXtoY = new QAction(tr("Normalize X Axis to Y Axis"), this);
+  _zoomNormalizeXtoY->setShortcut(Qt::Key_N);
+
+  _zoomToggleLogX = new QAction(tr("Toggle Log X Axis"), this);
+  _zoomToggleLogX->setShortcut(Qt::Key_G);
+
+  _zoomYLocalMaximum = new QAction(tr("Y-Zoom Local Maximum"), this);
+  _zoomYLocalMaximum->setShortcut(Qt::SHIFT+Qt::Key_L);
+
+  _zoomYMaximum = new QAction(tr("Y-Zoom Maximum"), this);
+  _zoomYMaximum->setShortcut(Qt::SHIFT+Qt::Key_M);
+
+  _zoomYOut = new QAction(tr("Y-Zoom Out"), this);
+  _zoomYOut->setShortcut(Qt::SHIFT+Qt::Key_Up);
+
+  _zoomYIn = new QAction(tr("Y-Zoom In"), this);
+  _zoomYIn->setShortcut(Qt::SHIFT+Qt::Key_Down);
+
+  _zoomNormalizeYtoX = new QAction(tr("Normalize Y Axis to X Axis"), this);
+  _zoomNormalizeYtoX->setShortcut(Qt::SHIFT+Qt::Key_N);
+
+  _zoomToggleLogY = new QAction(tr("Toggle Log Y Axis"), this);
+  _zoomToggleLogY->setShortcut(Qt::Key_L);
+}
+
+
+void PlotRenderItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
+  QMenu menu;
+
+  addTitle(&menu);
+
+  QAction *editAction = menu.addAction(tr("Edit"));
+  connect(editAction, SIGNAL(triggered()), this, SLOT(edit()));
+
+  QMenu zoom;
+  zoom.setTitle(tr("Zoom"));
+
+  zoom.addAction(_zoomMaximum);
+  zoom.addAction(_zoomMaxSpikeInsensitive);
+//   zoom.addAction(_zoomPrevious);
+  zoom.addAction(_zoomYMeanCentered);
+
+  zoom.addSeparator();
+
+  zoom.addAction(_zoomXMaximum);
+  zoom.addAction(_zoomXOut);
+  zoom.addAction(_zoomXIn);
+  zoom.addAction(_zoomNormalizeXtoY);
+  zoom.addAction(_zoomToggleLogX);
+
+  zoom.addSeparator();
+
+  zoom.addAction(_zoomYLocalMaximum);
+  zoom.addAction(_zoomYMaximum);
+  zoom.addAction(_zoomYOut);
+  zoom.addAction(_zoomYIn);
+  zoom.addAction(_zoomNormalizeYtoX);
+  zoom.addAction(_zoomToggleLogY);
+
+  menu.addMenu(&zoom);
+
+  menu.exec(event->screenPos());
+}
+
+
 void PlotRenderItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
   if (parentView()->viewMode() != View::Data) {
     event->ignore();
@@ -284,6 +377,67 @@
   }
 }
 
+
+void PlotRenderItem::zoomMaximum() {
+  qDebug() << "Zoom Maximum" << endl;
 }
 
+
+void PlotRenderItem::zoomMaxSpikeInsensitive() {
+}
+
+
+// void PlotRenderItem::zoomPrevious() {
+// }
+
+
+void PlotRenderItem::zoomYMeanCentered() {
+}
+
+
+void PlotRenderItem::zoomXMaximum() {
+}
+
+
+void PlotRenderItem::zoomXOut() {
+}
+
+
+void PlotRenderItem::zoomXIn() {
+}
+
+
+void PlotRenderItem::zoomNormalizeXtoY() {
+}
+
+
+void PlotRenderItem::zoomToggleLogX() {
+}
+
+
+void PlotRenderItem::zoomYLocalMaximum() {
+}
+
+
+void PlotRenderItem::zoomYMaximum() {
+}
+
+
+void PlotRenderItem::zoomYOut() {
+}
+
+
+void PlotRenderItem::zoomYIn() {
+}
+
+
+void PlotRenderItem::zoomNormalizeYtoX() {
+}
+
+
+void PlotRenderItem::zoomToggleLogY() {
+}
+
+}
+
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.h #721141:721142
@@ -30,7 +30,7 @@
 {
   Q_OBJECT
   public:
-    PlotRenderItem(const QString &name, PlotItem *parentItem);
+    PlotRenderItem(PlotItem *parentItem);
     virtual ~PlotRenderItem();
 
     PlotItem *plotItem() const;
@@ -59,6 +59,7 @@
     QRectF mapFromProjection(const QRectF &rect) const;
 
   protected:
+    virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
     virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
     virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
@@ -73,11 +74,47 @@
     void updateGeometry();
     void updateViewMode();
 
+    void zoomMaximum();
+    void zoomMaxSpikeInsensitive();
+//     void zoomPrevious();
+    void zoomYMeanCentered();
+    void zoomXMaximum();
+    void zoomXOut();
+    void zoomXIn();
+    void zoomNormalizeXtoY();
+    void zoomToggleLogX();
+    void zoomYLocalMaximum();
+    void zoomYMaximum();
+    void zoomYOut();
+    void zoomYIn();
+    void zoomNormalizeYtoX();
+    void zoomToggleLogY();
+
   private:
+    void createActions();
+
+  private:
     RenderType _type;
     KstRelationList _relationList;
     QRectF _zoomRect;
     SelectionRect _selectionRect;
+
+    QAction *_zoomMaximum;
+    QAction *_zoomMaxSpikeInsensitive;
+    QAction *_zoomPrevious;
+    QAction *_zoomYMeanCentered;
+    QAction *_zoomXMaximum;
+    QAction *_zoomXOut;
+    QAction *_zoomXIn;
+    QAction *_zoomNormalizeXtoY;
+    QAction *_zoomToggleLogX;
+    QAction *_zoomYLocalMaximum;
+    QAction *_zoomYMaximum;
+    QAction *_zoomYOut;
+    QAction *_zoomYIn;
+    QAction *_zoomNormalizeYtoX;
+    QAction *_zoomToggleLogY;
+
 };
 
 }
--- branches/work/kst/portto4/kst/src/libkstapp/svgitem.cpp #721141:721142
@@ -21,7 +21,7 @@
 SvgItem::SvgItem(View *parent, const QString &file)
   : ViewItem(parent), _svg(new QSvgRenderer(file)) {
   //FIXME need to set the element id??
-  setName("SvgItem");
+  setName("Svg");
   setLockAspectRatio(true);
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/vectorcurverenderitem.cpp #721141:721142
@@ -18,9 +18,10 @@
 
 namespace Kst {
 
-VectorCurveRenderItem::VectorCurveRenderItem(const QString &name, PlotItem *parentItem)
-  : PlotRenderItem(name, parentItem) {
+VectorCurveRenderItem::VectorCurveRenderItem(PlotItem *parentItem)
+  : PlotRenderItem(parentItem) {
   setType(Cartesian);
+  setName(tr("Vector Curve"));
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/vectorcurverenderitem.h #721141:721142
@@ -20,7 +20,7 @@
 {
   Q_OBJECT
   public:
-    VectorCurveRenderItem(const QString &name, PlotItem *parentItem);
+    VectorCurveRenderItem(PlotItem *parentItem);
     virtual ~VectorCurveRenderItem();
 
     virtual void paintRelations(QPainter *painter);
--- branches/work/kst/portto4/kst/src/libkstapp/view.cpp #721141:721142
@@ -163,6 +163,32 @@
 }
 
 
+void View::registerShortcut(QAction *action) {
+  grabShortcut(action->shortcut(), Qt::WidgetShortcut);
+  _shortcutMap.insert(action->shortcut().toString(), action);
+}
+
+
+bool View::event(QEvent *event) {
+
+  if (event->type() == QEvent::Shortcut) {
+    QShortcutEvent *e = static_cast<QShortcutEvent*>(event);
+    if (!_shortcutMap.contains(e->key()))
+        return QGraphicsView::event(event);
+
+    if (QAction *action = _shortcutMap.value(e->key())) {
+      ViewItem *i = qgraphicsitem_cast<ViewItem*>(scene()->itemAt(mapToScene(mapFromGlobal(QCursor::pos()))));
+      if (i == action->parent()) {
+        action->trigger();
+        return true;
+      }
+    }
+  }
+
+  return QGraphicsView::event(event);
+}
+
+
 bool View::eventFilter(QObject *obj, QEvent *event) {
   if (obj != scene() || _mouseMode != Create)
     return QGraphicsView::eventFilter(obj, event);
--- branches/work/kst/portto4/kst/src/libkstapp/view.h #721141:721142
@@ -12,6 +12,8 @@
 #ifndef VIEW_H
 #define VIEW_H
 
+#include <QHash>
+#include <QAction>
 #include <QGraphicsView>
 
 #include "kst_export.h"
@@ -78,6 +80,8 @@
 
     QPointF snapPoint(const QPointF &point);
 
+    void registerShortcut(QAction *action);
+
   Q_SIGNALS:
     void viewModeChanged(View::ViewMode oldMode);
     void mouseModeChanged(View::MouseMode oldMode);
@@ -87,6 +91,7 @@
     void createLayout();
 
   protected:
+    bool event(QEvent *event);
     bool eventFilter(QObject *obj, QEvent *event);
     void resizeEvent(QResizeEvent *event);
     void drawBackground(QPainter *painter, const QRectF &rect);
@@ -110,6 +115,7 @@
     bool _showGrid;
     bool _snapToGridHorizontal;
     bool _snapToGridVertical;
+    QHash<QString, QAction*> _shortcutMap;
 };
 
 }
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #721141:721142
@@ -23,8 +23,10 @@
 
 #include <QMenu>
 #include <QDebug>
+#include <QLabel>
+#include <QHBoxLayout>
+#include <QWidgetAction>
 #include <QGraphicsScene>
-#include <QKeyEvent>
 #include <QGraphicsSceneContextMenuEvent>
 
 static const double ONE_PI = 3.14159265358979323846264338327950288419717;
@@ -49,7 +51,7 @@
     _allowedGrips(TopLeftGrip | TopRightGrip | BottomRightGrip | BottomLeftGrip |
                   TopMidGrip | RightMidGrip | BottomMidGrip | LeftMidGrip) {
 
-  setName("ViewItem");
+  setName("View Item");
   setAcceptsHoverEvents(true);
   setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable);
   connect(parent, SIGNAL(mouseModeChanged(View::MouseMode)),
@@ -556,9 +558,28 @@
 }
 
 
+void ViewItem::addTitle(QMenu *menu) const {
+  QWidgetAction *action = new QWidgetAction(menu);
+  action->setEnabled(false);
+
+  QLabel *label = new QLabel(name() + tr(" Menu"), menu);
+  label->setAlignment(Qt::AlignCenter);
+  label->setStyleSheet("QLabel {"
+                       "border-bottom: 2px solid lightGray;"
+                       "font: bold large;"
+                       "padding: 3px;"
+                       "margin: 1px;"
+                       "}");
+  action->setDefaultWidget(label);
+  menu->addAction(action);
+}
+
+
 void ViewItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
   QMenu menu;
 
+  addTitle(&menu);
+
   QAction *editAction = menu.addAction(tr("Edit"));
   connect(editAction, SIGNAL(triggered()), this, SLOT(edit()));
 
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #721141:721142
@@ -155,6 +155,7 @@
     QPointF lockOffset(const QPointF &offset, qreal ratio, bool oddCorner) const;
     bool maybeReparent();
     GripMode nextGripMode(GripMode currentMode) const;
+    void addTitle(QMenu *menu) const;
 
   protected Q_SLOTS:
     virtual void creationPolygonChanged(View::CreationEvent event);


More information about the Kst mailing list