annotate filestatuswidget.cpp @ 363:f89e50d748ed feature_93

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