~ubuntu-branches/ubuntu/utopic/smb4k/utopic-proposed

« back to all changes in this revision

Viewing changes to smb4k/sharesview/smb4ksharesiconview.cpp

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2012-05-19 18:54:34 UTC
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: package-import@ubuntu.com-20120519185434-kpqpdrg5i47zm7tl
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
    smb4ksharesiconview  -  This is the shares icon view of Smb4K.
3
3
                             -------------------
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
 ***************************************************************************/
8
8
 
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>
51
51
{
52
52
  setViewMode( IconMode );
53
53
  setMouseTracking( true );
54
 
  setSelectionMode( SingleSelection );
 
54
  setSelectionMode( ExtendedSelection );
55
55
  setResizeMode( Adjust );
56
56
  setSortingEnabled( true );
57
57
  setWordWrap( true );
59
59
  setAcceptDrops( true );
60
60
  setDragEnabled( true );
61
61
  setDropIndicatorShown( true );
62
 
 
 
62
  
63
63
  setContextMenuPolicy( Qt::CustomContextMenu );
64
64
 
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 );
69
69
 
70
70
  // Connections:
71
71
  connect( this, SIGNAL( itemEntered( QListWidgetItem * ) ),
91
91
}
92
92
 
93
93
 
94
 
void Smb4KSharesIconView::updateToolTip()
 
94
bool Smb4KSharesIconView::event( QEvent *e )
95
95
{
96
 
  if ( !m_tooltip )
 
96
  switch ( e->type() )
97
97
  {
98
 
    return;
 
98
    case QEvent::ToolTip:
 
99
    {
 
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 ) );
 
103
      
 
104
      if ( item )
 
105
      {
 
106
        if ( Smb4KSettings::showShareToolTip() )
 
107
        {
 
108
          if ( !m_tooltip->isVisible() || (m_tooltip->networkItem() && 
 
109
               QString::compare( item->shareItem()->key(), m_tooltip->networkItem()->key() ) != 0) )
 
110
          {
 
111
            m_tooltip->show( item->shareItem(), pos );
 
112
          }
 
113
          else
 
114
          {
 
115
            // Do nothing
 
116
          }
 
117
        }
 
118
        else
 
119
        {
 
120
          if ( m_tooltip->isVisible() )
 
121
          {
 
122
            m_tooltip->hide();
 
123
          }
 
124
          else
 
125
          {
 
126
            // Do nothing
 
127
          }
 
128
        }
 
129
      }
 
130
      else
 
131
      {
 
132
        if ( m_tooltip->isVisible() )
 
133
        {
 
134
          m_tooltip->hide();
 
135
        }
 
136
        else
 
137
        {
 
138
          // Do nothing
 
139
        }
 
140
      }
 
141
 
 
142
break;
 
143
    }
 
144
    default:
 
145
    {
 
146
      break;
 
147
    }
99
148
  }
100
149
 
101
 
  m_tooltip->update();
102
 
}
103
 
 
104
 
 
105
 
void Smb4KSharesIconView::mouseMoveEvent( QMouseEvent *e )
106
 
{
107
 
  m_pos = e->pos();
108
 
 
109
 
  QListWidget::mouseMoveEvent( e );
 
150
  return QListWidget::event( e );
110
151
}
111
152
 
112
153
 
113
154
void Smb4KSharesIconView::leaveEvent( QEvent *e )
114
155
{
115
 
  slotHideToolTip();
116
 
 
 
156
  if ( m_tooltip->isVisible() )
 
157
  {
 
158
    m_tooltip->hide();
 
159
  }
 
160
  else
 
161
  {
 
162
    // Do nothing
 
163
  }
 
164
  
117
165
  m_auto_select_timer->stop();
118
 
 
119
166
  m_mouse_inside = false;
120
 
 
121
167
  QListWidget::leaveEvent( e );
122
168
}
123
169
 
125
171
void Smb4KSharesIconView::enterEvent( QEvent *e )
126
172
{
127
173
  m_mouse_inside = true;
128
 
 
129
174
  QListWidget::enterEvent( e );
130
175
}
131
176
 
