export the location as tooltip property

This commit is contained in:
Marco Martin 2014-01-13 02:00:45 +01:00
parent 69efa8d941
commit 4235ec4842
4 changed files with 51 additions and 17 deletions

View File

@ -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;
}

View File

@ -30,7 +30,9 @@
#include <kwindoweffects.h>
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()) {

View File

@ -25,6 +25,7 @@
#include <QQuickItem>
#include <QWeakPointer>
#include <QtCore/QVariant>
#include <Plasma/Plasma>
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<QQuickItem> m_mainItem;
QTimer *m_showTimer;
QString m_mainText;

View File

@ -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)