mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
plasma: drop extender support
unused Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
386f894043
commit
6635f1d35d
27 changed files with 8 additions and 4079 deletions
|
@ -428,9 +428,6 @@ install(
|
|||
Plasma/Delegate
|
||||
Plasma/Dialog
|
||||
Plasma/DialogShadows
|
||||
Plasma/Extender
|
||||
Plasma/ExtenderGroup
|
||||
Plasma/ExtenderItem
|
||||
Plasma/FlashingLabel
|
||||
Plasma/Frame
|
||||
Plasma/FrameSvg
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
#include "../../plasma/extender.h"
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
#include "../../plasma/extendergroup.h"
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
#include "../../plasma/extenderitem.h"
|
||||
|
|
@ -3,7 +3,6 @@ include_directories(
|
|||
${KDE4_KDECORE_INCLUDES}
|
||||
${KDE4_KDEUI_INCLUDES}
|
||||
${KDE4_KIO_INCLUDES}
|
||||
${CMAKE_SOURCE_DIR}/plasma/extenders
|
||||
# for the export headers
|
||||
${CMAKE_BINARY_DIR}/kutils
|
||||
)
|
||||
|
@ -39,17 +38,12 @@ set(plasma_LIB_SRCS
|
|||
delegate.cpp
|
||||
dialog.cpp
|
||||
dialogshadows.cpp
|
||||
extenders/extender.cpp
|
||||
extenders/extendergroup.cpp
|
||||
extenders/extenderitem.cpp
|
||||
paintutils.cpp
|
||||
framesvg.cpp
|
||||
plasma.cpp
|
||||
popupapplet.cpp
|
||||
private/applethandle.cpp
|
||||
private/associatedapplicationmanager.cpp
|
||||
private/extenderapplet.cpp
|
||||
private/extenderitemmimedata.cpp
|
||||
private/nativetabbar.cpp
|
||||
private/packages.cpp
|
||||
private/runnerjobs.cpp
|
||||
|
@ -151,9 +145,6 @@ install(
|
|||
delegate.h
|
||||
dialog.h
|
||||
dialogshadows.h
|
||||
extenders/extender.h
|
||||
extenders/extendergroup.h
|
||||
extenders/extenderitem.h
|
||||
paintutils.h
|
||||
windoweffects.h
|
||||
framesvg.h
|
||||
|
@ -223,9 +214,3 @@ install(
|
|||
DESTINATION ${KDE4_SERVICETYPES_INSTALL_DIR}
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
data/services/plasma-applet-extenderapplet.desktop
|
||||
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
|
||||
)
|
||||
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
#include "containment.h"
|
||||
#include "corona.h"
|
||||
#include "dialog.h"
|
||||
#include "extenders/extender.h"
|
||||
#include "extenders/extenderitem.h"
|
||||
#include "package.h"
|
||||
#include "plasma.h"
|
||||
#include "svg.h"
|
||||
|
@ -44,11 +42,9 @@
|
|||
#include "animations/animation.h"
|
||||
#include "private/applet_p.h"
|
||||
#include "private/applethandle_p.h"
|
||||
#include "private/extenderitem_p.h"
|
||||
#include "private/framesvg_p.h"
|
||||
#include "private/associatedapplicationmanager_p.h"
|
||||
#include "private/containment_p.h"
|
||||
#include "private/extenderapplet_p.h"
|
||||
#include "private/package_p.h"
|
||||
#include "private/packages_p.h"
|
||||
#include "private/popupapplet_p.h"
|
||||
|
@ -170,23 +166,6 @@ Applet::~Applet()
|
|||
//let people know that i will die
|
||||
emit appletDestroyed(this);
|
||||
|
||||
if (!d->transient && d->extender) {
|
||||
//This would probably be nicer if it was located in extender. But in it's dtor, this won't
|
||||
//work since when that get's called, the applet's config() isn't accessible anymore. (same
|
||||
//problem with calling saveState(). Doing this in saveState() might be a possibility, but
|
||||
//that would require every extender savestate implementation to call it's parent function,
|
||||
//which isn't very nice.
|
||||
d->extender.data()->saveState();
|
||||
|
||||
foreach (ExtenderItem *item, d->extender.data()->attachedItems()) {
|
||||
if (item->autoExpireDelay()) {
|
||||
//destroy temporary extender items, or items that aren't detached, so their
|
||||
//configuration won't linger after a plasma restart.
|
||||
item->destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// clean up our config dialog, if any
|
||||
delete KConfigDialog::exists(d->configDialogId());
|
||||
delete d;
|
||||
|
@ -500,8 +479,7 @@ void AppletPrivate::createMessageOverlay(bool usePopup)
|
|||
messageOverlayProxy = new QGraphicsProxyWidget(q);
|
||||
messageOverlayProxy->setWidget(popup->widget());
|
||||
messageOverlay = new AppletOverlayWidget(messageOverlayProxy);
|
||||
} else if (popup->graphicsWidget() &&
|
||||
popup->graphicsWidget() != extender.data()) {
|
||||
} else if (popup->graphicsWidget()) {
|
||||
messageOverlay = new AppletOverlayWidget(popup->graphicsWidget());
|
||||
}
|
||||
}
|
||||
|
@ -528,7 +506,7 @@ void AppletPrivate::positionMessageOverlay()
|
|||
// popupapplet with widget()
|
||||
topItem = popup->d->proxy.data();
|
||||
messageOverlay->setGeometry(popup->widget()->contentsRect());
|
||||
} else if (usePopup && popup->graphicsWidget() && popup->graphicsWidget() != extender.data()) {
|
||||
} else if (usePopup && popup->graphicsWidget()) {
|
||||
// popupapplet with graphicsWidget()
|
||||
topItem = popup->graphicsWidget();
|
||||
QGraphicsWidget *w = dynamic_cast<QGraphicsWidget *>(topItem);
|
||||
|
@ -662,24 +640,6 @@ void Applet::constraintsEvent(Plasma::Constraints constraints)
|
|||
// << ", Location: " << location();
|
||||
}
|
||||
|
||||
void Applet::initExtenderItem(ExtenderItem *item)
|
||||
{
|
||||
kWarning() << "Missing implementation of initExtenderItem in the applet "
|
||||
<< item->config().readEntry("SourceAppletPluginName", "")
|
||||
<< "!\n Any applet that uses extenders should implement initExtenderItem to "
|
||||
<< "instantiate a widget. Destroying the item...";
|
||||
item->destroy();
|
||||
}
|
||||
|
||||
Extender *Applet::extender() const
|
||||
{
|
||||
if (!d->extender) {
|
||||
new Extender(const_cast<Applet*>(this));
|
||||
}
|
||||
|
||||
return d->extender.data();
|
||||
}
|
||||
|
||||
void Applet::setBusy(bool busy)
|
||||
{
|
||||
if (busy) {
|
||||
|
@ -1143,12 +1103,6 @@ void Applet::flushPendingConstraintsEvents()
|
|||
action->setEnabled(unlocked);
|
||||
}
|
||||
|
||||
if (d->extender) {
|
||||
foreach (ExtenderItem *item, d->extender.data()->attachedItems()) {
|
||||
item->d->setMovable(unlocked);
|
||||
}
|
||||
}
|
||||
|
||||
if (!unlocked && d->handle) {
|
||||
AppletHandle *h = d->handle.data();
|
||||
disconnect(this);
|
||||
|
@ -2074,13 +2028,8 @@ Applet *Applet::load(const QString &appletName, uint appletId, const QVariantLis
|
|||
QVariantList allArgs;
|
||||
allArgs << offer->storageId() << appletId << args;
|
||||
|
||||
Applet* applet = nullptr;
|
||||
QString error;
|
||||
if (appletName == "internal:extender") {
|
||||
applet = new ExtenderApplet(nullptr, allArgs);
|
||||
} else {
|
||||
applet = offer->createInstance<Plasma::Applet>(nullptr, allArgs, &error);
|
||||
}
|
||||
Applet* applet = offer->createInstance<Plasma::Applet>(nullptr, allArgs, &error);
|
||||
|
||||
if (!applet) {
|
||||
kWarning() << "Could not load applet" << appletName << "! reason given:" << error;
|
||||
|
@ -2332,8 +2281,6 @@ AppletPrivate::AppletPrivate(KService::Ptr service, const KPluginInfo *info, int
|
|||
|
||||
AppletPrivate::~AppletPrivate()
|
||||
{
|
||||
delete extender.data();
|
||||
|
||||
delete mainConfig;
|
||||
mainConfig = 0;
|
||||
delete modificationsTimer;
|
||||
|
|
|
@ -47,8 +47,6 @@ namespace Plasma
|
|||
class AppletPrivate;
|
||||
class Containment;
|
||||
class Context;
|
||||
class Extender;
|
||||
class ExtenderItem;
|
||||
|
||||
/**
|
||||
* @class Applet plasma/applet.h <Plasma/Applet>
|
||||
|
@ -486,24 +484,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||
*/
|
||||
virtual void removeAssociatedWidget(QWidget *widget);
|
||||
|
||||
/**
|
||||
* Gets called when an extender item has to be initialized after a plasma restart. If you
|
||||
* create ExtenderItems in your applet, you should implement this function to again create
|
||||
* the widget that should be shown in this extender item. This function might look something
|
||||
* like this:
|
||||
*
|
||||
* @code
|
||||
* SuperCoolWidget *widget = new SuperCoolWidget();
|
||||
* item->setWidget(widget);
|
||||
* @endcode
|
||||
*
|
||||
* You can also add one or more custom qactions to this extender item in this function.
|
||||
*
|
||||
* Note that by default, not all ExtenderItems are persistent. Only items that are detached,
|
||||
* will have their configuration stored when plasma exits.
|
||||
*/
|
||||
virtual void initExtenderItem(ExtenderItem *item);
|
||||
|
||||
/**
|
||||
* @param parent the QGraphicsItem this applet is parented to
|
||||
* @param serviceId the name of the .desktop file containing the
|
||||
|
@ -903,11 +883,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||
*/
|
||||
bool isRegisteredAsDragHandle(QGraphicsItem *item);
|
||||
|
||||
/**
|
||||
* @return the extender of this applet.
|
||||
*/
|
||||
Extender *extender() const;
|
||||
|
||||
/**
|
||||
* @internal scene event filter; used to manage applet dragging
|
||||
*/
|
||||
|
@ -973,12 +948,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||
friend class PopupApplet;
|
||||
friend class PopupAppletPrivate;
|
||||
friend class AssociatedApplicationManager;
|
||||
|
||||
friend class Extender;
|
||||
friend class ExtenderGroup;
|
||||
friend class ExtenderGroupPrivate;
|
||||
friend class ExtenderPrivate;
|
||||
friend class ExtenderItem;
|
||||
};
|
||||
|
||||
} // Plasma namespace
|
||||
|
|
|
@ -26,14 +26,10 @@
|
|||
#include "containmentactions.h"
|
||||
#include "containmentactionspluginsconfig.h"
|
||||
#include "corona.h"
|
||||
#include "extender.h"
|
||||
#include "extenderitem.h"
|
||||
#include "svg.h"
|
||||
#include "wallpaper.h"
|
||||
#include "private/applet_p.h"
|
||||
#include "private/containmentactionspluginsconfig_p.h"
|
||||
#include "private/extenderitemmimedata_p.h"
|
||||
#include "private/extenderapplet_p.h"
|
||||
#include "private/wallpaper_p.h"
|
||||
#include "plasma/plasma.h"
|
||||
#include "animations/animation.h"
|
||||
|
@ -1090,8 +1086,7 @@ void Containment::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
|
|||
{
|
||||
event->setAccepted(immutability() == Mutable &&
|
||||
(event->mimeData()->hasFormat(static_cast<Corona*>(scene())->appletMimeType()) ||
|
||||
KUrl::List::canDecode(event->mimeData()) ||
|
||||
event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())));
|
||||
KUrl::List::canDecode(event->mimeData())));
|
||||
//kDebug() << immutability() << Mutable << (immutability() == Mutable) << event->isAccepted();
|
||||
|
||||
if (!event->isAccepted()) {
|
||||
|
@ -1215,32 +1210,6 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
|
|||
if (dropEvent) {
|
||||
dropEvent->acceptProposedAction();
|
||||
}
|
||||
} else if (mimeData->hasFormat(ExtenderItemMimeData::mimeType())) {
|
||||
kDebug() << "mimetype plasma/extenderitem is dropped, creating internal:extender";
|
||||
//Handle dropping extenderitems.
|
||||
const ExtenderItemMimeData *extenderData = qobject_cast<const ExtenderItemMimeData*>(mimeData);
|
||||
if (extenderData) {
|
||||
ExtenderItem *item = extenderData->extenderItem();
|
||||
QRectF geometry(pos - extenderData->pointerOffset(), item->size());
|
||||
kDebug() << "desired geometry: " << geometry;
|
||||
Applet *applet = qobject_cast<ExtenderApplet *>(item->extender() ? item->extender()->applet() : 0);
|
||||
if (applet) {
|
||||
qreal left, top, right, bottom;
|
||||
applet->getContentsMargins(&left, &top, &right, &bottom);
|
||||
applet->setPos(geometry.topLeft() - QPointF(int(left), int(top)));
|
||||
applet->show();
|
||||
} else {
|
||||
applet = addApplet("internal:extender", QVariantList(), geometry, 0, true);
|
||||
applet->hide();
|
||||
applet->init();
|
||||
appletAppeared(applet);
|
||||
applet->flushPendingConstraintsEvents();
|
||||
applet->d->scheduleModificationNotification();
|
||||
applet->adjustSize();
|
||||
applet->show();
|
||||
}
|
||||
item->setExtender(applet->extender());
|
||||
}
|
||||
} else if (KUrl::List::canDecode(mimeData)) {
|
||||
foreach (const KUrl &url, KUrl::List::fromMimeData(mimeData)) {
|
||||
QRectF geom(pos, QSize());
|
||||
|
|
|
@ -1,85 +0,0 @@
|
|||
[Desktop Entry]
|
||||
Name=Collection
|
||||
Name[ar]=المجموعة
|
||||
Name[ast]=Coleición
|
||||
Name[be@latin]=Zbor
|
||||
Name[bg]=Колекция
|
||||
Name[bn]=সংকলন
|
||||
Name[bs]=Kolekcija
|
||||
Name[ca]=Col·lecció
|
||||
Name[ca@valencia]=Col·lecció
|
||||
Name[cs]=Sbírka
|
||||
Name[csb]=Kòlekcëjô
|
||||
Name[da]=Samling
|
||||
Name[de]=Sammlung
|
||||
Name[el]=Συλλογή
|
||||
Name[en_GB]=Collection
|
||||
Name[eo]=Kolekto
|
||||
Name[es]=Colección
|
||||
Name[et]=Kollektsioon
|
||||
Name[eu]=Bilduma
|
||||
Name[fa]=مجموعه
|
||||
Name[fi]=Kokoelma
|
||||
Name[fr]=Collection
|
||||
Name[fy]=Kolleksje
|
||||
Name[ga]=Bailiúchán
|
||||
Name[gl]=Colección
|
||||
Name[gu]=ભંડોળ
|
||||
Name[he]=אוסף
|
||||
Name[hi]=शब्द पूर्णता
|
||||
Name[hr]=Kolekcija
|
||||
Name[hu]=Gyűjtemény
|
||||
Name[hy]=Հավաքածու
|
||||
Name[ia]=Collection
|
||||
Name[id]=Koleksi
|
||||
Name[is]=Safn
|
||||
Name[it]=Collezione
|
||||
Name[ja]=コレクション
|
||||
Name[kk]=Collection
|
||||
Name[km]=សម្រាំង
|
||||
Name[kn]=ಸಮೂಹ
|
||||
Name[ko]=모음집
|
||||
Name[ku]=Berhevok
|
||||
Name[lt]=Rinkinys
|
||||
Name[lv]=Kolekcija
|
||||
Name[ml]=കൂട്ടം
|
||||
Name[mr]=संग्रह
|
||||
Name[ms]=Koleksi
|
||||
Name[nb]=Samling
|
||||
Name[nds]=Sammeln
|
||||
Name[nl]=Verzameling
|
||||
Name[nn]=Samling
|
||||
Name[pa]=ਭੰਡਾਰ
|
||||
Name[pl]=Kolekcja
|
||||
Name[pt]=Colecção
|
||||
Name[pt_BR]=Coleção
|
||||
Name[ro]=Colecție
|
||||
Name[ru]=Коллекция
|
||||
Name[se]=Čoahkádus
|
||||
Name[si]=එකතුව
|
||||
Name[sk]=Kolekcia
|
||||
Name[sl]=Zbirka
|
||||
Name[sq]=Koleksioni
|
||||
Name[sr]=збирка
|
||||
Name[sr@ijekavian]=збирка
|
||||
Name[sr@ijekavianlatin]=zbirka
|
||||
Name[sr@latin]=zbirka
|
||||
Name[sv]=Samling
|
||||
Name[ta]=சேகரங்கள்
|
||||
Name[tg]=Коллексия
|
||||
Name[th]=ชุดสะสม
|
||||
Name[tr]=Koleksiyon
|
||||
Name[tt]=Коллекция
|
||||
Name[ug]=توپلام
|
||||
Name[uk]=Збірка
|
||||
Name[vi]=Bộ sưu tập
|
||||
Name[wa]=Ramexhnêye
|
||||
Name[x-test]=xxCollectionxx
|
||||
Name[zh_CN]=收藏
|
||||
Name[zh_TW]=收藏
|
||||
Type=Service
|
||||
Icon=utilities-desktop-extra
|
||||
NoDisplay=true
|
||||
X-KDE-ServiceTypes=Plasma/Applet
|
||||
X-KDE-PluginInfo-Name=internal:extender
|
||||
X-KDE-PluginInfo-EnabledByDefault=false
|
|
@ -43,8 +43,6 @@
|
|||
#include "plasma/animator.h"
|
||||
#include "plasma/containment.h"
|
||||
#include "plasma/corona.h"
|
||||
#include "plasma/extenders/extender.h"
|
||||
#include "plasma/private/extender_p.h"
|
||||
#include "plasma/framesvg.h"
|
||||
#include "plasma/theme.h"
|
||||
#include "plasma/widgets/scrollwidget.h"
|
||||
|
@ -122,8 +120,6 @@ void DialogPrivate::checkBorders(bool updateMaskIfNeeded)
|
|||
QGraphicsWidget *graphicsWidget = graphicsWidgetPtr.data();
|
||||
const FrameSvg::EnabledBorders currentBorders = background->enabledBorders();
|
||||
FrameSvg::EnabledBorders borders = FrameSvg::AllBorders;
|
||||
|
||||
Extender *extender = qobject_cast<Extender*>(graphicsWidget);
|
||||
Plasma::Applet *applet = appletPtr.data();
|
||||
|
||||
//used to remove borders at the edge of the desktop
|
||||
|
@ -223,30 +219,7 @@ void DialogPrivate::checkBorders(bool updateMaskIfNeeded)
|
|||
|
||||
background->setEnabledBorders(borders);
|
||||
dialogshadows->addWindow(q, borders);
|
||||
|
||||
if (extender) {
|
||||
FrameSvg::EnabledBorders disabledBorders = FrameSvg::NoBorder;
|
||||
if (!(borders & FrameSvg::LeftBorder)) {
|
||||
disabledBorders |= FrameSvg::LeftBorder;
|
||||
}
|
||||
if (!(borders & FrameSvg::RightBorder)) {
|
||||
disabledBorders |= FrameSvg::RightBorder;
|
||||
}
|
||||
extender->d->setDisabledBordersHint(disabledBorders);
|
||||
|
||||
//if there is a scrollbar, reserve a margin to not draw it over the shadow
|
||||
qreal left, top, right, bottom;
|
||||
background->getMargins(left, top, right, bottom);
|
||||
if (extender->d->scrollWidget->viewportGeometry().height() < extender->d->scrollWidget->contentsSize().height()) {
|
||||
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
||||
leftWidth = left;
|
||||
} else {
|
||||
rightWidth = right;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
background->getMargins(leftWidth, topHeight, rightWidth, bottomHeight);
|
||||
}
|
||||
|
||||
//kDebug() << leftWidth << topHeight << rightWidth << bottomHeight;
|
||||
q->setContentsMargins(leftWidth, topHeight, rightWidth, bottomHeight);
|
||||
|
|
|
@ -1,948 +0,0 @@
|
|||
/*
|
||||
* Copyright 2008, 2009 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "extender.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QDesktopWidget>
|
||||
#include <QLabel>
|
||||
#include <QtGui/qgraphicssceneevent.h>
|
||||
#include <QGraphicsGridLayout>
|
||||
#include <QGraphicsLinearLayout>
|
||||
#include <QPainter>
|
||||
|
||||
#include <kdebug.h>
|
||||
|
||||
#include "applet.h"
|
||||
#include "containment.h"
|
||||
#include "corona.h"
|
||||
#include "dialog.h"
|
||||
#include "extendergroup.h"
|
||||
#include "extenderitem.h"
|
||||
#include "framesvg.h"
|
||||
#include "paintutils.h"
|
||||
#include "popupapplet.h"
|
||||
#include "svg.h"
|
||||
#include "theme.h"
|
||||
#include "widgets/label.h"
|
||||
#include "widgets/scrollwidget.h"
|
||||
|
||||
#include "private/applet_p.h"
|
||||
#include "private/applethandle_p.h"
|
||||
#include "private/extender_p.h"
|
||||
#include "private/extenderapplet_p.h"
|
||||
#include "private/extenderitem_p.h"
|
||||
#include "private/extenderitemmimedata_p.h"
|
||||
#include "private/popupapplet_p.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
Spacer::Spacer(QGraphicsItem *parent)
|
||||
: QGraphicsWidget(parent)
|
||||
{
|
||||
}
|
||||
|
||||
Spacer::~Spacer()
|
||||
{
|
||||
}
|
||||
|
||||
void Spacer::setMargins(qreal left, qreal top, qreal right, qreal bottom)
|
||||
{
|
||||
m_left = left;
|
||||
m_top = top;
|
||||
m_right = right;
|
||||
m_bottom = bottom;
|
||||
}
|
||||
|
||||
|
||||
void Spacer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
QPainterPath p = Plasma::PaintUtils::roundedRectangle(
|
||||
contentsRect().adjusted(m_left, m_top, -m_right, -m_bottom), 4);
|
||||
|
||||
QColor c = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
|
||||
c.setAlphaF(0.3);
|
||||
painter->fillPath(p, c);
|
||||
}
|
||||
|
||||
|
||||
Extender::Extender(Applet *applet)
|
||||
: QGraphicsWidget(applet),
|
||||
d(new ExtenderPrivate(applet, this))
|
||||
{
|
||||
//At multiple places in the extender code, we make the assumption that an applet doesn't have
|
||||
//more then one extender. If a second extender is created, destroy the first one to avoid leaks.
|
||||
if (applet->d->extender) {
|
||||
kWarning() << "Applet already has an extender, and can have only one extender."
|
||||
<< "The previous extender will be destroyed.";
|
||||
delete applet->d->extender.data();
|
||||
} else if (PopupApplet *popup = qobject_cast<PopupApplet *>(applet)) {
|
||||
if (!popup->d->graphicsWidget) {
|
||||
// ensure the popup gets a dialog with us as the graphics widget
|
||||
popup->d->popupConstraintsEvent(SizeConstraint);
|
||||
}
|
||||
}
|
||||
|
||||
applet->d->extender = this;
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
d->scrollWidget = new ScrollWidget(this);
|
||||
d->scrollWidget->setOverflowBordersVisible(false);
|
||||
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(QRectF)),
|
||||
this, SLOT(viewportGeometryChanged(QRectF)));
|
||||
|
||||
d->layout = new QGraphicsLinearLayout(d->mainWidget);
|
||||
d->layout->setOrientation(Qt::Vertical);
|
||||
d->layout->setContentsMargins(0, 0, 0, 0);
|
||||
d->layout->setSpacing(0);
|
||||
|
||||
|
||||
QGraphicsLinearLayout *lay = new QGraphicsLinearLayout(Qt::Vertical, this);
|
||||
lay->addItem(d->scrollWidget);
|
||||
setContentsMargins(0, 0, 0, 0);
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
d->loadExtenderItems();
|
||||
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
Extender::~Extender()
|
||||
{
|
||||
d->destroying = true;
|
||||
|
||||
// when deleting items that are connected to us, it can happen that
|
||||
// other items which are in groups may get deleted as well. so we first
|
||||
// build a new list of guarded pointers, and then use that list. that
|
||||
// way when items are deleted behind our back, we are still safe.
|
||||
// FIXME: having groups and items in the same collection is probably a mistake,
|
||||
// so would be a good candidate for a refactoring exercise
|
||||
QList<QWeakPointer<ExtenderItem> > guardedItems;
|
||||
|
||||
foreach (ExtenderItem *item, d->attachedExtenderItems) {
|
||||
guardedItems << QWeakPointer<ExtenderItem>(item);
|
||||
}
|
||||
|
||||
d->attachedExtenderItems.clear();
|
||||
|
||||
foreach (const QWeakPointer<ExtenderItem> &guardedItem, guardedItems) {
|
||||
ExtenderItem *item = guardedItem.data();
|
||||
if (item) {
|
||||
item->disconnect(this);
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
delete d;
|
||||
}
|
||||
|
||||
void Extender::setEmptyExtenderMessage(const QString &message)
|
||||
{
|
||||
d->emptyExtenderMessage = message;
|
||||
|
||||
if (d->emptyExtenderLabel) {
|
||||
d->emptyExtenderLabel->setText(message);
|
||||
}
|
||||
}
|
||||
|
||||
QString Extender::emptyExtenderMessage() const
|
||||
{
|
||||
return d->emptyExtenderMessage;
|
||||
}
|
||||
|
||||
QList<ExtenderItem*> Extender::items() const
|
||||
{
|
||||
QList<ExtenderItem*> result;
|
||||
|
||||
//FIXME: a triple nested loop ... ew. there should be a more efficient way to do this
|
||||
//iterate through all extenders we can find and check each extenders source applet.
|
||||
if (!d->applet) {
|
||||
return QList<ExtenderItem*>();
|
||||
}
|
||||
|
||||
Containment *containment = d->applet.data()->containment();
|
||||
if (!containment) {
|
||||
return result;
|
||||
}
|
||||
|
||||
foreach (Containment *c, containment->corona()->containments()) {
|
||||
foreach (Applet *applet, c->applets()) {
|
||||
if (applet->d->extender) {
|
||||
foreach (ExtenderItem *item, applet->d->extender.data()->d->attachedExtenderItems) {
|
||||
if (item->d->sourceApplet == d->applet.data()) {
|
||||
result.append(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QList<ExtenderItem*> Extender::attachedItems() const
|
||||
{
|
||||
return d->attachedExtenderItems;
|
||||
}
|
||||
|
||||
QList<ExtenderItem*> Extender::detachedItems() const
|
||||
{
|
||||
QList<ExtenderItem*> result;
|
||||
|
||||
//FIXME: a triple nested loop ... ew. there should be a more efficient way to do this
|
||||
//iterate through all extenders we can find and check each extenders source applet.
|
||||
if (!d->applet) {
|
||||
return QList<ExtenderItem*>();
|
||||
}
|
||||
Containment *containment = d->applet.data()->containment();
|
||||
if (!containment) {
|
||||
return result;
|
||||
}
|
||||
|
||||
foreach (Containment *c, containment->corona()->containments()) {
|
||||
foreach (Applet *applet, c->applets()) {
|
||||
if (applet->d->extender) {
|
||||
foreach (ExtenderItem *item, applet->d->extender.data()->attachedItems()) {
|
||||
if (item->d->sourceApplet == d->applet.data() && item->isDetached()) {
|
||||
result.append(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ExtenderItem *Extender::item(const QString &name) const
|
||||
{
|
||||
// chances are the item is in our own extender, so check there first
|
||||
foreach (ExtenderItem *item, d->attachedExtenderItems) {
|
||||
if (item->d->sourceApplet == d->applet.data() && item->name() == name) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
// maybe it's been moved elsewhere, so lets search through the entire tree of elements
|
||||
//FIXME: a triple nested loop ... ew. there should be a more efficient way to do this
|
||||
//iterate through all extenders we can find and check each extenders source applet.
|
||||
if (!d->applet) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Containment *containment = d->applet.data()->containment();
|
||||
if (!containment) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
QList<Containment *> containments;
|
||||
if (containment->corona()) {
|
||||
containments = containment->corona()->containments();
|
||||
} else {
|
||||
containments << containment;
|
||||
}
|
||||
|
||||
foreach (const Containment *c, containments) {
|
||||
foreach (const Applet *applet, c->applets()) {
|
||||
if (applet->d->extender) {
|
||||
if (applet->d->extender.data() == this) {
|
||||
// skip it, we checked it already
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!applet->d->extender) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (ExtenderItem *item, applet->d->extender.data()->attachedItems()) {
|
||||
if (item->d->sourceApplet == d->applet.data() && item->name() == name) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ExtenderGroup *Extender::group(const QString &name) const
|
||||
{
|
||||
return qobject_cast<ExtenderGroup*>(item(name));
|
||||
}
|
||||
|
||||
bool Extender::hasItem(const QString &name) const
|
||||
{
|
||||
if (item(name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!d->applet) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//if item(name) returns false, that doesn't mean that the item doesn't exist, just that it has
|
||||
//not been instantiated yet. check to see if there's mention of this item existing in the
|
||||
//plasma config's section DetachedExtenderItems
|
||||
Corona *corona = qobject_cast<Corona *>(scene());
|
||||
if (!corona) {
|
||||
return false;
|
||||
}
|
||||
|
||||
KConfigGroup extenderItemGroup(corona->config(), "DetachedExtenderItems");
|
||||
foreach (const QString &extenderItemId, extenderItemGroup.groupList()) {
|
||||
KConfigGroup cg = extenderItemGroup.group(extenderItemId);
|
||||
if (uint(cg.readEntry("sourceAppletId", 0)) == d->applet.data()->id() &&
|
||||
cg.readEntry("extenderItemName", "") == name &&
|
||||
cg.readEntry("sourceAppletPluginName", "") == d->applet.data()->pluginName()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Extender::setAppearance(Appearance appearance)
|
||||
{
|
||||
if (d->appearance == appearance) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->appearance = appearance;
|
||||
d->updateBorders();
|
||||
}
|
||||
|
||||
Extender::Appearance Extender::appearance() const
|
||||
{
|
||||
return d->appearance;
|
||||
}
|
||||
|
||||
QList<ExtenderGroup*> Extender::groups() const
|
||||
{
|
||||
QList<ExtenderGroup *> result;
|
||||
foreach (ExtenderItem *item, d->attachedExtenderItems) {
|
||||
if (item->isGroup() && !result.contains(item->group())) {
|
||||
ExtenderGroup *group = qobject_cast<ExtenderGroup *>(item);
|
||||
if (group) {
|
||||
result.append(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Applet *Extender::applet() const
|
||||
{
|
||||
return d->applet.data();
|
||||
}
|
||||
|
||||
void Extender::saveState()
|
||||
{
|
||||
foreach (ExtenderItem *item, attachedItems()) {
|
||||
item->config().writeEntry("extenderItemPosition", item->geometry().y());
|
||||
}
|
||||
}
|
||||
|
||||
QVariant Extender::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
if (change == QGraphicsItem::ItemPositionHasChanged) {
|
||||
emit geometryChanged();
|
||||
}
|
||||
|
||||
return QGraphicsWidget::itemChange(change, value);
|
||||
}
|
||||
|
||||
void Extender::resizeEvent(QGraphicsSceneResizeEvent *event)
|
||||
{
|
||||
QGraphicsWidget::resizeEvent(event);
|
||||
emit geometryChanged();
|
||||
}
|
||||
|
||||
void Extender::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
if (!d->applet) {
|
||||
return;
|
||||
}
|
||||
|
||||
PopupApplet *popupApplet = qobject_cast<PopupApplet*>(d->applet.data());
|
||||
if (isEmpty() && popupApplet) {
|
||||
popupApplet->hidePopup();
|
||||
}
|
||||
}
|
||||
|
||||
void Extender::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
|
||||
event->accept();
|
||||
|
||||
const ExtenderItemMimeData *mimeData =
|
||||
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
|
||||
|
||||
if (mimeData) {
|
||||
itemHoverEnterEvent(mimeData->extenderItem());
|
||||
|
||||
PopupApplet *popupApplet = qobject_cast<PopupApplet*>(d->applet.data());
|
||||
if (popupApplet) {
|
||||
popupApplet->showPopup();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Extender::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
|
||||
const ExtenderItemMimeData *mimeData =
|
||||
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
|
||||
|
||||
if (mimeData) {
|
||||
itemHoverMoveEvent(mimeData->extenderItem(), event->pos());
|
||||
|
||||
d->setPositionFromDragPosition(event->scenePos());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Extender::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
|
||||
const ExtenderItemMimeData *mimeData =
|
||||
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
|
||||
|
||||
if (mimeData) {
|
||||
itemHoverLeaveEvent(mimeData->extenderItem());
|
||||
|
||||
//Some logic to conveniently show/hide popups or applets when logical.
|
||||
Extender *sourceExtender = mimeData->extenderItem()->d->extender;
|
||||
|
||||
//Hide popups when they're not the extender where we started, and we're leaving the
|
||||
//extender. Use a small timeout here, to avoid accidental hides of extenders we're
|
||||
//targetting.
|
||||
PopupApplet *popupApplet = qobject_cast<PopupApplet*>(d->applet.data());
|
||||
if (popupApplet && sourceExtender != this) {
|
||||
kDebug() << "leaving another extender then the extender we started, so hide the popup.";
|
||||
popupApplet->showPopup(250);
|
||||
}
|
||||
|
||||
//Hide popups when we drag the last item away.
|
||||
if (popupApplet && sourceExtender == this && (attachedItems().count() < 2)) {
|
||||
kDebug() << "leaving the extender, and there are no more attached items so hide the popup.";
|
||||
popupApplet->hidePopup();
|
||||
}
|
||||
|
||||
//Hide empty internal extender containers when we drag the last item away. Avoids having
|
||||
//an ugly empty applet on the desktop temporarily.
|
||||
ExtenderApplet *extenderApplet = qobject_cast<ExtenderApplet*>(d->applet.data());
|
||||
if (extenderApplet && sourceExtender == this && attachedItems().count() < 2 &&
|
||||
extenderApplet->formFactor() != Plasma::Horizontal &&
|
||||
extenderApplet->formFactor() != Plasma::Vertical) {
|
||||
kDebug() << "leaving the internal extender container, so hide the applet and it's handle.";
|
||||
extenderApplet->hide();
|
||||
AppletHandle *handle = dynamic_cast<AppletHandle*>(extenderApplet->parentItem());
|
||||
if (handle) {
|
||||
handle->hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Extender::dropEvent(QGraphicsSceneDragDropEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
|
||||
const ExtenderItemMimeData *mimeData =
|
||||
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
|
||||
|
||||
if (mimeData) {
|
||||
mimeData->extenderItem()->setExtender(this, event->pos());
|
||||
QApplication::restoreOverrideCursor();
|
||||
itemHoverLeaveEvent(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Extender::itemAddedEvent(ExtenderItem *item, const QPointF &pos)
|
||||
{
|
||||
ExtenderGroup *group = item->isGroup() ? static_cast<ExtenderGroup*>(item) : 0;
|
||||
if (group && group->autoHide() && group->items().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!item->group()) {
|
||||
if (pos == QPointF(-1, -1)) {
|
||||
//if it was already there, reposition
|
||||
d->layout->removeItem(item);
|
||||
//if just plain adding an item, add it at a sane position:
|
||||
if (appearance() == BottomUpStacked) {
|
||||
//at the top
|
||||
d->layout->insertItem(0, item);
|
||||
} else {
|
||||
//at the bottom
|
||||
d->layout->addItem(item);
|
||||
}
|
||||
} else {
|
||||
kDebug() << "inserting at" << pos << d->insertIndexFromPos(pos) << item->size();
|
||||
d->layout->insertItem(d->insertIndexFromPos(pos), item);
|
||||
kDebug() << item->size();
|
||||
}
|
||||
}
|
||||
|
||||
d->adjustMinimumSize();
|
||||
|
||||
//remove the empty extender message if needed.
|
||||
d->updateEmptyExtenderLabel();
|
||||
d->updateBorders();
|
||||
|
||||
d->adjustSize();
|
||||
}
|
||||
|
||||
void Extender::itemRemovedEvent(ExtenderItem *item)
|
||||
{
|
||||
if (d->destroying) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->layout->removeItem(item);
|
||||
|
||||
if (d->spacerWidget) {
|
||||
d->layout->removeItem(d->spacerWidget);
|
||||
delete d->spacerWidget;
|
||||
d->spacerWidget = 0;
|
||||
}
|
||||
|
||||
d->adjustMinimumSize();
|
||||
|
||||
//add the empty extender message if needed.
|
||||
d->updateEmptyExtenderLabel();
|
||||
d->updateBorders();
|
||||
|
||||
d->layout->updateGeometry();
|
||||
static_cast<QGraphicsLayoutItem *>(d->scrollWidget)->updateGeometry();
|
||||
updateGeometry();
|
||||
|
||||
d->adjustSize();
|
||||
}
|
||||
|
||||
void Extender::itemHoverEnterEvent(ExtenderItem *item)
|
||||
{
|
||||
itemHoverMoveEvent(item, QPointF(0, 0));
|
||||
}
|
||||
|
||||
void Extender::itemHoverMoveEvent(ExtenderItem *item, const QPointF &pos)
|
||||
{
|
||||
if (d->spacerWidget && d->spacerWidget->geometry().contains(pos)) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Make sure we remove any spacer that might already be in the layout.
|
||||
if (d->spacerWidget) {
|
||||
d->layout->removeItem(d->spacerWidget);
|
||||
}
|
||||
|
||||
int insertIndex = d->insertIndexFromPos(pos);
|
||||
|
||||
//Create a widget that functions as spacer, and add that to the layout.
|
||||
if (!d->spacerWidget) {
|
||||
Spacer *widget = new Spacer(this);
|
||||
qreal left, top, right, bottom;
|
||||
d->background->getMargins(left, top, right, bottom);
|
||||
widget->setMargins(left, 4, right, 4);
|
||||
|
||||
widget->setMinimumSize(item->minimumSize());
|
||||
widget->setPreferredSize(item->preferredSize());
|
||||
widget->setMaximumSize(item->maximumSize());
|
||||
widget->setSizePolicy(item->sizePolicy());
|
||||
d->spacerWidget = widget;
|
||||
}
|
||||
d->layout->insertItem(insertIndex, d->spacerWidget);
|
||||
|
||||
//Make sure we remove any 'no detachables' label that might be there, and update the layout.
|
||||
d->updateEmptyExtenderLabel();
|
||||
}
|
||||
|
||||
void Extender::itemHoverLeaveEvent(ExtenderItem *item)
|
||||
{
|
||||
Q_UNUSED(item);
|
||||
|
||||
if (d->spacerWidget) {
|
||||
//Remove any trace of the spacer widget.
|
||||
d->layout->removeItem(d->spacerWidget);
|
||||
delete d->spacerWidget;
|
||||
d->spacerWidget = 0;
|
||||
|
||||
d->currentSpacerIndex = -1;
|
||||
|
||||
d->updateEmptyExtenderLabel();
|
||||
}
|
||||
}
|
||||
|
||||
FrameSvg::EnabledBorders Extender::enabledBordersForItem(ExtenderItem *item) const
|
||||
{
|
||||
if (d->layout->count() < 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ExtenderItem *topItem = dynamic_cast<ExtenderItem*>(d->layout->itemAt(0));
|
||||
ExtenderItem *bottomItem = dynamic_cast<ExtenderItem*>(d->layout->itemAt(d->layout->count() - 1));
|
||||
|
||||
FrameSvg::EnabledBorders borders = FrameSvg::NoBorder;
|
||||
|
||||
if (item->group()) {
|
||||
return FrameSvg::NoBorder;
|
||||
} else if (d->appearance == TopDownStacked && bottomItem != item) {
|
||||
borders = FrameSvg::LeftBorder | FrameSvg::BottomBorder | FrameSvg::RightBorder;
|
||||
} else if (d->appearance == BottomUpStacked && topItem != item) {
|
||||
borders = FrameSvg::LeftBorder | FrameSvg::TopBorder | FrameSvg::RightBorder;
|
||||
} else if (d->appearance != NoBorders) {
|
||||
borders = FrameSvg::LeftBorder | FrameSvg::RightBorder;
|
||||
} else {
|
||||
return FrameSvg::NoBorder;
|
||||
}
|
||||
|
||||
if (d->scrollWidget->viewportGeometry().height() < d->mainWidget->boundingRect().height()) {
|
||||
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
||||
borders &= ~FrameSvg::LeftBorder;
|
||||
} else {
|
||||
borders &= ~FrameSvg::RightBorder;
|
||||
}
|
||||
}
|
||||
|
||||
//someone (i.e. a Dialog) told the extender to disable some border?
|
||||
borders &= ~d->disabledBordersHint;
|
||||
|
||||
|
||||
return borders;
|
||||
}
|
||||
|
||||
ExtenderPrivate::ExtenderPrivate(Applet *applet, Extender *extender) :
|
||||
q(extender),
|
||||
applet(applet),
|
||||
background(new FrameSvg(extender)),
|
||||
disabledBordersHint(FrameSvg::NoBorder),
|
||||
currentSpacerIndex(-1),
|
||||
spacerWidget(0),
|
||||
emptyExtenderMessage(QString()),
|
||||
emptyExtenderLabel(0),
|
||||
appearance(Extender::NoBorders),
|
||||
destroying(false),
|
||||
scrollbarVisible(false)
|
||||
{
|
||||
background->setImagePath("widgets/extender-background");
|
||||
}
|
||||
|
||||
ExtenderPrivate::~ExtenderPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void ExtenderPrivate::addExtenderItem(ExtenderItem *item, const QPointF &pos)
|
||||
{
|
||||
if (attachedExtenderItems.contains(item)) {
|
||||
pendingItems.remove(item);
|
||||
q->itemAddedEvent(item, pos);
|
||||
return;
|
||||
}
|
||||
|
||||
QObject::connect(item, SIGNAL(destroyed(Plasma::ExtenderItem*)), q, SLOT(extenderItemDestroyed(Plasma::ExtenderItem*)));
|
||||
attachedExtenderItems.append(item);
|
||||
q->itemHoverLeaveEvent(item);
|
||||
pendingItems.insert(item, pos);
|
||||
QTimer::singleShot(0, q, SLOT(delayItemAddedEvent()));
|
||||
}
|
||||
|
||||
void ExtenderPrivate::removeExtenderItem(ExtenderItem *item)
|
||||
{
|
||||
attachedExtenderItems.removeAll(item);
|
||||
pendingItems.remove(item);
|
||||
|
||||
//collapse the popupapplet if the last item is removed.
|
||||
if (attachedExtenderItems.isEmpty()) {
|
||||
PopupApplet *popupApplet = qobject_cast<PopupApplet*>(applet.data());
|
||||
if (popupApplet) {
|
||||
popupApplet->hidePopup();
|
||||
}
|
||||
}
|
||||
|
||||
q->itemRemovedEvent(item);
|
||||
}
|
||||
|
||||
int ExtenderPrivate::insertIndexFromPos(const QPointF &pos) const
|
||||
{
|
||||
int insertIndex = -1;
|
||||
|
||||
//XXX: duplicated from panel
|
||||
if (pos != QPointF(-1, -1)) {
|
||||
for (int i = 0; i < layout->count(); ++i) {
|
||||
QRectF siblingGeometry = layout->itemAt(i)->geometry();
|
||||
qreal middle = (siblingGeometry.top() + siblingGeometry.bottom()) / 2.0;
|
||||
if (pos.y() < middle) {
|
||||
insertIndex = i;
|
||||
break;
|
||||
} else if (pos.y() <= siblingGeometry.bottom()) {
|
||||
insertIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return insertIndex;
|
||||
}
|
||||
|
||||
void ExtenderPrivate::loadExtenderItems()
|
||||
{
|
||||
if (!applet) {
|
||||
return;
|
||||
}
|
||||
|
||||
KConfigGroup cg = applet.data()->config("ExtenderItems");
|
||||
|
||||
//first create a list of extenderItems, and then sort them on their position, so the items get
|
||||
//recreated in the correct order.
|
||||
QList<QPair<int, QString> > groupList;
|
||||
foreach (const QString &extenderItemId, cg.groupList()) {
|
||||
KConfigGroup dg = cg.group(extenderItemId);
|
||||
groupList.append(qMakePair(dg.readEntry("extenderItemPosition", 0), extenderItemId));
|
||||
}
|
||||
qSort(groupList);
|
||||
|
||||
//iterate over the extender items
|
||||
for (int i = 0; i < groupList.count(); i++) {
|
||||
QPair<int, QString> pair = groupList[i];
|
||||
|
||||
KConfigGroup dg = cg.group(pair.second);
|
||||
|
||||
//load the relevant settings.
|
||||
QString extenderItemId = dg.name();
|
||||
QString extenderItemName = dg.readEntry("extenderItemName", "");
|
||||
QString appletName = dg.readEntry("sourceAppletPluginName", "");
|
||||
uint sourceAppletId = dg.readEntry("sourceAppletId", 0);
|
||||
|
||||
bool temporarySourceApplet = false;
|
||||
|
||||
kDebug() << "applet id = " << applet.data()->id();
|
||||
kDebug() << "sourceappletid = " << sourceAppletId;
|
||||
|
||||
//find the source applet.
|
||||
Applet *sourceApplet = 0;
|
||||
if (applet.data()->id() == sourceAppletId) {
|
||||
// it's ours!
|
||||
sourceApplet = applet.data();
|
||||
} else {
|
||||
// maybe it's foreign?
|
||||
Containment *containment = applet.data()->containment();
|
||||
|
||||
if (containment) {
|
||||
Corona *corona = containment->corona();
|
||||
|
||||
if (sourceAppletId == q->applet()->id()) {
|
||||
sourceApplet = q->applet();
|
||||
} else {
|
||||
foreach (Containment *containment, corona->containments()) {
|
||||
foreach (Applet *applet, containment->applets()) {
|
||||
if (applet->id() == sourceAppletId) {
|
||||
sourceApplet = applet;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//There is no source applet. We just instantiate one just for the sake of creating
|
||||
//detachables.
|
||||
if (!sourceApplet) {
|
||||
kDebug() << "creating a temporary applet as factory";
|
||||
sourceApplet = Applet::load(appletName);
|
||||
temporarySourceApplet = true;
|
||||
//TODO: maybe add an option to applet to indicate that it shouldn't be deleted after
|
||||
//having used it as factory.
|
||||
}
|
||||
|
||||
if (!sourceApplet) {
|
||||
kDebug() << "sourceApplet is null? appletName = " << appletName;
|
||||
kDebug() << " extenderItemId = " << extenderItemId;
|
||||
} else {
|
||||
ExtenderItem *item;
|
||||
if (dg.readEntry("isGroup", false)) {
|
||||
item = new ExtenderGroup(q, extenderItemId.toInt());
|
||||
} else {
|
||||
item = new ExtenderItem(q, extenderItemId.toInt());
|
||||
}
|
||||
sourceApplet->initExtenderItem(item);
|
||||
item->d->sourceApplet = sourceApplet;
|
||||
|
||||
if (temporarySourceApplet) {
|
||||
delete sourceApplet;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ExtenderPrivate::updateBorders()
|
||||
{
|
||||
foreach (ExtenderItem *item, attachedExtenderItems) {
|
||||
if (item && (item->d->background->enabledBorders() != q->enabledBordersForItem(item))) {
|
||||
//call themeChanged to change the backgrounds enabled borders, and move all contained
|
||||
//widgets according to it's changed margins.
|
||||
item->d->themeChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ExtenderPrivate::delayItemAddedEvent()
|
||||
{
|
||||
QHashIterator<Plasma::ExtenderItem *, QPointF> it(pendingItems);
|
||||
while (it.hasNext()) {
|
||||
q->itemAddedEvent(it.key(), it.value());
|
||||
}
|
||||
pendingItems.clear();
|
||||
}
|
||||
|
||||
void ExtenderPrivate::updateEmptyExtenderLabel()
|
||||
{
|
||||
if (q->isEmpty() && !emptyExtenderLabel &&
|
||||
!emptyExtenderMessage.isEmpty() && !spacerWidget ) {
|
||||
//add the empty extender label.
|
||||
emptyExtenderLabel = new Label(q);
|
||||
emptyExtenderLabel->setAlignment(Qt::AlignCenter);
|
||||
emptyExtenderLabel->setText(emptyExtenderMessage);
|
||||
|
||||
qreal left, top, right, bottom;
|
||||
background->getMargins(left, top, right, bottom);
|
||||
emptyExtenderLabel->nativeWidget()->setMargin(left + right);
|
||||
|
||||
emptyExtenderLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
|
||||
layout->addItem(emptyExtenderLabel);
|
||||
} else if (!q->isEmpty() && emptyExtenderLabel) {
|
||||
//remove the empty extender label.
|
||||
layout->removeItem(emptyExtenderLabel);
|
||||
delete emptyExtenderLabel;
|
||||
emptyExtenderLabel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ExtenderPrivate::adjustMinimumSize()
|
||||
{
|
||||
//FIXME: hardcoded number for the scrollbar
|
||||
scrollWidget->setMinimumWidth(mainWidget->effectiveSizeHint(Qt::MinimumSize).width() + 32);
|
||||
//FIXME: hardcoded number
|
||||
scrollWidget->setMinimumHeight(qMin((qreal)300, mainWidget->effectiveSizeHint(Qt::MinimumSize).height()));
|
||||
}
|
||||
|
||||
void ExtenderPrivate::setPositionFromDragPosition(const QPointF &pos)
|
||||
{
|
||||
const qreal ratio = (q->mapFromScene(pos).y()/scrollWidget->size().height());
|
||||
|
||||
mainWidget->setPos(mainWidget->pos().x(), 30 + (ratio *(scrollWidget->size().height() - mainWidget->size().height() - 30)));
|
||||
}
|
||||
|
||||
ExtenderGroup *ExtenderPrivate::findGroup(const QString &name) const
|
||||
{
|
||||
foreach (ExtenderItem *item, attachedExtenderItems) {
|
||||
if (item->isGroup() && item->name() == name) {
|
||||
return qobject_cast<ExtenderGroup*>(item);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ExtenderPrivate::extenderItemDestroyed(Plasma::ExtenderItem *item)
|
||||
{
|
||||
pendingItems.remove(item);
|
||||
|
||||
if (attachedExtenderItems.contains(item)) {
|
||||
// removeExtenderItem also removes the item from attachedExtenderItems
|
||||
removeExtenderItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
void ExtenderPrivate::viewportGeometryChanged(const QRectF &rect)
|
||||
{
|
||||
if (appearance != Extender::TopDownStacked && appearance != Extender::BottomUpStacked) {
|
||||
scrollbarVisible = (rect.height() > mainWidget->boundingRect().height());
|
||||
return;
|
||||
}
|
||||
|
||||
bool scroll = !(rect.height() >= mainWidget->boundingRect().height());
|
||||
|
||||
if (scroll != scrollbarVisible) {
|
||||
scrollbarVisible = scroll;
|
||||
updateBorders();
|
||||
}
|
||||
}
|
||||
|
||||
void ExtenderPrivate::setDisabledBordersHint(const FrameSvg::EnabledBorders borders)
|
||||
{
|
||||
if (disabledBordersHint == borders) {
|
||||
return;
|
||||
}
|
||||
|
||||
disabledBordersHint = borders;
|
||||
foreach (Plasma::ExtenderItem *item, attachedExtenderItems) {
|
||||
item->d->themeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void ExtenderPrivate::adjustSize()
|
||||
{
|
||||
QRect screenRect;
|
||||
QSizeF size = mainWidget->effectiveSizeHint(Qt::PreferredSize);
|
||||
if (applet) {
|
||||
Containment *containment = applet.data()->containment();
|
||||
if (containment && containment->corona()) {
|
||||
screenRect = containment->corona()->screenGeometry(containment->screen());
|
||||
}
|
||||
}
|
||||
q->resize(qMin(screenRect.width()/3, (int)size.width()),
|
||||
qMin(screenRect.height()/3, (int)size.height()));
|
||||
}
|
||||
|
||||
bool Extender::isEmpty() const
|
||||
{
|
||||
//It's empty if it doesn't have items or has only group that are empty and autohide
|
||||
foreach (const ExtenderItem *item, d->attachedExtenderItems) {
|
||||
if (!item->isGroup()) {
|
||||
return false;
|
||||
} else {
|
||||
//a static_cast here should be safe, it's not the case apparently
|
||||
const ExtenderGroup *group = qobject_cast<const ExtenderGroup *>(item);
|
||||
if (group && (!group->autoHide() || group->items().size() > 0)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
#include "moc_extender.cpp"
|
|
@ -1,324 +0,0 @@
|
|||
/*
|
||||
* Copyright 2008, 2009 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_EXTENDER_H
|
||||
#define PLASMA_EXTENDER_H
|
||||
|
||||
#include <QtGui/QGraphicsWidget>
|
||||
|
||||
#include "plasma/framesvg.h"
|
||||
#include "plasma/plasma_export.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class ExtenderGroup;
|
||||
class ExtenderPrivate;
|
||||
class ExtenderItem;
|
||||
class Applet;
|
||||
|
||||
/**
|
||||
* @class Extender plasma/extender.h <Plasma/Extender>
|
||||
*
|
||||
* @short Extends applets to allow detachable parts
|
||||
*
|
||||
* An Extender is a widget that visually extends the normal contents of an applet with
|
||||
* additional dynamic widgets called ExtenderItems. These ExtenderItems can be
|
||||
* detached by the user and dropped either on another Extender or on the canvas directly.
|
||||
*
|
||||
* This widget allows using ExtenderItems in your applet. Extender takes care of the presentation
|
||||
* of a collection of ExtenderItems and keeps track of ExtenderItems that originate in it.
|
||||
*
|
||||
* The default Extender implementation displays extender items in a vertical layout with
|
||||
* spacers that appear when dropping an ExtenderItem over it.
|
||||
*
|
||||
* If you wish to have a different presentation of extender items, you can choose to subclass
|
||||
* Extender and reimplement the extenderItem* events and, optionally, the saveState function.
|
||||
*
|
||||
* To use an Extender in you applet, you'll have to instantiate one. A call to extender() in your
|
||||
* applet will create an extender on your applet if you haven't got one already. Every applet can
|
||||
* contain only one extender. Think of it as a decorator that adds some functionality to applets
|
||||
* that require it. Never instantiate an Extender before init() in your applet. This won't work
|
||||
* correctly since a scene is required when an Extender is instantiated.
|
||||
*
|
||||
* As soon as an Extender is instantiated, ExtenderItems contained previously in this Extender are
|
||||
* restored using the initExtenderItem function from the applet the items originally came from. For
|
||||
* more information on how this works and how to use ExtenderItems in general, see the ExtenderItem
|
||||
* API documentation.
|
||||
*/
|
||||
class PLASMA_EXPORT Extender : public QGraphicsWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString emptyExtenderMessage READ emptyExtenderMessage WRITE setEmptyExtenderMessage)
|
||||
Q_PROPERTY(QList<ExtenderItem*> items READ items)
|
||||
Q_PROPERTY(QList<ExtenderItem*> attachedItems READ attachedItems)
|
||||
Q_PROPERTY(QList<ExtenderItem*> detachedItems READ detachedItems)
|
||||
Q_PROPERTY(QList<ExtenderGroup*> groups READ groups)
|
||||
Q_PROPERTY(bool empty READ isEmpty)
|
||||
|
||||
public:
|
||||
/**
|
||||
* Description on how to render the extender's items.
|
||||
*/
|
||||
enum Appearance {
|
||||
NoBorders = 0, /**< Draws no borders on the extender's items. When placed in an applet
|
||||
on the desktop, use this setting and use the standard margins of
|
||||
the applet containing this extender. */
|
||||
BottomUpStacked = 1, /**< Draws no borders on the topmost extenderitem, but draws the
|
||||
left, top and right border on subsequent items. When margins
|
||||
of the containing dialog are set to 0, except for the top
|
||||
margin, this leads to the 'stacked' look, recommended for
|
||||
extenders of applet's contained in a panel at the bottom of
|
||||
the screen. */
|
||||
TopDownStacked = 2 /**< Draws no borders on the bottom extenderitem, but draws the
|
||||
left, bottom and right border on subsequent items. When margins
|
||||
of the containing dialog are set to 0, except for the bottom
|
||||
margin, this leads to the 'stacked' look, recommended for
|
||||
extenders of applet's contained in a panel at the top of
|
||||
the screen. */
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an extender. Note that extender expects applet to have a config(), and needs a
|
||||
* scene because of that. So you should only instantiate an extender in init() or later, not
|
||||
* in an applet's constructor.
|
||||
* The constructor also takes care of restoring ExtenderItems that were contained in this
|
||||
* extender before, so ExtenderItems are persistent between sessions.
|
||||
* Note that a call to extender() in an applet will instantiate an Extender for you if one
|
||||
* isn't already associated with your applet.
|
||||
* @param applet The applet this extender is part of. Null is not allowed here.
|
||||
*/
|
||||
explicit Extender(Applet *applet);
|
||||
|
||||
~Extender();
|
||||
|
||||
/**
|
||||
* @param message The text to be shown whenever the applet's extender is empty.
|
||||
*/
|
||||
void setEmptyExtenderMessage(const QString &message);
|
||||
|
||||
/**
|
||||
* @return The text to be shown whenever the applet's layout is empty.
|
||||
*/
|
||||
QString emptyExtenderMessage() const;
|
||||
|
||||
/**
|
||||
* @returns a list of all extender items (attached AND detached) where the source applet is
|
||||
* this applet.
|
||||
*/
|
||||
QList<ExtenderItem*> items() const;
|
||||
|
||||
/**
|
||||
* @returns a list of all attached extender items.
|
||||
*/
|
||||
QList<ExtenderItem*> attachedItems() const;
|
||||
|
||||
/**
|
||||
* @returns a list of all detached extender items.
|
||||
*/
|
||||
QList<ExtenderItem*> detachedItems() const;
|
||||
|
||||
/**
|
||||
* This function can be used for obtaining the extender item specified by name. For checking
|
||||
* whether or not an item already exists, you should use hasItem instead: while plasma is
|
||||
* starting up, not all detached items might have been instantiated yet. hasItem returns true
|
||||
* even if the requested item isn't instantiated yet.
|
||||
* @returns the requested item
|
||||
*/
|
||||
Q_INVOKABLE ExtenderItem *item(const QString &name) const;
|
||||
|
||||
/**
|
||||
* Extra convenience function for obtaining groups specified by name. This will avoid needed
|
||||
* to call item and casting to ExtenderGroup, which is otherwise quite common.
|
||||
* @returns the requested group
|
||||
* @since 4.3
|
||||
*/
|
||||
Q_INVOKABLE ExtenderGroup *group(const QString &name) const;
|
||||
|
||||
/**
|
||||
* This function can be used for easily determining if a certain item is already displayed
|
||||
* in an extender item somewhere, so your applet doesn't duplicate this item. This is needed
|
||||
* because ExtenderItems are persistent, so you can't blindly add new extender items in all
|
||||
* cases.
|
||||
* @returns whether or not this item already exists.
|
||||
* @since 4.3
|
||||
*/
|
||||
Q_INVOKABLE bool hasItem(const QString &name) const;
|
||||
|
||||
/**
|
||||
* @return true if the Extender is visually empty (though it may have items such as
|
||||
* empty groups or detached items associatd with it)
|
||||
*/
|
||||
bool isEmpty() const;
|
||||
|
||||
/**
|
||||
* Use this function to instruct the extender on how to render its items. Usually you will
|
||||
* want to call this function in your applet's constraintsEvent, allthough this is already
|
||||
* done for you when using PopupApplet as base class for your applet. Defaults to NoBorders.
|
||||
* @param appearance the way this extender should look.
|
||||
*/
|
||||
void setAppearance(Appearance appearance);
|
||||
|
||||
/**
|
||||
* @returns the current way of rendering extender items that is used.
|
||||
*/
|
||||
Appearance appearance() const;
|
||||
|
||||
/**
|
||||
* @returns a list of groups that are contained in this extender.
|
||||
* @since 4.3
|
||||
*/
|
||||
QList<ExtenderGroup*> groups() const;
|
||||
|
||||
/**
|
||||
* @returns the Applet this Extender is associated with
|
||||
* @since 4.4
|
||||
*/
|
||||
Applet *applet() const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Get's called after an item has been added to this extender. The bookkeeping has already
|
||||
* been done when this function get's called. The only thing left to do is put it somewhere
|
||||
* appropriate. The default implementation adds the extenderItem to the appropriate place in
|
||||
* a QGraphicsLinearLayout.
|
||||
* @param item The item that has just been added.
|
||||
* @param pos The location the item has been dropped in local coordinates.
|
||||
*/
|
||||
virtual void itemAddedEvent(ExtenderItem *item, const QPointF &pos = QPointF(-1, -1));
|
||||
|
||||
/**
|
||||
* Get's called after an item has been removed from this extender. All bookkeeping has
|
||||
* already been done when this function get's called.
|
||||
* @param item The item that has just been removed.
|
||||
*/
|
||||
virtual void itemRemovedEvent(ExtenderItem *item);
|
||||
|
||||
/**
|
||||
* Get's called when an ExtenderItem that get's dragged enters this extender. Default
|
||||
* implementation does nothing.
|
||||
*/
|
||||
virtual void itemHoverEnterEvent(ExtenderItem *item);
|
||||
|
||||
/**
|
||||
* Gets called when an ExtenderItem is hovering over this extender. Implement this function
|
||||
* to give some visual feedback about what will happen when the mouse button is released at
|
||||
* that position. The default implementation shows a spacer at the appropriate location in
|
||||
* the layout.
|
||||
* @param item The item that's hovering over this extender. Most useful for obtaining the
|
||||
* size of the spacer.
|
||||
* @param pos The location the item is hovering.
|
||||
*/
|
||||
virtual void itemHoverMoveEvent(ExtenderItem *item, const QPointF &pos);
|
||||
|
||||
/**
|
||||
* Get's called when an ExtenderItem that was previously hovering over this extender moves
|
||||
* away from this extender. The default implementation removes any spacer from the layout.
|
||||
*/
|
||||
virtual void itemHoverLeaveEvent(ExtenderItem *item);
|
||||
|
||||
/**
|
||||
* This function get's called for every extender when plasma exits. Implement this function
|
||||
* to store the current state of this extender (position in a layout for example), so this
|
||||
* can be restored when applet starts again. The default implementation stores the y
|
||||
* coordinate of every extender item in the config field extenderItemPos.
|
||||
*/
|
||||
virtual void saveState();
|
||||
|
||||
/**
|
||||
* This function get's called on every item to determine which background border's to
|
||||
* render.
|
||||
* @param item the item for which its position or extender has changed.
|
||||
* @return the borders that have to be enabled on its background.
|
||||
*/
|
||||
virtual FrameSvg::EnabledBorders enabledBordersForItem(ExtenderItem *item) const;
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsWidget
|
||||
*/
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsWidget
|
||||
*/
|
||||
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsWidget
|
||||
*/
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsWidget
|
||||
*/
|
||||
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsWidget
|
||||
*/
|
||||
void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsWidget
|
||||
*/
|
||||
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsWidget
|
||||
*/
|
||||
void dropEvent(QGraphicsSceneDragDropEvent *event);
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* Fires when an extender item is added to this extender.
|
||||
*/
|
||||
void itemAttached(Plasma::ExtenderItem *);
|
||||
|
||||
/**
|
||||
* Fires when an extender item is removed from this extender.
|
||||
*/
|
||||
void itemDetached(Plasma::ExtenderItem *);
|
||||
|
||||
/**
|
||||
* Fires when an extender's preferred size changes.
|
||||
*/
|
||||
void geometryChanged();
|
||||
|
||||
private:
|
||||
ExtenderPrivate *const d;
|
||||
|
||||
Q_PRIVATE_SLOT(d, void delayItemAddedEvent())
|
||||
Q_PRIVATE_SLOT(d, void extenderItemDestroyed(Plasma::ExtenderItem *item))
|
||||
Q_PRIVATE_SLOT(d, void viewportGeometryChanged(const QRectF &))
|
||||
|
||||
friend class ExtenderPrivate;
|
||||
friend class ExtenderGroup;
|
||||
friend class ExtenderGroupPrivate;
|
||||
friend class ExtenderItem;
|
||||
friend class ExtenderItemPrivate;
|
||||
//dialog needs access to the extender's applet location.
|
||||
friend class DialogPrivate;
|
||||
//applet should be able to call saveState();
|
||||
friend class Applet;
|
||||
|
||||
};
|
||||
} // Plasma namespace
|
||||
|
||||
#endif //PLASMA_EXTENDER_H
|
||||
|
|
@ -1,397 +0,0 @@
|
|||
/*
|
||||
* Copyright 2009 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "extendergroup.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include <QTimer>
|
||||
#include <QtGui/QGraphicsWidget>
|
||||
#include <QtGui/QGraphicsLinearLayout>
|
||||
#include <QtGui/qgraphicssceneevent.h>
|
||||
|
||||
#include "applet.h"
|
||||
#include "extender.h"
|
||||
#include "extenderitem.h"
|
||||
#include "theme.h"
|
||||
#include "widgets/scrollwidget.h"
|
||||
|
||||
#include "private/extender_p.h"
|
||||
#include "private/extendergroup_p.h"
|
||||
#include "private/extenderitemmimedata_p.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
ExtenderGroup::ExtenderGroup(Extender *parent, uint groupId)
|
||||
: ExtenderItem(parent, groupId),
|
||||
d(new ExtenderGroupPrivate(this))
|
||||
{
|
||||
connect(extender(), SIGNAL(itemAttached(Plasma::ExtenderItem*)),
|
||||
this, SLOT(addItemToGroup(Plasma::ExtenderItem*)));
|
||||
connect(extender(), SIGNAL(itemDetached(Plasma::ExtenderItem*)),
|
||||
this, SLOT(removeItemFromGroup(Plasma::ExtenderItem*)));
|
||||
|
||||
//this isn't actually connected to anything, we will just check if it's running or not
|
||||
d->resizeTimer = new QTimer(this);
|
||||
d->resizeTimer->setSingleShot(true);
|
||||
|
||||
config().writeEntry("isGroup", true);
|
||||
|
||||
setAcceptDrops(true);
|
||||
|
||||
QGraphicsLinearLayout *lay = static_cast<QGraphicsLinearLayout *>(layout());
|
||||
d->childsWidget = new QGraphicsWidget(this);
|
||||
d->childsWidget->installEventFilter(this);
|
||||
d->layout = new QGraphicsLinearLayout(Qt::Vertical, d->childsWidget);
|
||||
d->childsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
lay->addItem(d->childsWidget);
|
||||
|
||||
QAction *expand = new QAction(this);
|
||||
expand->setVisible(false);
|
||||
expand->setToolTip(i18n("Show this group."));
|
||||
connect(expand, SIGNAL(triggered()), this, SLOT(expandGroup()));
|
||||
addAction("expand", expand);
|
||||
|
||||
QAction *collapse = new QAction(this);
|
||||
collapse->setVisible(true);
|
||||
collapse->setToolTip(i18n("Hide this group."));
|
||||
connect(collapse, SIGNAL(triggered()), this, SLOT(collapseGroup()));
|
||||
addAction("collapse", collapse);
|
||||
|
||||
d->themeChanged();
|
||||
|
||||
QString groupName;
|
||||
foreach (ExtenderItem *item, extender()->attachedItems()) {
|
||||
groupName = item->config().readEntry("group", "");
|
||||
if (!groupName.isEmpty() && groupName == name()) {
|
||||
item->setGroup(this);
|
||||
}
|
||||
}
|
||||
|
||||
if (items().isEmpty() && d->autoHide && !isDetached()) {
|
||||
extender()->itemRemovedEvent(this);
|
||||
hide();
|
||||
}
|
||||
|
||||
if (!config().readEntry("groupCollapsed", true)) {
|
||||
expandGroup();
|
||||
}
|
||||
|
||||
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
|
||||
this, SLOT(themeChanged()));
|
||||
|
||||
}
|
||||
|
||||
ExtenderGroup::~ExtenderGroup()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
QList<ExtenderItem*> ExtenderGroup::items() const
|
||||
{
|
||||
QList<ExtenderItem*> result;
|
||||
foreach (ExtenderItem *item, extender()->attachedItems()) {
|
||||
if (item->group() == this) {
|
||||
result.append(item);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ExtenderGroup::autoHide() const
|
||||
{
|
||||
return d->autoHide;
|
||||
}
|
||||
|
||||
void ExtenderGroup::setAutoHide(bool autoHide)
|
||||
{
|
||||
d->autoHide = autoHide;
|
||||
if (autoHide && items().isEmpty()) {
|
||||
extender()->itemRemovedEvent(this);
|
||||
hide();
|
||||
} else if (!autoHide && !isVisible()) {
|
||||
extender()->itemAddedEvent(this);
|
||||
show();
|
||||
}
|
||||
}
|
||||
|
||||
bool ExtenderGroup::isAutoCollapse() const
|
||||
{
|
||||
return d->autoCollapse;
|
||||
}
|
||||
|
||||
void ExtenderGroup::setAutoCollapse(bool collapse)
|
||||
{
|
||||
d->autoCollapse = collapse;
|
||||
}
|
||||
|
||||
bool ExtenderGroup::isGroupCollapsed() const
|
||||
{
|
||||
return d->collapsed;
|
||||
}
|
||||
|
||||
void ExtenderGroup::setGroupCollapsed(bool collapsed)
|
||||
{
|
||||
if (collapsed) {
|
||||
collapseGroup();
|
||||
} else {
|
||||
expandGroup();
|
||||
}
|
||||
}
|
||||
|
||||
void ExtenderGroup::expandGroup()
|
||||
{
|
||||
if (d->autoCollapse) {
|
||||
setCollapsed(false);
|
||||
}
|
||||
if (d->collapsed == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->collapsed = false;
|
||||
config().writeEntry("groupCollapsed", d->collapsed);
|
||||
action("collapse")->setVisible(true);
|
||||
action("expand")->setVisible(false);
|
||||
|
||||
d->childsWidget->show();
|
||||
static_cast<QGraphicsLinearLayout *>(layout())->addItem(d->childsWidget);
|
||||
updateGeometry();
|
||||
|
||||
foreach (ExtenderItem *item, extender()->attachedItems()) {
|
||||
if (item->group() == this) {
|
||||
item->show();
|
||||
extender()->itemAddedEvent(item);
|
||||
}
|
||||
}
|
||||
|
||||
//extender()->resize(extender()->effectiveSizeHint(Qt::PreferredSize));
|
||||
}
|
||||
|
||||
void ExtenderGroup::collapseGroup()
|
||||
{
|
||||
if (d->autoCollapse) {
|
||||
setCollapsed(true);
|
||||
}
|
||||
if (d->collapsed == true) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->collapsed = true;
|
||||
config().writeEntry("groupCollapsed", d->collapsed);
|
||||
action("collapse")->setVisible(false);
|
||||
action("expand")->setVisible(true);
|
||||
|
||||
d->childsWidget->hide();
|
||||
static_cast<QGraphicsLinearLayout *>(layout())->removeItem(d->childsWidget);
|
||||
updateGeometry();
|
||||
|
||||
foreach (ExtenderItem *item, extender()->attachedItems()) {
|
||||
if (item != this && item->group() == this) {
|
||||
item->hide();
|
||||
extender()->itemRemovedEvent(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ExtenderGroup::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == d->childsWidget && event->type() == QEvent::GraphicsSceneResize) {
|
||||
static_cast<QGraphicsLayoutItem *>(extender()->d->scrollWidget)->updateGeometry();
|
||||
if (!d->resizeTimer->isActive()) {
|
||||
static_cast<QGraphicsLayoutItem *>(extender())->updateGeometry();
|
||||
extender()->d->adjustSize();
|
||||
d->resizeTimer->start(0);
|
||||
}
|
||||
}
|
||||
|
||||
return ExtenderItem::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void ExtenderGroup::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
|
||||
event->accept();
|
||||
|
||||
dragMoveEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void ExtenderGroup::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
|
||||
const ExtenderItemMimeData *mimeData =
|
||||
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
|
||||
|
||||
if (mimeData) {
|
||||
QPointF pos(event->pos());
|
||||
if (d->spacerWidget && d->spacerWidget->geometry().contains(pos)) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Make sure we remove any spacer that might already be in the layout.
|
||||
if (d->spacerWidget) {
|
||||
d->layout->removeItem(d->spacerWidget);
|
||||
}
|
||||
|
||||
int insertIndex = d->insertIndexFromPos(pos);
|
||||
|
||||
//Create a widget that functions as spacer, and add that to the layout.
|
||||
if (!d->spacerWidget) {
|
||||
Spacer *widget = new Spacer(this);
|
||||
ExtenderItem *item = mimeData->extenderItem();
|
||||
qreal left, top, right, bottom;
|
||||
extender()->d->background->getMargins(left, top, right, bottom);
|
||||
widget->setMargins(left, 4, right, 4);
|
||||
|
||||
widget->setMinimumSize(item->minimumSize());
|
||||
widget->setPreferredSize(item->preferredSize());
|
||||
widget->setMaximumSize(item->maximumSize());
|
||||
widget->setSizePolicy(item->sizePolicy());
|
||||
d->spacerWidget = widget;
|
||||
}
|
||||
d->layout->insertItem(insertIndex, d->spacerWidget);
|
||||
|
||||
extender()->d->setPositionFromDragPosition(event->scenePos());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ExtenderGroup::dropEvent(QGraphicsSceneDragDropEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
|
||||
const ExtenderItemMimeData *mimeData =
|
||||
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
|
||||
|
||||
if (mimeData) {
|
||||
mimeData->extenderItem()->setGroup(this, event->pos());
|
||||
QApplication::restoreOverrideCursor();
|
||||
d->layout->removeItem(d->spacerWidget);
|
||||
d->spacerWidget->deleteLater();
|
||||
d->spacerWidget = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ExtenderGroup::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
|
||||
if (d->spacerWidget) {
|
||||
d->layout->removeItem(d->spacerWidget);
|
||||
d->spacerWidget->deleteLater();
|
||||
d->spacerWidget = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ExtenderGroupPrivate::ExtenderGroupPrivate(ExtenderGroup *group)
|
||||
: q(group),
|
||||
spacerWidget(0),
|
||||
svg(new Svg(group)),
|
||||
collapsed(false),
|
||||
autoHide(true),
|
||||
autoCollapse(false)
|
||||
{
|
||||
}
|
||||
|
||||
ExtenderGroupPrivate::~ExtenderGroupPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void ExtenderGroupPrivate::addItemToGroup(Plasma::ExtenderItem *item, const QPointF &pos)
|
||||
{
|
||||
if (item->group() == q) {
|
||||
item->setParentItem(childsWidget);
|
||||
item->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
layout->insertItem(insertIndexFromPos(pos), item);
|
||||
layout->activate();
|
||||
|
||||
if (!q->isVisible() && !q->items().isEmpty()) {
|
||||
q->extender()->itemAddedEvent(q);
|
||||
q->show();
|
||||
}
|
||||
childsWidget->setVisible(!q->isGroupCollapsed());
|
||||
|
||||
if (!q->isGroupCollapsed()) {
|
||||
layout->updateGeometry();
|
||||
static_cast<QGraphicsLayoutItem *>(q)->updateGeometry();
|
||||
static_cast<QGraphicsLayoutItem *>(childsWidget)->updateGeometry();
|
||||
static_cast<QGraphicsLayoutItem *>(q->extender()->d->scrollWidget)->updateGeometry();
|
||||
}
|
||||
|
||||
q->extender()->d->adjustSize();
|
||||
}
|
||||
}
|
||||
|
||||
void ExtenderGroupPrivate::removeItemFromGroup(Plasma::ExtenderItem *item)
|
||||
{
|
||||
if (item->group() == q) {
|
||||
if (q->items().isEmpty() && autoHide && !q->isDetached()) {
|
||||
q->extender()->itemRemovedEvent(q);
|
||||
q->hide();
|
||||
}
|
||||
layout->removeItem(item);
|
||||
item->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
|
||||
layout->updateGeometry();
|
||||
static_cast<QGraphicsLayoutItem *>(q)->updateGeometry();
|
||||
static_cast<QGraphicsLayoutItem *>(childsWidget)->updateGeometry();
|
||||
static_cast<QGraphicsLayoutItem *>(q->extender()->d->scrollWidget)->updateGeometry();
|
||||
|
||||
q->extender()->d->adjustSize();
|
||||
}
|
||||
}
|
||||
|
||||
void ExtenderGroupPrivate::themeChanged()
|
||||
{
|
||||
svg->setImagePath("widgets/configuration-icons");
|
||||
svg->resize();
|
||||
|
||||
q->action("expand")->setIcon(QIcon(svg->pixmap("restore")));
|
||||
q->action("collapse")->setIcon(QIcon(svg->pixmap("collapse")));
|
||||
}
|
||||
|
||||
int ExtenderGroupPrivate::insertIndexFromPos(const QPointF &pos) const
|
||||
{
|
||||
int insertIndex = -1;
|
||||
|
||||
//XXX: duplicated from panel
|
||||
if (pos != QPointF(-1, -1)) {
|
||||
for (int i = 0; i < layout->count(); ++i) {
|
||||
QRectF siblingGeometry = layout->itemAt(i)->geometry();
|
||||
qreal middle = (siblingGeometry.top() + siblingGeometry.bottom()) / 2.0;
|
||||
if (pos.y() < middle) {
|
||||
insertIndex = i;
|
||||
break;
|
||||
} else if (pos.y() <= siblingGeometry.bottom()) {
|
||||
insertIndex = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return insertIndex;
|
||||
}
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
#include "moc_extendergroup.cpp"
|
|
@ -1,136 +0,0 @@
|
|||
/*
|
||||
* Copyright 2009 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_EXTENDERGROUP_H
|
||||
#define PLASMA_EXTENDERGROUP_H
|
||||
|
||||
#include <QtGui/QGraphicsWidget>
|
||||
#include <QtCore/QList>
|
||||
|
||||
#include "extenderitem.h"
|
||||
|
||||
#include "plasma/plasma_export.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class ExtenderGroupPrivate;
|
||||
class ExtenderItem;
|
||||
class Applet;
|
||||
|
||||
/**
|
||||
* @class ExtenderGroup plasma/extendergroup.h <Plasma/ExtenderGroup>
|
||||
*
|
||||
* @short Allows for grouping of extender items.
|
||||
*
|
||||
* To be able to group multiple items together, you'll need to instantiate an ExtenderGroup, and
|
||||
* call setGroup() on all extender items you wish to add to this group.
|
||||
* This ExtenderGroup is just the same as any other ExtenderItem, except for the expand group and
|
||||
* collapse group buttons it provides, and the fact that it will automatically hide itself if less
|
||||
* then one item belong to this group and autoHide is set to true.
|
||||
*
|
||||
* @since 4.3
|
||||
*/
|
||||
class PLASMA_EXPORT ExtenderGroup : public ExtenderItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool autoHide READ autoHide WRITE setAutoHide)
|
||||
Q_PROPERTY(bool groupCollapsed READ isGroupCollapsed WRITE setGroupCollapsed)
|
||||
Q_PROPERTY(bool autoCollapse READ isAutoCollapse WRITE setAutoCollapse)
|
||||
|
||||
public:
|
||||
/**
|
||||
* Creates a group.
|
||||
* @param applet The applet this group is part of. Null is not allowed here.
|
||||
*/
|
||||
explicit ExtenderGroup(Extender *parent, uint groupId = 0);
|
||||
|
||||
~ExtenderGroup();
|
||||
|
||||
/**
|
||||
* @return a list of items that belong to this group.
|
||||
*/
|
||||
QList<ExtenderItem*> items() const;
|
||||
|
||||
/**
|
||||
* @return whether or not this item hides itself if there are less then 2 items in.
|
||||
*/
|
||||
bool autoHide() const;
|
||||
|
||||
/**
|
||||
* @param autoHide whether or not this item hides itself if less then 2 items belong to this group. The default value is true.
|
||||
*/
|
||||
void setAutoHide(bool autoHide);
|
||||
|
||||
/**
|
||||
* @return if the group is collapsed
|
||||
* @since 4.4
|
||||
*/
|
||||
bool isGroupCollapsed() const;
|
||||
|
||||
/**
|
||||
* @return whether or not this item collapses itself when the group gets collapsed
|
||||
* @since 4.4
|
||||
*/
|
||||
bool isAutoCollapse() const;
|
||||
|
||||
/**
|
||||
* @param autoCollapse whether or not this item collapses itself when the group gets collapsed, the default value is false
|
||||
* @since 4.4
|
||||
*/
|
||||
void setAutoCollapse(bool collapse);
|
||||
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
* expands or collapses this group
|
||||
* @since 4.4
|
||||
*/
|
||||
void setGroupCollapsed(bool collapsed);
|
||||
|
||||
/**
|
||||
* Expands this group to show all ExtenderItems that are contained in this group.
|
||||
*/
|
||||
void expandGroup();
|
||||
|
||||
/**
|
||||
* Collapses this group to hide all ExtenderItems that are contained in this group, and
|
||||
* shows the summary item.
|
||||
*/
|
||||
void collapseGroup();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
|
||||
void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
|
||||
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
|
||||
void dropEvent(QGraphicsSceneDragDropEvent *event);
|
||||
|
||||
private:
|
||||
ExtenderGroupPrivate * const d;
|
||||
|
||||
Q_PRIVATE_SLOT(d, void addItemToGroup(Plasma::ExtenderItem *item))
|
||||
Q_PRIVATE_SLOT(d, void removeItemFromGroup(Plasma::ExtenderItem *item))
|
||||
Q_PRIVATE_SLOT(d, void themeChanged())
|
||||
|
||||
friend class ExtenderItem;
|
||||
};
|
||||
} // Plasma namespace
|
||||
|
||||
#endif //PLASMA_EXTENDER_H
|
||||
|
File diff suppressed because it is too large
Load diff
|
@ -1,312 +0,0 @@
|
|||
/*
|
||||
* Copyright 2008, 2009 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_EXTENDERITEM_H
|
||||
#define PLASMA_EXTENDERITEM_H
|
||||
|
||||
#include <QtGui/QGraphicsWidget>
|
||||
|
||||
#include <kconfiggroup.h>
|
||||
#include <kicon.h>
|
||||
|
||||
#include "plasma/plasma_export.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class Applet;
|
||||
class Extender;
|
||||
class ExtenderGroup;
|
||||
class ExtenderItemPrivate;
|
||||
|
||||
/**
|
||||
* @class ExtenderItem plasma/extenderitem.h <Plasma/ExtenderItem>
|
||||
*
|
||||
* @short Provides detachable items for an Extender
|
||||
*
|
||||
* This class wraps around a QGraphicsWidget and provides drag&drop handling, a draghandle,
|
||||
* title and ability to display qactions as a row of icon, ability to expand, collapse, return
|
||||
* to source and tracks configuration associated with this item for you.
|
||||
*
|
||||
* Typical usage of ExtenderItems in your applet could look like this:
|
||||
*
|
||||
* @code
|
||||
* if (!extender()->hasItem("networkmonitoreth0")) {
|
||||
* ExtenderItem *item = new ExtenderItem(extender());
|
||||
* //name can be used to later access this item through extender()->item(name):
|
||||
* item->setName("networkmonitoreth0");
|
||||
* item->config().writeEntry("device", "eth0");
|
||||
* initExtenderItem(item);
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* Note that we first check if the item already exists: ExtenderItems are persistent
|
||||
* between sessions so we can't blindly add items since they might already exist.
|
||||
*
|
||||
* You'll then need to implement the initExtenderItem function. Having this function in your applet
|
||||
* makes sure that detached extender items get restored after plasma is restarted, just like applets
|
||||
* are. That is also the reason that we write an entry in item->config().
|
||||
* In this function you should instantiate a QGraphicsWidget or QGraphicsItem and call the
|
||||
* setWidget function on the ExtenderItem. This is the only correct way of adding actual content to
|
||||
* a extenderItem. An example:
|
||||
*
|
||||
* @code
|
||||
* void MyApplet::initExtenderItem(Plasma::ExtenderItem *item)
|
||||
* {
|
||||
* QGraphicsWidget *myNetworkMonitorWidget = new NetworkMonitorWidget(item);
|
||||
* item->setWidget(myNetworkMonitorWidget);
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
*/
|
||||
class PLASMA_EXPORT ExtenderItem : public QGraphicsWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QGraphicsItem * widget READ widget WRITE setWidget)
|
||||
Q_PROPERTY(QString title READ title WRITE setTitle)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
|
||||
Q_PROPERTY(Extender * extender READ extender WRITE setExtender)
|
||||
Q_PROPERTY(bool collapsed READ isCollapsed WRITE setCollapsed)
|
||||
Q_PROPERTY(bool detached READ isDetached)
|
||||
Q_PROPERTY(uint autoExpireDelay READ autoExpireDelay WRITE setAutoExpireDelay)
|
||||
|
||||
public:
|
||||
/**
|
||||
* The constructor takes care of adding this item to an extender.
|
||||
* @param hostExtender The extender the extender item belongs to.
|
||||
* @param extenderItemId the id of the extender item. Use the default 0 to assign a new,
|
||||
* unique id to this extender item.
|
||||
*/
|
||||
explicit ExtenderItem(Extender *hostExtender, uint extenderItemId = 0);
|
||||
|
||||
~ExtenderItem();
|
||||
|
||||
/**
|
||||
* fetch the configuration of this widget.
|
||||
* @return the configuration of this widget.
|
||||
*/
|
||||
KConfigGroup config() const;
|
||||
|
||||
/**
|
||||
* @param widget The widget that should be wrapped into the extender item.
|
||||
* It has to be a QGraphicsWidget.
|
||||
*/
|
||||
void setWidget(QGraphicsItem *widget);
|
||||
|
||||
/**
|
||||
* @return The widget that is wrapped into the extender item.
|
||||
*/
|
||||
QGraphicsItem *widget() const;
|
||||
|
||||
/**
|
||||
* @param title the title that will be shown in the extender item's dragger. Default is
|
||||
* no title. This title will also be stored in the item's configuration, so you don't have
|
||||
* to manually store/restore this information for your extender items.
|
||||
*/
|
||||
void setTitle(const QString &title);
|
||||
|
||||
/**
|
||||
* @return the title shown in the extender item's dragger.
|
||||
*/
|
||||
QString title() const;
|
||||
|
||||
/**
|
||||
* You can assign names to extender items to look them up through the item() function.
|
||||
* Make sure you only use unique names. This name will be stored in the item's
|
||||
* configuration.
|
||||
* @param name the name of the item. Defaults to an empty string.
|
||||
*/
|
||||
void setName(const QString &name);
|
||||
|
||||
/**
|
||||
* @return the name of the item.
|
||||
*/
|
||||
QString name() const;
|
||||
|
||||
/**
|
||||
* @param icon the icon name to display in the extender item's
|
||||
* drag handle. Defaults to the source applet's icon. This icon name will also be stored
|
||||
* in the item's configuration, so you don't have to manually store/restore this
|
||||
* information.
|
||||
*/
|
||||
void setIcon(const QString &icon);
|
||||
|
||||
/**
|
||||
* @param icon the icon to display in the extender item's drag handle. Defaults to the
|
||||
* source applet's icon.
|
||||
*/
|
||||
void setIcon(const QIcon &icon);
|
||||
|
||||
/**
|
||||
* @return the icon being displayed in the extender item's drag handle.
|
||||
*/
|
||||
QIcon icon() const;
|
||||
|
||||
/**
|
||||
* @param extender the extender this item belongs to.
|
||||
* @param pos the position in the extender this item should be added. Defaults to 'just
|
||||
* append'.
|
||||
*/
|
||||
void setExtender(Extender *extender, const QPointF &pos = QPointF(-1, -1));
|
||||
|
||||
/**
|
||||
* @return the extender this items belongs to.
|
||||
*/
|
||||
Extender *extender() const;
|
||||
|
||||
/**
|
||||
* @param group the group you want this item to belong to. Note that you can't nest
|
||||
* ExtenderGroups.
|
||||
*
|
||||
* @param group the new group
|
||||
* @param pos position inside the extender group
|
||||
* @since 4.5
|
||||
*/
|
||||
void setGroup(ExtenderGroup *group, const QPointF &pos = QPointF(-1, -1));
|
||||
|
||||
/**
|
||||
* @returns the group this item belongs to.
|
||||
* @since 4.3
|
||||
*/
|
||||
ExtenderGroup *group() const;
|
||||
|
||||
/**
|
||||
* @returns whether or not this is an ExtenderGroup.
|
||||
* @since 4.3
|
||||
*/
|
||||
bool isGroup() const;
|
||||
|
||||
/**
|
||||
* @param time (in ms) before this extender item destroys itself unless it is detached,
|
||||
* in which case this extender stays around. 0 means forever and is the default.
|
||||
*/
|
||||
void setAutoExpireDelay(uint time);
|
||||
|
||||
/**
|
||||
* @return whether or not this extender item has an auto expire delay.
|
||||
*/
|
||||
uint autoExpireDelay() const;
|
||||
|
||||
/**
|
||||
* @return whether or not this item is detached from its original source.
|
||||
*/
|
||||
bool isDetached() const;
|
||||
|
||||
/**
|
||||
* @return whether or not the extender item is collapsed.
|
||||
*/
|
||||
bool isCollapsed() const;
|
||||
|
||||
/**
|
||||
* @param name the name to store the action under in our collection.
|
||||
* @param action the action to add. Actions will be displayed as an icon in the drag
|
||||
* handle.
|
||||
*/
|
||||
void addAction(const QString &name, QAction *action);
|
||||
|
||||
/**
|
||||
* @return the QAction with the given name from our collection. By default the action
|
||||
* collection contains a "movebacktosource" action which will be only shown when the
|
||||
* item is detached.
|
||||
*/
|
||||
QAction *action(const QString &name) const;
|
||||
|
||||
/**
|
||||
* Set the ExtenderItem as transient: won't be saved in the Plasma config
|
||||
* and won't be restored. This is intended for items that have contents
|
||||
* valid only for this session.
|
||||
*
|
||||
* @param transient true if the ExtenderItem will be transient
|
||||
*
|
||||
* @since 4.6
|
||||
*/
|
||||
void setTransient(const bool transient);
|
||||
|
||||
/**
|
||||
* @return true if the ExtenderItem is transient.
|
||||
* @since 4.6
|
||||
*/
|
||||
bool isTransient() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
* Destroys the extender item. As opposed to calling delete on this class, destroy also
|
||||
* removes the config group associated with this item.
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
/**
|
||||
* Collapse or expand the extender item. Defaults to false.
|
||||
*/
|
||||
void setCollapsed(bool collapsed);
|
||||
|
||||
/**
|
||||
* Returns the extender item to its source applet.
|
||||
*/
|
||||
void returnToSource();
|
||||
|
||||
/**
|
||||
* Shows a close button in this item's drag handle. By default a close button will not be
|
||||
* shown.
|
||||
*/
|
||||
void showCloseButton();
|
||||
|
||||
/**
|
||||
* Hides the close button in this item's drag handle.
|
||||
*/
|
||||
void hideCloseButton();
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* Emitted when the extender item is destroyed
|
||||
* @since 4.4.1
|
||||
*/
|
||||
void destroyed(Plasma::ExtenderItem *item);
|
||||
|
||||
protected:
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
|
||||
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
||||
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
Q_PRIVATE_SLOT(d, void toggleCollapse())
|
||||
Q_PRIVATE_SLOT(d, void updateToolBox())
|
||||
Q_PRIVATE_SLOT(d, void themeChanged())
|
||||
Q_PRIVATE_SLOT(d, void sourceAppletRemoved())
|
||||
Q_PRIVATE_SLOT(d, void actionDestroyed(QObject*))
|
||||
|
||||
ExtenderItemPrivate * const d;
|
||||
|
||||
friend class Applet;
|
||||
friend class Extender;
|
||||
friend class ExtenderPrivate;
|
||||
friend class ExtenderItemPrivate;
|
||||
};
|
||||
} // namespace Plasma
|
||||
#endif // PLASMA_EXTENDERITEM_H
|
|
@ -35,13 +35,10 @@
|
|||
#include <netwm.h>
|
||||
|
||||
#include "plasma/private/applet_p.h"
|
||||
#include "plasma/private/extenderitemmimedata_p.h"
|
||||
#include "plasma/corona.h"
|
||||
#include "plasma/containment.h"
|
||||
#include "plasma/private/containment_p.h"
|
||||
#include "plasma/dialog.h"
|
||||
#include "plasma/extenders/extender.h"
|
||||
#include "plasma/extenders/extenderitem.h"
|
||||
#include "plasma/theme.h"
|
||||
#include "plasma/tooltipmanager.h"
|
||||
#include "plasma/widgets/iconwidget.h"
|
||||
|
@ -142,9 +139,8 @@ QGraphicsWidget *PopupApplet::graphicsWidget()
|
|||
{
|
||||
if (d->graphicsWidget) {
|
||||
return d->graphicsWidget.data();
|
||||
} else {
|
||||
return static_cast<Applet*>(this)->d->extender.data();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void PopupApplet::setGraphicsWidget(QGraphicsWidget *graphicsWidget)
|
||||
|
@ -164,32 +160,10 @@ void PopupApplet::setGraphicsWidget(QGraphicsWidget *graphicsWidget)
|
|||
d->graphicsWidget = graphicsWidget;
|
||||
}
|
||||
|
||||
void PopupAppletPrivate::checkExtenderAppearance(Plasma::FormFactor f)
|
||||
{
|
||||
Extender *extender = qobject_cast<Extender*>(q->graphicsWidget());
|
||||
if (extender) {
|
||||
if (f != Plasma::Horizontal && f != Plasma::Vertical) {
|
||||
extender->setAppearance(Extender::NoBorders);
|
||||
} else if (q->location() == TopEdge) {
|
||||
extender->setAppearance(Extender::TopDownStacked);
|
||||
} else {
|
||||
extender->setAppearance(Extender::BottomUpStacked);
|
||||
}
|
||||
|
||||
if (dialogPtr) {
|
||||
dialogPtr.data()->setGraphicsWidget(extender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints)
|
||||
{
|
||||
Plasma::FormFactor f = q->formFactor();
|
||||
|
||||
if (constraints & Plasma::LocationConstraint) {
|
||||
checkExtenderAppearance(f);
|
||||
}
|
||||
|
||||
if (constraints & Plasma::FormFactorConstraint ||
|
||||
constraints & Plasma::StartupCompletedConstraint ||
|
||||
(constraints & Plasma::SizeConstraint &&
|
||||
|
@ -211,10 +185,6 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints)
|
|||
minimum = gWidget->minimumSize();
|
||||
// our layout may have been replaced on us in the call to graphicsWidget!
|
||||
lay = dynamic_cast<QGraphicsLinearLayout *>(q->layout());
|
||||
|
||||
if (!(constraints & LocationConstraint)) {
|
||||
checkExtenderAppearance(f);
|
||||
}
|
||||
} else if (qWidget) {
|
||||
minimum = qWidget->minimumSizeHint();
|
||||
}
|
||||
|
@ -382,7 +352,7 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints)
|
|||
}
|
||||
|
||||
//no longer use Qt::Popup since that seems to cause a lot of problem when you drag
|
||||
//stuff out of your Dialog (extenders). Monitor WindowDeactivate events so we can
|
||||
//stuff out of your Dialog. Monitor WindowDeactivate events so we can
|
||||
//emulate the same kind of behavior as Qt::Popup (close when you click somewhere
|
||||
//else.
|
||||
|
||||
|
@ -519,50 +489,6 @@ bool PopupApplet::eventFilter(QObject *watched, QEvent *event)
|
|||
return Applet::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
//FIXME: some duplication between the drag events... maybe add some simple helper function?
|
||||
void PopupApplet::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
|
||||
const ExtenderItemMimeData *mimeData =
|
||||
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
|
||||
if (mimeData && qobject_cast<Extender*>(graphicsWidget())) {
|
||||
event->accept();
|
||||
showPopup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PopupApplet::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
|
||||
const ExtenderItemMimeData *mimeData =
|
||||
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
|
||||
if (mimeData && qobject_cast<Extender*>(graphicsWidget())) {
|
||||
//We want to hide the popup if we're not moving onto the popup AND it is not the popup
|
||||
//we started.
|
||||
if (d->dialogPtr && !d->dialogPtr.data()->geometry().contains(event->screenPos()) &&
|
||||
mimeData->extenderItem()->extender() != qobject_cast<Extender*>(graphicsWidget())) {
|
||||
//We actually try to hide the popup, with a call to showPopup, with a smal timeout,
|
||||
//so if the user moves into the popup fast enough, it remains open (the extender
|
||||
//will call showPopup which will cancel the timeout.
|
||||
showPopup(250);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PopupApplet::dropEvent(QGraphicsSceneDragDropEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
|
||||
const ExtenderItemMimeData *mimeData =
|
||||
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
|
||||
if (mimeData && qobject_cast<Extender*>(graphicsWidget())) {
|
||||
mimeData->extenderItem()->setExtender(extender());
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PopupApplet::showPopup(uint popupDuration)
|
||||
{
|
||||
// use autohideTimer to store when the next show should be
|
||||
|
@ -748,18 +674,6 @@ void PopupAppletPrivate::internalTogglePopup(bool fromActivatedSignal)
|
|||
|
||||
dialog->clearFocus();
|
||||
} else {
|
||||
if (q->graphicsWidget() &&
|
||||
q->graphicsWidget() == static_cast<Applet*>(q)->d->extender.data() &&
|
||||
static_cast<Applet*>(q)->d->extender.data()->isEmpty()) {
|
||||
// nothing to show, so let's not.
|
||||
if (!fromActivatedSignal) {
|
||||
QObject::disconnect(q, SIGNAL(activate()), q, SLOT(appletActivated()));
|
||||
emit q->activate();
|
||||
QObject::connect(q, SIGNAL(activate()), q, SLOT(appletActivated()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ToolTipManager::self()->hide(q);
|
||||
showDialogTimer.start(0, q);
|
||||
}
|
||||
|
|
|
@ -36,17 +36,12 @@ class PopupAppletPrivate;
|
|||
|
||||
/**
|
||||
* Allows applets to automatically 'collapse' into an icon when put in an panel, and is a convenient
|
||||
* base class for any applet that wishes to use extenders.
|
||||
* base class for any applet.
|
||||
*
|
||||
* Applets that subclass this class should implement either widget() or graphicsWidget() to return a
|
||||
* widget that will be displayed in the applet if the applet is in a Planar or MediaCenter form
|
||||
* factor. If the applet is put in a panel, an icon will be displayed instead, which shows the
|
||||
* widget in a popup when clicked.
|
||||
*
|
||||
* If you use this class as a base class for your extender using applet, the extender will
|
||||
* automatically be used for the popup; reimplementing graphicsWidget() is unnecessary in this case.
|
||||
* If you need a popup that does not steal window focus when openend or used, set window flag
|
||||
* Qt::X11BypassWindowManagerHint the widget returned by widget() or graphicsWidget().
|
||||
*/
|
||||
|
||||
class PLASMA_EXPORT PopupApplet : public Plasma::Applet
|
||||
|
@ -190,21 +185,6 @@ protected:
|
|||
*/
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsLayoutItem
|
||||
*/
|
||||
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsLayoutItem
|
||||
*/
|
||||
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsLayoutItem
|
||||
*/
|
||||
void dropEvent(QGraphicsSceneDragDropEvent *event);
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsLayoutItem
|
||||
*/
|
||||
|
@ -223,7 +203,6 @@ private:
|
|||
|
||||
friend class Applet;
|
||||
friend class AppletPrivate;
|
||||
friend class Extender;
|
||||
friend class PopupAppletPrivate;
|
||||
PopupAppletPrivate * const d;
|
||||
};
|
||||
|
|
|
@ -141,7 +141,6 @@ public:
|
|||
Applet *q;
|
||||
|
||||
// applet attributes
|
||||
QWeakPointer<Extender> extender;
|
||||
Applet::BackgroundHints preferredBackgroundHints;
|
||||
Applet::BackgroundHints backgroundHints;
|
||||
Plasma::AspectRatioMode aspectRatioMode;
|
||||
|
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
* Copyright 2008 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef LIBS_PLASMA_EXTENDER_P_H
|
||||
#define LIBS_PLASMA_EXTENDER_P_H
|
||||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include <QtCore/qpoint.h>
|
||||
#include "plasma/extenders/extender.h"
|
||||
|
||||
#include <QGraphicsGridLayout>
|
||||
#include <QGraphicsLinearLayout>
|
||||
#include <QGraphicsWidget>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class Applet;
|
||||
class Extender;
|
||||
class ExtenderGroup;
|
||||
class ExtenderItem;
|
||||
class Label;
|
||||
class ScrollWidget;
|
||||
class Svg;
|
||||
|
||||
class Spacer : public QGraphicsWidget
|
||||
{
|
||||
public:
|
||||
Spacer(QGraphicsItem *parent);
|
||||
~Spacer();
|
||||
|
||||
void setMargins(qreal left, qreal top, qreal right, qreal bottom);
|
||||
|
||||
protected:
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * widget = 0);
|
||||
|
||||
|
||||
private:
|
||||
qreal m_left;
|
||||
qreal m_top;
|
||||
qreal m_right;
|
||||
qreal m_bottom;
|
||||
};
|
||||
|
||||
class ExtenderPrivate
|
||||
{
|
||||
public:
|
||||
ExtenderPrivate(Applet *applet, Extender *q);
|
||||
~ExtenderPrivate();
|
||||
|
||||
void addExtenderItem(ExtenderItem *item, const QPointF &pos = QPointF(-1, -1));
|
||||
void extenderItemDestroyed(Plasma::ExtenderItem *item);
|
||||
void viewportGeometryChanged(const QRectF &rect);
|
||||
void removeExtenderItem(ExtenderItem *item);
|
||||
int insertIndexFromPos(const QPointF &pos) const;
|
||||
void loadExtenderItems();
|
||||
void updateBorders();
|
||||
void delayItemAddedEvent();
|
||||
void updateEmptyExtenderLabel();
|
||||
void adjustMinimumSize();
|
||||
void setPositionFromDragPosition(const QPointF &pos);
|
||||
ExtenderGroup *findGroup(const QString &name) const;
|
||||
void setDisabledBordersHint(const FrameSvg::EnabledBorders borders);
|
||||
void adjustSize();
|
||||
|
||||
Extender *q;
|
||||
|
||||
QWeakPointer<Applet> applet;
|
||||
ScrollWidget *scrollWidget;
|
||||
QGraphicsWidget *mainWidget;
|
||||
QGraphicsLinearLayout *layout;
|
||||
FrameSvg *background;
|
||||
FrameSvg::EnabledBorders disabledBordersHint;
|
||||
|
||||
int currentSpacerIndex;
|
||||
Spacer *spacerWidget;
|
||||
|
||||
QString emptyExtenderMessage;
|
||||
Label *emptyExtenderLabel;
|
||||
|
||||
QList<ExtenderItem*> attachedExtenderItems;
|
||||
|
||||
Extender::Appearance appearance;
|
||||
|
||||
static QGraphicsGridLayout *s_popupLayout;
|
||||
|
||||
bool destroying;
|
||||
bool scrollbarVisible;
|
||||
|
||||
QHash<ExtenderItem *, QPointF> pendingItems;
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif // LIBS_PLASMA_EXTENDER_P_H
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* Copyright 2008 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "extenderapplet_p.h"
|
||||
|
||||
#include "plasma/extenders/extender.h"
|
||||
#include "plasma/extenders/extenderitem.h"
|
||||
|
||||
#include <QGraphicsLinearLayout>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
ExtenderApplet::ExtenderApplet(QObject *parent, const QVariantList &args)
|
||||
: PopupApplet(parent, args)
|
||||
{
|
||||
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
}
|
||||
|
||||
ExtenderApplet::~ExtenderApplet()
|
||||
{
|
||||
if (destroyed()) {
|
||||
disconnect(extender(), SIGNAL(itemDetached(Plasma::ExtenderItem*)),
|
||||
this, SLOT(itemDetached(Plasma::ExtenderItem*)));
|
||||
foreach (ExtenderItem *item, extender()->attachedItems()) {
|
||||
item->returnToSource();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ExtenderApplet::init()
|
||||
{
|
||||
setPopupIcon("utilities-desktop-extra");
|
||||
setAspectRatioMode(Plasma::IgnoreAspectRatio);
|
||||
|
||||
extender()->setAppearance(Extender::NoBorders);
|
||||
|
||||
connect(extender(), SIGNAL(itemDetached(Plasma::ExtenderItem*)),
|
||||
this, SLOT(itemDetached(Plasma::ExtenderItem*)));
|
||||
connect(extender(), SIGNAL(geometryChanged()),
|
||||
this, SLOT(extenderGeometryChanged()));
|
||||
}
|
||||
|
||||
void ExtenderApplet::itemDetached(Plasma::ExtenderItem *)
|
||||
{
|
||||
if (extender()->attachedItems().isEmpty()) {
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void ExtenderApplet::extenderGeometryChanged()
|
||||
{
|
||||
if (formFactor() != Plasma::Horizontal &&
|
||||
formFactor() != Plasma::Vertical) {
|
||||
|
||||
qreal left, top, right, bottom;
|
||||
getContentsMargins(&left, &top, &right, &bottom);
|
||||
QSizeF margins(left + right, top + bottom);
|
||||
|
||||
setMinimumSize(extender()->minimumSize() + margins);
|
||||
setMaximumSize(extender()->maximumSize() + margins);
|
||||
setPreferredSize(extender()->preferredSize() + margins);
|
||||
|
||||
updateGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#include "moc_extenderapplet_p.cpp"
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* Copyright 2008 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef EXTENDERAPPLET_H
|
||||
#define EXTENDERAPPLET_H
|
||||
|
||||
#include "popupapplet.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
/**
|
||||
* This class is used as a 'host' for detached extender items. When an extender item is dropped
|
||||
* somewhere, this applet is added at the location where the item is dropped, and the item is added
|
||||
* to its extender.
|
||||
*/
|
||||
class ExtenderApplet : public Plasma::PopupApplet
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ExtenderApplet(QObject *parent, const QVariantList &args);
|
||||
~ExtenderApplet();
|
||||
|
||||
void init();
|
||||
|
||||
public Q_SLOTS:
|
||||
void itemDetached(Plasma::ExtenderItem *);
|
||||
void extenderGeometryChanged();
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
* Copyright 2009 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_EXTENDERGROUPPRIVATE_H
|
||||
#define PLASMA_EXTENDERGROUPPRIVATE_H
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class ScrollWidget;
|
||||
class ExtenderGroup;
|
||||
class ExtenderItem;
|
||||
class Svg;
|
||||
class Spacer;
|
||||
|
||||
class ExtenderGroupPrivate
|
||||
{
|
||||
public:
|
||||
ExtenderGroupPrivate(ExtenderGroup *group);
|
||||
~ExtenderGroupPrivate();
|
||||
|
||||
void addItemToGroup(Plasma::ExtenderItem *item, const QPointF &pos = QPointF(-1, -1));
|
||||
void removeItemFromGroup(Plasma::ExtenderItem *item);
|
||||
void themeChanged();
|
||||
int insertIndexFromPos(const QPointF &pos) const;
|
||||
|
||||
Plasma::ExtenderGroup *q;
|
||||
Spacer *spacerWidget;
|
||||
Plasma::Svg *svg;
|
||||
QGraphicsWidget *childsWidget;
|
||||
QGraphicsLinearLayout *layout;
|
||||
QTimer *resizeTimer;
|
||||
bool collapsed;
|
||||
bool autoHide;
|
||||
bool autoCollapse;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,102 +0,0 @@
|
|||
/*
|
||||
* Copyright 2008 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef LIBS_PLASMA_EXTENDERITEM_P_H
|
||||
#define LIBS_PLASMA_EXTENDERITEM_P_H
|
||||
|
||||
#include <QtCore/qpoint.h>
|
||||
#include <QPoint>
|
||||
#include <QRect>
|
||||
#include <QString>
|
||||
|
||||
#include <QGraphicsItem>
|
||||
#include <QGraphicsWidget>
|
||||
#include <QGraphicsLinearLayout>
|
||||
#include <QGraphicsView>
|
||||
#include <QTimer>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class Applet;
|
||||
class ExtenderGroup;
|
||||
class ExtenderItem;
|
||||
class Extender;
|
||||
class Label;
|
||||
class IconWidget;
|
||||
class FrameSvg;
|
||||
class ExtenderItemToolbox;
|
||||
|
||||
class ExtenderItemPrivate
|
||||
{
|
||||
public:
|
||||
ExtenderItemPrivate(ExtenderItem *extenderItem, Extender *hostExtender);
|
||||
~ExtenderItemPrivate();
|
||||
|
||||
QRectF dragHandleRect();
|
||||
void toggleCollapse();
|
||||
void updateToolBox();
|
||||
Applet *hostApplet() const;
|
||||
void themeChanged();
|
||||
void sourceAppletRemoved();
|
||||
void resizeContent(const QSizeF &newSize);
|
||||
void actionDestroyed(QObject *o);
|
||||
void updateSizeHints();
|
||||
void setMovable(bool movable);
|
||||
|
||||
ExtenderItem *q;
|
||||
|
||||
QWeakPointer<QGraphicsWidget> widget;
|
||||
|
||||
ExtenderItemToolbox *toolbox;
|
||||
QGraphicsLinearLayout *toolboxLayout;
|
||||
QGraphicsLinearLayout *layout;
|
||||
|
||||
Extender *extender;
|
||||
Applet *sourceApplet;
|
||||
ExtenderGroup *group;
|
||||
|
||||
KConfigGroup config;
|
||||
KSharedConfig::Ptr transientConfig;
|
||||
|
||||
FrameSvg *background;
|
||||
|
||||
IconWidget *collapseIcon;
|
||||
Label *titleLabel;
|
||||
|
||||
QHash<QString, QAction*> actions;
|
||||
QList<QAction*> actionsInOrder;
|
||||
|
||||
QString name;
|
||||
QString iconName;
|
||||
|
||||
uint extenderItemId;
|
||||
QTimer *expirationTimer;
|
||||
|
||||
bool dragStarted : 1;
|
||||
bool destroyActionVisibility : 1;
|
||||
bool collapsed : 1;
|
||||
bool transient : 1;
|
||||
|
||||
static uint s_maxExtenderItemId;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // LIB_PLASMA_EXTENDERITEM_P_H
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright 2008 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "extenderitemmimedata_p.h"
|
||||
|
||||
#include "plasma/extenders/extenderitem.h"
|
||||
|
||||
#include <QMimeData>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
ExtenderItemMimeData::ExtenderItemMimeData() : QMimeData()
|
||||
{
|
||||
}
|
||||
|
||||
ExtenderItemMimeData::~ExtenderItemMimeData()
|
||||
{
|
||||
}
|
||||
|
||||
QStringList ExtenderItemMimeData::formats() const
|
||||
{
|
||||
return QStringList(mimeType());
|
||||
}
|
||||
|
||||
bool ExtenderItemMimeData::hasFormat(const QString &type) const
|
||||
{
|
||||
return (type == mimeType());
|
||||
}
|
||||
|
||||
void ExtenderItemMimeData::setExtenderItem(ExtenderItem *item)
|
||||
{
|
||||
m_extenderItem = item;
|
||||
}
|
||||
|
||||
void ExtenderItemMimeData::setPointerOffset(const QPoint &p)
|
||||
{
|
||||
m_offset = p;
|
||||
}
|
||||
|
||||
QPoint ExtenderItemMimeData::pointerOffset() const
|
||||
{
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
ExtenderItem *ExtenderItemMimeData::extenderItem() const
|
||||
{
|
||||
return m_extenderItem;
|
||||
}
|
||||
|
||||
QString ExtenderItemMimeData::mimeType()
|
||||
{
|
||||
return "plasma/extenderitem";
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* Copyright 2008 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef EXTENDERITEMMIMEDATA_H
|
||||
#define EXTENDERITEMMIMEDATA_H
|
||||
|
||||
#include <QMimeData>
|
||||
#include <QPoint>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class ExtenderItem;
|
||||
|
||||
/**
|
||||
* This class is used to deliver pointers to ExtenderItems to drag/drop event handlers.
|
||||
*/
|
||||
class ExtenderItemMimeData : public QMimeData
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ExtenderItemMimeData();
|
||||
~ExtenderItemMimeData();
|
||||
|
||||
QStringList formats() const;
|
||||
bool hasFormat(const QString &mimeType) const;
|
||||
|
||||
void setExtenderItem(ExtenderItem *item);
|
||||
ExtenderItem *extenderItem() const;
|
||||
|
||||
static QString mimeType();
|
||||
|
||||
void setPointerOffset(const QPoint &p);
|
||||
QPoint pointerOffset() const;
|
||||
|
||||
private:
|
||||
ExtenderItem *m_extenderItem;
|
||||
QPoint m_offset;
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif
|
|
@ -45,7 +45,6 @@ public:
|
|||
void restoreDialogSize();
|
||||
void updateDialogPosition(bool move = true);
|
||||
void popupConstraintsEvent(Plasma::Constraints constraints);
|
||||
void checkExtenderAppearance(Plasma::FormFactor f);
|
||||
KConfigGroup popupConfigGroup();
|
||||
void appletActivated();
|
||||
void statusChange(Plasma::ItemStatus status);
|
||||
|
|
Loading…
Add table
Reference in a new issue