# HG changeset patch # User Chris Cannam # Date 1294326902 0 # Node ID e67bd8abc3e331ab194892b536c62efc95d19b8b # Parent a1f4b53590519f6a95beb2a62fa874ca34a852af * Add settings for text verboseness and toolbar labels diff -r a1f4b5359051 -r e67bd8abc3e3 filestatuswidget.cpp --- a/filestatuswidget.cpp Thu Jan 06 13:16:34 2011 +0000 +++ b/filestatuswidget.cpp Thu Jan 06 15:15:02 2011 +0000 @@ -31,6 +31,7 @@ #include #include #include +#include FileStatusWidget::FileStatusWidget(QWidget *parent) : QWidget(parent), @@ -72,17 +73,9 @@ layout->addWidget(new QLabel("
"), ++row, 0, 1, 3); ++row; - //!!! option to be less verbose -> shorten this - m_noModificationsLabel = new QLabel - (tr("This area will list files in your working folder that you have changed.

At the moment you have no uncommitted changes.

To see changes previously made to the repository,
switch to the History tab.

%1
") -#if defined Q_OS_MAC - .arg(tr("To open the working folder in Finder,
click on the “Local” folder path shown above.")) -#elif defined Q_OS_WIN32 - .arg(tr("To open the working folder in Windows Explorer,
click on the “Local” folder path shown above.")) -#else - .arg(tr("To open the working folder in your system file manager,
click the “Local” folder path shown above.")) -#endif - ); + + m_noModificationsLabel = new QLabel; + setNoModificationsLabelText(); layout->addWidget(m_noModificationsLabel, row, 1, 1, 2); m_noModificationsLabel->hide(); @@ -113,19 +106,29 @@ m_highlightExplanation = tr("Files highlighted in red " "have appeared since your most recent commit or update."); + m_boxesParent = new QWidget(this); + layout->addWidget(m_boxesParent, ++row, 0, 1, 3); + + QGridLayout *boxesLayout = new QGridLayout; + boxesLayout->setMargin(0); + m_boxesParent->setLayout(boxesLayout); + int boxRow = 0; + for (int i = int(FileStates::FirstState); i <= int(FileStates::LastState); ++i) { FileStates::State s = FileStates::State(i); - QWidget *box = new QWidget; + QWidget *box = new QWidget(m_boxesParent); QGridLayout *boxlayout = new QGridLayout; boxlayout->setMargin(0); box->setLayout(boxlayout); boxlayout->addItem(new QSpacerItem(3, 3), 0, 0); - boxlayout->addWidget(new QLabel(labelFor(s)), 1, 0); + QLabel *label = new QLabel(labelFor(s)); + label->setWordWrap(true); + boxlayout->addWidget(label, 1, 0); QListWidget *w = new QListWidget; m_stateListMap[s] = w; @@ -137,10 +140,13 @@ boxlayout->addItem(new QSpacerItem(2, 2), 3, 0); - layout->addWidget(box, ++row, 0, 1, 3); + boxesLayout->addWidget(box, ++boxRow, 0); + m_boxes.push_back(box); box->hide(); } + m_gridlyLayout = false; + layout->setRowStretch(++row, 20); layout->addItem(new QSpacerItem(8, 8), ++row, 0); @@ -184,15 +190,44 @@ QString FileStatusWidget::labelFor(FileStates::State s, bool addHighlightExplanation) { - if (addHighlightExplanation) { - return QString("%1
%2
%3
") - .arg(m_simpleLabels[s]) - .arg(m_descriptions[s]) - .arg(m_highlightExplanation); + QSettings settings; + settings.beginGroup("Presentation"); + if (settings.value("showhelpfultext", true).toBool()) { + if (addHighlightExplanation) { + return QString("%1
%2
%3
") + .arg(m_simpleLabels[s]) + .arg(m_descriptions[s]) + .arg(m_highlightExplanation); + } else { + return QString("%1
%2
") + .arg(m_simpleLabels[s]) + .arg(m_descriptions[s]); + } } else { - return QString("%1
%2
") - .arg(m_simpleLabels[s]) - .arg(m_descriptions[s]); + return QString("%1") + .arg(m_simpleLabels[s]); + } + settings.endGroup(); +} + +void FileStatusWidget::setNoModificationsLabelText() +{ + QSettings settings; + settings.beginGroup("Presentation"); + if (settings.value("showhelpfultext", true).toBool()) { + m_noModificationsLabel->setText + (tr("This area will list files in your working folder that you have changed.

At the moment you have no uncommitted changes.

To see changes previously made to the repository,
switch to the History tab.

