Output panes: Support keyboard shortcuts for zooming

Fixes: QTCREATORBUG-22567
Change-Id: I3c7419c7b464c329d8f8dae11db9a0b01e51f32c
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Christian Kandeler
2019-06-20 17:27:10 +02:00
parent 864e3ab44a
commit 41ade463da
8 changed files with 51 additions and 7 deletions

View File

@@ -41,6 +41,8 @@ class QWidget;
QT_END_NAMESPACE
namespace Core {
class CommandButton;
class IContext;
class CORE_EXPORT IOutputPane : public QObject
{
@@ -93,6 +95,7 @@ signals:
void setBadgeNumber(int number);
void zoomIn(int range);
void zoomOut(int range);
void resetZoom();
void wheelZoomEnabledChanged(bool enabled);
void fontChanged(const QFont &font);
@@ -103,7 +106,7 @@ protected:
Qt::CaseSensitivity filterCaseSensitivity() const { return m_filterCaseSensitivity; }
void setFilteringEnabled(bool enable);
QWidget *filterWidget() const { return m_filterOutputLineEdit; }
void setupContext(const char *context, QWidget *widget);
void setZoomButtonsEnabled(bool enabled);
private:
@@ -115,11 +118,12 @@ private:
Id filterRegexpActionId() const;
Id filterCaseSensitivityActionId() const;
QToolButton * const m_zoomInButton = nullptr;
QToolButton * const m_zoomOutButton = nullptr;
Core::CommandButton * const m_zoomInButton;
Core::CommandButton * const m_zoomOutButton;
QAction *m_filterActionRegexp = nullptr;
QAction *m_filterActionCaseSensitive = nullptr;
Utils::FancyLineEdit *m_filterOutputLineEdit = nullptr;
IContext *m_context = nullptr;
bool m_filterRegexp = false;
Qt::CaseSensitivity m_filterCaseSensitivity = Qt::CaseInsensitive;
};

View File

@@ -56,6 +56,7 @@ MessageOutputWindow::MessageOutputWindow()
connect(this, &IOutputPane::zoomIn, m_widget, &Core::OutputWindow::zoomIn);
connect(this, &IOutputPane::zoomOut, m_widget, &Core::OutputWindow::zoomOut);
connect(this, &IOutputPane::resetZoom, m_widget, &Core::OutputWindow::resetZoom);
connect(this, &IOutputPane::fontChanged, m_widget, &OutputWindow::setBaseFont);
connect(this, &IOutputPane::wheelZoomEnabledChanged, m_widget, &OutputWindow::setWheelZoomEnabled);
@@ -65,6 +66,7 @@ MessageOutputWindow::MessageOutputWindow()
setupFilterUi("MessageOutputPane.Filter");
setFilteringEnabled(true);
setupContext(Constants::C_GENERAL_OUTPUT_PANE, m_widget);
}
MessageOutputWindow::~MessageOutputWindow()

View File

