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