• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kdeui

kcmenumngr.cpp

Go to the documentation of this file.
00001 /*
00002  *  This file is part of the KDE Libraries
00003  *  Copyright (C) 1999 Matthias Ettrich <ettrich@kde.org>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Library General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU Library General Public License
00016  *  along with this library; see the file COPYING.LIB.  If not, write to
00017  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  *  Boston, MA 02110-1301, USA.
00019  *
00020  */
00021 #include <qwidget.h>
00022 #include <qpopupmenu.h>
00023 #include "kcmenumngr.h"
00024 #include "kglobal.h"
00025 #include "kconfig.h"
00026 #include "kshortcut.h"
00027 
00028 #undef KeyPress
00029 #undef None
00030 
00031 template class QPtrDict<QPopupMenu>;
00032 
00033 KContextMenuManager* KContextMenuManager::manager = 0;
00034 
00035 KContextMenuManager::KContextMenuManager( QObject* parent, const char* name )
00036     : QObject( parent, name)
00037 {
00038     KConfigGroupSaver saver ( KGlobal::config(), QString::fromLatin1("Shortcuts") ) ;
00039     menuKey = KShortcut( saver.config()->readEntry(QString::fromLatin1("PopupContextMenu"), QString::fromLatin1("Menu") ) ).keyCodeQt();
00040     saver.config()->setGroup( QString::fromLatin1("ContextMenus") ) ;
00041     showOnPress = saver.config()->readBoolEntry(QString::fromLatin1("ShowOnPress"), true );
00042 }
00043 
00044 KContextMenuManager::~KContextMenuManager()
00045 {
00046 }
00047 
00048 
00049 bool KContextMenuManager::showOnButtonPress( void )
00050 {
00051   if ( !manager )
00052     manager = new KContextMenuManager;
00053   return manager->showOnPress;
00054 }
00055 
00056 
00057 void KContextMenuManager::insert( QWidget* widget, QPopupMenu* popup )
00058 {
00059     if ( !manager )
00060     manager = new KContextMenuManager;
00061     
00062     manager->connect( widget, SIGNAL( destroyed() ), manager, SLOT( widgetDestroyed() ) );
00063     manager->menus.insert( widget, popup );
00064     widget->installEventFilter( manager );
00065 }
00066 
00067 bool KContextMenuManager::eventFilter( QObject *o, QEvent * e)
00068 {
00069     QPopupMenu* popup = 0;
00070     QPoint pos;
00071     switch ( e->type() ) {
00072     case QEvent::MouseButtonPress:
00073     if (((QMouseEvent*) e )->button() != RightButton )
00074         break;
00075     if ( !showOnPress )
00076         return true; // eat event for safety
00077     popup = menus[o];
00078     pos = ((QMouseEvent*) e )->globalPos();
00079     break;
00080     case QEvent::MouseButtonRelease:
00081     if ( showOnPress  || ((QMouseEvent*) e )->button() != RightButton )
00082         break;
00083     popup = menus[o];   
00084     pos = ((QMouseEvent*) e )->globalPos();
00085     break;
00086     case QEvent::KeyPress:
00087     {
00088         if ( !o->isWidgetType() )
00089         break;
00090         QKeyEvent *k = (QKeyEvent *)e;
00091         int key = k->key();
00092         if ( k->state() & ShiftButton )
00093         key |= SHIFT;
00094         if ( k->state() & ControlButton )
00095         key |= CTRL;
00096         if ( k->state() & AltButton )
00097         key |= ALT;
00098         if ( key != menuKey )
00099         break;
00100         popup = menus[o];
00101         if ( popup ) {
00102         QWidget* w = (QWidget*) o ;
00103         
00104         // ### workaround
00105         pos = w->mapToGlobal( w->rect().center() );
00106         // with later Qt snapshot 
00107         // pos = w->mapToGlobal( w->microFocusHint().center() );
00108         }
00109     }
00110     break;
00111     default: 
00112     break;
00113     }
00114     
00115     if ( popup ) {
00116     popup->popup( pos );
00117     return true;
00118     }
00119     
00120     return false;
00121 }
00122 
00123 void KContextMenuManager::widgetDestroyed()
00124 {
00125     if ( menus.find( (QObject*)sender() ) )
00126     menus.remove( (QObject*)sender() );
00127 }
00128 
00129 #include "kcmenumngr.moc"

kdeui

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

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal