libplasma
widget.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "widget.h"
00023
00024 #include <cmath>
00025 #include <limits>
00026
00027 #include <QApplication>
00028 #include <QGraphicsScene>
00029 #include <QGraphicsSceneHoverEvent>
00030 #include <QGraphicsView>
00031 #include <QHelpEvent>
00032 #include <QList>
00033 #include <QPainter>
00034 #include <QStyleOptionGraphicsItem>
00035 #include <QGraphicsLayout>
00036 #include <QGraphicsLinearLayout>
00037
00038 #include <KDebug>
00039
00040 #include "plasma/applet.h"
00041
00042 #include "plasma/plasma.h"
00043 #include "plasma/view.h"
00044 #include "plasma/containment.h"
00045
00046 namespace Plasma
00047 {
00048
00049 class WidgetPrivate
00050 {
00051 public:
00052 WidgetPrivate()
00053 : minimumSize(0,0),
00054 maximumSize(std::numeric_limits<qreal>::infinity(),
00055 std::numeric_limits<qreal>::infinity()),
00056 wasMovable(false)
00057
00058 { }
00059
00060 ~WidgetPrivate()
00061 {
00062
00063 }
00064
00065 QSizeF minimumSize;
00066 QSizeF maximumSize;
00067
00068 bool wasMovable;
00069
00070 bool shouldPaint(QPainter *painter, const QTransform &transform);
00071
00072 };
00073
00074 bool WidgetPrivate::shouldPaint(QPainter *painter, const QTransform &transform)
00075 {
00076 Q_UNUSED(painter)
00077 Q_UNUSED(transform)
00078
00079
00080 return true;
00081 }
00082
00083 Widget::Widget(QGraphicsItem *parent, QObject* parentObject)
00084 : QGraphicsWidget(parent),
00085 d(new WidgetPrivate)
00086 {
00087 setFlag(QGraphicsItem::ItemClipsToShape, true);
00088 setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
00089 }
00090
00091 Widget::~Widget()
00092 {
00093 #ifdef TOOLTIPMANAGER
00094 if (ToolTip::self()->currentWidget() == this) {
00095 ToolTip::self()->hide();
00096 }
00097 #endif
00098 delete d;
00099 }
00100
00101
00102 #ifdef TOOLTIPMANAGER
00103 const ToolTipData* Widget::toolTip() const
00104 {
00105 return d->toolTip;
00106 }
00107
00108 void Widget::setToolTip(const ToolTipData &tip)
00109 {
00110 if (tip.image.isNull() &&
00111 tip.subText.isEmpty() &&
00112 tip.mainText.isEmpty()) {
00113 delete d->toolTip;
00114 d->toolTip = 0;
00115 return;
00116 }
00117
00118 if (!d->toolTip) {
00119 d->toolTip = new ToolTipData;
00120 }
00121
00122 *d->toolTip = tip;
00123
00124
00125 ToolTip::self()->setData(this, *d->toolTip);
00126 }
00127
00128 void Widget::updateToolTip(bool update)
00129 {
00130 Q_UNUSED(update)
00131 }
00132
00133 bool Widget::sceneEvent(QEvent *event)
00134 {
00135 switch (event->type()) {
00136 case QEvent::GraphicsSceneHoverMove:
00137
00138
00139 if (ToolTip::self()->isVisible()) {
00140 break;
00141 }
00142
00143 case QEvent::GraphicsSceneHoverEnter:
00144 {
00145
00146 if (!d->toolTip) {
00147 break;
00148 }
00149
00150
00151
00152
00153 QGraphicsView *parentView = view();
00154 if (parentView) {
00155 ToolTip::self()->show(this);
00156 }
00157
00158 break;
00159 }
00160
00161 case QEvent::GraphicsSceneHoverLeave:
00162 ToolTip::self()->delayedHide();
00163 break;
00164
00165 case QEvent::GraphicsSceneMousePress:
00166 case QEvent::GraphicsSceneWheel:
00167 ToolTip::self()->hide();
00168
00169 default:
00170 break;
00171 }
00172
00173 return QGraphicsItem::sceneEvent(event);
00174 }
00175 #endif
00176 }
00177