not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / systemsettings / kicongrouppage.cpp
blob74124b265b0fe7336b493d99731f6dadf3c729e8
1 /*
2 kicongrouppage.cpp
4 Copyright (c) 2007 Michael D. Stemle, Jr. <manchicken@notsosoft.net>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (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.
23 #include "kicongrouppage.h"
25 #include <QtAlgorithms>
26 #include <QStyle>
28 /*********** KIconGroupPage **************/
29 KIconGroupPage::KIconGroupPage(QWidget* parent) : QFrame(parent) {
30 render();
33 KIconGroupPage::~KIconGroupPage() {
34 // Delete the rows...
35 qDeleteAll(m_rows);
36 m_rows.clear();
39 const KIconGroupRow* KIconGroupPage::appendGroup(QString name) {
40 KIconGroupRow* group = new KIconGroupRow(name, parentWidget());
42 m_rows.insert(name, group);
44 render();
46 return group;
49 const KIconGroupItem* KIconGroupPage::appendIconToGroup(const QString& group,
50 const QIcon& icon,
51 const QString& label) {
52 if (!m_rows.contains(group)) {
53 appendGroup(group);
56 return m_rows[group]->appendIcon(icon, label);
59 void KIconGroupPage::render() {
60 m_layout = new QBoxLayout(QBoxLayout::TopToBottom, parentWidget());
64 /*********** KIconGroupRow **************/
65 KIconGroupRow::KIconGroupRow(QWidget* parent) : QBoxLayout(QBoxLayout::LeftToRight, parent) {
66 render();
69 KIconGroupRow::KIconGroupRow(QString& name, QWidget* parent) : QBoxLayout(QBoxLayout::LeftToRight, parent) {
70 setGroupName(name);
71 render();
74 KIconGroupRow::~KIconGroupRow() {
75 // Let's delete our icons
76 qDeleteAll(m_icons.begin(), m_icons.end());
77 m_icons.clear();
80 const KIconGroupItem* KIconGroupRow::appendIcon( const QIcon& icon, const QString& label ) {
81 KIconGroupItem* item = new KIconGroupItem(parentWidget(),icon,label);
82 item->setParent(parentWidget());
84 m_icons.append(item);
86 return item;
89 void KIconGroupRow::render() {
93 /*********** KIconGroupItem **************/
94 KIconGroupItem::KIconGroupItem(QWidget* parent,
95 const QIcon& icon,
96 const QString& label) : QLabel(parent) {
97 m_parent = parent;
98 m_icon = icon;
99 m_text = label; // Lets keep our own copy...
101 render();
104 void KIconGroupItem::render() {
105 QStyle *stl = 0;
107 // If there's no parent, we've got no style, can't draw an icon.
108 if (!m_parent) {
109 return;
112 setPixmap(static_cast<const QPixmap&>(m_icon.pixmap(m_parent->style()->pixelMetric(QStyle::PM_IconViewIconSize))));
113 setText(m_text);
116 void KIconGroupItem::setParent(QWidget* parent) {
117 m_parent = parent;
119 render();
122 void KIconGroupItem::setIcon(const QIcon& icon) {
123 m_icon = icon;
125 render();
128 void KIconGroupItem::setLabel(const QString& label) {
129 m_text = label;
131 render();
134 #include "kicongrouppage.moc"