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() )
103 if ( mParentScrollArea )
105 QgsDebugMsgLevel(
"found a QScrollArea parent: " + mParentScrollArea->objectName(), 5 );
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 ( parentWidget() )
248 if (
mSyncParent->parentWidget()->objectName() != QLatin1String(
"QgisApp" ) )
285 QgsDebugMsg( QStringLiteral(
"did not find a sync parent" ) );
304 setUpdatesEnabled(
false );
308 QStyleOptionGroupBox box;
309 initStyleOption( &box );
310 QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box,
311 QStyle::SC_GroupBoxFrame,
this );
318 int offsetStyle = QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) ? 8 : 0;
319 int topBuffer = 1 + offsetStyle;
320 int offsetTop = topBuffer;
321 int offsetTopTri = topBuffer;
325 offsetTopTri += ( rectTitle.height() -
mCollapseButton->height() ) / 2;
335 if ( QApplication::style()->objectName().compare( QLatin1String(
"oxygen" ), Qt::CaseInsensitive ) == 0 )
337 QStyleOptionGroupBox box;
338 initStyleOption( &box );
339 QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box,
340 QStyle::SC_GroupBoxFrame,
this );
341 QRect rectCheckBox = style()->subControlRect( QStyle::CC_GroupBox, &box,
342 QStyle::SC_GroupBoxCheckBox,
this );
343 if ( rectFrame.left() <= 0 )
344 offsetLeft = 6 + rectFrame.left();
345 if ( rectFrame.top() <= 0 )
350 offsetTop = ( rectCheckBox.height() / 2 ) -
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(
363 objectName(), QApplication::style()->objectName() ).arg( offsetLeft ).arg( offsetTop ).arg( offsetTopTri ), 5 );
367 if ( QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) )
369 ss += QLatin1String(
"QgsCollapsibleGroupBoxBasic, QgsCollapsibleGroupBox {" );
370 ss += QStringLiteral(
" margin-top: %1px;" ).arg( topBuffer + rectFrame.top() );
373 ss += QLatin1String(
"QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title {" );
374 ss += QLatin1String(
" subcontrol-origin: margin;" );
375 ss += QLatin1String(
" subcontrol-position: top left;" );
376 ss += QStringLiteral(
" margin-left: %1px;" ).arg( marginLeft );
377 ss += QStringLiteral(
" margin-right: %1px;" ).arg( marginRight );
378 ss += QStringLiteral(
" left: %1px;" ).arg( offsetLeft );
379 ss += QStringLiteral(
" top: %1px;" ).arg( offsetTop );
380 if ( QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) )
382 ss += QLatin1String(
" background-color: rgba(0,0,0,0)" );
385 setStyleSheet( styleSheet() + ss );
389 ssd = QStringLiteral(
"QgsCollapsibleGroupBoxBasic > QToolButton#%1, QgsCollapsibleGroupBox > QToolButton#%1 {" ).arg(
mCollapseButton->objectName() );
390 ssd += QLatin1String(
" background-color: rgba(255, 255, 255, 0); border: none;" );
391 ssd += QStringLiteral(
"} QgsCollapsibleGroupBoxBasic > QToolButton#%1:focus, QgsCollapsibleGroupBox > QToolButton#%1:focus { border: 1px solid palette(highlight); }" ).arg(
mCollapseButton->objectName() );
393 if ( offsetLeft != 0 || offsetTopTri != 0 )
395 setUpdatesEnabled(
true );
421 setMaximumHeight( collapse ?
titleRect().bottom() + 6 : 16777215 );
428 QApplication::processEvents();
444 const char *hideKey =
"CollGrpBxHide";
446 QString ss = styleSheet();
455 Q_FOREACH ( QObject *child, children() )
457 QWidget *w = qobject_cast<QWidget *>( child );
460 w->setProperty( hideKey,
true );
473 Q_FOREACH ( QObject *child, children() )
475 QWidget *w = qobject_cast<QWidget *>( child );
478 if ( w->property( hideKey ).toBool() )
490 , mSettings( settings )
562 if ( objectName().isEmpty() || (
mSettingGroup.isEmpty() && window()->objectName().isEmpty() ) )
567 QString
saveKey =
'/' + objectName();
577 saveKey =
'/' + setgrp +
saveKey;
578 saveKey = QStringLiteral(
"QgsCollapsibleGroupBox" ) +
saveKey;
594 setUpdatesEnabled(
false );
598 QVariant val =
mSettings->value( key +
"/checked" );
599 if ( ! val.isNull() )
600 setChecked( val.toBool() );
604 QVariant val =
mSettings->value( key +
"/collapsed" );
605 if ( ! val.isNull() )
609 setUpdatesEnabled(
true );
625 mSettings->setValue( key + QStringLiteral(
"/checked" ), isChecked() );
633 mAltDown = (
event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
634 mShiftDown = (
event->modifiers() & Qt::ShiftModifier );
635 QToolButton::mouseReleaseEvent( event );
This class is a composition of two QSettings instances:
QString syncGroup
An optional group to be collapsed and uncollapsed in sync with this group box if the Alt-modifier is ...
void collapsedStateChanged(bool collapsed)
Signal emitted when groupbox collapsed/expanded state is changed, and when first shown.
QScrollArea * mParentScrollArea
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
void saveState() const
Will save the collapsed and checked state.
void setCollapsed(bool collapse)
Collapse or uncollapse this groupbox.
void changeEvent(QEvent *event) override
void showEvent(QShowEvent *event) override
bool isCollapsed() const
Returns the current collapsed state of this group box.
QgsGroupBoxCollapseButton * mCollapseButton
QString syncGroup() const
Named group which synchronizes collapsing action when triangle is clicked while holding alt modifier ...
void checkClicked(bool ckd)
void setSettings(QgsSettings *settings)
A groupbox that collapses/expands when toggled.
#define QgsDebugMsgLevel(str, level)
void setSyncGroup(const QString &grp)
Named group which synchronizes collapsing action when triangle is clicked while holding alt modifier ...
void mouseReleaseEvent(QMouseEvent *event) override
~QgsCollapsibleGroupBox() override
void mousePressEvent(QMouseEvent *event) override
QgsCollapsibleGroupBoxBasic(QWidget *parent=nullptr)
void showEvent(QShowEvent *event) override
void loadState()
Will load the collapsed and checked state.
QPointer< QgsSettings > mSettings
void checkToggled(bool ckd)
const QString COLLAPSE_HIDE_BORDER_FIX
QgsCollapsibleGroupBox(QWidget *parent=nullptr, QgsSettings *settings=nullptr)
void collapseExpandFixes()
Visual fixes for when group box is collapsed/expanded.