Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Change collapsible arrows to detail the direction of the changing content #1136

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Libs/Widgets/ctkCollapsibleButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,20 @@ void ctkCollapsibleButtonPrivate::init()
this->ContentsMidLineWidth = 0;

this->CollapsedHeight = 14;
this->ExclusiveMouseOver = false;
this->ExclusiveMouseOver = false;
this->LookOffWhenChecked = true; // set as a prop ?

this->MaximumHeight = q->maximumHeight();

this->TextAlignment = Qt::AlignLeft | Qt::AlignVCenter;
this->IndicatorAlignment = Qt::AlignLeft | Qt::AlignVCenter;

q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum,
QSizePolicy::Preferred,
QSizePolicy::Preferred,
QSizePolicy::DefaultType));
q->setContentsMargins(0, q->buttonSizeHint().height(),0 , 0);
// by default QAbstractButton changed the background role to Button
// we want a regular background
// we want a regular background
q->setBackgroundRole(QPalette::Window);

QObject::connect(q, SIGNAL(toggled(bool)),
Expand Down Expand Up @@ -422,7 +422,7 @@ QSize ctkCollapsibleButton::buttonSizeHint()const

QStyleOptionButton opt;
opt.initFrom(this);

// indicator
QSize indicatorSize = QSize(style()->pixelMetric(QStyle::PM_IndicatorWidth, &opt, this),
style()->pixelMetric(QStyle::PM_IndicatorHeight, &opt, this));
Expand All @@ -431,8 +431,8 @@ QSize ctkCollapsibleButton::buttonSizeHint()const
int iw = indicatorSize.width() + indicatorSpacing;
w += iw;
h = qMax(h, ih);
// text

// text
QString string(this->text());
bool empty = string.isEmpty();
if (empty)
Expand Down Expand Up @@ -466,7 +466,7 @@ QSize ctkCollapsibleButton::minimumSizeHint()const
{// no layout, means the button is empty ?
return buttonSize;
}
QSize s = this->QAbstractButton::minimumSizeHint();
QSize s = this->QAbstractButton::minimumSizeHint();
return s.expandedTo(buttonSize);
}

Expand All @@ -481,7 +481,7 @@ QSize ctkCollapsibleButton::sizeHint()const
}
// open
// QAbstractButton works well only if a layout is set
QSize s = this->QAbstractButton::sizeHint();
QSize s = this->QAbstractButton::sizeHint();
return s.expandedTo(buttonSize + QSize(0, d->CollapsedHeight));
}

Expand All @@ -505,13 +505,13 @@ void ctkCollapsibleButton::paintEvent(QPaintEvent * _event)
QRect buttonRect = opt.rect;
QList<QWidget*> _children = this->findChildren<QWidget*>();
QList<QWidget*>::ConstIterator it;
for (it = _children.constBegin(); it != _children.constEnd(); ++it )
for (it = _children.constBegin(); it != _children.constEnd(); ++it )
{
if ((*it)->underMouse())
{
// the mouse has been moved from the collapsible button to one
// the mouse has been moved from the collapsible button to one
// of its children. The paint event rect is the child rect, this
// is why we have to request another paint event to redraw the
// is why we have to request another paint event to redraw the
// button to remove the highlight effect.
if (!_event->rect().contains(buttonRect))
{// repaint the button rect.
Expand All @@ -524,7 +524,7 @@ void ctkCollapsibleButton::paintEvent(QPaintEvent * _event)
}
if (d->ExclusiveMouseOver && !exclusiveMouseOver)
{
// the mouse is over the widget, but not over the children. As it
// the mouse is over the widget, but not over the children. As it
// has been de-highlighted in the past, we should refresh the button
// rect to re-highlight the button.
if (!_event->rect().contains(buttonRect))
Expand Down Expand Up @@ -592,11 +592,11 @@ void ctkCollapsibleButton::paintEvent(QPaintEvent * _event)
}
if (d->Collapsed)
{
style()->drawPrimitive(QStyle::PE_IndicatorArrowRight, &indicatorOpt, &p, this);
style()->drawPrimitive(QStyle::PE_IndicatorArrowDown, &indicatorOpt, &p, this);
}
else
{
style()->drawPrimitive(QStyle::PE_IndicatorArrowDown, &indicatorOpt, &p, this);
style()->drawPrimitive(QStyle::PE_IndicatorArrowUp, &indicatorOpt, &p, this);
}

// Draw Text
Expand Down
3 changes: 2 additions & 1 deletion Libs/Widgets/ctkCollapsibleGroupBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ctkCollapsibleGroupBoxStyle:public ctkProxyStyle
const ctkCollapsibleGroupBox* groupBox= qobject_cast<const ctkCollapsibleGroupBox*>(widget);
if (groupBox)
{
this->Superclass::drawPrimitive(groupBox->isChecked() ? QStyle::PE_IndicatorArrowDown : QStyle::PE_IndicatorArrowRight, opt, p, widget);
this->Superclass::drawPrimitive(groupBox->isChecked() ? QStyle::PE_IndicatorArrowUp : QStyle::PE_IndicatorArrowDown, opt, p, widget);
return;
}
}
Expand Down Expand Up @@ -225,6 +225,7 @@ void ctkCollapsibleGroupBox::expand(bool _expand)
}
}


if (_expand)
{
this->setMaximumHeight(d->MaxHeight);
Expand Down