Add action to toggle ‘visualize whitespaces’ in editors
authorErik Larsson <erik@ortogonal.com>
Sun, 15 Dec 2013 15:19:59 +0000 (16:19 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 23 Jan 2014 06:44:15 +0000 (07:44 +0100)
Add action, in ‘View’, that lets the user toggle the whitespace markers
in editors. Whitespace markers are the small dots/arrows etc. marking
spaces, tabs and new-lines. To some translators this can make it hard
to see the text, hence the reason for making it possible to toggle.

Change-Id: I484b51b078c84dacc1fe534b935dd9f8ce12de42
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
src/linguist/linguist/mainwindow.cpp
src/linguist/linguist/mainwindow.h
src/linguist/linguist/mainwindow.ui
src/linguist/linguist/messageeditor.cpp
src/linguist/linguist/messageeditor.h
src/linguist/linguist/messageeditorwidgets.cpp
src/linguist/linguist/messageeditorwidgets.h

index bb9f83a..f2897fb 100644 (file)
@@ -489,6 +489,7 @@ MainWindow::MainWindow()
     connect(m_ui.actionLengthVariants, SIGNAL(toggled(bool)),
             m_messageEditor, SLOT(setLengthVariants(bool)));
     m_messageEditor->setLengthVariants(m_ui.actionLengthVariants->isChecked());
+    m_messageEditor->setVisualizeWhitespace(m_ui.actionVisualizeWhitespace->isChecked());
 
     m_focusWatcher = new FocusWatcher(m_messageEditor, this);
     m_contextView->installEventFilter(m_focusWatcher);
@@ -1906,6 +1907,7 @@ void MainWindow::setupMenuBar()
     connect(m_ui.actionResetSorting, SIGNAL(triggered()), this, SLOT(resetSorting()));
     connect(m_ui.actionDisplayGuesses, SIGNAL(triggered()), m_phraseView, SLOT(toggleGuessing()));
     connect(m_ui.actionStatistics, SIGNAL(triggered()), this, SLOT(toggleStatistics()));
+    connect(m_ui.actionVisualizeWhitespace, SIGNAL(triggered()), this, SLOT(toggleVisualizeWhitespace()));
     connect(m_ui.menuView, SIGNAL(aboutToShow()), this, SLOT(updateViewMenu()));
     m_ui.menuViewViews->addAction(m_contextDock->toggleViewAction());
     m_ui.menuViewViews->addAction(m_messagesDock->toggleViewAction());
@@ -2572,6 +2574,8 @@ void MainWindow::readConfig()
         config.value(settingPath("Validators/PlaceMarkers"), true).toBool());
     m_ui.actionLengthVariants->setChecked(
         config.value(settingPath("Options/LengthVariants"), false).toBool());
+    m_ui.actionVisualizeWhitespace->setChecked(
+        config.value(settingPath("Options/VisualizeWhitespace"), true).toBool());
 
     recentFiles().readConfig();
 
@@ -2598,6 +2602,8 @@ void MainWindow::writeConfig()
         m_ui.actionPlaceMarkerMatches->isChecked());
     config.setValue(settingPath("Options/LengthVariants"),
         m_ui.actionLengthVariants->isChecked());
+    config.setValue(settingPath("Options/VisualizeWhitespace"),
+        m_ui.actionVisualizeWhitespace->isChecked());
     config.setValue(settingPath("MainWindowState"),
         saveState());
     recentFiles().writeConfig();
@@ -2650,6 +2656,11 @@ void MainWindow::toggleStatistics()
     }
 }
 
+void MainWindow::toggleVisualizeWhitespace()
+{
+    m_messageEditor->setVisualizeWhitespace(m_ui.actionVisualizeWhitespace->isChecked());
+}
+
 void MainWindow::maybeUpdateStatistics(const MultiDataIndex &index)
 {
     if (index.model() == m_currentIndex.model())
index ee2ba5e..8167289 100644 (file)
@@ -166,6 +166,7 @@ private slots:
                   bool matchCase, bool ignoreAccelerators, bool skipObsolete);
     void revalidate();
     void toggleStatistics();
+    void toggleVisualizeWhitespace();
     void onWhatsThis();
     void updatePhraseDicts();
     void updatePhraseDict(int model);
index 022a281..f54fe89 100644 (file)
     <addaction name="actionDisplayGuesses"/>
     <addaction name="actionStatistics"/>
     <addaction name="actionLengthVariants"/>
+    <addaction name="actionVisualizeWhitespace"/>
     <addaction name="separator"/>
     <addaction name="menuToolbars"/>
     <addaction name="menuViewViews"/>
     <string>Length Variants</string>
    </property>
   </action>
+  <action name="actionVisualizeWhitespace">
+   <property name="checkable">
+    <bool>true</bool>
+   </property>
+   <property name="text">
+    <string>Visualize whitespaces</string>
+   </property>
+   <property name="toolTip">
+    <string>Toogle visualize whitespaces in editors</string>
+   </property>
+  </action>
  </widget>
  <resources/>
  <connections/>
