ToolTip polishing
- manage mainComponent entirely in ToolTip.qml - less resizing/setvisible makes it faster and smoother - fix timer connects in dialog - Kill dead code
This commit is contained in:
parent
98d432ebca
commit
50a4abac6d
@ -45,29 +45,21 @@ MouseArea {
|
|||||||
property string iconSource // icon name
|
property string iconSource // icon name
|
||||||
property string image // string / url to the image
|
property string image // string / url to the image
|
||||||
property Item target: parent
|
property Item target: parent
|
||||||
property alias mainItem: tooltipWindow.mainItem
|
property Component mainComponent: tooltipComponent // custom component to create inside the tooltip
|
||||||
|
|
||||||
// private props
|
// private props
|
||||||
property int _s: theme.iconSizes.small / 2
|
property int _s: theme.iconSizes.small / 2
|
||||||
|
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
onEntered: {
|
|
||||||
print("entered");
|
onEntered: show();
|
||||||
show();
|
onExited: hide();
|
||||||
}
|
|
||||||
onExited: {
|
|
||||||
print("exit");
|
|
||||||
hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
function show() {
|
function show() {
|
||||||
var mi = tooltip.mainItem;
|
var mi = tooltip.mainItem;
|
||||||
if (mi == null) {
|
if (mi == null) {
|
||||||
mi = tooltipWindow.mainComponent.createObject( tooltip.target, { "mainText": tooltip.mainText, "subText": tooltip.subText, "iconSource": tooltip.iconSource, "image": tooltip.image });
|
mi = tooltip.mainComponent.createObject( tooltip.target, { "mainText": tooltip.mainText, "subText": tooltip.subText, "iconSource": tooltip.iconSource, "image": tooltip.image });
|
||||||
} else {
|
|
||||||
// TODO: update properties
|
|
||||||
}
|
}
|
||||||
//return;
|
|
||||||
tooltipWindow.visualParent = tooltip.target;
|
tooltipWindow.visualParent = tooltip.target;
|
||||||
tooltipWindow.mainItem = mi;
|
tooltipWindow.mainItem = mi;
|
||||||
tooltipWindow.visible = true;
|
tooltipWindow.visible = true;
|
||||||
@ -89,77 +81,70 @@ MouseArea {
|
|||||||
tooltipWindow.mainItem.destroy();
|
tooltipWindow.mainItem.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Component {
|
||||||
|
id: tooltipComponent
|
||||||
|
|
||||||
PlasmaCore.ToolTipProxy {
|
Item {
|
||||||
id: tooltipWindow
|
id: tooltipContentItem
|
||||||
visualParent: tooltip.target
|
x: _s
|
||||||
|
y: _s
|
||||||
|
width: childrenRect.width + _s
|
||||||
|
height: childrenRect.height
|
||||||
|
|
||||||
mainComponent: Component {
|
property string mainText: "" // string
|
||||||
id: tooltipSvg
|
property string subText: "" // string
|
||||||
//imagePath: "widgets/tooltip"
|
property string iconSource: "" // icon name
|
||||||
// width: childrenRect.width + margins.left + margins.right + 2*_s
|
property string image: "" // string / url to the image
|
||||||
// height: childrenRect.height + margins.top + margins.bottom + 2*_s
|
|
||||||
|
|
||||||
Item {
|
property int maxTextSize: Math.max(tooltipMaintext.paintedWidth, tooltipSubtext.paintedWidth)
|
||||||
id: tooltipContentItem
|
property int maxSize: theme.iconSizes.desktop * 6
|
||||||
x: _s
|
property int preferredTextWidth: Math.min(maxTextSize, maxSize)
|
||||||
y: _s
|
|
||||||
width: childrenRect.width + _s
|
|
||||||
height: childrenRect.height
|
|
||||||
|
|
||||||
property string mainText: "Default mainText" // string
|
property int _s: theme.iconSizes.small / 2
|
||||||
property string subText: "Default subText" // string
|
|
||||||
property string iconSource: "klipper" // icon name
|
|
||||||
property string image: "" // string / url to the image
|
|
||||||
|
|
||||||
property int maxTextSize: Math.max(tooltipMaintext.paintedWidth, tooltipSubtext.paintedWidth)
|
Image {
|
||||||
property int maxSize: theme.iconSizes.desktop * 6
|
id: tooltipImage
|
||||||
property int preferredTextWidth: Math.min(maxTextSize, maxSize)
|
source: image
|
||||||
|
}
|
||||||
|
|
||||||
property int _s: theme.iconSizes.small / 2
|
PlasmaCore.IconItem {
|
||||||
|
id: tooltipIcon
|
||||||
Image {
|
width: theme.iconSizes.desktop
|
||||||
id: tooltipImage
|
height: width
|
||||||
source: image
|
source: iconSource
|
||||||
|
anchors {
|
||||||
|
leftMargin: _s
|
||||||
}
|
}
|
||||||
|
}
|
||||||
PlasmaCore.IconItem {
|
PlasmaExtras.Heading {
|
||||||
id: tooltipIcon
|
id: tooltipMaintext
|
||||||
width: theme.iconSizes.desktop
|
level: 3
|
||||||
height: width
|
width: parent.preferredTextWidth
|
||||||
source: iconSource
|
wrapMode: Text.WordWrap
|
||||||
anchors {
|
text: mainText
|
||||||
leftMargin: _s
|
anchors {
|
||||||
}
|
left: (tooltipImage.source != "") ? tooltipImage.right : tooltipIcon.right
|
||||||
|
leftMargin: _s*2
|
||||||
|
top: tooltipIcon.top
|
||||||
}
|
}
|
||||||
PlasmaExtras.Heading {
|
}
|
||||||
id: tooltipMaintext
|
PlasmaComponents.Label {
|
||||||
level: 3
|
id: tooltipSubtext
|
||||||
width: parent.preferredTextWidth
|
width: parent.preferredTextWidth
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
text: mainText
|
text: subText
|
||||||
anchors {
|
opacity: 0.5
|
||||||
left: (tooltipImage.source != "") ? tooltipImage.right : tooltipIcon.right
|
anchors {
|
||||||
leftMargin: _s*2
|
left: tooltipMaintext.left
|
||||||
top: tooltipIcon.top
|
topMargin: _s
|
||||||
}
|
bottomMargin: _s
|
||||||
|
top: tooltipMaintext.bottom
|
||||||
}
|
}
|
||||||
PlasmaComponents.Label {
|
|
||||||
id: tooltipSubtext
|
|
||||||
width: parent.preferredTextWidth
|
|
||||||
wrapMode: Text.WordWrap
|
|
||||||
text: subText
|
|
||||||
opacity: 0.5
|
|
||||||
anchors {
|
|
||||||
left: tooltipMaintext.left
|
|
||||||
topMargin: _s
|
|
||||||
bottomMargin: _s
|
|
||||||
top: tooltipMaintext.bottom
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Component.onCompleted: print("XXX Tooltip mainItem created.")
|
|
||||||
Component.onDestruction: print("XXX Tooltip mainItem destroyed.")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
PlasmaCore.ToolTipProxy {
|
||||||
|
id: tooltipWindow
|
||||||
|
visualParent: tooltip.target
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,10 +109,10 @@ void DialogProxy::setMainItem(QQuickItem *mainItem)
|
|||||||
mainItem->setProperty("parent", QVariant::fromValue(contentItem()));
|
mainItem->setProperty("parent", QVariant::fromValue(contentItem()));
|
||||||
|
|
||||||
if (mainItem->metaObject()->indexOfSignal("widthChanged")) {
|
if (mainItem->metaObject()->indexOfSignal("widthChanged")) {
|
||||||
connect(mainItem, SIGNAL(widthChanged()), m_syncTimer, SIGNAL(start()));
|
connect(mainItem, SIGNAL(widthChanged()), m_syncTimer, SLOT(start()));
|
||||||
}
|
}
|
||||||
if (mainItem->metaObject()->indexOfSignal("heightChanged")) {
|
if (mainItem->metaObject()->indexOfSignal("heightChanged")) {
|
||||||
connect(mainItem, SIGNAL(heightChanged()), m_syncTimer, SIGNAL(start()));
|
connect(mainItem, SIGNAL(heightChanged()), m_syncTimer, SLOT(start()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,7 +358,6 @@ void DialogProxy::syncMainItemToSize()
|
|||||||
|
|
||||||
void DialogProxy::syncToMainItemSize()
|
void DialogProxy::syncToMainItemSize()
|
||||||
{
|
{
|
||||||
qDebug() << "XXXX XXX size sync";
|
|
||||||
if (!m_mainItem) {
|
if (!m_mainItem) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include "framesvgitem.h"
|
#include "framesvgitem.h"
|
||||||
#include <kwindoweffects.h>
|
#include <kwindoweffects.h>
|
||||||
@ -68,34 +67,11 @@ QQuickItem *ToolTip::mainItem() const
|
|||||||
|
|
||||||
void ToolTip::setMainItem(QQuickItem *mainItem)
|
void ToolTip::setMainItem(QQuickItem *mainItem)
|
||||||
{
|
{
|
||||||
qDebug() << "XXXX mainitem changed: " << mainItem->width() << mainItem->height();
|
|
||||||
|
|
||||||
if (m_mainItem.data() != mainItem) {
|
if (m_mainItem.data() != mainItem) {
|
||||||
qDebug() << " XXX new mainItem";
|
|
||||||
// disconnect(m_mainItem.data(), &QQuickItem::widthChanged, this, &ToolTip::syncGeometry);
|
|
||||||
// disconnect(m_mainItem.data(), &QQuickItem::heightChanged, this, &ToolTip::syncGeometry);
|
|
||||||
if (m_mainItem) {
|
if (m_mainItem) {
|
||||||
m_mainItem.data()->setParent(parent());
|
m_mainItem.data()->setParent(parent());
|
||||||
}
|
}
|
||||||
m_mainItem = mainItem;
|
m_mainItem = mainItem;
|
||||||
|
|
||||||
if (mainItem) {
|
|
||||||
//mainItem->setParentItem(0);
|
|
||||||
// connect(m_mainItem.data(), &QQuickItem::widthChanged, this, &ToolTip::syncGeometry);
|
|
||||||
// connect(m_mainItem.data(), &QQuickItem::heightChanged, this, &ToolTip::syncGeometry);
|
|
||||||
qDebug() << "XXX new mainITem connected";
|
|
||||||
//mainItem->setParent(contentItem());
|
|
||||||
//mainItem->setProperty("parent", QVariant::fromValue(contentItem()));
|
|
||||||
|
|
||||||
// if (mainItem->metaObject()->indexOfSignal("widthChanged")) {
|
|
||||||
// connect(mainItem, SIGNAL(widthChanged()), m_syncTimer, SIGNAL(start()));
|
|
||||||
// }
|
|
||||||
// if (mainItem->metaObject()->indexOfSignal("heightChanged")) {
|
|
||||||
// connect(mainItem, SIGNAL(heightChanged()), m_syncTimer, SIGNAL(start()));
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
//if this is called in Compenent.onCompleted we have to wait a loop the item is added to a scene
|
|
||||||
emit mainItemChanged();
|
emit mainItemChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,10 +79,8 @@ void ToolTip::setMainItem(QQuickItem *mainItem)
|
|||||||
QQuickItem *ToolTip::visualParent() const
|
QQuickItem *ToolTip::visualParent() const
|
||||||
{
|
{
|
||||||
if (m_visualParent.data()) {
|
if (m_visualParent.data()) {
|
||||||
qDebug() << "returning real visualParent";
|
|
||||||
return m_visualParent.data();
|
return m_visualParent.data();
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "returning parent as visualParent";
|
|
||||||
QQuickItem *qqi = qobject_cast<QQuickItem*>(parent());
|
QQuickItem *qqi = qobject_cast<QQuickItem*>(parent());
|
||||||
return qqi;
|
return qqi;
|
||||||
}
|
}
|
||||||
@ -117,46 +91,24 @@ void ToolTip::setVisualParent(QQuickItem *visualParent)
|
|||||||
if (m_visualParent.data() == visualParent) {
|
if (m_visualParent.data() == visualParent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (visualParent) {
|
|
||||||
//setPosition(popupPosition(visualParent, Qt::AlignCenter));
|
|
||||||
}
|
|
||||||
emit visualParentChanged();
|
emit visualParentChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ToolTip::isVisible() const
|
bool ToolTip::isVisible() const
|
||||||
{
|
{
|
||||||
//return QQuickWindow::isVisible();
|
ToolTipDialog *dlg = ToolTipDialog::instance();
|
||||||
return true;
|
return (dlg->mainItem() == mainItem() && mainItem() && mainItem()->isVisible());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTip::setVisible(const bool visible)
|
void ToolTip::setVisible(const bool visible)
|
||||||
{
|
{
|
||||||
ToolTipDialog *dlg = ToolTipDialog::instance();
|
ToolTipDialog *dlg = ToolTipDialog::instance();
|
||||||
qDebug() << "creating tooltipdialog" << visible;
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
//dlg->mainItem()->deleteLater();
|
|
||||||
|
|
||||||
// QObject *myObject = m_mainComponent.data()->create();
|
|
||||||
// QQuickItem *item = qobject_cast<QQuickItem*>(myObject);
|
|
||||||
qDebug() << "---- XXX Setting visible: " << mainItem();
|
|
||||||
setMainItem(mainItem());
|
|
||||||
|
|
||||||
|
|
||||||
qDebug() << "XXX showing tooltip: " << ToolTipDialog::instance();
|
|
||||||
qDebug() << "XXX positioning near: " << visualParent()->objectName();
|
|
||||||
dlg->setMainItem(mainItem());
|
dlg->setMainItem(mainItem());
|
||||||
dlg->setVisualParent(visualParent());
|
dlg->setVisualParent(visualParent());
|
||||||
dlg->syncToMainItemSize();
|
|
||||||
//dlg->setPosition(dlg->popupPosition(visualParent()));
|
|
||||||
dlg->setVisible(true);
|
dlg->setVisible(true);
|
||||||
|
|
||||||
// syncGeometry();
|
|
||||||
// raise();
|
|
||||||
} else {
|
} else {
|
||||||
dlg->setVisible(false);
|
dlg->setVisible(false);
|
||||||
//dlg->mainItem()->deleteLater();
|
|
||||||
}
|
}
|
||||||
//QQuickWindow::setVisible(visible);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,9 +32,7 @@ class QQuickItem;
|
|||||||
class QGraphicsWidget;
|
class QGraphicsWidget;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* QML wrapper for kdelibs Plasma::ToolTip
|
* Exposed as `ToolTipProxy` in QML.
|
||||||
*
|
|
||||||
* Exposed as `ToolTip` in QML.
|
|
||||||
*/
|
*/
|
||||||
class ToolTip : public QObject
|
class ToolTip : public QObject
|
||||||
{
|
{
|
||||||
@ -46,10 +44,10 @@ class ToolTip : public QObject
|
|||||||
Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)
|
Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main QML item that will be displayed in the Dialog
|
* T
|
||||||
*/
|
*/
|
||||||
Q_PROPERTY(QQuickItem *mainItem READ mainItem WRITE setMainItem NOTIFY mainItemChanged)
|
Q_PROPERTY(QQuickItem *mainItem READ mainItem WRITE setMainItem NOTIFY mainItemChanged)
|
||||||
Q_PROPERTY(QQmlComponent *mainComponent READ mainComponent WRITE setMainComponent NOTIFY mainComponentChanged)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main QML item that will be displayed in the Dialog
|
* The main QML item that will be displayed in the Dialog
|
||||||
|
Loading…
x
Reference in New Issue
Block a user