mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-15 10:33:59 +02:00
fix checkrect hit area in delegate too
This commit is contained in:
@@ -58,7 +58,6 @@ ConfigDelegateBase::sizeHint( const QStyleOptionViewItem& option, const QModelIn
|
|||||||
void
|
void
|
||||||
ConfigDelegateBase::drawCheckBox( QStyleOptionViewItemV4& opt, QPainter* p, const QWidget* w ) const
|
ConfigDelegateBase::drawCheckBox( QStyleOptionViewItemV4& opt, QPainter* p, const QWidget* w ) const
|
||||||
{
|
{
|
||||||
m_checkRect = opt.rect;
|
|
||||||
QStyle* style = w ? w->style() : QApplication::style();
|
QStyle* style = w ? w->style() : QApplication::style();
|
||||||
opt.checkState == Qt::Checked ? opt.state |= QStyle::State_On : opt.state |= QStyle::State_Off;
|
opt.checkState == Qt::Checked ? opt.state |= QStyle::State_On : opt.state |= QStyle::State_Off;
|
||||||
style->drawPrimitive( QStyle::PE_IndicatorViewItemCheck, &opt, p, w );
|
style->drawPrimitive( QStyle::PE_IndicatorViewItemCheck, &opt, p, w );
|
||||||
@@ -94,7 +93,7 @@ ConfigDelegateBase::editorEvent ( QEvent* event, QAbstractItemModel* model, cons
|
|||||||
m_configPressed = false;
|
m_configPressed = false;
|
||||||
|
|
||||||
QMouseEvent* me = static_cast< QMouseEvent* >( event );
|
QMouseEvent* me = static_cast< QMouseEvent* >( event );
|
||||||
if( me->button() != Qt::LeftButton || !m_checkRect.contains( me->pos() ) )
|
if( me->button() != Qt::LeftButton || !checkRectForIndex( option, index ).contains( me->pos() ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// eat the double click events inside the check rect
|
// eat the double click events inside the check rect
|
||||||
|
@@ -35,6 +35,8 @@ 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 checkbox, you need to have this say where to paint it
|
||||||
|
virtual QRect checkRectForIndex( const QStyleOptionViewItem& option, const QModelIndex& idx ) const = 0;
|
||||||
// if you want to use a config wrench, you need to have this say where to paint it
|
// 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;
|
virtual QRect configRectForIndex( const QStyleOptionViewItem& option, const QModelIndex& idx ) const = 0;
|
||||||
|
|
||||||
@@ -46,8 +48,6 @@ protected:
|
|||||||
void drawConfigWrench( QPainter* painter, QStyleOptionViewItemV4& option, QStyleOptionToolButton& topt ) const;
|
void drawConfigWrench( QPainter* painter, QStyleOptionViewItemV4& option, QStyleOptionToolButton& topt ) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable QRect m_checkRect;
|
|
||||||
mutable QRect m_configRect;
|
|
||||||
bool m_configPressed;
|
bool m_configPressed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -112,6 +112,17 @@ ResolverConfigDelegate::configRectForIndex( const QStyleOptionViewItem& option,
|
|||||||
return confRect;
|
return confRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRect
|
||||||
|
ResolverConfigDelegate::checkRectForIndex( const QStyleOptionViewItem &option, const QModelIndex &idx ) const
|
||||||
|
{
|
||||||
|
QStyleOptionViewItemV4 opt = option;
|
||||||
|
initStyleOption( &opt, idx );
|
||||||
|
QRect itemRect = opt.rect;
|
||||||
|
int top = itemRect.top();
|
||||||
|
|
||||||
|
QRect checkRect = QRect(2 * PADDING, 2 * PADDING + top, ICONSIZE, ICONSIZE );
|
||||||
|
return checkRect;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ResolverConfigDelegate::onConfigPressed( const QModelIndex& idx )
|
ResolverConfigDelegate::onConfigPressed( const QModelIndex& idx )
|
||||||
|
@@ -29,6 +29,8 @@ 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 checkRectForIndex( const QStyleOptionViewItem &option, const QModelIndex &idx ) const;
|
||||||
virtual QRect configRectForIndex( const QStyleOptionViewItem& option, const QModelIndex& idx ) const;
|
virtual QRect configRectForIndex( const QStyleOptionViewItem& option, const QModelIndex& idx ) const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#define ICONSIZE 24
|
#define ICONSIZE 24
|
||||||
|
#define CHECK_LEFT_EDGE 8
|
||||||
SipConfigDelegate::SipConfigDelegate( QObject* parent )
|
SipConfigDelegate::SipConfigDelegate( QObject* parent )
|
||||||
: ConfigDelegateBase ( parent )
|
: ConfigDelegateBase ( parent )
|
||||||
{
|
{
|
||||||
@@ -62,8 +63,7 @@ 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 checkLeftEdge = 8;
|
int iconLeftEdge = CHECK_LEFT_EDGE + 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
|
||||||
@@ -82,7 +82,7 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option
|
|||||||
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( CHECK_LEFT_EDGE + diff, pos + top, rectW, rectW );
|
||||||
QPixmap p( RESPATH "images/list-add.png" );
|
QPixmap p( RESPATH "images/list-add.png" );
|
||||||
painter->drawPixmap( plusRect, p );
|
painter->drawPixmap( plusRect, p );
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option
|
|||||||
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( CHECK_LEFT_EDGE + diff, pos + top, rectW, rectW );
|
||||||
QPixmap p( icon.pixmap( rect.size() ) );
|
QPixmap p( icon.pixmap( rect.size() ) );
|
||||||
painter->drawPixmap( rect, p );
|
painter->drawPixmap( rect, p );
|
||||||
}
|
}
|
||||||
@@ -138,7 +138,7 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option
|
|||||||
} 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( CHECK_LEFT_EDGE, pos + top, ICONSIZE, ICONSIZE );
|
||||||
opt.rect = checkRect;
|
opt.rect = checkRect;
|
||||||
drawCheckBox( opt, painter, w );
|
drawCheckBox( opt, painter, w );
|
||||||
|
|
||||||
@@ -214,8 +214,26 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRect
|
||||||
|
SipConfigDelegate::checkRectForIndex( const QStyleOptionViewItem &option, const QModelIndex &idx ) const
|
||||||
|
{
|
||||||
|
if( !idx.data( SipModel::FactoryItemRole ).toBool() && !idx.data( SipModel::FactoryRole ).toBool() )
|
||||||
|
{
|
||||||
|
QStyleOptionViewItemV4 opt = option;
|
||||||
|
initStyleOption( &opt, idx );
|
||||||
|
int mid = opt.rect.height() / 2;
|
||||||
|
int pos = ( mid ) - ( ICONSIZE / 2 );
|
||||||
|
QRect checkRect = QRect( CHECK_LEFT_EDGE, pos + opt.rect.top(), ICONSIZE, ICONSIZE );
|
||||||
|
|
||||||
|
return checkRect;
|
||||||
|
}
|
||||||
|
return QRect();
|
||||||
|
}
|
||||||
|
|
||||||
QRect
|
QRect
|
||||||
SipConfigDelegate::configRectForIndex( const QStyleOptionViewItem& option, const QModelIndex& idx ) const
|
SipConfigDelegate::configRectForIndex( const QStyleOptionViewItem& option, const QModelIndex& idx ) const
|
||||||
|
{
|
||||||
|
if( !idx.data( SipModel::FactoryItemRole ).toBool() && !idx.data( SipModel::FactoryRole ).toBool() )
|
||||||
{
|
{
|
||||||
QStyleOptionViewItemV4 opt = option;
|
QStyleOptionViewItemV4 opt = option;
|
||||||
initStyleOption( &opt, idx );
|
initStyleOption( &opt, idx );
|
||||||
@@ -223,6 +241,8 @@ SipConfigDelegate::configRectForIndex( const QStyleOptionViewItem& option, const
|
|||||||
QRect confRect = QRect( itemRect.width() - ICONSIZE - 2 * PADDING, (opt.rect.height() / 2) - ICONSIZE / 2 + opt.rect.top(), ICONSIZE, ICONSIZE );
|
QRect confRect = QRect( itemRect.width() - ICONSIZE - 2 * PADDING, (opt.rect.height() / 2) - ICONSIZE / 2 + opt.rect.top(), ICONSIZE, ICONSIZE );
|
||||||
return confRect;
|
return confRect;
|
||||||
}
|
}
|
||||||
|
return QRect();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QSize
|
QSize
|
||||||
|
@@ -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 checkRectForIndex( const QStyleOptionViewItem &option, const QModelIndex &idx ) const;
|
||||||
virtual QRect configRectForIndex( const QStyleOptionViewItem& option, const QModelIndex& idx ) 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