annotate filestatuswidget.cpp @ 359:550650bbb959 feature_91

Add "Open Recent". Fixes #91
author Chris Cannam
date Thu, 17 Mar 2011 16:35:38 +0000
parents 293d91cf44de
children 4cd753e083cc
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@88 21
Chris@88 22 #include <QLabel>
Chris@88 23 #include <QListWidget>
Chris@88 24 #include <QGridLayout>
Chris@93 25 #include <QFileInfo>
Chris@93 26 #include <QApplication>
Chris@93 27 #include <QDateTime>
Chris@115 28 #include <QPushButton>
Chris@186 29 #include <QToolButton>
Chris@186 30 #include <QDir>
Chris@186 31 #include <QProcess>
Chris@199 32 #include <QCheckBox>
Chris@230 33 #include <QSettings>
Chris@323 34 #include <QAction>
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@230 46 m_noModificationsLabel = new QLabel;
Chris@230 47 setNoModificationsLabelText();
Chris@297 48 layout->addWidget(m_noModificationsLabel, row, 0);
Chris@202 49 m_noModificationsLabel->hide();
Chris@106 50
Chris@100 51 m_simpleLabels[FileStates::Clean] = tr("Unmodified:");
Chris@100 52 m_simpleLabels[FileStates::Modified] = tr("Modified:");
Chris@100 53 m_simpleLabels[FileStates::Added] = tr("Added:");
Chris@100 54 m_simpleLabels[FileStates::Removed] = tr("Removed:");
Chris@100 55 m_simpleLabels[FileStates::Missing] = tr("Missing:");
Chris@163 56 m_simpleLabels[FileStates::InConflict] = tr("In Conflict:");
Chris@100 57 m_simpleLabels[FileStates::Unknown] = tr("Untracked:");
Chris@199 58 m_simpleLabels[FileStates::Ignored] = tr("Ignored:");
Chris@99 59
Chris@326 60 m_actionLabels[FileStates::Annotate] = tr("Show annotated version");
Chris@326 61 m_actionLabels[FileStates::Diff] = tr("Diff to parent");
Chris@325 62 m_actionLabels[FileStates::Commit] = tr("Commit...");
Chris@328 63 m_actionLabels[FileStates::Revert] = tr("Revert to last committed state");
Chris@326 64 m_actionLabels[FileStates::Add] = tr("Add to version control");
Chris@326 65 m_actionLabels[FileStates::Remove] = tr("Remove from version control");
Chris@326 66 m_actionLabels[FileStates::RedoMerge] = tr("Redo merge");
Chris@328 67 m_actionLabels[FileStates::MarkResolved] = tr("Mark conflict as resolved");
Chris@325 68 m_actionLabels[FileStates::Ignore] = tr("Ignore");
Chris@326 69 m_actionLabels[FileStates::UnIgnore] = tr("Stop ignoring");
Chris@325 70
Chris@100 71 m_descriptions[FileStates::Clean] = tr("You have not changed these files.");
Chris@100 72 m_descriptions[FileStates::Modified] = tr("You have changed these files since you last committed them.");
Chris@225 73 m_descriptions[FileStates::Added] = tr("These files will be added to version control next time you commit them.");
Chris@225 74 m_descriptions[FileStates::Removed] = tr("These files will be removed from version control next time you commit them.<br>"
Chris@100 75 "They will not be deleted from the local folder.");
Chris@109 76 m_descriptions[FileStates::Missing] = tr("These files are recorded in the version control, but absent from your working folder.<br>"
Chris@153 77 "If you intended to delete them, select them and use Remove to tell the version control system about it.<br>"
Chris@153 78 "If you deleted them by accident, select them and use Revert to restore their previous contents.");
Chris@163 79 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 80 m_descriptions[FileStates::Unknown] = tr("These files are in your working folder but are not under version control.<br>"
Chris@186 81 // "Select a file and use Add to place it under version control or Ignore to remove it from this list.");
Chris@186 82 "Select a file and use Add to place it under version control.");
Chris@199 83 m_descriptions[FileStates::Ignored] = tr("These files have names that match entries in the working folder's .hgignore file,<br>"
Chris@199 84 "and so will be ignored by the version control system.");
Chris@100 85
Chris@118 86 m_highlightExplanation = tr("Files highlighted <font color=#d40000>in red</font> "
Chris@100 87 "have appeared since your most recent commit or update.");
Chris@89 88
Chris@230 89 m_boxesParent = new QWidget(this);
Chris@297 90 layout->addWidget(m_boxesParent, ++row, 0);
Chris@230 91
Chris@230 92 QGridLayout *boxesLayout = new QGridLayout;
Chris@230 93 boxesLayout->setMargin(0);
Chris@230 94 m_boxesParent->setLayout(boxesLayout);
Chris@230 95 int boxRow = 0;
Chris@230 96
Chris@94 97 for (int i = int(FileStates::FirstState);
Chris@163 98 i <= int(FileStates::LastState); ++i) {
Chris@89 99
Chris@94 100 FileStates::State s = FileStates::State(i);
Chris@89 101
Chris@230 102 QWidget *box = new QWidget(m_boxesParent);
Chris@89 103 QGridLayout *boxlayout = new QGridLayout;
Chris@99 104 boxlayout->setMargin(0);
Chris@89 105 box->setLayout(boxlayout);
Chris@89 106
Chris@211 107 boxlayout->addItem(new QSpacerItem(3, 3), 0, 0);
Chris@101 108
Chris@230 109 QLabel *label = new QLabel(labelFor(s));
Chris@230 110 label->setWordWrap(true);
Chris@230 111 boxlayout->addWidget(label, 1, 0);
Chris@89 112
Chris@94 113 QListWidget *w = new QListWidget;
Chris@94 114 m_stateListMap[s] = w;
Chris@94 115 w->setSelectionMode(QListWidget::ExtendedSelection);
Chris@101 116 boxlayout->addWidget(w, 2, 0);
Chris@89 117
Chris@95 118 connect(w, SIGNAL(itemSelectionChanged()),
Chris@95 119 this, SLOT(itemSelectionChanged()));
Chris@331 120 connect(w, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
Chris@331 121 this, SLOT(itemDoubleClicked(QListWidgetItem *)));
Chris@95 122
Chris@325 123 FileStates::Activities activities = m_fileStates.activitiesSupportedBy(s);
Chris@325 124 int prevGroup = -1;
Chris@325 125 foreach (FileStates::Activity a, activities) {
Chris@326 126 // Skip activities which are not yet implemented
Chris@331 127 if (a == FileStates::Ignore ||
Chris@326 128 a == FileStates::UnIgnore) {
Chris@326 129 continue;
Chris@326 130 }
Chris@325 131 int group = FileStates::activityGroup(a);
Chris@325 132 if (group != prevGroup && prevGroup != -1) {
Chris@325 133 QAction *sep = new QAction("", w);
Chris@325 134 sep->setSeparator(true);
Chris@325 135 w->insertAction(0, sep);
Chris@325 136 }
Chris@325 137 prevGroup = group;
Chris@325 138 QAction *act = new QAction(m_actionLabels[a], w);
Chris@326 139 act->setProperty("state", s);
Chris@326 140 act->setProperty("activity", a);
Chris@326 141 connect(act, SIGNAL(triggered()), this, SLOT(menuActionActivated()));
Chris@325 142 w->insertAction(0, act);
Chris@325 143 }
Chris@323 144 w->setContextMenuPolicy(Qt::ActionsContextMenu);
Chris@323 145
Chris@211 146 boxlayout->addItem(new QSpacerItem(2, 2), 3, 0);
Chris@211 147
Chris@230 148 boxesLayout->addWidget(box, ++boxRow, 0);
Chris@230 149 m_boxes.push_back(box);
Chris@89 150 box->hide();
Chris@89 151 }
Chris@89 152
Chris@230 153 m_gridlyLayout = false;
Chris@230 154
Chris@89 155 layout->setRowStretch(++row, 20);
Chris@186 156
Chris@211 157 layout->addItem(new QSpacerItem(8, 8), ++row, 0);
Chris@199 158
Chris@199 159 m_showAllFiles = new QCheckBox(tr("Show all files"), this);
Chris@340 160 m_showAllFiles->setEnabled(false);
Chris@297 161 layout->addWidget(m_showAllFiles, ++row, 0, Qt::AlignLeft);
Chris@199 162 connect(m_showAllFiles, SIGNAL(toggled(bool)),
Chris@199 163 this, SIGNAL(showAllChanged(bool)));
Chris@88 164 }
Chris@88 165
Chris@93 166 FileStatusWidget::~FileStatusWidget()
Chris@93 167 {
Chris@93 168 delete m_dateReference;
Chris@93 169 }
Chris@93 170
Chris@100 171 QString FileStatusWidget::labelFor(FileStates::State s, bool addHighlightExplanation)
Chris@100 172 {
Chris@230 173 QSettings settings;
Chris@230 174 settings.beginGroup("Presentation");
Chris@230 175 if (settings.value("showhelpfultext", true).toBool()) {
Chris@230 176 if (addHighlightExplanation) {
Chris@230 177 return QString("<qt><b>%1</b><br>%2<br>%3</qt>")
Chris@230 178 .arg(m_simpleLabels[s])
Chris@230 179 .arg(m_descriptions[s])
Chris@230 180 .arg(m_highlightExplanation);
Chris@230 181 } else {
Chris@230 182 return QString("<qt><b>%1</b><br>%2</qt>")
Chris@230 183 .arg(m_simpleLabels[s])
Chris@230 184 .arg(m_descriptions[s]);
Chris@230 185 }
Chris@100 186 } else {
Chris@230 187 return QString("<qt><b>%1</b></qt>")
Chris@230 188 .arg(m_simpleLabels[s]);
Chris@230 189 }
Chris@230 190 settings.endGroup();
Chris@230 191 }
Chris@230 192
Chris@230 193 void FileStatusWidget::setNoModificationsLabelText()
Chris@230 194 {
Chris@230 195 QSettings settings;
Chris@230 196 settings.beginGroup("Presentation");
Chris@230 197 if (settings.value("showhelpfultext", true).toBool()) {
Chris@230 198 m_noModificationsLabel->setText
Chris@230 199 (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 200 #if defined Q_OS_MAC
Chris@230 201 .arg(tr("To open the working folder in Finder,<br>click on the &ldquo;Local&rdquo; folder path shown above."))
Chris@230 202 #elif defined Q_OS_WIN32
Chris@230 203 .arg(tr("To open the working folder in Windows Explorer,<br>click on the &ldquo;Local&rdquo; folder path shown above."))
Chris@230 204 #else
Chris@230 205 .arg(tr("To open the working folder in your system file manager,<br>click the &ldquo;Local&rdquo; folder path shown above."))
Chris@230 206 #endif
Chris@230 207 );
Chris@230 208 } else {
Chris@230 209 m_noModificationsLabel->setText
Chris@230 210 (tr("<qt>You have no uncommitted changes.</qt>"));
Chris@100 211 }
Chris@100 212 }
Chris@100 213
Chris@319 214
Chris@326 215 void FileStatusWidget::menuActionActivated()
Chris@326 216 {
Chris@326 217 QAction *act = qobject_cast<QAction *>(sender());
Chris@326 218 if (!act) return;
Chris@326 219
Chris@326 220 FileStates::State state = (FileStates::State)
Chris@326 221 act->property("state").toUInt();
Chris@326 222 FileStates::Activity activity = (FileStates::Activity)
Chris@326 223 act->property("activity").toUInt();
Chris@319 224
Chris@326 225 DEBUG << "menuActionActivated: state = " << state << ", activity = "
Chris@326 226 << activity << endl;
Chris@319 227
Chris@326 228 if (!FileStates::supportsActivity(state, activity)) {
Chris@326 229 std::cerr << "WARNING: FileStatusWidget::menuActionActivated: "
Chris@326 230 << "Action state " << state << " does not support activity "
Chris@326 231 << activity << std::endl;
Chris@326 232 return;
Chris@326 233 }
Chris@326 234
Chris@326 235 QStringList files = getSelectedFilesInState(state);
Chris@326 236
Chris@326 237 switch (activity) {
Chris@326 238 case FileStates::Annotate: emit annotateFiles(files); break;
Chris@326 239 case FileStates::Diff: emit diffFiles(files); break;
Chris@326 240 case FileStates::Commit: emit commitFiles(files); break;
Chris@326 241 case FileStates::Revert: emit revertFiles(files); break;
Chris@326 242 case FileStates::Add: emit addFiles(files); break;
Chris@326 243 case FileStates::Remove: emit removeFiles(files); break;
Chris@326 244 case FileStates::RedoMerge: emit redoFileMerges(files); break;
Chris@326 245 case FileStates::MarkResolved: emit markFilesResolved(files); break;
Chris@326 246 case FileStates::Ignore: emit ignoreFiles(files); break;
Chris@326 247 case FileStates::UnIgnore: emit unIgnoreFiles(files); break;
Chris@326 248 }
Chris@326 249 }
Chris@319 250
Chris@331 251 void FileStatusWidget::itemDoubleClicked(QListWidgetItem *item)
Chris@331 252 {
Chris@331 253 QStringList files;
Chris@350 254 QString file = item->text();
Chris@350 255 files << file;
Chris@350 256
Chris@350 257 switch (m_fileStates.stateOf(file)) {
Chris@350 258
Chris@350 259 case FileStates::Modified:
Chris@350 260 case FileStates::InConflict:
Chris@350 261 emit diffFiles(files);
Chris@350 262 break;
Chris@350 263
Chris@350 264 case FileStates::Clean:
Chris@350 265 case FileStates::Missing:
Chris@350 266 emit annotateFiles(files);
Chris@350 267 break;
Chris@350 268 }
Chris@331 269 }
Chris@319 270
Chris@95 271 void FileStatusWidget::itemSelectionChanged()
Chris@95 272 {
Chris@135 273 DEBUG << "FileStatusWidget::itemSelectionChanged" << endl;
Chris@135 274
Chris@135 275 QListWidget *list = qobject_cast<QListWidget *>(sender());
Chris@135 276
Chris@135 277 if (list) {
Chris@135 278 foreach (QListWidget *w, m_stateListMap) {
Chris@135 279 if (w != list) {
Chris@135 280 w->blockSignals(true);
Chris@135 281 w->clearSelection();
Chris@135 282 w->blockSignals(false);
Chris@135 283 }
Chris@135 284 }
Chris@135 285 }
Chris@135 286
Chris@95 287 m_selectedFiles.clear();
Chris@95 288
Chris@95 289 foreach (QListWidget *w, m_stateListMap) {
Chris@95 290 QList<QListWidgetItem *> sel = w->selectedItems();
Chris@95 291 foreach (QListWidgetItem *i, sel) {
Chris@95 292 m_selectedFiles.push_back(i->text());
Chris@95 293 DEBUG << "file " << i->text() << " is selected" << endl;
Chris@95 294 }
Chris@95 295 }
Chris@95 296
Chris@95 297 emit selectionChanged();
Chris@95 298 }
Chris@95 299
Chris@94 300 void FileStatusWidget::clearSelections()
Chris@94 301 {
Chris@95 302 m_selectedFiles.clear();
Chris@94 303 foreach (QListWidget *w, m_stateListMap) {
Chris@94 304 w->clearSelection();
Chris@94 305 }
Chris@94 306 }
Chris@94 307
Chris@95 308 bool FileStatusWidget::haveChangesToCommit() const
Chris@95 309 {
Chris@326 310 return !getAllCommittableFiles().empty();
Chris@95 311 }
Chris@95 312
Chris@95 313 bool FileStatusWidget::haveSelection() const
Chris@95 314 {
Chris@95 315 return !m_selectedFiles.empty();
Chris@95 316 }
Chris@95 317
Chris@326 318 QStringList FileStatusWidget::getSelectedFilesInState(FileStates::State s) const
Chris@95 319 {
Chris@95 320 QStringList files;
Chris@95 321 foreach (QString f, m_selectedFiles) {
Chris@326 322 if (m_fileStates.stateOf(f) == s) files.push_back(f);
Chris@95 323 }
Chris@95 324 return files;
Chris@326 325 }
Chris@326 326
Chris@326 327 QStringList FileStatusWidget::getSelectedFilesSupportingActivity(FileStates::Activity a) const
Chris@326 328 {
Chris@326 329 QStringList files;
Chris@326 330 foreach (QString f, m_selectedFiles) {
Chris@326 331 if (m_fileStates.supportsActivity(f, a)) files.push_back(f);
Chris@326 332 }
Chris@326 333 return files;
Chris@326 334 }
Chris@95 335
Chris@103 336 QStringList FileStatusWidget::getAllCommittableFiles() const
Chris@103 337 {
Chris@326 338 return m_fileStates.filesSupportingActivity(FileStates::Commit);
Chris@109 339 }
Chris@109 340
Chris@109 341 QStringList FileStatusWidget::getAllRevertableFiles() const
Chris@109 342 {
Chris@326 343 return m_fileStates.filesSupportingActivity(FileStates::Revert);
Chris@163 344 }
Chris@163 345
Chris@163 346 QStringList FileStatusWidget::getAllUnresolvedFiles() const
Chris@163 347 {
Chris@326 348 return m_fileStates.filesInState(FileStates::InConflict);
Chris@109 349 }
Chris@109 350
Chris@95 351 QStringList FileStatusWidget::getSelectedAddableFiles() const
Chris@95 352 {
Chris@326 353 return getSelectedFilesSupportingActivity(FileStates::Add);
Chris@103 354 }
Chris@103 355
Chris@95 356 QStringList FileStatusWidget::getSelectedRemovableFiles() const
Chris@95 357 {
Chris@326 358 return getSelectedFilesSupportingActivity(FileStates::Remove);
Chris@103 359 }
Chris@103 360
Chris@283 361 QString
Chris@283 362 FileStatusWidget::localPath() const
Chris@283 363 {
Chris@287 364 return m_localPath;
Chris@283 365 }
Chris@283 366
Chris@88 367 void
Chris@88 368 FileStatusWidget::setLocalPath(QString p)
Chris@88 369 {
Chris@287 370 m_localPath = p;
Chris@93 371 delete m_dateReference;
Chris@93 372 m_dateReference = new QFileInfo(p + "/.hg/dirstate");
Chris@93 373 if (!m_dateReference->exists() ||
Chris@93 374 !m_dateReference->isFile() ||
Chris@93 375 !m_dateReference->isReadable()) {
Chris@93 376 DEBUG << "FileStatusWidget::setLocalPath: date reference file "
Chris@93 377 << m_dateReference->absoluteFilePath()
Chris@93 378 << " does not exist, is not a file, or cannot be read"
Chris@93 379 << endl;
Chris@93 380 delete m_dateReference;
Chris@93 381 m_dateReference = 0;
Chris@340 382 m_showAllFiles->setEnabled(false);
Chris@340 383 } else {
Chris@340 384 m_showAllFiles->setEnabled(true);
Chris@93 385 }
Chris@283 386 }
Chris@283 387
Chris@88 388 void
Chris@92 389 FileStatusWidget::setFileStates(FileStates p)
Chris@88 390 {
Chris@92 391 m_fileStates = p;
Chris@88 392 updateWidgets();
Chris@88 393 }
Chris@88 394
Chris@88 395 void
Chris@88 396 FileStatusWidget::updateWidgets()
Chris@88 397 {
Chris@95 398 QDateTime lastInteractionTime;
Chris@95 399 if (m_dateReference) {
Chris@95 400 lastInteractionTime = m_dateReference->lastModified();
Chris@95 401 DEBUG << "reference time: " << lastInteractionTime << endl;
Chris@95 402 }
Chris@95 403
Chris@95 404 QSet<QString> selectedFiles;
Chris@95 405 foreach (QString f, m_selectedFiles) selectedFiles.insert(f);
Chris@95 406
Chris@230 407 int visibleCount = 0;
Chris@115 408
Chris@94 409 foreach (FileStates::State s, m_stateListMap.keys()) {
Chris@95 410
Chris@94 411 QListWidget *w = m_stateListMap[s];
Chris@94 412 w->clear();
Chris@324 413 QStringList files = m_fileStates.filesInState(s);
Chris@93 414
Chris@95 415 QStringList highPriority, lowPriority;
Chris@95 416
Chris@95 417 foreach (QString file, files) {
Chris@95 418
Chris@95 419 bool highlighted = false;
Chris@95 420
Chris@95 421 if (s == FileStates::Unknown) {
Chris@95 422 // We want to highlight untracked files that have appeared
Chris@95 423 // since the last interaction with the repo
Chris@287 424 QString fn(m_localPath + "/" + file);
Chris@95 425 DEBUG << "comparing with " << fn << endl;
Chris@95 426 QFileInfo fi(fn);
Chris@100 427 if (fi.exists() && fi.created() > lastInteractionTime) {
Chris@95 428 DEBUG << "file " << fn << " is newer (" << fi.lastModified()
Chris@95 429 << ") than reference" << endl;
Chris@95 430 highlighted = true;
Chris@95 431 }
Chris@95 432 }
Chris@95 433
Chris@95 434 if (highlighted) {
Chris@95 435 highPriority.push_back(file);
Chris@95 436 } else {
Chris@95 437 lowPriority.push_back(file);
Chris@93 438 }
Chris@93 439 }
Chris@95 440
Chris@95 441 foreach (QString file, highPriority) {
Chris@95 442 QListWidgetItem *item = new QListWidgetItem(file);
Chris@95 443 w->addItem(item);
Chris@326 444 item->setForeground(QColor("#d40000"));
Chris@95 445 item->setSelected(selectedFiles.contains(file));
Chris@95 446 }
Chris@95 447
Chris@95 448 foreach (QString file, lowPriority) {
Chris@95 449 QListWidgetItem *item = new QListWidgetItem(file);
Chris@95 450 w->addItem(item);
Chris@95 451 item->setSelected(selectedFiles.contains(file));
Chris@95 452 }
Chris@95 453
Chris@100 454 setLabelFor(w, s, !highPriority.empty());
Chris@100 455
Chris@115 456 if (files.empty()) {
Chris@115 457 w->parentWidget()->hide();
Chris@115 458 } else {
Chris@115 459 w->parentWidget()->show();
Chris@230 460 ++visibleCount;
Chris@115 461 }
Chris@93 462 }
Chris@115 463
Chris@230 464 m_noModificationsLabel->setVisible(visibleCount == 0);
Chris@230 465
Chris@230 466 if (visibleCount > 3) {
Chris@230 467 layoutBoxesGridly(visibleCount);
Chris@230 468 } else {
Chris@230 469 layoutBoxesLinearly();
Chris@230 470 }
Chris@115 471
Chris@230 472 setNoModificationsLabelText();
Chris@230 473 }
Chris@230 474
Chris@230 475 void FileStatusWidget::layoutBoxesGridly(int visibleCount)
Chris@230 476 {
Chris@230 477 if (m_gridlyLayout && m_lastGridlyCount == visibleCount) return;
Chris@230 478
Chris@230 479 delete m_boxesParent->layout();
Chris@230 480
Chris@230 481 QGridLayout *layout = new QGridLayout;
Chris@230 482 layout->setMargin(0);
Chris@230 483 m_boxesParent->setLayout(layout);
Chris@230 484
Chris@230 485 int row = 0;
Chris@230 486 int col = 0;
Chris@230 487
Chris@230 488 DEBUG << "FileStatusWidget::layoutBoxesGridly: visibleCount = "
Chris@230 489 << visibleCount << endl;
Chris@230 490
Chris@230 491 for (int i = 0; i < m_boxes.size(); ++i) {
Chris@230 492
Chris@230 493 if (!m_boxes[i]->isVisible()) continue;
Chris@230 494
Chris@230 495 if (col == 0 && row >= (visibleCount+1)/2) {
Chris@230 496 layout->addItem(new QSpacerItem(10, 5), 0, 1);
Chris@230 497 col = 2;
Chris@230 498 row = 0;
Chris@230 499 }
Chris@230 500
Chris@230 501 layout->addWidget(m_boxes[i], row, col);
Chris@230 502
Chris@230 503 ++row;
Chris@230 504 }
Chris@230 505
Chris@230 506 m_gridlyLayout = true;
Chris@230 507 m_lastGridlyCount = visibleCount;
Chris@230 508 }
Chris@230 509
Chris@230 510 void FileStatusWidget::layoutBoxesLinearly()
Chris@230 511 {
Chris@230 512 if (!m_gridlyLayout) return;
Chris@230 513
Chris@230 514 delete m_boxesParent->layout();
Chris@230 515
Chris@230 516 QGridLayout *layout = new QGridLayout;
Chris@230 517 layout->setMargin(0);
Chris@230 518 m_boxesParent->setLayout(layout);
Chris@230 519
Chris@230 520 for (int i = 0; i < m_boxes.size(); ++i) {
Chris@230 521 layout->addWidget(m_boxes[i], i, 0);
Chris@230 522 }
Chris@230 523
Chris@230 524 m_gridlyLayout = false;
Chris@88 525 }
Chris@88 526
Chris@100 527 void FileStatusWidget::setLabelFor(QWidget *w, FileStates::State s, bool addHighlight)
Chris@100 528 {
Chris@100 529 QString text = labelFor(s, addHighlight);
Chris@100 530 QWidget *p = w->parentWidget();
Chris@100 531 QList<QLabel *> ql = p->findChildren<QLabel *>();
Chris@100 532 if (!ql.empty()) ql[0]->setText(text);
Chris@100 533 }
Chris@115 534