diff --git a/src/library/libraryview.cpp b/src/library/libraryview.cpp index f494f79eb..a92ecda22 100644 --- a/src/library/libraryview.cpp +++ b/src/library/libraryview.cpp @@ -34,10 +34,13 @@ #include #include +#include #include #include #include #include +#include +#include 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(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) : AutoExpandingTreeView(parent), scripts_(NULL), diff --git a/src/library/libraryview.h b/src/library/libraryview.h index d82adbda2..6d57e2bd7 100644 --- a/src/library/libraryview.h +++ b/src/library/libraryview.h @@ -37,9 +37,14 @@ class QMimeData; namespace smart_playlists { class Wizard; } class LibraryItemDelegate : public QStyledItemDelegate { + Q_OBJECT public: LibraryItemDelegate(QObject* parent); 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 {