mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 16:44:05 +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/sourcetreeitemwidget.cpp
|
||||
sourcetree/sourcetreeview.cpp
|
||||
sourcetree/sourcetreedelegate.cpp
|
||||
|
||||
topbar/topbar.cpp
|
||||
topbar/clearbutton.cpp
|
||||
@@ -231,7 +230,6 @@ SET( tomahawkHeadersGui ${tomahawkHeadersGui}
|
||||
sourcetree/sourcetreeitem.h
|
||||
sourcetree/sourcetreeitemwidget.h
|
||||
sourcetree/sourcetreeview.h
|
||||
sourcetree/sourcetreedelegate.h
|
||||
|
||||
topbar/topbar.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
|
||||
SourcesModel::loadSources()
|
||||
{
|
||||
|
@@ -18,6 +18,7 @@ public:
|
||||
virtual QStringList mimeTypes() const;
|
||||
virtual Qt::DropActions supportedDropActions() 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 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>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<width>298</width>
|
||||
<height>44</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
|
@@ -6,7 +6,6 @@
|
||||
#include "playlistmanager.h"
|
||||
#include "sourcetreeitem.h"
|
||||
#include "sourcesmodel.h"
|
||||
#include "sourcetreedelegate.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QContextMenuEvent>
|
||||
@@ -36,9 +35,6 @@ SourceTreeView::SourceTreeView( QWidget* parent )
|
||||
setContextMenuPolicy( Qt::CustomContextMenu );
|
||||
connect( this, SIGNAL( customContextMenuRequested( const QPoint& ) ), SLOT( onCustomContextMenu( const QPoint& ) ) );
|
||||
|
||||
m_delegate = new SourceTreeDelegate( this );
|
||||
setItemDelegate( m_delegate );
|
||||
|
||||
m_model = new SourcesModel( this );
|
||||
setModel( m_model );
|
||||
|
||||
|
@@ -9,7 +9,6 @@
|
||||
class CollectionModel;
|
||||
class PlaylistModel;
|
||||
class SourcesModel;
|
||||
class SourceTreeDelegate;
|
||||
|
||||
class SourceTreeView : public QTreeView
|
||||
{
|
||||
@@ -48,7 +47,6 @@ private:
|
||||
|
||||
CollectionModel* m_collectionModel;
|
||||
SourcesModel* m_model;
|
||||
SourceTreeDelegate* m_delegate;
|
||||
QModelIndex m_contextMenuIndex;
|
||||
|
||||
QMenu m_playlistMenu;
|
||||
|
Reference in New Issue
Block a user