21 #include "qgssettings.h"
23 #include <QToolButton>
24 #include <QMouseEvent>
25 #include <QPushButton>
26 #include <QStyleOptionGroupBox>
27 #include <QScrollArea>
39 : QGroupBox( title, parent )
72 setFocusPolicy( Qt::StrongFocus );
96 if ( parent() && parent()->parent() )
106 QgsDebugMsgLevel( QStringLiteral(
"did not find a QScrollArea parent" ), 5 );
134 if ( event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier | Qt::ShiftModifier )
143 QGroupBox::mousePressEvent( event );
148 mAltDown = (
event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
149 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,
194 QStyle::SC_GroupBoxLabel,
this );
237 QgsDebugMsg( QStringLiteral(
"Alt or Shift key down, syncing group" ) );
239 if (
auto *lParentWidget = parentWidget() )
245 if (
mSyncParent->parentWidget()->objectName() != QLatin1String(
"QgisApp" ) )
264 if ( grpbox->syncGroup() ==
syncGroup() && grpbox->isEnabled() )
273 grpbox->setCollapsed(
mShiftDown ?
true : !thisCollapsed );
283 QgsDebugMsg( QStringLiteral(
"did not find a sync parent" ) );
302 #if QT_VERSION < QT_VERSION_CHECK(5, 12, 4)
304 QGroupBox::setStyleSheet( QString() );
306 QGroupBox::setStyleSheet( style );
311 setUpdatesEnabled(
false );
313 QgsSettings settings;
315 QStyleOptionGroupBox box;
316 initStyleOption( &box );
317 QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box,
318 QStyle::SC_GroupBoxFrame,
this );
325 int offsetStyle = QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) ? 8 : 0;
326 int topBuffer = 1 + offsetStyle;
327 int offsetTop = topBuffer;
328 int offsetTopTri = topBuffer;
332 offsetTopTri += ( rectTitle.height() -
mCollapseButton->height() ) / 2;
342 if ( QApplication::style()->objectName().compare( QLatin1String(
"oxygen" ), Qt::CaseInsensitive ) == 0 )
344 QStyleOptionGroupBox box;
345 initStyleOption( &box );
346 QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box,
347 QStyle::SC_GroupBoxFrame,
this );
348 QRect rectCheckBox = style()->subControlRect( QStyle::CC_GroupBox, &box,
349 QStyle::SC_GroupBoxCheckBox,
this );
350 if ( rectFrame.left() <= 0 )
351 offsetLeft = 6 + rectFrame.left();
352 if ( rectFrame.top() <= 0 )
357 offsetTop = ( rectCheckBox.height() / 2 ) -
359 offsetTopTri = offsetTop + 1;
363 offsetTop = 6 + rectFrame.top();
364 offsetTopTri = offsetTop;
369 QgsDebugMsgLevel( QStringLiteral(
"groupbox: %1 style: %2 offset: left=%3 top=%4 top2=%5" ).arg(
370 objectName(), QApplication::style()->objectName() ).arg( offsetLeft ).arg( offsetTop ).arg( offsetTopTri ), 5 );
374 if ( QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) )
376 ss += QLatin1String(
"QgsCollapsibleGroupBoxBasic, QgsCollapsibleGroupBox {" );
377 ss += QStringLiteral(
" margin-top: %1px;" ).arg( topBuffer + rectFrame.top() );
380 ss += QLatin1String(
"QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title {" );
381 ss += QLatin1String(
" subcontrol-origin: margin;" );
382 ss += QLatin1String(
" subcontrol-position: top left;" );
383 ss += QStringLiteral(
" margin-left: %1px;" ).arg( marginLeft );
384 ss += QStringLiteral(
" margin-right: %1px;" ).arg( marginRight );
385 ss += QStringLiteral(
" left: %1px;" ).arg( offsetLeft );
386 ss += QStringLiteral(
" top: %1px;" ).arg( offsetTop );
387 if ( QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) )
389 ss += QLatin1String(
" background-color: rgba(0,0,0,0)" );
396 ssd = QStringLiteral(
"QgsCollapsibleGroupBoxBasic > QToolButton#%1, QgsCollapsibleGroupBox > QToolButton#%1 {" ).arg(
mCollapseButton->objectName() );
397 ssd += QLatin1String(
" background-color: rgba(255, 255, 255, 0); border: none;" );
398 ssd += QStringLiteral(
"} QgsCollapsibleGroupBoxBasic > QToolButton#%1:focus, QgsCollapsibleGroupBox > QToolButton#%1:focus { border: 1px solid palette(highlight); }" ).arg(
mCollapseButton->objectName() );
400 if ( offsetLeft != 0 || offsetTopTri != 0 )
402 setUpdatesEnabled(
true );
428 setMaximumHeight( collapse ?
titleRect().bottom() + 6 : 16777215 );
435 QApplication::processEvents();
451 const char *hideKey =
"CollGrpBxHide";
453 QString ss = styleSheet();
462 const auto constChildren = children();
463 for ( QObject *child : constChildren )
465 QWidget *w = qobject_cast<QWidget *>( child );
468 w->setProperty( hideKey,
true );
481 const auto constChildren = children();
482 for ( QObject *child : constChildren )
484 QWidget *w = qobject_cast<QWidget *>( child );
487 if ( w->property( hideKey ).toBool() )
499 , mSettings( settings )
505 QWidget *parent, QgsSettings *settings )
507 , mSettings( settings )
571 if ( objectName().isEmpty() || (
mSettingGroup.isEmpty() && window()->objectName().isEmpty() ) )
576 QString
saveKey =
'/' + objectName();
603 setUpdatesEnabled(
false );
607 QVariant val =
mSettings->value( key +
"/checked" );
608 if ( ! val.isNull() )
609 setChecked( val.toBool() );
613 QVariant val =
mSettings->value( key +
"/collapsed" );
614 if ( ! val.isNull() )
618 setUpdatesEnabled(
true );
634 mSettings->setValue( key + QStringLiteral(
"/checked" ), isChecked() );
642 mAltDown = (
event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
643 mShiftDown = (
event->modifiers() & Qt::ShiftModifier );
644 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.
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)
const QString COLLAPSE_HIDE_BORDER_FIX
#define QgsDebugMsgLevel(str, level)