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/serviceprovider.cpp
private/style.cpp private/style.cpp
private/trustedonlyauthorization.cpp private/trustedonlyauthorization.cpp
private/toolbox.cpp private/internaltoolbox.cpp
private/tooltip.cpp private/tooltip.cpp
private/wallpaperrenderthread.cpp private/wallpaperrenderthread.cpp
private/windowpreview.cpp private/windowpreview.cpp
@ -121,6 +121,7 @@ set(plasma_LIB_SRCS
servicejob.cpp servicejob.cpp
svg.cpp svg.cpp
theme.cpp theme.cpp
abstracttoolbox.cpp
tooltipcontent.cpp tooltipcontent.cpp
tooltipmanager.cpp tooltipmanager.cpp
version.cpp version.cpp
@ -287,6 +288,7 @@ set(plasma_LIB_INCLUDES
servicejob.h servicejob.h
svg.h svg.h
theme.h theme.h
abstracttoolbox.h
tooltipcontent.h tooltipcontent.h
tooltipmanager.h tooltipmanager.h
version.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/popupapplet_p.h"
#include "private/service_p.h" #include "private/service_p.h"
#include "private/remotedataengine.h" #include "private/remotedataengine.h"
#include "private/toolbox_p.h" #include "private/internaltoolbox_p.h"
#include "private/associatedapplicationmanager_p.h" #include "private/associatedapplicationmanager_p.h"
#include "ui_publish.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 //update the view transform of the toolbox, since it ignores transforms
if (v && c && c->d->toolBox) { 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(); c->d->positionToolBox();
} }
if (v) { if (toolBox && v) {
c->d->toolBox->setViewTransform(v->transform()); toolBox->setViewTransform(v->transform());
} }
} }

View File

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

View File

@ -50,6 +50,7 @@ class View;
class Wallpaper; class Wallpaper;
class ContainmentActions; class ContainmentActions;
class ContainmentPrivate; class ContainmentPrivate;
class AbstractToolBox;
/** /**
* @class Containment plasma/containment.h <Plasma/Containment> * @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 * @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: private:
Q_PRIVATE_SLOT(d, void appletDestroyed(Plasma::Applet*)) Q_PRIVATE_SLOT(d, void appletDestroyed(Plasma::Applet*))

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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