Chris@88
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@88
|
2
|
Chris@88
|
3 /*
|
Chris@88
|
4 EasyMercurial
|
Chris@88
|
5
|
Chris@88
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@88
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@88
|
8 Copyright (c) 2010 Chris Cannam
|
Chris@88
|
9 Copyright (c) 2010 Queen Mary, University of London
|
Chris@88
|
10
|
Chris@88
|
11 This program is free software; you can redistribute it and/or
|
Chris@88
|
12 modify it under the terms of the GNU General Public License as
|
Chris@88
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@88
|
14 License, or (at your option) any later version. See the file
|
Chris@88
|
15 COPYING included with this distribution for more information.
|
Chris@88
|
16 */
|
Chris@88
|
17
|
Chris@88
|
18 #include "filestatuswidget.h"
|
Chris@88
|
19
|
Chris@88
|
20 #include <QLabel>
|
Chris@88
|
21 #include <QListWidget>
|
Chris@88
|
22 #include <QGridLayout>
|
Chris@88
|
23
|
Chris@88
|
24 FileStatusWidget::FileStatusWidget(QWidget *parent) :
|
Chris@88
|
25 QWidget(parent)
|
Chris@88
|
26 {
|
Chris@88
|
27 QGridLayout *layout = new QGridLayout;
|
Chris@88
|
28 setLayout(layout);
|
Chris@88
|
29
|
Chris@88
|
30 int row = 0;
|
Chris@88
|
31
|
Chris@88
|
32 layout->addWidget(new QLabel(tr("Local:")), row, 0);
|
Chris@88
|
33 m_localPathLabel = new QLabel;
|
Chris@89
|
34 QFont f(m_localPathLabel->font());
|
Chris@89
|
35 f.setBold(true);
|
Chris@89
|
36 m_localPathLabel->setFont(f);
|
Chris@88
|
37 layout->addWidget(m_localPathLabel, row, 1);
|
Chris@88
|
38
|
Chris@88
|
39 ++row;
|
Chris@88
|
40 layout->addWidget(new QLabel(tr("Remote:")), row, 0);
|
Chris@88
|
41 m_remoteURLLabel = new QLabel;
|
Chris@88
|
42 layout->addWidget(m_remoteURLLabel, row, 1);
|
Chris@88
|
43
|
Chris@89
|
44 layout->setColumnStretch(1, 20);
|
Chris@88
|
45
|
Chris@89
|
46 QStringList labels;
|
Chris@89
|
47 labels << tr("Modified files:")
|
Chris@89
|
48 << tr("Added files:")
|
Chris@89
|
49 << tr("Removed files:")
|
Chris@89
|
50 << tr("New untracked files:")
|
Chris@89
|
51 << tr("Missing files:");
|
Chris@89
|
52
|
Chris@89
|
53 QList<QListWidget **> lists;
|
Chris@89
|
54 lists << &m_modifiedList
|
Chris@89
|
55 << &m_addedList
|
Chris@89
|
56 << &m_removedList
|
Chris@89
|
57 << &m_unknownList
|
Chris@89
|
58 << &m_missingList;
|
Chris@89
|
59
|
Chris@89
|
60 for (int i = 0; i < labels.size(); ++i) {
|
Chris@89
|
61
|
Chris@89
|
62 QWidget *box = new QWidget;
|
Chris@89
|
63 QGridLayout *boxlayout = new QGridLayout;
|
Chris@89
|
64 box->setLayout(boxlayout);
|
Chris@89
|
65
|
Chris@89
|
66 boxlayout->addWidget(new QLabel(labels[i]), 0, 0);
|
Chris@89
|
67
|
Chris@89
|
68 *lists[i] = new QListWidget;
|
Chris@89
|
69 (*lists[i])->setSelectionMode(QListWidget::ExtendedSelection);
|
Chris@89
|
70 boxlayout->addWidget(*lists[i], 1, 0);
|
Chris@89
|
71
|
Chris@89
|
72 layout->addWidget(box, ++row, 0, 1, 2);
|
Chris@89
|
73 box->hide();
|
Chris@89
|
74 }
|
Chris@89
|
75
|
Chris@89
|
76 layout->setRowStretch(++row, 20);
|
Chris@88
|
77 }
|
Chris@88
|
78
|
Chris@88
|
79 void
|
Chris@88
|
80 FileStatusWidget::setLocalPath(QString p)
|
Chris@88
|
81 {
|
Chris@88
|
82 m_localPath = p;
|
Chris@88
|
83 m_localPathLabel->setText(p);
|
Chris@88
|
84 }
|
Chris@88
|
85
|
Chris@88
|
86 void
|
Chris@88
|
87 FileStatusWidget::setRemoteURL(QString r)
|
Chris@88
|
88 {
|
Chris@88
|
89 m_remoteURL = r;
|
Chris@88
|
90 m_remoteURLLabel->setText(r);
|
Chris@88
|
91 }
|
Chris@88
|
92
|
Chris@88
|
93 void
|
Chris@88
|
94 FileStatusWidget::setStatParser(StatParser p)
|
Chris@88
|
95 {
|
Chris@88
|
96 m_statParser = p;
|
Chris@88
|
97 updateWidgets();
|
Chris@88
|
98 }
|
Chris@88
|
99
|
Chris@88
|
100 void
|
Chris@88
|
101 FileStatusWidget::updateWidgets()
|
Chris@88
|
102 {
|
Chris@89
|
103 StatParser &sp = m_statParser;
|
Chris@89
|
104 QMap<QStringList *, QListWidget *> listmap;
|
Chris@89
|
105 listmap[&sp.modified] = m_modifiedList;
|
Chris@89
|
106 listmap[&sp.added] = m_addedList;
|
Chris@89
|
107 listmap[&sp.removed] = m_removedList;
|
Chris@89
|
108 listmap[&sp.missing] = m_missingList;
|
Chris@89
|
109 listmap[&sp.unknown] = m_unknownList;
|
Chris@88
|
110
|
Chris@89
|
111 foreach (QStringList *sl, listmap.keys()) {
|
Chris@89
|
112 listmap[sl]->clear();
|
Chris@89
|
113 listmap[sl]->addItems(*sl);
|
Chris@89
|
114 listmap[sl]->parentWidget()->setVisible(!sl->empty());
|
Chris@89
|
115 }
|
Chris@88
|
116 }
|
Chris@88
|
117
|