diff --git a/src/configdelegatebase.cpp b/src/configdelegatebase.cpp index 2ddd010c6..ef385fe2b 100644 --- a/src/configdelegatebase.cpp +++ b/src/configdelegatebase.cpp @@ -58,7 +58,6 @@ ConfigDelegateBase::sizeHint( const QStyleOptionViewItem& option, const QModelIn void ConfigDelegateBase::drawCheckBox( QStyleOptionViewItemV4& opt, QPainter* p, const QWidget* w ) const { - m_checkRect = opt.rect; QStyle* style = w ? w->style() : QApplication::style(); opt.checkState == Qt::Checked ? opt.state |= QStyle::State_On : opt.state |= QStyle::State_Off; style->drawPrimitive( QStyle::PE_IndicatorViewItemCheck, &opt, p, w ); @@ -94,7 +93,7 @@ ConfigDelegateBase::editorEvent ( QEvent* event, QAbstractItemModel* model, cons m_configPressed = false; 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; // eat the double click events inside the check rect diff --git a/src/configdelegatebase.h b/src/configdelegatebase.h index c9f01b864..57d21e966 100644 --- a/src/configdelegatebase.h +++ b/src/configdelegatebase.h @@ -35,6 +35,8 @@ public: 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 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; private: - mutable QRect m_checkRect; - mutable QRect m_configRect; bool m_configPressed; }; diff --git a/src/resolverconfigdelegate.cpp b/src/resolverconfigdelegate.cpp index dc291a69b..5d4f00e7d 100644 --- a/src/resolverconfigdelegate.cpp +++ b/src/resolverconfigdelegate.cpp @@ -112,6 +112,17 @@ ResolverConfigDelegate::configRectForIndex( const QStyleOptionViewItem& option, 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 ResolverConfigDelegate::onConfigPressed( const QModelIndex& idx ) diff --git a/src/resolverconfigdelegate.h b/src/resolverconfigdelegate.h index b376044bf..25a9f5a01 100644 --- a/src/resolverconfigdelegate.h +++ b/src/resolverconfigdelegate.h @@ -29,7 +29,9 @@ 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; + + virtual QRect checkRectForIndex( const QStyleOptionViewItem &option, const QModelIndex &idx ) const; + virtual QRect configRectForIndex( const QStyleOptionViewItem& option, const QModelIndex& idx ) const; private slots: void onConfigPressed ( const QModelIndex& ); diff --git a/src/sipconfigdelegate.cpp b/src/sipconfigdelegate.cpp index 9cc8fdc31..730969a5e 100644 --- a/src/sipconfigdelegate.cpp +++ b/src/sipconfigdelegate.cpp @@ -25,6 +25,7 @@ #include #define ICONSIZE 24 +#define CHECK_LEFT_EDGE 8 SipConfigDelegate::SipConfigDelegate( QObject* parent ) : ConfigDelegateBase ( parent ) { @@ -62,8 +63,7 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option QStyle* style = w ? w->style() : QApplication::style(); style->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter, w ); - int checkLeftEdge = 8; - int iconLeftEdge = checkLeftEdge + ICONSIZE + PADDING; + int iconLeftEdge = CHECK_LEFT_EDGE + ICONSIZE + PADDING; int textLeftEdge = iconLeftEdge + ICONSIZE + PADDING; 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 diff = ( ICONSIZE/ 2 ) - ( 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" ); painter->drawPixmap( plusRect, p ); @@ -118,7 +118,7 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option int rectW = 18; int diff = ( ICONSIZE/ 2 ) - ( 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() ) ); painter->drawPixmap( rect, p ); } @@ -138,7 +138,7 @@ SipConfigDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option } else { // this is an existing account to show // draw checkbox first 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; drawCheckBox( opt, painter, w ); @@ -214,14 +214,34 @@ 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 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; + if( !idx.data( SipModel::FactoryItemRole ).toBool() && !idx.data( SipModel::FactoryRole ).toBool() ) + { + 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; + } + return QRect(); } diff --git a/src/sipconfigdelegate.h b/src/sipconfigdelegate.h index c69ed9edc..cccc82a61 100644 --- a/src/sipconfigdelegate.h +++ b/src/sipconfigdelegate.h @@ -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 checkRectForIndex( const QStyleOptionViewItem &option, const QModelIndex &idx ) const; virtual QRect configRectForIndex( const QStyleOptionViewItem& option, const QModelIndex& idx ) const; private slots: void askedForEdit( const QModelIndex& idx );