* showAddWidgets() -> showAddWidgetsInterface(QPointF)

* private slots & methods ->pimpl & Q_PRIVATE_SLOTS

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=800867
This commit is contained in:
Aaron J. Seigo 2008-04-25 02:53:35 +00:00
parent 5a3d06c565
commit 6bff9ea245
2 changed files with 65 additions and 56 deletions

View File

@ -105,7 +105,22 @@ public:
toolbox->setPos(QPointF(r.right(), r.y())); toolbox->setPos(QPointF(r.right(), r.y()));
} }
void triggerShowAddWidgets()
{
emit q->showAddWidgetsInterface(QPointF());
}
bool regionIsEmpty(const QRectF &region, Applet *ignoredApplet=0) const;
void positionPanel(bool force = false);
void positionContainment();
void setLockToolText(); void setLockToolText();
void handleDisappeared(AppletHandle *handle);
void destroyApplet();
/**
* Repositions the Plasma toolbox. Useful to ensure its always in the correct place within the view.
*/
void repositionToolbox();
Applet* addApplet(const QString& name, const QVariantList& args = QVariantList(), Applet* addApplet(const QString& name, const QVariantList& args = QVariantList(),
const QRectF &geometry = QRectF(-1, -1, -1, -1), uint id = 0, const QRectF &geometry = QRectF(-1, -1, -1, -1), uint id = 0,
bool delayedInit = false); bool delayedInit = false);
@ -318,10 +333,10 @@ void Containment::containmentConstraintsUpdated(Plasma::Constraints constraints)
if (constraints & Plasma::SizeConstraint) { if (constraints & Plasma::SizeConstraint) {
switch (containmentType()) { switch (containmentType()) {
case PanelContainment: case PanelContainment:
positionPanel(); d->positionPanel();
break; break;
default: default:
positionContainment(); d->positionContainment();
break; break;
} }
} }
@ -339,7 +354,7 @@ void Containment::setContainmentType(Containment::Type type)
if (isContainment() && type == DesktopContainment) { if (isContainment() && type == DesktopContainment) {
if (!d->toolbox) { if (!d->toolbox) {
QGraphicsWidget *addWidgetTool = addToolBoxTool("addwidgets", "list-add", i18n("Add Widgets")); QGraphicsWidget *addWidgetTool = addToolBoxTool("addwidgets", "list-add", i18n("Add Widgets"));
connect(addWidgetTool, SIGNAL(clicked()), this, SIGNAL(showAddWidgets())); connect(addWidgetTool, SIGNAL(clicked()), this, SLOT(triggerShowAddWidgets()));
QGraphicsWidget *zoomInTool = addToolBoxTool("zoomIn", "zoom-in", i18n("Zoom In")); QGraphicsWidget *zoomInTool = addToolBoxTool("zoomIn", "zoom-in", i18n("Zoom In"));
connect(zoomInTool, SIGNAL(clicked()), this, SLOT(zoomIn())); connect(zoomInTool, SIGNAL(clicked()), this, SLOT(zoomIn()));
@ -452,8 +467,7 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
appletV.setValue((QObject*)applet); appletV.setValue((QObject*)applet);
closeApplet->setData(appletV); closeApplet->setData(appletV);
closeApplet->setIcon(KIcon("edit-delete")); closeApplet->setIcon(KIcon("edit-delete"));
connect(closeApplet, SIGNAL(triggered(bool)), connect(closeApplet, SIGNAL(triggered(bool)), this, SLOT(destroyApplet()));
this, SLOT(destroyApplet()));
desktopMenu.addAction(closeApplet); desktopMenu.addAction(closeApplet);
hasEntries = true; hasEntries = true;
} }
@ -488,9 +502,9 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
desktopMenu.exec(event->screenPos()); desktopMenu.exec(event->screenPos());
} }
void Containment::destroyApplet() void Containment::Private::destroyApplet()
{ {
QAction *action = qobject_cast<QAction*>(sender()); QAction *action = qobject_cast<QAction*>(q->sender());
if (!action) { if (!action) {
return; return;
@ -515,7 +529,7 @@ void Containment::setFormFactor(FormFactor formFactor)
if (isContainment() && containmentType() == PanelContainment && was != formFactor) { if (isContainment() && containmentType() == PanelContainment && was != formFactor) {
// we are a panel and we have chaged our orientation // we are a panel and we have chaged our orientation
positionPanel(true); d->positionPanel(true);
} }
QGraphicsLayout *lay = layout(); QGraphicsLayout *lay = layout();
@ -768,9 +782,9 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit)
emit appletAdded(applet, pos); emit appletAdded(applet, pos);
} }
bool Containment::regionIsEmpty(const QRectF &region, Applet *ignoredApplet) const bool Containment::Private::regionIsEmpty(const QRectF &region, Applet *ignoredApplet) const
{ {
foreach (Applet *applet, d->applets) { foreach (Applet *applet, applets) {
if (applet != ignoredApplet && applet->geometry().intersects(region)) { if (applet != ignoredApplet && applet->geometry().intersects(region)) {
return false; return false;
} }
@ -867,9 +881,9 @@ void Containment::setScreen(int screen)
} }
} }
void Containment::positionContainment() void Containment::Private::positionContainment()
{ {
Corona *c = corona(); Corona *c = q->corona();
if (!c) { if (!c) {
return; return;
} }
@ -879,7 +893,7 @@ void Containment::positionContainment()
while (it.hasNext()) { while (it.hasNext()) {
Containment *containment = it.next(); Containment *containment = it.next();
if (containment == this || if (containment == q ||
containment->containmentType() == PanelContainment) { containment->containmentType() == PanelContainment) {
// weed out all containments we don't care about at all // weed out all containments we don't care about at all
// e.g. Panels and ourself // e.g. Panels and ourself
@ -887,7 +901,7 @@ void Containment::positionContainment()
continue; continue;
} }
if (collidesWithItem(containment)) { if (q->collidesWithItem(containment)) {
break; break;
} }
} }
@ -923,17 +937,17 @@ void Containment::positionContainment()
height += INTER_CONTAINMENT_MARGIN; height += INTER_CONTAINMENT_MARGIN;
// a mildly naive "find the first slot" approach // a mildly naive "find the first slot" approach
QRectF r = boundingRect(); QRectF r = q->boundingRect();
QPointF topLeft(0, 0); QPointF topLeft(0, 0);
setPos(topLeft); q->setPos(topLeft);
d->positioning = true; positioning = true;
while (true) { while (true) {
it.toFront(); it.toFront();
while (it.hasNext()) { while (it.hasNext()) {
Containment *containment = it.next(); Containment *containment = it.next();
if (collidesWithItem(containment)) { if (q->collidesWithItem(containment)) {
break; break;
} }
@ -959,16 +973,16 @@ void Containment::positionContainment()
} }
kDebug() << "trying at" << topLeft; kDebug() << "trying at" << topLeft;
setPos(topLeft); q->setPos(topLeft);
//kDebug() << collidingItems().count() << collidingItems()[0] << (QGraphicsItem*)this; //kDebug() << collidingItems().count() << collidingItems()[0] << (QGraphicsItem*)this;
} }
d->positioning = false; positioning = false;
} }
void Containment::positionPanel(bool force) void Containment::Private::positionPanel(bool force)
{ {
if (!scene()) { if (!q->scene()) {
kDebug() << "no scene yet"; kDebug() << "no scene yet";
return; return;
} }
@ -976,25 +990,25 @@ void Containment::positionPanel(bool force)
// we position panels in negative coordinates, and stack all horizontal // we position panels in negative coordinates, and stack all horizontal
// and all vertical panels with each other. // and all vertical panels with each other.
const QPointF p = pos(); const QPointF p = q->pos();
if (!force && if (!force &&
p.y() + size().height() < -INTER_CONTAINMENT_MARGIN && p.y() + q->size().height() < -INTER_CONTAINMENT_MARGIN &&
scene()->collidingItems(this).isEmpty()) { q->scene()->collidingItems(q).isEmpty()) {
// already positioned and not running into any other panels // already positioned and not running into any other panels
return; return;
} }
//TODO: research how non-Horizontal, non-Vertical (e.g. Planar) panels behave here //TODO: research how non-Horizontal, non-Vertical (e.g. Planar) panels behave here
bool horiz = formFactor() == Plasma::Horizontal; bool horiz = q->formFactor() == Plasma::Horizontal;
qreal bottom = horiz ? 0 : VERTICAL_STACKING_OFFSET; qreal bottom = horiz ? 0 : VERTICAL_STACKING_OFFSET;
qreal lastHeight = 0; qreal lastHeight = 0;
// this should be ok for small numbers of panels, but we ever end // this should be ok for small numbers of panels, but we ever end
// up managing hundreds of them, this simplistic alogrithm will // up managing hundreds of them, this simplistic alogrithm will
// likely be too slow. // likely be too slow.
foreach (const Containment* other, corona()->containments()) { foreach (const Containment* other, q->corona()->containments()) {
if (other == this || if (other == q ||
other->containmentType() != PanelContainment || other->containmentType() != PanelContainment ||
horiz != (other->formFactor() == Plasma::Horizontal)) { horiz != (other->formFactor() == Plasma::Horizontal)) {
// only line up with panels of the same orientation // only line up with panels of the same orientation
@ -1024,21 +1038,21 @@ void Containment::positionPanel(bool force)
if (horiz) { if (horiz) {
bottom -= lastHeight + INTER_CONTAINMENT_MARGIN; bottom -= lastHeight + INTER_CONTAINMENT_MARGIN;
//TODO: fix x position for non-flush-left panels //TODO: fix x position for non-flush-left panels
kDebug() << "moved to" << QPointF(0, bottom - size().height()); kDebug() << "moved to" << QPointF(0, bottom - q->size().height());
newPos = QPointF(0, bottom - size().height()); newPos = QPointF(0, bottom - q->size().height());
} else { } else {
bottom += lastHeight + INTER_CONTAINMENT_MARGIN; bottom += lastHeight + INTER_CONTAINMENT_MARGIN;
//TODO: fix y position for non-flush-top panels //TODO: fix y position for non-flush-top panels
kDebug() << "moved to" << QPointF(bottom + size().width(), -INTER_CONTAINMENT_MARGIN - size().height()); kDebug() << "moved to" << QPointF(bottom + q->size().width(), -INTER_CONTAINMENT_MARGIN - q->size().height());
newPos = QPointF(bottom + size().width(), -INTER_CONTAINMENT_MARGIN - size().height()); newPos = QPointF(bottom + q->size().width(), -INTER_CONTAINMENT_MARGIN - q->size().height());
} }
d->positioning = true; positioning = true;
if (p != newPos) { if (p != newPos) {
setPos(newPos); q->setPos(newPos);
emit geometryChanged(); emit q->geometryChanged();
} }
d->positioning = false; positioning = false;
} }
int Containment::screen() const int Containment::screen() const
@ -1230,9 +1244,9 @@ bool Containment::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
return false; return false;
} }
void Containment::handleDisappeared(AppletHandle *handle) void Containment::Private::handleDisappeared(AppletHandle *handle)
{ {
d->handles.remove(handle->applet()); handles.remove(handle->applet());
handle->deleteLater(); handle->deleteLater();
} }
@ -1245,10 +1259,10 @@ QVariant Containment::itemChange(GraphicsItemChange change, const QVariant &valu
!d->positioning) { !d->positioning) {
switch (containmentType()) { switch (containmentType()) {
case PanelContainment: case PanelContainment:
positionPanel(); d->positionPanel();
break; break;
default: default:
positionContainment(); d->positionContainment();
break; break;
} }
} }
@ -1309,11 +1323,11 @@ void Containment::hideToolbox()
} }
} }
void Containment::repositionToolbox() void Containment::Private::repositionToolbox()
{ {
//kDebug() << "reposition" << d->screen << (QObject*)d->toolbox; //kDebug() << "reposition" << d->screen << (QObject*)d->toolbox;
if (d->toolbox) { if (toolbox) {
d->positionToolbox(); positionToolbox();
} }
} }