%1
") +#if defined Q_OS_MAC + .arg(tr("To open the working folder in Finder,
click on the “Local” folder path shown above.")) +#elif defined Q_OS_WIN32 + .arg(tr("To open the working folder in Windows Explorer,
click on the “Local” folder path shown above.")) +#else + .arg(tr("To open the working folder in your system file manager,
click the “Local” folder path shown above.")) +#endif + ); + } else { + m_noModificationsLabel->setText + (tr("You have no uncommitted changes.")); } } @@ -430,7 +465,7 @@ QSet selectedFiles; foreach (QString f, m_selectedFiles) selectedFiles.insert(f); - bool haveAnything = false; + int visibleCount = 0; foreach (FileStates::State s, m_stateListMap.keys()) { @@ -483,13 +518,72 @@ w->parentWidget()->hide(); } else { w->parentWidget()->show(); - haveAnything = true; + ++visibleCount; } } - m_noModificationsLabel->setVisible(!haveAnything); + m_noModificationsLabel->setVisible(visibleCount == 0); + + if (visibleCount > 3) { + layoutBoxesGridly(visibleCount); + } else { + layoutBoxesLinearly(); + } updateStateLabel(); + setNoModificationsLabelText(); +} + +void FileStatusWidget::layoutBoxesGridly(int visibleCount) +{ + if (m_gridlyLayout && m_lastGridlyCount == visibleCount) return; + + delete m_boxesParent->layout(); + + QGridLayout *layout = new QGridLayout; + layout->setMargin(0); + m_boxesParent->setLayout(layout); + + int row = 0; + int col = 0; + + DEBUG << "FileStatusWidget::layoutBoxesGridly: visibleCount = " + << visibleCount << endl; + + for (int i = 0; i < m_boxes.size(); ++i) { + + if (!m_boxes[i]->isVisible()) continue; + + if (col == 0 && row >= (visibleCount+1)/2) { + layout->addItem(new QSpacerItem(10, 5), 0, 1); + col = 2; + row = 0; + } + + layout->addWidget(m_boxes[i], row, col); + + ++row; + } + + m_gridlyLayout = true; + m_lastGridlyCount = visibleCount; +} + +void FileStatusWidget::layoutBoxesLinearly() +{ + if (!m_gridlyLayout) return; + + delete m_boxesParent->layout(); + + QGridLayout *layout = new QGridLayout; + layout->setMargin(0); + m_boxesParent->setLayout(layout); + + for (int i = 0; i < m_boxes.size(); ++i) { + layout->addWidget(m_boxes[i], i, 0); + } + + m_gridlyLayout = false; } void FileStatusWidget::setLabelFor(QWidget *w, FileStates::State s, bool addHighlight) diff -r a1f4b5359051 -r e67bd8abc3e3 filestatuswidget.h --- a/filestatuswidget.h Thu Jan 06 13:16:34 2011 +0000 +++ b/filestatuswidget.h Thu Jan 06 15:15:02 2011 +0000 @@ -21,6 +21,7 @@ #include "filestates.h" #include +#include class QLabel; class QListWidget; @@ -75,6 +76,7 @@ public slots: void clearSelections(); + void updateWidgets(); private slots: void itemSelectionChanged(); @@ -103,8 +105,15 @@ QFileInfo *m_dateReference; QStringList m_selectedFiles; - void updateWidgets(); + bool m_gridlyLayout; + int m_lastGridlyCount; + QList m_boxes; + QWidget *m_boxesParent; + + void layoutBoxesGridly(int count); + void layoutBoxesLinearly(); void updateStateLabel(); + void setNoModificationsLabelText(); QString labelFor(FileStates::State, bool addHighlightExplanation = false); void setLabelFor(QWidget *w, FileStates::State, bool addHighlightExplanation); }; diff -r a1f4b5359051 -r e67bd8abc3e3 hgtabwidget.cpp --- a/hgtabwidget.cpp Thu Jan 06 13:16:34 2011 +0000 +++ b/hgtabwidget.cpp Thu Jan 06 15:15:02 2011 +0000 @@ -87,6 +87,11 @@ m_historyWidget->setCurrent(ids, branch, showUncommitted); } +void HgTabWidget::updateFileStates() +{ + m_fileStatusWidget->updateWidgets(); +} + void HgTabWidget::updateHistory() { m_historyWidget->update(); diff -r a1f4b5359051 -r e67bd8abc3e3 hgtabwidget.h --- a/hgtabwidget.h Thu Jan 06 13:16:34 2011 +0000 +++ b/hgtabwidget.h Thu Jan 06 15:15:02 2011 +0000 @@ -50,6 +50,7 @@ void setCurrent(QStringList ids, QString branch); + void updateFileStates(); void updateHistory(); FileStates getFileStates() { return m_fileStates; } diff -r a1f4b5359051 -r e67bd8abc3e3 mainwindow.cpp --- a/mainwindow.cpp Thu Jan 06 13:16:34 2011 +0000 +++ b/mainwindow.cpp Thu Jan 06 15:15:02 2011 +0000 @@ -1312,6 +1312,11 @@ { SettingsDialog *settingsDlg = new SettingsDialog(this); settingsDlg->exec(); + + if (settingsDlg->presentationChanged()) { + hgTabs->updateFileStates(); + updateToolBarStyle(); + } } #define STDOUT_NEEDS_BIG_WINDOW 512 @@ -2240,11 +2245,22 @@ workFolderToolBar->addAction(hgRemoveAct); workFolderToolBar -> setMovable(false); - foreach (QToolButton *tb, findChildren()) { - tb->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - } + updateToolBarStyle(); } +void MainWindow::updateToolBarStyle() +{ + QSettings settings; + settings.beginGroup("Presentation"); + bool showText = settings.value("showiconlabels", true).toBool(); + settings.endGroup(); + + foreach (QToolButton *tb, findChildren()) { + tb->setToolButtonStyle(showText ? + Qt::ToolButtonTextUnderIcon : + Qt::ToolButtonIconOnly); + } +} void MainWindow::createStatusBar() { diff -r a1f4b5359051 -r e67bd8abc3e3 mainwindow.h --- a/mainwindow.h Thu Jan 06 13:16:34 2011 +0000 +++ b/mainwindow.h Thu Jan 06 15:15:02 2011 +0000 @@ -116,6 +116,7 @@ void connectTabsSignals(); void createMenus(); void createToolBars(); + void updateToolBarStyle(); void createStatusBar(); void readSettings(); void splitChangeSets(QStringList *list, QString hgLogOutput); diff -r a1f4b5359051 -r e67bd8abc3e3 settingsdialog.cpp --- a/settingsdialog.cpp Thu Jan 06 13:16:34 2011 +0000 +++ b/settingsdialog.cpp Thu Jan 06 15:15:02 2011 +0000 @@ -27,7 +27,8 @@ #include SettingsDialog::SettingsDialog(QWidget *parent) : - QDialog(parent) + QDialog(parent), + m_presentationChanged(false) { setModal(true); setWindowTitle(tr("Settings")); @@ -37,6 +38,8 @@ QGridLayout *mainLayout = new QGridLayout; setLayout(mainLayout); + + QGroupBox *meBox = new QGroupBox(tr("User details")); mainLayout->addWidget(meBox, 0, 0); QGridLayout *meLayout = new QGridLayout; @@ -60,8 +63,31 @@ settings.endGroup(); + + + QGroupBox *lookBox = new QGroupBox(tr("Presentation")); + mainLayout->addWidget(lookBox, 1, 0); + QGridLayout *lookLayout = new QGridLayout; + lookBox->setLayout(lookLayout); + + settings.beginGroup("Presentation"); + + row = 0; + + m_showIconLabels = new QCheckBox(tr("Show labels on toolbar icons")); + m_showIconLabels->setChecked(settings.value("showiconlabels", true).toBool()); + lookLayout->addWidget(m_showIconLabels, row++, 0); + + m_showExtraText = new QCheckBox(tr("Show long descriptions for file status headings")); + m_showExtraText->setChecked(settings.value("showhelpfultext", true).toBool()); + lookLayout->addWidget(m_showExtraText, row++, 0); + + settings.endGroup(); + + + QGroupBox *pathsBox = new QGroupBox(tr("System application locations")); - mainLayout->addWidget(pathsBox, 1, 0); + mainLayout->addWidget(pathsBox, 2, 0); QGridLayout *pathsLayout = new QGridLayout; pathsBox->setLayout(pathsLayout); @@ -135,9 +161,10 @@ settings.endGroup(); + QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok); connect(bbox, SIGNAL(accepted()), this, SLOT(accept())); - mainLayout->addWidget(bbox, 2, 0); + mainLayout->addWidget(bbox, 3, 0); m_ok = bbox->button(QDialogButtonBox::Ok); } @@ -199,6 +226,19 @@ settings.setValue("name", m_nameEdit->text()); settings.setValue("email", m_emailEdit->text()); settings.endGroup(); + settings.beginGroup("Presentation"); + bool b; + b = m_showIconLabels->isChecked(); + if (b != settings.value("showiconlabels", true)) { + settings.setValue("showiconlabels", b); + m_presentationChanged = true; + } + b = m_showExtraText->isChecked(); + if (b != settings.value("showhelpfultext", true)) { + settings.setValue("showhelpfultext", b); + m_presentationChanged = true; + } + settings.endGroup(); settings.beginGroup("Locations"); settings.setValue("hgbinary", m_hgPathLabel->text()); settings.setValue("extdiffbinary", m_diffPathLabel->text()); diff -r a1f4b5359051 -r e67bd8abc3e3 settingsdialog.h --- a/settingsdialog.h Thu Jan 06 13:16:34 2011 +0000 +++ b/settingsdialog.h Thu Jan 06 15:15:02 2011 +0000 @@ -30,6 +30,10 @@ public: SettingsDialog(QWidget *parent = 0); + + bool presentationChanged() { + return m_presentationChanged; + } private slots: void hgPathBrowse(); @@ -51,8 +55,13 @@ QCheckBox *m_useExtension; QLineEdit *m_extensionPathLabel; + QCheckBox *m_showIconLabels; + QCheckBox *m_showExtraText; + QPushButton *m_ok; + bool m_presentationChanged; + void browseFor(QString, QLineEdit *); };