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

libkleo

dnattributeorderconfigwidget.cpp

Go to the documentation of this file.
00001 /*  -*- c++ -*-
00002     dnattributeorderconfigwidget.cpp
00003 
00004     This file is part of libkleopatra, the KDE keymanagement library
00005     Copyright (c) 2004 Klar�vdalens Datakonsult AB
00006 
00007     Libkleopatra is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU General Public License as
00009     published by the Free Software Foundation; either version 2 of the
00010     License, or (at your option) any later version.
00011 
00012     Libkleopatra is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021     In addition, as a special exception, the copyright holders give
00022     permission to link the code of this program with any edition of
00023     the Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), and distribute linked
00025     combinations including the two.  You must obey the GNU General
00026     Public License in all respects for all of the code used other than
00027     Qt.  If you modify this file, you may extend this exception to
00028     your version of the file, but you are not obligated to do so.  If
00029     you do not wish to do so, delete this exception statement from
00030     your version.
00031  */
00032 
00033 #include "dnattributeorderconfigwidget.h"
00034 
00035 #include "kleo/dn.h"
00036 
00037 #include <klocale.h>
00038 #include <kdebug.h>
00039 #include <kdialog.h>
00040 #include <kiconloader.h>
00041 #include <kconfig.h>
00042 
00043 #include <QToolButton>
00044 #include <QGridLayout>
00045 #include <QLayout>
00046 #include <QLabel>
00047 
00048 #include <q3listview.h>
00049 #include <q3header.h>
00050 
00051 #include <cassert>
00052 
00053 class Kleo::DNAttributeOrderConfigWidget::Private {
00054 public:
00055   enum { UUp=0, Up=1, Left=2, Right=3, Down=4, DDown=5 };
00056 
00057   Q3ListView * availableLV;
00058   Q3ListView * currentLV;
00059   QToolButton * navTB[6];
00060 
00061   Q3ListViewItem * placeHolderItem;
00062 
00063   Kleo::DNAttributeMapper * mapper;
00064 };
00065 
00066 static void prepare( Q3ListView * lv ) {
00067   lv->setAllColumnsShowFocus( true );
00068   lv->setResizeMode( Q3ListView::LastColumn );
00069   lv->header()->setClickEnabled( false );
00070   lv->addColumn( QString() );
00071   lv->addColumn( i18n("Description") );
00072 }
00073 
00074 Kleo::DNAttributeOrderConfigWidget::DNAttributeOrderConfigWidget( DNAttributeMapper * mapper, QWidget * parent, Qt::WindowFlags f )
00075   : QWidget( parent, f ), d( new Private )
00076 {
00077   assert( mapper );
00078   d->mapper = mapper;
00079 
00080   QGridLayout * glay = new QGridLayout( this );
00081   glay->setMargin( 0 );
00082   glay->setSpacing( KDialog::spacingHint() );
00083   glay->setColumnStretch( 0, 1 );
00084   glay->setColumnStretch( 2, 1 );
00085 
00086   int row = -1;
00087 
00088   ++row;
00089   glay->addWidget( new QLabel( i18n("Available attributes:"), this ), row, 0 );
00090   glay->addWidget( new QLabel( i18n("Current attribute order:"), this ), row, 2 );
00091 
00092 
00093   ++row;
00094   glay->setRowStretch( row, 1 );
00095 
00096   d->availableLV = new Q3ListView( this );
00097   prepare( d->availableLV );
00098   d->availableLV->setSorting( 0 );
00099   glay->addWidget( d->availableLV, row, 0 );
00100 
00101   d->currentLV = new Q3ListView( this );
00102   prepare( d->currentLV );
00103   d->currentLV->setSorting( -1 );
00104   glay->addWidget( d->currentLV, row, 2 );
00105 
00106   connect( d->availableLV, SIGNAL(clicked(Q3ListViewItem*)),
00107        SLOT(slotAvailableSelectionChanged(Q3ListViewItem*)) );
00108   connect( d->currentLV, SIGNAL(clicked(Q3ListViewItem*)),
00109        SLOT(slotCurrentOrderSelectionChanged(Q3ListViewItem*)) );
00110 
00111   d->placeHolderItem = new Q3ListViewItem( d->availableLV, "_X_", i18n("All others") );
00112 
00113   // the up/down/left/right arrow cross:
00114 
00115   QGridLayout * xlay = new QGridLayout();
00116   xlay->setSpacing( 0 );
00117   xlay->setObjectName( "xlay" );
00118   xlay->setAlignment( Qt::AlignCenter );
00119 
00120   static const struct {
00121     const char * icon;
00122     int row, col;
00123     const char * tooltip;
00124     const char * slot;
00125   } navButtons[] = {
00126     { "go-top",    0, 1, I18N_NOOP( "Move to top" ),    SLOT(slotDoubleUpButtonClicked()) },
00127     { "go-up",    1, 1, I18N_NOOP( "Move one up" ),    SLOT(slotUpButtonClicked()) },
00128     { "go-previous",  2, 0, I18N_NOOP( "Remove from current attribute order" ), SLOT(slotLeftButtonClicked()) },
00129     { "go-next", 2, 2, I18N_NOOP( "Add to current attribute order" ), SLOT(slotRightButtonClicked()) },
00130     { "go-down",  3, 1, I18N_NOOP( "Move one down" ),  SLOT(slotDownButtonClicked()) },
00131     { "go-bottom",  4, 1, I18N_NOOP( "Move to bottom" ), SLOT(slotDoubleDownButtonClicked()) }
00132   };
00133 
00134   for ( unsigned int i = 0 ; i < sizeof navButtons / sizeof *navButtons ; ++i ) {
00135     QToolButton * tb = d->navTB[i] = new QToolButton( this );
00136     tb->setIcon( KIcon( navButtons[i].icon ) );
00137     tb->setEnabled( false );
00138     tb->setToolTip( i18n( navButtons[i].tooltip ) );
00139     xlay->addWidget( tb, navButtons[i].row, navButtons[i].col );
00140     connect( tb, SIGNAL(clicked()), navButtons[i].slot );
00141   }
00142 
00143   glay->addLayout( xlay, row, 1 );
00144 }
00145 
00146 Kleo::DNAttributeOrderConfigWidget::~DNAttributeOrderConfigWidget() {
00147   delete d;
00148 }
00149 
00150 void Kleo::DNAttributeOrderConfigWidget::load() {
00151   // save the _X_ item:
00152   takePlaceHolderItem();
00153   // clear the rest:
00154   d->availableLV->clear();
00155   d->currentLV->clear();
00156 
00157   const QStringList order = d->mapper->attributeOrder();
00158 
00159   // fill the RHS listview:
00160   Q3ListViewItem * last = 0;
00161   for ( QStringList::const_iterator it = order.begin() ; it != order.end() ; ++it ) {
00162     const QString attr = (*it).toUpper();
00163     if ( attr == "_X_" ) {
00164       takePlaceHolderItem();
00165       d->currentLV->insertItem( d->placeHolderItem );
00166       d->placeHolderItem->moveItem( last );
00167       last = d->placeHolderItem;
00168     } else
00169       last = new Q3ListViewItem( d->currentLV, last, attr, d->mapper->name2label( attr ) );
00170   }
00171 
00172   // fill the LHS listview with what's left:
00173 
00174   const QStringList all = Kleo::DNAttributeMapper::instance()->names();
00175   for ( QStringList::const_iterator it = all.begin() ; it != all.end() ; ++it )
00176     if ( !order.contains( *it )  )
00177       (void)new Q3ListViewItem( d->availableLV, *it, d->mapper->name2label( *it ) );
00178 
00179   if ( !d->placeHolderItem->listView() )
00180     d->availableLV->insertItem( d->placeHolderItem );
00181 }
00182 
00183 void Kleo::DNAttributeOrderConfigWidget::takePlaceHolderItem() {
00184   if ( Q3ListView * lv = d->placeHolderItem->listView() )
00185     lv->takeItem( d->placeHolderItem );
00186 }
00187 
00188 void Kleo::DNAttributeOrderConfigWidget::save() const {
00189   QStringList order;
00190   for ( Q3ListViewItemIterator it( d->currentLV ) ; it.current() ; ++it )
00191     order.push_back( it.current()->text( 0 ) );
00192 
00193   d->mapper->setAttributeOrder( order );
00194 }
00195 
00196 void Kleo::DNAttributeOrderConfigWidget::defaults() {
00197   kDebug() <<"Sorry, not implemented: Kleo::DNAttributeOrderConfigWidget::defaults()";
00198 }
00199 
00200 
00201 
00202 void Kleo::DNAttributeOrderConfigWidget::slotAvailableSelectionChanged( Q3ListViewItem * item ) {
00203   d->navTB[Private::Right]->setEnabled( item );
00204 }
00205 
00206 void Kleo::DNAttributeOrderConfigWidget::slotCurrentOrderSelectionChanged( Q3ListViewItem * item ) {
00207   enableDisableButtons( item );
00208 }
00209 
00210 void Kleo::DNAttributeOrderConfigWidget::enableDisableButtons( Q3ListViewItem * item ) {
00211   d->navTB[Private::UUp  ]->setEnabled( item && item->itemAbove() );
00212   d->navTB[Private::Up   ]->setEnabled( item && item->itemAbove() );
00213   d->navTB[Private::Left ]->setEnabled( item );
00214   d->navTB[Private::Down ]->setEnabled( item && item->itemBelow() );
00215   d->navTB[Private::DDown]->setEnabled( item && item->itemBelow() );
00216 }
00217 
00218 void Kleo::DNAttributeOrderConfigWidget::slotUpButtonClicked() {
00219   Q3ListViewItem * item = d->currentLV->selectedItem();
00220   if ( !item )
00221     return;
00222   Q3ListViewItem * above = item->itemAbove();
00223   if ( !above )
00224     return;
00225   above->moveItem( item ); // moves "above" to after "item", ie. "item" one up
00226   enableDisableButtons( item );
00227   emit changed();
00228 }
00229 
00230 void Kleo::DNAttributeOrderConfigWidget::slotDoubleUpButtonClicked() {
00231   Q3ListViewItem * item = d->currentLV->selectedItem();
00232   if ( !item )
00233     return;
00234   if ( item == d->currentLV->firstChild() )
00235     return;
00236   d->currentLV->takeItem( item );
00237   d->currentLV->insertItem( item );
00238   d->currentLV->setSelected( item, true );
00239   enableDisableButtons( item );
00240   emit changed();
00241 }
00242 
00243 void Kleo::DNAttributeOrderConfigWidget::slotDownButtonClicked() {
00244   Q3ListViewItem * item = d->currentLV->selectedItem();
00245   if ( !item )
00246     return;
00247   Q3ListViewItem * below = item->itemBelow();
00248   if ( !below )
00249     return;
00250   item->moveItem( below ); // moves "item" to after "below", ie. "item" one down
00251   enableDisableButtons( item );
00252   emit changed();
00253 }
00254 
00255 void Kleo::DNAttributeOrderConfigWidget::slotDoubleDownButtonClicked() {
00256   Q3ListViewItem * item = d->currentLV->selectedItem();
00257   if ( !item )
00258     return;
00259   Q3ListViewItem * last = d->currentLV->lastItem();
00260   assert( last );
00261   if ( item == last )
00262     return;
00263   item->moveItem( last ); // moves "item" to after "last", ie. to the bottom
00264   enableDisableButtons( item );
00265   emit changed();
00266 }
00267 
00268 void Kleo::DNAttributeOrderConfigWidget::slotLeftButtonClicked() {
00269   Q3ListViewItem * right = d->currentLV->selectedItem();
00270   if ( !right )
00271     return;
00272   Q3ListViewItem * next = right->itemBelow();
00273   if ( !next )
00274     next = right->itemAbove();
00275   d->currentLV->takeItem( right );
00276   d->availableLV->insertItem( right );
00277   if ( next )
00278     d->currentLV->setSelected( next, true );
00279   enableDisableButtons( next );
00280   emit changed();
00281 }
00282 
00283 void Kleo::DNAttributeOrderConfigWidget::slotRightButtonClicked() {
00284   Q3ListViewItem * left = d->availableLV->selectedItem();
00285   if ( !left )
00286     return;
00287   Q3ListViewItem * next = left->itemBelow();
00288   if ( !next )
00289     next = left->itemAbove();
00290   d->availableLV->takeItem( left );
00291   d->currentLV->insertItem( left );
00292   if ( Q3ListViewItem * right = d->currentLV->selectedItem() ) {
00293     if ( Q3ListViewItem * above = right->itemAbove() )
00294       left->moveItem( above ); // move new item immediately before old selected
00295     d->currentLV->setSelected( right, false );
00296   }
00297   d->currentLV->setSelected( left, true );
00298   enableDisableButtons( left );
00299   d->navTB[Private::Right]->setEnabled( next );
00300   if ( next )
00301     d->availableLV->setSelected( next, true );
00302   emit changed();
00303 }
00304 
00305 
00306 
00307 void Kleo::DNAttributeOrderConfigWidget::virtual_hook( int, void* ) {}
00308 
00309 #include "dnattributeorderconfigwidget.moc"

libkleo

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

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal