basic tooltip featureset finished
This implementation deviates a bit from the Plasma 1 tooltips: - image is now a string - tooltips align to the parent by default, or the visualParent set Otherwise, the changes should be fairly transparant. A crude basic featureset works.
This commit is contained in:
parent
c2b868fa56
commit
e4ee4d6dd0
@ -38,46 +38,42 @@ import org.kde.plasma.extras 2.0 as PlasmaExtras
|
||||
*
|
||||
*/
|
||||
MouseArea {
|
||||
id: tooltip
|
||||
|
||||
property alias mainText: tooltipWindow.mainText
|
||||
property alias subText: tooltipWindow.subText
|
||||
property alias image: tooltipWindow.image
|
||||
|
||||
property alias mainText: tooltipWindow.mainText // string
|
||||
property alias subText: tooltipWindow.subText // string
|
||||
property alias iconSource: tooltipIcon.source // icon name
|
||||
property alias image: tooltipImage.source // string / url to the image
|
||||
property Item visualParent: parent
|
||||
|
||||
// private props
|
||||
property int _s: theme.iconSizes.small / 2
|
||||
|
||||
hoverEnabled: true
|
||||
onEntered: {
|
||||
print("entere");
|
||||
print("entered");
|
||||
tooltipWindow.visible = true;
|
||||
tooltipHideTimer.running = false;
|
||||
print(" ttsvg: w " + tooltipSvg.width);
|
||||
print(" ttsvg: h " + tooltipSvg.height);
|
||||
|
||||
}
|
||||
|
||||
onExited: {
|
||||
print("exit");
|
||||
tooltipHideTimer.running = true
|
||||
|
||||
}
|
||||
|
||||
|
||||
Timer {
|
||||
id: tooltipHideTimer
|
||||
running: false
|
||||
repeat: false
|
||||
interval: 100
|
||||
|
||||
|
||||
interval: 50
|
||||
onTriggered: {
|
||||
print("Hiding tooltip ...");
|
||||
//print("Hiding tooltip ...");
|
||||
tooltipWindow.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
PlasmaCore.ToolTipWindow {
|
||||
id: tooltipWindow
|
||||
visualParent: tooltip.visualParent
|
||||
|
||||
mainItem: PlasmaCore.FrameSvgItem {
|
||||
id: tooltipSvg
|
||||
@ -85,60 +81,55 @@ MouseArea {
|
||||
width: childrenRect.width + margins.left + margins.right + 2*_s
|
||||
height: childrenRect.height + margins.top + margins.bottom + 2*_s
|
||||
|
||||
onWidthChanged: print("XXXX ====================================== svgframe width: " + width)
|
||||
onChildrenRectChanged: print("XXXX childrenRect chagned" + childrenRect.width + " " + childrenRect.height)
|
||||
|
||||
Item {
|
||||
id: tooltipContentItem
|
||||
x: tooltipSvg.margins.left
|
||||
y: tooltipSvg.margins.top
|
||||
width: childrenRect.width
|
||||
x: tooltipSvg.margins.left + _s
|
||||
y: tooltipSvg.margins.top + _s
|
||||
width: childrenRect.width + _s
|
||||
height: childrenRect.height
|
||||
anchors {
|
||||
topMargin: parent.anchors.margins.top
|
||||
leftMargin: parent.anchors.margins.left + _s
|
||||
rightMargin: _s
|
||||
//fill: parent
|
||||
}
|
||||
|
||||
// FIXME: Image { source: tooltipWindow.image }
|
||||
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
|
||||
}
|
||||
|
||||
PlasmaCore.IconItem {
|
||||
id: tooltipIcon
|
||||
width: theme.iconSizes.desktop
|
||||
height: width
|
||||
source: "zanshin"
|
||||
// anchors {
|
||||
// left: parent.left
|
||||
// verticalCenter: parent.verticalCenter
|
||||
// }
|
||||
anchors {
|
||||
leftMargin: _s
|
||||
}
|
||||
}
|
||||
PlasmaExtras.Heading {
|
||||
id: tooltipMaintext
|
||||
level: 4
|
||||
level: 3
|
||||
width: parent.preferredTextWidth
|
||||
wrapMode: Text.WordWrap
|
||||
text: tooltipWindow.mainText
|
||||
anchors {
|
||||
left: tooltipIcon.right
|
||||
leftMargin: _s
|
||||
topMargin: _s
|
||||
top: parent.top
|
||||
left: (tooltipImage.source != "") ? tooltipImage.right : tooltipIcon.right
|
||||
leftMargin: _s*2
|
||||
top: tooltipIcon.top
|
||||
}
|
||||
}
|
||||
PlasmaComponents.Label {
|
||||
id: tooltipSubtext
|
||||
width: parent.preferredTextWidth
|
||||
wrapMode: Text.WordWrap
|
||||
text: tooltipWindow.subText
|
||||
opacity: 0.5
|
||||
anchors {
|
||||
left: tooltipIcon.right
|
||||
leftMargin: _s
|
||||
left: tooltipMaintext.left
|
||||
topMargin: _s
|
||||
bottomMargin: _s
|
||||
top: tooltipMaintext.bottom
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
/***************************************************************************
|
||||
* Copyright 2011 Marco Martin <mart@kde.org> *
|
||||
* Copyright 2011 Artur Duque de Souza <asouza@kde.org> *
|
||||
* Copyright 2013 Sebastian Kügler <sebas@kde.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
@ -21,17 +22,9 @@
|
||||
#include "tooltip.h"
|
||||
|
||||
#include <QQuickItem>
|
||||
// #include <QGraphicsWidget>
|
||||
// #include <QGraphicsScene>
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
|
||||
//#include <KIcon>
|
||||
// #include <KIconLoader>
|
||||
// #include <Plasma/ToolTipContent>
|
||||
// #include <Plasma/ToolTipManager>
|
||||
|
||||
|
||||
ToolTipWindow::ToolTipWindow(QWindow *parent)
|
||||
: QQuickWindow(parent), m_mainText(""), m_subText(""), m_widget(0)
|
||||
{
|
||||
@ -50,7 +43,7 @@ ToolTipWindow::ToolTipWindow(QWindow *parent)
|
||||
m_syncTimer = new QTimer(this);
|
||||
m_syncTimer->setSingleShot(true);
|
||||
m_syncTimer->setInterval(250);
|
||||
// connect(m_syncTimer, &QTimer::timeout, this, &DialogProxy::syncToMainItemSize);
|
||||
connect(m_syncTimer, &QTimer::timeout, this, &ToolTipWindow::syncGeometry);
|
||||
|
||||
connect(this, SIGNAL(targetChanged()), this, SLOT(updateToolTip()));
|
||||
connect(this, SIGNAL(mainTextChanged()), this, SLOT(updateToolTip()));
|
||||
@ -88,7 +81,7 @@ void ToolTipWindow::syncGeometry()
|
||||
qDebug() << " XXX synching geometry";
|
||||
qDebug() << "XXXX mainitem : " << mainItem()->width() << mainItem()->height();
|
||||
resize(mainItem()->width(), mainItem()->height());
|
||||
setPosition(popupPosition());
|
||||
setPosition(popupPosition(visualParent()));
|
||||
}
|
||||
|
||||
QString ToolTipWindow::mainText() const
|
||||
@ -232,8 +225,13 @@ void ToolTipWindow::setVisualParent(QQuickItem *visualParent)
|
||||
if (visualParent) {
|
||||
setPosition(popupPosition(visualParent, Qt::AlignCenter));
|
||||
}
|
||||
disconnect(m_visualParent.data(), &QQuickItem::xChanged, this, &ToolTipWindow::syncGeometry);
|
||||
disconnect(m_visualParent.data(), &QQuickItem::yChanged, this, &ToolTipWindow::syncGeometry);
|
||||
//disconnect(visualParent, &QQuickItem::yChanged, this, &ToolTipWindow::syncGeometry);
|
||||
|
||||
m_visualParent = visualParent;
|
||||
connect(m_visualParent.data(), &QQuickItem::xChanged, this, &ToolTipWindow::syncGeometry);
|
||||
connect(m_visualParent.data(), &QQuickItem::yChanged, this, &ToolTipWindow::syncGeometry);
|
||||
emit visualParentChanged();
|
||||
}
|
||||
|
||||
@ -248,7 +246,8 @@ void ToolTipWindow::setVisible(const bool visible)
|
||||
{
|
||||
qDebug() << visible;
|
||||
if (visible) {
|
||||
setPosition(popupPosition());
|
||||
//setPosition(popupPosition());
|
||||
syncGeometry();
|
||||
raise();
|
||||
}
|
||||
QQuickWindow::setVisible(visible);
|
||||
@ -257,13 +256,23 @@ void ToolTipWindow::setVisible(const bool visible)
|
||||
QPoint ToolTipWindow::popupPosition(QQuickItem *item, Qt::AlignmentFlag alignment)
|
||||
{
|
||||
// FIXME :: Item
|
||||
QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
|
||||
if (parentItem && parentItem->window()) {
|
||||
qDebug() << "XXX NO visual parent ... Centering at " << (parentItem->window()->geometry().center() - QPoint(width()/2, height()/2));
|
||||
qDebug() << parentItem->window()->geometry().center() - QPoint(width()/2, height()/2);
|
||||
return parentItem->window()->geometry().center() - QPoint(width()/2, height()/2);
|
||||
if (!item) {
|
||||
item = qobject_cast<QQuickItem *>(visualParent());
|
||||
}
|
||||
if (item && item->window()) {
|
||||
QPointF itemScreenPos;
|
||||
|
||||
QPointF pos = item->mapToScene(QPointF(0, 0));
|
||||
//qDebug() << "I've an Item at " << pos;
|
||||
if (item->window() && item->window()->screen()) {
|
||||
pos = item->window()->mapToGlobal(pos.toPoint());
|
||||
} else {
|
||||
}
|
||||
itemScreenPos = QPoint(pos.x() + (item->width() - mainItem()->width())/2, pos.y()-mainItem()->height());
|
||||
qDebug() << "XXX Centering at visualParent" << itemScreenPos;
|
||||
return itemScreenPos.toPoint();
|
||||
} else {
|
||||
qDebug() << "XXX No QQuickItem as parent found";
|
||||
qDebug() << "XXX No QQuickItem visualParent found";
|
||||
return QPoint(100, 100);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
/***************************************************************************
|
||||
* Copyright 2011 Marco Martin <mart@kde.org> *
|
||||
* Copyright 2011 Artur Duque de Souza <asouza@kde.org> *
|
||||
* Copyright 2013 Sebastian Kügler <sebas@kde.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
|
Loading…
x
Reference in New Issue
Block a user