Commit d01e7f8a authored by kaniini's avatar kaniini

Merge branch 'icon-caching' into 'master'

Add Caching, reduce the aliasing of the icons

See merge request !8
parents 457cda34 7967300f
......@@ -4,6 +4,7 @@
#include <QHeaderView>
#include <QBitmap>
#include <QPalette>
#include <QPixmapCache>
#include "timelinewidget.h"
#include "composeform.h"
......@@ -14,6 +15,7 @@
// control the size of the actionbar
#define ACTIONBAR_ICON_SIZE 16
#define ACTIONBAR_ICON_SUPERSIZED ACTIONBAR_ICON_SIZE * 3
#define ACTIONBAR_CONTAINER_MARGIN 8
#define ACTIONBAR_CONTAINER_HEIGHT (ACTIONBAR_ICON_SIZE + (ACTIONBAR_CONTAINER_MARGIN * 2))
#define ACTIONBAR_ICON_SPACING 20
......@@ -72,7 +74,7 @@ static QPixmap colorize_pixmap (QPixmap pixmap, QColor color) {
return result;
}
static QColor desaturate(QColor c)
static QColor desaturate (QColor c)
{
int h, s, v;
c.getHsv(&h, &s, &v);
......@@ -81,29 +83,36 @@ static QColor desaturate(QColor c)
return QColor::fromHsv(h, s, v);
}
static QString icon_name_id (QString icon_name, QString fallback, IconState state){
return icon_name +" :" + fallback + state;
}
static QPixmap pixmap_from_theme (QPalette palette, QString icon_name, QString fallback, IconState state=Default)
{
QIcon base = QIcon::fromTheme (icon_name, QIcon (fallback));
QIcon derived = QIcon ();
switch(state){
case Default:
derived.addPixmap (colorize_pixmap (base.pixmap (ACTIONBAR_ICON_SIZE, ACTIONBAR_ICON_SIZE),
palette.text ().color ()));
break;
case Highlighted:
derived.addPixmap (colorize_pixmap (base.pixmap (ACTIONBAR_ICON_SIZE, ACTIONBAR_ICON_SIZE),
desaturate (palette.highlight ().color ())));
break;
case Enabled:
derived.addPixmap (colorize_pixmap (base.pixmap (ACTIONBAR_ICON_SIZE, ACTIONBAR_ICON_SIZE),
palette.highlight ().color ()));
break;
QString ico_key=icon_name_id (icon_name, fallback, state);
QPixmap cached_pixmap;
if(!QPixmapCache::find (ico_key, &cached_pixmap)){
switch(state){
case Default:
cached_pixmap = colorize_pixmap (base.pixmap (ACTIONBAR_ICON_SUPERSIZED, ACTIONBAR_ICON_SUPERSIZED),
palette.text ().color ());
break;
case Highlighted:
cached_pixmap = colorize_pixmap (base.pixmap (ACTIONBAR_ICON_SUPERSIZED, ACTIONBAR_ICON_SUPERSIZED),
desaturate (palette.highlight ().color ()));
break;
case Enabled:
cached_pixmap = colorize_pixmap (base.pixmap (ACTIONBAR_ICON_SUPERSIZED, ACTIONBAR_ICON_SUPERSIZED),
palette.highlight ().color ());
break;
}
QPixmapCache::insert (ico_key, cached_pixmap);
}
derived.addPixmap (cached_pixmap);
return derived.pixmap (ACTIONBAR_ICON_SIZE, ACTIONBAR_ICON_SIZE);
}
......
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