00001
00002
00003
00004
00005
00006 #include <qapplication.h>
00007 #include <qregexp.h>
00008 #include <qpopupmenu.h>
00009 #include <qclipboard.h>
00010 #include <qaction.h>
00011 #include "common.h"
00012 #include "domain.h"
00013 #include "revdesc.h"
00014
00015 RevDesc::RevDesc(QWidget* p, const char* n) : QTextBrowser(p, n), d(NULL) {
00016
00017 setTextFormat(Qt::RichText);
00018
00019 connect(this, SIGNAL(linkClicked(const QString&)),
00020 this, SLOT(on_linkClicked(const QString&)));
00021
00022 connect(this, SIGNAL(highlighted(const QString&)),
00023 this, SLOT(on_highlighted(const QString&)));
00024 }
00025
00026 void RevDesc::on_linkClicked(const QString& link) {
00027
00028 QRegExp reSHA("[0-9a-f]{40}", false);
00029 if (link.find(reSHA) != -1) {
00030
00031 setText(text());
00032 d->st.setSha(link);
00033 UPDATE_DOMAIN(d);
00034 }
00035 }
00036
00037 void RevDesc::on_highlighted(const QString& link) {
00038
00039 highlightedLink = link;
00040 }
00041
00042 QPopupMenu* RevDesc::createPopupMenu(const QPoint& pos) {
00043
00044 QPopupMenu* popup = QTextBrowser::createPopupMenu(pos);
00045
00046 if (highlightedLink.isEmpty())
00047 return popup;
00048
00049 QAction* act = new QAction("Copy link sha1", 0, popup);
00050 connect(act, SIGNAL(activated()), this, SLOT(on_linkCopy()));
00051 act->addTo(popup);
00052 return popup;
00053 }
00054
00055 void RevDesc::on_linkCopy() {
00056
00057 QClipboard* cb = QApplication::clipboard();
00058 cb->setText(highlightedLink, QClipboard::Clipboard);
00059 }