mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 00:54:20 +02:00
* No need for our own SourceTreeView ItemDelegate.
This commit is contained in:
@@ -114,7 +114,6 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
|
|||||||
sourcetree/sourcetreeitem.cpp
|
sourcetree/sourcetreeitem.cpp
|
||||||
sourcetree/sourcetreeitemwidget.cpp
|
sourcetree/sourcetreeitemwidget.cpp
|
||||||
sourcetree/sourcetreeview.cpp
|
sourcetree/sourcetreeview.cpp
|
||||||
sourcetree/sourcetreedelegate.cpp
|
|
||||||
|
|
||||||
topbar/topbar.cpp
|
topbar/topbar.cpp
|
||||||
topbar/clearbutton.cpp
|
topbar/clearbutton.cpp
|
||||||
@@ -231,7 +230,6 @@ SET( tomahawkHeadersGui ${tomahawkHeadersGui}
|
|||||||
sourcetree/sourcetreeitem.h
|
sourcetree/sourcetreeitem.h
|
||||||
sourcetree/sourcetreeitemwidget.h
|
sourcetree/sourcetreeitemwidget.h
|
||||||
sourcetree/sourcetreeview.h
|
sourcetree/sourcetreeview.h
|
||||||
sourcetree/sourcetreedelegate.h
|
|
||||||
|
|
||||||
topbar/topbar.h
|
topbar/topbar.h
|
||||||
topbar/clearbutton.h
|
topbar/clearbutton.h
|
||||||
|
@@ -67,6 +67,18 @@ SourcesModel::flags( const QModelIndex& index ) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariant
|
||||||
|
SourcesModel::data( const QModelIndex& index, int role ) const
|
||||||
|
{
|
||||||
|
if ( role == Qt::SizeHintRole )
|
||||||
|
{
|
||||||
|
return QSize( 0, 18 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return QStandardItemModel::data( index, role );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SourcesModel::loadSources()
|
SourcesModel::loadSources()
|
||||||
{
|
{
|
||||||
|
@@ -18,6 +18,7 @@ public:
|
|||||||
virtual QStringList mimeTypes() const;
|
virtual QStringList mimeTypes() const;
|
||||||
virtual Qt::DropActions supportedDropActions() const;
|
virtual Qt::DropActions supportedDropActions() const;
|
||||||
virtual Qt::ItemFlags flags( const QModelIndex& index ) const;
|
virtual Qt::ItemFlags flags( const QModelIndex& index ) const;
|
||||||
|
QVariant data( const QModelIndex& index, int role ) const;
|
||||||
|
|
||||||
bool appendItem( const Tomahawk::source_ptr& source );
|
bool appendItem( const Tomahawk::source_ptr& source );
|
||||||
bool removeItem( const Tomahawk::source_ptr& source );
|
bool removeItem( const Tomahawk::source_ptr& source );
|
||||||
|
@@ -1,52 +0,0 @@
|
|||||||
#include "sourcetreedelegate.h"
|
|
||||||
|
|
||||||
#include <QLineEdit>
|
|
||||||
#include <QAbstractItemView>
|
|
||||||
|
|
||||||
|
|
||||||
SourceTreeDelegate::SourceTreeDelegate( QAbstractItemView* parent )
|
|
||||||
: QStyledItemDelegate( (QObject*)parent )
|
|
||||||
, m_view( parent )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QWidget*
|
|
||||||
SourceTreeDelegate::createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
|
||||||
{
|
|
||||||
QLineEdit* editor = new QLineEdit( parent );
|
|
||||||
editor->setFrame( false );
|
|
||||||
editor->setObjectName( "playlistEditor" );
|
|
||||||
|
|
||||||
return editor;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
SourceTreeDelegate::updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
|
||||||
{
|
|
||||||
if ( editor->objectName() != "playlistEditor" )
|
|
||||||
return;
|
|
||||||
|
|
||||||
QRect r = option.rect;
|
|
||||||
r.adjust( 20, -1, -8, 1 );
|
|
||||||
|
|
||||||
editor->setGeometry( r );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
SourceTreeDelegate::setModelData( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index ) const
|
|
||||||
{
|
|
||||||
QLineEdit* le = static_cast<QLineEdit*>( editor );
|
|
||||||
|
|
||||||
model->setData( index, le->text(), Qt::EditRole );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QSize
|
|
||||||
SourceTreeDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
|
||||||
{
|
|
||||||
QSize size = QStyledItemDelegate::sizeHint( option, index );
|
|
||||||
return size;
|
|
||||||
}
|
|
@@ -1,25 +0,0 @@
|
|||||||
#ifndef SOURCETREEDELEGATE_H
|
|
||||||
#define SOURCETREEDELEGATE_H
|
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QStyledItemDelegate>
|
|
||||||
|
|
||||||
class SourceTreeDelegate : public QStyledItemDelegate
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
SourceTreeDelegate( QAbstractItemView* parent = 0 );
|
|
||||||
|
|
||||||
protected:
|
|
||||||
QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
|
||||||
|
|
||||||
QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
|
||||||
void updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
|
||||||
void setModelData( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index ) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
QAbstractItemView* m_view;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // SOURCETREEDELEGATE_H
|
|
@@ -6,12 +6,12 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>298</width>
|
||||||
<height>44</height>
|
<height>44</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
|
@@ -6,7 +6,6 @@
|
|||||||
#include "playlistmanager.h"
|
#include "playlistmanager.h"
|
||||||
#include "sourcetreeitem.h"
|
#include "sourcetreeitem.h"
|
||||||
#include "sourcesmodel.h"
|
#include "sourcesmodel.h"
|
||||||
#include "sourcetreedelegate.h"
|
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QContextMenuEvent>
|
#include <QContextMenuEvent>
|
||||||
@@ -36,9 +35,6 @@ SourceTreeView::SourceTreeView( QWidget* parent )
|
|||||||
setContextMenuPolicy( Qt::CustomContextMenu );
|
setContextMenuPolicy( Qt::CustomContextMenu );
|
||||||
connect( this, SIGNAL( customContextMenuRequested( const QPoint& ) ), SLOT( onCustomContextMenu( const QPoint& ) ) );
|
connect( this, SIGNAL( customContextMenuRequested( const QPoint& ) ), SLOT( onCustomContextMenu( const QPoint& ) ) );
|
||||||
|
|
||||||
m_delegate = new SourceTreeDelegate( this );
|
|
||||||
setItemDelegate( m_delegate );
|
|
||||||
|
|
||||||
m_model = new SourcesModel( this );
|
m_model = new SourcesModel( this );
|
||||||
setModel( m_model );
|
setModel( m_model );
|
||||||
|
|
||||||
|
@@ -9,7 +9,6 @@
|
|||||||
class CollectionModel;
|
class CollectionModel;
|
||||||
class PlaylistModel;
|
class PlaylistModel;
|
||||||
class SourcesModel;
|
class SourcesModel;
|
||||||
class SourceTreeDelegate;
|
|
||||||
|
|
||||||
class SourceTreeView : public QTreeView
|
class SourceTreeView : public QTreeView
|
||||||
{
|
{
|
||||||
@@ -48,7 +47,6 @@ private:
|
|||||||
|
|
||||||
CollectionModel* m_collectionModel;
|
CollectionModel* m_collectionModel;
|
||||||
SourcesModel* m_model;
|
SourcesModel* m_model;
|
||||||
SourceTreeDelegate* m_delegate;
|
|
||||||
QModelIndex m_contextMenuIndex;
|
QModelIndex m_contextMenuIndex;
|
||||||
|
|
||||||
QMenu m_playlistMenu;
|
QMenu m_playlistMenu;
|
||||||
|
Reference in New Issue
Block a user