40 #include <kiconloader.h>
43 #include <QToolButton>
44 #include <QGridLayout>
48 #include <QTreeWidget>
49 #include <QHeaderView>
53 class Kleo::DNAttributeOrderConfigWidget::Private {
55 enum { UUp=0, Up=1, Left=2, Right=3, Down=4, DDown=5 };
57 #ifndef QT_NO_TREEWIDGET
61 QToolButton * navTB[6];
63 #ifndef QT_NO_TREEWIDGET
70 #ifndef QT_NO_TREEWIDGET
72 lv->setAllColumnsShowFocus(
true );
73 lv->header()->setStretchLastSection(
true );
74 lv->setHeaderLabels( QStringList() <<
QString() << i18n(
"Description") );
79 :
QWidget( parent, f ), d( new Private )
84 QGridLayout * glay =
new QGridLayout(
this );
86 glay->setSpacing( KDialog::spacingHint() );
87 glay->setColumnStretch( 0, 1 );
88 glay->setColumnStretch( 2, 1 );
93 glay->addWidget(
new QLabel( i18n(
"Available attributes:"),
this ), row, 0 );
94 glay->addWidget(
new QLabel( i18n(
"Current attribute order:"),
this ), row, 2 );
98 glay->setRowStretch( row, 1 );
100 #ifndef QT_NO_TREEWIDGET
103 d->availableLV->sortItems( 0, Qt::AscendingOrder );
104 glay->addWidget( d->availableLV, row, 0 );
108 glay->addWidget( d->currentLV, row, 2 );
116 d->placeHolderItem->setText( 0, QLatin1String(
"_X_") );
117 d->placeHolderItem->setText( 1, i18n(
"All others") );
122 QGridLayout * xlay =
new QGridLayout();
123 xlay->setSpacing( 0 );
124 xlay->setObjectName( QLatin1String(
"xlay") );
125 xlay->setAlignment( Qt::AlignCenter );
127 static const struct {
130 const char * tooltip;
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()) }
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 );
150 glay->addLayout( xlay, row, 1 );
158 #ifndef QT_NO_TREEWIDGET
160 takePlaceHolderItem();
162 d->availableLV->clear();
163 d->currentLV->clear();
165 const QStringList order = d->mapper->attributeOrder();
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;
177 last->setText( 0, attr );
178 last->setText( 1, d->mapper->name2label( attr ) );
185 for ( QStringList::const_iterator it = all.begin() ; it != all.end() ; ++it ) {
186 if ( !order.contains( *it ) ) {
188 item->setText( 0, *it );
189 item->setText( 1, d->mapper->name2label( *it ) );
193 if ( !d->placeHolderItem->treeWidget() )
194 d->availableLV->addTopLevelItem( d->placeHolderItem );
198 void Kleo::DNAttributeOrderConfigWidget::takePlaceHolderItem() {
199 #ifndef QT_NO_TREEWIDGET
200 if (
QTreeWidget* lv = d->placeHolderItem->treeWidget() )
201 lv->takeTopLevelItem( lv->indexOfTopLevelItem( d->placeHolderItem ) );
206 #ifndef QT_NO_TREEWIDGET
208 for ( QTreeWidgetItemIterator it( d->currentLV ) ; (*it) ; ++it )
209 order.push_back( (*it)->text( 0 ) );
211 d->mapper->setAttributeOrder( order );
216 kDebug(5150) <<
"Sorry, not implemented: Kleo::DNAttributeOrderConfigWidget::defaults()";
221 void Kleo::DNAttributeOrderConfigWidget::slotAvailableSelectionChanged(
QTreeWidgetItem * item ) {
222 d->navTB[Private::Right]->setEnabled( item );
225 void Kleo::DNAttributeOrderConfigWidget::slotCurrentOrderSelectionChanged(
QTreeWidgetItem * item ) {
226 enableDisableButtons( item );
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 ) );
239 void Kleo::DNAttributeOrderConfigWidget::slotUpButtonClicked() {
240 #ifndef QT_NO_TREEWIDGET
241 if ( d->currentLV->selectedItems().size() <= 0 )
244 int itemIndex = d->currentLV->indexOfTopLevelItem( item );
245 if ( itemIndex <= 0 )
247 d->currentLV->takeTopLevelItem( itemIndex );
248 d->currentLV->insertTopLevelItem( itemIndex - 1, item );
249 d->currentLV->clearSelection();
250 item->setSelected(
true );
251 enableDisableButtons( item );
256 void Kleo::DNAttributeOrderConfigWidget::slotDoubleUpButtonClicked() {
257 #ifndef QT_NO_TREEWIDGET
258 if ( d->currentLV->selectedItems().size() <= 0 )
261 int itemIndex = d->currentLV->indexOfTopLevelItem( item );
262 if ( itemIndex == 0 )
264 d->currentLV->takeTopLevelItem( itemIndex );
265 d->currentLV->insertTopLevelItem( 0, item );
266 d->currentLV->clearSelection();
267 item->setSelected(
true );
268 enableDisableButtons( item );
273 void Kleo::DNAttributeOrderConfigWidget::slotDownButtonClicked() {
274 #ifndef QT_NO_TREEWIDGET
275 if ( d->currentLV->selectedItems().size() <= 0 )
278 int itemIndex = d->currentLV->indexOfTopLevelItem( item );
279 if ( itemIndex + 1 >= d->currentLV->topLevelItemCount() )
281 d->currentLV->takeTopLevelItem( itemIndex );
282 d->currentLV->insertTopLevelItem( itemIndex + 1, item );
283 d->currentLV->clearSelection();
284 item->setSelected(
true );
285 enableDisableButtons( item );
290 void Kleo::DNAttributeOrderConfigWidget::slotDoubleDownButtonClicked() {
291 #ifndef QT_NO_TREEWIDGET
292 if ( d->currentLV->selectedItems().size() <= 0 )
295 const int itemIndex = d->currentLV->indexOfTopLevelItem( item );
296 if ( itemIndex + 1 >= d->currentLV->topLevelItemCount() )
298 d->currentLV->takeTopLevelItem( itemIndex );
299 d->currentLV->addTopLevelItem( item );
300 d->currentLV->clearSelection();
301 item->setSelected(
true );
302 enableDisableButtons( item );
307 void Kleo::DNAttributeOrderConfigWidget::slotLeftButtonClicked() {
308 #ifndef QT_NO_TREEWIDGET
309 if ( d->currentLV->selectedItems().size() <= 0 )
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 );
319 next->setSelected(
true );
320 enableDisableButtons( next );
325 void Kleo::DNAttributeOrderConfigWidget::slotRightButtonClicked() {
326 #ifndef QT_NO_TREEWIDGET
327 if ( d->availableLV->selectedItems().size() <= 0 )
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 ) {
337 newRightIndex = d->currentLV->indexOfTopLevelItem( right );
338 right->setSelected(
false );
340 d->currentLV->insertTopLevelItem( newRightIndex, left );
341 left->setSelected(
true );
342 enableDisableButtons( left );
343 d->navTB[Private::Right]->setEnabled( next );
345 next->setSelected(
true );
354 #include "dnattributeorderconfigwidget.moc"
QStringList names() const
static const DNAttributeMapper * instance()