changeset 231:6c5a06da0ab9

Merge
author Chris Cannam
date Thu, 06 Jan 2011 15:15:43 +0000
parents e67bd8abc3e3 (diff) 1b2ee42fa004 (current diff)
children 41ae9544a255
files
diffstat 9 files changed, 226 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/filestatuswidget.cpp	Thu Jan 06 14:17:35 2011 +0000
+++ b/filestatuswidget.cpp	Thu Jan 06 15:15:43 2011 +0000
@@ -31,6 +31,7 @@
 #include <QDir>
 #include <QProcess>
 #include <QCheckBox>
+#include <QSettings>
 
 FileStatusWidget::FileStatusWidget(QWidget *parent) :
     QWidget(parent),
@@ -72,17 +73,9 @@
     layout->addWidget(new QLabel("<qt><hr></qt>"), ++row, 0, 1, 3);
 
     ++row;
-    //!!! option to be less verbose -> shorten this
-    m_noModificationsLabel = new QLabel
-        (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>")
-#if defined Q_OS_MAC
-         .arg(tr("To open the working folder in Finder,<br>click on the &ldquo;Local&rdquo; folder path shown above."))
-#elif defined Q_OS_WIN32
-         .arg(tr("To open the working folder in Windows Explorer,<br>click on the &ldquo;Local&rdquo; folder path shown above."))
-#else
-         .arg(tr("To open the working folder in your system file manager,<br>click the &ldquo;Local&rdquo; folder path shown above."))
-#endif
-            );
+
+    m_noModificationsLabel = new QLabel;
+    setNoModificationsLabelText();
     layout->addWidget(m_noModificationsLabel, row, 1, 1, 2);
     m_noModificationsLabel->hide();
 
@@ -97,8 +90,8 @@
 
     m_descriptions[FileStates::Clean] = tr("You have not changed these files.");
     m_descriptions[FileStates::Modified] = tr("You have changed these files since you last committed them.");
-    m_descriptions[FileStates::Added] = tr("These files will be added to version control next time you commit.");
-    m_descriptions[FileStates::Removed] = tr("These files will be removed from version control next time you commit.<br>"
+    m_descriptions[FileStates::Added] = tr("These files will be added to version control next time you commit them.");
+    m_descriptions[FileStates::Removed] = tr("These files will be removed from version control next time you commit them.<br>"
                                              "They will not be deleted from the local folder.");
     m_descriptions[FileStates::Missing] = tr("These files are recorded in the version control, but absent from your working folder.<br>"
                                              "If you intended to delete them, select them and use Remove to tell the version control system about it.<br>"
@@ -113,19 +106,29 @@
     m_highlightExplanation = tr("Files highlighted <font color=#d40000>in red</font> "
                                 "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("<qt><b>%1</b><br>%2<br>%3</qt>")
-                       .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("<qt><b>%1</b><br>%2<br>%3</qt>")
+                .arg(m_simpleLabels[s])
+                .arg(m_descriptions[s])
+                .arg(m_highlightExplanation);
+        } else {
+            return QString("<qt><b>%1</b><br>%2</qt>")
+                .arg(m_simpleLabels[s])
+                .arg(m_descriptions[s]);
+        }
     } else {
-        return QString("<qt><b>%1</b><br>%2</qt>")
-                       .arg(m_simpleLabels[s])
-                       .arg(m_descriptions[s]);
+        return QString("<qt><b>%1</b></qt>")
+            .arg(m_simpleLabels[s]);
+    }
+    settings.endGroup();
+}
+
+void FileStatusWidget::setNoModificationsLabelText()
+{
+    QSettings settings;
+    settings.beginGroup("Presentation");
+    if (settings.value("showhelpfultext", true).toBool()) {
+        m_noModificationsLabel->setText
+            (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>")
+#if defined Q_OS_MAC
+             .arg(tr("To open the working folder in Finder,<br>click on the &ldquo;Local&rdquo; folder path shown above."))
+#elif defined Q_OS_WIN32
+             .arg(tr("To open the working folder in Windows Explorer,<br>click on the &ldquo;Local&rdquo; folder path shown above."))
+#else
+             .arg(tr("To open the working folder in your system file manager,<br>click the &ldquo;Local&rdquo; folder path shown above."))
+#endif
+                );
+    } else {
+        m_noModificationsLabel->setText
+            (tr("<qt>You have no uncommitted changes.</qt>"));
     }
 }
 
@@ -430,7 +465,7 @@
     QSet<QString> 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)
--- a/filestatuswidget.h	Thu Jan 06 14:17:35 2011 +0000
+++ b/filestatuswidget.h	Thu Jan 06 15:15:43 2011 +0000
@@ -21,6 +21,7 @@
 #include "filestates.h"
 
 #include <QWidget>
+#include <QList>
 
 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<QWidget *> 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);
 };
--- a/hgtabwidget.cpp	Thu Jan 06 14:17:35 2011 +0000
+++ b/hgtabwidget.cpp	Thu Jan 06 15:15:43 2011 +0000
@@ -87,6 +87,11 @@
     m_historyWidget->setCurrent(ids, branch, showUncommitted);
 }
 
