
Originally Posted by
dvmorris
is there an example in the svn checkout that uses the shortcut manager? like a hello world kind of example or something?
Well I'm afraid I did not make any example... However it is really simple to use and here is a sample code :
#include "qshortcutmanager.h"
#include <QMenu>
#include <QAction>
#include <QMenuBar>
#include <QMainWindow>
#include <QMessageBox>
#include <QApplication>
int main(int argc, char **argv)
{
QShortcutManager sm;
ms.setText( "This is a stub message box. The\n"
"only nice thing about it is that\n"
"it is triggered via a configurable\n"
"shortcut\n\n"
"So long buddy!");
QMenu help
("&Help",
&main
);
ms.connect( a , SIGNAL( triggered() ),
SLOT ( exec() ) );
sm.registerAction(a, "Help", "CTRL+M");
help.addAction(a);
QMenu settings
("&Settings",
&main
);
sm.connect( b , SIGNAL( triggered() ),
SLOT ( configure() ) );
sm.registerAction(b, "Settings", "CTRL+S");
settings.addAction(b);
main.menuBar()->addMenu(&settings);
main.menuBar()->addMenu(&help);
main.show();
return app.exec();
}
#include "qshortcutmanager.h"
#include <QMenu>
#include <QAction>
#include <QMenuBar>
#include <QMainWindow>
#include <QMessageBox>
#include <QApplication>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QMainWindow main;
QShortcutManager sm;
QMessageBox ms(&main);
ms.setText( "This is a stub message box. The\n"
"only nice thing about it is that\n"
"it is triggered via a configurable\n"
"shortcut\n\n"
"So long buddy!");
QMenu help("&Help", &main);
QAction *a = new QAction("Show message box", &main);
ms.connect( a , SIGNAL( triggered() ),
SLOT ( exec() ) );
sm.registerAction(a, "Help", "CTRL+M");
help.addAction(a);
QMenu settings("&Settings", &main);
QAction *b = new QAction("Configure &shortcuts", &main);
sm.connect( b , SIGNAL( triggered() ),
SLOT ( configure() ) );
sm.registerAction(b, "Settings", "CTRL+S");
settings.addAction(b);
main.menuBar()->addMenu(&settings);
main.menuBar()->addMenu(&help);
main.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Of course to compile this you need to link against Edyuk core library or to pack the need components in your project (no path relocation in the example below : it is assumed that you copied the files in your project folder...) :
QT *= xml
HEADERS += qshortcutmanager.h qshortcutdialog.h
SOURCES += qshortcutmanager.cpp qshortcutdialog.cpp
FORMS += shortcutdialog.ui
QT *= xml
HEADERS += qshortcutmanager.h qshortcutdialog.h
SOURCES += qshortcutmanager.cpp qshortcutdialog.cpp
FORMS += shortcutdialog.ui
To copy to clipboard, switch view to plain text mode
Hope this helps.
P.S : I just checked Edyuk sources and the settings storage path is incorrectly set. If you wish to use QShortcutManager within one of your application you should change some code in qshortcutmanager.cpp Replace the content of the QShortcutManager::file(const QString& lang) function with the code below :
QString QShortcutManager
::file(const QString
& lang
) {
+ "."
+ "shortcuts_"
+ lang
+ ".xml";
}
QString QShortcutManager::file(const QString& lang)
{
return QDir::homePath()
+ QDir::separator()
+ "."
+ QApplication::applicationName()
+ QDir::separator()
+ "shortcuts_"
+ lang
+ ".xml";
}
To copy to clipboard, switch view to plain text mode
Bookmarks