Commit 8dfa9a5d authored by Daniel Teske's avatar Daniel Teske

ZOOOOM for CompileOutputWindow and AppOutWindow

Implement zooming for the compile output and app output panes.
Those windows can be zoomed by toolbar buttons or ctrl+mousewheel.
The zoom factor is synced between app output panes, but not between
compile and app output. The scroll wheel zoom can be disabled
in the settings.

While at it, fix that the AppOutputPane did not update its font
on changes to the fontsettings.

Task-number: QTCREATORBUG-12476
Change-Id: I8a1639ab3d39c24a5fc21ed82f558f3d10efc02d
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent cac53ea4
......@@ -135,30 +135,30 @@ void OutputFormatter::initFormats()
if (!plainTextEdit())
return;
QFont boldFont = d->font;
QFont boldFont;
boldFont.setBold(true);
Theme *theme = creatorTheme();
// NormalMessageFormat
d->formats[NormalMessageFormat].setFont(boldFont);
d->formats[NormalMessageFormat].setFont(boldFont, QTextCharFormat::FontPropertiesSpecifiedOnly);
d->formats[NormalMessageFormat].setForeground(theme->color(Theme::OutputPanes_NormalMessageTextColor));
// ErrorMessageFormat
d->formats[ErrorMessageFormat].setFont(boldFont);
d->formats[ErrorMessageFormat].setFont(boldFont, QTextCharFormat::FontPropertiesSpecifiedOnly);
d->formats[ErrorMessageFormat].setForeground(theme->color(Theme::OutputPanes_ErrorMessageTextColor));
// StdOutFormat
d->formats[StdOutFormat].setFont(d->font);
d->formats[StdOutFormat].setFont(d->font, QTextCharFormat::FontPropertiesSpecifiedOnly);
d->formats[StdOutFormat].setForeground(theme->color(Theme::OutputPanes_StdOutTextColor));
d->formats[StdOutFormatSameLine] = d->formats[StdOutFormat];
// StdErrFormat
d->formats[StdErrFormat].setFont(d->font);
d->formats[StdErrFormat].setFont(d->font, QTextCharFormat::FontPropertiesSpecifiedOnly);
d->formats[StdErrFormat].setForeground(theme->color(Theme::OutputPanes_StdErrTextColor));
d->formats[StdErrFormatSameLine] = d->formats[StdErrFormat];
d->formats[DebugFormat].setFont(d->font);
d->formats[DebugFormat].setFont(d->font, QTextCharFormat::FontPropertiesSpecifiedOnly);
d->formats[DebugFormat].setForeground(theme->color(Theme::OutputPanes_DebugTextColor));
}
......@@ -167,17 +167,6 @@ void OutputFormatter::handleLink(const QString &href)
Q_UNUSED(href);
}
QFont OutputFormatter::font() const
{
return d->font;
}
void OutputFormatter::setFont(const QFont &font)
{
d->font = font;
initFormats();
}
void OutputFormatter::flush()
{
d->escapeCodeHandler.endFormatScope();
......
......@@ -60,8 +60,6 @@ public:
QPlainTextEdit *plainTextEdit() const;
virtual void setPlainTextEdit(QPlainTextEdit *plainText);
QFont font() const;
void setFont(const QFont &font);
void flush();
virtual void appendMessage(const QString &text, OutputFormat format);
......
......@@ -56,6 +56,8 @@ public:
, scrollToBottom(false)
, linksActive(true)
, mousePressed(false)
, m_zoomEnabled(false)
, m_originalFontSize(0)
, maxLineCount(100000)
, cursor(document)
{
......@@ -74,6 +76,8 @@ public:
bool scrollToBottom;
bool linksActive;
bool mousePressed;
bool m_zoomEnabled;
float m_originalFontSize;
int maxLineCount;
QTextCursor cursor;
};
......@@ -133,6 +137,8 @@ OutputWindow::OutputWindow(Context context, QWidget *parent)
connect(&m_scrollTimer, &QTimer::timeout,
this, &OutputWindow::scrollToBottom);
m_lastMessage.start();
d->m_originalFontSize = font().pointSizeF();
}
OutputWindow::~OutputWindow()
......@@ -215,6 +221,51 @@ void OutputWindow::showEvent(QShowEvent *e)
d->scrollToBottom = false;
}
void OutputWindow::wheelEvent(QWheelEvent *e)
{
if (d->m_zoomEnabled) {
if (e->modifiers() & Qt::ControlModifier) {
float delta = e->angleDelta().y() / 120.f;
zoomInF(delta);
emit wheelZoom();
return;
}
} else {
QAbstractScrollArea::wheelEvent(e);
updateMicroFocus();
}
}
void OutputWindow::setBaseFont(const QFont &newFont)
{
float zoom = fontZoom();
d->m_originalFontSize = newFont.pointSizeF();
QFont tmp = newFont;
float newZoom = qMax(d->m_originalFontSize + zoom, 4.0f);
tmp.setPointSizeF(newZoom);
setFont(tmp);
}
float OutputWindow::fontZoom() const
{
return font().pointSizeF() - d->m_originalFontSize;
}
void OutputWindow::setFontZoom(float zoom)
{
QFont f = font();
if (f.pointSizeF() == d->m_originalFontSize + zoom)
return;
float newZoom = qMax(d->m_originalFontSize + zoom, 4.0f);
f.setPointSizeF(newZoom);
setFont(f);
}
void OutputWindow::setWheelZoomEnabled(bool enabled)
{
d->m_zoomEnabled = enabled;
}
QString OutputWindow::doNewlineEnforcement(const QString &out)
{
d->scrollToBottom = true;
......
......@@ -71,6 +71,14 @@ public:
void setMaxLineCount(int count);
int maxLineCount() const;
void setBaseFont(const QFont &newFont);
float fontZoom() const;
void setFontZoom(float zoom);
void setWheelZoomEnabled(bool enabled);
signals:
void wheelZoom();
public slots:
void setWordWrapEnabled(bool wrap);
......@@ -82,8 +90,10 @@ protected:
virtual void mouseMoveEvent(QMouseEvent *e);
virtual void resizeEvent(QResizeEvent *e);
virtual void keyPressEvent(QKeyEvent *ev);
virtual void wheelEvent(QWheelEvent *e);
private:
using QPlainTextEdit::setFont; // call setBaseFont instead, which respects the zoom factor
QTimer m_scrollTimer;
QTime m_lastMessage;
void enableUndoRedo();
......
......@@ -40,8 +40,11 @@
#include <coreplugin/coreconstants.h>
#include <coreplugin/outputwindow.h>
#include <coreplugin/find/basetextfind.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/icore.h>
#include <texteditor/fontsettings.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/behaviorsettings.h>
#include <extensionsystem/pluginmanager.h>
#include <extensionsystem/invoker.h>
......@@ -75,6 +78,10 @@ static QString msgAttachDebuggerTooltip(const QString &handleDescription = QStri
AppOutputPane::tr("Attach debugger to %1").arg(handleDescription);
}
namespace {
const char SETTINGS_KEY[] = "ProjectExplorer/AppOutput/Zoom";
}
namespace ProjectExplorer {
namespace Internal {
......@@ -149,7 +156,9 @@ AppOutputPane::AppOutputPane() :
m_closeOtherTabsAction(new QAction(tr("Close Other Tabs"), this)),
m_reRunButton(new QToolButton),
m_stopButton(new QToolButton),
m_attachButton(new QToolButton)
m_attachButton(new QToolButton),
m_zoomInButton(new QToolButton),
m_zoomOutButton(new QToolButton)
{
setObjectName(QLatin1String("AppOutputPane")); // Used in valgrind engine
......@@ -185,6 +194,20 @@ AppOutputPane::AppOutputPane() :
connect(m_attachButton, SIGNAL(clicked()),
this, SLOT(attachToRunControl()));
m_zoomInButton->setToolTip(tr("Increase Font Size"));
m_zoomInButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_PLUS)));
m_zoomInButton->setAutoRaise(true);
connect(m_zoomInButton, &QToolButton::clicked,
this, &AppOutputPane::zoomIn);
m_zoomOutButton->setToolTip(tr("Decrease Font Size"));
m_zoomOutButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_MINUS)));
m_zoomOutButton->setAutoRaise(true);
connect(m_zoomOutButton, &QToolButton::clicked,
this, &AppOutputPane::zoomOut);
// Spacer (?)
QVBoxLayout *layout = new QVBoxLayout;
......@@ -200,6 +223,12 @@ AppOutputPane::AppOutputPane() :
m_mainWidget->setLayout(layout);
connect(TextEditor::TextEditorSettings::instance(), &TextEditor::TextEditorSettings::fontSettingsChanged,
this, &AppOutputPane::updateFontSettings);
connect(TextEditor::TextEditorSettings::instance(), &TextEditor::TextEditorSettings::behaviorSettingsChanged,
this, &AppOutputPane::updateBehaviorSettings);
connect(SessionManager::instance(), SIGNAL(aboutToUnloadSession(QString)),
this, SLOT(aboutToUnloadSession()));
connect(ProjectExplorerPlugin::instance(), SIGNAL(settingsChanged()),
......@@ -209,6 +238,12 @@ AppOutputPane::AppOutputPane() :
connect(this, &AppOutputPane::allRunControlsFinished,
WinDebugInterface::instance(), &WinDebugInterface::stop);
#endif
QSettings *settings = Core::ICore::settings();
m_zoom = settings->value(QLatin1String(SETTINGS_KEY), 0).toFloat();
connect(Core::ICore::instance(), &Core::ICore::saveSettingsRequested,
this, &AppOutputPane::saveSettings);
}
AppOutputPane::~AppOutputPane()
......@@ -221,6 +256,12 @@ AppOutputPane::~AppOutputPane()
delete m_mainWidget;
}
void AppOutputPane::saveSettings()
{
QSettings *settings = Core::ICore::settings();
settings->setValue(QLatin1String(SETTINGS_KEY), m_zoom);
}
int AppOutputPane::currentIndex() const
{
if (const QWidget *w = m_tabWidget->currentWidget())
......@@ -286,7 +327,8 @@ QWidget *AppOutputPane::outputWidget(QWidget *)
QList<QWidget*> AppOutputPane::toolBarWidgets() const
{
return QList<QWidget*>() << m_reRunButton << m_stopButton << m_attachButton;
return QList<QWidget*>() << m_reRunButton << m_stopButton << m_attachButton
<< m_zoomInButton << m_zoomOutButton;
}
QString AppOutputPane::displayName() const
......@@ -329,6 +371,20 @@ void AppOutputPane::setFocus()
m_tabWidget->currentWidget()->setFocus();
}
void AppOutputPane::updateFontSettings()
{
QFont f = TextEditor::TextEditorSettings::fontSettings().font();
foreach (const RunControlTab &rcTab, m_runControlTabs)
rcTab.window->setBaseFont(f);
}
void AppOutputPane::updateBehaviorSettings()
{
bool zoomEnabled = TextEditor::TextEditorSettings::behaviorSettings().m_scrollWheelZooming;
foreach (const RunControlTab &rcTab, m_runControlTabs)
rcTab.window->setWheelZoomEnabled(zoomEnabled);
}
void AppOutputPane::createNewOutputWindow(RunControl *rc)
{
connect(rc, SIGNAL(started()),
......@@ -341,7 +397,6 @@ void AppOutputPane::createNewOutputWindow(RunControl *rc)
this, SLOT(appendMessage(ProjectExplorer::RunControl*,QString,Utils::OutputFormat)));
Utils::OutputFormatter *formatter = rc->outputFormatter();
formatter->setFont(TextEditor::TextEditorSettings::fontSettings().font());
// First look if we can reuse a tab
const int size = m_runControlTabs.size();
......@@ -369,6 +424,17 @@ void AppOutputPane::createNewOutputWindow(RunControl *rc)
ow->setFormatter(formatter);
ow->setWordWrapEnabled(ProjectExplorerPlugin::projectExplorerSettings().wrapAppOutput);
ow->setMaxLineCount(ProjectExplorerPlugin::projectExplorerSettings().maxAppOutputLines);
ow->setWheelZoomEnabled(TextEditor::TextEditorSettings::behaviorSettings().m_scrollWheelZooming);
ow->setBaseFont(TextEditor::TextEditorSettings::fontSettings().font());
ow->setFontZoom(m_zoom);
connect(ow, &Core::OutputWindow::wheelZoom,
this, [this, ow]() {
m_zoom = ow->fontZoom();
foreach (const RunControlTab &tab, m_runControlTabs)
tab.window->setFontZoom(m_zoom);
});
Aggregation::Aggregate *agg = new Aggregation::Aggregate;
agg->add(ow);
agg->add(new Core::BaseTextFind(ow));
......@@ -545,6 +611,24 @@ void AppOutputPane::enableButtons()
enableButtons(rc, isRunning);
}
void AppOutputPane::zoomIn()
{
foreach (const RunControlTab &tab, m_runControlTabs)
tab.window->zoomIn(1);
if (m_runControlTabs.isEmpty())
return;
m_zoom = m_runControlTabs.first().window->fontZoom();
}
void AppOutputPane::zoomOut()
{
foreach (const RunControlTab &tab, m_runControlTabs)
tab.window->zoomOut(1);
if (m_runControlTabs.isEmpty())
return;
m_zoom = m_runControlTabs.first().window->fontZoom();
}
void AppOutputPane::enableButtons(const RunControl *rc /* = 0 */, bool isRunning /* = false */)
{
if (rc) {
......@@ -558,12 +642,16 @@ void AppOutputPane::enableButtons(const RunControl *rc /* = 0 */, bool isRunning
m_attachButton->setEnabled(false);
m_attachButton->setToolTip(msgAttachDebuggerTooltip());
}
m_zoomInButton->setEnabled(true);
m_zoomOutButton->setEnabled(true);
} else {
m_reRunButton->setEnabled(false);
m_reRunButton->setIcon(QIcon(QLatin1String(Constants::ICON_RUN_SMALL)));
m_attachButton->setEnabled(false);
m_attachButton->setToolTip(msgAttachDebuggerTooltip());
m_stopAction->setEnabled(false);
m_zoomInButton->setEnabled(false);
m_zoomOutButton->setEnabled(false);
}
}
......
......@@ -119,6 +119,9 @@ private slots:
void updateFromSettings();
void enableButtons();
void zoomIn();
void zoomOut();
private:
void enableButtons(const RunControl *rc, bool isRunning);
......@@ -143,6 +146,9 @@ private:
int tabWidgetIndexOf(int runControlIndex) const;
void handleOldOutput(Core::OutputWindow *window) const;
void updateCloseActions();
void updateFontSettings();
void saveSettings();
void updateBehaviorSettings();
QWidget *m_mainWidget;
class TabWidget *m_tabWidget;
......@@ -154,6 +160,9 @@ private:
QToolButton *m_reRunButton;
QToolButton *m_stopButton;
QToolButton *m_attachButton;
QToolButton *m_zoomInButton;
QToolButton *m_zoomOutButton;
float m_zoom;
};
} // namespace Internal
......
......@@ -38,9 +38,12 @@
#include <coreplugin/outputwindow.h>
#include <coreplugin/find/basetextfind.h>
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
#include <extensionsystem/pluginmanager.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/fontsettings.h>
#include <texteditor/behaviorsettings.h>
#include <utils/ansiescapecodehandler.h>
#include <utils/theme/theme.h>
......@@ -56,6 +59,7 @@ using namespace ProjectExplorer::Internal;
namespace {
const int MAX_LINECOUNT = 100000;
const char SETTINGS_KEY[] = "ProjectExplorer/CompileOutput/Zoom";
}
namespace ProjectExplorer {
......@@ -65,11 +69,28 @@ class CompileOutputTextEdit : public Core::OutputWindow
{
Q_OBJECT
public:
CompileOutputTextEdit(const Core::Context &context) : Core::OutputWindow(context)
CompileOutputTextEdit(const Core::Context &context)
: Core::OutputWindow(context)
{
setWheelZoomEnabled(true);
QSettings *settings = Core::ICore::settings();
float zoom = settings->value(QLatin1String(SETTINGS_KEY), 0).toFloat();
setFontZoom(zoom);
fontSettingsChanged();
connect(TextEditor::TextEditorSettings::instance(), SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
this, SLOT(fontSettingsChanged()));
connect(Core::ICore::instance(), &Core::ICore::saveSettingsRequested,
this, &CompileOutputTextEdit::saveSettings);
}
void saveSettings()
{
QSettings *settings = Core::ICore::settings();
settings->setValue(QLatin1String(SETTINGS_KEY), fontZoom());
}
void addTask(const Task &task, int blocknumber)
......@@ -84,17 +105,10 @@ public:
private slots:
void fontSettingsChanged()
{
setFont(TextEditor::TextEditorSettings::fontSettings().font());
setBaseFont(TextEditor::TextEditorSettings::fontSettings().font());
}
protected:
void wheelEvent(QWheelEvent *ev)
{
// from QPlainTextEdit, but without scroll wheel zooming
QAbstractScrollArea::wheelEvent(ev);
updateMicroFocus();
}
void mouseDoubleClickEvent(QMouseEvent *ev)
{
int line = cursorForPosition(ev->pos()).block().blockNumber();
......@@ -113,6 +127,8 @@ private:
CompileOutputWindow::CompileOutputWindow(QAction *cancelBuildAction) :
m_cancelBuildButton(new QToolButton),
m_zoomInButton(new QToolButton),
m_zoomOutButton(new QToolButton),
m_escapeCodeHandler(new Utils::AnsiEscapeCodeHandler)
{
Core::Context context(Constants::C_COMPILE_OUTPUT);
......@@ -133,6 +149,19 @@ CompileOutputWindow::CompileOutputWindow(QAction *cancelBuildAction) :
m_outputWindow->setPalette(p);
m_cancelBuildButton->setDefaultAction(cancelBuildAction);
m_zoomInButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_PLUS)));
m_zoomOutButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_MINUS)));
updateZoomEnabled();
connect(TextEditor::TextEditorSettings::instance(),
&TextEditor::TextEditorSettings::behaviorSettingsChanged,
this, &CompileOutputWindow::updateZoomEnabled);
connect(m_zoomInButton, &QToolButton::clicked,
this, [this]() { m_outputWindow->zoomIn(1); });
connect(m_zoomOutButton, &QToolButton::clicked,
this, [this]() { m_outputWindow->zoomOut(1); });
Aggregation::Aggregate *agg = new Aggregation::Aggregate;
agg->add(m_outputWindow);
......@@ -152,9 +181,21 @@ CompileOutputWindow::~CompileOutputWindow()
ExtensionSystem::PluginManager::removeObject(m_handler);
delete m_handler;
delete m_cancelBuildButton;
delete m_zoomInButton;
delete m_zoomOutButton;
delete m_escapeCodeHandler;
}
void CompileOutputWindow::updateZoomEnabled()
{
const TextEditor::BehaviorSettings &settings
= TextEditor::TextEditorSettings::behaviorSettings();
bool zoomEnabled = settings.m_scrollWheelZooming;
m_zoomInButton->setEnabled(zoomEnabled);
m_zoomOutButton->setEnabled(zoomEnabled);
m_outputWindow->setWheelZoomEnabled(zoomEnabled);
}
void CompileOutputWindow::updateWordWrapMode()
{
m_outputWindow->setWordWrapEnabled(ProjectExplorerPlugin::projectExplorerSettings().wrapAppOutput);
......@@ -182,7 +223,9 @@ QWidget *CompileOutputWindow::outputWidget(QWidget *)
QList<QWidget *> CompileOutputWindow::toolBarWidgets() const
{
return QList<QWidget *>() << m_cancelBuildButton;
return QList<QWidget *>() << m_cancelBuildButton
<< m_zoomInButton
<< m_zoomOutButton;
}
void CompileOutputWindow::appendText(const QString &text, BuildStep::OutputFormat format)
......
......@@ -88,12 +88,15 @@ public:
private slots:
void updateWordWrapMode();
void updateZoomEnabled();
private:
CompileOutputTextEdit *m_outputWindow;
QHash<unsigned int, QPair<int, int>> m_taskPositions;
ShowOutputTaskHandler * m_handler;
QToolButton *m_cancelBuildButton;
QToolButton *m_zoomInButton;
QToolButton *m_zoomOutButton;
Utils::AnsiEscapeCodeHandler *m_escapeCodeHandler;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment