libyui-qt-pkg  2.47.5
YQIconPool.cc
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: YQIconPool.cc
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38 /-*/
39 
40 #include <qpixmap.h>
41 #include <QIcon>
42 
43 #define YUILogComponent "qt-ui"
44 #include "YUILog.h"
45 #include "utf8.h"
46 
47 #include "YQIconPool.h"
48 
49 using std::endl;
50 
51 
52 
53 YQIconPool * YQIconPool::_iconPool = 0;
54 
55 QPixmap YQIconPool::pkgTaboo() { return iconPool()->cachedIcon( "package-available-locked", true ); }
56 QPixmap YQIconPool::pkgDel() { return iconPool()->cachedIcon( "package-remove", true ); }
57 QPixmap YQIconPool::pkgUpdate() { return iconPool()->cachedIcon( "package-upgrade", true ); }
58 QPixmap YQIconPool::pkgInstall() { return iconPool()->cachedIcon( "package-install", true ); }
59 QPixmap YQIconPool::pkgAutoInstall() { return iconPool()->cachedIcon( "package-install-auto", true ); }
60 QPixmap YQIconPool::pkgAutoUpdate() { return iconPool()->cachedIcon( "package-upgrade-auto", true ); }
61 QPixmap YQIconPool::pkgAutoDel() { return iconPool()->cachedIcon( "package-remove-auto", true ); }
62 QPixmap YQIconPool::pkgKeepInstalled() { return iconPool()->cachedIcon( "package-installed-updated", true ); }
63 QPixmap YQIconPool::pkgNoInst() { return iconPool()->cachedIcon( "package-available", true ); }
64 QPixmap YQIconPool::pkgProtected() { return iconPool()->cachedIcon( "package-installed-locked", true ); }
65 
66 QPixmap YQIconPool::disabledPkgTaboo() { return iconPool()->cachedIcon( "package-available-locked", false ); }
67 QPixmap YQIconPool::disabledPkgDel() { return iconPool()->cachedIcon( "package-remove", false ); }
68 QPixmap YQIconPool::disabledPkgUpdate() { return iconPool()->cachedIcon( "package-upgrade", false ); }
69 QPixmap YQIconPool::disabledPkgInstall() { return iconPool()->cachedIcon( "package-install", false ); }
70 QPixmap YQIconPool::disabledPkgAutoInstall() { return iconPool()->cachedIcon( "package-install-auto", false ); }
71 QPixmap YQIconPool::disabledPkgAutoUpdate() { return iconPool()->cachedIcon( "package-upgrade-auto", false ); }
72 QPixmap YQIconPool::disabledPkgAutoDel() { return iconPool()->cachedIcon( "package-remove-auto", false ); }
73 QPixmap YQIconPool::disabledPkgKeepInstalled() { return iconPool()->cachedIcon( "package-installed-updated", false ); }
74 QPixmap YQIconPool::disabledPkgNoInst() { return iconPool()->cachedIcon( "package-available", false ); }
75 QPixmap YQIconPool::disabledPkgProtected() { return iconPool()->cachedIcon( "package-installed-locked", false ); }
76 
77 QPixmap YQIconPool::normalPkgConflict() { return iconPool()->cachedIcon( "emblem-warning", true ); }
78 
79 QPixmap YQIconPool::treePlus() { return iconPool()->cachedIcon( "list-add", true ); }
80 QPixmap YQIconPool::treeMinus() { return iconPool()->cachedIcon( "list-remove", true ); }
81 
82 QPixmap YQIconPool::warningSign() { return iconPool()->cachedIcon( "emblem-warning", true ); }
83 QPixmap YQIconPool::pkgSatisfied() { return iconPool()->cachedIcon( "package-supported", true ); }
84 
85 QPixmap YQIconPool::tabRemove() { return iconPool()->cachedIcon( "tab-close", true ); }
86 QPixmap YQIconPool::arrowLeft() { return iconPool()->cachedIcon( "arrow-left", true ); }
87 QPixmap YQIconPool::arrowRight() { return iconPool()->cachedIcon( "arrow-right", true ); }
88 QPixmap YQIconPool::arrowDown() { return iconPool()->cachedIcon( "arrow-down", true ); }
89 
91 {
92  if ( ! _iconPool )
93  _iconPool = new YQIconPool();
94 
95  return _iconPool;
96 }
97 
98 
99 YQIconPool::YQIconPool()
100 {
101 }
102 
103 
104 YQIconPool::~YQIconPool()
105 {
106  // NOP
107 }
108 
109 
110 
111 QPixmap
112 YQIconPool::cachedIcon( const QString icon_name, const bool enabled )
113 {
114  Q_INIT_RESOURCE(qt_pkg_icons);
115  QPixmap iconPixmap = _iconCache[ icon_name + enabled ];
116 
117  if ( !iconPixmap )
118  {
119  iconPixmap = loadIcon( icon_name, enabled );
120 
121  if ( !iconPixmap )
122  {
123  // Create an icon for the cache to avoid more than one complaint
124  // and to have a clearly visible error icon (a small red square)
125  iconPixmap = QPixmap( 8, 8 );
126  iconPixmap.fill( Qt::red );
127  }
128  }
129 
130  _iconCache.insert( icon_name + enabled, iconPixmap );
131 
132  return iconPixmap;
133 }
134 
135 
136 QPixmap
137 YQIconPool::loadIcon( const QString icon_name, const bool enabled )
138 {
139  QPixmap iconPixmap = _iconCache[ icon_name + enabled ];
140 
141  if ( QIcon::hasThemeIcon( icon_name ) )
142  {
143  yuiDebug() << "Loading theme icon " << icon_name << endl;
144 
145  QIcon icon = QIcon::fromTheme( icon_name, QIcon( ":/" + icon_name ) );
146  iconPixmap = icon.pixmap( QSize( 16, 16 ), enabled ? QIcon::Normal : QIcon::Disabled );
147  }
148  else
149  {
150  yuiDebug() << "Loading built-in icon " << icon_name << endl;
151 
152  QIcon icon = QIcon( ":/" + icon_name );
153  iconPixmap = icon.pixmap( QSize( 16, 16 ), enabled ? QIcon::Normal : QIcon::Disabled );
154  }
155 
156  if ( !iconPixmap )
157  yuiError() << "Could not load icon " << icon_name << endl;
158 
159  return iconPixmap;
160 }
161 
static YQIconPool * iconPool()
Return the global icon pool.
Definition: YQIconPool.cc:90
QPixmap cachedIcon(const QString icon_name, const bool enabled)
Return the cached icon for &#39;icon_name&#39;.
Definition: YQIconPool.cc:112
QPixmap loadIcon(const QString icon_name, const bool enabled)
Load the icon for &#39;icon_name&#39; from the icon theme or, if that fails, from the compiled-in icons (usin...
Definition: YQIconPool.cc:137