Commit 3779147f authored by Morten Johan Sørvig's avatar Morten Johan Sørvig
Browse files

Add 2x icons for retina displays.



This change updates the mode selector/fancyactionbar
in Qt Creator with new high-resolution icons.

Set Qt::AA_UseHighDpiImages on Qt 5.1 and higher to
make QIcon generate high-dpi pixmaps. Add "@2x" mode
images.

Update StyleHelper::drawIconWithShadow to handle high-dpi
pixmaps. The shadow-drawing algorithm is kept in device
pixels.

Change-Id: I411b7a24e534a2d75a1bbdc4d10219dcbea26bed
Reviewed-by: default avatarJens Bache-Wiig <jens.bache-wiig@digia.com>
parent 87284f7d
...@@ -307,6 +307,10 @@ int main(int argc, char **argv) ...@@ -307,6 +307,10 @@ int main(int argc, char **argv)
QtSystemExceptionHandler systemExceptionHandler; QtSystemExceptionHandler systemExceptionHandler;
#endif #endif
#if QT_VERSION >= 0x050100
app.setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif
// Manually determine -settingspath command line option // Manually determine -settingspath command line option
// We can't use the regular way of the plugin manager, because that needs to parse pluginspecs // We can't use the regular way of the plugin manager, because that needs to parse pluginspecs
// but the settings path can influence which plugins are enabled // but the settings path can influence which plugins are enabled
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <QPainter> #include <QPainter>
#include <QApplication> #include <QApplication>
#include <QStyleOption> #include <QStyleOption>
#include <qmath.h>
// Clamps float color values within (0, 255) // Clamps float color values within (0, 255)
static int clamp(float x) static int clamp(float x)
...@@ -363,15 +364,32 @@ void StyleHelper::menuGradient(QPainter *painter, const QRect &spanRect, const Q ...@@ -363,15 +364,32 @@ void StyleHelper::menuGradient(QPainter *painter, const QRect &spanRect, const Q
} }
} }
static qreal pixmapDevicePixelRatio(const QPixmap &pixmap)
{
#if QT_VERSION > 0x050000
return pixmap.devicePixelRatio();
#else
return 1.0;
#endif
}
// Draws a cached pixmap with shadow // Draws a cached pixmap with shadow
void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect, void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect,
QPainter *p, QIcon::Mode iconMode, int radius, const QColor &color, const QPoint &offset) QPainter *p, QIcon::Mode iconMode, int dipRadius, const QColor &color, const QPoint &dipOffset)
{ {
QPixmap cache; QPixmap cache;
QString pixmapName = QString::fromLatin1("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height()); QString pixmapName = QString::fromLatin1("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height());
if (!QPixmapCache::find(pixmapName, cache)) { if (!QPixmapCache::find(pixmapName, cache)) {
// High-dpi support: The in parameters (rect, radius, offset) are in
// device-independent pixels. The call to QIcon::pixmap() below might
// return a high-dpi pixmap, which will in that case have a devicePixelRatio
// different than 1. The shadow drawing caluculations are done in device
// pixels.
QPixmap px = icon.pixmap(rect.size()); QPixmap px = icon.pixmap(rect.size());
int devicePixelRatio = qCeil(pixmapDevicePixelRatio(px));
int radius = dipRadius * devicePixelRatio;
QPoint offset = dipOffset * devicePixelRatio;
cache = QPixmap(px.size() + QSize(radius * 2, radius * 2)); cache = QPixmap(px.size() + QSize(radius * 2, radius * 2));
cache.fill(Qt::transparent); cache.fill(Qt::transparent);
...@@ -396,7 +414,7 @@ void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect, ...@@ -396,7 +414,7 @@ void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect,
QPainter tmpPainter(&tmp); QPainter tmpPainter(&tmp);
tmpPainter.setCompositionMode(QPainter::CompositionMode_Source); tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
tmpPainter.drawPixmap(QPoint(radius, radius), px); tmpPainter.drawPixmap(QRect(radius, radius, px.width(), px.height()), px);
tmpPainter.end(); tmpPainter.end();
// blur the alpha channel // blur the alpha channel
...@@ -423,13 +441,17 @@ void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect, ...@@ -423,13 +441,17 @@ void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect,
cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp); cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp);
// Draw the actual pixmap... // Draw the actual pixmap...
cachePainter.drawPixmap(QPoint(radius, radius) + offset, px); cachePainter.drawPixmap(QRect(QPoint(radius, radius) + offset, QSize(px.width(), px.height())), px);
#if QT_VERSION > 0x050000
cache.setDevicePixelRatio(devicePixelRatio);
#endif
QPixmapCache::insert(pixmapName, cache); QPixmapCache::insert(pixmapName, cache);
} }
QRect targetRect = cache.rect(); QRect targetRect = cache.rect();
targetRect.moveCenter(rect.center()); targetRect.setSize(targetRect.size() / pixmapDevicePixelRatio(cache));
p->drawPixmap(targetRect.topLeft() - offset, cache); targetRect.moveCenter(rect.center() - dipOffset);
p->drawPixmap(targetRect, cache);
} }
// Draws a CSS-like border image where the defined borders are not stretched // Draws a CSS-like border image where the defined borders are not stretched
......
...@@ -83,8 +83,8 @@ public: ...@@ -83,8 +83,8 @@ public:
static bool usePixmapCache() { return true; } static bool usePixmapCache() { return true; }
static void drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode, static void drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode,
int radius = 3, const QColor &color = QColor(0, 0, 0, 130), int dipRadius = 3, const QColor &color = QColor(0, 0, 0, 130),
const QPoint &offset = QPoint(1, -2)); const QPoint &dipOffset = QPoint(1, -2));
static void drawCornerImage(const QImage &img, QPainter *painter, QRect rect, static void drawCornerImage(const QImage &img, QPainter *painter, QRect rect,
int left = 0, int top = 0, int right = 0, int bottom = 0); int left = 0, int top = 0, int right = 0, int bottom = 0);
......
<RCC> <RCC>
<qresource prefix="/"> <qresource prefix="/">
<file>images/analyzer_mode.png</file> <file>images/analyzer_mode.png</file>
<file>images/analyzer_mode@2x.png</file>
<file>images/analyzer_category.png</file> <file>images/analyzer_category.png</file>
<file>images/analyzer_start_small.png</file> <file>images/analyzer_start_small.png</file>
</qresource> </qresource>
......
...@@ -204,6 +204,7 @@ const char ICON_CLOSE_SPLIT_RIGHT[] = ":/core/images/splitbutton_closeright.png ...@@ -204,6 +204,7 @@ const char ICON_CLOSE_SPLIT_RIGHT[] = ":/core/images/splitbutton_closeright.png
const char ICON_FILTER[] = ":/core/images/filtericon.png"; const char ICON_FILTER[] = ":/core/images/filtericon.png";
const char ICON_LINK[] = ":/core/images/linkicon.png"; const char ICON_LINK[] = ":/core/images/linkicon.png";
const char ICON_QTLOGO_32[] = ":/core/images/logo/32/QtProject-qtcreator.png"; const char ICON_QTLOGO_32[] = ":/core/images/logo/32/QtProject-qtcreator.png";
const char ICON_QTLOGO_64[] = ":/core/images/logo/64/QtProject-qtcreator.png";
const char ICON_QTLOGO_128[] = ":/core/images/logo/128/QtProject-qtcreator.png"; const char ICON_QTLOGO_128[] = ":/core/images/logo/128/QtProject-qtcreator.png";
const char WIZARD_CATEGORY_QT[] = "R.Qt"; const char WIZARD_CATEGORY_QT[] = "R.Qt";
......
<RCC> <RCC>
<qresource prefix="/fancyactionbar"> <qresource prefix="/fancyactionbar">
<file>images/mode_Debug.png</file> <file>images/mode_Debug.png</file>
<file>images/mode_Debug@2x.png</file>
<file>images/mode_Edit.png</file> <file>images/mode_Edit.png</file>
<file>images/mode_Edit@2x.png</file>
<file>images/mode_Output.png</file> <file>images/mode_Output.png</file>
<file>images/mode_Project.png</file> <file>images/mode_Project.png</file>
<file>images/mode_Project@2x.png</file>
<file>images/mode_Reference.png</file> <file>images/mode_Reference.png</file>
<file>images/mode_Reference@2x.png</file>
<file>images/mode_Design.png</file> <file>images/mode_Design.png</file>
<file>images/mode_Design@2x.png</file>
</qresource> </qresource>
</RCC> </RCC>
...@@ -136,7 +136,11 @@ WelcomeMode::WelcomeMode() : ...@@ -136,7 +136,11 @@ WelcomeMode::WelcomeMode() :
, m_networkAccessManagerFactory(new NetworkAccessManagerFactory) , m_networkAccessManagerFactory(new NetworkAccessManagerFactory)
{ {
setDisplayName(tr("Welcome")); setDisplayName(tr("Welcome"));
setIcon(QIcon(QLatin1String(Core::Constants::ICON_QTLOGO_32))); QIcon qtLogo;
qtLogo.addFile(QLatin1String(Core::Constants::ICON_QTLOGO_32));
qtLogo.addFile(QLatin1String(Core::Constants::ICON_QTLOGO_64));
qtLogo.addFile(QLatin1String(Core::Constants::ICON_QTLOGO_128));
setIcon(qtLogo);
setPriority(Core::Constants::P_MODE_WELCOME); setPriority(Core::Constants::P_MODE_WELCOME);
setId(Core::Constants::MODE_WELCOME); setId(Core::Constants::MODE_WELCOME);
setType(Core::Constants::MODE_WELCOME_TYPE); setType(Core::Constants::MODE_WELCOME_TYPE);
......
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