From f6d68660c90af2d1514b0877edaed82f7d2a25d8 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 25 Apr 2019 12:45:54 +0200 Subject: [PATCH] Allow to toggle word wrap in views --- src/blackgui/menus/menuaction.h | 13 ++++++++----- src/blackgui/views/viewbase.h | 3 +++ src/blackgui/views/viewbasenontemplate.cpp | 20 +++++++++++++++++--- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/blackgui/menus/menuaction.h b/src/blackgui/menus/menuaction.h index bdcf1ac2c..811b5d897 100644 --- a/src/blackgui/menus/menuaction.h +++ b/src/blackgui/menus/menuaction.h @@ -188,20 +188,23 @@ namespace BlackGui //! View resizing static const QString &pathViewResize() { static const QString p("View.15.Resize"); return p; } + //! View word wrap + static const QString &pathViewWordWrap() { static const QString p("View.16.WordWrap"); return p; } + //! View clear highlighting - static const QString &pathViewClearHighlighting() { static const QString p("View.16.ClearHighlight"); return p; } + static const QString &pathViewClearHighlighting() { static const QString p("View.17.ClearHighlight"); return p; } //! View filter - static const QString &pathViewFilter() { static const QString p("View.17.Filter"); return p; } + static const QString &pathViewFilter() { static const QString p("View.18.Filter"); return p; } //! View update - static const QString &pathViewUpdates() { static const QString p("View.18.Updates"); return p; } + static const QString &pathViewUpdates() { static const QString p("View.19.Updates"); return p; } //! View load/save - static const QString &pathViewLoadSave() { static const QString p("View.18.LoadSave"); return p; } + static const QString &pathViewLoadSave() { static const QString p("View.19.LoadSave"); return p; } //! View cut and paste - static const QString &pathViewCutPaste() { static const QString p("View.18.CutPaste"); return p; } + static const QString &pathViewCutPaste() { static const QString p("View.19.CutPaste"); return p; } // ---- nested dock widgets ---- diff --git a/src/blackgui/views/viewbase.h b/src/blackgui/views/viewbase.h index a440c8d62..69ced3217 100644 --- a/src/blackgui/views/viewbase.h +++ b/src/blackgui/views/viewbase.h @@ -596,6 +596,9 @@ namespace BlackGui //! Toggle the resize mode void toggleResizeMode(bool checked); + //! Toggle the resize mode + void toggleWordWrap(bool checked); + //! Set the filter widget internally //! \remarks used for dialog and filter widget void setFilterWidgetImpl(QWidget *filterWidget); diff --git a/src/blackgui/views/viewbasenontemplate.cpp b/src/blackgui/views/viewbasenontemplate.cpp index bcf69eff4..b6bb34d04 100644 --- a/src/blackgui/views/viewbasenontemplate.cpp +++ b/src/blackgui/views/viewbasenontemplate.cpp @@ -19,6 +19,7 @@ #include "blackgui/views/viewbase.h" #include "blackgui/shortcut.h" #include "blackmisc/logmessage.h" +#include "viewbase.h" #include #include @@ -85,7 +86,7 @@ namespace BlackGui copy->setContext(Qt::WidgetShortcut); QShortcut *resize = new QShortcut(CShortcut::keyResizeView(), this); - connect(resize, &QShortcut::activated, this, &CViewBaseNonTemplate::fullResizeToContents); + connect(resize, &QShortcut::activated, this, &CViewBaseNonTemplate::resizeToContents); resize->setObjectName("Resize view shortcut for " + this->objectName()); resize->setContext(Qt::WidgetShortcut); } @@ -436,13 +437,19 @@ namespace BlackGui } } - - QAction *actionInteractiveResize = menuActions.addAction(CIcons::viewMultiColumn(), "Resize (auto)", CMenuAction::pathViewResize(), nullptr); + QAction *actionInteractiveResize = menuActions.addAction(CIcons::viewTile(), "Resize (auto)", CMenuAction::pathViewResize(), nullptr); actionInteractiveResize->setObjectName(this->objectName().append("ActionResizing")); actionInteractiveResize->setCheckable(true); actionInteractiveResize->setChecked(autoResize); actionInteractiveResize->setEnabled(enabled); connect(actionInteractiveResize, &QAction::toggled, this, &CViewBaseNonTemplate::toggleResizeMode); + + QAction *actionWordWrap = menuActions.addAction(CIcons::viewMultiColumn(), "Word wrap (multiline)", CMenuAction::pathViewResize(), nullptr); + actionWordWrap->setObjectName(this->objectName().append("ActionResizing")); + actionWordWrap->setCheckable(true); + actionWordWrap->setChecked(this->wordWrap()); + actionWordWrap->setEnabled(true); + connect(actionWordWrap, &QAction::toggled, this, &CViewBaseNonTemplate::toggleWordWrap); } void CViewBaseNonTemplate::resizeEvent(QResizeEvent *event) @@ -836,6 +843,13 @@ namespace BlackGui m_resizeMode = checked ? ResizingAuto : ResizingOff; } + void CViewBaseNonTemplate::toggleWordWrap(bool checked) + { + if (this->wordWrap() == checked) { return; } + this->setWordWrap(checked); + this->resizeRowsToContents(); + } + void CViewBaseNonTemplate::toggleAutoDisplay() { const QAction *a = qobject_cast(QObject::sender());