133
178
void Smb4KSharesIconView::mousePressEvent( QMouseEvent *e )
134
179
{
135
180
  // Hide the current tool tip so that it is not in the way.
136
 
  if ( !m_tooltip->isCleared() )
 
181
  if ( m_tooltip->isVisible() )
137
182
  {
138
 
    slotHideToolTip();
 
183
    m_tooltip->hide();
139
184
  }
140
185
  else
141
186
  {
146
191
  // item, unselect the current item.
147
192
  QListWidgetItem *item = itemAt( e->pos() );
148
193
 
149
 
  if ( !item && currentItem() )
 
194
  if ( !item && !selectedItems().isEmpty() )
150
195
  {
151
 
    currentItem()->setSelected( false );
 
196
    clearSelection();
152
197
    setCurrentItem( NULL );
153
198
    emit itemPressed( currentItem() );
154
199
  }
164
209
void Smb4KSharesIconView::focusOutEvent( QFocusEvent *e )
165
210
{
166
211
  m_auto_select_timer->stop();
167
 
 
168
212
  QListWidget::focusOutEvent( e );
169
213
}
170
214
 
171
215
 
172
216
void Smb4KSharesIconView::wheelEvent( QWheelEvent *e )
173
217
{
174
 
  slotHideToolTip();
175
 
 
 
218
  if ( m_tooltip->isVisible() )
 
219
  {
 
220
    m_tooltip->hide();
 
221
  }
 
222
  else
 
223
  {
 
224
    // Do nothing
 
225
  }
 
226
  
176
227
  QListWidget::wheelEvent( e );
177
228
}
178
229
 
201
252
  if ( item && (item->flags() & Qt::ItemIsDropEnabled) &&
202
253
       (e->proposedAction() & (Qt::CopyAction | Qt::MoveAction)) )
203
254
  {
204
 
    QUrl url = QUrl::fromLocalFile( item->itemData()->share()->path() );
 
255
    QUrl url = QUrl::fromLocalFile( item->shareItem()->path() );
205
256
 
206
257
    if ( e->source() == this && e->mimeData()->urls().first() == url )
207
258
    {
225
276
 
226
277
  if ( item && (e->proposedAction() & (Qt::CopyAction | Qt::MoveAction)) )
227
278
  {
228
 
    QUrl url = QUrl::fromLocalFile( item->itemData()->share()->path() );
 
279
    QUrl url = QUrl::fromLocalFile( item->shareItem()->path() );
229
280
 
230
281
    if ( e->source() == this && e->mimeData()->urls().first() == url )
231
282
    {
261
312
  {
262
313
    Smb4KSharesIconViewItem *item = static_cast<Smb4KSharesIconViewItem *>( list.at( i ) );
263
314
 
264
 
    urls.append( QUrl::fromLocalFile( item->itemData()->share()->path() ) );
 
315
    urls.append( QUrl::fromLocalFile( item->shareItem()->path() ) );
265
316
  }
266
317
 
267
318
  mimeData->setUrls( urls );
272
323
 
273
324
void Smb4KSharesIconView::startDrag( Qt::DropActions supported )
274
325
{
275
 
  slotHideToolTip();
 
326
  if ( m_tooltip->isVisible() )
 
327
  {
 
328
    m_tooltip->hide();
 
329
  }
 
330
  else
 
331
  {
 
332
    // Do nothing
 
333
  }
276
334
 
277
335
  QList<QListWidgetItem *> list = selectedItems();
278
336
 
292
350
    if ( list.count() == 1 )
293
351
    {
294
352
      Smb4KSharesIconViewItem *item = static_cast<Smb4KSharesIconViewItem *>( list.first() );
295
 
 
296
 
      pixmap = item->itemData()->pixmap( KIconLoader::SizeMedium );
 
353
      pixmap = item->icon().pixmap( KIconLoader::SizeMedium );
297
354
    }
298
355
    else
299
356
    {
338
395
    // Do nothing
339
396
  }
340
397
 
341
 
  Smb4KSharesIconViewItem *shareItem = static_cast<Smb4KSharesIconViewItem *>( item );
342
 
 
343
 
  if ( Smb4KSettings::showShareToolTip() )
344
 
  {
345
 
    if ( m_tooltip->data() == NULL || m_tooltip->data() != shareItem->itemData() )
346
 
    {
347
 
      if ( !m_tooltip->isVisible() )
348
 
      {
349
 
        m_tooltip->setupToolTip( shareItem->itemData() );
350
 
 
351
 
        m_tooltip_timer->setSingleShot( true );
352
 
        connect( m_tooltip_timer, SIGNAL( timeout() ), this, SLOT( slotShowToolTip() ) );
353
 
 
354
 
        m_tooltip_timer->start( 2000 );
355
 
      }
356
 
      else
357
 
      {
358
 
        slotHideToolTip();
359
 
      }
360
 
    }
361
 
    else
362
 
    {
363
 
      // Do nothing.
364
 
    }
365
 
  }
366
 
  else
367
 
  {
368
 
    if ( m_tooltip->isVisible() )
369
 
    {
370
 
      slotHideToolTip();
 
398
  if ( m_tooltip->isVisible() )
 
399
  {
 
400
    Smb4KSharesIconViewItem *share_item = static_cast<Smb4KSharesIconViewItem *>( item );
 
401
      
 
402
    if ( share_item && m_tooltip->networkItem() &&
 
403
         QString::compare( share_item->shareItem()->key(), m_tooltip->networkItem()->key() ) != 0 )
 
404
    {
 
405
      m_tooltip->hide();
371
406
    }
372
407
    else
373
408
    {
374
409
      // Do nothing
375
410
    }
376
411
  }
 
412
  else
 
413
  {
 
414
    // Do nothing
 
415
  }
377
416
}
378
417
 
379
418
 
395
434
  // Hide the tool tip.
396
435
  if ( m_tooltip->isVisible() )
397
436
  {
398
 
    slotHideToolTip();
 
437
    m_tooltip->hide();  
399
438
  }
400
439
  else
401
440
  {
404
443
}
405
444
 
406
445
 
407
 
void Smb4KSharesIconView::slotShowToolTip()
408
 
{
409
 
  disconnect( m_tooltip_timer, 0, 0, 0 );
410
 
 
411
 
  if ( Smb4KSettings::showShareToolTip() )
412
 
  {
413
 
    Smb4KSharesIconViewItem *shareItem = static_cast<Smb4KSharesIconViewItem *>( itemAt( m_pos ) );
414
 
 
415
 
    if ( shareItem && !m_tooltip->isCleared() )
416
 
    {
417
 
      if ( !m_tooltip->isVisible() )
418
 
      {
419
 
        QPoint p( viewport()->mapToGlobal( m_pos ) );
420
 
 
421
 
        QDesktopWidget *d = QApplication::desktop();
422
 
 
423
 
        if ( p.x() + m_tooltip->width() > d->width() )
424
 
        {
425
 
          p.setX( p.x() - m_tooltip->width() - 5 );
426
 
        }
427
 
        else
428
 
        {
429
 
          p.setX( p.x() + 5 );
430
 
        }
431
 
 
432
 
        if ( p.y() + m_tooltip->height() > d->height() )
433
 
        {
434
 
          p.setY( p.y() - m_tooltip->height() - 5 );
435
 
        }
436
 
        else
437
 
        {
438
 
          p.setY( p.y() + 5 );
439
 
        }
440
 
 
441
 
        m_tooltip->setGeometry( p.x(), p.y(), m_tooltip->width(), m_tooltip->height() );
442
 
        m_tooltip->setVisible( true );
443
 
 
444
 
        m_tooltip_timer->setSingleShot( true );
445
 
        connect( m_tooltip_timer, SIGNAL( timeout() ), this, SLOT( slotHideToolTip() ) );
446
 
 
447
 
        m_tooltip_timer->start( 10000 );
448
 
      }
449
 
      else
450
 
      {
451
 
        // Do nothing
452
 
      }
453
 
    }
454
 
    else
455
 
    {
456
 
      slotHideToolTip();
457
 
    }
458
 
  }
459
 
  else
460
 
  {
461
 
    slotHideToolTip();
462
 
  }
463
 
}
464
 
 
465
 
 
466
 
void Smb4KSharesIconView::slotHideToolTip()
467
 
{
468
 
  disconnect( m_tooltip_timer, 0, 0, 0 );
469
 
 
470
 
  m_tooltip->setVisible( false );
471
 
  m_tooltip->clearToolTip();
472
 
}
473
 
 
474
 
 
475
446
void Smb4KSharesIconView::slotKDESettingsChanged( int category )
476
447
{
477
448
  // Adjust to KDE's default mouse settings.
512
483
void Smb4KSharesIconView::slotAutoSelectItem()
513
484
{
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 );
516
488
 
517
489
  if ( !m_auto_select_item || !shareItem || m_auto_select_item != shareItem )
518
490
  {