mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
fix config rect handling
This commit is contained in:
@@ -71,7 +71,6 @@ ConfigDelegateBase::drawConfigWrench ( QPainter* painter, QStyleOptionViewItemV4
|
|||||||
const QWidget* w = opt.widget;
|
const QWidget* w = opt.widget;
|
||||||
QStyle* style = w ? w->style() : QApplication::style();
|
QStyle* style = w ? w->style() : QApplication::style();
|
||||||
|
|
||||||
m_configRect = topt.rect;
|
|
||||||
// draw it the same size as the check belox
|
// draw it the same size as the check belox
|
||||||
topt.font = opt.font;
|
topt.font = opt.font;
|
||||||
topt.icon = QIcon( RESPATH "images/configure.png" );
|
topt.icon = QIcon( RESPATH "images/configure.png" );
|
||||||
@@ -109,7 +108,7 @@ ConfigDelegateBase::editorEvent ( QEvent* event, QAbstractItemModel* model, cons
|
|||||||
|
|
||||||
} else if( event->type() == QEvent::MouseButtonPress ) {
|
} else if( event->type() == QEvent::MouseButtonPress ) {
|
||||||
QMouseEvent* me = static_cast< QMouseEvent* >( event );
|
QMouseEvent* me = static_cast< QMouseEvent* >( event );
|
||||||
if( me->button() == Qt::LeftButton && m_configRect.contains( me->pos() ) ) {
|
if( me->button() == Qt::LeftButton && configRectForIndex( option, index ).contains( me->pos() ) ) {
|
||||||
m_configPressed = true;
|
m_configPressed = true;
|
||||||
|
|
||||||
emit configPressed( index );
|
emit configPressed( index );
|
||||||
|
@@ -35,6 +35,9 @@ public:
|
|||||||
|
|
||||||
virtual bool editorEvent ( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
|
virtual bool editorEvent ( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
|
||||||
|
|
||||||
|
// if you want to use a config wrench, you need to have this say where to paint it
|
||||||
|
virtual QRect configRectForIndex( const QStyleOptionViewItem& option, const QModelIndex& idx ) const = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void configPressed( const QModelIndex& idx );
|
void configPressed( const QModelIndex& idx );
|
||||||
|
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
|
||||||
#define PADDING 4
|
#define PADDING 4
|
||||||
|
#define ICONSIZE 24
|
||||||
ResolverConfigDelegate::ResolverConfigDelegate( QObject* parent )
|
ResolverConfigDelegate::ResolverConfigDelegate( QObject* parent )
|
||||||
: ConfigDelegateBase( parent )
|
: ConfigDelegateBase( parent )
|
||||||
{
|
{
|
||||||
@@ -60,8 +60,7 @@ ResolverConfigDelegate::paint( QPainter* painter, const QStyleOptionViewItem& op
|
|||||||
style->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter, w );
|
style->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter, w );
|
||||||
|
|
||||||
int rightSplit = itemRect.width();
|
int rightSplit = itemRect.width();
|
||||||
int rectW = 24;
|
QRect confRect = QRect( rightSplit - ICONSIZE - 2 * PADDING, 2 * PADDING + top, ICONSIZE, ICONSIZE );
|
||||||
QRect confRect = QRect( rightSplit - rectW - 2 * PADDING, 2 * PADDING + top, rectW, rectW );
|
|
||||||
|
|
||||||
// if the resolver has a config widget, paint it first (right-aligned)
|
// if the resolver has a config widget, paint it first (right-aligned)
|
||||||
if( index.data( ResolversModel::HasConfig ).toBool() ) {
|
if( index.data( ResolversModel::HasConfig ).toBool() ) {
|
||||||
@@ -101,6 +100,19 @@ ResolverConfigDelegate::paint( QPainter* painter, const QStyleOptionViewItem& op
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRect
|
||||||
|
ResolverConfigDelegate::configRectForIndex( const QStyleOptionViewItem& option, const QModelIndex& idx ) const
|
||||||
|
{
|
||||||
|
QStyleOptionViewItemV4 opt = option;
|
||||||
|
initStyleOption( &opt, idx );
|
||||||
|
QRect itemRect = opt.rect;
|
||||||
|
int top = itemRect.top();
|
||||||
|
|
||||||
|
QRect confRect = QRect( itemRect.width() - ICONSIZE - 2 * PADDING, 2 * PADDING + top, ICONSIZE, ICONSIZE );
|
||||||
|
return confRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ResolverConfigDelegate::onConfigPressed( const QModelIndex& idx )
|
ResolverConfigDelegate::onConfigPressed( const QModelIndex& idx )
|
||||||
{
|
{
|
||||||
|
@@ -29,6 +29,7 @@ class ResolverConfigDelegate : public ConfigDelegateBase
|
|||||||
public:
|
public:
|
||||||
explicit ResolverConfigDelegate(QObject* parent = 0);
|
explicit ResolverConfigDelegate(QObject* parent = 0);
|
||||||
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||||
|
virtual QRect configRectForIndex ( const QStyleOptionViewItem& option, const QModelIndex& idx ) const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onConfigPressed ( const QModelIndex& );
|
void onConfigPressed ( const QModelIndex& );
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
|
#define ICONSIZE 24
|
||||||
SipConfigDelegate::SipConfigDelegate( QObject* parent )
|
SipConfigDelegate::SipConfigDelegate( QObject* parent )
|
||||||
: ConfigDelegateBase ( parent )
|
: ConfigDelegateBase ( parent )
|
||||||
{
|
{
|
||||||
@@ -61,10 +62,9 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option
|
|||||||
QStyle* style = w ? w->style() : QApplication::style();
|
QStyle* style = w ? w->style() : QApplication::style();
|
||||||
style->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter, w );
|
style->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter, w );
|
||||||
|
|
||||||
int iconSize = 24;
|
|
||||||
int checkLeftEdge = 8;
|
int checkLeftEdge = 8;
|
||||||
int iconLeftEdge = checkLeftEdge + iconSize + PADDING;
|
int iconLeftEdge = checkLeftEdge + ICONSIZE + PADDING;
|
||||||
int textLeftEdge = iconLeftEdge + iconSize + PADDING;
|
int textLeftEdge = iconLeftEdge + ICONSIZE + PADDING;
|
||||||
|
|
||||||
if( index.data( SipModel::FactoryRole ).toBool() ) { // this is the "add new account" row
|
if( index.data( SipModel::FactoryRole ).toBool() ) { // this is the "add new account" row
|
||||||
// draw a border and background
|
// draw a border and background
|
||||||
@@ -80,7 +80,7 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option
|
|||||||
|
|
||||||
// draw "+" icon in checkbox column
|
// draw "+" icon in checkbox column
|
||||||
int rectW = 18;
|
int rectW = 18;
|
||||||
int diff = ( iconSize/ 2 ) - ( rectW / 2) ;
|
int diff = ( ICONSIZE/ 2 ) - ( rectW / 2) ;
|
||||||
int pos = ( mid ) - ( rectW / 2 );
|
int pos = ( mid ) - ( rectW / 2 );
|
||||||
QRect plusRect = QRect( checkLeftEdge + diff, pos + top, rectW, rectW );
|
QRect plusRect = QRect( checkLeftEdge + diff, pos + top, rectW, rectW );
|
||||||
QPixmap p( RESPATH "images/list-add.png" );
|
QPixmap p( RESPATH "images/list-add.png" );
|
||||||
@@ -116,7 +116,7 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option
|
|||||||
QIcon icon = index.data( SipModel::FactoryItemIcon ).value< QIcon >();
|
QIcon icon = index.data( SipModel::FactoryItemIcon ).value< QIcon >();
|
||||||
if( !icon.isNull() ) {
|
if( !icon.isNull() ) {
|
||||||
int rectW = 18;
|
int rectW = 18;
|
||||||
int diff = ( iconSize/ 2 ) - ( rectW / 2) ;
|
int diff = ( ICONSIZE/ 2 ) - ( rectW / 2) ;
|
||||||
int pos = ( mid ) - ( rectW / 2 );
|
int pos = ( mid ) - ( rectW / 2 );
|
||||||
QRect rect = QRect( checkLeftEdge + diff, pos + top, rectW, rectW );
|
QRect rect = QRect( checkLeftEdge + diff, pos + top, rectW, rectW );
|
||||||
QPixmap p( icon.pixmap( rect.size() ) );
|
QPixmap p( icon.pixmap( rect.size() ) );
|
||||||
@@ -137,15 +137,15 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option
|
|||||||
painter->drawText( textR, text );
|
painter->drawText( textR, text );
|
||||||
} else { // this is an existing account to show
|
} else { // this is an existing account to show
|
||||||
// draw checkbox first
|
// draw checkbox first
|
||||||
int pos = ( mid ) - ( iconSize / 2 );
|
int pos = ( mid ) - ( ICONSIZE / 2 );
|
||||||
QRect checkRect = QRect( checkLeftEdge, pos + top, iconSize, iconSize );
|
QRect checkRect = QRect( checkLeftEdge, pos + top, ICONSIZE, ICONSIZE );
|
||||||
opt.rect = checkRect;
|
opt.rect = checkRect;
|
||||||
drawCheckBox( opt, painter, w );
|
drawCheckBox( opt, painter, w );
|
||||||
|
|
||||||
// draw the icon if it exists
|
// draw the icon if it exists
|
||||||
pos = ( mid ) - ( iconSize / 2 );
|
pos = ( mid ) - ( ICONSIZE / 2 );
|
||||||
if( !index.data( Qt::DecorationRole ).value< QIcon >().isNull() ) {
|
if( !index.data( Qt::DecorationRole ).value< QIcon >().isNull() ) {
|
||||||
QRect prect = QRect( iconLeftEdge, pos + top, iconSize, iconSize );
|
QRect prect = QRect( iconLeftEdge, pos + top, ICONSIZE, ICONSIZE );
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->drawPixmap( prect, index.data( Qt::DecorationRole ).value< QIcon >().pixmap( prect.size() ) );
|
painter->drawPixmap( prect, index.data( Qt::DecorationRole ).value< QIcon >().pixmap( prect.size() ) );
|
||||||
@@ -153,7 +153,7 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option
|
|||||||
}
|
}
|
||||||
|
|
||||||
// from the right edge--config status and online/offline
|
// from the right edge--config status and online/offline
|
||||||
QRect confRect = QRect( itemRect.width() - iconSize - 2 * PADDING, mid - iconSize / 2 + top, iconSize, iconSize );
|
QRect confRect = QRect( itemRect.width() - ICONSIZE - 2 * PADDING, mid - ICONSIZE / 2 + top, ICONSIZE, ICONSIZE );
|
||||||
if( index.data( SipModel::HasConfig ).toBool() ) {
|
if( index.data( SipModel::HasConfig ).toBool() ) {
|
||||||
|
|
||||||
QStyleOptionToolButton topt;
|
QStyleOptionToolButton topt;
|
||||||
@@ -214,6 +214,17 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRect
|
||||||
|
SipConfigDelegate::configRectForIndex( const QStyleOptionViewItem& option, const QModelIndex& idx ) const
|
||||||
|
{
|
||||||
|
QStyleOptionViewItemV4 opt = option;
|
||||||
|
initStyleOption( &opt, idx );
|
||||||
|
QRect itemRect = opt.rect;
|
||||||
|
QRect confRect = QRect( itemRect.width() - ICONSIZE - 2 * PADDING, (opt.rect.height() / 2) - ICONSIZE / 2 + opt.rect.top(), ICONSIZE, ICONSIZE );
|
||||||
|
return confRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QSize
|
QSize
|
||||||
SipConfigDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
SipConfigDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||||
{
|
{
|
||||||
|
@@ -33,6 +33,7 @@ public:
|
|||||||
virtual bool editorEvent ( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
|
virtual bool editorEvent ( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
|
||||||
virtual QSize sizeHint ( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
virtual QSize sizeHint ( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
|
|
||||||
|
virtual QRect configRectForIndex( const QStyleOptionViewItem& option, const QModelIndex& idx ) const;
|
||||||
private slots:
|
private slots:
|
||||||
void askedForEdit( const QModelIndex& idx );
|
void askedForEdit( const QModelIndex& idx );
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user