19#include "moc_qgscollapsiblegroupbox.cpp" 
   28#include <QStyleOptionGroupBox> 
   40  : QGroupBox( title, parent )
 
 
   45void QgsCollapsibleGroupBoxBasic::init()
 
   73  setFocusPolicy( Qt::StrongFocus );
 
   97  if ( parent() && parent()->parent() )
 
  107    QgsDebugMsgLevel( QStringLiteral( 
"did not find a QScrollArea parent" ), 5 );
 
 
  135  if ( event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier | Qt::ShiftModifier )
 
  144  QGroupBox::mousePressEvent( event );
 
 
  149  mAltDown = ( 
event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
 
  150  mShiftDown = ( 
event->modifiers() & Qt::ShiftModifier );
 
  163  QGroupBox::mouseReleaseEvent( event );
 
 
  172  QGroupBox::changeEvent( event );
 
  174  if ( event->type() == QEvent::EnabledChange && isEnabled() )
 
 
  182  if ( !grp.isEmpty() )
 
  184    tipTxt = tr( 
"Ctrl (or Alt)-click to toggle all" ) + 
'\n' + tr( 
"Shift-click to expand, then collapse others" );
 
 
  191  QStyleOptionGroupBox box;
 
  192  initStyleOption( &box );
 
  193  return style()->subControlRect( QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxLabel, 
this );
 
 
  236    QgsDebugMsgLevel( QStringLiteral( 
"Alt or Shift key down, syncing group" ), 2 );
 
  238    if ( 
auto *lParentWidget = parentWidget() )
 
  244        if ( 
mSyncParent->parentWidget()->objectName() != QLatin1String( 
"QgisApp" ) )
 
  263        if ( grpbox->syncGroup() == 
syncGroup() && grpbox->isEnabled() )
 
  272            grpbox->setCollapsed( 
mShiftDown ? 
true : !thisCollapsed );
 
 
  301  QGroupBox::setStyleSheet( style );
 
 
  306  setUpdatesEnabled( 
false );
 
  310  QStyleOptionGroupBox box;
 
  311  initStyleOption( &box );
 
  312  const QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxFrame, 
this );
 
  316  const int marginLeft = 20; 
 
  317  const int marginRight = 5; 
 
  319  const int offsetStyle = QApplication::style()->objectName().contains( QLatin1String( 
"macintosh" ) ) ? 8 : 0;
 
  320  const int topBuffer = 1 + offsetStyle; 
 
  321  int offsetTop = topBuffer;
 
  322  int offsetTopTri = topBuffer; 
 
  326    offsetTopTri += ( rectTitle.height() - 
mCollapseButton->height() ) / 2;
 
  336  if ( QApplication::style()->objectName().compare( QLatin1String( 
"oxygen" ), Qt::CaseInsensitive ) == 0 )
 
  338    QStyleOptionGroupBox box;
 
  339    initStyleOption( &box );
 
  340    const QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxFrame, 
this );
 
  341    const QRect rectCheckBox = style()->subControlRect( QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxCheckBox, 
this );
 
  342    if ( rectFrame.left() <= 0 )
 
  343      offsetLeft = 6 + rectFrame.left();
 
  344    if ( rectFrame.top() <= 0 )
 
  349        offsetTop = ( rectCheckBox.height() / 2 ) - ( 
mCollapseButton->height() / 2 ) + rectCheckBox.top();
 
  350        offsetTopTri = offsetTop + 1;
 
  354        offsetTop = 6 + rectFrame.top();
 
  355        offsetTopTri = offsetTop;
 
  360  QgsDebugMsgLevel( QStringLiteral( 
"groupbox: %1 style: %2 offset: left=%3 top=%4 top2=%5" ).arg( objectName(), QApplication::style()->objectName() ).arg( offsetLeft ).arg( offsetTop ).arg( offsetTopTri ), 5 );
 
  364  if ( QApplication::style()->objectName().contains( QLatin1String( 
"macintosh" ) ) )
 
  366    ss += QLatin1String( 
"QgsCollapsibleGroupBoxBasic, QgsCollapsibleGroupBox {" );
 
  367    ss += QStringLiteral( 
"  margin-top: %1px;" ).arg( topBuffer + rectFrame.top() );
 
  370  ss += QLatin1String( 
"QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title {" );
 
  371  ss += QLatin1String( 
"  subcontrol-origin: margin;" );
 
  372  ss += QLatin1String( 
"  subcontrol-position: top left;" );
 
  373  ss += QStringLiteral( 
"  margin-left: %1px;" ).arg( marginLeft );
 
  374  ss += QStringLiteral( 
"  margin-right: %1px;" ).arg( marginRight );
 
  375  ss += QStringLiteral( 
"  left: %1px;" ).arg( offsetLeft );
 
  376  ss += QStringLiteral( 
"  top: %1px;" ).arg( offsetTop );
 
  377  if ( QApplication::style()->objectName().contains( QLatin1String( 
"macintosh" ) ) )
 
  379    ss += QLatin1String( 
"  background-color: rgba(0,0,0,0)" );
 
  386  ssd = QStringLiteral( 
"QgsCollapsibleGroupBoxBasic > QToolButton#%1, QgsCollapsibleGroupBox > QToolButton#%1 {" ).arg( 
mCollapseButton->objectName() );
 
  387  ssd += QLatin1String( 
"  background-color: rgba(255, 255, 255, 0); border: none;" );
 
  388  ssd += QStringLiteral( 
"} QgsCollapsibleGroupBoxBasic > QToolButton#%1:focus, QgsCollapsibleGroupBox > QToolButton#%1:focus {  border: 1px solid palette(highlight); }" ).arg( 
mCollapseButton->objectName() );
 
  390  if ( offsetLeft != 0 || offsetTopTri != 0 )
 
  392  setUpdatesEnabled( 
true );
 
 
  418  setMaximumHeight( collapse ? 
titleRect().bottom() + 6 : 16777215 );
 
  425    QApplication::processEvents();
 
 
  441  const char *hideKey = 
