changeset 129:4986642800f0

* Initial work on showing uncommitted changes (as dashed box) in history graph
author Chris Cannam
date Mon, 29 Nov 2010 20:53:34 +0000
parents fcaf09ee825d
children 9ae4cc0055e8
files easyhg.pro hgtabwidget.cpp hgtabwidget.h historywidget.cpp historywidget.h mainwindow.cpp uncommitteditem.cpp uncommitteditem.h
diffstat 8 files changed, 176 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/easyhg.pro	Mon Nov 29 20:09:58 2010 +0000
+++ b/easyhg.pro	Mon Nov 29 20:53:34 2010 +0000
@@ -37,7 +37,8 @@
     hgaction.h \
     historywidget.h \
     changesetscene.h \
-    incomingdialog.h
+    incomingdialog.h \
+    uncommitteditem.h
 SOURCES = main.cpp \
     mainwindow.cpp \
     hgtabwidget.cpp \
@@ -65,7 +66,8 @@
     confirmcommentdialog.cpp \
     historywidget.cpp \
     changesetscene.cpp \
-    incomingdialog.cpp
+    incomingdialog.cpp \
+    uncommitteditem.cpp
 
 macx-* {
     SOURCES += common_osx.mm
--- a/hgtabwidget.cpp	Mon Nov 29 20:09:58 2010 +0000
+++ b/hgtabwidget.cpp	Mon Nov 29 20:53:34 2010 +0000
@@ -54,6 +54,11 @@
     m_historyWidget->setCurrent(ids);
 }
 
+void HgTabWidget::showUncommittedChanges(bool u)
+{
+    m_historyWidget->showUncommittedChanges(u);
+}
+
 bool HgTabWidget::canCommit() const
 {
     if (!m_fileStatusWidget->getSelectedAddableFiles().empty()) return false;
--- a/hgtabwidget.h	Mon Nov 29 20:09:58 2010 +0000
+++ b/hgtabwidget.h	Mon Nov 29 20:53:34 2010 +0000
@@ -49,6 +49,7 @@
     void setState(QString state);
 
     void setCurrent(QStringList ids);
+    void showUncommittedChanges(bool);
 
     FileStates getFileStates() { return m_fileStates; }
 
--- a/historywidget.cpp	Mon Nov 29 20:09:58 2010 +0000
+++ b/historywidget.cpp	Mon Nov 29 20:53:34 2010 +0000
@@ -22,6 +22,7 @@
 #include "panner.h"
 #include "grapher.h"
 #include "debug.h"
+#include "uncommitteditem.h"
 
 #include <iostream>
 
@@ -31,6 +32,8 @@
 {
     m_panned = new Panned;
     m_panner = new Panner;
+    m_uncommitted = new UncommittedItem();
+    m_uncommitted->setRow(-1);
 
     QGridLayout *layout = new QGridLayout;
     layout->addWidget(m_panned, 0, 0);
@@ -44,6 +47,7 @@
 HistoryWidget::~HistoryWidget()
 {
     clearChangesets();
+    delete m_uncommitted;
 }
 
 void HistoryWidget::clearChangesets()
@@ -62,7 +66,17 @@
 
 void HistoryWidget::showUncommittedChanges(bool show)
 {
-    //!!! implement!
+    QGraphicsScene *scene = m_panned->scene();
+    if (!scene) return;
+
+    if (show) {
+        if (m_uncommitted->scene() == scene) return;
+        scene->addItem(m_uncommitted);
+        m_uncommitted->ensureVisible();
+    } else {
+        if (m_uncommitted->scene() != scene) return;
+        scene->removeItem(m_uncommitted);
+    }
 }
     
 void HistoryWidget::parseNewLog(QString log)
@@ -90,6 +104,7 @@
 void HistoryWidget::layoutAll()
 {
     setChangesetParents();
+    showUncommittedChanges(false); // detach the item from our scene
 
     ChangesetScene *scene = new ChangesetScene();
     ChangesetItem *tipItem = 0;
@@ -146,6 +161,10 @@
                 DEBUG << "id " << id << " is current" << endl;
             }
             csit->setCurrent(current);
+            m_uncommitted->setRow(csit->row() - 1);
+            m_uncommitted->setColumn(csit->column());
+            m_uncommitted->setWide(csit->isWide());
+            m_uncommitted->setBranch(csit->getChangeset()->branch());
         }
     }
 }
--- a/historywidget.h	Mon Nov 29 20:09:58 2010 +0000
+++ b/historywidget.h	Mon Nov 29 20:53:34 2010 +0000
@@ -24,6 +24,7 @@
 
 class Panned;
 class Panner;
