comparison annotatedialog.cpp @ 332:70ad221e1619

Improve the Annotate output
author Chris Cannam
date Sun, 13 Mar 2011 10:59:34 +0000
parents acfe9390d5c6
children
comparison
equal deleted inserted replaced
331:acfe9390d5c6 332:70ad221e1619
15 COPYING included with this distribution for more information. 15 COPYING included with this distribution for more information.
16 */ 16 */
17 17
18 #include "annotatedialog.h" 18 #include "annotatedialog.h"
19 #include "common.h" 19 #include "common.h"
20 #include "colourset.h"
20 #include "debug.h" 21 #include "debug.h"
21 22
22 #include <QDialogButtonBox> 23 #include <QDialogButtonBox>
23 #include <QLabel> 24 #include <QLabel>
24 #include <QTableWidget> 25 #include <QTableWidget>
26 #include <QGridLayout> 27 #include <QGridLayout>
27 28
28 AnnotateDialog::AnnotateDialog(QWidget *w, QString text) : 29 AnnotateDialog::AnnotateDialog(QWidget *w, QString text) :
29 QDialog(w) 30 QDialog(w)
30 { 31 {
31 setMinimumWidth(600); 32 setMinimumWidth(800);
32 setMinimumHeight(700); 33 setMinimumHeight(500);
33 34
34 text.replace("\r\n", "\n"); 35 text.replace("\r\n", "\n");
35 QStringList lines = text.split("\n"); 36 QStringList lines = text.split("\n");
36 37
37 QGridLayout *layout = new QGridLayout; 38 QGridLayout *layout = new QGridLayout;
40 QRegExp annotateLineRE = QRegExp("^([^:]+) ([a-z0-9]{12}) ([0-9-]+): (.*)$"); 41 QRegExp annotateLineRE = QRegExp("^([^:]+) ([a-z0-9]{12}) ([0-9-]+): (.*)$");
41 42
42 table->setRowCount(lines.size()); 43 table->setRowCount(lines.size());
43 table->setColumnCount(4); 44 table->setColumnCount(4);
44 table->horizontalHeader()->setStretchLastSection(true); 45 table->horizontalHeader()->setStretchLastSection(true);
46 table->verticalHeader()->setDefaultSectionSize
47 (table->verticalHeader()->fontMetrics().height() + 2);
45 48
46 QStringList labels; 49 QStringList labels;
47 labels << tr("User") << tr("Revision") << tr("Date") << tr("Content"); 50 labels << tr("User") << tr("Revision") << tr("Date") << tr("Content");
48 table->setHorizontalHeaderLabels(labels); 51 table->setHorizontalHeaderLabels(labels);
52
53 table->setShowGrid(false);
54
55 QFont monofont("Monospace");
56 monofont.setStyleHint(QFont::TypeWriter);
49 57
50 int row = 0; 58 int row = 0;
51 59
52 foreach (QString line, lines) { 60 foreach (QString line, lines) {
53 if (annotateLineRE.indexIn(line) == 0) { 61 if (annotateLineRE.indexIn(line) == 0) {
54 QStringList items = annotateLineRE.capturedTexts(); 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);
55 // note items[0] is the whole match, so we want 1-4 68 // note items[0] is the whole match, so we want 1-4
56 for (int col = 0; col+1 < items.size(); ++col) { 69 for (int col = 0; col+1 < items.size(); ++col) {
57 std::cerr << "row " << row << " col " << col << " text " 70 QString item = items[col+1];
58 << items[col+1] << std::endl; 71 if (col == 0) item = item.trimmed();
59 table->setItem(row, col, new QTableWidgetItem(items[col+1])); 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);
60 } 79 }
61 } else { 80 } else {
62 DEBUG << "AnnotateDialog: Failed to match RE in line: " << line << " at row " << row << endl; 81 DEBUG << "AnnotateDialog: Failed to match RE in line: " << line << " at row " << row << endl;
63 } 82 }
64 ++row; 83 ++row;