forked from nitramr/indigoDock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
indigodropzone.cpp
196 lines (128 loc) · 4.32 KB
/
indigodropzone.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include "indigodropzone.h"
/* TODO:
*
* - add better splitter widget (redocking within a dropzone
*
*/
IndigoDropZone::IndigoDropZone(QWidget *parent) :
QWidget(parent)
{
setMouseTracking(true);
setAutoFillBackground( true );
colorNormal = QColor( 153, 153, 153 );
colorHighlight = QColor( 0, 179, 255 );
transparency = 0.1; // 10%
colorHighlightAlpha = blendColor(colorNormal,colorHighlight, transparency);
palette.setColor( QPalette::Background, colorNormal );
setPalette( palette );
padding = 6;
borderHighlight = 3;
isHighlight = false;
m_splitter = new QSplitter();
m_splitter->setHandleWidth(padding);
m_splitter->setOrientation(Qt::Vertical);
m_splitter->setStretchFactor(1, 1);
m_splitter->move(this->pos());
m_layout = new QVBoxLayout;
m_layout->setMargin(padding);
setLayout(m_layout);
m_placeholder = new QWidget(this);
}
void IndigoDropZone::hoverZone(){
QPoint cursor = this->mapFromGlobal(QCursor::pos());
if (this->rect().contains(cursor) ) {
// TODO: Add Global Tabwidget list; use for each loop to search in every tabbwidget for active docks;
if(IndigoTabbar *tab = qobject_cast<IndigoTabbar*>(parent()->parent())) {
if(IndigoDropZone *zone = qobject_cast<IndigoDropZone*>(tab->m_activeWidget)){
zone->isHighlight = true;
zone->addPlaceholder();
zone->update();
}
}
}else{
if(IndigoTabbar *tab = qobject_cast<IndigoTabbar*>(parent()->parent())) {
if(IndigoDropZone *zone = qobject_cast<IndigoDropZone*>(tab->m_activeWidget)){
zone->isHighlight = false;
zone->removePlaceholder();
zone->update();
}
}
}
}
void IndigoDropZone::dropPanel()
{
QPoint cursor = this->mapFromGlobal(QCursor::pos());
if (this->rect().contains(cursor) ) {
if(IndigoTabbar *tab = qobject_cast<IndigoTabbar*>(parent()->parent())) {
IndigoDropZone *zone = qobject_cast<IndigoDropZone*>(tab->m_activeWidget);
if (!zone) return;
IndigoPanel *pan = qobject_cast<IndigoPanel *>(sender());
if (!pan) return;
pan->setParent(zone);
pan->setLastParent(zone);
zone->isHighlight = false;
zone->removePlaceholder();
zone->addPanel(pan);
zone->update(); // defocus
}else{
qDebug() << "DropZone parent is not type of IndigoTabbar" << endl;
}
}
}
/**
* Add Panel in Splitter
* @brief Indigo2DropZone::addPanel
* @param panel
*/
void IndigoDropZone::addPanel (IndigoPanel * panel){
m_splitter->addWidget(panel);
m_layout->addWidget(m_splitter);
m_splitter->show();
panel->show();
}
void IndigoDropZone::addPlaceholder (){
m_splitter->addWidget(m_placeholder);
m_layout->addWidget(m_splitter);
m_splitter->show();
}
void IndigoDropZone::removePlaceholder (){
m_placeholder->setParent(this);
}
void IndigoDropZone::setBackgroundColor(const QColor bgColor){
colorNormal = bgColor;
colorHighlightAlpha = blendColor(colorNormal,colorHighlight, transparency);
}
void IndigoDropZone::paintEvent(QPaintEvent*) {
QPainter painter(this);
// Draw highlight
if(isHighlight){
QPoint pRect = m_placeholder->mapToParent(QPoint(padding,padding));
int width = m_placeholder->width();
int height = m_placeholder->height();
int x = pRect.x();
int y = pRect.y();
int offset = borderHighlight;
painter.fillRect(x, y, width, height, colorHighlight);
painter.fillRect(x + offset, y + offset, width -(offset*2), height -(offset*2),colorHighlightAlpha);
// Reset highlight (normal view)
}else{
int width = size().width();
int height = size().height();
painter.fillRect(0, 0, width, height, colorNormal);
}
}
/***********************+
*
* Helper
*
* *********************/
QColor IndigoDropZone::blendColor(QColor color1, QColor color2, double ratio){
if(ratio < 0 && ratio > 1){
ratio = 0;
}
return QColor(
color1.red()* (1-ratio) + color2.red()*ratio,
color1.green()* (1-ratio) + color2.green()*ratio,
color1.blue()* (1-ratio) + color2.blue()*ratio,
255);
}