+class UncommittedItem;
 
 class HistoryWidget : public QWidget
 {
@@ -42,6 +43,7 @@
 private:
     Changesets m_changesets;
     QStringList m_currentIds;
+    UncommittedItem *m_uncommitted;
 
     Panned *m_panned;
     Panner *m_panner;
--- a/mainwindow.cpp	Mon Nov 29 20:09:58 2010 +0000
+++ b/mainwindow.cpp	Mon Nov 29 20:53:34 2010 +0000
@@ -1246,13 +1246,8 @@
         break;
         
     case ACT_QUERY_PARENTS:
-    {
         foreach (Changeset *cs, currentParents) delete cs;
         currentParents = Changeset::parseChangesets(output);
-        QStringList ids;
-        foreach (Changeset *cs, currentParents) ids.push_back(cs->id());
-        hgTabs->setCurrent(ids);
-    }
         break;
         
     case ACT_QUERY_HEADS:
@@ -1507,6 +1502,11 @@
     hgMergeAct->setEnabled(localRepoActionsEnabled && canMerge);
     hgUpdateAct->setEnabled(localRepoActionsEnabled && canUpdate);
 
+    QStringList ids;
+    foreach (Changeset *cs, currentParents) ids.push_back(cs->id());
+    hgTabs->setCurrent(ids);
+    hgTabs->showUncommittedChanges(hgTabs->canCommit());
+
     // Set the state field on the file status widget
 
     QString branchText;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uncommitteditem.cpp	Mon Nov 29 20:53:34 2010 +0000
@@ -0,0 +1,85 @@
+/* -*- 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 "uncommitteditem.h"
+#include "colourset.h"
+#include "debug.h"
+
+#include <QPainter>
+#include <QGraphicsScene>
+
+UncommittedItem::UncommittedItem() :
+    m_column(0), m_row(0), m_wide(false)
+{
+    m_font = QFont();
+    m_font.setPixelSize(11);
+    m_font.setBold(false);
+    m_font.setItalic(false);
+}
+
+QRectF
+UncommittedItem::boundingRect() const
+{
+    //!!! this stuff is gross, refactor with changesetitem
+    int w = 100;
+    if (m_wide) w = 180;
+    return QRectF(-((w-50)/2 - 1), -30, w - 3, 79);
+}
+
+void
+UncommittedItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *option,
+		       QWidget *w)
+{
+    paint->save();
+    
+    ColourSet *colourSet = ColourSet::instance();
+    QColor branchColour = colourSet->getColourFor(m_branch);
+
+    QFont f(m_font);
+
+    QTransform t = paint->worldTransform();
+    float scale = std::min(t.m11(), t.m22());
+    if (scale > 1.0) {
+	int ps = int((f.pixelSize() / scale) + 0.5);
+	if (ps < 8) ps = 8;
+	f.setPixelSize(ps);
+    }
+
+    if (scale < 0.1) {
+	paint->setPen(QPen(branchColour, 0, Qt::DashLine));
+    } else {
+	paint->setPen(QPen(branchColour, 2, Qt::DashLine));
+    }
+	
+    paint->setFont(f);
+    QFontMetrics fm(f);
+    int fh = fm.height();
+
+    int width = 100;
+    if (m_wide) width = 180;
+    int x0 = -((width - 50) / 2 - 1);
+
+    int height = 49;
+    QRectF r(x0, 0, width - 3, height);
+    paint->drawRect(r);
+
+    QString label = tr("Uncommitted changes");
+    paint->drawText(-(fm.width(label) - 50)/2, 25 - fm.height()/2 + fm.ascent(), label);
+
+    paint->restore();
+    return;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uncommitteditem.h	Mon Nov 29 20:53:34 2010 +0000
@@ -0,0 +1,54 @@
+/* -*- 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 UNCOMMITTEDITEM_H
+#define UNCOMMITTEDITEM_H
+
+#include <QGraphicsItem>
+#include <QFont>
+
+class UncommittedItem : public QObject, public QGraphicsItem
+{
+    Q_OBJECT
+    Q_INTERFACES(QGraphicsItem)
+
+public:
+    UncommittedItem();
+
+    virtual QRectF boundingRect() const;
+    virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
+
+    QString branch() const { return m_branch; }
+    void setBranch(QString b) { m_branch = b; }
+    
+    int column() const { return m_column; }
+    int row() const { return m_row; }
+    void setColumn(int c) { m_column = c; setX(c * 100); }
+    void setRow(int r) { m_row = r; setY(r * 90); }
+
+    bool isWide() const { return m_wide; }
+    void setWide(bool w) { m_wide = w; }
+
+private:
+    QString m_branch;
+    QFont m_font;
+    int m_column;
+    int m_row;
+    bool m_wide;
+};
+
+#endif // UNCOMMITTEDITEM_H