IMPROVEMENT: the whole extender scrolls when there is not enough room anymore.
the extendergroup doen't have a scrollwidget anymore still needs perfecting but is already less buggy and prettier svn path=/trunk/KDE/kdelibs/; revision=1184907
This commit is contained in:
parent
b6624d3fe1
commit
7306716038
@ -37,6 +37,7 @@
|
||||
#include "svg.h"
|
||||
#include "theme.h"
|
||||
#include "widgets/label.h"
|
||||
#include "widgets/scrollwidget.h"
|
||||
|
||||
#include "private/applet_p.h"
|
||||
#include "private/applethandle_p.h"
|
||||
@ -102,12 +103,24 @@ Extender::Extender(Applet *applet)
|
||||
applet->d->extender = this;
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
setContentsMargins(0, 0, 0, 0);
|
||||
d->layout = new QGraphicsLinearLayout(this);
|
||||
d->scrollWidget = new ScrollWidget(this);
|
||||
d->scrollWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
d->mainWidget = new QGraphicsWidget(d->scrollWidget);
|
||||
d->scrollWidget->setWidget(d->mainWidget);
|
||||
d->mainWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
connect(d->scrollWidget, SIGNAL(viewportGeometryChanged(const QRectF &)),
|
||||
this, SLOT(viewportGeometryChanged(const QRectF &)));
|
||||
|
||||
d->layout = new QGraphicsLinearLayout(d->mainWidget);
|
||||
d->layout->setOrientation(Qt::Vertical);
|
||||
d->layout->setContentsMargins(0, 0, 0, 0);
|
||||
d->layout->setSpacing(0);
|
||||
setLayout(d->layout);
|
||||
|
||||
|
||||
QGraphicsLinearLayout *lay = new QGraphicsLinearLayout(Qt::Vertical, this);
|
||||
lay->addItem(d->scrollWidget);
|
||||
setContentsMargins(0, 0, 0, 0);
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
d->loadExtenderItems();
|
||||
|
||||
@ -490,6 +503,11 @@ void Extender::itemAddedEvent(ExtenderItem *item, const QPointF &pos)
|
||||
}
|
||||
}
|
||||
|
||||
//FIXME: hardcoded number for the scrollbar
|
||||
d->scrollWidget->setMinimumWidth(d->mainWidget->effectiveSizeHint(Qt::MinimumSize).width() + 32);
|
||||
//FIXME: hardcoded number
|
||||
d->scrollWidget->setMinimumHeight(qMin((qreal)300, d->mainWidget->effectiveSizeHint(Qt::MinimumSize).height()));
|
||||
|
||||
//remove the empty extender message if needed.
|
||||
d->updateEmptyExtenderLabel();
|
||||
d->updateBorders();
|
||||
@ -578,17 +596,30 @@ FrameSvg::EnabledBorders Extender::enabledBordersForItem(ExtenderItem *item) con
|
||||
|
||||
ExtenderItem *topItem = dynamic_cast<ExtenderItem*>(d->layout->itemAt(0));
|
||||
ExtenderItem *bottomItem = dynamic_cast<ExtenderItem*>(d->layout->itemAt(d->layout->count() - 1));
|
||||
|
||||
FrameSvg::EnabledBorders borders = FrameSvg::NoBorder;
|
||||
|
||||
if (item->group()) {
|
||||
return FrameSvg::NoBorder;
|
||||
} else if (d->appearance == TopDownStacked && bottomItem != item) {
|
||||
return FrameSvg::LeftBorder | FrameSvg::BottomBorder | FrameSvg::RightBorder;
|
||||
borders = FrameSvg::LeftBorder | FrameSvg::BottomBorder | FrameSvg::RightBorder;
|
||||
} else if (d->appearance == BottomUpStacked && topItem != item) {
|
||||
return FrameSvg::LeftBorder | FrameSvg::TopBorder | FrameSvg::RightBorder;
|
||||
borders = FrameSvg::LeftBorder | FrameSvg::TopBorder | FrameSvg::RightBorder;
|
||||
} else if (d->appearance != NoBorders) {
|
||||
return FrameSvg::LeftBorder | FrameSvg::RightBorder;
|
||||
borders = FrameSvg::LeftBorder | FrameSvg::RightBorder;
|
||||
} else {
|
||||
return 0;
|
||||
return FrameSvg::NoBorder;
|
||||
}
|
||||
|
||||
if (d->scrollWidget->viewportGeometry().height() < d->mainWidget->boundingRect().height()) {
|
||||
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
||||
borders &= ~FrameSvg::LeftBorder;
|
||||
} else {
|
||||
borders &= ~FrameSvg::RightBorder;
|
||||
}
|
||||
}
|
||||
|
||||
return borders;
|
||||
}
|
||||
|
||||
ExtenderPrivate::ExtenderPrivate(Applet *applet, Extender *extender) :
|
||||
@ -811,6 +842,32 @@ void ExtenderPrivate::extenderItemDestroyed(ExtenderItem *item)
|
||||
}
|
||||
}
|
||||
|
||||
void ExtenderPrivate::viewportGeometryChanged(const QRectF &rect)
|
||||
{
|
||||
if (appearance != Extender::TopDownStacked && appearance != Extender::BottomUpStacked) {
|
||||
scrollbarVisible = (rect.height() > mainWidget->boundingRect().height());
|
||||
return;
|
||||
}
|
||||
|
||||
bool scroll;
|
||||
if (rect.height() >= mainWidget->boundingRect().height()) {
|
||||
scroll = false;
|
||||
scrollWidget->setContentsMargins(0, 0, 0, 0);
|
||||
} else {
|
||||
scroll = true;
|
||||
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
||||
scrollWidget->setContentsMargins(background->marginSize(RightMargin), 0, 0, 0);
|
||||
} else {
|
||||
scrollWidget->setContentsMargins(0, 0, background->marginSize(RightMargin), 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (scroll != scrollbarVisible) {
|
||||
scrollbarVisible = scroll;
|
||||
updateBorders();
|
||||
}
|
||||
}
|
||||
|
||||
bool Extender::isEmpty() const
|
||||
{
|
||||
//It's empty if it doesn't have items or has only group that are empty and autohide
|
||||
|
@ -305,6 +305,7 @@ class PLASMA_EXPORT Extender : public QGraphicsWidget
|
||||
|
||||
Q_PRIVATE_SLOT(d, void delayItemAddedEvent())
|
||||
Q_PRIVATE_SLOT(d, void extenderItemDestroyed(ExtenderItem *item))
|
||||
Q_PRIVATE_SLOT(d, void viewportGeometryChanged(const QRectF &))
|
||||
|
||||
friend class ExtenderPrivate;
|
||||
friend class ExtenderGroup;
|
||||
|
@ -54,16 +54,11 @@ ExtenderGroup::ExtenderGroup(Extender *parent, uint groupId)
|
||||
setAcceptDrops(true);
|
||||
|
||||
QGraphicsLinearLayout *lay = static_cast<QGraphicsLinearLayout *>(layout());
|
||||
d->scrollWidget = new ScrollWidget(this);
|
||||
d->scrollWidget->show();
|
||||
lay->addItem(d->scrollWidget);
|
||||
d->scrollWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
d->childsWidget = new QGraphicsWidget(d->scrollWidget);
|
||||
d->childsWidget = new QGraphicsWidget(this);
|
||||
d->childsWidget->installEventFilter(this);
|
||||
d->scrollWidget->setWidget(d->childsWidget);
|
||||
d->layout = new QGraphicsLinearLayout(Qt::Vertical, d->childsWidget);
|
||||
d->childsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
d->scrollWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
lay->addItem(d->childsWidget);
|
||||
|
||||
QAction *expand = new QAction(this);
|
||||
expand->setVisible(true);
|
||||
@ -181,8 +176,8 @@ void ExtenderGroup::expandGroup()
|
||||
extender()->itemAddedEvent(item);
|
||||
}
|
||||
}
|
||||
d->scrollWidget->show();
|
||||
static_cast<QGraphicsLinearLayout *>(layout())->addItem(d->scrollWidget);
|
||||
d->childsWidget->show();
|
||||
static_cast<QGraphicsLinearLayout *>(layout())->addItem(d->childsWidget);
|
||||
updateGeometry();
|
||||
extender()->resize(extender()->effectiveSizeHint(Qt::PreferredSize));
|
||||
}
|
||||
@ -206,8 +201,8 @@ void ExtenderGroup::collapseGroup()
|
||||
extender()->itemRemovedEvent(item);
|
||||
}
|
||||
}
|
||||
d->scrollWidget->hide();
|
||||
static_cast<QGraphicsLinearLayout *>(layout())->removeItem(d->scrollWidget);
|
||||
d->childsWidget->hide();
|
||||
static_cast<QGraphicsLinearLayout *>(layout())->removeItem(d->childsWidget);
|
||||
}
|
||||
|
||||
void ExtenderGroup::resizeEvent(QGraphicsSceneResizeEvent *event)
|
||||
@ -325,7 +320,7 @@ void ExtenderGroupPrivate::addItemToGroup(Plasma::ExtenderItem *item, const QPoi
|
||||
q->extender()->itemAddedEvent(q);
|
||||
q->show();
|
||||
}
|
||||
scrollWidget->setVisible(!q->isCollapsed());
|
||||
childsWidget->setVisible(!q->isCollapsed());
|
||||
q->extender()->resize(q->extender()->effectiveSizeHint(Qt::PreferredSize));
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ class Extender;
|
||||
class ExtenderGroup;
|
||||
class ExtenderItem;
|
||||
class Label;
|
||||
class ScrollWidget;
|
||||
class Svg;
|
||||
|
||||
class Spacer : public QGraphicsWidget
|
||||
@ -66,6 +67,7 @@ class ExtenderPrivate
|
||||
|
||||
void addExtenderItem(ExtenderItem *item, const QPointF &pos = QPointF(-1, -1));
|
||||
void extenderItemDestroyed(ExtenderItem *item);
|
||||
void viewportGeometryChanged(const QRectF &rect);
|
||||
void removeExtenderItem(ExtenderItem *item);
|
||||
int insertIndexFromPos(const QPointF &pos) const;
|
||||
void loadExtenderItems();
|
||||
@ -77,6 +79,8 @@ class ExtenderPrivate
|
||||
Extender *q;
|
||||
|
||||
QWeakPointer<Applet> applet;
|
||||
ScrollWidget *scrollWidget;
|
||||
QGraphicsWidget *mainWidget;
|
||||
QGraphicsLinearLayout *layout;
|
||||
FrameSvg *background;
|
||||
|
||||
@ -93,6 +97,7 @@ class ExtenderPrivate
|
||||
static QGraphicsGridLayout *s_popupLayout;
|
||||
|
||||
bool destroying;
|
||||
bool scrollbarVisible;
|
||||
|
||||
QList<QPair<ExtenderItem *, QPointF> > pendingItems;
|
||||
};
|
||||
|
@ -43,7 +43,6 @@ class ExtenderGroupPrivate
|
||||
Plasma::ExtenderGroup *q;
|
||||
Spacer *spacerWidget;
|
||||
Plasma::Svg *svg;
|
||||
Plasma::ScrollWidget *scrollWidget;
|
||||
QGraphicsWidget *childsWidget;
|
||||
QGraphicsLinearLayout *layout;
|
||||
bool collapsed;
|
||||
|
Loading…
Reference in New Issue
Block a user