annotate filestatuswidget.cpp @ 262:a7843b03b4cf easyhg_v0.3.1

Merge
author Chris Cannam
date Wed, 12 Jan 2011 15:54:08 +0000
parents 8fd71f570884
children bc39f2e28da8
rev   line source
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@244 8 Copyright (c) 2011 Chris Cannam
Chris@244 9 Copyright (c) 2011 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@115 19 #include "debug.h"
Chris@115 20 #include "multichoicedialog.h"
Chris@186 21 #include "clickablelabel.h"
Chris@88 22
Chris@88 23 #include <QLabel>
Chris@88 24 #include <QListWidget>
Chris@88 25 #include <QGridLayout>
Chris@93 26 #include <QFileInfo>
Chris@93 27 #include <QApplication>
Chris@93 28 #include <QDateTime>
Chris@115 29 #include <QPushButton>
Chris@186 30 #include <QToolButton>
Chris@186 31 #include <QDir>
Chris@186 32 #include <QProcess>
Chris@199 33 #include <QCheckBox>
Chris@230 34 #include <QSettings>
Chris@88 35
Chris@88 36 FileStatusWidget::FileStatusWidget(QWidget *parent) :
Chris@93 37 QWidget(parent),
Chris@93 38 m_dateReference(0)
Chris@88 39 {
Chris@88 40 QGridLayout *layout = new QGridLayout;
Chris@215 41 layout->setMargin(10);
Chris@88 42 setLayout(layout);
Chris@88 43
Chris@88 44 int row = 0;
Chris@211 45
Chris@211 46 #ifndef Q_OS_MAC
Chris@115 47 layout->addItem(new QSpacerItem(1, 1), row, 0);
Chris@211 48 ++row;
Chris@211 49 #endif
Chris@115 50
Chris@88 51 layout->addWidget(new QLabel(tr("Local:")), row, 0);
Chris@186 52
Chris@186 53 m_openButton = new ClickableLabel;
Chris@186 54 QFont f(m_openButton->font());
Chris@89 55 f.setBold(true);
Chris@186 56 m_openButton->setFont(f);
Chris@186 57 m_openButton->setMouseUnderline(true);
Chris@186 58 connect(m_openButton, SIGNAL(clicked()), this, SLOT(openButtonClicked()));
Chris@187 59 layout->addWidget(m_openButton, row, 1, 1, 2, Qt::AlignLeft);
Chris@88 60
Chris@88 61 ++row;
Chris@88 62 layout->addWidget(new QLabel(tr("Remote:")), row, 0);
Chris@88 63 m_remoteURLLabel = new QLabel;
Chris@186 64 layout->addWidget(m_remoteURLLabel, row, 1, 1, 2);
Chris@88 65
Chris@106 66 ++row;
Chris@115 67 layout->addWidget(new QLabel(tr("State:")), row, 0);
Chris@115 68 m_stateLabel = new QLabel;
Chris@115 69 layout->addWidget(m_stateLabel, row, 1, 1, 2);
Chris@106 70
Chris@89 71 layout->setColumnStretch(1, 20);
Chris@88 72
Chris@115 73 layout->addWidget(new QLabel("<qt><hr></qt>"), ++row, 0, 1, 3);
Chris@115 74
Chris@115 75 ++row;
Chris@230 76
Chris@230 77 m_noModificationsLabel = new QLabel;
Chris@230 78 setNoModificationsLabelText();
Chris@115 79 layout->addWidget(m_noModificationsLabel, row, 1, 1, 2);
Chris@202 80 m_noModificationsLabel->hide();
Chris@106 81
Chris@100 82 m_simpleLabels[FileStates::Clean] = tr("Unmodified:");
Chris@100 83 m_simpleLabels[FileStates::Modified] = tr("Modified:");
Chris@100 84 m_simpleLabels[FileStates::Added] = tr("Added:");
Chris@100 85 m_simpleLabels[FileStates::Removed] = tr("Removed:");
Chris@100 86 m_simpleLabels[FileStates::Missing] = tr("Missing:");
Chris@163 87 m_simpleLabels[FileStates::InConflict] = tr("In Conflict:");
Chris@100 88 m_simpleLabels[FileStates::Unknown] = tr("Untracked:");
Chris@199 89 m_simpleLabels[FileStates::Ignored] = tr("Ignored:");
Chris@99 90
Chris@100 91 m_descriptions[FileStates::Clean] = tr("You have not changed these files.");
Chris@100 92 m_descriptions[FileStates::Modified] = tr("You have changed these files since you last committed them.");
Chris@225 93 m_descriptions[FileStates::Added] = tr("These files will be added to version control next time you commit them.");
Chris@225 94 m_descriptions[FileStates::Removed] = tr("These files will be removed from version control next time you commit them.<br>"
Chris@100 95 "They will not be deleted from the local folder.");
Chris@109 96 m_descriptions[FileStates::Missing] = tr("These files are recorded in the version control, but absent from your working folder.<br>"
Chris@153 97 "If you intended to delete them, select them and use Remove to tell the version control system about it.<br>"
Chris@153 98 "If you deleted them by accident, select them and use Revert to restore their previous contents.");
Chris@163 99 m_descriptions[FileStates::InConflict] = tr("These files are unresolved following an incomplete merge.<br>Select a file and use Merge to try to resolve the merge again.");
Chris@100 100 m_descriptions[FileStates::Unknown] = tr("These files are in your working folder but are not under version control.<br>"
Chris@186 101 // "Select a file and use Add to place it under version control or Ignore to remove it from this list.");
Chris@186 102 "Select a file and use Add to place it under version control.");
Chris@199 103 m_descriptions[FileStates::Ignored] = tr("These files have names that match entries in the working folder's .hgignore file,<br>"
Chris@199 104 "and so will be ignored by the version control system.");
Chris@100 105
Chris@118 106 m_highlightExplanation = tr("Files highlighted <font color=#d40000>in red</font> "
Chris@100 107 "have appeared since your most recent commit or update.");
Chris@89 108
Chris@230 109 m_boxesParent = new QWidget(this);
Chris@230 110 layout->addWidget(m_boxesParent, ++row, 0, 1, 3);
Chris@230 111
Chris@230 112 QGridLayout *boxesLayout = new QGridLayout;
Chris@230 113 boxesLayout->setMargin(0);
Chris@230 114 m_boxesParent->setLayout(boxesLayout);
Chris@230 115 int boxRow = 0;
Chris@230 116
Chris@94 117 for (int i = int(FileStates::FirstState);
Chris@163 118 i <= int(FileStates::LastState); ++i) {
Chris@89 119
Chris@94 120 FileStates::State s = FileStates::State(i);
Chris@89 121
Chris@230 122 QWidget *box = new QWidget(m_boxesParent);
Chris@89 123 QGridLayout *boxlayout = new QGridLayout;
Chris@99 124 boxlayout->setMargin(0);
Chris@89 125 box->setLayout(boxlayout);
Chris@89 126
Chris@211 127 boxlayout->addItem(new QSpacerItem(3, 3), 0, 0);
Chris@101 128
Chris@230 129 QLabel *label = new QLabel(labelFor(s));
Chris@230 130 label->setWordWrap(true);
Chris@230 131 boxlayout->addWidget(label, 1, 0);
Chris@89 132
Chris@94 133 QListWidget *w = new QListWidget;
Chris@94 134 m_stateListMap[s] = w;
Chris@94 135 w->setSelectionMode(QListWidget::ExtendedSelection);
Chris@101 136 boxlayout->addWidget(w, 2, 0);
Chris@89 137
Chris@95 138 connect(w, SIGNAL(itemSelectionChanged()),
Chris@95 139 this, SLOT(itemSelectionChanged()));
Chris@95 140
Chris@211 141 boxlayout->addItem(new QSpacerItem(2, 2), 3, 0);
Chris@211 142
Chris@230 143 boxesLayout->addWidget(box, ++boxRow, 0);
Chris@230 144 m_boxes.push_back(box);
Chris@89 145 box->hide();
Chris@89 146 }
Chris@89 147
Chris@230 148 m_gridlyLayout = false;
Chris@230 149
Chris@89 150 layout->setRowStretch(++row, 20);
Chris@186 151
Chris@211 152 layout->addItem(new QSpacerItem(8, 8), ++row, 0);
Chris@199 153
Chris@199 154 m_showAllFiles = new QCheckBox(tr("Show all files"), this);
Chris@199 155 layout->addWidget(m_showAllFiles, ++row, 0, 1, 3, Qt::AlignLeft);
Chris@199 156 connect(m_showAllFiles, SIGNAL(toggled(bool)),
Chris@199 157 this, SIGNAL(showAllChanged(bool)));
Chris@88 158 }
Chris@88 159
Chris@93 160 FileStatusWidget::~FileStatusWidget()
Chris@93 161 {
Chris@93 162 delete m_dateReference;
Chris@93 163 }
Chris@93 164
Chris@186 165 void FileStatusWidget::openButtonClicked()
Chris@186 166 {
Chris@186 167 QDir d(m_localPath);
Chris@186 168 if (d.exists()) {
Chris@186 169 QStringList args;
Chris@201 170 QString path = d.canonicalPath();
Chris@201 171 #if defined Q_OS_WIN32
Chris@201 172 // Although the Win32 API is quite happy to have
Chris@201 173 // forward slashes as directory separators, Windows
Chris@201 174 // Explorer is not
Chris@201 175 path = path.replace('/', '\\');
Chris@201 176 args << path;
Chris@201 177 QProcess::execute("c:/windows/explorer.exe", args);
Chris@201 178 #else
Chris@201 179 args << path;
Chris@186 180 QProcess::execute(
Chris@201 181 #if defined Q_OS_MAC
Chris@186 182 "/usr/bin/open",
Chris@186 183 #else
Chris@186 184 "/usr/bin/xdg-open",
Chris@186 185 #endif
Chris@186 186 args);
Chris@201 187 #endif
Chris@186 188 }
Chris@186 189 }
Chris@186 190
Chris@100 191 QString FileStatusWidget::labelFor(FileStates::State s, bool addHighlightExplanation)
Chris@100 192 {
Chris@230 193 QSettings settings;
Chris@230 194 settings.beginGroup("Presentation");
Chris@230 195 if (settings.value("showhelpfultext", true).toBool()) {
Chris@230 196 if (addHighlightExplanation) {
Chris@230 197 return QString("<qt><b>%1</b><br>%2<br>%3</qt>")
Chris@230 198 .arg(m_simpleLabels[s])
Chris@230 199 .arg(m_descriptions[s])
Chris@230 200 .arg(m_highlightExplanation);
Chris@230 201 } else {
Chris@230 202 return QString("<qt><b>%1</b><br>%2</qt>")
Chris@230 203 .arg(m_simpleLabels[s])
Chris@230 204 .arg(m_descriptions[s]);
Chris@230 205 }
Chris@100 206 } else {
Chris@230 207 return QString("<qt><b>%1</b></qt>")
Chris@230 208 .arg(m_simpleLabels[s]);
Chris@230 209 }
Chris@230 210 settings.endGroup();
Chris@230 211 }
Chris@230 212
Chris@230 213 void FileStatusWidget::setNoModificationsLabelText()
Chris@230 214 {
Chris@230 215 QSettings settings;
Chris@230 216 settings.beginGroup("Presentation");
Chris@230 217 if (settings.value("showhelpfultext", true).toBool()) {
Chris@230 218 m_noModificationsLabel->setText
Chris@230 219 (tr("<qt>This area will list files in your working folder that you have changed.<br><br>At the moment you have no uncommitted changes.<br><br>To see changes previously made to the repository,<br>switch to the History tab.<br><br>%1</qt>")
Chris@230 220 #if defined Q_OS_MAC
Chris@230 221 .arg(tr("To open the working folder in Finder,<br>click on the &ldquo;Local&rdquo; folder path shown above."))
Chris@230 222 #elif defined Q_OS_WIN32
Chris@230 223 .arg(tr("To open the working folder in Windows Explorer,<br>click on the &ldquo;Local&rdquo; folder path shown above."))
Chris@230 224 #else
Chris@230 225 .arg(tr("To open the working folder in your system file manager,<br>click the &ldquo;Local&rdquo; folder path shown above."))
Chris@230 226 #endif
Chris@230 227 );
Chris@230 228 } else {
Chris@230 229 m_noModificationsLabel->setText
Chris@230 230 (tr("<qt>You have no uncommitted changes.</qt>"));
Chris@100 231 }
Chris@100 232 }
Chris@100 233
Chris@95 234 void FileStatusWidget::itemSelectionChanged()
Chris@95 235 {
Chris@135 236 DEBUG << "FileStatusWidget::itemSelectionChanged" << endl;
Chris@135 237
Chris@135 238 QListWidget *list = qobject_cast<QListWidget *>(sender());
Chris@135 239
Chris@135 240 if (list) {
Chris@135 241 foreach (QListWidget *w, m_stateListMap) {
Chris@135 242 if (w != list) {
Chris@135 243 w->blockSignals(true);
Chris@135 244 w->clearSelection();
Chris@135 245 w->blockSignals(false);
Chris@135 246 }
Chris@135 247 }
Chris@135 248 }
Chris@135 249
Chris@95 250 m_selectedFiles.clear();
Chris@95 251
Chris@95 252 foreach (QListWidget *w, m_stateListMap) {
Chris@95 253 QList<QListWidgetItem *> sel = w->selectedItems();
Chris@95 254 foreach (QListWidgetItem *i, sel) {
Chris@95 255 m_selectedFiles.push_back(i->text());
Chris@95 256 DEBUG << "file " << i->text() << " is selected" << endl;
Chris@95 257 }
Chris@95 258 }
Chris@95 259
Chris@95 260 emit selectionChanged();
Chris@95 261 }
Chris@95 262
Chris@94 263 void FileStatusWidget::clearSelections()
Chris@94 264 {
Chris@95 265 m_selectedFiles.clear();
Chris@94 266 foreach (QListWidget *w, m_stateListMap) {
Chris@94 267 w->clearSelection();
Chris@94 268 }
Chris@94 269 }
Chris@94 270
Chris@95 271 bool FileStatusWidget::haveChangesToCommit() const
Chris@95 272 {
Chris@95 273 return !m_fileStates.added().empty() ||
Chris@95 274 !m_fileStates.removed().empty() ||
Chris@95 275 !m_fileStates.modified().empty();
Chris@95 276 }
Chris@95 277
Chris@95 278 bool FileStatusWidget::haveSelection() const
Chris@95 279 {
Chris@95 280 return !m_selectedFiles.empty();
Chris@95 281 }
Chris@95 282
Chris@95 283 QStringList FileStatusWidget::getAllSelectedFiles() const
Chris@95 284 {
Chris@95 285 return m_selectedFiles;
Chris@95 286 }
Chris@95 287
Chris@95 288 QStringList FileStatusWidget::getSelectedCommittableFiles() const
Chris@95 289 {
Chris@95 290 QStringList files;
Chris@95 291 foreach (QString f, m_selectedFiles) {
Chris@95 292 switch (m_fileStates.getStateOfFile(f)) {
Chris@95 293 case FileStates::Added:
Chris@95 294 case FileStates::Modified:
Chris@95 295 case FileStates::Removed:
Chris@95 296 files.push_back(f);
Chris@95 297 break;
Chris@95 298 default: break;
Chris@95 299 }
Chris@95 300 }
Chris@95 301 return files;
Chris@95 302 }
Chris@95 303
Chris@103 304 QStringList FileStatusWidget::getAllCommittableFiles() const
Chris@103 305 {
Chris@103 306 QStringList files;
Chris@103 307 files << m_fileStates.getFilesInState(FileStates::Modified);
Chris@103 308 files << m_fileStates.getFilesInState(FileStates::Added);
Chris@103 309 files << m_fileStates.getFilesInState(FileStates::Removed);
Chris@103 310 return files;
Chris@103 311 }
Chris@103 312
Chris@109 313 QStringList FileStatusWidget::getSelectedRevertableFiles() const
Chris@109 314 {
Chris@109 315 QStringList files;
Chris@109 316 foreach (QString f, m_selectedFiles) {
Chris@109 317 switch (m_fileStates.getStateOfFile(f)) {
Chris@109 318 case FileStates::Added:
Chris@109 319 case FileStates::Modified:
Chris@109 320 case FileStates::Removed:
Chris@109 321 case FileStates::Missing:
Chris@163 322 case FileStates::InConflict:
Chris@109 323 files.push_back(f);
Chris@109 324 break;
Chris@109 325 default: break;
Chris@109 326 }
Chris@109 327 }
Chris@109 328 return files;
Chris@109 329 }
Chris@109 330
Chris@109 331 QStringList FileStatusWidget::getAllRevertableFiles() const
Chris@109 332 {
Chris@109 333 QStringList files;
Chris@109 334 files << m_fileStates.getFilesInState(FileStates::Modified);
Chris@109 335 files << m_fileStates.getFilesInState(FileStates::Added);
Chris@109 336 files << m_fileStates.getFilesInState(FileStates::Removed);
Chris@109 337 files << m_fileStates.getFilesInState(FileStates::Missing);
Chris@163 338 files << m_fileStates.getFilesInState(FileStates::InConflict);
Chris@163 339 return files;
Chris@163 340 }
Chris@163 341
Chris@163 342 QStringList FileStatusWidget::getSelectedUnresolvedFiles() const
Chris@163 343 {
Chris@163 344 QStringList files;
Chris@163 345 foreach (QString f, m_selectedFiles) {
Chris@163 346 switch (m_fileStates.getStateOfFile(f)) {
Chris@163 347 case FileStates::InConflict:
Chris@163 348 files.push_back(f);
Chris@163 349 break;
Chris@163 350 default: break;
Chris@163 351 }
Chris@163 352 }
Chris@163 353 return files;
Chris@163 354 }
Chris@163 355
Chris@163 356 QStringList FileStatusWidget::getAllUnresolvedFiles() const
Chris@163 357 {
Chris@163 358 QStringList files;
Chris@163 359 files << m_fileStates.getFilesInState(FileStates::InConflict);
Chris@109 360 return files;
Chris@109 361 }
Chris@109 362
Chris@95 363 QStringList FileStatusWidget::getSelectedAddableFiles() const
Chris@95 364 {
Chris@95 365 QStringList files;
Chris@95 366 foreach (QString f, m_selectedFiles) {
Chris@95 367 switch (m_fileStates.getStateOfFile(f)) {
Chris@95 368 case FileStates::Unknown:
Chris@95 369 case FileStates::Removed:
Chris@95 370 files.push_back(f);
Chris@95 371 break;
Chris@95 372 default: break;
Chris@95 373 }
Chris@95 374 }
Chris@95 375 return files;
Chris@95 376 }
Chris@95 377
Chris@103 378 QStringList FileStatusWidget::getAllAddableFiles() const
Chris@103 379 {
Chris@103 380 QStringList files;
Chris@103 381 files << m_fileStates.getFilesInState(FileStates::Removed);
Chris@103 382 files << m_fileStates.getFilesInState(FileStates::Unknown);
Chris@103 383 return files;
Chris@103 384 }
Chris@103 385
Chris@95 386 QStringList FileStatusWidget::getSelectedRemovableFiles() const
Chris@95 387 {
Chris@95 388 QStringList files;
Chris@95 389 foreach (QString f, m_selectedFiles) {
Chris@95 390 switch (m_fileStates.getStateOfFile(f)) {
Chris@95 391 case FileStates::Clean:
Chris@95 392 case FileStates::Added:
Chris@95 393 case FileStates::Modified:
Chris@95 394 case FileStates::Missing:
Chris@163 395 case FileStates::InConflict:
Chris@95 396 files.push_back(f);
Chris@95 397 break;
Chris@95 398 default: break;
Chris@95 399 }
Chris@95 400 }
Chris@95 401 return files;
Chris@95 402 }
Chris@95 403
Chris@103 404 QStringList FileStatusWidget::getAllRemovableFiles() const
Chris@103 405 {
Chris@103 406 QStringList files;
Chris@103 407 files << m_fileStates.getFilesInState(FileStates::Clean);
Chris@103 408 files << m_fileStates.getFilesInState(FileStates::Added);
Chris@103 409 files << m_fileStates.getFilesInState(FileStates::Modified);
Chris@103 410 files << m_fileStates.getFilesInState(FileStates::Missing);
Chris@163 411 files << m_fileStates.getFilesInState(FileStates::InConflict);
Chris@103 412 return files;
Chris@103 413 }
Chris@103 414
Chris@88 415 void
Chris@88 416 FileStatusWidget::setLocalPath(QString p)
Chris@88 417 {
Chris@88 418 m_localPath = p;
Chris@186 419 m_openButton->setText(p);
Chris@93 420 delete m_dateReference;
Chris@93 421 m_dateReference = new QFileInfo(p + "/.hg/dirstate");
Chris@93 422 if (!m_dateReference->exists() ||
Chris@93 423 !m_dateReference->isFile() ||
Chris@93 424 !m_dateReference->isReadable()) {
Chris@93 425 DEBUG << "FileStatusWidget::setLocalPath: date reference file "
Chris@93 426 << m_dateReference->absoluteFilePath()
Chris@93 427 << " does not exist, is not a file, or cannot be read"
Chris@93 428 << endl;
Chris@93 429 delete m_dateReference;
Chris@93 430 m_dateReference = 0;
Chris@93 431 }
Chris@186 432 m_openButton->setEnabled(QDir(m_localPath).exists());
Chris@88 433 }
Chris@88 434
Chris@88 435 void
Chris@88 436 FileStatusWidget::setRemoteURL(QString r)
Chris@88 437 {
Chris@88 438 m_remoteURL = r;
Chris@88 439 m_remoteURLLabel->setText(r);
Chris@88 440 }
Chris@88 441
Chris@88 442 void
Chris@92 443 FileStatusWidget::setFileStates(FileStates p)
Chris@88 444 {
Chris@92 445 m_fileStates = p;
Chris@88 446 updateWidgets();
Chris@88 447 }
Chris@88 448
Chris@88 449 void
Chris@115 450 FileStatusWidget::setState(QString b)
Chris@106 451 {
Chris@115 452 m_state = b;
Chris@115 453 updateStateLabel();
Chris@106 454 }
Chris@106 455
Chris@106 456 void
Chris@88 457 FileStatusWidget::updateWidgets()
Chris@88 458 {
Chris@95 459 QDateTime lastInteractionTime;
Chris@95 460 if (m_dateReference) {
Chris@95 461 lastInteractionTime = m_dateReference->lastModified();
Chris@95 462 DEBUG << "reference time: " << lastInteractionTime << endl;
Chris@95 463 }
Chris@95 464
Chris@95 465 QSet<QString> selectedFiles;
Chris@95 466 foreach (QString f, m_selectedFiles) selectedFiles.insert(f);
Chris@95 467
Chris@230 468 int visibleCount = 0;
Chris@115 469
Chris@94 470 foreach (FileStates::State s, m_stateListMap.keys()) {
Chris@95 471
Chris@94 472 QListWidget *w = m_stateListMap[s];
Chris@94 473 w->clear();
Chris@95 474 QStringList files = m_fileStates.getFilesInState(s);
Chris@93 475
Chris@95 476 QStringList highPriority, lowPriority;
Chris@95 477
Chris@95 478 foreach (QString file, files) {
Chris@95 479
Chris@95 480 bool highlighted = false;
Chris@95 481
Chris@95 482 if (s == FileStates::Unknown) {
Chris@95 483 // We want to highlight untracked files that have appeared
Chris@95 484 // since the last interaction with the repo
Chris@95 485 QString fn(m_localPath + "/" + file);
Chris@95 486 DEBUG << "comparing with " << fn << endl;
Chris@95 487 QFileInfo fi(fn);
Chris@100 488 if (fi.exists() && fi.created() > lastInteractionTime) {
Chris@95 489 DEBUG << "file " << fn << " is newer (" << fi.lastModified()
Chris@95 490 << ") than reference" << endl;
Chris@95 491 highlighted = true;
Chris@95 492 }
Chris@95 493 }
Chris@95 494
Chris@95 495 if (highlighted) {
Chris@95 496 highPriority.push_back(file);
Chris@95 497 } else {
Chris@95 498 lowPriority.push_back(file);
Chris@93 499 }
Chris@93 500 }
Chris@95 501
Chris@95 502 foreach (QString file, highPriority) {
Chris@95 503 QListWidgetItem *item = new QListWidgetItem(file);
Chris@95 504 w->addItem(item);
Chris@118 505 item->setForeground(QColor("#d40000")); //!!! and a nice gold star
Chris@95 506 item->setSelected(selectedFiles.contains(file));
Chris@95 507 }
Chris@95 508
Chris@95 509 foreach (QString file, lowPriority) {
Chris@95 510 QListWidgetItem *item = new QListWidgetItem(file);
Chris@95 511 w->addItem(item);
Chris@95 512 item->setSelected(selectedFiles.contains(file));
Chris@95 513 }
Chris@95 514
Chris@100 515 setLabelFor(w, s, !highPriority.empty());
Chris@100 516
Chris@115 517 if (files.empty()) {
Chris@115 518 w->parentWidget()->hide();
Chris@115 519 } else {
Chris@115 520 w->parentWidget()->show();
Chris@230 521 ++visibleCount;
Chris@115 522 }
Chris@93 523 }
Chris@115 524
Chris@230 525 m_noModificationsLabel->setVisible(visibleCount == 0);
Chris@230 526
Chris@230 527 if (visibleCount > 3) {
Chris@230 528 layoutBoxesGridly(visibleCount);
Chris@230 529 } else {
Chris@230 530 layoutBoxesLinearly();
Chris@230 531 }
Chris@115 532
Chris@115 533 updateStateLabel();
Chris@230 534 setNoModificationsLabelText();
Chris@230 535 }
Chris@230 536
Chris@230 537 void FileStatusWidget::layoutBoxesGridly(int visibleCount)
Chris@230 538 {
Chris@230 539 if (m_gridlyLayout && m_lastGridlyCount == visibleCount) return;
Chris@230 540
Chris@230 541 delete m_boxesParent->layout();
Chris@230 542
Chris@230 543 QGridLayout *layout = new QGridLayout;
Chris@230 544 layout->setMargin(0);
Chris@230 545 m_boxesParent->setLayout(layout);
Chris@230 546
Chris@230 547 int row = 0;
Chris@230 548 int col = 0;
Chris@230 549
Chris@230 550 DEBUG << "FileStatusWidget::layoutBoxesGridly: visibleCount = "
Chris@230 551 << visibleCount << endl;
Chris@230 552
Chris@230 553 for (int i = 0; i < m_boxes.size(); ++i) {
Chris@230 554
Chris@230 555 if (!m_boxes[i]->isVisible()) continue;
Chris@230 556
Chris@230 557 if (col == 0 && row >= (visibleCount+1)/2) {
Chris@230 558 layout->addItem(new QSpacerItem(10, 5), 0, 1);
Chris@230 559 col = 2;
Chris@230 560 row = 0;
Chris@230 561 }
Chris@230 562
Chris@230 563 layout->addWidget(m_boxes[i], row, col);
Chris@230 564
Chris@230 565 ++row;
Chris@230 566 }
Chris@230 567
Chris@230 568 m_gridlyLayout = true;
Chris@230 569 m_lastGridlyCount = visibleCount;
Chris@230 570 }
Chris@230 571
Chris@230 572 void FileStatusWidget::layoutBoxesLinearly()
Chris@230 573 {
Chris@230 574 if (!m_gridlyLayout) return;
Chris@230 575
Chris@230 576 delete m_boxesParent->layout();
Chris@230 577
Chris@230 578 QGridLayout *layout = new QGridLayout;
Chris@230 579 layout->setMargin(0);
Chris@230 580 m_boxesParent->setLayout(layout);
Chris@230 581
Chris@230 582 for (int i = 0; i < m_boxes.size(); ++i) {
Chris@230 583 layout->addWidget(m_boxes[i], i, 0);
Chris@230 584 }
Chris@230 585
Chris@230 586 m_gridlyLayout = false;
Chris@88 587 }
Chris@88 588
Chris@100 589 void FileStatusWidget::setLabelFor(QWidget *w, FileStates::State s, bool addHighlight)
Chris@100 590 {
Chris@100 591 QString text = labelFor(s, addHighlight);
Chris@100 592 QWidget *p = w->parentWidget();
Chris@100 593 QList<QLabel *> ql = p->findChildren<QLabel *>();
Chris@100 594 if (!ql.empty()) ql[0]->setText(text);
Chris@100 595 }
Chris@115 596
Chris@115 597 void FileStatusWidget::updateStateLabel()
Chris@115 598 {
Chris@115 599 m_stateLabel->setText(m_state);
Chris@115 600 }