"CollGrpBxHide";
 
  443  QString ss = styleSheet();
 
  452    const auto constChildren = children();
 
  453    for ( QObject *child : constChildren )
 
  455      QWidget *w = qobject_cast<QWidget *>( child );
 
  458        w->setProperty( hideKey, 
true );
 
  471    const auto constChildren = children();
 
  472    for ( QObject *child : constChildren )
 
  474      QWidget *w = qobject_cast<QWidget *>( child );
 
  477        if ( w->property( hideKey ).toBool() )
 
 
  489  , mSettings( settings )
 
 
  496  , mSettings( settings )
 
 
  513  mSettings = settings;
 
  514  mDelSettings = 
false; 
 
 
  517void QgsCollapsibleGroupBox::init()
 
  521  mDelSettings = 
false;
 
  528  mSaveCollapsedState = 
true;
 
  531  mSaveCheckedState = 
false;
 
  563  if ( objectName().isEmpty() || ( mSettingGroup.isEmpty() && window()->objectName().isEmpty() ) )
 
  568  QString 
saveKey = 
'/' + objectName();
 
  577  const QString setgrp = mSettingGroup.isEmpty() ? window()->objectName() : mSettingGroup;
 
 
  588  if ( !isEnabled() || ( !mSaveCollapsedState && !mSaveCheckedState ) )
 
  595  setUpdatesEnabled( 
false );
 
  597  if ( mSaveCheckedState )
 
  599    const QVariant val = mSettings->value( key + 
"/checked" );
 
  601      setChecked( val.toBool() );
 
  603  if ( mSaveCollapsedState )
 
  605    const QVariant val = mSettings->value( key + 
"/collapsed" );
 
  610  setUpdatesEnabled( 
true );
 
 
  618  if ( !
mShown || !isEnabled() || ( !mSaveCollapsedState && !mSaveCheckedState ) )
 
  625  if ( mSaveCheckedState )
 
  626    mSettings->setValue( key + QStringLiteral( 
"/checked" ), isChecked() );
 
  627  if ( mSaveCollapsedState )
 
  628    mSettings->setValue( key + QStringLiteral( 
"/collapsed" ), 
isCollapsed() );
 
 
  634  mAltDown = ( 
event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
 
  635  mShiftDown = ( 
event->modifiers() & Qt::ShiftModifier );
 
  636  QToolButton::mouseReleaseEvent( event );
 
 
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
 
A groupbox that collapses/expands when toggled.
 
QString syncGroup
An optional group to be collapsed and uncollapsed in sync with this group box if the Alt-modifier is ...
 
void changeEvent(QEvent *event) override
 
void collapseExpandFixes()
Visual fixes for when group box is collapsed/expanded.
 
QgsCollapsibleGroupBoxBasic(QWidget *parent=nullptr)
 
void setSyncGroup(const QString &grp)
Named group which synchronizes collapsing action when triangle is clicked while holding alt modifier ...
 
void checkToggled(bool ckd)
 
bool isCollapsed() const
Returns the current collapsed state of this group box.
 
void showEvent(QShowEvent *event) override
 
void collapsedStateChanged(bool collapsed)
Signal emitted when groupbox collapsed/expanded state is changed, and when first shown.
 
void checkClicked(bool ckd)
 
QgsGroupBoxCollapseButton * mCollapseButton
 
void setStyleSheet(const QString &style)
Overridden to prepare base call and avoid crash due to specific QT versions.
 
void setCollapsed(bool collapse)
Collapse or uncollapse this groupbox.
 
QScrollArea * mParentScrollArea
 
void mousePressEvent(QMouseEvent *event) override
 
void mouseReleaseEvent(QMouseEvent *event) override
 
void saveState() const
Will save the collapsed and checked state.
 
QgsCollapsibleGroupBox(QWidget *parent=nullptr, QgsSettings *settings=nullptr)
 
void showEvent(QShowEvent *event) override
 
void loadState()
Will load the collapsed and checked state.
 
~QgsCollapsibleGroupBox() override
 
void setSettings(QgsSettings *settings)
 
Stores settings for use within QGIS.
 
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
 
const QString COLLAPSE_HIDE_BORDER_FIX
 
#define QgsDebugMsgLevel(str, level)