mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-14 21:11:56 +02:00
added SettingsListDelegate to center the items in SettingsDialogList
BUG: 314
This commit is contained in:
parent
fbcfb552ad
commit
27480f8cdb
@ -72,6 +72,7 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
|
||||
configdelegatebase.cpp
|
||||
sipconfigdelegate.cpp
|
||||
resolverconfigdelegate.cpp
|
||||
settingslistdelegate.cpp
|
||||
resolversmodel.cpp
|
||||
tomahawkwindow.cpp
|
||||
)
|
||||
@ -115,6 +116,7 @@ SET( tomahawkHeadersGui ${tomahawkHeadersGui}
|
||||
configdelegatebase.h
|
||||
resolverconfigdelegate.h
|
||||
sipconfigdelegate.h
|
||||
settingslistdelegate.h
|
||||
resolversmodel.h
|
||||
delegateconfigwrapper.h
|
||||
tomahawkwindow.h
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "delegateconfigwrapper.h"
|
||||
#include "sip/SipModel.h"
|
||||
#include "sipconfigdelegate.h"
|
||||
#include "settingslistdelegate.h"
|
||||
|
||||
#include "utils/logger.h"
|
||||
|
||||
@ -181,6 +182,7 @@ SettingsDialog::SettingsDialog( QWidget *parent )
|
||||
connect( this, SIGNAL( rejected() ), SLOT( onRejected() ) );
|
||||
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user