diff --git a/CMakeLists.txt b/CMakeLists.txt index aae05bcea..8fdc3c35b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ set(DEBIAN_PACKAGE_SECTION "kde4") set(CPACK_SOURCE_GENERATOR "TBZ2") set(CPACK_PACKAGE_VERSION_MAJOR "0") set(CPACK_PACKAGE_VERSION_MINOR "9") -set(CPACK_PACKAGE_VERSION_PATCH "0") +set(CPACK_PACKAGE_VERSION_PATCH "50") set(CPACK_PACKAGE_CONTACT "Craig Drummond ") set(CANTATA_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}") set(CANTATA_VERSION_FULL "${CANTATA_VERSION}.${CPACK_PACKAGE_VERSION_PATCH}") @@ -188,6 +188,7 @@ SET( CANTATA_MOC_HDRS widgets/actionlabel.h widgets/playqueueview.h widgets/groupedview.h + widgets/actionitemdelegate.h widgets/coverwidget.h widgets/volumecontrol.h widgets/genrecombo.h diff --git a/ChangeLog b/ChangeLog index 76c26e6c0..228eca72f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ -0.9.0 +X.X.X +----- +1. Give tooltips to view actions. + +0.9.0 ----- 1. Add a 'server' mode to cantata-dynamic. This contains a basic HTTP API to list rules, update rules, and start/stop the dynamic mode. diff --git a/widgets/actionitemdelegate.cpp b/widgets/actionitemdelegate.cpp index 53ead9b02..e8698ea10 100644 --- a/widgets/actionitemdelegate.cpp +++ b/widgets/actionitemdelegate.cpp @@ -25,9 +25,13 @@ #include "itemview.h" #include "icon.h" #include "config.h" +#include "groupedview.h" #include #include #include +#include +#include +#include int ActionItemDelegate::constBorder = 1; int ActionItemDelegate::constActionBorder = 4; @@ -179,3 +183,73 @@ void ActionItemDelegate::drawIcons(QPainter *painter, const QRect &r, bool mouse } } +bool ActionItemDelegate::helpEvent(QHelpEvent *e, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index) +{ + if (QEvent::ToolTip==e->type() && (act1 || act2 || toggle)) { + QAction *act=getAction(view, index); + if (act) { + QToolTip::showText(e->globalPos(), act->toolTip(), view); + return true; + } + } + return QStyledItemDelegate::helpEvent(e, view, option, index); +} + +QAction * ActionItemDelegate::getAction(QAbstractItemView *view, const QModelIndex &index) +{ + if (!hasActions(index, actLevel)) { + return 0; + } + + bool rtl = Qt::RightToLeft==QApplication::layoutDirection(); + QListView *lv=qobject_cast(view); + GroupedView *gv=lv ? 0 : qobject_cast(view); + bool iconMode=lv && QListView::ListMode!=lv->viewMode() && index.child(0, 0).isValid(); + QRect rect = view->visualRect(index); + rect.moveTo(view->viewport()->mapToGlobal(QPoint(rect.x(), rect.y()))); + bool showCapacity = !index.data(ItemView::Role_CapacityText).toString().isEmpty(); + bool haveToggle = toggle && !index.data(ItemView::Role_ToggleIcon).value().isNull(); + if (gv || lv || showCapacity) { + if (iconMode) { + rect.adjust(ActionItemDelegate::constBorder, ActionItemDelegate::constBorder, -ActionItemDelegate::constBorder, -ActionItemDelegate::constBorder); + } else { + rect.adjust(ActionItemDelegate::constBorder+3, 0, -(ActionItemDelegate::constBorder+3), 0); + } + } + + if (showCapacity) { + int textHeight=QFontMetrics(QApplication::font()).height(); + rect.adjust(0, 0, 0, -(textHeight+8)); + } + + QRect actionRect=ActionItemDelegate::calcActionRect(rtl, iconMode, rect); + QRect actionRect2(actionRect); + ActionItemDelegate::adjustActionRect(rtl, iconMode, actionRect2); + + actionRect=iconMode ? actionRect.adjusted(0, -2, 0, 2) : actionRect.adjusted(-2, 0, 2, 0); + if (act1 && actionRect.contains(QCursor::pos())) { + return act1; + } + + if (act1) { + ActionItemDelegate::adjustActionRect(rtl, iconMode, actionRect); + } + + actionRect=iconMode ? actionRect.adjusted(0, -2, 0, 2) : actionRect.adjusted(-2, 0, 2, 0); + if (act2 && actionRect.contains(QCursor::pos())) { + return act2; + } + + if (haveToggle) { + if (act1 || act2) { + ActionItemDelegate::adjustActionRect(rtl, iconMode, actionRect); + } + + actionRect=iconMode ? actionRect.adjusted(0, -2, 0, 2) : actionRect.adjusted(-2, 0, 2, 0); + if (toggle && actionRect.contains(QCursor::pos())) { + return toggle; + } + } + + return 0; +} diff --git a/widgets/actionitemdelegate.h b/widgets/actionitemdelegate.h index 919a6a098..d7b2d437d 100644 --- a/widgets/actionitemdelegate.h +++ b/widgets/actionitemdelegate.h @@ -30,6 +30,8 @@ class QAction; class ActionItemDelegate : public QStyledItemDelegate { + Q_OBJECT + public: static void setup(); @@ -54,6 +56,13 @@ public: void drawIcons(QPainter *painter, const QRect &r, bool mouseOver, bool rtl, bool iconMode, const QModelIndex &index) const; +public Q_SLOTS: + bool helpEvent(QHelpEvent *e, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index); + +private: + QAction * getAction(QAbstractItemView *view, const QModelIndex &index); + +public: QAction *act1; QAction *act2; QAction *toggle;