Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/kget/core/kget.cpp b/kget/core/kget.cpp
- index bc2a90b..48f48e8 100644
- --- a/kget/core/kget.cpp
- +++ b/kget/core/kget.cpp
- @@ -4,6 +4,7 @@
- Copyright (C) 2007-2009 Lukas Appelhans <l.appelhans@gmx.de>
- Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
- Copyright (C) 2008 Dario Freddi <drf54321@gmail.com>
- + Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net>
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public
- @@ -740,6 +741,7 @@ TransferGroupScheduler * KGet::m_scheduler = new TransferGroupScheduler();
- MainWindow * KGet::m_mainWindow = 0;
- KUiServerJobs * KGet::m_jobManager = 0;
- TransferHistoryStore * KGet::m_store = 0;
- +QHash<QString, QPixmap> KGet::m_pixmapCache;
- // ------ PRIVATE FUNCTIONS ------
- KGet::KGet()
- @@ -1170,7 +1172,11 @@ bool KGet::safeDeleteFile( const KUrl& url )
- KNotification *KGet::showNotification(QWidget *parent, const QString &eventType,
- const QString &text, const QString &icon, const QString &title, const KNotification::NotificationFlags &flags)
- {
- - return KNotification::event(eventType, title, text, KIcon(icon).pixmap(KIconLoader::SizeMedium), parent, flags);
- + if (!m_pixmapCache.contains(icon)) {
- + m_pixmapCache[icon] = KIcon(icon).pixmap(KIconLoader::SizeMedium);
- + }
- +
- + return KNotification::event(eventType, title, text, m_pixmapCache[icon], parent, flags);
- }
- GenericObserver::GenericObserver(QObject *parent)
- diff --git a/kget/core/kget.h b/kget/core/kget.h
- index b1ca1b0..5a17a5f 100644
- --- a/kget/core/kget.h
- +++ b/kget/core/kget.h
- @@ -2,6 +2,7 @@
- Copyright (C) 2005 Dario Massarin <nekkar@libero.it>
- Copyright (C) 2009 Lukas Appelhans <l.appelhans@gmx.de>
- + Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net>
- Based on:
- kmainwidget.{h,cpp}
- @@ -408,6 +409,12 @@ class KGET_EXPORT KGet
- //pointer to the used TransferHistoryStore
- static TransferHistoryStore *m_store;
- +
- + /**
- + * Caches pixmaps for faster retrieval
- + * @note used in showNotifications and speeds up showing them
- + */
- + static QHash<QString, QPixmap> m_pixmapCache;
- };
- class KGet::TransferData
- diff --git a/kget/core/transfergroup.cpp b/kget/core/transfergroup.cpp
- index c02d074..b279b47 100644
- --- a/kget/core/transfergroup.cpp
- +++ b/kget/core/transfergroup.cpp
- @@ -23,6 +23,7 @@
- #include <QDateTime>
- #include <QDomElement>
- +QHash<QString, QPixmap> TransferGroup::m_pixmapCache;;
- TransferGroup::TransferGroup(TransferTreeModel * model, Scheduler * parent, const QString & name)
- : JobQueue(parent),
- @@ -76,6 +77,20 @@ bool TransferGroup::supportsSpeedLimits()
- return true;
- }
- +void TransferGroup::setIconName(const QString &name)
- +{
- + m_iconName = name;
- +}
- +
- +QPixmap TransferGroup::pixmap()
- +{
- + if (!m_pixmapCache.contains(m_iconName)) {
- + m_pixmapCache[m_iconName] = KIcon(m_iconName).pixmap(32);
- + }
- +
- + return m_pixmapCache[m_iconName];
- +}
- +
- void TransferGroup::setStatus(Status queueStatus)
- {
- JobQueue::setStatus(queueStatus);
- diff --git a/kget/core/transfergroup.h b/kget/core/transfergroup.h
- index 81e2bc1..85c0cf0 100644
- --- a/kget/core/transfergroup.h
- +++ b/kget/core/transfergroup.h
- @@ -246,7 +246,7 @@ class KGET_EXPORT TransferGroup : public JobQueue
- * Set the group's icon
- * @param name the icon's name
- */
- - void setIconName(const QString &name) {m_iconName = name;}
- + void setIconName(const QString &name);
- /**
- * @returns the group's icon's name
- @@ -256,7 +256,7 @@ class KGET_EXPORT TransferGroup : public JobQueue
- /**
- * @return the group's icon
- */
- - QPixmap pixmap() {return KIcon(m_iconName).pixmap(32);}
- + QPixmap pixmap();
- /**
- * @return the handler associated with this group
- @@ -316,6 +316,7 @@ class KGET_EXPORT TransferGroup : public JobQueue
- QString m_iconName;
- QString m_defaultFolder;
- QRegExp m_regExp;
- + static QHash<QString, QPixmap> m_pixmapCache;
- #ifdef HAVE_NEPOMUK
- QStringList m_tags;
- #endif //HAVE_NEPOMUK
- diff --git a/kget/ui/transfersviewdelegate.cpp b/kget/ui/transfersviewdelegate.cpp
- index 40d5ae7..f10ab95 100644
- --- a/kget/ui/transfersviewdelegate.cpp
- +++ b/kget/ui/transfersviewdelegate.cpp
- @@ -48,6 +48,11 @@ GroupStatusButton::GroupStatusButton(const QModelIndex & index, QWidget * parent
- setAttribute(Qt::WA_NoSystemBackground);
- }
- +void GroupStatusButton::resetIconCache()
- +{
- + m_iconCache.clear();
- +}
- +
- void GroupStatusButton::checkStateSet()
- {
- // kDebug(5001) << "GroupStatusButton::checkStateSet";
- @@ -140,9 +145,11 @@ void GroupStatusButton::paintEvent(QPaintEvent * event)
- p.drawEllipse(rect().x()+5, rect().y()+4, rect().width()-10, rect().width()-10);
- }
- - p.drawPixmap(rect().topLeft() + QPoint(offset, offset - 1),
- - icon().pixmap(m_iconSize, isChecked() || m_status == Blinking ?
- - QIcon::Normal : QIcon::Disabled));
- + const QIcon::Mode iconMode = ((isChecked() || (m_status == Blinking)) ? QIcon::Normal : QIcon::Disabled);
- + if (!m_iconCache.contains(iconMode)) {
- + m_iconCache[iconMode] = icon().pixmap(m_iconSize, iconMode);
- + }
- + p.drawPixmap(rect().topLeft() + QPoint(offset, offset - 1), m_iconCache[iconMode]);
- }
- void GroupStatusButton::timerEvent(QTimerEvent *event)
- diff --git a/kget/ui/transfersviewdelegate.h b/kget/ui/transfersviewdelegate.h
- index 7b9e1f0..86262ae 100644
- --- a/kget/ui/transfersviewdelegate.h
- +++ b/kget/ui/transfersviewdelegate.h
- @@ -32,6 +32,13 @@ class GroupStatusButton : public QToolButton
- public:
- GroupStatusButton(const QModelIndex &index, QWidget *parent);
- + /**
- + * GroupStatusButton uses a cache for the set icon, if the
- + * icon changes the cache still remains the same.
- + * To use the new icon you have to call resetCache first.
- + */
- + void resetIconCache();
- +
- protected:
- void checkStateSet();
- void enterEvent(QEvent * event);
- @@ -44,7 +51,8 @@ class GroupStatusButton : public QToolButton
- QModelIndex m_index;
- int m_timerId;
- - int m_iconSize;
- + const int m_iconSize;
- + QHash<int, QPixmap> m_iconCache;
- float m_gradientId;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement