summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-10-28 01:24:25 (UTC)
committer ulf69 <ulf69>2004-10-28 01:24:25 (UTC)
commit2fe1a56682ef4dc1fa0a30f764c7313b583631c5 (patch) (unidiff)
tree291b87266c05359c8a2ba9a54a9df182380f77ef
parent621a8505690485db909a573f83433873197595c0 (diff)
downloadkdepimpi-2fe1a56682ef4dc1fa0a30f764c7313b583631c5.zip
kdepimpi-2fe1a56682ef4dc1fa0a30f764c7313b583631c5.tar.gz
kdepimpi-2fe1a56682ef4dc1fa0a30f764c7313b583631c5.tar.bz2
removed debugoutput
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdeui/klistview.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/microkde/kdeui/klistview.cpp b/microkde/kdeui/klistview.cpp
index 32483bb..6859d36 100644
--- a/microkde/kdeui/klistview.cpp
+++ b/microkde/kdeui/klistview.cpp
@@ -1,2221 +1,2221 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Reginald Stadlbauer <reggie@kde.org> 2 Copyright (C) 2000 Reginald Stadlbauer <reggie@kde.org>
3 Copyright (C) 2000 Charles Samuels <charles@kde.org> 3 Copyright (C) 2000 Charles Samuels <charles@kde.org>
4 Copyright (C) 2000 Peter Putzer 4 Copyright (C) 2000 Peter Putzer
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation. 8 License version 2 as published by the Free Software Foundation.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <qdragobject.h> 21#include <qdragobject.h>
22#include <qtimer.h> 22#include <qtimer.h>
23#include <qheader.h> 23#include <qheader.h>
24#include <qcursor.h> 24#include <qcursor.h>
25#include <qtooltip.h> 25#include <qtooltip.h>
26#include <qstyle.h> 26#include <qstyle.h>
27#include <qpainter.h> 27#include <qpainter.h>
28 28
29#include <kglobalsettings.h> 29#include <kglobalsettings.h>
30#include <kconfig.h> 30#include <kconfig.h>
31#include <kconfigbase.h> 31#include <kconfigbase.h>
32//US #include <kcursor.h> 32//US #include <kcursor.h>
33#include <kapplication.h> 33#include <kapplication.h>
34//US #include <kipc.h> 34//US #include <kipc.h>
35#include <kdebug.h> 35#include <kdebug.h>
36#ifdef _WIN32_ 36#ifdef _WIN32_
37#define Q_WS_QWS 37#define Q_WS_QWS
38#endif 38#endif
39#ifndef _WIN32_ 39#ifndef _WIN32_
40#define private public 40#define private public
41#include <qlistview.h> 41#include <qlistview.h>
42#undef private 42#undef private
43#endif 43#endif
44#include "klistview.h" 44#include "klistview.h"
45//US #include "klistviewlineedit.h" 45//US #include "klistviewlineedit.h"
46#ifndef DESKTOP_VERSION 46#ifndef DESKTOP_VERSION
47#include <qpe/qpeapplication.h> 47#include <qpe/qpeapplication.h>
48#endif 48#endif
49 49
50// /*US 50// /*US
51class KListView::Tooltip : public QToolTip 51class KListView::Tooltip : public QToolTip
52{ 52{
53public: 53public:
54 Tooltip (KListView* parent, QToolTipGroup* group = 0L); 54 Tooltip (KListView* parent, QToolTipGroup* group = 0L);
55 virtual ~Tooltip () {} 55 virtual ~Tooltip () {}
56 56
57protected: 57protected:
58 // */ 58 // */
59 /** 59 /**
60 * Reimplemented from QToolTip for internal reasons. 60 * Reimplemented from QToolTip for internal reasons.
61 */ 61 */
62 // /*US 62 // /*US
63 virtual void maybeTip (const QPoint&); 63 virtual void maybeTip (const QPoint&);
64 64
65private: 65private:
66 KListView* mParent; 66 KListView* mParent;
67}; 67};
68 68
69KListView::Tooltip::Tooltip (KListView* parent, QToolTipGroup* group) 69KListView::Tooltip::Tooltip (KListView* parent, QToolTipGroup* group)
70 : QToolTip (parent, group), 70 : QToolTip (parent, group),
71 mParent (parent) 71 mParent (parent)
72{ 72{
73} 73}
74 74
75void KListView::Tooltip::maybeTip (const QPoint&) 75void KListView::Tooltip::maybeTip (const QPoint&)
76{ 76{
77 // FIXME 77 // FIXME
78} 78}
79// */ 79// */
80 80
81class KListView::KListViewPrivate 81class KListView::KListViewPrivate
82{ 82{
83public: 83public:
84 KListViewPrivate (KListView* listview) 84 KListViewPrivate (KListView* listview)
85 : pCurrentItem (0L), 85 : pCurrentItem (0L),
86 autoSelectDelay(1), 86 autoSelectDelay(1),
87//US dragDelay (KGlobalSettings::dndEventDelay()), 87//US dragDelay (KGlobalSettings::dndEventDelay()),
88 88
89 dragDelay (10), 89 dragDelay (10),
90//US editor (new KListViewLineEdit (listview)), 90//US editor (new KListViewLineEdit (listview)),
91 cursorInExecuteArea(false), 91 cursorInExecuteArea(false),
92 bUseSingle(false), 92 bUseSingle(false),
93 bChangeCursorOverItem(false), 93 bChangeCursorOverItem(false),
94 itemsMovable (true), 94 itemsMovable (true),
95 selectedBySimpleMove(false), 95 selectedBySimpleMove(false),
96 selectedUsingMouse(false), 96 selectedUsingMouse(false),
97 itemsRenameable (false), 97 itemsRenameable (false),
98 validDrag (false), 98 validDrag (false),
99 dragEnabled (false), 99 dragEnabled (false),
100 autoOpen (true), 100 autoOpen (true),
101 dropVisualizer (true), 101 dropVisualizer (true),
102 dropHighlighter (false), 102 dropHighlighter (false),
103 createChildren (true), 103 createChildren (true),
104 pressedOnSelected (false), 104 pressedOnSelected (false),
105 wasShiftEvent (false), 105 wasShiftEvent (false),
106 fullWidth (false), 106 fullWidth (false),
107 sortAscending(true), 107 sortAscending(true),
108 tabRename(true), 108 tabRename(true),
109 sortColumn(0), 109 sortColumn(0),
110 selectionDirection(0), 110 selectionDirection(0),
111 tooltipColumn (0), 111 tooltipColumn (0),
112 selectionMode (Single), 112 selectionMode (Single),
113 contextMenuKey ( Qt::Key_Menu ),//KGlobalSettings::contextMenuKey()), 113 contextMenuKey ( Qt::Key_Menu ),//KGlobalSettings::contextMenuKey()),
114 showContextMenusOnPress (true),//showContextMenusOnPress (KGlobalSettings::showContextMenusOnPress()), 114 showContextMenusOnPress (true),//showContextMenusOnPress (KGlobalSettings::showContextMenusOnPress()),
115 mDropVisualizerWidth (4) 115 mDropVisualizerWidth (4)
116 { 116 {
117 renameable += 0; 117 renameable += 0;
118//US connect(editor, SIGNAL(done(QListViewItem*,int)), listview, SLOT(doneEditing(QListViewItem*,int))); 118//US connect(editor, SIGNAL(done(QListViewItem*,int)), listview, SLOT(doneEditing(QListViewItem*,int)));
119 } 119 }
120 120
121 ~KListViewPrivate () 121 ~KListViewPrivate ()
122 { 122 {
123//US delete editor; 123//US delete editor;
124 } 124 }
125 125
126 QListViewItem* pCurrentItem; 126 QListViewItem* pCurrentItem;
127 127
128 QTimer autoSelect; 128 QTimer autoSelect;
129 int autoSelectDelay; 129 int autoSelectDelay;
130 130
131 QTimer dragExpand; 131 QTimer dragExpand;
132 QListViewItem* dragOverItem; 132 QListViewItem* dragOverItem;
133 QPoint dragOverPoint; 133 QPoint dragOverPoint;
134 134
135 QPoint startDragPos; 135 QPoint startDragPos;
136 int dragDelay; 136 int dragDelay;
137 137
138//US KListViewLineEdit *editor; 138//US KListViewLineEdit *editor;
139 QValueList<int> renameable; 139 QValueList<int> renameable;
140 140
141 bool cursorInExecuteArea:1; 141 bool cursorInExecuteArea:1;
142 bool bUseSingle:1; 142 bool bUseSingle:1;
143 bool bChangeCursorOverItem:1; 143 bool bChangeCursorOverItem:1;
144 bool itemsMovable:1; 144 bool itemsMovable:1;
145 bool selectedBySimpleMove : 1; 145 bool selectedBySimpleMove : 1;
146 bool selectedUsingMouse:1; 146 bool selectedUsingMouse:1;
147 bool itemsRenameable:1; 147 bool itemsRenameable:1;
148 bool validDrag:1; 148 bool validDrag:1;
149 bool dragEnabled:1; 149 bool dragEnabled:1;
150 bool autoOpen:1; 150 bool autoOpen:1;
151 bool dropVisualizer:1; 151 bool dropVisualizer:1;
152 bool dropHighlighter:1; 152 bool dropHighlighter:1;
153 bool createChildren:1; 153 bool createChildren:1;
154 bool pressedOnSelected:1; 154 bool pressedOnSelected:1;
155 bool wasShiftEvent:1; 155 bool wasShiftEvent:1;
156 bool fullWidth:1; 156 bool fullWidth:1;
157 bool sortAscending:1; 157 bool sortAscending:1;
158 bool tabRename:1; 158 bool tabRename:1;
159 159
160 int sortColumn; 160 int sortColumn;
161 161
162 //+1 means downwards (y increases, -1 means upwards, 0 means not selected), aleXXX 162 //+1 means downwards (y increases, -1 means upwards, 0 means not selected), aleXXX
163 int selectionDirection; 163 int selectionDirection;
164 int tooltipColumn; 164 int tooltipColumn;
165 165
166 SelectionModeExt selectionMode; 166 SelectionModeExt selectionMode;
167 int contextMenuKey; 167 int contextMenuKey;
168 bool showContextMenusOnPress; 168 bool showContextMenusOnPress;
169 169
170 QRect mOldDropVisualizer; 170 QRect mOldDropVisualizer;
171 int mDropVisualizerWidth; 171 int mDropVisualizerWidth;
172 QRect mOldDropHighlighter; 172 QRect mOldDropHighlighter;
173 QListViewItem *afterItemDrop; 173 QListViewItem *afterItemDrop;
174 QListViewItem *parentItemDrop; 174 QListViewItem *parentItemDrop;
175 175
176 QColor alternateBackground; 176 QColor alternateBackground;
177}; 177};
178 178
179/*US 179/*US
180KListViewLineEdit::KListViewLineEdit(KListView *parent) 180KListViewLineEdit::KListViewLineEdit(KListView *parent)
181 : KLineEdit(parent->viewport()), item(0), col(0), p(parent) 181 : KLineEdit(parent->viewport()), item(0), col(0), p(parent)
182{ 182{
183 setFrame( false ); 183 setFrame( false );
184 hide(); 184 hide();
185 connect( parent, SIGNAL( selectionChanged() ), SLOT( slotSelectionChanged() )); 185 connect( parent, SIGNAL( selectionChanged() ), SLOT( slotSelectionChanged() ));
186} 186}
187 187
188KListViewLineEdit::~KListViewLineEdit() 188KListViewLineEdit::~KListViewLineEdit()
189{ 189{
190} 190}
191 191
192void KListViewLineEdit::load(QListViewItem *i, int c) 192void KListViewLineEdit::load(QListViewItem *i, int c)
193{ 193{
194 item=i; 194 item=i;
195 col=c; 195 col=c;
196 196
197 QRect rect(p->itemRect(i)); 197 QRect rect(p->itemRect(i));
198 setText(item->text(c)); 198 setText(item->text(c));
199 199
200 int fieldX = rect.x() - 1; 200 int fieldX = rect.x() - 1;
201 int fieldW = p->columnWidth(col) + 2; 201 int fieldW = p->columnWidth(col) + 2;
202 202
203 int pos = p->header()->mapToIndex(col); 203 int pos = p->header()->mapToIndex(col);
204 for ( int index = 0; index < pos; index++ ) 204 for ( int index = 0; index < pos; index++ )
205 fieldX += p->columnWidth( p->header()->mapToSection( index )); 205 fieldX += p->columnWidth( p->header()->mapToSection( index ));
206 206
207 if ( col == 0 ) { 207 if ( col == 0 ) {
208 int d = i->depth() + (p->rootIsDecorated() ? 1 : 0); 208 int d = i->depth() + (p->rootIsDecorated() ? 1 : 0);
209 d *= p->treeStepSize(); 209 d *= p->treeStepSize();
210 fieldX += d; 210 fieldX += d;
211 fieldW -= d; 211 fieldW -= d;
212 } 212 }
213 213
214 if ( i->pixmap( col ) ) {// add width of pixmap 214 if ( i->pixmap( col ) ) {// add width of pixmap
215 int d = i->pixmap( col )->width(); 215 int d = i->pixmap( col )->width();
216 fieldX += d; 216 fieldX += d;
217 fieldW -= d; 217 fieldW -= d;
218 } 218 }
219 219
220 setGeometry(fieldX, rect.y() - 1, fieldW, rect.height() + 2); 220 setGeometry(fieldX, rect.y() - 1, fieldW, rect.height() + 2);
221 show(); 221 show();
222 setFocus(); 222 setFocus();
223} 223}
224*/ 224*/
225 /*Helper functions to for 225 /*Helper functions to for
226 *tabOrderedRename functionality. 226 *tabOrderedRename functionality.
227 */ 227 */
228 228
229static int nextCol (KListView *pl, QListViewItem *pi, int start, int dir) 229static int nextCol (KListView *pl, QListViewItem *pi, int start, int dir)
230{ 230{
231 if (pi) 231 if (pi)
232 { 232 {
233 //Find the next renameable column in the current row 233 //Find the next renameable column in the current row
234 for (; ((dir == +1) ? (start < pl->columns()) : (start >= 0)); start += dir) 234 for (; ((dir == +1) ? (start < pl->columns()) : (start >= 0)); start += dir)
235 if (pl->isRenameable(start)) 235 if (pl->isRenameable(start))
236 return start; 236 return start;
237 } 237 }
238 238
239 return -1; 239 return -1;
240} 240}
241 241
242static QListViewItem *prevItem (QListViewItem *pi) 242static QListViewItem *prevItem (QListViewItem *pi)
243{ 243{
244 QListViewItem *pa = pi->itemAbove(); 244 QListViewItem *pa = pi->itemAbove();
245 245
246 /*Does what the QListViewItem::previousSibling() 246 /*Does what the QListViewItem::previousSibling()
247 *of my dreams would do. 247 *of my dreams would do.
248 */ 248 */
249 if (pa && pa->parent() == pi->parent()) 249 if (pa && pa->parent() == pi->parent())
250 return pa; 250 return pa;
251 251
252 return NULL; 252 return NULL;
253} 253}
254 254
255static QListViewItem *lastQChild (QListViewItem *pi) 255static QListViewItem *lastQChild (QListViewItem *pi)
256{ 256{
257 if (pi) 257 if (pi)
258 { 258 {
259 /*Since there's no QListViewItem::lastChild(). 259 /*Since there's no QListViewItem::lastChild().
260 *This finds the last sibling for the given 260 *This finds the last sibling for the given
261 *item. 261 *item.
262 */ 262 */
263 for (QListViewItem *pt = pi->nextSibling(); pt; pt = pt->nextSibling()) 263 for (QListViewItem *pt = pi->nextSibling(); pt; pt = pt->nextSibling())
264 pi = pt; 264 pi = pt;
265 } 265 }
266 266
267 return pi; 267 return pi;
268} 268}
269/*US 269/*US
270void KListViewLineEdit::selectNextCell (QListViewItem *pitem, int column, bool forward) 270void KListViewLineEdit::selectNextCell (QListViewItem *pitem, int column, bool forward)
271{ 271{
272 const int ncols = p->columns(); 272 const int ncols = p->columns();
273 const int dir = forward ? +1 : -1; 273 const int dir = forward ? +1 : -1;
274 const int restart = forward ? 0 : (ncols - 1); 274 const int restart = forward ? 0 : (ncols - 1);
275 QListViewItem *top = (pitem && pitem->parent()) 275 QListViewItem *top = (pitem && pitem->parent())
276 ? pitem->parent()->firstChild() 276 ? pitem->parent()->firstChild()
277 : p->firstChild(); 277 : p->firstChild();
278 QListViewItem *pi = pitem; 278 QListViewItem *pi = pitem;
279 279
280 terminate(); //Save current changes 280 terminate(); //Save current changes
281 281
282 do 282 do
283 { 283 {
284*/ 284*/
285 /*Check the rest of the current row for an editable column, 285 /*Check the rest of the current row for an editable column,
286 *if that fails, check the entire next/previous row. The 286 *if that fails, check the entire next/previous row. The
287 *last case goes back to the first item in the current branch 287 *last case goes back to the first item in the current branch
288 *or the last item in the current branch depending on the 288 *or the last item in the current branch depending on the
289 *direction. 289 *direction.
290 */ 290 */
291/*US 291/*US
292 if ((column = nextCol(p, pi, column + dir, dir)) != -1 || 292 if ((column = nextCol(p, pi, column + dir, dir)) != -1 ||
293 (column = nextCol(p, (pi = (forward ? pi->nextSibling() : prevItem(pi))), restart, dir)) != -1 || 293 (column = nextCol(p, (pi = (forward ? pi->nextSibling() : prevItem(pi))), restart, dir)) != -1 ||
294 (column = nextCol(p, (pi = (forward ? top : lastQChild(pitem))), restart, dir)) != -1) 294 (column = nextCol(p, (pi = (forward ? top : lastQChild(pitem))), restart, dir)) != -1)
295 { 295 {
296 if (pi) 296 if (pi)
297 { 297 {
298 p->setCurrentItem(pi); //Calls terminate 298 p->setCurrentItem(pi); //Calls terminate
299 p->rename(pi, column); 299 p->rename(pi, column);
300*/ 300*/
301 /*Some listviews may override rename() to 301 /*Some listviews may override rename() to
302 *prevent certain items from being renamed, 302 *prevent certain items from being renamed,
303 *if this is done, [m_]item will be NULL 303 *if this is done, [m_]item will be NULL
304 *after the rename() call... try again. 304 *after the rename() call... try again.
305 */ 305 */
306/*US 306/*US
307 if (!item) 307 if (!item)
308 continue; 308 continue;
309 309
310 break; 310 break;
311 } 311 }
312 } 312 }
313 } 313 }
314 while (pi && !item); 314 while (pi && !item);
315} 315}
316*/ 316*/
317 317
318/*US 318/*US
319#ifdef KeyPress 319#ifdef KeyPress
320#undef KeyPress 320#undef KeyPress
321#endif 321#endif
322 322
323bool KListViewLineEdit::event (QEvent *pe) 323bool KListViewLineEdit::event (QEvent *pe)
324{ 324{
325 if (pe->type() == QEvent::KeyPress) 325 if (pe->type() == QEvent::KeyPress)
326 { 326 {
327 QKeyEvent *k = (QKeyEvent *) pe; 327 QKeyEvent *k = (QKeyEvent *) pe;
328 328
329 if ((k->key() == Qt::Key_Backtab || k->key() == Qt::Key_Tab) && 329 if ((k->key() == Qt::Key_Backtab || k->key() == Qt::Key_Tab) &&
330 p->tabOrderedRenaming() && p->itemsRenameable() && 330 p->tabOrderedRenaming() && p->itemsRenameable() &&
331 !(k->state() & ControlButton || k->state() & AltButton)) 331 !(k->state() & ControlButton || k->state() & AltButton))
332 { 332 {
333 selectNextCell(item, col, 333 selectNextCell(item, col,
334 (k->key() == Key_Tab && !(k->state() & ShiftButton))); 334 (k->key() == Key_Tab && !(k->state() & ShiftButton)));
335 return true; 335 return true;
336 } 336 }
337 } 337 }
338 338
339 return KLineEdit::event(pe); 339 return KLineEdit::event(pe);
340} 340}
341 341
342void KListViewLineEdit::keyPressEvent(QKeyEvent *e) 342void KListViewLineEdit::keyPressEvent(QKeyEvent *e)
343{ 343{
344 if(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) 344 if(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter )
345 terminate(true); 345 terminate(true);
346 else if(e->key() == Qt::Key_Escape) 346 else if(e->key() == Qt::Key_Escape)
347 terminate(false); 347 terminate(false);
348 else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Up) 348 else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Up)
349 { 349 {
350 terminate(true); 350 terminate(true);
351 KLineEdit::keyPressEvent(e); 351 KLineEdit::keyPressEvent(e);
352 } 352 }
353 else 353 else
354 KLineEdit::keyPressEvent(e); 354 KLineEdit::keyPressEvent(e);
355} 355}
356 356
357void KListViewLineEdit::terminate() 357void KListViewLineEdit::terminate()
358{ 358{
359 terminate(true); 359 terminate(true);
360} 360}
361 361
362void KListViewLineEdit::terminate(bool commit) 362void KListViewLineEdit::terminate(bool commit)
363{ 363{
364 if ( item ) 364 if ( item )
365 { 365 {
366 //kdDebug() << "KListViewLineEdit::terminate " << commit << endl; 366 //kdDebug() << "KListViewLineEdit::terminate " << commit << endl;
367 if (commit) 367 if (commit)
368 item->setText(col, text()); 368 item->setText(col, text());
369 int c=col; 369 int c=col;
370 QListViewItem *i=item; 370 QListViewItem *i=item;
371 col=0; 371 col=0;
372 item=0; 372 item=0;
373 hide(); // will call focusOutEvent, that's why we set item=0 before 373 hide(); // will call focusOutEvent, that's why we set item=0 before
374 emit done(i,c); 374 emit done(i,c);
375 } 375 }
376} 376}
377 377
378void KListViewLineEdit::focusOutEvent(QFocusEvent *ev) 378void KListViewLineEdit::focusOutEvent(QFocusEvent *ev)
379{ 379{
380 QFocusEvent * focusEv = static_cast<QFocusEvent*>(ev); 380 QFocusEvent * focusEv = static_cast<QFocusEvent*>(ev);
381 // Don't let a RMB close the editor 381 // Don't let a RMB close the editor
382 if (focusEv->reason() != QFocusEvent::Popup && focusEv->reason() != QFocusEvent::ActiveWindow) 382 if (focusEv->reason() != QFocusEvent::Popup && focusEv->reason() != QFocusEvent::ActiveWindow)
383 terminate(true); 383 terminate(true);
384} 384}
385 385
386void KListViewLineEdit::paintEvent( QPaintEvent *e ) 386void KListViewLineEdit::paintEvent( QPaintEvent *e )
387{ 387{
388 KLineEdit::paintEvent( e ); 388 KLineEdit::paintEvent( e );
389 389
390 if ( !frame() ) { 390 if ( !frame() ) {
391 QPainter p( this ); 391 QPainter p( this );
392 p.setClipRegion( e->region() ); 392 p.setClipRegion( e->region() );
393 p.drawRect( rect() ); 393 p.drawRect( rect() );
394 } 394 }
395} 395}
396 396
397// selection changed -> terminate. As our "item" can be already deleted, 397// selection changed -> terminate. As our "item" can be already deleted,
398// we can't call terminate(false), because that would emit done() with 398// we can't call terminate(false), because that would emit done() with
399// a dangling pointer to "item". 399// a dangling pointer to "item".
400void KListViewLineEdit::slotSelectionChanged() 400void KListViewLineEdit::slotSelectionChanged()
401{ 401{
402 item = 0; 402 item = 0;
403 col = 0; 403 col = 0;
404 hide(); 404 hide();
405} 405}
406*/ 406*/
407 407
408KListView::KListView( QWidget *parent, const char *name ) 408KListView::KListView( QWidget *parent, const char *name )
409 : QListView( parent, name ), 409 : QListView( parent, name ),
410 d (new KListViewPrivate (this)) 410 d (new KListViewPrivate (this))
411{ 411{
412#ifndef DESKTOP_VERSION 412#ifndef DESKTOP_VERSION
413 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 413 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
414#endif 414#endif
415//US setDragAutoScroll(true); 415//US setDragAutoScroll(true);
416 416
417 connect( this, SIGNAL( onViewport() ), 417 connect( this, SIGNAL( onViewport() ),
418 this, SLOT( slotOnViewport() ) ); 418 this, SLOT( slotOnViewport() ) );
419 connect( this, SIGNAL( onItem( QListViewItem * ) ), 419 connect( this, SIGNAL( onItem( QListViewItem * ) ),
420 this, SLOT( slotOnItem( QListViewItem * ) ) ); 420 this, SLOT( slotOnItem( QListViewItem * ) ) );
421 421
422 connect (this, SIGNAL(contentsMoving(int,int)), 422 connect (this, SIGNAL(contentsMoving(int,int)),
423 this, SLOT(cleanDropVisualizer())); 423 this, SLOT(cleanDropVisualizer()));
424 connect (this, SIGNAL(contentsMoving(int,int)), 424 connect (this, SIGNAL(contentsMoving(int,int)),
425 this, SLOT(cleanItemHighlighter())); 425 this, SLOT(cleanItemHighlighter()));
426 426
427/*US 427/*US
428 slotSettingsChanged(KApplication::SETTINGS_MOUSE); 428 slotSettingsChanged(KApplication::SETTINGS_MOUSE);
429 429
430 if (kapp) 430 if (kapp)
431 { 431 {
432 connect( kapp, SIGNAL( settingsChanged(int) ), SLOT( slotSettingsChanged(int) ) ); 432 connect( kapp, SIGNAL( settingsChanged(int) ), SLOT( slotSettingsChanged(int) ) );
433 kapp->addKipcEventMask( KIPC::SettingsChanged ); 433 kapp->addKipcEventMask( KIPC::SettingsChanged );
434 } 434 }
435*/ 435*/
436 slotSettingsChanged(1); //US do this to initialize the connections 436 slotSettingsChanged(1); //US do this to initialize the connections
437 437
438 438
439 connect(&d->autoSelect, SIGNAL( timeout() ), 439 connect(&d->autoSelect, SIGNAL( timeout() ),
440 this, SLOT( slotAutoSelect() ) ); 440 this, SLOT( slotAutoSelect() ) );
441 connect(&d->dragExpand, SIGNAL( timeout() ), 441 connect(&d->dragExpand, SIGNAL( timeout() ),
442 this, SLOT( slotDragExpand() ) ); 442 this, SLOT( slotDragExpand() ) );
443 443
444 // context menu handling 444 // context menu handling
445 if (d->showContextMenusOnPress) 445 if (d->showContextMenusOnPress)
446 { 446 {
447 connect (this, SIGNAL (rightButtonPressed (QListViewItem*, const QPoint&, int)), 447 connect (this, SIGNAL (rightButtonPressed (QListViewItem*, const QPoint&, int)),
448 this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); 448 this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int)));
449 } 449 }
450 else 450 else
451 { 451 {
452 connect (this, SIGNAL (rightButtonClicked (QListViewItem*, const QPoint&, int)), 452 connect (this, SIGNAL (rightButtonClicked (QListViewItem*, const QPoint&, int)),
453 this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); 453 this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int)));
454 } 454 }
455 455
456 connect (this, SIGNAL (menuShortCutPressed (KListView*, QListViewItem*)), 456 connect (this, SIGNAL (menuShortCutPressed (KListView*, QListViewItem*)),
457 this, SLOT (emitContextMenu (KListView*, QListViewItem*))); 457 this, SLOT (emitContextMenu (KListView*, QListViewItem*)));
458 458
459 459
460 //qDebug("KListView::KListView make alternate color configurable"); 460 //qDebug("KListView::KListView make alternate color configurable");
461//US d->alternateBackground = KGlobalSettings::alternateBackgroundColor(); 461//US d->alternateBackground = KGlobalSettings::alternateBackgroundColor();
462 d->alternateBackground = QColor(240, 240, 240); 462 d->alternateBackground = QColor(240, 240, 240);
463} 463}
464 464
465 465
466 466
467KListView::~KListView() 467KListView::~KListView()
468{ 468{
469 delete d; 469 delete d;
470} 470}
471 471
472bool KListView::isExecuteArea( const QPoint& point ) 472bool KListView::isExecuteArea( const QPoint& point )
473{ 473{
474 if ( itemAt( point ) ) 474 if ( itemAt( point ) )
475 return isExecuteArea( point.x() ); 475 return isExecuteArea( point.x() );
476 476
477 return false; 477 return false;
478} 478}
479 479
480bool KListView::isExecuteArea( int x ) 480bool KListView::isExecuteArea( int x )
481{ 481{
482 if( allColumnsShowFocus() ) 482 if( allColumnsShowFocus() )
483 return true; 483 return true;
484 else { 484 else {
485 int offset = 0; 485 int offset = 0;
486 int width = columnWidth( 0 ); 486 int width = columnWidth( 0 );
487 int pos = header()->mapToIndex( 0 ); 487 int pos = header()->mapToIndex( 0 );
488 488
489 for ( int index = 0; index < pos; index++ ) 489 for ( int index = 0; index < pos; index++ )
490 offset += columnWidth( header()->mapToSection( index ) ); 490 offset += columnWidth( header()->mapToSection( index ) );
491 491
492 x += contentsX(); // in case of a horizontal scrollbar 492 x += contentsX(); // in case of a horizontal scrollbar
493 return ( x > offset && x < ( offset + width ) ); 493 return ( x > offset && x < ( offset + width ) );
494 } 494 }
495} 495}
496 496
497void KListView::slotOnItem( QListViewItem *item ) 497void KListView::slotOnItem( QListViewItem *item )
498{ 498{
499 QPoint vp = viewport()->mapFromGlobal( QCursor::pos() ); 499 QPoint vp = viewport()->mapFromGlobal( QCursor::pos() );
500 if ( item && isExecuteArea( vp.x() ) && (d->autoSelectDelay > -1) && d->bUseSingle ) { 500 if ( item && isExecuteArea( vp.x() ) && (d->autoSelectDelay > -1) && d->bUseSingle ) {
501 d->autoSelect.start( d->autoSelectDelay, true ); 501 d->autoSelect.start( d->autoSelectDelay, true );
502 d->pCurrentItem = item; 502 d->pCurrentItem = item;
503 } 503 }
504} 504}
505 505
506void KListView::slotOnViewport() 506void KListView::slotOnViewport()
507{ 507{
508 if ( d->bChangeCursorOverItem ) 508 if ( d->bChangeCursorOverItem )
509 viewport()->unsetCursor(); 509 viewport()->unsetCursor();
510 510
511 d->autoSelect.stop(); 511 d->autoSelect.stop();
512 d->pCurrentItem = 0L; 512 d->pCurrentItem = 0L;
513} 513}
514 514
515void KListView::slotSettingsChanged(int category) 515void KListView::slotSettingsChanged(int category)
516{ 516{
517 //qDebug("KListView::slotSettingsChanged has to be verified"); 517 //qDebug("KListView::slotSettingsChanged has to be verified");
518 518
519 519
520 switch (category) 520 switch (category)
521 { 521 {
522 //US I create my private category (=1) to set the settings 522 //US I create my private category (=1) to set the settings
523 case 1: 523 case 1:
524 d->dragDelay = 2; 524 d->dragDelay = 2;
525 //US set explicitly d->bUseSingle = KGlobalSettings::singleClick(); 525 //US set explicitly d->bUseSingle = KGlobalSettings::singleClick();
526 qDebug("KListView::slotSettingsChanged: single%i", d->bUseSingle); 526 // qDebug("KListView::slotSettingsChanged: single%i", d->bUseSingle);
527 527
528 disconnect(this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), 528 disconnect(this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)),
529 this, SLOT (slotMouseButtonClicked (int, QListViewItem*, const QPoint &, int))); 529 this, SLOT (slotMouseButtonClicked (int, QListViewItem*, const QPoint &, int)));
530 530
531 if( d->bUseSingle ) 531 if( d->bUseSingle )
532 connect (this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), 532 connect (this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)),
533 this, SLOT (slotMouseButtonClicked( int, QListViewItem*, const QPoint &, int))); 533 this, SLOT (slotMouseButtonClicked( int, QListViewItem*, const QPoint &, int)));
534 534
535 //US d->bChangeCursorOverItem = KGlobalSettings::changeCursorOverIcon(); 535 //US d->bChangeCursorOverItem = KGlobalSettings::changeCursorOverIcon();
536 //US d->autoSelectDelay = KGlobalSettings::autoSelectDelay(); 536 //US d->autoSelectDelay = KGlobalSettings::autoSelectDelay();
537 537
538 if( !d->bUseSingle || !d->bChangeCursorOverItem ) 538 if( !d->bUseSingle || !d->bChangeCursorOverItem )
539 viewport()->unsetCursor(); 539 viewport()->unsetCursor();
540 540
541 break; 541 break;
542 542
543 /*US 543 /*US
544 case KApplication::SETTINGS_MOUSE: 544 case KApplication::SETTINGS_MOUSE:
545 d->dragDelay = KGlobalSettings::dndEventDelay(); 545 d->dragDelay = KGlobalSettings::dndEventDelay();
546 d->bUseSingle = KGlobalSettings::singleClick(); 546 d->bUseSingle = KGlobalSettings::singleClick();
547 547
548 disconnect(this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), 548 disconnect(this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)),
549 this, SLOT (slotMouseButtonClicked (int, QListViewItem*, const QPoint &, int))); 549 this, SLOT (slotMouseButtonClicked (int, QListViewItem*, const QPoint &, int)));
550 550
551 if( d->bUseSingle ) 551 if( d->bUseSingle )
552 connect (this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), 552 connect (this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)),
553 this, SLOT (slotMouseButtonClicked( int, QListViewItem*, const QPoint &, int))); 553 this, SLOT (slotMouseButtonClicked( int, QListViewItem*, const QPoint &, int)));
554 554
555 d->bChangeCursorOverItem = KGlobalSettings::changeCursorOverIcon(); 555 d->bChangeCursorOverItem = KGlobalSettings::changeCursorOverIcon();
556 d->autoSelectDelay = KGlobalSettings::autoSelectDelay(); 556 d->autoSelectDelay = KGlobalSettings::autoSelectDelay();
557 557
558 if( !d->bUseSingle || !d->bChangeCursorOverItem ) 558 if( !d->bUseSingle || !d->bChangeCursorOverItem )
559 viewport()->unsetCursor(); 559 viewport()->unsetCursor();
560 560
561 break; 561 break;
562 case KApplication::SETTINGS_POPUPMENU: 562 case KApplication::SETTINGS_POPUPMENU:
563 d->contextMenuKey = KGlobalSettings::contextMenuKey (); 563 d->contextMenuKey = KGlobalSettings::contextMenuKey ();
564 d->showContextMenusOnPress = KGlobalSettings::showContextMenusOnPress (); 564 d->showContextMenusOnPress = KGlobalSettings::showContextMenusOnPress ();
565 565
566 if (d->showContextMenusOnPress) 566 if (d->showContextMenusOnPress)
567 { 567 {
568 disconnect (0L, 0L, this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); 568 disconnect (0L, 0L, this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int)));
569 569
570 connect(this, SIGNAL (rightButtonPressed (QListViewItem*, const QPoint&, int)), 570 connect(this, SIGNAL (rightButtonPressed (QListViewItem*, const QPoint&, int)),
571 this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); 571 this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int)));
572 } 572 }
573 else 573 else
574 { 574 {
575 disconnect (0L, 0L, this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); 575 disconnect (0L, 0L, this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int)));
576 576
577 connect(this, SIGNAL (rightButtonClicked (QListViewItem*, const QPoint&, int)), 577 connect(this, SIGNAL (rightButtonClicked (QListViewItem*, const QPoint&, int)),
578 this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); 578 this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int)));
579 } 579 }
580 break; 580 break;
581 */ 581 */
582 582
583 default: 583 default:
584 break; 584 break;
585 } 585 }
586 586
587} 587}
588 588
589void KListView::slotAutoSelect() 589void KListView::slotAutoSelect()
590{ 590{
591 // check that the item still exists 591 // check that the item still exists
592 if( itemIndex( d->pCurrentItem ) == -1 ) 592 if( itemIndex( d->pCurrentItem ) == -1 )
593 return; 593 return;
594 594
595 if (!isActiveWindow()) 595 if (!isActiveWindow())
596 { 596 {
597 d->autoSelect.stop(); 597 d->autoSelect.stop();
598 return; 598 return;
599 } 599 }
600 600
601 //Give this widget the keyboard focus. 601 //Give this widget the keyboard focus.
602 if( !hasFocus() ) 602 if( !hasFocus() )
603 setFocus(); 603 setFocus();
604 604
605 QListViewItem* previousItem = currentItem(); 605 QListViewItem* previousItem = currentItem();
606 setCurrentItem( d->pCurrentItem ); 606 setCurrentItem( d->pCurrentItem );
607 607
608#if 0 608#if 0
609#ifndef Q_WS_QWS 609#ifndef Q_WS_QWS
610 // FIXME(E): Implement for Qt Embedded 610 // FIXME(E): Implement for Qt Embedded
611 if( d->pCurrentItem ) { 611 if( d->pCurrentItem ) {
612 //Shift pressed? 612 //Shift pressed?
613 if( (keybstate & ShiftMask) ) { 613 if( (keybstate & ShiftMask) ) {
614 bool block = signalsBlocked(); 614 bool block = signalsBlocked();
615 blockSignals( true ); 615 blockSignals( true );
616 616
617 //No Ctrl? Then clear before! 617 //No Ctrl? Then clear before!
618 if( !(keybstate & ControlMask) ) 618 if( !(keybstate & ControlMask) )
619 clearSelection(); 619 clearSelection();
620 620
621 bool select = !d->pCurrentItem->isSelected(); 621 bool select = !d->pCurrentItem->isSelected();
622 bool update = viewport()->isUpdatesEnabled(); 622 bool update = viewport()->isUpdatesEnabled();
623 viewport()->setUpdatesEnabled( false ); 623 viewport()->setUpdatesEnabled( false );
624 624
625 bool down = previousItem->itemPos() < d->pCurrentItem->itemPos(); 625 bool down = previousItem->itemPos() < d->pCurrentItem->itemPos();
626 QListViewItemIterator lit( down ? previousItem : d->pCurrentItem ); 626 QListViewItemIterator lit( down ? previousItem : d->pCurrentItem );
627 for ( ; lit.current(); ++lit ) { 627 for ( ; lit.current(); ++lit ) {
628 if ( down && lit.current() == d->pCurrentItem ) { 628 if ( down && lit.current() == d->pCurrentItem ) {
629 d->pCurrentItem->setSelected( select ); 629 d->pCurrentItem->setSelected( select );
630 break; 630 break;
631 } 631 }
632 if ( !down && lit.current() == previousItem ) { 632 if ( !down && lit.current() == previousItem ) {
633 previousItem->setSelected( select ); 633 previousItem->setSelected( select );
634 break; 634 break;
635 } 635 }
636 lit.current()->setSelected( select ); 636 lit.current()->setSelected( select );
637 } 637 }
638 638
639 blockSignals( block ); 639 blockSignals( block );
640 viewport()->setUpdatesEnabled( update ); 640 viewport()->setUpdatesEnabled( update );
641 triggerUpdate(); 641 triggerUpdate();
642 642
643 emit selectionChanged(); 643 emit selectionChanged();
644 644
645 if( selectionMode() == QListView::Single ) 645 if( selectionMode() == QListView::Single )
646 emit selectionChanged( d->pCurrentItem ); 646 emit selectionChanged( d->pCurrentItem );
647 } 647 }
648 else if( (keybstate & ControlMask) ) 648 else if( (keybstate & ControlMask) )
649 setSelected( d->pCurrentItem, !d->pCurrentItem->isSelected() ); 649 setSelected( d->pCurrentItem, !d->pCurrentItem->isSelected() );
650 else { 650 else {
651 bool block = signalsBlocked(); 651 bool block = signalsBlocked();
652 blockSignals( true ); 652 blockSignals( true );
653 653
654 if( !d->pCurrentItem->isSelected() ) 654 if( !d->pCurrentItem->isSelected() )
655 clearSelection(); 655 clearSelection();
656 656
657 blockSignals( block ); 657 blockSignals( block );
658 658
659 setSelected( d->pCurrentItem, true ); 659 setSelected( d->pCurrentItem, true );
660 } 660 }
661 } 661 }
662 else 662 else
663 kdDebug() << "KListView::slotAutoSelect: Thats not supposed to happen!!!!" << endl; 663 kdDebug() << "KListView::slotAutoSelect: Thats not supposed to happen!!!!" << endl;
664#endif 664#endif
665#endif 665#endif
666} 666}
667 667
668void KListView::slotHeaderChanged() 668void KListView::slotHeaderChanged()
669{ 669{
670 if (d->fullWidth && columns()) 670 if (d->fullWidth && columns())
671 { 671 {
672 int w = 0; 672 int w = 0;
673 for (int i = 0; i < columns() - 1; ++i) w += columnWidth(i); 673 for (int i = 0; i < columns() - 1; ++i) w += columnWidth(i);
674 setColumnWidth( columns() - 1, viewport()->width() - w - 1 ); 674 setColumnWidth( columns() - 1, viewport()->width() - w - 1 );
675 } 675 }
676} 676}
677 677
678void KListView::emitExecute( int buttonstate, QListViewItem *item, const QPoint &pos, int c) 678void KListView::emitExecute( int buttonstate, QListViewItem *item, const QPoint &pos, int c)
679{ 679{
680 // qDebug("KListView::emitExecute buttonstate=%i", buttonstate); 680 // qDebug("KListView::emitExecute buttonstate=%i", buttonstate);
681 if( isExecuteArea( viewport()->mapFromGlobal(pos) ) ) { 681 if( isExecuteArea( viewport()->mapFromGlobal(pos) ) ) {
682 682
683 // Double click mode ? 683 // Double click mode ?
684 if ( !d->bUseSingle ) 684 if ( !d->bUseSingle )
685 { 685 {
686 emit executed( item ); 686 emit executed( item );
687 emit executed( item, pos, c ); 687 emit executed( item, pos, c );
688 } 688 }
689 else 689 else
690 { 690 {
691 //US special implementation for embedded systems 691 //US special implementation for embedded systems
692 d->autoSelect.stop(); 692 d->autoSelect.stop();
693 693
694 //Dont emit executed if in SC mode and Shift or Ctrl are pressed 694 //Dont emit executed if in SC mode and Shift or Ctrl are pressed
695 if( !( (buttonstate==ShiftButton) || (buttonstate==ControlButton) )) { 695 if( !( (buttonstate==ShiftButton) || (buttonstate==ControlButton) )) {
696 // if( !( ((keybstate & ShiftMask) || (keybstate & ControlMask)) ) ) { 696 // if( !( ((keybstate & ShiftMask) || (keybstate & ControlMask)) ) ) {
697 697
698 emit executed( item ); 698 emit executed( item );
699 emit executed( item, pos, c ); 699 emit executed( item, pos, c );
700 } 700 }
701 } 701 }
702 } 702 }
703} 703}
704 704
705void KListView::focusInEvent( QFocusEvent *fe ) 705void KListView::focusInEvent( QFocusEvent *fe )
706{ 706{
707 // kdDebug()<<"KListView::focusInEvent()"<<endl; 707 // kdDebug()<<"KListView::focusInEvent()"<<endl;
708 QListView::focusInEvent( fe ); 708 QListView::focusInEvent( fe );
709 if ((d->selectedBySimpleMove) 709 if ((d->selectedBySimpleMove)
710 && (d->selectionMode == FileManager) 710 && (d->selectionMode == FileManager)
711 && (fe->reason()!=QFocusEvent::Popup) 711 && (fe->reason()!=QFocusEvent::Popup)
712 && (fe->reason()!=QFocusEvent::ActiveWindow) 712 && (fe->reason()!=QFocusEvent::ActiveWindow)
713 && (currentItem()!=0)) 713 && (currentItem()!=0))
714 { 714 {
715 currentItem()->setSelected(true); 715 currentItem()->setSelected(true);
716 currentItem()->repaint(); 716 currentItem()->repaint();
717 emit selectionChanged(); 717 emit selectionChanged();
718 }; 718 };
719} 719}
720 720
721void KListView::focusOutEvent( QFocusEvent *fe ) 721void KListView::focusOutEvent( QFocusEvent *fe )
722{ 722{
723 cleanDropVisualizer(); 723 cleanDropVisualizer();
724 cleanItemHighlighter(); 724 cleanItemHighlighter();
725 725
726 d->autoSelect.stop(); 726 d->autoSelect.stop();
727 727
728 if ((d->selectedBySimpleMove) 728 if ((d->selectedBySimpleMove)
729 && (d->selectionMode == FileManager) 729 && (d->selectionMode == FileManager)
730 && (fe->reason()!=QFocusEvent::Popup) 730 && (fe->reason()!=QFocusEvent::Popup)
731 && (fe->reason()!=QFocusEvent::ActiveWindow) 731 && (fe->reason()!=QFocusEvent::ActiveWindow)
732 && (currentItem()!=0) 732 && (currentItem()!=0)
733/*US && (!d->editor->isVisible()) */ 733/*US && (!d->editor->isVisible()) */
734 ) 734 )
735 { 735 {
736 currentItem()->setSelected(false); 736 currentItem()->setSelected(false);
737 currentItem()->repaint(); 737 currentItem()->repaint();
738 emit selectionChanged(); 738 emit selectionChanged();
739 }; 739 };
740 740
741 QListView::focusOutEvent( fe ); 741 QListView::focusOutEvent( fe );
742} 742}
743 743
744void KListView::leaveEvent( QEvent *e ) 744void KListView::leaveEvent( QEvent *e )
745{ 745{
746 d->autoSelect.stop(); 746 d->autoSelect.stop();
747 747
748 QListView::leaveEvent( e ); 748 QListView::leaveEvent( e );
749} 749}
750 750
751bool KListView::event( QEvent *e ) 751bool KListView::event( QEvent *e )
752{ 752{
753 if (e->type() == QEvent::ApplicationPaletteChange) { 753 if (e->type() == QEvent::ApplicationPaletteChange) {
754 //qDebug("KListView::event make alternate color configurable"); 754 //qDebug("KListView::event make alternate color configurable");
755//US d->alternateBackground=KGlobalSettings::alternateBackgroundColor(); 755//US d->alternateBackground=KGlobalSettings::alternateBackgroundColor();
756 d->alternateBackground = QColor(240, 240, 240); 756 d->alternateBackground = QColor(240, 240, 240);
757 } 757 }
758 758
759 return QListView::event(e); 759 return QListView::event(e);
760} 760}
761 761
762void KListView::contentsMousePressEvent( QMouseEvent *e ) 762void KListView::contentsMousePressEvent( QMouseEvent *e )
763{ 763{
764 //qDebug("KListView::contentsMousePressEvent"); 764 //qDebug("KListView::contentsMousePressEvent");
765 if( (selectionModeExt() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) ) 765 if( (selectionModeExt() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) )
766 { 766 {
767 bool block = signalsBlocked(); 767 bool block = signalsBlocked();
768 blockSignals( true ); 768 blockSignals( true );
769 769
770 clearSelection(); 770 clearSelection();
771 771
772 blockSignals( block ); 772 blockSignals( block );
773 } 773 }
774 else if ((selectionModeExt()==FileManager) && (d->selectedBySimpleMove)) 774 else if ((selectionModeExt()==FileManager) && (d->selectedBySimpleMove))
775 { 775 {
776 d->selectedBySimpleMove=false; 776 d->selectedBySimpleMove=false;
777 d->selectedUsingMouse=true; 777 d->selectedUsingMouse=true;
778 if (currentItem()!=0) 778 if (currentItem()!=0)
779 { 779 {
780 currentItem()->setSelected(false); 780 currentItem()->setSelected(false);
781 currentItem()->repaint(); 781 currentItem()->repaint();
782// emit selectionChanged(); 782// emit selectionChanged();
783 }; 783 };
784 }; 784 };
785 785
786 QPoint p( contentsToViewport( e->pos() ) ); 786 QPoint p( contentsToViewport( e->pos() ) );
787 QListViewItem *at = itemAt (p); 787 QListViewItem *at = itemAt (p);
788 788
789 // true if the root decoration of the item "at" was clicked (i.e. the +/- sign) 789 // true if the root decoration of the item "at" was clicked (i.e. the +/- sign)
790 bool rootDecoClicked = at 790 bool rootDecoClicked = at
791 && ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) + 791 && ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) +
792 treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ) 792 treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() )
793 && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) ); 793 && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) );
794 794
795 if (e->button() == LeftButton && !rootDecoClicked) 795 if (e->button() == LeftButton && !rootDecoClicked)
796 { 796 {
797 //Start a drag 797 //Start a drag
798 d->startDragPos = e->pos(); 798 d->startDragPos = e->pos();
799 799
800 if (at) 800 if (at)
801 { 801 {
802 d->validDrag = true; 802 d->validDrag = true;
803 d->pressedOnSelected = at->isSelected(); 803 d->pressedOnSelected = at->isSelected();
804 } 804 }
805 } 805 }
806 806
807 QListView::contentsMousePressEvent( e ); 807 QListView::contentsMousePressEvent( e );
808} 808}
809 809
810void KListView::contentsMouseMoveEvent( QMouseEvent *e ) 810void KListView::contentsMouseMoveEvent( QMouseEvent *e )
811{ 811{
812 if (!dragEnabled() || d->startDragPos.isNull() || !d->validDrag) { 812 if (!dragEnabled() || d->startDragPos.isNull() || !d->validDrag) {
813 QListView::contentsMouseMoveEvent (e); 813 QListView::contentsMouseMoveEvent (e);
814 return; 814 return;
815 } 815 }
816 816
817 QPoint vp = contentsToViewport(e->pos()); 817 QPoint vp = contentsToViewport(e->pos());
818 QListViewItem *item = itemAt( vp ); 818 QListViewItem *item = itemAt( vp );
819 819
820 //do we process cursor changes at all? 820 //do we process cursor changes at all?
821 if ( item && d->bChangeCursorOverItem && d->bUseSingle ) 821 if ( item && d->bChangeCursorOverItem && d->bUseSingle )
822 { 822 {
823 //Cursor moved on a new item or in/out the execute area 823 //Cursor moved on a new item or in/out the execute area
824 if( (item != d->pCurrentItem) || 824 if( (item != d->pCurrentItem) ||
825 (isExecuteArea(vp) != d->cursorInExecuteArea) ) 825 (isExecuteArea(vp) != d->cursorInExecuteArea) )
826 { 826 {
827 d->cursorInExecuteArea = isExecuteArea(vp); 827 d->cursorInExecuteArea = isExecuteArea(vp);
828 //qDebug("KListView::contentsMouseMoveEvent drag&drop not supported yet"); 828 //qDebug("KListView::contentsMouseMoveEvent drag&drop not supported yet");
829/*US 829/*US
830 if( d->cursorInExecuteArea ) //cursor moved in execute area 830 if( d->cursorInExecuteArea ) //cursor moved in execute area
831 viewport()->setCursor( KCursor::handCursor() ); 831 viewport()->setCursor( KCursor::handCursor() );
832 else //cursor moved out of execute area 832 else //cursor moved out of execute area
833 viewport()->unsetCursor(); 833 viewport()->unsetCursor();
834*/ 834*/
835 } 835 }
836 } 836 }
837 837
838 bool dragOn = dragEnabled(); 838 bool dragOn = dragEnabled();
839 QPoint newPos = e->pos(); 839 QPoint newPos = e->pos();
840 if (dragOn && d->validDrag && 840 if (dragOn && d->validDrag &&
841 (newPos.x() > d->startDragPos.x()+d->dragDelay || 841 (newPos.x() > d->startDragPos.x()+d->dragDelay ||
842 newPos.x() < d->startDragPos.x()-d->dragDelay || 842 newPos.x() < d->startDragPos.x()-d->dragDelay ||
843 newPos.y() > d->startDragPos.y()+d->dragDelay || 843 newPos.y() > d->startDragPos.y()+d->dragDelay ||
844 newPos.y() < d->startDragPos.y()-d->dragDelay)) 844 newPos.y() < d->startDragPos.y()-d->dragDelay))
845 //(d->startDragPos - e->pos()).manhattanLength() > QApplication::startDragDistance()) 845 //(d->startDragPos - e->pos()).manhattanLength() > QApplication::startDragDistance())
846 { 846 {
847 QListView::contentsMouseReleaseEvent( 0 ); 847 QListView::contentsMouseReleaseEvent( 0 );
848 startDrag(); 848 startDrag();
849 d->startDragPos = QPoint(); 849 d->startDragPos = QPoint();
850 d->validDrag = false; 850 d->validDrag = false;
851 } 851 }
852} 852}
853 853
854void KListView::contentsMouseReleaseEvent( QMouseEvent *e ) 854void KListView::contentsMouseReleaseEvent( QMouseEvent *e )
855{ 855{
856 if (e->button() == LeftButton) 856 if (e->button() == LeftButton)
857 { 857 {
858 // If the row was already selected, maybe we want to start an in-place editing 858 // If the row was already selected, maybe we want to start an in-place editing
859 if ( d->pressedOnSelected && itemsRenameable() ) 859 if ( d->pressedOnSelected && itemsRenameable() )
860 { 860 {
861 QPoint p( contentsToViewport( e->pos() ) ); 861 QPoint p( contentsToViewport( e->pos() ) );
862 QListViewItem *at = itemAt (p); 862 QListViewItem *at = itemAt (p);
863 if ( at ) 863 if ( at )
864 { 864 {
865 // true if the root decoration of the item "at" was clicked (i.e. the +/- sign) 865 // true if the root decoration of the item "at" was clicked (i.e. the +/- sign)
866 bool rootDecoClicked = 866 bool rootDecoClicked =
867 ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) + 867 ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) +
868 treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ) 868 treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() )
869 && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) ); 869 && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) );
870 870
871 if (!rootDecoClicked) 871 if (!rootDecoClicked)
872 { 872 {
873 int col = header()->mapToLogical( header()->cellAt( p.x() ) ); 873 int col = header()->mapToLogical( header()->cellAt( p.x() ) );
874 if ( d->renameable.contains(col) ) 874 if ( d->renameable.contains(col) )
875 rename(at, col); 875 rename(at, col);
876 } 876 }
877 } 877 }
878 } 878 }
879 879
880 d->pressedOnSelected = false; 880 d->pressedOnSelected = false;
881 d->validDrag = false; 881 d->validDrag = false;
882 d->startDragPos = QPoint(); 882 d->startDragPos = QPoint();
883 } 883 }
884 QListView::contentsMouseReleaseEvent( e ); 884 QListView::contentsMouseReleaseEvent( e );
885} 885}
886 886
887void KListView::contentsMouseDoubleClickEvent ( QMouseEvent *e ) 887void KListView::contentsMouseDoubleClickEvent ( QMouseEvent *e )
888{ 888{
889 //qDebug("KListView::contentsMouseDoubleClickEvent"); 889 //qDebug("KListView::contentsMouseDoubleClickEvent");
890 // We don't want to call the parent method because it does setOpen, 890 // We don't want to call the parent method because it does setOpen,
891 // whereas we don't do it in single click mode... (David) 891 // whereas we don't do it in single click mode... (David)
892 //QListView::contentsMouseDoubleClickEvent( e ); 892 //QListView::contentsMouseDoubleClickEvent( e );
893 893
894 QPoint vp = contentsToViewport(e->pos()); 894 QPoint vp = contentsToViewport(e->pos());
895 QListViewItem *item = itemAt( vp ); 895 QListViewItem *item = itemAt( vp );
896 emit QListView::doubleClicked( item ); // we do it now 896 emit QListView::doubleClicked( item ); // we do it now
897 897
898 int col = item ? header()->mapToLogical( header()->cellAt( vp.x() ) ) : -1; 898 int col = item ? header()->mapToLogical( header()->cellAt( vp.x() ) ) : -1;
899 899
900 if( item ) { 900 if( item ) {
901 //qDebug("KListView::contentsMouseDoubleClickEvent: emit doubleClicked"); 901 //qDebug("KListView::contentsMouseDoubleClickEvent: emit doubleClicked");
902 902
903 emit doubleClicked( item, e->globalPos(), col ); 903 emit doubleClicked( item, e->globalPos(), col );
904 904
905 if( (e->button() == LeftButton) && !d->bUseSingle ) { 905 if( (e->button() == LeftButton) && !d->bUseSingle ) {
906 //qDebug("KListView::contentsMouseDoubleClickEvent: emitExecute"); 906 //qDebug("KListView::contentsMouseDoubleClickEvent: emitExecute");
907 907
908 emitExecute( e->button(), item, e->globalPos(), col); 908 emitExecute( e->button(), item, e->globalPos(), col);
909 } 909 }
910 } 910 }
911} 911}
912 912
913void KListView::slotMouseButtonClicked( int btn, QListViewItem *item, const QPoint &pos, int c ) 913void KListView::slotMouseButtonClicked( int btn, QListViewItem *item, const QPoint &pos, int c )
914{ 914{
915 //qDebug("KListView::slotMouseButtonClicked"); 915 //qDebug("KListView::slotMouseButtonClicked");
916 916
917 if( (btn == LeftButton) && item ) { 917 if( (btn == LeftButton) && item ) {
918 //qDebug("KListView::slotMouseButtonClicked: emitExecute"); 918 //qDebug("KListView::slotMouseButtonClicked: emitExecute");
919 919
920 emitExecute(btn, item, pos, c); 920 emitExecute(btn, item, pos, c);
921 } 921 }
922} 922}
923 923
924void KListView::contentsDropEvent(QDropEvent* e) 924void KListView::contentsDropEvent(QDropEvent* e)
925{ 925{
926qDebug("KListView::contentsDropEvent drag&drop not supported yet"); 926qDebug("KListView::contentsDropEvent drag&drop not supported yet");
927/*US 927/*US
928 cleanDropVisualizer(); 928 cleanDropVisualizer();
929 cleanItemHighlighter(); 929 cleanItemHighlighter();
930 d->dragExpand.stop(); 930 d->dragExpand.stop();
931 931
932 if (acceptDrag (e)) 932 if (acceptDrag (e))
933 { 933 {
934 e->acceptAction(); 934 e->acceptAction();
935 QListViewItem *afterme; 935 QListViewItem *afterme;
936 QListViewItem *parent; 936 QListViewItem *parent;
937 findDrop(e->pos(), parent, afterme); 937 findDrop(e->pos(), parent, afterme);
938 938
939 if (e->source() == viewport() && itemsMovable()) 939 if (e->source() == viewport() && itemsMovable())
940 movableDropEvent(parent, afterme); 940 movableDropEvent(parent, afterme);
941 else 941 else
942 { 942 {
943 943
944 emit dropped(e, afterme); 944 emit dropped(e, afterme);
945 emit dropped(this, e, afterme); 945 emit dropped(this, e, afterme);
946 emit dropped(e, parent, afterme); 946 emit dropped(e, parent, afterme);
947 emit dropped(this, e, parent, afterme); 947 emit dropped(this, e, parent, afterme);
948 948
949 } 949 }
950 } 950 }
951*/ 951*/
952 952
953} 953}
954 954
955void KListView::movableDropEvent (QListViewItem* parent, QListViewItem* afterme) 955void KListView::movableDropEvent (QListViewItem* parent, QListViewItem* afterme)
956{ 956{
957 QPtrList<QListViewItem> items, afterFirsts, afterNows; 957 QPtrList<QListViewItem> items, afterFirsts, afterNows;
958 QListViewItem *current=currentItem(); 958 QListViewItem *current=currentItem();
959 bool hasMoved=false; 959 bool hasMoved=false;
960 for (QListViewItem *i = firstChild(), *iNext=0; i != 0; i = iNext) 960 for (QListViewItem *i = firstChild(), *iNext=0; i != 0; i = iNext)
961 { 961 {
962 iNext=i->itemBelow(); 962 iNext=i->itemBelow();
963 if (!i->isSelected()) 963 if (!i->isSelected())
964 continue; 964 continue;
965 965
966 // don't drop an item after itself, or else 966 // don't drop an item after itself, or else
967 // it moves to the top of the list 967 // it moves to the top of the list
968 if (i==afterme) 968 if (i==afterme)
969 continue; 969 continue;
970 970
971 i->setSelected(false); 971 i->setSelected(false);
972 972
973 QListViewItem *afterFirst = i->itemAbove(); 973 QListViewItem *afterFirst = i->itemAbove();
974 974
975 if (!hasMoved) 975 if (!hasMoved)
976 { 976 {
977 emit aboutToMove(); 977 emit aboutToMove();
978 hasMoved=true; 978 hasMoved=true;
979 } 979 }
980 980
981 moveItem(i, parent, afterme); 981 moveItem(i, parent, afterme);
982 982
983 // ###### This should include the new parent !!! -> KDE 3.0 983 // ###### This should include the new parent !!! -> KDE 3.0
984 // If you need this right now, have a look at keditbookmarks. 984 // If you need this right now, have a look at keditbookmarks.
985 emit moved(i, afterFirst, afterme); 985 emit moved(i, afterFirst, afterme);
986 986
987 items.append (i); 987 items.append (i);
988 afterFirsts.append (afterFirst); 988 afterFirsts.append (afterFirst);
989 afterNows.append (afterme); 989 afterNows.append (afterme);
990 990
991 afterme = i; 991 afterme = i;
992 } 992 }
993 clearSelection(); 993 clearSelection();
994 for (QListViewItem *i=items.first(); i != 0; i=items.next() ) 994 for (QListViewItem *i=items.first(); i != 0; i=items.next() )
995 i->setSelected(true); 995 i->setSelected(true);
996 if (current) 996 if (current)
997 setCurrentItem(current); 997 setCurrentItem(current);
998 998
999 emit moved(items,afterFirsts,afterNows); 999 emit moved(items,afterFirsts,afterNows);
1000 1000
1001 if (firstChild()) 1001 if (firstChild())
1002 emit moved(); 1002 emit moved();
1003} 1003}
1004 1004
1005void KListView::contentsDragMoveEvent(QDragMoveEvent *event) 1005void KListView::contentsDragMoveEvent(QDragMoveEvent *event)
1006{ 1006{
1007 qDebug("KListView::contentsDropEvent drag&drop not supported yet"); 1007 qDebug("KListView::contentsDropEvent drag&drop not supported yet");
1008/*US 1008/*US
1009 if (acceptDrag(event)) 1009 if (acceptDrag(event))
1010 { 1010 {
1011 event->acceptAction(); 1011 event->acceptAction();
1012 //Clean up the view 1012 //Clean up the view
1013 1013
1014 findDrop(event->pos(), d->parentItemDrop, d->afterItemDrop); 1014 findDrop(event->pos(), d->parentItemDrop, d->afterItemDrop);
1015 QPoint vp = contentsToViewport( event->pos() ); 1015 QPoint vp = contentsToViewport( event->pos() );
1016 QListViewItem *item = isExecuteArea( vp ) ? itemAt( vp ) : 0L; 1016 QListViewItem *item = isExecuteArea( vp ) ? itemAt( vp ) : 0L;
1017 1017
1018 if ( item != d->dragOverItem ) 1018 if ( item != d->dragOverItem )
1019 { 1019 {
1020 d->dragExpand.stop(); 1020 d->dragExpand.stop();
1021 d->dragOverItem = item; 1021 d->dragOverItem = item;
1022 d->dragOverPoint = vp; 1022 d->dragOverPoint = vp;
1023 if ( d->dragOverItem && d->dragOverItem->isExpandable() && !d->dragOverItem->isOpen() ) 1023 if ( d->dragOverItem && d->dragOverItem->isExpandable() && !d->dragOverItem->isOpen() )
1024 d->dragExpand.start( QApplication::startDragTime(), true ); 1024 d->dragExpand.start( QApplication::startDragTime(), true );
1025 } 1025 }
1026 if (dropVisualizer()) 1026 if (dropVisualizer())
1027 { 1027 {
1028 QRect tmpRect = drawDropVisualizer(0, d->parentItemDrop, d->afterItemDrop); 1028 QRect tmpRect = drawDropVisualizer(0, d->parentItemDrop, d->afterItemDrop);
1029 if (tmpRect != d->mOldDropVisualizer) 1029 if (tmpRect != d->mOldDropVisualizer)
1030 { 1030 {
1031 cleanDropVisualizer(); 1031 cleanDropVisualizer();
1032 d->mOldDropVisualizer=tmpRect; 1032 d->mOldDropVisualizer=tmpRect;
1033 viewport()->repaint(tmpRect); 1033 viewport()->repaint(tmpRect);
1034 } 1034 }
1035 } 1035 }
1036 if (dropHighlighter()) 1036 if (dropHighlighter())
1037 { 1037 {
1038 QRect tmpRect = drawItemHighlighter(0, d->afterItemDrop); 1038 QRect tmpRect = drawItemHighlighter(0, d->afterItemDrop);
1039 if (tmpRect != d->mOldDropHighlighter) 1039 if (tmpRect != d->mOldDropHighlighter)
1040 { 1040 {
1041 cleanItemHighlighter(); 1041 cleanItemHighlighter();
1042 d->mOldDropHighlighter=tmpRect; 1042 d->mOldDropHighlighter=tmpRect;
1043 viewport()->repaint(tmpRect); 1043 viewport()->repaint(tmpRect);
1044 } 1044 }
1045 } 1045 }
1046 } 1046 }
1047 else 1047 else
1048 event->ignore(); 1048 event->ignore();
1049*/ 1049*/
1050} 1050}
1051 1051
1052void KListView::slotDragExpand() 1052void KListView::slotDragExpand()
1053{ 1053{
1054 if ( itemAt( d->dragOverPoint ) == d->dragOverItem ) 1054 if ( itemAt( d->dragOverPoint ) == d->dragOverItem )
1055 d->dragOverItem->setOpen( true ); 1055 d->dragOverItem->setOpen( true );
1056} 1056}
1057 1057
1058void KListView::contentsDragLeaveEvent (QDragLeaveEvent*) 1058void KListView::contentsDragLeaveEvent (QDragLeaveEvent*)
1059{ 1059{
1060 d->dragExpand.stop(); 1060 d->dragExpand.stop();
1061 cleanDropVisualizer(); 1061 cleanDropVisualizer();
1062 cleanItemHighlighter(); 1062 cleanItemHighlighter();
1063} 1063}
1064 1064
1065void KListView::cleanDropVisualizer() 1065void KListView::cleanDropVisualizer()
1066{ 1066{
1067 if (d->mOldDropVisualizer.isValid()) 1067 if (d->mOldDropVisualizer.isValid())
1068 { 1068 {
1069 QRect rect=d->mOldDropVisualizer; 1069 QRect rect=d->mOldDropVisualizer;
1070 d->mOldDropVisualizer = QRect(); 1070 d->mOldDropVisualizer = QRect();
1071 viewport()->repaint(rect, true); 1071 viewport()->repaint(rect, true);
1072 } 1072 }
1073} 1073}
1074 1074
1075int KListView::depthToPixels( int depth ) 1075int KListView::depthToPixels( int depth )
1076{ 1076{
1077 return treeStepSize() * ( depth + (rootIsDecorated() ? 1 : 0) ) + itemMargin(); 1077 return treeStepSize() * ( depth + (rootIsDecorated() ? 1 : 0) ) + itemMargin();
1078} 1078}
1079 1079
1080void KListView::findDrop(const QPoint &pos, QListViewItem *&parent, QListViewItem *&after) 1080void KListView::findDrop(const QPoint &pos, QListViewItem *&parent, QListViewItem *&after)
1081{ 1081{
1082 QPoint p (contentsToViewport(pos)); 1082 QPoint p (contentsToViewport(pos));
1083 1083
1084 // Get the position to put it in 1084 // Get the position to put it in
1085 QListViewItem *atpos = itemAt(p); 1085 QListViewItem *atpos = itemAt(p);
1086 1086
1087 QListViewItem *above; 1087 QListViewItem *above;
1088 if (!atpos) // put it at the end 1088 if (!atpos) // put it at the end
1089 above = lastItem(); 1089 above = lastItem();
1090 else 1090 else
1091 { 1091 {
1092 // Get the closest item before us ('atpos' or the one above, if any) 1092 // Get the closest item before us ('atpos' or the one above, if any)
1093 if (p.y() - itemRect(atpos).topLeft().y() < (atpos->height()/2)) 1093 if (p.y() - itemRect(atpos).topLeft().y() < (atpos->height()/2))
1094 above = atpos->itemAbove(); 1094 above = atpos->itemAbove();
1095 else 1095 else
1096 above = atpos; 1096 above = atpos;
1097 } 1097 }
1098 1098
1099 if (above) 1099 if (above)
1100 { 1100 {
1101 // Now, we know we want to go after "above". But as a child or as a sibling ? 1101 // Now, we know we want to go after "above". But as a child or as a sibling ?
1102 // We have to ask the "above" item if it accepts children. 1102 // We have to ask the "above" item if it accepts children.
1103 if (above->isExpandable()) 1103 if (above->isExpandable())
1104 { 1104 {
1105 // The mouse is sufficiently on the right ? - doesn't matter if 'above' has visible children 1105 // The mouse is sufficiently on the right ? - doesn't matter if 'above' has visible children
1106 if (p.x() >= depthToPixels( above->depth() + 1 ) || 1106 if (p.x() >= depthToPixels( above->depth() + 1 ) ||
1107 (above->isOpen() && above->childCount() > 0) ) 1107 (above->isOpen() && above->childCount() > 0) )
1108 { 1108 {
1109 parent = above; 1109 parent = above;
1110 after = 0L; 1110 after = 0L;
1111 return; 1111 return;
1112 } 1112 }
1113 } 1113 }
1114 1114
1115 // Ok, there's one more level of complexity. We may want to become a new 1115 // Ok, there's one more level of complexity. We may want to become a new
1116 // sibling, but of an upper-level group, rather than the "above" item 1116 // sibling, but of an upper-level group, rather than the "above" item
1117 QListViewItem * betterAbove = above->parent(); 1117 QListViewItem * betterAbove = above->parent();
1118 QListViewItem * last = above; 1118 QListViewItem * last = above;
1119 while ( betterAbove ) 1119 while ( betterAbove )
1120 { 1120 {
1121 // We are allowed to become a sibling of "betterAbove" only if we are 1121 // We are allowed to become a sibling of "betterAbove" only if we are
1122 // after its last child 1122 // after its last child
1123 if ( last->nextSibling() == 0 ) 1123 if ( last->nextSibling() == 0 )
1124 { 1124 {
1125 if (p.x() < depthToPixels ( betterAbove->depth() + 1 )) 1125 if (p.x() < depthToPixels ( betterAbove->depth() + 1 ))
1126 above = betterAbove; // store this one, but don't stop yet, there may be a better one 1126 above = betterAbove; // store this one, but don't stop yet, there may be a better one
1127 else 1127 else
1128 break; // not enough on the left, so stop 1128 break; // not enough on the left, so stop
1129 last = betterAbove; 1129 last = betterAbove;
1130 betterAbove = betterAbove->parent(); // up one level 1130 betterAbove = betterAbove->parent(); // up one level
1131 } else 1131 } else
1132 break; // we're among the child of betterAbove, not after the last one 1132 break; // we're among the child of betterAbove, not after the last one
1133 } 1133 }
1134 } 1134 }
1135 // set as sibling 1135 // set as sibling
1136 after = above; 1136 after = above;
1137 parent = after ? after->parent() : 0L ; 1137 parent = after ? after->parent() : 0L ;
1138} 1138}
1139 1139
1140QListViewItem* KListView::lastChild () const 1140QListViewItem* KListView::lastChild () const
1141{ 1141{
1142 QListViewItem* lastchild = firstChild(); 1142 QListViewItem* lastchild = firstChild();
1143 1143
1144 if (lastchild) 1144 if (lastchild)
1145 for (; lastchild->nextSibling(); lastchild = lastchild->nextSibling()); 1145 for (; lastchild->nextSibling(); lastchild = lastchild->nextSibling());
1146 1146
1147 return lastchild; 1147 return lastchild;
1148} 1148}
1149 1149
1150QListViewItem *KListView::lastItem() const 1150QListViewItem *KListView::lastItem() const
1151{ 1151{
1152 QListViewItem* last = lastChild(); 1152 QListViewItem* last = lastChild();
1153 1153
1154 for (QListViewItemIterator it (last); it.current(); ++it) 1154 for (QListViewItemIterator it (last); it.current(); ++it)
1155 last = it.current(); 1155 last = it.current();
1156 1156
1157 return last; 1157 return last;
1158} 1158}
1159 1159
1160KLineEdit *KListView::renameLineEdit() const 1160KLineEdit *KListView::renameLineEdit() const
1161{ 1161{
1162//US return d->editor; 1162//US return d->editor;
1163qDebug("KListView::renameLineEdit returns 0. Might crash"); 1163qDebug("KListView::renameLineEdit returns 0. Might crash");
1164return 0; 1164return 0;
1165} 1165}
1166 1166
1167void KListView::startDrag() 1167void KListView::startDrag()
1168{ 1168{
1169qDebug("KListView::startDrag drag&drop not supported yet."); 1169qDebug("KListView::startDrag drag&drop not supported yet.");
1170/*US 1170/*US
1171 QDragObject *drag = dragObject(); 1171 QDragObject *drag = dragObject();
1172 1172
1173 if (!drag) 1173 if (!drag)
1174 return; 1174 return;
1175 1175
1176 if (drag->drag() && drag->target() != viewport()) 1176 if (drag->drag() && drag->target() != viewport())
1177 emit moved(); 1177 emit moved();
1178*/ 1178*/
1179} 1179}
1180 1180
1181QDragObject *KListView::dragObject() 1181QDragObject *KListView::dragObject()
1182{ 1182{
1183 if (!currentItem()) 1183 if (!currentItem())
1184 return 0; 1184 return 0;
1185 1185
1186 return new QStoredDrag("application/x-qlistviewitem", viewport()); 1186 return new QStoredDrag("application/x-qlistviewitem", viewport());
1187} 1187}
1188 1188
1189void KListView::setItemsMovable(bool b) 1189void KListView::setItemsMovable(bool b)
1190{ 1190{
1191 d->itemsMovable=b; 1191 d->itemsMovable=b;
1192} 1192}
1193 1193
1194bool KListView::itemsMovable() const 1194bool KListView::itemsMovable() const
1195{ 1195{
1196 return d->itemsMovable; 1196 return d->itemsMovable;
1197} 1197}
1198 1198
1199void KListView::setItemsRenameable(bool b) 1199void KListView::setItemsRenameable(bool b)
1200{ 1200{
1201 d->itemsRenameable=b; 1201 d->itemsRenameable=b;
1202} 1202}
1203 1203
1204bool KListView::itemsRenameable() const 1204bool KListView::itemsRenameable() const
1205{ 1205{
1206 return d->itemsRenameable; 1206 return d->itemsRenameable;
1207} 1207}
1208 1208
1209 1209
1210void KListView::setDragEnabled(bool b) 1210void KListView::setDragEnabled(bool b)
1211{ 1211{
1212 d->dragEnabled=b; 1212 d->dragEnabled=b;
1213} 1213}
1214 1214
1215bool KListView::dragEnabled() const 1215bool KListView::dragEnabled() const
1216{ 1216{
1217 return d->dragEnabled; 1217 return d->dragEnabled;
1218} 1218}
1219 1219
1220void KListView::setAutoOpen(bool b) 1220void KListView::setAutoOpen(bool b)
1221{ 1221{
1222 d->autoOpen=b; 1222 d->autoOpen=b;
1223} 1223}
1224 1224
1225bool KListView::autoOpen() const 1225bool KListView::autoOpen() const
1226{ 1226{
1227 return d->autoOpen; 1227 return d->autoOpen;
1228} 1228}
1229 1229
1230bool KListView::dropVisualizer() const 1230bool KListView::dropVisualizer() const
1231{ 1231{
1232 return d->dropVisualizer; 1232 return d->dropVisualizer;
1233} 1233}
1234 1234
1235void KListView::setDropVisualizer(bool b) 1235void KListView::setDropVisualizer(bool b)
1236{ 1236{
1237 d->dropVisualizer=b; 1237 d->dropVisualizer=b;
1238} 1238}
1239 1239
1240QPtrList<QListViewItem> KListView::selectedItems() const 1240QPtrList<QListViewItem> KListView::selectedItems() const
1241{ 1241{
1242 QPtrList<QListViewItem> list; 1242 QPtrList<QListViewItem> list;
1243 for (QListViewItem *i=firstChild(); i!=0; i=i->itemBelow()) 1243 for (QListViewItem *i=firstChild(); i!=0; i=i->itemBelow())
1244 if (i->isSelected()) list.append(i); 1244 if (i->isSelected()) list.append(i);
1245 return list; 1245 return list;
1246} 1246}
1247 1247
1248 1248
1249void KListView::moveItem(QListViewItem *item, QListViewItem *parent, QListViewItem *after) 1249void KListView::moveItem(QListViewItem *item, QListViewItem *parent, QListViewItem *after)
1250{ 1250{
1251 // sanity check - don't move a item into it's own child structure 1251 // sanity check - don't move a item into it's own child structure
1252 QListViewItem *i = parent; 1252 QListViewItem *i = parent;
1253 while(i) 1253 while(i)
1254 { 1254 {
1255 if(i == item) 1255 if(i == item)
1256 return; 1256 return;
1257 i = i->parent(); 1257 i = i->parent();
1258 } 1258 }
1259 1259
1260 // Basically reimplementing the QListViewItem(QListViewItem*, QListViewItem*) constructor 1260 // Basically reimplementing the QListViewItem(QListViewItem*, QListViewItem*) constructor
1261 // in here, without ever deleting the item. 1261 // in here, without ever deleting the item.
1262 if (item->parent()) 1262 if (item->parent())
1263 item->parent()->takeItem(item); 1263 item->parent()->takeItem(item);
1264 else 1264 else
1265 takeItem(item); 1265 takeItem(item);
1266 1266
1267 if (parent) 1267 if (parent)
1268 parent->insertItem(item); 1268 parent->insertItem(item);
1269 else 1269 else
1270 insertItem(item); 1270 insertItem(item);
1271 1271
1272 if (after) 1272 if (after)
1273 ;//item->moveToJustAfter(after); 1273 ;//item->moveToJustAfter(after);
1274} 1274}
1275 1275
1276void KListView::contentsDragEnterEvent(QDragEnterEvent *event) 1276void KListView::contentsDragEnterEvent(QDragEnterEvent *event)
1277{ 1277{
1278qDebug("KListView::contentsDragEnterEvent drag&drop not supported yet."); 1278qDebug("KListView::contentsDragEnterEvent drag&drop not supported yet.");
1279/*US 1279/*US
1280 if (acceptDrag (event)) 1280 if (acceptDrag (event))
1281 event->accept(); 1281 event->accept();
1282*/ 1282*/
1283} 1283}
1284 1284
1285void KListView::setDropVisualizerWidth (int w) 1285void KListView::setDropVisualizerWidth (int w)
1286{ 1286{
1287 d->mDropVisualizerWidth = w > 0 ? w : 1; 1287 d->mDropVisualizerWidth = w > 0 ? w : 1;
1288} 1288}
1289 1289
1290QRect KListView::drawDropVisualizer(QPainter *p, QListViewItem *parent, 1290QRect KListView::drawDropVisualizer(QPainter *p, QListViewItem *parent,
1291 QListViewItem *after) 1291 QListViewItem *after)
1292{ 1292{
1293 QRect insertmarker; 1293 QRect insertmarker;
1294 1294
1295 if (!after && !parent) 1295 if (!after && !parent)
1296 insertmarker = QRect (0, 0, viewport()->width(), d->mDropVisualizerWidth/2); 1296 insertmarker = QRect (0, 0, viewport()->width(), d->mDropVisualizerWidth/2);
1297 else 1297 else
1298 { 1298 {
1299 int level = 0; 1299 int level = 0;
1300 if (after) 1300 if (after)
1301 { 1301 {
1302 QListViewItem* it = 0L; 1302 QListViewItem* it = 0L;
1303 if (after->isOpen()) 1303 if (after->isOpen())
1304 { 1304 {
1305 // Look for the last child (recursively) 1305 // Look for the last child (recursively)
1306 it = after->firstChild(); 1306 it = after->firstChild();
1307 if (it) 1307 if (it)
1308 while (it->nextSibling() || it->firstChild()) 1308 while (it->nextSibling() || it->firstChild())
1309 if ( it->nextSibling() ) 1309 if ( it->nextSibling() )
1310 it = it->nextSibling(); 1310 it = it->nextSibling();
1311 else 1311 else
1312 it = it->firstChild(); 1312 it = it->firstChild();
1313 } 1313 }
1314 1314
1315 insertmarker = itemRect (it ? it : after); 1315 insertmarker = itemRect (it ? it : after);
1316 level = after->depth(); 1316 level = after->depth();
1317 } 1317 }
1318 else if (parent) 1318 else if (parent)
1319 { 1319 {
1320 insertmarker = itemRect (parent); 1320 insertmarker = itemRect (parent);
1321 level = parent->depth() + 1; 1321 level = parent->depth() + 1;
1322 } 1322 }
1323 insertmarker.setLeft( treeStepSize() * ( level + (rootIsDecorated() ? 1 : 0) ) + itemMargin() ); 1323 insertmarker.setLeft( treeStepSize() * ( level + (rootIsDecorated() ? 1 : 0) ) + itemMargin() );
1324 insertmarker.setRight (viewport()->width()); 1324 insertmarker.setRight (viewport()->width());
1325 insertmarker.setTop (insertmarker.bottom() - d->mDropVisualizerWidth/2 + 1); 1325 insertmarker.setTop (insertmarker.bottom() - d->mDropVisualizerWidth/2 + 1);
1326 insertmarker.setBottom (insertmarker.bottom() + d->mDropVisualizerWidth/2); 1326 insertmarker.setBottom (insertmarker.bottom() + d->mDropVisualizerWidth/2);
1327 } 1327 }
1328 1328
1329 // This is not used anymore, at least by KListView itself (see viewportPaintEvent) 1329 // This is not used anymore, at least by KListView itself (see viewportPaintEvent)
1330 // Remove for KDE 3.0. 1330 // Remove for KDE 3.0.
1331 if (p) 1331 if (p)
1332 p->fillRect(insertmarker, Dense4Pattern); 1332 p->fillRect(insertmarker, Dense4Pattern);
1333 1333
1334 return insertmarker; 1334 return insertmarker;
1335} 1335}
1336 1336
1337QRect KListView::drawItemHighlighter(QPainter *painter, QListViewItem *item) 1337QRect KListView::drawItemHighlighter(QPainter *painter, QListViewItem *item)
1338{ 1338{
1339 QRect r; 1339 QRect r;
1340 1340
1341 if (item) 1341 if (item)
1342 { 1342 {
1343 r = itemRect(item); 1343 r = itemRect(item);
1344 r.setLeft(r.left()+(item->depth()+1)*treeStepSize()); 1344 r.setLeft(r.left()+(item->depth()+1)*treeStepSize());
1345 if (painter) { 1345 if (painter) {
1346//US style().drawPrimitive(QStyle::PE_FocusRect, painter, r, colorGroup(), 1346//US style().drawPrimitive(QStyle::PE_FocusRect, painter, r, colorGroup(),
1347//US QStyle::Style_FocusAtBorder, colorGroup().highlight()); 1347//US QStyle::Style_FocusAtBorder, colorGroup().highlight());
1348 const QColor* pHighl = &(colorGroup().highlight()); 1348 const QColor* pHighl = &(colorGroup().highlight());
1349 //LR style().drawFocusRect(painter, r, colorGroup(), pHighl, true); 1349 //LR style().drawFocusRect(painter, r, colorGroup(), pHighl, true);
1350 1350
1351qDebug("KListView::drawItemHighlighter has to be verified"); 1351qDebug("KListView::drawItemHighlighter has to be verified");
1352 1352
1353 } 1353 }
1354 1354
1355 } 1355 }
1356 1356
1357 return r; 1357 return r;
1358} 1358}
1359 1359
1360void KListView::cleanItemHighlighter () 1360void KListView::cleanItemHighlighter ()
1361{ 1361{
1362 if (d->mOldDropHighlighter.isValid()) 1362 if (d->mOldDropHighlighter.isValid())
1363 { 1363 {
1364 QRect rect=d->mOldDropHighlighter; 1364 QRect rect=d->mOldDropHighlighter;
1365 d->mOldDropHighlighter = QRect(); 1365 d->mOldDropHighlighter = QRect();
1366 viewport()->repaint(rect, true); 1366 viewport()->repaint(rect, true);
1367 } 1367 }
1368} 1368}
1369 1369
1370void KListView::rename(QListViewItem *item, int c) 1370void KListView::rename(QListViewItem *item, int c)
1371{ 1371{
1372 if (d->renameable.contains(c)) 1372 if (d->renameable.contains(c))
1373 { 1373 {
1374 ensureItemVisible(item); 1374 ensureItemVisible(item);
1375//US d->editor->load(item,c); 1375//US d->editor->load(item,c);
1376qDebug("KListView::rename has to be verified"); 1376qDebug("KListView::rename has to be verified");
1377 1377
1378 } 1378 }
1379} 1379}
1380 1380
1381bool KListView::isRenameable (int col) const 1381bool KListView::isRenameable (int col) const
1382{ 1382{
1383 return d->renameable.contains(col); 1383 return d->renameable.contains(col);
1384} 1384}
1385 1385
1386void KListView::setRenameable (int col, bool yesno) 1386void KListView::setRenameable (int col, bool yesno)
1387{ 1387{
1388 if (col>=header()->count()) return; 1388 if (col>=header()->count()) return;
1389 1389
1390 d->renameable.remove(col); 1390 d->renameable.remove(col);
1391 if (yesno && d->renameable.find(col)==d->renameable.end()) 1391 if (yesno && d->renameable.find(col)==d->renameable.end())
1392 d->renameable+=col; 1392 d->renameable+=col;
1393 else if (!yesno && d->renameable.find(col)!=d->renameable.end()) 1393 else if (!yesno && d->renameable.find(col)!=d->renameable.end())
1394 d->renameable.remove(col); 1394 d->renameable.remove(col);
1395} 1395}
1396 1396
1397void KListView::doneEditing(QListViewItem *item, int row) 1397void KListView::doneEditing(QListViewItem *item, int row)
1398{ 1398{
1399 emit itemRenamed(item, item->text(row), row); 1399 emit itemRenamed(item, item->text(row), row);
1400 emit itemRenamed(item); 1400 emit itemRenamed(item);
1401} 1401}
1402 1402
1403bool KListView::acceptDrag(QDropEvent* e) const 1403bool KListView::acceptDrag(QDropEvent* e) const
1404{ 1404{
1405qDebug("KListView::acceptDrag drag&drop not supported yet"); 1405qDebug("KListView::acceptDrag drag&drop not supported yet");
1406//US return acceptDrops() && itemsMovable() && (e->source()==viewport()); 1406//US return acceptDrops() && itemsMovable() && (e->source()==viewport());
1407return false; 1407return false;
1408} 1408}
1409 1409
1410void KListView::setCreateChildren(bool b) 1410void KListView::setCreateChildren(bool b)
1411{ 1411{
1412 d->createChildren=b; 1412 d->createChildren=b;
1413} 1413}
1414 1414
1415bool KListView::createChildren() const 1415bool KListView::createChildren() const
1416{ 1416{
1417 return d->createChildren; 1417 return d->createChildren;
1418} 1418}
1419 1419
1420 1420
1421int KListView::tooltipColumn() const 1421int KListView::tooltipColumn() const
1422{ 1422{
1423 return d->tooltipColumn; 1423 return d->tooltipColumn;
1424} 1424}
1425 1425
1426void KListView::setTooltipColumn(int column) 1426void KListView::setTooltipColumn(int column)
1427{ 1427{
1428 d->tooltipColumn=column; 1428 d->tooltipColumn=column;
1429} 1429}
1430 1430
1431void KListView::setDropHighlighter(bool b) 1431void KListView::setDropHighlighter(bool b)
1432{ 1432{
1433 d->dropHighlighter=b; 1433 d->dropHighlighter=b;
1434} 1434}
1435 1435
1436bool KListView::dropHighlighter() const 1436bool KListView::dropHighlighter() const
1437{ 1437{
1438 return d->dropHighlighter; 1438 return d->dropHighlighter;
1439} 1439}
1440 1440
1441bool KListView::showTooltip(QListViewItem *item, const QPoint &, int column) const 1441bool KListView::showTooltip(QListViewItem *item, const QPoint &, int column) const
1442{ 1442{
1443 return ((tooltip(item, column).length()>0) && (column==tooltipColumn())); 1443 return ((tooltip(item, column).length()>0) && (column==tooltipColumn()));
1444} 1444}
1445 1445
1446QString KListView::tooltip(QListViewItem *item, int column) const 1446QString KListView::tooltip(QListViewItem *item, int column) const
1447{ 1447{
1448 return item->text(column); 1448 return item->text(column);
1449} 1449}
1450 1450
1451void KListView::setTabOrderedRenaming(bool b) 1451void KListView::setTabOrderedRenaming(bool b)
1452{ 1452{
1453 d->tabRename = b; 1453 d->tabRename = b;
1454} 1454}
1455 1455
1456bool KListView::tabOrderedRenaming() const 1456bool KListView::tabOrderedRenaming() const
1457{ 1457{
1458 return d->tabRename; 1458 return d->tabRename;
1459} 1459}
1460 1460
1461void KListView::keyPressEvent (QKeyEvent* e) 1461void KListView::keyPressEvent (QKeyEvent* e)
1462{ 1462{
1463 //don't we need a contextMenuModifier too ? (aleXXX) 1463 //don't we need a contextMenuModifier too ? (aleXXX)
1464 if (e->key() == d->contextMenuKey) 1464 if (e->key() == d->contextMenuKey)
1465 { 1465 {
1466 emit menuShortCutPressed (this, currentItem()); 1466 emit menuShortCutPressed (this, currentItem());
1467 return; 1467 return;
1468 } 1468 }
1469 if (e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace) 1469 if (e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace)
1470 { 1470 {
1471 emit signalDelete ( ); 1471 emit signalDelete ( );
1472 return; 1472 return;
1473 } 1473 }
1474 1474
1475 if (d->selectionMode != FileManager) 1475 if (d->selectionMode != FileManager)
1476 QListView::keyPressEvent (e); 1476 QListView::keyPressEvent (e);
1477 else 1477 else
1478 fileManagerKeyPressEvent (e); 1478 fileManagerKeyPressEvent (e);
1479} 1479}
1480 1480
1481void KListView::activateAutomaticSelection() 1481void KListView::activateAutomaticSelection()
1482{ 1482{
1483 d->selectedBySimpleMove=true; 1483 d->selectedBySimpleMove=true;
1484 d->selectedUsingMouse=false; 1484 d->selectedUsingMouse=false;
1485 if (currentItem()!=0) 1485 if (currentItem()!=0)
1486 { 1486 {
1487 selectAll(false); 1487 selectAll(false);
1488 currentItem()->setSelected(true); 1488 currentItem()->setSelected(true);
1489 currentItem()->repaint(); 1489 currentItem()->repaint();
1490 emit selectionChanged(); 1490 emit selectionChanged();
1491 }; 1491 };
1492} 1492}
1493 1493
1494void KListView::deactivateAutomaticSelection() 1494void KListView::deactivateAutomaticSelection()
1495{ 1495{
1496 d->selectedBySimpleMove=false; 1496 d->selectedBySimpleMove=false;
1497} 1497}
1498 1498
1499bool KListView::automaticSelection() const 1499bool KListView::automaticSelection() const
1500{ 1500{
1501 return d->selectedBySimpleMove; 1501 return d->selectedBySimpleMove;
1502} 1502}
1503 1503
1504void KListView::fileManagerKeyPressEvent (QKeyEvent* e) 1504void KListView::fileManagerKeyPressEvent (QKeyEvent* e)
1505{ 1505{
1506 //don't care whether it's on the keypad or not 1506 //don't care whether it's on the keypad or not
1507 int e_state=(e->state() & ~Keypad); 1507 int e_state=(e->state() & ~Keypad);
1508 1508
1509 int oldSelectionDirection(d->selectionDirection); 1509 int oldSelectionDirection(d->selectionDirection);
1510 1510
1511 if ((e->key()!=Key_Shift) && (e->key()!=Key_Control) 1511 if ((e->key()!=Key_Shift) && (e->key()!=Key_Control)
1512 && (e->key()!=Key_Meta) && (e->key()!=Key_Alt)) 1512 && (e->key()!=Key_Meta) && (e->key()!=Key_Alt))
1513 { 1513 {
1514 if ((e_state==ShiftButton) && (!d->wasShiftEvent) && (!d->selectedBySimpleMove)) 1514 if ((e_state==ShiftButton) && (!d->wasShiftEvent) && (!d->selectedBySimpleMove))
1515 selectAll(FALSE); 1515 selectAll(FALSE);
1516 d->selectionDirection=0; 1516 d->selectionDirection=0;
1517 d->wasShiftEvent = (e_state == ShiftButton); 1517 d->wasShiftEvent = (e_state == ShiftButton);
1518 }; 1518 };
1519 1519
1520 //d->wasShiftEvent = (e_state == ShiftButton); 1520 //d->wasShiftEvent = (e_state == ShiftButton);
1521 1521
1522 1522
1523 QListViewItem* item = currentItem(); 1523 QListViewItem* item = currentItem();
1524 if (item==0) return; 1524 if (item==0) return;
1525 1525
1526 QListViewItem* repaintItem1 = item; 1526 QListViewItem* repaintItem1 = item;
1527 QListViewItem* repaintItem2 = 0L; 1527 QListViewItem* repaintItem2 = 0L;
1528 QListViewItem* visItem = 0L; 1528 QListViewItem* visItem = 0L;
1529 1529
1530 QListViewItem* nextItem = 0L; 1530 QListViewItem* nextItem = 0L;
1531 int items = 0; 1531 int items = 0;
1532 1532
1533 bool shiftOrCtrl((e_state==ControlButton) || (e_state==ShiftButton)); 1533 bool shiftOrCtrl((e_state==ControlButton) || (e_state==ShiftButton));
1534 int selectedItems(0); 1534 int selectedItems(0);
1535 for (QListViewItem *tmpItem=firstChild(); tmpItem!=0; tmpItem=tmpItem->nextSibling()) 1535 for (QListViewItem *tmpItem=firstChild(); tmpItem!=0; tmpItem=tmpItem->nextSibling())
1536 if (tmpItem->isSelected()) selectedItems++; 1536 if (tmpItem->isSelected()) selectedItems++;
1537 1537
1538 if (((selectedItems==0) || ((selectedItems==1) && (d->selectedUsingMouse))) 1538 if (((selectedItems==0) || ((selectedItems==1) && (d->selectedUsingMouse)))
1539 && (e_state==NoButton) 1539 && (e_state==NoButton)
1540 && ((e->key()==Key_Down) 1540 && ((e->key()==Key_Down)
1541 || (e->key()==Key_Up) 1541 || (e->key()==Key_Up)
1542 || (e->key()==Key_Next) 1542 || (e->key()==Key_Next)
1543 || (e->key()==Key_Prior) 1543 || (e->key()==Key_Prior)
1544 || (e->key()==Key_Home) 1544 || (e->key()==Key_Home)
1545 || (e->key()==Key_End))) 1545 || (e->key()==Key_End)))
1546 { 1546 {
1547 d->selectedBySimpleMove=true; 1547 d->selectedBySimpleMove=true;
1548 d->selectedUsingMouse=false; 1548 d->selectedUsingMouse=false;
1549 } 1549 }
1550 else if (selectedItems>1) 1550 else if (selectedItems>1)
1551 d->selectedBySimpleMove=false; 1551 d->selectedBySimpleMove=false;
1552 1552
1553 bool emitSelectionChanged(false); 1553 bool emitSelectionChanged(false);
1554 1554
1555 switch (e->key()) 1555 switch (e->key())
1556 { 1556 {
1557 case Key_Escape: 1557 case Key_Escape:
1558 selectAll(FALSE); 1558 selectAll(FALSE);
1559 emitSelectionChanged=TRUE; 1559 emitSelectionChanged=TRUE;
1560 break; 1560 break;
1561 1561
1562 case Key_Space: 1562 case Key_Space:
1563 //toggle selection of current item 1563 //toggle selection of current item
1564 if (d->selectedBySimpleMove) 1564 if (d->selectedBySimpleMove)
1565 d->selectedBySimpleMove=false; 1565 d->selectedBySimpleMove=false;
1566 item->setSelected(!item->isSelected()); 1566 item->setSelected(!item->isSelected());
1567 emitSelectionChanged=TRUE; 1567 emitSelectionChanged=TRUE;
1568 break; 1568 break;
1569 1569
1570 case Key_Insert: 1570 case Key_Insert:
1571 //toggle selection of current item and move to the next item 1571 //toggle selection of current item and move to the next item
1572 if (d->selectedBySimpleMove) 1572 if (d->selectedBySimpleMove)
1573 { 1573 {
1574 d->selectedBySimpleMove=false; 1574 d->selectedBySimpleMove=false;
1575 if (!item->isSelected()) item->setSelected(TRUE); 1575 if (!item->isSelected()) item->setSelected(TRUE);
1576 } 1576 }
1577 else 1577 else
1578 { 1578 {
1579 item->setSelected(!item->isSelected()); 1579 item->setSelected(!item->isSelected());
1580 }; 1580 };
1581 1581
1582 nextItem=item->itemBelow(); 1582 nextItem=item->itemBelow();
1583 1583
1584 if (nextItem!=0) 1584 if (nextItem!=0)
1585 { 1585 {
1586 repaintItem2=nextItem; 1586 repaintItem2=nextItem;
1587 visItem=nextItem; 1587 visItem=nextItem;
1588 setCurrentItem(nextItem); 1588 setCurrentItem(nextItem);
1589 }; 1589 };
1590 d->selectionDirection=1; 1590 d->selectionDirection=1;
1591 emitSelectionChanged=TRUE; 1591 emitSelectionChanged=TRUE;
1592 break; 1592 break;
1593 1593
1594 case Key_Down: 1594 case Key_Down:
1595 nextItem=item->itemBelow(); 1595 nextItem=item->itemBelow();
1596 //toggle selection of current item and move to the next item 1596 //toggle selection of current item and move to the next item
1597 if (shiftOrCtrl) 1597 if (shiftOrCtrl)
1598 { 1598 {
1599 d->selectionDirection=1; 1599 d->selectionDirection=1;
1600 if (d->selectedBySimpleMove) 1600 if (d->selectedBySimpleMove)
1601 d->selectedBySimpleMove=false; 1601 d->selectedBySimpleMove=false;
1602 else 1602 else
1603 { 1603 {
1604 if (oldSelectionDirection!=-1) 1604 if (oldSelectionDirection!=-1)
1605 { 1605 {
1606 item->setSelected(!item->isSelected()); 1606 item->setSelected(!item->isSelected());
1607 emitSelectionChanged=TRUE; 1607 emitSelectionChanged=TRUE;
1608 }; 1608 };
1609 }; 1609 };
1610 } 1610 }
1611 else if ((d->selectedBySimpleMove) && (nextItem!=0)) 1611 else if ((d->selectedBySimpleMove) && (nextItem!=0))
1612 { 1612 {
1613 item->setSelected(false); 1613 item->setSelected(false);
1614 emitSelectionChanged=TRUE; 1614 emitSelectionChanged=TRUE;
1615 }; 1615 };
1616 1616
1617 if (nextItem!=0) 1617 if (nextItem!=0)
1618 { 1618 {
1619 if (d->selectedBySimpleMove) 1619 if (d->selectedBySimpleMove)
1620 nextItem->setSelected(true); 1620 nextItem->setSelected(true);
1621 repaintItem2=nextItem; 1621 repaintItem2=nextItem;
1622 visItem=nextItem; 1622 visItem=nextItem;
1623 setCurrentItem(nextItem); 1623 setCurrentItem(nextItem);
1624 }; 1624 };
1625 break; 1625 break;
1626 1626
1627 case Key_Up: 1627 case Key_Up:
1628 nextItem=item->itemAbove(); 1628 nextItem=item->itemAbove();
1629 d->selectionDirection=-1; 1629 d->selectionDirection=-1;
1630 //move to the prev. item and toggle selection of this one 1630 //move to the prev. item and toggle selection of this one
1631 // => No, can't select the last item, with this. For symmetry, let's 1631 // => No, can't select the last item, with this. For symmetry, let's
1632 // toggle selection and THEN move up, just like we do in down (David) 1632 // toggle selection and THEN move up, just like we do in down (David)
1633 if (shiftOrCtrl) 1633 if (shiftOrCtrl)
1634 { 1634 {
1635 if (d->selectedBySimpleMove) 1635 if (d->selectedBySimpleMove)
1636 d->selectedBySimpleMove=false; 1636 d->selectedBySimpleMove=false;
1637 else 1637 else
1638 { 1638 {
1639 if (oldSelectionDirection!=1) 1639 if (oldSelectionDirection!=1)
1640 { 1640 {
1641 item->setSelected(!item->isSelected()); 1641 item->setSelected(!item->isSelected());
1642 emitSelectionChanged=TRUE; 1642 emitSelectionChanged=TRUE;
1643 }; 1643 };
1644 } 1644 }
1645 } 1645 }
1646 else if ((d->selectedBySimpleMove) && (nextItem!=0)) 1646 else if ((d->selectedBySimpleMove) && (nextItem!=0))
1647 { 1647 {
1648 item->setSelected(false); 1648 item->setSelected(false);
1649 emitSelectionChanged=TRUE; 1649 emitSelectionChanged=TRUE;
1650 }; 1650 };
1651 1651
1652 if (nextItem!=0) 1652 if (nextItem!=0)
1653 { 1653 {
1654 if (d->selectedBySimpleMove) 1654 if (d->selectedBySimpleMove)
1655 nextItem->setSelected(true); 1655 nextItem->setSelected(true);
1656 repaintItem2=nextItem; 1656 repaintItem2=nextItem;
1657 visItem=nextItem; 1657 visItem=nextItem;
1658 setCurrentItem(nextItem); 1658 setCurrentItem(nextItem);
1659 }; 1659 };
1660 break; 1660 break;
1661 1661
1662 case Key_End: 1662 case Key_End:
1663 //move to the last item and toggle selection of all items inbetween 1663 //move to the last item and toggle selection of all items inbetween
1664 nextItem=item; 1664 nextItem=item;
1665 if (d->selectedBySimpleMove) 1665 if (d->selectedBySimpleMove)
1666 item->setSelected(false); 1666 item->setSelected(false);
1667 if (shiftOrCtrl) 1667 if (shiftOrCtrl)
1668 d->selectedBySimpleMove=false; 1668 d->selectedBySimpleMove=false;
1669 1669
1670 while(nextItem!=0) 1670 while(nextItem!=0)
1671 { 1671 {
1672 if (shiftOrCtrl) 1672 if (shiftOrCtrl)
1673 nextItem->setSelected(!nextItem->isSelected()); 1673 nextItem->setSelected(!nextItem->isSelected());
1674 if (nextItem->itemBelow()==0) 1674 if (nextItem->itemBelow()==0)
1675 { 1675 {
1676 if (d->selectedBySimpleMove) 1676 if (d->selectedBySimpleMove)
1677 nextItem->setSelected(true); 1677 nextItem->setSelected(true);
1678 repaintItem2=nextItem; 1678 repaintItem2=nextItem;
1679 visItem=nextItem; 1679 visItem=nextItem;
1680 setCurrentItem(nextItem); 1680 setCurrentItem(nextItem);
1681 } 1681 }
1682 nextItem=nextItem->itemBelow(); 1682 nextItem=nextItem->itemBelow();
1683 } 1683 }
1684 emitSelectionChanged=TRUE; 1684 emitSelectionChanged=TRUE;
1685 break; 1685 break;
1686 1686
1687 case Key_Home: 1687 case Key_Home:
1688 // move to the first item and toggle selection of all items inbetween 1688 // move to the first item and toggle selection of all items inbetween
1689 nextItem = firstChild(); 1689 nextItem = firstChild();
1690 visItem = nextItem; 1690 visItem = nextItem;
1691 repaintItem2 = visItem; 1691 repaintItem2 = visItem;
1692 if (d->selectedBySimpleMove) 1692 if (d->selectedBySimpleMove)
1693 item->setSelected(false); 1693 item->setSelected(false);
1694 if (shiftOrCtrl) 1694 if (shiftOrCtrl)
1695 { 1695 {
1696 d->selectedBySimpleMove=false; 1696 d->selectedBySimpleMove=false;
1697 1697
1698 while ( nextItem != item ) 1698 while ( nextItem != item )
1699 { 1699 {
1700 nextItem->setSelected( !nextItem->isSelected() ); 1700 nextItem->setSelected( !nextItem->isSelected() );
1701 nextItem = nextItem->itemBelow(); 1701 nextItem = nextItem->itemBelow();
1702 } 1702 }
1703 item->setSelected( !item->isSelected() ); 1703 item->setSelected( !item->isSelected() );
1704 } 1704 }
1705 setCurrentItem( firstChild() ); 1705 setCurrentItem( firstChild() );
1706 emitSelectionChanged=TRUE; 1706 emitSelectionChanged=TRUE;
1707 break; 1707 break;
1708 1708
1709 case Key_Next: 1709 case Key_Next:
1710 items=visibleHeight()/item->height(); 1710 items=visibleHeight()/item->height();
1711 nextItem=item; 1711 nextItem=item;
1712 if (d->selectedBySimpleMove) 1712 if (d->selectedBySimpleMove)
1713 item->setSelected(false); 1713 item->setSelected(false);
1714 if (shiftOrCtrl) 1714 if (shiftOrCtrl)
1715 { 1715 {
1716 d->selectedBySimpleMove=false; 1716 d->selectedBySimpleMove=false;
1717 d->selectionDirection=1; 1717 d->selectionDirection=1;
1718 }; 1718 };
1719 1719
1720 for (int i=0; i<items; i++) 1720 for (int i=0; i<items; i++)
1721 { 1721 {
1722 if (shiftOrCtrl) 1722 if (shiftOrCtrl)
1723 nextItem->setSelected(!nextItem->isSelected()); 1723 nextItem->setSelected(!nextItem->isSelected());
1724 //the end 1724 //the end
1725 if ((i==items-1) || (nextItem->itemBelow()==0)) 1725 if ((i==items-1) || (nextItem->itemBelow()==0))
1726 1726
1727 { 1727 {
1728 if (shiftOrCtrl) 1728 if (shiftOrCtrl)
1729 nextItem->setSelected(!nextItem->isSelected()); 1729 nextItem->setSelected(!nextItem->isSelected());
1730 if (d->selectedBySimpleMove) 1730 if (d->selectedBySimpleMove)
1731 nextItem->setSelected(true); 1731 nextItem->setSelected(true);
1732 ensureItemVisible(nextItem); 1732 ensureItemVisible(nextItem);
1733 setCurrentItem(nextItem); 1733 setCurrentItem(nextItem);
1734 update(); 1734 update();
1735 if ((shiftOrCtrl) || (d->selectedBySimpleMove)) 1735 if ((shiftOrCtrl) || (d->selectedBySimpleMove))
1736 { 1736 {
1737 emit selectionChanged(); 1737 emit selectionChanged();
1738 } 1738 }
1739 return; 1739 return;
1740 } 1740 }
1741 nextItem=nextItem->itemBelow(); 1741 nextItem=nextItem->itemBelow();
1742 } 1742 }
1743 break; 1743 break;
1744 1744
1745 case Key_Prior: 1745 case Key_Prior:
1746 items=visibleHeight()/item->height(); 1746 items=visibleHeight()/item->height();
1747 nextItem=item; 1747 nextItem=item;
1748 if (d->selectedBySimpleMove) 1748 if (d->selectedBySimpleMove)
1749 item->setSelected(false); 1749 item->setSelected(false);
1750 if (shiftOrCtrl) 1750 if (shiftOrCtrl)
1751 { 1751 {
1752 d->selectionDirection=-1; 1752 d->selectionDirection=-1;
1753 d->selectedBySimpleMove=false; 1753 d->selectedBySimpleMove=false;
1754 }; 1754 };
1755 1755
1756 for (int i=0; i<items; i++) 1756 for (int i=0; i<items; i++)
1757 { 1757 {
1758 if ((nextItem!=item) &&(shiftOrCtrl)) 1758 if ((nextItem!=item) &&(shiftOrCtrl))
1759 nextItem->setSelected(!nextItem->isSelected()); 1759 nextItem->setSelected(!nextItem->isSelected());
1760 //the end 1760 //the end
1761 if ((i==items-1) || (nextItem->itemAbove()==0)) 1761 if ((i==items-1) || (nextItem->itemAbove()==0))
1762 1762
1763 { 1763 {
1764 if (d->selectedBySimpleMove) 1764 if (d->selectedBySimpleMove)
1765 nextItem->setSelected(true); 1765 nextItem->setSelected(true);
1766 ensureItemVisible(nextItem); 1766 ensureItemVisible(nextItem);
1767 setCurrentItem(nextItem); 1767 setCurrentItem(nextItem);
1768 update(); 1768 update();
1769 if ((shiftOrCtrl) || (d->selectedBySimpleMove)) 1769 if ((shiftOrCtrl) || (d->selectedBySimpleMove))
1770 { 1770 {
1771 emit selectionChanged(); 1771 emit selectionChanged();
1772 } 1772 }
1773 return; 1773 return;
1774 } 1774 }
1775 nextItem=nextItem->itemAbove(); 1775 nextItem=nextItem->itemAbove();
1776 } 1776 }
1777 break; 1777 break;
1778 1778
1779 case Key_Minus: 1779 case Key_Minus:
1780 if ( item->isOpen() ) 1780 if ( item->isOpen() )
1781 setOpen( item, FALSE ); 1781 setOpen( item, FALSE );
1782 break; 1782 break;
1783 case Key_Plus: 1783 case Key_Plus:
1784 if ( !item->isOpen() && (item->isExpandable() || item->childCount()) ) 1784 if ( !item->isOpen() && (item->isExpandable() || item->childCount()) )
1785 setOpen( item, TRUE ); 1785 setOpen( item, TRUE );
1786 break; 1786 break;
1787 default: 1787 default:
1788 bool realKey = ((e->key()!=Key_Shift) && (e->key()!=Key_Control) 1788 bool realKey = ((e->key()!=Key_Shift) && (e->key()!=Key_Control)
1789 && (e->key()!=Key_Meta) && (e->key()!=Key_Alt)); 1789 && (e->key()!=Key_Meta) && (e->key()!=Key_Alt));
1790 1790
1791 bool selectCurrentItem = (d->selectedBySimpleMove) && (item->isSelected()); 1791 bool selectCurrentItem = (d->selectedBySimpleMove) && (item->isSelected());
1792 if (realKey && selectCurrentItem) 1792 if (realKey && selectCurrentItem)
1793 item->setSelected(false); 1793 item->setSelected(false);
1794 //this is mainly for the "goto filename beginning with pressed char" feature (aleXXX) 1794 //this is mainly for the "goto filename beginning with pressed char" feature (aleXXX)
1795 QListView::SelectionMode oldSelectionMode = selectionMode(); 1795 QListView::SelectionMode oldSelectionMode = selectionMode();
1796 setSelectionMode (QListView::Multi); 1796 setSelectionMode (QListView::Multi);
1797 QListView::keyPressEvent (e); 1797 QListView::keyPressEvent (e);
1798 setSelectionMode (oldSelectionMode); 1798 setSelectionMode (oldSelectionMode);
1799 if (realKey && selectCurrentItem) 1799 if (realKey && selectCurrentItem)
1800 { 1800 {
1801 currentItem()->setSelected(true); 1801 currentItem()->setSelected(true);
1802 emitSelectionChanged=TRUE; 1802 emitSelectionChanged=TRUE;
1803 } 1803 }
1804 repaintItem2=currentItem(); 1804 repaintItem2=currentItem();
1805 if (realKey) 1805 if (realKey)
1806 visItem=currentItem(); 1806 visItem=currentItem();
1807 break; 1807 break;
1808 } 1808 }
1809 1809
1810 if (visItem) 1810 if (visItem)
1811 ensureItemVisible(visItem); 1811 ensureItemVisible(visItem);
1812 1812
1813 QRect ir; 1813 QRect ir;
1814 if (repaintItem1) 1814 if (repaintItem1)
1815 ir = ir.unite( itemRect(repaintItem1) ); 1815 ir = ir.unite( itemRect(repaintItem1) );
1816 if (repaintItem2) 1816 if (repaintItem2)
1817 ir = ir.unite( itemRect(repaintItem2) ); 1817 ir = ir.unite( itemRect(repaintItem2) );
1818 1818
1819 if ( !ir.isEmpty() ) 1819 if ( !ir.isEmpty() )
1820 { // rectangle to be repainted 1820 { // rectangle to be repainted
1821 if ( ir.x() < 0 ) 1821 if ( ir.x() < 0 )
1822 ir.moveBy( -ir.x(), 0 ); 1822 ir.moveBy( -ir.x(), 0 );
1823 viewport()->repaint( ir, FALSE ); 1823 viewport()->repaint( ir, FALSE );
1824 } 1824 }
1825 /*if (repaintItem1) 1825 /*if (repaintItem1)
1826 repaintItem1->repaint(); 1826 repaintItem1->repaint();
1827 if (repaintItem2) 1827 if (repaintItem2)
1828 repaintItem2->repaint();*/ 1828 repaintItem2->repaint();*/
1829 update(); 1829 update();
1830 if (emitSelectionChanged) 1830 if (emitSelectionChanged)
1831 emit selectionChanged(); 1831 emit selectionChanged();
1832} 1832}
1833 1833
1834void KListView::setSelectionModeExt (SelectionModeExt mode) 1834void KListView::setSelectionModeExt (SelectionModeExt mode)
1835{ 1835{
1836 d->selectionMode = mode; 1836 d->selectionMode = mode;
1837 1837
1838 switch (mode) 1838 switch (mode)
1839 { 1839 {
1840 case Single: 1840 case Single:
1841 case Multi: 1841 case Multi:
1842 case Extended: 1842 case Extended:
1843 case NoSelection: 1843 case NoSelection:
1844 setSelectionMode (static_cast<QListView::SelectionMode>(static_cast<int>(mode))); 1844 setSelectionMode (static_cast<QListView::SelectionMode>(static_cast<int>(mode)));
1845 break; 1845 break;
1846 1846
1847 case FileManager: 1847 case FileManager:
1848 setSelectionMode (QListView::Extended); 1848 setSelectionMode (QListView::Extended);
1849 break; 1849 break;
1850 1850
1851 default: 1851 default:
1852 kdWarning () << "Warning: illegal selection mode " << int(mode) << " set!" << endl; 1852 kdWarning () << "Warning: illegal selection mode " << int(mode) << " set!" << endl;
1853 break; 1853 break;
1854 } 1854 }
1855} 1855}
1856 1856
1857KListView::SelectionModeExt KListView::selectionModeExt () const 1857KListView::SelectionModeExt KListView::selectionModeExt () const
1858{ 1858{
1859 return d->selectionMode; 1859 return d->selectionMode;
1860} 1860}
1861 1861
1862int KListView::itemIndex( const QListViewItem *item ) const 1862int KListView::itemIndex( const QListViewItem *item ) const
1863{ 1863{
1864 if ( !item ) 1864 if ( !item )
1865 return -1; 1865 return -1;
1866 1866
1867 if ( item == firstChild() ) 1867 if ( item == firstChild() )
1868 return 0; 1868 return 0;
1869 else { 1869 else {
1870 QListViewItemIterator it(firstChild()); 1870 QListViewItemIterator it(firstChild());
1871 uint j = 0; 1871 uint j = 0;
1872 for (; it.current() && it.current() != item; ++it, ++j ); 1872 for (; it.current() && it.current() != item; ++it, ++j );
1873 1873
1874 if( !it.current() ) 1874 if( !it.current() )
1875 return -1; 1875 return -1;
1876 1876
1877 return j; 1877 return j;
1878 } 1878 }
1879} 1879}
1880 1880
1881QListViewItem* KListView::itemAtIndex(int index) 1881QListViewItem* KListView::itemAtIndex(int index)
1882{ 1882{
1883 if (index<0) 1883 if (index<0)
1884 return 0; 1884 return 0;
1885 1885
1886 int j(0); 1886 int j(0);
1887 for (QListViewItemIterator it=firstChild(); it.current(); it++) 1887 for (QListViewItemIterator it=firstChild(); it.current(); it++)
1888 { 1888 {
1889 if (j==index) 1889 if (j==index)
1890 return it.current(); 1890 return it.current();
1891 j++; 1891 j++;
1892 }; 1892 };
1893 return 0; 1893 return 0;
1894} 1894}
1895 1895
1896 1896
1897void KListView::emitContextMenu (KListView*, QListViewItem* i) 1897void KListView::emitContextMenu (KListView*, QListViewItem* i)
1898{ 1898{
1899 QPoint p; 1899 QPoint p;
1900 // qDebug("KListView::emitContextMenu "); 1900 // qDebug("KListView::emitContextMenu ");
1901 1901
1902 if (i) 1902 if (i)
1903 p = viewport()->mapToGlobal(itemRect(i).center()); 1903 p = viewport()->mapToGlobal(itemRect(i).center());
1904 else 1904 else
1905 p = mapToGlobal(rect().center()); 1905 p = mapToGlobal(rect().center());
1906 1906
1907 emit contextMenu (this, i, p); 1907 emit contextMenu (this, i, p);
1908} 1908}
1909 1909
1910void KListView::emitContextMenu (QListViewItem* i, const QPoint& p, int col) 1910void KListView::emitContextMenu (QListViewItem* i, const QPoint& p, int col)
1911{ 1911{
1912 // qDebug("KListView::emitContextMenu col"); 1912 // qDebug("KListView::emitContextMenu col");
1913 emit contextRequest( i, p, col ); 1913 emit contextRequest( i, p, col );
1914 emit contextMenu (this, i, p); 1914 emit contextMenu (this, i, p);
1915} 1915}
1916 1916
1917void KListView::setAcceptDrops (bool val) 1917void KListView::setAcceptDrops (bool val)
1918{ 1918{
1919 QListView::setAcceptDrops (val); 1919 QListView::setAcceptDrops (val);
1920 viewport()->setAcceptDrops (val); 1920 viewport()->setAcceptDrops (val);
1921} 1921}
1922 1922
1923int KListView::dropVisualizerWidth () const 1923int KListView::dropVisualizerWidth () const
1924{ 1924{
1925 return d->mDropVisualizerWidth; 1925 return d->mDropVisualizerWidth;
1926} 1926}
1927 1927
1928 1928
1929void KListView::viewportPaintEvent(QPaintEvent *e) 1929void KListView::viewportPaintEvent(QPaintEvent *e)
1930{ 1930{
1931 QListView::viewportPaintEvent(e); 1931 QListView::viewportPaintEvent(e);
1932 1932
1933 if (d->mOldDropVisualizer.isValid() && e->rect().intersects(d->mOldDropVisualizer)) 1933 if (d->mOldDropVisualizer.isValid() && e->rect().intersects(d->mOldDropVisualizer))
1934 { 1934 {
1935 QPainter painter(viewport()); 1935 QPainter painter(viewport());
1936 1936
1937 // This is where we actually draw the drop-visualizer 1937 // This is where we actually draw the drop-visualizer
1938 painter.fillRect(d->mOldDropVisualizer, Dense4Pattern); 1938 painter.fillRect(d->mOldDropVisualizer, Dense4Pattern);
1939 } 1939 }
1940 if (d->mOldDropHighlighter.isValid() && e->rect().intersects(d->mOldDropHighlighter)) 1940 if (d->mOldDropHighlighter.isValid() && e->rect().intersects(d->mOldDropHighlighter))
1941 { 1941 {
1942 QPainter painter(viewport()); 1942 QPainter painter(viewport());
1943 1943
1944qDebug("KListView::viewportPaintEvent has to be verified"); 1944qDebug("KListView::viewportPaintEvent has to be verified");
1945 1945
1946 // This is where we actually draw the drop-highlighter 1946 // This is where we actually draw the drop-highlighter
1947//US style().drawPrimitive(QStyle::PE_FocusRect, &painter, d->mOldDropHighlighter, colorGroup(), 1947//US style().drawPrimitive(QStyle::PE_FocusRect, &painter, d->mOldDropHighlighter, colorGroup(),
1948//US QStyle::Style_FocusAtBorder); 1948//US QStyle::Style_FocusAtBorder);
1949 1949
1950//LR style().drawFocusRect(&painter, d->mOldDropHighlighter, colorGroup(), (const QColor*)0, true); 1950//LR style().drawFocusRect(&painter, d->mOldDropHighlighter, colorGroup(), (const QColor*)0, true);
1951 1951
1952 1952
1953 } 1953 }
1954} 1954}
1955 1955
1956void KListView::setFullWidth() 1956void KListView::setFullWidth()
1957{ 1957{
1958 setFullWidth(true); 1958 setFullWidth(true);
1959} 1959}
1960 1960
1961void KListView::setFullWidth(bool fullWidth) 1961void KListView::setFullWidth(bool fullWidth)
1962{ 1962{
1963 d->fullWidth = fullWidth; 1963 d->fullWidth = fullWidth;
1964//US header()->setStretchEnabled(fullWidth, columns()-1); 1964//US header()->setStretchEnabled(fullWidth, columns()-1);
1965} 1965}
1966 1966
1967bool KListView::fullWidth() const 1967bool KListView::fullWidth() const
1968{ 1968{
1969 return d->fullWidth; 1969 return d->fullWidth;
1970} 1970}
1971 1971
1972int KListView::addColumn(const QString& label, int width) 1972int KListView::addColumn(const QString& label, int width)
1973{ 1973{
1974 int result = QListView::addColumn(label, width); 1974 int result = QListView::addColumn(label, width);
1975 if (d->fullWidth) { 1975 if (d->fullWidth) {
1976//US header()->setStretchEnabled(false, columns()-2); 1976//US header()->setStretchEnabled(false, columns()-2);
1977//US header()->setStretchEnabled(true, columns()-1); 1977//US header()->setStretchEnabled(true, columns()-1);
1978 } 1978 }
1979 return result; 1979 return result;
1980} 1980}
1981 1981
1982int KListView::addColumn(const QIconSet& iconset, const QString& label, int width) 1982int KListView::addColumn(const QIconSet& iconset, const QString& label, int width)
1983{ 1983{
1984 int result = QListView::addColumn(iconset, label, width); 1984 int result = QListView::addColumn(iconset, label, width);
1985 if (d->fullWidth) { 1985 if (d->fullWidth) {
1986//US header()->setStretchEnabled(false, columns()-2); 1986//US header()->setStretchEnabled(false, columns()-2);
1987//US header()->setStretchEnabled(true, columns()-1); 1987//US header()->setStretchEnabled(true, columns()-1);
1988 } 1988 }
1989 return result; 1989 return result;
1990} 1990}
1991 1991
1992void KListView::removeColumn(int index) 1992void KListView::removeColumn(int index)
1993{ 1993{
1994 QListView::removeColumn(index); 1994 QListView::removeColumn(index);
1995//US if (d->fullWidth && index == columns()) header()->setStretchEnabled(true, columns()-1); 1995//US if (d->fullWidth && index == columns()) header()->setStretchEnabled(true, columns()-1);
1996} 1996}
1997 1997
1998void KListView::viewportResizeEvent(QResizeEvent* e) 1998void KListView::viewportResizeEvent(QResizeEvent* e)
1999{ 1999{
2000 QListView::viewportResizeEvent(e); 2000 QListView::viewportResizeEvent(e);
2001} 2001}
2002 2002
2003const QColor &KListView::alternateBackground() const 2003const QColor &KListView::alternateBackground() const
2004{ 2004{
2005 return d->alternateBackground; 2005 return d->alternateBackground;
2006} 2006}
2007 2007
2008void KListView::setAlternateBackground(const QColor &c) 2008void KListView::setAlternateBackground(const QColor &c)
2009{ 2009{
2010 d->alternateBackground = c; 2010 d->alternateBackground = c;
2011 repaint(); 2011 repaint();
2012} 2012}
2013 2013
2014void KListView::saveLayout(KConfig *config, const QString &group) const 2014void KListView::saveLayout(KConfig *config, const QString &group) const
2015{ 2015{
2016 KConfigGroupSaver saver(config, group); 2016 KConfigGroupSaver saver(config, group);
2017 QStringList widths, order; 2017 QStringList widths, order;
2018 for (int i = 0; i < columns(); ++i) 2018 for (int i = 0; i < columns(); ++i)
2019 { 2019 {
2020 widths << QString::number(columnWidth(i)); 2020 widths << QString::number(columnWidth(i));
2021 order << QString::number(header()->mapToIndex(i)); 2021 order << QString::number(header()->mapToIndex(i));
2022 } 2022 }
2023 config->writeEntry("ColumnWidths", widths); 2023 config->writeEntry("ColumnWidths", widths);
2024 config->writeEntry("ColumnOrder", order); 2024 config->writeEntry("ColumnOrder", order);
2025 config->writeEntry("SortColumn", d->sortColumn); 2025 config->writeEntry("SortColumn", d->sortColumn);
2026 config->writeEntry("SortAscending", d->sortAscending); 2026 config->writeEntry("SortAscending", d->sortAscending);
2027} 2027}
2028 2028
2029void KListView::restoreLayout(KConfig *config, const QString &group) 2029void KListView::restoreLayout(KConfig *config, const QString &group)
2030{ 2030{
2031 KConfigGroupSaver saver(config, group); 2031 KConfigGroupSaver saver(config, group);
2032 QStringList cols = config->readListEntry("ColumnWidths"); 2032 QStringList cols = config->readListEntry("ColumnWidths");
2033 int i = 0; 2033 int i = 0;
2034 for (QStringList::ConstIterator it = cols.begin(); it != cols.end(); ++it) 2034 for (QStringList::ConstIterator it = cols.begin(); it != cols.end(); ++it)
2035 setColumnWidth(i++, (*it).toInt()); 2035 setColumnWidth(i++, (*it).toInt());
2036 2036
2037 cols = config->readListEntry("ColumnOrder"); 2037 cols = config->readListEntry("ColumnOrder");
2038 i = 0; 2038 i = 0;
2039 for (QStringList::ConstIterator it = cols.begin(); it != cols.end(); ++it) 2039 for (QStringList::ConstIterator it = cols.begin(); it != cols.end(); ++it)
2040 header()->moveSection(i++, (*it).toInt()); 2040 header()->moveSection(i++, (*it).toInt());
2041 2041
2042/*US I changed the following code, because hasKey is not available. 2042/*US I changed the following code, because hasKey is not available.
2043!!! check if my version is correct 2043!!! check if my version is correct
2044 if (config->hasKey("SortColumn")) 2044 if (config->hasKey("SortColumn"))
2045 setSorting(config->readNumEntry("SortColumn"), config->readBoolEntry("SortAscending", true)); 2045 setSorting(config->readNumEntry("SortColumn"), config->readBoolEntry("SortAscending", true));
2046*/ 2046*/
2047 QStringList langLst = config->readListEntry( "SortColumn" ); 2047 QStringList langLst = config->readListEntry( "SortColumn" );
2048 if (!langLst.isEmpty()) 2048 if (!langLst.isEmpty())
2049 setSorting(config->readNumEntry("SortColumn"), config->readBoolEntry("SortAscending", true)); 2049 setSorting(config->readNumEntry("SortColumn"), config->readBoolEntry("SortAscending", true));
2050} 2050}
2051 2051
2052void KListView::setSorting(int column, bool ascending) 2052void KListView::setSorting(int column, bool ascending)
2053{ 2053{
2054 d->sortColumn = column; 2054 d->sortColumn = column;
2055 d->sortAscending = ascending; 2055 d->sortAscending = ascending;
2056 QListView::setSorting(column, ascending); 2056 QListView::setSorting(column, ascending);
2057} 2057}
2058 2058
2059int KListView::columnSorted(void) const 2059int KListView::columnSorted(void) const
2060{ 2060{
2061 return d->sortColumn; 2061 return d->sortColumn;
2062} 2062}
2063 2063
2064bool KListView::ascendingSort(void) const 2064bool KListView::ascendingSort(void) const
2065{ 2065{
2066 return d->sortAscending; 2066 return d->sortAscending;
2067} 2067}
2068 2068
2069KListViewItem::KListViewItem(QListView *parent) 2069KListViewItem::KListViewItem(QListView *parent)
2070 : QListViewItem(parent) 2070 : QListViewItem(parent)
2071{ 2071{
2072 init(); 2072 init();
2073} 2073}
2074 2074
2075KListViewItem::KListViewItem(QListViewItem *parent) 2075KListViewItem::KListViewItem(QListViewItem *parent)
2076 : QListViewItem(parent) 2076 : QListViewItem(parent)
2077{ 2077{
2078 init(); 2078 init();
2079} 2079}
2080 2080
2081KListViewItem::KListViewItem(QListView *parent, QListViewItem *after) 2081KListViewItem::KListViewItem(QListView *parent, QListViewItem *after)
2082 : QListViewItem(parent, after) 2082 : QListViewItem(parent, after)
2083{ 2083{
2084 init(); 2084 init();
2085} 2085}
2086 2086
2087KListViewItem::KListViewItem(QListViewItem *parent, QListViewItem *after) 2087KListViewItem::KListViewItem(QListViewItem *parent, QListViewItem *after)
2088 : QListViewItem(parent, after) 2088 : QListViewItem(parent, after)
2089{ 2089{
2090 init(); 2090 init();
2091} 2091}
2092 2092
2093KListViewItem::KListViewItem(QListView *parent, 2093KListViewItem::KListViewItem(QListView *parent,
2094 QString label1, QString label2, QString label3, QString label4, 2094 QString label1, QString label2, QString label3, QString label4,
2095 QString label5, QString label6, QString label7, QString label8) 2095 QString label5, QString label6, QString label7, QString label8)
2096 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) 2096 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
2097{ 2097{
2098 init(); 2098 init();
2099} 2099}
2100 2100
2101KListViewItem::KListViewItem(QListViewItem *parent, 2101KListViewItem::KListViewItem(QListViewItem *parent,
2102 QString label1, QString label2, QString label3, QString label4, 2102 QString label1, QString label2, QString label3, QString label4,
2103 QString label5, QString label6, QString label7, QString label8) 2103 QString label5, QString label6, QString label7, QString label8)
2104 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) 2104 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
2105{ 2105{
2106 init(); 2106 init();
2107} 2107}
2108 2108
2109KListViewItem::KListViewItem(QListView *parent, QListViewItem *after, 2109KListViewItem::KListViewItem(QListView *parent, QListViewItem *after,
2110 QString label1, QString label2, QString label3, QString label4, 2110 QString label1, QString label2, QString label3, QString label4,
2111 QString label5, QString label6, QString label7, QString label8) 2111 QString label5, QString label6, QString label7, QString label8)
2112 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) 2112 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
2113{ 2113{
2114 init(); 2114 init();
2115} 2115}
2116 2116
2117KListViewItem::KListViewItem(QListViewItem *parent, QListViewItem *after, 2117KListViewItem::KListViewItem(QListViewItem *parent, QListViewItem *after,
2118 QString label1, QString label2, QString label3, QString label4, 2118 QString label1, QString label2, QString label3, QString label4,
2119 QString label5, QString label6, QString label7, QString label8) 2119 QString label5, QString label6, QString label7, QString label8)
2120 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) 2120 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
2121{ 2121{
2122 init(); 2122 init();
2123} 2123}
2124 2124
2125KListViewItem::~KListViewItem() 2125KListViewItem::~KListViewItem()
2126{ 2126{
2127} 2127}
2128 2128
2129void KListViewItem::init() 2129void KListViewItem::init()
2130{ 2130{
2131 m_known = false; 2131 m_known = false;
2132} 2132}
2133 2133
2134const QColor &KListViewItem::backgroundColor() 2134const QColor &KListViewItem::backgroundColor()
2135{ 2135{
2136 if (isAlternate()) 2136 if (isAlternate())
2137 return static_cast< KListView* >(listView())->alternateBackground(); 2137 return static_cast< KListView* >(listView())->alternateBackground();
2138 return listView()->viewport()->colorGroup().base(); 2138 return listView()->viewport()->colorGroup().base();
2139} 2139}
2140 2140
2141bool KListViewItem::isAlternate() 2141bool KListViewItem::isAlternate()
2142{ 2142{
2143 KListView *lv = static_cast<KListView *>(listView()); 2143 KListView *lv = static_cast<KListView *>(listView());
2144 if (lv && lv->alternateBackground().isValid()) 2144 if (lv && lv->alternateBackground().isValid())
2145 { 2145 {
2146 KListViewItem *above = 0; 2146 KListViewItem *above = 0;
2147//US above = dynamic_cast<KListViewItem *>(itemAbove()); 2147//US above = dynamic_cast<KListViewItem *>(itemAbove());
2148 above = (KListViewItem *)(itemAbove()); 2148 above = (KListViewItem *)(itemAbove());
2149 m_known = above ? above->m_known : true; 2149 m_known = above ? above->m_known : true;
2150 if (m_known) 2150 if (m_known)
2151 { 2151 {
2152 m_odd = above ? !above->m_odd : false; 2152 m_odd = above ? !above->m_odd : false;
2153 } 2153 }
2154 else 2154 else
2155 { 2155 {
2156 KListViewItem *item; 2156 KListViewItem *item;
2157 bool previous = true; 2157 bool previous = true;
2158 if (parent()) 2158 if (parent())
2159 { 2159 {
2160//US item = dynamic_cast<KListViewItem *>(parent()); 2160//US item = dynamic_cast<KListViewItem *>(parent());
2161 item = (KListViewItem *)(parent()); 2161 item = (KListViewItem *)(parent());
2162 if (item) 2162 if (item)
2163 previous = item->m_odd; 2163 previous = item->m_odd;
2164//US item = dynamic_cast<KListViewItem *>(parent()->firstChild()); 2164//US item = dynamic_cast<KListViewItem *>(parent()->firstChild());
2165 item = (KListViewItem *)(parent()->firstChild()); 2165 item = (KListViewItem *)(parent()->firstChild());
2166 } 2166 }
2167 else 2167 else
2168 { 2168 {
2169//US item = dynamic_cast<KListViewItem *>(lv->firstChild()); 2169//US item = dynamic_cast<KListViewItem *>(lv->firstChild());
2170 item = (KListViewItem *)(lv->firstChild()); 2170 item = (KListViewItem *)(lv->firstChild());
2171 } 2171 }
2172 2172
2173 while(item) 2173 while(item)
2174 { 2174 {
2175 item->m_odd = previous = !previous; 2175 item->m_odd = previous = !previous;
2176 item->m_known = true; 2176 item->m_known = true;
2177//US item = dynamic_cast<KListViewItem *>(item->nextSibling()); 2177//US item = dynamic_cast<KListViewItem *>(item->nextSibling());
2178 item = (KListViewItem *)(item->nextSibling()); 2178 item = (KListViewItem *)(item->nextSibling());
2179 } 2179 }
2180 } 2180 }
2181 return m_odd; 2181 return m_odd;
2182 } 2182 }
2183 return false; 2183 return false;
2184} 2184}
2185 2185
2186void KListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) 2186void KListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
2187{ 2187{
2188 QColorGroup _cg = cg; 2188 QColorGroup _cg = cg;
2189 const QPixmap *pm = listView()->viewport()->backgroundPixmap(); 2189 const QPixmap *pm = listView()->viewport()->backgroundPixmap();
2190 if (pm && !pm->isNull()) 2190 if (pm && !pm->isNull())
2191 { 2191 {
2192 _cg.setBrush(QColorGroup::Base, QBrush(backgroundColor(), *pm)); 2192 _cg.setBrush(QColorGroup::Base, QBrush(backgroundColor(), *pm));
2193 QPoint o = p->brushOrigin(); 2193 QPoint o = p->brushOrigin();
2194 p->setBrushOrigin( o.x()-listView()->contentsX(), o.y()-listView()->contentsY() ); 2194 p->setBrushOrigin( o.x()-listView()->contentsX(), o.y()-listView()->contentsY() );
2195 } 2195 }
2196 else if (isAlternate()) { 2196 else if (isAlternate()) {
2197//US if (listView()->viewport()->backgroundMode()==Qt::FixedColor) 2197//US if (listView()->viewport()->backgroundMode()==Qt::FixedColor)
2198 if (listView()->viewport()->backgroundMode()==QWidget::PaletteBackground) 2198 if (listView()->viewport()->backgroundMode()==QWidget::PaletteBackground)
2199 _cg.setColor(QColorGroup::Background, static_cast< KListView* >(listView())->alternateBackground()); 2199 _cg.setColor(QColorGroup::Background, static_cast< KListView* >(listView())->alternateBackground());
2200 else 2200 else
2201 _cg.setColor(QColorGroup::Base, static_cast< KListView* >(listView())->alternateBackground()); 2201 _cg.setColor(QColorGroup::Base, static_cast< KListView* >(listView())->alternateBackground());
2202 } 2202 }
2203 QListViewItem::paintCell(p, _cg, column, width, alignment); 2203 QListViewItem::paintCell(p, _cg, column, width, alignment);
2204} 2204}
2205 2205
2206//US we do not have a "global KDE" variable to setup singleClick functionality 2206//US we do not have a "global KDE" variable to setup singleClick functionality
2207void KListView::setSingleClick(bool s) 2207void KListView::setSingleClick(bool s)
2208{ 2208{
2209 d->bUseSingle = s; 2209 d->bUseSingle = s;
2210 slotSettingsChanged(1); 2210 slotSettingsChanged(1);
2211 // qDebug("KListView::setSingleClick: single %i", d->bUseSingle); 2211 // qDebug("KListView::setSingleClick: single %i", d->bUseSingle);
2212} 2212}
2213 2213
2214 2214
2215void KListView::virtual_hook( int, void* ) 2215void KListView::virtual_hook( int, void* )
2216{ /*BASE::virtual_hook( id, data );*/ } 2216{ /*BASE::virtual_hook( id, data );*/ }
2217 2217
2218//US #include "klistview.moc" 2218//US #include "klistview.moc"
2219//US #include "klistviewlineedit.moc" 2219//US #include "klistviewlineedit.moc"
2220 2220
2221// vim: ts=2 sw=2 et 2221// vim: ts=2 sw=2 et