23 #include <QToolButton>
24 #include <QMouseEvent>
25 #include <QPushButton>
26 #include <QStyleOptionGroupBox>
27 #include <QScrollArea>
39 : QGroupBox( title, parent )
72 #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
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 );
166 QGroupBox::mouseReleaseEvent( event );
175 QGroupBox::changeEvent( event );
177 if ( event->type() == QEvent::EnabledChange && isEnabled() )
185 if ( !grp.isEmpty() )
187 tipTxt = tr(
"Ctrl (or Alt)-click to toggle all" ) +
'\n' + tr(
"Shift-click to expand, then collapse others" );
194 QStyleOptionGroupBox box;
195 initStyleOption( &box );
196 return style()->subControlRect( QStyle::CC_GroupBox, &box,
197 QStyle::SC_GroupBoxLabel,
this );
240 QgsDebugMsg( QStringLiteral(
"Alt or Shift key down, syncing group" ) );
242 if (
auto *lParentWidget = parentWidget() )
248 if (
mSyncParent->parentWidget()->objectName() != QLatin1String(
"QgisApp" ) )
267 if ( grpbox->syncGroup() ==
syncGroup() && grpbox->isEnabled() )
276 grpbox->setCollapsed(
mShiftDown ?
true : !thisCollapsed );
286 QgsDebugMsg( QStringLiteral(
"did not find a sync parent" ) );
305 #if QT_VERSION < QT_VERSION_CHECK(5, 12, 4)
307 QGroupBox::setStyleSheet( QString() );
309 QGroupBox::setStyleSheet( style );
314 setUpdatesEnabled(
false );
318 QStyleOptionGroupBox box;
319 initStyleOption( &box );
320 QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box,
321 QStyle::SC_GroupBoxFrame,
this );
328 int offsetStyle = QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) ? 8 : 0;
329 int topBuffer = 1 + offsetStyle;
330 int offsetTop = topBuffer;
331 int offsetTopTri = topBuffer;
335 offsetTopTri += ( rectTitle.height() -
mCollapseButton->height() ) / 2;
345 if ( QApplication::style()->objectName().compare( QLatin1String(
"oxygen" ), Qt::CaseInsensitive ) == 0 )
347 QStyleOptionGroupBox box;
348 initStyleOption( &box );
349 QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box,
350 QStyle::SC_GroupBoxFrame,
this );
351 QRect rectCheckBox = style()->subControlRect( QStyle::CC_GroupBox, &box,
352 QStyle::SC_GroupBoxCheckBox,
this );
353 if ( rectFrame.left() <= 0 )
354 offsetLeft = 6 + rectFrame.left();
355 if ( rectFrame.top() <= 0 )
360 offsetTop = ( rectCheckBox.height() / 2 ) -
362 offsetTopTri = offsetTop + 1;
366 offsetTop = 6 + rectFrame.top();
367 offsetTopTri = offsetTop;
372 QgsDebugMsgLevel( QStringLiteral(
"groupbox: %1 style: %2 offset: left=%3 top=%4 top2=%5" ).arg(
373 objectName(), QApplication::style()->objectName() ).arg( offsetLeft ).arg( offsetTop ).arg( offsetTopTri ), 5 );
377 if ( QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) )
379 ss += QLatin1String(
"QgsCollapsibleGroupBoxBasic, QgsCollapsibleGroupBox {" );
380 ss += QStringLiteral(
" margin-top: %1px;" ).arg( topBuffer + rectFrame.top() );
383 ss += QLatin1String(
"QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title {" );
384 ss += QLatin1String(
" subcontrol-origin: margin;" );
385 ss += QLatin1String(
" subcontrol-position: top left;" );
386 ss += QStringLiteral(
" margin-left: %1px;" ).arg( marginLeft );
387 ss += QStringLiteral(
" margin-right: %1px;" ).arg( marginRight );
388 ss += QStringLiteral(
" left: %1px;" ).arg( offsetLeft );
389 ss += QStringLiteral(
" top: %1px;" ).arg( offsetTop );
390 if ( QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) )
392 ss += QLatin1String(
" background-color: rgba(0,0,0,0)" );
399 ssd = QStringLiteral(
"QgsCollapsibleGroupBoxBasic > QToolButton#%1, QgsCollapsibleGroupBox > QToolButton#%1 {" ).arg(
mCollapseButton->objectName() );
400 ssd += QLatin1String(
" background-color: rgba(255, 255, 255, 0); border: none;" );
401 ssd += QStringLiteral(
"} QgsCollapsibleGroupBoxBasic > QToolButton#%1:focus, QgsCollapsibleGroupBox > QToolButton#%1:focus { border: 1px solid palette(highlight); }" ).arg(
mCollapseButton->objectName() );
403 if ( offsetLeft != 0 || offsetTopTri != 0 )
405 setUpdatesEnabled(
true );
431 setMaximumHeight( collapse ?
titleRect().bottom() + 6 : 16777215 );
438 QApplication::processEvents();
454 const char *hideKey =
"CollGrpBxHide";
456 QString ss = styleSheet();
465 const auto constChildren = children();
466 for ( QObject *child : constChildren )
468 QWidget *w = qobject_cast<QWidget *>( child );
471 w->setProperty( hideKey,
true );
484 const auto constChildren = children();
485 for ( QObject *child : constChildren )
487 QWidget *w = qobject_cast<QWidget *>( child );
490 if ( w->property( hideKey ).toBool() )
502 , mSettings( settings )
510 , mSettings( settings )
574 if ( objectName().isEmpty() || (
mSettingGroup.isEmpty() && window()->objectName().isEmpty() ) )
579 QString
saveKey =
'/' + objectName();
606 setUpdatesEnabled(
false );
610 QVariant val =
mSettings->value( key +
"/checked" );
611 if ( ! val.isNull() )
612 setChecked( val.toBool() );
616 QVariant val =
mSettings->value( key +
"/collapsed" );
617 if ( ! val.isNull() )
621 setUpdatesEnabled(
true );
637 mSettings->setValue( key + QStringLiteral(
"/checked" ), isChecked() );
645 mAltDown = (
event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
646 mShiftDown = (
event->modifiers() & Qt::ShiftModifier );
647 QToolButton::mouseReleaseEvent( event );
static QIcon getThemeIcon(const QString &name)
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.
QPointer< QgsSettings > mSettings
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)
This class is a composition of two QSettings instances:
const QString COLLAPSE_HIDE_BORDER_FIX
#define QgsDebugMsgLevel(str, level)