comparison filestatuswidget.cpp @ 230:e67bd8abc3e3

* Add settings for text verboseness and toolbar labels
author Chris Cannam
date Thu, 06 Jan 2011 15:15:02 +0000
parents 05255f23f2af
children 8fd71f570884
comparison
equal deleted inserted replaced
229:a1f4b5359051 230:e67bd8abc3e3
29 #include <QPushButton> 29 #include <QPushButton>
30 #include <QToolButton> 30 #include <QToolButton>
31 #include <QDir> 31 #include <QDir>
32 #include <QProcess> 32 #include <QProcess>
33 #include <QCheckBox> 33 #include <QCheckBox>
34 #include <QSettings>
34 35
35 FileStatusWidget::FileStatusWidget(QWidget *parent) : 36 FileStatusWidget::FileStatusWidget(QWidget *parent) :
36 QWidget(parent), 37 QWidget(parent),
37 m_dateReference(0) 38 m_dateReference(0)
38 { 39 {
70 layout->setColumnStretch(1, 20); 71 layout->setColumnStretch(1, 20);
71 72
72 layout->addWidget(new QLabel("<qt><hr></qt>"), ++row, 0, 1, 3); 73 layout->addWidget(new QLabel("<qt><hr></qt>"), ++row, 0, 1, 3);
73 74
74 ++row; 75 ++row;
75 //!!! option to be less verbose -> shorten this 76
76 m_noModificationsLabel = new QLabel 77 m_noModificationsLabel = new QLabel;
77 (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>") 78 setNoModificationsLabelText();
78 #if defined Q_OS_MAC
79 .arg(tr("To open the working folder in Finder,<br>click on the &ldquo;Local&rdquo; folder path shown above."))
80 #elif defined Q_OS_WIN32
81 .arg(tr("To open the working folder in Windows Explorer,<br>click on the &ldquo;Local&rdquo; folder path shown above."))
82 #else
83 .arg(tr("To open the working folder in your system file manager,<br>click the &ldquo;Local&rdquo; folder path shown above."))
84 #endif
85 );
86 layout->addWidget(m_noModificationsLabel, row, 1, 1, 2); 79 layout->addWidget(m_noModificationsLabel, row, 1, 1, 2);
87 m_noModificationsLabel->hide(); 80 m_noModificationsLabel->hide();
88 81
89 m_simpleLabels[FileStates::Clean] = tr("Unmodified:"); 82 m_simpleLabels[FileStates::Clean] = tr("Unmodified:");
90 m_simpleLabels[FileStates::Modified] = tr("Modified:"); 83 m_simpleLabels[FileStates::Modified] = tr("Modified:");
111 "and so will be ignored by the version control system."); 104 "and so will be ignored by the version control system.");
112 105
113 m_highlightExplanation = tr("Files highlighted <font color=#d40000>in red</font> " 106 m_highlightExplanation = tr("Files highlighted <font color=#d40000>in red</font> "
114 "have appeared since your most recent commit or update."); 107 "have appeared since your most recent commit or update.");
115 108
109 m_boxesParent = new QWidget(this);
110 layout->addWidget(m_boxesParent, ++row, 0, 1, 3);
111
112 QGridLayout *boxesLayout = new QGridLayout;
113 boxesLayout->setMargin(0);
114 m_boxesParent->setLayout(boxesLayout);
115 int boxRow = 0;
116
116 for (int i = int(FileStates::FirstState); 117 for (int i = int(FileStates::FirstState);
117 i <= int(FileStates::LastState); ++i) { 118 i <= int(FileStates::LastState); ++i) {
118 119
119 FileStates::State s = FileStates::State(i); 120 FileStates::State s = FileStates::State(i);
120 121
121 QWidget *box = new QWidget; 122 QWidget *box = new QWidget(m_boxesParent);
122 QGridLayout *boxlayout = new QGridLayout; 123 QGridLayout *boxlayout = new QGridLayout;
123 boxlayout->setMargin(0); 124 boxlayout->setMargin(0);
124 box->setLayout(boxlayout); 125 box->setLayout(boxlayout);
125 126
126 boxlayout->addItem(new QSpacerItem(3, 3), 0, 0); 127 boxlayout->addItem(new QSpacerItem(3, 3), 0, 0);
127 128
128 boxlayout->addWidget(new QLabel(labelFor(s)), 1, 0); 129 QLabel *label = new QLabel(labelFor(s));
130 label->setWordWrap(true);
131 boxlayout->addWidget(label, 1, 0);
129 132
130 QListWidget *w = new QListWidget; 133 QListWidget *w = new QListWidget;
131 m_stateListMap[s] = w; 134 m_stateListMap[s] = w;
132 w->setSelectionMode(QListWidget::ExtendedSelection); 135 w->setSelectionMode(QListWidget::ExtendedSelection);
133 boxlayout->addWidget(w, 2, 0); 136 boxlayout->addWidget(w, 2, 0);
135 connect(w, SIGNAL(itemSelectionChanged()), 138 connect(w, SIGNAL(itemSelectionChanged()),
136 this, SLOT(itemSelectionChanged())); 139 this, SLOT(itemSelectionChanged()));
137 140
138 boxlayout->addItem(new QSpacerItem(2, 2), 3, 0); 141 boxlayout->addItem(new QSpacerItem(2, 2), 3, 0);
139 142
140 layout->addWidget(box, ++row, 0, 1, 3); 143 boxesLayout->addWidget(box, ++boxRow, 0);
144 m_boxes.push_back(box);
141 box->hide(); 145 box->hide();
142 } 146 }
147
148 m_gridlyLayout = false;
143 149
144 layout->setRowStretch(++row, 20); 150 layout->setRowStretch(++row, 20);
145 151
146 layout->addItem(new QSpacerItem(8, 8), ++row, 0); 152 layout->addItem(new QSpacerItem(8, 8), ++row, 0);
147 153
182 } 188 }
183 } 189 }
184 190
185 QString FileStatusWidget::labelFor(FileStates::State s, bool addHighlightExplanation) 191 QString FileStatusWidget::labelFor(FileStates::State s, bool addHighlightExplanation)
186 { 192 {
187 if (addHighlightExplanation) { 193 QSettings settings;
188 return QString("<qt><b>%1</b><br>%2<br>%3</qt>") 194 settings.beginGroup("Presentation");
189 .arg(m_simpleLabels[s]) 195 if (settings.value("showhelpfultext", true).toBool()) {
190 .arg(m_descriptions[s]) 196 if (addHighlightExplanation) {
191 .arg(m_highlightExplanation); 197 return QString("<qt><b>%1</b><br>%2<br>%3</qt>")
198 .arg(m_simpleLabels[s])
199 .arg(m_descriptions[s])
200 .arg(m_highlightExplanation);
201 } else {
202 return QString("<qt><b>%1</b><br>%2</qt>")
203 .arg(m_simpleLabels[s])
204 .arg(m_descriptions[s]);
205 }
192 } else { 206 } else {
193 return QString("<qt><b>%1</b><br>%2</qt>") 207 return QString("<qt><b>%1</b></qt>")
194 .arg(m_simpleLabels[s]) 208 .arg(m_simpleLabels[s]);
195 .arg(m_descriptions[s]); 209 }
210 settings.endGroup();
211 }
212
213 void FileStatusWidget::setNoModificationsLabelText()
214 {
215 QSettings settings;
216 settings.beginGroup("Presentation");
217 if (settings.value("showhelpfultext", true).toBool()) {
218 m_noModificationsLabel->setText
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>")
220 #if defined Q_OS_MAC
221 .arg(tr("To open the working folder in Finder,<br>click on the &ldquo;Local&rdquo; folder path shown above."))
222 #elif defined Q_OS_WIN32
223 .arg(tr("To open the working folder in Windows Explorer,<br>click on the &ldquo;Local&rdquo; folder path shown above."))
224 #else
225 .arg(tr("To open the working folder in your system file manager,<br>click the &ldquo;Local&rdquo; folder path shown above."))
226 #endif
227 );
228 } else {
229 m_noModificationsLabel->setText
230 (tr("<qt>You have no uncommitted changes.</qt>"));
196 } 231 }
197 } 232 }
198 233
199 void FileStatusWidget::itemSelectionChanged() 234 void FileStatusWidget::itemSelectionChanged()
200 { 235 {
428 } 463 }
429 464
430 QSet<QString> selectedFiles; 465 QSet<QString> selectedFiles;
431 foreach (QString f, m_selectedFiles) selectedFiles.insert(f); 466 foreach (QString f, m_selectedFiles) selectedFiles.insert(f);
432 467
433 bool haveAnything = false; 468 int visibleCount = 0;
434 469
435 foreach (FileStates::State s, m_stateListMap.keys()) { 470 foreach (FileStates::State s, m_stateListMap.keys()) {
436 471
437 QListWidget *w = m_stateListMap[s]; 472 QListWidget *w = m_stateListMap[s];
438 w->clear(); 473 w->clear();
481 516
482 if (files.empty()) { 517 if (files.empty()) {
483 w->parentWidget()->hide(); 518 w->parentWidget()->hide();
484 } else { 519 } else {
485 w->parentWidget()->show(); 520 w->parentWidget()->show();
486 haveAnything = true; 521 ++visibleCount;
487 } 522 }
488 } 523 }
489 524
490 m_noModificationsLabel->setVisible(!haveAnything); 525 m_noModificationsLabel->setVisible(visibleCount == 0);
526
527 if (visibleCount > 3) {
528 layoutBoxesGridly(visibleCount);
529 } else {
530 layoutBoxesLinearly();
531 }
491 532
492 updateStateLabel(); 533 updateStateLabel();
534 setNoModificationsLabelText();
535 }
536
537 void FileStatusWidget::layoutBoxesGridly(int visibleCount)
538 {
539 if (m_gridlyLayout && m_lastGridlyCount == visibleCount) return;
540
541 delete m_boxesParent->layout();
542
543 QGridLayout *layout = new QGridLayout;
544 layout->setMargin(0);
545 m_boxesParent->setLayout(layout);
546
547 int row = 0;
548 int col = 0;
549
550 DEBUG << "FileStatusWidget::layoutBoxesGridly: visibleCount = "
551 << visibleCount << endl;
552
553 for (int i = 0; i < m_boxes.size(); ++i) {
554
555 if (!m_boxes[i]->isVisible()) continue;
556
557 if (col == 0 && row >= (visibleCount+1)/2) {
558 layout->addItem(new QSpacerItem(10, 5), 0, 1);
559 col = 2;
560 row = 0;
561 }
562
563 layout->addWidget(m_boxes[i], row, col);
564
565 ++row;
566 }
567
568 m_gridlyLayout = true;
569 m_lastGridlyCount = visibleCount;
570 }
571
572 void FileStatusWidget::layoutBoxesLinearly()
573 {
574 if (!m_gridlyLayout) return;
575
576 delete m_boxesParent->layout();
577
578 QGridLayout *layout = new QGridLayout;
579 layout->setMargin(0);
580 m_boxesParent->setLayout(layout);
581
582 for (int i = 0; i < m_boxes.size(); ++i) {
583 layout->addWidget(m_boxes[i], i, 0);
584 }
585
586 m_gridlyLayout = false;
493 } 587 }
494 588
495 void FileStatusWidget::setLabelFor(QWidget *w, FileStates::State s, bool addHighlight) 589 void FileStatusWidget::setLabelFor(QWidget *w, FileStates::State s, bool addHighlight)
496 { 590 {
497 QString text = labelFor(s, addHighlight); 591 QString text = labelFor(s, addHighlight);