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 setUpdatesEnabled(
false );
309 QStyleOptionGroupBox box;
310 initStyleOption( &box );
311 QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box,
312 QStyle::SC_GroupBoxFrame,
this );
319 int offsetStyle = QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) ? 8 : 0;
320 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 QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box,
341 QStyle::SC_GroupBoxFrame,
this );
342 QRect rectCheckBox = style()->subControlRect( QStyle::CC_GroupBox, &box,
343 QStyle::SC_GroupBoxCheckBox,
this );
344 if ( rectFrame.left() <= 0 )
345 offsetLeft = 6 + rectFrame.left();
346 if ( rectFrame.top() <= 0 )
351 offsetTop = ( rectCheckBox.height() / 2 ) -
353 offsetTopTri = offsetTop + 1;
357 offsetTop = 6 + rectFrame.top();
358 offsetTopTri = offsetTop;
363 QgsDebugMsgLevel( QStringLiteral(
"groupbox: %1 style: %2 offset: left=%3 top=%4 top2=%5" ).arg(
364 objectName(), QApplication::style()->objectName() ).arg( offsetLeft ).arg( offsetTop ).arg( offsetTopTri ), 5 );
368 if ( QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) )
370 ss += QLatin1String(
"QgsCollapsibleGroupBoxBasic, QgsCollapsibleGroupBox {" );
371 ss += QStringLiteral(
" margin-top: %1px;" ).arg( topBuffer + rectFrame.top() );
374 ss += QLatin1String(
"QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title {" );
375 ss += QLatin1String(
" subcontrol-origin: margin;" );
376 ss += QLatin1String(
" subcontrol-position: top left;" );
377 ss += QStringLiteral(
" margin-left: %1px;" ).arg( marginLeft );
378 ss += QStringLiteral(
" margin-right: %1px;" ).arg( marginRight );
379 ss += QStringLiteral(
" left: %1px;" ).arg( offsetLeft );
380 ss += QStringLiteral(
" top: %1px;" ).arg( offsetTop );
381 if ( QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) )
383 ss += QLatin1String(
" background-color: rgba(0,0,0,0)" );
386 setStyleSheet( styleSheet() + ss );
390 ssd = QStringLiteral(
"QgsCollapsibleGroupBoxBasic > QToolButton#%1, QgsCollapsibleGroupBox > QToolButton#%1 {" ).arg(
mCollapseButton->objectName() );
391 ssd += QLatin1String(
" background-color: rgba(255, 255, 255, 0); border: none;" );
392 ssd += QStringLiteral(
"} QgsCollapsibleGroupBoxBasic > QToolButton#%1:focus, QgsCollapsibleGroupBox > QToolButton#%1:focus { border: 1px solid palette(highlight); }" ).arg(
mCollapseButton->objectName() );
394 if ( offsetLeft != 0 || offsetTopTri != 0 )
396 setUpdatesEnabled(
true );
422 setMaximumHeight( collapse ?
titleRect().bottom() + 6 : 16777215 );
429 QApplication::processEvents();
445 const char *hideKey =
"CollGrpBxHide";
447 QString ss = styleSheet();
456 const auto constChildren = children();
457 for ( QObject *child : constChildren )
459 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 )
501 , mSettings( settings )
565 if ( objectName().isEmpty() || (
mSettingGroup.isEmpty() && window()->objectName().isEmpty() ) )
570 QString
saveKey =
'/' + objectName();
597 setUpdatesEnabled(
false );
601 QVariant val =
mSettings->value( key +
"/checked" );
602 if ( ! val.isNull() )
603 setChecked( val.toBool() );
607 QVariant val =
mSettings->value( key +
"/collapsed" );
608 if ( ! val.isNull() )
612 setUpdatesEnabled(
true );
628 mSettings->setValue( key + QStringLiteral(
"/checked" ), isChecked() );
636 mAltDown = (
event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
637 mShiftDown = (
event->modifiers() & Qt::ShiftModifier );
638 QToolButton::mouseReleaseEvent( event );