Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix QgsCollapsibleGroupBox UI (arrows should render correctly)
  • Loading branch information
etiennesky committed Sep 7, 2012
1 parent 32ea8f9 commit 09c3693
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 32 deletions.
2 changes: 0 additions & 2 deletions images/images.qrc
Expand Up @@ -211,8 +211,6 @@
<file>themes/default/mIconWarn.png</file>
<file>themes/default/mIconZoom.png</file>
<file>themes/default/mIconZip.png</file>
<file>themes/default/mIconCollapse.png</file>
<file>themes/default/mIconExpand.png</file>
<file>themes/default/mMapserverExport.png</file>
<file>themes/default/plugin.png</file>
<file>themes/default/propertyicons/action.png</file>
Expand Down
Binary file removed images/themes/default/mIconCollapse.png
Binary file not shown.
Binary file removed images/themes/default/mIconExpand.png
Binary file not shown.
62 changes: 33 additions & 29 deletions src/gui/qgscollapsiblegroupbox.cpp
Expand Up @@ -23,44 +23,48 @@
#include <QStyleOptionGroupBox>
#include <QStylePainter>
#include <QLayout>
#include <QProxyStyle>

class QgsCollapsibleGroupBoxStyle : public QProxyStyle
{
public:
QgsCollapsibleGroupBoxStyle( QStyle * style = 0 ) : QProxyStyle( style ) {}

void drawPrimitive( PrimitiveElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget ) const
{
if ( element == PE_IndicatorCheckBox )
{
const QgsCollapsibleGroupBox* groupBox =
dynamic_cast<const QgsCollapsibleGroupBox*>( widget );
if ( groupBox )
{
return drawPrimitive( groupBox->isCollapsed() ?
PE_IndicatorArrowRight : PE_IndicatorArrowDown,
option, painter, widget );
}
}
return QProxyStyle::drawPrimitive( element, option, painter, widget );
}
};

QgsCollapsibleGroupBox::QgsCollapsibleGroupBox( QWidget *parent )
: QGroupBox( parent ), mCollapsed( false )
{
connect( this, SIGNAL( toggled( bool ) ), this, SLOT( setToggled( bool ) ) );
init();
}

QgsCollapsibleGroupBox::QgsCollapsibleGroupBox( const QString &title, QWidget *parent )
QgsCollapsibleGroupBox::QgsCollapsibleGroupBox( const QString &title,
QWidget *parent )
: QGroupBox( title, parent ), mCollapsed( false )
{}

void QgsCollapsibleGroupBox::paintEvent( QPaintEvent * event )
{
QGroupBox::paintEvent( event );

// paint expand/collapse icon only if groupbox is checkable as icon replaces check box
if ( ! isCheckable() )
return;
init();
}

// create background mask + expand/collapse icon
// icons from http://www.iconfinder.com/search/?q=iconset%3AsplashyIcons
QPixmap icon( mCollapsed ?
QgsApplication::getThemePixmap( "/mIconExpand.png" ) :
QgsApplication::getThemePixmap( "/mIconCollapse.png" ) );
QPixmap background( icon.width() + 2, icon.height() + 2 );
background.fill( palette().color( backgroundRole() ) );

// paint on top of checkbox - does this work with all platforms/themes?
QStylePainter paint( this );
QStyleOptionGroupBox option;
initStyleOption( &option );
paint.drawComplexControl( QStyle::CC_GroupBox, option );
paint.drawItemPixmap( option.rect.adjusted( 4, -1, 0, 0 ),
Qt::AlignTop | Qt::AlignLeft,
background );
paint.drawItemPixmap( option.rect.adjusted( 6, 0, 0, 0 ),
Qt::AlignTop | Qt::AlignLeft,
icon );
void QgsCollapsibleGroupBox::init()
{
setStyle( new QgsCollapsibleGroupBoxStyle( QApplication::style() ) );
connect( this, SIGNAL( toggled( bool ) ), this, SLOT( setToggled( bool ) ) );
}

void QgsCollapsibleGroupBox::showEvent( QShowEvent * event )
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgscollapsiblegroupbox.h
Expand Up @@ -46,7 +46,7 @@ class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox
void setCollapsed( bool collapse );

protected:
void paintEvent( QPaintEvent * );
void init();
void showEvent( QShowEvent * event );

private:
Expand Down

0 comments on commit 09c3693

Please sign in to comment.