diff --git a/components/Button.qml b/components/Button.qml index 1a978be454efcf8928924503f18b4db56db6e091..885a9f0e84f24d2983045e73f613c0ab6d1a6a16 100644 --- a/components/Button.qml +++ b/components/Button.qml @@ -2,7 +2,7 @@ import QtQuick 1.0 import "custom" as Components Components.Button { - id:button + id: button width: Math.max(80, sizehint.width) height: Math.max(22, sizehint.height) @@ -11,6 +11,10 @@ Components.Button { property bool defaultbutton property string hint + TooltipArea { + anchors.fill: parent + text: button.tooltip + } background: StyleItem { id: styleitem @@ -25,13 +29,6 @@ Components.Button { // If no icon, let the style do the drawing activeControl: focus ? "default" : "" - Connections{ - target: button - onToolTipTriggered: styleitem.showTip() - } - function showTip(){ - showToolTip(tooltip); - } } label: Item { diff --git a/src/styleitem/qstyleitem.cpp b/src/styleitem/qstyleitem.cpp index 0fa139889ba1526db57a3a6ea4b0d886bbadb350..1bdb9f774aab7731bb44bbbe5e9537e5967f991f 100644 --- a/src/styleitem/qstyleitem.cpp +++ b/src/styleitem/qstyleitem.cpp @@ -831,23 +831,6 @@ bool QStyleItem::eventFilter(QObject *o, QEvent *e) { return QObject::eventFilter(o, e); } -void QStyleItem::showToolTip(const QString &str) -{ - QPoint global; - QPointF scenePos = mapToScene(width() - 20, 0); - QGraphicsScene *scene = QGraphicsItem::scene(); - QObject *parent = scene->parent(); - if (parent) { - QGraphicsView *view = qobject_cast<QGraphicsView*>(parent); - if (view) { - QPoint p = view->mapFromScene(scenePos); - global = view->mapToGlobal(p); - } - } - - QToolTip::showText(QPoint(global.x(),global.y()), str); -} - QRect QStyleItem::subControlRect(const QString &subcontrolString) { QStyle::SubControl subcontrol = QStyle::SC_None; diff --git a/src/styleitem/qstyleitem.h b/src/styleitem/qstyleitem.h index 105f90fe3760af8d6309f3ede86b33761ce9aa8e..6f6daf270269e1c1ab197b728c3a0bbf732923e5 100644 --- a/src/styleitem/qstyleitem.h +++ b/src/styleitem/qstyleitem.h @@ -174,7 +174,6 @@ public Q_SLOTS: void updateItem(){update();} QString hitTest(int x, int y); QRect subControlRect(const QString &subcontrolString); - void showToolTip(const QString &str); int textWidth(const QString &); Q_SIGNALS: diff --git a/src/styleitem/qstyleplugin.cpp b/src/styleitem/qstyleplugin.cpp index b1cd386d07138cf76a19182ae596d6caf1ecc69d..ef7c630f23b0ceb589ef44f27ed6601e1abf3476 100644 --- a/src/styleitem/qstyleplugin.cpp +++ b/src/styleitem/qstyleplugin.cpp @@ -47,6 +47,7 @@ #include "qdesktopitem.h" #include "qwheelarea.h" #include "qcursorarea.h" +#include "qtooltiparea.h" #include <qdeclarativeextensionplugin.h> #include <qdeclarativeengine.h> @@ -82,6 +83,7 @@ void StylePlugin::registerTypes(const char *uri) { qmlRegisterType<QStyleItem>(uri, 0, 1, "StyleItem"); qmlRegisterType<QCursorArea>(uri, 0, 1, "CursorArea"); + qmlRegisterType<QTooltipArea>(uri, 0, 1, "TooltipArea"); qmlRegisterType<QRangeModel>(uri, 0, 1, "RangeModel"); qmlRegisterType<QGraphicsDropShadowEffect>(uri, 0, 1, "DropShadow"); qmlRegisterType<QDeclarativeFolderListModel>(uri, 0, 1, "FileSystemModel"); diff --git a/src/styleitem/qtooltiparea.cpp b/src/styleitem/qtooltiparea.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2a1cb3e2abac70a440501c509efab1371614d59a --- /dev/null +++ b/src/styleitem/qtooltiparea.cpp @@ -0,0 +1,41 @@ +#include "qtooltiparea.h" +#include <QGraphicsView> +#include <QToolTip> +#include <QApplication> + +QTooltipArea::QTooltipArea(QDeclarativeItem *parent) : + QDeclarativeItem(parent) +{ + setAcceptHoverEvents(true); + connect(&m_tiptimer, SIGNAL(timeout()), this, SLOT(timeout())); +} + +void QTooltipArea::setText(const QString &t) +{ + if (t != m_text) { + m_text = t; + emit textChanged(); + } +} + +void QTooltipArea::showToolTip(const QString &str) const +{ + QToolTip::showText(cursor().pos(), str); +} + +void QTooltipArea::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + m_tiptimer.start(1000); + return QDeclarativeItem::hoverEnterEvent(event); +} + +void QTooltipArea::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + m_tiptimer.stop(); + return QDeclarativeItem::hoverLeaveEvent(event); +} + +void QTooltipArea::timeout() +{ + showToolTip(m_text); +} diff --git a/src/styleitem/qtooltiparea.h b/src/styleitem/qtooltiparea.h new file mode 100644 index 0000000000000000000000000000000000000000..9a2c68e6d5bb60758a7b6278d70284afe26e5908 --- /dev/null +++ b/src/styleitem/qtooltiparea.h @@ -0,0 +1,32 @@ +#ifndef QTOOLTIPAREA_H +#define QTOOLTIPAREA_H + +#include <QDeclarativeItem> +#include <QTimer> + +class QTooltipArea : public QDeclarativeItem +{ + Q_OBJECT + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + +public: + QTooltipArea(QDeclarativeItem *parent = 0); + void setText(const QString &t); + QString text() const {return m_text;} + void showToolTip(const QString &str) const; + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + +public slots: + void timeout(); + +signals: + void textChanged(); + +private: + + QTimer m_tiptimer; + QString m_text; +}; + +#endif // QTOOLTIPAREA_H diff --git a/src/styleitem/styleitem.pro b/src/styleitem/styleitem.pro index 68c6d57a42fda28eb9120e7bd8e91ae13b55cd49..21aba3fa4e2fd53406f68d448cd5408fd359d54d 100644 --- a/src/styleitem/styleitem.pro +++ b/src/styleitem/styleitem.pro @@ -21,7 +21,8 @@ HEADERS += qtmenu.h \ qwindowitem.h \ qdesktopitem.h \ qtoplevelwindow.h \ - qcursorarea.h + qcursorarea.h \ + qtooltiparea.h SOURCES += qtmenu.cpp \ qtmenubar.cpp \ @@ -34,7 +35,8 @@ SOURCES += qtmenu.cpp \ qwindowitem.cpp \ qdesktopitem.cpp \ qtoplevelwindow.cpp \ - qcursorarea.cpp + qcursorarea.cpp \ + qtooltiparea.cpp TARGETPATH = QtDesktop/plugin @@ -57,3 +59,5 @@ symbian { + +