• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdeui
 

kdeui

  • kdeui
kcmenumngr.cpp
1 /*
2  * This file is part of the KDE Libraries
3  * Copyright (C) 1999 Matthias Ettrich <ettrich@kde.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  *
20  */
21 #include <tqwidget.h>
22 #include <tqpopupmenu.h>
23 #include "kcmenumngr.h"
24 #include "kglobal.h"
25 #include "kconfig.h"
26 #include "kshortcut.h"
27 
28 #undef KeyPress
29 #undef None
30 
31 template class TQPtrDict<TQPopupMenu>;
32 
33 KContextMenuManager* KContextMenuManager::manager = 0;
34 
35 KContextMenuManager::KContextMenuManager( TQObject* parent, const char* name )
36  : TQObject( parent, name)
37 {
38  KConfigGroupSaver saver ( KGlobal::config(), TQString::fromLatin1("Shortcuts") ) ;
39  menuKey = KShortcut( saver.config()->readEntry(TQString::fromLatin1("PopupContextMenu"), TQString::fromLatin1("Menu") ) ).keyCodeQt();
40  saver.config()->setGroup( TQString::fromLatin1("ContextMenus") ) ;
41  showOnPress = saver.config()->readBoolEntry(TQString::fromLatin1("ShowOnPress"), true );
42 }
43 
44 KContextMenuManager::~KContextMenuManager()
45 {
46 }
47 
48 
49 bool KContextMenuManager::showOnButtonPress( void )
50 {
51  if ( !manager )
52  manager = new KContextMenuManager;
53  return manager->showOnPress;
54 }
55 
56 
57 void KContextMenuManager::insert( TQWidget* widget, TQPopupMenu* popup )
58 {
59  if ( !manager )
60  manager = new KContextMenuManager;
61 
62  manager->connect( widget, TQT_SIGNAL( destroyed() ), manager, TQT_SLOT( widgetDestroyed() ) );
63  manager->menus.insert( widget, popup );
64  widget->installEventFilter( manager );
65 }
66 
67 bool KContextMenuManager::eventFilter( TQObject *o, TQEvent * e)
68 {
69  TQPopupMenu* popup = 0;
70  TQPoint pos;
71  switch ( e->type() ) {
72  case TQEvent::MouseButtonPress:
73  if (((TQMouseEvent*) e )->button() != Qt::RightButton )
74  break;
75  if ( !showOnPress )
76  return true; // eat event for safety
77  popup = menus[o];
78  pos = ((TQMouseEvent*) e )->globalPos();
79  break;
80  case TQEvent::MouseButtonRelease:
81  if ( showOnPress || ((TQMouseEvent*) e )->button() != Qt::RightButton )
82  break;
83  popup = menus[o];
84  pos = ((TQMouseEvent*) e )->globalPos();
85  break;
86  case TQEvent::KeyPress:
87  {
88  if ( !o->isWidgetType() )
89  break;
90  TQKeyEvent *k = (TQKeyEvent *)e;
91  int key = k->key();
92  if ( k->state() & ShiftButton )
93  key |= SHIFT;
94  if ( k->state() & ControlButton )
95  key |= CTRL;
96  if ( k->state() & AltButton )
97  key |= ALT;
98  if ( key != menuKey )
99  break;
100  popup = menus[o];
101  if ( popup ) {
102  TQWidget* w = (TQWidget*) o ;
103 
104  // ### workaround
105  pos = w->mapToGlobal( w->rect().center() );
106  // with later Qt snapshot
107  // pos = w->mapToGlobal( w->microFocusHint().center() );
108  }
109  }
110  break;
111  default:
112  break;
113  }
114 
115  if ( popup ) {
116  popup->popup( pos );
117  return true;
118  }
119 
120  return false;
121 }
122 
123 void KContextMenuManager::widgetDestroyed()
124 {
125  if ( menus.find( (TQObject*)sender() ) )
126  menus.remove( (TQObject*)sender() );
127 }
128 
129 #include "kcmenumngr.moc"
KConfigGroupSaver
KContextMenuManager
Convenience class to mangage context menus.
Definition: kcmenumngr.h:79
KContextMenuManager::insert
static void insert(TQWidget *widget, TQPopupMenu *popup)
Makes popup a context popup menu for widget widget.
Definition: kcmenumngr.cpp:57
KContextMenuManager::showOnButtonPress
static bool showOnButtonPress(void)
Use this method to get information about when a popup menu should be activated.
Definition: kcmenumngr.cpp:49
KGlobal::config
static KConfig * config()
KShortcut
KShortcut::keyCodeQt
int keyCodeQt() const
KStdAccel::name
TQString name(StdAccel id)

kdeui

Skip menu "kdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeui

Skip menu "kdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeui by doxygen 1.9.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |