2008-07-16 17:17:44 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2008-07-30 22:35:42 +02:00
|
|
|
|
2008-08-23 18:17:04 +02:00
|
|
|
#include "tooltip_p.h"
|
|
|
|
#include "windowpreview_p.h"
|
2008-07-16 17:17:44 +02:00
|
|
|
|
|
|
|
#include <QBitmap>
|
2008-08-23 18:17:04 +02:00
|
|
|
#include <QGridLayout>
|
2008-07-16 17:17:44 +02:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QMouseEvent>
|
2008-08-23 18:17:04 +02:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QPalette>
|
2008-07-16 17:17:44 +02:00
|
|
|
|
|
|
|
#include <KDebug>
|
|
|
|
#include <KGlobal>
|
2008-08-23 18:17:04 +02:00
|
|
|
|
|
|
|
#include <plasma/plasma.h>
|
2008-07-16 17:17:44 +02:00
|
|
|
#include <plasma/theme.h>
|
|
|
|
#include <plasma/panelsvg.h>
|
|
|
|
|
|
|
|
namespace Plasma {
|
|
|
|
|
|
|
|
class ToolTipPrivate
|
|
|
|
{
|
|
|
|
public:
|
2008-07-17 01:27:34 +02:00
|
|
|
ToolTipPrivate(QObject *s)
|
2008-10-12 01:28:20 +02:00
|
|
|
: label(0),
|
|
|
|
imageLabel(0),
|
|
|
|
preview(0),
|
|
|
|
windowToPreview(0),
|
2008-10-21 03:33:32 +02:00
|
|
|
source(s)
|
2008-07-16 17:17:44 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
QLabel *label;
|
|
|
|
QLabel *imageLabel;
|
|
|
|
WindowPreview *preview;
|
|
|
|
WId windowToPreview;
|
|
|
|
PanelSvg *background;
|
2008-07-17 01:27:34 +02:00
|
|
|
QObject *source;
|
2008-07-16 17:17:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
void ToolTip::showEvent(QShowEvent *e)
|
|
|
|
{
|
|
|
|
QWidget::showEvent(e);
|
|
|
|
d->preview->setInfo();
|
|
|
|
}
|
|
|
|
|
2008-07-17 01:27:34 +02:00
|
|
|
void ToolTip::hideEvent(QHideEvent *e)
|
|
|
|
{
|
|
|
|
QWidget::hideEvent(e);
|
|
|
|
if (d->source) {
|
2008-09-18 23:53:52 +02:00
|
|
|
QMetaObject::invokeMethod(d->source, "toolTipHidden");
|
2008-07-17 01:27:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-12 01:28:20 +02:00
|
|
|
void ToolTip::mouseReleaseEvent(QMouseEvent *event)
|
2008-07-16 17:17:44 +02:00
|
|
|
{
|
|
|
|
if (rect().contains(event->pos())) {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-17 01:27:34 +02:00
|
|
|
ToolTip::ToolTip(QObject *source)
|
2008-10-12 01:28:20 +02:00
|
|
|
: QWidget(0),
|
|
|
|
d(new ToolTipPrivate(source))
|
2008-07-16 17:17:44 +02:00
|
|
|
{
|
2008-07-17 01:27:34 +02:00
|
|
|
if (source) {
|
|
|
|
connect(source, SIGNAL(destroyed(QObject*)), this, SLOT(sourceDestroyed()));
|
|
|
|
}
|
|
|
|
|
2008-07-16 17:17:44 +02:00
|
|
|
setWindowFlags(Qt::ToolTip);
|
|
|
|
QGridLayout *l = new QGridLayout;
|
2008-08-23 18:17:04 +02:00
|
|
|
d->preview = new WindowPreview(this);
|
|
|
|
d->label = new QLabel(this);
|
2008-07-16 17:17:44 +02:00
|
|
|
d->label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
d->label->setWordWrap(true);
|
2008-08-23 18:17:04 +02:00
|
|
|
d->imageLabel = new QLabel(this);
|
2008-07-16 17:17:44 +02:00
|
|
|
d->imageLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
|
|
|
|
|
|
|
d->background = new PanelSvg(this);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolTip::~ToolTip()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2008-07-16 17:18:02 +02:00
|
|
|
void ToolTip::setContent(const ToolTipManager::ToolTipContent &data)
|
2008-07-16 17:17:44 +02:00
|
|
|
{
|
|
|
|
//reset our size
|
|
|
|
d->label->setText("<qt><b>" + data.mainText + "</b><br>" + data.subText + "</qt>");
|
|
|
|
d->imageLabel->setPixmap(data.image);
|
|
|
|
d->windowToPreview = data.windowToPreview;
|
2008-10-12 01:28:20 +02:00
|
|
|
d->preview->setWindowId(d->windowToPreview);
|
2008-07-16 17:17:44 +02:00
|
|
|
|
|
|
|
if (isVisible()) {
|
|
|
|
resize(sizeHint());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-18 23:53:52 +02:00
|
|
|
void ToolTip::prepareShowing(bool cueUpdate)
|
2008-07-16 17:17:44 +02:00
|
|
|
{
|
2008-09-18 23:53:52 +02:00
|
|
|
if (cueUpdate && d->source) {
|
2008-08-12 20:40:45 +02:00
|
|
|
QMetaObject::invokeMethod(d->source, "toolTipAboutToShow");
|
2008-07-17 01:27:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d->windowToPreview != 0) {
|
2008-07-16 17:17:44 +02:00
|
|
|
// show/hide the preview area
|
|
|
|
d->preview->show();
|
|
|
|
} else {
|
|
|
|
d->preview->hide();
|
|
|
|
}
|
|
|
|
|
2008-07-17 01:27:34 +02:00
|
|
|
layout()->activate();
|
2008-07-16 17:17:44 +02:00
|
|
|
resize(sizeHint());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolTip::resizeEvent(QResizeEvent *e)
|
|
|
|
{
|
|
|
|
QWidget::resizeEvent(e);
|
|
|
|
d->background->resizePanel(size());
|
|
|
|
|
|
|
|
setMask(d->background->mask());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolTip::paintEvent(QPaintEvent *e)
|
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
painter.setClipRect(e->rect());
|
2008-10-12 01:28:20 +02:00
|
|
|
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
2008-07-16 17:17:44 +02:00
|
|
|
painter.fillRect(rect(), Qt::transparent);
|
|
|
|
|
2008-07-27 19:20:27 +02:00
|
|
|
d->background->paintPanel(&painter);
|
2008-07-16 17:17:44 +02:00
|
|
|
}
|
|
|
|
|
2008-07-17 01:27:34 +02:00
|
|
|
void ToolTip::sourceDestroyed()
|
|
|
|
{
|
|
|
|
d->source = 0;
|
|
|
|
}
|
|
|
|
|
2008-07-16 17:17:44 +02:00
|
|
|
void ToolTip::updateTheme()
|
|
|
|
{
|
|
|
|
d->background->setImagePath("widgets/tooltip");
|
|
|
|
d->background->setEnabledBorders(PanelSvg::AllBorders);
|
|
|
|
|
|
|
|
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();
|
2008-10-12 01:28:20 +02:00
|
|
|
plasmaPalette.setColor(QPalette::Window,
|
|
|
|
Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor));
|
|
|
|
plasmaPalette.setColor(QPalette::WindowText,
|
|
|
|
Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
|
2008-07-16 17:17:44 +02:00
|
|
|
setAutoFillBackground(true);
|
|
|
|
setPalette(plasmaPalette);
|
|
|
|
}
|
|
|
|
|
2008-08-23 18:17:04 +02:00
|
|
|
} // namespace Plasma
|
2008-07-16 17:17:44 +02:00
|
|
|
|
|
|
|
#include "tooltip_p.moc"
|