• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

libplasma

widget.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2007 by Alexander Wiedenbruch <mail@wiedenbruch.de>
00003  *                      and Matias Valdenegro <mvaldenegro@informatica.utem.cl>
00004  *
00005  *   This program is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU Library General Public License as
00007  *   published by the Free Software Foundation; either version 2, or
00008  *   (at your option) any later version.
00009  *
00010  *   This program is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details
00014  *
00015  *   You should have received a copy of the GNU Library General Public
00016  *   License along with this program; if not, write to the
00017  *   Free Software Foundation, Inc.,
00018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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               //toolTip(0)
00058         { }
00059 
00060         ~WidgetPrivate()
00061         {
00062             //delete toolTip;
00063         }
00064 
00065         QSizeF minimumSize;
00066         QSizeF maximumSize;
00067 
00068         bool wasMovable;
00069 
00070         bool shouldPaint(QPainter *painter, const QTransform &transform);
00071         //ToolTipData *toolTip;
00072 };
00073 
00074 bool WidgetPrivate::shouldPaint(QPainter *painter, const QTransform &transform)
00075 {
00076     Q_UNUSED(painter)
00077     Q_UNUSED(transform)
00078     //qreal zoomLevel = painter->transform().m11() / transform.m11();
00079     //return (fabs(zoomLevel - scalingFactor(Plasma::DesktopZoom))) < std::numeric_limits<double>::epsilon();
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     // this does a check to ensure the current widget is us
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         // If the tooltip isn't visible, run through showing the tooltip again
00138         // so that it only becomes visible after a stationary hover
00139         if (ToolTip::self()->isVisible()) {
00140             break;
00141         }
00142 
00143     case QEvent::GraphicsSceneHoverEnter:
00144     {
00145         // Check that there is a tooltip to show
00146         if (!d->toolTip) {
00147             break;
00148         }
00149 
00150         // If the mouse is in the widget's area at the time that it is being
00151         // created the widget can receive a hover event before it is fully
00152         // initialized, in which case view() will return 0.
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 } // Plasma namespace
00177 

libplasma

Skip menu "libplasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal