comparison filestatuswidget.cpp @ 115:78374cefa10f

* Add useful state message to file status page. Also add shouldBeFast() method to HgAction; use it to avoid showing progress bar for fast actions
author Chris Cannam
date Fri, 26 Nov 2010 21:48:25 +0000
parents 1721c580c10e
children 9734fb0d6fff
comparison
equal deleted inserted replaced
114:bb2d2eecdd60 115:78374cefa10f
14 License, or (at your option) any later version. See the file 14 License, or (at your option) any later version. See the file
15 COPYING included with this distribution for more information. 15 COPYING included with this distribution for more information.
16 */ 16 */
17 17
18 #include "filestatuswidget.h" 18 #include "filestatuswidget.h"
19 #include "debug.h"
20 #include "multichoicedialog.h"
19 21
20 #include <QLabel> 22 #include <QLabel>
21 #include <QListWidget> 23 #include <QListWidget>
22 #include <QGridLayout> 24 #include <QGridLayout>
23 #include <QFileInfo> 25 #include <QFileInfo>
24 #include <QApplication> 26 #include <QApplication>
25 #include <QDateTime> 27 #include <QDateTime>
26 28 #include <QPushButton>
27 #include "debug.h"
28 29
29 FileStatusWidget::FileStatusWidget(QWidget *parent) : 30 FileStatusWidget::FileStatusWidget(QWidget *parent) :
30 QWidget(parent), 31 QWidget(parent),
31 m_dateReference(0) 32 m_dateReference(0)
32 { 33 {
33 QGridLayout *layout = new QGridLayout; 34 QGridLayout *layout = new QGridLayout;
34 setLayout(layout); 35 setLayout(layout);
35 36
36 int row = 0; 37 int row = 0;
37 38
39 layout->addItem(new QSpacerItem(1, 1), row, 0);
40
41 ++row;
38 layout->addWidget(new QLabel(tr("Local:")), row, 0); 42 layout->addWidget(new QLabel(tr("Local:")), row, 0);
39 m_localPathLabel = new QLabel; 43 m_localPathLabel = new QLabel;
40 QFont f(m_localPathLabel->font()); 44 QFont f(m_localPathLabel->font());
41 f.setBold(true); 45 f.setBold(true);
42 m_localPathLabel->setFont(f); 46 m_localPathLabel->setFont(f);
46 layout->addWidget(new QLabel(tr("Remote:")), row, 0); 50 layout->addWidget(new QLabel(tr("Remote:")), row, 0);
47 m_remoteURLLabel = new QLabel; 51 m_remoteURLLabel = new QLabel;
48 layout->addWidget(m_remoteURLLabel, row, 1); 52 layout->addWidget(m_remoteURLLabel, row, 1);
49 53
50 ++row; 54 ++row;
51 layout->addWidget(new QLabel(tr("Branch:")), row, 0); 55 layout->addWidget(new QLabel(tr("State:")), row, 0);
52 m_branchLabel = new QLabel; 56 m_stateLabel = new QLabel;
53 layout->addWidget(m_branchLabel, row, 1); 57 layout->addWidget(m_stateLabel, row, 1, 1, 2);
54 58
55 layout->setColumnStretch(1, 20); 59 layout->setColumnStretch(1, 20);
56 60
57 layout->addWidget(new QLabel("<qt><hr></qt>"), ++row, 0, 1, 2); 61 layout->addWidget(new QLabel("<qt><hr></qt>"), ++row, 0, 1, 3);
62
63 ++row;
64 m_noModificationsLabel = new QLabel
65 (tr("You have made no changes."));
66 layout->addWidget(m_noModificationsLabel, row, 1, 1, 2);
58 67
59 m_simpleLabels[FileStates::Clean] = tr("Unmodified:"); 68 m_simpleLabels[FileStates::Clean] = tr("Unmodified:");
60 m_simpleLabels[FileStates::Modified] = tr("Modified:"); 69 m_simpleLabels[FileStates::Modified] = tr("Modified:");
61 m_simpleLabels[FileStates::Added] = tr("Added:"); 70 m_simpleLabels[FileStates::Added] = tr("Added:");
62 m_simpleLabels[FileStates::Removed] = tr("Removed:"); 71 m_simpleLabels[FileStates::Removed] = tr("Removed:");
97 boxlayout->addWidget(w, 2, 0); 106 boxlayout->addWidget(w, 2, 0);
98 107
99 connect(w, SIGNAL(itemSelectionChanged()), 108 connect(w, SIGNAL(itemSelectionChanged()),
100 this, SLOT(itemSelectionChanged())); 109 this, SLOT(itemSelectionChanged()));
101 110
102 layout->addWidget(box, ++row, 0, 1, 2); 111 layout->addWidget(box, ++row, 0, 1, 3);
103 box->hide(); 112 box->hide();
104 } 113 }
105 114
106 layout->setRowStretch(++row, 20); 115 layout->setRowStretch(++row, 20);
107 } 116 }
301 m_fileStates = p; 310 m_fileStates = p;
302 updateWidgets(); 311 updateWidgets();
303 } 312 }
304 313
305 void 314 void
306 FileStatusWidget::setBranch(QString b) 315 FileStatusWidget::setState(QString b)
307 { 316 {
308 m_branch = b; 317 m_state = b;
309 m_branchLabel->setText(b); 318 updateStateLabel();
310 } 319 }
311 320
312 void 321 void
313 FileStatusWidget::updateWidgets() 322 FileStatusWidget::updateWidgets()
314 { 323 {
318 DEBUG << "reference time: " << lastInteractionTime << endl; 327 DEBUG << "reference time: " << lastInteractionTime << endl;
319 } 328 }
320 329
321 QSet<QString> selectedFiles; 330 QSet<QString> selectedFiles;
322 foreach (QString f, m_selectedFiles) selectedFiles.insert(f); 331 foreach (QString f, m_selectedFiles) selectedFiles.insert(f);
332
333 bool haveAnything = false;
323 334
324 foreach (FileStates::State s, m_stateListMap.keys()) { 335 foreach (FileStates::State s, m_stateListMap.keys()) {
325 336
326 QListWidget *w = m_stateListMap[s]; 337 QListWidget *w = m_stateListMap[s];
327 w->clear(); 338 w->clear();
366 item->setSelected(selectedFiles.contains(file)); 377 item->setSelected(selectedFiles.contains(file));
367 } 378 }
368 379
369 setLabelFor(w, s, !highPriority.empty()); 380 setLabelFor(w, s, !highPriority.empty());
370 381
371 w->parentWidget()->setVisible(!files.empty()); 382 if (files.empty()) {
372 } 383 w->parentWidget()->hide();
384 } else {
385 w->parentWidget()->show();
386 haveAnything = true;
387 }
388 }
389
390 m_noModificationsLabel->setVisible(!haveAnything);
391
392 updateStateLabel();
373 } 393 }
374 394
375 void FileStatusWidget::setLabelFor(QWidget *w, FileStates::State s, bool addHighlight) 395 void FileStatusWidget::setLabelFor(QWidget *w, FileStates::State s, bool addHighlight)
376 { 396 {
377 QString text = labelFor(s, addHighlight); 397 QString text = labelFor(s, addHighlight);
378 QWidget *p = w->parentWidget(); 398 QWidget *p = w->parentWidget();
379 QList<QLabel *> ql = p->findChildren<QLabel *>(); 399 QList<QLabel *> ql = p->findChildren<QLabel *>();
380 if (!ql.empty()) ql[0]->setText(text); 400 if (!ql.empty()) ql[0]->setText(text);
381 } 401 }
402
403 void FileStatusWidget::updateStateLabel()
404 {
405 m_stateLabel->setText(m_state);
406 }