~ubuntu-branches/ubuntu/vivid/krusader/vivid-proposed

« back to all changes in this revision

Viewing changes to krusader/Panel/krmousehandler.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-05-05 22:26:37 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505222637-ydv3cwjwy365on2r
Tags: 1:2.1.0~beta1-1ubuntu1
* Merge from Debian Unstable.  Remaining changes:
  - Retain Kubuntu doc path

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
                        krmousehandler.cpp  -  description
3
 
                             -------------------
4
 
    begin                : Sat Feb 14 2009
5
 
    copyright            : (C) 2009+ by Csaba Karai
6
 
    email                : 
7
 
 ***************************************************************************/
8
 
 
9
 
/***************************************************************************
10
 
 *                                                                         *
11
 
 *   This program is free software; you can redistribute it and/or modify  *
12
 
 *   it under the terms of the GNU General Public License as published by  *
13
 
 *   the Free Software Foundation; either version 2 of the License, or     *
14
 
 *   (at your option) any later version.                                   *
15
 
 *                                                                         *
16
 
 ***************************************************************************/
 
1
/*****************************************************************************
 
2
 * Copyright (C) 2009 Csaba Karai <cskarai@freemail.hu>                      *
 
3
 *                                                                           *
 
4
 * This program is free software; you can redistribute it and/or modify      *
 
5
 * it under the terms of the GNU General Public License as published by      *
 
6
 * the Free Software Foundation; either version 2 of the License, or         *
 
7
 * (at your option) any later version.                                       *
 
8
 *                                                                           *
 
9
 * This package is distributed in the hope that it will be useful,           *
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
 
12
 * GNU General Public License for more details.                              *
 
13
 *                                                                           *
 
14
 * You should have received a copy of the GNU General Public License         *
 
15
 * along with this package; if not, write to the Free Software               *
 
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA *
 
17
 *****************************************************************************/
17
18
 
18
19
#include "krmousehandler.h"
19
20
#include "krview.h"
24
25
 
25
26
#define CANCEL_TWO_CLICK_RENAME {_singleClicked = false;_renameTimer.stop();}
26
27
 
27
 
KrMouseHandler::KrMouseHandler( KrView * view, int contextMenuShift ) : _view( view ), _rightClickedItem( 0 ),
28
 
        _contextMenuTimer(), _contextMenuShift( contextMenuShift ), _singleClicked( false ), _singleClickTime(),
29
 
        _renameTimer(), _dragStartPos( -1, -1 ), _emptyContextMenu( false )
30
 
{
31
 
        KConfigGroup grpSvr( krConfig, "Look&Feel" );
32
 
        // decide on single click/double click selection
33
 
        _singleClick = grpSvr.readEntry( "Single Click Selects", _SingleClickSelects ) && KGlobalSettings::singleClick();
34
 
        connect( &_contextMenuTimer, SIGNAL (timeout()), this, SLOT (showContextMenu()));
35
 
        connect( &_renameTimer, SIGNAL( timeout() ), this, SIGNAL( renameCurrentItem() ) );
36
 
}
37
 
 
38
 
bool KrMouseHandler::mousePressEvent( QMouseEvent *e )
39
 
