-
Notifications
You must be signed in to change notification settings - Fork 0
/
agtagtextitem.cpp
148 lines (113 loc) · 5.23 KB
/
agtagtextitem.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "aglobal.h"
#include "agtagtextitem.h"
#include <QSettings>
#include <QDebug>
#include <QGraphicsSceneMouseEvent>
AGTagTextItem::AGTagTextItem(QGraphicsItem *parent, QFileInfo fileInfo, QString tagName) :
QGraphicsTextItem(parent)
{
// changed = true;
this->mediaType = "Tag";
this->itemType = "Base";
this->fileInfo = fileInfo;
this->tagName = tagName;
clipItem = (AGClipRectItem *) parent;
this->clipItem->tags << this;
setData(itemTypeIndex, itemType);
setData(mediaTypeIndex, mediaType);
// setData(folderNameIndex, fileInfo.absolutePath());
// setData(fileNameIndex, fileInfo.fileName());
// qDebug()<<"AGTagTextItem::AGTagTextItem"<<fileInfo.fileName()<<tagName;
if (tagName == "*" || tagName == "**" || tagName == "***" || tagName == "****" || tagName == "*****")
setDefaultTextColor(Qt::yellow);
else if (QSettings().value("theme") == "Black")
setDefaultTextColor(Qt::white);
else
setDefaultTextColor(Qt::black);
if (AGlobal().audioExtensions.contains(fileInfo.suffix(), Qt::CaseInsensitive))
setHtml(QString("<div align=\"center\">") + tagName + "</div>");//#008000 darkgreen style='background-color: rgba(0, 128, 0, 0.5);'
else
setHtml(QString("<div align=\"center\">") + tagName + "</div>");//blue-ish #2a82da style='background-color: rgba(42, 130, 218, 0.5);'
// setPlainText(tagName);
setFlag(QGraphicsItem::ItemIsMovable, true); //to put in bin
// setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
// this->setFlag(QGraphicsItem::ItemIsSelectable);
// this->setAcceptHoverEvents(true);
// this->setAcceptDrops(true);
fileContextMenu = new QMenu();
// setContextMenuPolicy(Qt::CustomContextMenu);
fileContextMenu->setToolTipsVisible(true);
// fileContextMenu->eventFilter()
QPalette pal = fileContextMenu->palette();
QColor menuColor;
if (QSettings().value("theme") == "Black")
{
menuColor = QColor(41, 42, 45);//80,80,80);
fileContextMenu->setStyleSheet(R"(
QMenu::separator {
background-color: darkgray;
}
QMenu {
border: 1px solid darkgray;
}
)");
}
else
menuColor = pal.window().color();
pal.setColor(QPalette::Base, menuColor);
pal.setColor(QPalette::Window, menuColor);
fileContextMenu->setPalette(pal);
}
void AGTagTextItem::onItemRightClicked(QPoint pos)
{
QGraphicsView *view = scene()->views().first();
fileContextMenu->clear();
fileContextMenu->addAction(new QAction("Zoom to item",fileContextMenu));
connect(fileContextMenu->actions().last(), &QAction::triggered, [=]()
{
view->fitInView(boundingRect()|childrenBoundingRect(), Qt::KeepAspectRatio);
});
fileContextMenu->actions().last()->setToolTip(tr("<p><b>%1</b></p>"
"<p><i>Zooms in to %2 and it's details</i></p>"
).arg(fileContextMenu->actions().last()->text(), fileInfo.fileName()));
fileContextMenu->addAction(new QAction("Delete tag",fileContextMenu));
connect(fileContextMenu->actions().last(), &QAction::triggered, [=]()
{
emit deleteItem(true, "Tag", fileInfo, clipItem->clipIn, tagName);
});
fileContextMenu->actions().last()->setToolTip(tr("<p><b>%1</b></p>"
"<p><i>Remove %2</i></p>"
).arg(fileContextMenu->actions().last()->text(), fileInfo.fileName()));
QPointF map = view->mapToGlobal(QPoint(pos.x()+10, pos.y()));
fileContextMenu->popup(QPoint(map.x(), map.y()));
}
//void AGTagTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
//{
// qDebug()<<"AGTagTextItem::mousePressEvent"<<event;
// if (event->button() == Qt::LeftButton)
// {
// }
// else
// QGraphicsTextItem::mousePressEvent(event);
//}
void AGTagTextItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
// qDebug()<<"AGTagTextItem::hoverMoveEvent"<<event->pos();
if (event->modifiers() == Qt::ShiftModifier)
{
// if (event->pos().y() > rect().height() * 0.7) //only hover on timeline
{
int progress;
if (mediaType == "Tag") //it always is
{
// qDebug()<<"clipItem"<<clipItem->itemToString()<<clipItem->clipIn<<clipItem->clipOut;
progress = clipItem->clipIn + (clipItem->clipOut - clipItem->clipIn) * event->pos().x()/clipItem->rect().width();
}
else
progress = clipItem->mediaItem->duration * event->pos().x()/clipItem->rect().width();
// qDebug()<<"AGTagTextItem::hoverMoveEvent"<<"emit hoverPositionChanged"<<progress<<clipItem->mediaItem->duration<<event->pos().x()/clipItem->rect().width();
emit hoverPositionChanged(clipItem, progress);
}
}
QGraphicsTextItem::hoverMoveEvent(event);
}