Skip to content

Commit

Permalink
Add a lot of tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Sep 24, 2021
1 parent 27e47dc commit 611991a
Show file tree
Hide file tree
Showing 22 changed files with 116 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/lib/core/view/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ void View::resizeEvent(QResizeEvent* e)
QMainWindow::resizeEvent(e);
sizeChanged(e->size());
}

bool score::View::event(QEvent* event)
{
if (event->type() == QEvent::StatusTip)
Expand All @@ -484,7 +485,7 @@ bool score::View::event(QEvent* event)
tip.push_front("<b>");
tip.push_back("</b>");
}
tip.replace(QChar('\n'), "</br>");
tip.replace(QChar('\n'), "<br/>");
m_status->setText(tip);
}
else if (event->type() == QEvent::ToolTip)
Expand Down
5 changes: 3 additions & 2 deletions src/lib/score/graphics/GraphicsItem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ QGraphicsView* getView(const QPainter& painter);

SCORE_LIB_BASE_EXPORT
QImage newImage(double logical_w, double logical_h);

template <typename T>
struct graphics_item_ptr
{
T* impl{};
graphics_item_ptr() = default;
graphics_item_ptr(const graphics_item_ptr&) = default;
graphics_item_ptr(graphics_item_ptr&&) = default;
graphics_item_ptr(graphics_item_ptr&&) noexcept = default;
graphics_item_ptr& operator=(const graphics_item_ptr&) = default;
graphics_item_ptr& operator=(graphics_item_ptr&&) = default;
graphics_item_ptr& operator=(graphics_item_ptr&&) noexcept = default;

graphics_item_ptr(T* p)
: impl{p}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/score-lib-process/Effect/EffectLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ auto createControl(
QPointF pos = Process::currentWigetPos(i, setup.getControlSize);
item->setPos(pos);
item->setRect(itemRect);
item->setToolTip(QString("%1\n%2").arg(port.name(), port.description()));

return Controls{item, portItem, widg, lab, itemRect};
}
Expand All @@ -153,6 +154,7 @@ auto createControl(
lab->setPos(20., 2);
item->setPos(pos);
item->setRect(itemRect);
item->setToolTip(QString("%1\n%2").arg(port.name(), port.description()));

return Controls{item, portItem, nullptr, lab, itemRect};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CableItem::CableItem(
auto& plug = ctx.dataflow;
this->setCursor(Qt::CrossCursor);
this->setFlag(QGraphicsItem::ItemClipsToShape);
this->setToolTip(tr("Cable\n"));

SCORE_ASSERT(canCreateCable(c, plug));

Expand Down
11 changes: 11 additions & 0 deletions src/plugins/score-lib-process/Process/Dataflow/NodeItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,17 @@ void NodeItem::createContentItem()
m_contentSize = m_fx->boundingRect().size();
}

if(m_fx->toolTip().isEmpty())
{
auto& p = this->m_context.app.interfaces<Process::ProcessFactoryList>();
const auto& desc = p.get(m_model.concreteKey())->descriptor({});
this->setToolTip(QString("%1\n%2").arg(desc.prettyName, desc.description));
}
else
{
this->setToolTip(m_fx->toolTip());
}

// Positions / size
m_fx->setPos({0, 0});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ SegmentView::SegmentView(
: QGraphicsItem{parent}
, m_style{style}
{
this->setToolTip(QObject::tr("Curve segment\nRight-click to change options. If the type is power, shift can be used to change its curvature."));

this->setCacheMode(QGraphicsItem::NoCache);
this->setZValue(1);
this->setFlag(ItemIsFocusable, false);
Expand Down
1 change: 1 addition & 0 deletions src/plugins/score-plugin-midi/Midi/MidiNoteView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ NoteView::NoteView(const Note& n, Presenter& p, View* parent)
, m_presenter{p}
, m_action{None}
{
this->setToolTip(QObject::tr("A MIDI note."));
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CommentBlockView::CommentBlockView(
this->setParentItem(parent);
this->setZValue(ZPos::Comment);
this->setAcceptHoverEvents(true);
this->setToolTip(tr("Comment box\nPut the text you want in here by double-clicking !"));

m_textItem = new score::TextItem{"", this};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ConditionView::ConditionView(const EventModel& model, QGraphicsItem* parent)
, m_model{model}
{
this->setCacheMode(QGraphicsItem::NoCache);
this->setToolTip(tr("Condition\nSet whether the following intervals will execute."));
setFlag(ItemStacksBehindParent, true);
setCursor(Qt::CursorShape::CrossCursor);
setHeight(0.);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ AddressBarItem::AddressBarItem(
: QGraphicsItem{parent}
, m_ctx{ctx}
{
this->setToolTip(tr("Address bar\nClick here to travel to the specific hierarchy level"));
this->setFlag(QGraphicsItem::ItemHasNoContents, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class TimeSignatureHandle
TimeSignatureHandle(const IntervalModel& itv, QGraphicsItem* parent)
: QGraphicsItem{parent}
{
this->setToolTip(QObject::tr("Time signature handle\nDrag to displace, double-click to change the signature."));
setFlag(ItemIsSelectable, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ IntervalView::IntervalView(IntervalPresenter& presenter, QGraphicsItem* parent)
, m_dropTarget{false}
, m_state{}
{
this->setToolTip(QObject::tr("Interval\nA span of time which can contain processes."));
setAcceptHoverEvents(true);
setAcceptDrops(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ void LayerData::addView(
container->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
container->setY(m_slotY);
auto view = factory.makeLayerView(*m_model, context, container);
if(view->toolTip().isEmpty())
{
auto& p = context.app.interfaces<Process::ProcessFactoryList>();
const auto& desc = p.get(m_model->concreteKey())->descriptor({});
view->setToolTip(QString("%1\n%2").arg(desc.prettyName, desc.description));
}

double startX = m_model->flags() & Process::ProcessFlags::HandlesLooping
? 0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ SlotHeader::SlotHeader(
, m_width{slotView.view()->boundingRect().width()}
, m_slotIndex{slotIndex}
{
this->setToolTip(QObject::tr("Slot header\nDrag the \u2630 symbol to move the slot elsewhere."));
this->setCacheMode(QGraphicsItem::NoCache);
this->setAcceptHoverEvents(true);
this->setFlag(ItemClipsToShape);
Expand Down Expand Up @@ -312,6 +313,7 @@ AmovibleSlotFooter::AmovibleSlotFooter(
, m_fullView{
bool(qobject_cast<const FullViewIntervalPresenter*>(&m_presenter))}
{
this->setToolTip(QObject::tr("Drag me to resize this slot."));
auto& skin = score::Skin::instance();
this->setCursor(skin.CursorScaleV);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SCORE_PLUGIN_SCENARIO_EXPORT LeftBraceView final : public IntervalBrace
LeftBraceView(const IntervalView& parentCstr, QGraphicsItem* parent)
: IntervalBrace{parentCstr, parent}
{
this->setToolTip(QObject::tr("Interval left brace\nDrag to change the minimal duration of an interval."));
}
~LeftBraceView() override;

Expand All @@ -28,6 +29,7 @@ class SCORE_PLUGIN_SCENARIO_EXPORT RightBraceView final : public IntervalBrace
: IntervalBrace{parentCstr, parent}
{
this->setRotation(180);
this->setToolTip(QObject::tr("Interval right brace\nDrag to change the maximal duration of an interval."));
}
~RightBraceView() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,55 @@ void ProcessGraphicsView::dropEvent(QDropEvent* event)
}
}

bool ProcessGraphicsView::event(QEvent* event)
{
switch (event->type())
{
case QEvent::HoverEnter:
hoverEnterEvent(static_cast<QHoverEvent*>(event));
return true;
case QEvent::HoverLeave:
hoverLeaveEvent(static_cast<QHoverEvent*>(event));
return true;
case QEvent::HoverMove:
hoverMoveEvent(static_cast<QHoverEvent*>(event));
return true;
default:
return QGraphicsView::event(event);
}
}

void ProcessGraphicsView::hoverEnterEvent(QHoverEvent* event)
{

}

void ProcessGraphicsView::hoverMoveEvent(QHoverEvent* event)
{
const auto scenePos = this->mapToScene(event->pos());
auto items = this->scene()->items(scenePos);
auto set_tip = [&] (const QString& t) {
QStatusTipEvent ev{t};
auto obj = reinterpret_cast<QObject*>(this->m_app.mainWindow);
obj->event(&ev);
};
for (int i = 0; i < items.size(); ++i)
{
if(const auto& tooltip = items.at(i)->toolTip(); !tooltip.isEmpty())
{
set_tip(tooltip);
return;
}
}

set_tip(QString{});
}

void ProcessGraphicsView::hoverLeaveEvent(QHoverEvent* event)
{

}

ScenarioDocumentView::ScenarioDocumentView(
const score::DocumentContext& ctx,
QObject* parent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ class SCORE_PLUGIN_SCENARIO_EXPORT ProcessGraphicsView final
void dragMoveEvent(QDragMoveEvent* event) override;
void dragLeaveEvent(QDragLeaveEvent* event) override;
void dropEvent(QDropEvent* event) override;
bool event(QEvent*) override;

void hoverEnterEvent(QHoverEvent* event);
void hoverMoveEvent(QHoverEvent* event);
void hoverLeaveEvent(QHoverEvent* event);

void checkAndRemoveCurrentDialog(QPoint pos);
// void drawBackground(QPainter* painter, const QRectF& rect) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ ScenarioScene::ScenarioScene(QObject* parent)
{
setItemIndexMethod(QGraphicsScene::NoIndex);
}

void ScenarioScene::helpEvent(QGraphicsSceneHelpEvent* event)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ class ScenarioScene final : public QGraphicsScene
W_OBJECT(ScenarioScene)
public:
ScenarioScene(QObject* parent);

void helpEvent(QGraphicsSceneHelpEvent* event) override;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Scenario
class CrossOverlay : public QGraphicsItem
{
public:
CrossOverlay(StateView* parent)
explicit CrossOverlay(StateView* parent)
: QGraphicsItem{parent}
{
this->setFlag(ItemStacksBehindParent, true);
Expand Down Expand Up @@ -111,7 +111,11 @@ class CrossOverlay : public QGraphicsItem
class StatePlusOverlay final : public CrossOverlay
{
public:
using CrossOverlay::CrossOverlay;
explicit StatePlusOverlay(StateView* parent)
: CrossOverlay{parent}
{
this->setToolTip(QObject::tr("Create an interval.\nDrag the plus to create an interval"));
}

private:
const score::Brush& brush() const noexcept override
Expand Down Expand Up @@ -140,7 +144,11 @@ class StatePlusOverlay final : public CrossOverlay
class StateGraphPlusOverlay final : public CrossOverlay
{
public:
using CrossOverlay::CrossOverlay;
explicit StateGraphPlusOverlay(StateView* parent)
: CrossOverlay{parent}
{
this->setToolTip(QObject::tr("Create a graph link.\nDrag the plus to create a graph link"));
}

private:
const score::Brush& brush() const noexcept override
Expand Down Expand Up @@ -169,7 +177,11 @@ class StateGraphPlusOverlay final : public CrossOverlay
class StateSequencePlusOverlay final : public CrossOverlay
{
public:
using CrossOverlay::CrossOverlay;
explicit StateSequencePlusOverlay(StateView* parent)
: CrossOverlay{parent}
{
this->setToolTip(QObject::tr("Create a sequence.\nDrag the plus to create a sequence."));
}

private:
const score::Brush& brush() const noexcept override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ StateView::StateView(StatePresenter& pres, QGraphicsItem* parent)
if (!is_hidpi())
this->setCacheMode(QGraphicsItem::CacheMode::ItemCoordinateCache);
this->setParentItem(parent);
this->setToolTip(QStringLiteral("State view"));

auto& skin = score::Skin::instance();
this->setCursor(skin.CursorMove);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ TriggerView::TriggerView(QGraphicsItem* parent)
, m_waiting{false}
{
auto& skin = score::Skin::instance();
this->setToolTip(QObject::tr("Trigger\nUsed to introduce temporal interactions."));
this->setCursor(skin.CursorPointingHand);
this->setCacheMode(QGraphicsItem::NoCache);
this->setAcceptHoverEvents(true);
Expand Down

0 comments on commit 611991a

Please sign in to comment.