[prev in list] [next in list] [prev in thread] [next in thread] 

List:       konsole-devel
Subject:    [Konsole-devel] [PATCH] Shortcuts with hidden menu bar
From:       Robin Stocker <robin () nibor ! org>
Date:       2007-07-24 15:47:00
Message-ID: 46A61EF4.9070207 () nibor ! org
[Download RAW message or body]

Hi,

As Konsole is probably the application I use the most, I thought I might
help a little with the development of the interesting KDE 4 version.

The attached patch makes the action shortcuts work with a hidden menu
bar. It applies to trunk/KDE/kdebase/apps/konsole.

The problem was: In Qt4, invisible widgets don't get events anymore,
because that's usually how you want it to behave. Because the actions
are added to the menu and the menu is hidden, the shortcuts do not work.


There are several solutions:

- In the *ui.rc files, add each action not only to <MenuBar>, but also
to <MainWindow>. Not good.

- Add all actions of actionCollection to the main window after they are
all added. I grepped for takeAction, to see if any actions are removed,
but found nothing. This is the method I implemented in the patch.

- actionCollection provides the signal inserted(QAction *). Connect the
signal to a new slot in MainWindow which adds the action. One would also
have to provide a new method for the signal removed, so this would
amount to four slots in two classes.


The best solution would be to use KActionCollection.addAssociatedWidget,
but in line 238 of kdelibs/kdeui/actions/kactioncollection.cpp, before
the action is added to the specified widget, it does this:

        action->setShortcutContext(Qt::WidgetShortcut);

Because of this, the shortcut will only get triggered when the main
window widget is directly focussed, but that's never the case.

I don't know where actionCollection is used, but maybe this code could
be changed; maybe add a method setAssociatedWidgetShortcutContext or
something like it. Because then, this would be the cleanest solution.


Cheers,
  Robin Stocker

["shortcuts-with-hidden-menubar.diff" (text/plain)]

Index: TODO
===================================================================
--- TODO	(revision 691893)
+++ TODO	(working copy)
@@ -84,8 +84,6 @@ The KDE 4.0 TODO List:
 
 == BUGS ==
 
-- Shortcuts do not work when the menu bar is hidden.
-
 - Allow the user to over-ride the "no Ctrl+[Key] shortcuts" limitation with shortcuts
 set in the configuration dialog, but warn the user if they try to do so.  This is the 
 behaviour in KDE 3.
Index: src/SessionController.cpp
===================================================================
--- src/SessionController.cpp	(revision 691893)
+++ src/SessionController.cpp	(working copy)
@@ -87,6 +87,10 @@ SessionController::SessionController(Ses
     setXMLFile("konsole/sessionui.rc");
     setupActions();
 
+    // add all actions to this window, so that the keyboard shortcuts can be
+    // used even when the menu is hidden
+    view->addActions(actionCollection()->actions());
+
     setIdentifier(_session->sessionId());
     sessionTitleChanged();
     
Index: src/MainWindow.cpp
===================================================================
--- src/MainWindow.cpp	(revision 691893)
+++ src/MainWindow.cpp	(working copy)
@@ -81,6 +81,10 @@ MainWindow::MainWindow()
     // replace standard shortcuts which cannot be used in a terminal
     // (as they are reserved for use by terminal programs)
     correctShortcuts();
+
+    // add all actions to this window, so that the keyboard shortcuts can be
+    // used even when the menu is hidden
+    addActions(actionCollection()->actions());
 }
 
 void MainWindow::correctShortcuts()


_______________________________________________
konsole-devel mailing list
konsole-devel@kde.org
https://mail.kde.org/mailman/listinfo/konsole-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic