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

libkleo

  • sources
  • kde-4.12
  • kdepim
  • libkleo
  • ui
dnattributeorderconfigwidget.cpp
Go to the documentation of this file.
1 /* -*- c++ -*-
2  dnattributeorderconfigwidget.cpp
3 
4  This file is part of libkleopatra, the KDE keymanagement library
5  Copyright (c) 2004 Klarävdalens Datakonsult AB
6 
7  Libkleopatra is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of the
10  License, or (at your option) any later version.
11 
12  Libkleopatra 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 GNU
15  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  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31  */
32 
33 #include "dnattributeorderconfigwidget.h"
34 
35 #include "kleo/dn.h"
36 
37 #include <klocale.h>
38 #include <kdebug.h>
39 #include <kdialog.h>
40 #include <kiconloader.h>
41 #include <kconfig.h>
42 
43 #include <QToolButton>
44 #include <QGridLayout>
45 #include <QLayout>
46 #include <QLabel>
47 
48 #include <QTreeWidget>
49 #include <QHeaderView>
50 
51 #include <cassert>
52 
53 class Kleo::DNAttributeOrderConfigWidget::Private {
54 public:
55  enum { UUp=0, Up=1, Left=2, Right=3, Down=4, DDown=5 };
56 
57 #ifndef QT_NO_TREEWIDGET
58  QTreeWidget * availableLV;
59  QTreeWidget* currentLV;
60 #endif
61  QToolButton * navTB[6];
62 
63 #ifndef QT_NO_TREEWIDGET
64  QTreeWidgetItem * placeHolderItem;
65 #endif
66 
67  Kleo::DNAttributeMapper * mapper;
68 };
69 
70 #ifndef QT_NO_TREEWIDGET
71 static void prepare( QTreeWidget * lv ) {
72  lv->setAllColumnsShowFocus( true );
73  lv->header()->setStretchLastSection( true );
74  lv->setHeaderLabels( QStringList() << QString() << i18n("Description") );
75 }
76 #endif
77 
78 Kleo::DNAttributeOrderConfigWidget::DNAttributeOrderConfigWidget( DNAttributeMapper * mapper, QWidget * parent, Qt::WindowFlags f )
79  : QWidget( parent, f ), d( new Private )
80 {
81  assert( mapper );
82  d->mapper = mapper;
83 
84  QGridLayout * glay = new QGridLayout( this );
85  glay->setMargin( 0 );
86  glay->setSpacing( KDialog::spacingHint() );
87  glay->setColumnStretch( 0, 1 );
88  glay->setColumnStretch( 2, 1 );
89 
90  int row = -1;
91 
92  ++row;
93  glay->addWidget( new QLabel( i18n("Available attributes:"), this ), row, 0 );
94  glay->addWidget( new QLabel( i18n("Current attribute order:"), this ), row, 2 );
95 
96 
97  ++row;
98  glay->setRowStretch( row, 1 );
99 
100 #ifndef QT_NO_TREEWIDGET
101  d->availableLV = new QTreeWidget( this );
102  prepare( d->availableLV );
103  d->availableLV->sortItems( 0, Qt::AscendingOrder );
104  glay->addWidget( d->availableLV, row, 0 );
105 
106  d->currentLV = new QTreeWidget( this );
107  prepare( d->currentLV );
108  glay->addWidget( d->currentLV, row, 2 );
109 
110  connect( d->availableLV, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
111  SLOT(slotAvailableSelectionChanged(QTreeWidgetItem*)) );
112  connect( d->currentLV, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
113  SLOT(slotCurrentOrderSelectionChanged(QTreeWidgetItem*)) );
114 
115  d->placeHolderItem = new QTreeWidgetItem( d->availableLV );
116  d->placeHolderItem->setText( 0, QLatin1String("_X_") );
117  d->placeHolderItem->setText( 1, i18n("All others") );
118 #endif
119 
120  // the up/down/left/right arrow cross:
121 
122  QGridLayout * xlay = new QGridLayout();
123  xlay->setSpacing( 0 );
124  xlay->setObjectName( QLatin1String("xlay") );
125  xlay->setAlignment( Qt::AlignCenter );
126 
127  static const struct {
128  const char * icon;
129  int row, col;
130  const char * tooltip;
131  const char * slot;
132  } navButtons[] = {
133  { "go-top", 0, 1, I18N_NOOP( "Move to top" ), SLOT(slotDoubleUpButtonClicked()) },
134  { "go-up", 1, 1, I18N_NOOP( "Move one up" ), SLOT(slotUpButtonClicked()) },
135  { "go-previous", 2, 0, I18N_NOOP( "Remove from current attribute order" ), SLOT(slotLeftButtonClicked()) },
136  { "go-next", 2, 2, I18N_NOOP( "Add to current attribute order" ), SLOT(slotRightButtonClicked()) },
137  { "go-down", 3, 1, I18N_NOOP( "Move one down" ), SLOT(slotDownButtonClicked()) },
138  { "go-bottom", 4, 1, I18N_NOOP( "Move to bottom" ), SLOT(slotDoubleDownButtonClicked()) }
139  };
140 
141  for ( unsigned int i = 0 ; i < sizeof navButtons / sizeof *navButtons ; ++i ) {
142  QToolButton * tb = d->navTB[i] = new QToolButton( this );
143  tb->setIcon( KIcon( QLatin1String(navButtons[i].icon) ) );
144  tb->setEnabled( false );
145  tb->setToolTip( i18n( navButtons[i].tooltip ) );
146  xlay->addWidget( tb, navButtons[i].row, navButtons[i].col );
147  connect( tb, SIGNAL(clicked()), navButtons[i].slot );
148  }
149 
150  glay->addLayout( xlay, row, 1 );
151 }
152 
153 Kleo::DNAttributeOrderConfigWidget::~DNAttributeOrderConfigWidget() {
154  delete d;
155 }
156 
157 void Kleo::DNAttributeOrderConfigWidget::load() {
158 #ifndef QT_NO_TREEWIDGET
159  // save the _X_ item:
160  takePlaceHolderItem();
161  // clear the rest:
162  d->availableLV->clear();
163  d->currentLV->clear();
164 
165  const QStringList order = d->mapper->attributeOrder();
166 
167  // fill the RHS listview:
168  QTreeWidgetItem* last = 0;
169  for ( QStringList::const_iterator it = order.begin() ; it != order.end() ; ++it ) {
170  const QString attr = (*it).toUpper();
171  if ( attr == QLatin1String("_X_") ) {
172  takePlaceHolderItem();
173  d->currentLV->insertTopLevelItem( d->currentLV->topLevelItemCount(), d->placeHolderItem );
174  last = d->placeHolderItem;
175  } else {
176  last = new QTreeWidgetItem( d->currentLV, last );
177  last->setText( 0, attr );
178  last->setText( 1, d->mapper->name2label( attr ) );
179  }
180  }
181 
182  // fill the LHS listview with what's left:
183 
184  const QStringList all = Kleo::DNAttributeMapper::instance()->names();
185  for ( QStringList::const_iterator it = all.begin() ; it != all.end() ; ++it ) {
186  if ( !order.contains( *it ) ) {
187  QTreeWidgetItem *item = new QTreeWidgetItem( d->availableLV );
188  item->setText( 0, *it );
189  item->setText( 1, d->mapper->name2label( *it ) );
190  }
191  }
192 
193  if ( !d->placeHolderItem->treeWidget() )
194  d->availableLV->addTopLevelItem( d->placeHolderItem );
195 #endif
196 }
197 
198 void Kleo::DNAttributeOrderConfigWidget::takePlaceHolderItem() {
199 #ifndef QT_NO_TREEWIDGET
200  if ( QTreeWidget* lv = d->placeHolderItem->treeWidget() )
201  lv->takeTopLevelItem( lv->indexOfTopLevelItem( d->placeHolderItem ) );
202 #endif
203 }
204 
205 void Kleo::DNAttributeOrderConfigWidget::save() const {
206 #ifndef QT_NO_TREEWIDGET
207  QStringList order;
208  for ( QTreeWidgetItemIterator it( d->currentLV ) ; (*it) ; ++it )
209  order.push_back( (*it)->text( 0 ) );
210 
211  d->mapper->setAttributeOrder( order );
212 #endif
213 }
214 
215 void Kleo::DNAttributeOrderConfigWidget::defaults() {
216  kDebug(5150) <<"Sorry, not implemented: Kleo::DNAttributeOrderConfigWidget::defaults()";
217 }
218 
219 
220 
221 void Kleo::DNAttributeOrderConfigWidget::slotAvailableSelectionChanged( QTreeWidgetItem * item ) {
222  d->navTB[Private::Right]->setEnabled( item );
223 }
224 
225 void Kleo::DNAttributeOrderConfigWidget::slotCurrentOrderSelectionChanged( QTreeWidgetItem * item ) {
226  enableDisableButtons( item );
227 }
228 
229 void Kleo::DNAttributeOrderConfigWidget::enableDisableButtons( QTreeWidgetItem * item ) {
230 #ifndef QT_NO_TREEWIDGET
231  d->navTB[Private::UUp ]->setEnabled( item && d->currentLV->itemAbove( item ) );
232  d->navTB[Private::Up ]->setEnabled( item && d->currentLV->itemAbove( item ) );
233  d->navTB[Private::Left ]->setEnabled( item );
234  d->navTB[Private::Down ]->setEnabled( item && d->currentLV->itemBelow( item ) );
235  d->navTB[Private::DDown]->setEnabled( item && d->currentLV->itemBelow( item ) );
236 #endif
237 }
238 
239 void Kleo::DNAttributeOrderConfigWidget::slotUpButtonClicked() {
240 #ifndef QT_NO_TREEWIDGET
241  if ( d->currentLV->selectedItems().size() <= 0 )
242  return;
243  QTreeWidgetItem * item = d->currentLV->selectedItems().first();
244  int itemIndex = d->currentLV->indexOfTopLevelItem( item );
245  if ( itemIndex <= 0 )
246  return;
247  d->currentLV->takeTopLevelItem( itemIndex );
248  d->currentLV->insertTopLevelItem( itemIndex - 1, item );
249  d->currentLV->clearSelection();
250  item->setSelected( true );
251  enableDisableButtons( item );
252  emit changed();
253 #endif
254 }
255 
256 void Kleo::DNAttributeOrderConfigWidget::slotDoubleUpButtonClicked() {
257 #ifndef QT_NO_TREEWIDGET
258  if ( d->currentLV->selectedItems().size() <= 0 )
259  return;
260  QTreeWidgetItem * item = d->currentLV->selectedItems().first();
261  int itemIndex = d->currentLV->indexOfTopLevelItem( item );
262  if ( itemIndex == 0 )
263  return;
264  d->currentLV->takeTopLevelItem( itemIndex );
265  d->currentLV->insertTopLevelItem( 0, item );
266  d->currentLV->clearSelection();
267  item->setSelected( true );
268  enableDisableButtons( item );
269  emit changed();
270 #endif
271 }
272 
273 void Kleo::DNAttributeOrderConfigWidget::slotDownButtonClicked() {
274 #ifndef QT_NO_TREEWIDGET
275  if ( d->currentLV->selectedItems().size() <= 0 )
276  return;
277  QTreeWidgetItem * item = d->currentLV->selectedItems().first();
278  int itemIndex = d->currentLV->indexOfTopLevelItem( item );
279  if ( itemIndex + 1 >= d->currentLV->topLevelItemCount() )
280  return;
281  d->currentLV->takeTopLevelItem( itemIndex );
282  d->currentLV->insertTopLevelItem( itemIndex + 1, item );
283  d->currentLV->clearSelection();
284  item->setSelected( true );
285  enableDisableButtons( item );
286  emit changed();
287 #endif
288 }
289 
290 void Kleo::DNAttributeOrderConfigWidget::slotDoubleDownButtonClicked() {
291 #ifndef QT_NO_TREEWIDGET
292  if ( d->currentLV->selectedItems().size() <= 0 )
293  return;
294  QTreeWidgetItem * item = d->currentLV->selectedItems().first();
295  const int itemIndex = d->currentLV->indexOfTopLevelItem( item );
296  if ( itemIndex + 1 >= d->currentLV->topLevelItemCount() )
297  return;
298  d->currentLV->takeTopLevelItem( itemIndex );
299  d->currentLV->addTopLevelItem( item );
300  d->currentLV->clearSelection();
301  item->setSelected( true );
302  enableDisableButtons( item );
303  emit changed();
304 #endif
305 }
306 
307 void Kleo::DNAttributeOrderConfigWidget::slotLeftButtonClicked() {
308 #ifndef QT_NO_TREEWIDGET
309  if ( d->currentLV->selectedItems().size() <= 0 )
310  return;
311  QTreeWidgetItem * right = d->currentLV->selectedItems().first();
312  QTreeWidgetItem * next = d->currentLV->itemBelow( right );
313  if ( !next )
314  next = d->currentLV->itemAbove( right );
315  d->currentLV->takeTopLevelItem( d->currentLV->indexOfTopLevelItem( right ) );
316  d->availableLV->addTopLevelItem( right );
317  d->availableLV->sortItems( 0, Qt::AscendingOrder );
318  if ( next )
319  next->setSelected( true );
320  enableDisableButtons( next );
321  emit changed();
322 #endif
323 }
324 
325 void Kleo::DNAttributeOrderConfigWidget::slotRightButtonClicked() {
326 #ifndef QT_NO_TREEWIDGET
327  if ( d->availableLV->selectedItems().size() <= 0 )
328  return;
329  QTreeWidgetItem * left = d->availableLV->selectedItems().first();
330  QTreeWidgetItem* next = d->availableLV->itemBelow( left );
331  if ( !next )
332  next = d->availableLV->itemAbove( left );
333  d->availableLV->takeTopLevelItem( d->availableLV->indexOfTopLevelItem( left ) );
334  int newRightIndex = d->currentLV->topLevelItemCount();
335  if ( d->currentLV->selectedItems().size() > 0 ) {
336  QTreeWidgetItem * right = d->currentLV->selectedItems().first();
337  newRightIndex = d->currentLV->indexOfTopLevelItem( right );
338  right->setSelected( false );
339  }
340  d->currentLV->insertTopLevelItem( newRightIndex, left );
341  left->setSelected( true );
342  enableDisableButtons( left );
343  d->navTB[Private::Right]->setEnabled( next );
344  if ( next )
345  next->setSelected( true );
346  emit changed();
347 #endif
348 }
349 
350 
351 
352 void Kleo::DNAttributeOrderConfigWidget::virtual_hook( int, void* ) {}
353 
354 #include "dnattributeorderconfigwidget.moc"
Kleo::DNAttributeOrderConfigWidget::defaults
void defaults()
Definition: dnattributeorderconfigwidget.cpp:215
QTreeWidget
QWidget
kdtools::all
bool all(InputIterator first, InputIterator last)
Definition: stl_util.h:211
QString
Kleo::DNAttributeOrderConfigWidget::save
void save() const
Definition: dnattributeorderconfigwidget.cpp:205
dn.h
Kleo::DNAttributeMapper
DN Attribute mapper.
Definition: dn.h:53
Kleo::DNAttributeOrderConfigWidget::virtual_hook
virtual void virtual_hook(int, void *)
Definition: dnattributeorderconfigwidget.cpp:352
dnattributeorderconfigwidget.h
Kleo::DNAttributeMapper::names
QStringList names() const
Definition: dn.cpp:522
Kleo::DNAttributeOrderConfigWidget::DNAttributeOrderConfigWidget
DNAttributeOrderConfigWidget(DNAttributeMapper *mapper, QWidget *parent=0, Qt::WindowFlags f=0)
Definition: dnattributeorderconfigwidget.cpp:78
QTreeWidgetItem
Kleo::DNAttributeOrderConfigWidget::~DNAttributeOrderConfigWidget
~DNAttributeOrderConfigWidget()
Definition: dnattributeorderconfigwidget.cpp:153
Kleo::DNAttributeOrderConfigWidget::load
void load()
Definition: dnattributeorderconfigwidget.cpp:157
Kleo::DNAttributeMapper::instance
static const DNAttributeMapper * instance()
Definition: dn.cpp:508
prepare
static void prepare(QTreeWidget *lv)
Definition: dnattributeorderconfigwidget.cpp:71
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:57:48 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkleo

Skip menu "libkleo"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

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