-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
glasslibrarywidget.cpp
executable file
·151 lines (128 loc) · 3.28 KB
/
glasslibrarywidget.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
149
150
151
#include <QPainter>
#include <QMouseEvent>
#include <QApplication>
#include <QMimeData>
#include <QDrag>
#include "glassmime.h"
#include "glasscolorlibrarywidget.h"
#include "canelibrarywidget.h"
#include "glasslibrarywidget.h"
#include "globalbackgroundcolor.h"
#include "mainwindow.h"
GlassLibraryWidget :: GlassLibraryWidget(MainWindow* _window) : QLabel(_window)
{
this->window = _window;
setDependency(NO_DEPENDENCY);
}
const QPixmap* GlassLibraryWidget :: dragPixmap()
{
return pixmap();
}
bool GlassLibraryWidget :: isDraggable()
{
return false;
}
void GlassLibraryWidget :: updateStyleSheet()
{
QColor color;
QString style;
switch (dependency)
{
case NO_DEPENDENCY:
color = GlobalBackgroundColor::qcolor;
style.append("border: 2px solid " + color.name() + ";");
break;
case IS_DEPENDENCY:
color = QColor(0, 0, 255);
style.append("border: 2px solid " + color.name() + ";");
break;
case USES_DEPENDENCY:
color = QColor(200, 100, 0);
style.append("border: 2px dotted " + color.name() + ";");
break;
case USEDBY_DEPENDENCY:
color = QColor(0, 139, 69);
style.append("border: 2px dashed " + color.name() + ";");
break;
}
setStyleSheet(style);
}
void GlassLibraryWidget :: setDependency(enum Dependency _d)
{
dependency = _d;
updateStyleSheet();
}
int GlassLibraryWidget :: hitValue(QPoint p)
{
if (0 < p.x() && p.x() < 20 && 0 < p.y() && p.y() < 20)
return 1;
else if (80 < p.x() && p.x() < 100 && 0 < p.y() && p.y() < 20)
return -1;
else
return 0;
}
void GlassLibraryWidget :: mousePressEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton)
{
mouseDown = true;
mouseDownPos = event->pos();
}
}
void GlassLibraryWidget :: mouseMoveEvent(QMouseEvent* event)
{
if ((event->pos() - mouseDownPos).manhattanLength() > QApplication::startDragDistance()
|| !this->rect().contains(event->pos()))
{
if (!this->isDraggable())
return;
mouseDown = false;
char buf[500];
QPixmap pixmap;
GlassMime::encode(buf, this, this->mimeType());
QByteArray pointerData(buf);
QMimeData* mimeData = new QMimeData;
mimeData->setText(pointerData);
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setPixmap(*(this->dragPixmap()));
drag->setHotSpot(QPoint(50, 50));
drag->exec(Qt::CopyAction);
}
}
void GlassLibraryWidget :: mouseReleaseEvent(QMouseEvent*)
{
if (mouseDown)
{
int v = hitValue(mouseDownPos);
if (v > 0)
this->window->copyLibraryWidget(this);
else if (v < 0)
this->window->deleteLibraryWidget(this);
else
this->window->setEditorLibraryWidget(this);
}
mouseDown = false;
}
void GlassLibraryWidget :: paintEvent(QPaintEvent* event)
{
QLabel::paintEvent(event);
QPainter painter;
painter.begin(this);
painter.setPen(QPen(Qt::black));
if (this->dependency == IS_DEPENDENCY)
{
QColor color;
color.setRgb(255, 255, 255);
painter.fillRect(3, 3, 15, 15, color);
painter.drawLine(10, 5, 10, 15);
painter.drawLine(5, 10, 15, 10);
if (!this->window->hasDependancies(this))
{
color.setRgb(255, 255, 255);
painter.fillRect(100-3-15, 3, 15, 15, color);
painter.drawLine(100-6, 10, 100-16, 10);
}
}
painter.end();
}