From ee801a0eb598769715fb6282b984e8c82eaf37bd Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 16 Mar 2019 18:21:37 +0100 Subject: [PATCH] General Messages Pane: Add font settings and zoom As the settings are managed by TextEditor, but Core does not depend on TextEditor, no signal connection can be used. Instead, call the needed functions in MessageManager directly. Fixes: QTCREATORBUG-18908 Change-Id: Idc81f1071d5228cd6582e3a00189a5db24288fc6 Reviewed-by: David Schulz --- src/plugins/coreplugin/messagemanager.cpp | 16 +++++ src/plugins/coreplugin/messagemanager.h | 7 +++ .../coreplugin/messageoutputwindow.cpp | 58 ++++++++++++++++++- src/plugins/coreplugin/messageoutputwindow.h | 15 ++++- src/plugins/texteditor/texteditorsettings.cpp | 14 +++++ 5 files changed, 108 insertions(+), 2 deletions(-) diff --git a/src/plugins/coreplugin/messagemanager.cpp b/src/plugins/coreplugin/messagemanager.cpp index af2eddab6c2..84b20329f55 100644 --- a/src/plugins/coreplugin/messagemanager.cpp +++ b/src/plugins/coreplugin/messagemanager.cpp @@ -31,6 +31,8 @@ #include +#include + using namespace Core; static MessageManager *m_instance = nullptr; @@ -76,6 +78,20 @@ void MessageManager::init() ExtensionSystem::PluginManager::addObject(m_messageOutputWindow); } +void MessageManager::setFont(const QFont &font) +{ + QTC_ASSERT(m_messageOutputWindow, return); + + m_messageOutputWindow->setFont(font); +} + +void MessageManager::setWheelZoomEnabled(bool enabled) +{ + QTC_ASSERT(m_messageOutputWindow, return); + + m_messageOutputWindow->setWheelZoomEnabled(enabled); +} + void MessageManager::write(const QString &text, PrintToOutputPaneFlags flags) { QTC_ASSERT(m_messageOutputWindow, return); diff --git a/src/plugins/coreplugin/messagemanager.h b/src/plugins/coreplugin/messagemanager.h index 9d8e07d2b45..6ead1ddeb82 100644 --- a/src/plugins/coreplugin/messagemanager.h +++ b/src/plugins/coreplugin/messagemanager.h @@ -31,6 +31,10 @@ #include #include +QT_BEGIN_NAMESPACE +class QFont; +QT_END_NAMESPACE + namespace Core { namespace Internal { class MainWindow; } @@ -55,6 +59,9 @@ public: static void showOutputPane(Core::MessageManager::PrintToOutputPaneFlags flags = NoModeSwitch); + static void setFont(const QFont &font); + static void setWheelZoomEnabled(bool enabled); + public slots: static void write(const QString &text, Core::MessageManager::PrintToOutputPaneFlags flags = NoModeSwitch); diff --git a/src/plugins/coreplugin/messageoutputwindow.cpp b/src/plugins/coreplugin/messageoutputwindow.cpp index 35a1bd50bed..5541090379f 100644 --- a/src/plugins/coreplugin/messageoutputwindow.cpp +++ b/src/plugins/coreplugin/messageoutputwindow.cpp @@ -30,11 +30,20 @@ #include "find/basetextfind.h" #include +#include +#include + +#include +#include namespace Core { namespace Internal { -MessageOutputWindow::MessageOutputWindow() +const char zoomSettingsKey[] = "Core/MessageOutput/Zoom"; + +MessageOutputWindow::MessageOutputWindow() : + m_zoomInButton(new QToolButton), + m_zoomOutButton(new QToolButton) { m_widget = new OutputWindow(Context(Constants::C_GENERAL_OUTPUT_PANE)); m_widget->setReadOnly(true); @@ -49,10 +58,27 @@ MessageOutputWindow::MessageOutputWindow() auto agg = new Aggregation::Aggregate; agg->add(m_widget); agg->add(new BaseTextFind(m_widget)); + + loadSettings(); + + m_zoomInButton->setToolTip(tr("Increase Font Size")); + m_zoomInButton->setIcon(Utils::Icons::PLUS_TOOLBAR.icon()); + m_zoomInButton->setAutoRaise(true); + connect(m_zoomInButton, &QToolButton::clicked, this, [this] { m_widget->zoomIn(1); }); + + m_zoomOutButton->setToolTip(tr("Decrease Font Size")); + m_zoomOutButton->setIcon(Utils::Icons::MINUS.icon()); + m_zoomOutButton->setAutoRaise(true); + connect(m_zoomOutButton, &QToolButton::clicked, this, [this] { m_widget->zoomOut(1); }); + + connect(Core::ICore::instance(), &Core::ICore::saveSettingsRequested, + this, &MessageOutputWindow::storeSettings); } MessageOutputWindow::~MessageOutputWindow() { + delete m_zoomInButton; + delete m_zoomOutButton; delete m_widget; } @@ -82,6 +108,11 @@ QWidget *MessageOutputWindow::outputWidget(QWidget *parent) return m_widget; } +QList MessageOutputWindow::toolBarWidgets() const +{ + return {m_zoomInButton, m_zoomOutButton}; +} + QString MessageOutputWindow::displayName() const { return tr("General Messages"); @@ -126,5 +157,30 @@ bool MessageOutputWindow::canNavigate() const return false; } +void MessageOutputWindow::setFont(const QFont &font) +{ + m_widget->setBaseFont(font); +} + +void MessageOutputWindow::setWheelZoomEnabled(bool enabled) +{ + m_widget->setWheelZoomEnabled(enabled); +} + +void MessageOutputWindow::storeSettings() const +{ + QSettings * const s = Core::ICore::settings(); + + s->setValue(zoomSettingsKey, m_widget->fontZoom()); +} + +void MessageOutputWindow::loadSettings() +{ + QSettings * const s = Core::ICore::settings(); + + float zoom = s->value(zoomSettingsKey, 0).toFloat(); + m_widget->setFontZoom(zoom); +} + } // namespace Internal } // namespace Core diff --git a/src/plugins/coreplugin/messageoutputwindow.h b/src/plugins/coreplugin/messageoutputwindow.h index bd8c5ca3d43..238fbb7b81e 100644 --- a/src/plugins/coreplugin/messageoutputwindow.h +++ b/src/plugins/coreplugin/messageoutputwindow.h @@ -27,6 +27,11 @@ #include "ioutputpane.h" +QT_BEGIN_NAMESPACE +class QFont; +class QToolButton; +QT_END_NAMESPACE + namespace Core { class OutputWindow; @@ -41,7 +46,7 @@ public: ~MessageOutputWindow() override; QWidget *outputWidget(QWidget *parent) override; - QList toolBarWidgets() const override { return {}; } + QList toolBarWidgets() const override; QString displayName() const override; int priorityInStatusBar() const override; @@ -59,8 +64,16 @@ public: void goToPrev() override; bool canNavigate() const override; + void setFont(const QFont &font); + void setWheelZoomEnabled(bool enabled); + private: + void storeSettings() const; + void loadSettings(); + OutputWindow *m_widget; + QToolButton *m_zoomInButton = nullptr; + QToolButton *m_zoomOutButton = nullptr; }; } // namespace Internal diff --git a/src/plugins/texteditor/texteditorsettings.cpp b/src/plugins/texteditor/texteditorsettings.cpp index 78cea2b828b..bdc7e7a583b 100644 --- a/src/plugins/texteditor/texteditorsettings.cpp +++ b/src/plugins/texteditor/texteditorsettings.cpp @@ -47,6 +47,7 @@ #include #include +#include #include #include @@ -367,14 +368,27 @@ TextEditorSettings::TextEditorSettings() new SnippetsSettingsPage(Constants::TEXT_EDITOR_SNIPPETS_SETTINGS, this); d->m_completionSettingsPage = new CompletionSettingsPage(this); + auto updateGeneralMessagesFontSettings = []() { + Core::MessageManager::setFont(d->m_fontSettingsPage->fontSettings().font()); + }; connect(d->m_fontSettingsPage, &FontSettingsPage::changed, this, &TextEditorSettings::fontSettingsChanged); + connect(d->m_fontSettingsPage, &FontSettingsPage::changed, + this, updateGeneralMessagesFontSettings); + updateGeneralMessagesFontSettings(); connect(d->m_behaviorSettingsPage, &BehaviorSettingsPage::typingSettingsChanged, this, &TextEditorSettings::typingSettingsChanged); connect(d->m_behaviorSettingsPage, &BehaviorSettingsPage::storageSettingsChanged, this, &TextEditorSettings::storageSettingsChanged); + auto updateGeneralMessagesBehaviorSettings = []() { + bool wheelZoom = d->m_behaviorSettingsPage->behaviorSettings().m_scrollWheelZooming; + Core::MessageManager::setWheelZoomEnabled(wheelZoom); + }; connect(d->m_behaviorSettingsPage, &BehaviorSettingsPage::behaviorSettingsChanged, this, &TextEditorSettings::behaviorSettingsChanged); + connect(d->m_behaviorSettingsPage, &BehaviorSettingsPage::behaviorSettingsChanged, + this, updateGeneralMessagesBehaviorSettings); + updateGeneralMessagesBehaviorSettings(); connect(d->m_behaviorSettingsPage, &BehaviorSettingsPage::extraEncodingSettingsChanged, this, &TextEditorSettings::extraEncodingSettingsChanged); connect(d->m_displaySettingsPage, &DisplaySettingsPage::marginSettingsChanged,