Commit 1c048b8e authored by Matthias Möller's avatar Matthias Möller
Browse files

install event filter for menu widgets

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@13968 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 9aa913db
...@@ -327,8 +327,12 @@ public: ...@@ -327,8 +327,12 @@ public:
// Filter alt key events under windows // Filter alt key events under windows
//bool eventFilter(QObject *obj, QEvent *ev); //bool eventFilter(QObject *obj, QEvent *ev);
private:
//event handling
bool event( QEvent *event ); bool event( QEvent *event );
bool eventFilter(QObject *_obj, QEvent *_event);
signals : signals :
/** When this Signal is emitted when a Keyevent Event occures /** When this Signal is emitted when a Keyevent Event occures
...@@ -602,7 +606,6 @@ public: ...@@ -602,7 +606,6 @@ public:
/// Move a specific toolbox widget to the bottom of the side area /// Move a specific toolbox widget to the bottom of the side area
void moveToolBoxToBottom(QString _name); void moveToolBoxToBottom(QString _name);
/** @} */ /** @} */
......
...@@ -79,50 +79,51 @@ void CoreWidget::slotAddMenubarAction( QAction* _action , QString _name ) { ...@@ -79,50 +79,51 @@ void CoreWidget::slotAddMenubarAction( QAction* _action , QString _name ) {
void CoreWidget::slotGetMenubarMenu (QString _name, QMenu *& _menu, bool _create) void CoreWidget::slotGetMenubarMenu (QString _name, QMenu *& _menu, bool _create)
{ {
//if menu already exists, return it
if (menus_.contains (_name)) if (menus_.contains (_name))
_menu = menus_[_name]; _menu = menus_[_name];
//otherwise create a new one
else if (_create) else if (_create)
{ {
_menu = new QMenu(_name); _menu = new QMenu(_name);
menus_[_name] = _menu; menus_[_name] = _menu;
//we have to install an event filter to get event information (e.g. what this)
_menu->installEventFilter(this);
//guarantee that helpMenu_ is always at the end of all menus
menuBar()->insertAction(helpMenu_->menuAction() ,_menu->menuAction ()); menuBar()->insertAction(helpMenu_->menuAction() ,_menu->menuAction ());
} else }
//otherwise no menu was found
else
_menu = NULL; _menu = NULL;
} }
//============================================================================= //=============================================================================
/*
bool CoreWidget::eventFilter(QObject *obj, QEvent *event)
{
if (obj == menuBar() ) {
emit log(LOGERR,"Alt filter menubar " + QString::number(int(event->type())));
if (event->type() == QEvent::ShortcutOverride) {
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
if ( (keyEvent->key() == Qt::Key_Alt ||
keyEvent->key() == Qt::Key_Meta ) &&
keyEvent->modifiers() == Qt::AltModifier )
emit log(LOGERR,"Alt key press");
return obj->eventFilter(obj, event);
} else {
return obj->eventFilter(obj, event);
}
} else {
// pass the event on to the parent class
return QMainWindow::eventFilter(obj, event);
}
}*/
void CoreWidget::setupMenuBar() bool CoreWidget::eventFilter(QObject *_obj, QEvent *_event)
{ {
//WhatsThisClicked event for hyperlinks in 'whats this' boxes
if( _event->type() == QEvent::WhatsThisClicked )
{
QWhatsThisClickedEvent *wtcEvent = static_cast<QWhatsThisClickedEvent*>(_event);
QWhatsThis::hideText();
this->showHelpBrowser(wtcEvent->href());
return true;
}
return _obj->event(_event);
}
// menuBar()->installEventFilter(this); //=============================================================================
void CoreWidget::setupMenuBar()
{
// ====================================================================== // ======================================================================
// File Menu // File Menu
// ====================================================================== // ======================================================================
fileMenu_ = new QMenu( FILEMENU ); fileMenu_ = new QMenu( FILEMENU );
menuBar()->addMenu(fileMenu_ ); menuBar()->addMenu( fileMenu_ );
menus_[tr("File")] = fileMenu_; menus_[tr("File")] = fileMenu_;
//Clear all //Clear all
...@@ -140,7 +141,6 @@ void CoreWidget::setupMenuBar() ...@@ -140,7 +141,6 @@ void CoreWidget::setupMenuBar()
AC_Load->setStatusTip(tr("Load an object")); AC_Load->setStatusTip(tr("Load an object"));
AC_Load->setWhatsThis(tr("Load a new object")); AC_Load->setWhatsThis(tr("Load a new object"));
AC_Load->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"document-open.png")); AC_Load->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"document-open.png"));
connect(AC_Load, SIGNAL(triggered()), this, SIGNAL(loadMenu())); connect(AC_Load, SIGNAL(triggered()), this, SIGNAL(loadMenu()));
fileMenu_->addAction(AC_Load); fileMenu_->addAction(AC_Load);
...@@ -518,6 +518,15 @@ void CoreWidget::setupMenuBar() ...@@ -518,6 +518,15 @@ void CoreWidget::setupMenuBar()
mainToolbar_->addSeparator(); mainToolbar_->addSeparator();
mainToolbar_->addAction(AC_load_ini); mainToolbar_->addAction(AC_load_ini);
mainToolbar_->addAction(AC_save_ini); mainToolbar_->addAction(AC_save_ini);
// install event filters for what is this event
// todo: why doesn't go any event through CoreWidget::event from menus? i don't get it
fileMenu_->installEventFilter(this);
viewMenu_->installEventFilter(this);
toolsMenu_->installEventFilter(this);
windowMenu_->installEventFilter(this);
helpMenu_->installEventFilter(this);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment