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 );
247 QgsDebugMsg(
"Alt or Shift key down, syncing group" );
249 if ( parentWidget() )
255 if (
mSyncParent->parentWidget()->objectName() != QString(
"QgisApp" ) )
275 if (
mShiftDown && grpbox == dynamic_cast<QgsCollapsibleGroupBoxBasic *>(
this ) )
311 setUpdatesEnabled(
false );
315 bool usingQgsStyle = settings.value(
"qgis/stylesheet/groupBoxCustom", QVariant(
false ) ).toBool();
317 QStyleOptionGroupBox box;
318 initStyleOption( &box );
319 QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box,
320 QStyle::SC_GroupBoxFrame,
this );
327 int offsetStyle = QApplication::style()->objectName().contains(
"macintosh" ) ? ( usingQgsStyle ? 1 : 8 ) : 0;
328 int topBuffer = ( usingQgsStyle ? 3 : 1 ) + offsetStyle;
329 int offsetTop = topBuffer;
330 int offsetTopTri = topBuffer;
334 offsetTopTri += ( rectTitle.height() -
mCollapseButton->height() ) / 2 ;
344 if ( QApplication::style()->objectName().toLower() ==
"oxygen" )
346 QStyleOptionGroupBox box;
347 initStyleOption( &box );
348 QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box,
349 QStyle::SC_GroupBoxFrame,
this );
350 QRect rectCheckBox = style()->subControlRect( QStyle::CC_GroupBox, &box,
351 QStyle::SC_GroupBoxCheckBox,
this );
352 if ( rectFrame.left() <= 0 )
353 offsetLeft = 6 + rectFrame.left();
354 if ( rectFrame.top() <= 0 )
359 offsetTop = ( rectCheckBox.height() / 2 ) -
361 offsetTopTri = offsetTop + 1;
365 offsetTop = 6 + rectFrame.top();
366 offsetTopTri = offsetTop;
371 QgsDebugMsg( QString(
"groupbox: %1 style: %2 offset: left=%3 top=%4 top2=%5" ).arg(
372 objectName() ).arg( QApplication::style()->objectName() ).arg( offsetLeft ).arg( offsetTop ).arg( offsetTopTri ) );
376 if ( usingQgsStyle || QApplication::style()->objectName().contains(
"macintosh" ) )
378 ss +=
"QgsCollapsibleGroupBoxBasic, QgsCollapsibleGroupBox {";
379 ss += QString(
" margin-top: %1px;" ).arg( topBuffer + ( usingQgsStyle ? rectTitle.height() + 5 : rectFrame.top() ) );
382 ss +=
"QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title {";
383 ss +=
" subcontrol-origin: margin;";
384 ss +=
" subcontrol-position: top left;";
385 ss += QString(
" margin-left: %1px;" ).arg( marginLeft );
386 ss += QString(
" margin-right: %1px;" ).arg( marginRight );
387 ss += QString(
" left: %1px;" ).arg( offsetLeft );
388 ss += QString(
" top: %1px;" ).arg( offsetTop );
389 if ( QApplication::style()->objectName().contains(
"macintosh" ) )
391 ss +=
" background-color: rgba(0,0,0,0)";
398 ssd = QString(
"QgsCollapsibleGroupBoxBasic > QToolButton#%1, QgsCollapsibleGroupBox > QToolButton#%1 {" ).arg(
mCollapseButton->objectName() );
399 ssd +=
" background-color: rgba(255, 255, 255, 0); border: none;";
402 if ( offsetLeft != 0 || offsetTopTri != 0 )
405 setUpdatesEnabled(
true );
430 setMaximumHeight( collapse ?
titleRect().bottom() + 6 : 16777215 );
437 QApplication::processEvents();
446 if ( QApplication::style()->objectName().contains(
"macintosh" ) )
451 const QByteArray objKey = QString(
"CollGrpBxHiddenButton_%1" ).arg( objectName() ).toUtf8();
452 const char* pbHideKey = objKey.constData();
455 const char* gbHideKey =
"CollGrpBxHideGrpBx";
460 foreach ( QGroupBox* gbx, findChildren<QGroupBox *>() )
462 if ( gbx->isVisible() && !gbx->property( gbHideKey ).isValid() )
464 gbx->setProperty( gbHideKey, QVariant(
true ) );
470 foreach ( QPushButton* pBtn, findChildren<QPushButton *>() )
472 if ( pBtn->isVisible() && !pBtn->property( pbHideKey ).isValid() )
474 pBtn->setProperty( pbHideKey, QVariant(
true ) );
482 foreach ( QPushButton* pBtn, findChildren<QPushButton *>() )
484 if ( pBtn->property( pbHideKey ).isValid() )
486 pBtn->setProperty( pbHideKey, QVariant() );
492 foreach ( QGroupBox* gbx, findChildren<QGroupBox *>() )
494 if ( gbx->property( gbHideKey ).isValid() )
496 gbx->setProperty( gbHideKey, QVariant() );
514 QWidget *parent, QSettings* settings )
583 QString
saveKey =
"/" + objectName();
593 saveKey =
"/" + setgrp +
saveKey;
594 saveKey =
"QgsCollapsibleGroupBox" +
saveKey;
607 setUpdatesEnabled(
false );
613 val =
mSettings->value( key +
"/checked" );
614 if ( ! val.isNull() )
615 setChecked( val.toBool() );
619 val =
mSettings->value( key +
"/collapsed" );
620 if ( ! val.isNull() )
624 setUpdatesEnabled(
true );
639 mSettings->setValue( key +
"/checked", isChecked() );