19#include "moc_qgscollapsiblegroupbox.cpp"
28#include <QStyleOptionGroupBox>
41 : QGroupBox( title, parent )
46void QgsCollapsibleGroupBoxBasic::init()
74 setFocusPolicy( Qt::StrongFocus );
98 if ( parent() && parent()->parent() )
108 QgsDebugMsgLevel( QStringLiteral(
"did not find a QScrollArea parent" ), 5 );
136 if ( event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier | Qt::ShiftModifier )
145 QGroupBox::mousePressEvent( event );
150 mAltDown = (
event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
151 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,
196 QStyle::SC_GroupBoxLabel,
this );
239 QgsDebugMsgLevel( QStringLiteral(
"Alt or Shift key down, syncing group" ), 2 );
241 if (
auto *lParentWidget = parentWidget() )
247 if (
mSyncParent->parentWidget()->objectName() != QLatin1String(
"QgisApp" ) )
266 if ( grpbox->syncGroup() ==
syncGroup() && grpbox->isEnabled() )
275 grpbox->setCollapsed(
mShiftDown ?
true : !thisCollapsed );
304 QGroupBox::setStyleSheet( style );
309 setUpdatesEnabled(
false );
313 QStyleOptionGroupBox box;
314 initStyleOption( &box );
315 const QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box,
316 QStyle::SC_GroupBoxFrame,
this );
320 const int marginLeft = 20;
321 const int marginRight = 5;
323 const int offsetStyle = QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) ? 8 : 0;
324 const int topBuffer = 1 + offsetStyle;
325 int offsetTop = topBuffer;
326 int offsetTopTri = topBuffer;
330 offsetTopTri += ( rectTitle.height() -
mCollapseButton->height() ) / 2;
340 if ( QApplication::style()->objectName().compare( QLatin1String(
"oxygen" ), Qt::CaseInsensitive ) == 0 )
342 QStyleOptionGroupBox box;
343 initStyleOption( &box );
344 const QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box,
345 QStyle::SC_GroupBoxFrame,
this );
346 const QRect rectCheckBox = style()->subControlRect( QStyle::CC_GroupBox, &box,
347 QStyle::SC_GroupBoxCheckBox,
this );
348 if ( rectFrame.left() <= 0 )
349 offsetLeft = 6 + rectFrame.left();
350 if ( rectFrame.top() <= 0 )
355 offsetTop = ( rectCheckBox.height() / 2 ) -
357 offsetTopTri = offsetTop + 1;
361 offsetTop = 6 + rectFrame.top();
362 offsetTopTri = offsetTop;
367 QgsDebugMsgLevel( QStringLiteral(
"groupbox: %1 style: %2 offset: left=%3 top=%4 top2=%5" ).arg(
368 objectName(), QApplication::style()->objectName() ).arg( offsetLeft ).arg( offsetTop ).arg( offsetTopTri ), 5 );
372 if ( QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) )
374 ss += QLatin1String(
"QgsCollapsibleGroupBoxBasic, QgsCollapsibleGroupBox {" );
375 ss += QStringLiteral(
" margin-top: %1px;" ).arg( topBuffer + rectFrame.top() );
378 ss += QLatin1String(
"QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title {" );
379 ss += QLatin1String(
" subcontrol-origin: margin;" );
380 ss += QLatin1String(
" subcontrol-position: top left;" );
381 ss += QStringLiteral(
" margin-left: %1px;" ).arg( marginLeft );
382 ss += QStringLiteral(
" margin-right: %1px;" ).arg( marginRight );
383 ss += QStringLiteral(
" left: %1px;" ).arg( offsetLeft );
384 ss += QStringLiteral(
" top: %1px;" ).arg( offsetTop );
385 if ( QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) )
387 ss += QLatin1String(
" background-color: rgba(0,0,0,0)" );
394 ssd = QStringLiteral(
"QgsCollapsibleGroupBoxBasic > QToolButton#%1, QgsCollapsibleGroupBox > QToolButton#%1 {" ).arg(
mCollapseButton->objectName() );
395 ssd += QLatin1String(
" background-color: rgba(255, 255, 255, 0); border: none;" );
396 ssd += QStringLiteral(
"} QgsCollapsibleGroupBoxBasic > QToolButton#%1:focus, QgsCollapsibleGroupBox > QToolButton#%1:focus { border: 1px solid palette(highlight); }" ).arg(
mCollapseButton->objectName() );
398 if ( offsetLeft != 0 || offsetTopTri != 0 )
400 setUpdatesEnabled(
true );
426 setMaximumHeight( collapse ?
titleRect().bottom() + 6 : 16777215 );
433 QApplication::processEvents();
449 const char *hideKey =
"CollGrpBxHide";
451 QString ss = styleSheet();
460 const auto constChildren = children();
461 for ( QObject *child : constChildren )
463 QWidget *w = qobject_cast<QWidget *>( child );
466 w->setProperty( hideKey,
true );
479 const auto constChildren = children();
480 for ( QObject *child : constChildren )
482 QWidget *w = qobject_cast<QWidget *>( child );
485 if ( w->property( hideKey ).toBool() )
497 , mSettings( settings )
505 , mSettings( settings )
522 mSettings = settings;
523 mDelSettings =
false;
526void QgsCollapsibleGroupBox::init()
530 mDelSettings =
false;
537 mSaveCollapsedState =
true;
540 mSaveCheckedState =
false;
572 if ( objectName().isEmpty() || ( mSettingGroup.isEmpty() && window()->objectName().isEmpty() ) )
577 QString
saveKey =
'/' + objectName();
586 const QString setgrp = mSettingGroup.isEmpty() ? window()->objectName() : mSettingGroup;
597 if ( !isEnabled() || ( !mSaveCollapsedState && !mSaveCheckedState ) )
604 setUpdatesEnabled(
false );
606 if ( mSaveCheckedState )
608 const QVariant val = mSettings->value( key +
"/checked" );
610 setChecked( val.toBool() );
612 if ( mSaveCollapsedState )
614 const QVariant val = mSettings->value( key +
"/collapsed" );
619 setUpdatesEnabled(
true );
627 if ( !
mShown || !isEnabled() || ( !mSaveCollapsedState && !mSaveCheckedState ) )
634 if ( mSaveCheckedState )
635 mSettings->setValue( key + QStringLiteral(
"/checked" ), isChecked() );
636 if ( mSaveCollapsedState )
637 mSettings->setValue( key + QStringLiteral(
"/collapsed" ),
isCollapsed() );
643 mAltDown = (
event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
644 mShiftDown = (
event->modifiers() & Qt::ShiftModifier );
645 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)
This class is a composition of two QSettings instances:
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)