28#include <QStyleOptionGroupBox>
31#include "moc_qgscollapsiblegroupbox.cpp"
42 : QGroupBox( title, parent )
47void QgsCollapsibleGroupBoxBasic::init()
75 setFocusPolicy( Qt::StrongFocus );
99 if ( parent() && parent()->parent() )
109 QgsDebugMsgLevel( QStringLiteral(
"did not find a QScrollArea parent" ), 5 );
137 if ( event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier | Qt::ShiftModifier )
146 QGroupBox::mousePressEvent( event );
151 mAltDown = (
event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
152 mShiftDown = (
event->modifiers() & Qt::ShiftModifier );
165 QGroupBox::mouseReleaseEvent( event );
174 QGroupBox::changeEvent( event );
176 if ( event->type() == QEvent::EnabledChange && isEnabled() )
184 if ( !grp.isEmpty() )
186 tipTxt = tr(
"Ctrl (or Alt)-click to toggle all" ) +
'\n' + tr(
"Shift-click to expand, then collapse others" );
193 QStyleOptionGroupBox box;
194 initStyleOption( &box );
195 return style()->subControlRect( QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxLabel,
this );
238 QgsDebugMsgLevel( QStringLiteral(
"Alt or Shift key down, syncing group" ), 2 );
240 if (
auto *lParentWidget = parentWidget() )
246 if (
mSyncParent->parentWidget()->objectName() != QLatin1String(
"QgisApp" ) )
265 if ( grpbox->syncGroup() ==
syncGroup() && grpbox->isEnabled() )
274 grpbox->setCollapsed(
mShiftDown ?
true : !thisCollapsed );
303 QGroupBox::setStyleSheet( style );
308 setUpdatesEnabled(
false );
312 QStyleOptionGroupBox box;
313 initStyleOption( &box );
314 const QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxFrame,
this );
318 const int marginLeft = 20;
319 const int marginRight = 5;
321 const int offsetStyle = QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) ? 8 : 0;
322 const int topBuffer = 1 + offsetStyle;
323 int offsetTop = topBuffer;
324 int offsetTopTri = topBuffer;
328 offsetTopTri += ( rectTitle.height() -
mCollapseButton->height() ) / 2;
338 if ( QApplication::style()->objectName().compare( QLatin1String(
"oxygen" ), Qt::CaseInsensitive ) == 0 )
340 QStyleOptionGroupBox box;
341 initStyleOption( &box );
342 const QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxFrame,
this );
343 const QRect rectCheckBox = style()->subControlRect( QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxCheckBox,
this );
344 if ( rectFrame.left() <= 0 )
345 offsetLeft = 6 + rectFrame.left();
346 if ( rectFrame.top() <= 0 )
351 offsetTop = ( rectCheckBox.height() / 2 ) - (
mCollapseButton->height() / 2 ) + rectCheckBox.top();
352 offsetTopTri = offsetTop + 1;
356 offsetTop = 6 + rectFrame.top();
357 offsetTopTri = offsetTop;
362 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 );
366 if ( QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) )
368 ss += QLatin1String(
"QgsCollapsibleGroupBoxBasic, QgsCollapsibleGroupBox {" );
369 ss += QStringLiteral(
" margin-top: %1px;" ).arg( topBuffer + rectFrame.top() );
372 ss += QLatin1String(
"QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title {" );
373 ss += QLatin1String(
" subcontrol-origin: margin;" );
374 ss += QLatin1String(
" subcontrol-position: top left;" );
375 ss += QStringLiteral(
" margin-left: %1px;" ).arg( marginLeft );
376 ss += QStringLiteral(
" margin-right: %1px;" ).arg( marginRight );
377 ss += QStringLiteral(
" left: %1px;" ).arg( offsetLeft );
378 ss += QStringLiteral(
" top: %1px;" ).arg( offsetTop );
379 if ( QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) )
381 ss += QLatin1String(
" background-color: rgba(0,0,0,0)" );
388 ssd = QStringLiteral(
"QgsCollapsibleGroupBoxBasic > QToolButton#%1, QgsCollapsibleGroupBox > QToolButton#%1 {" ).arg(
mCollapseButton->objectName() );
389 ssd += QLatin1String(
" background-color: rgba(255, 255, 255, 0); border: none;" );
390 ssd += QStringLiteral(
"} QgsCollapsibleGroupBoxBasic > QToolButton#%1:focus, QgsCollapsibleGroupBox > QToolButton#%1:focus { border: 1px solid palette(highlight); }" ).arg(
mCollapseButton->objectName() );
392 if ( offsetLeft != 0 || offsetTopTri != 0 )
394 setUpdatesEnabled(
true );
420 setMaximumHeight( collapse ?
titleRect().bottom() + 6 : 16777215 );
427 QApplication::processEvents();
443 const char *hideKey =
"CollGrpBxHide";
445 QString ss = styleSheet();
454 const auto constChildren = children();
455 for ( QObject *child : constChildren )
457 QWidget *w = qobject_cast<QWidget *>( child );
462 w->setProperty( hideKey,
true );
475 const auto constChildren = children();
476 for ( QObject *child : constChildren )
478 QWidget *w = qobject_cast<QWidget *>( child );
481 if ( w->property( hideKey ).toBool() )
493 , mSettings( settings )
500 , mSettings( settings )
517 mSettings = settings;
518 mDelSettings =
false;
521void QgsCollapsibleGroupBox::init()
525 mDelSettings =
false;
532 mSaveCollapsedState =
true;
535 mSaveCheckedState =
false;
567 if ( objectName().isEmpty() || ( mSettingGroup.isEmpty() && window()->objectName().isEmpty() ) )
572 QString
saveKey =
'/' + objectName();
581 const QString setgrp = mSettingGroup.isEmpty() ? window()->objectName() : mSettingGroup;
592 if ( !isEnabled() || ( !mSaveCollapsedState && !mSaveCheckedState ) )
599 setUpdatesEnabled(
false );
601 if ( mSaveCheckedState )
603 const QVariant val = mSettings->value( key +
"/checked" );
605 setChecked( val.toBool() );
607 if ( mSaveCollapsedState )
609 const QVariant val = mSettings->value( key +
"/collapsed" );
614 setUpdatesEnabled(
true );
622 if ( !
mShown || !isEnabled() || ( !mSaveCollapsedState && !mSaveCheckedState ) )
629 if ( mSaveCheckedState )
630 mSettings->setValue( key + QStringLiteral(
"/checked" ), isChecked() );
631 if ( mSaveCollapsedState )
632 mSettings->setValue( key + QStringLiteral(
"/collapsed" ),
isCollapsed() );
638 mAltDown = (
event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
639 mShiftDown = (
event->modifiers() & Qt::ShiftModifier );
640 QToolButton::mouseReleaseEvent( event );
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
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)