Show tooltip for long text in MIDI panel (tracks table)

This commit is contained in:
Andrey M. Tokarev 2013-09-08 21:00:52 +04:00
parent e6b047c0c0
commit a7f5d0a90e
5 changed files with 67 additions and 3 deletions

View file

@ -154,7 +154,7 @@ QT4_WRAP_CPP (mocs
importmidi_operation.h importmidi_quant.h importmidi_chord.h
importmidi_tuplet.h importmidi_inner.h importmidi_data.h importmidi_swing.h
debugger/debugger.h importmidi_fraction.h importmidi_drum.h
importmidi_lrhand.h importmidi_lyrics.h
importmidi_lrhand.h importmidi_lyrics.h importmidi_trview.h
${OMR_MOCS}
${SCRIPT_MOCS}
)
@ -269,7 +269,7 @@ add_executable ( ${ExecutableName}
importmidi_opmodel.cpp importmidi_trmodel.cpp importmidi_opdelegate.cpp
importmidi_meter.cpp importmidi_quant.cpp importmidi_tuplet.cpp importmidi_chord.cpp
importmidi_data.cpp importmidi_swing.cpp importmidi_fraction.cpp importmidi_drum.cpp
importmidi_clef.cpp importmidi_lrhand.cpp importmidi_lyrics.cpp
importmidi_clef.cpp importmidi_lrhand.cpp importmidi_lyrics.cpp importmidi_trview.cpp
${OMR_FILES}
${AUDIO}

View file

@ -196,7 +196,7 @@
<property name="handleWidth">
<number>2</number>
</property>
<widget class="QTableView" name="tableViewTracks">
<widget class="TracksView" name="tableViewTracks">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
@ -235,6 +235,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>TracksView</class>
<extends>QTableView</extends>
<header>mscore/importmidi_trview.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="musescore.qrc"/>
</resources>

View file

@ -417,6 +417,18 @@ QVariant TracksModel::data(const QModelIndex &index, int role) const
case Qt::TextAlignmentRole:
return Qt::AlignCenter;
break;
case Qt::ToolTipRole:
if (trackIndex != -1) {
switch (index.column()) {
case TrackCol::STAFF_NAME:
return tracksData_[trackIndex].meta.staffName;
case TrackCol::INSTRUMENT:
return tracksData_[trackIndex].meta.instrumentName;
default:
break;
}
}
break;
default:
break;
}

View file

@ -0,0 +1,28 @@
#include "importmidi_trview.h"
TracksView::TracksView(QWidget *parent)
: QTableView(parent)
{
}
// show tooltip if the text is wider than the table cell
bool TracksView::viewportEvent(QEvent *event)
{
if (event->type() == QEvent::ToolTip) {
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
QModelIndex index = indexAt(helpEvent->pos());
if (index.isValid()) {
QSize sizeHint = itemDelegate(index)->sizeHint(viewOptions(), index);
QRect rItem(0, 0, sizeHint.width(), sizeHint.height());
QRect rVisual = visualRect(index);
if (rItem.width() <= rVisual.width()) {
QToolTip::hideText();
return false;
}
}
}
return QTableView::viewportEvent(event);
}

View file

@ -0,0 +1,17 @@
#ifndef IMPORTMIDI_TRVIEW_H
#define IMPORTMIDI_TRVIEW_H
#include <QTableView>
class TracksView : public QTableView
{
public:
explicit TracksView(QWidget *parent);
protected:
bool viewportEvent(QEvent *event);
};
#endif // IMPORTMIDI_TRVIEW_H