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 "svg.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
#include "widgets/label.h"
|
#include "widgets/label.h"
|
||||||
|
#include "widgets/scrollwidget.h"
|
||||||
|
|
||||||
#include "private/applet_p.h"
|
#include "private/applet_p.h"
|
||||||
#include "private/applethandle_p.h"
|
#include "private/applethandle_p.h"
|
||||||
@ -102,12 +103,24 @@ Extender::Extender(Applet *applet)
|
|||||||
applet->d->extender = this;
|
applet->d->extender = this;
|
||||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
|
||||||
setContentsMargins(0, 0, 0, 0);
|
d->scrollWidget = new ScrollWidget(this);
|
||||||
d->layout = new QGraphicsLinearLayout(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->setOrientation(Qt::Vertical);
|
||||||
d->layout->setContentsMargins(0, 0, 0, 0);
|
d->layout->setContentsMargins(0, 0, 0, 0);
|
||||||
d->layout->setSpacing(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();
|
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.
|
//remove the empty extender message if needed.
|
||||||
d->updateEmptyExtenderLabel();
|
d->updateEmptyExtenderLabel();
|
||||||
d->updateBorders();
|
d->updateBorders();
|
||||||
@ -578,17 +596,30 @@ FrameSvg::EnabledBorders Extender::enabledBordersForItem(ExtenderItem *item) con
|
|||||||
|
|
||||||
ExtenderItem *topItem = dynamic_cast<ExtenderItem*>(d->layout->itemAt(0));
|
ExtenderItem *topItem = dynamic_cast<ExtenderItem*>(d->layout->itemAt(0));
|
||||||
ExtenderItem *bottomItem = dynamic_cast<ExtenderItem*>(d->layout->itemAt(d->layout->count() - 1));
|
ExtenderItem *bottomItem = dynamic_cast<ExtenderItem*>(d->layout->itemAt(d->layout->count() - 1));
|
||||||
|
|
||||||
|
FrameSvg::EnabledBorders borders = FrameSvg::NoBorder;
|
||||||
|
|
||||||
if (item->group()) {
|
if (item->group()) {
|
||||||
return FrameSvg::NoBorder;
|
return FrameSvg::NoBorder;
|
||||||
} else if (d->appearance == TopDownStacked && bottomItem != item) {
|
} 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) {
|
} 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) {
|
} else if (d->appearance != NoBorders) {
|
||||||
return FrameSvg::LeftBorder | FrameSvg::RightBorder;
|
borders = FrameSvg::LeftBorder | FrameSvg::RightBorder;
|
||||||
} else {
|
} 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) :
|
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
|
bool Extender::isEmpty() const
|
||||||
{
|
{
|
||||||
//It's empty if it doesn't have items or has only group that are empty and autohide
|
//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 delayItemAddedEvent())
|
||||||
Q_PRIVATE_SLOT(d, void extenderItemDestroyed(ExtenderItem *item))
|
Q_PRIVATE_SLOT(d, void extenderItemDestroyed(ExtenderItem *item))
|
||||||
|
Q_PRIVATE_SLOT(d, void viewportGeometryChanged(const QRectF &))
|
||||||
|
|
||||||
friend class ExtenderPrivate;
|
friend class ExtenderPrivate;
|
||||||
friend class ExtenderGroup;
|
friend class ExtenderGroup;
|
||||||
|
@ -54,16 +54,11 @@ ExtenderGroup::ExtenderGroup(Extender *parent, uint groupId)
|
|||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
|
|
||||||
QGraphicsLinearLayout *lay = static_cast<QGraphicsLinearLayout *>(layout());
|
QGraphicsLinearLayout *lay = static_cast<QGraphicsLinearLayout *>(layout());
|
||||||
d->scrollWidget = new ScrollWidget(this);
|
d->childsWidget = new QGraphicsWidget(this);
|
||||||
d->scrollWidget->show();
|
|
||||||
lay->addItem(d->scrollWidget);
|
|
||||||
d->scrollWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
||||||
d->childsWidget = new QGraphicsWidget(d->scrollWidget);
|
|
||||||
d->childsWidget->installEventFilter(this);
|
d->childsWidget->installEventFilter(this);
|
||||||
d->scrollWidget->setWidget(d->childsWidget);
|
|
||||||
d->layout = new QGraphicsLinearLayout(Qt::Vertical, d->childsWidget);
|
d->layout = new QGraphicsLinearLayout(Qt::Vertical, d->childsWidget);
|
||||||
d->childsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
d->childsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
d->scrollWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
lay->addItem(d->childsWidget);
|
||||||
|
|
||||||
QAction *expand = new QAction(this);
|
QAction *expand = new QAction(this);
|
||||||
expand->setVisible(true);
|
expand->setVisible(true);
|
||||||
@ -181,8 +176,8 @@ void ExtenderGroup::expandGroup()
|
|||||||
extender()->itemAddedEvent(item);
|
extender()->itemAddedEvent(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d->scrollWidget->show();
|
d->childsWidget->show();
|
||||||
static_cast<QGraphicsLinearLayout *>(layout())->addItem(d->scrollWidget);
|
static_cast<QGraphicsLinearLayout *>(layout())->addItem(d->childsWidget);
|
||||||
updateGeometry();
|
updateGeometry();
|
||||||
extender()->resize(extender()->effectiveSizeHint(Qt::PreferredSize));
|
extender()->resize(extender()->effectiveSizeHint(Qt::PreferredSize));
|
||||||
}
|
}
|
||||||
@ -206,8 +201,8 @@ void ExtenderGroup::collapseGroup()
|
|||||||
extender()->itemRemovedEvent(item);
|
extender()->itemRemovedEvent(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d->scrollWidget->hide();
|
d->childsWidget->hide();
|
||||||
static_cast<QGraphicsLinearLayout *>(layout())->removeItem(d->scrollWidget);
|
static_cast<QGraphicsLinearLayout *>(layout())->removeItem(d->childsWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExtenderGroup::resizeEvent(QGraphicsSceneResizeEvent *event)
|
void ExtenderGroup::resizeEvent(QGraphicsSceneResizeEvent *event)
|
||||||
@ -325,7 +320,7 @@ void ExtenderGroupPrivate::addItemToGroup(Plasma::ExtenderItem *item, const QPoi
|
|||||||
q->extender()->itemAddedEvent(q);
|
q->extender()->itemAddedEvent(q);
|
||||||
q->show();
|
q->show();
|
||||||
}
|
}
|
||||||
scrollWidget->setVisible(!q->isCollapsed());
|
childsWidget->setVisible(!q->isCollapsed());
|
||||||
q->extender()->resize(q->extender()->effectiveSizeHint(Qt::PreferredSize));
|
q->extender()->resize(q->extender()->effectiveSizeHint(Qt::PreferredSize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ class Extender;
|
|||||||
class ExtenderGroup;
|
class ExtenderGroup;
|
||||||
class ExtenderItem;
|
class ExtenderItem;
|
||||||
class Label;
|
class Label;
|
||||||
|
class ScrollWidget;
|
||||||
class Svg;
|
class Svg;
|
||||||
|
|
||||||
class Spacer : public QGraphicsWidget
|
class Spacer : public QGraphicsWidget
|
||||||
@ -66,6 +67,7 @@ class ExtenderPrivate
|
|||||||
|
|
||||||
void addExtenderItem(ExtenderItem *item, const QPointF &pos = QPointF(-1, -1));
|
void addExtenderItem(ExtenderItem *item, const QPointF &pos = QPointF(-1, -1));
|
||||||
void extenderItemDestroyed(ExtenderItem *item);
|
void extenderItemDestroyed(ExtenderItem *item);
|
||||||
|
void viewportGeometryChanged(const QRectF &rect);
|
||||||
void removeExtenderItem(ExtenderItem *item);
|
void removeExtenderItem(ExtenderItem *item);
|
||||||
int insertIndexFromPos(const QPointF &pos) const;
|
int insertIndexFromPos(const QPointF &pos) const;
|
||||||
void loadExtenderItems();
|
void loadExtenderItems();
|
||||||
@ -77,6 +79,8 @@ class ExtenderPrivate
|
|||||||
Extender *q;
|
Extender *q;
|
||||||
|
|
||||||
QWeakPointer<Applet> applet;
|
QWeakPointer<Applet> applet;
|
||||||
|
ScrollWidget *scrollWidget;
|
||||||
|
QGraphicsWidget *mainWidget;
|
||||||
QGraphicsLinearLayout *layout;
|
QGraphicsLinearLayout *layout;
|
||||||
FrameSvg *background;
|
FrameSvg *background;
|
||||||
|
|
||||||
@ -93,6 +97,7 @@ class ExtenderPrivate
|
|||||||
static QGraphicsGridLayout *s_popupLayout;
|
static QGraphicsGridLayout *s_popupLayout;
|
||||||
|
|
||||||
bool destroying;
|
bool destroying;
|
||||||
|
bool scrollbarVisible;
|
||||||
|
|
||||||
QList<QPair<ExtenderItem *, QPointF> > pendingItems;
|
QList<QPair<ExtenderItem *, QPointF> > pendingItems;
|
||||||
};
|
};
|
||||||
|
@ -43,7 +43,6 @@ class ExtenderGroupPrivate
|
|||||||
Plasma::ExtenderGroup *q;
|
Plasma::ExtenderGroup *q;
|
||||||
Spacer *spacerWidget;
|
Spacer *spacerWidget;
|
||||||
Plasma::Svg *svg;
|
Plasma::Svg *svg;
|
||||||
Plasma::ScrollWidget *scrollWidget;
|
|
||||||
QGraphicsWidget *childsWidget;
|
QGraphicsWidget *childsWidget;
|
||||||
QGraphicsLinearLayout *layout;
|
QGraphicsLinearLayout *layout;
|
||||||
bool collapsed;
|
bool collapsed;
|
||||||
|
Loading…
Reference in New Issue
Block a user