Mercurial > hg > easyhg
changeset 133:aaeab914f2a3
* Better attempt at retaining current visible area when history scene changes; first cut at highlighting new items
author | Chris Cannam |
---|---|
date | Tue, 30 Nov 2010 12:45:34 +0000 |
parents | 16ceeee30e2a |
children | 1208d9688a8f |
files | changesetitem.cpp changesetitem.h historywidget.cpp historywidget.h mainwindow.cpp mainwindow.h panned.cpp panned.h panner.cpp |
diffstat | 9 files changed, 115 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/changesetitem.cpp Tue Nov 30 11:41:46 2010 +0000 +++ b/changesetitem.cpp Tue Nov 30 12:45:34 2010 +0000 @@ -28,7 +28,8 @@ ChangesetItem::ChangesetItem(Changeset *cs) : m_changeset(cs), m_detail(0), - m_showBranch(false), m_column(0), m_row(0), m_wide(false), m_current(false) + m_showBranch(false), m_column(0), m_row(0), m_wide(false), + m_current(false), m_new(false) { m_font = QFont(); m_font.setPixelSize(11); @@ -122,6 +123,13 @@ QRectF r(x0, 0, width - 3, height); paint->drawRect(r); + if (m_new) { + paint->save(); + paint->setPen(Qt::yellow); + paint->drawRect(QRectF(x0 - 2, -2, width + 1, height + 4)); + paint->restore(); + } + if (m_current) { paint->drawRect(QRectF(x0 - 4, -4, width + 5, height + 8)); }
--- a/changesetitem.h Tue Nov 30 11:41:46 2010 +0000 +++ b/changesetitem.h Tue Nov 30 12:45:34 2010 +0000 @@ -48,6 +48,9 @@ bool isCurrent() const { return m_current; } void setCurrent(bool c) { m_current = c; } + bool isNew() const { return m_new; } + void setNew(bool n) { m_new = n; } + bool shouldShowBranch() const { return m_showBranch; } void setShowBranch(bool s) { m_showBranch = s; } @@ -71,6 +74,7 @@ int m_row; bool m_wide; bool m_current; + bool m_new; }; #endif // CHANGESETITEM_H
--- a/historywidget.cpp Tue Nov 30 11:41:46 2010 +0000 +++ b/historywidget.cpp Tue Nov 30 12:45:34 2010 +0000 @@ -60,8 +60,11 @@ { if (m_currentIds == ids) return; DEBUG << "HistoryWidget::setCurrent: " << ids.size() << " ids" << endl; - m_currentIds = ids; - updateCurrentItems(); + m_currentIds.clear(); + foreach (QString id, ids) { + m_currentIds.push_back(id); + } + updateNewAndCurrentItems(); } void HistoryWidget::showUncommittedChanges(bool show) @@ -84,8 +87,7 @@ DEBUG << "HistoryWidget::parseNewLog: log has " << log.length() << " chars" << endl; Changesets csets = Changeset::parseChangesets(log); DEBUG << "HistoryWidget::parseNewLog: log has " << csets.size() << " changesets" << endl; - clearChangesets(); - m_changesets = csets; + replaceChangesets(csets); layoutAll(); } @@ -95,12 +97,47 @@ Changesets csets = Changeset::parseChangesets(log); DEBUG << "HistoryWidget::parseIncrementalLog: log has " << csets.size() << " changesets" << endl; if (!csets.empty()) { - csets << m_changesets; - m_changesets = csets; + addChangesets(csets); layoutAll(); } } +void HistoryWidget::replaceChangesets(Changesets csets) +{ + QSet<QString> oldIds; + foreach (Changeset *cs, m_changesets) { + oldIds.insert(cs->id()); + } + + QSet<QString> newIds; + foreach (Changeset *cs, csets) { + if (!oldIds.contains(cs->id())) { + newIds.insert(cs->id()); + } + } + + if (newIds.size() == csets.size()) { + // completely new set, unrelated to the old: don't mark new + m_newIds.clear(); + } else { + m_newIds = newIds; + } + + clearChangesets(); + m_changesets = csets; +} + +void HistoryWidget::addChangesets(Changesets csets) +{ + m_newIds.clear(); + foreach (Changeset *cs, csets) { + m_newIds.insert(cs->id()); + } + + csets << m_changesets; + m_changesets = csets; +} + void HistoryWidget::layoutAll() { setChangesetParents(); @@ -128,7 +165,7 @@ if (oldScene) delete oldScene; if (tipItem) tipItem->ensureVisible(); - updateCurrentItems(); + updateNewAndCurrentItems(); } void HistoryWidget::setChangesetParents() @@ -147,20 +184,32 @@ } } -void HistoryWidget::updateCurrentItems() +void HistoryWidget::updateNewAndCurrentItems() { QGraphicsScene *scene = m_panned->scene(); if (!scene) return; + QList<QGraphicsItem *> items = scene->items(); foreach (QGraphicsItem *it, items) { + ChangesetItem *csit = dynamic_cast<ChangesetItem *>(it); - if (csit) { - QString id = csit->getChangeset()->id(); - bool current = m_currentIds.contains(id); - if (current) { - DEBUG << "id " << id << " is current" << endl; - } - csit->setCurrent(current); + if (!csit) continue; + + QString id = csit->getChangeset()->id(); + + bool current = m_currentIds.contains(id); + if (current) { + DEBUG << "id " << id << " is current" << endl; + } + bool newid = m_newIds.contains(id); + if (newid) { + DEBUG << "id " << id << " is new" << endl; + } + + csit->setCurrent(current); + csit->setNew(newid); + + if (current) { m_uncommitted->setRow(csit->row() - 1); m_uncommitted->setColumn(csit->column()); m_uncommitted->setWide(csit->isWide()); @@ -168,4 +217,3 @@ } } } -
--- a/historywidget.h Tue Nov 30 11:41:46 2010 +0000 +++ b/historywidget.h Tue Nov 30 12:45:34 2010 +0000 @@ -21,6 +21,7 @@ #include "changeset.h" #include <QWidget> +#include <QSet> class Panned; class Panner; @@ -43,15 +44,18 @@ private: Changesets m_changesets; QStringList m_currentIds; + QSet<QString> m_newIds; UncommittedItem *m_uncommitted; Panned *m_panned; Panner *m_panner; void clearChangesets(); + void replaceChangesets(Changesets); + void addChangesets(Changesets); void layoutAll(); void setChangesetParents(); - void updateCurrentItems(); + void updateNewAndCurrentItems(); }; #endif
--- a/mainwindow.cpp Tue Nov 30 11:41:46 2010 +0000 +++ b/mainwindow.cpp Tue Nov 30 12:45:34 2010 +0000 @@ -46,6 +46,7 @@ QString wndTitle; fsWatcher = 0; + commitsSincePush = 0; createActions(); createMenus();
--- a/mainwindow.h Tue Nov 30 11:41:46 2010 +0000 +++ b/mainwindow.h Tue Nov 30 12:45:34 2010 +0000 @@ -49,6 +49,7 @@ QString currentBranch; Changesets currentHeads; Changesets currentParents; + int commitsSincePush; bool needNewLog; protected:
--- a/panned.cpp Tue Nov 30 11:41:46 2010 +0000 +++ b/panned.cpp Tue Nov 30 12:45:34 2010 +0000 @@ -44,6 +44,32 @@ if (pr != m_pannedRect) { DEBUG << "Panned: setting panned rect to " << pr << endl; m_pannedRect = pr; + centerOn(pr.center()); + emit pannedRectChanged(pr); + } +} + +void +Panned::setScene(QGraphicsScene *s) +{ + if (!scene()) { + QGraphicsView::setScene(s); + return; + } + + QPointF nearpt = mapToScene(0, 0); + QPointF farpt = mapToScene(width(), height()); + QSizeF sz(farpt.x()-nearpt.x(), farpt.y()-nearpt.y()); + QRectF pr(nearpt, sz); + + QGraphicsView::setScene(s); + + DEBUG << "Panned::setScene: pr = " << pr << ", sceneRect = " << sceneRect() << endl; + + if (scene() && sceneRect().intersects(pr)) { + DEBUG << "Panned::setScene: restoring old rect " << pr << endl; + m_pannedRect = pr; + centerOn(pr.center()); emit pannedRectChanged(pr); } } @@ -63,6 +89,7 @@ QRectF pr(nearpt, sz); if (pr != m_pannedRect) { + DEBUG << "Panned::drawForeground: visible rect " << pr << " differs from panned rect " << m_pannedRect << ", updating panned rect" <<endl; if (pr.x() != m_pannedRect.x()) emit pannedContentsScrolled(); m_pannedRect = pr; emit pannedRectChanged(pr);
--- a/panned.h Tue Nov 30 11:41:46 2010 +0000 +++ b/panned.h Tue Nov 30 12:45:34 2010 +0000 @@ -31,6 +31,8 @@ Panned(); virtual ~Panned() { } + virtual void setScene(QGraphicsScene *s); + signals: void pannedRectChanged(QRectF); void wheelEventReceived(QWheelEvent *);
--- a/panner.cpp Tue Nov 30 11:41:46 2010 +0000 +++ b/panner.cpp Tue Nov 30 12:45:34 2010 +0000 @@ -66,7 +66,7 @@ Panner::setScene(QGraphicsScene *s) { if (scene()) { - disconnect(scene(), SIGNAL(sceneChanged(const QList<QRectF> &)), + disconnect(scene(), SIGNAL(changed(const QList<QRectF> &)), this, SLOT(slotSceneChanged(const QList<QRectF> &))); disconnect(scene(), SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(slotSceneRectChanged(const QRectF &))); @@ -78,7 +78,7 @@ fit(r); } m_cache = QPixmap(); - connect(scene(), SIGNAL(sceneChanged(const QList<QRectF> &)), + connect(scene(), SIGNAL(changed(const QList<QRectF> &)), this, SLOT(slotSceneChanged(const QList<QRectF> &))); connect(scene(), SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(slotSceneRectChanged(const QRectF &)));