2 changes: 2 additions & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Binary file added images/themes/default/mIconCollapse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mIconExpand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 18 additions & 6 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "qgsproject.h"

#include "qgsrasterformatsaveoptionswidget.h"
#include "qgsrasterpyramidsoptionswidget.h"
#include "qgsdialog.h"

#include <QInputDialog>
Expand Down Expand Up @@ -1118,15 +1119,26 @@ void QgsOptions::editGdalDriver( const QString& driverName )
QLabel *label = new QLabel( title, &dlg );
label->setAlignment( Qt::AlignHCenter );
layout->addWidget( label );
QgsRasterFormatSaveOptionsWidget* optionsWidget =
new QgsRasterFormatSaveOptionsWidget( &dlg, driverName,
QgsRasterFormatSaveOptionsWidget::Full, "gdal" );
layout->addWidget( optionsWidget );

if ( dlg.exec() == QDialog::Accepted )
if ( driverName == "_pyramids" )
{
optionsWidget->apply();
QgsRasterPyramidsOptionsWidget* optionsWidget =
new QgsRasterPyramidsOptionsWidget( &dlg, "gdal" );
layout->addWidget( optionsWidget );
dlg.resize( 400, 400 );
if ( dlg.exec() == QDialog::Accepted )
optionsWidget->apply();
}
else
{
QgsRasterFormatSaveOptionsWidget* optionsWidget =
new QgsRasterFormatSaveOptionsWidget( &dlg, driverName,
QgsRasterFormatSaveOptionsWidget::Full, "gdal" );
layout->addWidget( optionsWidget );
if ( dlg.exec() == QDialog::Accepted )
optionsWidget->apply();
}

}

// Return state of the visibility flag for newly added layers. If
Expand Down
5 changes: 5 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ qgsprojectionselector.cpp
qgsquickprint.cpp
qgsrasterlayersaveasdialog.cpp
qgsrasterformatsaveoptionswidget.cpp
qgsrasterpyramidsoptionswidget.cpp
qgsrubberband.cpp
qgsscalecombobox.cpp
qgstextannotationitem.cpp
Expand All @@ -93,6 +94,7 @@ qgsexpressionbuilderwidget.cpp
qgsexpressionbuilderdialog.cpp
qgsexpressionhighlighter.cpp
qgsquerybuilder.cpp
qgscollapsiblegroupbox.cpp
)

IF (WITH_TOUCH)
Expand Down Expand Up @@ -168,6 +170,7 @@ qgsprojectionselector.h
qgsquickprint.h
qgsrasterlayersaveasdialog.h
qgsrasterformatsaveoptionswidget.h
qgsrasterpyramidsoptionswidget.h
qgsludialog.h
qgsprojectbadlayerguihandler.h
qgslonglongvalidator.h
Expand All @@ -176,6 +179,7 @@ qgsscalecombobox.h
qgsexpressionbuilderwidget.h
qgsexpressionhighlighter.h
qgsquerybuilder.h
qgscollapsiblegroupbox.h
)

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

attributetable/qgsattributetablemodel.h
attributetable/qgsattributetablememorymodel.h
Expand Down
127 changes: 127 additions & 0 deletions src/gui/qgscollapsiblegroupbox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/***************************************************************************
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;

mCollapsed = collapse;

// 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 );
}
}

// if we are collapsing, save hidden widgets in a list
if ( collapse )
{
mHiddenWidgets.clear();
foreach ( QWidget *widget, findChildren<QWidget*>() )
{
if ( widget->isHidden() )
mHiddenWidgets << widget;
}
}

// show/hide widgets
foreach ( QWidget *widget, findChildren<QWidget*>() )
widget->setHidden( collapse );

// if we are expanding, re-hide saved hidden widgets
if ( ! collapse )
{
foreach ( QWidget *widget, mHiddenWidgets )
{
widget->setHidden( true );
}
}

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

58 changes: 58 additions & 0 deletions src/gui/qgscollapsiblegroupbox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/***************************************************************************
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;
QList< QWidget* > mHiddenWidgets;
};

#endif
Loading