{
40
 
        _rightClickedItem = _clickedItem = 0;
41
 
        KrViewItem * item = _view->getKrViewItemAt( e->pos() );
42
 
        if( !_view->isFocused() )
43
 
                _view->op()->emitNeedFocus();
44
 
        if (e->button() == Qt::LeftButton)
45
 
        {
46
 
                _dragStartPos = e->pos();
47
 
                if( e->modifiers() == Qt::NoModifier )
48
 
                {
49
 
                        if( item )
50
 
                        {
51
 
                                if( KrSelectionMode::getSelectionHandler()->leftButtonSelects() )
52
 
                                {
53
 
                                        if( KrSelectionMode::getSelectionHandler()->leftButtonPreservesSelection() )
54
 
                                                item->setSelected(!item->isSelected());
55
 
                                        else {
56
 
                                                if( item->isSelected() )
57
 
                                                        _clickedItem = item;
58
 
                                                else
59
 
                                                {
60
 
                                                        // clear the current selection
61
 
                                                        _view->changeSelection( KRQuery( "*" ), false, true);
62
 
                                                        item->setSelected( true );
63
 
                                                }
64
 
                                        }
65
 
                                }
66
 
                                _view->setCurrentKrViewItem( item );
67
 
                        }
68
 
                        e->accept();
69
 
                        return true;
70
 
                }
71
 
                else if( e->modifiers() == Qt::ControlModifier )
72
 
                {
73
 
                        if( item && (KrSelectionMode::getSelectionHandler()->shiftCtrlLeftButtonSelects() || 
74
 
                                     KrSelectionMode::getSelectionHandler()->leftButtonSelects() ) )
75
 
                        {
76
 
                                item->setSelected(!item->isSelected());
77
 
                        }
78
 
                        if( item )
79
 
                                _view->setCurrentKrViewItem( item );
80
 
                        e->accept();
81
 
                        return true;
82
 
                }
83
 
                else if( e->modifiers() == Qt::ShiftModifier )
84
 
                {
85
 
                        if( item && (KrSelectionMode::getSelectionHandler()->shiftCtrlLeftButtonSelects() || 
86
 
                                     KrSelectionMode::getSelectionHandler()->leftButtonSelects() ) )
87
 
                        {
88
 
                                KrViewItem * current = _view->getCurrentKrViewItem();
89
 
                                if( current != 0 )
90
 
                                        _view->selectRegion( item, current, true );
91
 
                        }
92
 
                        if( item )
93
 
                                _view->setCurrentKrViewItem( item );
94
 
                        e->accept();
95
 
                        return true;
96
 
                }
97
 
        }
98
 
        if (e->button() == Qt::RightButton)
99
 
        {
100
 
                //dragStartPos = e->pos();
101
 
                if( e->modifiers() == Qt::NoModifier )
102
 
                {
103
 
                        if( item )
104
 
                        {
105
 
                                if( KrSelectionMode::getSelectionHandler()->rightButtonSelects() )
106
 
                                {
107
 
                                        if( KrSelectionMode::getSelectionHandler()->rightButtonPreservesSelection() ) {
108
 
                                                if (KrSelectionMode::getSelectionHandler()->showContextMenu() >= 0)
109
 
                                                {
110
 
                                                        _rightClickSelects = !item->isSelected();
111
 
                                                        _rightClickedItem = item;
112
 
                                                }
113
 
                                                item->setSelected(!item->isSelected());
114
 
                                        } else {
115
 
                                                if( item->isSelected() ) {
116
 
                                                        _clickedItem = item;
117
 
                                                } else {
118
 
                                                        // clear the current selection
119
 
                                                        _view->changeSelection( KRQuery( "*" ), false, true);
120
 
                                                        item->setSelected( true );
121
 
                                                }
122
 
                                        }
123
 
                                }
124
 
                                _view->setCurrentKrViewItem( item );
125
 
                        }
126
 
                        handleContextMenu( item, e->globalPos() );
127
 
                        e->accept();
128
 
                        return true;
129
 
                }
130
 
                else if( e->modifiers() == Qt::ControlModifier )
131
 
                {
132
 
                        if( item && (KrSelectionMode::getSelectionHandler()->shiftCtrlRightButtonSelects() || 
133
 
                                     KrSelectionMode::getSelectionHandler()->rightButtonSelects() ) )
134
 
                        {
135
 
                                item->setSelected(!item->isSelected());
136
 
                        }
137
 
                        if( item )
138
 
                                _view->setCurrentKrViewItem( item );
139
 
                        e->accept();
140
 
                        return true;
141
 
                }
142
 
                else if( e->modifiers() == Qt::ShiftModifier )
143
 
                {
144
 
                        if( item && (KrSelectionMode::getSelectionHandler()->shiftCtrlRightButtonSelects() || 
145
 
                                     KrSelectionMode::getSelectionHandler()->rightButtonSelects() ) )
146
 
                        {
147
 
                                KrViewItem * current = _view->getCurrentKrViewItem();
148
 
                                if( current != 0 )
149
 
                                        _view->selectRegion( item, current, true );
150
 
                        }
151
 
                        if( item )
152
 
                                _view->setCurrentKrViewItem( item );
153
 
                        e->accept();
154
 
                        return true;
155
 
                }
156
 
        }
157
 
        return false;
158
 
}
159
 
 
160
 
