Mercurial > hg > octave-terminal
changeset 13494:7e203a75d5cc
Switching between tabs is now possible.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Fri, 29 Apr 2011 00:20:00 +0200 |
parents | 4eb90890962c |
children | 11e03a76d8c0 |
files | gui//src/FileEditorMdiSubWindow.cpp gui//src/FileEditorMdiSubWindow.h gui//src/MainWindow.cpp gui//src/MainWindow.h gui//src/NumberedCodeEdit.cpp gui//src/QTerminalWidget.cpp gui//src/QTerminalWidget.h gui//src/TerminalDisplay.cpp |
diffstat | 8 files changed, 94 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/gui//src/FileEditorMdiSubWindow.cpp +++ b/gui//src/FileEditorMdiSubWindow.cpp @@ -35,6 +35,12 @@ m_simpleEditor->load(fileName); } +void FileEditorMdiSubWindow::installEventFilter(QObject *object) { + QMdiSubWindow::installEventFilter(object); + m_numberedTextView->installEventFilter(object); + m_simpleEditor->installEventFilter(object); +} + void FileEditorMdiSubWindow::newFile() { if(m_modified) { int decision
--- a/gui//src/FileEditorMdiSubWindow.h +++ b/gui//src/FileEditorMdiSubWindow.h @@ -31,6 +31,8 @@ FileEditorMdiSubWindow(QWidget *parent = 0); void loadFile(QString fileName); + void installEventFilter(QObject *object); + public slots: void newFile(); void saveFile();
--- a/gui//src/MainWindow.cpp +++ b/gui//src/MainWindow.cpp @@ -31,7 +31,7 @@ m_isRunning(true) { QDesktopServices desktopServices; m_settingsFile = desktopServices.storageLocation(QDesktopServices::HomeLocation) + "/.quint/settings.ini"; - constructWindow(); + construct(); establishOctaveLink(); } @@ -46,11 +46,13 @@ m_openedFiles->addSubWindow(subWindow); subWindow->setWindowTitle(fileName); subWindow->showMaximized(); + subWindow->installEventFilter(m_centralTabWidget); } else { FileEditorMdiSubWindow *subWindow = new FileEditorMdiSubWindow(m_openedFiles); m_openedFiles->addSubWindow(subWindow); subWindow->loadFile(fileName); subWindow->showMaximized(); + subWindow->installEventFilter(m_centralTabWidget); } m_centralTabWidget->setCurrentWidget(m_openedFiles); } @@ -114,10 +116,11 @@ settings.setValue("MainWindow/windowState", saveState()); } -void MainWindow::constructWindow() { +void MainWindow::construct() { setWindowIcon(QIcon("../media/quint_icon_small.png")); QStyle *style = QApplication::style(); + m_centralTabWidget = new TabWidgetWithShortcuts(this); m_octaveTerminal = new OctaveTerminal(this); m_generalPurposeToolbar = new QToolBar(tr("Octave Toolbar"), this); m_variablesDockWidget = new VariablesDockWidget(this); @@ -127,12 +130,18 @@ m_statusBar = new QStatusBar(this); m_browserWidget = new BrowserWidget(this); m_serviceWidget = new BrowserWidget(this); - m_centralTabWidget = new QTabWidget(this); + m_centralTabWidget->addTab(m_octaveTerminal, tr("Command Window")); m_centralTabWidget->addTab(m_openedFiles, tr("File Editor")); m_centralTabWidget->addTab(m_browserWidget, tr("Documentation")); m_centralTabWidget->addTab(m_serviceWidget, tr("Service")); + m_octaveTerminal->installEventFilter(m_centralTabWidget); + m_octaveTerminal->installEventFilterOnDisplay(m_centralTabWidget); + m_openedFiles->installEventFilter(m_centralTabWidget); + m_browserWidget->installEventFilter(m_centralTabWidget); + m_serviceWidget->installEventFilter(m_centralTabWidget); + // TODO: Add meaningfull toolbar items. QAction *commandAction = new QAction(style->standardIcon(QStyle::SP_CommandLink), "", m_generalPurposeToolbar);
--- a/gui//src/MainWindow.h +++ b/gui//src/MainWindow.h @@ -25,6 +25,7 @@ #include <QMdiArea> #include <QStatusBar> #include <QToolBar> +#include <QQueue> #include "OctaveTerminal.h" #include "OctaveLink.h" #include "VariablesDockWidget.h" @@ -79,6 +80,65 @@ class OctaveMainThread; class OctaveCallbackThread; +class TabWidgetWithShortcuts : public QTabWidget { +public: + TabWidgetWithShortcuts(QWidget *parent = 0) + : QTabWidget(parent), + m_showingShortcuts(false) { + setFocusPolicy(Qt::NoFocus); + } + +protected: + bool eventFilter(QObject *object, QEvent *event) { + if(event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); + if(keyEvent->modifiers() == Qt::ControlModifier) { + showShortcuts(); + switch(keyEvent->key()) { + case Qt::Key_1: setCurrentIndex(0); return true; + case Qt::Key_2: setCurrentIndex(1); return true; + case Qt::Key_3: setCurrentIndex(2); return true; + case Qt::Key_4: setCurrentIndex(3); return true; + }; + } + } else if(event->type() == QEvent::KeyRelease) { + QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); + if(keyEvent->modifiers() != Qt::ControlModifier) { + hideShortcuts(); + } + } + return QTabWidget::eventFilter(object, event); + } + +private: + void showShortcuts() { + if(m_showingShortcuts) + return; + + int tabCount = count(); + for(int tabIndex = 0; tabIndex < tabCount; tabIndex++) { + m_backuppedTabTitles.push_back(tabText(tabIndex)); + setTabText(tabIndex, QString("%1 [%2]").arg(tabText(tabIndex)).arg(tabIndex + 1)); + } + + m_showingShortcuts = true; + } + + void hideShortcuts() { + if(!m_showingShortcuts) + return; + int tabCount = count(); + for(int tabIndex = 0; tabIndex < tabCount; tabIndex++) { + setTabText(tabIndex, m_backuppedTabTitles.front()); + m_backuppedTabTitles.pop_front(); + } + m_showingShortcuts = false; + } + + bool m_showingShortcuts; + QQueue<QString> m_backuppedTabTitles; +}; + /** * \class MainWindow * @@ -111,14 +171,14 @@ void writeSettings(); private: - void constructWindow(); + void construct(); void establishOctaveLink(); OctaveTerminal *m_octaveTerminal; VariablesDockWidget *m_variablesDockWidget; HistoryDockWidget *m_historyDockWidget; FilesDockWidget *m_filesDockWidget; QMdiArea *m_openedFiles; - QTabWidget *m_centralTabWidget; + TabWidgetWithShortcuts *m_centralTabWidget; QStatusBar *m_statusBar; QToolBar *m_generalPurposeToolbar; BrowserWidget *m_browserWidget;
--- a/gui//src/NumberedCodeEdit.cpp +++ b/gui//src/NumberedCodeEdit.cpp @@ -213,7 +213,7 @@ setLineWidth( 2 ); view=textEdit; - view->installEventFilter( this ); + view->installEventFilter( this ); connect( view->document(), SIGNAL(contentsChange(int,int,int)), this, SLOT(textChanged(int,int,int)) );
--- a/gui//src/QTerminalWidget.cpp +++ b/gui//src/QTerminalWidget.cpp @@ -75,11 +75,10 @@ if(startnow && m_impl->m_session) { m_impl->m_session->run(); } - - this->setFocus(Qt::OtherFocusReason); + + setFocus(Qt::OtherFocusReason); m_impl->m_terminalDisplay->resize(this->size()); - - this->setFocusProxy(m_impl->m_terminalDisplay); + setFocusProxy(m_impl->m_terminalDisplay); } void QTerminalWidget::startShellProgram() @@ -174,6 +173,10 @@ m_impl->m_session->sendText(text); } +void QTerminalWidget::installEventFilterOnDisplay(QObject *object) { + m_impl->m_terminalDisplay->installEventFilter(object); +} + void QTerminalWidget::resizeEvent(QResizeEvent*) { m_impl->m_terminalDisplay->resize(this->size());
--- a/gui//src/QTerminalWidget.h +++ b/gui//src/QTerminalWidget.h @@ -70,6 +70,9 @@ /** Send some text to the terminal. */ void sendText(const QString &text); + + /** Installs an event filter onto the display. */ + void installEventFilterOnDisplay(QObject *object); signals: /** Emitted, when the current program has finished. */