Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.47 KB | None | 0 0
  1. diff --git a/kget/core/kget.cpp b/kget/core/kget.cpp
  2. index bc2a90b..48f48e8 100644
  3. --- a/kget/core/kget.cpp
  4. +++ b/kget/core/kget.cpp
  5. @@ -4,6 +4,7 @@
  6.     Copyright (C) 2007-2009 Lukas Appelhans <l.appelhans@gmx.de>
  7.     Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
  8.     Copyright (C) 2008 Dario Freddi <drf54321@gmail.com>
  9. +   Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net>
  10.  
  11.     This program is free software; you can redistribute it and/or
  12.     modify it under the terms of the GNU General Public
  13. @@ -740,6 +741,7 @@ TransferGroupScheduler * KGet::m_scheduler = new TransferGroupScheduler();
  14.  MainWindow * KGet::m_mainWindow = 0;
  15.  KUiServerJobs * KGet::m_jobManager = 0;
  16.  TransferHistoryStore * KGet::m_store = 0;
  17. +QHash<QString, QPixmap> KGet::m_pixmapCache;
  18.  
  19.  // ------ PRIVATE FUNCTIONS ------
  20.  KGet::KGet()
  21. @@ -1170,7 +1172,11 @@ bool KGet::safeDeleteFile( const KUrl& url )
  22.  KNotification *KGet::showNotification(QWidget *parent, const QString &eventType,
  23.                              const QString &text, const QString &icon, const QString &title, const KNotification::NotificationFlags &flags)
  24.  {
  25. -    return KNotification::event(eventType, title, text, KIcon(icon).pixmap(KIconLoader::SizeMedium), parent, flags);
  26. +    if (!m_pixmapCache.contains(icon)) {
  27. +        m_pixmapCache[icon] = KIcon(icon).pixmap(KIconLoader::SizeMedium);
  28. +    }
  29. +
  30. +    return KNotification::event(eventType, title, text, m_pixmapCache[icon], parent, flags);
  31.  }
  32.  
  33.  GenericObserver::GenericObserver(QObject *parent)
  34. diff --git a/kget/core/kget.h b/kget/core/kget.h
  35. index b1ca1b0..5a17a5f 100644
  36. --- a/kget/core/kget.h
  37. +++ b/kget/core/kget.h
  38. @@ -2,6 +2,7 @@
  39.  
  40.     Copyright (C) 2005 Dario Massarin <nekkar@libero.it>
  41.     Copyright (C) 2009 Lukas Appelhans <l.appelhans@gmx.de>
  42. +   Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net>
  43.  
  44.     Based on:
  45.         kmainwidget.{h,cpp}
  46. @@ -408,6 +409,12 @@ class KGET_EXPORT KGet
  47.  
  48.          //pointer to the used TransferHistoryStore
  49.          static TransferHistoryStore *m_store;
  50. +
  51. +        /**
  52. +         * Caches pixmaps for faster retrieval
  53. +         * @note used in showNotifications and speeds up showing them
  54. +         */
  55. +        static QHash<QString, QPixmap> m_pixmapCache;
  56.  };
  57.  
  58.  class KGet::TransferData
  59. diff --git a/kget/core/transfergroup.cpp b/kget/core/transfergroup.cpp
  60. index c02d074..b279b47 100644
  61. --- a/kget/core/transfergroup.cpp
  62. +++ b/kget/core/transfergroup.cpp
  63. @@ -23,6 +23,7 @@
  64.  #include <QDateTime>
  65.  #include <QDomElement>
  66.  
  67. +QHash<QString, QPixmap> TransferGroup::m_pixmapCache;;
  68.  
  69.  TransferGroup::TransferGroup(TransferTreeModel * model, Scheduler * parent, const QString & name)
  70.      : JobQueue(parent),
  71. @@ -76,6 +77,20 @@ bool TransferGroup::supportsSpeedLimits()
  72.      return true;
  73.  }
  74.  
  75. +void TransferGroup::setIconName(const QString &name)
  76. +{
  77. +    m_iconName = name;
  78. +}
  79. +
  80. +QPixmap TransferGroup::pixmap()
  81. +{
  82. +    if (!m_pixmapCache.contains(m_iconName)) {
  83. +        m_pixmapCache[m_iconName] = KIcon(m_iconName).pixmap(32);
  84. +    }
  85. +
  86. +    return m_pixmapCache[m_iconName];
  87. +}
  88. +
  89.  void TransferGroup::setStatus(Status queueStatus)
  90.  {
  91.      JobQueue::setStatus(queueStatus);
  92. diff --git a/kget/core/transfergroup.h b/kget/core/transfergroup.h
  93. index 81e2bc1..85c0cf0 100644
  94. --- a/kget/core/transfergroup.h
  95. +++ b/kget/core/transfergroup.h
  96. @@ -246,7 +246,7 @@ class KGET_EXPORT TransferGroup : public JobQueue
  97.           * Set the group's icon
  98.          * @param name the icon's name
  99.           */
  100. -        void setIconName(const QString &name) {m_iconName = name;}
  101. +        void setIconName(const QString &name);
  102.  
  103.          /**
  104.           * @returns the group's icon's name
  105. @@ -256,7 +256,7 @@ class KGET_EXPORT TransferGroup : public JobQueue
  106.          /**
  107.           * @return the group's icon
  108.           */
  109. -        QPixmap pixmap() {return KIcon(m_iconName).pixmap(32);}
  110. +        QPixmap pixmap();
  111.  
  112.          /**
  113.           * @return the handler associated with this group
  114. @@ -316,6 +316,7 @@ class KGET_EXPORT TransferGroup : public JobQueue
  115.          QString m_iconName;
  116.          QString m_defaultFolder;
  117.          QRegExp m_regExp;
  118. +        static QHash<QString, QPixmap> m_pixmapCache;
  119.  #ifdef HAVE_NEPOMUK
  120.          QStringList m_tags;
  121.  #endif //HAVE_NEPOMUK
  122. diff --git a/kget/ui/transfersviewdelegate.cpp b/kget/ui/transfersviewdelegate.cpp
  123. index 40d5ae7..f10ab95 100644
  124. --- a/kget/ui/transfersviewdelegate.cpp
  125. +++ b/kget/ui/transfersviewdelegate.cpp
  126. @@ -48,6 +48,11 @@ GroupStatusButton::GroupStatusButton(const QModelIndex & index, QWidget * parent
  127.      setAttribute(Qt::WA_NoSystemBackground);
  128.  }
  129.  
  130. +void GroupStatusButton::resetIconCache()
  131. +{
  132. +    m_iconCache.clear();
  133. +}
  134. +
  135.  void GroupStatusButton::checkStateSet()
  136.  {
  137.  //     kDebug(5001) << "GroupStatusButton::checkStateSet";
  138. @@ -140,9 +145,11 @@ void GroupStatusButton::paintEvent(QPaintEvent * event)
  139.          p.drawEllipse(rect().x()+5, rect().y()+4, rect().width()-10, rect().width()-10);
  140.      }
  141.  
  142. -    p.drawPixmap(rect().topLeft() + QPoint(offset, offset - 1),
  143. -                 icon().pixmap(m_iconSize, isChecked() || m_status == Blinking ?
  144. -                                           QIcon::Normal : QIcon::Disabled));
  145. +    const QIcon::Mode iconMode = ((isChecked() || (m_status == Blinking)) ? QIcon::Normal : QIcon::Disabled);
  146. +    if (!m_iconCache.contains(iconMode)) {
  147. +        m_iconCache[iconMode] = icon().pixmap(m_iconSize, iconMode);
  148. +    }
  149. +    p.drawPixmap(rect().topLeft() + QPoint(offset, offset - 1), m_iconCache[iconMode]);
  150.  }
  151.  
  152.  void GroupStatusButton::timerEvent(QTimerEvent *event)
  153. diff --git a/kget/ui/transfersviewdelegate.h b/kget/ui/transfersviewdelegate.h
  154. index 7b9e1f0..86262ae 100644
  155. --- a/kget/ui/transfersviewdelegate.h
  156. +++ b/kget/ui/transfersviewdelegate.h
  157. @@ -32,6 +32,13 @@ class GroupStatusButton : public QToolButton
  158.      public:
  159.          GroupStatusButton(const QModelIndex &index, QWidget *parent);
  160.  
  161. +        /**
  162. +         * GroupStatusButton uses a cache for the set icon, if the
  163. +         * icon changes the cache still remains the same.
  164. +         * To use the new icon you have to call resetCache first.
  165. +         */
  166. +        void resetIconCache();
  167. +
  168.      protected:
  169.          void checkStateSet();
  170.          void enterEvent(QEvent * event);
  171. @@ -44,7 +51,8 @@ class GroupStatusButton : public QToolButton
  172.          QModelIndex m_index;
  173.  
  174.          int m_timerId;
  175. -        int m_iconSize;
  176. +        const int m_iconSize;
  177. +        QHash<int, QPixmap> m_iconCache;
  178.  
  179.          float m_gradientId;
  180.  };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement