1 | |
2 | /* |
3 | * kcmcontainer.cpp |
4 | * |
5 | * Copyright (C) 2010 David Hubner <hubnerd@ntlworld.com> |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. |
11 | * |
12 | * This program is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with this program; if not, write to the Free Software |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | * |
21 | */ |
22 | |
23 | #include "kcmcontainer.h" |
24 | |
25 | //KDE |
26 | #include <KIcon> |
27 | #include <KDebug> |
28 | |
29 | //QT |
30 | #include <QVBoxLayout> |
31 | #include <QApplication> |
32 | #include <QStyle> |
33 | |
34 | KcmContainer::KcmContainer(QWidget *parent) |
35 | : QScrollArea(parent), |
36 | m_titleLabel(NULL), |
37 | m_centerWidget(NULL), |
38 | m_mod(NULL), |
39 | m_kcmTopEdge(-1) |
40 | { |
41 | setWidgetResizable( true ); |
42 | setFrameStyle( QFrame::NoFrame ); |
43 | |
44 | setContainerLayout(); |
45 | } |
46 | |
47 | KcmContainer::~KcmContainer() |
48 | { |
49 | delete m_mod; |
50 | } |
51 | |
52 | void KcmContainer::setContainerLayout() |
53 | { |
54 | if (!m_mod && m_centerWidget) |
55 | { |
56 | // we have no module, but a widget set up for one, |
57 | // so just return for now |
58 | return; |
59 | } |
60 | |
61 | m_mod = NULL; // will be deleted on the line below |
62 | delete m_centerWidget; |
63 | m_centerWidget = new QWidget(this); |
64 | m_centerWidget->setContentsMargins(0,0,0,0); |
65 | |
66 | QVBoxLayout *centerWidgetLayout = new QVBoxLayout(m_centerWidget); |
67 | centerWidgetLayout->setContentsMargins(0, 0, 0, 0); |
68 | |
69 | QFont bFont; |
70 | bFont.setBold(true); |
71 | |
72 | m_titleLabel = new QLabel(m_centerWidget); |
73 | m_titleLabel->setFont(bFont); |
74 | m_titleLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); |
75 | m_titleLabel->setContentsMargins(style()->pixelMetric(QStyle::PM_DefaultFrameWidth), 0, 0, 0); |
76 | m_titleLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
77 | |
78 | centerWidgetLayout->addWidget(m_titleLabel); |
79 | setWidget(m_centerWidget); |
80 | m_centerWidget->setAutoFillBackground(false); |
81 | setKcmTopEdge(m_kcmTopEdge); |
82 | } |
83 | |
84 | void KcmContainer::setKcm(const KCModuleInfo &info) |
85 | { |
86 | setContainerLayout(); |
87 | |
88 | m_mod = new KCModuleProxy(info); |
89 | m_modInfo = info; |
90 | |
91 | setKcmTitle(info); |
92 | |
93 | m_mod->setWhatsThis(m_mod->quickHelp()); |
94 | m_centerWidget->layout()->addWidget(m_mod); |
95 | } |
96 | |
97 | void KcmContainer::setKcmTopEdge(int y) |
98 | { |
99 | m_kcmTopEdge = y; |
100 | if (m_kcmTopEdge < 0) |
101 | { |
102 | return; |
103 | } |
104 | |
105 | if (m_titleLabel) |
106 | { |
107 | int spacing = style()->layoutSpacing(QSizePolicy::DefaultType, QSizePolicy::DefaultType, Qt::Vertical); |
108 | m_titleLabel->setMinimumHeight(m_kcmTopEdge - spacing); |
109 | } |
110 | } |
111 | |
112 | void KcmContainer::setKcmTitle(const KCModuleInfo &info) |
113 | { |
114 | const QString kcmTitle = info.moduleName(); |
115 | const QString = info.comment(); |
116 | |
117 | m_titleLabel->setText(i18n("%1 ( %2 )" ,kcmTitle,kcmComment)); |
118 | } |
119 | |
120 | QString KcmContainer::helpPath() const |
121 | { |
122 | if(m_mod == NULL) return QString(); |
123 | return m_modInfo.docPath(); |
124 | } |
125 | |
126 | KCModule::Buttons KcmContainer::buttons() const |
127 | { |
128 | return m_mod->buttons(); |
129 | } |
130 | |
131 | const KAboutData *KcmContainer::kcmAboutData() const |
132 | { |
133 | return m_mod->aboutData(); |
134 | } |
135 | |
136 | QString KcmContainer::exportText() const |
137 | { |
138 | return m_mod->realModule()->exportText(); |
139 | } |
140 | |
141 | QString KcmContainer::name() const |
142 | { |
143 | return m_modInfo.moduleName(); |
144 | } |
145 | |
146 | QString KcmContainer::fileName() const |
147 | { |
148 | return m_modInfo.fileName(); |
149 | } |
150 | |