bool KrMouseHandler::mouseReleaseEvent( QMouseEvent *e )
161
 
{
162
 
        if( e->button() == Qt::LeftButton )
163
 
                _dragStartPos = QPoint( -1, -1 );
164
 
        KrViewItem * item = _view->getKrViewItemAt( e->pos() );
165
 
        
166
 
        if( item && item == _clickedItem )
167
 
        {
168
 
                if(((e->button() == Qt::LeftButton) && ( e->modifiers() == Qt::NoModifier ) &&
169
 
                    ( KrSelectionMode::getSelectionHandler()->leftButtonSelects() ) &&
170
 
                   !( KrSelectionMode::getSelectionHandler()->leftButtonPreservesSelection() ) ) ||
171
 
                   ((e->button() == Qt::RightButton) && ( e->modifiers() == Qt::NoModifier ) &&
172
 
                    ( KrSelectionMode::getSelectionHandler()->rightButtonSelects() ) &&
173
 
                   !( KrSelectionMode::getSelectionHandler()->rightButtonPreservesSelection() )))
174
 
                {
175
 
                        // clear the current selection
176
 
                        _view->changeSelection( KRQuery( "*" ), false, true);
177
 
                        item->setSelected( true );
178
 
                }
179
 
        }
180
 
        
181
 
        if( e->button() == Qt::RightButton ) {
182
 
                _rightClickedItem = 0;
183
 
                _contextMenuTimer.stop();
184
 
        }
185
 
        if( _singleClick && e->button() == Qt::LeftButton )
186
 
        {
187
 
                CANCEL_TWO_CLICK_RENAME;
188
 
                e->accept();
189
 
                if( item == 0 )
190
 
                        return true;
191
 
                QString tmp = item->name();
192
 
                _view->op()->emitExecuted(tmp);
193
 
                return true;
194
 
        } else if( !_singleClick && e->button() == Qt::LeftButton )
195
 
        {
196
 
                if( item && e->modifiers() == Qt::NoModifier )
197
 
                {
198
 
                        if ( _singleClicked && !_renameTimer.isActive() && _singleClickedItem == item ) {
199
 
                                KSharedConfigPtr config = KGlobal::config();
200
 
                                KConfigGroup group( krConfig, "KDE" );
201
 
                                int doubleClickInterval = group.readEntry( "DoubleClickInterval", 400 );
202
 
                                
203
 
                                int msecsFromLastClick = _singleClickTime.msecsTo( QTime::currentTime() );
204
 
                                
205
 
                                if ( msecsFromLastClick > doubleClickInterval && msecsFromLastClick < 5 * doubleClickInterval ) {
206
 
                                        _singleClicked = false;
207
 
                                        _renameTimer.setSingleShot( true );
208
 
                                        _renameTimer.start( doubleClickInterval );
209
 
                                        return true;
210
 
                                }
211
 
                        }
212
 
                        
213
 
                        CANCEL_TWO_CLICK_RENAME;
214
 
                        _singleClicked = true;
215
 
                        _singleClickedItem = item;
216
 
                        _singleClickTime = QTime::currentTime();
217
 
                        
218
 
                        return true;
219
 
                }
220
 
        }
221
 
        
222
 
        CANCEL_TWO_CLICK_RENAME;
223
 
 
224
 
        if ( e->button() == Qt::MidButton && item != 0 )
225
 
        {
226
 
                                e->accept();
227
 
                if( item == 0 )
228
 
                        return true;
229
 
                _view->op()->emitMiddleButtonClicked( item );
230
 
                return true;
231
 
        }
232
 
        return false;
233
 
}
234
 
 
235
 