+void HgTabWidget::updateFileStates()
+{
+    m_fileStatusWidget->updateWidgets();
+}
+
 void HgTabWidget::updateHistory()
 {
     m_historyWidget->update();
--- a/hgtabwidget.h	Thu Jan 06 14:17:35 2011 +0000
+++ b/hgtabwidget.h	Thu Jan 06 15:15:43 2011 +0000
@@ -50,6 +50,7 @@
 
     void setCurrent(QStringList ids, QString branch);
 
+    void updateFileStates();
     void updateHistory();
 
     FileStates getFileStates() { return m_fileStates; }
--- a/mainwindow.cpp	Thu Jan 06 14:17:35 2011 +0000
+++ b/mainwindow.cpp	Thu Jan 06 15:15:43 2011 +0000
@@ -41,6 +41,7 @@
 #include "confirmcommentdialog.h"
 #include "incomingdialog.h"
 #include "settingsdialog.h"
+#include "version.h"
 
 
 MainWindow::MainWindow(QString myDirPath) :
@@ -154,7 +155,7 @@
 void MainWindow::about()
 {
    QMessageBox::about(this, tr("About EasyMercurial"),
-                      tr("<qt><h2>About EasyMercurial</h2>"
+                      tr("<qt><h2>EasyMercurial v%1</h2>"
 #ifdef Q_OS_MAC
                          "<font size=-1>"
 #endif
@@ -188,7 +189,7 @@
 #ifdef Q_OS_MAC
                          "</font>"
 #endif
-                         ));
+                          ).arg(EASYHG_VERSION));
 }
 
 void MainWindow::clearSelections()
@@ -1311,6 +1312,11 @@
 {
     SettingsDialog *settingsDlg = new SettingsDialog(this);
     settingsDlg->exec();
+
+    if (settingsDlg->presentationChanged()) {
+        hgTabs->updateFileStates();
+        updateToolBarStyle();
+    }
 }
 
 #define STDOUT_NEEDS_BIG_WINDOW 512
@@ -2030,6 +2036,7 @@
     bool canUpdate = false;
     bool haveMerge = false;
     bool emptyRepo = false;
+    bool noWorkingCopy = false;
     int currentBranchHeads = 0;
 
     if (currentParents.size() == 1) {
@@ -2056,7 +2063,16 @@
             }
         }
     } else if (currentParents.size() == 0) {
-        emptyRepo = true;
+        if (currentHeads.size() == 0) {
+            // No heads -> empty repo
+            emptyRepo = true;
+        } else {
+            // Heads, but no parents -> no working copy, e.g. we have
+            // just converted this repo but haven't updated in it yet.
+            // Uncommon but confusing; probably merits a special case
+            noWorkingCopy = true;
+            canUpdate = true;
+        }
     } else {
         haveMerge = true;
         justMerged = true;
@@ -2080,6 +2096,8 @@
         hgTabs->setState(tr("(Examining repository)"));
     } else if (emptyRepo) {
         hgTabs->setState(tr("Nothing committed to this repository yet"));
+    } else if (noWorkingCopy) {
+        hgTabs->setState(tr("No working copy yet: consider updating"));
     } else if (canMerge) {
         hgTabs->setState(tr("<b>Awaiting merge</b> on %1").arg(branchText));
     } else if (!hgTabs->getAllUnresolvedFiles().empty()) {
@@ -2227,11 +2245,22 @@
     workFolderToolBar->addAction(hgRemoveAct);
     workFolderToolBar -> setMovable(false);
 
-    foreach (QToolButton *tb, findChildren<QToolButton *>()) {
-        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<QToolButton *>()) {
+        tb->setToolButtonStyle(showText ?
+                               Qt::ToolButtonTextUnderIcon :
+                               Qt::ToolButtonIconOnly);
+    }
+}    
 
 void MainWindow::createStatusBar()
 {
--- a/mainwindow.h	Thu Jan 06 14:17:35 2011 +0000
+++ b/mainwindow.h	Thu Jan 06 15:15:43 2011 +0000
@@ -116,6 +116,7 @@
     void connectTabsSignals();
     void createMenus();
     void createToolBars();
+    void updateToolBarStyle();
     void createStatusBar();
     void readSettings();
     void splitChangeSets(QStringList *list, QString hgLogOutput);
--- a/settingsdialog.cpp	Thu Jan 06 14:17:35 2011 +0000
+++ b/settingsdialog.cpp	Thu Jan 06 15:15:43 2011 +0000
@@ -27,7 +27,8 @@
 #include <QFileDialog>
 
 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());
--- a/settingsdialog.h	Thu Jan 06 14:17:35 2011 +0000
+++ b/settingsdialog.h	Thu Jan 06 15:15:43 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 *);
 };
 
--- a/version.h	Thu Jan 06 14:17:35 2011 +0000
+++ b/version.h	Thu Jan 06 15:15:43 2011 +0000
@@ -1,1 +1,1 @@
-#define EASYHG_VERSION                      "0.8"
+#define EASYHG_VERSION "0.1"