# HG changeset patch # User Chris Cannam # Date 1290981120 0 # Node ID 005a54380502b2bb46961618e9728dfd5831246c # Parent 9734fb0d6fff394752eadc0758373a2db11535bb * Make scene remember which item has its details showing, and remove the previous one when a new one is clicked diff -r 9734fb0d6fff -r 005a54380502 changesetitem.cpp --- 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 diff -r 9734fb0d6fff -r 005a54380502 changesetitem.h --- 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 *); diff -r 9734fb0d6fff -r 005a54380502 changesetscene.cpp --- /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(sender()); + if (!csi) return; + + if (m_detailShown) { + m_detailShown->hideDetail(); + } + m_detailShown = csi; +} + diff -r 9734fb0d6fff -r 005a54380502 changesetscene.h --- /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 + +class ChangesetItem; + +class ChangesetScene : public QGraphicsScene +{ + Q_OBJECT + +public: + ChangesetScene(); + +public slots: + void changesetDetailShown(); + +private: + ChangesetItem *m_detailShown; +}; + +#endif diff -r 9734fb0d6fff -r 005a54380502 easyhg.pro --- 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 diff -r 9734fb0d6fff -r 005a54380502 grapher.cpp --- 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 +#include "changesetscene.h" #include @@ -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 diff -r 9734fb0d6fff -r 005a54380502 grapher.h --- 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 #include @@ -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 IdChangesetMap; IdChangesetMap m_changesets; diff -r 9734fb0d6fff -r 005a54380502 historywidget.cpp --- 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;