changeset 119:005a54380502

* Make scene remember which item has its details showing, and remove the previous one when a new one is clicked
author Chris Cannam
date Sun, 28 Nov 2010 21:52:00 +0000
parents 9734fb0d6fff
children c92f5859c707
files changesetitem.cpp changesetitem.h changesetscene.cpp changesetscene.h easyhg.pro grapher.cpp grapher.h historywidget.cpp
diffstat 8 files changed, 122 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/changesetitem.cpp	Fri Nov 26 23:49:48 2010 +0000
+++ b/changesetitem.cpp	Sun Nov 28 21:52:00 2010 +0000
@@ -44,15 +44,9 @@
 }
 
 void
-ChangesetItem::mousePressEvent(QGraphicsSceneMouseEvent *e)
+ChangesetItem::showDetail()
 {
-    DEBUG << "ChangesetItem::mousePressEvent" << endl;
-    //!!! how best to handle this?
-    if (m_detail) {
-        delete m_detail;
-        m_detail = 0;
-        return;
-    }
+    if (m_detail) return;
     m_detail = new ChangesetDetailItem(m_changeset);
     m_detail->setZValue(zValue() + 1);
     scene()->addItem(m_detail);
@@ -60,6 +54,26 @@
     if (m_wide) w = 180;
     m_detail->moveBy(x() - (m_detail->boundingRect().width() - 50) / 2,
                      y() + 60);
+    emit detailShown();
+}    
+
+void
+ChangesetItem::hideDetail()
+{
+    delete m_detail;
+    m_detail = 0;
+    emit detailHidden();
+}    
+
+void
+ChangesetItem::mousePressEvent(QGraphicsSceneMouseEvent *e)
+{
+    DEBUG << "ChangesetItem::mousePressEvent" << endl;
+    if (m_detail) {
+        hideDetail();
+    } else {
+        showDetail();
+    }
 }
 
 void
--- a/changesetitem.h	Fri Nov 26 23:49:48 2010 +0000
+++ b/changesetitem.h	Sun Nov 28 21:52:00 2010 +0000
@@ -24,8 +24,11 @@
 class Changeset;
 class ChangesetDetailItem;
 
-class ChangesetItem : public QGraphicsItem
+class ChangesetItem : public QObject, public QGraphicsItem
 {
+    Q_OBJECT
+    Q_INTERFACES(QGraphicsItem)
+
 public:
     ChangesetItem(Changeset *cs);
 
@@ -45,6 +48,14 @@
     bool shouldShowBranch() const { return m_showBranch; }
     void setShowBranch(bool s) { m_showBranch = s; }
 
+signals:
+    void detailShown();
+    void detailHidden();
+
+public slots:
+    void showDetail();
+    void hideDetail();
+
 protected:
     virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/changesetscene.cpp	Sun Nov 28 21:52:00 2010 +0000
@@ -0,0 +1,37 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    EasyMercurial
+
+    Based on HgExplorer by Jari Korhonen
+    Copyright (c) 2010 Jari Korhonen
+    Copyright (c) 2010 Chris Cannam
+    Copyright (c) 2010 Queen Mary, University of London
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#include "changesetscene.h"
+#include "changesetitem.h"
+
+ChangesetScene::ChangesetScene()
+    : QGraphicsScene(), m_detailShown(0)
+{
+}
+
+void
+ChangesetScene::changesetDetailShown()
+{
+    ChangesetItem *csi = qobject_cast<ChangesetItem *>(sender());
+    if (!csi) return;
+
+    if (m_detailShown) {
+	m_detailShown->hideDetail();
+    }
+    m_detailShown = csi;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/changesetscene.h	Sun Nov 28 21:52:00 2010 +0000
@@ -0,0 +1,39 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    EasyMercurial
+
+    Based on HgExplorer by Jari Korhonen
+    Copyright (c) 2010 Jari Korhonen
+    Copyright (c) 2010 Chris Cannam
+    Copyright (c) 2010 Queen Mary, University of London
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#ifndef CHANGESETSCENE_H
+#define CHANGESETSCENE_H
+
+#include <QGraphicsScene>
+
+class ChangesetItem;
+
+class ChangesetScene : public QGraphicsScene
+{
+    Q_OBJECT
+
+public:
+    ChangesetScene();
+
+public slots:
+    void changesetDetailShown();
+
+private:
+    ChangesetItem *m_detailShown;
+};
+
+#endif
--- a/easyhg.pro	Fri Nov 26 23:49:48 2010 +0000
+++ b/easyhg.pro	Sun Nov 28 21:52:00 2010 +0000
@@ -35,7 +35,8 @@
     filestatuswidget.h \
     confirmcommentdialog.h \
     hgaction.h \
-    historywidget.h
+    historywidget.h \
+    changesetscene.h
 SOURCES = main.cpp \
     mainwindow.cpp \
     hgtabwidget.cpp \
@@ -61,7 +62,8 @@
     filestates.cpp \
     filestatuswidget.cpp \
     confirmcommentdialog.cpp \
-    historywidget.cpp
+    historywidget.cpp \
+    changesetscene.cpp
 
 macx-* {
     SOURCES += common_osx.mm
--- a/grapher.cpp	Fri Nov 26 23:49:48 2010 +0000
+++ b/grapher.cpp	Sun Nov 28 21:52:00 2010 +0000
@@ -19,8 +19,7 @@
 #include "connectionitem.h"
 #include "dateitem.h"
 #include "debug.h"
-
-#include <QGraphicsScene>
+#include "changesetscene.h"
 
 #include <iostream>
 
@@ -346,6 +345,8 @@
         item->setY(0);
         m_items[id] = item;
         m_scene->addItem(item);
+        QObject::connect(item, SIGNAL(detailShown()),
+                         m_scene, SLOT(changesetDetailShown()));
     }
 
     // Add the connecting lines
--- a/grapher.h	Fri Nov 26 23:49:48 2010 +0000
+++ b/grapher.h	Sun Nov 28 21:52:00 2010 +0000
@@ -20,6 +20,7 @@
 
 #include "changeset.h"
 #include "changesetitem.h"
+#include "changesetscene.h"
 
 #include <QSet>
 #include <QMap>
@@ -30,7 +31,7 @@
 class Grapher
 {
 public:
-    Grapher(QGraphicsScene *scene) { m_scene = scene; }
+    Grapher(ChangesetScene *scene) { m_scene = scene; }
 
     void layout(Changesets csets);
 
@@ -48,7 +49,7 @@
     };
 
 private:
-    QGraphicsScene *m_scene;
+    ChangesetScene *m_scene;
 
     typedef QMap<QString, Changeset *> IdChangesetMap;
     IdChangesetMap m_changesets;
--- a/historywidget.cpp	Fri Nov 26 23:49:48 2010 +0000
+++ b/historywidget.cpp	Sun Nov 28 21:52:00 2010 +0000
@@ -17,6 +17,7 @@
 
 #include "historywidget.h"
 
+#include "changesetscene.h"
 #include "panned.h"
 #include "panner.h"
 #include "grapher.h"
@@ -53,7 +54,7 @@
     
 void HistoryWidget::parseLog(QString log)
 {
-    QGraphicsScene *scene = new QGraphicsScene();
+    ChangesetScene *scene = new ChangesetScene();
     Changesets csets = parseChangeSets(log);
     ChangesetItem *tipItem = 0;