tdelistview.cpp
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2000 Reginald Stadlbauer <reggie@kde.org> 00003 Copyright (C) 2000,2003 Charles Samuels <charles@kde.org> 00004 Copyright (C) 2000 Peter Putzer 00005 Copyright (C) 2014 Timothy Pearson <kb9vqf@pearsoncomputing.net> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License version 2 as published by the Free Software Foundation. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include "config.h" 00023 00024 #include <tqdragobject.h> 00025 #include <tqtimer.h> 00026 #include <tqheader.h> 00027 #include <tqcursor.h> 00028 #include <tqtooltip.h> 00029 #include <tqstyle.h> 00030 #include <tqpainter.h> 00031 00032 #include <tdeglobalsettings.h> 00033 #include <tdeconfig.h> 00034 #include <kcursor.h> 00035 #include <tdeapplication.h> 00036 #include <kipc.h> 00037 #include <kdebug.h> 00038 00039 #include "tdelistview.h" 00040 #include "tdelistviewlineedit.h" 00041 00042 class TDEListView::Tooltip : public TQToolTip 00043 { 00044 public: 00045 Tooltip (TDEListView* parent, TQToolTipGroup* group = 0L); 00046 virtual ~Tooltip () {} 00047 00048 protected: 00052 virtual void maybeTip (const TQPoint&); 00053 00054 private: 00055 TDEListView* mParent; 00056 }; 00057 00058 TDEListView::Tooltip::Tooltip (TDEListView* parent, TQToolTipGroup* group) 00059 : TQToolTip (parent, group), 00060 mParent (parent) 00061 { 00062 } 00063 00064 void TDEListView::Tooltip::maybeTip (const TQPoint&) 00065 { 00066 // FIXME 00067 } 00068 00069 class TDEListView::TDEListViewPrivate 00070 { 00071 public: 00072 TDEListViewPrivate (TDEListView* listview) 00073 : pCurrentItem (0), 00074 autoSelectDelay(0), 00075 useSmallExecuteArea(false), 00076 dragOverItem(0), 00077 dragDelay(TDEGlobalSettings::dndEventDelay()), 00078 editor(new TDEListViewLineEdit(listview)), 00079 cursorInExecuteArea(false), 00080 itemsMovable (true), 00081 selectedBySimpleMove(false), 00082 selectedUsingMouse(false), 00083 itemsRenameable (false), 00084 validDrag (false), 00085 dragEnabled (false), 00086 autoOpen (true), 00087 disableAutoSelection (false), 00088 dropVisualizer (true), 00089 dropHighlighter (false), 00090 createChildren (true), 00091 pressedOnSelected (false), 00092 wasShiftEvent (false), 00093 fullWidth (false), 00094 sortAscending(true), 00095 tabRename(true), 00096 sortColumn(0), 00097 selectionDirection(0), 00098 selectionRegion(0), 00099 tooltipColumn (0), 00100 selectionMode (Single), 00101 contextMenuKey (TDEGlobalSettings::contextMenuKey()), 00102 showContextMenusOnPress (TDEGlobalSettings::showContextMenusOnPress()), 00103 mDropVisualizerWidth (4), 00104 paintAbove (0), 00105 paintCurrent (0), 00106 paintBelow (0), 00107 painting (false), 00108 shadeSortColumn(TDEGlobalSettings::shadeSortColumn()), 00109 initialFileManagerItem(0) 00110 { 00111 renameable.append(0); 00112 connect(editor, TQT_SIGNAL(done(TQListViewItem*,int)), listview, TQT_SLOT(doneEditing(TQListViewItem*,int))); 00113 connect(editor, TQT_SIGNAL(renameNext(TQListViewItem*,int)), listview, TQT_SLOT(renameNextProxy(TQListViewItem*,int))); 00114 connect(editor, TQT_SIGNAL(renamePrev(TQListViewItem*,int)), listview, TQT_SLOT(renamePrevProxy(TQListViewItem*,int))); 00115 } 00116 00117 ~TDEListViewPrivate () 00118 { 00119 delete editor; 00120 } 00121 00122 TQListViewItem* pCurrentItem; 00123 00124 TQTimer autoSelect; 00125 int autoSelectDelay; 00126 bool useSmallExecuteArea; 00127 00128 TQTimer dragExpand; 00129 TQListViewItem* dragOverItem; 00130 TQPoint dragOverPoint; 00131 00132 TQPoint startDragPos; 00133 int dragDelay; 00134 00135 TDEListViewLineEdit *editor; 00136 TQValueList<int> renameable; 00137 00138 bool cursorInExecuteArea:1; 00139 bool bUseSingle:1; 00140 bool bChangeCursorOverItem:1; 00141 bool itemsMovable:1; 00142 bool selectedBySimpleMove : 1; 00143 bool selectedUsingMouse:1; 00144 bool itemsRenameable:1; 00145 bool validDrag:1; 00146 bool dragEnabled:1; 00147 bool autoOpen:1; 00148 bool disableAutoSelection:1; 00149 bool dropVisualizer:1; 00150 bool dropHighlighter:1; 00151 bool createChildren:1; 00152 bool pressedOnSelected:1; 00153 bool wasShiftEvent:1; 00154 bool fullWidth:1; 00155 bool sortAscending:1; 00156 bool tabRename:1; 00157 00158 int sortColumn; 00159 00160 //+1 means downwards (y increases, -1 means upwards, 0 means not selected), aleXXX 00161 int selectionDirection; 00162 int selectionRegion; 00163 int tooltipColumn; 00164 00165 SelectionModeExt selectionMode; 00166 int contextMenuKey; 00167 bool showContextMenusOnPress; 00168 00169 TQRect mOldDropVisualizer; 00170 int mDropVisualizerWidth; 00171 TQRect mOldDropHighlighter; 00172 TQListViewItem *afterItemDrop; 00173 TQListViewItem *parentItemDrop; 00174 00175 TQListViewItem *paintAbove; 00176 TQListViewItem *paintCurrent; 00177 TQListViewItem *paintBelow; 00178 bool painting:1; 00179 bool shadeSortColumn:1; 00180 00181 TQColor alternateBackground; 00182 00183 TQListViewItem *initialFileManagerItem; 00184 }; 00185 00186 00187 TDEListViewLineEdit::TDEListViewLineEdit(TDEListView *parent) 00188 : KLineEdit(parent->viewport()), item(0), col(0), p(parent), m_renSett() 00189 { 00190 setFrame( false ); 00191 hide(); 00192 connect( parent, TQT_SIGNAL( selectionChanged() ), TQT_SLOT( slotSelectionChanged() )); 00193 connect( parent, TQT_SIGNAL( itemRemoved( TQListViewItem * ) ), 00194 TQT_SLOT( slotItemRemoved( TQListViewItem * ) )); 00195 } 00196 00197 TDEListViewLineEdit::~TDEListViewLineEdit() 00198 { 00199 } 00200 00201 TQListViewItem *TDEListViewLineEdit::currentItem() const 00202 { 00203 return item; 00204 } 00205 00206 void TDEListViewLineEdit::load(TQListViewItem *i, int c) 00207 { 00208 item=i; 00209 col=c; 00210 00211 TQRect rect(p->itemRect(i)); 00212 setText(item->text(c)); 00213 home( true ); 00214 00215 int fieldX = rect.x() - 1; 00216 int fieldW = p->columnWidth(col) + 2; 00217 00218 TQHeader* const pHeader = p->header(); 00219 00220 const int pos = pHeader->mapToIndex(col); 00221 for ( int index = 0; index < pos; ++index ) 00222 fieldX += p->columnWidth( pHeader->mapToSection( index )); 00223 00224 if ( col == 0 ) { 00225 int d = i->depth() + (p->rootIsDecorated() ? 1 : 0); 00226 d *= p->treeStepSize(); 00227 fieldX += d; 00228 fieldW -= d; 00229 } 00230 00231 if ( i->pixmap( col ) ) {// add width of pixmap 00232 int d = i->pixmap( col )->width(); 00233 fieldX += d; 00234 fieldW -= d; 00235 } 00236 00237 setGeometry(fieldX, rect.y() - 1, fieldW, rect.height() + 2); 00238 show(); 00239 setFocus(); 00240 } 00241 00242 /* Helper functions to for 00243 * tabOrderedRename functionality. 00244 */ 00245 00246 static int nextCol (TDEListView *pl, TQListViewItem *pi, int start, int dir) 00247 { 00248 if (pi) 00249 { 00250 // Find the next renameable column in the current row 00251 for (; ((dir == +1) ? (start < pl->columns()) : (start >= 0)); start += dir) 00252 if (pl->isRenameable(start)) 00253 return start; 00254 } 00255 00256 return -1; 00257 } 00258 00259 static TQListViewItem *prevItem (TQListViewItem *pi) 00260 { 00261 TQListViewItem *pa = pi->itemAbove(); 00262 00263 /* Does what the TQListViewItem::previousSibling() 00264 * of my dreams would do. 00265 */ 00266 if (pa && pa->parent() == pi->parent()) 00267 return pa; 00268 00269 return 0; 00270 } 00271 00272 static TQListViewItem *lastQChild (TQListViewItem *pi) 00273 { 00274 if (pi) 00275 { 00276 /* Since there's no TQListViewItem::lastChild(). 00277 * This finds the last sibling for the given 00278 * item. 00279 */ 00280 for (TQListViewItem *pt = pi->nextSibling(); pt; pt = pt->nextSibling()) 00281 pi = pt; 00282 } 00283 00284 return pi; 00285 } 00286 00287 void TDEListViewLineEdit::selectNextCell (TQListViewItem *pitem, int column, bool forward) 00288 { 00289 const int ncols = p->columns(); 00290 const int dir = forward ? +1 : -1; 00291 const int restart = forward ? 0 : (ncols - 1); 00292 TQListViewItem *top = (pitem && pitem->parent()) 00293 ? pitem->parent()->firstChild() 00294 : p->firstChild(); 00295 TQListViewItem *pi = pitem; 00296 00297 terminate(); // Save current changes 00298 00299 do 00300 { 00301 /* Check the rest of the current row for an editable column, 00302 * if that fails, check the entire next/previous row. The 00303 * last case goes back to the first item in the current branch 00304 * or the last item in the current branch depending on the 00305 * direction. 00306 */ 00307 if ((column = nextCol(p, pi, column + dir, dir)) != -1 || 00308 (column = nextCol(p, (pi = (forward ? pi->nextSibling() : prevItem(pi))), restart, dir)) != -1 || 00309 (column = nextCol(p, (pi = (forward ? top : lastQChild(pitem))), restart, dir)) != -1) 00310 { 00311 if (pi) 00312 { 00313 p->setCurrentItem(pi); // Calls terminate 00314 p->rename(pi, column); 00315 00316 /* Some listviews may override rename() to 00317 * prevent certain items from being renamed, 00318 * if this is done, [m_]item will be NULL 00319 * after the rename() call... try again. 00320 */ 00321 if (!item) 00322 continue; 00323 00324 break; 00325 } 00326 } 00327 } 00328 while (pi && !item); 00329 } 00330 00331 #ifdef KeyPress 00332 #undef KeyPress 00333 #endif 00334 00335 bool TDEListViewLineEdit::event(TQEvent *pe) 00336 { 00337 if (pe->type() == TQEvent::KeyPress) 00338 { 00339 TQKeyEvent *k = (TQKeyEvent*)pe; 00340 KKey kk(k); 00341 if (m_renSett.m_useRenameSignals && 00342 (m_renSett.m_SCNext.contains(kk) || m_renSett.m_SCPrev.contains(kk))) 00343 { 00344 keyPressEvent(k); 00345 return true; 00346 } 00347 else if ((k->key() == Qt::Key_Backtab || k->key() == Qt::Key_Tab) && 00348 p->tabOrderedRenaming() && p->itemsRenameable() && 00349 !(k->state() & ControlButton || k->state() & AltButton)) 00350 { 00351 selectNextCell(item, col, (k->key() == Key_Tab && !(k->state() & ShiftButton))); 00352 return true; 00353 } 00354 } 00355 return KLineEdit::event(pe); 00356 } 00357 00358 void TDEListViewLineEdit::keyPressEvent(TQKeyEvent *e) 00359 { 00360 KKey kk(e); 00361 if (m_renSett.m_useRenameSignals && 00362 (m_renSett.m_SCNext.contains(kk) || m_renSett.m_SCPrev.contains(kk))) 00363 { 00364 TQListViewItem *i=item; 00365 int c=col; 00366 terminate(true); 00367 KLineEdit::keyPressEvent(e); 00368 if (m_renSett.m_SCNext.contains(kk)) 00369 { 00370 emit renameNext(i,c); 00371 } 00372 else 00373 { 00374 emit renamePrev(i,c); 00375 } 00376 } 00377 else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) 00378 terminate(true); 00379 else if(e->key() == Qt::Key_Escape) 00380 terminate(false); 00381 else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Up) 00382 { 00383 terminate(true); 00384 KLineEdit::keyPressEvent(e); 00385 } 00386 else 00387 KLineEdit::keyPressEvent(e); 00388 } 00389 00390 void TDEListViewLineEdit::terminate() 00391 { 00392 terminate(true); 00393 } 00394 00395 void TDEListViewLineEdit::terminate(bool commit) 00396 { 00397 if ( item ) 00398 { 00399 //kdDebug() << "TDEListViewLineEdit::terminate " << commit << endl; 00400 if (commit) 00401 item->setText(col, text()); 00402 int c=col; 00403 TQListViewItem *i=item; 00404 col=0; 00405 item=0; 00406 p->setFocus();// will call focusOutEvent, that's why we set item=0 before 00407 hide(); 00408 if (commit) 00409 emit done(i,c); 00410 } 00411 } 00412 00413 void TDEListViewLineEdit::focusOutEvent(TQFocusEvent *ev) 00414 { 00415 TQFocusEvent * focusEv = static_cast<TQFocusEvent*>(ev); 00416 // Don't let a RMB close the editor 00417 if (focusEv->reason() != TQFocusEvent::Popup && focusEv->reason() != TQFocusEvent::ActiveWindow) 00418 terminate(true); 00419 else 00420 KLineEdit::focusOutEvent(ev); 00421 } 00422 00423 void TDEListViewLineEdit::paintEvent( TQPaintEvent *e ) 00424 { 00425 KLineEdit::paintEvent( e ); 00426 00427 if ( !frame() ) { 00428 TQPainter p( this ); 00429 p.setClipRegion( e->region() ); 00430 p.drawRect( rect() ); 00431 } 00432 } 00433 00434 // selection changed -> terminate. As our "item" can be already deleted, 00435 // we can't call terminate(false), because that would emit done() with 00436 // a dangling pointer to "item". 00437 void TDEListViewLineEdit::slotSelectionChanged() 00438 { 00439 item = 0; 00440 col = 0; 00441 hide(); 00442 } 00443 00444 // if the current item was removed -> terminate. Can't call terminate(false) 00445 // due to same reason as slotSelectionChanged(). 00446 void TDEListViewLineEdit::slotItemRemoved(TQListViewItem *i) 00447 { 00448 if (currentItem() != i) 00449 return; 00450 00451 item = 0; 00452 col = 0; 00453 hide(); 00454 } 00455 00456 00457 TDEListView::TDEListView( TQWidget *parent, const char *name ) 00458 : TQListView(parent, name), d(new TDEListViewPrivate(this)) 00459 { 00460 setDragAutoScroll(true); 00461 00462 connect( this, TQT_SIGNAL( onViewport() ), 00463 this, TQT_SLOT( slotOnViewport() ) ); 00464 connect( this, TQT_SIGNAL( onItem( TQListViewItem * ) ), 00465 this, TQT_SLOT( slotOnItem( TQListViewItem * ) ) ); 00466 00467 connect (this, TQT_SIGNAL(contentsMoving(int,int)), 00468 this, TQT_SLOT(cleanDropVisualizer())); 00469 connect (this, TQT_SIGNAL(contentsMoving(int,int)), 00470 this, TQT_SLOT(cleanItemHighlighter())); 00471 00472 slotSettingsChanged(TDEApplication::SETTINGS_MOUSE); 00473 if (kapp) 00474 { 00475 connect( kapp, TQT_SIGNAL( settingsChanged(int) ), TQT_SLOT( slotSettingsChanged(int) ) ); 00476 kapp->addKipcEventMask( KIPC::SettingsChanged ); 00477 } 00478 00479 connect(&d->autoSelect, TQT_SIGNAL( timeout() ), 00480 this, TQT_SLOT( slotAutoSelect() ) ); 00481 connect(&d->dragExpand, TQT_SIGNAL( timeout() ), 00482 this, TQT_SLOT( slotDragExpand() ) ); 00483 00484 // context menu handling 00485 if (d->showContextMenusOnPress) 00486 { 00487 connect (this, TQT_SIGNAL (rightButtonPressed (TQListViewItem*, const TQPoint&, int)), 00488 this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); 00489 } 00490 else 00491 { 00492 connect (this, TQT_SIGNAL (rightButtonClicked (TQListViewItem*, const TQPoint&, int)), 00493 this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); 00494 } 00495 00496 connect (this, TQT_SIGNAL (menuShortCutPressed (TDEListView*, TQListViewItem*)), 00497 this, TQT_SLOT (emitContextMenu (TDEListView*, TQListViewItem*))); 00498 d->alternateBackground = TDEGlobalSettings::alternateBackgroundColor(); 00499 } 00500 00501 TDEListView::~TDEListView() 00502 { 00503 delete d; 00504 } 00505 00506 bool TDEListView::isExecuteArea( const TQPoint& point ) 00507 { 00508 TQListViewItem* item = itemAt( point ); 00509 if ( item ) { 00510 return isExecuteArea( point.x(), item ); 00511 } 00512 00513 return false; 00514 } 00515 00516 bool TDEListView::isExecuteArea( int x ) 00517 { 00518 return isExecuteArea( x, 0 ); 00519 } 00520 00521 bool TDEListView::isExecuteArea( int x, TQListViewItem* item ) 00522 { 00523 if ( allColumnsShowFocus() ) { 00524 return true; 00525 } 00526 else { 00527 int offset = 0; 00528 int width = columnWidth( 0 ); 00529 00530 TQHeader* const thisHeader = header(); 00531 const int pos = thisHeader->mapToIndex( 0 ); 00532 00533 for ( int index = 0; index < pos; ++index ) { 00534 offset += columnWidth( thisHeader->mapToSection( index ) ); 00535 } 00536 00537 x += contentsX(); // in case of a horizontal scrollbar 00538 00539 // If a small execute area was requested, trim area to the size of the item text/icon 00540 // Otherwise just use the column width, as at least one entire column is highlighted on row selection! 00541 if ( item && d->useSmallExecuteArea ) { 00542 width = treeStepSize()*( item->depth() + ( rootIsDecorated() ? 1 : 0 ) ); 00543 width += itemMargin(); 00544 int ca = AlignHorizontal_Mask & columnAlignment( 0 ); 00545 if ( ca == AlignLeft || ca == AlignAuto ) { 00546 width += item->width( fontMetrics(), this, 0 ); 00547 if ( width > columnWidth( 0 ) ) { 00548 width = columnWidth( 0 ); 00549 } 00550 } 00551 } 00552 if ( item ) { 00553 if (!allColumnsShowFocus()) { 00554 offset += treeStepSize()*( item->depth() + ( rootIsDecorated() ? 1 : 0 ) ); 00555 } 00556 } 00557 00558 return ( x > offset && x < ( offset + width ) ); 00559 } 00560 } 00561 00562 void TDEListView::slotOnItem( TQListViewItem *item ) 00563 { 00564 TQPoint vp = viewport()->mapFromGlobal( TQCursor::pos() ); 00565 if ( item && isExecuteArea( vp.x() ) && (d->autoSelectDelay > -1) && d->bUseSingle ) { 00566 d->autoSelect.start( d->autoSelectDelay, true ); 00567 d->pCurrentItem = item; 00568 } 00569 } 00570 00571 void TDEListView::slotOnViewport() 00572 { 00573 if ( d->bChangeCursorOverItem ) 00574 viewport()->unsetCursor(); 00575 00576 d->autoSelect.stop(); 00577 d->pCurrentItem = 0L; 00578 } 00579 00580 void TDEListView::slotSettingsChanged(int category) 00581 { 00582 switch (category) 00583 { 00584 case TDEApplication::SETTINGS_MOUSE: 00585 d->dragDelay = TDEGlobalSettings::dndEventDelay(); 00586 d->bUseSingle = TDEGlobalSettings::singleClick(); 00587 00588 disconnect(this, TQT_SIGNAL (mouseButtonClicked (int, TQListViewItem*, const TQPoint &, int)), 00589 this, TQT_SLOT (slotMouseButtonClicked (int, TQListViewItem*, const TQPoint &, int))); 00590 00591 if( d->bUseSingle ) 00592 connect (this, TQT_SIGNAL (mouseButtonClicked (int, TQListViewItem*, const TQPoint &, int)), 00593 this, TQT_SLOT (slotMouseButtonClicked( int, TQListViewItem*, const TQPoint &, int))); 00594 00595 d->bChangeCursorOverItem = TDEGlobalSettings::changeCursorOverIcon(); 00596 if ( !d->disableAutoSelection ) 00597 d->autoSelectDelay = TDEGlobalSettings::autoSelectDelay(); 00598 00599 if( !d->bUseSingle || !d->bChangeCursorOverItem ) 00600 viewport()->unsetCursor(); 00601 00602 break; 00603 00604 case TDEApplication::SETTINGS_POPUPMENU: 00605 d->contextMenuKey = TDEGlobalSettings::contextMenuKey (); 00606 d->showContextMenusOnPress = TDEGlobalSettings::showContextMenusOnPress (); 00607 00608 if (d->showContextMenusOnPress) 00609 { 00610 disconnect (0L, 0L, this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); 00611 00612 connect(this, TQT_SIGNAL (rightButtonPressed (TQListViewItem*, const TQPoint&, int)), 00613 this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); 00614 } 00615 else 00616 { 00617 disconnect (0L, 0L, this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); 00618 00619 connect(this, TQT_SIGNAL (rightButtonClicked (TQListViewItem*, const TQPoint&, int)), 00620 this, TQT_SLOT (emitContextMenu (TQListViewItem*, const TQPoint&, int))); 00621 } 00622 break; 00623 00624 default: 00625 break; 00626 } 00627 } 00628 00629 void TDEListView::slotAutoSelect() 00630 { 00631 // check that the item still exists 00632 if( itemIndex( d->pCurrentItem ) == -1 ) 00633 return; 00634 00635 if (!isActiveWindow()) 00636 { 00637 d->autoSelect.stop(); 00638 return; 00639 } 00640 00641 //Give this widget the keyboard focus. 00642 if( !hasFocus() ) 00643 setFocus(); 00644 00645 ButtonState keybstate = TDEApplication::keyboardMouseState(); 00646 00647 TQListViewItem* previousItem = currentItem(); 00648 setCurrentItem( d->pCurrentItem ); 00649 00650 if( d->pCurrentItem ) { 00651 //Shift pressed? 00652 if( (keybstate & TQt::ShiftButton) ) { 00653 bool block = signalsBlocked(); 00654 blockSignals( true ); 00655 00656 //No Ctrl? Then clear before! 00657 if( !(keybstate & TQt::ControlButton) ) 00658 clearSelection(); 00659 00660 bool select = !d->pCurrentItem->isSelected(); 00661 bool update = viewport()->isUpdatesEnabled(); 00662 viewport()->setUpdatesEnabled( false ); 00663 00664 bool down = previousItem->itemPos() < d->pCurrentItem->itemPos(); 00665 TQListViewItemIterator lit( down ? previousItem : d->pCurrentItem ); 00666 for ( ; lit.current(); ++lit ) { 00667 if ( down && lit.current() == d->pCurrentItem ) { 00668 d->pCurrentItem->setSelected( select ); 00669 break; 00670 } 00671 if ( !down && lit.current() == previousItem ) { 00672 previousItem->setSelected( select ); 00673 break; 00674 } 00675 lit.current()->setSelected( select ); 00676 } 00677 00678 blockSignals( block ); 00679 viewport()->setUpdatesEnabled( update ); 00680 triggerUpdate(); 00681 00682 emit selectionChanged(); 00683 00684 if( selectionMode() == TQListView::Single ) 00685 emit selectionChanged( d->pCurrentItem ); 00686 } 00687 else if( (keybstate & TDEApplication::ControlModifier) ) 00688 setSelected( d->pCurrentItem, !d->pCurrentItem->isSelected() ); 00689 else { 00690 bool block = signalsBlocked(); 00691 blockSignals( true ); 00692 00693 if( !d->pCurrentItem->isSelected() ) 00694 clearSelection(); 00695 00696 blockSignals( block ); 00697 00698 setSelected( d->pCurrentItem, true ); 00699 } 00700 } 00701 else 00702 kdDebug() << "TDEListView::slotAutoSelect: That�s not supposed to happen!!!!" << endl; 00703 } 00704 00705 void TDEListView::slotHeaderChanged() 00706 { 00707 00708 const int colCount = columns(); 00709 if (d->fullWidth && colCount) 00710 { 00711 int w = 0; 00712 const int lastColumn = colCount - 1; 00713 for (int i = 0; i < lastColumn; ++i) w += columnWidth(i); 00714 setColumnWidth( lastColumn, viewport()->width() - w - 1 ); 00715 } 00716 } 00717 00718 void TDEListView::emitExecute( TQListViewItem *item, const TQPoint &pos, int c ) 00719 { 00720 if( isExecuteArea( viewport()->mapFromGlobal(pos) ) ) { 00721 d->validDrag=false; 00722 00723 // Double click mode ? 00724 if ( !d->bUseSingle ) 00725 { 00726 viewport()->unsetCursor(); 00727 emit executed( item ); 00728 emit executed( item, pos, c ); 00729 } 00730 else 00731 { 00732 ButtonState keybstate = TDEApplication::keyboardMouseState(); 00733 00734 d->autoSelect.stop(); 00735 00736 //Don't emit executed if in SC mode and Shift or Ctrl are pressed 00737 if( !( ((keybstate & TQt::ShiftButton) || (keybstate & TQt::ControlButton)) ) ) { 00738 viewport()->unsetCursor(); 00739 emit executed( item ); 00740 emit executed( item, pos, c ); 00741 } 00742 } 00743 } 00744 } 00745 00746 void TDEListView::focusInEvent( TQFocusEvent *fe ) 00747 { 00748 // kdDebug()<<"TDEListView::focusInEvent()"<<endl; 00749 TQListView::focusInEvent( fe ); 00750 if ((d->selectedBySimpleMove) 00751 && (d->selectionMode == FileManager) 00752 && (fe->reason()!=TQFocusEvent::Popup) 00753 && (fe->reason()!=TQFocusEvent::ActiveWindow) 00754 && (currentItem())) 00755 { 00756 currentItem()->setSelected(true); 00757 currentItem()->repaint(); 00758 emit selectionChanged(); 00759 }; 00760 } 00761 00762 void TDEListView::focusOutEvent( TQFocusEvent *fe ) 00763 { 00764 cleanDropVisualizer(); 00765 cleanItemHighlighter(); 00766 00767 d->autoSelect.stop(); 00768 00769 if ((d->selectedBySimpleMove) 00770 && (d->selectionMode == FileManager) 00771 && (fe->reason()!=TQFocusEvent::Popup) 00772 && (fe->reason()!=TQFocusEvent::ActiveWindow) 00773 && (currentItem()) 00774 && (!d->editor->isVisible())) 00775 { 00776 currentItem()->setSelected(false); 00777 currentItem()->repaint(); 00778 emit selectionChanged(); 00779 }; 00780 00781 TQListView::focusOutEvent( fe ); 00782 } 00783 00784 void TDEListView::leaveEvent( TQEvent *e ) 00785 { 00786 d->autoSelect.stop(); 00787 00788 TQListView::leaveEvent( e ); 00789 } 00790 00791 bool TDEListView::event( TQEvent *e ) 00792 { 00793 if (e->type() == TQEvent::ApplicationPaletteChange) 00794 d->alternateBackground=TDEGlobalSettings::alternateBackgroundColor(); 00795 00796 return TQListView::event(e); 00797 } 00798 00799 void TDEListView::contentsMousePressEvent( TQMouseEvent *e ) 00800 { 00801 if( (selectionModeExt() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) ) 00802 { 00803 bool block = signalsBlocked(); 00804 blockSignals( true ); 00805 00806 clearSelection(); 00807 00808 blockSignals( block ); 00809 } 00810 else if ((selectionModeExt()==FileManager) && (d->selectedBySimpleMove)) 00811 { 00812 d->selectedBySimpleMove=false; 00813 d->selectedUsingMouse=true; 00814 if (currentItem()) 00815 { 00816 currentItem()->setSelected(false); 00817 currentItem()->repaint(); 00818 // emit selectionChanged(); 00819 } 00820 } 00821 00822 TQPoint p( contentsToViewport( e->pos() ) ); 00823 TQListViewItem *at = itemAt (p); 00824 00825 // true if the root decoration of the item "at" was clicked (i.e. the +/- sign) 00826 bool rootDecoClicked = at 00827 && ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) + 00828 treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ) 00829 && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) ); 00830 00831 if (e->button() == Qt::LeftButton && !rootDecoClicked) 00832 { 00833 //Start a drag 00834 d->startDragPos = e->pos(); 00835 00836 if (at) 00837 { 00838 d->validDrag = true; 00839 d->pressedOnSelected = at->isSelected(); 00840 } 00841 } 00842 00843 TQListView::contentsMousePressEvent( e ); 00844 } 00845 00846 void TDEListView::contentsMouseMoveEvent( TQMouseEvent *e ) 00847 { 00848 if (!dragEnabled() || d->startDragPos.isNull() || !d->validDrag) 00849 TQListView::contentsMouseMoveEvent (e); 00850 00851 TQPoint vp = contentsToViewport(e->pos()); 00852 TQListViewItem *item = itemAt( vp ); 00853 00854 //do we process cursor changes at all? 00855 if ( item && d->bChangeCursorOverItem && d->bUseSingle ) 00856 { 00857 //Cursor moved on a new item or in/out the execute area 00858 if( (item != d->pCurrentItem) || 00859 (isExecuteArea(vp) != d->cursorInExecuteArea) ) 00860 { 00861 d->cursorInExecuteArea = isExecuteArea(vp); 00862 00863 if( d->cursorInExecuteArea ) //cursor moved in execute area 00864 viewport()->setCursor( KCursor::handCursor() ); 00865 else //cursor moved out of execute area 00866 viewport()->unsetCursor(); 00867 } 00868 } 00869 00870 bool dragOn = dragEnabled(); 00871 TQPoint newPos = e->pos(); 00872 if (dragOn && d->validDrag && 00873 (newPos.x() > d->startDragPos.x()+d->dragDelay || 00874 newPos.x() < d->startDragPos.x()-d->dragDelay || 00875 newPos.y() > d->startDragPos.y()+d->dragDelay || 00876 newPos.y() < d->startDragPos.y()-d->dragDelay)) 00877 //(d->startDragPos - e->pos()).manhattanLength() > TQApplication::startDragDistance()) 00878 { 00879 TQListView::contentsMouseReleaseEvent( 0 ); 00880 startDrag(); 00881 d->startDragPos = TQPoint(); 00882 d->validDrag = false; 00883 } 00884 } 00885 00886 void TDEListView::contentsMouseReleaseEvent( TQMouseEvent *e ) 00887 { 00888 if (e->button() == Qt::LeftButton) 00889 { 00890 // If the row was already selected, maybe we want to start an in-place editing 00891 if ( d->pressedOnSelected && itemsRenameable() ) 00892 { 00893 TQPoint p( contentsToViewport( e->pos() ) ); 00894 TQListViewItem *at = itemAt (p); 00895 if ( at ) 00896 { 00897 // true if the root decoration of the item "at" was clicked (i.e. the +/- sign) 00898 bool rootDecoClicked = 00899 ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) + 00900 treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ) 00901 && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) ); 00902 00903 if (!rootDecoClicked) 00904 { 00905 int col = header()->mapToLogical( header()->cellAt( p.x() ) ); 00906 if ( d->renameable.contains(col) ) 00907 rename(at, col); 00908 } 00909 } 00910 } 00911 00912 d->pressedOnSelected = false; 00913 d->validDrag = false; 00914 d->startDragPos = TQPoint(); 00915 } 00916 TQListView::contentsMouseReleaseEvent( e ); 00917 } 00918 00919 void TDEListView::contentsMouseDoubleClickEvent ( TQMouseEvent *e ) 00920 { 00921 // We don't want to call the parent method because it does setOpen, 00922 // whereas we don't do it in single click mode... (David) 00923 //TQListView::contentsMouseDoubleClickEvent( e ); 00924 if ( !e || e->button() != Qt::LeftButton ) { 00925 return; 00926 } 00927 00928 TQPoint vp = contentsToViewport(e->pos()); 00929 TQListViewItem *item = itemAt( vp ); 00930 emit TQListView::doubleClicked( item ); // we do it now 00931 00932 int col = item ? header()->mapToLogical( header()->cellAt( vp.x() ) ) : -1; 00933 00934 if( item ) { 00935 emit doubleClicked( item, e->globalPos(), col ); 00936 00937 if( (e->button() == Qt::LeftButton) && !d->bUseSingle ) { 00938 emitExecute( item, e->globalPos(), col ); 00939 } 00940 } 00941 } 00942 00943 void TDEListView::slotMouseButtonClicked( int btn, TQListViewItem *item, const TQPoint &pos, int c ) 00944 { 00945 if( (btn == Qt::LeftButton) && item ) { 00946 emitExecute(item, pos, c); 00947 } 00948 } 00949 00950 void TDEListView::contentsDropEvent(TQDropEvent* e) 00951 { 00952 cleanDropVisualizer(); 00953 cleanItemHighlighter(); 00954 d->dragExpand.stop(); 00955 00956 if (acceptDrag (e)) 00957 { 00958 e->acceptAction(); 00959 TQListViewItem *afterme; 00960 TQListViewItem *parent; 00961 00962 findDrop(e->pos(), parent, afterme); 00963 00964 if (e->source() == viewport() && itemsMovable()) 00965 movableDropEvent(parent, afterme); 00966 else 00967 { 00968 emit dropped(e, afterme); 00969 emit dropped(this, e, afterme); 00970 emit dropped(e, parent, afterme); 00971 emit dropped(this, e, parent, afterme); 00972 } 00973 } 00974 } 00975 00976 void TDEListView::movableDropEvent (TQListViewItem* parent, TQListViewItem* afterme) 00977 { 00978 TQPtrList<TQListViewItem> items, afterFirsts, afterNows; 00979 TQListViewItem *current=currentItem(); 00980 bool hasMoved=false; 00981 for (TQListViewItem *i = firstChild(), *iNext=0; i; i = iNext) 00982 { 00983 iNext=i->itemBelow(); 00984 if (!i->isSelected()) 00985 continue; 00986 00987 // don't drop an item after itself, or else 00988 // it moves to the top of the list 00989 if (i==afterme) 00990 continue; 00991 00992 i->setSelected(false); 00993 00994 TQListViewItem *afterFirst = i->itemAbove(); 00995 00996 if (!hasMoved) 00997 { 00998 emit aboutToMove(); 00999 hasMoved=true; 01000 } 01001 01002 moveItem(i, parent, afterme); 01003 01004 // ###### This should include the new parent !!! -> KDE 3.0 01005 // If you need this right now, have a look at keditbookmarks. 01006 emit moved(i, afterFirst, afterme); 01007 01008 items.append (i); 01009 afterFirsts.append (afterFirst); 01010 afterNows.append (afterme); 01011 01012 afterme = i; 01013 } 01014 clearSelection(); 01015 for (TQListViewItem *i=items.first(); i; i=items.next() ) 01016 i->setSelected(true); 01017 if (current) 01018 setCurrentItem(current); 01019 01020 emit moved(items,afterFirsts,afterNows); 01021 01022 if (firstChild()) 01023 emit moved(); 01024 } 01025 01026 void TDEListView::contentsDragMoveEvent(TQDragMoveEvent *event) 01027 { 01028 if (acceptDrag(event)) 01029 { 01030 event->acceptAction(); 01031 //Clean up the view 01032 01033 findDrop(event->pos(), d->parentItemDrop, d->afterItemDrop); 01034 TQPoint vp = contentsToViewport( event->pos() ); 01035 TQListViewItem *item = isExecuteArea( vp ) ? itemAt( vp ) : 0L; 01036 01037 if ( item != d->dragOverItem ) 01038 { 01039 d->dragExpand.stop(); 01040 d->dragOverItem = item; 01041 d->dragOverPoint = vp; 01042 if ( d->dragOverItem && d->dragOverItem->isExpandable() && !d->dragOverItem->isOpen() ) 01043 d->dragExpand.start( TQApplication::startDragTime(), true ); 01044 } 01045 if (dropVisualizer()) 01046 { 01047 TQRect tmpRect = drawDropVisualizer(0, d->parentItemDrop, d->afterItemDrop); 01048 if (tmpRect != d->mOldDropVisualizer) 01049 { 01050 cleanDropVisualizer(); 01051 d->mOldDropVisualizer=tmpRect; 01052 viewport()->repaint(tmpRect); 01053 } 01054 } 01055 if (dropHighlighter()) 01056 { 01057 TQRect tmpRect = drawItemHighlighter(0, itemAt( vp )); 01058 if (tmpRect != d->mOldDropHighlighter) 01059 { 01060 cleanItemHighlighter(); 01061 d->mOldDropHighlighter=tmpRect; 01062 viewport()->repaint(tmpRect); 01063 } 01064 } 01065 } 01066 else 01067 event->ignore(); 01068 } 01069 01070 void TDEListView::slotDragExpand() 01071 { 01072 if ( itemAt( d->dragOverPoint ) == d->dragOverItem ) 01073 d->dragOverItem->setOpen( true ); 01074 } 01075 01076 void TDEListView::contentsDragLeaveEvent (TQDragLeaveEvent*) 01077 { 01078 d->dragExpand.stop(); 01079 cleanDropVisualizer(); 01080 cleanItemHighlighter(); 01081 } 01082 01083 void TDEListView::cleanDropVisualizer() 01084 { 01085 if (d->mOldDropVisualizer.isValid()) 01086 { 01087 TQRect rect=d->mOldDropVisualizer; 01088 d->mOldDropVisualizer = TQRect(); 01089 viewport()->repaint(rect, true); 01090 } 01091 } 01092 01093 int TDEListView::depthToPixels( int depth ) 01094 { 01095 return treeStepSize() * ( depth + (rootIsDecorated() ? 1 : 0) ) + itemMargin(); 01096 } 01097 01098 void TDEListView::findDrop(const TQPoint &pos, TQListViewItem *&parent, TQListViewItem *&after) 01099 { 01100 TQPoint p (contentsToViewport(pos)); 01101 01102 // Get the position to put it in 01103 TQListViewItem *atpos = itemAt(p); 01104 01105 TQListViewItem *above; 01106 if (!atpos) // put it at the end 01107 above = lastItem(); 01108 else 01109 { 01110 // Get the closest item before us ('atpos' or the one above, if any) 01111 if (p.y() - itemRect(atpos).topLeft().y() < (atpos->height()/2)) 01112 above = atpos->itemAbove(); 01113 else 01114 above = atpos; 01115 } 01116 01117 if (above) 01118 { 01119 // if above has children, I might need to drop it as the first item there 01120 01121 if (above->firstChild() && above->isOpen()) 01122 { 01123 parent = above; 01124 after = 0; 01125 return; 01126 } 01127 01128 // Now, we know we want to go after "above". But as a child or as a sibling ? 01129 // We have to ask the "above" item if it accepts children. 01130 if (above->isExpandable()) 01131 { 01132 // The mouse is sufficiently on the right ? - doesn't matter if 'above' has visible children 01133 if (p.x() >= depthToPixels( above->depth() + 1 ) || 01134 (above->isOpen() && above->childCount() > 0) ) 01135 { 01136 parent = above; 01137 after = 0L; 01138 return; 01139 } 01140 } 01141 01142 // Ok, there's one more level of complexity. We may want to become a new 01143 // sibling, but of an upper-level group, rather than the "above" item 01144 TQListViewItem * betterAbove = above->parent(); 01145 TQListViewItem * last = above; 01146 while ( betterAbove ) 01147 { 01148 // We are allowed to become a sibling of "betterAbove" only if we are 01149 // after its last child 01150 if ( !last->nextSibling() ) 01151 { 01152 if (p.x() < depthToPixels ( betterAbove->depth() + 1 )) 01153 above = betterAbove; // store this one, but don't stop yet, there may be a better one 01154 else 01155 break; // not enough on the left, so stop 01156 last = betterAbove; 01157 betterAbove = betterAbove->parent(); // up one level 01158 } else 01159 break; // we're among the child of betterAbove, not after the last one 01160 } 01161 } 01162 // set as sibling 01163 after = above; 01164 parent = after ? after->parent() : 0L ; 01165 } 01166 01167 TQListViewItem* TDEListView::lastChild () const 01168 { 01169 TQListViewItem* lastchild = firstChild(); 01170 01171 if (lastchild) 01172 for (; lastchild->nextSibling(); lastchild = lastchild->nextSibling()); 01173 01174 return lastchild; 01175 } 01176 01177 TQListViewItem *TDEListView::lastItem() const 01178 { 01179 TQListViewItem* last = lastChild(); 01180 01181 for (TQListViewItemIterator it (last); it.current(); ++it) 01182 last = it.current(); 01183 01184 return last; 01185 } 01186 01187 KLineEdit *TDEListView::renameLineEdit() const 01188 { 01189 return d->editor; 01190 } 01191 01192 void TDEListView::startDrag() 01193 { 01194 TQDragObject *drag = dragObject(); 01195 01196 if (!drag) 01197 return; 01198 01199 if (drag->drag() && drag->target() != viewport()) 01200 emit moved(); 01201 } 01202 01203 TQDragObject *TDEListView::dragObject() 01204 { 01205 if (!currentItem()) 01206 return 0; 01207 01208 01209 return new TQStoredDrag("application/x-qlistviewitem", viewport()); 01210 } 01211 01212 void TDEListView::setItemsMovable(bool b) 01213 { 01214 d->itemsMovable=b; 01215 } 01216 01217 bool TDEListView::itemsMovable() const 01218 { 01219 return d->itemsMovable; 01220 } 01221 01222 void TDEListView::setItemsRenameable(bool b) 01223 { 01224 d->itemsRenameable=b; 01225 } 01226 01227 bool TDEListView::itemsRenameable() const 01228 { 01229 return d->itemsRenameable; 01230 } 01231 01232 01233 void TDEListView::setDragEnabled(bool b) 01234 { 01235 d->dragEnabled=b; 01236 } 01237 01238 bool TDEListView::dragEnabled() const 01239 { 01240 return d->dragEnabled; 01241 } 01242 01243 void TDEListView::setAutoOpen(bool b) 01244 { 01245 d->autoOpen=b; 01246 } 01247 01248 bool TDEListView::autoOpen() const 01249 { 01250 return d->autoOpen; 01251 } 01252 01253 bool TDEListView::dropVisualizer() const 01254 { 01255 return d->dropVisualizer; 01256 } 01257 01258 void TDEListView::setDropVisualizer(bool b) 01259 { 01260 d->dropVisualizer=b; 01261 } 01262 01263 TQPtrList<TQListViewItem> TDEListView::selectedItems() const 01264 { 01265 return selectedItems(true); 01266 } 01267 01268 TQPtrList<TQListViewItem> TDEListView::selectedItems(bool includeHiddenItems) const 01269 { 01270 TQPtrList<TQListViewItem> list; 01271 01272 // Using selectionMode() instead of selectionModeExt() since for the cases that 01273 // we're interested in selectionMode() should work for either variety of the 01274 // setSelectionMode(). 01275 01276 switch(selectionMode()) 01277 { 01278 case NoSelection: 01279 break; 01280 case Single: 01281 if(selectedItem() && (includeHiddenItems || selectedItem()->isVisible())) 01282 list.append(selectedItem()); 01283 break; 01284 default: 01285 { 01286 int flags = TQListViewItemIterator::Selected; 01287 if (!includeHiddenItems) 01288 { 01289 flags |= TQListViewItemIterator::Visible; 01290 } 01291 01292 TQListViewItemIterator it(const_cast<TDEListView *>(this), flags); 01293 01294 for(; it.current(); ++it) 01295 list.append(it.current()); 01296 01297 break; 01298 } 01299 } 01300 01301 return list; 01302 } 01303 01304 01305 void TDEListView::moveItem(TQListViewItem *item, TQListViewItem *parent, TQListViewItem *after) 01306 { 01307 // sanity check - don't move a item into its own child structure 01308 TQListViewItem *i = parent; 01309 while(i) 01310 { 01311 if(i == item) 01312 return; 01313 i = i->parent(); 01314 } 01315 01316 if (after) 01317 { 01318 item->moveItem(after); 01319 return; 01320 } 01321 01322 // Basically reimplementing the TQListViewItem(TQListViewItem*, TQListViewItem*) constructor 01323 // in here, without ever deleting the item. 01324 if (item->parent()) 01325 item->parent()->takeItem(item); 01326 else 01327 takeItem(item); 01328 01329 if (parent) 01330 parent->insertItem(item); 01331 else 01332 insertItem(item); 01333 } 01334 01335 void TDEListView::contentsDragEnterEvent(TQDragEnterEvent *event) 01336 { 01337 if (acceptDrag (event)) 01338 event->accept(); 01339 } 01340 01341 void TDEListView::setDropVisualizerWidth (int w) 01342 { 01343 d->mDropVisualizerWidth = w > 0 ? w : 1; 01344 } 01345 01346 TQRect TDEListView::drawDropVisualizer(TQPainter *p, TQListViewItem *parent, 01347 TQListViewItem *after) 01348 { 01349 TQRect insertmarker; 01350 01351 if (!after && !parent) 01352 insertmarker = TQRect (0, 0, viewport()->width(), d->mDropVisualizerWidth/2); 01353 else 01354 { 01355 int level = 0; 01356 if (after) 01357 { 01358 TQListViewItem* it = 0L; 01359 if (after->isOpen()) 01360 { 01361 // Look for the last child (recursively) 01362 it = after->firstChild(); 01363 if (it) 01364 while (it->nextSibling() || it->firstChild()) 01365 if ( it->nextSibling() ) 01366 it = it->nextSibling(); 01367 else 01368 it = it->firstChild(); 01369 } 01370 01371 insertmarker = itemRect (it ? it : after); 01372 level = after->depth(); 01373 } 01374 else if (parent) 01375 { 01376 insertmarker = itemRect (parent); 01377 level = parent->depth() + 1; 01378 } 01379 insertmarker.setLeft( treeStepSize() * ( level + (rootIsDecorated() ? 1 : 0) ) + itemMargin() ); 01380 insertmarker.setRight (viewport()->width()); 01381 insertmarker.setTop (insertmarker.bottom() - d->mDropVisualizerWidth/2 + 1); 01382 insertmarker.setBottom (insertmarker.bottom() + d->mDropVisualizerWidth/2); 01383 } 01384 01385 // This is not used anymore, at least by TDEListView itself (see viewportPaintEvent) 01386 // Remove for KDE 4.0. 01387 if (p) 01388 p->fillRect(insertmarker, Dense4Pattern); 01389 01390 return insertmarker; 01391 } 01392 01393 TQRect TDEListView::drawItemHighlighter(TQPainter *painter, TQListViewItem *item) 01394 { 01395 TQRect r; 01396 01397 if (item) 01398 { 01399 r = itemRect(item); 01400 r.setLeft(r.left()+(item->depth()+(rootIsDecorated() ? 1 : 0))*treeStepSize()); 01401 if (painter) 01402 style().tqdrawPrimitive(TQStyle::PE_FocusRect, painter, r, colorGroup(), 01403 TQStyle::Style_FocusAtBorder, colorGroup().highlight()); 01404 } 01405 01406 return r; 01407 } 01408 01409 void TDEListView::cleanItemHighlighter () 01410 { 01411 if (d->mOldDropHighlighter.isValid()) 01412 { 01413 TQRect rect=d->mOldDropHighlighter; 01414 d->mOldDropHighlighter = TQRect(); 01415 viewport()->repaint(rect, true); 01416 } 01417 } 01418 01419 void TDEListView::rename(TQListViewItem *item, int c) 01420 { 01421 if (d->renameable.contains(c)) 01422 { 01423 ensureItemVisible(item); 01424 d->editor->load(item,c); 01425 } 01426 } 01427 01428 bool TDEListView::isRenameable (int col) const 01429 { 01430 return d->renameable.contains(col); 01431 } 01432 01433 void TDEListView::setRenameable (int col, bool renameable) 01434 { 01435 if (col>=header()->count()) return; 01436 01437 d->renameable.remove(col); 01438 if (renameable) 01439 d->renameable+=col; 01440 } 01441 01442 void TDEListView::doneEditing(TQListViewItem *item, int row) 01443 { 01444 emit itemRenamed(item, item->text(row), row); 01445 emit itemRenamed(item); 01446 } 01447 01448 void TDEListView::renameNextProxy(TQListViewItem *item, int col) 01449 { 01450 emit renameNext(item, col); 01451 } 01452 01453 void TDEListView::renamePrevProxy(TQListViewItem *item, int col) 01454 { 01455 emit renamePrev(item, col); 01456 } 01457 01458 01459 bool TDEListView::acceptDrag(TQDropEvent* e) const 01460 { 01461 return acceptDrops() && itemsMovable() && (e->source()==viewport()); 01462 } 01463 01464 void TDEListView::setCreateChildren(bool b) 01465 { 01466 d->createChildren=b; 01467 } 01468 01469 bool TDEListView::createChildren() const 01470 { 01471 return d->createChildren; 01472 } 01473 01474 01475 int TDEListView::tooltipColumn() const 01476 { 01477 return d->tooltipColumn; 01478 } 01479 01480 void TDEListView::setTooltipColumn(int column) 01481 { 01482 d->tooltipColumn=column; 01483 } 01484 01485 void TDEListView::setDropHighlighter(bool b) 01486 { 01487 d->dropHighlighter=b; 01488 } 01489 01490 bool TDEListView::dropHighlighter() const 01491 { 01492 return d->dropHighlighter; 01493 } 01494 01495 bool TDEListView::showTooltip(TQListViewItem *item, const TQPoint &, int column) const 01496 { 01497 return ((column==tooltipColumn()) && !tooltip(item, column).isEmpty()); 01498 } 01499 01500 TQString TDEListView::tooltip(TQListViewItem *item, int column) const 01501 { 01502 return item->text(column); 01503 } 01504 01505 void TDEListView::setTabOrderedRenaming(bool b) 01506 { 01507 d->tabRename = b; 01508 } 01509 01510 bool TDEListView::tabOrderedRenaming() const 01511 { 01512 return d->tabRename; 01513 } 01514 01515 void TDEListView::keyPressEvent (TQKeyEvent* e) 01516 { 01517 //don't we need a contextMenuModifier too ? (aleXXX) 01518 if (e->key() == d->contextMenuKey) 01519 { 01520 emit menuShortCutPressed (this, currentItem()); 01521 return; 01522 } 01523 01524 if (d->selectionMode != FileManager) 01525 TQListView::keyPressEvent (e); 01526 else 01527 fileManagerKeyPressEvent (e); 01528 } 01529 01530 void TDEListView::activateAutomaticSelection() 01531 { 01532 d->selectedBySimpleMove=true; 01533 d->selectedUsingMouse=false; 01534 if (currentItem()) 01535 { 01536 currentItem()->setSelected(true); 01537 currentItem()->repaint(); 01538 emit selectionChanged(); 01539 }; 01540 } 01541 01542 void TDEListView::deactivateAutomaticSelection() 01543 { 01544 d->selectedBySimpleMove=false; 01545 } 01546 01547 bool TDEListView::automaticSelection() const 01548 { 01549 return d->selectedBySimpleMove; 01550 } 01551 01552 void TDEListView::resetKeyboardSelectionOperation() 01553 { 01554 d->wasShiftEvent = false; 01555 d->selectionDirection = 0; 01556 } 01557 01558 void TDEListView::setActiveMultiSelectItem(TQListViewItem *item) { 01559 TQListViewItem* origItem = currentItem(); 01560 if (!d->initialFileManagerItem) { 01561 d->initialFileManagerItem = origItem; 01562 } 01563 setCurrentItem(item); 01564 } 01565 01566 void TDEListView::fileManagerKeyPressEvent (TQKeyEvent* e) 01567 { 01568 //don't care whether it's on the keypad or not 01569 int e_state=(e->state() & ~Keypad); 01570 01571 // Handle non-control keypresses 01572 if ((e->key()!=Key_Shift) && (e->key()!=Key_Control) 01573 && (e->key()!=Key_Meta) && (e->key()!=Key_Alt)) { 01574 if ((e_state==ShiftButton) && (!d->wasShiftEvent) && (!d->selectedBySimpleMove)) { 01575 selectAll(false); 01576 d->selectionRegion = 0; 01577 d->initialFileManagerItem = NULL; 01578 } 01579 d->selectionDirection=0; 01580 d->wasShiftEvent = (e_state == ShiftButton); 01581 } 01582 01583 //d->wasShiftEvent = (e_state == ShiftButton); 01584 01585 TQListViewItem* item = currentItem(); 01586 if (!item) { 01587 return; 01588 } 01589 01590 TQListViewItem* repaintItem1 = item; 01591 TQListViewItem* repaintItem2 = 0L; 01592 TQListViewItem* visItem = 0L; 01593 01594 TQListViewItem* nextItem = 0L; 01595 int items = 0; 01596 01597 bool shiftOrCtrl((e_state==ControlButton) || (e_state==ShiftButton)); 01598 int selectedItems(0); 01599 for (TQListViewItem *tmpItem=firstChild(); tmpItem; tmpItem=tmpItem->nextSibling()) { 01600 if (tmpItem->isSelected()) selectedItems++; 01601 } 01602 01603 if (((!selectedItems) || ((selectedItems==1) && (d->selectedUsingMouse))) 01604 && (e_state==Qt::NoButton) 01605 && ((e->key()==Key_Down) 01606 || (e->key()==Key_Up) 01607 || (e->key()==Key_Next) 01608 || (e->key()==Key_Prior) 01609 || (e->key()==Key_Home) 01610 || (e->key()==Key_End))) { 01611 d->selectedBySimpleMove=true; 01612 d->selectedUsingMouse=false; 01613 } 01614 else if (selectedItems>1) { 01615 d->selectedBySimpleMove=false; 01616 } 01617 01618 bool emitSelectionChanged(false); 01619 01620 switch (e->key()) { 01621 case Key_Escape: 01622 selectAll(false); 01623 emitSelectionChanged=true; 01624 break; 01625 01626 case Key_Space: 01627 //toggle selection of current item 01628 if (d->selectedBySimpleMove) { 01629 d->selectedBySimpleMove=false; 01630 } 01631 item->setSelected(!item->isSelected()); 01632 emitSelectionChanged=true; 01633 break; 01634 01635 case Key_Insert: 01636 //toggle selection of current item and move to the next item 01637 if (d->selectedBySimpleMove) { 01638 d->selectedBySimpleMove=false; 01639 if (!item->isSelected()) item->setSelected(true); 01640 } 01641 else { 01642 item->setSelected(!item->isSelected()); 01643 } 01644 01645 nextItem=item->itemBelow(); 01646 01647 if (nextItem) { 01648 repaintItem2=nextItem; 01649 visItem=nextItem; 01650 setCurrentItem(nextItem); 01651 } 01652 d->selectionDirection=1; 01653 emitSelectionChanged=true; 01654 break; 01655 01656 case Key_Down: 01657 nextItem=item->itemBelow(); 01658 if (shiftOrCtrl) { 01659 d->selectionDirection=1; 01660 d->selectedBySimpleMove=false; 01661 if (!d->initialFileManagerItem) { 01662 d->initialFileManagerItem = item; 01663 item->setSelected(true); 01664 if (nextItem) { 01665 nextItem->setSelected(true); 01666 } 01667 emitSelectionChanged=true; 01668 d->selectionRegion=1; 01669 } 01670 else { 01671 if (item == d->initialFileManagerItem) { 01672 item->setSelected(true); 01673 if (nextItem) { 01674 nextItem->setSelected(true); 01675 } 01676 emitSelectionChanged=true; 01677 d->selectionRegion=1; 01678 } 01679 else { 01680 if (d->selectionRegion == 1) { 01681 if (nextItem) { 01682 nextItem->setSelected(true); 01683 } 01684 emitSelectionChanged=true; 01685 } 01686 else if (d->selectionRegion == -1) { 01687 item->setSelected(false); 01688 emitSelectionChanged=true; 01689 } 01690 } 01691 } 01692 } 01693 else if ((d->selectedBySimpleMove) && (nextItem)) { 01694 item->setSelected(false); 01695 emitSelectionChanged=true; 01696 } 01697 01698 if (nextItem) { 01699 if (d->selectedBySimpleMove) { 01700 nextItem->setSelected(true); 01701 } 01702 repaintItem2=nextItem; 01703 visItem=nextItem; 01704 setCurrentItem(nextItem); 01705 } 01706 break; 01707 01708 case Key_Up: 01709 nextItem=item->itemAbove(); 01710 if (shiftOrCtrl) { 01711 d->selectionDirection=-1; 01712 d->selectedBySimpleMove=false; 01713 if (!d->initialFileManagerItem) { 01714 d->initialFileManagerItem = item; 01715 item->setSelected(true); 01716 if (nextItem) { 01717 nextItem->setSelected(true); 01718 } 01719 emitSelectionChanged=true; 01720 d->selectionRegion=-1; 01721 } 01722 else { 01723 if (item == d->initialFileManagerItem) { 01724 item->setSelected(true); 01725 if (nextItem) { 01726 nextItem->setSelected(true); 01727 } 01728 emitSelectionChanged=true; 01729 d->selectionRegion=-1; 01730 } 01731 else { 01732 if (d->selectionRegion == -1) { 01733 if (nextItem) { 01734 nextItem->setSelected(true); 01735 } 01736 emitSelectionChanged=true; 01737 } 01738 else if (d->selectionRegion == 1) { 01739 item->setSelected(false); 01740 emitSelectionChanged=true; 01741 } 01742 } 01743 } 01744 } 01745 else if ((d->selectedBySimpleMove) && (nextItem)) { 01746 item->setSelected(false); 01747 emitSelectionChanged=true; 01748 } 01749 01750 if (nextItem) { 01751 if (d->selectedBySimpleMove) { 01752 nextItem->setSelected(true); 01753 } 01754 repaintItem2=nextItem; 01755 visItem=nextItem; 01756 setCurrentItem(nextItem); 01757 } 01758 break; 01759 01760 case Key_End: 01761 // move to the last item and toggle selection of all items in-between 01762 nextItem=item; 01763 if (d->selectedBySimpleMove) { 01764 item->setSelected(false); 01765 } 01766 if (shiftOrCtrl) { 01767 d->selectedBySimpleMove=false; 01768 } 01769 01770 while (nextItem) { 01771 if (shiftOrCtrl) { 01772 if (!d->initialFileManagerItem) { 01773 d->initialFileManagerItem = nextItem; 01774 nextItem->setSelected(true); 01775 emitSelectionChanged=true; 01776 d->selectionRegion=1; 01777 } 01778 else { 01779 if (nextItem == d->initialFileManagerItem) { 01780 nextItem->setSelected(true); 01781 emitSelectionChanged=true; 01782 d->selectionRegion=1; 01783 } 01784 else { 01785 if (d->selectionRegion == 1) { 01786 nextItem->setSelected(true); 01787 emitSelectionChanged=true; 01788 } 01789 else if (d->selectionRegion == -1) { 01790 nextItem->setSelected(false); 01791 emitSelectionChanged=true; 01792 } 01793 } 01794 } 01795 } 01796 if (!nextItem->itemBelow()) { 01797 if (d->selectedBySimpleMove) { 01798 nextItem->setSelected(true); 01799 } 01800 repaintItem2=nextItem; 01801 visItem=nextItem; 01802 setCurrentItem(nextItem); 01803 } 01804 nextItem=nextItem->itemBelow(); 01805 } 01806 emitSelectionChanged=true; 01807 break; 01808 01809 case Key_Home: 01810 // move to the first item and toggle selection of all items in-between 01811 nextItem=item; 01812 if (d->selectedBySimpleMove) { 01813 item->setSelected(false); 01814 } 01815 if (shiftOrCtrl) { 01816 d->selectedBySimpleMove=false; 01817 } 01818 01819 while (nextItem) { 01820 if (shiftOrCtrl) { 01821 if (!d->initialFileManagerItem) { 01822 d->initialFileManagerItem = nextItem; 01823 nextItem->setSelected(true); 01824 emitSelectionChanged=true; 01825 d->selectionRegion=-1; 01826 } 01827 else { 01828 if (nextItem == d->initialFileManagerItem) { 01829 nextItem->setSelected(true); 01830 emitSelectionChanged=true; 01831 d->selectionRegion=-1; 01832 } 01833 else { 01834 if (d->selectionRegion == -1) { 01835 nextItem->setSelected(true); 01836 emitSelectionChanged=true; 01837 } 01838 else if (d->selectionRegion == 1) { 01839 nextItem->setSelected(false); 01840 emitSelectionChanged=true; 01841 } 01842 } 01843 } 01844 } 01845 if (!nextItem->itemAbove()) { 01846 if (d->selectedBySimpleMove) { 01847 nextItem->setSelected(true); 01848 } 01849 repaintItem2=nextItem; 01850 visItem=nextItem; 01851 setCurrentItem(nextItem); 01852 } 01853 nextItem=nextItem->itemAbove(); 01854 } 01855 emitSelectionChanged=true; 01856 break; 01857 01858 case Key_Next: 01859 items=visibleHeight()/item->height(); 01860 nextItem=item; 01861 if (d->selectedBySimpleMove) { 01862 item->setSelected(false); 01863 } 01864 if (shiftOrCtrl) { 01865 d->selectedBySimpleMove=false; 01866 d->selectionDirection=1; 01867 } 01868 01869 for (int i=0; i<items; i++) { 01870 if (shiftOrCtrl) { 01871 if (!d->initialFileManagerItem) { 01872 d->initialFileManagerItem = nextItem; 01873 nextItem->setSelected(true); 01874 emitSelectionChanged=true; 01875 d->selectionRegion=1; 01876 } 01877 else { 01878 if (nextItem == d->initialFileManagerItem) { 01879 nextItem->setSelected(true); 01880 emitSelectionChanged=true; 01881 d->selectionRegion=1; 01882 } 01883 else { 01884 if (d->selectionRegion == 1) { 01885 nextItem->setSelected(true); 01886 emitSelectionChanged=true; 01887 } 01888 else if (d->selectionRegion == -1) { 01889 if (i==items-1) { 01890 nextItem->setSelected(true); 01891 } 01892 else { 01893 nextItem->setSelected(false); 01894 } 01895 emitSelectionChanged=true; 01896 } 01897 } 01898 } 01899 } 01900 // last item 01901 if ((i==items-1) || (!nextItem->itemBelow())) { 01902 if (d->selectedBySimpleMove) { 01903 nextItem->setSelected(true); 01904 } 01905 ensureItemVisible(nextItem); 01906 setCurrentItem(nextItem); 01907 update(); 01908 if ((shiftOrCtrl) || (d->selectedBySimpleMove)) { 01909 emit selectionChanged(); 01910 } 01911 return; 01912 } 01913 nextItem=nextItem->itemBelow(); 01914 } 01915 break; 01916 01917 case Key_Prior: 01918 items=visibleHeight()/item->height(); 01919 nextItem=item; 01920 if (d->selectedBySimpleMove) { 01921 item->setSelected(false); 01922 } 01923 if (shiftOrCtrl) { 01924 d->selectionDirection=-1; 01925 d->selectedBySimpleMove=false; 01926 } 01927 01928 for (int i=0; i<items; i++) { 01929 if (shiftOrCtrl) { 01930 if (!d->initialFileManagerItem) { 01931 d->initialFileManagerItem = nextItem; 01932 nextItem->setSelected(true); 01933 emitSelectionChanged=true; 01934 d->selectionRegion=-1; 01935 } 01936 else { 01937 if (nextItem == d->initialFileManagerItem) { 01938 nextItem->setSelected(true); 01939 emitSelectionChanged=true; 01940 d->selectionRegion=-1; 01941 } 01942 else { 01943 if (d->selectionRegion == -1) { 01944 nextItem->setSelected(true); 01945 emitSelectionChanged=true; 01946 } 01947 else if (d->selectionRegion == 1) { 01948 if (i==items-1) { 01949 nextItem->setSelected(true); 01950 } 01951 else { 01952 nextItem->setSelected(false); 01953 } 01954 emitSelectionChanged=true; 01955 } 01956 } 01957 } 01958 } 01959 // last item 01960 if ((i==items-1) || (!nextItem->itemAbove())) { 01961 if (d->selectedBySimpleMove) { 01962 nextItem->setSelected(true); 01963 } 01964 ensureItemVisible(nextItem); 01965 setCurrentItem(nextItem); 01966 update(); 01967 if ((shiftOrCtrl) || (d->selectedBySimpleMove)) { 01968 emit selectionChanged(); 01969 } 01970 return; 01971 } 01972 nextItem=nextItem->itemAbove(); 01973 } 01974 break; 01975 01976 case Key_Minus: 01977 if ( item->isOpen() ) { 01978 setOpen( item, false ); 01979 } 01980 break; 01981 case Key_Plus: 01982 if ( !item->isOpen() && (item->isExpandable() || item->childCount()) ) { 01983 setOpen( item, true ); 01984 } 01985 break; 01986 default: 01987 bool realKey = ((e->key()!=Key_Shift) && (e->key()!=Key_Control) 01988 && (e->key()!=Key_Meta) && (e->key()!=Key_Alt)); 01989 01990 bool selectCurrentItem = (d->selectedBySimpleMove) && (item->isSelected()); 01991 if (realKey && selectCurrentItem) { 01992 item->setSelected(false); 01993 } 01994 //this is mainly for the "goto filename beginning with pressed char" feature (aleXXX) 01995 TQListView::SelectionMode oldSelectionMode = selectionMode(); 01996 setSelectionMode (TQListView::Multi); 01997 TQListView::keyPressEvent (e); 01998 setSelectionMode (oldSelectionMode); 01999 if (realKey && selectCurrentItem) { 02000 currentItem()->setSelected(true); 02001 emitSelectionChanged=true; 02002 } 02003 repaintItem2=currentItem(); 02004 if (realKey) { 02005 visItem=currentItem(); 02006 } 02007 break; 02008 } 02009 02010 if (visItem) { 02011 ensureItemVisible(visItem); 02012 } 02013 02014 TQRect ir; 02015 if (repaintItem1) { 02016 ir = ir.unite( itemRect(repaintItem1) ); 02017 } 02018 if (repaintItem2) { 02019 ir = ir.unite( itemRect(repaintItem2) ); 02020 } 02021 02022 if ( !ir.isEmpty() ) { 02023 // rectangle to be repainted 02024 if ( ir.x() < 0 ) { 02025 ir.moveBy( -ir.x(), 0 ); 02026 } 02027 viewport()->repaint( ir, false ); 02028 } 02029 /*if (repaintItem1) { 02030 repaintItem1->repaint(); 02031 } 02032 if (repaintItem2) { 02033 repaintItem2->repaint(); 02034 }*/ 02035 02036 update(); 02037 if (emitSelectionChanged) { 02038 emit selectionChanged(); 02039 } 02040 } 02041 02042 void TDEListView::setSelectionModeExt (SelectionModeExt mode) 02043 { 02044 d->selectionMode = mode; 02045 02046 switch (mode) 02047 { 02048 case Single: 02049 case Multi: 02050 case Extended: 02051 case NoSelection: 02052 setSelectionMode (static_cast<TQListView::SelectionMode>(static_cast<int>(mode))); 02053 break; 02054 02055 case FileManager: 02056 setSelectionMode (TQListView::Extended); 02057 break; 02058 02059 default: 02060 kdWarning () << "Warning: illegal selection mode " << int(mode) << " set!" << endl; 02061 break; 02062 } 02063 } 02064 02065 TDEListView::SelectionModeExt TDEListView::selectionModeExt () const 02066 { 02067 return d->selectionMode; 02068 } 02069 02070 int TDEListView::itemIndex( const TQListViewItem *item ) const 02071 { 02072 if ( !item ) 02073 return -1; 02074 02075 if ( item == firstChild() ) 02076 return 0; 02077 else { 02078 TQListViewItemIterator it(firstChild()); 02079 uint j = 0; 02080 for (; it.current() && it.current() != item; ++it, ++j ); 02081 02082 if( !it.current() ) 02083 return -1; 02084 02085 return j; 02086 } 02087 } 02088 02089 TQListViewItem* TDEListView::itemAtIndex(int index) 02090 { 02091 if (index<0) 02092 return 0; 02093 02094 int j(0); 02095 for (TQListViewItemIterator it=firstChild(); it.current(); ++it) 02096 { 02097 if (j==index) 02098 return it.current(); 02099 ++j; 02100 }; 02101 return 0; 02102 } 02103 02104 02105 void TDEListView::emitContextMenu (TDEListView*, TQListViewItem* i) 02106 { 02107 TQPoint p; 02108 02109 if (i) 02110 p = viewport()->mapToGlobal(itemRect(i).center()); 02111 else 02112 p = mapToGlobal(rect().center()); 02113 02114 emit contextMenu (this, i, p); 02115 } 02116 02117 void TDEListView::emitContextMenu (TQListViewItem* i, const TQPoint& p, int) 02118 { 02119 emit contextMenu (this, i, p); 02120 } 02121 02122 void TDEListView::setAcceptDrops (bool val) 02123 { 02124 TQListView::setAcceptDrops (val); 02125 viewport()->setAcceptDrops (val); 02126 } 02127 02128 int TDEListView::dropVisualizerWidth () const 02129 { 02130 return d->mDropVisualizerWidth; 02131 } 02132 02133 02134 void TDEListView::viewportPaintEvent(TQPaintEvent *e) 02135 { 02136 d->paintAbove = 0; 02137 d->paintCurrent = 0; 02138 d->paintBelow = 0; 02139 d->painting = true; 02140 02141 TQListView::viewportPaintEvent(e); 02142 02143 if (d->mOldDropVisualizer.isValid() && e->rect().intersects(d->mOldDropVisualizer)) 02144 { 02145 TQPainter painter(viewport()); 02146 02147 // This is where we actually draw the drop-visualizer 02148 painter.fillRect(d->mOldDropVisualizer, Dense4Pattern); 02149 } 02150 if (d->mOldDropHighlighter.isValid() && e->rect().intersects(d->mOldDropHighlighter)) 02151 { 02152 TQPainter painter(viewport()); 02153 02154 // This is where we actually draw the drop-highlighter 02155 style().tqdrawPrimitive(TQStyle::PE_FocusRect, &painter, d->mOldDropHighlighter, colorGroup(), 02156 TQStyle::Style_FocusAtBorder); 02157 } 02158 d->painting = false; 02159 } 02160 02161 void TDEListView::setFullWidth() 02162 { 02163 setFullWidth(true); 02164 } 02165 02166 void TDEListView::setFullWidth(bool fullWidth) 02167 { 02168 d->fullWidth = fullWidth; 02169 header()->setStretchEnabled(fullWidth, columns()-1); 02170 } 02171 02172 bool TDEListView::fullWidth() const 02173 { 02174 return d->fullWidth; 02175 } 02176 02177 int TDEListView::addColumn(const TQString& label, int width) 02178 { 02179 int result = TQListView::addColumn(label, width); 02180 if (d->fullWidth) { 02181 header()->setStretchEnabled(false, columns()-2); 02182 header()->setStretchEnabled(true, columns()-1); 02183 } 02184 return result; 02185 } 02186 02187 int TDEListView::addColumn(const TQIconSet& iconset, const TQString& label, int width) 02188 { 02189 int result = TQListView::addColumn(iconset, label, width); 02190 if (d->fullWidth) { 02191 header()->setStretchEnabled(false, columns()-2); 02192 header()->setStretchEnabled(true, columns()-1); 02193 } 02194 return result; 02195 } 02196 02197 void TDEListView::removeColumn(int index) 02198 { 02199 TQListView::removeColumn(index); 02200 if (d->fullWidth && index == columns()) header()->setStretchEnabled(true, columns()-1); 02201 } 02202 02203 void TDEListView::viewportResizeEvent(TQResizeEvent* e) 02204 { 02205 TQListView::viewportResizeEvent(e); 02206 } 02207 02208 const TQColor &TDEListView::alternateBackground() const 02209 { 02210 return d->alternateBackground; 02211 } 02212 02213 void TDEListView::setAlternateBackground(const TQColor &c) 02214 { 02215 d->alternateBackground = c; 02216 repaint(); 02217 } 02218 02219 void TDEListView::setShadeSortColumn(bool shadeSortColumn) 02220 { 02221 d->shadeSortColumn = shadeSortColumn; 02222 repaint(); 02223 } 02224 02225 bool TDEListView::shadeSortColumn() const 02226 { 02227 return d->shadeSortColumn; 02228 } 02229 02230 void TDEListView::saveLayout(TDEConfig *config, const TQString &group) const 02231 { 02232 TDEConfigGroupSaver saver(config, group); 02233 TQStringList widths, order; 02234 02235 const int colCount = columns(); 02236 TQHeader* const thisHeader = header(); 02237 for (int i = 0; i < colCount; ++i) 02238 { 02239 widths << TQString::number(columnWidth(i)); 02240 order << TQString::number(thisHeader->mapToIndex(i)); 02241 } 02242 config->writeEntry("ColumnWidths", widths); 02243 config->writeEntry("ColumnOrder", order); 02244 config->writeEntry("SortColumn", d->sortColumn); 02245 config->writeEntry("SortAscending", d->sortAscending); 02246 } 02247 02248 void TDEListView::restoreLayout(TDEConfig *config, const TQString &group) 02249 { 02250 TDEConfigGroupSaver saver(config, group); 02251 TQStringList cols = config->readListEntry("ColumnWidths"); 02252 int i = 0; 02253 { // scope the iterators 02254 TQStringList::ConstIterator it = cols.constBegin(); 02255 const TQStringList::ConstIterator itEnd = cols.constEnd(); 02256 for (; it != itEnd; ++it) 02257 setColumnWidth(i++, (*it).toInt()); 02258 } 02259 02260 // move sections in the correct sequence: from lowest to highest index position 02261 // otherwise we move a section from an index, which modifies 02262 // all index numbers to the right of the moved one 02263 cols = config->readListEntry("ColumnOrder"); 02264 const int colCount = columns(); 02265 for (i = 0; i < colCount; ++i) // final index positions from lowest to highest 02266 { 02267 TQStringList::ConstIterator it = cols.constBegin(); 02268 const TQStringList::ConstIterator itEnd = cols.constEnd(); 02269 02270 int section = 0; 02271 for (; (it != itEnd) && ((*it).toInt() != i); ++it, ++section) ; 02272 02273 if ( it != itEnd ) { 02274 // found the section to move to position i 02275 header()->moveSection(section, i); 02276 } 02277 } 02278 02279 if (config->hasKey("SortColumn")) 02280 setSorting(config->readNumEntry("SortColumn"), config->readBoolEntry("SortAscending", true)); 02281 } 02282 02283 void TDEListView::setSorting(int column, bool ascending) 02284 { 02285 TQListViewItem *selected = 0; 02286 02287 if (selectionMode() == TQListView::Single) { 02288 selected = selectedItem(); 02289 if (selected && !selected->isVisible()) 02290 selected = 0; 02291 } 02292 else if (selectionMode() != TQListView::NoSelection) { 02293 TQListViewItem *item = firstChild(); 02294 while (item && !selected) { 02295 if (item->isSelected() && item->isVisible()) 02296 selected = item; 02297 item = item->itemBelow(); 02298 } 02299 } 02300 02301 d->sortColumn = column; 02302 d->sortAscending = ascending; 02303 TQListView::setSorting(column, ascending); 02304 02305 if (selected) 02306 ensureItemVisible(selected); 02307 02308 TQListViewItem* item = firstChild(); 02309 while ( item ) { 02310 TDEListViewItem *kItem = dynamic_cast<TDEListViewItem*>(item); 02311 if (kItem) kItem->m_known = false; 02312 item = item->itemBelow(); 02313 } 02314 } 02315 02316 int TDEListView::columnSorted(void) const 02317 { 02318 return d->sortColumn; 02319 } 02320 02321 bool TDEListView::ascendingSort(void) const 02322 { 02323 return d->sortAscending; 02324 } 02325 02326 void TDEListView::takeItem(TQListViewItem *item) 02327 { 02328 if(item && item == d->editor->currentItem()) 02329 d->editor->terminate(); 02330 02331 TQListView::takeItem(item); 02332 } 02333 02334 void TDEListView::disableAutoSelection() 02335 { 02336 if ( d->disableAutoSelection ) 02337 return; 02338 02339 d->disableAutoSelection = true; 02340 d->autoSelect.stop(); 02341 d->autoSelectDelay = -1; 02342 } 02343 02344 void TDEListView::resetAutoSelection() 02345 { 02346 if ( !d->disableAutoSelection ) 02347 return; 02348 02349 d->disableAutoSelection = false; 02350 d->autoSelectDelay = TDEGlobalSettings::autoSelectDelay(); 02351 } 02352 02353 void TDEListView::doubleClicked( TQListViewItem *item, const TQPoint &pos, int c ) 02354 { 02355 emit TQListView::doubleClicked( item, pos, c ); 02356 } 02357 02358 TDEListViewItem::TDEListViewItem(TQListView *parent) 02359 : TQListViewItem(parent) 02360 { 02361 init(); 02362 } 02363 02364 TDEListViewItem::TDEListViewItem(TQListViewItem *parent) 02365 : TQListViewItem(parent) 02366 { 02367 init(); 02368 } 02369 02370 TDEListViewItem::TDEListViewItem(TQListView *parent, TQListViewItem *after) 02371 : TQListViewItem(parent, after) 02372 { 02373 init(); 02374 } 02375 02376 TDEListViewItem::TDEListViewItem(TQListViewItem *parent, TQListViewItem *after) 02377 : TQListViewItem(parent, after) 02378 { 02379 init(); 02380 } 02381 02382 TDEListViewItem::TDEListViewItem(TQListView *parent, 02383 TQString label1, TQString label2, TQString label3, TQString label4, 02384 TQString label5, TQString label6, TQString label7, TQString label8) 02385 : TQListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) 02386 { 02387 init(); 02388 } 02389 02390 TDEListViewItem::TDEListViewItem(TQListViewItem *parent, 02391 TQString label1, TQString label2, TQString label3, TQString label4, 02392 TQString label5, TQString label6, TQString label7, TQString label8) 02393 : TQListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) 02394 { 02395 init(); 02396 } 02397 02398 TDEListViewItem::TDEListViewItem(TQListView *parent, TQListViewItem *after, 02399 TQString label1, TQString label2, TQString label3, TQString label4, 02400 TQString label5, TQString label6, TQString label7, TQString label8) 02401 : TQListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) 02402 { 02403 init(); 02404 } 02405 02406 TDEListViewItem::TDEListViewItem(TQListViewItem *parent, TQListViewItem *after, 02407 TQString label1, TQString label2, TQString label3, TQString label4, 02408 TQString label5, TQString label6, TQString label7, TQString label8) 02409 : TQListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) 02410 { 02411 init(); 02412 } 02413 02414 TDEListViewItem::~TDEListViewItem() 02415 { 02416 if(listView()) 02417 emit static_cast<TDEListView *>(listView())->itemRemoved(this); 02418 } 02419 02420 void TDEListViewItem::init() 02421 { 02422 m_odd = m_known = false; 02423 TDEListView *lv = static_cast<TDEListView *>(listView()); 02424 setDragEnabled( dragEnabled() || lv->dragEnabled() ); 02425 emit lv->itemAdded(this); 02426 } 02427 02428 void TDEListViewItem::insertItem(TQListViewItem *item) 02429 { 02430 TQListViewItem::insertItem(item); 02431 if(listView()) 02432 emit static_cast<TDEListView *>(listView())->itemAdded(item); 02433 } 02434 02435 void TDEListViewItem::takeItem(TQListViewItem *item) 02436 { 02437 TQListViewItem::takeItem(item); 02438 if(listView()) 02439 emit static_cast<TDEListView *>(listView())->itemRemoved(item); 02440 } 02441 02442 const TQColor &TDEListViewItem::backgroundColor() 02443 { 02444 if (isAlternate()) 02445 return static_cast< TDEListView* >(listView())->alternateBackground(); 02446 return listView()->viewport()->colorGroup().base(); 02447 } 02448 02449 TQColor TDEListViewItem::backgroundColor(int column) 02450 { 02451 TDEListView* view = static_cast< TDEListView* >(listView()); 02452 TQColor color = isAlternate() ? 02453 view->alternateBackground() : 02454 view->viewport()->colorGroup().base(); 02455 02456 // calculate a different color if the current column is sorted (only if more than 1 column) 02457 if ( (view->columns() > 1) && view->shadeSortColumn() && (column == view->columnSorted()) ) 02458 { 02459 if ( color == Qt::black ) 02460 color = TQColor(55, 55, 55); // dark gray 02461 else 02462 { 02463 int h,s,v; 02464 color.hsv(&h, &s, &v); 02465 if ( v > 175 ) 02466 color = color.dark(104); 02467 else 02468 color = color.light(120); 02469 } 02470 } 02471 02472 return color; 02473 } 02474 02475 bool TDEListViewItem::isAlternate() 02476 { 02477 TDEListView* const lv = static_cast<TDEListView *>(listView()); 02478 if (lv && lv->alternateBackground().isValid()) 02479 { 02480 TDEListViewItem *above; 02481 02482 TDEListView::TDEListViewPrivate* const lvD = lv->d; 02483 02484 // Ok, there's some weirdness here that requires explanation as this is a 02485 // speed hack. itemAbove() is a O(n) operation (though this isn't 02486 // immediately clear) so we want to call it as infrequently as possible -- 02487 // especially in the case of painting a cell. 02488 // 02489 // So, in the case that we *are* painting a cell: (1) we're assuming that 02490 // said painting is happening top to bottem -- this assumption is present 02491 // elsewhere in the implementation of this class, (2) itemBelow() is fast -- 02492 // roughly constant time. 02493 // 02494 // Given these assumptions we can do a mixture of caching and telling the 02495 // next item that the when that item is the current item that the now 02496 // current item will be the item above it. 02497 // 02498 // Ideally this will make checking to see if the item above the current item 02499 // is the alternate color a constant time operation rather than 0(n). 02500 02501 if (lvD->painting) { 02502 if (lvD->paintCurrent != this) 02503 { 02504 lvD->paintAbove = lvD->paintBelow == this ? lvD->paintCurrent : itemAbove(); 02505 lvD->paintCurrent = this; 02506 lvD->paintBelow = itemBelow(); 02507 } 02508 02509 above = dynamic_cast<TDEListViewItem *>(lvD->paintAbove); 02510 } 02511 else 02512 { 02513 above = dynamic_cast<TDEListViewItem *>(itemAbove()); 02514 } 02515 02516 m_known = above ? above->m_known : true; 02517 if (m_known) 02518 { 02519 m_odd = above ? !above->m_odd : false; 02520 } 02521 else 02522 { 02523 TDEListViewItem *item; 02524 bool previous = true; 02525 if (parent()) 02526 { 02527 item = dynamic_cast<TDEListViewItem *>(parent()); 02528 if (item) 02529 previous = item->m_odd; 02530 item = dynamic_cast<TDEListViewItem *>(parent()->firstChild()); 02531 } 02532 else 02533 { 02534 item = dynamic_cast<TDEListViewItem *>(lv->firstChild()); 02535 } 02536 02537 while(item) 02538 { 02539 previous = !previous; 02540 item->m_odd = previous; 02541 item->m_known = true; 02542 item = dynamic_cast<TDEListViewItem *>(item->nextSibling()); 02543 } 02544 } 02545 return m_odd; 02546 } 02547 return false; 02548 } 02549 02550 void TDEListViewItem::paintCell(TQPainter *p, const TQColorGroup &cg, int column, int width, int alignment) 02551 { 02552 TQColorGroup _cg = cg; 02553 TQListView* lv = listView(); 02554 const TQPixmap *pm = lv->viewport()->backgroundPixmap(); 02555 02556 if (pm && !pm->isNull()) 02557 { 02558 _cg.setBrush(TQColorGroup::Base, TQBrush(backgroundColor(column), *pm)); 02559 TQPoint o = p->brushOrigin(); 02560 p->setBrushOrigin( o.x()-lv->contentsX(), o.y()-lv->contentsY() ); 02561 } 02562 else 02563 { 02564 _cg.setColor((lv->viewport()->backgroundMode() == TQt::FixedColor) ? 02565 TQColorGroup::Background : TQColorGroup::Base, 02566 backgroundColor(column)); 02567 } 02568 TQListViewItem::paintCell(p, _cg, column, width, alignment); 02569 } 02570 02578 void TDEListView::selectAll( bool select ) 02579 { 02580 if ( ((SelectionModeExt)selectionMode() == Multi) || ((SelectionModeExt)selectionMode() == Extended) ) { 02581 bool b = signalsBlocked(); 02582 blockSignals( TRUE ); 02583 bool anything = FALSE; 02584 TQListViewItemIterator it( this ); 02585 while ( it.current() ) { 02586 TQListViewItem *i = it.current(); 02587 if ( select == TRUE ) { 02588 if ( (bool)i->isVisible() == TRUE ) { 02589 i->setSelected( TRUE ); 02590 anything = TRUE; 02591 } 02592 if ( (bool)i->isVisible() == FALSE ) { 02593 i->setSelected( FALSE ); 02594 anything = TRUE; 02595 } 02596 } 02597 else { 02598 if ( (bool)i->isSelected() != select ) { 02599 i->setSelected( select ); 02600 anything = TRUE; 02601 } 02602 } 02603 ++it; 02604 } 02605 blockSignals( b ); 02606 if ( anything ) { 02607 emit selectionChanged(); 02608 // d->useDoubleBuffer = TRUE; 02609 triggerUpdate(); 02610 } 02611 } else if ( currentItem() ) { 02612 TQListViewItem * i = currentItem(); 02613 setSelected( i, select ); 02614 } 02615 } 02616 02617 void TDEListView::setUseSmallExecuteArea(bool enable) 02618 { 02619 d->useSmallExecuteArea = enable; 02620 } 02621 02622 bool TDEListView::useSmallExecuteArea() const 02623 { 02624 return d->useSmallExecuteArea; 02625 } 02626 02627 void TDEListView::setRenameSettings(const TDEListViewRenameSettings &renSett) 02628 { 02629 d->editor->setRenameSettings(renSett); 02630 } 02631 02632 void TDEListView::virtual_hook( int, void* ) 02633 { /*BASE::virtual_hook( id, data );*/ } 02634 02635 #include "tdelistview.moc" 02636 #include "tdelistviewlineedit.moc" 02637 02638 // vim: noet