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

tdeui

  • tdeui
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 "tdeglobal.h"
25#include "tdeconfig.h"
26#include "tdeshortcut.h"
27
28#undef KeyPress
29#undef None
30
31template class TQPtrDict<TQPopupMenu>;
32
33KContextMenuManager* KContextMenuManager::manager = 0;
34
35KContextMenuManager::KContextMenuManager( TQObject* parent, const char* name )
36 : TQObject( parent, name)
37{
38 TDEConfigGroupSaver saver ( TDEGlobal::config(), TQString::fromLatin1("Shortcuts") ) ;
39 menuKey = TDEShortcut( 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
44KContextMenuManager::~KContextMenuManager()
45{
46}
47
48
49bool KContextMenuManager::showOnButtonPress( void )
50{
51 if ( !manager )
52 manager = new KContextMenuManager;
53 return manager->showOnPress;
54}
55
56
57void KContextMenuManager::insert( TQWidget* widget, TQPopupMenu* popup )
58{
59 if ( !manager )
60 manager = new KContextMenuManager;
61
62 manager->connect( widget, TQ_SIGNAL( destroyed() ), manager, TQ_SLOT( widgetDestroyed() ) );
63 manager->menus.insert( widget, popup );
64 widget->installEventFilter( manager );
65}
66
67bool 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() != TQt::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() != TQt::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
123void KContextMenuManager::widgetDestroyed()
124{
125 if ( menus.find( (TQObject*)sender() ) )
126 menus.remove( (TQObject*)sender() );
127}
128
129#include "kcmenumngr.moc"
KContextMenuManager
Convenience class to mangage context menus.
Definition: kcmenumngr.h:77
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
TDEConfigGroupSaver
TDEGlobal::config
static TDEConfig * config()
TDEShortcut
TDEShortcut::keyCodeQt
int keyCodeQt() const
TDEStdAccel::name
TQString name(StdAccel id)

tdeui

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

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.4
This website is maintained by Timothy Pearson.