Author: aschnell
Date: Mon Mar 9 16:52:01 2009
New Revision: 56027
URL: http://svn.opensuse.org/viewcvs/yast?rev=56027&view=rev
Log:
- added support for context menus
Modified:
trunk/libyui/src/YGraph.h
trunk/qt-graph/VERSION.cmake
trunk/qt-graph/package/yast2-qt-graph.changes
trunk/qt-graph/src/QY2Graph.cc
trunk/qt-graph/src/QY2Graph.h
trunk/qt-graph/src/YQGraph.cc
trunk/qt-graph/src/YQGraph.h
Modified: trunk/libyui/src/YGraph.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YGraph.h?rev=56027&r1=56026&r2=56027&view=diff
==============================================================================
--- trunk/libyui/src/YGraph.h (original)
+++ trunk/libyui/src/YGraph.h Mon Mar 9 16:52:01 2009
@@ -126,7 +126,8 @@
virtual void setGraph( graph_t * graph );
/**
- * Return name of activated node.
+ * Return name of activated node. Activation can happen due to e.g. single
+ * right mouse click (context menu) or double left mouse click.
*/
virtual string activatedNode() const;
@@ -146,6 +147,7 @@
private:
ImplPtr<YGraphPrivate> priv;
+
};
Modified: trunk/qt-graph/VERSION.cmake
URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/VERSION.cmake?rev=56027&r1=56026&r2=56027&view=diff
==============================================================================
--- trunk/qt-graph/VERSION.cmake (original)
+++ trunk/qt-graph/VERSION.cmake Mon Mar 9 16:52:01 2009
@@ -1,3 +1,3 @@
SET(VERSION_MAJOR "2")
SET(VERSION_MINOR "18")
-SET(VERSION_PATCH "3")
+SET(VERSION_PATCH "4")
Modified: trunk/qt-graph/package/yast2-qt-graph.changes
URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/package/yast2-qt-graph.changes?rev=56027&r1=56026&r2=56027&view=diff
==============================================================================
--- trunk/qt-graph/package/yast2-qt-graph.changes (original)
+++ trunk/qt-graph/package/yast2-qt-graph.changes Mon Mar 9 16:52:01 2009
@@ -1,4 +1,10 @@
-------------------------------------------------------------------
+Mon Mar 09 16:11:20 CET 2009 - aschnell@suse.de
+
+- added support for context menus
+- 2.18.4
+
+-------------------------------------------------------------------
Tue Feb 24 12:46:13 CET 2009 - aschnell@suse.de
- support newlines in tooltips
Modified: trunk/qt-graph/src/QY2Graph.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/src/QY2Graph.cc?rev=56027&r1=56026&r2=56027&view=diff
==============================================================================
--- trunk/qt-graph/src/QY2Graph.cc (original)
+++ trunk/qt-graph/src/QY2Graph.cc Mon Mar 9 16:52:01 2009
@@ -62,10 +62,6 @@
scene = new QGraphicsScene(this);
scene->setItemIndexMethod(QGraphicsScene::BspTreeIndex);
setScene(scene);
-
- signalMapper = new QSignalMapper(this);
- connect(signalMapper, SIGNAL(mapped(const QString&)),
- this, SIGNAL(nodeDoubleClickEvent(const QString&)));
}
@@ -117,6 +113,28 @@
}
+void
+QY2Graph::contextMenuEvent(QContextMenuEvent* event)
+{
+ QY2Node* node = dynamic_cast(itemAt(event->pos()));
+
+ if (node)
+ emit nodeContextMenuEvent(event->pos(), node->name);
+ else
+ emit backgroundContextMenuEvent(event->pos());
+}
+
+
+void
+QY2Graph::mouseDoubleClickEvent(QMouseEvent* event)
+{
+ QY2Node* node = dynamic_cast(itemAt(event->pos()));
+
+ if (node)
+ emit nodeDoubleClickEvent(node->name);
+}
+
+
QPointF
QY2Graph::gToQ(const point& p, bool upside_down) const
{
@@ -349,7 +367,7 @@
drawLabel(ND_label(node), &painter);
painter.end();
- QY2Node* item = new QY2Node(makeShape(node), picture);
+ QY2Node* item = new QY2Node(makeShape(node), picture, node->name);
item->setPos(gToQ(ND_coord_i(node)));
@@ -369,9 +387,6 @@
scene->addItem(item);
- signalMapper->setMapping(item, QString(node->name));
- connect(item, SIGNAL(doubleClickEvent()), signalMapper, SLOT(map()));
-
for (edge_t* edge = agfstout(graph, node); edge != NULL; edge = agnxtout(graph, edge))
{
const splines* spl = ED_spl(edge);
@@ -412,11 +427,11 @@
}
-QY2Node::QY2Node(const QPainterPath& path, const QPicture& picture)
+QY2Node::QY2Node(const QPainterPath& path, const QPicture& picture, const QString& name)
: QGraphicsPathItem(path),
- picture(picture)
+ picture(picture),
+ name(name)
{
- setAcceptedMouseButtons(Qt::LeftButton);
}
@@ -431,19 +446,6 @@
}
-void
-QY2Node::mouseDoubleClickEvent(QGraphicsSceneMouseEvent*)
-{
- emit doubleClickEvent();
-}
-
-
-void
-QY2Node::mousePressEvent(QGraphicsSceneMouseEvent*)
-{
-}
-
-
QY2Edge::QY2Edge(const QPainterPath& path, const QPicture& picture)
: QGraphicsPathItem(path),
picture(picture)
Modified: trunk/qt-graph/src/QY2Graph.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/src/QY2Graph.h?rev=56027&r1=56026&r2=56027&view=diff
==============================================================================
--- trunk/qt-graph/src/QY2Graph.h (original)
+++ trunk/qt-graph/src/QY2Graph.h Mon Mar 9 16:52:01 2009
@@ -26,7 +26,6 @@
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsPathItem>
-#include <QSignalMapper>
#include <QPicture>
@@ -53,20 +52,24 @@
signals:
+ void backgroundContextMenuEvent(const QPoint& pos);
+ void nodeContextMenuEvent(const QPoint& pos, const QString& name);
void nodeDoubleClickEvent(const QString& name);
protected:
void keyPressEvent(QKeyEvent* event);
void wheelEvent(QWheelEvent* event);
- void scaleView(qreal scaleFactor);
+ void contextMenuEvent(QContextMenuEvent* event);
+ void mouseDoubleClickEvent(QMouseEvent* event);
private:
void init();
+ void scaleView(qreal scaleFactor);
+
QGraphicsScene* scene;
- QSignalMapper* signalMapper;
QRectF graphRect;
@@ -95,23 +98,18 @@
public:
- QY2Node(const QPainterPath& path, const QPicture& picture);
+ QY2Node(const QPainterPath& path, const QPicture& picture, const QString& name);
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
-signals:
-
- void doubleClickEvent();
-
-protected:
-
- void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event);
- void mousePressEvent(QGraphicsSceneMouseEvent* event);
-
private:
QPicture picture;
+public:
+
+ QString name;
+
};
Modified: trunk/qt-graph/src/YQGraph.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/src/YQGraph.cc?rev=56027&r1=56026&r2=56027&view=diff
==============================================================================
--- trunk/qt-graph/src/YQGraph.cc (original)
+++ trunk/qt-graph/src/YQGraph.cc Mon Mar 9 16:52:01 2009
@@ -38,8 +38,7 @@
{
setWidgetRep(this);
- connect(this, SIGNAL(nodeDoubleClickEvent(const QString&)),
- this, SLOT(nodeActivated(const QString&)));
+ init();
}
@@ -49,8 +48,7 @@
{
setWidgetRep(this);
- connect(this, SIGNAL(nodeDoubleClickEvent(const QString&)),
- this, SLOT(nodeActivated(const QString&)));
+ init();
}
@@ -60,6 +58,20 @@
void
+YQGraph::init()
+{
+ connect(this, SIGNAL(backgroundContextMenuEvent(const QPoint&)),
+ this, SLOT(backgroundContextMenu(const QPoint&)));
+
+ connect(this, SIGNAL(nodeContextMenuEvent(const QPoint&, const QString&)),
+ this, SLOT(nodeContextMenu(const QPoint&, const QString&)));
+
+ connect(this, SIGNAL(nodeDoubleClickEvent(const QString&)),
+ this, SLOT(nodeDoubleClick(const QString&)));
+}
+
+
+void
YQGraph::renderGraph(const string& filename, const string& layoutAlgorithm)
{
QY2Graph::renderGraph(filename, layoutAlgorithm);
@@ -95,7 +107,30 @@
void
-YQGraph::nodeActivated(const QString& name)
+YQGraph::backgroundContextMenu(const QPoint& pos)
+{
+ if (contextMenu())
+ {
+ lastActivatedNode.clear();
+ YQUI::yqApp()->setContextMenuPos(viewport()->mapToGlobal(pos));
+ YQUI::ui()->sendEvent(new YWidgetEvent(this, YEvent::ContextMenuActivated));
+ }
+}
+
+void
+YQGraph::nodeContextMenu(const QPoint& pos, const QString& name)
+{
+ if (contextMenu())
+ {
+ lastActivatedNode = name.toStdString();
+ YQUI::yqApp()->setContextMenuPos(viewport()->mapToGlobal(pos));
+ YQUI::ui()->sendEvent(new YWidgetEvent(this, YEvent::ContextMenuActivated));
+ }
+}
+
+
+void
+YQGraph::nodeDoubleClick(const QString& name)
{
lastActivatedNode = name.toStdString();
YQUI::ui()->sendEvent(new YWidgetEvent(this, YEvent::Activated));
Modified: trunk/qt-graph/src/YQGraph.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/src/YQGraph.h?rev=56027&r1=56026&r2=56027&view=diff
==============================================================================
--- trunk/qt-graph/src/YQGraph.h (original)
+++ trunk/qt-graph/src/YQGraph.h Mon Mar 9 16:52:01 2009
@@ -66,9 +66,13 @@
private slots:
- void nodeActivated(const QString& name);
+ void backgroundContextMenu(const QPoint& pos);
+ void nodeContextMenu(const QPoint& pos, const QString& name);
+ void nodeDoubleClick(const QString& name);
-private:
+private:
+
+ void init();
string lastActivatedNode;
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org