forked from qt-creator/qt-creator
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: Jens Bache-Wiig <jens.bache-wiig@digia.com>
This commit is contained in:
@@ -307,6 +307,10 @@ int main(int argc, char **argv)
|
||||
QtSystemExceptionHandler systemExceptionHandler;
|
||||
#endif
|
||||
|
||||
#if QT_VERSION >= 0x050100
|
||||
app.setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
#endif
|
||||
|
||||
// Manually determine -settingspath command line option
|
||||
// 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
|
||||
|
@@ -35,6 +35,7 @@
|
||||
#include <QPainter>
|
||||
#include <QApplication>
|
||||
#include <QStyleOption>
|
||||
#include <qmath.h>
|
||||
|
||||
// Clamps float color values within (0, 255)
|
||||
static int clamp(float x)
|
||||
@@ -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
|
||||
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;
|
||||
QString pixmapName = QString::fromLatin1("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height());
|
||||
|
||||
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());
|
||||
int devicePixelRatio = qCeil(pixmapDevicePixelRatio(px));
|
||||
int radius = dipRadius * devicePixelRatio;
|
||||
QPoint offset = dipOffset * devicePixelRatio;
|
||||
cache = QPixmap(px.size() + QSize(radius * 2, radius * 2));
|
||||
cache.fill(Qt::transparent);
|
||||
|
||||
@@ -396,7 +414,7 @@ void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect,
|
||||
|
||||
QPainter tmpPainter(&tmp);
|
||||
tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
tmpPainter.drawPixmap(QPoint(radius, radius), px);
|
||||
tmpPainter.drawPixmap(QRect(radius, radius, px.width(), px.height()), px);
|
||||
tmpPainter.end();
|
||||
|
||||
// blur the alpha channel
|
||||
@@ -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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
QRect targetRect = cache.rect();
|
||||
targetRect.moveCenter(rect.center());
|
||||
p->drawPixmap(targetRect.topLeft() - offset, cache);
|
||||
targetRect.setSize(targetRect.size() / pixmapDevicePixelRatio(cache));
|
||||
targetRect.moveCenter(rect.center() - dipOffset);
|
||||
p->drawPixmap(targetRect, cache);
|
||||
}
|
||||
|
||||
// Draws a CSS-like border image where the defined borders are not stretched
|
||||
|
@@ -83,8 +83,8 @@ public:
|
||||
static bool usePixmapCache() { return true; }
|
||||
|
||||
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),
|
||||
const QPoint &offset = QPoint(1, -2));
|
||||
int dipRadius = 3, const QColor &color = QColor(0, 0, 0, 130),
|
||||
const QPoint &dipOffset = QPoint(1, -2));
|
||||
static void drawCornerImage(const QImage &img, QPainter *painter, QRect rect,
|
||||
int left = 0, int top = 0, int right = 0, int bottom = 0);
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>images/analyzer_mode.png</file>
|
||||
<file>images/analyzer_mode@2x.png</file>
|
||||
<file>images/analyzer_category.png</file>
|
||||
<file>images/analyzer_start_small.png</file>
|
||||
</qresource>
|
||||
|
BIN
src/plugins/analyzerbase/images/analyzer_mode@2x.png
Normal file
BIN
src/plugins/analyzerbase/images/analyzer_mode@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
@@ -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_LINK[] = ":/core/images/linkicon.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 WIZARD_CATEGORY_QT[] = "R.Qt";
|
||||
|
@@ -1,10 +1,15 @@
|
||||
<RCC>
|
||||
<qresource prefix="/fancyactionbar">
|
||||
<file>images/mode_Debug.png</file>
|
||||
<file>images/mode_Debug@2x.png</file>
|
||||
<file>images/mode_Edit.png</file>
|
||||
<file>images/mode_Edit@2x.png</file>
|
||||
<file>images/mode_Output.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@2x.png</file>
|
||||
<file>images/mode_Design.png</file>
|
||||
<file>images/mode_Design@2x.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
BIN
src/plugins/coreplugin/images/mode_Debug@2x.png
Normal file
BIN
src/plugins/coreplugin/images/mode_Debug@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
BIN
src/plugins/coreplugin/images/mode_Design@2x.png
Normal file
BIN
src/plugins/coreplugin/images/mode_Design@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.1 KiB |
BIN
src/plugins/coreplugin/images/mode_Edit@2x.png
Normal file
BIN
src/plugins/coreplugin/images/mode_Edit@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
BIN
src/plugins/coreplugin/images/mode_Project@2x.png
Normal file
BIN
src/plugins/coreplugin/images/mode_Project@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
BIN
src/plugins/coreplugin/images/mode_Reference@2x.png
Normal file
BIN
src/plugins/coreplugin/images/mode_Reference@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
@@ -136,7 +136,11 @@ WelcomeMode::WelcomeMode() :
|
||||
, m_networkAccessManagerFactory(new NetworkAccessManagerFactory)
|
||||
{
|
||||
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);
|
||||
setId(Core::Constants::MODE_WELCOME);
|
||||
setType(Core::Constants::MODE_WELCOME_TYPE);
|
||||
|
Reference in New Issue
Block a user