/
cell.cpp
49 lines (40 loc) · 1.24 KB
/
cell.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "cell.h"
#include "chunkscene.h"
#include <QPen>
#include <QGraphicsSceneMouseEvent>
#include <QtGui>
Cell::Cell(ChunkScene *scene, int row, int col, int x, int y, int w, int h, const QString ¬e_name, QColor bg)
:QGraphicsRectItem(x,y,w,h), _scene(scene), _row(row), _col(col), _note_name(note_name), _bg(bg)
{
setPen(QPen(QColor(210,210,210)));
setBrush(QBrush(_bg));
setAcceptsHoverEvents(true);
}
void Cell::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
setBrush(QBrush(QColor(200,200,200)));
setToolTip(_note_name);
}
void Cell::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
setBrush(QBrush(_bg));
setToolTip("");
}
void Cell::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if(event->button() & Qt::LeftButton)
{
_scene->startDrag(QPoint(_row,_col));
}
}
void Cell::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
qreal lod = option->levelOfDetailFromTransform(painter->worldTransform());
const QString & n = _scene->noteName(_row);
if(lod >= 1 or (n == "C" or (n == "E" and lod >= 0.6) or (n == "G" and lod >= 0.5)))
{
QGraphicsRectItem::paint(painter,option,widget);
}
}