support for multiple windows thumbnails in a tooltip
svn path=/trunk/KDE/kdelibs/; revision=941541
This commit is contained in:
parent
7abc872ac3
commit
13ddc52057
@ -226,7 +226,14 @@ void ToolTip::setContent(QObject *tipper, const ToolTipContent &data)
|
|||||||
//reset our size
|
//reset our size
|
||||||
d->text->setContent(data);
|
d->text->setContent(data);
|
||||||
d->imageLabel->setPixmap(data.image());
|
d->imageLabel->setPixmap(data.image());
|
||||||
d->preview->setWindowId(data.windowToPreview());
|
if (data.windowsToPreview().size() > 1) {
|
||||||
|
d->preview->setWindowIds(data.windowsToPreview());
|
||||||
|
} else {
|
||||||
|
QList<WId>ids;
|
||||||
|
ids.append(data.windowToPreview());
|
||||||
|
d->preview->setWindowIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
d->autohide = data.autohide();
|
d->autohide = data.autohide();
|
||||||
d->source = tipper;
|
d->source = tipper;
|
||||||
|
|
||||||
@ -239,7 +246,7 @@ void ToolTip::setContent(QObject *tipper, const ToolTipContent &data)
|
|||||||
|
|
||||||
void ToolTip::prepareShowing()
|
void ToolTip::prepareShowing()
|
||||||
{
|
{
|
||||||
if (d->preview->windowId() != 0) {
|
if (!d->preview->isEmpty()) {
|
||||||
// show/hide the preview area
|
// show/hide the preview area
|
||||||
d->preview->show();
|
d->preview->show();
|
||||||
} else {
|
} else {
|
||||||
|
@ -65,68 +65,101 @@ WindowPreview::WindowPreview(QWidget *parent)
|
|||||||
m_background->setElementPrefix("raised");
|
m_background->setElementPrefix("raised");
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowPreview::setWindowId(WId w)
|
void WindowPreview::setWindowIds(const QList<WId> wids)
|
||||||
{
|
{
|
||||||
if (!previewsAvailable()) {
|
if (!previewsAvailable()) {
|
||||||
setMinimumSize(0,0);
|
setMinimumSize(0,0);
|
||||||
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
||||||
id = 0;
|
ids.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
id = w;
|
ids = wids;
|
||||||
readWindowSize();
|
readWindowSizes();
|
||||||
QSize s(sizeHint());
|
QSize s(sizeHint());
|
||||||
if (s.isValid()) {
|
if (s.isValid()) {
|
||||||
setFixedSize(sizeHint());
|
setFixedSize(sizeHint());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WId WindowPreview::windowId() const
|
QList<WId> WindowPreview::windowIds() const
|
||||||
{
|
{
|
||||||
return id;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize WindowPreview::sizeHint() const
|
QSize WindowPreview::sizeHint() const
|
||||||
{
|
{
|
||||||
if (id == 0) {
|
if (ids.size() == 0) {
|
||||||
return QSize();
|
return QSize();
|
||||||
}
|
}
|
||||||
if (!windowSize.isValid()) {
|
if (!windowSizes.size() == 0) {
|
||||||
readWindowSize();
|
readWindowSizes();
|
||||||
}
|
}
|
||||||
QSize s = windowSize;
|
|
||||||
s.scale(200, 150, Qt::KeepAspectRatio);
|
int maxHeight = 0;
|
||||||
|
int totalWidth = 0;
|
||||||
|
foreach (QSize s, windowSizes) {
|
||||||
|
if (s.height() > maxHeight) {
|
||||||
|
maxHeight = s.height();
|
||||||
|
}
|
||||||
|
|
||||||
|
totalWidth += s.width();
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize s(totalWidth, maxHeight);
|
||||||
|
|
||||||
|
qreal left, top, right, bottom;
|
||||||
|
m_background->getMargins(left, top, right, bottom);
|
||||||
|
|
||||||
|
s.scale(windowWidth*windowSizes.size(), windowHeight, Qt::KeepAspectRatio);
|
||||||
|
|
||||||
|
s = s + QSize(left+right+windowMargin*(windowSizes.size()-1), top+bottom);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowPreview::readWindowSize() const
|
void WindowPreview::readWindowSizes() const
|
||||||
{
|
{
|
||||||
|
windowSizes.clear();
|
||||||
|
foreach (WId id, ids) {
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
KWindowInfo info = KWindowSystem::windowInfo(id, NET::WMGeometry|NET::WMFrameExtents);
|
KWindowInfo info = KWindowSystem::windowInfo(id, NET::WMGeometry|NET::WMFrameExtents);
|
||||||
windowSize = info.frameGeometry().size();
|
windowSizes.append(info.frameGeometry().size());
|
||||||
} else {
|
} else {
|
||||||
windowSize = QSize();
|
windowSizes.append(QSize());
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
windowSize = QSize();
|
windowSizes.append(QSize());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WindowPreview::isEmpty() const
|
||||||
|
{
|
||||||
|
if (ids.size() == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
foreach (WId id, ids) {
|
||||||
|
if (id != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void WindowPreview::setInfo()
|
void WindowPreview::setInfo()
|
||||||
{
|
{
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
Display *dpy = QX11Info::display();
|
Display *dpy = QX11Info::display();
|
||||||
Atom atom = XInternAtom(dpy, "_KDE_WINDOW_PREVIEW", False);
|
Atom atom = XInternAtom(dpy, "_KDE_WINDOW_PREVIEW", False);
|
||||||
if (id == 0) {
|
if (isEmpty()) {
|
||||||
XDeleteProperty(dpy, parentWidget()->winId(), atom);
|
XDeleteProperty(dpy, parentWidget()->winId(), atom);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!windowSize.isValid()) {
|
if (windowSizes.size() == 0) {
|
||||||
readWindowSize();
|
readWindowSizes();
|
||||||
}
|
}
|
||||||
if (!windowSize.isValid()) {
|
if (windowSizes.size() == 0) {
|
||||||
XDeleteProperty(dpy, parentWidget()->winId(), atom);
|
XDeleteProperty(dpy, parentWidget()->winId(), atom);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -140,8 +173,33 @@ void WindowPreview::setInfo()
|
|||||||
m_background->getMargins(left, top, right, bottom);
|
m_background->getMargins(left, top, right, bottom);
|
||||||
QRect thumbnailRect = geometry().adjusted(left, top, -right, -bottom);
|
QRect thumbnailRect = geometry().adjusted(left, top, -right, -bottom);
|
||||||
|
|
||||||
|
const int numWindows = ids.size();
|
||||||
|
|
||||||
|
QList <QRect> thumbnailRects;
|
||||||
|
int x = thumbnailRect.x();
|
||||||
|
|
||||||
|
foreach (QSize s, windowSizes) {
|
||||||
|
s.scale((qreal)(thumbnailRect.width()-5*(numWindows-1))/numWindows, thumbnailRect.height(), Qt::KeepAspectRatio);
|
||||||
|
int y = thumbnailRect.y() + (thumbnailRect.height() - s.height())/2;
|
||||||
|
thumbnailRects.append(QRect(QPoint(x,y), s));
|
||||||
|
x += s.width() + 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
long data[(1 + 6*numWindows)];
|
||||||
|
data[0] = numWindows;
|
||||||
|
|
||||||
|
for (int i = 0; i<numWindows; ++i) {
|
||||||
|
const int start = i*6+1;
|
||||||
|
const QRect thumbnailRect = thumbnailRects[i];
|
||||||
|
|
||||||
|
data[start] = 5;
|
||||||
|
data[start+1] = ids[i];
|
||||||
|
data[start+2] = thumbnailRect.x();
|
||||||
|
data[start+3] = thumbnailRect.y();
|
||||||
|
data[start+4] = thumbnailRect.width();
|
||||||
|
data[start+5] = thumbnailRect.height();
|
||||||
|
}
|
||||||
|
|
||||||
long data[] = { 1, 5, id, thumbnailRect.x(), thumbnailRect.y(), thumbnailRect.width(), thumbnailRect.height() };
|
|
||||||
XChangeProperty(dpy, parentWidget()->winId(), atom, atom, 32, PropModeReplace,
|
XChangeProperty(dpy, parentWidget()->winId(), atom, atom, 32, PropModeReplace,
|
||||||
reinterpret_cast<unsigned char *>(data), sizeof(data) / sizeof(data[ 0 ]));
|
reinterpret_cast<unsigned char *>(data), sizeof(data) / sizeof(data[ 0 ]));
|
||||||
#endif
|
#endif
|
||||||
|
@ -44,20 +44,25 @@ public:
|
|||||||
|
|
||||||
WindowPreview(QWidget *parent = 0);
|
WindowPreview(QWidget *parent = 0);
|
||||||
|
|
||||||
void setWindowId(WId w);
|
void setWindowIds(const QList<WId> w);
|
||||||
WId windowId() const;
|
QList<WId> windowIds() const;
|
||||||
void setInfo();
|
void setInfo();
|
||||||
|
bool isEmpty() const;
|
||||||
virtual QSize sizeHint() const;
|
virtual QSize sizeHint() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *e);
|
void paintEvent(QPaintEvent *e);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void readWindowSize() const;
|
void readWindowSizes() const;
|
||||||
|
|
||||||
WId id;
|
QList<WId> ids;
|
||||||
mutable QSize windowSize;
|
mutable QList<QSize> windowSizes;
|
||||||
FrameSvg *m_background;
|
FrameSvg *m_background;
|
||||||
|
|
||||||
|
static const int windowMargin = 5;
|
||||||
|
static const int windowWidth = 200;
|
||||||
|
static const int windowHeight = 150;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Plasma
|
} // namespace Plasma
|
||||||
|
@ -46,15 +46,14 @@ class ToolTipContentPrivate
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ToolTipContentPrivate()
|
ToolTipContentPrivate()
|
||||||
: windowToPreview(0),
|
: autohide(true)
|
||||||
autohide(true)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QString mainText;
|
QString mainText;
|
||||||
QString subText;
|
QString subText;
|
||||||
QPixmap image;
|
QPixmap image;
|
||||||
WId windowToPreview;
|
QList<WId> windowsToPreview;
|
||||||
QHash<QString, ToolTipResource> resources;
|
QHash<QString, ToolTipResource> resources;
|
||||||
bool autohide;
|
bool autohide;
|
||||||
};
|
};
|
||||||
@ -105,7 +104,7 @@ bool ToolTipContent::isEmpty() const
|
|||||||
return d->mainText.isEmpty() &&
|
return d->mainText.isEmpty() &&
|
||||||
d->subText.isEmpty() &&
|
d->subText.isEmpty() &&
|
||||||
d->image.isNull() &&
|
d->image.isNull() &&
|
||||||
d->windowToPreview == 0;
|
(d->windowsToPreview.size() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTipContent::setMainText(const QString &text)
|
void ToolTipContent::setMainText(const QString &text)
|
||||||
@ -143,14 +142,29 @@ QPixmap ToolTipContent::image() const
|
|||||||
return d->image;
|
return d->image;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTipContent::setWindowToPreview(WId id)
|
void ToolTipContent::setWindowToPreview(const WId id)
|
||||||
{
|
{
|
||||||
d->windowToPreview = id;
|
d->windowsToPreview.clear();
|
||||||
|
d->windowsToPreview.append(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
WId ToolTipContent::windowToPreview() const
|
WId ToolTipContent::windowToPreview() const
|
||||||
{
|
{
|
||||||
return d->windowToPreview;
|
if (d->windowsToPreview.size() == 1) {
|
||||||
|
return d->windowsToPreview.first();
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToolTipContent::setWindowsToPreview(QList<WId> ids)
|
||||||
|
{
|
||||||
|
d->windowsToPreview = ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<WId> ToolTipContent::windowsToPreview() const
|
||||||
|
{
|
||||||
|
return d->windowsToPreview;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTipContent::setAutohide(bool autohide)
|
void ToolTipContent::setAutohide(bool autohide)
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
#include <QtCore/QUrl>
|
#include <QtCore/QUrl>
|
||||||
#include <QtCore/QVariant>
|
#include <QtCore/QVariant>
|
||||||
|
#include <QtCore/QList>
|
||||||
#include <QtGui/QPixmap>
|
#include <QtGui/QPixmap>
|
||||||
#include <QtGui/QIcon>
|
#include <QtGui/QIcon>
|
||||||
|
|
||||||
@ -91,12 +92,20 @@ public:
|
|||||||
/** An icon to display */
|
/** An icon to display */
|
||||||
QPixmap image() const;
|
QPixmap image() const;
|
||||||
|
|
||||||
|
//BIC FIXME: remove when we can break BC
|
||||||
/** Sets the ID of the window to show a preview for */
|
/** Sets the ID of the window to show a preview for */
|
||||||
void setWindowToPreview(WId id);
|
void setWindowToPreview(WId id);
|
||||||
|
|
||||||
|
//BIC FIXME: remove when we can break BC
|
||||||
/** Id of a window if you want to show a preview */
|
/** Id of a window if you want to show a preview */
|
||||||
WId windowToPreview() const;
|
WId windowToPreview() const;
|
||||||
|
|
||||||
|
/** Sets the IDS of the windows to show a preview for */
|
||||||
|
void setWindowsToPreview(const QList<WId> ids);
|
||||||
|
|
||||||
|
/** Ids of a windows if you want to show a preview */
|
||||||
|
QList<WId> windowsToPreview() const;
|
||||||
|
|
||||||
/** Sets whether or not to autohide the tooltip, defaults to true */
|
/** Sets whether or not to autohide the tooltip, defaults to true */
|
||||||
void setAutohide(bool autohide);
|
void setAutohide(bool autohide);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user