2
2
smb4knetworkbrowser - The network browser widget of Smb4K.
4
4
begin : Mo Jan 8 2007
5
copyright : (C) 2007 by Alexander Reinholdt
6
email : dustpuppy@users.berlios.de
5
copyright : (C) 2007-2011 by Alexander Reinholdt
6
email : alexander.reinholdt@kdemail.net
7
7
***************************************************************************/
9
9
/***************************************************************************
20
20
* You should have received a copy of the GNU General Public License *
21
21
* along with this program; if not, write to the *
22
* Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
22
* Free Software Foundation, 51 Franklin Street, Suite 500, Boston, *
23
* MA 02110-1335, USA *
24
24
***************************************************************************/
37
37
#include <klocale.h>
38
38
#include <kglobalsettings.h>
39
39
#include <kapplication.h>
40
#include <kiconloader.h>
41
42
// application specific includes
42
43
#include <smb4knetworkbrowser.h>
43
44
#include <smb4knetworkbrowseritem.h>
44
#include <smb4knetworkbrowsertooltip.h>
45
#include <../tooltips/smb4ktooltip.h>
45
46
#include <core/smb4ksettings.h>
52
53
setAllColumnsShowFocus( false );
53
54
setMouseTracking( true );
54
55
setSelectionMode( SingleSelection );
56
57
setContextMenuPolicy( Qt::CustomContextMenu );
58
m_tooltip = new Smb4KNetworkBrowserToolTip( this );
59
m_tooltip = new Smb4KToolTip( this );
59
60
m_mouse_inside = false;
60
m_tooltip_timer = new QTimer( this );
61
61
m_auto_select_timer = new QTimer( this );
63
63
QStringList header_labels;
70
70
header()->setResizeMode( QHeaderView::ResizeToContents );
72
72
// Add some connections:
73
connect( this, SIGNAL( itemExpanded( QTreeWidgetItem * ) ),
74
this, SLOT( slotItemExpanded( QTreeWidgetItem * ) ) );
76
connect( this, SIGNAL( itemCollapsed( QTreeWidgetItem * ) ),
77
this, SLOT( slotItemCollapsed( QTreeWidgetItem * ) ) );
79
73
connect( this, SIGNAL( itemExecuted( QTreeWidgetItem *, int ) ),
80
74
this, SLOT( slotItemExecuted( QTreeWidgetItem *, int ) ) );
99
bool Smb4KNetworkBrowser::event( QEvent *e )
103
case QEvent::ToolTip:
105
// Intercept the tool tip event and show our own tool tip.
106
QPoint pos = viewport()->mapFromGlobal( cursor().pos() );
107
Smb4KNetworkBrowserItem *item = static_cast<Smb4KNetworkBrowserItem *>( itemAt( pos ) );
111
if ( Smb4KSettings::showNetworkItemToolTip() )
115
switch ( item->type() )
117
case Smb4KNetworkBrowserItem::Host:
122
case Smb4KNetworkBrowserItem::Share:
134
// Check that the tooltip is not over the root decoration.
135
// If it is, hide it.
136
if ( pos.x() <= ind * indentation() )
138
if ( m_tooltip->isVisible() )
149
if ( !m_tooltip->isVisible() || (m_tooltip->networkItem() &&
150
QString::compare( item->networkItem()->key(), m_tooltip->networkItem()->key() ) != 0) )
152
switch ( item->type() )
154
case Smb4KNetworkBrowserItem::Workgroup:
156
m_tooltip->show( item->workgroupItem(), pos );
159
case Smb4KNetworkBrowserItem::Host:
161
m_tooltip->show( item->hostItem(), pos );
164
case Smb4KNetworkBrowserItem::Share:
166
m_tooltip->show( item->shareItem(), pos );
183
if ( m_tooltip->isVisible() )
195
if ( m_tooltip->isVisible() )
213
return QTreeWidget::event( e );
105
217
void Smb4KNetworkBrowser::mouseMoveEvent( QMouseEvent *e )
107
// Store the position of the mouse:
110
219
// Find the item over which the user moved the mouse:
111
Smb4KNetworkBrowserItem *item = static_cast<Smb4KNetworkBrowserItem *>( itemAt( m_pos ) );
220
Smb4KNetworkBrowserItem *item = static_cast<Smb4KNetworkBrowserItem *>( itemAt( e->pos() ) );
115
emit itemEntered( item, columnAt( m_pos.x() ) );
224
emit itemEntered( item, columnAt( e->pos().x() ) );
226
// Hide tool tip if the items diverge.
227
if ( m_tooltip->networkItem() && m_tooltip->networkItem() != item->networkItem() )
122
242
QTreeWidget::mouseMoveEvent( e );
146
272
void Smb4KNetworkBrowser::mousePressEvent( QMouseEvent *e )
148
274
// Hide the current tool tip so that it is not in the way.
275
if ( m_tooltip->isVisible() )
151
284
// Get the item that is under the mouse. If there is no
152
285
// item, unselect the current item.
170
303
void Smb4KNetworkBrowser::focusOutEvent( QFocusEvent *e )
172
305
m_auto_select_timer->stop();
174
306
QTreeWidget::focusOutEvent( e );
178
310
void Smb4KNetworkBrowser::wheelEvent( QWheelEvent *e )
312
if ( m_tooltip->isVisible() )
182
321
QTreeWidget::wheelEvent( e );
187
326
// SLOT IMPLEMENTATIONS
188
327
/////////////////////////////////////////////////////////////////////////////
190
void Smb4KNetworkBrowser::slotItemExpanded( QTreeWidgetItem *item )
192
item->setSelected( true );
196
void Smb4KNetworkBrowser::slotItemCollapsed( QTreeWidgetItem *item )
198
item->setSelected( false );
202
329
void Smb4KNetworkBrowser::slotItemEntered( QTreeWidgetItem *item, int /*column*/ )
204
331
// Comply with KDE's settings.
224
// Now initialize the hiding/showing of the tool tip.
225
Smb4KNetworkBrowserItem *browserItem = static_cast<Smb4KNetworkBrowserItem *>( item );
351
if ( m_tooltip->isVisible() )
229
int indentation_factor = 1;
231
switch ( item->type() )
233
case Smb4KNetworkBrowserItem::Host:
235
indentation_factor = 2;
239
case Smb4KNetworkBrowserItem::Share:
241
indentation_factor = 3;
251
// Check that the mouse is not over the root decoration.
252
// If it is, hide the tool tip.
253
if ( m_pos.x() <= indentation_factor * indentation() )
353
Smb4KNetworkBrowserItem *browser_item = static_cast<Smb4KNetworkBrowserItem *>( item );
355
if ( browser_item && m_tooltip->networkItem() &&
356
QString::compare( browser_item->networkItem()->key(), m_tooltip->networkItem()->key() ) != 0 )
259
if ( Smb4KSettings::showNetworkItemToolTip() )
261
if ( m_tooltip->item() == NULL || m_tooltip->item() != browserItem )
263
if ( !m_tooltip->isVisible() )
265
m_tooltip->setupToolTip( browserItem );
267
m_tooltip_timer->setSingleShot( true );
268
connect( m_tooltip_timer, SIGNAL( timeout() ), this, SLOT( slotShowToolTip() ) );
270
m_tooltip_timer->start( 2000 );
284
if ( m_tooltip->isVisible() )
371
void Smb4KNetworkBrowser::slotShowToolTip()
373
disconnect( m_tooltip_timer, 0, 0, 0 );
375
if ( Smb4KSettings::showNetworkItemToolTip() )
377
Smb4KNetworkBrowserItem *browserItem = static_cast<Smb4KNetworkBrowserItem *>( itemAt( m_pos ) );
379
if ( browserItem && !m_tooltip->isCleared() )
381
if ( !m_tooltip->isVisible() )
383
QPoint p( viewport()->mapToGlobal( m_pos ) );
385
QDesktopWidget *d = QApplication::desktop();
387
if ( p.x() + m_tooltip->width() > d->width() )
389
p.setX( p.x() - m_tooltip->width() - 5 );
396
if ( p.y() + m_tooltip->height() > d->height() )
398
p.setY( p.y() - m_tooltip->height() - 5 );
405
m_tooltip->setGeometry( p.x(), p.y(), m_tooltip->width(), m_tooltip->height() );
406
m_tooltip->setVisible( true );
408
m_tooltip_timer->setSingleShot( true );
409
connect( m_tooltip_timer, SIGNAL( timeout() ), this, SLOT( slotHideToolTip() ) );
411
m_tooltip_timer->start( 10000 );
430
void Smb4KNetworkBrowser::slotHideToolTip()
432
disconnect( m_tooltip_timer, 0, 0, 0 );
434
m_tooltip->setVisible( false );
435
m_tooltip->clearToolTip();
439
440
void Smb4KNetworkBrowser::slotKDESettingsChanged( int category )
441
442
// Adjust to KDE's default mouse settings.
476
477
void Smb4KNetworkBrowser::slotAutoSelectItem()
478
479
// Check that the item is still valid.
479
QTreeWidgetItem *item = itemAt( m_pos );
480
QPoint pos = viewport()->mapFromGlobal( cursor().pos() );
481
QTreeWidgetItem *item = itemAt( pos );
481
483
if ( !m_auto_select_item || !item || m_auto_select_item != item )