Menu item "Checkout" spawns a dialog, thus requires ellipsis
[qgit4/redivivus.git] / src / revdesc.cpp
blobe1dcd15c3a250e92e29cea3152e05bd1954613e4
1 /*
2 Author: Marco Costalba (C) 2005-2007
4 Copyright: See COPYING file that comes with this distribution
5 */
6 #include <QApplication>
7 #include <QMenu>
8 #include <QContextMenuEvent>
9 #include <QRegExp>
10 #include <QClipboard>
11 #include "domain.h"
12 #include "revdesc.h"
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());
30 UPDATE_DOMAIN(d);
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());
53 delete menu;