Window size synching with tooltip content

This commit is contained in:
Sebastian Kügler 2013-04-04 01:46:02 +02:00
parent efd12a5ec1
commit 7e6d750f2a
4 changed files with 39 additions and 60 deletions

View File

@ -39,27 +39,32 @@ import org.kde.plasma.extras 2.0 as PlasmaExtras
*/ */
MouseArea { MouseArea {
property alias mainText: tooltipWindow.mainText
property alias subText: tooltipWindow.subText
property alias image: tooltipWindow.image
property int _s: theme.iconSizes.small / 2 property int _s: theme.iconSizes.small / 2
hoverEnabled: true hoverEnabled: true
onEntered: { onEntered: {
print("entere"); print("entere");
toolTipWindow.visible = true; tooltipWindow.visible = true;
toolTipHideTimer.running = false; tooltipHideTimer.running = false;
print(" ttsvg: w " + toolTipSvg.width); print(" ttsvg: w " + tooltipSvg.width);
print(" ttsvg: h " + toolTipSvg.height); print(" ttsvg: h " + tooltipSvg.height);
} }
onExited: { onExited: {
print("exit"); print("exit");
toolTipHideTimer.running = true tooltipHideTimer.running = true
} }
Timer { Timer {
id: toolTipHideTimer id: tooltipHideTimer
running: false running: false
repeat: false repeat: false
interval: 100 interval: 100
@ -67,15 +72,15 @@ MouseArea {
onTriggered: { onTriggered: {
print("Hiding tooltip ..."); print("Hiding tooltip ...");
toolTipWindow.visible = false; tooltipWindow.visible = false;
} }
} }
PlasmaCore.ToolTipWindow { PlasmaCore.ToolTipWindow {
id: toolTipWindow id: tooltipWindow
mainItem: PlasmaCore.FrameSvgItem { mainItem: PlasmaCore.FrameSvgItem {
id: toolTipSvg id: tooltipSvg
imagePath: "widgets/tooltip" imagePath: "widgets/tooltip"
width: childrenRect.width + margins.left + margins.right width: childrenRect.width + margins.left + margins.right
height: childrenRect.height + margins.top + margins.bottom height: childrenRect.height + margins.top + margins.bottom
@ -84,9 +89,9 @@ MouseArea {
onChildrenRectChanged: print("XXXX childrenRect chagned" + childrenRect.width + " " + childrenRect.height) onChildrenRectChanged: print("XXXX childrenRect chagned" + childrenRect.width + " " + childrenRect.height)
Item { Item {
id: toolTipContentItem id: tooltipContentItem
x: toolTipSvg.margins.left x: tooltipSvg.margins.left
y: toolTipSvg.margins.top y: tooltipSvg.margins.top
width: childrenRect.width width: childrenRect.width
height: childrenRect.height height: childrenRect.height
anchors { anchors {
@ -95,6 +100,8 @@ MouseArea {
//fill: parent //fill: parent
} }
// FIXME: Image { source: tooltipWindow.image }
PlasmaCore.IconItem { PlasmaCore.IconItem {
id: tooltipIcon id: tooltipIcon
width: theme.iconSizes.desktop width: theme.iconSizes.desktop
@ -108,7 +115,7 @@ MouseArea {
PlasmaExtras.Heading { PlasmaExtras.Heading {
id: tooltipMaintext id: tooltipMaintext
level: 4 level: 4
text: "Emperor fish sighted" text: tooltipWindow.mainText
anchors { anchors {
left: tooltipIcon.right left: tooltipIcon.right
leftMargin: _s leftMargin: _s
@ -118,7 +125,7 @@ MouseArea {
} }
PlasmaComponents.Label { PlasmaComponents.Label {
id: tooltipSubtext id: tooltipSubtext
text: "You've come across a beautiful sea creature" text: tooltipWindow.subText
anchors { anchors {
left: tooltipIcon.right left: tooltipIcon.right
leftMargin: _s leftMargin: _s

View File

@ -40,7 +40,7 @@ ToolTipWindow::ToolTipWindow(QWindow *parent)
setFormat(format); setFormat(format);
setClearBeforeRendering(true); setClearBeforeRendering(true);
setColor(QColor(Qt::transparent)); setColor(QColor(Qt::transparent));
setFlags(Qt::FramelessWindowHint); // setFlags(Qt::FramelessWindowHint);
// tooltipDialog.setAttribute(Qt.WA_X11NetWmWindowTypeToolTip, true) // tooltipDialog.setAttribute(Qt.WA_X11NetWmWindowTypeToolTip, true)
// tooltipDialog.windowFlags = Qt.Window|Qt.WindowStaysOnTopHint|Qt.X11BypassWindowManagerHint // tooltipDialog.windowFlags = Qt.Window|Qt.WindowStaysOnTopHint|Qt.X11BypassWindowManagerHint
@ -82,46 +82,12 @@ void ToolTipWindow::setTarget(QQuickItem *target)
} }
} }
void ToolTipWindow::syncTarget() void ToolTipWindow::syncGeometry()
{ {
/* qDebug() << " XXX synching geometry";
if (!m_target) { qDebug() << "XXXX mainitem : " << mainItem()->width() << mainItem()->height();
return; resize(mainItem()->width(), mainItem()->height());
} setPosition(100, 100);
// find the scene
QGraphicsScene *scene = m_target.data()->scene();
if (!scene) {
QObject *parent = m_target.data();
while ((parent = parent->parent())) {
QQuickItem *qo = qobject_cast<QQuickItem*>(parent);
if (qo && qo->scene()) {
scene = qo->scene();
scene->addItem(m_target.data());
break;
}
}
}
QQuickItem *item = qobject_cast<QQuickItem*>(m_target.data());
if (!item) {
return;
}
if (!m_declarativeItemContainer && scene) {
m_declarativeItemContainer = QWeakPointer<QQuickItem>(new QQuickItem());
m_declarativeItemContainer.data()->setObjectName("DIContainer");
scene->addItem(m_declarativeItemContainer.data());
}
if (m_declarativeItemContainer) {
m_target.data()->setObjectName("Original Item");
m_declarativeItemContainer.data()->setDeclarativeItem(item, false);
m_declarativeItemContainer.data()->setAcceptHoverEvents(true);
m_declarativeItemContainer.data()->setParentItem(m_target.data());
m_widget = m_declarativeItemContainer.data();
emit targetChanged();
}
*/
} }
QString ToolTipWindow::mainText() const QString ToolTipWindow::mainText() const
@ -217,20 +183,24 @@ QQuickItem *ToolTipWindow::mainItem() const
void ToolTipWindow::setMainItem(QQuickItem *mainItem) void ToolTipWindow::setMainItem(QQuickItem *mainItem)
{ {
qDebug() << "mainitem changed: " << mainItem->width() << mainItem->height(); qDebug() << "XXXX mainitem changed: " << mainItem->width() << mainItem->height();
//resize(mainItem->width(), mainItem->height()); // resize(400, 200);
resize(400, 200);
if (m_mainItem.data() != mainItem) { if (m_mainItem.data() != mainItem) {
qDebug() << " XXX new mainItem";
disconnect(m_mainItem.data(), &QQuickItem::widthChanged, this, &ToolTipWindow::syncGeometry);
disconnect(m_mainItem.data(), &QQuickItem::heightChanged, this, &ToolTipWindow::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) { if (mainItem) {
//mainItem->setParentItem(0); //mainItem->setParentItem(0);
connect(m_mainItem.data(), &QQuickItem::widthChanged, this, &ToolTipWindow::syncGeometry);
connect(m_mainItem.data(), &QQuickItem::heightChanged, this, &ToolTipWindow::syncGeometry);
qDebug() << "XXX new mainITem connected";
mainItem->setParent(contentItem()); mainItem->setParent(contentItem());
mainItem->setProperty("parent", QVariant::fromValue(contentItem())); mainItem->setProperty("parent", QVariant::fromValue(contentItem()));

View File

@ -111,7 +111,7 @@ Q_SIGNALS:
void visibleChanged(); void visibleChanged();
protected Q_SLOTS: protected Q_SLOTS:
void syncTarget(); void syncGeometry();
void updateToolTip(); void updateToolTip();
private: private:

View File

@ -97,6 +97,8 @@ PlasmaComponents.Page {
PlasmaCore.ToolTip { PlasmaCore.ToolTip {
anchors.fill: parent anchors.fill: parent
mainText: "Fish sighted"
subText: "A mean-looking grouper swam by"
} }
} }