Mercurial > hg > easyhg
comparison filestatuswidget.cpp @ 307:5b4aa1c24407 new-branches-with-status-outside-tabs
Merge branch status_outside_tabs into branch new-branches, and make a new branch
author | Chris Cannam |
---|---|
date | Mon, 28 Feb 2011 13:09:37 +0000 |
parents | e4284fab6962 |
children | 1aba0914dcfc |
comparison
equal
deleted
inserted
replaced
278:f7cdd5b31aed | 307:5b4aa1c24407 |
---|---|
16 */ | 16 */ |
17 | 17 |
18 #include "filestatuswidget.h" | 18 #include "filestatuswidget.h" |
19 #include "debug.h" | 19 #include "debug.h" |
20 #include "multichoicedialog.h" | 20 #include "multichoicedialog.h" |
21 #include "clickablelabel.h" | |
22 | 21 |
23 #include <QLabel> | 22 #include <QLabel> |
24 #include <QListWidget> | 23 #include <QListWidget> |
25 #include <QGridLayout> | 24 #include <QGridLayout> |
26 #include <QFileInfo> | 25 #include <QFileInfo> |
41 layout->setMargin(10); | 40 layout->setMargin(10); |
42 setLayout(layout); | 41 setLayout(layout); |
43 | 42 |
44 int row = 0; | 43 int row = 0; |
45 | 44 |
46 #ifndef Q_OS_MAC | |
47 layout->addItem(new QSpacerItem(1, 1), row, 0); | |
48 ++row; | |
49 #endif | |
50 | |
51 layout->addWidget(new QLabel(tr("Local:")), row, 0); | |
52 | |
53 m_openButton = new ClickableLabel; | |
54 QFont f(m_openButton->font()); | |
55 f.setBold(true); | |
56 m_openButton->setFont(f); | |
57 m_openButton->setMouseUnderline(true); | |
58 connect(m_openButton, SIGNAL(clicked()), this, SLOT(openButtonClicked())); | |
59 layout->addWidget(m_openButton, row, 1, 1, 2, Qt::AlignLeft); | |
60 | |
61 ++row; | |
62 layout->addWidget(new QLabel(tr("Remote:")), row, 0); | |
63 m_remoteURLLabel = new QLabel; | |
64 layout->addWidget(m_remoteURLLabel, row, 1, 1, 2); | |
65 | |
66 ++row; | |
67 layout->addWidget(new QLabel(tr("State:")), row, 0); | |
68 m_stateLabel = new QLabel; | |
69 layout->addWidget(m_stateLabel, row, 1, 1, 2); | |
70 | |
71 layout->setColumnStretch(1, 20); | |
72 | |
73 layout->addWidget(new QLabel("<qt><hr></qt>"), ++row, 0, 1, 3); | |
74 | |
75 ++row; | |
76 | |
77 m_noModificationsLabel = new QLabel; | 45 m_noModificationsLabel = new QLabel; |
78 setNoModificationsLabelText(); | 46 setNoModificationsLabelText(); |
79 layout->addWidget(m_noModificationsLabel, row, 1, 1, 2); | 47 layout->addWidget(m_noModificationsLabel, row, 0); |
80 m_noModificationsLabel->hide(); | 48 m_noModificationsLabel->hide(); |
81 | 49 |
82 m_simpleLabels[FileStates::Clean] = tr("Unmodified:"); | 50 m_simpleLabels[FileStates::Clean] = tr("Unmodified:"); |
83 m_simpleLabels[FileStates::Modified] = tr("Modified:"); | 51 m_simpleLabels[FileStates::Modified] = tr("Modified:"); |
84 m_simpleLabels[FileStates::Added] = tr("Added:"); | 52 m_simpleLabels[FileStates::Added] = tr("Added:"); |
105 | 73 |
106 m_highlightExplanation = tr("Files highlighted <font color=#d40000>in red</font> " | 74 m_highlightExplanation = tr("Files highlighted <font color=#d40000>in red</font> " |
107 "have appeared since your most recent commit or update."); | 75 "have appeared since your most recent commit or update."); |
108 | 76 |
109 m_boxesParent = new QWidget(this); | 77 m_boxesParent = new QWidget(this); |
110 layout->addWidget(m_boxesParent, ++row, 0, 1, 3); | 78 layout->addWidget(m_boxesParent, ++row, 0); |
111 | 79 |
112 QGridLayout *boxesLayout = new QGridLayout; | 80 QGridLayout *boxesLayout = new QGridLayout; |
113 boxesLayout->setMargin(0); | 81 boxesLayout->setMargin(0); |
114 m_boxesParent->setLayout(boxesLayout); | 82 m_boxesParent->setLayout(boxesLayout); |
115 int boxRow = 0; | 83 int boxRow = 0; |
150 layout->setRowStretch(++row, 20); | 118 layout->setRowStretch(++row, 20); |
151 | 119 |
152 layout->addItem(new QSpacerItem(8, 8), ++row, 0); | 120 layout->addItem(new QSpacerItem(8, 8), ++row, 0); |
153 | 121 |
154 m_showAllFiles = new QCheckBox(tr("Show all files"), this); | 122 m_showAllFiles = new QCheckBox(tr("Show all files"), this); |
155 layout->addWidget(m_showAllFiles, ++row, 0, 1, 3, Qt::AlignLeft); | 123 layout->addWidget(m_showAllFiles, ++row, 0, Qt::AlignLeft); |
156 connect(m_showAllFiles, SIGNAL(toggled(bool)), | 124 connect(m_showAllFiles, SIGNAL(toggled(bool)), |
157 this, SIGNAL(showAllChanged(bool))); | 125 this, SIGNAL(showAllChanged(bool))); |
158 } | 126 } |
159 | 127 |
160 FileStatusWidget::~FileStatusWidget() | 128 FileStatusWidget::~FileStatusWidget() |
161 { | 129 { |
162 delete m_dateReference; | 130 delete m_dateReference; |
163 } | |
164 | |
165 void FileStatusWidget::openButtonClicked() | |
166 { | |
167 QDir d(m_localPath); | |
168 if (d.exists()) { | |
169 QStringList args; | |
170 QString path = d.canonicalPath(); | |
171 #if defined Q_OS_WIN32 | |
172 // Although the Win32 API is quite happy to have | |
173 // forward slashes as directory separators, Windows | |
174 // Explorer is not | |
175 path = path.replace('/', '\\'); | |
176 args << path; | |
177 QProcess::execute("c:/windows/explorer.exe", args); | |
178 #else | |
179 args << path; | |
180 QProcess::execute( | |
181 #if defined Q_OS_MAC | |
182 "/usr/bin/open", | |
183 #else | |
184 "/usr/bin/xdg-open", | |
185 #endif | |
186 args); | |
187 #endif | |
188 } | |
189 } | 131 } |
190 | 132 |
191 QString FileStatusWidget::labelFor(FileStates::State s, bool addHighlightExplanation) | 133 QString FileStatusWidget::labelFor(FileStates::State s, bool addHighlightExplanation) |
192 { | 134 { |
193 QSettings settings; | 135 QSettings settings; |
410 files << m_fileStates.getFilesInState(FileStates::Missing); | 352 files << m_fileStates.getFilesInState(FileStates::Missing); |
411 files << m_fileStates.getFilesInState(FileStates::InConflict); | 353 files << m_fileStates.getFilesInState(FileStates::InConflict); |
412 return files; | 354 return files; |
413 } | 355 } |
414 | 356 |
357 QString | |
358 FileStatusWidget::localPath() const | |
359 { | |
360 return m_localPath; | |
361 } | |
362 | |
415 void | 363 void |
416 FileStatusWidget::setLocalPath(QString p) | 364 FileStatusWidget::setLocalPath(QString p) |
417 { | 365 { |
418 m_localPath = p; | 366 m_localPath = p; |
419 m_openButton->setText(p); | |
420 delete m_dateReference; | 367 delete m_dateReference; |
421 m_dateReference = new QFileInfo(p + "/.hg/dirstate"); | 368 m_dateReference = new QFileInfo(p + "/.hg/dirstate"); |
422 if (!m_dateReference->exists() || | 369 if (!m_dateReference->exists() || |
423 !m_dateReference->isFile() || | 370 !m_dateReference->isFile() || |
424 !m_dateReference->isReadable()) { | 371 !m_dateReference->isReadable()) { |
427 << " does not exist, is not a file, or cannot be read" | 374 << " does not exist, is not a file, or cannot be read" |
428 << endl; | 375 << endl; |
429 delete m_dateReference; | 376 delete m_dateReference; |
430 m_dateReference = 0; | 377 m_dateReference = 0; |
431 } | 378 } |
432 m_openButton->setEnabled(QDir(m_localPath).exists()); | |
433 } | |
434 | |
435 void | |
436 FileStatusWidget::setRemoteURL(QString r) | |
437 { | |
438 m_remoteURL = r; | |
439 m_remoteURLLabel->setText(r); | |
440 } | 379 } |
441 | 380 |
442 void | 381 void |
443 FileStatusWidget::setFileStates(FileStates p) | 382 FileStatusWidget::setFileStates(FileStates p) |
444 { | 383 { |
445 m_fileStates = p; | 384 m_fileStates = p; |
446 updateWidgets(); | 385 updateWidgets(); |
447 } | |
448 | |
449 void | |
450 FileStatusWidget::setState(QString b) | |
451 { | |
452 m_state = b; | |
453 updateStateLabel(); | |
454 } | 386 } |
455 | 387 |
456 void | 388 void |
457 FileStatusWidget::updateWidgets() | 389 FileStatusWidget::updateWidgets() |
458 { | 390 { |
528 layoutBoxesGridly(visibleCount); | 460 layoutBoxesGridly(visibleCount); |
529 } else { | 461 } else { |
530 layoutBoxesLinearly(); | 462 layoutBoxesLinearly(); |
531 } | 463 } |
532 | 464 |
533 updateStateLabel(); | |
534 setNoModificationsLabelText(); | 465 setNoModificationsLabelText(); |
535 } | 466 } |
536 | 467 |
537 void FileStatusWidget::layoutBoxesGridly(int visibleCount) | 468 void FileStatusWidget::layoutBoxesGridly(int visibleCount) |
538 { | 469 { |
592 QWidget *p = w->parentWidget(); | 523 QWidget *p = w->parentWidget(); |
593 QList<QLabel *> ql = p->findChildren<QLabel *>(); | 524 QList<QLabel *> ql = p->findChildren<QLabel *>(); |
594 if (!ql.empty()) ql[0]->setText(text); | 525 if (!ql.empty()) ql[0]->setText(text); |
595 } | 526 } |
596 | 527 |
597 void FileStatusWidget::updateStateLabel() | |
598 { | |
599 m_stateLabel->setText(m_state); | |
600 } |