37 #include "dnattributeorderconfigwidget.h"
41 #include <tdelocale.h>
44 #include <kiconloader.h>
45 #include <tdeconfig.h>
46 #include <tdeapplication.h>
48 #include <tqtoolbutton.h>
52 #include <tqlistview.h>
53 #include <tqtooltip.h>
57 struct Kleo::DNAttributeOrderConfigWidget::Private {
58 enum { UUp=0, Up=1, Left=2, Right=3, Down=4, DDown=5 };
60 TQListView * availableLV;
61 TQListView * currentLV;
62 TQToolButton * navTB[6];
64 TQListViewItem * placeHolderItem;
69 static void prepare( TQListView * lv ) {
70 lv->setAllColumnsShowFocus(
true );
71 lv->setResizeMode( TQListView::LastColumn );
72 lv->header()->setClickEnabled(
false );
73 lv->addColumn( TQString() );
74 lv->addColumn( i18n(
"Description") );
77 Kleo::DNAttributeOrderConfigWidget::DNAttributeOrderConfigWidget( DNAttributeMapper * mapper, TQWidget * parent,
const char * name, WFlags f )
78 : TQWidget( parent, name, f ), d( 0 )
84 TQGridLayout * glay =
new TQGridLayout(
this, 2, 3, 0, KDialog::spacingHint() );
85 glay->setColStretch( 0, 1 );
86 glay->setColStretch( 2, 1 );
91 glay->addWidget(
new TQLabel( i18n(
"Available attributes:"),
this ), row, 0 );
92 glay->addWidget(
new TQLabel( i18n(
"Current attribute order:"),
this ), row, 2 );
96 glay->setRowStretch( row, 1 );
98 d->availableLV =
new TQListView(
this );
99 prepare( d->availableLV );
100 d->availableLV->setSorting( 0 );
101 glay->addWidget( d->availableLV, row, 0 );
103 d->currentLV =
new TQListView(
this );
104 prepare( d->currentLV );
105 d->currentLV->setSorting( -1 );
106 glay->addWidget( d->currentLV, row, 2 );
108 connect( d->availableLV, TQ_SIGNAL(clicked( TQListViewItem * )),
109 TQ_SLOT(slotAvailableSelectionChanged(TQListViewItem*)) );
110 connect( d->currentLV, TQ_SIGNAL(clicked(TQListViewItem*)),
111 TQ_SLOT(slotCurrentOrderSelectionChanged(TQListViewItem*)) );
113 d->placeHolderItem =
new TQListViewItem( d->availableLV,
"_X_", i18n(
"All others") );
117 TQGridLayout * xlay =
new TQGridLayout( 5, 3, 0,
"xlay" );
118 xlay->setAlignment( AlignCenter );
120 static const struct {
123 const char * tooltip;
126 {
"2uparrow", 0, 1, I18N_NOOP(
"Move to top" ), TQ_SLOT(slotDoubleUpButtonClicked()) },
127 {
"1uparrow", 1, 1, I18N_NOOP(
"Move one up" ), TQ_SLOT(slotUpButtonClicked()) },
128 {
"1leftarrow", 2, 0, I18N_NOOP(
"Remove from current attribute order" ), TQ_SLOT(slotLeftButtonClicked()) },
129 {
"1rightarrow", 2, 2, I18N_NOOP(
"Add to current attribute order" ), TQ_SLOT(slotRightButtonClicked()) },
130 {
"1downarrow", 3, 1, I18N_NOOP(
"Move one down" ), TQ_SLOT(slotDownButtonClicked()) },
131 {
"2downarrow", 4, 1, I18N_NOOP(
"Move to bottom" ), TQ_SLOT(slotDoubleDownButtonClicked()) }
134 for (
unsigned int i = 0 ; i <
sizeof navButtons /
sizeof *navButtons ; ++i ) {
135 TQToolButton * tb = d->navTB[i] =
new TQToolButton(
this );
136 tb->setIconSet( SmallIconSet( navButtons[i].icon ) );
137 tb->setEnabled(
false );
138 TQToolTip::add( tb, i18n( navButtons[i].tooltip ) );
139 xlay->addWidget( tb, navButtons[i].row, navButtons[i].col );
140 connect( tb, TQ_SIGNAL(clicked()), navButtons[i].slot );
143 glay->addLayout( xlay, row, 1 );
146 Kleo::DNAttributeOrderConfigWidget::~DNAttributeOrderConfigWidget() {
150 void Kleo::DNAttributeOrderConfigWidget::load() {
152 takePlaceHolderItem();
154 d->availableLV->clear();
155 d->currentLV->clear();
157 const TQStringList order = d->mapper->attributeOrder();
160 TQListViewItem * last = 0;
161 for ( TQStringList::const_iterator it = order.begin() ; it != order.end() ; ++it ) {
162 const TQString attr = (*it).upper();
163 if ( attr ==
"_X_" ) {
164 takePlaceHolderItem();
165 d->currentLV->insertItem( d->placeHolderItem );
166 d->placeHolderItem->moveItem( last );
167 last = d->placeHolderItem;
169 last =
new TQListViewItem( d->currentLV, last, attr, d->mapper->name2label( attr ) );
174 const TQStringList all = Kleo::DNAttributeMapper::instance()->names();
175 for ( TQStringList::const_iterator it = all.begin() ; it != all.end() ; ++it )
176 if ( order.find( *it ) == order.end() )
177 (void)
new TQListViewItem( d->availableLV, *it, d->mapper->name2label( *it ) );
179 if ( !d->placeHolderItem->listView() )
180 d->availableLV->insertItem( d->placeHolderItem );
183 void Kleo::DNAttributeOrderConfigWidget::takePlaceHolderItem() {
184 if ( TQListView * lv = d->placeHolderItem->listView() )
185 lv->takeItem( d->placeHolderItem );
188 void Kleo::DNAttributeOrderConfigWidget::save()
const {
190 for ( TQListViewItemIterator it( d->currentLV ) ; it.current() ; ++it )
191 order.push_back( it.current()->text( 0 ) );
193 d->mapper->setAttributeOrder( order );
196 void Kleo::DNAttributeOrderConfigWidget::defaults() {
197 kdDebug() <<
"Sorry, not implemented: Kleo::DNAttributeOrderConfigWidget::defaults()" << endl;
202 void Kleo::DNAttributeOrderConfigWidget::slotAvailableSelectionChanged( TQListViewItem * item ) {
203 d->navTB[Private::Right]->setEnabled( item );
206 void Kleo::DNAttributeOrderConfigWidget::slotCurrentOrderSelectionChanged( TQListViewItem * item ) {
207 enableDisableButtons( item );
210 void Kleo::DNAttributeOrderConfigWidget::enableDisableButtons( TQListViewItem * item ) {
211 d->navTB[Private::UUp ]->setEnabled( item && item->itemAbove() );
212 d->navTB[Private::Up ]->setEnabled( item && item->itemAbove() );
213 d->navTB[Private::Left ]->setEnabled( item );
214 d->navTB[Private::Down ]->setEnabled( item && item->itemBelow() );
215 d->navTB[Private::DDown]->setEnabled( item && item->itemBelow() );
218 void Kleo::DNAttributeOrderConfigWidget::slotUpButtonClicked() {
219 TQListViewItem * item = d->currentLV->selectedItem();
222 TQListViewItem * above = item->itemAbove();
225 above->moveItem( item );
226 enableDisableButtons( item );
230 void Kleo::DNAttributeOrderConfigWidget::slotDoubleUpButtonClicked() {
231 TQListViewItem * item = d->currentLV->selectedItem();
234 if ( item == d->currentLV->firstChild() )
236 d->currentLV->takeItem( item );
237 d->currentLV->insertItem( item );
238 d->currentLV->setSelected( item,
true );
239 enableDisableButtons( item );
243 void Kleo::DNAttributeOrderConfigWidget::slotDownButtonClicked() {
244 TQListViewItem * item = d->currentLV->selectedItem();
247 TQListViewItem * below = item->itemBelow();
250 item->moveItem( below );
251 enableDisableButtons( item );
255 void Kleo::DNAttributeOrderConfigWidget::slotDoubleDownButtonClicked() {
256 TQListViewItem * item = d->currentLV->selectedItem();
259 TQListViewItem * last = d->currentLV->lastItem();
263 item->moveItem( last );
264 enableDisableButtons( item );
268 void Kleo::DNAttributeOrderConfigWidget::slotLeftButtonClicked() {
269 TQListViewItem * right = d->currentLV->selectedItem();
272 TQListViewItem * next = right->itemBelow();
274 next = right->itemAbove();
275 d->currentLV->takeItem( right );
276 d->availableLV->insertItem( right );
278 d->currentLV->setSelected( next,
true );
279 enableDisableButtons( next );
283 void Kleo::DNAttributeOrderConfigWidget::slotRightButtonClicked() {
284 TQListViewItem * left = d->availableLV->selectedItem();
287 TQListViewItem * next = left->itemBelow();
289 next = left->itemAbove();
290 d->availableLV->takeItem( left );
291 d->currentLV->insertItem( left );
292 if ( TQListViewItem * right = d->currentLV->selectedItem() ) {
293 if ( TQListViewItem * above = right->itemAbove() )
294 left->moveItem( above );
295 d->currentLV->setSelected( right,
false );
297 d->currentLV->setSelected( left,
true );
298 enableDisableButtons( left );
299 d->navTB[Private::Right]->setEnabled( next );
301 d->availableLV->setSelected( next,
true );
307 void Kleo::DNAttributeOrderConfigWidget::virtual_hook(
int,
void* ) {}
309 #include "dnattributeorderconfigwidget.moc"