2 Author: Marco Costalba (C) 2005-2007
4 Copyright: See COPYING file that comes with this distribution
6 #include <QApplication>
8 #include <QContextMenuEvent>
14 RevDesc::RevDesc(QWidget
* p
) : QTextBrowser(p
), d(NULL
) {
16 connect(this, SIGNAL(anchorClicked(const QUrl
&)),
17 this, SLOT(on_anchorClicked(const QUrl
&)));
19 connect(this, SIGNAL(highlighted(const QUrl
&)),
20 this, SLOT(on_highlighted(const QUrl
&)));
23 void RevDesc::on_anchorClicked(const QUrl
& link
) {
25 QRegExp
re("[0-9a-f]{40}", Qt::CaseInsensitive
);
26 if (re
.exactMatch(link
.toString())) {
28 setSource(QUrl()); // override default navigation behavior
29 d
->st
.setSha(link
.toString());
34 void RevDesc::on_highlighted(const QUrl
& link
) {
36 highlightedLink
= link
.toString();
39 void RevDesc::on_linkCopy() {
41 QClipboard
* cb
= QApplication::clipboard();
42 cb
->setText(highlightedLink
);
45 void RevDesc::contextMenuEvent(QContextMenuEvent
* e
) {
47 QMenu
* menu
= createStandardContextMenu();
48 if (!highlightedLink
.isEmpty()) {
49 QAction
* act
= menu
->addAction("Copy link SHA1");
50 connect(act
, SIGNAL(triggered()), this, SLOT(on_linkCopy()));
52 menu
->exec(e
->globalPos());