diff --git a/src/linguist/linguist/mainwindow.cpp b/src/linguist/linguist/mainwindow.cpp index bb9f83ab1fed450fdff0fcbc638fe8f092a542f5..f2897fbbe005aecf3c4730e5d0de68e1bd0f917b 100644 --- a/src/linguist/linguist/mainwindow.cpp +++ b/src/linguist/linguist/mainwindow.cpp @@ -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()) diff --git a/src/linguist/linguist/mainwindow.h b/src/linguist/linguist/mainwindow.h index ee2ba5e19a86bb1355d02d08c00a8a10abeb8aec..8167289c54244b3abfe24966681e86ef19bf2de4 100644 --- a/src/linguist/linguist/mainwindow.h +++ b/src/linguist/linguist/mainwindow.h @@ -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); diff --git a/src/linguist/linguist/mainwindow.ui b/src/linguist/linguist/mainwindow.ui index 022a2814f75a1abb463181729bf52d9e5a173c38..f54fe898cbbc383d15ecea0c60168d250c33d592 100644 --- a/src/linguist/linguist/mainwindow.ui +++ b/src/linguist/linguist/mainwindow.ui @@ -117,6 +117,7 @@ <addaction name="actionDisplayGuesses"/> <addaction name="actionStatistics"/> <addaction name="actionLengthVariants"/> + <addaction name="actionVisualizeWhitespace"/> <addaction name="separator"/> <addaction name="menuToolbars"/> <addaction name="menuViewViews"/> @@ -886,6 +887,17 @@ <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/> diff --git a/src/linguist/linguist/messageeditor.cpp b/src/linguist/linguist/messageeditor.cpp index a832e30d8a891e8d048334fb70fc35a2edc53cf5..4ca5f3c2d40e96165633a72fc9c13d7308ca6ff3 100644 --- a/src/linguist/linguist/messageeditor.cpp +++ b/src/linguist/linguist/messageeditor.cpp @@ -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 diff --git a/src/linguist/linguist/messageeditor.h b/src/linguist/linguist/messageeditor.h index 6f7c657e6bcdb63bccbf4ca78d94b3e4b26b5301..8af58c491f293183dc70c9617ce2f897774b2b06 100644 --- a/src/linguist/linguist/messageeditor.h +++ b/src/linguist/linguist/messageeditor.h @@ -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; diff --git a/src/linguist/linguist/messageeditorwidgets.cpp b/src/linguist/linguist/messageeditorwidgets.cpp index 0850d30bbfddbb069f1bb322aacd7a88def7cef5..1db7f261bd0a669a7b28135e05c2f2b7fa5a5561 100644 --- a/src/linguist/linguist/messageeditorwidgets.cpp +++ b/src/linguist/linguist/messageeditorwidgets.cpp @@ -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) diff --git a/src/linguist/linguist/messageeditorwidgets.h b/src/linguist/linguist/messageeditorwidgets.h index a5560c5c741ce47bbe482e8ce1d966e5aa5f32b9..e7cb211d329c9faff7d7efe73039127cd1bd6334 100644 --- a/src/linguist/linguist/messageeditorwidgets.h +++ b/src/linguist/linguist/messageeditorwidgets.h @@ -99,6 +99,7 @@ signals: public slots: void setPlainText(const QString & text, bool userAction); + void setVisualizeWhitespace(bool value); private: MessageHighlighter *m_highlighter;