changeset 141:e6c6b88d19b9

* Start hooking up right-button menus on changeset & uncommitted items
author Chris Cannam
date Tue, 30 Nov 2010 17:56:11 +0000
parents bad40d7e7a2b
children 46bf2a4a1fc8
files changesetitem.cpp changesetitem.h changesetscene.cpp changesetscene.h grapher.cpp hgtabwidget.cpp hgtabwidget.h historywidget.cpp historywidget.h mainwindow.cpp mainwindow.h uncommitteditem.cpp uncommitteditem.h
diffstat 13 files changed, 261 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/changesetitem.cpp	Tue Nov 30 14:59:52 2010 +0000
+++ b/changesetitem.cpp	Tue Nov 30 17:56:11 2010 +0000
@@ -41,6 +41,12 @@
     m_font.setItalic(false);
 }
 
+QString
+ChangesetItem::getId()
+{
+    return m_changeset->id();
+}
+
 QRectF
 ChangesetItem::boundingRect() const
 {
@@ -87,6 +93,9 @@
             showDetail();
         }
     } else if (e->button() == Qt::RightButton) {
+        if (m_detail) {
+            hideDetail();
+        }
         activateMenu();
     }
 }
@@ -95,22 +104,41 @@
 ChangesetItem::activateMenu()
 {
     QMenu *menu = new QMenu;
-    QLabel *label = new QLabel(tr("<qt><b>Identifier: </b>%1</qt>")
+    QLabel *label = new QLabel(tr("<qt><b>Revision: </b>%1</qt>")
                                .arg(m_changeset->id()));
-    QWidgetAction *wa = new QWidgetAction(menu);;
+    QWidgetAction *wa = new QWidgetAction(menu);
     wa->setDefaultWidget(label);
     menu->addAction(wa);
     menu->addSeparator();
+
     QAction *update = menu->addAction(tr("Update to this revision"));
+    connect(update, SIGNAL(triggered()), this, SLOT(updateActivated()));
+
     menu->addSeparator();
+
     QAction *diffParent = menu->addAction(tr("Diff against previous revision"));
+    connect(diffParent, SIGNAL(triggered()), this, SLOT(diffToPreviousActivated()));
     QAction *diffCurrent = menu->addAction(tr("Diff against current revision"));
+    connect(diffCurrent, SIGNAL(triggered()), this, SLOT(diffToCurrentActivated()));
+
     menu->addSeparator();
+
     QAction *merge = menu->addAction(tr("Merge from here to current"));
+    connect(merge, SIGNAL(triggered()), this, SLOT(mergeActivated()));
     QAction *tag = menu->addAction(tr("Tag this revision"));
-    menu->exec(QCursor::pos());
+    connect(tag, SIGNAL(triggered()), this, SLOT(tagActivated()));
+
+    QAction *a = menu->exec(QCursor::pos());
+    ungrabMouse();
+    if (a) a->trigger();
 }
 
+void ChangesetItem::updateActivated() { emit updateTo(getId()); }
+void ChangesetItem::diffToPreviousActivated() { emit diffToPrevious(getId()); }
+void ChangesetItem::diffToCurrentActivated() { emit diffToCurrent(getId()); }
+void ChangesetItem::mergeActivated() { emit mergeFrom(getId()); }
+void ChangesetItem::tagActivated() { emit tag(getId()); }
+
 void
 ChangesetItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *option,
                      QWidget *w)
--- a/changesetitem.h	Tue Nov 30 14:59:52 2010 +0000
+++ b/changesetitem.h	Tue Nov 30 17:56:11 2010 +0000
@@ -36,6 +36,7 @@
     virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
 
     Changeset *getChangeset() { return m_changeset; }
+    QString getId();
 
     int column() const { return m_column; }
     int row() const { return m_row; }
@@ -58,10 +59,23 @@
     void detailShown();
     void detailHidden();
 
+    void updateTo(QString);
+    void diffToPrevious(QString);
+    void diffToCurrent(QString);
+    void mergeFrom(QString);
+    void tag(QString);
+
 public slots:
     void showDetail();
     void hideDetail();
 
+private slots:
+    void updateActivated();
+    void diffToPreviousActivated();
+    void diffToCurrentActivated();
+    void mergeActivated();
+    void tagActivated();
+
 protected:
     virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
 
--- a/changesetscene.cpp	Tue Nov 30 14:59:52 2010 +0000
+++ b/changesetscene.cpp	Tue Nov 30 17:56:11 2010 +0000
@@ -17,6 +17,7 @@
 
 #include "changesetscene.h"
 #include "changesetitem.h"
