Clean up tooltips a little, and fix some memory leaks.
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=851425
This commit is contained in:
parent
c6531619cf
commit
1edb8aab86
@ -54,6 +54,7 @@ set(plasma_LIB_SRCS
|
||||
private/style.cpp
|
||||
private/toolbox.cpp
|
||||
private/tooltip.cpp
|
||||
private/windowpreview.cpp
|
||||
querymatch.cpp
|
||||
runnercontext.cpp
|
||||
runnermanager.cpp
|
||||
|
@ -6,7 +6,6 @@
|
||||
* 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
|
||||
@ -19,32 +18,23 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "private/tooltip_p.h"
|
||||
#include "tooltip_p.h"
|
||||
#include "windowpreview_p.h"
|
||||
|
||||
#include <QBitmap>
|
||||
#include <QHBoxLayout>
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QMouseEvent>
|
||||
#include <QPixmap>
|
||||
#include <QTimer>
|
||||
#include <QGraphicsView>
|
||||
#ifdef Q_WS_X11
|
||||
#include <QX11Info>
|
||||
#endif
|
||||
#include <QPainter>
|
||||
#include <QPalette>
|
||||
|
||||
#include <KDebug>
|
||||
#include <KGlobal>
|
||||
#include <KWindowSystem>
|
||||
|
||||
#include <plasma/plasma.h>
|
||||
#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
|
||||
@ -97,11 +87,11 @@ ToolTip::ToolTip(QObject *source)
|
||||
|
||||
setWindowFlags(Qt::ToolTip);
|
||||
QGridLayout *l = new QGridLayout;
|
||||
d->preview = new WindowPreview;
|
||||
d->label = new QLabel;
|
||||
d->preview = new WindowPreview(this);
|
||||
d->label = new QLabel(this);
|
||||
d->label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
d->label->setWordWrap(true);
|
||||
d->imageLabel = new QLabel;
|
||||
d->imageLabel = new QLabel(this);
|
||||
d->imageLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
|
||||
d->background = new PanelSvg(this);
|
||||
@ -197,92 +187,7 @@ void ToolTip::updateTheme()
|
||||
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();
|
||||
}
|
||||
} // namespace Plasma
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
#include "tooltip_p.moc"
|
||||
|
@ -6,7 +6,6 @@
|
||||
* 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
|
||||
@ -22,24 +21,22 @@
|
||||
#ifndef PLASMA_TOOLTIP_P_H
|
||||
#define PLASMA_TOOLTIP_P_H
|
||||
|
||||
#include <QWidget> // base class
|
||||
#include <QPixmap> // stack allocated
|
||||
#include <QPoint> // stack allocated
|
||||
#include <QString> // stack allocated
|
||||
#include <QGraphicsWidget>
|
||||
#include <QWidget> // base class
|
||||
|
||||
#include <plasma/tooltipmanager.h> //ToolTipContent struct
|
||||
|
||||
namespace Plasma {
|
||||
|
||||
class ToolTipPrivate;
|
||||
class ToolTipPrivate;
|
||||
|
||||
class ToolTip : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ToolTip(QObject *source);
|
||||
~ToolTip();
|
||||
|
||||
void updateTheme();
|
||||
void setContent(const ToolTipManager::ToolTipContent &data);
|
||||
void prepareShowing();
|
||||
@ -56,24 +53,10 @@ private Q_SLOTS:
|
||||
void sourceDestroyed();
|
||||
|
||||
private:
|
||||
ToolTipPrivate *const d;
|
||||
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;
|
||||
};
|
||||
} // namespace Plasma
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // PLASMA_TOOLTIP_P_H
|
||||
|
||||
|
126
private/windowpreview.cpp
Normal file
126
private/windowpreview.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright 2007 by Dan Meltzer <hydrogen@notyetimplemented.com>
|
||||
* Copyright (C) 2008 by Alexis Ménard <darktears31@gmail.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 "windowpreview_p.h"
|
||||
|
||||
#include <KWindowSystem>
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
#include <QX11Info>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <fixx11h.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace Plasma {
|
||||
|
||||
bool WindowPreview::previewsAvailable() // static
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
WindowPreview::WindowPreview(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void WindowPreview::setWindowId(WId w)
|
||||
{
|
||||
if (!previewsAvailable()) {
|
||||
id = 0;
|
||||
return;
|
||||
}
|
||||
id = w;
|
||||
readWindowSize();
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#include "windowpreview_p.moc"
|
59
private/windowpreview_p.h
Normal file
59
private/windowpreview_p.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2007 by Dan Meltzer <hydrogen@notyetimplemented.com>
|
||||
* Copyright (C) 2008 by Alexis Ménard <darktears31@gmail.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_WINDOWPREVIEW_P_H
|
||||
#define PLASMA_WINDOWPREVIEW_P_H
|
||||
|
||||
#include <QWidget> // base class
|
||||
#include <QSize> // stack allocated
|
||||
|
||||
namespace Plasma {
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* 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 automaticaly detected).
|
||||
*/
|
||||
class WindowPreview : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static bool previewsAvailable();
|
||||
|
||||
WindowPreview(QWidget *parent = 0);
|
||||
|
||||
void setWindowId(WId w);
|
||||
void setInfo();
|
||||
virtual QSize sizeHint() const;
|
||||
|
||||
private:
|
||||
void readWindowSize() const;
|
||||
|
||||
WId id;
|
||||
mutable QSize windowSize;
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif // PLASMA_WINDOWPREVIEW_P_H
|
||||
|
Loading…
Reference in New Issue
Block a user