2007-03-01 20:58:19 +01:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2007 by Alexander Wiedenbruch <mail@wiedenbruch.de>
|
2007-05-22 18:48:34 +02:00
|
|
|
* and Matias Valdenegro <mvaldenegro@informatica.utem.cl>
|
2007-03-01 20:58:19 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-09-14 22:17:11 +02:00
|
|
|
* it under the terms of the GNU Library General Public License as
|
2007-09-14 21:06:18 +02:00
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
2007-03-01 20:58:19 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2007-05-22 18:48:34 +02:00
|
|
|
|
2007-05-30 18:47:36 +02:00
|
|
|
#include "widget.h"
|
|
|
|
|
2007-08-05 16:24:24 +02:00
|
|
|
#include <cmath>
|
2007-08-05 14:58:40 +02:00
|
|
|
#include <limits>
|
2007-07-23 00:16:40 +02:00
|
|
|
|
2007-09-13 21:33:44 +02:00
|
|
|
#include <QApplication>
|
2007-12-08 04:35:11 +01:00
|
|
|
#include <QGraphicsScene>
|
2007-12-21 06:33:17 +01:00
|
|
|
#include <QGraphicsSceneHoverEvent>
|
2007-12-08 04:35:11 +01:00
|
|
|
#include <QGraphicsView>
|
2007-12-21 06:33:17 +01:00
|
|
|
#include <QHelpEvent>
|
2007-09-13 21:33:44 +02:00
|
|
|
#include <QList>
|
2007-08-01 22:51:27 +02:00
|
|
|
#include <QPainter>
|
2007-09-10 21:06:58 +02:00
|
|
|
#include <QStyleOptionGraphicsItem>
|
2008-04-13 15:23:39 +02:00
|
|
|
#include <QGraphicsLayout>
|
|
|
|
#include <QGraphicsLinearLayout>
|
2007-05-23 19:18:43 +02:00
|
|
|
|
2007-08-05 14:58:40 +02:00
|
|
|
#include <KDebug>
|
|
|
|
|
2008-02-18 00:02:46 +01:00
|
|
|
#include "plasma/applet.h"
|
|
|
|
|
2007-08-01 22:51:27 +02:00
|
|
|
#include "plasma/plasma.h"
|
2008-01-21 12:42:08 +01:00
|
|
|
#include "plasma/view.h"
|
|
|
|
#include "plasma/containment.h"
|
2007-03-01 20:58:19 +01:00
|
|
|
|
2007-03-02 06:27:33 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2007-03-03 14:13:39 +01:00
|
|
|
class Widget::Private
|
|
|
|
{
|
|
|
|
public:
|
2007-07-12 20:11:50 +02:00
|
|
|
Private()
|
2008-02-29 18:50:57 +01:00
|
|
|
: minimumSize(0,0),
|
|
|
|
maximumSize(std::numeric_limits<qreal>::infinity(),
|
|
|
|
std::numeric_limits<qreal>::infinity()),
|
2008-04-14 17:15:26 +02:00
|
|
|
wasMovable(false)
|
|
|
|
//toolTip(0)
|
2007-07-12 20:11:50 +02:00
|
|
|
{ }
|
2008-02-05 19:26:17 +01:00
|
|
|
|
|
|
|
~Private()
|
|
|
|
{
|
2008-04-14 17:15:26 +02:00
|
|
|
//delete toolTip;
|
2008-02-05 19:26:17 +01:00
|
|
|
}
|
2007-05-22 18:48:34 +02:00
|
|
|
|
2008-02-29 18:50:57 +01:00
|
|
|
QSizeF minimumSize;
|
|
|
|
QSizeF maximumSize;
|
|
|
|
|
2007-10-24 08:54:26 +02:00
|
|
|
bool wasMovable;
|
|
|
|
|
2007-08-01 22:51:27 +02:00
|
|
|
bool shouldPaint(QPainter *painter, const QTransform &transform);
|
2008-04-14 17:15:26 +02:00
|
|
|
//ToolTipData *toolTip;
|
2007-03-03 14:13:39 +01:00
|
|
|
};
|
2007-03-01 20:58:19 +01:00
|
|
|
|
2007-08-01 22:51:27 +02:00
|
|
|
bool Widget::Private::shouldPaint(QPainter *painter, const QTransform &transform)
|
|
|
|
{
|
2007-10-01 07:06:51 +02:00
|
|
|
Q_UNUSED(painter)
|
|
|
|
Q_UNUSED(transform)
|
|
|
|
//qreal zoomLevel = painter->transform().m11() / transform.m11();
|
2007-08-28 21:12:13 +02:00
|
|
|
//return (fabs(zoomLevel - scalingFactor(Plasma::DesktopZoom))) < std::numeric_limits<double>::epsilon();
|
|
|
|
return true;
|
2007-08-01 22:51:27 +02:00
|
|
|
}
|
|
|
|
|
2008-02-29 18:50:57 +01:00
|
|
|
Widget::Widget(QGraphicsItem *parent, QObject* parentObject)
|
2008-04-13 15:23:39 +02:00
|
|
|
: QGraphicsWidget(parent),
|
2007-03-03 14:13:39 +01:00
|
|
|
d(new Private)
|
2007-03-01 20:58:19 +01:00
|
|
|
{
|
2007-07-25 01:31:52 +02:00
|
|
|
setFlag(QGraphicsItem::ItemClipsToShape, true);
|
2007-07-28 21:27:09 +02:00
|
|
|
setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
|
2007-03-01 20:58:19 +01:00
|
|
|
}
|
|
|
|
|
2007-03-03 14:13:39 +01:00
|
|
|
Widget::~Widget()
|
2007-03-01 20:58:19 +01:00
|
|
|
{
|
2008-04-14 16:50:02 +02:00
|
|
|
#ifdef TOOLTIPMANAGER
|
2008-01-07 05:39:36 +01:00
|
|
|
if (ToolTip::self()->currentWidget() == this) {
|
|
|
|
ToolTip::self()->hide();
|
2007-12-31 02:45:48 +01:00
|
|
|
}
|
2008-04-14 16:50:02 +02:00
|
|
|
#endif
|
2007-03-03 14:13:39 +01:00
|
|
|
delete d;
|
2007-03-01 20:58:19 +01:00
|
|
|
}
|
2007-03-02 06:27:33 +01:00
|
|
|
|
2007-08-01 22:51:27 +02:00
|
|
|
|
2008-04-14 16:50:02 +02:00
|
|
|
#ifdef TOOLTIPMANAGER
|
2008-02-05 19:26:17 +01:00
|
|
|
const ToolTipData* Widget::toolTip() const
|
2007-12-21 06:33:17 +01:00
|
|
|
{
|
|
|
|
return d->toolTip;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::setToolTip(const ToolTipData &tip)
|
|
|
|
{
|
2008-02-05 19:26:17 +01:00
|
|
|
if (tip.image.isNull() &&
|
|
|
|
tip.subText.isEmpty() &&
|
|
|
|
tip.mainText.isEmpty()) {
|
|
|
|
delete d->toolTip;
|
|
|
|
d->toolTip = 0;
|
2008-02-05 21:10:53 +01:00
|
|
|
return;
|
2008-02-05 19:26:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!d->toolTip) {
|
|
|
|
d->toolTip = new ToolTipData;
|
|
|
|
}
|
|
|
|
|
|
|
|
*d->toolTip = tip;
|
|
|
|
|
2008-04-08 09:20:36 +02:00
|
|
|
// this does a check to ensure the current widget is us
|
|
|
|
ToolTip::self()->setData(this, *d->toolTip);
|
2007-12-21 06:33:17 +01:00
|
|
|
}
|
|
|
|
|
2008-04-02 01:01:52 +02:00
|
|
|
void Widget::updateToolTip(bool update)
|
2008-03-18 02:39:28 +01:00
|
|
|
{
|
2008-04-08 09:20:36 +02:00
|
|
|
Q_UNUSED(update)
|
2008-03-18 02:39:28 +01:00
|
|
|
}
|
|
|
|
|
2007-12-30 11:45:21 +01:00
|
|
|
bool Widget::sceneEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::GraphicsSceneHoverMove:
|
|
|
|
// If the tooltip isn't visible, run through showing the tooltip again
|
|
|
|
// so that it only becomes visible after a stationary hover
|
2008-01-07 05:39:36 +01:00
|
|
|
if (ToolTip::self()->isVisible()) {
|
2007-12-30 11:45:21 +01:00
|
|
|
break;
|
|
|
|
}
|
2007-12-21 06:33:17 +01:00
|
|
|
|
2007-12-30 11:45:21 +01:00
|
|
|
case QEvent::GraphicsSceneHoverEnter:
|
|
|
|
{
|
|
|
|
// Check that there is a tooltip to show
|
2008-02-05 19:26:17 +01:00
|
|
|
if (!d->toolTip) {
|
2007-12-30 11:45:21 +01:00
|
|
|
break;
|
|
|
|
}
|
2007-12-30 11:17:33 +01:00
|
|
|
|
2007-12-30 11:45:21 +01:00
|
|
|
// If the mouse is in the widget's area at the time that it is being
|
|
|
|
// created the widget can receive a hover event before it is fully
|
|
|
|
// initialized, in which case view() will return 0.
|
|
|
|
QGraphicsView *parentView = view();
|
|
|
|
if (parentView) {
|
2008-02-05 19:26:17 +01:00
|
|
|
ToolTip::self()->show(this);
|
2007-12-30 11:45:21 +01:00
|
|
|
}
|
2007-12-22 07:43:05 +01:00
|
|
|
|
2007-12-30 11:45:21 +01:00
|
|
|
break;
|
2007-12-30 11:17:33 +01:00
|
|
|
}
|
|
|
|
|
2007-12-30 11:45:21 +01:00
|
|
|
case QEvent::GraphicsSceneHoverLeave:
|
2008-02-05 19:26:17 +01:00
|
|
|
ToolTip::self()->delayedHide();
|
|
|
|
break;
|
|
|
|
|
2007-12-30 11:45:21 +01:00
|
|
|
case QEvent::GraphicsSceneMousePress:
|
|
|
|
case QEvent::GraphicsSceneWheel:
|
2008-01-07 05:39:36 +01:00
|
|
|
ToolTip::self()->hide();
|
2007-12-21 06:33:17 +01:00
|
|
|
|
2007-12-30 11:45:21 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QGraphicsItem::sceneEvent(event);
|
2007-12-21 06:33:17 +01:00
|
|
|
}
|
2008-04-14 16:50:02 +02:00
|
|
|
#endif
|
2007-03-02 06:27:33 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|