Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / kcontrol / hardware / display / display.cpp
blob7b8870fbc87f6ed7d9df44fe55daeb0bc8b648e6
1 /* This file is part of the KDE project
2 Copyright (C) 2003-2004 Nadeem Hasan <nhasan@kde.org>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (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 GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include <QApplication>
21 #include <QLayout>
22 #include <QTabWidget>
23 #include <QVBoxLayout>
24 #include <QDesktopWidget>
26 #include <kcmoduleloader.h>
27 #include <klocale.h>
28 #include <kdialog.h>
30 #include "display.h"
31 #include <KPluginFactory>
32 #include <KPluginLoader>
34 K_PLUGIN_FACTORY(DisplayFactory,
35 registerPlugin<KCMDisplay>();
37 K_EXPORT_PLUGIN(DisplayFactory("display"))
39 KCMDisplay::KCMDisplay( QWidget *parent, const QVariantList & )
40 : KCModule( DisplayFactory::componentData(), parent )
41 , m_changed(false)
43 m_tabs = new QTabWidget( this );
45 addTab( "randr", i18n( "Size && Orientation" ) );
46 addTab( "nvidiadisplay", i18n( "Graphics Adaptor" ) );
47 addTab( "nvidia3d", i18n( "3D Options" ) );
48 addTab( "kgamma", i18n( "Monitor Gamma" ) );
49 if ( QApplication::desktop()->isVirtualDesktop() )
50 addTab( "xinerama", i18n( "Multiple Monitors" ) );
51 addTab( "energy", i18n( "Power Control" ) );
53 QVBoxLayout *top = new QVBoxLayout( this );
54 top->setMargin( 0 );
55 top->setSpacing( KDialog::spacingHint() );
56 top->addWidget( m_tabs );
58 setButtons( Apply|Help );
59 load();
62 void KCMDisplay::addTab( const QString &name, const QString &label )
64 QWidget *page = new QWidget( m_tabs );
65 QVBoxLayout *top = new QVBoxLayout( page );
66 top->setMargin( KDialog::marginHint() );
68 KCModule *kcm = KCModuleLoader::loadModule( name, KCModuleLoader::None,page );
70 if ( kcm )
72 top->addWidget( kcm );
73 m_tabs->addTab( page, label );
75 connect( kcm, SIGNAL( changed(bool) ), SLOT( moduleChanged(bool) ) );
76 m_modules.insert(kcm, false);
78 else
79 delete page;
82 void KCMDisplay::load()
84 for (QMap<KCModule*, bool>::ConstIterator it = m_modules.begin(); it != m_modules.end(); ++it)
85 it.key()->load();
88 void KCMDisplay::save()
90 for (QMap<KCModule*, bool>::Iterator it = m_modules.begin(); it != m_modules.end(); ++it)
91 if (it.value())
92 it.key()->save();
95 void KCMDisplay::moduleChanged( bool isChanged )
97 QMap<KCModule*, bool>::Iterator currentModule = m_modules.find(static_cast<KCModule*>(const_cast<QObject*>(sender())));
98 Q_ASSERT(currentModule != m_modules.end());
99 if (currentModule.value() == isChanged)
100 return;
102 currentModule.value() = isChanged;
104 bool c = false;
106 for (QMap<KCModule*, bool>::ConstIterator it = m_modules.begin(); it != m_modules.end(); ++it) {
107 if (it.value()) {
108 c = true;
109 break;
113 if (m_changed != c) {
114 m_changed = c;
115 emit changed(c);
119 #include "display.moc"