diff --git a/addons/konsole/kateconsole.cpp b/addons/konsole/kateconsole.cpp index b47058cd4bb0e07260a91c8f27ef18c7f4293f93..530302085471cc1e02304b2ae0bd578fb2474968 100644 --- a/addons/konsole/kateconsole.cpp +++ b/addons/konsole/kateconsole.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -204,6 +205,10 @@ void KateConsole::loadConsoleIfNeeded() return; } + if (auto konsoleTabWidget = qobject_cast(m_part->widget())) { + konsoleTabWidget->setTabBarAutoHide(true); + konsoleTabWidget->installEventFilter(this); + } layout()->addWidget(m_part->widget()); // start the terminal @@ -212,7 +217,6 @@ void KateConsole::loadConsoleIfNeeded() // KGlobal::locale()->insertCatalog("konsole"); // FIXME KF5: insert catalog setFocusProxy(m_part->widget()); - m_part->widget()->show(); connect(m_part, &KParts::ReadOnlyPart::destroyed, this, &KateConsole::slotDestroyed); // clang-format off @@ -221,6 +225,29 @@ void KateConsole::loadConsoleIfNeeded() slotSync(); } +static bool isCtrlShiftT(QKeyEvent *ke) +{ + return ke->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier) && ke->key() == Qt::Key_T; +} + +bool KateConsole::eventFilter(QObject *w, QEvent *e) +{ + if (!m_part) { + return QWidget::eventFilter(w, e); + } + + if (e->type() == QEvent::KeyPress || e->type() == QEvent::ShortcutOverride) { + QKeyEvent *keyEvent = static_cast(e); + if (isCtrlShiftT(keyEvent)) { + e->accept(); + QMetaObject::invokeMethod(m_part, "newTab"); + return true; + } + } + + return QWidget::eventFilter(w, e); +} + void KateConsole::slotDestroyed() { m_part = nullptr; diff --git a/addons/konsole/kateconsole.h b/addons/konsole/kateconsole.h index 9292a20edd8e053b6b3a5ce4c1550069cc075d29..ceb011bfbd055783a30c8a048faf1a50da9e83ef 100644 --- a/addons/konsole/kateconsole.h +++ b/addons/konsole/kateconsole.h @@ -122,6 +122,8 @@ public: return m_mw; } + bool eventFilter(QObject *w, QEvent *e) override; + public Q_SLOTS: /** * pipe current document to console diff --git a/addons/project/kateprojectinfoviewterminal.cpp b/addons/project/kateprojectinfoviewterminal.cpp index 9ecdfe31636d5449f40387926b396f255f66c3ec..404373981dbbf1a0856140303cea347d83d997ed 100644 --- a/addons/project/kateprojectinfoviewterminal.cpp +++ b/addons/project/kateprojectinfoviewterminal.cpp @@ -15,6 +15,8 @@ #include #include +#include + KPluginFactory *KateProjectInfoViewTerminal::s_pluginFactory = nullptr; KateProjectInfoViewTerminal::KateProjectInfoViewTerminal(KateProjectPluginView *pluginView, const QString &directory) @@ -92,7 +94,12 @@ void KateProjectInfoViewTerminal::loadTerminal() /** * add to widget */ + if (auto konsoleTabWidget = qobject_cast(m_konsolePart->widget())) { + konsoleTabWidget->setTabBarAutoHide(true); + konsoleTabWidget->installEventFilter(this); + } m_layout->addWidget(m_konsolePart->widget()); + setFocusProxy(m_konsolePart->widget()); /** @@ -147,3 +154,25 @@ void KateProjectInfoViewTerminal::respawn(const QString &directory) loadTerminal(); } +static bool isCtrlShiftT(QKeyEvent *ke) +{ + return ke->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier) && ke->key() == Qt::Key_T; +} + +bool KateProjectInfoViewTerminal::eventFilter(QObject *w, QEvent *e) +{ + if (!m_konsolePart) { + return QWidget::eventFilter(w, e); + } + + if (e->type() == QEvent::KeyPress || e->type() == QEvent::ShortcutOverride) { + QKeyEvent *keyEvent = static_cast(e); + if (isCtrlShiftT(keyEvent)) { + e->accept(); + QMetaObject::invokeMethod(m_konsolePart, "newTab"); + return true; + } + } + + return QWidget::eventFilter(w, e); +} diff --git a/addons/project/kateprojectinfoviewterminal.h b/addons/project/kateprojectinfoviewterminal.h index c05379eac28cab2f1bac7fbed9507dc44b26bf07..1d65e6d7b08dc226a1d188975a96b62a4eb27768 100644 --- a/addons/project/kateprojectinfoviewterminal.h +++ b/addons/project/kateprojectinfoviewterminal.h @@ -52,6 +52,8 @@ public: void respawn(const QString &dirPath); + bool eventFilter(QObject *o, QEvent *e) override; + private Q_SLOTS: /** * Construct a new terminal for this view