Showing with 78 additions and 11 deletions.
  1. +4 −1 src/app/qgisapp.cpp
  2. +72 −10 src/gui/qgscollapsiblegroupbox.cpp
  3. +2 −0 src/gui/qgscollapsiblegroupbox.h
5 changes: 4 additions & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4011,7 +4011,10 @@ void QgisApp::saveAsRasterFile()
return;
}

QgsRasterLayerSaveAsDialog d( rasterLayer, rasterLayer->dataProvider(), mMapCanvas->extent(), rasterLayer->crs(), mMapCanvas->mapRenderer()->destinationCrs() );
QgsRasterLayerSaveAsDialog d( rasterLayer, rasterLayer->dataProvider(),
mMapCanvas->extent(), rasterLayer->crs(),
mMapCanvas->mapRenderer()->destinationCrs(),
this );
if ( d.exec() == QDialog::Accepted )
{
QgsRasterFileWriter fileWriter( d.outputFileName() );
Expand Down
82 changes: 72 additions & 10 deletions src/gui/qgscollapsiblegroupbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ QIcon QgsCollapsibleGroupBox::mCollapseIcon;
QIcon QgsCollapsibleGroupBox::mExpandIcon;

QgsCollapsibleGroupBox::QgsCollapsibleGroupBox( QWidget *parent )
: QGroupBox( parent ), mCollapsed( false ), mSaveState( true )
: QGroupBox( parent )
{
init();
}

QgsCollapsibleGroupBox::QgsCollapsibleGroupBox( const QString &title,
QWidget *parent )
: QGroupBox( title, parent ), mCollapsed( false ), mSaveState( true )
: QGroupBox( title, parent )
{
init();
}
Expand All @@ -48,6 +48,12 @@ QgsCollapsibleGroupBox::~QgsCollapsibleGroupBox()

void QgsCollapsibleGroupBox::init()
{
// variables
mCollapsed = false;
mSaveState = true;
mInitFlat = false;
mShown = false;

// init icons
if ( mCollapseIcon.isNull() )
{
Expand All @@ -70,11 +76,22 @@ void QgsCollapsibleGroupBox::init()

void QgsCollapsibleGroupBox::showEvent( QShowEvent * event )
{
// initialise widget on first show event only
if ( mShown )
{
event->accept();
return;
}
mShown = true;

// check if groupbox was set to flat in Designer or in code
mInitFlat = isFlat();

loadState();

updateStyle();

// expand if needed - any calls to setCollapsed() before only set mCollapsed
// expand if needed - any calls to setCollapsed() before only set mCollapsed, but have UI effect
if ( mCollapsed )
{
setCollapsed( mCollapsed );
Expand All @@ -85,6 +102,7 @@ void QgsCollapsibleGroupBox::showEvent( QShowEvent * event )
still emit signal for connections using expanded state */
emit collapsedStateChanged( this );
}

event->accept();
}

Expand Down Expand Up @@ -152,7 +170,6 @@ void QgsCollapsibleGroupBox::saveState()
{
if ( ! mSaveState )
return;
QgsDebugMsg( "key = " + saveKey() + " objectName = " + objectName() );
QSettings settings;
QString key = saveKey();
settings.setValue( key + "/checked", isChecked() );
Expand All @@ -178,24 +195,66 @@ void QgsCollapsibleGroupBox::updateStyle()
{
setUpdatesEnabled( false );

// customize style sheet
// margin/offset defaults
int marginLeft = 20; // title margin for disclosure triangle
int marginRight = 5; // a little bit of space on the right, to match space on the left
int offsetLeft = 0; // offset for oxygen theme
int offsetTop = 0;
int offsetTop2 = 0; // offset for triangle

// calculate offset if frame overlaps triangle (oxygen theme)
// using an offset of 6 pixels from frame border
if ( QApplication::style()->objectName().toLower() == "oxygen" )
{
QStyleOptionGroupBox box;
initStyleOption( &box );
QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box,
QStyle::SC_GroupBoxFrame, this );
QRect rectCheckBox = style()->subControlRect( QStyle::CC_GroupBox, &box,
QStyle::SC_GroupBoxCheckBox, this );
if ( rectFrame.left() <= 0 )
offsetLeft = 6 + rectFrame.left();
if ( rectFrame.top() <= 0 )
{
if ( isCheckable() )
{
// if is checkable align with checkbox
offsetTop = ( rectCheckBox.height() / 2 ) -
( mCollapseButton->height() / 2 ) + rectCheckBox.top();
offsetTop2 = offsetTop + 1;
}
else
{
offsetTop = 6 + rectFrame.top();
offsetTop2 = offsetTop;
}
}
}

QgsDebugMsg( QString( "groupbox: %1 style: %2 offset: left=%3 top=%4 top2=%5" ).arg(
objectName() ).arg( QApplication::style()->objectName() ).arg( offsetLeft ).arg( offsetTop ).arg( offsetTop2 ) );

// customize style sheet for collapse/expand button and force left-aligned title
// TODO: move to app stylesheet system, when appropriate
QString ss;
ss += "QgsCollapsibleGroupBox::title {";
ss += " subcontrol-origin: margin;";
ss += " subcontrol-position: top left;";
ss += " margin-left: 20px;"; // offset for disclosure triangle
ss += " margin-right: 5px;"; // a little bit of space on the right, to match space on the left
ss += QString( " margin-left: %1px;" ).arg( marginLeft );
ss += QString( " margin-right: %1px;" ).arg( marginRight );
ss += QString( " left: %1px;" ).arg( offsetLeft );
ss += QString( " top: %1px;" ).arg( offsetTop );
ss += "}";
setStyleSheet( ss );

// clear toolbutton default background and border
// TODO: move to app stylesheet system, when appropriate
// clear toolbutton default background and border and apply offset
QString ssd;
ssd = QString( "QgsCollapsibleGroupBox > QToolButton#%1 {" ).arg( mCollapseButton->objectName() );
ssd += " background-color: rgba(255, 255, 255, 0); border: none;";
ssd += "}";
mCollapseButton->setStyleSheet( ssd );
if ( offsetLeft != 0 || offsetTop2 != 0 )
mCollapseButton->move( offsetLeft, offsetTop2 );

setUpdatesEnabled( true );
}
Expand All @@ -208,9 +267,12 @@ void QgsCollapsibleGroupBox::setCollapsed( bool collapse )
return;

// for consistent look/spacing across platforms when collapsed
setFlat( collapse );
if ( ! mInitFlat ) // skip if initially set to flat in Designer
setFlat( collapse );

// avoid flicker in X11
QApplication::processEvents();

// set maximum height to hide contents - does this work in all envs?
// setMaximumHeight( collapse ? 25 : 16777215 );
setMaximumHeight( collapse ? titleRect().bottom() + 6 : 16777215 );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgscollapsiblegroupbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox

bool mCollapsed;
bool mSaveState;
bool mInitFlat;
bool mShown;
QToolButton* mCollapseButton;

static QIcon mCollapseIcon;
Expand Down