From 00a991964613919b5d61394fa9f4f17f255f47e1 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Fri, 8 Jul 2016 16:20:50 +0200 Subject: [PATCH] Core: Lazier loading of OutputPaneManageButton images Only load button state images when needed. And not at all with the flat themes. Change-Id: I2e150eaabab5c91a7230d911bf51cde47b390b04 Reviewed-by: Alessandro Portale --- src/plugins/coreplugin/outputpanemanager.cpp | 39 +++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/plugins/coreplugin/outputpanemanager.cpp b/src/plugins/coreplugin/outputpanemanager.cpp index 25ae1277108..289f01279de 100644 --- a/src/plugins/coreplugin/outputpanemanager.cpp +++ b/src/plugins/coreplugin/outputpanemanager.cpp @@ -670,12 +670,6 @@ QSize OutputPaneToggleButton::sizeHint() const void OutputPaneToggleButton::paintEvent(QPaintEvent*) { - static const QImage panelButton(StyleHelper::dpiSpecificImageFile(QStringLiteral(":/core/images/panel_button.png"))); - static const QImage panelButtonHover(StyleHelper::dpiSpecificImageFile(QStringLiteral(":/core/images/panel_button_hover.png"))); - static const QImage panelButtonPressed(StyleHelper::dpiSpecificImageFile(QStringLiteral(":/core/images/panel_button_pressed.png"))); - static const QImage panelButtonChecked(StyleHelper::dpiSpecificImageFile(QStringLiteral(":/core/images/panel_button_checked.png"))); - static const QImage panelButtonCheckedHover(StyleHelper::dpiSpecificImageFile(QStringLiteral(":/core/images/panel_button_checked_hover.png"))); - const QFontMetrics fm = fontMetrics(); const int baseLine = (height() - fm.height() + 1) / 2 + fm.ascent(); const int numberWidth = fm.width(m_number); @@ -686,7 +680,6 @@ void OutputPaneToggleButton::paintEvent(QPaintEvent*) styleOption.initFrom(this); const bool hovered = !HostOsInfo::isMacHost() && (styleOption.state & QStyle::State_MouseOver); - const QImage *image = 0; if (creatorTheme()->flag(Theme::FlatToolBars)) { Theme::Color c = Theme::BackgroundColorDark; @@ -698,12 +691,32 @@ void OutputPaneToggleButton::paintEvent(QPaintEvent*) if (c != Theme::BackgroundColorDark) p.fillRect(rect(), creatorTheme()->color(c)); } else { - if (isDown()) - image = &panelButtonPressed; - else if (isChecked()) - image = hovered ? &panelButtonCheckedHover : &panelButtonChecked; - else - image = hovered ? &panelButtonHover : &panelButton; + const QImage *image = 0; + if (isDown()) { + static const QImage pressed( + StyleHelper::dpiSpecificImageFile(":/core/images/panel_button_pressed.png")); + image = &pressed; + } else if (isChecked()) { + if (hovered) { + static const QImage checkedHover( + StyleHelper::dpiSpecificImageFile(":/core/images/panel_button_checked_hover.png")); + image = &checkedHover; + } else { + static const QImage checked( + StyleHelper::dpiSpecificImageFile(":/core/images/panel_button_checked.png")); + image = &checked; + } + } else { + if (hovered) { + static const QImage hover( + StyleHelper::dpiSpecificImageFile(":/core/images/panel_button_hover.png")); + image = &hover; + } else { + static const QImage button( + StyleHelper::dpiSpecificImageFile(":/core/images/panel_button.png")); + image = &button; + } + } if (image) StyleHelper::drawCornerImage(*image, &p, rect(), numberAreaWidth(), buttonBorderWidth, buttonBorderWidth, buttonBorderWidth); }