-
Notifications
You must be signed in to change notification settings - Fork 6
/
hovertabbar.cpp
130 lines (108 loc) · 4.11 KB
/
hovertabbar.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
#include "hovertabbar.h"
extern CefHandler* handler;
extern CefBrowserSettings defaultBrowserSettings;
HoverTabBar::HoverTabBar(MainWindow *parent) : QTabBar(parent)
{
this->setMouseTracking(true);
this->setStyleSheet("");
this->setAcceptDrops(true);
this->mainWindow = parent;
}
void HoverTabBar::mouseMoveEvent(QMouseEvent *event) {
if (settings.value("behaviour/tabPreview", false).toBool()) {
int tabAtIndex = tabAt(event->pos());
if (currentHoverTab != tabAtIndex) {
if (tabAtIndex != this->currentIndex() && tabAtIndex != -1) {
emit previewTab(tabAtIndex);
} else if (tabAtIndex == this->currentIndex()) {
emit this->cancelPreview();
}
currentHoverTab = tabAtIndex;
}
}
event->accept();
}
void HoverTabBar::leaveEvent(QEvent *event) {
//Don't check the setting here (just in case)
emit this->cancelPreview();
currentHoverTab = -1;
}
void HoverTabBar::setStyleSheet(QString styleSheet) {
//Check if this is a refresh or not
if (styleSheet != "") {
//We need to set the new stylesheet
currentStyleSheet = styleSheet;
}
QString newStyleSheet = "QTabBar::scroller {width: 0px;}";
QTabBar::setStyleSheet(newStyleSheet + currentStyleSheet);
}
void HoverTabBar::dragEnterEvent(QDragEnterEvent* event) {
const QMimeData* data = event->mimeData();
if (data->hasUrls()) {
event->setDropAction(Qt::CopyAction);
event->accept();
}
}
void HoverTabBar::dragMoveEvent(QDragMoveEvent* event) {
int tabAtIndex = tabAt(event->pos());
}
void HoverTabBar::dragLeaveEvent(QDragLeaveEvent* event) {
}
void HoverTabBar::dropEvent(QDropEvent* event) {
const QMimeData* data = event->mimeData();
int tabAtIndex = tabAt(event->pos());
if (data->hasUrls() && data->urls().count() > 0) {
//Direction:
//0: None
//1: Left
//2: Right
int direction = 0;
//Go 5 pixels in both directions so we can see where to open this new tab
int x = event->pos().x();
while (x - 5 != event->pos().x()) {
x++;
if (tabAt(QPoint(x, event->pos().y())) != tabAtIndex) {
direction = 2;
break;
}
}
if (direction == 0) {
x = event->pos().x();
while (x + 5 != event->pos().x()) {
x--;
if (tabAt(QPoint(x, event->pos().y())) != tabAtIndex) {
direction = 1;
break;
}
}
}
QString url = data->urls().first().toString();
if (direction == 0) {
//Spawn tab and replace
//mainWindow->navigate(tabAtIndex, url);
//mainWindow->browserList.at(index).get()->GetMainFrame().get()->LoadURL(url.toStdString());
qDebug() << "Spawn Browser and replace tab";
} else {
Browser newBrowser;
if (mainWindow->oblivionWindow()) {
CefBrowserSettings settings = defaultBrowserSettings;
settings.application_cache = STATE_DISABLED;
CefRequestContextSettings contextSettings;
CefRefPtr<CefRequestContext> context = CefRequestContext::CreateContext(contextSettings, new OblivionRequestContextHandler);
context.get()->RegisterSchemeHandlerFactory("theweb", "theweb", new theWebSchemeHandler());
newBrowser = CefBrowserHost::CreateBrowserSync(CefWindowInfo(), handler, url.toStdString(), settings, context);
} else {
newBrowser = CefBrowserHost::CreateBrowserSync(CefWindowInfo(), handler, url.toStdString(), defaultBrowserSettings, CefRefPtr<CefRequestContext>());
}
if (direction == 1) {
//Spawn tab on left
mainWindow->createNewTab(newBrowser);
qDebug() << "Load on left";
} else {
//Spawn tab on right
mainWindow->createNewTab(newBrowser);
qDebug() << "Load on right";
}
}
}
}