2
2
smb4ksharesiconview - This is the shares icon view of Smb4K.
4
4
begin : Mo Dez 4 2006
5
copyright : (C) 2006-2008 by Alexander Reinholdt
6
email : dustpuppy@users.berlios.de
5
copyright : (C) 2006-2010 by Alexander Reinholdt
6
email : alexander.reinholdt@kdemail.net
7
7
***************************************************************************/
9
9
/***************************************************************************
40
40
// application specific includes
41
41
#include <smb4ksharesiconview.h>
42
42
#include <smb4ksharesiconviewitem.h>
43
#include <smb4ksharesviewtooltip.h>
43
#include <../tooltips/smb4ktooltip.h>
44
44
#include <core/smb4kshare.h>
45
45
#include <core/smb4ksettings.h>
46
46
#include <core/smb4kcore.h>
59
59
setAcceptDrops( true );
60
60
setDragEnabled( true );
61
61
setDropIndicatorShown( true );
63
63
setContextMenuPolicy( Qt::CustomContextMenu );
65
65
m_tooltip_timer = new QTimer( this );
66
66
m_auto_select_timer = new QTimer( this );
67
67
m_mouse_inside = false;
68
m_tooltip = new Smb4KSharesViewToolTip( this );
68
m_tooltip = new Smb4KToolTip( this );
71
71
connect( this, SIGNAL( itemEntered( QListWidgetItem * ) ),
94
void Smb4KSharesIconView::updateToolTip()
94
bool Smb4KSharesIconView::event( QEvent *e )
100
// Intercept the tool tip event and show our own tool tip.
101
QPoint pos = viewport()->mapFromGlobal( cursor().pos() );
102
Smb4KSharesIconViewItem *item = static_cast<Smb4KSharesIconViewItem *>( itemAt( pos ) );
106
if ( Smb4KSettings::showShareToolTip() )
108
if ( !m_tooltip->isVisible() || (m_tooltip->networkItem() &&
109
QString::compare( item->shareItem()->key(), m_tooltip->networkItem()->key() ) != 0) )
111
m_tooltip->show( item->shareItem(), pos );
120
if ( m_tooltip->isVisible() )
132
if ( m_tooltip->isVisible() )
105
void Smb4KSharesIconView::mouseMoveEvent( QMouseEvent *e )
109
QListWidget::mouseMoveEvent( e );
150
return QListWidget::event( e );
113
154
void Smb4KSharesIconView::leaveEvent( QEvent *e )
156
if ( m_tooltip->isVisible() )
117
165
m_auto_select_timer->stop();
119
166
m_mouse_inside = false;
121
167
QListWidget::leaveEvent( e );
146
191
// item, unselect the current item.
147
192
QListWidgetItem *item = itemAt( e->pos() );
149
if ( !item && currentItem() )
194
if ( !item && !selectedItems().isEmpty() )
151
currentItem()->setSelected( false );
152
197
setCurrentItem( NULL );
153
198
emit itemPressed( currentItem() );
164
209
void Smb4KSharesIconView::focusOutEvent( QFocusEvent *e )
166
211
m_auto_select_timer->stop();
168
212
QListWidget::focusOutEvent( e );
172
216
void Smb4KSharesIconView::wheelEvent( QWheelEvent *e )
218
if ( m_tooltip->isVisible() )
176
227
QListWidget::wheelEvent( e );
201
252
if ( item && (item->flags() & Qt::ItemIsDropEnabled) &&
202
253
(e->proposedAction() & (Qt::CopyAction | Qt::MoveAction)) )
204
QUrl url = QUrl::fromLocalFile( item->itemData()->share()->path() );
255
QUrl url = QUrl::fromLocalFile( item->shareItem()->path() );
206
257
if ( e->source() == this && e->mimeData()->urls().first() == url )
226
277
if ( item && (e->proposedAction() & (Qt::CopyAction | Qt::MoveAction)) )
228
QUrl url = QUrl::fromLocalFile( item->itemData()->share()->path() );
279
QUrl url = QUrl::fromLocalFile( item->shareItem()->path() );
230
281
if ( e->source() == this && e->mimeData()->urls().first() == url )
262
313
Smb4KSharesIconViewItem *item = static_cast<Smb4KSharesIconViewItem *>( list.at( i ) );
264
urls.append( QUrl::fromLocalFile( item->itemData()->share()->path() ) );
315
urls.append( QUrl::fromLocalFile( item->shareItem()->path() ) );
267
318
mimeData->setUrls( urls );
341
Smb4KSharesIconViewItem *shareItem = static_cast<Smb4KSharesIconViewItem *>( item );
343
if ( Smb4KSettings::showShareToolTip() )
345
if ( m_tooltip->data() == NULL || m_tooltip->data() != shareItem->itemData() )
347
if ( !m_tooltip->isVisible() )
349
m_tooltip->setupToolTip( shareItem->itemData() );
351
m_tooltip_timer->setSingleShot( true );
352
connect( m_tooltip_timer, SIGNAL( timeout() ), this, SLOT( slotShowToolTip() ) );
354
m_tooltip_timer->start( 2000 );
368
if ( m_tooltip->isVisible() )
398
if ( m_tooltip->isVisible() )
400
Smb4KSharesIconViewItem *share_item = static_cast<Smb4KSharesIconViewItem *>( item );
402
if ( share_item && m_tooltip->networkItem() &&
403
QString::compare( share_item->shareItem()->key(), m_tooltip->networkItem()->key() ) != 0 )
407
void Smb4KSharesIconView::slotShowToolTip()
409
disconnect( m_tooltip_timer, 0, 0, 0 );
411
if ( Smb4KSettings::showShareToolTip() )
413
Smb4KSharesIconViewItem *shareItem = static_cast<Smb4KSharesIconViewItem *>( itemAt( m_pos ) );
415
if ( shareItem && !m_tooltip->isCleared() )
417
if ( !m_tooltip->isVisible() )
419
QPoint p( viewport()->mapToGlobal( m_pos ) );
421
QDesktopWidget *d = QApplication::desktop();
423
if ( p.x() + m_tooltip->width() > d->width() )
425
p.setX( p.x() - m_tooltip->width() - 5 );
432
if ( p.y() + m_tooltip->height() > d->height() )
434
p.setY( p.y() - m_tooltip->height() - 5 );
441
m_tooltip->setGeometry( p.x(), p.y(), m_tooltip->width(), m_tooltip->height() );
442
m_tooltip->setVisible( true );
444
m_tooltip_timer->setSingleShot( true );
445
connect( m_tooltip_timer, SIGNAL( timeout() ), this, SLOT( slotHideToolTip() ) );
447
m_tooltip_timer->start( 10000 );
466
void Smb4KSharesIconView::slotHideToolTip()
468
disconnect( m_tooltip_timer, 0, 0, 0 );
470
m_tooltip->setVisible( false );
471
m_tooltip->clearToolTip();
475
446
void Smb4KSharesIconView::slotKDESettingsChanged( int category )
477
448
// Adjust to KDE's default mouse settings.
512
483
void Smb4KSharesIconView::slotAutoSelectItem()
514
485
// Check that the item is still valid.
515
QListWidgetItem *shareItem = itemAt( m_pos );
486
QPoint pos = viewport()->mapFromGlobal( cursor().pos() );
487
QListWidgetItem *shareItem = itemAt( pos );
517
489
if ( !m_auto_select_item || !shareItem || m_auto_select_item != shareItem )