+#include "uncommitteditem.h"
 
 ChangesetScene::ChangesetScene()
     : QGraphicsScene(), m_detailShown(0)
@@ -24,6 +25,45 @@
 }
 
 void
+ChangesetScene::addChangesetItem(ChangesetItem *item)
+{
+    addItem(item);
+
+    connect(item, SIGNAL(detailShown()),
+            this, SLOT(changesetDetailShown()));
+
+    connect(item, SIGNAL(updateTo(QString)),
+            this, SIGNAL(updateTo(QString)));
+
+    connect(item, SIGNAL(diffToCurrent(QString)),
+            this, SIGNAL(diffToCurrent(QString)));
+
+    connect(item, SIGNAL(diffToPrevious(QString)),
+            this, SIGNAL(diffToPrevious(QString)));
+
+    connect(item, SIGNAL(mergeFrom(QString)),
+            this, SIGNAL(mergeFrom(QString)));
+
+    connect(item, SIGNAL(tag(QString)),
+            this, SIGNAL(tag(QString)));
+}
+
+void
+ChangesetScene::addUncommittedItem(UncommittedItem *item)
+{
+    addItem(item);
+    
+    connect(item, SIGNAL(commit()),
+            this, SIGNAL(commit()));
+    
+    connect(item, SIGNAL(revert()),
+            this, SIGNAL(revert()));
+    
+    connect(item, SIGNAL(diff()),
+            this, SIGNAL(diffWorkingFolder()));
+}
+
+void
 ChangesetScene::changesetDetailShown()
 {
     ChangesetItem *csi = qobject_cast<ChangesetItem *>(sender());
--- a/changesetscene.h	Tue Nov 30 14:59:52 2010 +0000
+++ b/changesetscene.h	Tue Nov 30 17:56:11 2010 +0000
@@ -21,6 +21,7 @@
 #include <QGraphicsScene>
 
 class ChangesetItem;
+class UncommittedItem;
 
 class ChangesetScene : public QGraphicsScene
 {
@@ -29,6 +30,20 @@
 public:
     ChangesetScene();
 
+    void addChangesetItem(ChangesetItem *item);
+    void addUncommittedItem(UncommittedItem *item);
+
+signals:
+    void commit();
+    void revert();
+    void diffWorkingFolder();
+
+    void updateTo(QString id);
+    void diffToPrevious(QString id);
+    void diffToCurrent(QString id);
+    void mergeFrom(QString id);
+    void tag(QString id);
+
 public slots:
     void changesetDetailShown();
 
--- a/grapher.cpp	Tue Nov 30 14:59:52 2010 +0000
+++ b/grapher.cpp	Tue Nov 30 17:56:11 2010 +0000
@@ -347,9 +347,7 @@
         item->setX(0);
         item->setY(0);
         m_items[id] = item;
-        m_scene->addItem(item);
-        QObject::connect(item, SIGNAL(detailShown()),
-                         m_scene, SLOT(changesetDetailShown()));
+        m_scene->addChangesetItem(item);
     }
 
     // Add the connecting lines
--- a/hgtabwidget.cpp	Tue Nov 30 14:59:52 2010 +0000
+++ b/hgtabwidget.cpp	Tue Nov 30 17:56:11 2010 +0000
@@ -42,6 +42,30 @@
     // History graph page
     m_historyWidget = new HistoryWidget;
     addTab(m_historyWidget, tr("History"));
+
+    connect(m_historyWidget, SIGNAL(commit()),
+            this, SIGNAL(commit()));
+    
+    connect(m_historyWidget, SIGNAL(revert()),
+            this, SIGNAL(revert()));
+    
+    connect(m_historyWidget, SIGNAL(diffWorkingFolder()),
+            this, SIGNAL(diffWorkingFolder()));
+
+    connect(m_historyWidget, SIGNAL(updateTo(QString)),
+            this, SIGNAL(updateTo(QString)));
+
+    connect(m_historyWidget, SIGNAL(diffToCurrent(QString)),
+            this, SIGNAL(diffToCurrent(QString)));
+
+    connect(m_historyWidget, SIGNAL(diffToPrevious(QString)),
+            this, SIGNAL(diffToPrevious(QString)));
+
+    connect(m_historyWidget, SIGNAL(mergeFrom(QString)),
+            this, SIGNAL(mergeFrom(QString)));
+
+    connect(m_historyWidget, SIGNAL(tag(QString)),
+            this, SIGNAL(tag(QString)));
 }
 
 void HgTabWidget::clearSelections()
