Changeset View
Changeset View
Standalone View
Standalone View
src/ViewContainer.cpp
Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | 63 | { | |||
---|---|---|---|---|---|
67 | setTabBar(tabBarWidget); | 67 | setTabBar(tabBarWidget); | ||
68 | setDocumentMode(true); | 68 | setDocumentMode(true); | ||
69 | setMovable(true); | 69 | setMovable(true); | ||
70 | connect(tabBarWidget, &DetachableTabBar::moveTabToWindow, this, &TabbedViewContainer::moveTabToWindow); | 70 | connect(tabBarWidget, &DetachableTabBar::moveTabToWindow, this, &TabbedViewContainer::moveTabToWindow); | ||
71 | tabBar()->setContextMenuPolicy(Qt::CustomContextMenu); | 71 | tabBar()->setContextMenuPolicy(Qt::CustomContextMenu); | ||
72 | _newTabButton->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); | 72 | _newTabButton->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); | ||
73 | _newTabButton->setAutoRaise(true); | 73 | _newTabButton->setAutoRaise(true); | ||
74 | connect(_newTabButton, &QToolButton::clicked, this, [this]{ | 74 | connect(_newTabButton, &QToolButton::clicked, this, [this]{ | ||
75 | emit newViewRequest(); | 75 | emit newViewRequest(this); | ||
76 | }); | 76 | }); | ||
77 | 77 | | |||
78 | _closeTabButton->setIcon(QIcon::fromTheme(QStringLiteral("tab-close"))); | 78 | _closeTabButton->setIcon(QIcon::fromTheme(QStringLiteral("tab-close"))); | ||
79 | _closeTabButton->setAutoRaise(true); | 79 | _closeTabButton->setAutoRaise(true); | ||
80 | connect(_closeTabButton, &QToolButton::clicked, this, [this]{ | 80 | connect(_closeTabButton, &QToolButton::clicked, this, [this]{ | ||
81 | closeCurrentTab(); | 81 | closeCurrentTab(); | ||
82 | }); | 82 | }); | ||
83 | 83 | | |||
84 | connect(tabBar(), &QTabBar::tabBarDoubleClicked, this, | 84 | connect(tabBar(), &QTabBar::tabBarDoubleClicked, this, | ||
85 | &Konsole::TabbedViewContainer::tabDoubleClicked); | 85 | &Konsole::TabbedViewContainer::tabDoubleClicked); | ||
86 | connect(tabBar(), &QTabBar::customContextMenuRequested, this, | 86 | connect(tabBar(), &QTabBar::customContextMenuRequested, this, | ||
87 | &Konsole::TabbedViewContainer::openTabContextMenu); | 87 | &Konsole::TabbedViewContainer::openTabContextMenu); | ||
88 | connect(tabBarWidget, &DetachableTabBar::detachTab, this, [this](int idx) { | 88 | connect(tabBarWidget, &DetachableTabBar::detachTab, this, [this](int idx) { | ||
89 | emit detachTab(this, widget(idx)); | 89 | emit detachTab(this, widget(idx)); | ||
90 | }); | 90 | }); | ||
91 | connect(this, &TabbedViewContainer::currentChanged, this, [this](int index) { | 91 | connect(this, &TabbedViewContainer::currentChanged, this, &TabbedViewContainer::currentTabChanged); | ||
92 | if (index != -1) { | | |||
93 | QWidget *view = widget(index); | | |||
94 | view->setFocus(); | | |||
95 | updateTabHistory(view); | | |||
96 | } else { | | |||
97 | deleteLater(); | | |||
98 | } | | |||
99 | }); | | |||
100 | 92 | | |||
101 | // The context menu of tab bar | 93 | // The context menu of tab bar | ||
102 | _contextPopupMenu = new QMenu(tabBar()); | 94 | _contextPopupMenu = new QMenu(tabBar()); | ||
103 | connect(_contextPopupMenu, &QMenu::aboutToHide, this, [this]() { | 95 | connect(_contextPopupMenu, &QMenu::aboutToHide, this, [this]() { | ||
104 | // Remove the read-only action when the popup closes | 96 | // Remove the read-only action when the popup closes | ||
105 | for (auto &action : _contextPopupMenu->actions()) { | 97 | for (auto &action : _contextPopupMenu->actions()) { | ||
106 | if (action->objectName() == QStringLiteral("view-readonly")) { | 98 | if (action->objectName() == QStringLiteral("view-readonly")) { | ||
107 | _contextPopupMenu->removeAction(action); | 99 | _contextPopupMenu->removeAction(action); | ||
Show All 24 Lines | 121 | auto closeAction = _contextPopupMenu->addAction( | |||
132 | [this] { closeTerminalTab(_contextMenuTabIndex); } | 124 | [this] { closeTerminalTab(_contextMenuTabIndex); } | ||
133 | ); | 125 | ); | ||
134 | closeAction->setObjectName(QStringLiteral("tab-close")); | 126 | closeAction->setObjectName(QStringLiteral("tab-close")); | ||
135 | 127 | | |||
136 | auto profileMenu = new QMenu(); | 128 | auto profileMenu = new QMenu(); | ||
137 | auto profileList = new ProfileList(false, profileMenu); | 129 | auto profileList = new ProfileList(false, profileMenu); | ||
138 | profileList->syncWidgetActions(profileMenu, true); | 130 | profileList->syncWidgetActions(profileMenu, true); | ||
139 | connect(profileList, &Konsole::ProfileList::profileSelected, this, | 131 | connect(profileList, &Konsole::ProfileList::profileSelected, this, | ||
140 | static_cast<void (TabbedViewContainer::*)(Profile::Ptr)>(&Konsole::TabbedViewContainer::newViewRequest)); | 132 | [this](Profile::Ptr profile) { newViewWithProfileRequest(this, profile); }); | ||
141 | _newTabButton->setMenu(profileMenu); | 133 | _newTabButton->setMenu(profileMenu); | ||
142 | 134 | | |||
143 | konsoleConfigChanged(); | 135 | konsoleConfigChanged(); | ||
144 | connect(KonsoleSettings::self(), &KonsoleSettings::configChanged, this, &TabbedViewContainer::konsoleConfigChanged); | 136 | connect(KonsoleSettings::self(), &KonsoleSettings::configChanged, this, &TabbedViewContainer::konsoleConfigChanged); | ||
145 | } | 137 | } | ||
146 | 138 | | |||
147 | TabbedViewContainer::~TabbedViewContainer() | 139 | TabbedViewContainer::~TabbedViewContainer() | ||
148 | { | 140 | { | ||
149 | for(int i = 0, end = count(); i < end; i++) { | 141 | for(int i = 0, end = count(); i < end; i++) { | ||
150 | auto view = widget(i); | 142 | auto view = widget(i); | ||
151 | disconnect(view, &QWidget::destroyed, this, &Konsole::TabbedViewContainer::viewDestroyed); | 143 | disconnect(view, &QWidget::destroyed, this, &Konsole::TabbedViewContainer::viewDestroyed); | ||
152 | } | 144 | } | ||
153 | } | 145 | } | ||
154 | 146 | | |||
155 | void TabbedViewContainer::moveTabToWindow(int index, QWidget *window) | 147 | void TabbedViewContainer::moveTabToWindow(int index, QWidget *window) | ||
156 | { | 148 | { | ||
157 | const int id = viewProperties(widget(index))->identifier(); | 149 | const int id = viewProperties(widget(index))->identifier(); | ||
158 | // This one line here will be removed as soon as I finish my new split handling. | 150 | // This one line here will be removed as soon as I finish my new split handling. | ||
159 | // it's hacky but it works. | 151 | // it's hacky but it works. | ||
160 | const auto widgets = window->findChildren<TabbedViewContainer*>(); | 152 | const auto widgets = window->findChildren<TabbedViewContainer*>(); | ||
161 | const auto currentPos = QCursor::pos(); | 153 | const auto currentPos = QCursor::pos(); | ||
162 | for(const auto dropWidget : widgets) { | 154 | for(const auto dropWidget : widgets) { | ||
163 | if (dropWidget->rect().contains(dropWidget->mapFromGlobal(currentPos))) { | 155 | if (dropWidget->rect().contains(dropWidget->mapFromGlobal(currentPos))) { | ||
164 | emit dropWidget->moveViewRequest(-1, id, this); | 156 | emit dropWidget->moveViewRequest(-1, id); | ||
165 | removeView(widget(index)); | 157 | removeView(widget(index)); | ||
166 | } | 158 | } | ||
167 | } | 159 | } | ||
168 | } | 160 | } | ||
169 | 161 | | |||
170 | void TabbedViewContainer::konsoleConfigChanged() | 162 | void TabbedViewContainer::konsoleConfigChanged() | ||
171 | { | 163 | { | ||
172 | // don't show tabs if we are in KParts mode. | 164 | // don't show tabs if we are in KParts mode. | ||
▲ Show 20 Lines • Show All 209 Lines • ▼ Show 20 Line(s) | 371 | { | |||
382 | } | 374 | } | ||
383 | } | 375 | } | ||
384 | 376 | | |||
385 | void TabbedViewContainer::tabDoubleClicked(int index) | 377 | void TabbedViewContainer::tabDoubleClicked(int index) | ||
386 | { | 378 | { | ||
387 | if (index >= 0) { | 379 | if (index >= 0) { | ||
388 | renameTab(index); | 380 | renameTab(index); | ||
389 | } else { | 381 | } else { | ||
390 | emit newViewRequest(); | 382 | emit newViewRequest(this); | ||
391 | } | 383 | } | ||
392 | } | 384 | } | ||
393 | 385 | | |||
394 | void TabbedViewContainer::renameTab(int index) | 386 | void TabbedViewContainer::renameTab(int index) | ||
395 | { | 387 | { | ||
396 | if (index != -1) { | 388 | if (index != -1) { | ||
397 | _navigation[widget(index)]->rename(); | 389 | _navigation[widget(index)]->rename(); | ||
398 | } | 390 | } | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 418 | if (sessionController != nullptr) { | |||
440 | } | 432 | } | ||
441 | } | 433 | } | ||
442 | 434 | | |||
443 | _contextPopupMenu->exec(tabBar()->mapToGlobal(point)); | 435 | _contextPopupMenu->exec(tabBar()->mapToGlobal(point)); | ||
444 | } | 436 | } | ||
445 | 437 | | |||
446 | void TabbedViewContainer::currentTabChanged(int index) | 438 | void TabbedViewContainer::currentTabChanged(int index) | ||
447 | { | 439 | { | ||
448 | setCurrentIndex(index); | 440 | if (index != -1) { | ||
449 | if (widget(index) != nullptr) { | 441 | QWidget *view = widget(index); | ||
450 | emit activeViewChanged(widget(index)); | 442 | view->setFocus(); | ||
451 | } | 443 | updateTabHistory(view); | ||
452 | 444 | emit activeViewChanged(view); | |||
453 | // clear activity indicators | | |||
454 | setTabActivity(index, false); | 445 | setTabActivity(index, false); | ||
446 | } else { | ||||
447 | deleteLater(); | ||||
448 | } | ||||
455 | } | 449 | } | ||
456 | 450 | | |||
457 | void TabbedViewContainer::wheelScrolled(int delta) | 451 | void TabbedViewContainer::wheelScrolled(int delta) | ||
458 | { | 452 | { | ||
459 | if (delta < 0) { | 453 | if (delta < 0) { | ||
460 | activateNextView(); | 454 | activateNextView(); | ||
461 | } else { | 455 | } else { | ||
462 | activatePreviousView(); | 456 | activatePreviousView(); | ||
▲ Show 20 Lines • Show All 75 Lines • Show Last 20 Lines |