2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2008 by Montel Laurent <montel@kde.org>
|
|
|
|
*
|
|
|
|
* 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_POPUPAPPLET_H
|
|
|
|
#define PLASMA_POPUPAPPLET_H
|
|
|
|
|
|
|
|
#include <plasma/applet.h>
|
|
|
|
#include <plasma/plasma_export.h>
|
2009-07-08 16:55:59 +02:00
|
|
|
#include <plasma/plasma.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
class QGraphicsProxyWidget;
|
|
|
|
class QGraphicsLinearLayout;
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class PopupAppletPrivate;
|
|
|
|
|
|
|
|
/**
|
2011-11-17 14:40:53 +01:00
|
|
|
* Allows applets to automatically 'collapse' into an icon when put in an panel.
|
2008-11-04 00:08:39 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class PLASMA_EXPORT PopupApplet : public Plasma::Applet
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2010-09-13 01:54:30 +02:00
|
|
|
Q_PROPERTY(Qt::AlignmentFlag popupAlignment READ popupAlignment WRITE setPopupAlignment)
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
public:
|
|
|
|
PopupApplet(QObject *parent, const QVariantList &args);
|
|
|
|
~PopupApplet();
|
|
|
|
|
|
|
|
/**
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param icon the icon that has to be displayed when the applet is in a panel.
|
2009-08-02 21:28:05 +02:00
|
|
|
* Passing in a null icon means that the popup applet itself
|
|
|
|
* will provide an interface for when the PopupApplet is not showing
|
|
|
|
* the widget() or graphicsWidget() directly.
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
|
|
|
void setPopupIcon(const QIcon &icon);
|
|
|
|
|
|
|
|
/**
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param icon the icon that has to be displayed when the applet is in a panel.
|
2009-08-02 21:28:05 +02:00
|
|
|
* Passing in an empty QString() means that the popup applet itself
|
|
|
|
* will provide an interface for when the PopupApplet is not showing
|
|
|
|
* the widget() or graphicsWidget() directly.
|
2010-10-19 22:02:51 +02:00
|
|
|
|
|
|
|
* If you set a popup icon you must also set a minimum size of the applet. When the applet
|
2010-06-22 14:27:22 +02:00
|
|
|
* is smaller than this minimum size, it will be displayed as that icon.
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
|
|
|
void setPopupIcon(const QString &iconName);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the icon that is displayed when the applet is in a panel.
|
|
|
|
*/
|
|
|
|
QIcon popupIcon() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implement either this function or graphicsWidget().
|
|
|
|
* @return the widget that will get shown in either a layout, in the applet or in a Dialog,
|
|
|
|
* depending on the form factor of the applet.
|
|
|
|
*/
|
|
|
|
virtual QWidget *widget();
|
2009-07-17 14:31:08 +02:00
|
|
|
void setWidget(QWidget * widget);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implement either this function or widget().
|
|
|
|
* @return the widget that will get shown in either a layout, in the applet or in a Dialog,
|
|
|
|
* depending on the form factor of the applet.
|
2010-10-19 22:02:51 +02:00
|
|
|
* If you set a popup icon you must also set a minimum size of the applet. When the applet
|
2010-06-22 14:27:22 +02:00
|
|
|
* is smaller than this minimum size, it will be displayed as that icon.
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
|
|
|
virtual QGraphicsWidget *graphicsWidget();
|
2009-07-17 14:31:08 +02:00
|
|
|
void setGraphicsWidget(QGraphicsWidget * widget);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
/**
|
2010-09-13 01:54:30 +02:00
|
|
|
* @return the placement of the popup relating to the applet
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
|
|
|
Plasma::PopupPlacement popupPlacement() const;
|
|
|
|
|
2010-09-13 01:54:30 +02:00
|
|
|
/**
|
|
|
|
* Sets the default alignment of the popup relative to the applet
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param alignment the alignment to use; Qt::AlignLeft or Qt::AlignRight
|
2010-09-13 01:54:30 +02:00
|
|
|
* @since 4.6
|
|
|
|
*/
|
|
|
|
void setPopupAlignment(Qt::AlignmentFlag alignment);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the default alignment of the popup relative to the applet
|
|
|
|
* @since 4.6
|
|
|
|
*/
|
|
|
|
Qt::AlignmentFlag popupAlignment() const;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
/**
|
2008-11-27 07:09:00 +01:00
|
|
|
* Sets whether or not the dialog popup that gets created should be a "passive" popup
|
2009-10-23 15:48:29 +02:00
|
|
|
* that does not steal focus from other windows or not.
|
2008-11-27 07:03:53 +01:00
|
|
|
*
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param passive true if the dialog should be treated as a passive popup
|
2008-11-04 00:08:39 +01:00
|
|
|
*/
|
2008-11-27 07:03:53 +01:00
|
|
|
void setPassivePopup(bool passive);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-27 07:09:00 +01:00
|
|
|
/**
|
|
|
|
* @return true if the dialog will be treated as a passive poup
|
|
|
|
*/
|
|
|
|
bool isPassivePopup() const;
|
|
|
|
|
2008-12-29 07:03:43 +01:00
|
|
|
/**
|
|
|
|
* @return true if the applet is popped up
|
|
|
|
*/
|
|
|
|
bool isPopupShowing() const;
|
|
|
|
|
2010-10-19 22:02:51 +02:00
|
|
|
/**
|
|
|
|
* @return true if the applet is collapsed to an icon
|
|
|
|
* @since 4.6
|
|
|
|
*/
|
|
|
|
bool isIconified() const;
|
|
|
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
public Q_SLOTS:
|
|
|
|
/**
|
|
|
|
* Hides the popup.
|
|
|
|
*/
|
|
|
|
void hidePopup();
|
|
|
|
|
2008-11-17 21:03:20 +01:00
|
|
|
/**
|
|
|
|
* Shows the dialog showing the widget if the applet is in a panel.
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param displayTime the time in ms that the popup should be displayed, defaults to 0 which means
|
2008-11-17 21:03:20 +01:00
|
|
|
* always (until the user closes it again, that is).
|
|
|
|
*/
|
|
|
|
void showPopup(uint displayTime = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggles the popup.
|
|
|
|
*/
|
|
|
|
void togglePopup();
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
protected:
|
2008-11-27 07:03:53 +01:00
|
|
|
/**
|
|
|
|
* This event handler can be reimplemented in a subclass to receive an
|
|
|
|
* event before the popup is shown or hidden.
|
2011-06-13 14:47:29 +02:00
|
|
|
* @param show true if the popup is going to be shown, false if the popup
|
2008-11-27 07:03:53 +01:00
|
|
|
* is going to be hidden.
|
|
|
|
* Note that showing and hiding the popup on click is already done in PopupApplet.
|
|
|
|
*/
|
|
|
|
virtual void popupEvent(bool show);
|
|
|
|
|
2010-05-25 20:21:04 +02:00
|
|
|
/**
|
|
|
|
* Reimplemented from QGraphicsLayoutItem
|
|
|
|
*/
|
|
|
|
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reimplemented from QGraphicsLayoutItem
|
|
|
|
*/
|
2008-11-04 00:08:39 +01:00
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
2010-05-25 20:21:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reimplemented from QGraphicsLayoutItem
|
|
|
|
*/
|
2008-11-04 00:08:39 +01:00
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
2010-05-25 20:21:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reimplemented from QGraphicsLayoutItem
|
|
|
|
*/
|
2008-11-04 00:08:39 +01:00
|
|
|
bool eventFilter(QObject *watched, QEvent *event);
|
2010-05-25 20:21:04 +02:00
|
|
|
|
2010-12-14 04:14:14 +01:00
|
|
|
/**
|
|
|
|
* Reimplemented from QGraphicsLayoutItem
|
|
|
|
*/
|
|
|
|
void timerEvent(QTimerEvent *event);
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
private:
|
2009-10-23 15:48:29 +02:00
|
|
|
/**
|
|
|
|
* @internal This constructor is to be used with the Package loading system.
|
|
|
|
*
|
|
|
|
* @param parent a QObject parent; you probably want to pass in 0
|
|
|
|
* @param args a list of strings containing two entries: the service id
|
|
|
|
* and the applet id
|
|
|
|
* @since 4.3
|
|
|
|
*/
|
|
|
|
PopupApplet(const QString &packagePath, uint appletId, const QVariantList &args);
|
|
|
|
|
2008-12-30 03:06:06 +01:00
|
|
|
Q_PRIVATE_SLOT(d, void internalTogglePopup())
|
2008-11-04 00:08:39 +01:00
|
|
|
Q_PRIVATE_SLOT(d, void hideTimedPopup())
|
|
|
|
Q_PRIVATE_SLOT(d, void clearPopupLostFocus())
|
|
|
|
Q_PRIVATE_SLOT(d, void dialogSizeChanged())
|
|
|
|
Q_PRIVATE_SLOT(d, void dialogStatusChanged(bool))
|
2009-06-25 16:13:14 +02:00
|
|
|
Q_PRIVATE_SLOT(d, void updateDialogPosition())
|
2010-04-15 21:25:30 +02:00
|
|
|
Q_PRIVATE_SLOT(d, void appletActivated())
|
2010-05-25 20:21:04 +02:00
|
|
|
Q_PRIVATE_SLOT(d, void iconSizeChanged(int))
|
2011-02-05 02:51:12 +01:00
|
|
|
Q_PRIVATE_SLOT(d, void statusChangeWhileShown(Plasma::ItemStatus status))
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
friend class Applet;
|
2009-08-24 19:27:24 +02:00
|
|
|
friend class AppletPrivate;
|
2010-09-26 22:35:00 +02:00
|
|
|
friend class Extender;
|
2008-11-27 07:03:53 +01:00
|
|
|
friend class PopupAppletPrivate;
|
2008-11-04 00:08:39 +01:00
|
|
|
PopupAppletPrivate * const d;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#endif /* POPUPAPPLET_H */
|
|
|
|
|