00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifdef HAVE_CONFIG_H
00034 #include <config.h>
00035 #endif
00036
00037 #include "dnattributeorderconfigwidget.h"
00038
00039 #include "kleo/dn.h"
00040
00041 #include <klocale.h>
00042 #include <kdebug.h>
00043 #include <kdialog.h>
00044 #include <kiconloader.h>
00045 #include <kconfig.h>
00046 #include <kapplication.h>
00047
00048 #include <tqtoolbutton.h>
00049 #include <tqlayout.h>
00050 #include <tqheader.h>
00051 #include <tqlabel.h>
00052 #include <tqlistview.h>
00053 #include <tqtooltip.h>
00054
00055 #include <assert.h>
00056
00057 struct Kleo::DNAttributeOrderConfigWidget::Private {
00058 enum { UUp=0, Up=1, Left=2, Right=3, Down=4, DDown=5 };
00059
00060 TQListView * availableLV;
00061 TQListView * currentLV;
00062 TQToolButton * navTB[6];
00063
00064 TQListViewItem * placeHolderItem;
00065
00066 Kleo::DNAttributeMapper * mapper;
00067 };
00068
00069 static void prepare( TQListView * lv ) {
00070 lv->setAllColumnsShowFocus( true );
00071 lv->setResizeMode( TQListView::LastColumn );
00072 lv->header()->setClickEnabled( false );
00073 lv->addColumn( TQString() );
00074 lv->addColumn( i18n("Description") );
00075 }
00076
00077 Kleo::DNAttributeOrderConfigWidget::DNAttributeOrderConfigWidget( DNAttributeMapper * mapper, TQWidget * parent, const char * name, WFlags f )
00078 : TQWidget( parent, name, f ), d( 0 )
00079 {
00080 assert( mapper );
00081 d = new Private();
00082 d->mapper = mapper;
00083
00084 TQGridLayout * glay = new TQGridLayout( this, 2, 3, 0, KDialog::spacingHint() );
00085 glay->setColStretch( 0, 1 );
00086 glay->setColStretch( 2, 1 );
00087
00088 int row = -1;
00089
00090 ++row;
00091 glay->addWidget( new TQLabel( i18n("Available attributes:"), this ), row, 0 );
00092 glay->addWidget( new TQLabel( i18n("Current attribute order:"), this ), row, 2 );
00093
00094
00095 ++row;
00096 glay->setRowStretch( row, 1 );
00097
00098 d->availableLV = new TQListView( this );
00099 prepare( d->availableLV );
00100 d->availableLV->setSorting( 0 );
00101 glay->addWidget( d->availableLV, row, 0 );
00102
00103 d->currentLV = new TQListView( this );
00104 prepare( d->currentLV );
00105 d->currentLV->setSorting( -1 );
00106 glay->addWidget( d->currentLV, row, 2 );
00107
00108 connect( d->availableLV, TQT_SIGNAL(clicked( TQListViewItem * )),
00109 TQT_SLOT(slotAvailableSelectionChanged(TQListViewItem*)) );
00110 connect( d->currentLV, TQT_SIGNAL(clicked(TQListViewItem*)),
00111 TQT_SLOT(slotCurrentOrderSelectionChanged(TQListViewItem*)) );
00112
00113 d->placeHolderItem = new TQListViewItem( d->availableLV, "_X_", i18n("All others") );
00114
00115
00116
00117 TQGridLayout * xlay = new TQGridLayout( 5, 3, 0, "xlay" );
00118 xlay->setAlignment( 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 { "2uparrow", 0, 1, I18N_NOOP( "Move to top" ), TQT_SLOT(slotDoubleUpButtonClicked()) },
00127 { "1uparrow", 1, 1, I18N_NOOP( "Move one up" ), TQT_SLOT(slotUpButtonClicked()) },
00128 { "1leftarrow", 2, 0, I18N_NOOP( "Remove from current attribute order" ), TQT_SLOT(slotLeftButtonClicked()) },
00129 { "1rightarrow", 2, 2, I18N_NOOP( "Add to current attribute order" ), TQT_SLOT(slotRightButtonClicked()) },
00130 { "1downarrow", 3, 1, I18N_NOOP( "Move one down" ), TQT_SLOT(slotDownButtonClicked()) },
00131 { "2downarrow", 4, 1, I18N_NOOP( "Move to bottom" ), TQT_SLOT(slotDoubleDownButtonClicked()) }
00132 };
00133
00134 for ( unsigned int i = 0 ; i < sizeof navButtons / sizeof *navButtons ; ++i ) {
00135 TQToolButton * tb = d->navTB[i] = new TQToolButton( this );
00136 tb->setIconSet( SmallIconSet( navButtons[i].icon ) );
00137 tb->setEnabled( false );
00138 TQToolTip::add( tb, i18n( navButtons[i].tooltip ) );
00139 xlay->addWidget( tb, navButtons[i].row, navButtons[i].col );
00140 connect( tb, TQT_SIGNAL(clicked()), navButtons[i].slot );
00141 }
00142
00143 glay->addLayout( xlay, row, 1 );
00144 }
00145
00146 Kleo::DNAttributeOrderConfigWidget::~DNAttributeOrderConfigWidget() {
00147 delete d; d = 0;
00148 }
00149
00150 void Kleo::DNAttributeOrderConfigWidget::load() {
00151
00152 takePlaceHolderItem();
00153
00154 d->availableLV->clear();
00155 d->currentLV->clear();
00156
00157 const TQStringList order = d->mapper->attributeOrder();
00158
00159
00160 TQListViewItem * last = 0;
00161 for ( TQStringList::const_iterator it = order.begin() ; it != order.end() ; ++it ) {
00162 const TQString attr = (*it).upper();
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 TQListViewItem( d->currentLV, last, attr, d->mapper->name2label( attr ) );
00170 }
00171
00172
00173
00174 const TQStringList all = Kleo::DNAttributeMapper::instance()->names();
00175 for ( TQStringList::const_iterator it = all.begin() ; it != all.end() ; ++it )
00176 if ( order.find( *it ) == order.end() )
00177 (void)new TQListViewItem( 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 ( TQListView * lv = d->placeHolderItem->listView() )
00185 lv->takeItem( d->placeHolderItem );
00186 }
00187
00188 void Kleo::DNAttributeOrderConfigWidget::save() const {
00189 TQStringList order;
00190 for ( TQListViewItemIterator 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 kdDebug() << "Sorry, not implemented: Kleo::DNAttributeOrderConfigWidget::defaults()" << endl;
00198 }
00199
00200
00201
00202 void Kleo::DNAttributeOrderConfigWidget::slotAvailableSelectionChanged( TQListViewItem * item ) {
00203 d->navTB[Private::Right]->setEnabled( item );
00204 }
00205
00206 void Kleo::DNAttributeOrderConfigWidget::slotCurrentOrderSelectionChanged( TQListViewItem * item ) {
00207 enableDisableButtons( item );
00208 }
00209
00210 void Kleo::DNAttributeOrderConfigWidget::enableDisableButtons( TQListViewItem * 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 TQListViewItem * item = d->currentLV->selectedItem();
00220 if ( !item )
00221 return;
00222 TQListViewItem * above = item->itemAbove();
00223 if ( !above )
00224 return;
00225 above->moveItem( item );
00226 enableDisableButtons( item );
00227 emit changed();
00228 }
00229
00230 void Kleo::DNAttributeOrderConfigWidget::slotDoubleUpButtonClicked() {
00231 TQListViewItem * 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 TQListViewItem * item = d->currentLV->selectedItem();
00245 if ( !item )
00246 return;
00247 TQListViewItem * below = item->itemBelow();
00248 if ( !below )
00249 return;
00250 item->moveItem( below );
00251 enableDisableButtons( item );
00252 emit changed();
00253 }
00254
00255 void Kleo::DNAttributeOrderConfigWidget::slotDoubleDownButtonClicked() {
00256 TQListViewItem * item = d->currentLV->selectedItem();
00257 if ( !item )
00258 return;
00259 TQListViewItem * last = d->currentLV->lastItem();
00260 assert( last );
00261 if ( item == last )
00262 return;
00263 item->moveItem( last );
00264 enableDisableButtons( item );
00265 emit changed();
00266 }
00267
00268 void Kleo::DNAttributeOrderConfigWidget::slotLeftButtonClicked() {
00269 TQListViewItem * right = d->currentLV->selectedItem();
00270 if ( !right )
00271 return;
00272 TQListViewItem * 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 TQListViewItem * left = d->availableLV->selectedItem();
00285 if ( !left )
00286 return;
00287 TQListViewItem * next = left->itemBelow();
00288 if ( !next )
00289 next = left->itemAbove();
00290 d->availableLV->takeItem( left );
00291 d->currentLV->insertItem( left );
00292 if ( TQListViewItem * right = d->currentLV->selectedItem() ) {
00293 if ( TQListViewItem * above = right->itemAbove() )
00294 left->moveItem( above );
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"