summaryrefslogtreecommitdiff
path: root/tagitem.h
blob: 908f441dc09dd0748407d09e2a71de768eb2d5ff (plain)
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
#ifndef TAGITEM_H
#define TAGITEM_H

#include "sqlitebackend.h"

#include <QGraphicsPixmapItem>


class TagItem : public QGraphicsSimpleTextItem
{
public:
    TagItem(const Tag &tag);
    TagItem() : valid(false) {};

    enum { Type = UserType + 1 };
    int type() const override { return Type; }
    bool isValid() { return valid; }
    void tagUpdated(const Tag &tag);
    Tag tag() { return m_tag; }


    virtual QRectF boundingRect() const override;
    virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
    virtual QPainterPath shape() const override;

protected:
    QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) override;

    virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
    virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;

private:
    Tag m_tag;
    bool valid;
    QMargins m_margins;
    bool dragAboveThreshold = false;
};

#endif // TAGITEM_H