23 #include <QToolButton> 24 #include <QMouseEvent> 25 #include <QPushButton> 26 #include <QStyleOptionGroupBox> 27 #include <QScrollArea> 37 : QGroupBox( title, parent )
70 #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) 73 setFocusPolicy( Qt::StrongFocus );
97 if ( parent() && parent()->parent() )
101 if ( mParentScrollArea )
103 QgsDebugMsgLevel(
"found a QScrollArea parent: " + mParentScrollArea->objectName(), 5 );
135 if ( event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier | Qt::ShiftModifier )
144 QGroupBox::mousePressEvent( event );
149 mAltDown = (
event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
150 mShiftDown = (
event->modifiers() & Qt::ShiftModifier );
164 QGroupBox::mouseReleaseEvent( event );
173 QGroupBox::changeEvent( event );
175 if ( event->type() == QEvent::EnabledChange && isEnabled() )
183 if ( !grp.isEmpty() )
185 tipTxt = tr(
"Ctrl (or Alt)-click to toggle all" ) +
'\n' + tr(
"Shift-click to expand, then collapse others" );
192 QStyleOptionGroupBox box;
193 initStyleOption( &box );
194 return style()->subControlRect( QStyle::CC_GroupBox, &box,
195 QStyle::SC_GroupBoxLabel,
this );
238 QgsDebugMsg(
"Alt or Shift key down, syncing group" );
240 if ( parentWidget() )
246 if (
mSyncParent->parentWidget()->objectName() != QLatin1String(
"QgisApp" ) )
302 setUpdatesEnabled(
false );
306 bool usingQgsStyle = settings.
value( QStringLiteral(
"qgis/stylesheet/groupBoxCustom" ), QVariant(
false ) ).toBool();
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" ) ) ? ( usingQgsStyle ? 1 : 8 ) : 0;
319 int topBuffer = ( usingQgsStyle ? 3 : 1 ) + offsetStyle;
320 int offsetTop = topBuffer;
321 int offsetTopTri = topBuffer;
325 offsetTopTri += ( rectTitle.height() -
mCollapseButton->height() ) / 2;
335 if ( QApplication::style()->objectName().toLower() == QLatin1String(
"oxygen" ) )
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( QString(
"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 ( usingQgsStyle || QApplication::style()->objectName().contains( QLatin1String(
"macintosh" ) ) )
369 ss += QLatin1String(
"QgsCollapsibleGroupBoxBasic, QgsCollapsibleGroupBox {" );
370 ss += QStringLiteral(
" margin-top: %1px;" ).arg( topBuffer + ( usingQgsStyle ? rectTitle.height() + 5 : 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";
448 Q_FOREACH ( QObject *child, children() )
450 QWidget *w = qobject_cast<QWidget *>( child );
453 w->setProperty( hideKey,
true );
460 Q_FOREACH ( QObject *child, children() )
462 QWidget *w = qobject_cast<QWidget *>( child );
465 if ( w->property( hideKey ).toBool() )
477 , mSettings( settings )
549 if ( objectName().isEmpty() || (
mSettingGroup.isEmpty() && window()->objectName().isEmpty() ) )
554 QString
saveKey =
'/' + objectName();
564 saveKey =
'/' + setgrp +
saveKey;
565 saveKey = QStringLiteral(
"QgsCollapsibleGroupBox" ) +
saveKey;
581 setUpdatesEnabled(
false );
585 QVariant val =
mSettings->value( key +
"/checked" );
586 if ( ! val.isNull() )
587 setChecked( val.toBool() );
591 QVariant val =
mSettings->value( key +
"/collapsed" );
592 if ( ! val.isNull() )
596 setUpdatesEnabled(
true );
612 mSettings->setValue( key + QStringLiteral(
"/checked" ), isChecked() );
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
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
void loadState()
Will load the collapsed and checked state.
QPointer< QgsSettings > mSettings
void checkToggled(bool ckd)
QgsCollapsibleGroupBox(QWidget *parent=nullptr, QgsSettings *settings=nullptr)
void collapseExpandFixes()
Visual fixes for when group box is collapsed/expanded.