From ebd78c06b05528dece1dcfa8011bdb5ea594c09f Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Wed, 4 May 2011 11:56:00 -0400 Subject: [PATCH] only show clicked wrench as down --- src/configdelegatebase.cpp | 10 +++++----- src/configdelegatebase.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/configdelegatebase.cpp b/src/configdelegatebase.cpp index ef385fe2b..0008dcaee 100644 --- a/src/configdelegatebase.cpp +++ b/src/configdelegatebase.cpp @@ -26,7 +26,6 @@ ConfigDelegateBase::ConfigDelegateBase ( QObject* parent ) : QStyledItemDelegate ( parent ) - , m_configPressed( false ) { } @@ -77,8 +76,9 @@ ConfigDelegateBase::drawConfigWrench ( QPainter* painter, QStyleOptionViewItemV4 topt.subControls = QStyle::SC_ToolButton; topt.activeSubControls = QStyle::SC_None; topt.features = QStyleOptionToolButton::None; - topt.state = m_configPressed ? QStyle::State_On : QStyle::State_Raised; - if( opt.state & QStyle::State_MouseOver || m_configPressed ) + bool pressed = ( m_configPressed == opt.index ); + topt.state = pressed ? QStyle::State_On : QStyle::State_Raised; + if( opt.state & QStyle::State_MouseOver || pressed ) topt.state |= QStyle::State_HasFocus; style->drawComplexControl( QStyle::CC_ToolButton, &topt, painter, w ); } @@ -90,7 +90,7 @@ ConfigDelegateBase::editorEvent ( QEvent* event, QAbstractItemModel* model, cons initStyleOption( &viewOpt, index ); if( event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::MouseButtonDblClick ) { - m_configPressed = false; + m_configPressed = QModelIndex(); QMouseEvent* me = static_cast< QMouseEvent* >( event ); if( me->button() != Qt::LeftButton || !checkRectForIndex( option, index ).contains( me->pos() ) ) @@ -108,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 && configRectForIndex( option, index ).contains( me->pos() ) ) { - m_configPressed = true; + m_configPressed = index; emit configPressed( index ); return true; diff --git a/src/configdelegatebase.h b/src/configdelegatebase.h index 57d21e966..8f98685ba 100644 --- a/src/configdelegatebase.h +++ b/src/configdelegatebase.h @@ -48,7 +48,7 @@ protected: void drawConfigWrench( QPainter* painter, QStyleOptionViewItemV4& option, QStyleOptionToolButton& topt ) const; private: - bool m_configPressed; + QModelIndex m_configPressed; }; #endif // CONFIGDELEGATEBASE_H