--- a/hgtabwidget.h	Tue Nov 30 14:59:52 2010 +0000
+++ b/hgtabwidget.h	Tue Nov 30 17:56:11 2010 +0000
@@ -76,6 +76,16 @@
 signals:
     void selectionChanged();
 
+    void commit();
+    void revert();
+    void diffWorkingFolder();
+
+    void updateTo(QString id);
+    void diffToPrevious(QString id);
+    void diffToCurrent(QString id);
+    void mergeFrom(QString id);
+    void tag(QString id);
+
 public slots:
     void clearSelections();
 
--- a/historywidget.cpp	Tue Nov 30 14:59:52 2010 +0000
+++ b/historywidget.cpp	Tue Nov 30 17:56:11 2010 +0000
@@ -72,10 +72,11 @@
 {
     if (m_uncommittedVisible == show) return;
     m_uncommittedVisible = show;
-    QGraphicsScene *scene = m_panned->scene();
+    ChangesetScene *scene = qobject_cast<ChangesetScene *>(m_panned->scene());
     if (!scene) return;
     if (m_uncommittedVisible) {
-        scene->addItem(m_uncommitted);
+        scene->addUncommittedItem(m_uncommitted);
+        m_uncommitted->ensureVisible();
     } else {
         scene->removeItem(m_uncommitted);
     }
@@ -174,7 +175,7 @@
     }
 
     if (m_uncommittedVisible) {
-        scene->addItem(m_uncommitted);
+        scene->addUncommittedItem(m_uncommitted);
     }
 
     m_panned->setScene(scene);
@@ -183,11 +184,14 @@
     updateNewAndCurrentItems();
 
     if (m_uncommittedVisible) {
+        DEBUG << "asking uncommitted item to be visible" << endl;
         m_uncommitted->ensureVisible();
     } else if (tipItem) {
         DEBUG << "asking tip item to be visible" << endl;
         tipItem->ensureVisible();
     }
+
+    connectSceneSignals();
 }
 
 void HistoryWidget::setChangesetParents()
@@ -242,3 +246,33 @@
         }
     }
 }
+
+void HistoryWidget::connectSceneSignals()
+{
+    ChangesetScene *scene = qobject_cast<ChangesetScene *>(m_panned->scene());
+    if (!scene) return;
+    
+    connect(scene, SIGNAL(commit()),
+            this, SIGNAL(commit()));
+    
+    connect(scene, SIGNAL(revert()),
+            this, SIGNAL(revert()));
+    
+    connect(scene, SIGNAL(diffWorkingFolder()),
+            this, SIGNAL(diffWorkingFolder()));
+
+    connect(scene, SIGNAL(updateTo(QString)),
+            this, SIGNAL(updateTo(QString)));
+
+    connect(scene, SIGNAL(diffToCurrent(QString)),
+            this, SIGNAL(diffToCurrent(QString)));
+
+    connect(scene, SIGNAL(diffToPrevious(QString)),
+            this, SIGNAL(diffToPrevious(QString)));
+
+    connect(scene, SIGNAL(mergeFrom(QString)),
+            this, SIGNAL(mergeFrom(QString)));
+
+    connect(scene, SIGNAL(tag(QString)),
+            this, SIGNAL(tag(QString)));
+}
--- a/historywidget.h	Tue Nov 30 14:59:52 2010 +0000
+++ b/historywidget.h	Tue Nov 30 17:56:11 2010 +0000
@@ -42,6 +42,17 @@
     void parseIncrementalLog(QString log);
 
     bool haveNewItems() const { return !m_newIds.empty(); }
+
+signals:
+    void commit();
+    void revert();
+    void diffWorkingFolder();
+
+    void updateTo(QString id);
+    void diffToPrevious(QString id);
+    void diffToCurrent(QString id);
+    void mergeFrom(QString id);
+    void tag(QString id);
     
 private:
     Changesets m_changesets;
@@ -59,6 +70,7 @@
     void layoutAll();
     void setChangesetParents();
     void updateNewAndCurrentItems();
+    void connectSceneSignals();
 };
 
 #endif
--- a/mainwindow.cpp	Tue Nov 30 14:59:52 2010 +0000
+++ b/mainwindow.cpp	Tue Nov 30 17:56:11 2010 +0000
@@ -69,6 +69,7 @@
 
     justMerged = false;
     hgTabs = new HgTabWidget((QWidget *) this, remoteRepoPath, workFolderPath);