index a832e30..4ca5f3c 100644 (file)
@@ -95,6 +95,7 @@ MessageEditor::MessageEditor(MultiDataModel *dataModel, QMainWindow *parent)
       m_redoAvail(false),
       m_cutAvail(false),
       m_copyAvail(false),
+      m_visualizeWhitespace(true),
       m_selectionHolder(0),
       m_focusWidget(0)
 {
@@ -216,6 +217,7 @@ void MessageEditor::messageModelAppended()
     ed.transCommentText->setWhatsThis(tr("Here you can enter comments for your own use."
                         " They have no effect on the translated applications.") );
     ed.transCommentText->getEditor()->installEventFilter(this);
+    ed.transCommentText->getEditor()->setVisualizeWhitespace(m_visualizeWhitespace);
     connect(ed.transCommentText, SIGNAL(selectionChanged(QTextEdit*)),
             SLOT(selectionChanged(QTextEdit*)));
     connect(ed.transCommentText, SIGNAL(textChanged(QTextEdit*)),
@@ -300,6 +302,15 @@ void MessageEditor::editorCreated(QTextEdit *te)
 
             te->installEventFilter(this);
 
+            if (m_visualizeWhitespace) {
+                QTextOption option = te->document()->defaultTextOption();
+
+                option.setFlags(option.flags()
+                                | QTextOption::ShowLineAndParagraphSeparators
+                                | QTextOption::ShowTabsAndSpaces);
+                te->document()->setDefaultTextOption(option);
+            }
+
             fixTabOrder();
             return;
         }
@@ -914,4 +925,19 @@ bool MessageEditor::focusNextUnfinished()
     return focusNextUnfinished(m_currentModel + 1);
 }
 
+void MessageEditor::setVisualizeWhitespace(bool value)
+{
+    m_visualizeWhitespace = value;
+    m_source->getEditor()->setVisualizeWhitespace(value);
+    m_pluralSource->getEditor()->setVisualizeWhitespace(value);
+    m_commentText->getEditor()->setVisualizeWhitespace(value);
+
+    foreach (const MessageEditorData &med, m_editors) {
+        med.transCommentText->getEditor()->setVisualizeWhitespace(value);
+        foreach (FormMultiWidget *widget, med.transTexts)
+            foreach (FormatTextEdit *te, widget->getEditors())
+                te->setVisualizeWhitespace(value);
+    }
+}
+
 QT_END_NAMESPACE
index 6f7c657..8af58c4 100644 (file)
@@ -87,6 +87,7 @@ public:
     void setEditorFocus(int model);
     void setUnfinishedEditorFocus();
     bool focusNextUnfinished();
+    void setVisualizeWhitespace(bool value);
 
 signals:
     void translationChanged(const QStringList &translations);
@@ -172,6 +173,7 @@ private:
     bool m_copyAvail;
 
     bool m_clipboardEmpty;
+    bool m_visualizeWhitespace;
 
     QTextEdit *m_selectionHolder;
     QWidget *m_focusWidget;
index 0850d30..1db7f26 100644 (file)
@@ -114,11 +114,6 @@ FormatTextEdit::FormatTextEdit(QWidget *parent)
 {
     setLineWrapMode(QTextEdit::WidgetWidth);
     setAcceptRichText(false);
-    QTextOption option = document()->defaultTextOption();
-    option.setFlags(option.flags()
-                    | QTextOption::ShowLineAndParagraphSeparators
-                    | QTextOption::ShowTabsAndSpaces);
-    document()->setDefaultTextOption(option);
 
     // Do not set different background if disabled
     QPalette p = palette();
@@ -168,6 +163,21 @@ void FormatTextEdit::setPlainText(const QString &text, bool userAction)
     }
 }
 
+void FormatTextEdit::setVisualizeWhitespace(bool value)
+{
+    QTextOption option = document()->defaultTextOption();
+    if (value) {
+        option.setFlags(option.flags()
+                        | QTextOption::ShowLineAndParagraphSeparators
+                        | QTextOption::ShowTabsAndSpaces);
+    } else {
+        option.setFlags(option.flags()
+                        & ~QTextOption::ShowLineAndParagraphSeparators
+                        & ~QTextOption::ShowTabsAndSpaces);
+    }
+    document()->setDefaultTextOption(option);
+}
+
 FormWidget::FormWidget(const QString &label, bool isEditable, QWidget *parent)
         : QWidget(parent),
           m_hideWhenEmpty(false)
index a5560c5..e7cb211 100644 (file)
@@ -99,6 +99,7 @@ signals:
 
 public slots:
     void setPlainText(const QString & text, bool userAction);
+    void setVisualizeWhitespace(bool value);
 
 private:
     MessageHighlighter *m_highlighter;