Skip to content

Commit 523b56f

Browse files
committed
implement collapsible groupbox items - needs feedback before implementing as a widget in qgis_gui
1 parent 5579962 commit 523b56f

File tree

3 files changed

+344
-94
lines changed

3 files changed

+344
-94
lines changed

src/gui/qgsrasterlayersaveasdialog.cpp

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,109 @@
99
#include <QFileDialog>
1010
#include <QSettings>
1111

12+
13+
// this widget class will go into its separate file
14+
15+
// #include <QMouseEvent>
16+
// #include <QStyleOptionGroupBox>
17+
// #include <QStylePainter>
18+
19+
GroupBox::GroupBox( QWidget *parent )
20+
: QGroupBox( parent ), m_collapsed( false )
21+
{
22+
connect( this, SIGNAL( toggled ( bool ) ), this, SLOT( setToggled( bool ) ) );
23+
//setToggled( isChecked() );
24+
}
25+
26+
GroupBox::GroupBox( const QString &title, QWidget *parent )
27+
: QGroupBox(title, parent ), m_collapsed( false )
28+
{}
29+
30+
bool GroupBox::isCollapsed() { return m_collapsed; }
31+
32+
// void GroupBox::mousePressEvent( QMouseEvent *e )
33+
// {
34+
// QgsDebugMsg("press event");
35+
// if( e->button() == Qt::LeftButton )
36+
// {
37+
// QgsDebugMsg("left but");
38+
// QStyleOptionGroupBox option;
39+
// initStyleOption( &option );
40+
// QRect buttonArea( 0, 0, 16, 16 );
41+
// buttonArea.moveTopRight( option.rect.adjusted( 0, 0, -10, 0
42+
// ).topRight() );
43+
// if( buttonArea.contains( e->pos() ) )
44+
// {
45+
// clickPos = e->pos();
46+
// return;
47+
// }
48+
// }
49+
// QGroupBox::mousePressEvent( e );
50+
// }
51+
52+
// void GroupBox::mouseReleaseEvent( QMouseEvent *e )
53+
// {
54+
// QgsDebugMsg("release");
55+
// if( e->button() == Qt::LeftButton && clickPos == e->pos() )
56+
// setCollapse( !isCollapsed() );
57+
// }
58+
59+
// void GroupBox::paintEvent( QPaintEvent * )
60+
// {
61+
// QgsDebugMsg("paint event");
62+
63+
// QStylePainter paint( this );
64+
// QStyleOptionGroupBox option;
65+
// initStyleOption( &option );
66+
// paint.drawComplexControl( QStyle::CC_GroupBox, option );
67+
// paint.drawItemPixmap(
68+
// option.rect.adjusted( 0, 0, -10, 0 ),
69+
// Qt::AlignTop | Qt::AlignRight,
70+
// QPixmap( m_collapsed ?
71+
// ":/images/images/navigate_down2_16x16.png" :
72+
// ":/images/images/navigate_up2_16x16.png" ) );
73+
// }
74+
75+
void GroupBox::showEvent( QShowEvent * event )
76+
{
77+
// QgsDebugMsg(QString("%1 showEvent %2 %3").arg(objectName()).arg(isChecked()).arg(isCollapsed()));
78+
QGroupBox::showEvent( event );
79+
if ( ! isChecked() && ! isCollapsed() )
80+
setCollapsed( true );
81+
}
82+
83+
void GroupBox::setCollapsed( bool collapse )
84+
{
85+
if ( ! isVisible() )
86+
return;
87+
// QgsDebugMsg(QString("%1 setcollapse %2").arg(objectName()).arg(collapse));
88+
89+
// minimize layout margins, restore later
90+
if ( collapse )
91+
{
92+
if ( layout() )
93+
{
94+
margins = layout()->contentsMargins();
95+
layout()->setContentsMargins(1,1,1,1);
96+
}
97+
}
98+
else
99+
{
100+
if ( layout() )
101+
{
102+
layout()->setContentsMargins( margins );
103+
}
104+
}
105+
m_collapsed = collapse;
106+
foreach( QWidget *widget, findChildren<QWidget*>() )
107+
widget->setHidden( collapse );
108+
109+
if ( m_collapsed )
110+
emit collapsed( this );
111+
else
112+
emit expanded( this );
113+
}
114+
12115
QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* sourceProvider, const QgsRectangle& currentExtent,
13116
const QgsCoordinateReferenceSystem& layerCrs,
14117
const QgsCoordinateReferenceSystem& currentCrs,
@@ -26,7 +129,7 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* s
26129
mLoadTransparentNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionCopySelected.png" ) );
27130
mRemoveSelectedNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionDeleteAttribute.png" ) );
28131
mRemoveAllNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionRemove.png" ) );
29-
mNoDataGroupBox->setEnabled( false ); // not yet implemented
132+
// mNoDataGroupBox->setEnabled( false ); // not yet implemented
30133

31134
setValidators();
32135
// Translated labels + EPSG are updated later
@@ -81,6 +184,12 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* s
81184
{
82185
okButton->setEnabled( false );
83186
}
187+
188+
// this should scroll down to make widget visible, but it's not happening
189+
// (at least part of it is visible)...
190+
connect( mCreateOptionsGroupBox, SIGNAL( expanded( QWidget* ) ),
191+
this, SLOT( groupBoxExpanded( QWidget* ) ) );
192+
84193
}
85194

86195
void QgsRasterLayerSaveAsDialog::setValidators()

src/gui/qgsrasterlayersaveasdialog.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast
7979

8080
void on_mCrsComboBox_currentIndexChanged( int ) { crsChanged(); }
8181

82+
void groupBoxExpanded( QWidget * widget ) { mScrollArea->ensureWidgetVisible( widget ); }
83+
8284
private:
8385
QgsRasterDataProvider* mDataProvider;
8486
QgsRectangle mCurrentExtent;
@@ -105,4 +107,44 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast
105107
void updateCrsGroup();
106108
};
107109

110+
108111
#endif // QGSRASTERLAYERSAVEASDIALOG_H
112+
113+
114+
// this widget class will go into its separate file
115+
#ifndef GROUPBOX_H
116+
#define GROUPBOX_H
117+
118+
#include <QGroupBox>
119+
120+
class GroupBox : public QGroupBox
121+
{
122+
Q_OBJECT
123+
124+
public:
125+
GroupBox( QWidget *parent = 0 );
126+
GroupBox( const QString &title, QWidget *parent = 0 );
127+
128+
bool isCollapsed();
129+
130+
signals:
131+
void collapsed( QWidget* );
132+
void expanded( QWidget* );
133+
134+
public slots:
135+
void setToggled( bool toggled ) { setCollapsed( ! toggled ); }
136+
void setCollapsed( bool collapsed );
137+
138+
protected:
139+
/* void mousePressEvent( QMouseEvent *e ); */
140+
/* void mouseReleaseEvent( QMouseEvent *e ); */
141+
/* void paintEvent( QPaintEvent * ); */
142+
void showEvent( QShowEvent * event );
143+
144+
private:
145+
QPoint clickPos;
146+
bool m_collapsed;
147+
QMargins margins;
148+
};
149+
150+
#endif

0 commit comments

Comments
 (0)