ToolTip->ToolTipArea
This commit is contained in:
parent
798b7665d4
commit
6a0525c1c3
@ -91,103 +91,67 @@ PlasmaComponents.Page {
|
|||||||
|
|
||||||
Row {
|
Row {
|
||||||
spacing: _s
|
spacing: _s
|
||||||
PlasmaCore.IconItem {
|
PlasmaCore.ToolTipArea {
|
||||||
id: akonadiIcon
|
width: childrenRect.width
|
||||||
objectName: "akonadiIcon"
|
height: childrenRect.height
|
||||||
source: "akonadi"
|
icon: "klipper"
|
||||||
width: height
|
mainText: "Fish sighted in the wild, in the wild, a fish was seen."
|
||||||
height: _h
|
subText: "A mean-looking grouper swam by."
|
||||||
//anchors.horizontalCenter: parent.horizontalCenter
|
PlasmaCore.IconItem {
|
||||||
Rectangle { color: "orange"; opacity: 0.3; anchors.fill: parent; }
|
id: akonadiIcon
|
||||||
PlasmaCore.ToolTip {
|
objectName: "akonadiIcon"
|
||||||
anchors.fill: parent
|
source: "akonadi"
|
||||||
target: akonadiIcon
|
width: height
|
||||||
icon: "klipper"
|
height: _h
|
||||||
mainText: "Fish sighted in the wild, in the wild, a fish was seen."
|
//anchors.horizontalCenter: parent.horizontalCenter
|
||||||
subText: "A mean-looking grouper swam by."
|
Rectangle { color: "orange"; opacity: 0.3; anchors.fill: parent; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Image {
|
PlasmaCore.ToolTipArea {
|
||||||
objectName: "bridgeimage"
|
|
||||||
height: _h
|
height: _h
|
||||||
width: height
|
width: height
|
||||||
fillMode: Image.PreserveAspectFit
|
image: bridgeimage.source
|
||||||
source: "../images/bridge.jpg"
|
mainText: "Bridge"
|
||||||
PlasmaCore.ToolTip {
|
subText: "Waalbrug."
|
||||||
target: parent
|
Image {
|
||||||
image: parent.source
|
id: bridgeimage
|
||||||
mainText: "Bridge"
|
objectName: "bridgeimage"
|
||||||
subText: "Waalbrug."
|
height: _h
|
||||||
|
width: height
|
||||||
|
fillMode: Image.PreserveAspectFit
|
||||||
|
source: "../images/bridge.jpg"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Image {
|
PlasmaCore.ToolTipArea {
|
||||||
objectName: "surfboardimage"
|
width: childrenRect.width
|
||||||
height: _h
|
height: childrenRect.height
|
||||||
width: height
|
mainItem: PlasmaComponents.Label {
|
||||||
fillMode: Image.PreserveAspectFit
|
text: "Nijmegen North Beach"
|
||||||
source: "../images/surfboard.jpg"
|
anchors.centerIn: parent
|
||||||
PlasmaCore.ToolTip {
|
}
|
||||||
anchors.fill: parent
|
Image {
|
||||||
image: parent.source
|
objectName: "surfboardimage"
|
||||||
mainItem: PlasmaComponents.Label {
|
height: _h
|
||||||
text: "Nijmegen North Beach"
|
width: height
|
||||||
anchors.centerIn: parent
|
fillMode: Image.PreserveAspectFit
|
||||||
}
|
source: "../images/surfboard.jpg"
|
||||||
|
|
||||||
//subText: "A surfboard on the beach. <br />The photo shows the Waal river's north beach, \
|
//subText: "A surfboard on the beach. <br />The photo shows the Waal river's north beach, \
|
||||||
//across the water from Nijmegen, Netherlands. It was taken during the summer festivals a few years back."
|
//across the water from Nijmegen, Netherlands. It was taken during the summer festivals a few years back."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlasmaComponents.Button {
|
PlasmaCore.ToolTipArea {
|
||||||
text: "Button"
|
width: childrenRect.width
|
||||||
iconSource: "call-start"
|
height: childrenRect.height
|
||||||
PlasmaCore.ToolTip {
|
mainText: "Tooltip on button"
|
||||||
target: parent
|
PlasmaComponents.Button {
|
||||||
mainText: "Tooltip on button"
|
id: button
|
||||||
}
|
text: "Button"
|
||||||
}
|
iconSource: "call-start"
|
||||||
|
|
||||||
|
|
||||||
QtExtras.MouseEventListener {
|
|
||||||
id: task1
|
|
||||||
|
|
||||||
width: height
|
|
||||||
height: _h*2
|
|
||||||
|
|
||||||
hoverEnabled: true
|
|
||||||
|
|
||||||
onContainsMouseChanged: {
|
|
||||||
if (containsMouse) {
|
|
||||||
print("Setting target to task1");
|
|
||||||
tooltip.target = task1;
|
|
||||||
tooltip.mainText = "Bridge"
|
|
||||||
tooltip.subText = "in Nijmegen"
|
|
||||||
} else {
|
|
||||||
print("Setting target to null");
|
|
||||||
tooltip.target = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Image {
|
|
||||||
objectName: "bridgeimage1"
|
|
||||||
anchors.fill: parent
|
|
||||||
fillMode: Image.PreserveAspectFit
|
|
||||||
source: "../images/bridge.jpg"
|
|
||||||
MouseArea {
|
|
||||||
anchors.fill: parent
|
|
||||||
onClicked: {
|
|
||||||
print("bridgeimage1 clicked");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PlasmaCore.ToolTip {
|
|
||||||
id: tooltip
|
|
||||||
target: null
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ void CoreBindingsPlugin::registerTypes(const char *uri)
|
|||||||
qmlRegisterType<Plasma::SortFilterModel>(uri, 2, 0, "SortFilterModel");
|
qmlRegisterType<Plasma::SortFilterModel>(uri, 2, 0, "SortFilterModel");
|
||||||
|
|
||||||
qmlRegisterType<DialogProxy>(uri, 2, 0, "Dialog");
|
qmlRegisterType<DialogProxy>(uri, 2, 0, "Dialog");
|
||||||
qmlRegisterType<ToolTip>(uri, 2, 0, "ToolTip");
|
qmlRegisterType<ToolTip>(uri, 2, 0, "ToolTipArea");
|
||||||
|
|
||||||
qmlRegisterInterface<Plasma::Service>("Service");
|
qmlRegisterInterface<Plasma::Service>("Service");
|
||||||
qRegisterMetaType<Plasma::Service*>("Service");
|
qRegisterMetaType<Plasma::Service*>("Service");
|
||||||
|
@ -90,7 +90,6 @@ Item {
|
|||||||
PlasmaExtras.Heading {
|
PlasmaExtras.Heading {
|
||||||
id: tooltipMaintext
|
id: tooltipMaintext
|
||||||
level: 3
|
level: 3
|
||||||
width: parent.preferredTextWidth
|
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
text: toolTip ? toolTip.mainText : ""
|
text: toolTip ? toolTip.mainText : ""
|
||||||
anchors {
|
anchors {
|
||||||
|
@ -35,9 +35,11 @@ ToolTip::ToolTip(QQuickItem *parent)
|
|||||||
m_showTimer = new QTimer(this);
|
m_showTimer = new QTimer(this);
|
||||||
m_showTimer->setSingleShot(true);
|
m_showTimer->setSingleShot(true);
|
||||||
connect(m_showTimer, &QTimer::timeout, [=]() {
|
connect(m_showTimer, &QTimer::timeout, [=]() {
|
||||||
setVisible(true);
|
showToolTip();
|
||||||
});
|
});
|
||||||
|
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
|
setFiltersChildMouseEvents(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ToolTip::~ToolTip()
|
ToolTip::~ToolTip()
|
||||||
@ -58,60 +60,26 @@ void ToolTip::setMainItem(QQuickItem *mainItem)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QQuickItem *ToolTip::target() const
|
void ToolTip::showToolTip()
|
||||||
{
|
|
||||||
if (m_target.data()) {
|
|
||||||
return m_target.data();
|
|
||||||
} else {
|
|
||||||
QQuickItem *qqi = qobject_cast<QQuickItem*>(parent());
|
|
||||||
return qqi;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTip::setTarget(QQuickItem *target)
|
|
||||||
{
|
|
||||||
if (m_target.data() == target) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_target = target;
|
|
||||||
setParentItem(target);
|
|
||||||
|
|
||||||
property("anchors").value<QObject *>()->setProperty("fill", QVariant::fromValue(parentItem()));
|
|
||||||
|
|
||||||
emit targetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ToolTip::isVisible() const
|
|
||||||
{
|
{
|
||||||
ToolTipDialog *dlg = ToolTipDialog::instance();
|
ToolTipDialog *dlg = ToolTipDialog::instance();
|
||||||
return (dlg->mainItem() == mainItem() && mainItem() && mainItem()->isVisible());
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTip::setVisible(const bool visible)
|
if (!mainItem()) {
|
||||||
{
|
setMainItem(dlg->loadDefaultItem());
|
||||||
ToolTipDialog *dlg = ToolTipDialog::instance();
|
|
||||||
if (visible) {
|
|
||||||
|
|
||||||
if (!mainItem()) {
|
|
||||||
setMainItem(dlg->loadDefaultItem());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dlg->mainItem()) {
|
|
||||||
dlg->mainItem()->setVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mainItem()) {
|
|
||||||
mainItem()->setProperty("toolTip", QVariant::fromValue(this));
|
|
||||||
mainItem()->setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
dlg->setMainItem(mainItem());
|
|
||||||
dlg->setVisualParent(target());
|
|
||||||
dlg->setVisible(true);
|
|
||||||
} else {
|
|
||||||
dlg->setVisible(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dlg->mainItem()) {
|
||||||
|
dlg->mainItem()->setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mainItem()) {
|
||||||
|
mainItem()->setProperty("toolTip", QVariant::fromValue(this));
|
||||||
|
mainItem()->setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
dlg->setMainItem(mainItem());
|
||||||
|
dlg->setVisible(true);
|
||||||
|
dlg->setVisualParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ToolTip::mainText() const
|
QString ToolTip::mainText() const
|
||||||
@ -185,24 +153,20 @@ void ToolTip::setImage(const QVariant &image)
|
|||||||
void ToolTip::hoverEnterEvent(QHoverEvent *event)
|
void ToolTip::hoverEnterEvent(QHoverEvent *event)
|
||||||
{
|
{
|
||||||
if (ToolTipDialog::instance()->isVisible()) {
|
if (ToolTipDialog::instance()->isVisible()) {
|
||||||
//FIXME: setVisible needs to be renamed in sync or something like that
|
//FIXME: showToolTip needs to be renamed in sync or something like that
|
||||||
setVisible(true);
|
showToolTip();
|
||||||
} else {
|
} else {
|
||||||
m_showTimer->start(500);
|
m_showTimer->start(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
//relay the event
|
|
||||||
if (window()) {
|
|
||||||
window()->sendEvent(target(), event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTip::hoverLeaveEvent(QHoverEvent *event)
|
void ToolTip::hoverLeaveEvent(QHoverEvent *event)
|
||||||
{
|
{
|
||||||
m_showTimer->stop();
|
m_showTimer->stop();
|
||||||
|
|
||||||
//relay the event
|
|
||||||
if (window()) {
|
|
||||||
window()->sendEvent(target(), event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ToolTip::childMouseEventFilter(QQuickItem *item, QEvent *event)
|
||||||
|
{
|
||||||
|
return QQuickItem::childMouseEventFilter(item, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -43,16 +43,6 @@ class ToolTip : public QQuickItem
|
|||||||
*/
|
*/
|
||||||
Q_PROPERTY(QQuickItem *mainItem READ mainItem WRITE setMainItem NOTIFY mainItemChanged)
|
Q_PROPERTY(QQuickItem *mainItem READ mainItem WRITE setMainItem NOTIFY mainItemChanged)
|
||||||
|
|
||||||
/**
|
|
||||||
* The main QML item that will be displayed in the Dialog
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Visibility of the Dialog window. Doesn't have anything to do with the visibility of the mainItem.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main text of this tooltip
|
* The main text of this tooltip
|
||||||
*/
|
*/
|
||||||
@ -81,11 +71,7 @@ public:
|
|||||||
QQuickItem *mainItem() const;
|
QQuickItem *mainItem() const;
|
||||||
void setMainItem(QQuickItem *mainItem);
|
void setMainItem(QQuickItem *mainItem);
|
||||||
|
|
||||||
QQuickItem *target() const;
|
void showToolTip();
|
||||||
void setTarget(QQuickItem *target);
|
|
||||||
|
|
||||||
bool isVisible() const;
|
|
||||||
void setVisible(const bool visible);
|
|
||||||
|
|
||||||
QString mainText() const;
|
QString mainText() const;
|
||||||
void setMainText(const QString &mainText);
|
void setMainText(const QString &mainText);
|
||||||
@ -100,12 +86,12 @@ public:
|
|||||||
void setImage(const QVariant &image);
|
void setImage(const QVariant &image);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool childMouseEventFilter(QQuickItem *item, QEvent *event);
|
||||||
void hoverEnterEvent(QHoverEvent *event);
|
void hoverEnterEvent(QHoverEvent *event);
|
||||||
void hoverLeaveEvent(QHoverEvent *event);
|
void hoverLeaveEvent(QHoverEvent *event);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void mainItemChanged();
|
void mainItemChanged();
|
||||||
void targetChanged();
|
|
||||||
void visibleChanged();
|
void visibleChanged();
|
||||||
void mainTextChanged();
|
void mainTextChanged();
|
||||||
void subTextChanged();
|
void subTextChanged();
|
||||||
@ -114,7 +100,6 @@ Q_SIGNALS:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QWeakPointer<QQuickItem> m_mainItem;
|
QWeakPointer<QQuickItem> m_mainItem;
|
||||||
QWeakPointer<QQuickItem> m_target;
|
|
||||||
QTimer *m_showTimer;
|
QTimer *m_showTimer;
|
||||||
QString m_mainText;
|
QString m_mainText;
|
||||||
QString m_subText;
|
QString m_subText;
|
||||||
|
@ -60,7 +60,7 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept
|
|||||||
|
|
||||||
if (path.scheme() == QStringLiteral("plasmapackage")) {
|
if (path.scheme() == QStringLiteral("plasmapackage")) {
|
||||||
//FIXME: this is incorrect but works around a bug in qml in resolution of urls of qmldir files
|
//FIXME: this is incorrect but works around a bug in qml in resolution of urls of qmldir files
|
||||||
if (type == QQmlAbstractUrlInterceptor::QmldirFile) {
|
if (0&&type == QQmlAbstractUrlInterceptor::QmldirFile) {
|
||||||
return QUrl(m_package.filePath(0, path.path()));
|
return QUrl(m_package.filePath(0, path.path()));
|
||||||
} else {
|
} else {
|
||||||
return QUrl::fromLocalFile(m_package.filePath(0, path.path()));
|
return QUrl::fromLocalFile(m_package.filePath(0, path.path()));
|
||||||
|
Loading…
Reference in New Issue
Block a user