1
0
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:
Michael Zanetti 2011-08-10 03:41:02 +02:00
parent fbcfb552ad
commit 27480f8cdb
4 changed files with 60 additions and 0 deletions

View File

@ -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

View File

@ -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());
}

View 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();
}

View 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