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 image // string / url to the image
|
||||
property Item target: parent
|
||||
property alias mainItem: tooltipWindow.mainItem
|
||||
property Component mainComponent: tooltipComponent // custom component to create inside the tooltip
|
||||
|
||||
// private props
|
||||
property int _s: theme.iconSizes.small / 2
|
||||
|
||||
hoverEnabled: true
|
||||
onEntered: {
|
||||
print("entered");
|
||||
show();
|
||||
}
|
||||
onExited: {
|
||||
print("exit");
|
||||
hide();
|
||||
}
|
||||
|
||||
onEntered: show();
|
||||
onExited: hide();
|
||||
|
||||
function show() {
|
||||
var mi = tooltip.mainItem;
|
||||
if (mi == null) {
|
||||
mi = tooltipWindow.mainComponent.createObject( tooltip.target, { "mainText": tooltip.mainText, "subText": tooltip.subText, "iconSource": tooltip.iconSource, "image": tooltip.image });
|
||||
} else {
|
||||
// TODO: update properties
|
||||
mi = tooltip.mainComponent.createObject( tooltip.target, { "mainText": tooltip.mainText, "subText": tooltip.subText, "iconSource": tooltip.iconSource, "image": tooltip.image });
|
||||
}
|
||||
//return;
|
||||
tooltipWindow.visualParent = tooltip.target;
|
||||
tooltipWindow.mainItem = mi;
|
||||
tooltipWindow.visible = true;
|
||||
@ -89,77 +81,70 @@ MouseArea {
|
||||
tooltipWindow.mainItem.destroy();
|
||||
}
|
||||
}
|
||||
Component {
|
||||
id: tooltipComponent
|
||||
|
||||
PlasmaCore.ToolTipProxy {
|
||||
id: tooltipWindow
|
||||
visualParent: tooltip.target
|
||||
Item {
|
||||
id: tooltipContentItem
|
||||
x: _s
|
||||
y: _s
|
||||
width: childrenRect.width + _s
|
||||
height: childrenRect.height
|
||||
|
||||
mainComponent: Component {
|
||||
id: tooltipSvg
|
||||
//imagePath: "widgets/tooltip"
|
||||
// width: childrenRect.width + margins.left + margins.right + 2*_s
|
||||
// height: childrenRect.height + margins.top + margins.bottom + 2*_s
|
||||
property string mainText: "" // string
|
||||
property string subText: "" // string
|
||||
property string iconSource: "" // icon name
|
||||
property string image: "" // string / url to the image
|
||||
|
||||
Item {
|
||||
id: tooltipContentItem
|
||||
x: _s
|
||||
y: _s
|
||||
width: childrenRect.width + _s
|
||||
height: childrenRect.height
|
||||
property int maxTextSize: Math.max(tooltipMaintext.paintedWidth, tooltipSubtext.paintedWidth)
|
||||
property int maxSize: theme.iconSizes.desktop * 6
|
||||
property int preferredTextWidth: Math.min(maxTextSize, maxSize)
|
||||
|
||||
property string mainText: "Default mainText" // string
|
||||
property string subText: "Default subText" // string
|
||||
property string iconSource: "klipper" // icon name
|
||||
property string image: "" // string / url to the image
|
||||
property int _s: theme.iconSizes.small / 2
|
||||
|
||||
property int maxTextSize: Math.max(tooltipMaintext.paintedWidth, tooltipSubtext.paintedWidth)
|
||||
property int maxSize: theme.iconSizes.desktop * 6
|
||||
property int preferredTextWidth: Math.min(maxTextSize, maxSize)
|
||||
Image {
|
||||
id: tooltipImage
|
||||
source: image
|
||||
}
|
||||
|
||||
property int _s: theme.iconSizes.small / 2
|
||||
|
||||
Image {
|
||||
id: tooltipImage
|
||||
source: image
|
||||
PlasmaCore.IconItem {
|
||||
id: tooltipIcon
|
||||
width: theme.iconSizes.desktop
|
||||
height: width
|
||||
source: iconSource
|
||||
anchors {
|
||||
leftMargin: _s
|
||||
}
|
||||
|
||||
PlasmaCore.IconItem {
|
||||
id: tooltipIcon
|
||||
width: theme.iconSizes.desktop
|
||||
height: width
|
||||
source: iconSource
|
||||
anchors {
|
||||
leftMargin: _s
|
||||
}
|
||||
}
|
||||
PlasmaExtras.Heading {
|
||||
id: tooltipMaintext
|
||||
level: 3
|
||||
width: parent.preferredTextWidth
|
||||
wrapMode: Text.WordWrap
|
||||
text: mainText
|
||||
anchors {
|
||||
left: (tooltipImage.source != "") ? tooltipImage.right : tooltipIcon.right
|
||||
leftMargin: _s*2
|
||||
top: tooltipIcon.top
|
||||
}
|
||||
PlasmaExtras.Heading {
|
||||
id: tooltipMaintext
|
||||
level: 3
|
||||
width: parent.preferredTextWidth
|
||||
wrapMode: Text.WordWrap
|
||||
text: mainText
|
||||
anchors {
|
||||
left: (tooltipImage.source != "") ? tooltipImage.right : tooltipIcon.right
|
||||
leftMargin: _s*2
|
||||
top: tooltipIcon.top
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
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()));
|
||||
|
||||
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")) {
|
||||
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()
|
||||
{
|
||||
qDebug() << "XXXX XXX size sync";
|
||||
if (!m_mainItem) {
|
||||
return;
|
||||
}
|
||||
|
@ -24,7 +24,6 @@
|
||||
|
||||
#include <QQuickItem>
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
|
||||
#include "framesvgitem.h"
|
||||
#include <kwindoweffects.h>
|
||||
@ -68,34 +67,11 @@ QQuickItem *ToolTip::mainItem() const
|
||||
|
||||
void ToolTip::setMainItem(QQuickItem *mainItem)
|
||||
{
|
||||
qDebug() << "XXXX mainitem changed: " << mainItem->width() << mainItem->height();
|
||||
|
||||
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) {
|
||||
m_mainItem.data()->setParent(parent());
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
@ -103,10 +79,8 @@ void ToolTip::setMainItem(QQuickItem *mainItem)
|
||||
QQuickItem *ToolTip::visualParent() const
|
||||
{
|
||||
if (m_visualParent.data()) {
|
||||
qDebug() << "returning real visualParent";
|
||||
return m_visualParent.data();
|
||||
} else {
|
||||
qDebug() << "returning parent as visualParent";
|
||||
QQuickItem *qqi = qobject_cast<QQuickItem*>(parent());
|
||||
return qqi;
|
||||
}
|
||||
@ -117,46 +91,24 @@ void ToolTip::setVisualParent(QQuickItem *visualParent)
|
||||
if (m_visualParent.data() == visualParent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (visualParent) {
|
||||
//setPosition(popupPosition(visualParent, Qt::AlignCenter));
|
||||
}
|
||||
emit visualParentChanged();
|
||||
}
|
||||
|
||||
bool ToolTip::isVisible() const
|
||||
{
|
||||
//return QQuickWindow::isVisible();
|
||||
return true;
|
||||
ToolTipDialog *dlg = ToolTipDialog::instance();
|
||||
return (dlg->mainItem() == mainItem() && mainItem() && mainItem()->isVisible());
|
||||
}
|
||||
|
||||
void ToolTip::setVisible(const bool visible)
|
||||
{
|
||||
ToolTipDialog *dlg = ToolTipDialog::instance();
|
||||
qDebug() << "creating tooltipdialog" << 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->setVisualParent(visualParent());
|
||||
dlg->syncToMainItemSize();
|
||||
//dlg->setPosition(dlg->popupPosition(visualParent()));
|
||||
dlg->setVisible(true);
|
||||
|
||||
// syncGeometry();
|
||||
// raise();
|
||||
} else {
|
||||
dlg->setVisible(false);
|
||||
//dlg->mainItem()->deleteLater();
|
||||
}
|
||||
//QQuickWindow::setVisible(visible);
|
||||
}
|
||||
|
||||
|
@ -32,9 +32,7 @@ class QQuickItem;
|
||||
class QGraphicsWidget;
|
||||
|
||||
/**
|
||||
* QML wrapper for kdelibs Plasma::ToolTip
|
||||
*
|
||||
* Exposed as `ToolTip` in QML.
|
||||
* Exposed as `ToolTipProxy` in QML.
|
||||
*/
|
||||
class ToolTip : public QObject
|
||||
{
|
||||
@ -46,10 +44,10 @@ class ToolTip : public QObject
|
||||
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(QQmlComponent *mainComponent READ mainComponent WRITE setMainComponent NOTIFY mainComponentChanged)
|
||||
|
||||
|
||||
/**
|
||||
* The main QML item that will be displayed in the Dialog
|
||||
|
Loading…
Reference in New Issue
Block a user