Make tooltip positioning work
This commit is contained in:
parent
5a82aa9211
commit
9eda3882ca
@ -40,10 +40,10 @@ import org.kde.plasma.extras 2.0 as PlasmaExtras
|
|||||||
MouseArea {
|
MouseArea {
|
||||||
id: tooltip
|
id: tooltip
|
||||||
|
|
||||||
property string mainText: tooltipMaintext.text // string
|
property string mainText // string
|
||||||
property string subText: tooltipSubtext.text // string
|
property string subText // string
|
||||||
property string iconSource: tooltipIcon.source // icon name
|
property string iconSource // icon name
|
||||||
property string image: tooltipImage.source // 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 alias mainItem: tooltipWindow.mainItem
|
||||||
|
|
||||||
|
@ -132,12 +132,12 @@ void DialogProxy::setVisualParent(QQuickItem *visualParent)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (visualParent) {
|
|
||||||
setPosition(popupPosition(visualParent, Qt::AlignCenter));
|
|
||||||
}
|
|
||||||
|
|
||||||
m_visualParent = visualParent;
|
m_visualParent = visualParent;
|
||||||
emit visualParentChanged();
|
emit visualParentChanged();
|
||||||
|
if (visualParent && isVisible()) {
|
||||||
|
setPosition(popupPosition(visualParent, Qt::AlignCenter));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DialogProxy::isVisible() const
|
bool DialogProxy::isVisible() const
|
||||||
@ -147,9 +147,8 @@ bool DialogProxy::isVisible() const
|
|||||||
|
|
||||||
void DialogProxy::setVisible(const bool visible)
|
void DialogProxy::setVisible(const bool visible)
|
||||||
{
|
{
|
||||||
//qDebug() << visible;
|
//QRect avail = QRect(400, 300, 1200, 800); // FIXME
|
||||||
QRect avail = QRect(400, 300, 1200, 800); // FIXME
|
QRect avail;
|
||||||
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
syncToMainItemSize();
|
syncToMainItemSize();
|
||||||
if (!m_visualParent.isNull()) {
|
if (!m_visualParent.isNull()) {
|
||||||
@ -194,15 +193,13 @@ QPoint DialogProxy::popupPosition(QQuickItem *item, Qt::AlignmentFlag alignment)
|
|||||||
//If no item was specified try to align at the center of the parent view
|
//If no item was specified try to align at the center of the parent view
|
||||||
QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
|
QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
|
||||||
if (parentItem && parentItem->window()) {
|
if (parentItem && parentItem->window()) {
|
||||||
//qDebug() << "NO visual parent ... Centering at " << (parentItem->window()->geometry().center() - QPoint(width()/2, height()/2));
|
|
||||||
return parentItem->window()->geometry().center() - QPoint(width()/2, height()/2);
|
return parentItem->window()->geometry().center() - QPoint(width()/2, height()/2);
|
||||||
} else {
|
} else {
|
||||||
//qDebug() << "No QQuickItem as parent found";
|
|
||||||
return QPoint();
|
return QPoint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QPointF pos = item->mapToScene(QPointF(0, 0));
|
QPointF pos = item->mapToScene(QPointF(0, 0));
|
||||||
//qDebug() << "I've an Item at " << pos;
|
|
||||||
if (item->window() && item->window()->screen()) {
|
if (item->window() && item->window()->screen()) {
|
||||||
pos = item->window()->mapToGlobal(pos.toPoint());
|
pos = item->window()->mapToGlobal(pos.toPoint());
|
||||||
} else {
|
} else {
|
||||||
@ -282,7 +279,6 @@ QPoint DialogProxy::popupPosition(QQuickItem *item, Qt::AlignmentFlag alignment)
|
|||||||
} else {
|
} else {
|
||||||
menuPos.setY(avail.height() - item->boundingRect().height() + bottomMargin);
|
menuPos.setY(avail.height() - item->boundingRect().height() + bottomMargin);
|
||||||
}
|
}
|
||||||
//qDebug() << menuPos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//qDebug() << "Popup position" << menuPos << " Location: Plasma::" <<locString(l);
|
//qDebug() << "Popup position" << menuPos << " Location: Plasma::" <<locString(l);
|
||||||
@ -362,10 +358,11 @@ void DialogProxy::syncMainItemToSize()
|
|||||||
|
|
||||||
void DialogProxy::syncToMainItemSize()
|
void DialogProxy::syncToMainItemSize()
|
||||||
{
|
{
|
||||||
|
qDebug() << "XXXX XXX size sync";
|
||||||
if (!m_mainItem) {
|
if (!m_mainItem) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//qDebug() << " main item: " << m_mainItem.
|
||||||
//FIXME: workaround to prevent dialogs of Popup type disappearing on the second show
|
//FIXME: workaround to prevent dialogs of Popup type disappearing on the second show
|
||||||
const QSize s = QSize(m_mainItem.data()->width(), m_mainItem.data()->height()) +
|
const QSize s = QSize(m_mainItem.data()->width(), m_mainItem.data()->height()) +
|
||||||
QSize(m_frameSvgItem->margins()->left() + m_frameSvgItem->margins()->right(),
|
QSize(m_frameSvgItem->margins()->left() + m_frameSvgItem->margins()->right(),
|
||||||
|
@ -150,7 +150,7 @@ Q_SIGNALS:
|
|||||||
void locationChanged();
|
void locationChanged();
|
||||||
void visualParentChanged();
|
void visualParentChanged();
|
||||||
|
|
||||||
private Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void syncMainItemToSize();
|
void syncMainItemToSize();
|
||||||
void syncToMainItemSize();
|
void syncToMainItemSize();
|
||||||
|
|
||||||
|
@ -102,7 +102,14 @@ void ToolTip::setMainItem(QQuickItem *mainItem)
|
|||||||
|
|
||||||
QQuickItem *ToolTip::visualParent() const
|
QQuickItem *ToolTip::visualParent() const
|
||||||
{
|
{
|
||||||
return m_visualParent.data();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTip::setVisualParent(QQuickItem *visualParent)
|
void ToolTip::setVisualParent(QQuickItem *visualParent)
|
||||||
@ -126,19 +133,22 @@ bool ToolTip::isVisible() const
|
|||||||
void ToolTip::setVisible(const bool visible)
|
void ToolTip::setVisible(const bool visible)
|
||||||
{
|
{
|
||||||
ToolTipDialog *dlg = ToolTipDialog::instance();
|
ToolTipDialog *dlg = ToolTipDialog::instance();
|
||||||
qDebug() << visible;
|
qDebug() << "creating tooltipdialog" << visible;
|
||||||
if (visible) {
|
if (visible) {
|
||||||
//dlg->mainItem()->deleteLater();
|
//dlg->mainItem()->deleteLater();
|
||||||
|
|
||||||
// QObject *myObject = m_mainComponent.data()->create();
|
// QObject *myObject = m_mainComponent.data()->create();
|
||||||
// QQuickItem *item = qobject_cast<QQuickItem*>(myObject);
|
// QQuickItem *item = qobject_cast<QQuickItem*>(myObject);
|
||||||
qDebug() << "XXX Setting visible: " << mainItem();
|
qDebug() << "---- XXX Setting visible: " << mainItem();
|
||||||
setMainItem(mainItem());
|
setMainItem(mainItem());
|
||||||
|
|
||||||
|
|
||||||
qDebug() << "XXX showing tooltip: " << ToolTipDialog::instance();
|
qDebug() << "XXX showing tooltip: " << ToolTipDialog::instance();
|
||||||
|
qDebug() << "XXX positioning near: " << visualParent()->objectName();
|
||||||
dlg->setMainItem(mainItem());
|
dlg->setMainItem(mainItem());
|
||||||
dlg->setVisualParent(m_visualParent.data());
|
dlg->setVisualParent(visualParent());
|
||||||
dlg->setPosition(dlg->popupPosition(visualParent()));
|
dlg->syncToMainItemSize();
|
||||||
|
//dlg->setPosition(dlg->popupPosition(visualParent()));
|
||||||
dlg->setVisible(true);
|
dlg->setVisible(true);
|
||||||
|
|
||||||
// syncGeometry();
|
// syncGeometry();
|
||||||
|
@ -31,7 +31,6 @@ ToolTipDialog::ToolTipDialog(QQuickItem *parent)
|
|||||||
{
|
{
|
||||||
setFlags(Qt::ToolTip);
|
setFlags(Qt::ToolTip);
|
||||||
m_frameSvgItem->setImagePath("widgets/tooltip");
|
m_frameSvgItem->setImagePath("widgets/tooltip");
|
||||||
qDebug() << "XXX TOolTip ctor'ed";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ToolTipDialog::~ToolTipDialog()
|
ToolTipDialog::~ToolTipDialog()
|
||||||
|
@ -42,11 +42,6 @@ ToolTipWindow::ToolTipWindow(QWindow *parent)
|
|||||||
m_syncTimer->setSingleShot(true);
|
m_syncTimer->setSingleShot(true);
|
||||||
m_syncTimer->setInterval(250);
|
m_syncTimer->setInterval(250);
|
||||||
connect(m_syncTimer, &QTimer::timeout, this, &ToolTipWindow::syncGeometry);
|
connect(m_syncTimer, &QTimer::timeout, this, &ToolTipWindow::syncGeometry);
|
||||||
|
|
||||||
connect(this, SIGNAL(targetChanged()), this, SLOT(updateToolTip()));
|
|
||||||
connect(this, SIGNAL(mainTextChanged()), this, SLOT(updateToolTip()));
|
|
||||||
connect(this, SIGNAL(subTextChanged()), this, SLOT(updateToolTip()));
|
|
||||||
connect(this, SIGNAL(imageChanged()), this, SLOT(updateToolTip()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ToolTipWindow::~ToolTipWindow()
|
ToolTipWindow::~ToolTipWindow()
|
||||||
@ -76,8 +71,6 @@ void ToolTipWindow::setTarget(QQuickItem *target)
|
|||||||
|
|
||||||
void ToolTipWindow::syncGeometry()
|
void ToolTipWindow::syncGeometry()
|
||||||
{
|
{
|
||||||
qDebug() << " XXX synching geometry";
|
|
||||||
qDebug() << "XXXX mainitem : " << mainItem()->width() << mainItem()->height();
|
|
||||||
resize(mainItem()->width(), mainItem()->height());
|
resize(mainItem()->width(), mainItem()->height());
|
||||||
setPosition(popupPosition(visualParent()));
|
setPosition(popupPosition(visualParent()));
|
||||||
|
|
||||||
@ -132,47 +125,6 @@ void ToolTipWindow::setImage(QVariant name)
|
|||||||
emit imageChanged();
|
emit imageChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTipWindow::updateToolTip()
|
|
||||||
{
|
|
||||||
if (!m_widget) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Plasma::ToolTipContent data;
|
|
||||||
// data.setMainText(m_mainText);
|
|
||||||
// data.setSubText(m_subText);
|
|
||||||
|
|
||||||
// set image
|
|
||||||
switch (m_image.type()) {
|
|
||||||
case QVariant::String: {
|
|
||||||
QString name = m_image.toString();
|
|
||||||
if (!name.isEmpty()) {
|
|
||||||
QIcon icon = QIcon::fromTheme(name);
|
|
||||||
if (!icon.isNull()) {
|
|
||||||
// data.setImage(icon.pixmap(IconSize(KIconLoader::Desktop)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case QVariant::Icon: {
|
|
||||||
QIcon icon = m_image.value<QIcon>();
|
|
||||||
// data.setImage(icon);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case QVariant::Pixmap: {
|
|
||||||
QPixmap pixmap = m_image.value<QPixmap>();
|
|
||||||
// data.setImage(pixmap);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//Plasma::ToolTipManager::self()->setContent(m_widget, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
QQuickItem *ToolTipWindow::mainItem() const
|
QQuickItem *ToolTipWindow::mainItem() const
|
||||||
{
|
{
|
||||||
return m_mainItem.data();
|
return m_mainItem.data();
|
||||||
@ -180,11 +132,7 @@ QQuickItem *ToolTipWindow::mainItem() const
|
|||||||
|
|
||||||
void ToolTipWindow::setMainItem(QQuickItem *mainItem)
|
void ToolTipWindow::setMainItem(QQuickItem *mainItem)
|
||||||
{
|
{
|
||||||
qDebug() << "XXXX mainitem changed: " << mainItem->width() << mainItem->height();
|
|
||||||
|
|
||||||
// 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::widthChanged, this, &ToolTipWindow::syncGeometry);
|
||||||
disconnect(m_mainItem.data(), &QQuickItem::heightChanged, this, &ToolTipWindow::syncGeometry);
|
disconnect(m_mainItem.data(), &QQuickItem::heightChanged, this, &ToolTipWindow::syncGeometry);
|
||||||
if (m_mainItem) {
|
if (m_mainItem) {
|
||||||
@ -194,7 +142,6 @@ void ToolTipWindow::setMainItem(QQuickItem *mainItem)
|
|||||||
|
|
||||||
|
|
||||||
if (mainItem) {
|
if (mainItem) {
|
||||||
//mainItem->setParentItem(0);
|
|
||||||
connect(m_mainItem.data(), &QQuickItem::widthChanged, this, &ToolTipWindow::syncGeometry);
|
connect(m_mainItem.data(), &QQuickItem::widthChanged, this, &ToolTipWindow::syncGeometry);
|
||||||
connect(m_mainItem.data(), &QQuickItem::heightChanged, this, &ToolTipWindow::syncGeometry);
|
connect(m_mainItem.data(), &QQuickItem::heightChanged, this, &ToolTipWindow::syncGeometry);
|
||||||
qDebug() << "XXX new mainITem connected";
|
qDebug() << "XXX new mainITem connected";
|
||||||
@ -209,7 +156,7 @@ void ToolTipWindow::setMainItem(QQuickItem *mainItem)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//if this is called in Compenent.onCompleted we have to wait a loop the item is added to a scene
|
//if this is called in Component.onCompleted we have to wait a loop the item is added to a scene
|
||||||
emit mainItemChanged();
|
emit mainItemChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -230,7 +177,6 @@ void ToolTipWindow::setVisualParent(QQuickItem *visualParent)
|
|||||||
}
|
}
|
||||||
disconnect(m_visualParent.data(), &QQuickItem::xChanged, this, &ToolTipWindow::syncGeometry);
|
disconnect(m_visualParent.data(), &QQuickItem::xChanged, this, &ToolTipWindow::syncGeometry);
|
||||||
disconnect(m_visualParent.data(), &QQuickItem::yChanged, this, &ToolTipWindow::syncGeometry);
|
disconnect(m_visualParent.data(), &QQuickItem::yChanged, this, &ToolTipWindow::syncGeometry);
|
||||||
//disconnect(visualParent, &QQuickItem::yChanged, this, &ToolTipWindow::syncGeometry);
|
|
||||||
|
|
||||||
m_visualParent = visualParent;
|
m_visualParent = visualParent;
|
||||||
connect(m_visualParent.data(), &QQuickItem::xChanged, this, &ToolTipWindow::syncGeometry);
|
connect(m_visualParent.data(), &QQuickItem::xChanged, this, &ToolTipWindow::syncGeometry);
|
||||||
@ -242,14 +188,12 @@ void ToolTipWindow::setVisualParent(QQuickItem *visualParent)
|
|||||||
bool ToolTipWindow::isVisible() const
|
bool ToolTipWindow::isVisible() const
|
||||||
{
|
{
|
||||||
return QQuickWindow::isVisible();
|
return QQuickWindow::isVisible();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTipWindow::setVisible(const bool visible)
|
void ToolTipWindow::setVisible(const bool visible)
|
||||||
{
|
{
|
||||||
qDebug() << visible;
|
qDebug() << visible;
|
||||||
if (visible) {
|
if (visible) {
|
||||||
//setPosition(popupPosition());
|
|
||||||
syncGeometry();
|
syncGeometry();
|
||||||
raise();
|
raise();
|
||||||
}
|
}
|
||||||
@ -266,7 +210,6 @@ QPoint ToolTipWindow::popupPosition(QQuickItem *item, Qt::AlignmentFlag alignmen
|
|||||||
QPointF itemScreenPos;
|
QPointF itemScreenPos;
|
||||||
|
|
||||||
QPointF pos = item->mapToScene(QPointF(0, 0));
|
QPointF pos = item->mapToScene(QPointF(0, 0));
|
||||||
//qDebug() << "I've an Item at " << pos;
|
|
||||||
if (item->window() && item->window()->screen()) {
|
if (item->window() && item->window()->screen()) {
|
||||||
pos = item->window()->mapToGlobal(pos.toPoint());
|
pos = item->window()->mapToGlobal(pos.toPoint());
|
||||||
} else {
|
} else {
|
||||||
|
@ -113,7 +113,6 @@ Q_SIGNALS:
|
|||||||
|
|
||||||
protected Q_SLOTS:
|
protected Q_SLOTS:
|
||||||
void syncGeometry();
|
void syncGeometry();
|
||||||
void updateToolTip();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTimer *m_syncTimer;
|
QTimer *m_syncTimer;
|
||||||
|
Loading…
Reference in New Issue
Block a user