comparison src/annotatedialog.cpp @ 370:b9c153e00e84

Move source files to src/
author Chris Cannam
date Thu, 24 Mar 2011 10:27:51 +0000
parents annotatedialog.cpp@70ad221e1619
children 533519ebc0cb
comparison
equal deleted inserted replaced
369:19cce6d2c470 370:b9c153e00e84
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 EasyMercurial
5
6 Based on hgExplorer by Jari Korhonen
7 Copyright (c) 2010 Jari Korhonen
8 Copyright (c) 2011 Chris Cannam
9 Copyright (c) 2011 Queen Mary, University of London
10
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version. See the file
15 COPYING included with this distribution for more information.
16 */
17
18 #include "annotatedialog.h"
19 #include "common.h"
20 #include "colourset.h"
21 #include "debug.h"
22
23 #include <QDialogButtonBox>
24 #include <QLabel>
25 #include <QTableWidget>
26 #include <QHeaderView>
27 #include <QGridLayout>
28
29 AnnotateDialog::AnnotateDialog(QWidget *w, QString text) :
30 QDialog(w)
31 {
32 setMinimumWidth(800);
33 setMinimumHeight(500);
34
35 text.replace("\r\n", "\n");
36 QStringList lines = text.split("\n");
37
38 QGridLayout *layout = new QGridLayout;
39 QTableWidget *table = new QTableWidget;
40
41 QRegExp annotateLineRE = QRegExp("^([^:]+) ([a-z0-9]{12}) ([0-9-]+): (.*)$");
42
43 table->setRowCount(lines.size());
44 table->setColumnCount(4);
45 table->horizontalHeader()->setStretchLastSection(true);
46 table->verticalHeader()->setDefaultSectionSize
47 (table->verticalHeader()->fontMetrics().height() + 2);
48
49 QStringList labels;
50 labels << tr("User") << tr("Revision") << tr("Date") << tr("Content");
51 table->setHorizontalHeaderLabels(labels);
52
53 table->setShowGrid(false);
54
55 QFont monofont("Monospace");
56 monofont.setStyleHint(QFont::TypeWriter);
57
58 int row = 0;
59
60 foreach (QString line, lines) {
61 if (annotateLineRE.indexIn(line) == 0) {
62 QStringList items = annotateLineRE.capturedTexts();
63 QString id = items[2];
64 QColor colour = ColourSet::instance()->getColourFor(id);
65 QColor bg = QColor::fromHsv(colour.hue(),
66 30,
67 230);
68 // note items[0] is the whole match, so we want 1-4
69 for (int col = 0; col+1 < items.size(); ++col) {
70 QString item = items[col+1];
71 if (col == 0) item = item.trimmed();
72 QTableWidgetItem *wi = new QTableWidgetItem(item);
73 wi->setFlags(Qt::ItemIsEnabled);
74 wi->setBackground(bg);
75 if (col == 3) { // id, content
76 wi->setFont(monofont);
77 }
78 table->setItem(row, col, wi);
79 }
80 } else {
81 DEBUG << "AnnotateDialog: Failed to match RE in line: " << line << " at row " << row << endl;
82 }
83 ++row;
84 }
85
86 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok);
87 connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
88
89 layout->addWidget(table, 0, 0);
90 layout->addWidget(bb, 1, 0);
91
92 setLayout(layout);
93 }
94