diff hgexpwidget.cpp @ 32:4f307720272f

Version 0.5.0: Added "Copy comment" context menu to "parents" list.
author Jari Korhonen <jtkorhonen@gmail.com>
date Tue, 15 Jun 2010 03:16:40 +0300
parents 45bfb8dc1faf
children c32067cd19f8
line wrap: on
line diff
--- a/hgexpwidget.cpp	Mon Jun 14 22:04:52 2010 +0300
+++ b/hgexpwidget.cpp	Tue Jun 15 03:16:40 2010 +0300
@@ -3,6 +3,8 @@
 ****************************************************************************/
 
 #include <QtGui>
+#include <QtCore>
+#include <QClipboard>
 
 #include "hgexpwidget.h"
 #include "common.h"
@@ -42,6 +44,10 @@
     parentsLayout -> addWidget(parentsLabel);
     parentsLayout -> addWidget(localRepoHgParentsList);
     grpLocalRepo -> setLayout(parentsLayout);
+    copyCommentAct = new QAction("Copy comment", localRepoHgParentsList);
+    userListMenu = new QMenu(localRepoHgParentsList);
+    userListMenu -> addAction(copyCommentAct);
+    connect(copyCommentAct, SIGNAL(triggered()), this, SLOT(copyComment()));
 
     //Workfolder
     grpWorkFolder = new QGroupBox(tr(WORKFOLDER_STR) + workFolderPath);
@@ -106,6 +112,49 @@
     setTabEnabled(HISTORYTAB, false);
 }
 
+void HgExpWidget::contextMenuEvent(QContextMenuEvent * event)
+{
+    if (copyCommentAct -> isEnabled())
+    {
+        QPoint topL;
+        QPoint bottomR;
+
+        topL = localRepoHgParentsList->
+            mapToGlobal(QPoint(0, 0));
+        bottomR = localRepoHgParentsList->
+            mapToGlobal(QPoint(localRepoHgParentsList -> width(), localRepoHgParentsList -> height()));
+
+        if ((event -> globalPos().x() > topL.x()) && (event -> globalPos().x() < bottomR.x()))
+        {
+            if ((event -> globalPos().y() > topL.y()) && (event -> globalPos().y() < bottomR.y()))
+            {
+                userListMenu->exec(event -> globalPos());
+            }
+        }
+    }
+}
+
+void HgExpWidget::copyComment()
+{
+    if (localRepoHgParentsList -> count() >= 1)
+    {
+        QListWidgetItem *it =  localRepoHgParentsList -> item(0);
+        QString tmp = it -> text();
+        int ind = tmp.indexOf("summary:");
+        if (ind != -1)
+        {
+            QString comment;
+            ind += 11;   //jump over word "summary:"
+
+            comment = tmp.mid(ind);
+
+            QClipboard *clipboard = QApplication::clipboard();
+            clipboard->setText(comment);
+        }
+    }
+}
+
+
 
 QString HgExpWidget::getStatFlags()
 {
@@ -353,9 +402,23 @@
 }
 
 
+void HgExpWidget::enableDisableOtherTabs(int tabPage)
+{
+    static int oldTabPage = -1;
 
-void HgExpWidget::enableDisableOtherTabs()
-{
+    if  (tabPage != oldTabPage)
+    {
+        oldTabPage = tabPage;
+        if (tabPage == WORKTAB)
+        {
+            copyCommentAct -> setEnabled(true);
+        }
+        else
+        {
+            copyCommentAct -> setEnabled(false);
+        }
+    }
+
     //history list is only interesting when we have something in it ;-)
     if (localRepoHgLogList -> count() < 2)
     {