View File

@ -321,8 +321,11 @@ class PLASMA_EXPORT Containment : public Applet
/** /**
* Emitted when the containment requests an add widgets dialog is shown. * Emitted when the containment requests an add widgets dialog is shown.
* Usually only used for desktop containments. * Usually only used for desktop containments.
*
* @param pos where in the containment this request was made from, or
* an invalid position (QPointF()) is not location specific
*/ */
void showAddWidgets(); void showAddWidgetsInterface(const QPointF &pos);
/** /**
* This signal indicates that a containment has been newly * This signal indicates that a containment has been newly
@ -400,19 +403,11 @@ class PLASMA_EXPORT Containment : public Applet
void appletAnimationComplete(QGraphicsItem *item, Plasma::AnimationDriver::Animation anim); void appletAnimationComplete(QGraphicsItem *item, Plasma::AnimationDriver::Animation anim);
void dropEvent(QGraphicsSceneDragDropEvent* event); void dropEvent(QGraphicsSceneDragDropEvent* event);
private Q_SLOTS:
void handleDisappeared(AppletHandle *handle);
void destroyApplet();
/**
* Repositions the Plasma toolbox. Useful to ensure its always in the correct place within the view.
*/
void repositionToolbox();
private: private:
bool regionIsEmpty(const QRectF &region, Applet *ignoredApplet=0) const; Q_PRIVATE_SLOT(d, void triggerShowAddWidgets())
void positionPanel(bool force = false); Q_PRIVATE_SLOT(d, void handleDisappeared(AppletHandle *handle));
void positionContainment(); Q_PRIVATE_SLOT(d, void destroyApplet());
Q_PRIVATE_SLOT(d, void repositionToolbox());
friend class Applet; friend class Applet;
class Private; class Private;