From: <si...@us...> - 2006-08-27 14:37:06
|
Revision: 326 Author: sidos Date: 2006-08-27 07:36:56 -0700 (Sun, 27 Aug 2006) ViewCVS: http://svn.sourceforge.net/qterm/?rev=326&view=rev Log Message: ----------- configure shortcuts Modified Paths: -------------- branches/frame/qterm.pro branches/frame/qtermframe.cpp branches/frame/qtermframe.h Modified: branches/frame/qterm.pro =================================================================== --- branches/frame/qterm.pro 2006-08-25 08:23:34 UTC (rev 325) +++ branches/frame/qterm.pro 2006-08-27 14:36:56 UTC (rev 326) @@ -8,18 +8,20 @@ RESOURCES = frame.qrc -FORMS = ui/frame.ui ui/toolbardialog.ui +FORMS = ui/frame.ui ui/toolbardialog.ui ui/shortcutsdialog.ui SOURCES = main.cpp \ qterm.cpp \ qtermframe.cpp \ qtermwindowbase.cpp\ qtermeditor.cpp \ - toolbardialog.cpp + toolbardialog.cpp \ + shortcutsdialog.cpp HEADERS = qterm.h \ qtermframe.h \ qtermwindowbase.h\ qtermeditor.h \ - toolbardialog.h + toolbardialog.h \ + shortcutsdialog.h Modified: branches/frame/qtermframe.cpp =================================================================== --- branches/frame/qtermframe.cpp 2006-08-25 08:23:34 UTC (rev 325) +++ branches/frame/qtermframe.cpp 2006-08-27 14:36:56 UTC (rev 326) @@ -4,29 +4,31 @@ #include "qtermeditor.h" #include "toolbardialog.h" +#include "shortcutsdialog.h" #include <QtGui> QTermFrame :: QTermFrame() { - setWindowTitle( "QTerm "+QString(VERSION) ); + setupUi(this); + + setWindowTitle( QString("QTerm %1").arg(VERSION) ); setWindowIcon(QIcon(":/pic/qterm_32x32.png")); workspace=new QWorkspace(); setCentralWidget(workspace); connect(workspace, SIGNAL(windowActivated(QWidget*)), this, SLOT(winActivated(QWidget*))); - - setupUi(this); - createMenus(); - groupActions(); - + tabBar = new QTabBar(); PagerBar->addWidget(tabBar); connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(tabActivated(int))); + + createMenus(); + groupActions(); - loadSettings(); + loadSettings(); } QTermFrame :: ~QTermFrame() @@ -37,7 +39,6 @@ /******************** ******** EVENTS ***** *********************/ - void QTermFrame :: closeEvent(QCloseEvent *ce) { saveSettings(); @@ -104,10 +105,21 @@ { close(); } + +void QTermFrame :: on_actionConfigure_Shortcuts_triggered() +{ + QList<QAction*> actions = findChildren<QAction*>(QRegExp("action*")); + shortcutsDialog sd(this,actions,listShortcuts); + sd.exec(); + + saveShortcuts(); +} void QTermFrame :: on_actionConfigure_Toolbars_triggered() { toolbarDialog td(this); td.exec(); + + saveToolbars(); } void QTermFrame :: on_actionWhat_s_this_triggered() { @@ -124,6 +136,28 @@ QApplication::aboutQt(); } +void QTermFrame :: windowSwitcher() +{ + QShortcut* shortcut=qobject_cast<QShortcut*>(sender()); + int id=listShortcuts.indexOf(shortcut); + + switch(id) + { + case 10: + workspace->activatePreviousWindow(); + break; + case 11: + workspace->activateNextWindow(); + break; + } + + if(id>=listWindow.count()) + return; + QTermWindowBase * wb = listWindow.at(id); + if(wb!=0) + workspace->setActiveWindow(wb); +} + void QTermFrame :: actionsDispatcher(QAction* action) { QTermWindowBase * wb=qobject_cast<QTermWindowBase*>(workspace->activeWindow()); @@ -246,9 +280,35 @@ menuView->insertMenu(actionStatusbar,menuToolbars); } +void QTermFrame :: loadShortcuts() +{ + QSettings setting("qterm.cfg", QSettings::IniFormat); + setting.beginGroup("Shortcuts"); + QList<QAction*> actions = findChildren<QAction*>(QRegExp("action*")); + foreach(QAction* action, actions) + { + QString shortcut=setting.value(action->objectName()).toString(); + action->setShortcut(QKeySequence(shortcut)); + } + setting.endGroup(); +} + +void QTermFrame :: saveShortcuts() +{ + QSettings setting("qterm.cfg", QSettings::IniFormat); + setting.beginGroup("Shortcuts"); + QList<QAction*> actions = findChildren<QAction*>(QRegExp("action*")); + foreach(QAction* action, actions) + setting.setValue(action->objectName(), action->shortcut()); + foreach(QShortcut* shortcut, listShortcuts) + setting.setValue(shortcut->objectName(), shortcut->key()); + setting.endGroup(); +} + void QTermFrame :: loadSettings() { popToolbars(); + loadShortcuts(); QSettings setting("qterm.cfg", QSettings::IniFormat); setting.beginGroup("MainWindow"); @@ -260,17 +320,18 @@ setWindowState(Qt::WindowState(ws)); if((ws & Qt::WindowMaximized) == 0x0) { - resize(setting.value("Size").toSize()); + QSize sz=setting.value("Size").toSize(); + if(sz.isValid()) + resize(sz); move(setting.value("Position").toPoint()); } - actionStatusbar->setChecked(true); - statusBar()->setVisible(setting.value("StatusBar").toBool()); + bool showStatusbar = setting.value("StatusBar").toBool(); + actionStatusbar->setChecked(showStatusbar); setting.endGroup(); } void QTermFrame :: saveSettings() { - saveToolbars(); QSettings setting("qterm.cfg",QSettings::IniFormat); setting.beginGroup("MainWindow"); setting.setValue("ToolBars", saveState()); @@ -280,7 +341,7 @@ setting.setValue("Size", size()); } setting.setValue("State", uint(windowState())); - setting.setValue("StatusBar", statusBar()->isVisible()); + setting.setValue("StatusBar", actionStatusbar->isChecked()); setting.endGroup(); } @@ -303,8 +364,8 @@ // show only basic actions and add others to actionGroup QList<QAction*> actions = findChildren<QAction*>(QRegExp("action*")); - actionGroup = new QActionGroup(this); - connect(actionGroup, SIGNAL(triggered(QAction*)), + actionsExtra = new QActionGroup(this); + connect(actionsExtra, SIGNAL(triggered(QAction*)), this, SLOT(actionsDispatcher(QAction*))); foreach(QAction* action, actions) @@ -313,6 +374,30 @@ else { action->setVisible(false); - actionGroup->addAction(action); + actionsExtra->addAction(action); } + // create switch_to_window_ actions group + // load shortcuts + QSettings setting("qterm.cfg", QSettings::IniFormat); + setting.beginGroup("Shortcuts"); + for(int i=1;i<=10;i++) + { + QString name=QString("Switch to window %1").arg(i); + QString key = setting.value(name).toString(); + QShortcut* shortcut = new QShortcut(QKeySequence(key), + this,SLOT(windowSwitcher())); + shortcut->setObjectName(name); + listShortcuts << shortcut; + } + QStringList list; + list << "Prev Window" << "Next Window"; + foreach(QString name, list) + { + QString key = setting.value(name).toString(); + QShortcut* shortcut = new QShortcut(QKeySequence(key), + this, SLOT(windowSwitcher())); + shortcut->setObjectName(name); + listShortcuts << shortcut; + } + setting.endGroup(); } Modified: branches/frame/qtermframe.h =================================================================== --- branches/frame/qtermframe.h 2006-08-25 08:23:34 UTC (rev 325) +++ branches/frame/qtermframe.h 2006-08-27 14:36:56 UTC (rev 326) @@ -21,16 +21,19 @@ public slots: protected: - void closeEvent(QCloseEvent *); - + void closeEvent(QCloseEvent *); void newWindow(QTermWindowBase*); void groupActions(); void updateActions(); void createMenus(); + void saveToolbars(); void popToolbars(); + void loadShortcuts(); + void saveShortcuts(); + void loadSettings(); void saveSettings(); @@ -43,7 +46,8 @@ void on_actionStatusbar_toggled(bool); void on_actionConfigure_Toolbars_triggered(); - + void on_actionConfigure_Shortcuts_triggered(); + void on_actionAbout_QTerm_triggered(); void on_actionAbout_Qt_triggered(); void on_actionWhat_s_this_triggered(); @@ -52,9 +56,12 @@ void winActivated(QWidget*); void winClosed(QTermWindowBase*); void actionsDispatcher(QAction*); - + void windowSwitcher(); + private: - QActionGroup* actionGroup; + QList<QShortcut*> listShortcuts; + QActionGroup* actionsExtra; + QMenu* menuToolbars; QWorkspace* workspace; QTabBar* tabBar; QList<QTermWindowBase*> listWindow; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |