23 #include <QToolButton>
24 #include <QMouseEvent>
25 #include <QPushButton>
26 #include <QStyleOptionGroupBox>
28 #include <QScrollArea>
41 : QGroupBox( title, parent )
83 setFocusPolicy( Qt::StrongFocus );
86 connect(
this, SIGNAL( toggled(
bool ) ),
this, SLOT(
checkToggled(
bool ) ) );
87 connect(
this, SIGNAL( clicked(
bool ) ),
this, SLOT(
checkClicked(
bool ) ) );
108 if ( parent() && parent()->parent() )
118 QgsDebugMsg(
"did not find a QScrollArea parent" );
146 if ( event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier | Qt::ShiftModifier )
160 mAltDown = (
event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
161 mShiftDown = (
event->modifiers() & Qt::ShiftModifier );
186 if ( event->type() == QEvent::EnabledChange && isEnabled() )
193 QString tipTxt = QString(
"" );
194 if ( !grp.isEmpty() )
196 tipTxt =
tr(
"Ctrl (or Alt)-click to toggle all" ) +
"\n" +
tr(
"Shift-click to expand, then collapse others" );
203 QStyleOptionGroupBox box;
204 initStyleOption( &box );
205 return style()->subControlRect( QStyle::CC_GroupBox, &box,
206 QStyle::SC_GroupBoxLabel,
this );
249 QgsDebugMsg(
"Alt or Shift key down, syncing group" );
251 if ( parentWidget() )
257 if (
mSyncParent->parentWidget()->objectName() != QString(
"QgisApp" ) )
277 if (
mShiftDown && grpbox == dynamic_cast<QgsCollapsibleGroupBoxBasic *>(
this ) )
313 setUpdatesEnabled(
false );
317 bool usingQgsStyle = settings.value(
"qgis/stylesheet/groupBoxCustom", QVariant(
false ) ).toBool();
319 QStyleOptionGroupBox box;
320 initStyleOption( &box );
321 QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box,
322 QStyle::SC_GroupBoxFrame,
this );
329 int offsetStyle = QApplication::style()->objectName().contains(
"macintosh" ) ? ( usingQgsStyle ? 1 : 8 ) : 0;
330 int topBuffer = ( usingQgsStyle ? 3 : 1 ) + offsetStyle;
331 int offsetTop = topBuffer;
332 int offsetTopTri = topBuffer;
336 offsetTopTri += ( rectTitle.height() -
mCollapseButton->height() ) / 2;
346 if ( QApplication::style()->objectName().toLower() ==
"oxygen" )
348 QStyleOptionGroupBox box;
349 initStyleOption( &box );
350 QRect rectFrame = style()->subControlRect( QStyle::CC_GroupBox, &box,
351 QStyle::SC_GroupBoxFrame,
this );
352 QRect rectCheckBox = style()->subControlRect( QStyle::CC_GroupBox, &box,
353 QStyle::SC_GroupBoxCheckBox,
this );
354 if ( rectFrame.left() <= 0 )
355 offsetLeft = 6 + rectFrame.left();
356 if ( rectFrame.top() <= 0 )
361 offsetTop = ( rectCheckBox.height() / 2 ) -
363 offsetTopTri = offsetTop + 1;
367 offsetTop = 6 + rectFrame.top();
368 offsetTopTri = offsetTop;
373 QgsDebugMsg( QString(
"groupbox: %1 style: %2 offset: left=%3 top=%4 top2=%5" ).arg(
374 objectName() ).arg( QApplication::style()->objectName() ).arg( offsetLeft ).arg( offsetTop ).arg( offsetTopTri ) );
378 if ( usingQgsStyle || QApplication::style()->objectName().contains(
"macintosh" ) )
380 ss +=
"QgsCollapsibleGroupBoxBasic, QgsCollapsibleGroupBox {";
381 ss += QString(
" margin-top: %1px;" ).arg( topBuffer + ( usingQgsStyle ? rectTitle.height() + 5 : rectFrame.top() ) );
384 ss +=
"QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title {";
385 ss +=
" subcontrol-origin: margin;";
386 ss +=
" subcontrol-position: top left;";
387 ss += QString(
" margin-left: %1px;" ).arg( marginLeft );
388 ss += QString(
" margin-right: %1px;" ).arg( marginRight );
389 ss += QString(
" left: %1px;" ).arg( offsetLeft );
390 ss += QString(
" top: %1px;" ).arg( offsetTop );
391 if ( QApplication::style()->objectName().contains(
"macintosh" ) )
393 ss +=
" background-color: rgba(0,0,0,0)";
400 ssd = QString(
"QgsCollapsibleGroupBoxBasic > QToolButton#%1, QgsCollapsibleGroupBox > QToolButton#%1 {" ).arg(
mCollapseButton->objectName() );
401 ssd +=
" background-color: rgba(255, 255, 255, 0); border: none;";
402 ssd += QString(
"} QgsCollapsibleGroupBoxBasic > QToolButton#%1:focus, QgsCollapsibleGroupBox > QToolButton#%1:focus { border: 1px solid palette(highlight); }" ).arg(
mCollapseButton->objectName() );
404 if ( offsetLeft != 0 || offsetTopTri != 0 )
406 setUpdatesEnabled(
true );
431 setMaximumHeight( collapse ?
titleRect().bottom() + 6 : 16777215 );
438 QApplication::processEvents();
453 const char* hideKey =
"CollGrpBxHide";
457 Q_FOREACH ( QObject* child, children() )
459 QWidget* w = qobject_cast<QWidget*>( child );
462 w->setProperty( hideKey,
true );
469 Q_FOREACH ( QObject* child, children() )
471 QWidget* w = qobject_cast<QWidget*>( child );
474 if ( w->property( hideKey ).toBool() )
491 QWidget *parent, QSettings* settings )
560 QString
saveKey =
"/" + objectName();
570 saveKey =
"/" + setgrp +
saveKey;
571 saveKey =
"QgsCollapsibleGroupBox" +
saveKey;
584 setUpdatesEnabled(
false );
590 val =
mSettings->value( key +
"/checked" );
591 if ( ! val.isNull() )
592 setChecked( val.toBool() );
596 val =
mSettings->value( key +
"/collapsed" );
597 if ( ! val.isNull() )
601 setUpdatesEnabled(
true );
616 mSettings->setValue( key +
"/checked", isChecked() );