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
63 #ifndef QT_NO_TREEWIDGET
70 #ifndef QT_NO_TREEWIDGET
79 :
QWidget( parent, f ), d( new Private )
93 glay->
addWidget(
new QLabel( i18n(
"Available attributes:"),
this ), row, 0 );
94 glay->
addWidget(
new QLabel( i18n(
"Current attribute order:"),
this ), row, 2 );
100 #ifndef QT_NO_TREEWIDGET
103 d->availableLV->sortItems( 0, Qt::AscendingOrder );
104 glay->
addWidget( d->availableLV, row, 0 );
117 d->placeHolderItem->setText( 1, i18n(
"All others") );
127 static const struct {
130 const char * tooltip;
134 {
"go-top", 0, 1, I18N_NOOP(
"Move to top" ), SLOT(slotDoubleUpButtonClicked()),
false },
135 {
"go-up", 1, 1, I18N_NOOP(
"Move one up" ), SLOT(slotUpButtonClicked()),
true },
136 {
"go-previous", 2, 0, I18N_NOOP(
"Remove from current attribute order" ), SLOT(slotLeftButtonClicked()),
false },
137 {
"go-next", 2, 2, I18N_NOOP(
"Add to current attribute order" ), SLOT(slotRightButtonClicked()),
false },
138 {
"go-down", 3, 1, I18N_NOOP(
"Move one down" ), SLOT(slotDownButtonClicked()),
true },
139 {
"go-bottom", 4, 1, I18N_NOOP(
"Move to bottom" ), SLOT(slotDoubleDownButtonClicked()),
false }
142 for (
unsigned int i = 0 ; i <
sizeof navButtons /
sizeof *navButtons ; ++i ) {
146 tb->
setToolTip( i18n( navButtons[i].tooltip ) );
147 xlay->
addWidget( tb, navButtons[i].row, navButtons[i].col );
149 connect( tb, SIGNAL(clicked()), navButtons[i].slot );
160 #ifndef QT_NO_TREEWIDGET
162 takePlaceHolderItem();
164 d->availableLV->clear();
165 d->currentLV->clear();
167 const QStringList order = d->mapper->attributeOrder();
174 takePlaceHolderItem();
175 d->currentLV->insertTopLevelItem( d->currentLV->topLevelItemCount(), d->placeHolderItem );
176 last = d->placeHolderItem;
180 last->
setText( 1, d->mapper->name2label( attr ) );
191 item->
setText( 1, d->mapper->name2label( *it ) );
195 if ( !d->placeHolderItem->treeWidget() )
196 d->availableLV->addTopLevelItem( d->placeHolderItem );
200 void Kleo::DNAttributeOrderConfigWidget::takePlaceHolderItem() {
201 #ifndef QT_NO_TREEWIDGET
202 if (
QTreeWidget* lv = d->placeHolderItem->treeWidget() )
203 lv->takeTopLevelItem( lv->indexOfTopLevelItem( d->placeHolderItem ) );
208 #ifndef QT_NO_TREEWIDGET
213 d->mapper->setAttributeOrder( order );
218 kDebug(5150) <<
"Sorry, not implemented: Kleo::DNAttributeOrderConfigWidget::defaults()";
223 void Kleo::DNAttributeOrderConfigWidget::slotAvailableSelectionChanged(
QTreeWidgetItem * item ) {
224 d->navTB[Private::Right]->setEnabled( item );
227 void Kleo::DNAttributeOrderConfigWidget::slotCurrentOrderSelectionChanged(
QTreeWidgetItem * item ) {
228 enableDisableButtons( item );
231 void Kleo::DNAttributeOrderConfigWidget::enableDisableButtons(
QTreeWidgetItem * item ) {
232 #ifndef QT_NO_TREEWIDGET
233 d->navTB[Private::UUp ]->setEnabled( item && d->currentLV->itemAbove( item ) );
234 d->navTB[Private::Up ]->setEnabled( item && d->currentLV->itemAbove( item ) );
235 d->navTB[Private::Left ]->setEnabled( item );
236 d->navTB[Private::Down ]->setEnabled( item && d->currentLV->itemBelow( item ) );
237 d->navTB[Private::DDown]->setEnabled( item && d->currentLV->itemBelow( item ) );
241 void Kleo::DNAttributeOrderConfigWidget::slotUpButtonClicked() {
242 #ifndef QT_NO_TREEWIDGET
243 if ( d->currentLV->selectedItems().size() <= 0 )
246 int itemIndex = d->currentLV->indexOfTopLevelItem( item );
247 if ( itemIndex <= 0 )
249 d->currentLV->takeTopLevelItem( itemIndex );
250 d->currentLV->insertTopLevelItem( itemIndex - 1, item );
251 d->currentLV->clearSelection();
253 enableDisableButtons( item );
258 void Kleo::DNAttributeOrderConfigWidget::slotDoubleUpButtonClicked() {
259 #ifndef QT_NO_TREEWIDGET
260 if ( d->currentLV->selectedItems().size() <= 0 )
263 int itemIndex = d->currentLV->indexOfTopLevelItem( item );
264 if ( itemIndex == 0 )
266 d->currentLV->takeTopLevelItem( itemIndex );
267 d->currentLV->insertTopLevelItem( 0, item );
268 d->currentLV->clearSelection();
270 enableDisableButtons( item );
275 void Kleo::DNAttributeOrderConfigWidget::slotDownButtonClicked() {
276 #ifndef QT_NO_TREEWIDGET
277 if ( d->currentLV->selectedItems().size() <= 0 )
280 int itemIndex = d->currentLV->indexOfTopLevelItem( item );
281 if ( itemIndex + 1 >= d->currentLV->topLevelItemCount() )
283 d->currentLV->takeTopLevelItem( itemIndex );
284 d->currentLV->insertTopLevelItem( itemIndex + 1, item );
285 d->currentLV->clearSelection();
287 enableDisableButtons( item );
292 void Kleo::DNAttributeOrderConfigWidget::slotDoubleDownButtonClicked() {
293 #ifndef QT_NO_TREEWIDGET
294 if ( d->currentLV->selectedItems().size() <= 0 )
297 const int itemIndex = d->currentLV->indexOfTopLevelItem( item );
298 if ( itemIndex + 1 >= d->currentLV->topLevelItemCount() )
300 d->currentLV->takeTopLevelItem( itemIndex );
301 d->currentLV->addTopLevelItem( item );
302 d->currentLV->clearSelection();
304 enableDisableButtons( item );
309 void Kleo::DNAttributeOrderConfigWidget::slotLeftButtonClicked() {
310 #ifndef QT_NO_TREEWIDGET
311 if ( d->currentLV->selectedItems().size() <= 0 )
316 next = d->currentLV->itemAbove( right );
317 d->currentLV->takeTopLevelItem( d->currentLV->indexOfTopLevelItem( right ) );
318 d->availableLV->addTopLevelItem( right );
319 d->availableLV->sortItems( 0, Qt::AscendingOrder );
322 enableDisableButtons( next );
327 void Kleo::DNAttributeOrderConfigWidget::slotRightButtonClicked() {
328 #ifndef QT_NO_TREEWIDGET
329 if ( d->availableLV->selectedItems().size() <= 0 )
334 next = d->availableLV->itemAbove( left );
335 d->availableLV->takeTopLevelItem( d->availableLV->indexOfTopLevelItem( left ) );
336 int newRightIndex = d->currentLV->topLevelItemCount();
337 if ( d->currentLV->selectedItems().size() > 0 ) {
339 newRightIndex = d->currentLV->indexOfTopLevelItem( right );
342 d->currentLV->insertTopLevelItem( newRightIndex, left );
344 enableDisableButtons( left );
345 d->navTB[Private::Right]->setEnabled( next );
void push_back(const T &value)
bool contains(const QString &str, Qt::CaseSensitivity cs) const
void setSpacing(int spacing)
void setRowStretch(int row, int stretch)
QStringList names() const
void setObjectName(const QString &name)
void setAllColumnsShowFocus(bool enable)
void setMargin(int margin)
void addLayout(QLayout *layout, int row, int column, QFlags< Qt::AlignmentFlag > alignment)
bool setAlignment(QWidget *w, QFlags< Qt::AlignmentFlag > alignment)
void setColumnStretch(int column, int stretch)
void setText(int column, const QString &text)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
static const DNAttributeMapper * instance()