Display tooltip info in library only if text displayed is elided (as it was done for playlistdelegates, r2745). Partially fixes issue 451
This commit is contained in:
parent
33276132ec
commit
de2193f5af
|
@ -34,10 +34,13 @@
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QContextMenuEvent>
|
#include <QContextMenuEvent>
|
||||||
|
#include <QHelpEvent>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QToolTip>
|
||||||
|
#include <QWhatsThis>
|
||||||
|
|
||||||
using smart_playlists::Wizard;
|
using smart_playlists::Wizard;
|
||||||
|
|
||||||
|
@ -80,6 +83,50 @@ void LibraryItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LibraryItemDelegate::helpEvent(QHelpEvent *event, QAbstractItemView *view,
|
||||||
|
const QStyleOptionViewItem &option,
|
||||||
|
const QModelIndex &index) {
|
||||||
|
Q_UNUSED(option);
|
||||||
|
|
||||||
|
if (!event || !view)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QHelpEvent *he = static_cast<QHelpEvent*>(event);
|
||||||
|
QString text = displayText(index.data(), QLocale::system());
|
||||||
|
|
||||||
|
if (text.isEmpty() || !he)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
switch (event->type()) {
|
||||||
|
case QEvent::ToolTip: {
|
||||||
|
QRect displayed_text;
|
||||||
|
QSize real_text;
|
||||||
|
bool is_elided = false;
|
||||||
|
|
||||||
|
real_text = sizeHint(option, index);
|
||||||
|
displayed_text = view->visualRect(index);
|
||||||
|
is_elided = displayed_text.width() < real_text.width();
|
||||||
|
if(is_elided) {
|
||||||
|
QToolTip::showText(he->globalPos(), text, view);
|
||||||
|
} else { // in case that another text was previously displayed
|
||||||
|
QToolTip::hideText();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case QEvent::QueryWhatsThis:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case QEvent::WhatsThis:
|
||||||
|
QWhatsThis::showText(he->globalPos(), text, view);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
LibraryView::LibraryView(QWidget* parent)
|
LibraryView::LibraryView(QWidget* parent)
|
||||||
: AutoExpandingTreeView(parent),
|
: AutoExpandingTreeView(parent),
|
||||||
scripts_(NULL),
|
scripts_(NULL),
|
||||||
|
|
|
@ -37,9 +37,14 @@ class QMimeData;
|
||||||
namespace smart_playlists { class Wizard; }
|
namespace smart_playlists { class Wizard; }
|
||||||
|
|
||||||
class LibraryItemDelegate : public QStyledItemDelegate {
|
class LibraryItemDelegate : public QStyledItemDelegate {
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
LibraryItemDelegate(QObject* parent);
|
LibraryItemDelegate(QObject* parent);
|
||||||
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
bool helpEvent(QHelpEvent *event, QAbstractItemView *view,
|
||||||
|
const QStyleOptionViewItem &option, const QModelIndex &index);
|
||||||
};
|
};
|
||||||
|
|
||||||
class LibraryView : public AutoExpandingTreeView {
|
class LibraryView : public AutoExpandingTreeView {
|
||||||
|
|
Loading…
Reference in New Issue