IOutputPane: Refactor zoom function into base class

Try to make zoom and font handling in the panes more
similar and put common stuff into IOutputPane.

Change-Id: I59c38c5eecbf67b7ca6c9d84a6f61b1292a787df
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Andre Hartmann
2019-03-31 08:04:43 +02:00
committed by André Hartmann
parent e127d599ac
commit 48073b2990
12 changed files with 131 additions and 201 deletions

View File

@@ -41,11 +41,9 @@ namespace Internal {
const char zoomSettingsKey[] = "Core/MessageOutput/Zoom";
MessageOutputWindow::MessageOutputWindow() :
m_zoomInButton(new QToolButton),
m_zoomOutButton(new QToolButton)
MessageOutputWindow::MessageOutputWindow()
{
m_widget = new OutputWindow(Context(Constants::C_GENERAL_OUTPUT_PANE));
m_widget = new OutputWindow(Context(Constants::C_GENERAL_OUTPUT_PANE), zoomSettingsKey);
m_widget->setReadOnly(true);
// Let selected text be colored as if the text edit was editable,
// otherwise the highlight for searching is too light
@@ -55,30 +53,20 @@ MessageOutputWindow::MessageOutputWindow() :
QColor activeHighlightedText = p.color(QPalette::Active, QPalette::HighlightedText);
p.setColor(QPalette::HighlightedText, activeHighlightedText);
m_widget->setPalette(p);
setZoomButtonsEnabled(true);
connect(this, &IOutputPane::zoomIn, m_widget, &Core::OutputWindow::zoomIn);
connect(this, &IOutputPane::zoomOut, m_widget, &Core::OutputWindow::zoomOut);
connect(this, &IOutputPane::fontChanged, m_widget, &OutputWindow::setBaseFont);
connect(this, &IOutputPane::wheelZoomEnabledChanged, m_widget, &OutputWindow::setWheelZoomEnabled);
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;
}
@@ -108,11 +96,6 @@ QWidget *MessageOutputWindow::outputWidget(QWidget *parent)
return m_widget;
}
QList<QWidget *> MessageOutputWindow::toolBarWidgets() const
{
return {m_zoomInButton, m_zoomOutButton};
}
QString MessageOutputWindow::displayName() const
{
return tr("General Messages");
@@ -157,30 +140,5 @@ 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