+    connectTabsSignals();
     setCentralWidget(hgTabs);
 
     connect(hgTabs, SIGNAL(selectionChanged()),
@@ -1389,6 +1390,35 @@
     connect(hgServeAct, SIGNAL(triggered()), this, SLOT(hgServe()));
     connect(clearSelectionsAct, SIGNAL(triggered()), this, SLOT(clearSelections()));
 }
+
+void MainWindow::connectTabsSignals()
+{
+    connect(hgTabs, SIGNAL(commit()),
+            this, SLOT(hgCommit()));
+    
+    connect(hgTabs, SIGNAL(revert()),
+            this, SLOT(hgRevert()));
+    
+    connect(hgTabs, SIGNAL(diffWorkingFolder()),
+            this, SLOT(hgFolderDiff()));
+/*!!!!
+    connect(hgTabs, SIGNAL(updateTo(QString)),
+            this, SIGNAL(updateTo(QString)));
+
+    connect(hgTabs, SIGNAL(diffToCurrent(QString)),
+            this, SIGNAL(diffToCurrent(QString)));
+
+    connect(hgTabs, SIGNAL(diffToPrevious(QString)),
+            this, SIGNAL(diffToPrevious(QString)));
+
+    connect(hgTabs, SIGNAL(mergeFrom(QString)),
+            this, SIGNAL(mergeFrom(QString)));
+
+    connect(hgTabs, SIGNAL(tag(QString)),
+            this, SIGNAL(tag(QString)));
+*/
+}    
+
 /*!!!
 void MainWindow::tabChanged(int currTab)
 {
--- a/mainwindow.h	Tue Nov 30 14:59:52 2010 +0000
+++ b/mainwindow.h	Tue Nov 30 17:56:11 2010 +0000
@@ -104,6 +104,7 @@
     void hgLogIncremental();
     void createActions();
     void connectActions();
+    void connectTabsSignals();
     void createMenus();
     void createToolBars();
     void createStatusBar();
--- a/uncommitteditem.cpp	Tue Nov 30 14:59:52 2010 +0000
+++ b/uncommitteditem.cpp	Tue Nov 30 17:56:11 2010 +0000
@@ -21,6 +21,11 @@
 
 #include <QPainter>
 #include <QGraphicsScene>
+#include <QGraphicsSceneMouseEvent>
+#include <QMenu>
+#include <QAction>
+#include <QLabel>
+#include <QWidgetAction>
 
 UncommittedItem::UncommittedItem() :
     m_column(0), m_row(0), m_wide(false)
@@ -41,6 +46,37 @@
 }
 
 void
+UncommittedItem::mousePressEvent(QGraphicsSceneMouseEvent *e)
+{
+    DEBUG << "UncommittedItem::mousePressEvent" << endl;
+    if (e->button() == Qt::RightButton) {
+        activateMenu();
+    }
+}
+
+void
+UncommittedItem::activateMenu()
+{
+    QMenu *menu = new QMenu;
+    QLabel *label = new QLabel(tr("<qt><b>Uncommitted changes</b></qt>"));
+    QWidgetAction *wa = new QWidgetAction(menu);
+    wa->setDefaultWidget(label);
+    menu->addAction(wa);
+    menu->addSeparator();
+
+    QAction *commit = menu->addAction(tr("Commit..."));
+    connect(commit, SIGNAL(triggered()), this, SIGNAL(commit()));
+    QAction *revert = menu->addAction(tr("Revert..."));
+    connect(revert, SIGNAL(triggered()), this, SIGNAL(revert()));
+    QAction *dif = menu->addAction(tr("Diff"));
+    connect(dif, SIGNAL(triggered()), this, SIGNAL(diff()));
+
+    menu->exec(QCursor::pos());
+
+    ungrabMouse();
+}
+
+void
 UncommittedItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *option,
 		       QWidget *w)
 {
--- a/uncommitteditem.h	Tue Nov 30 14:59:52 2010 +0000
+++ b/uncommitteditem.h	Tue Nov 30 17:56:11 2010 +0000
@@ -43,7 +43,17 @@
     bool isWide() const { return m_wide; }
     void setWide(bool w) { m_wide = w; }
 
+signals:
+    void commit();
+    void revert();
+    void diff();
+
+protected:
+    virtual void mousePressEvent(QGraphicsSceneMouseEvent *);
+
 private:
+    void activateMenu();
+
     QString m_branch;
     QFont m_font;
     int m_column;