23 #include <QToolButton>
24 #include <QMouseEvent>
25 #include <QPushButton>
26 #include <QStyleOptionGroupBox>
28 #include <QScrollArea>
41 : QGroupBox( title, parent )
84 connect(
this, SIGNAL( toggled(
bool ) ),
this, SLOT(
checkToggled(
bool ) ) );
85 connect(
this, SIGNAL( clicked(
bool ) ),
this, SLOT(
checkClicked(
bool ) ) );
106 if ( parent() && parent()->parent() )
116 QgsDebugMsg(
"did not find a QScrollArea parent" );
144 if ( event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier | Qt::ShiftModifier )
158 mAltDown = (
event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
159 mShiftDown = (
event->modifiers() & Qt::ShiftModifier );
184 if ( event->type() == QEvent::EnabledChange && isEnabled() )
191 QString tipTxt = QString(
"" );
192 if ( !grp.isEmpty() )
194 tipTxt =
tr(
"Ctrl (or Alt)-click to toggle all" ) +
"\n" +
tr(
"Shift-click to expand, then collapse others" );
201 QStyleOptionGroupBox box;
202 initStyleOption( &box );
203 return style()->subControlRect( QStyle::CC_GroupBox, &box,
204 QStyle::SC_GroupBoxLabel,
this );
236 bool senderCollBtn =
false;
248 QgsDebugMsg(
"Alt or Shift key down, syncing group" );
250 if ( parentWidget() )
256 if (
mSyncParent->parentWidget()->objectName() != QString(
"QgisApp" ) )
276 if (
mShiftDown && grpbox == dynamic_cast<QgsCollapsibleGroupBoxBasic *>(
this ) )
312 setUpdatesEnabled(
false );
316 bool usingQgsStyle = settings.value(
"qgis/stylesheet/groupBoxCustom", QVariant(
false ) ).toBool();
318 QStyleOptionGroupBox box;
319 initStyleOption( &box );
320 QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box,
321 QStyle::SC_GroupBoxFrame,
this );
328 int offsetStyle = QApplication::style()->objectName().contains(
"macintosh" ) ? ( usingQgsStyle ? 1 : 8 ) : 0;
329 int topBuffer = ( usingQgsStyle ? 3 : 1 ) + offsetStyle;
330 int offsetTop = topBuffer;
331 int offsetTopTri = topBuffer;
335 offsetTopTri += ( rectTitle.height() -
mCollapseButton->height() ) / 2 ;
345 if ( QApplication::style()->objectName().toLower() ==
"oxygen" )
347 QStyleOptionGroupBox box;
348 initStyleOption( &box );
349 QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box,
350 QStyle::SC_GroupBoxFrame,
this );
351 QRect rectCheckBox = style()->subControlRect( QStyle::CC_GroupBox, &box,
352 QStyle::SC_GroupBoxCheckBox,
this );
353 if ( rectFrame.left() <= 0 )
354 offsetLeft = 6 + rectFrame.left();
355 if ( rectFrame.top() <= 0 )
360 offsetTop = ( rectCheckBox.height() / 2 ) -
362 offsetTopTri = offsetTop + 1;
366 offsetTop = 6 + rectFrame.top();
367 offsetTopTri = offsetTop;
372 QgsDebugMsg( QString(
"groupbox: %1 style: %2 offset: left=%3 top=%4 top2=%5" ).arg(
373 objectName() ).arg( QApplication::style()->objectName() ).arg( offsetLeft ).arg( offsetTop ).arg( offsetTopTri ) );
377 if ( usingQgsStyle || QApplication::style()->objectName().contains(
"macintosh" ) )
379 ss +=
"QgsCollapsibleGroupBoxBasic, QgsCollapsibleGroupBox {";
380 ss += QString(
" margin-top: %1px;" ).arg( topBuffer + ( usingQgsStyle ? rectTitle.height() + 5 : rectFrame.top() ) );
383 ss +=
"QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title {";
384 ss +=
" subcontrol-origin: margin;";
385 ss +=
" subcontrol-position: top left;";
386 ss += QString(
" margin-left: %1px;" ).arg( marginLeft );
387 ss += QString(
" margin-right: %1px;" ).arg( marginRight );
388 ss += QString(
" left: %1px;" ).arg( offsetLeft );
389 ss += QString(
" top: %1px;" ).arg( offsetTop );
390 if ( QApplication::style()->objectName().contains(
"macintosh" ) )
392 ss +=
" background-color: rgba(0,0,0,0)";
399 ssd = QString(
"QgsCollapsibleGroupBoxBasic > QToolButton#%1, QgsCollapsibleGroupBox > QToolButton#%1 {" ).arg(
mCollapseButton->objectName() );
400 ssd +=
" background-color: rgba(255, 255, 255, 0); border: none;";
403 if ( offsetLeft != 0 || offsetTopTri != 0 )
406 setUpdatesEnabled(
true );
431 setMaximumHeight( collapse ?
titleRect().bottom() + 6 : 16777215 );
438 QApplication::processEvents();
447 if ( QApplication::style()->objectName().contains(
"macintosh" ) )
452 const QByteArray objKey = QString(
"CollGrpBxHiddenButton_%1" ).arg( objectName() ).toUtf8();
453 const char* pbHideKey = objKey.constData();
456 const char* gbHideKey =
"CollGrpBxHideGrpBx";
461 foreach ( QGroupBox* gbx, findChildren<QGroupBox *>() )
463 if ( gbx->isVisible() && !gbx->property( gbHideKey ).isValid() )
465 gbx->setProperty( gbHideKey, QVariant(
true ) );
471 foreach ( QPushButton* pBtn, findChildren<QPushButton *>() )
473 if ( pBtn->isVisible() && !pBtn->property( pbHideKey ).isValid() )
475 pBtn->setProperty( pbHideKey, QVariant(
true ) );
483 foreach ( QPushButton* pBtn, findChildren<QPushButton *>() )
485 if ( pBtn->property( pbHideKey ).isValid() )
487 pBtn->setProperty( pbHideKey, QVariant() );
493 foreach ( QGroupBox* gbx, findChildren<QGroupBox *>() )
495 if ( gbx->property( gbHideKey ).isValid() )
497 gbx->setProperty( gbHideKey, QVariant() );
515 QWidget *parent, QSettings* settings )
584 QString
saveKey =
"/" + objectName();
594 saveKey =
"/" + setgrp +
saveKey;
595 saveKey =
"QgsCollapsibleGroupBox" +
saveKey;
608 setUpdatesEnabled(
false );
614 val =
mSettings->value( key +
"/checked" );
615 if ( ! val.isNull() )
616 setChecked( val.toBool() );
620 val =
mSettings->value( key +
"/collapsed" );
621 if ( ! val.isNull() )
625 setUpdatesEnabled(
true );
640 mSettings->setValue( key +
"/checked", isChecked() );