extragear/multimedia/amarok/src/browsers
Jeff Mitchell
mitchell at kde.org
Thu May 21 20:52:11 CEST 2009
SVN commit 971139 by mitchell:
Make all CollectionTreeView-derived browsers use the KDE-specified double/single-click settings. This was one of the goals for pre-2.1, so putting it in now (plus Leo requested it since he found it confusing to switch behaviors for various tree views, which is understandable).
I've run it through a gamut of tests with both single- and double-click modes, and seems to work well. But do test.
CCMAIL: amarok-devel at kde.org
M +106 -26 CollectionTreeView.cpp
M +11 -3 CollectionTreeView.h
M +0 -113 collectionbrowser/CollectionBrowserTreeView.cpp
M +0 -20 collectionbrowser/CollectionBrowserTreeView.h
--- trunk/extragear/multimedia/amarok/src/browsers/CollectionTreeView.cpp #971138:971139
@@ -46,8 +46,10 @@
#include <QContextMenuEvent>
#include <QHash>
+#include <QMouseEvent>
#include <QSet>
+#include <KGlobalSettings>
#include <KIcon>
#include <KLineEdit>
#include <KMenu>
@@ -66,7 +68,9 @@
, m_cmSeperator( 0 )
, m_dragMutex()
, m_ongoingDrag( false )
+ , m_justDoubleClicked( false )
{
+ setMouseTracking( true );
setSortingEnabled( true );
sortByColumn( 0, Qt::AscendingOrder );
setSelectionMode( QAbstractItemView::ExtendedSelection );
@@ -91,6 +95,8 @@
connect( this, SIGNAL( collapsed( const QModelIndex & ) ), SLOT( slotCollapsed( const QModelIndex & ) ) );
connect( this, SIGNAL( expanded( const QModelIndex & ) ), SLOT( slotExpanded( const QModelIndex & ) ) );
+
+ connect( &m_clickTimer, SIGNAL( timeout() ), this, SLOT( slotClickTimeout() ) );
}
void CollectionTreeView::setModel(QAbstractItemModel * model)
@@ -252,21 +258,115 @@
void CollectionTreeView::mouseDoubleClickEvent( QMouseEvent *event )
{
- QModelIndex index;
+ QModelIndex origIndex = indexAt( event->pos() );
+ QModelIndex filteredIndex;
if( m_filterModel )
- index = m_filterModel->mapToSource( indexAt( event->pos() ) );
+ filteredIndex = m_filterModel->mapToSource( indexAt( event->pos() ) );
else
- index = indexAt( event->pos() );
+ filteredIndex = indexAt( event->pos() );
- if( index.isValid() )
+ if( !filteredIndex.isValid() )
{
- CollectionTreeItem *item = static_cast<CollectionTreeItem*>( index.internalPointer() );
+ event->accept();
+ return;
+ }
+
+ CollectionTreeItem *item = static_cast<CollectionTreeItem*>( filteredIndex.internalPointer() );
+
+ if( event->button() != Qt::LeftButton || event->modifiers()
+ || KGlobalSettings::singleClick() || ( item && item->isTrackItem() ) )
+ {
playChildTracks( item, Playlist::AppendAndPlay );
+ update();
+ event->accept();
+ return;
}
+
+ m_clickTimer.stop();
+ //m_justDoubleClicked is necessary because the mouseReleaseEvent still
+ //comes through, but after the mouseDoubleClickEvent, so we need to tell
+ //mouseReleaseEvent to ignore that one event
+ m_justDoubleClicked = true;
+ setExpanded( origIndex, !isExpanded( origIndex ) );
+ event->accept();
}
-void CollectionTreeView::keyPressEvent( QKeyEvent * event )
+void CollectionTreeView::mousePressEvent( QMouseEvent *event )
{
+ if( KGlobalSettings::singleClick() )
+ setItemsExpandable( false );
+ update();
+ Amarok::PrettyTreeView::mousePressEvent( event );
+}
+
+void CollectionTreeView::mouseReleaseEvent( QMouseEvent *event )
+{
+ if( m_pd )
+ {
+ connect( m_pd, SIGNAL( fadeHideFinished() ), m_pd, SLOT( deleteLater() ) );
+ m_pd->hide();
+ }
+ m_pd = 0;
+
+ setItemsExpandable( true );
+ if( event->button() != Qt::LeftButton
+ || event->modifiers()
+ || selectedIndexes().size() > 1)
+ {
+ Amarok::PrettyTreeView::mousePressEvent( event );
+ update();
+ return;
+ }
+
+ if( m_clickTimer.isActive() || m_justDoubleClicked )
+ {
+ //it's a double-click...so ignore it
+ m_clickTimer.stop();
+ m_justDoubleClicked = false;
+ m_savedClickIndex = QModelIndex();
+ event->accept();
+ return;
+ }
+
+ m_savedClickIndex = indexAt( event->pos() );
+ KConfigGroup cg( KGlobal::config(), "KDE" );
+ m_clickTimer.start( cg.readEntry( "DoubleClickInterval", 400 ) );
+ m_clickLocation = event->pos();
+ event->accept();
+}
+
+void CollectionTreeView::mouseMoveEvent( QMouseEvent *event )
+{
+ if( event->buttons() || event->modifiers() )
+ {
+ Amarok::PrettyTreeView::mouseMoveEvent( event );
+ update();
+ return;
+ }
+ QPoint point = event->pos() - m_clickLocation;
+ KConfigGroup cg( KGlobal::config(), "KDE" );
+ if( point.manhattanLength() > cg.readEntry( "StartDragDistance", 4 ) )
+ {
+ m_clickTimer.stop();
+ slotClickTimeout();
+ event->accept();
+ }
+ else
+ Amarok::PrettyTreeView::mouseMoveEvent( event );
+}
+
+void CollectionTreeView::slotClickTimeout()
+{
+ m_clickTimer.stop();
+ if( m_savedClickIndex.isValid() && KGlobalSettings::singleClick() )
+ {
+ setExpanded( m_savedClickIndex, !isExpanded( m_savedClickIndex ) );
+ }
+ m_savedClickIndex = QModelIndex();
+}
+
+void CollectionTreeView::keyPressEvent( QKeyEvent *event )
+{
QModelIndexList indices = selectedIndexes();
if( m_filterModel )
{
@@ -407,14 +507,6 @@
m_dragMutex.unlock();
}
-void CollectionTreeView::getIndexForEvent( QMouseEvent *event, QModelIndex &index )
-{
- if( m_filterModel )
- index = m_filterModel->mapToSource( indexAt( event->pos() ) );
- else
- index = indexAt( event->pos() );
-}
-
void CollectionTreeView::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
{
Q_UNUSED( deselected )
@@ -906,18 +998,6 @@
return collection;
}
-void CollectionTreeView::mouseReleaseEvent( QMouseEvent * event )
-{
- if( m_pd )
- {
- connect( m_pd, SIGNAL( fadeHideFinished() ), m_pd, SLOT( deleteLater() ) );
- m_pd->hide();
- }
- m_pd = 0;
-
- QTreeView::mouseReleaseEvent( event );
-}
-
void CollectionTreeView::slotPlayChildTracks()
{
playChildTracks( m_currentItems, Playlist::LoadAndPlay );
--- trunk/extragear/multimedia/amarok/src/browsers/CollectionTreeView.h #971138:971139
@@ -25,7 +25,9 @@
#include "widgets/PrettyTreeView.h"
+#include <QModelIndex>
#include <QMutex>
+#include <QPoint>
#include <QSet>
#include <QSortFilterProxyModel>
#include <QTimer>
@@ -71,20 +73,22 @@
void slotFilterNow();
protected:
+ void mouseDoubleClickEvent( QMouseEvent *event );
+ void mouseMoveEvent( QMouseEvent *event );
+ void mousePressEvent( QMouseEvent *event );
void mouseReleaseEvent( QMouseEvent *event );
- void mouseDoubleClickEvent( QMouseEvent *event );
void keyPressEvent( QKeyEvent * event );
void startDrag( Qt::DropActions supportedActions );
//void changeEvent ( QEvent * event );
- void getIndexForEvent( QMouseEvent *event, QModelIndex &index );
-
protected slots:
virtual void selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected );
void slotExpand( const QModelIndex &index );
void slotCollapsed( const QModelIndex &index );
void slotExpanded( const QModelIndex &index );
+ void slotClickTimeout();
+
void slotPlayChildTracks();
void slotAppendChildTracks();
void slotQueueChildTracks();
@@ -133,6 +137,10 @@
QMutex m_dragMutex;
bool m_ongoingDrag;
+ QPoint m_clickLocation;
+ QTimer m_clickTimer;
+ QModelIndex m_savedClickIndex;
+ bool m_justDoubleClicked;
signals:
void itemSelected( CollectionTreeItem * item );
--- trunk/extragear/multimedia/amarok/src/browsers/collectionbrowser/CollectionBrowserTreeView.cpp #971138:971139
@@ -20,125 +20,12 @@
#include "Debug.h"
-#include <KGlobalSettings>
-
-#include <QMouseEvent>
-
-
CollectionBrowserTreeView::CollectionBrowserTreeView( QWidget *parent )
: CollectionTreeView( parent )
- , m_justDoubleClicked( false )
{
- setMouseTracking( true );
- connect( &m_clickTimer, SIGNAL( timeout() ), this, SLOT( slotClickTimeout() ) );
}
CollectionBrowserTreeView::~CollectionBrowserTreeView()
{
}
-void CollectionBrowserTreeView::mouseDoubleClickEvent( QMouseEvent *event )
-{
- if( event->button() != Qt::LeftButton || event->modifiers() )
- {
- CollectionTreeView::mouseDoubleClickEvent( event );
- update();
- return;
- }
- m_clickTimer.stop();
- //m_justDoubleClicked is necessary because the mouseReleaseEvent still
- //comes through, but after the mouseDoubleClickEvent, so we need to tell
- //mouseReleaseEvent to ignore that one event
- m_justDoubleClicked = true;
-
- QModelIndex origIndex = indexAt( event->pos() );
- QModelIndex filteredIndex;
- CollectionTreeView::getIndexForEvent( event, filteredIndex );
-
- if( filteredIndex.isValid() && !KGlobalSettings::singleClick() )
- {
- CollectionTreeItem *item = static_cast<CollectionTreeItem*>( filteredIndex.internalPointer() );
- if( item->isTrackItem() ) //detect if item is track
- {
- CollectionTreeView::mouseDoubleClickEvent( event );
- }
- else
- {
- setExpanded( origIndex, !isExpanded( origIndex ) );
- event->accept();
- }
- m_clickTimer.stop();
- }
- else // propagate to base class
- CollectionTreeView::mouseDoubleClickEvent( event );
-}
-
-void CollectionBrowserTreeView::mousePressEvent( QMouseEvent *event )
-{
- if( KGlobalSettings::singleClick() )
- setItemsExpandable( false );
- CollectionTreeView::mousePressEvent( event );
- update();
-}
-
-void CollectionBrowserTreeView::mouseReleaseEvent( QMouseEvent *event )
-{
- setItemsExpandable( true );
- if( event->button() != Qt::LeftButton
- || event->modifiers()
- || selectedIndexes().size() > 1)
- {
- CollectionTreeView::mouseReleaseEvent( event );
- update();
- return;
- }
-
- if( m_clickTimer.isActive() || m_justDoubleClicked )
- {
- //it's a double-click...so ignore it
- m_clickTimer.stop();
- m_justDoubleClicked = false;
- m_index = QModelIndex();
- event->accept();
- return;
- }
-
- QModelIndex index = indexAt( event->pos() );
- m_index = index;
- KConfigGroup cg( KGlobal::config(), "KDE" );
- m_clickTimer.start( cg.readEntry( "DoubleClickInterval", 400 ) );
- m_clickLocation = event->pos();
- event->accept();
-}
-
-void CollectionBrowserTreeView::mouseMoveEvent( QMouseEvent *event )
-{
- if( event->buttons() || event->modifiers() )
- {
- CollectionTreeView::mouseMoveEvent( event );
- update();
- return;
- }
- QPoint point = event->pos() - m_clickLocation;
- KConfigGroup cg( KGlobal::config(), "KDE" );
- if( point.manhattanLength() > cg.readEntry( "StartDragDistance", 4 ) )
- {
- m_clickTimer.stop();
- slotClickTimeout();
- event->accept();
- }
- else
- CollectionTreeView::mouseMoveEvent( event );
-}
-
-void CollectionBrowserTreeView::slotClickTimeout()
-{
- m_clickTimer.stop();
- if( m_index.isValid() && KGlobalSettings::singleClick() )
- {
- setExpanded( m_index, !isExpanded( m_index ) );
- }
- m_index = QModelIndex();
-}
-
-#include "CollectionBrowserTreeView.moc"
--- trunk/extragear/multimedia/amarok/src/browsers/collectionbrowser/CollectionBrowserTreeView.h #971138:971139
@@ -21,35 +21,15 @@
#include "CollectionTreeView.h"
-#include <QModelIndex>
-#include <QPoint>
-#include <QTimer>
-
/**
* Specialized CollectionTreeView that handles actions to top level items ( collections ) in a custom way.
*/
class CollectionBrowserTreeView : public CollectionTreeView
{
- Q_OBJECT
-
public:
CollectionBrowserTreeView( QWidget *parent = 0 );
~CollectionBrowserTreeView();
- protected:
- void mouseDoubleClickEvent( QMouseEvent *event );
- void mousePressEvent( QMouseEvent *event );
- void mouseReleaseEvent( QMouseEvent *event );
- void mouseMoveEvent( QMouseEvent *event );
-
- protected slots:
- void slotClickTimeout();
-
- private:
- QModelIndex m_index;
- QPoint m_clickLocation;
- QTimer m_clickTimer;
- bool m_justDoubleClicked;
};
#endif
More information about the Amarok-devel
mailing list