Commit 58aa116a authored by Laurent Montel's avatar Laurent Montel 😁

Adapt code from master code

parent 4efde039
...@@ -100,11 +100,10 @@ bool SplitterCollapser::Private::isVertical() const ...@@ -100,11 +100,10 @@ bool SplitterCollapser::Private::isVertical() const
bool SplitterCollapser::Private::isVisible() const bool SplitterCollapser::Private::isVisible() const
{ {
const QRect widgetRect = childWidget->geometry(); const QRect widgetRect = childWidget->geometry();
const QPoint br = widgetRect.bottomRight(); if ((widgetRect.height() == 0) || (widgetRect.width() == 0)) {
if ((br.x() <= 0) || (br.y() <= 0)) {
return false;
} else {
return true; return true;
} else {
return false;
} }
} }
...@@ -117,17 +116,17 @@ void SplitterCollapser::Private::updatePosition() ...@@ -117,17 +116,17 @@ void SplitterCollapser::Private::updatePosition()
if (!isVertical()) { if (!isVertical()) {
const int splitterWidth = splitter->width(); const int splitterWidth = splitter->width();
const int width = q->width(); const int width = q->sizeHint().width();
// FIXME: Make this configurable // FIXME: Make this configurable
y = 30; y = 30;
if (direction == LeftToRight) { if (direction == LeftToRight) {
if (isVisible()) { if (!isVisible()) {
x = widgetRect.right() + handleWidth; x = widgetRect.right() + handleWidth;
} else { } else {
x = 0; x = 0;
} }
} else { // RightToLeft } else { // RightToLeft
if (isVisible()) { if (!isVisible()) {
x = widgetRect.left() - handleWidth - width; x = widgetRect.left() - handleWidth - width;
} else { } else {
x = splitterWidth - handleWidth - width; x = splitterWidth - handleWidth - width;
...@@ -135,16 +134,16 @@ void SplitterCollapser::Private::updatePosition() ...@@ -135,16 +134,16 @@ void SplitterCollapser::Private::updatePosition()
} }
} else { } else {
x = 30; x = 30;
const int height = q->height(); const int height = q->sizeHint().height();
const int splitterHeight = splitter->height(); const int splitterHeight = splitter->height();
if (direction == TopToBottom) { if (direction == TopToBottom) {
if (isVisible()) { if (!isVisible()) {
y = widgetRect.bottom() + handleWidth; y = widgetRect.bottom() + handleWidth;
} else { } else {
y = 0; y = 0;
} }
} else { // BottomToTop } else { // BottomToTop
if (isVisible()) { if (!isVisible()) {
y = widgetRect.top() - handleWidth - height; y = widgetRect.top() - handleWidth - height;
} else { } else {
y = splitterHeight - handleWidth - height; y = splitterHeight - handleWidth - height;
...@@ -156,7 +155,7 @@ void SplitterCollapser::Private::updatePosition() ...@@ -156,7 +155,7 @@ void SplitterCollapser::Private::updatePosition()
void SplitterCollapser::Private::updateArrow() void SplitterCollapser::Private::updateArrow()
{ {
q->setArrowType(isVisible() ? s_arrowDirection[direction].arrowVisible : s_arrowDirection[direction].notArrowVisible); q->setArrowType(isVisible() ? s_arrowDirection[direction].notArrowVisible : s_arrowDirection[direction].arrowVisible);
} }
void SplitterCollapser::Private::widgetEventFilter(QEvent *event) void SplitterCollapser::Private::widgetEventFilter(QEvent *event)
...@@ -181,11 +180,10 @@ void SplitterCollapser::Private::updateOpacity() ...@@ -181,11 +180,10 @@ void SplitterCollapser::Private::updateOpacity()
const QPoint pos = q->parentWidget()->mapFromGlobal(QCursor::pos()); const QPoint pos = q->parentWidget()->mapFromGlobal(QCursor::pos());
const QRect opaqueRect = q->geometry(); const QRect opaqueRect = q->geometry();
const bool opaqueCollapser = opaqueRect.contains(pos); const bool opaqueCollapser = opaqueRect.contains(pos);
const int frame = opacityTimeLine->currentFrame(); if (opaqueCollapser) {
if (opaqueCollapser && frame == opacityTimeLine->startFrame()) {
opacityTimeLine->setDirection(QTimeLine::Forward); opacityTimeLine->setDirection(QTimeLine::Forward);
startTimeLine(); startTimeLine();
} else if (!opaqueCollapser && frame == opacityTimeLine->endFrame()) { } else {
opacityTimeLine->setDirection(QTimeLine::Backward); opacityTimeLine->setDirection(QTimeLine::Backward);
startTimeLine(); startTimeLine();
} }
...@@ -193,9 +191,10 @@ void SplitterCollapser::Private::updateOpacity() ...@@ -193,9 +191,10 @@ void SplitterCollapser::Private::updateOpacity()
void SplitterCollapser::Private::startTimeLine() void SplitterCollapser::Private::startTimeLine()
{ {
if (opacityTimeLine->state() != QTimeLine::Running) { if (opacityTimeLine->state() == QTimeLine::Running) {
opacityTimeLine->start(); opacityTimeLine->stop();
} }
opacityTimeLine->start();
} }
...@@ -237,7 +236,6 @@ SplitterCollapser::SplitterCollapser(QWidget *childWidget, QSplitter *splitter) ...@@ -237,7 +236,6 @@ SplitterCollapser::SplitterCollapser(QWidget *childWidget, QSplitter *splitter)
} }
connect(this, SIGNAL(clicked()), SLOT(slotClicked())); connect(this, SIGNAL(clicked()), SLOT(slotClicked()));
show();
} }
SplitterCollapser::~SplitterCollapser() SplitterCollapser::~SplitterCollapser()
...@@ -247,7 +245,7 @@ SplitterCollapser::~SplitterCollapser() ...@@ -247,7 +245,7 @@ SplitterCollapser::~SplitterCollapser()
bool SplitterCollapser::isCollapsed() const bool SplitterCollapser::isCollapsed() const
{ {
return !d->isVisible(); return d->isVisible();
} }
bool SplitterCollapser::eventFilter(QObject *object, QEvent *event) bool SplitterCollapser::eventFilter(QObject *object, QEvent *event)
...@@ -255,7 +253,7 @@ bool SplitterCollapser::eventFilter(QObject *object, QEvent *event) ...@@ -255,7 +253,7 @@ bool SplitterCollapser::eventFilter(QObject *object, QEvent *event)
if (object == d->childWidget) { if (object == d->childWidget) {
d->widgetEventFilter(event); d->widgetEventFilter(event);
} }
return false; return QToolButton::eventFilter(object, event);
} }
void SplitterCollapser::enterEvent(QEvent *event) void SplitterCollapser::enterEvent(QEvent *event)
...@@ -270,9 +268,18 @@ void SplitterCollapser::leaveEvent(QEvent *event) ...@@ -270,9 +268,18 @@ void SplitterCollapser::leaveEvent(QEvent *event)
d->updateOpacity(); d->updateOpacity();
} }
void SplitterCollapser::showEvent(QShowEvent *event)
{
Q_UNUSED(event)
d->updateOpacity();
}
QSize SplitterCollapser::sizeHint() const QSize SplitterCollapser::sizeHint() const
{ {
const int extent = style()->pixelMetric(QStyle::PM_ScrollBarExtent); QStyleOption opt;
opt.initFrom(this);
const int extent = style()->pixelMetric(QStyle::PM_ScrollBarExtent, &opt);
QSize sh(extent * 3 / 4, extent * 240 / 100); QSize sh(extent * 3 / 4, extent * 240 / 100);
if (d->isVertical()) { if (d->isVertical()) {
sh.transpose(); sh.transpose();
...@@ -284,7 +291,7 @@ void SplitterCollapser::slotClicked() ...@@ -284,7 +291,7 @@ void SplitterCollapser::slotClicked()
{ {
QList<int> sizes = d->splitter->sizes(); QList<int> sizes = d->splitter->sizes();
const int index = d->splitter->indexOf(d->childWidget); const int index = d->splitter->indexOf(d->childWidget);
if (d->isVisible()) { if (!d->isVisible()) {
d->sizeAtCollapse = sizes; d->sizeAtCollapse = sizes;
sizes[index] = 0; sizes[index] = 0;
} else { } else {
...@@ -305,7 +312,7 @@ void SplitterCollapser::slotClicked() ...@@ -305,7 +312,7 @@ void SplitterCollapser::slotClicked()
void SplitterCollapser::collapse() void SplitterCollapser::collapse()
{ {
if (d->isVisible()) { if (!d->isVisible()) {
slotClicked(); slotClicked();
} }
// else do nothing // else do nothing
...@@ -313,7 +320,7 @@ void SplitterCollapser::collapse() ...@@ -313,7 +320,7 @@ void SplitterCollapser::collapse()
void SplitterCollapser::restore() void SplitterCollapser::restore()
{ {
if (!d->isVisible()) { if (d->isVisible()) {
slotClicked(); slotClicked();
} }
// else do nothing // else do nothing
......
...@@ -84,6 +84,7 @@ protected: ...@@ -84,6 +84,7 @@ protected:
void enterEvent(QEvent *event); void enterEvent(QEvent *event);
void leaveEvent(QEvent *event); void leaveEvent(QEvent *event);
void showEvent(QShowEvent *event);
private: private:
class Private; class Private;
Private *const d; Private *const d;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment