From 4235ec4842731ecdd5d7b4653cc038718db180f2 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 13 Jan 2014 02:00:45 +0100 Subject: [PATCH] export the location as tooltip property --- src/declarativeimports/core/dialog.cpp | 2 +- src/declarativeimports/core/tooltip.cpp | 54 +++++++++++++------ src/declarativeimports/core/tooltip.h | 11 ++++ src/declarativeimports/core/tooltipdialog.cpp | 1 + 4 files changed, 51 insertions(+), 17 deletions(-) diff --git a/src/declarativeimports/core/dialog.cpp b/src/declarativeimports/core/dialog.cpp index 65b58cea1..2c15f30c1 100644 --- a/src/declarativeimports/core/dialog.cpp +++ b/src/declarativeimports/core/dialog.cpp @@ -445,7 +445,7 @@ void DialogProxy::syncBorders() int borders = Plasma::FrameSvg::AllBorders; //Tooltips always have all the borders - if (flags() & Qt::ToolTip) { + if (!(flags() & Qt::ToolTip)) { if (x() <= avail.x() || m_location == Plasma::Types::LeftEdge) { borders = borders & ~Plasma::FrameSvg::LeftBorder; } diff --git a/src/declarativeimports/core/tooltip.cpp b/src/declarativeimports/core/tooltip.cpp index 9c692e26b..607f08ceb 100644 --- a/src/declarativeimports/core/tooltip.cpp +++ b/src/declarativeimports/core/tooltip.cpp @@ -30,7 +30,9 @@ #include ToolTip::ToolTip(QQuickItem *parent) - : QQuickItem(parent) + : QQuickItem(parent), + m_containsMouse(false), + m_location(Plasma::Types::Floating) { m_showTimer = new QTimer(this); m_showTimer->setSingleShot(true); @@ -78,25 +80,31 @@ void ToolTip::showToolTip() } //heuristics for knowing the diration - Plasma::Types::Direction dir = Plasma::Types::Up; - QPoint pos = mapToScene(QPoint(0, 0)).toPoint(); - - if (window() && window()->screen()) { - pos = window()->mapToGlobal(pos); - } - QPoint popupPos = dlg->popupPosition(this, dlg->size(), Qt::AlignCenter); - - if (pos.y() + height() <= popupPos.y()) { - dir = Plasma::Types::Down; - } else if (pos.x() + width() <= popupPos.x()) { - dir = Plasma::Types::Right; - } else if (pos.y() >= popupPos.y() + dlg->height()) { + Plasma::Types::Direction dir; + if (m_location == Plasma::Types::Floating) { dir = Plasma::Types::Up; - } else if (pos.x() >= popupPos.x() + dlg->width()) { - dir = Plasma::Types::Left; + QPoint pos = mapToScene(QPoint(0, 0)).toPoint(); + + if (window() && window()->screen()) { + pos = window()->mapToGlobal(pos); + } + QPoint popupPos = dlg->popupPosition(this, dlg->size(), Qt::AlignCenter); + + if (pos.y() + height() <= popupPos.y()) { + dir = Plasma::Types::Down; + } else if (pos.x() + width() <= popupPos.x()) { + dir = Plasma::Types::Right; + } else if (pos.y() >= popupPos.y() + dlg->height()) { + dir = Plasma::Types::Up; + } else if (pos.x() >= popupPos.x() + dlg->width()) { + dir = Plasma::Types::Left; + } + } else { + dir = Plasma::locationToDirection(m_location); } dlg->setDirection(dir); + dlg->setLocation(m_location); dlg->setMainItem(mainItem()); dlg->setVisualParent(this); dlg->setVisible(true); @@ -132,6 +140,20 @@ void ToolTip::setSubText(const QString &subText) emit subTextChanged(); } +Plasma::Types::Location ToolTip::location() const +{ + return m_location; +} + +void ToolTip::setLocation(Plasma::Types::Location location) +{ + if (m_location == location) { + return; + } + m_location = location; + emit locationChanged(); +} + QVariant ToolTip::icon() const { if (m_icon.isValid()) { diff --git a/src/declarativeimports/core/tooltip.h b/src/declarativeimports/core/tooltip.h index c41cb9d07..a51c287db 100644 --- a/src/declarativeimports/core/tooltip.h +++ b/src/declarativeimports/core/tooltip.h @@ -25,6 +25,7 @@ #include #include #include +#include class QQuickItem; class QGraphicsWidget; @@ -89,6 +90,11 @@ class ToolTip : public QQuickItem */ Q_PROPERTY(bool m_containsMouse READ containsMouse NOTIFY containsMouseChanged) + /** + * Plasma Location of the dialog window. Useful if this dialog is a popup for a panel + */ + Q_PROPERTY(Plasma::Types::Location location READ location WRITE setLocation NOTIFY locationChanged) + /** * TODO: single property for images? * An image for this tooltip, accepted values are an icon name, a QIcon, QImage or QPixmap @@ -116,6 +122,9 @@ public: QVariant image() const; void setImage(const QVariant &image); + Plasma::Types::Location location() const; + void setLocation(Plasma::Types::Location location); + bool containsMouse() const; void setContainsMouse(bool contains); @@ -132,9 +141,11 @@ Q_SIGNALS: void iconChanged(); void imageChanged(); void containsMouseChanged(); + void locationChanged(); private: bool m_containsMouse; + Plasma::Types::Location m_location; QWeakPointer m_mainItem; QTimer *m_showTimer; QString m_mainText; diff --git a/src/declarativeimports/core/tooltipdialog.cpp b/src/declarativeimports/core/tooltipdialog.cpp index 68503cf56..5598c75ec 100644 --- a/src/declarativeimports/core/tooltipdialog.cpp +++ b/src/declarativeimports/core/tooltipdialog.cpp @@ -94,6 +94,7 @@ void ToolTipDialog::showEvent(QShowEvent *event) m_showTimer->start(m_hideTimeout); m_animation->stop(); DialogProxy::showEvent(event); + setFlags(Qt::ToolTip); } void ToolTipDialog::hideEvent(QHideEvent *event)