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

View File

@ -40,7 +40,7 @@ ToolTipWindow::ToolTipWindow(QWindow *parent)
setFormat(format);
setClearBeforeRendering(true);
setColor(QColor(Qt::transparent));
setFlags(Qt::FramelessWindowHint);
// setFlags(Qt::FramelessWindowHint);
// tooltipDialog.setAttribute(Qt.WA_X11NetWmWindowTypeToolTip, true)
// tooltipDialog.windowFlags = Qt.Window|Qt.WindowStaysOnTopHint|Qt.X11BypassWindowManagerHint
@ -82,46 +82,12 @@ void ToolTipWindow::setTarget(QQuickItem *target)
}
}
void ToolTipWindow::syncTarget()
void ToolTipWindow::syncGeometry()
{
/*
if (!m_target) {
return;
}
// 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();
}
*/
qDebug() << " XXX synching geometry";
qDebug() << "XXXX mainitem : " << mainItem()->width() << mainItem()->height();
resize(mainItem()->width(), mainItem()->height());
setPosition(100, 100);
}
QString ToolTipWindow::mainText() const
@ -217,20 +183,24 @@ QQuickItem *ToolTipWindow::mainItem() const
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) {
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) {
m_mainItem.data()->setParent(parent());
}
m_mainItem = mainItem;
if (mainItem) {
//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->setProperty("parent", QVariant::fromValue(contentItem()));

View File

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

View File

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