• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KUtils

  • kutils
  • ksettings
componentsdialog.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 Copyright (C) 2003 Matthias Kretz <kretz@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17
18*/
19
20#include "componentsdialog_p.h"
21#include <klocale.h>
22#include <QtGui/QLayout>
23#include <QtGui/QLabel>
24#include <kplugininfo.h>
25#include <kiconloader.h>
26#include <kdebug.h>
27#include <kconfig.h>
28#include <kseparator.h>
29
30#include <QtCore/QList>
31#include <QtGui/QTreeWidget>
32
33namespace KSettings
34{
35
36class ComponentsDialog::ComponentsDialogPrivate
37{
38 public:
39 QTreeWidget * listview;
40 QFrame * infowidget;
41 QLabel * iconwidget;
42 QLabel * commentwidget;
43 QLabel * descriptionwidget;
44 QMap<QTreeWidgetItem*, KPluginInfo*> plugininfomap;
45 QList<KPluginInfo*> plugininfolist;
46};
47
48ComponentsDialog::ComponentsDialog( QWidget * parent, const char * name )
49 : KDialog( parent ), d( new ComponentsDialogPrivate )
50{
51 setObjectName( name );
52 setModal( false );
53 setCaption( i18n( "Select Components" ) );
54
55 QWidget * page = new QWidget( this );
56 setMainWidget( page );
57 QHBoxLayout *hbox = new QHBoxLayout( page );
58 hbox->setMargin( 0 );
59
60 d->listview = new QTreeWidget( page );
61 d->listview->setMinimumSize( 200, 200 );
62 d->infowidget = new QFrame( page );
63 d->infowidget->setMinimumSize( 200, 200 );
64
65 QVBoxLayout *vbox = new QVBoxLayout( d->infowidget );
66 vbox->setMargin( 0 );
67
68 d->iconwidget = new QLabel( d->infowidget );
69 vbox->addWidget( d->iconwidget );
70 vbox->addWidget( new KSeparator( d->infowidget ) );
71 d->commentwidget = new QLabel( d->infowidget );
72 d->commentwidget->setWordWrap( true );
73 vbox->addWidget( d->commentwidget );
74 d->descriptionwidget = new QLabel( d->infowidget );
75 d->descriptionwidget->setWordWrap( true );
76 vbox->addWidget( d->descriptionwidget );
77
78 d->listview->setAcceptDrops( false );
79
80 connect( d->listview, SIGNAL(itemPressed(QTreeWidgetItem*,int)), this,
81 SLOT(executed(QTreeWidgetItem*,int)) );
82 connect( d->listview, SIGNAL(itemActivated(QTreeWidgetItem*,int)), this,
83 SLOT(executed(QTreeWidgetItem*,int)) );
84 connect( d->listview, SIGNAL(itemSelectionChanged(QTreeWidgetItem*,int)), this,
85 SLOT(executed(QTreeWidgetItem*,int)) );
86}
87
88ComponentsDialog::~ComponentsDialog()
89{
90 delete d;
91}
92
93void ComponentsDialog::addPluginInfo( KPluginInfo * info )
94{
95 d->plugininfolist.append( info );
96}
97
98void ComponentsDialog::setPluginInfos( const QMap<QString, KPluginInfo*> &
99 plugininfos )
100{
101 for( QMap<QString, KPluginInfo*>::ConstIterator it = plugininfos.begin();
102 it != plugininfos.end(); ++it )
103 {
104 d->plugininfolist.append( it.value() );
105 }
106}
107
108void ComponentsDialog::setPluginInfos( const QList<KPluginInfo *> &plugins )
109{
110 d->plugininfolist = plugins;
111}
112
113void ComponentsDialog::show()
114{
115 // clear the treelist
116 d->listview->clear();
117 d->plugininfomap.clear();
118
119 // construct the treelist
120 for( QList<KPluginInfo*>::ConstIterator it = d->plugininfolist.constBegin();
121 it != d->plugininfolist.constEnd(); ++it )
122 {
123 ( *it )->load();
124 QTreeWidgetItem * item = new QTreeWidgetItem( d->listview, QStringList( ( *it )->name() ) );
125 if( ! ( *it )->icon().isEmpty() )
126 item->setIcon( 0, SmallIcon( ( *it )->icon(), IconSize( KIconLoader::Small ) ) );
127 item->setCheckState( 0, ( *it )->isPluginEnabled() ? Qt::Checked : Qt::Unchecked );
128 d->plugininfomap[ item ] = ( *it );
129 }
130 KDialog::show();
131}
132
133void ComponentsDialog::executed( QTreeWidgetItem * item, int )
134{
135 kDebug( 704 ) ;
136 if( item == 0 )
137 return;
138
139 bool checked = ( item->checkState(0) == Qt::Checked );
140
141 kDebug( 704 ) << "it's a " << ( checked ? "checked" : "unchecked" )
142 << " QCheckListItem" << endl;
143
144 KPluginInfo * info = d->plugininfomap[ item ];
145 info->setPluginEnabled( checked );
146 //checkDependencies( info );
147 // show info about the component on the right
148 d->iconwidget->setPixmap( SmallIcon( info->icon(), KIconLoader::SizeLarge ) );
149 d->commentwidget->setText( info->comment() );
150 //d->descriptionwidget->setText( info->description() );
151}
152
153void ComponentsDialog::savePluginInfos()
154{
155 for( QList<KPluginInfo*>::ConstIterator it = d->plugininfolist.constBegin();
156 it != d->plugininfolist.constEnd(); ++it )
157 {
158 if ((*it)->config().isValid()) {
159 ( *it )->save();
160 (*it)->config().sync();
161 }
162 }
163}
164
165void ComponentsDialog::slotOk()
166{
167 savePluginInfos();
168 KDialog::slotButtonClicked( Ok );
169}
170
171void ComponentsDialog::slotApply()
172{
173 savePluginInfos();
174 KDialog::slotButtonClicked( Apply );
175}
176
177} //namespace
178
179#include "componentsdialog_p.moc"
KDialog
KDialog::setMainWidget
void setMainWidget(QWidget *widget)
KDialog::slotButtonClicked
virtual void slotButtonClicked(int button)
KDialog::Ok
Ok
KDialog::Apply
Apply
KDialog::setCaption
virtual void setCaption(const QString &caption)
KIconLoader::Small
Small
KIconLoader::SizeLarge
SizeLarge
KPluginInfo
KPluginInfo::icon
QString icon() const
KPluginInfo::comment
QString comment() const
KPluginInfo::setPluginEnabled
void setPluginEnabled(bool enabled)
KSeparator
KSettings::ComponentsDialog::slotApply
void slotApply()
Definition: componentsdialog.cpp:171
KSettings::ComponentsDialog::slotOk
void slotOk()
Definition: componentsdialog.cpp:165
KSettings::ComponentsDialog::ComponentsDialog
ComponentsDialog(QWidget *parent=0, const char *name=0)
Create Dialog.
Definition: componentsdialog.cpp:48
KSettings::ComponentsDialog::~ComponentsDialog
~ComponentsDialog()
Definition: componentsdialog.cpp:88
KSettings::ComponentsDialog::setPluginInfos
void setPluginInfos(const QMap< QString, KPluginInfo * > &plugininfos)
Set list of plugins the dialog offers for selection.
Definition: componentsdialog.cpp:98
KSettings::ComponentsDialog::show
void show()
reimplemented
Definition: componentsdialog.cpp:113
KSettings::ComponentsDialog::addPluginInfo
void addPluginInfo(KPluginInfo *)
Add a plugin that the dialog offers for selection.
Definition: componentsdialog.cpp:93
QFrame
QLabel
QList
QMap
QTreeWidget
QWidget
componentsdialog_p.h
kDebug
#define kDebug
kconfig.h
kdebug.h
SmallIcon
QPixmap SmallIcon(const QString &name, int force_size, int state, const QStringList &overlays)
IconSize
int IconSize(KIconLoader::Group group)
kiconloader.h
klocale.h
i18n
QString i18n(const char *text)
kplugininfo.h
kseparator.h
KSettings
A collection of classes to create configuration dialogs that work over component boundaries.
Definition: componentsdialog.cpp:34
name
const char * name(StandardAction id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KUtils

Skip menu "KUtils"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal