Export a really simple AbstractToolBox

add a setToolBox function

svn path=/trunk/KDE/kdelibs/; revision=1038024
This commit is contained in:
Marco Martin 2009-10-20 14:14:53 +00:00
parent cbc0f99d2a
commit 6b0a4590d2
13 changed files with 331 additions and 160 deletions

View File

@ -96,7 +96,7 @@ set(plasma_LIB_SRCS
private/serviceprovider.cpp
private/style.cpp
private/trustedonlyauthorization.cpp
private/toolbox.cpp
private/internaltoolbox.cpp
private/tooltip.cpp
private/wallpaperrenderthread.cpp
private/windowpreview.cpp
@ -121,6 +121,7 @@ set(plasma_LIB_SRCS
servicejob.cpp
svg.cpp
theme.cpp
abstracttoolbox.cpp
tooltipcontent.cpp
tooltipmanager.cpp
version.cpp
@ -287,6 +288,7 @@ set(plasma_LIB_INCLUDES
servicejob.h
svg.h
theme.h
abstracttoolbox.h
tooltipcontent.h
tooltipmanager.h
version.h

56
abstracttoolbox.cpp Normal file
View File

@ -0,0 +1,56 @@
/*
* Copyright 2008 by Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "abstracttoolbox.h"
#include "containment.h"
namespace Plasma
{
class AbstractToolBoxPrivate
{
public:
AbstractToolBoxPrivate(Containment *c)
: containment(c)
{}
Containment *containment;
};
AbstractToolBox::AbstractToolBox(Containment *parent)
: QGraphicsWidget(parent),
d(new AbstractToolBoxPrivate(parent))
{
}
AbstractToolBox::~AbstractToolBox()
{
delete d;
}
Containment *AbstractToolBox::containment() const
{
return d->containment;
}
} // plasma namespace
#include "abstracttoolbox.moc"

72
abstracttoolbox.h Normal file
View File

@ -0,0 +1,72 @@
/*
* Copyright 2008 by Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_ABSTRACTTOOLBOX_H
#define PLASMA_ABSTRACTTOOLBOX_H
#include <QGraphicsWidget>
#include "containment.h"
#include "plasma_export.h"
class QAction;
namespace Plasma
{
//class Widget;
//class EmptyGraphicsItem;
class AbstractToolBoxPrivate;
class PLASMA_EXPORT AbstractToolBox : public QGraphicsWidget
{
Q_OBJECT
Q_INTERFACES(QGraphicsItem)
public:
explicit AbstractToolBox(Containment *parent);
~AbstractToolBox();
/**
* create a toolbox tool from the given action
* @p action the action to associate hte tool with
*/
virtual void addTool(QAction *action) = 0;
/**
* remove the tool associated with this action
*/
virtual void removeTool(QAction *action) = 0;
virtual bool isShowing() const = 0;
virtual void setShowing(const bool show) = 0;
Q_SIGNALS:
void toggled();
protected:
Containment *containment() const;
private:
AbstractToolBoxPrivate * const d;
};
} // Plasma namespace
#endif // multiple inclusion guard

View File

@ -102,7 +102,7 @@
#include "private/popupapplet_p.h"
#include "private/service_p.h"
#include "private/remotedataengine.h"
#include "private/toolbox_p.h"
#include "private/internaltoolbox_p.h"
#include "private/associatedapplicationmanager_p.h"
#include "ui_publish.h"
@ -1328,11 +1328,12 @@ void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QW
//update the view transform of the toolbox, since it ignores transforms
if (v && c && c->d->toolBox) {
if (c->d->toolBox->viewTransform().isScaling() && !v->transform().isScaling()) {
InternalToolBox *toolBox = qobject_cast<InternalToolBox *>(c->d->toolBox);
if (toolBox && toolBox->viewTransform().isScaling() && !v->transform().isScaling()) {
c->d->positionToolBox();
}
if (v) {
c->d->toolBox->setViewTransform(v->transform());
if (toolBox && v) {
toolBox->setViewTransform(v->transform());
}
}

View File

@ -368,8 +368,9 @@ void Containment::restore(KConfigGroup &group)
setWallpaper(group.readEntry("wallpaperplugin", defaultWallpaper),
group.readEntry("wallpaperpluginmode", defaultWallpaperMode));
if (d->toolBox) {
d->toolBox->load(group);
InternalToolBox *toolBox = qobject_cast<InternalToolBox *>(d->toolBox);
if (toolBox) {
toolBox->load(group);
}
KConfigGroup cfg(&group, "ActionPlugins");
@ -414,8 +415,9 @@ void Containment::save(KConfigGroup &g) const
group.writeEntry("location", (int)d->location);
group.writeEntry("activity", d->context()->currentActivity());
if (d->toolBox) {
d->toolBox->save(group);
InternalToolBox *toolBox = qobject_cast<InternalToolBox *>(d->toolBox);
if (toolBox) {
toolBox->save(group);
}
if (d->wallpaper) {
@ -801,14 +803,15 @@ void Containment::setFormFactor(FormFactor formFactor)
d->positionPanel(true);
}
if (d->toolBox) {
InternalToolBox *toolBox = static_cast<InternalToolBox *>(d->toolBox);
if (toolBox) {
if (d->formFactor == Vertical) {
d->toolBox->setCorner(ToolBox::Bottom);
toolBox->setCorner(InternalToolBox::Bottom);
//defaults to horizontal
} else if (QApplication::layoutDirection() == Qt::RightToLeft) {
d->toolBox->setCorner(ToolBox::Left);
toolBox->setCorner(InternalToolBox::Left);
} else {
d->toolBox->setCorner(ToolBox::Right);
toolBox->setCorner(InternalToolBox::Right);
}
}
@ -1514,6 +1517,19 @@ const QGraphicsItem *Containment::toolBoxItem() const
return d->toolBox;
}
void Containment::setToolBox(AbstractToolBox *toolBox)
{
if (d->toolBox) {
d->toolBox->deleteLater();
}
d->toolBox = toolBox;
}
AbstractToolBox *Containment::toolBox() const
{
return d->toolBox;
}
void Containment::resizeEvent(QGraphicsSceneResizeEvent *event)
{
Applet::resizeEvent(event);
@ -1688,16 +1704,16 @@ void Containment::setToolBoxOpen(bool open)
void Containment::openToolBox()
{
if (d->toolBox && !d->toolBox->showing()) {
d->toolBox->showToolBox();
if (d->toolBox && !d->toolBox->isShowing()) {
d->toolBox->setShowing(true);
emit toolBoxVisibilityChanged(true);
}
}
void Containment::closeToolBox()
{
if (d->toolBox && d->toolBox->showing()) {
d->toolBox->hideToolBox();
if (d->toolBox && d->toolBox->isShowing()) {
d->toolBox->setShowing(false);
emit toolBoxVisibilityChanged(false);
}
}
@ -2021,31 +2037,40 @@ void ContainmentPrivate::zoomOut()
positionToolBox();
}
ToolBox *ContainmentPrivate::createToolBox()
AbstractToolBox *ContainmentPrivate::createToolBox()
{
if (!toolBox) {
switch (type) {
case Containment::PanelContainment:
case Containment::CustomPanelContainment:
toolBox = new PanelToolBox(q);
toolBox->setSize(KIconLoader::SizeSmallMedium);
toolBox->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall));
{
PanelToolBox *pt = new PanelToolBox(q);
toolBox = pt;
pt->setSize(KIconLoader::SizeSmallMedium);
pt->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall));
if (q->immutability() != Mutable) {
toolBox->hide();
pt->hide();
}
break;
}
default:
toolBox = new DesktopToolBox(q);
toolBox->setSize(KIconLoader::SizeSmallMedium);
toolBox->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall));
{
DesktopToolBox *dt = new DesktopToolBox(q);
toolBox = dt;
dt->setSize(KIconLoader::SizeSmallMedium);
dt->setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall));
break;
}
}
if (toolBox) {
InternalToolBox *internalToolBox = qobject_cast<InternalToolBox *>(toolBox);
QObject::connect(toolBox, SIGNAL(toggled()), q, SIGNAL(toolBoxToggled()));
QObject::connect(toolBox, SIGNAL(toggled()), q, SLOT(updateToolBoxVisibility()));
toolBox->load();
positionToolBox();
if (internalToolBox) {
internalToolBox->load();
positionToolBox();
}
}
}
@ -2054,14 +2079,15 @@ ToolBox *ContainmentPrivate::createToolBox()
void ContainmentPrivate::positionToolBox()
{
if (toolBox) {
toolBox->reposition();
PanelToolBox *internalToolBox = qobject_cast<PanelToolBox *>(toolBox);
if (internalToolBox) {
internalToolBox->reposition();
}
}
void ContainmentPrivate::updateToolBoxVisibility()
{
emit q->toolBoxVisibilityChanged(toolBox->showing());
emit q->toolBoxVisibilityChanged(toolBox->isShowing());
}
void ContainmentPrivate::triggerShowAddWidgets()
@ -2109,7 +2135,8 @@ void ContainmentPrivate::containmentConstraintsEvent(Plasma::Constraints constra
if (type == Containment::PanelContainment || type == Containment::CustomPanelContainment) {
toolBox->setVisible(unlocked);
} else {
toolBox->setIsMovable(unlocked);
InternalToolBox *internalToolBox = qobject_cast<InternalToolBox *>(toolBox);
internalToolBox->setIsMovable(unlocked);
}
}

View File

@ -50,6 +50,7 @@ class View;
class Wallpaper;
class ContainmentActions;
class ContainmentPrivate;
class AbstractToolBox;
/**
* @class Containment plasma/containment.h <Plasma/Containment>
@ -567,7 +568,23 @@ class PLASMA_EXPORT Containment : public Applet
/**
* @returns the toolbox associated with this containment, or a null pointer if none
*/
const QGraphicsItem *toolBoxItem() const;
KDE_DEPRECATED const QGraphicsItem *toolBoxItem() const;
/**
* Sets a custom ToolBox
* if there was an old one it will be deleted
* and the new one won't have any actions in it
*
* @param item the new toolbox item
* @since 4.4
*/
void setToolBox(AbstractToolBox *toolBox);
/**
* @return the ToolBox
* @since 4.4
*/
AbstractToolBox *toolBox() const;
private:
Q_PRIVATE_SLOT(d, void appletDestroyed(Plasma::Applet*))

View File

@ -35,7 +35,7 @@ namespace Plasma
class AccessAppletJob;
class Containment;
class ToolBox;
class AbstractToolBox;
class ContainmentPrivate
{
@ -63,7 +63,7 @@ public:
qDeleteAll(dropMenus);
}
ToolBox *createToolBox();
AbstractToolBox *createToolBox();
void positionToolBox();
void updateToolBoxVisibility();
void triggerShowAddWidgets();
@ -148,7 +148,7 @@ public:
QHash<QString, ContainmentActions*> actionPlugins;
int screen;
int desktop;
ToolBox *toolBox;
AbstractToolBox *toolBox;
Context *con;
Containment::Type type;
static bool s_positioning;

View File

@ -163,28 +163,28 @@ public:
void adjustBackgroundBorders()
{
switch (q->corner()) {
case ToolBox::TopRight:
case InternalToolBox::TopRight:
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::LeftBorder);
break;
case ToolBox::Top:
case InternalToolBox::Top:
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
break;
case ToolBox::TopLeft:
case InternalToolBox::TopLeft:
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::RightBorder);
break;
case ToolBox::Left:
case InternalToolBox::Left:
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::RightBorder);
break;
case ToolBox::Right:
case InternalToolBox::Right:
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::LeftBorder);
break;
case ToolBox::BottomLeft:
case InternalToolBox::BottomLeft:
background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::RightBorder);
break;
case ToolBox::Bottom:
case InternalToolBox::Bottom:
background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
break;
case ToolBox::BottomRight:
case InternalToolBox::BottomRight:
default:
background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::LeftBorder);
break;
@ -207,7 +207,7 @@ public:
};
DesktopToolBox::DesktopToolBox(Containment *parent)
: ToolBox(parent),
: InternalToolBox(parent),
d(new DesktopToolBoxPrivate(this))
{
d->background = new Plasma::FrameSvg(this);
@ -274,7 +274,7 @@ QSize DesktopToolBox::fullHeight() const
void DesktopToolBox::toolTipAboutToShow()
{
if (isToolbar() || showing()) {
if (isToolbar() || isShowing()) {
return;
}
@ -330,7 +330,7 @@ void DesktopToolBox::toolTriggered(bool)
{
QAction *action = qobject_cast<QAction *>(sender());
if (showing() && (!action || !action->autoRepeat())) {
if (isShowing() && (!action || !action->autoRepeat())) {
emit toggled();
}
}
@ -509,7 +509,7 @@ QPainterPath DesktopToolBox::shape() const
void DesktopToolBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
if (showing() || d->hovering) {
if (isShowing() || d->hovering) {
QGraphicsItem::hoverEnterEvent(event);
return;
}
@ -529,7 +529,7 @@ void DesktopToolBox::showToolBox()
{
setFlag(ItemIgnoresTransformations, isToolbar());
if (showing() && !isToolbar()) {
if (isShowing() && !isToolbar()) {
return;
}
@ -729,7 +729,7 @@ void DesktopToolBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
//kDebug() << event->pos() << event->scenePos()
// << d->toolBacker->rect().contains(event->scenePos().toPoint());
if (!d->hovering || showing() || isToolbar()) {
if (!d->hovering || isShowing() || isToolbar()) {
QGraphicsItem::hoverLeaveEvent(event);
return;
}
@ -748,7 +748,7 @@ void DesktopToolBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void DesktopToolBox::hideToolBox()
{
if (!showing()) {
if (!isShowing()) {
return;
}
@ -796,7 +796,7 @@ void DesktopToolBox::animateHighlight(qreal progress)
void DesktopToolBox::toolMoved(QGraphicsItem *item)
{
//kDebug() << "geometry is now " << static_cast<Plasma::Widget*>(item)->geometry();
if (!showing() &&
if (!isShowing() &&
QGraphicsItem::children().indexOf(static_cast<Plasma::Applet*>(item)) != -1) {
item->hide();
}
@ -808,7 +808,7 @@ void DesktopToolBox::toggle()
return;
}
if (showing()) {
if (isShowing()) {
hideToolBox();
} else {
showToolBox();

View File

@ -27,7 +27,7 @@
#include <kicon.h>
#include <private/toolbox_p.h>
#include <private/internaltoolbox_p.h>
#include "animator.h"
@ -38,7 +38,7 @@ class Widget;
class EmptyGraphicsItem;
class DesktopToolBoxPrivate;
class DesktopToolBox : public ToolBox
class DesktopToolBox : public InternalToolBox
{
Q_OBJECT

View File

@ -18,7 +18,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "toolbox_p.h"
#include "internaltoolbox_p.h"
#include <QAction>
#include <QApplication>
@ -39,14 +39,14 @@
namespace Plasma
{
class ToolBoxPrivate
class InternalToolBoxPrivate
{
public:
ToolBoxPrivate(Containment *c)
InternalToolBoxPrivate(Containment *c)
: containment(c),
corner(InternalToolBox::TopRight),
size(50),
iconSize(KIconLoader::SizeMedium, KIconLoader::SizeMedium),
corner(ToolBox::TopRight),
hidden(false),
showing(false),
movable(false),
@ -56,9 +56,9 @@ public:
{}
Containment *containment;
InternalToolBox::Corner corner;
int size;
QSize iconSize;
ToolBox::Corner corner;
QPoint dragStartRelative;
QTransform viewTransform;
bool hidden : 1;
@ -69,27 +69,27 @@ public:
bool userMoved : 1;
};
ToolBox::ToolBox(Containment *parent)
: QGraphicsWidget(parent),
d(new ToolBoxPrivate(parent))
InternalToolBox::InternalToolBox(Containment *parent)
: AbstractToolBox(parent),
d(new InternalToolBoxPrivate(parent))
{
d->userMoved = false;
setAcceptsHoverEvents(true);
}
ToolBox::~ToolBox()
InternalToolBox::~InternalToolBox()
{
delete d;
}
Containment *ToolBox::containment()
Containment *InternalToolBox::containment()
{
return d->containment;
}
QPoint ToolBox::toolPosition(int toolHeight)
QPoint InternalToolBox::toolPosition(int toolHeight)
{
switch (d->corner) {
switch (corner()) {
case TopRight:
return QPoint(boundingRect().width(), -toolHeight);
case Top:
@ -110,7 +110,7 @@ QPoint ToolBox::toolPosition(int toolHeight)
}
}
void ToolBox::addTool(QAction *action)
void InternalToolBox::addTool(QAction *action)
{
if (!action) {
return;
@ -144,7 +144,7 @@ void ToolBox::addTool(QAction *action)
//kDebug() << "added tool" << action->text() << (QGraphicsItem*)tool;
}
void ToolBox::updateToolBox()
void InternalToolBox::updateToolBox()
{
Plasma::IconWidget *tool = qobject_cast<Plasma::IconWidget *>(sender());
if (tool && tool->action() == 0) {
@ -160,11 +160,11 @@ void ToolBox::updateToolBox()
}
}
void ToolBox::toolTriggered(bool)
void InternalToolBox::toolTriggered(bool)
{
}
void ToolBox::removeTool(QAction *action)
void InternalToolBox::removeTool(QAction *action)
{
foreach (QGraphicsItem *child, QGraphicsItem::children()) {
//kDebug() << "checking tool" << child << child->data(ToolName);
@ -177,47 +177,37 @@ void ToolBox::removeTool(QAction *action)
}
}
int ToolBox::size() const
int InternalToolBox::size() const
{
return d->size;
}
void ToolBox::setSize(const int newSize)
void InternalToolBox::setSize(const int newSize)
{
d->size = newSize;
}
QSize ToolBox::iconSize() const
QSize InternalToolBox::iconSize() const
{
return d->iconSize;
}
void ToolBox::setIconSize(const QSize newSize)
void InternalToolBox::setIconSize(const QSize newSize)
{
d->iconSize = newSize;
}
bool ToolBox::showing() const
bool InternalToolBox::isShowing() const
{
return d->showing;
}
void ToolBox::setShowing(const bool show)
void InternalToolBox::setShowing(const bool show)
{
d->showing = show;
}
void ToolBox::setCorner(const Corner corner)
{
d->corner = corner;
}
ToolBox::Corner ToolBox::corner() const
{
return d->corner;
}
void ToolBox::mousePressEvent(QGraphicsSceneMouseEvent *event)
void InternalToolBox::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
event->accept();
@ -228,22 +218,22 @@ void ToolBox::mousePressEvent(QGraphicsSceneMouseEvent *event)
}
}
QSize ToolBox::cornerSize() const
QSize InternalToolBox::cornerSize() const
{
return boundingRect().size().toSize();
}
QSize ToolBox::fullWidth() const
QSize InternalToolBox::fullWidth() const
{
return boundingRect().size().toSize();
}
QSize ToolBox::fullHeight() const
QSize InternalToolBox::fullHeight() const
{
return boundingRect().size().toSize();
}
void ToolBox::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void InternalToolBox::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (!d->movable || (!d->dragging && boundingRect().contains(event->pos())) || isToolbar()) {
return;
@ -303,7 +293,7 @@ void ToolBox::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
x = qBound(0, x, areaWidth - w);
y = qBound(0, y, areaHeight - h);
Corner newCorner = d->corner;
Corner newCorner = corner();
if (x == 0) {
if (y == 0) {
newCorner = TopLeft;
@ -334,15 +324,15 @@ void ToolBox::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
newCorner = Bottom;
}
if (newCorner != d->corner) {
if (newCorner != corner()) {
prepareGeometryChange();
d->corner = newCorner;
setCorner(newCorner);
}
setPos(x, y);
}
void ToolBox::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void InternalToolBox::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton && !d->dragging && boundingRect().contains(event->pos())) {
emit toggled();
@ -353,32 +343,42 @@ void ToolBox::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
save(cg);
}
bool ToolBox::isMovable() const
bool InternalToolBox::isMovable() const
{
return d->movable;
}
void ToolBox::setIsMovable(bool movable)
void InternalToolBox::setIsMovable(bool movable)
{
d->movable = movable;
}
bool ToolBox::isToolbar() const
bool InternalToolBox::isToolbar() const
{
return d->toolbar;
}
void ToolBox::setIsToolbar(bool toolbar)
void InternalToolBox::setIsToolbar(bool toolbar)
{
d->toolbar = toolbar;
}
QTransform ToolBox::viewTransform() const
QTransform InternalToolBox::viewTransform() const
{
return d->viewTransform;
}
void ToolBox::setViewTransform(const QTransform &transform)
void InternalToolBox::setCorner(const Corner corner)
{
d->corner = corner;
}
InternalToolBox::Corner InternalToolBox::corner() const
{
return d->corner;
}
void InternalToolBox::setViewTransform(const QTransform &transform)
{
if (transform.isScaling()) {
d->toolbar = true;
@ -392,7 +392,7 @@ void ToolBox::setViewTransform(const QTransform &transform)
d->viewTransform = transform;
}
void ToolBox::save(KConfigGroup &cg) const
void InternalToolBox::save(KConfigGroup &cg) const
{
if (!d->movable) {
return;
@ -405,19 +405,19 @@ void ToolBox::save(KConfigGroup &cg) const
}
int offset = 0;
if (d->corner == ToolBox::Left ||
d->corner == ToolBox::Right) {
if (corner() == InternalToolBox::Left ||
corner() == InternalToolBox::Right) {
offset = y();
} else if (d->corner == ToolBox::Top ||
d->corner == ToolBox::Bottom) {
} else if (corner() == InternalToolBox::Top ||
corner() == InternalToolBox::Bottom) {
offset = x();
}
group.writeEntry("corner", int(d->corner));
group.writeEntry("corner", int(corner()));
group.writeEntry("offset", offset);
}
void ToolBox::load(const KConfigGroup &containmentGroup)
void InternalToolBox::load(const KConfigGroup &containmentGroup)
{
if (!d->movable) {
return;
@ -437,32 +437,32 @@ void ToolBox::load(const KConfigGroup &containmentGroup)
}
d->userMoved = true;
d->corner = Corner(group.readEntry("corner", int(d->corner)));
setCorner(Corner(group.readEntry("corner", int(corner()))));
int offset = group.readEntry("offset", 0);
switch (d->corner) {
case ToolBox::TopLeft:
switch (corner()) {
case InternalToolBox::TopLeft:
setPos(0, 0);
break;
case ToolBox::Top:
case InternalToolBox::Top:
setPos(offset, 0);
break;
case ToolBox::TopRight:
case InternalToolBox::TopRight:
setPos(d->containment->size().width() - boundingRect().width(), 0);
break;
case ToolBox::Right:
case InternalToolBox::Right:
setPos(d->containment->size().width() - boundingRect().width(), offset);
break;
case ToolBox::BottomRight:
case InternalToolBox::BottomRight:
setPos(d->containment->size().width() - boundingRect().width(), d->containment->size().height() - boundingRect().height());
break;
case ToolBox::Bottom:
case InternalToolBox::Bottom:
setPos(offset, d->containment->size().height() - boundingRect().height());
break;
case ToolBox::BottomLeft:
case InternalToolBox::BottomLeft:
setPos(0, d->containment->size().height() - boundingRect().height());
break;
case ToolBox::Left:
case InternalToolBox::Left:
setPos(0, offset);
break;
}
@ -470,7 +470,7 @@ void ToolBox::load(const KConfigGroup &containmentGroup)
// << (d->containment->containmentType() == Containment::PanelContainment);
}
void ToolBox::reposition()
void InternalToolBox::reposition()
{
if (d->userMoved) {
//FIXME: adjust for situations like changing of the available space
@ -482,7 +482,7 @@ void ToolBox::reposition()
d->containment->containmentType() == Containment::CustomPanelContainment) {
QRectF rect = boundingRect();
if (d->containment->formFactor() == Vertical) {
setCorner(ToolBox::Bottom);
setCorner(InternalToolBox::Bottom);
setPos(d->containment->geometry().width() / 2 - rect.width() / 2,
d->containment->geometry().height() - rect.height());
} else {
@ -490,11 +490,11 @@ void ToolBox::reposition()
if (QApplication::layoutDirection() == Qt::RightToLeft) {
setPos(d->containment->geometry().left(),
d->containment->geometry().height() / 2 - rect.height() / 2);
setCorner(ToolBox::Left);
setCorner(InternalToolBox::Left);
} else {
setPos(d->containment->geometry().width() - rect.width(),
d->containment->geometry().height() / 2 - rect.height() / 2);
setCorner(ToolBox::Right);
setCorner(InternalToolBox::Right);
}
}
@ -519,33 +519,33 @@ void ToolBox::reposition()
if (QApplication::layoutDirection() == Qt::RightToLeft) {
if (avail.top() > screenGeom.top()) {
setPos(avail.topLeft() - QPoint(0, avail.top()));
setCorner(ToolBox::Left);
setCorner(InternalToolBox::Left);
} else if (avail.left() > screenGeom.left()) {
setPos(avail.topLeft() - QPoint(boundingRect().width(), 0));
setCorner(ToolBox::Top);
setCorner(InternalToolBox::Top);
} else {
setPos(avail.topLeft());
setCorner(ToolBox::TopLeft);
setCorner(InternalToolBox::TopLeft);
}
} else {
if (avail.top() > screenGeom.top()) {
setPos(avail.topRight() - QPoint(boundingRect().width(), -avail.top()));
setCorner(ToolBox::Right);
setCorner(InternalToolBox::Right);
} else if (avail.right() < screenGeom.right()) {
setPos(avail.topRight() - QPoint(boundingRect().width(), 0));
setCorner(ToolBox::Top);
setCorner(InternalToolBox::Top);
} else {
setPos(avail.topRight() - QPoint(boundingRect().width(), 0));
setCorner(ToolBox::TopRight);
setCorner(InternalToolBox::TopRight);
}
}
} else {
if (QApplication::layoutDirection() == Qt::RightToLeft) {
setPos(d->containment->mapFromScene(QPointF(d->containment->geometry().topLeft())));
setCorner(ToolBox::TopLeft);
setCorner(InternalToolBox::TopLeft);
} else {
setPos(d->containment->mapFromScene(QPointF(d->containment->geometry().topRight())));
setCorner(ToolBox::TopRight);
setCorner(InternalToolBox::TopRight);
}
}
}
@ -553,5 +553,5 @@ void ToolBox::reposition()
} // plasma namespace
#include "toolbox_p.moc"
#include "internaltoolbox_p.moc"

View File

@ -24,6 +24,7 @@
#include <QGraphicsWidget>
#include "containment.h"
#include "abstracttoolbox.h"
class QAction;
@ -34,18 +35,15 @@ namespace Plasma
//class Widget;
//class EmptyGraphicsItem;
class ToolBoxPrivate;
class InternalToolBoxPrivate;
class ToolBox : public QGraphicsWidget
class InternalToolBox : public AbstractToolBox
{
Q_OBJECT
#if QT_VERSION >= 0x040600
Q_INTERFACES(QGraphicsItem)
#endif
public:
/**
* These flags represents what borders should be drawn
*/
enum Corner {
Top = 0,
TopRight,
@ -57,8 +55,8 @@ public:
BottomLeft
};
explicit ToolBox(Containment *parent);
~ToolBox();
explicit InternalToolBox(Containment *parent);
~InternalToolBox();
/**
* create a toolbox tool from the given action
@ -73,10 +71,11 @@ public:
void setSize(const int newSize);
QSize iconSize() const;
void setIconSize(const QSize newSize);
bool showing() const;
bool isShowing() const;
void setShowing(const bool show);
void setCorner(const Corner corner);
Corner corner() const;
virtual void setCorner(const Corner corner);
virtual Corner corner() const;
bool isMovable() const;
void setIsMovable(bool movable);
@ -103,9 +102,6 @@ public Q_SLOTS:
*/
void updateToolBox();
Q_SIGNALS:
void toggled();
protected:
Containment *containment();
QPoint toolPosition(int toolHeight);
@ -117,7 +113,7 @@ protected Q_SLOTS:
virtual void toolTriggered(bool);
private:
ToolBoxPrivate *d;
InternalToolBoxPrivate *d;
};

View File

@ -60,7 +60,7 @@ public:
};
PanelToolBox::PanelToolBox(Containment *parent)
: ToolBox(parent),
: InternalToolBox(parent),
d(new PanelToolBoxPrivate)
{
connect(this, SIGNAL(toggled()), this, SLOT(toggle()));
@ -97,9 +97,9 @@ QRectF PanelToolBox::boundingRect() const
QRectF r;
//Only Left,Right and Bottom supported, default to Right
if (corner() == ToolBox::Bottom) {
if (corner() == InternalToolBox::Bottom) {
r = QRectF(0, 0, size() * 2, size());
} else if (corner() == ToolBox::Left) {
} else if (corner() == InternalToolBox::Left) {
r = QRectF(0, 0, size(), size() * 2);
} else {
r = QRectF(0, 0, size(), size() * 2);
@ -132,13 +132,13 @@ void PanelToolBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
QRectF rect = boundingRect();
QString cornerElement;
if (corner() == ToolBox::Bottom) {
if (corner() == InternalToolBox::Bottom) {
gradientCenter = QPoint(rect.center().x(), rect.bottom());
cornerElement = "panel-south";
backgroundRect = d->background->elementRect(cornerElement).toRect();
backgroundRect.moveBottomLeft(shape().boundingRect().bottomLeft().toPoint());
} else if (corner() == ToolBox::Right) {
} else if (corner() == InternalToolBox::Right) {
gradientCenter = QPoint(rect.right(), rect.center().y());
cornerElement = "panel-east";
@ -159,10 +159,10 @@ void PanelToolBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
QRect iconRect;
//Only Left,Right and Bottom supported, default to Right
if (corner() == ToolBox::Bottom) {
if (corner() == InternalToolBox::Bottom) {
iconRect = QRect(QPoint(gradientCenter.x() - iconSize().width() / 2,
(int)rect.bottom() - iconSize().height() - 2), iconSize());
} else if (corner() == ToolBox::Left) {
} else if (corner() == InternalToolBox::Left) {
iconRect = QRect(QPoint(2, gradientCenter.y() - iconSize().height() / 2), iconSize());
} else {
iconRect = QRect(QPoint((int)rect.right() - iconSize().width() + 1,
@ -190,13 +190,13 @@ QPainterPath PanelToolBox::shape() const
QRectF rect = boundingRect();
//Only Left,Right and Bottom supported, default to Right
if (corner() == ToolBox::Bottom) {
if (corner() == InternalToolBox::Bottom) {
path.moveTo(rect.bottomLeft());
path.arcTo(QRectF(rect.center().x() - toolSize,
rect.bottom() - toolSize,
toolSize * 2,
toolSize * 2), 0, 180);
} else if (corner() == ToolBox::Left) {
} else if (corner() == InternalToolBox::Left) {
path.arcTo(QRectF(rect.left(),
rect.center().y() - toolSize,
toolSize * 2,
@ -221,7 +221,7 @@ void PanelToolBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
void PanelToolBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
//kDebug() << event->pos() << event->scenePos()
if (!showing()) {
if (!isShowing()) {
highlight(false);
}
@ -242,7 +242,7 @@ void PanelToolBox::hideToolBox()
void PanelToolBox::toolTipAboutToShow()
{
if (showing()) {
if (isShowing()) {
return;
}
@ -297,8 +297,8 @@ void PanelToolBox::animate(qreal progress)
void PanelToolBox::toggle()
{
setShowing(!showing());
highlight(showing());
setShowing(!isShowing());
highlight(isShowing());
}
} // plasma namespace

View File

@ -27,7 +27,7 @@
#include <kicon.h>
#include <private/toolbox_p.h>
#include <private/internaltoolbox_p.h>
#include "animator.h"
@ -38,7 +38,7 @@ class Widget;
class EmptyGraphicsItem;
class PanelToolBoxPrivate;
class PanelToolBox : public ToolBox
class PanelToolBox : public InternalToolBox
{
Q_OBJECT