annotate src/annotatedialog.cpp @ 676:cb4f7c3c01dd

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