comparison 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
comparison
equal deleted inserted replaced
31:552a49635124 32:4f307720272f
1 /**************************************************************************** 1 /****************************************************************************
2 ** Copyright (C) Jari Korhonen, 2010 (under lgpl) 2 ** Copyright (C) Jari Korhonen, 2010 (under lgpl)
3 ****************************************************************************/ 3 ****************************************************************************/
4 4
5 #include <QtGui> 5 #include <QtGui>
6 #include <QtCore>
7 #include <QClipboard>
6 8
7 #include "hgexpwidget.h" 9 #include "hgexpwidget.h"
8 #include "common.h" 10 #include "common.h"
9 11
10 #define REMOTE_REPO_STR "Remote repository: " 12 #define REMOTE_REPO_STR "Remote repository: "
40 localRepoHgParentsList -> setSelectionMode(QAbstractItemView::NoSelection); 42 localRepoHgParentsList -> setSelectionMode(QAbstractItemView::NoSelection);
41 parentsLayout = new QVBoxLayout; 43 parentsLayout = new QVBoxLayout;
42 parentsLayout -> addWidget(parentsLabel); 44 parentsLayout -> addWidget(parentsLabel);
43 parentsLayout -> addWidget(localRepoHgParentsList); 45 parentsLayout -> addWidget(localRepoHgParentsList);
44 grpLocalRepo -> setLayout(parentsLayout); 46 grpLocalRepo -> setLayout(parentsLayout);
47 copyCommentAct = new QAction("Copy comment", localRepoHgParentsList);
48 userListMenu = new QMenu(localRepoHgParentsList);
49 userListMenu -> addAction(copyCommentAct);
50 connect(copyCommentAct, SIGNAL(triggered()), this, SLOT(copyComment()));
45 51
46 //Workfolder 52 //Workfolder
47 grpWorkFolder = new QGroupBox(tr(WORKFOLDER_STR) + workFolderPath); 53 grpWorkFolder = new QGroupBox(tr(WORKFOLDER_STR) + workFolderPath);
48 workFolderLayout = new QHBoxLayout; 54 workFolderLayout = new QHBoxLayout;
49 workFolderFileList = new QListWidget; 55 workFolderFileList = new QListWidget;
104 //Initially, only work page is active 110 //Initially, only work page is active
105 setTabEnabled(HEADSTAB, false); 111 setTabEnabled(HEADSTAB, false);
106 setTabEnabled(HISTORYTAB, false); 112 setTabEnabled(HISTORYTAB, false);
107 } 113 }
108 114
115 void HgExpWidget::contextMenuEvent(QContextMenuEvent * event)
116 {
117 if (copyCommentAct -> isEnabled())
118 {
119 QPoint topL;
120 QPoint bottomR;
121
122 topL = localRepoHgParentsList->
123 mapToGlobal(QPoint(0, 0));
124 bottomR = localRepoHgParentsList->
125 mapToGlobal(QPoint(localRepoHgParentsList -> width(), localRepoHgParentsList -> height()));
126
127 if ((event -> globalPos().x() > topL.x()) && (event -> globalPos().x() < bottomR.x()))
128 {
129 if ((event -> globalPos().y() > topL.y()) && (event -> globalPos().y() < bottomR.y()))
130 {
131 userListMenu->exec(event -> globalPos());
132 }
133 }
134 }
135 }
136
137 void HgExpWidget::copyComment()
138 {
139 if (localRepoHgParentsList -> count() >= 1)
140 {
141 QListWidgetItem *it = localRepoHgParentsList -> item(0);
142 QString tmp = it -> text();
143 int ind = tmp.indexOf("summary:");
144 if (ind != -1)
145 {
146 QString comment;
147 ind += 11; //jump over word "summary:"
148
149 comment = tmp.mid(ind);
150
151 QClipboard *clipboard = QApplication::clipboard();
152 clipboard->setText(comment);
153 }
154 }
155 }
156
157
109 158
110 QString HgExpWidget::getStatFlags() 159 QString HgExpWidget::getStatFlags()
111 { 160 {
112 QString ret; 161 QString ret;
113 162
351 rev = ""; 400 rev = "";
352 } 401 }
353 } 402 }
354 403
355 404
356 405 void HgExpWidget::enableDisableOtherTabs(int tabPage)
357 void HgExpWidget::enableDisableOtherTabs() 406 {
358 { 407 static int oldTabPage = -1;
408
409 if (tabPage != oldTabPage)
410 {
411 oldTabPage = tabPage;
412 if (tabPage == WORKTAB)
413 {
414 copyCommentAct -> setEnabled(true);
415 }
416 else
417 {
418 copyCommentAct -> setEnabled(false);
419 }
420 }
421
359 //history list is only interesting when we have something in it ;-) 422 //history list is only interesting when we have something in it ;-)
360 if (localRepoHgLogList -> count() < 2) 423 if (localRepoHgLogList -> count() < 2)
361 { 424 {
362 setTabEnabled(HISTORYTAB, false); 425 setTabEnabled(HISTORYTAB, false);
363 } 426 }