@@ -35,6 +35,7 @@
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/actionmanager/commandbutton.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/find/optionspopup.h>
@@ -90,24 +91,27 @@ static bool g_managerConstructed = false; // For debugging reasons.
IOutputPane::IOutputPane(QObject *parent)
: QObject(parent),
m_zoomInButton(new QToolButton),
m_zoomOutButton(new QToolButton)
m_zoomInButton(new Core::CommandButton),
m_zoomOutButton(new Core::CommandButton)
{
// We need all pages first. Ignore latecomers and shout.
QTC_ASSERT(!g_managerConstructed, return);
g_outputPanes.append(OutputPaneData(this));
m_zoomInButton->setToolTip(tr("Increase Font Size"));
m_zoomInButton->setIcon(Utils::Icons::PLUS_TOOLBAR.icon());
m_zoomInButton->setCommandId(Constants::ZOOM_IN);
connect(m_zoomInButton, &QToolButton::clicked, this, [this] { emit zoomIn(1); });
m_zoomOutButton->setToolTip(tr("Decrease Font Size"));
m_zoomOutButton->setIcon(Utils::Icons::MINUS.icon());
m_zoomOutButton->setCommandId(Constants::ZOOM_OUT);
connect(m_zoomOutButton, &QToolButton::clicked, this, [this] { emit zoomOut(1); });
}
IOutputPane::~IOutputPane()
{
if (m_context)
ICore::removeContextObject(m_context);
const int i = Utils::indexOf(g_outputPanes, Utils::equal(&OutputPaneData::pane, this));
QTC_ASSERT(i >= 0, return);
delete g_outputPanes.at(i).button;
@@ -174,6 +178,26 @@ void IOutputPane::setFilteringEnabled(bool enable)
m_filterOutputLineEdit->setEnabled(enable);
}
void IOutputPane::setupContext(const char *context, QWidget *widget)
{
QTC_ASSERT(!m_context, return);
m_context = new IContext(this);
m_context->setContext(Context(context));
m_context->setWidget(widget);
ICore::addContextObject(m_context);
const auto zoomInAction = new QAction(this);
Core::ActionManager::registerAction(zoomInAction, Constants::ZOOM_IN, m_context->context());
connect(zoomInAction, &QAction::triggered, this, [this] { emit zoomIn(1); });
const auto zoomOutAction = new QAction(this);
Core::ActionManager::registerAction(zoomOutAction, Constants::ZOOM_OUT, m_context->context());
connect(zoomOutAction, &QAction::triggered, this, [this] { emit zoomOut(1); });
const auto resetZoomAction = new QAction(this);
Core::ActionManager::registerAction(resetZoomAction, Constants::ZOOM_RESET,
m_context->context());
connect(resetZoomAction, &QAction::triggered, this, &IOutputPane::resetZoom);
}
void IOutputPane::setZoomButtonsEnabled(bool enabled)
{
m_zoomInButton->setEnabled(enabled);

View File

@@ -75,6 +75,7 @@ public:
void setBaseFont(const QFont &newFont);
float fontZoom() const;
void setFontZoom(float zoom);
void resetZoom() { setFontZoom(0); }
void setWheelZoomEnabled(bool enabled);
void updateFilterProperties(const QString &filterText, Qt::CaseSensitivity caseSensitivity, bool regexp);

View File

@@ -213,6 +213,7 @@ AppOutputPane::AppOutputPane() :
connect(this, &Core::IOutputPane::zoomIn, this, &AppOutputPane::zoomIn);
connect(this, &Core::IOutputPane::zoomOut, this, &AppOutputPane::zoomOut);
connect(this, &IOutputPane::resetZoom, this, &AppOutputPane::resetZoom);
m_settingsButton->setToolTip(tr("Open Settings Page"));
m_settingsButton->setIcon(Utils::Icons::SETTINGS_TOOLBAR.icon());
@@ -247,6 +248,7 @@ AppOutputPane::AppOutputPane() :
setupFilterUi("AppOutputPane.Filter");
setFilteringEnabled(false);
setZoomButtonsEnabled(false);
setupContext("Core.AppOutputPane", m_mainWidget);
}
AppOutputPane::~AppOutputPane()
@@ -662,6 +664,12 @@ void AppOutputPane::zoomOut(int range)
tab.window->zoomOut(range);
}
void AppOutputPane::resetZoom()
{
for (const RunControlTab &tab : qAsConst(m_runControlTabs))
tab.window->resetZoom();
}
void AppOutputPane::enableButtons(const RunControl *rc)
{
if (rc) {

View File

@@ -120,6 +120,7 @@ private:
void zoomIn(int range);
void zoomOut(int range);
void resetZoom();
void enableButtons(const RunControl *rc);

View File

@@ -177,6 +177,7 @@ CompileOutputWindow::CompileOutputWindow(QAction *cancelBuildAction) :
connect(this, &IOutputPane::zoomIn, m_outputWindow, &Core::OutputWindow::zoomIn);
connect(this, &IOutputPane::zoomOut, m_outputWindow, &Core::OutputWindow::zoomOut);
connect(this, &IOutputPane::resetZoom, m_outputWindow, &Core::OutputWindow::resetZoom);
connect(TextEditor::TextEditorSettings::instance(), &TextEditor::TextEditorSettings::fontSettingsChanged,
this, updateFontSettings);
connect(TextEditor::TextEditorSettings::instance(), &TextEditor::TextEditorSettings::behaviorSettingsChanged,
@@ -194,6 +195,7 @@ CompileOutputWindow::CompileOutputWindow(QAction *cancelBuildAction) :
m_handler = new ShowOutputTaskHandler(this);
ExtensionSystem::PluginManager::addObject(m_handler);
setupContext(C_COMPILE_OUTPUT, m_outputWindow);
loadSettings();
updateFromSettings();
}

View File

@@ -302,9 +302,11 @@ VcsOutputWindow::VcsOutputWindow()
updateFontSettings();
updateBehaviorSettings();
setupContext(Internal::C_VCS_OUTPUT_PANE, &d->widget);
connect(this, &IOutputPane::zoomIn, &d->widget, &Core::OutputWindow::zoomIn);
connect(this, &IOutputPane::zoomOut, &d->widget, &Core::OutputWindow::zoomOut);
connect(this, &IOutputPane::resetZoom, &d->widget, &Core::OutputWindow::resetZoom);
connect(TextEditor::TextEditorSettings::instance(), &TextEditor::TextEditorSettings::fontSettingsChanged,
this, updateFontSettings);
connect(TextEditor::TextEditorSettings::instance(), &TextEditor::TextEditorSettings::behaviorSettingsChanged,