2016-01-21 13:32:27 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Christian Kamm <mail@ckamm.de>
|
|
|
|
*
|
|
|
|
* 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
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2016-01-21 13:32:27 +03:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tooltipupdater.h"
|
|
|
|
|
|
|
|
#include <QTreeView>
|
|
|
|
#include <QHelpEvent>
|
|
|
|
#include <QToolTip>
|
|
|
|
|
|
|
|
using namespace OCC;
|
|
|
|
|
|
|
|
ToolTipUpdater::ToolTipUpdater(QTreeView *treeView)
|
|
|
|
: QObject(treeView)
|
|
|
|
, _treeView(treeView)
|
|
|
|
{
|
2017-09-20 11:14:48 +03:00
|
|
|
connect(_treeView->model(), &QAbstractItemModel::dataChanged,
|
|
|
|
this, &ToolTipUpdater::dataChanged);
|
2016-01-21 13:32:27 +03:00
|
|
|
_treeView->viewport()->installEventFilter(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ToolTipUpdater::eventFilter(QObject * /*obj*/, QEvent *ev)
|
|
|
|
{
|
|
|
|
if (ev->type() == QEvent::ToolTip) {
|
2022-09-30 22:36:58 +03:00
|
|
|
auto *helpEvent = dynamic_cast<QHelpEvent *>(ev);
|
2016-01-21 13:32:27 +03:00
|
|
|
_toolTipPos = helpEvent->globalPos();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToolTipUpdater::dataChanged(const QModelIndex &topLeft,
|
|
|
|
const QModelIndex &bottomRight,
|
|
|
|
const QVector<int> &roles)
|
|
|
|
{
|
|
|
|
if (!QToolTip::isVisible() || !roles.contains(Qt::ToolTipRole) || _toolTipPos.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Was it the item under the cursor that changed?
|
|
|
|
auto index = _treeView->indexAt(_treeView->mapFromGlobal(QCursor::pos()));
|
|
|
|
if (topLeft == bottomRight && index != topLeft) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the currently active tooltip
|
|
|
|
QToolTip::showText(_toolTipPos, _treeView->model()->data(index, Qt::ToolTipRole).toString());
|
|
|
|
}
|