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

KUtils

  • sources
  • kde-4.14
  • kdelibs
  • 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 
33 namespace KSettings
34 {
35 
36 class 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 
48 ComponentsDialog::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 
88 ComponentsDialog::~ComponentsDialog()
89 {
90  delete d;
91 }
92 
93 void ComponentsDialog::addPluginInfo( KPluginInfo * info )
94 {
95  d->plugininfolist.append( info );
96 }
97 
98 void 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 
108 void ComponentsDialog::setPluginInfos( const QList<KPluginInfo *> &plugins )
109 {
110  d->plugininfolist = plugins;
111 }
112 
113 void 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 
133 void 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 
153 void 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 
165 void ComponentsDialog::slotOk()
166 {
167  savePluginInfos();
168  KDialog::slotButtonClicked( Ok );
169 }
170 
171 void ComponentsDialog::slotApply()
172 {
173  savePluginInfos();
174  KDialog::slotButtonClicked( Apply );
175 }
176 
177 } //namespace
178 
179 #include "componentsdialog_p.moc"
i18n
QString i18n(const char *text)
KIconLoader::SizeLarge
Apply
QWidget
KPluginInfo
KSettings::ComponentsDialog::setPluginInfos
void setPluginInfos(const QMap< QString, KPluginInfo * > &plugininfos)
Set list of plugins the dialog offers for selection.
Definition: componentsdialog.cpp:98
QTreeWidgetItem::checkState
Qt::CheckState checkState(int column) const
QDialog::setModal
void setModal(bool modal)
IconSize
int IconSize(KIconLoader::Group group)
kdebug.h
KSettings::ComponentsDialog::slotOk
void slotOk()
Definition: componentsdialog.cpp:165
kconfig.h
QMap< QTreeWidgetItem *, KPluginInfo * >
QTreeWidgetItem::setIcon
void setIcon(int column, const QIcon &icon)
KPluginInfo::comment
QString comment() const
QHBoxLayout
kiconloader.h
KDialog
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
klocale.h
KSettings::ComponentsDialog::addPluginInfo
void addPluginInfo(KPluginInfo *)
Add a plugin that the dialog offers for selection.
Definition: componentsdialog.cpp:93
kplugininfo.h
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
KSeparator
Ok
QTreeWidget
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
KIconLoader::Small
KPluginInfo::setPluginEnabled
void setPluginEnabled(bool enabled)
QObject::setObjectName
void setObjectName(const QString &name)
QVBoxLayout
QList< KPluginInfo * >
QMap::end
iterator end()
QLayout::setMargin
void setMargin(int margin)
componentsdialog_p.h
QMap::begin
iterator begin()
QStringList
QFrame
kseparator.h
QTreeWidgetItem::setCheckState
void setCheckState(int column, Qt::CheckState state)
QTreeWidgetItem
KPluginInfo::icon
QString icon() const
KSettings::ComponentsDialog::slotApply
void slotApply()
Definition: componentsdialog.cpp:171
QWidget::QWidget
QWidget(QWidget *parent, QFlags< Qt::WindowType > f)
QWidget::setCaption
void setCaption(const QString &c)
SmallIcon
QPixmap SmallIcon(const QString &name, int force_size, int state, const QStringList &overlays)
QWidget::show
void show()
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLabel
KSettings::ComponentsDialog::show
void show()
reimplemented
Definition: componentsdialog.cpp:113
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:25:27 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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