Give tooltips to view actions.
This commit is contained in:
@@ -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 <craig.p.drummond@gmail.com>")
|
||||
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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -25,9 +25,13 @@
|
||||
#include "itemview.h"
|
||||
#include "icon.h"
|
||||
#include "config.h"
|
||||
#include "groupedview.h"
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QAction>
|
||||
#include <QtGui/QPixmap>
|
||||
#include <QtGui/QListView>
|
||||
#include <QtGui/QHelpEvent>
|
||||
#include <QtGui/QToolTip>
|
||||
|
||||
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<QListView *>(view);
|
||||
GroupedView *gv=lv ? 0 : qobject_cast<GroupedView *>(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<QIcon>().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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user