Skip to content
Permalink
Browse files

add qgscollapsiblegroupbox, use in raster save dialog

  • Loading branch information
etiennesky committed Aug 24, 2012
1 parent 13a790d commit fe6923bad0f68f1a3061ac26e961b6d14f99613c
@@ -210,6 +210,8 @@
<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>
Binary file not shown.
Binary file not shown.
@@ -93,6 +93,7 @@ qgsexpressionbuilderwidget.cpp
qgsexpressionbuilderdialog.cpp
qgsexpressionhighlighter.cpp
qgsquerybuilder.cpp
qgscollapsiblegroupbox.cpp
)

IF (WITH_TOUCH)
@@ -176,6 +177,7 @@ qgsscalecombobox.h
qgsexpressionbuilderwidget.h
qgsexpressionhighlighter.h
qgsquerybuilder.h
qgscollapsiblegroupbox.h
)

QT4_WRAP_CPP(QGIS_GUI_MOC_SRCS ${QGIS_GUI_MOC_HDRS})
@@ -213,6 +215,7 @@ qgsfieldvalidator.h
qgsexpressionbuilderwidget.h
qgsexpressionbuilderdialog.h
qgsexpressionhighlighter.h
qgscollapsiblegroupbox.h

attributetable/qgsattributetablemodel.h
attributetable/qgsattributetablememorymodel.h
@@ -0,0 +1,105 @@
/***************************************************************************
qgscollapsiblegroupbox.cpp
-------------------
begin : August 2012
copyright : (C) 2012 by Etienne Tourigny
email : etourigny dot dev at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgscollapsiblegroupbox.h"

#include "qgsapplication.h"
#include "qgslogger.h"

#include <QStyleOptionGroupBox>
#include <QStylePainter>
#include <QLayout>

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

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;

// 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::showEvent( QShowEvent * event )
{
QGroupBox::showEvent( event );
// collapse if needed - any calls to setCollapsed() before have no effect
if ( isCheckable() && ! isChecked() && ! isCollapsed() )
setCollapsed( true );
}

void QgsCollapsibleGroupBox::setCollapsed( bool collapse )
{
if ( ! isVisible() )
return;

// minimize layout margins and save for subsequent restore
if ( collapse )
{
if ( layout() )
{
mMargins = layout()->contentsMargins();
layout()->setContentsMargins( 1, 1, 1, 1 );
}
}
else
{
if ( layout() )
{
layout()->setContentsMargins( mMargins );
}
}

mCollapsed = collapse;
foreach ( QWidget *widget, findChildren<QWidget*>() )
widget->setHidden( collapse );

if ( mCollapsed )
emit collapsed( this );
else
emit expanded( this );
}

@@ -0,0 +1,57 @@
/***************************************************************************
qgscollapsiblegroupbox.h
-------------------
begin : August 2012
copyright : (C) 2012 by Etienne Tourigny
email : etourigny dot dev at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSCOLLAPSIBLEGROUPBOX_H
#define QGSCOLLAPSIBLEGROUPBOX_H

#include "qgisgui.h"

/** \ingroup gui
* A groupbox that collapses/expands when toggled and draws an expand/collapse icon in lieu of checkbox.
* Widget must be checkable for expand/collapse icon to appear.
*/

#include <QGroupBox>

class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox
{
Q_OBJECT

public:
QgsCollapsibleGroupBox( QWidget *parent = 0 );
QgsCollapsibleGroupBox( const QString &title, QWidget *parent = 0 );

bool isCollapsed() const { return mCollapsed; }

signals:
void collapsed( QWidget* );
void expanded( QWidget* );

public slots:
void setToggled( bool toggled ) { setCollapsed( ! toggled ); }
void setCollapsed( bool collapse );

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

private:
bool mCollapsed;
QMargins mMargins;
};

#endif
@@ -10,108 +10,6 @@
#include <QSettings>


// this widget class will go into its separate file

// #include <QMouseEvent>
// #include <QStyleOptionGroupBox>
// #include <QStylePainter>

GroupBox::GroupBox( QWidget *parent )
: QGroupBox( parent ), m_collapsed( false )
{
connect( this, SIGNAL( toggled ( bool ) ), this, SLOT( setToggled( bool ) ) );
//setToggled( isChecked() );
}

