Skip to content

Commit

Permalink
implement collapsible groupbox items - needs feedback before implemen…
Browse files Browse the repository at this point in the history
…ting as a widget in qgis_gui
  • Loading branch information
etiennesky committed Aug 23, 2012
1 parent 5579962 commit 523b56f
Show file tree
Hide file tree
Showing 3 changed files with 344 additions and 94 deletions.
111 changes: 110 additions & 1 deletion src/gui/qgsrasterlayersaveasdialog.cpp
Expand Up @@ -9,6 +9,109 @@
#include <QFileDialog>
#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,
Expand All @@ -26,7 +129,7 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* s
mLoadTransparentNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionCopySelected.png" ) );
mRemoveSelectedNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionDeleteAttribute.png" ) );
mRemoveAllNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionRemove.png" ) );
mNoDataGroupBox->setEnabled( false ); // not yet implemented
// mNoDataGroupBox->setEnabled( false ); // not yet implemented

setValidators();
// Translated labels + EPSG are updated later
Expand Down Expand Up @@ -81,6 +184,12 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* s
{
okButton->setEnabled( false );
}

// 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* ) ),
this, SLOT( groupBoxExpanded( QWidget* ) ) );

}

void QgsRasterLayerSaveAsDialog::setValidators()
Expand Down
42 changes: 42 additions & 0 deletions src/gui/qgsrasterlayersaveasdialog.h
Expand Up @@ -79,6 +79,8 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast

void on_mCrsComboBox_currentIndexChanged( int ) { crsChanged(); }

void groupBoxExpanded( QWidget * widget ) { mScrollArea->ensureWidgetVisible( widget ); }

private:
QgsRasterDataProvider* mDataProvider;
QgsRectangle mCurrentExtent;
Expand All @@ -105,4 +107,44 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast
void updateCrsGroup();
};


#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 523b56f

Please sign in to comment.