2 * This file is part of the System Settings package
3 * Copyright (C) 2005 Benjamin C Meyer
4 * <ben+systempreferences at meyerhome dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #include "moduleiconitem.h"
23 #include <kiconloader.h>
25 #include <kcmoduleinfo.h>
29 #include <QApplication>
33 #define ICON_WIDTH 100
36 ModuleIconItem::ModuleIconItem( QListWidget
* parent
, const KCModuleInfo
& module
)
37 : QListWidgetItem(SmallIcon( module
.icon(), IMAGE_SIZE
), module
.moduleName(), parent
),
38 imageName(module
.icon())
40 setData( Qt::UserRole
, KIconLoader::DefaultState
);
41 modules
.append(module
);
45 ModuleIconItem::ModuleIconItem( QListWidget
* parent
, const QString
&text
,
46 const QString
&_imageName
)
47 : QListWidgetItem( SmallIcon( _imageName
, IMAGE_SIZE
), text
, parent
),
50 setData( Qt::UserRole
, KIconLoader::DefaultState
);
54 void ModuleIconItem::loadIcon( bool enabled
)
56 int newState
= enabled
? KIconLoader::DefaultState
: KIconLoader::DisabledState
;
57 if( newState
== data( Qt::UserRole
).toInt() )
60 setData( Qt::UserRole
, newState
);
61 setIcon( DesktopIcon( imageName
, IMAGE_SIZE
, newState
) );
64 void ModuleIconItem::setSize()
66 QStyle
*style
= listWidget()->style();
67 QFontMetrics
fm(font());
68 const QRect
&rect
= fm
.boundingRect(0, 0, ICON_WIDTH
, INT_MAX
, Qt::TextWordWrap
, text());
69 setData(Qt::SizeHintRole
, QSize(ICON_WIDTH
, IMAGE_SIZE
+ style
->pixelMetric(QStyle::PM_FocusFrameVMargin
) + rect
.height()));