GroupBox::GroupBox( const QString &title, QWidget *parent )
: QGroupBox(title, parent ), m_collapsed( false )
{}

bool GroupBox::isCollapsed() { return m_collapsed; }

// void GroupBox::mousePressEvent( QMouseEvent *e )
// {
// QgsDebugMsg("press event");
// if( e->button() == Qt::LeftButton )
// {
// QgsDebugMsg("left but");
// QStyleOptionGroupBox option;
// initStyleOption( &option );
// QRect buttonArea( 0, 0, 16, 16 );
// buttonArea.moveTopRight( option.rect.adjusted( 0, 0, -10, 0
// ).topRight() );
// if( buttonArea.contains( e->pos() ) )
// {
// clickPos = e->pos();
// return;
// }
// }
// QGroupBox::mousePressEvent( e );
// }

// void GroupBox::mouseReleaseEvent( QMouseEvent *e )
// {
// QgsDebugMsg("release");
// if( e->button() == Qt::LeftButton && clickPos == e->pos() )
// setCollapse( !isCollapsed() );
// }

// void GroupBox::paintEvent( QPaintEvent * )
// {
// QgsDebugMsg("paint event");

// QStylePainter paint( this );
// QStyleOptionGroupBox option;
// initStyleOption( &option );
// paint.drawComplexControl( QStyle::CC_GroupBox, option );
// paint.drawItemPixmap(
// option.rect.adjusted( 0, 0, -10, 0 ),
// Qt::AlignTop | Qt::AlignRight,
// QPixmap( m_collapsed ?
// ":/images/images/navigate_down2_16x16.png" :
// ":/images/images/navigate_up2_16x16.png" ) );
// }

void GroupBox::showEvent( QShowEvent * event )
{
// QgsDebugMsg(QString("%1 showEvent %2 %3").arg(objectName()).arg(isChecked()).arg(isCollapsed()));
QGroupBox::showEvent( event );
if ( ! isChecked() && ! isCollapsed() )
setCollapsed( true );
}

void GroupBox::setCollapsed( bool collapse )
{
if ( ! isVisible() )
return;
// QgsDebugMsg(QString("%1 setcollapse %2").arg(objectName()).arg(collapse));

// minimize layout margins, restore later
if ( collapse )
{
if ( layout() )
{
margins = layout()->contentsMargins();
layout()->setContentsMargins(1,1,1,1);
}
}
else
{
if ( layout() )
{
layout()->setContentsMargins( margins );
}
}
m_collapsed = collapse;
foreach( QWidget *widget, findChildren<QWidget*>() )
widget->setHidden( collapse );

if ( m_collapsed )
emit collapsed( this );
else
emit expanded( this );
}

QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* sourceProvider, const QgsRectangle& currentExtent,
const QgsCoordinateReferenceSystem& layerCrs,
const QgsCoordinateReferenceSystem& currentCrs,
@@ -187,7 +85,7 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* s

// this should scroll down to make widget visible, but it's not happening
// (at least part of it is visible)...
connect( mCreateOptionsGroupBox, SIGNAL( expanded( QWidget* ) ),
connect( mCreateOptionsGroupBox, SIGNAL( expanded( QWidget* ) ),
this, SLOT( groupBoxExpanded( QWidget* ) ) );

}
@@ -110,41 +110,3 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast

#endif // QGSRASTERLAYERSAVEASDIALOG_H


// this widget class will go into its separate file
#ifndef GROUPBOX_H
#define GROUPBOX_H

#include <QGroupBox>

class GroupBox : public QGroupBox
{
Q_OBJECT

public:
GroupBox( QWidget *parent = 0 );
GroupBox( const QString &title, QWidget *parent = 0 );

bool isCollapsed();

signals:
void collapsed( QWidget* );
void expanded( QWidget* );

public slots:
void setToggled( bool toggled ) { setCollapsed( ! toggled ); }
void setCollapsed( bool collapsed );

protected:
/* void mousePressEvent( QMouseEvent *e ); */
/* void mouseReleaseEvent( QMouseEvent *e ); */
/* void paintEvent( QPaintEvent * ); */
void showEvent( QShowEvent * event );

private:
QPoint clickPos;
bool m_collapsed;
QMargins margins;
};

#endif

0 comments on commit fe6923b

Please sign in to comment.
You can’t perform that action at this time.