Changeset View
Changeset View
Standalone View
Standalone View
src/MainWindow.cpp
Show All 16 Lines | 1 | /* | |||
---|---|---|---|---|---|
17 | 02110-1301 USA. | 17 | 02110-1301 USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | // Own | 20 | // Own | ||
21 | #include "MainWindow.h" | 21 | #include "MainWindow.h" | ||
22 | 22 | | |||
23 | // Qt | 23 | // Qt | ||
24 | #include <QVBoxLayout> | 24 | #include <QVBoxLayout> | ||
25 | #include <QMouseEvent> | ||||
25 | 26 | | |||
26 | // KDE | 27 | // KDE | ||
27 | #include <KAcceleratorManager> | 28 | #include <KAcceleratorManager> | ||
28 | #include <KActionCollection> | 29 | #include <KActionCollection> | ||
29 | #include <KActionMenu> | 30 | #include <KActionMenu> | ||
30 | #include <KShortcutsDialog> | 31 | #include <KShortcutsDialog> | ||
31 | #include <KLocalizedString> | 32 | #include <KLocalizedString> | ||
32 | #include <KToggleAction> | 33 | #include <KToggleAction> | ||
Show All 16 Lines | |||||
49 | #include "SessionController.h" | 50 | #include "SessionController.h" | ||
50 | #include "ProfileList.h" | 51 | #include "ProfileList.h" | ||
51 | #include "Session.h" | 52 | #include "Session.h" | ||
52 | #include "ViewManager.h" | 53 | #include "ViewManager.h" | ||
53 | #include "SessionManager.h" | 54 | #include "SessionManager.h" | ||
54 | #include "ProfileManager.h" | 55 | #include "ProfileManager.h" | ||
55 | #include "KonsoleSettings.h" | 56 | #include "KonsoleSettings.h" | ||
56 | #include "WindowSystemInfo.h" | 57 | #include "WindowSystemInfo.h" | ||
58 | #include "TerminalDisplay.h" | ||||
57 | #include "settings/FileLocationSettings.h" | 59 | #include "settings/FileLocationSettings.h" | ||
58 | #include "settings/GeneralSettings.h" | 60 | #include "settings/GeneralSettings.h" | ||
59 | #include "settings/ProfileSettings.h" | 61 | #include "settings/ProfileSettings.h" | ||
60 | #include "settings/TabBarSettings.h" | 62 | #include "settings/TabBarSettings.h" | ||
61 | 63 | | |||
62 | using namespace Konsole; | 64 | using namespace Konsole; | ||
63 | 65 | | |||
64 | MainWindow::MainWindow() : | 66 | MainWindow::MainWindow() : | ||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Line(s) | |||||
214 | { | 216 | { | ||
215 | disconnect(controller, &Konsole::SessionController::titleChanged, | 217 | disconnect(controller, &Konsole::SessionController::titleChanged, | ||
216 | this, &Konsole::MainWindow::activeViewTitleChanged); | 218 | this, &Konsole::MainWindow::activeViewTitleChanged); | ||
217 | disconnect(controller, &Konsole::SessionController::rawTitleChanged, | 219 | disconnect(controller, &Konsole::SessionController::rawTitleChanged, | ||
218 | this, &Konsole::MainWindow::updateWindowCaption); | 220 | this, &Konsole::MainWindow::updateWindowCaption); | ||
219 | disconnect(controller, &Konsole::SessionController::iconChanged, | 221 | disconnect(controller, &Konsole::SessionController::iconChanged, | ||
220 | this, &Konsole::MainWindow::updateWindowIcon); | 222 | this, &Konsole::MainWindow::updateWindowIcon); | ||
221 | 223 | | |||
224 | if (auto view = controller->view()) { | ||||
225 | view->removeEventFilter(this); | ||||
226 | } | ||||
227 | | ||||
222 | // KXmlGuiFactory::removeClient() will try to access actions associated | 228 | // KXmlGuiFactory::removeClient() will try to access actions associated | ||
223 | // with the controller internally, which may not be valid after the controller | 229 | // with the controller internally, which may not be valid after the controller | ||
224 | // itself is no longer valid (after the associated session and or view have | 230 | // itself is no longer valid (after the associated session and or view have | ||
225 | // been destroyed) | 231 | // been destroyed) | ||
226 | if (controller->isValid()) { | 232 | if (controller->isValid()) { | ||
227 | guiFactory()->removeClient(controller); | 233 | guiFactory()->removeClient(controller); | ||
228 | } | 234 | } | ||
229 | } | 235 | } | ||
230 | 236 | | |||
231 | void MainWindow::activeViewChanged(SessionController *controller) | 237 | void MainWindow::activeViewChanged(SessionController *controller) | ||
232 | { | 238 | { | ||
233 | // associate bookmark menu with current session | 239 | // associate bookmark menu with current session | ||
234 | bookmarkHandler()->setActiveView(controller); | 240 | bookmarkHandler()->setActiveView(controller); | ||
235 | disconnect(bookmarkHandler(), &Konsole::BookmarkHandler::openUrl, nullptr, nullptr); | 241 | disconnect(bookmarkHandler(), &Konsole::BookmarkHandler::openUrl, nullptr, nullptr); | ||
236 | connect(bookmarkHandler(), &Konsole::BookmarkHandler::openUrl, controller, | 242 | connect(bookmarkHandler(), &Konsole::BookmarkHandler::openUrl, controller, | ||
237 | &Konsole::SessionController::openUrl); | 243 | &Konsole::SessionController::openUrl); | ||
238 | 244 | | |||
239 | if (!_pluggedController.isNull()) { | 245 | if (!_pluggedController.isNull()) { | ||
240 | disconnectController(_pluggedController); | 246 | disconnectController(_pluggedController); | ||
241 | } | 247 | } | ||
242 | 248 | | |||
243 | Q_ASSERT(controller); | 249 | Q_ASSERT(controller); | ||
244 | _pluggedController = controller; | 250 | _pluggedController = controller; | ||
251 | _pluggedController->view()->installEventFilter(this); | ||||
245 | 252 | | |||
246 | setBlur(ViewManager::profileHasBlurEnabled(SessionManager::instance()->sessionProfile(_pluggedController->session()))); | 253 | setBlur(ViewManager::profileHasBlurEnabled(SessionManager::instance()->sessionProfile(_pluggedController->session()))); | ||
247 | 254 | | |||
248 | // listen for title changes from the current session | 255 | // listen for title changes from the current session | ||
249 | connect(controller, &Konsole::SessionController::titleChanged, this, | 256 | connect(controller, &Konsole::SessionController::titleChanged, this, | ||
250 | &Konsole::MainWindow::activeViewTitleChanged); | 257 | &Konsole::MainWindow::activeViewTitleChanged); | ||
251 | connect(controller, &Konsole::SessionController::rawTitleChanged, this, | 258 | connect(controller, &Konsole::SessionController::rawTitleChanged, this, | ||
252 | &Konsole::MainWindow::updateWindowCaption); | 259 | &Konsole::MainWindow::updateWindowCaption); | ||
▲ Show 20 Lines • Show All 571 Lines • ▼ Show 20 Line(s) | 830 | if (!KonsoleSettings::saveGeometryOnExit()) { | |||
824 | resize(sizeHint()); | 831 | resize(sizeHint()); | ||
825 | } | 832 | } | ||
826 | } | 833 | } | ||
827 | 834 | | |||
828 | // Call parent method | 835 | // Call parent method | ||
829 | KXmlGuiWindow::showEvent(event); | 836 | KXmlGuiWindow::showEvent(event); | ||
830 | } | 837 | } | ||
831 | 838 | | |||
839 | void MainWindow::triggerAction(const QString &name) const | ||||
840 | { | ||||
841 | if (auto action = actionCollection()->action(name)) { | ||||
842 | if (action->isEnabled()) { | ||||
843 | action->trigger(); | ||||
844 | } | ||||
845 | } | ||||
846 | } | ||||
847 | | ||||
848 | bool MainWindow::eventFilter(QObject *obj, QEvent *event) | ||||
849 | { | ||||
850 | if (obj == _pluggedController->view()) { | ||||
851 | switch(event->type()) { | ||||
852 | case QEvent::MouseButtonPress: | ||||
853 | case QEvent::MouseButtonDblClick: | ||||
854 | switch(static_cast<QMouseEvent*>(event)->button()) { | ||||
855 | case Qt::ForwardButton: | ||||
856 | triggerAction(QStringLiteral("next-view")); | ||||
857 | break; | ||||
858 | case Qt::BackButton: | ||||
859 | triggerAction(QStringLiteral("previous-view")); | ||||
860 | break; | ||||
861 | default: ; | ||||
862 | } | ||||
863 | default: ; | ||||
864 | } | ||||
865 | } | ||||
866 | | ||||
867 | return KXmlGuiWindow::eventFilter(obj, event); | ||||
868 | } | ||||
869 | | ||||
832 | bool MainWindow::focusNextPrevChild(bool) | 870 | bool MainWindow::focusNextPrevChild(bool) | ||
833 | { | 871 | { | ||
834 | // In stand-alone konsole, always disable implicit focus switching | 872 | // In stand-alone konsole, always disable implicit focus switching | ||
835 | // through 'Tab' and 'Shift+Tab' | 873 | // through 'Tab' and 'Shift+Tab' | ||
836 | // | 874 | // | ||
837 | // Kpart is another different story | 875 | // Kpart is another different story | ||
838 | return false; | 876 | return false; | ||
839 | } | 877 | } | ||
tcanabrava: return KXmlGuiWindow::eventFilter ? | |||||
extract those to a function so you don't repeat yourself? ? tcanabrava: extract those to a function so you don't repeat yourself?
case Qt::ForwardButton: triggerAction… |
return KXmlGuiWindow::eventFilter ?