# HG changeset patch # User Chris Cannam # Date 1291121134 0 # Node ID aaeab914f2a334d58826a6710b6d45a6804d28fe # Parent 16ceeee30e2ae80a40e51a3ef883dc1e830a0c94 * Better attempt at retaining current visible area when history scene changes; first cut at highlighting new items diff -r 16ceeee30e2a -r aaeab914f2a3 changesetitem.cpp --- 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)); } diff -r 16ceeee30e2a -r aaeab914f2a3 changesetitem.h --- 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 diff -r 16ceeee30e2a -r aaeab914f2a3 historywidget.cpp --- 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 oldIds; + foreach (Changeset *cs, m_changesets) { + oldIds.insert(cs->id()); + } + + QSet 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 items = scene->items(); foreach (QGraphicsItem *it, items) { + ChangesetItem *csit = dynamic_cast(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 @@ } } } - diff -r 16ceeee30e2a -r aaeab914f2a3 historywidget.h --- 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 +#include class Panned; class Panner; @@ -43,15 +44,18 @@ private: Changesets m_changesets; QStringList m_currentIds; + QSet 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 diff -r 16ceeee30e2a -r aaeab914f2a3 mainwindow.cpp --- 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(); diff -r 16ceeee30e2a -r aaeab914f2a3 mainwindow.h --- 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: diff -r 16ceeee30e2a -r aaeab914f2a3 panned.cpp --- 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" < &)), + disconnect(scene(), SIGNAL(changed(const QList &)), this, SLOT(slotSceneChanged(const QList &))); 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 &)), + connect(scene(), SIGNAL(changed(const QList &)), this, SLOT(slotSceneChanged(const QList &))); connect(scene(), SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(slotSceneRectChanged(const QRectF &)));