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-01-24 16:44:11 +01:00
|
|
|
#include <QDesktopWidget>
|
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-11-19 23:42:56 +01:00
|
|
|
#include "layouts/freelayout.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"
|
2008-02-18 00:02:46 +01:00
|
|
|
#include "plasma/widgets/tooltip_p.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()
|
2007-10-24 08:54:26 +02:00
|
|
|
: minimumSize(0,0),
|
|
|
|
maximumSize(std::numeric_limits<qreal>::infinity(),
|
|
|
|
std::numeric_limits<qreal>::infinity()),
|
|
|
|
opacity(1.0),
|
2008-02-05 19:26:17 +01:00
|
|
|
wasMovable(false),
|
|
|
|
toolTip(0)
|
2007-07-12 20:11:50 +02:00
|
|
|
{ }
|
2008-02-05 19:26:17 +01:00
|
|
|
|
|
|
|
~Private()
|
|
|
|
{
|
|
|
|
delete toolTip;
|
|
|
|
}
|
2007-05-22 18:48:34 +02:00
|
|
|
|
2007-07-27 08:35:39 +02:00
|
|
|
QSizeF minimumSize;
|
|
|
|
QSizeF maximumSize;
|
2007-05-22 18:48:34 +02:00
|
|
|
|
2007-08-13 11:01:00 +02:00
|
|
|
qreal opacity;
|
2007-09-13 07:34:11 +02:00
|
|
|
|
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-02-05 19:26:17 +01:00
|
|
|
ToolTipData *toolTip;
|
2007-03-03 14:13:39 +01:00
|
|
|
};
|
2007-03-01 20:58:19 +01:00
|
|
|
|
2007-08-13 11:01:00 +02:00
|
|
|
QGraphicsItem* Widget::graphicsItem()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2007-12-08 04:35:11 +01:00
|
|
|
QGraphicsView *Widget::view() const
|
|
|
|
{
|
|
|
|
// It's assumed that we won't be visible on more than one view here.
|
|
|
|
// Anything that actually needs view() should only really care about
|
|
|
|
// one of them anyway though.
|
|
|
|
if (!scene()) {
|
|
|
|
return 0;
|
|
|
|
}
|
2007-12-30 12:44:25 +01:00
|
|
|
|
2007-12-08 04:35:11 +01:00
|
|
|
foreach (QGraphicsView *view, scene()->views()) {
|
2007-12-30 12:44:25 +01:00
|
|
|
if (view->sceneRect().intersects(sceneBoundingRect()) ||
|
|
|
|
view->sceneRect().contains(scenePos())) {
|
2007-12-08 04:35:11 +01:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF Widget::mapFromView(const QGraphicsView *view, const QRect &rect) const
|
|
|
|
{
|
|
|
|
// TODO: Confirm that adjusted() is needed and is not covering for some
|
|
|
|
// issue elsewhere
|
|
|
|
return mapFromScene(view->mapToScene(rect)).boundingRect().adjusted(0, 0, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect Widget::mapToView(const QGraphicsView *view, const QRectF &rect) const
|
|
|
|
{
|
|
|
|
// TODO: Confirm that adjusted() is needed and is not covering for some
|
|
|
|
// issue elsewhere
|
|
|
|
return view->mapFromScene(mapToScene(rect)).boundingRect().adjusted(0, 0, -1, -1);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-10-30 22:00:01 +01:00
|
|
|
Widget::Widget(QGraphicsItem *parent, QObject* parentObject)
|
2007-08-17 17:05:01 +02:00
|
|
|
: QObject(parentObject),
|
|
|
|
QGraphicsItem(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);
|
2008-02-15 07:51:37 +01:00
|
|
|
setCacheMode(DeviceCoordinateCache);
|
2007-05-22 18:48:34 +02:00
|
|
|
|
2007-10-30 22:00:01 +01:00
|
|
|
Widget *w = dynamic_cast<Widget *>(parent);
|
|
|
|
if (w) {
|
|
|
|
w->addChild(this);
|
2007-07-12 19:54:58 +02:00
|
|
|
}
|
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-01-07 05:39:36 +01:00
|
|
|
if (ToolTip::self()->currentWidget() == this) {
|
|
|
|
ToolTip::self()->hide();
|
2007-12-31 02:45:48 +01:00
|
|
|
}
|
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-13 11:01:00 +02:00
|
|
|
void Widget::setOpacity(qreal opacity)
|
|
|
|
{
|
|
|
|
d->opacity = opacity;
|
|
|
|
}
|
2007-11-27 07:03:19 +01:00
|
|
|
|
2007-08-16 17:56:00 +02:00
|
|
|
qreal Widget::opacity() const
|
|
|
|
{
|
|
|
|
return d->opacity;
|
|
|
|
}
|
2007-08-13 11:01:00 +02:00
|
|
|
|
2007-09-10 21:06:58 +02:00
|
|
|
void Widget::setCachePaintMode(CachePaintMode mode, const QSize &size)
|
|
|
|
{
|
2008-02-15 07:51:37 +01:00
|
|
|
setCacheMode(CacheMode(mode), size);
|
2007-09-10 21:06:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget::CachePaintMode Widget::cachePaintMode() const
|
|
|
|
{
|
2008-02-15 07:51:37 +01:00
|
|
|
return CachePaintMode(cacheMode());
|
2007-09-10 21:06:58 +02:00
|
|
|
}
|
|
|
|
|
2007-09-10 22:44:24 +02:00
|
|
|
void Widget::update(const QRectF &rect)
|
2007-09-10 21:06:58 +02:00
|
|
|
{
|
2007-09-10 22:44:24 +02:00
|
|
|
QGraphicsItem::update(rect);
|
2007-09-10 21:06:58 +02:00
|
|
|
}
|
|
|
|
|
2007-05-22 18:48:34 +02:00
|
|
|
Qt::Orientations Widget::expandingDirections() const
|
|
|
|
{
|
2007-08-31 17:32:10 +02:00
|
|
|
return Qt::Horizontal | Qt::Vertical;
|
2007-05-22 18:48:34 +02:00
|
|
|
}
|
|
|
|
|
2008-02-18 00:02:46 +01:00
|
|
|
void Widget::setMinimumSize(const QSizeF& newMin)
|
2007-05-22 18:48:34 +02:00
|
|
|
{
|
2008-02-18 00:02:46 +01:00
|
|
|
d->minimumSize = newMin;
|
|
|
|
QSizeF s = size();
|
|
|
|
if (s != s.expandedTo(newMin)) {
|
|
|
|
setGeometry(QRectF(pos(), s.expandedTo(newMin)));
|
2007-11-28 19:41:21 +01:00
|
|
|
}
|
2007-05-22 18:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF Widget::minimumSize() const
|
|
|
|
{
|
2007-07-27 08:35:39 +02:00
|
|
|
return d->minimumSize;
|
|
|
|
}
|
|
|
|
|
2008-02-18 00:02:46 +01:00
|
|
|
void Widget::setMaximumSize(const QSizeF& newMax)
|
2007-07-27 08:35:39 +02:00
|
|
|
{
|
2008-02-18 00:02:46 +01:00
|
|
|
d->maximumSize = newMax;
|
|
|
|
QSizeF s = size();
|
|
|
|
if (s != s.boundedTo(newMax)) {
|
|
|
|
setGeometry(QRectF(pos(), s.boundedTo(newMax)));
|
2007-11-28 19:41:21 +01:00
|
|
|
}
|
2007-07-27 08:35:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF Widget::maximumSize() const
|
|
|
|
{
|
|
|
|
return d->maximumSize;
|
2007-05-22 18:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Widget::hasHeightForWidth() const
|
|
|
|
{
|
2007-07-12 19:54:58 +02:00
|
|
|
return false;
|
2007-05-22 18:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal Widget::heightForWidth(qreal w) const
|
|
|
|
{
|
2007-07-12 19:54:58 +02:00
|
|
|
Q_UNUSED(w);
|
2007-05-22 18:48:34 +02:00
|
|
|
|
2007-07-12 19:54:58 +02:00
|
|
|
return -1.0;
|
2007-05-22 18:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Widget::hasWidthForHeight() const
|
|
|
|
{
|
2007-07-12 19:54:58 +02:00
|
|
|
return false;
|
2007-05-22 18:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal Widget::widthForHeight(qreal h) const
|
|
|
|
{
|
2007-07-12 19:54:58 +02:00
|
|
|
Q_UNUSED(h);
|
2007-05-22 18:48:34 +02:00
|
|
|
|
2007-07-12 19:54:58 +02:00
|
|
|
return -1.0;
|
2007-05-22 18:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QRectF Widget::geometry() const
|
|
|
|
{
|
2008-02-18 00:02:46 +01:00
|
|
|
return QRectF(pos(), size());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::setSize(const QSizeF &s)
|
|
|
|
{
|
|
|
|
LayoutItem::setSize(s);
|
2007-07-23 00:16:40 +02:00
|
|
|
}
|
|
|
|
|
2007-05-22 18:48:34 +02:00
|
|
|
void Widget::setGeometry(const QRectF& geometry)
|
|
|
|
{
|
2008-02-18 00:02:46 +01:00
|
|
|
setPos(geometry.topLeft());
|
|
|
|
if (geometry.size().width() > 0 && geometry.size().height() > 0 && size() != geometry.size()) {
|
2007-08-13 11:01:00 +02:00
|
|
|
prepareGeometryChange();
|
2007-08-17 18:04:49 +02:00
|
|
|
qreal width = qBound(d->minimumSize.width(), geometry.size().width(), d->maximumSize.width());
|
|
|
|
qreal height = qBound(d->minimumSize.height(), geometry.size().height(), d->maximumSize.height());
|
|
|
|
|
2008-02-18 00:02:46 +01:00
|
|
|
setSize(QSizeF(width, height));
|
|
|
|
|
|
|
|
qreal xd = topLeft().x();
|
|
|
|
qreal yd = topLeft().y();
|
|
|
|
|
|
|
|
if (xd < 0) {
|
|
|
|
width -= xd;
|
|
|
|
xd = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (yd < 0) {
|
|
|
|
height -= yd;
|
|
|
|
yd = 0;
|
|
|
|
}
|
2007-08-17 18:04:49 +02:00
|
|
|
|
2007-09-13 07:34:11 +02:00
|
|
|
if (layout()) {
|
2008-02-18 00:02:46 +01:00
|
|
|
QRectF r(QPointF(xd, yd), QSizeF(width, height));
|
|
|
|
r = adjustToMargins(r);
|
|
|
|
layout()->setGeometry(r);
|
|
|
|
/*if (qobject_cast<Plasma::Applet*>(this)) {
|
|
|
|
kDebug() << (QObject*)this << this->geometry() << this->topLeft()
|
|
|
|
<< "layout geometry is now" << r << margin(RightMargin);
|
|
|
|
}*/
|
2007-09-13 07:34:11 +02:00
|
|
|
}
|
2007-11-04 06:36:39 +01:00
|
|
|
|
|
|
|
if (managingLayout()) {
|
|
|
|
managingLayout()->invalidate();
|
|
|
|
}
|
2007-08-13 11:01:00 +02:00
|
|
|
}
|
2007-08-31 17:32:10 +02:00
|
|
|
|
2007-07-12 19:54:58 +02:00
|
|
|
update();
|
2007-05-22 18:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::updateGeometry()
|
|
|
|
{
|
2007-10-01 07:06:51 +02:00
|
|
|
if (managingLayout()) {
|
2007-09-08 16:01:03 +02:00
|
|
|
managingLayout()->invalidate();
|
2007-10-11 05:30:50 +02:00
|
|
|
} else {
|
|
|
|
setGeometry(QRectF(pos(), sizeHint()));
|
2007-09-08 16:01:03 +02:00
|
|
|
}
|
2007-05-22 18:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF Widget::sizeHint() const
|
|
|
|
{
|
2007-08-17 17:05:01 +02:00
|
|
|
if (layout()) {
|
|
|
|
return layout()->sizeHint();
|
|
|
|
} else {
|
2008-02-18 00:02:46 +01:00
|
|
|
return size();
|
2007-08-17 17:05:01 +02:00
|
|
|
}
|
2007-08-03 20:56:14 +02:00
|
|
|
}
|
|
|
|
|
2007-09-13 21:33:44 +02:00
|
|
|
QFont Widget::font() const
|
|
|
|
{
|
2008-02-05 01:13:37 +01:00
|
|
|
return QApplication::font();
|
2007-09-13 21:33:44 +02:00
|
|
|
}
|
|
|
|
|
2007-05-22 18:48:34 +02:00
|
|
|
QRectF Widget::boundingRect() const
|
|
|
|
{
|
2008-02-18 00:02:46 +01:00
|
|
|
return QRectF(QPointF(0,0), size());
|
2007-05-22 18:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::resize(const QSizeF& size)
|
|
|
|
{
|
2007-07-23 00:16:40 +02:00
|
|
|
setGeometry(QRectF(pos(), size));
|
2007-05-22 18:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::resize(qreal w, qreal h)
|
|
|
|
{
|
2007-07-12 19:54:58 +02:00
|
|
|
resize(QSizeF(w, h));
|
2007-05-22 18:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget *Widget::parent() const
|
|
|
|
{
|
2008-01-23 00:39:15 +01:00
|
|
|
return parent(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget *Widget::parent(const QGraphicsItem *item)
|
|
|
|
{
|
|
|
|
Q_ASSERT(item);
|
|
|
|
QGraphicsItem *parent = item->parentItem();
|
2007-11-27 07:03:19 +01:00
|
|
|
|
|
|
|
while (parent) {
|
2007-12-02 12:19:26 +01:00
|
|
|
Widget *parentWidget = dynamic_cast<Widget *>(parent);
|
2007-11-27 07:03:19 +01:00
|
|
|
|
|
|
|
if (parentWidget) {
|
|
|
|
return parentWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent = parent->parentItem();
|
|
|
|
}
|
|
|
|
return 0;
|
2007-05-22 18:48:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::addChild(Widget *w)
|
|
|
|
{
|
2007-11-27 07:03:19 +01:00
|
|
|
if (!w || QGraphicsItem::children().contains(w)) {
|
2007-07-12 19:54:58 +02:00
|
|
|
return;
|
|
|
|
}
|
2007-05-22 18:48:34 +02:00
|
|
|
|
2007-10-30 00:10:45 +01:00
|
|
|
w->setParentItem(this);
|
2007-05-22 18:48:34 +02:00
|
|
|
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "Added Child Widget" << (QObject*)w << "our geom is" << geometry();
|
2007-05-22 18:48:34 +02:00
|
|
|
|
2007-07-12 19:54:58 +02:00
|
|
|
if (layout()) {
|
|
|
|
layout()->addItem(w);
|
|
|
|
}
|
2007-10-30 22:00:01 +01:00
|
|
|
|
|
|
|
updateGeometry();
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "after the item is added our geom is now" << geometry();
|
2007-05-22 18:48:34 +02:00
|
|
|
}
|
|
|
|
|
2007-07-12 20:11:50 +02:00
|
|
|
void Widget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
2007-08-01 22:51:27 +02:00
|
|
|
{
|
2007-11-27 07:03:19 +01:00
|
|
|
if (d->opacity < 1.0) {
|
|
|
|
painter->setOpacity(painter->opacity() * d->opacity);
|
|
|
|
}
|
2007-08-13 11:01:00 +02:00
|
|
|
|
2007-10-26 18:35:58 +02:00
|
|
|
/*
|
|
|
|
NOTE: put this back if we end up needing to control when things paint due to, e.g. zooming.
|
2007-09-18 23:30:30 +02:00
|
|
|
if (!d->shouldPaint(painter, transform())) {
|
|
|
|
return;
|
|
|
|
}
|
2007-10-26 18:35:58 +02:00
|
|
|
*/
|
2007-09-18 23:30:30 +02:00
|
|
|
|
2008-02-15 07:51:37 +01:00
|
|
|
paintWidget(painter, option, widget);
|
2007-08-01 22:51:27 +02:00
|
|
|
}
|
|
|
|
|
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-01-07 05:39:36 +01:00
|
|
|
if (ToolTip::self()->currentWidget() == this) {
|
2008-02-05 19:26:17 +01:00
|
|
|
ToolTip::self()->show(this);
|
2007-12-21 06:33:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-25 06:36:31 +01:00
|
|
|
void Widget::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
|
|
|
Q_UNUSED(painter);
|
|
|
|
Q_UNUSED(option);
|
|
|
|
Q_UNUSED(widget);
|
|
|
|
|
|
|
|
// Replaced by widget's own function
|
|
|
|
}
|
|
|
|
|
2007-10-30 00:10:45 +01:00
|
|
|
QVariant Widget::itemChange(GraphicsItemChange change, const QVariant &value)
|
2007-05-22 18:48:34 +02:00
|
|
|
{
|
2007-10-30 00:10:45 +01:00
|
|
|
if (change == QGraphicsItem::ItemChildRemovedChange) {
|
2007-11-27 07:03:19 +01:00
|
|
|
if (layout()) {
|
|
|
|
layout()->removeItem(dynamic_cast<Plasma::LayoutItem*>(value.value<QGraphicsItem*>()));
|
2007-10-30 00:10:45 +01:00
|
|
|
updateGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QGraphicsItem::itemChange(change, value);
|
2007-05-22 18:48:34 +02:00
|
|
|
}
|
|
|
|
|
2007-10-24 08:54:26 +02:00
|
|
|
void Widget::managingLayoutChanged()
|
|
|
|
{
|
|
|
|
if (managingLayout()) {
|
|
|
|
d->wasMovable = flags() & ItemIsMovable;
|
|
|
|
if (!dynamic_cast<FreeLayout*>(managingLayout())) {
|
2007-10-26 01:09:02 +02:00
|
|
|
setFlag(ItemIsMovable, false);
|
2007-10-24 08:54:26 +02:00
|
|
|
}
|
|
|
|
} else {
|
2007-10-26 01:09:02 +02:00
|
|
|
setFlag(ItemIsMovable, d->wasMovable);
|
2007-10-24 08:54:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-21 12:42:08 +01:00
|
|
|
QPoint Widget::popupPosition(const QSize s) const
|
|
|
|
{
|
|
|
|
QPoint pos = view()->mapFromScene(scenePos());
|
|
|
|
pos = view()->mapToGlobal(pos);
|
|
|
|
Plasma::View *pv = dynamic_cast<Plasma::View *>(view());
|
|
|
|
|
|
|
|
Plasma::Location loc = Floating;
|
|
|
|
if (pv) {
|
|
|
|
loc = pv->containment()->location();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (loc) {
|
|
|
|
case BottomEdge:
|
2008-01-22 15:06:37 +01:00
|
|
|
pos = QPoint(pos.x(), pos.y() - s.height());
|
|
|
|
break;
|
2008-01-21 12:42:08 +01:00
|
|
|
case TopEdge:
|
2008-01-22 15:06:37 +01:00
|
|
|
pos = QPoint(pos.x(), pos.y() + (int)size().height());
|
|
|
|
break;
|
2008-01-21 12:42:08 +01:00
|
|
|
case LeftEdge:
|
2008-01-22 15:06:37 +01:00
|
|
|
pos = QPoint(pos.x() + (int)size().width(), pos.y());
|
|
|
|
break;
|
2008-01-21 12:42:08 +01:00
|
|
|
case RightEdge:
|
2008-01-22 15:06:37 +01:00
|
|
|
pos = QPoint(pos.x() - s.width(), pos.y());
|
|
|
|
break;
|
2008-01-21 12:42:08 +01:00
|
|
|
default:
|
2008-01-26 13:37:17 +01:00
|
|
|
if (pos.y() - s.height() > 0) {
|
2008-01-22 15:06:37 +01:00
|
|
|
pos = QPoint(pos.x(), pos.y() - s.height());
|
2008-01-21 12:42:08 +01:00
|
|
|
} else {
|
2008-01-22 15:06:37 +01:00
|
|
|
pos = QPoint(pos.x(), pos.y() + (int)size().height());
|
2008-01-21 12:42:08 +01:00
|
|
|
}
|
|
|
|
}
|
2008-01-22 15:06:37 +01:00
|
|
|
|
2008-01-24 16:44:11 +01:00
|
|
|
//are we out of screen?
|
|
|
|
|
2008-02-12 11:07:45 +01:00
|
|
|
QRect screenRect = QApplication::desktop()->screenGeometry(pv ? pv->containment()->screen() : -1);
|
|
|
|
|
2008-02-12 10:41:49 +01:00
|
|
|
if (pos.rx() + s.width() > screenRect.right()) {
|
|
|
|
pos.rx() -= ((pos.rx() + s.width()) - screenRect.right());
|
2008-01-24 16:44:11 +01:00
|
|
|
}
|
2008-02-12 11:07:45 +01:00
|
|
|
|
2008-02-12 10:41:49 +01:00
|
|
|
if (pos.ry() + s.height() > screenRect.bottom()) {
|
|
|
|
pos.ry() -= ((pos.ry() + s.height()) - screenRect.bottom());
|
2008-01-22 15:06:37 +01:00
|
|
|
}
|
2008-01-26 13:37:17 +01:00
|
|
|
pos.rx() = qMax(0, pos.rx());
|
2008-01-22 15:06:37 +01:00
|
|
|
|
|
|
|
return pos;
|
2008-01-21 12:42:08 +01:00
|
|
|
}
|
|
|
|
|
2007-12-16 14:21:16 +01:00
|
|
|
void Widget::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
2007-12-16 14:51:27 +01:00
|
|
|
// HACK: QGraphicsItem's documentation says that the event will be passed
|
|
|
|
// to the parent if it's not handled, but it isn't passed. This can be
|
|
|
|
// removed when Qt4.4 becomes a requirement. See Qt bug #176902.
|
2007-12-16 14:21:16 +01:00
|
|
|
Widget *parentWidget = parent();
|
|
|
|
if (parentWidget) {
|
|
|
|
parentWidget->contextMenuEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-03-02 06:27:33 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|