[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/workspace/libs/plasma
From: Aaron J. Seigo <aseigo () kde ! org>
Date: 2008-11-02 6:55:11
Message-ID: 1225608911.643162.31361.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 878933 by aseigo:
use only one actual tip widget, store the data otherwise
M +12 -18 private/tooltip.cpp
M +2 -3 private/tooltip_p.h
M +1 -1 private/windowpreview.cpp
M +6 -0 tooltipcontent.cpp
M +2 -0 tooltipcontent.h
M +34 -87 tooltipmanager.cpp
M +1 -2 tooltipmanager.h
--- trunk/KDE/kdebase/workspace/libs/plasma/private/tooltip.cpp #878932:878933
@@ -40,11 +40,11 @@
class ToolTipPrivate
{
public:
- ToolTipPrivate(QObject *s)
+ ToolTipPrivate()
: label(0),
imageLabel(0),
preview(0),
- source(s),
+ source(0),
autohide(true)
{ }
@@ -77,14 +77,10 @@
}
}
-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 @@
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 @@
d->autohide = data.autohide();
if (isVisible()) {
+ d->preview->setInfo();
resize(sizeHint());
}
}
@@ -135,6 +135,7 @@
}
layout()->activate();
+ d->preview->setInfo();
resize(sizeHint());
}
@@ -157,11 +158,6 @@
d->background->paintFrame(&painter);
}
-void ToolTip::sourceDestroyed()
-{
- d->source = 0;
-}
-
bool ToolTip::autohide() const
{
return d->autohide;
@@ -169,9 +165,6 @@
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 @@
Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
setAutoFillBackground(true);
setPalette(plasmaPalette);
+ update();
}
} // namespace Plasma
--- trunk/KDE/kdebase/workspace/libs/plasma/private/tooltip_p.h #878932:878933
@@ -34,10 +34,9 @@
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 @@
void paintEvent(QPaintEvent *);
private Q_SLOTS:
- void sourceDestroyed();
+ void updateTheme();
private:
ToolTipPrivate * const d;
--- trunk/KDE/kdebase/workspace/libs/plasma/private/windowpreview.cpp #878932:878933
@@ -91,7 +91,7 @@
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();
--- trunk/KDE/kdebase/workspace/libs/plasma/tooltipcontent.cpp #878932:878933
@@ -50,6 +50,12 @@
{
}
+ToolTipContent &ToolTipContent::operator=(const ToolTipContent &other)
+{
+ *d = *other.d;
+ return *this;
+}
+
ToolTipContent::ToolTipContent(const QString &mainText,
const QString &subText,
const QPixmap &image)
--- trunk/KDE/kdebase/workspace/libs/plasma/tooltipcontent.h #878932:878933
@@ -54,6 +54,8 @@
const QString &subText,
const QIcon &icon);
+ ToolTipContent &operator=(const ToolTipContent &other);
+
/** @return true if all the fields are empty */
bool isEmpty() const;
--- trunk/KDE/kdebase/workspace/libs/plasma/tooltipmanager.cpp #878932:878933
@@ -56,6 +56,7 @@
: currentWidget(0),
showTimer(0),
hideTimer(0),
+ tipWidget(new ToolTip(0)),
state(ToolTipManager::Activated),
isShown(false),
delayedHide(false)
@@ -66,16 +67,13 @@
~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
*/
void onWidgetDestroyed(QObject * object);
@@ -87,7 +85,8 @@
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 @@
: 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 @@
return;
}
- if (d->currentWidget) {
- hide(d->currentWidget);
- }
-
d->hideTimer->stop();
d->delayedHide = false;
d->showTimer->stop();
@@ -156,12 +148,7 @@
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 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 @@
}
//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 @@
}
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 @@
}
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 @@
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 @@
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 @@
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);
--- trunk/KDE/kdebase/workspace/libs/plasma/tooltipmanager.h #878932:878933
@@ -184,11 +184,10 @@
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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic