-
Notifications
You must be signed in to change notification settings - Fork 1
/
GuiTabWidget.cpp
60 lines (53 loc) · 1.69 KB
/
GuiTabWidget.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
/*
* Copyright (C) 2013 Rajendran Thirupugalsamy
* See LICENSE for full copyright and license information.
* See COPYING for distribution information.
*/
#include <QTabBar>
#include <QMenu>
#include "GuiTabWidget.h"
#include "GuiMainWindow.h"
#include "GuiTerminalWindow.h"
#include "QtConfig.h"
#include "GuiSettingsWindow.h"
#include "GuiMenu.h"
#include "GuiTabBar.h"
GuiTabWidget::GuiTabWidget(GuiMainWindow * parent) :
QTabWidget(parent),
mainWindow(parent),
guiTabBar(new GuiTabBar(this, parent))
{
this->setTabBar(guiTabBar);
this->setContextMenuPolicy(Qt::CustomContextMenu);
guiTabBar->setCursor(Qt::ArrowCursor);
connect(this, SIGNAL(customContextMenuRequested(QPoint)),
SLOT(showContextMenu(QPoint)));
}
GuiTabBar::GuiTabBar(GuiTabWidget *t, GuiMainWindow *main)
: QTabBar(t),
mainWindow(main)
{
setAcceptDrops(true);
}
void GuiTabWidget::showContextMenu(const QPoint &point)
{
// handling only right-click on tabbar
if (point.isNull())
return;
GuiTerminalWindow *termWindow;
int menuTabIndex;
if ( ((menuTabIndex = tabBar()->tabAt(point)) == -1) ||
(!(termWindow = this->mainWindow->getCurrentTerminalInTab(menuTabIndex))))
return;
qutty_menu_id_t id;
if (termWindow && !termWindow->isSockDisconnected) {
id = MENU_RESTART_SESSION;
} else {
id = MENU_DUPLICATE_SESSION;
}
this->mainWindow->menuCookieTermWnd = termWindow;
mainWindow->menuGetActionById(id)->setVisible(false);
this->mainWindow->menuGetMenuById(MENU_TERM_WINDOW)->exec(this->mapToGlobal(point));
mainWindow->menuGetActionById(id)->setVisible(true);
this->mainWindow->menuCookieTermWnd = NULL;
}