bool KrMouseHandler::mouseDoubleClickEvent( QMouseEvent *e )
236
 
{
237
 
        CANCEL_TWO_CLICK_RENAME;
238
 
        
239
 
        KrViewItem * item = _view->getKrViewItemAt( e->pos() );
240
 
        if( _singleClick )
241
 
                return false;
242
 
        if( e->button() == Qt::LeftButton && item != 0 )
243
 
        {
244
 
                e->accept();
245
 
                QString tmp = item->name();
246
 
                _view->op()->emitExecuted(tmp);
247
 
                return true;
248
 
        }
249
 
        return false;
250
 
}
251
 
 
252
 
bool KrMouseHandler::mouseMoveEvent( QMouseEvent *e )
253
 
{
254
 
        KrViewItem * item =  _view->getKrViewItemAt( e->pos() );
255
 
        if ( ( _singleClicked || _renameTimer.isActive() ) && item != _singleClickedItem )
256
 
                CANCEL_TWO_CLICK_RENAME;
257
 
        
258
 
        if ( !item )
259
 
                return false;
260
 
        
261
 
        QString desc = item->description();
262
 
        _view->op()->emitItemDescription(desc);
263
 
        
264
 
        if ( _dragStartPos != QPoint( -1, -1 ) &&
265
 
                ( e->buttons() & Qt::LeftButton ) && ( _dragStartPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() )
266
 
        {
267
 
                _view->op()->startDrag();
268
 
                return true;
269
 
        }
270
 
        
271
 
        if (KrSelectionMode::getSelectionHandler()->rightButtonPreservesSelection() 
272
 
                && KrSelectionMode::getSelectionHandler()->rightButtonSelects()
273
 
                && KrSelectionMode::getSelectionHandler()->showContextMenu() >= 0 && e->buttons() == Qt::RightButton)
274
 
        {
275
 
                e->accept();
276
 
                if (item != _rightClickedItem && item && _rightClickedItem)
277
 
                {
278
 
                        _view->selectRegion( item, _rightClickedItem, _rightClickSelects );
279
 
                        _rightClickedItem = item;
280
 
                        _view->setCurrentKrViewItem( item );
281
 
                        _contextMenuTimer.stop();
282
 
                }
283
 
                return true;
284
 
        }
285
 
        return false;
286
 
}
287
 
 
288
 
bool KrMouseHandler::wheelEvent ( QWheelEvent * )
289
 
{
290
 
        if( !_view->isFocused() )
291
 
                _view->op()->emitNeedFocus();
292
 
        return false;
 
28
KrMouseHandler::KrMouseHandler(KrView * view, int contextMenuShift) : _view(view), _rightClickedItem(0),
 
29
        _contextMenuTimer(), _contextMenuShift(contextMenuShift), _singleClicked(false), _singleClickTime(),
 
30
        _renameTimer(), _dragStartPos(-1, -1), _emptyContextMenu(false)
 
31
{
 
32
    KConfigGroup grpSvr(krConfig, "Look&Feel");
 
33
    // decide on single click/double click selection
 
34
    _singleClick = grpSvr.readEntry("Single Click Selects", _SingleClickSelects) && KGlobalSettings::singleClick();
 
35
    connect(&_contextMenuTimer, SIGNAL(timeout()), this, SLOT(showContextMenu()));
 
36
    connect(&_renameTimer, SIGNAL(timeout()), this, SIGNAL(renameCurrentItem()));
 
37
}
 
38
 
 
39
bool KrMouseHandler::mousePressEvent(QMouseEvent *e)
 
40
{
 
41
    _rightClickedItem = _clickedItem = 0;
 
42
    KrViewItem * item = _view->getKrViewItemAt(e->pos());
 
43
    if (!_view->isFocused())
 
44
        _view->op()->emitNeedFocus();
 
45
    if (e->button() == Qt::LeftButton) {
 
46
        _dragStartPos = e->pos();
 
47
        if (e->modifiers() == Qt::NoModifier) {
 
48
            if (item) {
 
49
                if (KrSelectionMode::getSelectionHandler()->leftButtonSelects()) {
 
50
                    if (KrSelectionMode::getSelectionHandler()->leftButtonPreservesSelection())
 
51
                        item->setSelected(!item->isSelected());
 
52
                    else {
 
53
                        if (item->isSelected())
 
54
                            _clickedItem = item;
 
55
                        else {
 
56
                            // clear the current selection
 
57
                            _view->changeSelection(KRQuery("*"), false, true);
 
58
                            item->setSelected(true);
 
59
                        }
 
60
                    }
 
61
                }
 
62
                _view->setCurrentKrViewItem(item);
 
63
            }
 
64
            e->accept();
 
65
            return true;
 
66
        } else if (e->modifiers() == Qt::ControlModifier) {
 
67
            if (item && (KrSelectionMode::getSelectionHandler()->shiftCtrlLeftButtonSelects() ||
 
68
                         KrSelectionMode::getSelectionHandler()->leftButtonSelects())) {
 
69
                item->setSelected(!item->isSelected());
 
70
            }
 
71
            if (item)
 
72
                _view->setCurrentKrViewItem(item);
 
73
            e->accept();
 
74
            return true;
 
75
        } else if (e->modifiers() == Qt::ShiftModifier) {
 
76
            if (item && (KrSelectionMode::getSelectionHandler()->shiftCtrlLeftButtonSelects() ||
 
77
                         KrSelectionMode::getSelectionHandler()->leftButtonSelects())) {
 
78
                KrViewItem * current = _view->getCurrentKrViewItem();
 
79
                if (current != 0)
 
80
                    _view->selectRegion(item, current, true);
 
81
            }
 
82
            if (item)
 
83
                _view->setCurrentKrViewItem(item);
 
84
            e->accept();
 
85
            return true;
 
86
        }
 
87
    }
 
88
    if (e->button() == Qt::RightButton) {
 
89
        //dragStartPos = e->pos();
 
90
        if (e->modifiers() == Qt::NoModifier) {
 
91
            if (item) {
 
92
                if (KrSelectionMode::getSelectionHandler()->rightButtonSelects()) {
 
93
                    if (KrSelectionMode::getSelectionHandler()->rightButtonPreservesSelection()) {
 
94
                        if (KrSelectionMode::getSelectionHandler()->showContextMenu() >= 0) {
 
95
                            _rightClickSelects = !item->isSelected();
 
96
                            _rightClickedItem = item;
 
97
                        }
 
98
                        item->setSelected(!item->isSelected());
 
99
                    } else {
 
100
                        if (item->isSelected()) {
 
101
                            _clickedItem = item;
 
102
                        } else {
 
103
                            // clear the current selection
 
104
                            _view->changeSelection(KRQuery("*"), false, true);
 
105
                            item->setSelected(true);
 
106
                        }
 
107
                    }
 
108
                }
 
109
                _view->setCurrentKrViewItem(item);
 
110
            }
 
111
            handleContextMenu(item, e->globalPos());
 
112
            e->accept();
 
113
            return true;
 
114
        } else if (e->modifiers() == Qt::ControlModifier) {
 
115
            if (item && (KrSelectionMode::getSelectionHandler()->shiftCtrlRightButtonSelects() ||
 
116
                         KrSelectionMode::getSelectionHandler()->rightButtonSelects())) {
 
117
                item->setSelected(!item->isSelected());
 
118
            }
 
119
            if (item)
 
120
                _view->setCurrentKrViewItem(item);
 
121
            e->accept();
 
122
            return true;
 
123
        } else if (e->modifiers() == Qt::ShiftModifier) {
 
124
            if (item && (KrSelectionMode::getSelectionHandler()->shiftCtrlRightButtonSelects() ||
 
125
                         KrSelectionMode::getSelectionHandler()->rightButtonSelects())) {
 
126
                KrViewItem * current = _view->getCurrentKrViewItem();
 
127
                if (current != 0)
 
128
                    _view->selectRegion(item, current, true);
 
129
            }
 
130
            if (item)
 
131
                _view->setCurrentKrViewItem(item);
 
132
            e->accept();
 
133
            return true;
 
134
        }
 
135
    }
 
136
    return false;
 
137
}
 
138
 
 
139
bool KrMouseHandler::mouseReleaseEvent(QMouseEvent *e)
 
140
{
 
141
    if (e->button() == Qt::LeftButton)
 
142
        _dragStartPos = QPoint(-1, -1);
 
143
    KrViewItem * item = _view->getKrViewItemAt(e->pos());
 
144
 
 
145
    if (item && item == _clickedItem) {
 
146
        if (((e->button() == Qt::LeftButton) && (e->modifiers() == Qt::NoModifier) &&
 
147
                (KrSelectionMode::getSelectionHandler()->leftButtonSelects()) &&
 
148
                !(KrSelectionMode::getSelectionHandler()->leftButtonPreservesSelection())) ||
 
149
                ((e->button() == Qt::RightButton) && (e->modifiers() == Qt::NoModifier) &&
 
150
                 (KrSelectionMode::getSelectionHandler()->rightButtonSelects()) &&
 
151
                 !(KrSelectionMode::getSelectionHandler()->rightButtonPreservesSelection()))) {
 
152
            // clear the current selection
 
153
            _view->changeSelection(KRQuery("*"), false, true);
 
154
            item->setSelected(true);
 
155
        }
 
156
    }
 
157
 
 
158
    if (e->button() == Qt::RightButton) {
 
159
        _rightClickedItem = 0;
 
160
        _contextMenuTimer.stop();
 
161
    }
 
162
    if (_singleClick && e->button() == Qt::LeftButton) {
 
163
        CANCEL_TWO_CLICK_RENAME;
 
164
        e->accept();
 
165
        if (item == 0)
 
166
            return true;
 
167
        QString tmp = item->name();
 
168
        _view->op()->emitExecuted(tmp);
 
169
        return true;
 
170
    } else if (!_singleClick && e->button() == Qt::LeftButton) {
 
171
        if (item && e->modifiers() == Qt::NoModifier) {
 
172
            if (_singleClicked && !_renameTimer.isActive() && _singleClickedItem == item) {
 
173
                KSharedConfigPtr config = KGlobal::config();
 
174
                KConfigGroup group(krConfig, "KDE");
 
175
                int doubleClickInterval = group.readEntry("DoubleClickInterval", 400);
 
176
 
 
177
                int msecsFromLastClick = _singleClickTime.msecsTo(QTime::currentTime());
 
178
 
 
179
                if (msecsFromLastClick > doubleClickInterval && msecsFromLastClick < 5 * doubleClickInterval) {
 
180
                    _singleClicked = false;
 
181
                    _renameTimer.setSingleShot(true);
 
182
                    _renameTimer.start(doubleClickInterval);
 
183
                    return true;
 
184
                }
 
185
            }
 
186
 
 
187
            CANCEL_TWO_CLICK_RENAME;
 
188
            _singleClicked = true;
 
189
            _singleClickedItem = item;
 
190
            _singleClickTime = QTime::currentTime();
 
191
 
 
192
            return true;
 
193
        }
 
194
    }
 
195
 
 
196
    CANCEL_TWO_CLICK_RENAME;
 
197
 
 
198
    if (e->button() == Qt::MidButton && item != 0) {
 
199
        e->accept();
 
200
        if (item == 0)
 
201
            return true;
 
202
        _view->op()->emitMiddleButtonClicked(item);
 
203
        return true;
 
204
    }
 
205
    return false;
 
206
}
 
207
 
 
208
bool KrMouseHandler::mouseDoubleClickEvent(QMouseEvent *e)
 
209
{
 
210
    CANCEL_TWO_CLICK_RENAME;
 
211
 
 
212
    KrViewItem * item = _view->getKrViewItemAt(e->pos());
 
213
    if (_singleClick)
 
214
        return false;
 
215
    if (e->button() == Qt::LeftButton && item != 0) {
 
216
        e->accept();
 
217
        QString tmp = item->name();
 
218
        _view->op()->emitExecuted(tmp);
 
219
        return true;
 
220
    }
 
221
    return false;
 
222
}
 
223
 
 
224
bool KrMouseHandler::mouseMoveEvent(QMouseEvent *e)
 
225
{
 
226
    KrViewItem * item =  _view->getKrViewItemAt(e->pos());
 
227
    if ((_singleClicked || _renameTimer.isActive()) && item != _singleClickedItem)
 
228
        CANCEL_TWO_CLICK_RENAME;
 
229
 
 
230
    if (!item)
 
231
        return false;
 
232
 
 
233
    QString desc = item->description();
 
234
    _view->op()->emitItemDescription(desc);
 
235
 
 
236
    if (_dragStartPos != QPoint(-1, -1) &&
 
237
            (e->buttons() & Qt::LeftButton) && (_dragStartPos - e->pos()).manhattanLength() > QApplication::startDragDistance()) {
 
238
        _view->op()->startDrag();
 
239
        return true;
 
240
    }
 
241
 
 
242
    if (KrSelectionMode::getSelectionHandler()->rightButtonPreservesSelection()
 
243
            && KrSelectionMode::getSelectionHandler()->rightButtonSelects()
 
244
            && KrSelectionMode::getSelectionHandler()->showContextMenu() >= 0 && e->buttons() == Qt::RightButton) {
 
245
        e->accept();
 
246
        if (item != _rightClickedItem && item && _rightClickedItem) {
 
247
            _view->selectRegion(item, _rightClickedItem, _rightClickSelects);
 
248
            _rightClickedItem = item;
 
249
            _view->setCurrentKrViewItem(item);
 
250
            _contextMenuTimer.stop();
 
251
        }
 
252
        return true;
 
253
    }
 
254
    return false;
 
255
}
 
256
 
 
257
bool KrMouseHandler::wheelEvent(QWheelEvent *)
 
258
{
 
259
    if (!_view->isFocused())
 
260
        _view->op()->emitNeedFocus();
 
261
    return false;
293
262
}
294
263
 
295
264
void KrMouseHandler::showContextMenu()
296
265
{
297
 
        if (_rightClickedItem)
298
 
                _rightClickedItem->setSelected(true);
299
 
        if( _emptyContextMenu )
300
 
                _view->op()->emitEmptyContextMenu( _contextMenuPoint );
301
 
        else
302
 
                _view->op()->emitContextMenu( _contextMenuPoint );
303
 
}
304
 
 
305
 
void KrMouseHandler::handleContextMenu( KrViewItem * it, const QPoint & pos ) {
306
 
        if ( !_view->isFocused() )
307
 
                _view->op()->emitNeedFocus();
308
 
        int i = KrSelectionMode::getSelectionHandler()->showContextMenu();
309
 
        _contextMenuPoint = QPoint( pos.x(), pos.y() - _contextMenuShift );
310
 
        if (i < 0) {
311
 
                if ( !it || it->isDummy() )
312
 
                        _view->op()->emitEmptyContextMenu( _contextMenuPoint );
313
 
                else {
314
 
                        _view->setCurrentKrViewItem( it );
315
 
                        _view->op()->emitContextMenu( _contextMenuPoint );
316
 
                }
317
 
        }
318
 
        else if (i > 0) {
319
 
                _emptyContextMenu = !it || it->isDummy();
320
 
                _contextMenuTimer.setSingleShot( true );
321
 
                _contextMenuTimer.start(i);
322
 
        }
323
 
}
324
 
 
325
 
void KrMouseHandler::otherEvent( QEvent * e ) {
326
 
        switch ( e->type() ) {
327
 
                case QEvent::Timer:
328
 
                case QEvent::MouseMove:
329
 
                case QEvent::MouseButtonPress:
330
 
                case QEvent::MouseButtonRelease:
331
 
                        break;
332
 
                default:
333
 
                        CANCEL_TWO_CLICK_RENAME;
334
 
        }
 
266
    if (_rightClickedItem)
 
267
        _rightClickedItem->setSelected(true);
 
268
    if (_emptyContextMenu)
 
269
        _view->op()->emitEmptyContextMenu(_contextMenuPoint);
 
270
    else
 
271
        _view->op()->emitContextMenu(_contextMenuPoint);
 
272
}
 
273
 
 
274
void KrMouseHandler::handleContextMenu(KrViewItem * it, const QPoint & pos)
 
275
{
 
276
    if (!_view->isFocused())
 
277
        _view->op()->emitNeedFocus();
 
278
    int i = KrSelectionMode::getSelectionHandler()->showContextMenu();
 
279
    _contextMenuPoint = QPoint(pos.x(), pos.y() - _contextMenuShift);
 
280
    if (i < 0) {
 
281
        if (!it || it->isDummy())
 
282
            _view->op()->emitEmptyContextMenu(_contextMenuPoint);
 
283
        else {
 
284
            _view->setCurrentKrViewItem(it);
 
285
            _view->op()->emitContextMenu(_contextMenuPoint);
 
286
        }
 
287
    } else if (i > 0) {
 
288
        _emptyContextMenu = !it || it->isDummy();
 
289
        _contextMenuTimer.setSingleShot(true);
 
290
        _contextMenuTimer.start(i);
 
291
    }
 
292
}
 
293
 
 
294
void KrMouseHandler::otherEvent(QEvent * e)
 
295
{
 
296
    switch (e->type()) {
 
297
    case QEvent::Timer:
 
298
    case QEvent::MouseMove:
 
299
    case QEvent::MouseButtonPress:
 
300
    case QEvent::MouseButtonRelease:
 
301
        break;
 
302
    default:
 
303
        CANCEL_TWO_CLICK_RENAME;
 
304
    }
335
305
}
336
306
 
337
307
void KrMouseHandler::cancelTwoClickRename()
338
308
{
339
 
        CANCEL_TWO_CLICK_RENAME;
 
309
    CANCEL_TWO_CLICK_RENAME;
340
310
}
341
311
 
342
312
bool KrMouseHandler::dragEnterEvent(QDragEnterEvent *e)
343
313
{
344
 
        KUrl::List URLs = KUrl::List::fromMimeData( e->mimeData() );
345
 
        e->setAccepted( !URLs.isEmpty() );
346
 
        return true;
 
314
    KUrl::List URLs = KUrl::List::fromMimeData(e->mimeData());
 
315
    e->setAccepted(!URLs.isEmpty());
 
316
    return true;
347
317
}
348
318
 
349
319
bool KrMouseHandler::dragMoveEvent(QDragMoveEvent *e)
350
320
{
351
 
        KUrl::List URLs = KUrl::List::fromMimeData( e->mimeData() );
352
 
        e->setAccepted( !URLs.isEmpty() );
353
 
        return true;
 
321
    KUrl::List URLs = KUrl::List::fromMimeData(e->mimeData());
 
322
    e->setAccepted(!URLs.isEmpty());
 
323
    return true;
354
324
}
355
325
 
356
326
bool KrMouseHandler::dragLeaveEvent(QDragLeaveEvent *e)
357
327
{
358
 
        return false;
 
328
    return false;
359
329
}
360
330
 
361
 
bool KrMouseHandler::dropEvent ( QDropEvent *e )
 
331
bool KrMouseHandler::dropEvent(QDropEvent *e)
362
332
{
363
 
        _view->op()->emitGotDrop( e );
364
 
        return true;
 
333
    _view->op()->emitGotDrop(e);
 
334
    return true;
365
335
}