Mercurial > hg > easyhg
changeset 117:d5db15bf250c
* Start to sketch thing that shows the details of a changeset in the history view
author | Chris Cannam |
---|---|
date | Fri, 26 Nov 2010 22:46:29 +0000 |
parents | 807c79350bf1 |
children | 9734fb0d6fff |
files | changesetdetailitem.cpp changesetdetailitem.h changesetitem.cpp changesetitem.h easyhg.pro hgrunner.h hgtabwidget.cpp |
diffstat | 7 files changed, 199 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/changesetdetailitem.cpp Fri Nov 26 22:46:29 2010 +0000 @@ -0,0 +1,130 @@ +/* -*- 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 "changesetdetailitem.h" +#include "changeset.h" +#include "textabbrev.h" +#include "colourset.h" +#include "debug.h" + +#include <QPainter> + +ChangesetDetailItem::ChangesetDetailItem(Changeset *cs) : + m_changeset(cs) +{ + m_font = QFont(); + m_font.setPixelSize(11); + m_font.setBold(false); + m_font.setItalic(false); +} + +QRectF +ChangesetDetailItem::boundingRect() const +{ + return QRectF(0, 0, 350, 200); +} + +void +ChangesetDetailItem::paint(QPainter *paint, + const QStyleOptionGraphicsItem *option, + QWidget *w) +{ + paint->save(); + + ColourSet *colourSet = ColourSet::instance(); + QColor branchColour = colourSet->getColourFor(m_changeset->branch()); + QColor userColour = colourSet->getColourFor(m_changeset->author()); + + 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)); + } else { + paint->setPen(QPen(branchColour, 2)); + } + + paint->setFont(f); + QFontMetrics fm(f); + int fh = fm.height(); + + int width = 350; + int height = 200; + + QRectF r(0.5, 0.5, width - 1, height - 1); + paint->setBrush(Qt::white); + paint->drawRect(r); + + if (scale < 0.1) { + paint->restore(); + return; + } +/* + paint->fillRect(QRectF(x0 + 0.5, 0.5, width - 4, fh - 0.5), + QBrush(userColour)); + + paint->setPen(QPen(Qt::white)); + + int wid = width - 5; + QString person = TextAbbrev::abbreviate(m_changeset->authorName(), fm, wid); + paint->drawText(x0 + 3, fm.ascent(), person); + + paint->setPen(QPen(Qt::black)); + + if (m_showBranch) { + // write branch name + f.setBold(true); + paint->setFont(f); + QString branch = m_changeset->branch(); + if (branch == "") branch = "default"; + int wid = width - 3; + branch = TextAbbrev::abbreviate(branch, QFontMetrics(f), wid); + paint->drawText(x0, -fh + fm.ascent() - 4, branch); + f.setBold(false); + } + +// f.setItalic(true); + fm = QFontMetrics(f); + fh = fm.height(); + paint->setFont(f); + + QString comment = m_changeset->comment().trimmed(); + comment = comment.replace("\\n", " "); + comment = comment.replace(QRegExp("^\"\\s*\\**\\s*"), ""); + comment = comment.replace(QRegExp("\"$"), ""); + comment = comment.replace("\\\"", "\""); + + wid = width - 5; + int nlines = (height / fh) - 1; + if (nlines < 1) nlines = 1; + comment = TextAbbrev::abbreviate(comment, fm, wid, TextAbbrev::ElideEnd, + "...", nlines); + + QStringList lines = comment.split('\n'); + for (int i = 0; i < lines.size(); ++i) { + paint->drawText(x0 + 3, i * fh + fh + fm.ascent(), lines[i].trimmed()); + } + */ + paint->restore(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/changesetdetailitem.h Fri Nov 26 22:46:29 2010 +0000 @@ -0,0 +1,41 @@ +/* -*- 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 CHANGESETDETAILITEM_H +#define CHANGESETDETAILITEM_H + +#include <QGraphicsItem> +#include <QFont> + +class Changeset; + +class ChangesetDetailItem : public QGraphicsItem +{ +public: + ChangesetDetailItem(Changeset *cs); + + virtual QRectF boundingRect() const; + virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + + Changeset *getChangeset() { return m_changeset; } + +private: + QFont m_font; + Changeset *m_changeset; +}; + +#endif // CHANGESETDETAILITEM_H
--- a/changesetitem.cpp Fri Nov 26 22:06:52 2010 +0000 +++ b/changesetitem.cpp Fri Nov 26 22:46:29 2010 +0000 @@ -16,14 +16,18 @@ */ #include "changesetitem.h" +#include "changesetdetailitem.h" #include "changeset.h" #include "textabbrev.h" #include "colourset.h" +#include "debug.h" #include <QPainter> +#include <QGraphicsScene> ChangesetItem::ChangesetItem(Changeset *cs) : - m_changeset(cs), m_showBranch(false), m_column(0), m_row(0), m_wide(false) + m_changeset(cs), m_detail(0), + m_showBranch(false), m_column(0), m_row(0), m_wide(false) { m_font = QFont(); m_font.setPixelSize(11); @@ -40,6 +44,21 @@ } void +ChangesetItem::mousePressEvent(QGraphicsSceneMouseEvent *e) +{ + DEBUG << "ChangesetItem::mousePressEvent" << endl; + //!!! how best to handle this? + if (m_detail) return; + m_detail = new ChangesetDetailItem(m_changeset); + m_detail->setZValue(zValue() + 1); + scene()->addItem(m_detail); + int w = 100; + if (m_wide) w = 180; + m_detail->moveBy(x() - (m_detail->boundingRect().width() - 50) / 2, + y() + 60); +} + +void ChangesetItem::paint(QPainter *paint, const QStyleOptionGraphicsItem *option, QWidget *w) {
--- a/changesetitem.h Fri Nov 26 22:06:52 2010 +0000 +++ b/changesetitem.h Fri Nov 26 22:46:29 2010 +0000 @@ -22,6 +22,7 @@ #include <QFont> class Changeset; +class ChangesetDetailItem; class ChangesetItem : public QGraphicsItem { @@ -44,9 +45,13 @@ bool shouldShowBranch() const { return m_showBranch; } void setShowBranch(bool s) { m_showBranch = s; } +protected: + virtual void mousePressEvent(QGraphicsSceneMouseEvent *); + private: QFont m_font; Changeset *m_changeset; + ChangesetDetailItem *m_detail; bool m_showBranch; int m_column; int m_row;
--- a/easyhg.pro Fri Nov 26 22:06:52 2010 +0000 +++ b/easyhg.pro Fri Nov 26 22:46:29 2010 +0000 @@ -17,6 +17,7 @@ hgrunner.h \ changeset.h \ changesetitem.h \ + changesetdetailitem.h \ logparser.h \ panner.h \ panned.h \ @@ -42,6 +43,7 @@ grapher.cpp \ common.cpp \ changeset.cpp \ + changesetdetailitem.cpp \ changesetitem.cpp \ logparser.cpp \ panner.cpp \
--- a/hgrunner.h Fri Nov 26 22:06:52 2010 +0000 +++ b/hgrunner.h Fri Nov 26 22:46:29 2010 +0000 @@ -37,12 +37,7 @@ ~HgRunner(); void requestAction(HgAction action); -/*!!! - bool isCommandRunning(); - void killCurrentCommand(); - void hideProgBar(); -*/ signals: void commandCompleted(HgAction action, QString stdout); void commandFailed(HgAction action, QString stderr);
--- a/hgtabwidget.cpp Fri Nov 26 22:06:52 2010 +0000 +++ b/hgtabwidget.cpp Fri Nov 26 22:46:29 2010 +0000 @@ -29,7 +29,7 @@ HgTabWidget::HgTabWidget(QWidget *parent, QString remoteRepo, QString workFolderPath) : -QTabWidget(parent) + QTabWidget(parent) { // Work page m_fileStatusWidget = new FileStatusWidget;