mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-02-24 03:43:56 +01:00
fix config rect handling
This commit is contained in:
parent
63738b58c0
commit
811ac70fa6
@ -71,7 +71,6 @@ ConfigDelegateBase::drawConfigWrench ( QPainter* painter, QStyleOptionViewItemV4
|
||||
const QWidget* w = opt.widget;
|
||||
QStyle* style = w ? w->style() : QApplication::style();
|
||||
|
||||
m_configRect = topt.rect;
|
||||
// draw it the same size as the check belox
|
||||
topt.font = opt.font;
|
||||
topt.icon = QIcon( RESPATH "images/configure.png" );
|
||||
@ -109,7 +108,7 @@ ConfigDelegateBase::editorEvent ( QEvent* event, QAbstractItemModel* model, cons
|
||||
|
||||
} else if( event->type() == QEvent::MouseButtonPress ) {
|
||||
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;
|
||||
|
||||
emit configPressed( index );
|
||||
|
@ -35,6 +35,9 @@ public:
|
||||
|
||||
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:
|
||||
void configPressed( const QModelIndex& idx );
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include <QMouseEvent>
|
||||
|
||||
#define PADDING 4
|
||||
|
||||
#define ICONSIZE 24
|
||||
ResolverConfigDelegate::ResolverConfigDelegate( QObject* parent )
|
||||
: ConfigDelegateBase( parent )
|
||||
{
|
||||
@ -60,8 +60,7 @@ ResolverConfigDelegate::paint( QPainter* painter, const QStyleOptionViewItem& op
|
||||
style->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter, w );
|
||||
|
||||
int rightSplit = itemRect.width();
|
||||
int rectW = 24;
|
||||
QRect confRect = QRect( rightSplit - rectW - 2 * PADDING, 2 * PADDING + top, rectW, rectW );
|
||||
QRect confRect = QRect( rightSplit - ICONSIZE - 2 * PADDING, 2 * PADDING + top, ICONSIZE, ICONSIZE );
|
||||
|
||||
// if the resolver has a config widget, paint it first (right-aligned)
|
||||
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
|
||||
ResolverConfigDelegate::onConfigPressed( const QModelIndex& idx )
|
||||
{
|
||||
|
@ -29,6 +29,7 @@ class ResolverConfigDelegate : public ConfigDelegateBase
|
||||
public:
|
||||
explicit ResolverConfigDelegate(QObject* parent = 0);
|
||||
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
virtual QRect configRectForIndex ( const QStyleOptionViewItem& option, const QModelIndex& idx ) const;
|
||||
|
||||
private slots:
|
||||
void onConfigPressed ( const QModelIndex& );
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
|
||||
#define ICONSIZE 24
|
||||
SipConfigDelegate::SipConfigDelegate( QObject* parent )
|
||||
: ConfigDelegateBase ( parent )
|
||||
{
|
||||
@ -61,10 +62,9 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option
|
||||
QStyle* style = w ? w->style() : QApplication::style();
|
||||
style->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter, w );
|
||||
|
||||
int iconSize = 24;
|
||||
int checkLeftEdge = 8;
|
||||
int iconLeftEdge = checkLeftEdge + iconSize + PADDING;
|
||||
int textLeftEdge = iconLeftEdge + iconSize + PADDING;
|
||||
int iconLeftEdge = checkLeftEdge + ICONSIZE + PADDING;
|
||||
int textLeftEdge = iconLeftEdge + ICONSIZE + PADDING;
|
||||
|
||||
if( index.data( SipModel::FactoryRole ).toBool() ) { // this is the "add new account" row
|
||||
// draw a border and background
|
||||
@ -80,7 +80,7 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option
|
||||
|
||||
// draw "+" icon in checkbox column
|
||||
int rectW = 18;
|
||||
int diff = ( iconSize/ 2 ) - ( rectW / 2) ;
|
||||
int diff = ( ICONSIZE/ 2 ) - ( rectW / 2) ;
|
||||
int pos = ( mid ) - ( rectW / 2 );
|
||||
QRect plusRect = QRect( checkLeftEdge + diff, pos + top, rectW, rectW );
|
||||
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 >();
|
||||
if( !icon.isNull() ) {
|
||||
int rectW = 18;
|
||||
int diff = ( iconSize/ 2 ) - ( rectW / 2) ;
|
||||
int diff = ( ICONSIZE/ 2 ) - ( rectW / 2) ;
|
||||
int pos = ( mid ) - ( rectW / 2 );
|
||||
QRect rect = QRect( checkLeftEdge + diff, pos + top, rectW, rectW );
|
||||
QPixmap p( icon.pixmap( rect.size() ) );
|
||||
@ -137,15 +137,15 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option
|
||||
painter->drawText( textR, text );
|
||||
} else { // this is an existing account to show
|
||||
// draw checkbox first
|
||||
int pos = ( mid ) - ( iconSize / 2 );
|
||||
QRect checkRect = QRect( checkLeftEdge, pos + top, iconSize, iconSize );
|
||||
int pos = ( mid ) - ( ICONSIZE / 2 );
|
||||
QRect checkRect = QRect( checkLeftEdge, pos + top, ICONSIZE, ICONSIZE );
|
||||
opt.rect = checkRect;
|
||||
drawCheckBox( opt, painter, w );
|
||||
|
||||
// draw the icon if it exists
|
||||
pos = ( mid ) - ( iconSize / 2 );
|
||||
pos = ( mid ) - ( ICONSIZE / 2 );
|
||||
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->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
|
||||
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() ) {
|
||||
|
||||
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
|
||||
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 QSize sizeHint ( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||
|
||||
virtual QRect configRectForIndex( const QStyleOptionViewItem& option, const QModelIndex& idx ) const;
|
||||
private slots:
|
||||
void askedForEdit( const QModelIndex& idx );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user