mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 03:10:12 +02:00
added SettingsListDelegate to center the items in SettingsDialogList
BUG: 314
This commit is contained in:
@@ -72,6 +72,7 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
|
|||||||
configdelegatebase.cpp
|
configdelegatebase.cpp
|
||||||
sipconfigdelegate.cpp
|
sipconfigdelegate.cpp
|
||||||
resolverconfigdelegate.cpp
|
resolverconfigdelegate.cpp
|
||||||
|
settingslistdelegate.cpp
|
||||||
resolversmodel.cpp
|
resolversmodel.cpp
|
||||||
tomahawkwindow.cpp
|
tomahawkwindow.cpp
|
||||||
)
|
)
|
||||||
@@ -115,6 +116,7 @@ SET( tomahawkHeadersGui ${tomahawkHeadersGui}
|
|||||||
configdelegatebase.h
|
configdelegatebase.h
|
||||||
resolverconfigdelegate.h
|
resolverconfigdelegate.h
|
||||||
sipconfigdelegate.h
|
sipconfigdelegate.h
|
||||||
|
settingslistdelegate.h
|
||||||
resolversmodel.h
|
resolversmodel.h
|
||||||
delegateconfigwrapper.h
|
delegateconfigwrapper.h
|
||||||
tomahawkwindow.h
|
tomahawkwindow.h
|
||||||
|
@@ -45,6 +45,7 @@
|
|||||||
#include "delegateconfigwrapper.h"
|
#include "delegateconfigwrapper.h"
|
||||||
#include "sip/SipModel.h"
|
#include "sip/SipModel.h"
|
||||||
#include "sipconfigdelegate.h"
|
#include "sipconfigdelegate.h"
|
||||||
|
#include "settingslistdelegate.h"
|
||||||
|
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
|
|
||||||
@@ -181,6 +182,7 @@ SettingsDialog::SettingsDialog( QWidget *parent )
|
|||||||
connect( this, SIGNAL( rejected() ), SLOT( onRejected() ) );
|
connect( this, SIGNAL( rejected() ), SLOT( onRejected() ) );
|
||||||
|
|
||||||
ui->listWidget->setCurrentRow( 0 );
|
ui->listWidget->setCurrentRow( 0 );
|
||||||
|
ui->listWidget->setItemDelegate(new SettingsListDelegate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
36
src/settingslistdelegate.cpp
Normal file
36
src/settingslistdelegate.cpp
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#include "settingslistdelegate.h"
|
||||||
|
#include "utils/logger.h"
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
SettingsListDelegate::SettingsListDelegate(QObject *parent) :
|
||||||
|
QStyledItemDelegate(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
|
||||||
|
painter->save();
|
||||||
|
|
||||||
|
QStyleOptionViewItemV4 opt = option;
|
||||||
|
initStyleOption( &opt, QModelIndex() );
|
||||||
|
qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );
|
||||||
|
|
||||||
|
QRect iconRect = option.rect.adjusted( 23, 6, -option.rect.width() + option.decorationSize.width() + 7, -option.rect.height() + option.decorationSize.height() + 2 - 12 );
|
||||||
|
QPixmap avatar = index.data( Qt::DecorationRole ).value<QIcon>().pixmap( iconRect.size() );
|
||||||
|
painter->drawPixmap( iconRect, avatar.scaledToHeight( iconRect.height(), Qt::SmoothTransformation ) );
|
||||||
|
|
||||||
|
if ( ( option.state & QStyle::State_Selected ) == QStyle::State_Selected )
|
||||||
|
{
|
||||||
|
painter->setPen( option.palette.color( QPalette::HighlightedText ) );
|
||||||
|
}
|
||||||
|
QRect textRect = option.rect.adjusted( 6, iconRect.height() + 8, -6, 0 );
|
||||||
|
QString text = painter->fontMetrics().elidedText( index.data( Qt::DisplayRole ).toString(), Qt::ElideRight, textRect.width() );
|
||||||
|
QTextOption to( Qt::AlignHCenter );
|
||||||
|
painter->drawText( textRect, text, to);
|
||||||
|
|
||||||
|
painter->restore();
|
||||||
|
}
|
20
src/settingslistdelegate.h
Normal file
20
src/settingslistdelegate.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef SETTINGSLISTDELEGATE_H
|
||||||
|
#define SETTINGSLISTDELEGATE_H
|
||||||
|
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
|
class SettingsListDelegate : public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit SettingsListDelegate(QObject *parent = 0);
|
||||||
|
|
||||||
|
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SETTINGSLISTDELEGATE_H
|
Reference in New Issue
Block a user