2 Copyright (c) 2000 Matthias Elter <elter@kde.org>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "dockcontainer.h"
21 #include <kapplication.h>
22 #include <kmessagebox.h>
26 #include <kiconloader.h>
32 #include <QApplication>
36 #include "proxywidget.h"
37 #include "aboutwidget.h"
39 #include "dockcontainer.moc"
41 ModuleTitle::ModuleTitle(QWidget
*parent
) :
42 KTitleWidget(parent
) {
46 ModuleTitle::~ModuleTitle() {
50 void ModuleTitle::showTitleFor(ConfigModule
* config
) {
51 kDebug() << "Show title for" << endl
;
55 setWhatsThis(config
->comment() );
56 setCommentText(config
->docPath(), config
->comment(), config
->module()->quickHelp());
57 setPixmap(config
->realIcon(KIconLoader::SizeLarge
));
58 setText(config
->moduleName());
60 kDebug() << "Show title for done" << endl
;
63 void ModuleTitle::setCommentText(const QString
& docPath
, const QString
& text
, const QString
& quickHelp
) {
64 if (text
.isEmpty() && docPath
.isEmpty())
66 else if (docPath
.isEmpty())
69 setComment(quickHelp
+ i18n("<p>Click here to consult the full <a href=\"%1\">Manual</a>.</p>", "help:/" + docPath
));
73 void ModuleTitle::setCommentBaseText() {
74 setComment(i18n("<h1>KDE Info Center</h1>"
75 "There is no quick help available for the active info module."
77 "Click <a href = \"kinfocenter/index.html\">here</a> to read the general Info Center manual.") );
80 DockContainer::DockContainer(AboutWidget
* aboutWidget
, QWidget
*parent
) :
83 QVBoxLayout
* mainLayout
= new QVBoxLayout(this);
85 _moduleTitle
= new ModuleTitle(this);
86 mainLayout
->addWidget(_moduleTitle
);
88 _moduleWidgets
= new QStackedWidget(this);
89 mainLayout
->addWidget(_moduleWidgets
);
91 _busyWidget
= new QLabel(i18n("<big><b>Loading...</b></big>"), this);
92 _busyWidget
->setAlignment(Qt::AlignCenter
);
93 _busyWidget
->setSizePolicy(QSizePolicy::MinimumExpanding
, QSizePolicy::MinimumExpanding
);
95 _moduleWidgets
->addWidget(_busyWidget
);
97 _generalWidget
= aboutWidget
;
98 _moduleWidgets
->addWidget(_generalWidget
);
103 DockContainer::~DockContainer() {
108 ProxyWidget
* DockContainer::initializeModule(ConfigModule
* module
) {
111 QApplication::setOverrideCursor(Qt::WaitCursor
);
113 ProxyWidget
* proxy
= module
->module();
116 //If this module was not in the stack, add it.
117 if ( _moduleWidgets
->indexOf(proxy
) == -1) {
118 _moduleWidgets
->addWidget(proxy
);
123 QApplication::restoreOverrideCursor();
128 bool DockContainer::dockModule(ConfigModule
*module
) {
130 ProxyWidget
* widget
= initializeModule(module
);
133 kDebug() << "Failed to display module" << module
->moduleName() << endl
;
140 if (widget
== _moduleWidgets
->currentWidget()) {
141 kDebug() << "Module already displayed" << endl
;
145 if (widget
->isChanged()) {
147 int res
= KMessageBox::warningYesNoCancel(this, module
? i18n("There are unsaved changes in the active module.\n"
148 "Do you want to apply the changes before running "
149 "the new module or discard the changes?") : i18n("There are unsaved changes in the active module.\n"
150 "Do you want to apply the changes before exiting "
151 "the Control Center or discard the changes?"), i18n("Unsaved Changes"), KStandardGuiItem::apply(), KStandardGuiItem::discard());
152 if (res
== KMessageBox::Cancel
)
156 kDebug() << "Docking module..." << endl
;
158 showConfigWidget(module
);
163 void DockContainer::showAboutWidget() {
164 kDebug() << "Show About Widget" << endl
;
165 _moduleWidgets
->setCurrentWidget(_generalWidget
);
167 _moduleTitle
->hide();
171 void DockContainer::showBusyWidget() {
172 kDebug() << "Show Busy Widget" << endl
;
173 _moduleWidgets
->setCurrentWidget(_busyWidget
);
175 _moduleTitle
->hide();
177 kapp
->processEvents();
181 void DockContainer::showConfigWidget(ConfigModule
* module
) {
182 kDebug() << "Show Config Widget" << endl
;
184 _moduleTitle
->showTitleFor(module
);
185 _moduleTitle
->show();
187 _moduleWidgets
->setCurrentWidget(module
->module());