author | zautrix <zautrix> | 2005-06-30 05:09:00 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-06-30 05:09:00 (UTC) |
commit | 4e850fa7aa99f92676e49466cfccaa5d5e0ec24c (patch) (unidiff) | |
tree | 5f0149a356274f475268df69a09a1a63345e9b22 | |
parent | ba4a6a95356f9a8044257c45347cee8b15667d0c (diff) | |
download | kdepimpi-4e850fa7aa99f92676e49466cfccaa5d5e0ec24c.zip kdepimpi-4e850fa7aa99f92676e49466cfccaa5d5e0ec24c.tar.gz kdepimpi-4e850fa7aa99f92676e49466cfccaa5d5e0ec24c.tar.bz2 |
fix
-rw-r--r-- | microkde/kdeui/klistview.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/microkde/kdeui/klistview.cpp b/microkde/kdeui/klistview.cpp index f7d2187..60f3084 100644 --- a/microkde/kdeui/klistview.cpp +++ b/microkde/kdeui/klistview.cpp | |||
@@ -1,1251 +1,1251 @@ | |||
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 |
51 | class KListView::Tooltip : public QToolTip | 51 | class KListView::Tooltip : public QToolTip |
52 | { | 52 | { |
53 | public: | 53 | public: |
54 | Tooltip (KListView* parent, QToolTipGroup* group = 0L); | 54 | Tooltip (KListView* parent, QToolTipGroup* group = 0L); |
55 | virtual ~Tooltip () {} | 55 | virtual ~Tooltip () {} |
56 | 56 | ||
57 | protected: | 57 | protected: |
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 | ||
65 | private: | 65 | private: |
66 | KListView* mParent; | 66 | KListView* mParent; |
67 | }; | 67 | }; |
68 | 68 | ||
69 | KListView::Tooltip::Tooltip (KListView* parent, QToolTipGroup* group) | 69 | KListView::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 | ||
75 | void KListView::Tooltip::maybeTip (const QPoint&) | 75 | void KListView::Tooltip::maybeTip (const QPoint&) |
76 | { | 76 | { |
77 | // FIXME | 77 | // FIXME |
78 | } | 78 | } |
79 | // */ | 79 | // */ |
80 | 80 | ||
81 | class KListView::KListViewPrivate | 81 | class KListView::KListViewPrivate |
82 | { | 82 | { |
83 | public: | 83 | public: |
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 |
180 | KListViewLineEdit::KListViewLineEdit(KListView *parent) | 180 | KListViewLineEdit::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 | ||
188 | KListViewLineEdit::~KListViewLineEdit() | 188 | KListViewLineEdit::~KListViewLineEdit() |
189 | { | 189 | { |
190 | } | 190 | } |
191 | 191 | ||
192 | void KListViewLineEdit::load(QListViewItem *i, int c) | 192 | void 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 | ||
229 | static int nextCol (KListView *pl, QListViewItem *pi, int start, int dir) | 229 | static 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 | ||
242 | static QListViewItem *prevItem (QListViewItem *pi) | 242 | static 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 | ||
255 | static QListViewItem *lastQChild (QListViewItem *pi) | 255 | static 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 |
270 | void KListViewLineEdit::selectNextCell (QListViewItem *pitem, int column, bool forward) | 270 | void 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 | ||
323 | bool KListViewLineEdit::event (QEvent *pe) | 323 | bool 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 | ||
342 | void KListViewLineEdit::keyPressEvent(QKeyEvent *e) | 342 | void 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 | ||
357 | void KListViewLineEdit::terminate() | 357 | void KListViewLineEdit::terminate() |
358 | { | 358 | { |
359 | terminate(true); | 359 | terminate(true); |
360 | } | 360 | } |
361 | 361 | ||
362 | void KListViewLineEdit::terminate(bool commit) | 362 | void 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 | ||
378 | void KListViewLineEdit::focusOutEvent(QFocusEvent *ev) | 378 | void 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 | ||
386 | void KListViewLineEdit::paintEvent( QPaintEvent *e ) | 386 | void 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". |
400 | void KListViewLineEdit::slotSelectionChanged() | 400 | void 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 | ||
408 | KListView::KListView( QWidget *parent, const char *name ,bool emulateRightMouse ) | 408 | KListView::KListView( QWidget *parent, const char *name ,bool emulateRightMouse ) |
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 | if ( emulateRightMouse ) | 413 | if ( emulateRightMouse ) |
414 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); | 414 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); |
415 | #endif | 415 | #endif |
416 | //US setDragAutoScroll(true); | 416 | //US setDragAutoScroll(true); |
417 | 417 | ||
418 | connect( this, SIGNAL( onViewport() ), | 418 | connect( this, SIGNAL( onViewport() ), |
419 | this, SLOT( slotOnViewport() ) ); | 419 | this, SLOT( slotOnViewport() ) ); |
420 | connect( this, SIGNAL( onItem( QListViewItem * ) ), | 420 | connect( this, SIGNAL( onItem( QListViewItem * ) ), |
421 | this, SLOT( slotOnItem( QListViewItem * ) ) ); | 421 | this, SLOT( slotOnItem( QListViewItem * ) ) ); |
422 | 422 | ||
423 | connect (this, SIGNAL(contentsMoving(int,int)), | 423 | connect (this, SIGNAL(contentsMoving(int,int)), |
424 | this, SLOT(cleanDropVisualizer())); | 424 | this, SLOT(cleanDropVisualizer())); |
425 | connect (this, SIGNAL(contentsMoving(int,int)), | 425 | connect (this, SIGNAL(contentsMoving(int,int)), |
426 | this, SLOT(cleanItemHighlighter())); | 426 | this, SLOT(cleanItemHighlighter())); |
427 | 427 | ||
428 | /*US | 428 | /*US |
429 | slotSettingsChanged(KApplication::SETTINGS_MOUSE); | 429 | slotSettingsChanged(KApplication::SETTINGS_MOUSE); |
430 | 430 | ||
431 | if (kapp) | 431 | if (kapp) |
432 | { | 432 | { |
433 | connect( kapp, SIGNAL( settingsChanged(int) ), SLOT( slotSettingsChanged(int) ) ); | 433 | connect( kapp, SIGNAL( settingsChanged(int) ), SLOT( slotSettingsChanged(int) ) ); |
434 | kapp->addKipcEventMask( KIPC::SettingsChanged ); | 434 | kapp->addKipcEventMask( KIPC::SettingsChanged ); |
435 | } | 435 | } |
436 | */ | 436 | */ |
437 | slotSettingsChanged(1); //US do this to initialize the connections | 437 | slotSettingsChanged(1); //US do this to initialize the connections |
438 | 438 | ||
439 | 439 | ||
440 | connect(&d->autoSelect, SIGNAL( timeout() ), | 440 | connect(&d->autoSelect, SIGNAL( timeout() ), |
441 | this, SLOT( slotAutoSelect() ) ); | 441 | this, SLOT( slotAutoSelect() ) ); |
442 | connect(&d->dragExpand, SIGNAL( timeout() ), | 442 | connect(&d->dragExpand, SIGNAL( timeout() ), |
443 | this, SLOT( slotDragExpand() ) ); | 443 | this, SLOT( slotDragExpand() ) ); |
444 | 444 | ||
445 | // context menu handling | 445 | // context menu handling |
446 | if (d->showContextMenusOnPress) | 446 | if (d->showContextMenusOnPress) |
447 | { | 447 | { |
448 | connect (this, SIGNAL (rightButtonPressed (QListViewItem*, const QPoint&, int)), | 448 | connect (this, SIGNAL (rightButtonPressed (QListViewItem*, const QPoint&, int)), |
449 | this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); | 449 | this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); |
450 | } | 450 | } |
451 | else | 451 | else |
452 | { | 452 | { |
453 | connect (this, SIGNAL (rightButtonClicked (QListViewItem*, const QPoint&, int)), | 453 | connect (this, SIGNAL (rightButtonClicked (QListViewItem*, const QPoint&, int)), |
454 | this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); | 454 | this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); |
455 | } | 455 | } |
456 | 456 | ||
457 | connect (this, SIGNAL (menuShortCutPressed (KListView*, QListViewItem*)), | 457 | connect (this, SIGNAL (menuShortCutPressed (KListView*, QListViewItem*)), |
458 | this, SLOT (emitContextMenu (KListView*, QListViewItem*))); | 458 | this, SLOT (emitContextMenu (KListView*, QListViewItem*))); |
459 | 459 | ||
460 | 460 | ||
461 | //qDebug("KListView::KListView make alternate color configurable"); | 461 | //qDebug("KListView::KListView make alternate color configurable"); |
462 | d->alternateBackground = KGlobalSettings::alternateBackgroundColor(); | 462 | d->alternateBackground = KGlobalSettings::alternateBackgroundColor(); |
463 | } | 463 | } |
464 | 464 | ||
465 | 465 | ||
466 | 466 | ||
467 | KListView::~KListView() | 467 | KListView::~KListView() |
468 | { | 468 | { |
469 | delete d; | 469 | delete d; |
470 | } | 470 | } |
471 | 471 | ||
472 | bool KListView::isExecuteArea( const QPoint& point ) | 472 | bool 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 | QSize KListView::sizeHint() const | 479 | QSize KListView::sizeHint() const |
480 | { | 480 | { |
481 | //qDebug("KListView::QSize sizeHint() "); | 481 | //qDebug("KListView::QSize sizeHint() "); |
482 | #ifdef DESKTOP_VERSION | 482 | #ifdef DESKTOP_VERSION |
483 | QListView::sizeHint(); | 483 | return QListView::sizeHint(); |
484 | #else | 484 | #else |
485 | return QSize ( 40, 40 ); | 485 | return QSize ( 40, 40 ); |
486 | #endif | 486 | #endif |
487 | 487 | ||
488 | } | 488 | } |
489 | bool KListView::isExecuteArea( int x ) | 489 | bool KListView::isExecuteArea( int x ) |
490 | { | 490 | { |
491 | if( allColumnsShowFocus() ) | 491 | if( allColumnsShowFocus() ) |
492 | return true; | 492 | return true; |
493 | else { | 493 | else { |
494 | int offset = 0; | 494 | int offset = 0; |
495 | int width = columnWidth( 0 ); | 495 | int width = columnWidth( 0 ); |
496 | int pos = header()->mapToIndex( 0 ); | 496 | int pos = header()->mapToIndex( 0 ); |
497 | 497 | ||
498 | for ( int index = 0; index < pos; index++ ) | 498 | for ( int index = 0; index < pos; index++ ) |
499 | offset += columnWidth( header()->mapToSection( index ) ); | 499 | offset += columnWidth( header()->mapToSection( index ) ); |
500 | 500 | ||
501 | x += contentsX(); // in case of a horizontal scrollbar | 501 | x += contentsX(); // in case of a horizontal scrollbar |
502 | return ( x > offset && x < ( offset + width ) ); | 502 | return ( x > offset && x < ( offset + width ) ); |
503 | } | 503 | } |
504 | } | 504 | } |
505 | 505 | ||
506 | void KListView::slotOnItem( QListViewItem *item ) | 506 | void KListView::slotOnItem( QListViewItem *item ) |
507 | { | 507 | { |
508 | QPoint vp = viewport()->mapFromGlobal( QCursor::pos() ); | 508 | QPoint vp = viewport()->mapFromGlobal( QCursor::pos() ); |
509 | if ( item && isExecuteArea( vp.x() ) && (d->autoSelectDelay > -1) && d->bUseSingle ) { | 509 | if ( item && isExecuteArea( vp.x() ) && (d->autoSelectDelay > -1) && d->bUseSingle ) { |
510 | d->autoSelect.start( d->autoSelectDelay, true ); | 510 | d->autoSelect.start( d->autoSelectDelay, true ); |
511 | d->pCurrentItem = item; | 511 | d->pCurrentItem = item; |
512 | } | 512 | } |
513 | } | 513 | } |
514 | 514 | ||
515 | void KListView::slotOnViewport() | 515 | void KListView::slotOnViewport() |
516 | { | 516 | { |
517 | if ( d->bChangeCursorOverItem ) | 517 | if ( d->bChangeCursorOverItem ) |
518 | viewport()->unsetCursor(); | 518 | viewport()->unsetCursor(); |
519 | 519 | ||
520 | d->autoSelect.stop(); | 520 | d->autoSelect.stop(); |
521 | d->pCurrentItem = 0L; | 521 | d->pCurrentItem = 0L; |
522 | } | 522 | } |
523 | 523 | ||
524 | void KListView::slotSettingsChanged(int category) | 524 | void KListView::slotSettingsChanged(int category) |
525 | { | 525 | { |
526 | //qDebug("KListView::slotSettingsChanged has to be verified"); | 526 | //qDebug("KListView::slotSettingsChanged has to be verified"); |
527 | 527 | ||
528 | 528 | ||
529 | switch (category) | 529 | switch (category) |
530 | { | 530 | { |
531 | //US I create my private category (=1) to set the settings | 531 | //US I create my private category (=1) to set the settings |
532 | case 1: | 532 | case 1: |
533 | d->dragDelay = 2; | 533 | d->dragDelay = 2; |
534 | //US set explicitly d->bUseSingle = KGlobalSettings::singleClick(); | 534 | //US set explicitly d->bUseSingle = KGlobalSettings::singleClick(); |
535 | // qDebug("KListView::slotSettingsChanged: single%i", d->bUseSingle); | 535 | // qDebug("KListView::slotSettingsChanged: single%i", d->bUseSingle); |
536 | 536 | ||
537 | disconnect(this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), | 537 | disconnect(this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), |
538 | this, SLOT (slotMouseButtonClicked (int, QListViewItem*, const QPoint &, int))); | 538 | this, SLOT (slotMouseButtonClicked (int, QListViewItem*, const QPoint &, int))); |
539 | 539 | ||
540 | if( d->bUseSingle ) | 540 | if( d->bUseSingle ) |
541 | connect (this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), | 541 | connect (this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), |
542 | this, SLOT (slotMouseButtonClicked( int, QListViewItem*, const QPoint &, int))); | 542 | this, SLOT (slotMouseButtonClicked( int, QListViewItem*, const QPoint &, int))); |
543 | 543 | ||
544 | //US d->bChangeCursorOverItem = KGlobalSettings::changeCursorOverIcon(); | 544 | //US d->bChangeCursorOverItem = KGlobalSettings::changeCursorOverIcon(); |
545 | //US d->autoSelectDelay = KGlobalSettings::autoSelectDelay(); | 545 | //US d->autoSelectDelay = KGlobalSettings::autoSelectDelay(); |
546 | 546 | ||
547 | if( !d->bUseSingle || !d->bChangeCursorOverItem ) | 547 | if( !d->bUseSingle || !d->bChangeCursorOverItem ) |
548 | viewport()->unsetCursor(); | 548 | viewport()->unsetCursor(); |
549 | 549 | ||
550 | break; | 550 | break; |
551 | 551 | ||
552 | /*US | 552 | /*US |
553 | case KApplication::SETTINGS_MOUSE: | 553 | case KApplication::SETTINGS_MOUSE: |
554 | d->dragDelay = KGlobalSettings::dndEventDelay(); | 554 | d->dragDelay = KGlobalSettings::dndEventDelay(); |
555 | d->bUseSingle = KGlobalSettings::singleClick(); | 555 | d->bUseSingle = KGlobalSettings::singleClick(); |
556 | 556 | ||
557 | disconnect(this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), | 557 | disconnect(this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), |
558 | this, SLOT (slotMouseButtonClicked (int, QListViewItem*, const QPoint &, int))); | 558 | this, SLOT (slotMouseButtonClicked (int, QListViewItem*, const QPoint &, int))); |
559 | 559 | ||
560 | if( d->bUseSingle ) | 560 | if( d->bUseSingle ) |
561 | connect (this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), | 561 | connect (this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)), |
562 | this, SLOT (slotMouseButtonClicked( int, QListViewItem*, const QPoint &, int))); | 562 | this, SLOT (slotMouseButtonClicked( int, QListViewItem*, const QPoint &, int))); |
563 | 563 | ||
564 | d->bChangeCursorOverItem = KGlobalSettings::changeCursorOverIcon(); | 564 | d->bChangeCursorOverItem = KGlobalSettings::changeCursorOverIcon(); |
565 | d->autoSelectDelay = KGlobalSettings::autoSelectDelay(); | 565 | d->autoSelectDelay = KGlobalSettings::autoSelectDelay(); |
566 | 566 | ||
567 | if( !d->bUseSingle || !d->bChangeCursorOverItem ) | 567 | if( !d->bUseSingle || !d->bChangeCursorOverItem ) |
568 | viewport()->unsetCursor(); | 568 | viewport()->unsetCursor(); |
569 | 569 | ||
570 | break; | 570 | break; |
571 | case KApplication::SETTINGS_POPUPMENU: | 571 | case KApplication::SETTINGS_POPUPMENU: |
572 | d->contextMenuKey = KGlobalSettings::contextMenuKey (); | 572 | d->contextMenuKey = KGlobalSettings::contextMenuKey (); |
573 | d->showContextMenusOnPress = KGlobalSettings::showContextMenusOnPress (); | 573 | d->showContextMenusOnPress = KGlobalSettings::showContextMenusOnPress (); |
574 | 574 | ||
575 | if (d->showContextMenusOnPress) | 575 | if (d->showContextMenusOnPress) |
576 | { | 576 | { |
577 | disconnect (0L, 0L, this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); | 577 | disconnect (0L, 0L, this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); |
578 | 578 | ||
579 | connect(this, SIGNAL (rightButtonPressed (QListViewItem*, const QPoint&, int)), | 579 | connect(this, SIGNAL (rightButtonPressed (QListViewItem*, const QPoint&, int)), |
580 | this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); | 580 | this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); |
581 | } | 581 | } |
582 | else | 582 | else |
583 | { | 583 | { |
584 | disconnect (0L, 0L, this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); | 584 | disconnect (0L, 0L, this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); |
585 | 585 | ||
586 | connect(this, SIGNAL (rightButtonClicked (QListViewItem*, const QPoint&, int)), | 586 | connect(this, SIGNAL (rightButtonClicked (QListViewItem*, const QPoint&, int)), |
587 | this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); | 587 | this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int))); |
588 | } | 588 | } |
589 | break; | 589 | break; |
590 | */ | 590 | */ |
591 | 591 | ||
592 | default: | 592 | default: |
593 | break; | 593 | break; |
594 | } | 594 | } |
595 | 595 | ||
596 | } | 596 | } |
597 | 597 | ||
598 | void KListView::slotAutoSelect() | 598 | void KListView::slotAutoSelect() |
599 | { | 599 | { |
600 | // check that the item still exists | 600 | // check that the item still exists |
601 | if( itemIndex( d->pCurrentItem ) == -1 ) | 601 | if( itemIndex( d->pCurrentItem ) == -1 ) |
602 | return; | 602 | return; |
603 | 603 | ||
604 | if (!isActiveWindow()) | 604 | if (!isActiveWindow()) |
605 | { | 605 | { |
606 | d->autoSelect.stop(); | 606 | d->autoSelect.stop(); |
607 | return; | 607 | return; |
608 | } | 608 | } |
609 | 609 | ||
610 | //Give this widget the keyboard focus. | 610 | //Give this widget the keyboard focus. |
611 | if( !hasFocus() ) | 611 | if( !hasFocus() ) |
612 | setFocus(); | 612 | setFocus(); |
613 | 613 | ||
614 | QListViewItem* previousItem = currentItem(); | 614 | QListViewItem* previousItem = currentItem(); |
615 | setCurrentItem( d->pCurrentItem ); | 615 | setCurrentItem( d->pCurrentItem ); |
616 | 616 | ||
617 | #if 0 | 617 | #if 0 |
618 | #ifndef Q_WS_QWS | 618 | #ifndef Q_WS_QWS |
619 | // FIXME(E): Implement for Qt Embedded | 619 | // FIXME(E): Implement for Qt Embedded |
620 | if( d->pCurrentItem ) { | 620 | if( d->pCurrentItem ) { |
621 | //Shift pressed? | 621 | //Shift pressed? |
622 | if( (keybstate & ShiftMask) ) { | 622 | if( (keybstate & ShiftMask) ) { |
623 | bool block = signalsBlocked(); | 623 | bool block = signalsBlocked(); |
624 | blockSignals( true ); | 624 | blockSignals( true ); |
625 | 625 | ||
626 | //No Ctrl? Then clear before! | 626 | //No Ctrl? Then clear before! |
627 | if( !(keybstate & ControlMask) ) | 627 | if( !(keybstate & ControlMask) ) |
628 | clearSelection(); | 628 | clearSelection(); |
629 | 629 | ||
630 | bool select = !d->pCurrentItem->isSelected(); | 630 | bool select = !d->pCurrentItem->isSelected(); |
631 | bool update = viewport()->isUpdatesEnabled(); | 631 | bool update = viewport()->isUpdatesEnabled(); |
632 | viewport()->setUpdatesEnabled( false ); | 632 | viewport()->setUpdatesEnabled( false ); |
633 | 633 | ||
634 | bool down = previousItem->itemPos() < d->pCurrentItem->itemPos(); | 634 | bool down = previousItem->itemPos() < d->pCurrentItem->itemPos(); |
635 | QListViewItemIterator lit( down ? previousItem : d->pCurrentItem ); | 635 | QListViewItemIterator lit( down ? previousItem : d->pCurrentItem ); |
636 | for ( ; lit.current(); ++lit ) { | 636 | for ( ; lit.current(); ++lit ) { |
637 | if ( down && lit.current() == d->pCurrentItem ) { | 637 | if ( down && lit.current() == d->pCurrentItem ) { |
638 | d->pCurrentItem->setSelected( select ); | 638 | d->pCurrentItem->setSelected( select ); |
639 | break; | 639 | break; |
640 | } | 640 | } |
641 | if ( !down && lit.current() == previousItem ) { | 641 | if ( !down && lit.current() == previousItem ) { |
642 | previousItem->setSelected( select ); | 642 | previousItem->setSelected( select ); |
643 | break; | 643 | break; |
644 | } | 644 | } |
645 | lit.current()->setSelected( select ); | 645 | lit.current()->setSelected( select ); |
646 | } | 646 | } |
647 | 647 | ||
648 | blockSignals( block ); | 648 | blockSignals( block ); |
649 | viewport()->setUpdatesEnabled( update ); | 649 | viewport()->setUpdatesEnabled( update ); |
650 | triggerUpdate(); | 650 | triggerUpdate(); |
651 | 651 | ||
652 | emit selectionChanged(); | 652 | emit selectionChanged(); |
653 | 653 | ||
654 | if( selectionMode() == QListView::Single ) | 654 | if( selectionMode() == QListView::Single ) |
655 | emit selectionChanged( d->pCurrentItem ); | 655 | emit selectionChanged( d->pCurrentItem ); |
656 | } | 656 | } |
657 | else if( (keybstate & ControlMask) ) | 657 | else if( (keybstate & ControlMask) ) |
658 | setSelected( d->pCurrentItem, !d->pCurrentItem->isSelected() ); | 658 | setSelected( d->pCurrentItem, !d->pCurrentItem->isSelected() ); |
659 | else { | 659 | else { |
660 | bool block = signalsBlocked(); | 660 | bool block = signalsBlocked(); |
661 | blockSignals( true ); | 661 | blockSignals( true ); |
662 | 662 | ||
663 | if( !d->pCurrentItem->isSelected() ) | 663 | if( !d->pCurrentItem->isSelected() ) |
664 | clearSelection(); | 664 | clearSelection(); |
665 | 665 | ||
666 | blockSignals( block ); | 666 | blockSignals( block ); |
667 | 667 | ||
668 | setSelected( d->pCurrentItem, true ); | 668 | setSelected( d->pCurrentItem, true ); |
669 | } | 669 | } |
670 | } | 670 | } |
671 | else | 671 | else |
672 | kdDebug() << "KListView::slotAutoSelect: Thats not supposed to happen!!!!" << endl; | 672 | kdDebug() << "KListView::slotAutoSelect: Thats not supposed to happen!!!!" << endl; |
673 | #endif | 673 | #endif |
674 | #endif | 674 | #endif |
675 | } | 675 | } |
676 | 676 | ||
677 | void KListView::slotHeaderChanged() | 677 | void KListView::slotHeaderChanged() |
678 | { | 678 | { |
679 | if (d->fullWidth && columns()) | 679 | if (d->fullWidth && columns()) |
680 | { | 680 | { |
681 | int w = 0; | 681 | int w = 0; |
682 | for (int i = 0; i < columns() - 1; ++i) w += columnWidth(i); | 682 | for (int i = 0; i < columns() - 1; ++i) w += columnWidth(i); |
683 | setColumnWidth( columns() - 1, viewport()->width() - w - 1 ); | 683 | setColumnWidth( columns() - 1, viewport()->width() - w - 1 ); |
684 | } | 684 | } |
685 | } | 685 | } |
686 | 686 | ||
687 | void KListView::emitExecute( int buttonstate, QListViewItem *item, const QPoint &pos, int c) | 687 | void KListView::emitExecute( int buttonstate, QListViewItem *item, const QPoint &pos, int c) |
688 | { | 688 | { |
689 | // qDebug("KListView::emitExecute buttonstate=%i", buttonstate); | 689 | // qDebug("KListView::emitExecute buttonstate=%i", buttonstate); |
690 | if( isExecuteArea( viewport()->mapFromGlobal(pos) ) ) { | 690 | if( isExecuteArea( viewport()->mapFromGlobal(pos) ) ) { |
691 | 691 | ||
692 | // Double click mode ? | 692 | // Double click mode ? |
693 | if ( !d->bUseSingle ) | 693 | if ( !d->bUseSingle ) |
694 | { | 694 | { |
695 | emit executed( item ); | 695 | emit executed( item ); |
696 | emit executed( item, pos, c ); | 696 | emit executed( item, pos, c ); |
697 | } | 697 | } |
698 | else | 698 | else |
699 | { | 699 | { |
700 | //US special implementation for embedded systems | 700 | //US special implementation for embedded systems |
701 | d->autoSelect.stop(); | 701 | d->autoSelect.stop(); |
702 | 702 | ||
703 | //Dont emit executed if in SC mode and Shift or Ctrl are pressed | 703 | //Dont emit executed if in SC mode and Shift or Ctrl are pressed |
704 | if( !( (buttonstate==ShiftButton) || (buttonstate==ControlButton) )) { | 704 | if( !( (buttonstate==ShiftButton) || (buttonstate==ControlButton) )) { |
705 | // if( !( ((keybstate & ShiftMask) || (keybstate & ControlMask)) ) ) { | 705 | // if( !( ((keybstate & ShiftMask) || (keybstate & ControlMask)) ) ) { |
706 | 706 | ||
707 | emit executed( item ); | 707 | emit executed( item ); |
708 | emit executed( item, pos, c ); | 708 | emit executed( item, pos, c ); |
709 | } | 709 | } |
710 | } | 710 | } |
711 | } | 711 | } |
712 | } | 712 | } |
713 | 713 | ||
714 | void KListView::focusInEvent( QFocusEvent *fe ) | 714 | void KListView::focusInEvent( QFocusEvent *fe ) |
715 | { | 715 | { |
716 | // kdDebug()<<"KListView::focusInEvent()"<<endl; | 716 | // kdDebug()<<"KListView::focusInEvent()"<<endl; |
717 | QListView::focusInEvent( fe ); | 717 | QListView::focusInEvent( fe ); |
718 | if ((d->selectedBySimpleMove) | 718 | if ((d->selectedBySimpleMove) |
719 | && (d->selectionMode == FileManager) | 719 | && (d->selectionMode == FileManager) |
720 | && (fe->reason()!=QFocusEvent::Popup) | 720 | && (fe->reason()!=QFocusEvent::Popup) |
721 | && (fe->reason()!=QFocusEvent::ActiveWindow) | 721 | && (fe->reason()!=QFocusEvent::ActiveWindow) |
722 | && (currentItem()!=0)) | 722 | && (currentItem()!=0)) |
723 | { | 723 | { |
724 | currentItem()->setSelected(true); | 724 | currentItem()->setSelected(true); |
725 | currentItem()->repaint(); | 725 | currentItem()->repaint(); |
726 | emit selectionChanged(); | 726 | emit selectionChanged(); |
727 | }; | 727 | }; |
728 | } | 728 | } |
729 | 729 | ||
730 | void KListView::focusOutEvent( QFocusEvent *fe ) | 730 | void KListView::focusOutEvent( QFocusEvent *fe ) |
731 | { | 731 | { |
732 | cleanDropVisualizer(); | 732 | cleanDropVisualizer(); |
733 | cleanItemHighlighter(); | 733 | cleanItemHighlighter(); |
734 | 734 | ||
735 | d->autoSelect.stop(); | 735 | d->autoSelect.stop(); |
736 | 736 | ||
737 | if ((d->selectedBySimpleMove) | 737 | if ((d->selectedBySimpleMove) |
738 | && (d->selectionMode == FileManager) | 738 | && (d->selectionMode == FileManager) |
739 | && (fe->reason()!=QFocusEvent::Popup) | 739 | && (fe->reason()!=QFocusEvent::Popup) |
740 | && (fe->reason()!=QFocusEvent::ActiveWindow) | 740 | && (fe->reason()!=QFocusEvent::ActiveWindow) |
741 | && (currentItem()!=0) | 741 | && (currentItem()!=0) |
742 | /*US && (!d->editor->isVisible()) */ | 742 | /*US && (!d->editor->isVisible()) */ |
743 | ) | 743 | ) |
744 | { | 744 | { |
745 | currentItem()->setSelected(false); | 745 | currentItem()->setSelected(false); |
746 | currentItem()->repaint(); | 746 | currentItem()->repaint(); |
747 | emit selectionChanged(); | 747 | emit selectionChanged(); |
748 | }; | 748 | }; |
749 | 749 | ||
750 | QListView::focusOutEvent( fe ); | 750 | QListView::focusOutEvent( fe ); |
751 | } | 751 | } |
752 | 752 | ||
753 | void KListView::leaveEvent( QEvent *e ) | 753 | void KListView::leaveEvent( QEvent *e ) |
754 | { | 754 | { |
755 | d->autoSelect.stop(); | 755 | d->autoSelect.stop(); |
756 | 756 | ||
757 | QListView::leaveEvent( e ); | 757 | QListView::leaveEvent( e ); |
758 | } | 758 | } |
759 | 759 | ||
760 | bool KListView::event( QEvent *e ) | 760 | bool KListView::event( QEvent *e ) |
761 | { | 761 | { |
762 | if (e->type() == QEvent::ApplicationPaletteChange) { | 762 | if (e->type() == QEvent::ApplicationPaletteChange) { |
763 | //qDebug("KListView::event make alternate color configurable"); | 763 | //qDebug("KListView::event make alternate color configurable"); |
764 | //US d->alternateBackground=KGlobalSettings::alternateBackgroundColor(); | 764 | //US d->alternateBackground=KGlobalSettings::alternateBackgroundColor(); |
765 | d->alternateBackground = QColor(240, 240, 240); | 765 | d->alternateBackground = QColor(240, 240, 240); |
766 | } | 766 | } |
767 | 767 | ||
768 | return QListView::event(e); | 768 | return QListView::event(e); |
769 | } | 769 | } |
770 | 770 | ||
771 | void KListView::contentsMousePressEvent( QMouseEvent *e ) | 771 | void KListView::contentsMousePressEvent( QMouseEvent *e ) |
772 | { | 772 | { |
773 | //qDebug("KListView::contentsMousePressEvent"); | 773 | //qDebug("KListView::contentsMousePressEvent"); |
774 | if( (selectionModeExt() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) ) | 774 | if( (selectionModeExt() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) ) |
775 | { | 775 | { |
776 | bool block = signalsBlocked(); | 776 | bool block = signalsBlocked(); |
777 | blockSignals( true ); | 777 | blockSignals( true ); |
778 | 778 | ||
779 | clearSelection(); | 779 | clearSelection(); |
780 | 780 | ||
781 | blockSignals( block ); | 781 | blockSignals( block ); |
782 | } | 782 | } |
783 | else if ((selectionModeExt()==FileManager) && (d->selectedBySimpleMove)) | 783 | else if ((selectionModeExt()==FileManager) && (d->selectedBySimpleMove)) |
784 | { | 784 | { |
785 | d->selectedBySimpleMove=false; | 785 | d->selectedBySimpleMove=false; |
786 | d->selectedUsingMouse=true; | 786 | d->selectedUsingMouse=true; |
787 | if (currentItem()!=0) | 787 | if (currentItem()!=0) |
788 | { | 788 | { |
789 | currentItem()->setSelected(false); | 789 | currentItem()->setSelected(false); |
790 | currentItem()->repaint(); | 790 | currentItem()->repaint(); |
791 | // emit selectionChanged(); | 791 | // emit selectionChanged(); |
792 | }; | 792 | }; |
793 | }; | 793 | }; |
794 | 794 | ||
795 | QPoint p( contentsToViewport( e->pos() ) ); | 795 | QPoint p( contentsToViewport( e->pos() ) ); |
796 | QListViewItem *at = itemAt (p); | 796 | QListViewItem *at = itemAt (p); |
797 | 797 | ||
798 | // true if the root decoration of the item "at" was clicked (i.e. the +/- sign) | 798 | // true if the root decoration of the item "at" was clicked (i.e. the +/- sign) |
799 | bool rootDecoClicked = at | 799 | bool rootDecoClicked = at |
800 | && ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) + | 800 | && ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) + |
801 | treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ) | 801 | treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ) |
802 | && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) ); | 802 | && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) ); |
803 | 803 | ||
804 | if (e->button() == LeftButton && !rootDecoClicked) | 804 | if (e->button() == LeftButton && !rootDecoClicked) |
805 | { | 805 | { |
806 | //Start a drag | 806 | //Start a drag |
807 | d->startDragPos = e->pos(); | 807 | d->startDragPos = e->pos(); |
808 | 808 | ||
809 | if (at) | 809 | if (at) |
810 | { | 810 | { |
811 | d->validDrag = true; | 811 | d->validDrag = true; |
812 | d->pressedOnSelected = at->isSelected(); | 812 | d->pressedOnSelected = at->isSelected(); |
813 | } | 813 | } |
814 | } | 814 | } |
815 | 815 | ||
816 | QListView::contentsMousePressEvent( e ); | 816 | QListView::contentsMousePressEvent( e ); |
817 | } | 817 | } |
818 | 818 | ||
819 | void KListView::contentsMouseMoveEvent( QMouseEvent *e ) | 819 | void KListView::contentsMouseMoveEvent( QMouseEvent *e ) |
820 | { | 820 | { |
821 | if (!dragEnabled() || d->startDragPos.isNull() || !d->validDrag) { | 821 | if (!dragEnabled() || d->startDragPos.isNull() || !d->validDrag) { |
822 | QListView::contentsMouseMoveEvent (e); | 822 | QListView::contentsMouseMoveEvent (e); |
823 | return; | 823 | return; |
824 | } | 824 | } |
825 | 825 | ||
826 | QPoint vp = contentsToViewport(e->pos()); | 826 | QPoint vp = contentsToViewport(e->pos()); |
827 | QListViewItem *item = itemAt( vp ); | 827 | QListViewItem *item = itemAt( vp ); |
828 | 828 | ||
829 | //do we process cursor changes at all? | 829 | //do we process cursor changes at all? |
830 | if ( item && d->bChangeCursorOverItem && d->bUseSingle ) | 830 | if ( item && d->bChangeCursorOverItem && d->bUseSingle ) |
831 | { | 831 | { |
832 | //Cursor moved on a new item or in/out the execute area | 832 | //Cursor moved on a new item or in/out the execute area |
833 | if( (item != d->pCurrentItem) || | 833 | if( (item != d->pCurrentItem) || |
834 | (isExecuteArea(vp) != d->cursorInExecuteArea) ) | 834 | (isExecuteArea(vp) != d->cursorInExecuteArea) ) |
835 | { | 835 | { |
836 | d->cursorInExecuteArea = isExecuteArea(vp); | 836 | d->cursorInExecuteArea = isExecuteArea(vp); |
837 | //qDebug("KListView::contentsMouseMoveEvent drag&drop not supported yet"); | 837 | //qDebug("KListView::contentsMouseMoveEvent drag&drop not supported yet"); |
838 | /*US | 838 | /*US |
839 | if( d->cursorInExecuteArea ) //cursor moved in execute area | 839 | if( d->cursorInExecuteArea ) //cursor moved in execute area |
840 | viewport()->setCursor( KCursor::handCursor() ); | 840 | viewport()->setCursor( KCursor::handCursor() ); |
841 | else //cursor moved out of execute area | 841 | else //cursor moved out of execute area |
842 | viewport()->unsetCursor(); | 842 | viewport()->unsetCursor(); |
843 | */ | 843 | */ |
844 | } | 844 | } |
845 | } | 845 | } |
846 | 846 | ||
847 | bool dragOn = dragEnabled(); | 847 | bool dragOn = dragEnabled(); |
848 | QPoint newPos = e->pos(); | 848 | QPoint newPos = e->pos(); |
849 | if (dragOn && d->validDrag && | 849 | if (dragOn && d->validDrag && |
850 | (newPos.x() > d->startDragPos.x()+d->dragDelay || | 850 | (newPos.x() > d->startDragPos.x()+d->dragDelay || |
851 | newPos.x() < d->startDragPos.x()-d->dragDelay || | 851 | newPos.x() < d->startDragPos.x()-d->dragDelay || |
852 | newPos.y() > d->startDragPos.y()+d->dragDelay || | 852 | newPos.y() > d->startDragPos.y()+d->dragDelay || |
853 | newPos.y() < d->startDragPos.y()-d->dragDelay)) | 853 | newPos.y() < d->startDragPos.y()-d->dragDelay)) |
854 | //(d->startDragPos - e->pos()).manhattanLength() > QApplication::startDragDistance()) | 854 | //(d->startDragPos - e->pos()).manhattanLength() > QApplication::startDragDistance()) |
855 | { | 855 | { |
856 | QListView::contentsMouseReleaseEvent( 0 ); | 856 | QListView::contentsMouseReleaseEvent( 0 ); |
857 | startDrag(); | 857 | startDrag(); |
858 | d->startDragPos = QPoint(); | 858 | d->startDragPos = QPoint(); |
859 | d->validDrag = false; | 859 | d->validDrag = false; |
860 | } | 860 | } |
861 | } | 861 | } |
862 | 862 | ||
863 | void KListView::contentsMouseReleaseEvent( QMouseEvent *e ) | 863 | void KListView::contentsMouseReleaseEvent( QMouseEvent *e ) |
864 | { | 864 | { |
865 | if (e->button() == LeftButton) | 865 | if (e->button() == LeftButton) |
866 | { | 866 | { |
867 | // If the row was already selected, maybe we want to start an in-place editing | 867 | // If the row was already selected, maybe we want to start an in-place editing |
868 | if ( d->pressedOnSelected && itemsRenameable() ) | 868 | if ( d->pressedOnSelected && itemsRenameable() ) |
869 | { | 869 | { |
870 | QPoint p( contentsToViewport( e->pos() ) ); | 870 | QPoint p( contentsToViewport( e->pos() ) ); |
871 | QListViewItem *at = itemAt (p); | 871 | QListViewItem *at = itemAt (p); |
872 | if ( at ) | 872 | if ( at ) |
873 | { | 873 | { |
874 | // true if the root decoration of the item "at" was clicked (i.e. the +/- sign) | 874 | // true if the root decoration of the item "at" was clicked (i.e. the +/- sign) |
875 | bool rootDecoClicked = | 875 | bool rootDecoClicked = |
876 | ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) + | 876 | ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) + |
877 | treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ) | 877 | treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ) |
878 | && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) ); | 878 | && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) ); |
879 | 879 | ||
880 | if (!rootDecoClicked) | 880 | if (!rootDecoClicked) |
881 | { | 881 | { |
882 | int col = header()->mapToLogical( header()->cellAt( p.x() ) ); | 882 | int col = header()->mapToLogical( header()->cellAt( p.x() ) ); |
883 | if ( d->renameable.contains(col) ) | 883 | if ( d->renameable.contains(col) ) |
884 | rename(at, col); | 884 | rename(at, col); |
885 | } | 885 | } |
886 | } | 886 | } |
887 | } | 887 | } |
888 | 888 | ||
889 | d->pressedOnSelected = false; | 889 | d->pressedOnSelected = false; |
890 | d->validDrag = false; | 890 | d->validDrag = false; |
891 | d->startDragPos = QPoint(); | 891 | d->startDragPos = QPoint(); |
892 | } | 892 | } |
893 | QListView::contentsMouseReleaseEvent( e ); | 893 | QListView::contentsMouseReleaseEvent( e ); |
894 | } | 894 | } |
895 | 895 | ||
896 | void KListView::contentsMouseDoubleClickEvent ( QMouseEvent *e ) | 896 | void KListView::contentsMouseDoubleClickEvent ( QMouseEvent *e ) |
897 | { | 897 | { |
898 | //qDebug("KListView::contentsMouseDoubleClickEvent"); | 898 | //qDebug("KListView::contentsMouseDoubleClickEvent"); |
899 | // We don't want to call the parent method because it does setOpen, | 899 | // We don't want to call the parent method because it does setOpen, |
900 | // whereas we don't do it in single click mode... (David) | 900 | // whereas we don't do it in single click mode... (David) |
901 | //QListView::contentsMouseDoubleClickEvent( e ); | 901 | //QListView::contentsMouseDoubleClickEvent( e ); |
902 | 902 | ||
903 | QPoint vp = contentsToViewport(e->pos()); | 903 | QPoint vp = contentsToViewport(e->pos()); |
904 | QListViewItem *item = itemAt( vp ); | 904 | QListViewItem *item = itemAt( vp ); |
905 | emit QListView::doubleClicked( item ); // we do it now | 905 | emit QListView::doubleClicked( item ); // we do it now |
906 | 906 | ||
907 | int col = item ? header()->mapToLogical( header()->cellAt( vp.x() ) ) : -1; | 907 | int col = item ? header()->mapToLogical( header()->cellAt( vp.x() ) ) : -1; |
908 | 908 | ||
909 | if( item ) { | 909 | if( item ) { |
910 | //qDebug("KListView::contentsMouseDoubleClickEvent: emit doubleClicked"); | 910 | //qDebug("KListView::contentsMouseDoubleClickEvent: emit doubleClicked"); |
911 | 911 | ||
912 | emit doubleClicked( item, e->globalPos(), col ); | 912 | emit doubleClicked( item, e->globalPos(), col ); |
913 | 913 | ||
914 | if( (e->button() == LeftButton) && !d->bUseSingle ) { | 914 | if( (e->button() == LeftButton) && !d->bUseSingle ) { |
915 | //qDebug("KListView::contentsMouseDoubleClickEvent: emitExecute"); | 915 | //qDebug("KListView::contentsMouseDoubleClickEvent: emitExecute"); |
916 | 916 | ||
917 | emitExecute( e->button(), item, e->globalPos(), col); | 917 | emitExecute( e->button(), item, e->globalPos(), col); |
918 | } | 918 | } |
919 | } | 919 | } |
920 | } | 920 | } |
921 | 921 | ||
922 | void KListView::slotMouseButtonClicked( int btn, QListViewItem *item, const QPoint &pos, int c ) | 922 | void KListView::slotMouseButtonClicked( int btn, QListViewItem *item, const QPoint &pos, int c ) |
923 | { | 923 | { |
924 | //qDebug("KListView::slotMouseButtonClicked"); | 924 | //qDebug("KListView::slotMouseButtonClicked"); |
925 | 925 | ||
926 | if( (btn == LeftButton) && item ) { | 926 | if( (btn == LeftButton) && item ) { |
927 | //qDebug("KListView::slotMouseButtonClicked: emitExecute"); | 927 | //qDebug("KListView::slotMouseButtonClicked: emitExecute"); |
928 | 928 | ||
929 | emitExecute(btn, item, pos, c); | 929 | emitExecute(btn, item, pos, c); |
930 | } | 930 | } |
931 | } | 931 | } |
932 | 932 | ||
933 | void KListView::contentsDropEvent(QDropEvent* e) | 933 | void KListView::contentsDropEvent(QDropEvent* e) |
934 | { | 934 | { |
935 | qDebug("KListView::contentsDropEvent drag&drop not supported yet"); | 935 | qDebug("KListView::contentsDropEvent drag&drop not supported yet"); |
936 | /*US | 936 | /*US |
937 | cleanDropVisualizer(); | 937 | cleanDropVisualizer(); |
938 | cleanItemHighlighter(); | 938 | cleanItemHighlighter(); |
939 | d->dragExpand.stop(); | 939 | d->dragExpand.stop(); |
940 | 940 | ||
941 | if (acceptDrag (e)) | 941 | if (acceptDrag (e)) |
942 | { | 942 | { |
943 | e->acceptAction(); | 943 | e->acceptAction(); |
944 | QListViewItem *afterme; | 944 | QListViewItem *afterme; |
945 | QListViewItem *parent; | 945 | QListViewItem *parent; |
946 | findDrop(e->pos(), parent, afterme); | 946 | findDrop(e->pos(), parent, afterme); |
947 | 947 | ||
948 | if (e->source() == viewport() && itemsMovable()) | 948 | if (e->source() == viewport() && itemsMovable()) |
949 | movableDropEvent(parent, afterme); | 949 | movableDropEvent(parent, afterme); |
950 | else | 950 | else |
951 | { | 951 | { |
952 | 952 | ||
953 | emit dropped(e, afterme); | 953 | emit dropped(e, afterme); |
954 | emit dropped(this, e, afterme); | 954 | emit dropped(this, e, afterme); |
955 | emit dropped(e, parent, afterme); | 955 | emit dropped(e, parent, afterme); |
956 | emit dropped(this, e, parent, afterme); | 956 | emit dropped(this, e, parent, afterme); |
957 | 957 | ||
958 | } | 958 | } |
959 | } | 959 | } |
960 | */ | 960 | */ |
961 | 961 | ||
962 | } | 962 | } |
963 | 963 | ||
964 | void KListView::movableDropEvent (QListViewItem* parent, QListViewItem* afterme) | 964 | void KListView::movableDropEvent (QListViewItem* parent, QListViewItem* afterme) |
965 | { | 965 | { |
966 | QPtrList<QListViewItem> items, afterFirsts, afterNows; | 966 | QPtrList<QListViewItem> items, afterFirsts, afterNows; |
967 | QListViewItem *current=currentItem(); | 967 | QListViewItem *current=currentItem(); |
968 | bool hasMoved=false; | 968 | bool hasMoved=false; |
969 | for (QListViewItem *i = firstChild(), *iNext=0; i != 0; i = iNext) | 969 | for (QListViewItem *i = firstChild(), *iNext=0; i != 0; i = iNext) |
970 | { | 970 | { |
971 | iNext=i->itemBelow(); | 971 | iNext=i->itemBelow(); |
972 | if (!i->isSelected()) | 972 | if (!i->isSelected()) |
973 | continue; | 973 | continue; |
974 | 974 | ||
975 | // don't drop an item after itself, or else | 975 | // don't drop an item after itself, or else |
976 | // it moves to the top of the list | 976 | // it moves to the top of the list |
977 | if (i==afterme) | 977 | if (i==afterme) |
978 | continue; | 978 | continue; |
979 | 979 | ||
980 | i->setSelected(false); | 980 | i->setSelected(false); |
981 | 981 | ||
982 | QListViewItem *afterFirst = i->itemAbove(); | 982 | QListViewItem *afterFirst = i->itemAbove(); |
983 | 983 | ||
984 | if (!hasMoved) | 984 | if (!hasMoved) |
985 | { | 985 | { |
986 | emit aboutToMove(); | 986 | emit aboutToMove(); |
987 | hasMoved=true; | 987 | hasMoved=true; |
988 | } | 988 | } |
989 | 989 | ||
990 | moveItem(i, parent, afterme); | 990 | moveItem(i, parent, afterme); |
991 | 991 | ||
992 | // ###### This should include the new parent !!! -> KDE 3.0 | 992 | // ###### This should include the new parent !!! -> KDE 3.0 |
993 | // If you need this right now, have a look at keditbookmarks. | 993 | // If you need this right now, have a look at keditbookmarks. |
994 | emit moved(i, afterFirst, afterme); | 994 | emit moved(i, afterFirst, afterme); |
995 | 995 | ||
996 | items.append (i); | 996 | items.append (i); |
997 | afterFirsts.append (afterFirst); | 997 | afterFirsts.append (afterFirst); |
998 | afterNows.append (afterme); | 998 | afterNows.append (afterme); |
999 | 999 | ||
1000 | afterme = i; | 1000 | afterme = i; |
1001 | } | 1001 | } |
1002 | clearSelection(); | 1002 | clearSelection(); |
1003 | for (QListViewItem *i=items.first(); i != 0; i=items.next() ) | 1003 | for (QListViewItem *i=items.first(); i != 0; i=items.next() ) |
1004 | i->setSelected(true); | 1004 | i->setSelected(true); |
1005 | if (current) | 1005 | if (current) |
1006 | setCurrentItem(current); | 1006 | setCurrentItem(current); |
1007 | 1007 | ||
1008 | emit moved(items,afterFirsts,afterNows); | 1008 | emit moved(items,afterFirsts,afterNows); |
1009 | 1009 | ||
1010 | if (firstChild()) | 1010 | if (firstChild()) |
1011 | emit moved(); | 1011 | emit moved(); |
1012 | } | 1012 | } |
1013 | 1013 | ||
1014 | void KListView::contentsDragMoveEvent(QDragMoveEvent *event) | 1014 | void KListView::contentsDragMoveEvent(QDragMoveEvent *event) |
1015 | { | 1015 | { |
1016 | qDebug("KListView::contentsDropEvent drag&drop not supported yet"); | 1016 | qDebug("KListView::contentsDropEvent drag&drop not supported yet"); |
1017 | /*US | 1017 | /*US |
1018 | if (acceptDrag(event)) | 1018 | if (acceptDrag(event)) |
1019 | { | 1019 | { |
1020 | event->acceptAction(); | 1020 | event->acceptAction(); |
1021 | //Clean up the view | 1021 | //Clean up the view |
1022 | 1022 | ||
1023 | findDrop(event->pos(), d->parentItemDrop, d->afterItemDrop); | 1023 | findDrop(event->pos(), d->parentItemDrop, d->afterItemDrop); |
1024 | QPoint vp = contentsToViewport( event->pos() ); | 1024 | QPoint vp = contentsToViewport( event->pos() ); |
1025 | QListViewItem *item = isExecuteArea( vp ) ? itemAt( vp ) : 0L; | 1025 | QListViewItem *item = isExecuteArea( vp ) ? itemAt( vp ) : 0L; |
1026 | 1026 | ||
1027 | if ( item != d->dragOverItem ) | 1027 | if ( item != d->dragOverItem ) |
1028 | { | 1028 | { |
1029 | d->dragExpand.stop(); | 1029 | d->dragExpand.stop(); |
1030 | d->dragOverItem = item; | 1030 | d->dragOverItem = item; |
1031 | d->dragOverPoint = vp; | 1031 | d->dragOverPoint = vp; |
1032 | if ( d->dragOverItem && d->dragOverItem->isExpandable() && !d->dragOverItem->isOpen() ) | 1032 | if ( d->dragOverItem && d->dragOverItem->isExpandable() && !d->dragOverItem->isOpen() ) |
1033 | d->dragExpand.start( QApplication::startDragTime(), true ); | 1033 | d->dragExpand.start( QApplication::startDragTime(), true ); |
1034 | } | 1034 | } |
1035 | if (dropVisualizer()) | 1035 | if (dropVisualizer()) |
1036 | { | 1036 | { |
1037 | QRect tmpRect = drawDropVisualizer(0, d->parentItemDrop, d->afterItemDrop); | 1037 | QRect tmpRect = drawDropVisualizer(0, d->parentItemDrop, d->afterItemDrop); |
1038 | if (tmpRect != d->mOldDropVisualizer) | 1038 | if (tmpRect != d->mOldDropVisualizer) |
1039 | { | 1039 | { |
1040 | cleanDropVisualizer(); | 1040 | cleanDropVisualizer(); |
1041 | d->mOldDropVisualizer=tmpRect; | 1041 | d->mOldDropVisualizer=tmpRect; |
1042 | viewport()->repaint(tmpRect); | 1042 | viewport()->repaint(tmpRect); |
1043 | } | 1043 | } |
1044 | } | 1044 | } |
1045 | if (dropHighlighter()) | 1045 | if (dropHighlighter()) |
1046 | { | 1046 | { |
1047 | QRect tmpRect = drawItemHighlighter(0, d->afterItemDrop); | 1047 | QRect tmpRect = drawItemHighlighter(0, d->afterItemDrop); |
1048 | if (tmpRect != d->mOldDropHighlighter) | 1048 | if (tmpRect != d->mOldDropHighlighter) |
1049 | { | 1049 | { |
1050 | cleanItemHighlighter(); | 1050 | cleanItemHighlighter(); |
1051 | d->mOldDropHighlighter=tmpRect; | 1051 | d->mOldDropHighlighter=tmpRect; |
1052 | viewport()->repaint(tmpRect); | 1052 | viewport()->repaint(tmpRect); |
1053 | } | 1053 | } |
1054 | } | 1054 | } |
1055 | } | 1055 | } |
1056 | else | 1056 | else |
1057 | event->ignore(); | 1057 | event->ignore(); |
1058 | */ | 1058 | */ |
1059 | } | 1059 | } |
1060 | 1060 | ||
1061 | void KListView::slotDragExpand() | 1061 | void KListView::slotDragExpand() |
1062 | { | 1062 | { |
1063 | if ( itemAt( d->dragOverPoint ) == d->dragOverItem ) | 1063 | if ( itemAt( d->dragOverPoint ) == d->dragOverItem ) |
1064 | d->dragOverItem->setOpen( true ); | 1064 | d->dragOverItem->setOpen( true ); |
1065 | } | 1065 | } |
1066 | 1066 | ||
1067 | void KListView::contentsDragLeaveEvent (QDragLeaveEvent*) | 1067 | void KListView::contentsDragLeaveEvent (QDragLeaveEvent*) |
1068 | { | 1068 | { |
1069 | d->dragExpand.stop(); | 1069 | d->dragExpand.stop(); |
1070 | cleanDropVisualizer(); | 1070 | cleanDropVisualizer(); |
1071 | cleanItemHighlighter(); | 1071 | cleanItemHighlighter(); |
1072 | } | 1072 | } |
1073 | 1073 | ||
1074 | void KListView::cleanDropVisualizer() | 1074 | void KListView::cleanDropVisualizer() |
1075 | { | 1075 | { |
1076 | if (d->mOldDropVisualizer.isValid()) | 1076 | if (d->mOldDropVisualizer.isValid()) |
1077 | { | 1077 | { |
1078 | QRect rect=d->mOldDropVisualizer; | 1078 | QRect rect=d->mOldDropVisualizer; |
1079 | d->mOldDropVisualizer = QRect(); | 1079 | d->mOldDropVisualizer = QRect(); |
1080 | viewport()->repaint(rect, true); | 1080 | viewport()->repaint(rect, true); |
1081 | } | 1081 | } |
1082 | } | 1082 | } |
1083 | 1083 | ||
1084 | int KListView::depthToPixels( int depth ) | 1084 | int KListView::depthToPixels( int depth ) |
1085 | { | 1085 | { |
1086 | return treeStepSize() * ( depth + (rootIsDecorated() ? 1 : 0) ) + itemMargin(); | 1086 | return treeStepSize() * ( depth + (rootIsDecorated() ? 1 : 0) ) + itemMargin(); |
1087 | } | 1087 | } |
1088 | 1088 | ||
1089 | void KListView::findDrop(const QPoint &pos, QListViewItem *&parent, QListViewItem *&after) | 1089 | void KListView::findDrop(const QPoint &pos, QListViewItem *&parent, QListViewItem *&after) |
1090 | { | 1090 | { |
1091 | QPoint p (contentsToViewport(pos)); | 1091 | QPoint p (contentsToViewport(pos)); |
1092 | 1092 | ||
1093 | // Get the position to put it in | 1093 | // Get the position to put it in |
1094 | QListViewItem *atpos = itemAt(p); | 1094 | QListViewItem *atpos = itemAt(p); |
1095 | 1095 | ||
1096 | QListViewItem *above; | 1096 | QListViewItem *above; |
1097 | if (!atpos) // put it at the end | 1097 | if (!atpos) // put it at the end |
1098 | above = lastItem(); | 1098 | above = lastItem(); |
1099 | else | 1099 | else |
1100 | { | 1100 | { |
1101 | // Get the closest item before us ('atpos' or the one above, if any) | 1101 | // Get the closest item before us ('atpos' or the one above, if any) |
1102 | if (p.y() - itemRect(atpos).topLeft().y() < (atpos->height()/2)) | 1102 | if (p.y() - itemRect(atpos).topLeft().y() < (atpos->height()/2)) |
1103 | above = atpos->itemAbove(); | 1103 | above = atpos->itemAbove(); |
1104 | else | 1104 | else |
1105 | above = atpos; | 1105 | above = atpos; |
1106 | } | 1106 | } |
1107 | 1107 | ||
1108 | if (above) | 1108 | if (above) |
1109 | { | 1109 | { |
1110 | // Now, we know we want to go after "above". But as a child or as a sibling ? | 1110 | // Now, we know we want to go after "above". But as a child or as a sibling ? |
1111 | // We have to ask the "above" item if it accepts children. | 1111 | // We have to ask the "above" item if it accepts children. |
1112 | if (above->isExpandable()) | 1112 | if (above->isExpandable()) |
1113 | { | 1113 | { |
1114 | // The mouse is sufficiently on the right ? - doesn't matter if 'above' has visible children | 1114 | // The mouse is sufficiently on the right ? - doesn't matter if 'above' has visible children |
1115 | if (p.x() >= depthToPixels( above->depth() + 1 ) || | 1115 | if (p.x() >= depthToPixels( above->depth() + 1 ) || |
1116 | (above->isOpen() && above->childCount() > 0) ) | 1116 | (above->isOpen() && above->childCount() > 0) ) |
1117 | { | 1117 | { |
1118 | parent = above; | 1118 | parent = above; |
1119 | after = 0L; | 1119 | after = 0L; |
1120 | return; | 1120 | return; |
1121 | } | 1121 | } |
1122 | } | 1122 | } |
1123 | 1123 | ||
1124 | // Ok, there's one more level of complexity. We may want to become a new | 1124 | // Ok, there's one more level of complexity. We may want to become a new |
1125 | // sibling, but of an upper-level group, rather than the "above" item | 1125 | // sibling, but of an upper-level group, rather than the "above" item |
1126 | QListViewItem * betterAbove = above->parent(); | 1126 | QListViewItem * betterAbove = above->parent(); |
1127 | QListViewItem * last = above; | 1127 | QListViewItem * last = above; |
1128 | while ( betterAbove ) | 1128 | while ( betterAbove ) |
1129 | { | 1129 | { |
1130 | // We are allowed to become a sibling of "betterAbove" only if we are | 1130 | // We are allowed to become a sibling of "betterAbove" only if we are |
1131 | // after its last child | 1131 | // after its last child |
1132 | if ( last->nextSibling() == 0 ) | 1132 | if ( last->nextSibling() == 0 ) |
1133 | { | 1133 | { |
1134 | if (p.x() < depthToPixels ( betterAbove->depth() + 1 )) | 1134 | if (p.x() < depthToPixels ( betterAbove->depth() + 1 )) |
1135 | above = betterAbove; // store this one, but don't stop yet, there may be a better one | 1135 | above = betterAbove; // store this one, but don't stop yet, there may be a better one |
1136 | else | 1136 | else |
1137 | break; // not enough on the left, so stop | 1137 | break; // not enough on the left, so stop |
1138 | last = betterAbove; | 1138 | last = betterAbove; |
1139 | betterAbove = betterAbove->parent(); // up one level | 1139 | betterAbove = betterAbove->parent(); // up one level |
1140 | } else | 1140 | } else |
1141 | break; // we're among the child of betterAbove, not after the last one | 1141 | break; // we're among the child of betterAbove, not after the last one |
1142 | } | 1142 | } |
1143 | } | 1143 | } |
1144 | // set as sibling | 1144 | // set as sibling |
1145 | after = above; | 1145 | after = above; |
1146 | parent = after ? after->parent() : 0L ; | 1146 | parent = after ? after->parent() : 0L ; |
1147 | } | 1147 | } |
1148 | 1148 | ||
1149 | QListViewItem* KListView::lastChild () const | 1149 | QListViewItem* KListView::lastChild () const |
1150 | { | 1150 | { |
1151 | QListViewItem* lastchild = firstChild(); | 1151 | QListViewItem* lastchild = firstChild(); |
1152 | 1152 | ||
1153 | if (lastchild) | 1153 | if (lastchild) |
1154 | for (; lastchild->nextSibling(); lastchild = lastchild->nextSibling()); | 1154 | for (; lastchild->nextSibling(); lastchild = lastchild->nextSibling()); |
1155 | 1155 | ||
1156 | return lastchild; | 1156 | return lastchild; |
1157 | } | 1157 | } |
1158 | 1158 | ||
1159 | QListViewItem *KListView::lastItem() const | 1159 | QListViewItem *KListView::lastItem() const |
1160 | { | 1160 | { |
1161 | QListViewItem* last = lastChild(); | 1161 | QListViewItem* last = lastChild(); |
1162 | 1162 | ||
1163 | for (QListViewItemIterator it (last); it.current(); ++it) | 1163 | for (QListViewItemIterator it (last); it.current(); ++it) |
1164 | last = it.current(); | 1164 | last = it.current(); |
1165 | 1165 | ||
1166 | return last; | 1166 | return last; |
1167 | } | 1167 | } |
1168 | 1168 | ||
1169 | KLineEdit *KListView::renameLineEdit() const | 1169 | KLineEdit *KListView::renameLineEdit() const |
1170 | { | 1170 | { |
1171 | //US return d->editor; | 1171 | //US return d->editor; |
1172 | qDebug("KListView::renameLineEdit returns 0. Might crash"); | 1172 | qDebug("KListView::renameLineEdit returns 0. Might crash"); |
1173 | return 0; | 1173 | return 0; |
1174 | } | 1174 | } |
1175 | 1175 | ||
1176 | void KListView::startDrag() | 1176 | void KListView::startDrag() |
1177 | { | 1177 | { |
1178 | qDebug("KListView::startDrag drag&drop not supported yet."); | 1178 | qDebug("KListView::startDrag drag&drop not supported yet."); |
1179 | /*US | 1179 | /*US |
1180 | QDragObject *drag = dragObject(); | 1180 | QDragObject *drag = dragObject(); |
1181 | 1181 | ||
1182 | if (!drag) | 1182 | if (!drag) |
1183 | return; | 1183 | return; |
1184 | 1184 | ||
1185 | if (drag->drag() && drag->target() != viewport()) | 1185 | if (drag->drag() && drag->target() != viewport()) |
1186 | emit moved(); | 1186 | emit moved(); |
1187 | */ | 1187 | */ |
1188 | } | 1188 | } |
1189 | 1189 | ||
1190 | QDragObject *KListView::dragObject() | 1190 | QDragObject *KListView::dragObject() |
1191 | { | 1191 | { |
1192 | if (!currentItem()) | 1192 | if (!currentItem()) |
1193 | return 0; | 1193 | return 0; |
1194 | 1194 | ||
1195 | return new QStoredDrag("application/x-qlistviewitem", viewport()); | 1195 | return new QStoredDrag("application/x-qlistviewitem", viewport()); |
1196 | } | 1196 | } |
1197 | 1197 | ||
1198 | void KListView::setItemsMovable(bool b) | 1198 | void KListView::setItemsMovable(bool b) |
1199 | { | 1199 | { |
1200 | d->itemsMovable=b; | 1200 | d->itemsMovable=b; |
1201 | } | 1201 | } |
1202 | 1202 | ||
1203 | bool KListView::itemsMovable() const | 1203 | bool KListView::itemsMovable() const |
1204 | { | 1204 | { |
1205 | return d->itemsMovable; | 1205 | return d->itemsMovable; |
1206 | } | 1206 | } |
1207 | 1207 | ||
1208 | void KListView::setItemsRenameable(bool b) | 1208 | void KListView::setItemsRenameable(bool b) |
1209 | { | 1209 | { |
1210 | d->itemsRenameable=b; | 1210 | d->itemsRenameable=b; |
1211 | } | 1211 | } |
1212 | 1212 | ||
1213 | bool KListView::itemsRenameable() const | 1213 | bool KListView::itemsRenameable() const |
1214 | { | 1214 | { |
1215 | return d->itemsRenameable; | 1215 | return d->itemsRenameable; |
1216 | } | 1216 | } |
1217 | 1217 | ||
1218 | 1218 | ||
1219 | void KListView::setDragEnabled(bool b) | 1219 | void KListView::setDragEnabled(bool b) |
1220 | { | 1220 | { |
1221 | d->dragEnabled=b; | 1221 | d->dragEnabled=b; |
1222 | } | 1222 | } |
1223 | 1223 | ||
1224 | bool KListView::dragEnabled() const | 1224 | bool KListView::dragEnabled() const |
1225 | { | 1225 | { |
1226 | return d->dragEnabled; | 1226 | return d->dragEnabled; |
1227 | } | 1227 | } |
1228 | 1228 | ||
1229 | void KListView::setAutoOpen(bool b) | 1229 | void KListView::setAutoOpen(bool b) |
1230 | { | 1230 | { |
1231 | d->autoOpen=b; | 1231 | d->autoOpen=b; |
1232 | } | 1232 | } |
1233 | 1233 | ||
1234 | bool KListView::autoOpen() const | 1234 | bool KListView::autoOpen() const |
1235 | { | 1235 | { |
1236 | return d->autoOpen; | 1236 | return d->autoOpen; |
1237 | } | 1237 | } |
1238 | 1238 | ||
1239 | bool KListView::dropVisualizer() const | 1239 | bool KListView::dropVisualizer() const |
1240 | { | 1240 | { |
1241 | return d->dropVisualizer; | 1241 | return d->dropVisualizer; |
1242 | } | 1242 | } |
1243 | 1243 | ||
1244 | void KListView::setDropVisualizer(bool b) | 1244 | void KListView::setDropVisualizer(bool b) |
1245 | { | 1245 | { |
1246 | d->dropVisualizer=b; | 1246 | d->dropVisualizer=b; |
1247 | } | 1247 | } |
1248 | 1248 | ||
1249 | QPtrList<QListViewItem> KListView::selectedItems() const | 1249 | QPtrList<QListViewItem> KListView::selectedItems() const |
1250 | { | 1250 | { |
1251 | QPtrList<QListViewItem> list; | 1251 | QPtrList<QListViewItem> list; |