From 0b5c18f24a5f6e3d62c398210313f596a00cb3c1 Mon Sep 17 00:00:00 2001 From: nils Date: Sun, 2 Jan 2011 23:56:59 +0000 Subject: added shortcuts Ctrl+Tab and Ctrl+Shift+Tab to switch through the tabs git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@424 34ebc366-c3a9-4b3c-9f84-69acf7962910 --- gpgwin.cpp | 19 +++++++++++++++++-- gpgwin.h | 2 ++ textedit.cpp | 31 +++++++++++++++++++++++++++++-- textedit.h | 2 ++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/gpgwin.cpp b/gpgwin.cpp index 35bd30c..8ba9675 100644 --- a/gpgwin.cpp +++ b/gpgwin.cpp @@ -32,12 +32,12 @@ GpgWin::GpgWin() QString appPath = qApp->applicationDirPath(); iconPath = appPath + "/icons/"; - edit = new TextEdit(); - setCentralWidget(edit); setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea); + edit = new TextEdit(); + setCentralWidget(edit); /* the list of Keys available*/ mKeyList = new KeyList(mCtx, iconPath); @@ -61,7 +61,9 @@ GpgWin::GpgWin() // open filename if provided as first command line parameter QStringList args = qApp->arguments(); + qDebug() << args.size(); if (args.size() > 1) { + if (!args[1].startsWith("-")) { if (QFile::exists(args[1])) edit->loadFile(args[1]); @@ -288,6 +290,19 @@ void GpgWin::createActions() appendSelectedKeysAct = new QAction(tr("Append Selected Key(s) To Text"), this); appendSelectedKeysAct->setToolTip(tr("Append The Selected Keys To Text in Editor")); connect(appendSelectedKeysAct, SIGNAL(triggered()), this, SLOT(appendSelectedKeys())); + + + /** Key-Shortcuts for Tab-Switchung-Action + */ + switchTabUpAct = new QAction(this); + switchTabUpAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Tab)); + connect(switchTabUpAct, SIGNAL(triggered()), edit, SLOT(switchTabUp())); + this->addAction(switchTabUpAct); + + switchTabDownAct = new QAction(this); + switchTabDownAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Shift+ Qt::Key_Tab)); + connect(switchTabDownAct, SIGNAL(triggered()), edit, SLOT(switchTabDown())); + this->addAction(switchTabDownAct); } void GpgWin::createMenus() diff --git a/gpgwin.h b/gpgwin.h index ed09f8e..c44093a 100644 --- a/gpgwin.h +++ b/gpgwin.h @@ -109,6 +109,8 @@ private: QDialog *genkeyDialog; QAction *newTabAct; + QAction *switchTabUpAct; + QAction *switchTabDownAct; QAction *openAct; QAction *saveAct; QAction *saveAsAct; diff --git a/textedit.cpp b/textedit.cpp index 0e666e8..16cbd84 100644 --- a/textedit.cpp +++ b/textedit.cpp @@ -79,7 +79,7 @@ void TextEdit::newTab() EditorPage *page = new EditorPage(); tabWidget->addTab(page, header); tabWidget->setCurrentIndex(tabWidget->count() - 1); - + page->getTextPage()->setFocus(); connect(page->getTextPage(), SIGNAL(modificationChanged(bool)), this, SLOT(showModified())); // setCursorPosition(); } @@ -102,13 +102,13 @@ void TextEdit::open() QApplication::setOverrideCursor(Qt::WaitCursor); page->getTextPage()->setPlainText(in.readAll()); page->setFilePath(fileName); - QTextDocument *document = page->getTextPage()->document(); document->setModified(false); tabWidget->addTab(page, strippedName(fileName)); tabWidget->setCurrentIndex(tabWidget->count() - 1); QApplication::restoreOverrideCursor(); + page->getTextPage()->setFocus(); connect(page->getTextPage(), SIGNAL(modificationChanged(bool)), this, SLOT(showModified())); // setCursorPosition(); //enableAction(true) @@ -426,3 +426,30 @@ void TextEdit::showModified() { else tabWidget->setTabText(index, title.remove(0,2)); } + +void TextEdit::switchTabUp() { + if (tabWidget->count() > 1) + { + if (tabWidget->count() == tabWidget->currentIndex()+1){ + tabWidget->setCurrentIndex(0); + } + else + { + tabWidget->setCurrentIndex(tabWidget->currentIndex()+1); + } + } +} + +void TextEdit::switchTabDown() { + if (tabWidget->count() > 1) + { + if (tabWidget->currentIndex()==1) { + tabWidget->setCurrentIndex(tabWidget->count()-1); + } + else + { + tabWidget->setCurrentIndex(tabWidget->currentIndex()-1); + } + } +} + diff --git a/textedit.h b/textedit.h index 5e61721..5d6c1da 100644 --- a/textedit.h +++ b/textedit.h @@ -54,6 +54,8 @@ public slots: void newTab(); void showModified(); void closeTab(); + void switchTabUp(); + void switchTabDown(); private: QString strippedName(const QString &fullFileName); -- cgit v1.2.3