remove old stuff of tooltips
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=833275
This commit is contained in:
parent
47b851dbb3
commit
44c8ede79e
@ -1,380 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2007 by Dan Meltzer <hydrogen@notyetimplemented.com>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
#include "tooltip_p.h"
|
|
||||||
|
|
||||||
#include <QBitmap>
|
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QPixmap>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QGraphicsView>
|
|
||||||
#ifdef Q_WS_X11
|
|
||||||
#include <QX11Info>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <KDebug>
|
|
||||||
#include <KGlobal>
|
|
||||||
#include <KWindowSystem>
|
|
||||||
#include <plasma/theme.h>
|
|
||||||
#include <plasma/panelsvg.h>
|
|
||||||
|
|
||||||
#ifdef Q_WS_X11
|
|
||||||
#include <X11/Xlib.h>
|
|
||||||
#include <fixx11h.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "plasma/plasma.h"
|
|
||||||
|
|
||||||
namespace Plasma {
|
|
||||||
|
|
||||||
class ToolTipPrivate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ToolTipPrivate()
|
|
||||||
: label(0)
|
|
||||||
, imageLabel(0)
|
|
||||||
, preview(0)
|
|
||||||
, windowToPreview(0)
|
|
||||||
, currentWidget(0)
|
|
||||||
, isShown(false)
|
|
||||||
, delayedHide(false)
|
|
||||||
, showTimer(0)
|
|
||||||
, hideTimer(0)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
QLabel *label;
|
|
||||||
QLabel *imageLabel;
|
|
||||||
WindowPreview *preview;
|
|
||||||
WId windowToPreview;
|
|
||||||
Plasma::Widget *currentWidget;
|
|
||||||
bool isShown;
|
|
||||||
bool delayedHide;
|
|
||||||
QTimer *showTimer;
|
|
||||||
QTimer *hideTimer;
|
|
||||||
|
|
||||||
PanelSvg *background;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class ToolTipSingleton
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ToolTip self;
|
|
||||||
};
|
|
||||||
K_GLOBAL_STATIC( ToolTipSingleton, privateInstance )
|
|
||||||
|
|
||||||
ToolTip *ToolTip::self()
|
|
||||||
{
|
|
||||||
return &privateInstance->self;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTip::show(Plasma::Widget *widget)
|
|
||||||
{
|
|
||||||
d->hideTimer->stop();
|
|
||||||
d->delayedHide = false;
|
|
||||||
if (d->isShown && d->currentWidget) {
|
|
||||||
// we let know widget which had tooltip up to now that it's tooltip
|
|
||||||
// is not longer displayed
|
|
||||||
d->currentWidget->updateToolTip(false);
|
|
||||||
}
|
|
||||||
d->currentWidget = widget;
|
|
||||||
d->showTimer->stop();
|
|
||||||
|
|
||||||
if (d->isShown) {
|
|
||||||
// small delay to prevent unnecessary showing when the mouse is moving quickly across items
|
|
||||||
// which can be too much for less powerful CPUs to keep up with
|
|
||||||
d->showTimer->start(200);
|
|
||||||
} else {
|
|
||||||
d->showTimer->start(500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTip::delayedHide()
|
|
||||||
{
|
|
||||||
d->showTimer->stop(); // stop the timer to show the tooltip
|
|
||||||
d->delayedHide = true;
|
|
||||||
d->hideTimer->start(250);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTip::hide()
|
|
||||||
{
|
|
||||||
d->currentWidget = 0;
|
|
||||||
d->showTimer->stop(); //Mouse out, stop the timer to show the tooltip
|
|
||||||
d->delayedHide = false;
|
|
||||||
setVisible(false);
|
|
||||||
d->hideTimer->start(250); //250 ms delay before we are officially "gone" to allow for the time to move between widgets
|
|
||||||
}
|
|
||||||
|
|
||||||
Plasma::Widget *ToolTip::currentWidget() const
|
|
||||||
{
|
|
||||||
return d->currentWidget;
|
|
||||||
}
|
|
||||||
|
|
||||||
//PRIVATE FUNCTIONS
|
|
||||||
void ToolTip::showToolTip()
|
|
||||||
{
|
|
||||||
if (!d->currentWidget || !d->currentWidget->toolTip()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QGraphicsView *v = d->currentWidget->view();
|
|
||||||
if (v && v->mouseGrabber()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
d->currentWidget->updateToolTip(true);
|
|
||||||
setData(*d->currentWidget->toolTip());
|
|
||||||
|
|
||||||
if( d->windowToPreview != 0 ) {
|
|
||||||
// show/hide the preview area
|
|
||||||
d->preview->show();
|
|
||||||
} else {
|
|
||||||
d->preview->hide();
|
|
||||||
}
|
|
||||||
layout()->activate();
|
|
||||||
|
|
||||||
resize(sizeHint());
|
|
||||||
move(d->currentWidget->popupPosition(size()));
|
|
||||||
|
|
||||||
if (isVisible()) {
|
|
||||||
d->preview->setInfo();
|
|
||||||
} else {
|
|
||||||
setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
d->isShown = true; //ToolTip is visible
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTip::resetShownState()
|
|
||||||
{
|
|
||||||
if (!isVisible() || //One might have moused out and back in again
|
|
||||||
d->delayedHide) {
|
|
||||||
d->delayedHide = false;
|
|
||||||
d->isShown = false;
|
|
||||||
setVisible(false);
|
|
||||||
if (d->currentWidget) {
|
|
||||||
d->currentWidget->updateToolTip(false);
|
|
||||||
}
|
|
||||||
d->currentWidget = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTip::showEvent(QShowEvent *e)
|
|
||||||
{
|
|
||||||
QWidget::showEvent(e);
|
|
||||||
d->preview->setInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTip::mouseReleaseEvent(QMouseEvent* event)
|
|
||||||
{
|
|
||||||
if (rect().contains(event->pos())) {
|
|
||||||
hide();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ToolTip::ToolTip()
|
|
||||||
: QWidget(0)
|
|
||||||
, d( new ToolTipPrivate )
|
|
||||||
{
|
|
||||||
setWindowFlags(Qt::ToolTip);
|
|
||||||
QGridLayout *l = new QGridLayout;
|
|
||||||
d->preview = new WindowPreview;
|
|
||||||
d->label = new QLabel;
|
|
||||||
d->label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
||||||
d->label->setWordWrap(true);
|
|
||||||
d->imageLabel = new QLabel;
|
|
||||||
d->imageLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
|
||||||
|
|
||||||
d->background = new PanelSvg("widgets/tooltip", this);
|
|
||||||
d->background->setBorderFlags(PanelSvg::DrawAllBorders);
|
|
||||||
|
|
||||||
connect(d->background, SIGNAL(repaintNeeded()), this, SLOT(update()));
|
|
||||||
|
|
||||||
l->addWidget(d->preview, 0, 0, 1, 2);
|
|
||||||
l->addWidget(d->imageLabel, 1, 0);
|
|
||||||
l->addWidget(d->label, 1, 1);
|
|
||||||
setLayout(l);
|
|
||||||
|
|
||||||
d->showTimer = new QTimer(this);
|
|
||||||
d->showTimer->setSingleShot(true);
|
|
||||||
d->hideTimer = new QTimer(this);
|
|
||||||
d->hideTimer->setSingleShot(true);
|
|
||||||
|
|
||||||
connect(d->showTimer, SIGNAL(timeout()), SLOT(showToolTip()));
|
|
||||||
connect(d->hideTimer, SIGNAL(timeout()), SLOT(resetShownState()));
|
|
||||||
|
|
||||||
connect(Plasma::Theme::self(), SIGNAL(themeChanged()), this, SLOT(themeUpdated()));
|
|
||||||
themeUpdated();
|
|
||||||
}
|
|
||||||
|
|
||||||
ToolTip::~ToolTip()
|
|
||||||
{
|
|
||||||
delete d;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTip::setData(Plasma::Widget *widget, const Plasma::ToolTipData &data)
|
|
||||||
{
|
|
||||||
if (d->currentWidget && d->currentWidget == widget) {
|
|
||||||
setData(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTip::setData(const Plasma::ToolTipData &data)
|
|
||||||
{
|
|
||||||
//reset our size
|
|
||||||
d->label->setText("<qt><b>" + data.mainText + "</b><br>" + data.subText + "</qt>");
|
|
||||||
d->imageLabel->setPixmap(data.image);
|
|
||||||
d->windowToPreview = data.windowToPreview;
|
|
||||||
d->preview->setWindowId( d->windowToPreview );
|
|
||||||
|
|
||||||
if (isVisible()) {
|
|
||||||
resize(sizeHint());
|
|
||||||
|
|
||||||
if (d->currentWidget) {
|
|
||||||
move(d->currentWidget->popupPosition(size()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTip::themeUpdated()
|
|
||||||
{
|
|
||||||
const int topHeight = d->background->marginSize(Plasma::TopMargin);
|
|
||||||
const int leftWidth = d->background->marginSize(Plasma::LeftMargin);
|
|
||||||
const int rightWidth = d->background->marginSize(Plasma::RightMargin);
|
|
||||||
const int bottomHeight = d->background->marginSize(Plasma::BottomMargin);
|
|
||||||
setContentsMargins(leftWidth, topHeight, rightWidth, bottomHeight);
|
|
||||||
|
|
||||||
// Make the tooltip use Plasma's colorscheme
|
|
||||||
QPalette plasmaPalette = QPalette();
|
|
||||||
plasmaPalette.setColor(QPalette::Window, Plasma::Theme::self()->backgroundColor());
|
|
||||||
plasmaPalette.setColor(QPalette::WindowText, Plasma::Theme::self()->textColor());
|
|
||||||
setAutoFillBackground(true);
|
|
||||||
setPalette(plasmaPalette);
|
|
||||||
}
|
|
||||||
|
|
||||||
// A widget which reserves area for window preview and sets hints on the toplevel
|
|
||||||
// tooltip widget that tells KWin to render the preview in this area. This depends
|
|
||||||
// on KWin's TaskbarThumbnail compositing effect (which is here detected).
|
|
||||||
|
|
||||||
void WindowPreview::setWindowId(WId w)
|
|
||||||
{
|
|
||||||
if (!previewsAvailable()) {
|
|
||||||
id = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
id = w;
|
|
||||||
readWindowSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WindowPreview::previewsAvailable() const
|
|
||||||
{
|
|
||||||
if (!KWindowSystem::compositingActive()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#ifdef Q_WS_X11
|
|
||||||
// hackish way to find out if KWin has the effect enabled,
|
|
||||||
// TODO provide proper support
|
|
||||||
Display* dpy = QX11Info::display();
|
|
||||||
Atom atom = XInternAtom(dpy, "_KDE_WINDOW_PREVIEW", False);
|
|
||||||
int cnt;
|
|
||||||
Atom* list = XListProperties(dpy, DefaultRootWindow( dpy ), &cnt);
|
|
||||||
if (list != NULL) {
|
|
||||||
bool ret = ( qFind(list, list + cnt, atom) != list + cnt );
|
|
||||||
XFree(list);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize WindowPreview::sizeHint() const
|
|
||||||
{
|
|
||||||
if (id == 0) {
|
|
||||||
return QSize();
|
|
||||||
}
|
|
||||||
if (!windowSize.isValid()) {
|
|
||||||
readWindowSize();
|
|
||||||
}
|
|
||||||
QSize s = windowSize;
|
|
||||||
s.scale(200, 150, Qt::KeepAspectRatio);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WindowPreview::readWindowSize() const
|
|
||||||
{
|
|
||||||
#ifdef Q_WS_X11
|
|
||||||
Window r;
|
|
||||||
int x, y;
|
|
||||||
unsigned int w, h, b, d;
|
|
||||||
if (XGetGeometry(QX11Info::display(), id, &r, &x, &y, &w, &h, &b, &d)) {
|
|
||||||
windowSize = QSize( w, h );
|
|
||||||
} else {
|
|
||||||
windowSize = QSize();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
windowSize = QSize();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void WindowPreview::setInfo()
|
|
||||||
{
|
|
||||||
#ifdef Q_WS_X11
|
|
||||||
Display *dpy = QX11Info::display();
|
|
||||||
Atom atom = XInternAtom(dpy, "_KDE_WINDOW_PREVIEW", False);
|
|
||||||
if (id == 0) {
|
|
||||||
XDeleteProperty(dpy, parentWidget()->winId(), atom);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!windowSize.isValid()) {
|
|
||||||
readWindowSize();
|
|
||||||
}
|
|
||||||
if (!windowSize.isValid()) {
|
|
||||||
XDeleteProperty(dpy, parentWidget()->winId(), atom);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Q_ASSERT( parentWidget()->isWindow()); // parent must be toplevel
|
|
||||||
long data[] = { 1, 5, id, x(), y(), width(), height() };
|
|
||||||
XChangeProperty(dpy, parentWidget()->winId(), atom, atom, 32, PropModeReplace,
|
|
||||||
reinterpret_cast< unsigned char* >( data ), sizeof( data ) / sizeof( data[ 0 ] ));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTip::resizeEvent(QResizeEvent *e)
|
|
||||||
{
|
|
||||||
QWidget::resizeEvent(e);
|
|
||||||
d->background->resize(size());
|
|
||||||
|
|
||||||
setMask(d->background->mask());
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTip::paintEvent(QPaintEvent *e)
|
|
||||||
{
|
|
||||||
QPainter painter(this);
|
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
|
||||||
painter.setClipRect(e->rect());
|
|
||||||
painter.setCompositionMode(QPainter::CompositionMode_Source );
|
|
||||||
painter.fillRect(rect(), Qt::transparent);
|
|
||||||
|
|
||||||
d->background->paint(&painter, rect());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
#include "tooltip_p.moc"
|
|
@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2007 by Dan Meltzer <hydrogen@notyetimplemented.com>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef PLASMA_TOOLTIP_P_H
|
|
||||||
#define PLASMA_TOOLTIP_P_H
|
|
||||||
|
|
||||||
#include <plasma/widgets/widget.h> //ToolTipData struct
|
|
||||||
|
|
||||||
#include <QWidget> // base class
|
|
||||||
#include <QPixmap> // stack allocated
|
|
||||||
#include <QPoint> // stack allocated
|
|
||||||
#include <QString> // stack allocated
|
|
||||||
|
|
||||||
namespace Plasma {
|
|
||||||
|
|
||||||
class ToolTipData;
|
|
||||||
class ToolTipPrivate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
@author Dan Meltzer
|
|
||||||
* A Singleton tooltip. Before calling show it is necessary to
|
|
||||||
* call setLocation and setData
|
|
||||||
*/
|
|
||||||
class ToolTip : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
ToolTip();
|
|
||||||
~ToolTip();
|
|
||||||
|
|
||||||
static ToolTip *self();
|
|
||||||
void show(Plasma::Widget *widget);
|
|
||||||
void delayedHide();
|
|
||||||
void hide();
|
|
||||||
|
|
||||||
Plasma::Widget *currentWidget() const;
|
|
||||||
void setData(Plasma::Widget *widget, const Plasma::ToolTipData &data);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void showEvent(QShowEvent *);
|
|
||||||
void mouseReleaseEvent(QMouseEvent *);
|
|
||||||
|
|
||||||
void resizeEvent(QResizeEvent *);
|
|
||||||
void paintEvent(QPaintEvent *);
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void resetShownState();
|
|
||||||
void showToolTip();
|
|
||||||
void themeUpdated();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void setData(const Plasma::ToolTipData &data);
|
|
||||||
|
|
||||||
ToolTipPrivate *const d;
|
|
||||||
};
|
|
||||||
|
|
||||||
class WindowPreview : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
void setWindowId(WId w);
|
|
||||||
void setInfo();
|
|
||||||
virtual QSize sizeHint() const;
|
|
||||||
bool previewsAvailable() const;
|
|
||||||
private:
|
|
||||||
void readWindowSize() const;
|
|
||||||
WId id;
|
|
||||||
mutable QSize windowSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,177 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2007 by Alexander Wiedenbruch <mail@wiedenbruch.de>
|
|
||||||
* and Matias Valdenegro <mvaldenegro@informatica.utem.cl>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "widget.h"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <limits>
|
|
||||||
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QGraphicsScene>
|
|
||||||
#include <QGraphicsSceneHoverEvent>
|
|
||||||
#include <QGraphicsView>
|
|
||||||
#include <QHelpEvent>
|
|
||||||
#include <QList>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QStyleOptionGraphicsItem>
|
|
||||||
#include <QGraphicsLayout>
|
|
||||||
#include <QGraphicsLinearLayout>
|
|
||||||
|
|
||||||
#include <KDebug>
|
|
||||||
|
|
||||||
#include "plasma/applet.h"
|
|
||||||
|
|
||||||
#include "plasma/plasma.h"
|
|
||||||
#include "plasma/view.h"
|
|
||||||
#include "plasma/containment.h"
|
|
||||||
|
|
||||||
namespace Plasma
|
|
||||||
{
|
|
||||||
|
|
||||||
class WidgetPrivate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
WidgetPrivate()
|
|
||||||
: minimumSize(0,0),
|
|
||||||
maximumSize(std::numeric_limits<qreal>::infinity(),
|
|
||||||
std::numeric_limits<qreal>::infinity()),
|
|
||||||
wasMovable(false)
|
|
||||||
//toolTip(0)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
~WidgetPrivate()
|
|
||||||
{
|
|
||||||
//delete toolTip;
|
|
||||||
}
|
|
||||||
|
|
||||||
QSizeF minimumSize;
|
|
||||||
QSizeF maximumSize;
|
|
||||||
|
|
||||||
bool wasMovable;
|
|
||||||
|
|
||||||
bool shouldPaint(QPainter *painter, const QTransform &transform);
|
|
||||||
//ToolTipData *toolTip;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool WidgetPrivate::shouldPaint(QPainter *painter, const QTransform &transform)
|
|
||||||
{
|
|
||||||
Q_UNUSED(painter)
|
|
||||||
Q_UNUSED(transform)
|
|
||||||
//qreal zoomLevel = painter->transform().m11() / transform.m11();
|
|
||||||
//return (fabs(zoomLevel - scalingFactor(Plasma::DesktopZoom))) < std::numeric_limits<double>::epsilon();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget::Widget(QGraphicsItem *parent, QObject* parentObject)
|
|
||||||
: QGraphicsWidget(parent),
|
|
||||||
d(new WidgetPrivate)
|
|
||||||
{
|
|
||||||
setFlag(QGraphicsItem::ItemClipsToShape, true);
|
|
||||||
setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget::~Widget()
|
|
||||||
{
|
|
||||||
#ifdef TOOLTIPMANAGER
|
|
||||||
if (ToolTip::self()->currentWidget() == this) {
|
|
||||||
ToolTip::self()->hide();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
delete d;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef TOOLTIPMANAGER
|
|
||||||
const ToolTipData* Widget::toolTip() const
|
|
||||||
{
|
|
||||||
return d->toolTip;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Widget::setToolTip(const ToolTipData &tip)
|
|
||||||
{
|
|
||||||
if (tip.image.isNull() &&
|
|
||||||
tip.subText.isEmpty() &&
|
|
||||||
tip.mainText.isEmpty()) {
|
|
||||||
delete d->toolTip;
|
|
||||||
d->toolTip = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!d->toolTip) {
|
|
||||||
d->toolTip = new ToolTipData;
|
|
||||||
}
|
|
||||||
|
|
||||||
*d->toolTip = tip;
|
|
||||||
|
|
||||||
// this does a check to ensure the current widget is us
|
|
||||||
ToolTip::self()->setData(this, *d->toolTip);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Widget::updateToolTip(bool update)
|
|
||||||
{
|
|
||||||
Q_UNUSED(update)
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
if (ToolTip::self()->isVisible()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case QEvent::GraphicsSceneHoverEnter:
|
|
||||||
{
|
|
||||||
// Check that there is a tooltip to show
|
|
||||||
if (!d->toolTip) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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) {
|
|
||||||
ToolTip::self()->show(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case QEvent::GraphicsSceneHoverLeave:
|
|
||||||
ToolTip::self()->delayedHide();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case QEvent::GraphicsSceneMousePress:
|
|
||||||
case QEvent::GraphicsSceneWheel:
|
|
||||||
ToolTip::self()->hide();
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QGraphicsItem::sceneEvent(event);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
} // Plasma namespace
|
|
||||||
|
|
117
widgets/widget.h
117
widgets/widget.h
@ -1,117 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2007 by Alexander Wiedenbruch <mail@wiedenbruch.de>
|
|
||||||
* and Matias Valdenegro <mvaldenegro@informatica.utem.cl>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef WIDGET_H_
|
|
||||||
#define WIDGET_H_
|
|
||||||
|
|
||||||
#include <QtGui/QGraphicsWidget>
|
|
||||||
#include <QtGui/QPixmap>
|
|
||||||
|
|
||||||
#include <QtCore/QRectF>
|
|
||||||
#include <QtCore/QSizeF>
|
|
||||||
#include <QtCore/QString>
|
|
||||||
|
|
||||||
#include <plasma/plasma_export.h>
|
|
||||||
|
|
||||||
class QGraphicsView;
|
|
||||||
class QGraphicsSceneHoverEvent;
|
|
||||||
|
|
||||||
namespace Plasma
|
|
||||||
{
|
|
||||||
|
|
||||||
struct PLASMA_EXPORT ToolTipData
|
|
||||||
{
|
|
||||||
ToolTipData() : windowToPreview( 0 ) {}
|
|
||||||
QString mainText; //Important information
|
|
||||||
QString subText; //Elaborates on the Main Text
|
|
||||||
QPixmap image; // Icon to show;
|
|
||||||
WId windowToPreview; // Id of window to show preview
|
|
||||||
};
|
|
||||||
|
|
||||||
class Layout;
|
|
||||||
class WidgetPrivate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base class for all Widgets in Plasma.
|
|
||||||
*
|
|
||||||
* @author Alexander Wiedenbruch
|
|
||||||
* @author Matias Valdenegro
|
|
||||||
*
|
|
||||||
* Widgets are the basis for User Interfaces inside Plasma.
|
|
||||||
* Widgets are rectangular, but can be in any visible shape by just using transparency to mask
|
|
||||||
* out non-rectangular areas.
|
|
||||||
*
|
|
||||||
* To implement a Widget, just subclass Plasma::Widget and implement at minimum,
|
|
||||||
* sizeHint() and paintWidget()
|
|
||||||
*/
|
|
||||||
class PLASMA_EXPORT Widget : public QGraphicsWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Creates a new Plasma::Widget.
|
|
||||||
* @param parent the QGraphicsItem this icon is parented to.
|
|
||||||
*/
|
|
||||||
explicit Widget(QGraphicsItem *parent = 0 , QObject *parentObject = 0);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroys a Plasma::Widget.
|
|
||||||
*/
|
|
||||||
virtual ~Widget();
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef TOOLTIPMANAGER
|
|
||||||
/**
|
|
||||||
* The Data from the tooltip
|
|
||||||
* @returns A ToolTip::Data object with current information
|
|
||||||
*/
|
|
||||||
const ToolTipData* toolTip() const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setter for data shown in tooltip
|
|
||||||
* @param data a ToolTip::Data object containing icon and text
|
|
||||||
*/
|
|
||||||
void setToolTip(const ToolTipData &dt);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the tooltip is going to be shown or just after hiding
|
|
||||||
* it. This lets updating data right before a tooltip is shown or
|
|
||||||
* tracking current visibility. That allows e.g. tips that are more
|
|
||||||
* expensive to create ahead of time to be set at the last possible
|
|
||||||
* moment.
|
|
||||||
* @param update visibility of tooltip
|
|
||||||
*/
|
|
||||||
virtual void updateToolTip(bool update);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
|
||||||
#ifdef TOOLTIPMANAGER
|
|
||||||
virtual bool sceneEvent(QEvent *event);
|
|
||||||
#endif
|
|
||||||
private:
|
|
||||||
|
|
||||||
WidgetPrivate *const d;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // Plasma namespace
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue
Block a user