use only one actual tip widget, store the data otherwise
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=878933
This commit is contained in:
parent
1c75cca9e2
commit
d8f1ce657c
@ -40,11 +40,11 @@ namespace Plasma {
|
|||||||
class ToolTipPrivate
|
class ToolTipPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ToolTipPrivate(QObject *s)
|
ToolTipPrivate()
|
||||||
: label(0),
|
: label(0),
|
||||||
imageLabel(0),
|
imageLabel(0),
|
||||||
preview(0),
|
preview(0),
|
||||||
source(s),
|
source(0),
|
||||||
autohide(true)
|
autohide(true)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@ -77,14 +77,10 @@ void ToolTip::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ToolTip::ToolTip(QObject *source)
|
ToolTip::ToolTip(QWidget *parent)
|
||||||
: QWidget(0),
|
: QWidget(parent),
|
||||||
d(new ToolTipPrivate(source))
|
d(new ToolTipPrivate())
|
||||||
{
|
{
|
||||||
if (source) {
|
|
||||||
connect(source, SIGNAL(destroyed(QObject*)), this, SLOT(sourceDestroyed()));
|
|
||||||
}
|
|
||||||
|
|
||||||
setWindowFlags(Qt::ToolTip);
|
setWindowFlags(Qt::ToolTip);
|
||||||
QGridLayout *l = new QGridLayout;
|
QGridLayout *l = new QGridLayout;
|
||||||
d->preview = new WindowPreview(this);
|
d->preview = new WindowPreview(this);
|
||||||
@ -95,7 +91,10 @@ ToolTip::ToolTip(QObject *source)
|
|||||||
d->imageLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
d->imageLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||||
|
|
||||||
d->background = new FrameSvg(this);
|
d->background = new FrameSvg(this);
|
||||||
connect(d->background, SIGNAL(repaintNeeded()), this, SLOT(update()));
|
d->background->setImagePath("widgets/tooltip");
|
||||||
|
d->background->setEnabledBorders(FrameSvg::AllBorders);
|
||||||
|
updateTheme();
|
||||||
|
connect(d->background, SIGNAL(repaintNeeded()), this, SLOT(updateTheme()));
|
||||||
|
|
||||||
l->addWidget(d->preview, 0, 0, 1, 2);
|
l->addWidget(d->preview, 0, 0, 1, 2);
|
||||||
l->addWidget(d->imageLabel, 1, 0);
|
l->addWidget(d->imageLabel, 1, 0);
|
||||||
@ -117,6 +116,7 @@ void ToolTip::setContent(const ToolTipContent &data)
|
|||||||
d->autohide = data.autohide();
|
d->autohide = data.autohide();
|
||||||
|
|
||||||
if (isVisible()) {
|
if (isVisible()) {
|
||||||
|
d->preview->setInfo();
|
||||||
resize(sizeHint());
|
resize(sizeHint());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,6 +135,7 @@ void ToolTip::prepareShowing(bool cueUpdate)
|
|||||||
}
|
}
|
||||||
|
|
||||||
layout()->activate();
|
layout()->activate();
|
||||||
|
d->preview->setInfo();
|
||||||
resize(sizeHint());
|
resize(sizeHint());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,11 +158,6 @@ void ToolTip::paintEvent(QPaintEvent *e)
|
|||||||
d->background->paintFrame(&painter);
|
d->background->paintFrame(&painter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTip::sourceDestroyed()
|
|
||||||
{
|
|
||||||
d->source = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ToolTip::autohide() const
|
bool ToolTip::autohide() const
|
||||||
{
|
{
|
||||||
return d->autohide;
|
return d->autohide;
|
||||||
@ -169,9 +165,6 @@ bool ToolTip::autohide() const
|
|||||||
|
|
||||||
void ToolTip::updateTheme()
|
void ToolTip::updateTheme()
|
||||||
{
|
{
|
||||||
d->background->setImagePath("widgets/tooltip");
|
|
||||||
d->background->setEnabledBorders(FrameSvg::AllBorders);
|
|
||||||
|
|
||||||
const int topHeight = d->background->marginSize(Plasma::TopMargin);
|
const int topHeight = d->background->marginSize(Plasma::TopMargin);
|
||||||
const int leftWidth = d->background->marginSize(Plasma::LeftMargin);
|
const int leftWidth = d->background->marginSize(Plasma::LeftMargin);
|
||||||
const int rightWidth = d->background->marginSize(Plasma::RightMargin);
|
const int rightWidth = d->background->marginSize(Plasma::RightMargin);
|
||||||
@ -186,6 +179,7 @@ void ToolTip::updateTheme()
|
|||||||
Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
|
Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
|
||||||
setAutoFillBackground(true);
|
setAutoFillBackground(true);
|
||||||
setPalette(plasmaPalette);
|
setPalette(plasmaPalette);
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Plasma
|
} // namespace Plasma
|
||||||
|
@ -34,10 +34,9 @@ class ToolTip : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ToolTip(QObject *source);
|
ToolTip(QWidget *parent);
|
||||||
~ToolTip();
|
~ToolTip();
|
||||||
|
|
||||||
void updateTheme();
|
|
||||||
void setContent(const ToolTipContent &data);
|
void setContent(const ToolTipContent &data);
|
||||||
void prepareShowing(bool cueUpdate);
|
void prepareShowing(bool cueUpdate);
|
||||||
void setActivated(bool value);
|
void setActivated(bool value);
|
||||||
@ -52,7 +51,7 @@ protected:
|
|||||||
void paintEvent(QPaintEvent *);
|
void paintEvent(QPaintEvent *);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void sourceDestroyed();
|
void updateTheme();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ToolTipPrivate * const d;
|
ToolTipPrivate * const d;
|
||||||
|
@ -91,7 +91,7 @@ void WindowPreview::readWindowSize() const
|
|||||||
Window r;
|
Window r;
|
||||||
int x, y;
|
int x, y;
|
||||||
unsigned int w, h, b, d;
|
unsigned int w, h, b, d;
|
||||||
if (XGetGeometry(QX11Info::display(), id, &r, &x, &y, &w, &h, &b, &d)) {
|
if (id > 0 && XGetGeometry(QX11Info::display(), id, &r, &x, &y, &w, &h, &b, &d)) {
|
||||||
windowSize = QSize(w, h);
|
windowSize = QSize(w, h);
|
||||||
} else {
|
} else {
|
||||||
windowSize = QSize();
|
windowSize = QSize();
|
||||||
|
@ -50,6 +50,12 @@ ToolTipContent::ToolTipContent(const ToolTipContent &other)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ToolTipContent &ToolTipContent::operator=(const ToolTipContent &other)
|
||||||
|
{
|
||||||
|
*d = *other.d;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
ToolTipContent::ToolTipContent(const QString &mainText,
|
ToolTipContent::ToolTipContent(const QString &mainText,
|
||||||
const QString &subText,
|
const QString &subText,
|
||||||
const QPixmap &image)
|
const QPixmap &image)
|
||||||
|
@ -54,6 +54,8 @@ public:
|
|||||||
const QString &subText,
|
const QString &subText,
|
||||||
const QIcon &icon);
|
const QIcon &icon);
|
||||||
|
|
||||||
|
ToolTipContent &operator=(const ToolTipContent &other);
|
||||||
|
|
||||||
/** @return true if all the fields are empty */
|
/** @return true if all the fields are empty */
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ public :
|
|||||||
: currentWidget(0),
|
: currentWidget(0),
|
||||||
showTimer(0),
|
showTimer(0),
|
||||||
hideTimer(0),
|
hideTimer(0),
|
||||||
|
tipWidget(new ToolTip(0)),
|
||||||
state(ToolTipManager::Activated),
|
state(ToolTipManager::Activated),
|
||||||
isShown(false),
|
isShown(false),
|
||||||
delayedHide(false)
|
delayedHide(false)
|
||||||
@ -66,15 +67,12 @@ public :
|
|||||||
~ToolTipManagerPrivate()
|
~ToolTipManagerPrivate()
|
||||||
{
|
{
|
||||||
clearTips();
|
clearTips();
|
||||||
|
delete tipWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
void showToolTip();
|
void showToolTip();
|
||||||
void resetShownState();
|
void resetShownState();
|
||||||
|
|
||||||
/**
|
|
||||||
* called when the theme of plasma has change
|
|
||||||
*/
|
|
||||||
void themeUpdated();
|
|
||||||
/**
|
/**
|
||||||
* called when a widget inside the tooltip manager is deleted
|
* called when a widget inside the tooltip manager is deleted
|
||||||
*/
|
*/
|
||||||
@ -87,7 +85,8 @@ public :
|
|||||||
QGraphicsWidget *currentWidget;
|
QGraphicsWidget *currentWidget;
|
||||||
QTimer *showTimer;
|
QTimer *showTimer;
|
||||||
QTimer *hideTimer;
|
QTimer *hideTimer;
|
||||||
QHash<QGraphicsWidget *, ToolTip *> tooltips;
|
QHash<QGraphicsWidget *, ToolTipContent> tooltips;
|
||||||
|
ToolTip *tipWidget;
|
||||||
ToolTipManager::State state;
|
ToolTipManager::State state;
|
||||||
bool isShown : 1;
|
bool isShown : 1;
|
||||||
bool delayedHide : 1;
|
bool delayedHide : 1;
|
||||||
@ -113,9 +112,6 @@ ToolTipManager::ToolTipManager(QObject *parent)
|
|||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
d(new ToolTipManagerPrivate)
|
d(new ToolTipManagerPrivate)
|
||||||
{
|
{
|
||||||
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(themeUpdated()));
|
|
||||||
d->themeUpdated();
|
|
||||||
|
|
||||||
d->showTimer = new QTimer(this);
|
d->showTimer = new QTimer(this);
|
||||||
d->showTimer->setSingleShot(true);
|
d->showTimer->setSingleShot(true);
|
||||||
d->hideTimer = new QTimer(this);
|
d->hideTimer = new QTimer(this);
|
||||||
@ -136,10 +132,6 @@ void ToolTipManager::show(QGraphicsWidget *widget)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d->currentWidget) {
|
|
||||||
hide(d->currentWidget);
|
|
||||||
}
|
|
||||||
|
|
||||||
d->hideTimer->stop();
|
d->hideTimer->stop();
|
||||||
d->delayedHide = false;
|
d->delayedHide = false;
|
||||||
d->showTimer->stop();
|
d->showTimer->stop();
|
||||||
@ -156,12 +148,7 @@ void ToolTipManager::show(QGraphicsWidget *widget)
|
|||||||
|
|
||||||
bool ToolTipManager::isVisible(QGraphicsWidget *widget) const
|
bool ToolTipManager::isVisible(QGraphicsWidget *widget) const
|
||||||
{
|
{
|
||||||
ToolTip *tooltip = d->tooltips.value(widget);
|
return d->currentWidget == widget && d->tipWidget->isVisible();
|
||||||
if (tooltip) {
|
|
||||||
return tooltip->isVisible();
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTipManagerPrivate::doDelayedHide()
|
void ToolTipManagerPrivate::doDelayedHide()
|
||||||
@ -173,13 +160,14 @@ void ToolTipManagerPrivate::doDelayedHide()
|
|||||||
|
|
||||||
void ToolTipManager::hide(QGraphicsWidget *widget)
|
void ToolTipManager::hide(QGraphicsWidget *widget)
|
||||||
{
|
{
|
||||||
ToolTip *tooltip = d->tooltips.value(widget);
|
if (d->currentWidget != widget) {
|
||||||
if (tooltip) {
|
return;
|
||||||
d->showTimer->stop(); // stop the timer to show the tooltip
|
|
||||||
d->delayedHide = false;
|
|
||||||
d->currentWidget = 0;
|
|
||||||
tooltip->hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d->showTimer->stop(); // stop the timer to show the tooltip
|
||||||
|
d->delayedHide = false;
|
||||||
|
d->currentWidget = 0;
|
||||||
|
d->tipWidget->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTipManager::registerWidget(QGraphicsWidget *widget)
|
void ToolTipManager::registerWidget(QGraphicsWidget *widget)
|
||||||
@ -189,7 +177,7 @@ void ToolTipManager::registerWidget(QGraphicsWidget *widget)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//the tooltip is not registered we add it in our map of tooltips
|
//the tooltip is not registered we add it in our map of tooltips
|
||||||
d->tooltips.insert(widget, 0);
|
d->tooltips.insert(widget, ToolTipContent());
|
||||||
widget->installEventFilter(this);
|
widget->installEventFilter(this);
|
||||||
//connect to object destruction
|
//connect to object destruction
|
||||||
connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(onWidgetDestroyed(QObject*)));
|
connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(onWidgetDestroyed(QObject*)));
|
||||||
@ -202,10 +190,7 @@ void ToolTipManager::unregisterWidget(QGraphicsWidget *widget)
|
|||||||
}
|
}
|
||||||
|
|
||||||
widget->removeEventFilter(this);
|
widget->removeEventFilter(this);
|
||||||
ToolTip *tooltip = d->tooltips.take(widget);
|
d->tooltips.remove(widget);
|
||||||
if (tooltip) {
|
|
||||||
tooltip->deleteLater();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTipManager::setContent(QGraphicsWidget *widget, const ToolTipContent &data)
|
void ToolTipManager::setContent(QGraphicsWidget *widget, const ToolTipContent &data)
|
||||||
@ -215,24 +200,15 @@ void ToolTipManager::setContent(QGraphicsWidget *widget, const ToolTipContent &d
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerWidget(widget);
|
registerWidget(widget);
|
||||||
|
d->tooltips[widget] = data;
|
||||||
|
|
||||||
ToolTip *tooltip = d->tooltips.value(widget);
|
if (d->currentWidget == widget) {
|
||||||
|
if (data.isEmpty()) {
|
||||||
if (data.isEmpty()) {
|
hide(widget);
|
||||||
if (tooltip) {
|
|
||||||
tooltip->deleteLater();
|
|
||||||
}
|
}
|
||||||
d->tooltips.insert(widget, 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tooltip) {
|
d->tipWidget->setContent(data);
|
||||||
tooltip = new ToolTip(widget);
|
|
||||||
d->tooltips.insert(widget, tooltip);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tooltip->setContent(data);
|
|
||||||
tooltip->updateTheme();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTipManager::clearContent(QGraphicsWidget *widget)
|
void ToolTipManager::clearContent(QGraphicsWidget *widget)
|
||||||
@ -261,17 +237,6 @@ ToolTipManager::State ToolTipManager::state() const
|
|||||||
return d->state;
|
return d->state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTipManagerPrivate::themeUpdated()
|
|
||||||
{
|
|
||||||
QHashIterator<QGraphicsWidget*, ToolTip *> iterator(tooltips);
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
iterator.next();
|
|
||||||
if (iterator.value()) {
|
|
||||||
iterator.value()->updateTheme();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTipManagerPrivate::onWidgetDestroyed(QObject *object)
|
void ToolTipManagerPrivate::onWidgetDestroyed(QObject *object)
|
||||||
{
|
{
|
||||||
if (!object) {
|
if (!object) {
|
||||||
@ -293,41 +258,22 @@ void ToolTipManagerPrivate::onWidgetDestroyed(QObject *object)
|
|||||||
delayedHide = false;
|
delayedHide = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMutableHashIterator<QGraphicsWidget*, ToolTip *> iterator(tooltips);
|
tooltips.remove(w);
|
||||||
while (iterator.hasNext()) {
|
|
||||||
iterator.next();
|
|
||||||
//kDebug() << (int)iterator.key() << (int)w;
|
|
||||||
if (iterator.key() == w) {
|
|
||||||
ToolTip *tooltip = iterator.value();
|
|
||||||
iterator.remove();
|
|
||||||
if (tooltip) {
|
|
||||||
//kDebug() << "deleting the tooltip!";
|
|
||||||
tooltip->hide();
|
|
||||||
tooltip->deleteLater();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTipManagerPrivate::clearTips()
|
void ToolTipManagerPrivate::clearTips()
|
||||||
{
|
{
|
||||||
foreach (ToolTip *tip, tooltips) {
|
|
||||||
delete tip;
|
|
||||||
}
|
|
||||||
|
|
||||||
tooltips.clear();
|
tooltips.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTipManagerPrivate::resetShownState()
|
void ToolTipManagerPrivate::resetShownState()
|
||||||
{
|
{
|
||||||
if (currentWidget) {
|
if (currentWidget) {
|
||||||
ToolTip * tooltip = tooltips.value(currentWidget);
|
if (!tipWidget->isVisible() || delayedHide) {
|
||||||
if (tooltip && (!tooltip->isVisible() || delayedHide)) {
|
|
||||||
//One might have moused out and back in again
|
//One might have moused out and back in again
|
||||||
delayedHide = false;
|
delayedHide = false;
|
||||||
isShown = false;
|
isShown = false;
|
||||||
tooltip->hide();
|
tipWidget->hide();
|
||||||
currentWidget = 0;
|
currentWidget = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -342,30 +288,31 @@ void ToolTipManagerPrivate::showToolTip()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ToolTip *tooltip = tooltips.value(currentWidget);
|
ToolTipContent tooltip = tooltips.value(currentWidget);
|
||||||
bool justCreated = false;
|
bool justCreated = false;
|
||||||
|
|
||||||
if (!tooltip) {
|
if (tooltip.isEmpty()) {
|
||||||
// give the object a chance for delayed loading of the tip
|
// give the object a chance for delayed loading of the tip
|
||||||
QMetaObject::invokeMethod(currentWidget, "toolTipAboutToShow");
|
QMetaObject::invokeMethod(currentWidget, "toolTipAboutToShow");
|
||||||
tooltip = tooltips.value(currentWidget);
|
tooltip = tooltips.value(currentWidget);
|
||||||
//kDebug() << "attempt to make one ... we gots" << tooltip;
|
//kDebug() << "attempt to make one ... we gots" << tooltip.isEmpty();
|
||||||
if (tooltip) {
|
|
||||||
justCreated = true;
|
if (tooltip.isEmpty()) {
|
||||||
} else {
|
|
||||||
currentWidget = 0;
|
currentWidget = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
justCreated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
tooltip->hide();
|
|
||||||
//kDebug() << "about to show" << justCreated;
|
//kDebug() << "about to show" << justCreated;
|
||||||
tooltip->prepareShowing(!justCreated);
|
tipWidget->setContent(tooltip);
|
||||||
tooltip->move(ToolTipManager::self()->m_corona->popupPosition(currentWidget, tooltip->size()));
|
tipWidget->prepareShowing(!justCreated);
|
||||||
|
tipWidget->move(ToolTipManager::self()->m_corona->popupPosition(currentWidget, tipWidget->size()));
|
||||||
|
tipWidget->show();
|
||||||
isShown = true; //ToolTip is visible
|
isShown = true; //ToolTip is visible
|
||||||
tooltip->show();
|
|
||||||
|
|
||||||
delayedHide = tooltip->autohide();
|
delayedHide = tooltip.autohide();
|
||||||
if (delayedHide) {
|
if (delayedHide) {
|
||||||
//kDebug() << "starting authoide";
|
//kDebug() << "starting authoide";
|
||||||
hideTimer->start(3000);
|
hideTimer->start(3000);
|
||||||
|
@ -188,7 +188,6 @@ private:
|
|||||||
Q_PRIVATE_SLOT(d, void showToolTip())
|
Q_PRIVATE_SLOT(d, void showToolTip())
|
||||||
Q_PRIVATE_SLOT(d, void resetShownState())
|
Q_PRIVATE_SLOT(d, void resetShownState())
|
||||||
Q_PRIVATE_SLOT(d, void onWidgetDestroyed(QObject*))
|
Q_PRIVATE_SLOT(d, void onWidgetDestroyed(QObject*))
|
||||||
Q_PRIVATE_SLOT(d, void themeUpdated())
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Plasma
|
} // namespace Plasma
|
||||||
|
Loading…
Reference in New Issue
Block a user