kpanelmenu.cpp Source File (kdeui Library)

| # kdeui Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kpanelmenu.cpp

    00001 /*****************************************************************
    00002
    00003 Copyright (c) 1996-2000 the kicker authors. See file AUTHORS.
    00004           (c) Michael Goffioul <goffioul@imec.be>
    00005
    00006 Permission is hereby granted, free of charge, to any person obtaining a copy
    00007 of this software and associated documentation files (the "Software"), to deal
    00008 in the Software without restriction, including without limitation the rights
    00009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00010 copies of the Software, and to permit persons to whom the Software is
    00011 furnished to do so, subject to the following conditions:
    00012
    00013 The above copyright notice and this permission notice shall be included in
    00014 all copies or substantial portions of the Software.
    00015
    00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    00019 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
    00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    00022
    00023 ******************************************************************/
    00024
    00025 #include <kglobal.h>
    00026 #include <kconfig.h>
    00027 #include <qtimer.h>
    00028
    00029 #include "kpanelmenu.h"
    00030 #include "kpanelmenu.moc"
    00031 //#include "kaccelmanager.h"
    00032
    00033
    00034 class KPanelMenuPrivate
    00035 {
    00036 public:
    00037     bool init;
    00038     int clearDelay;
    00039     QString startPath;
    00040     QTimer t;
    00041 };
    00042
    00043 KPanelMenu::KPanelMenu(const QString &startDir, QWidget *parent, const char *name)
    00044   : KPopupMenu(parent, name)
    00045 {
    00046     init(startDir);
    00047 }
    00048
    00049 KPanelMenu::KPanelMenu(QWidget *parent, const char *name)
    00050   : KPopupMenu(parent, name)
    00051 {
    00052     init();
    00053 }
    00054
    00055 void KPanelMenu::init(const QString& path)
    00056 {
    00057     d = new KPanelMenuPrivate;
    00058
    00059     setInitialized( false );
    00060     d->startPath = path;
    00061
    00062     connect(this, SIGNAL(activated(int)), SLOT(slotExec(int)));
    00063     connect(this, SIGNAL(aboutToShow()), SLOT(slotAboutToShow()));
    00064
    00065     // setup cache timer
    00066     KConfig *config = KGlobal::config();
    00067     config->setGroup("menus");
    00068     d->clearDelay = config->readNumEntry("MenuCacheTime", 60000); // 1 minute
    00069
    00070     //KAcceleratorManager::manage(this);
    00071     setKeyboardShortcutsEnabled(true);
    00072 }
    00073
    00074 KPanelMenu::~KPanelMenu()
    00075 {
    00076     delete d;
    00077 }
    00078
    00079 void KPanelMenu::slotAboutToShow()
    00080 {
    00081     // stop the cache timer
    00082     if(d->clearDelay)
    00083         d->t.stop();
    00084
    00085     // teared off ?
    00086     if ( isTopLevel() )
    00087         d->clearDelay = 0;
    00088
    00089     internalInitialize();
    00090 }
    00091
    00092 void KPanelMenu::slotClear()
    00093 {
    00094     setInitialized( false );
    00095     clear();
    00096 }
    00097
    00098 void KPanelMenu::hideEvent(QHideEvent *ev)
    00099 {
    00100     // start the cache timer
    00101     if(d->clearDelay) {
    00102         disconnect(&(d->t), SIGNAL(timeout()), this, SLOT(slotClear()));
    00103         connect(&(d->t), SIGNAL(timeout()), this, SLOT(slotClear()));
    00104         d->t.start(d->clearDelay, true);
    00105     }
    00106     QPopupMenu::hideEvent(ev);
    00107 }
    00108
    00109 void KPanelMenu::disableAutoClear()
    00110 {
    00111     d->clearDelay = 0;
    00112 }
    00113
    00114 const QString& KPanelMenu::path() const
    00115 {
    00116     return d->startPath;
    00117 }
    00118
    00119 void KPanelMenu::setPath(const QString& p)
    00120 {
    00121     d->startPath = p;
    00122 }
    00123
    00124 bool KPanelMenu::initialized() const
    00125 {
    00126     return d->init;
    00127 }
    00128
    00129 void KPanelMenu::setInitialized(bool on)
    00130 {
    00131     d->init = on;
    00132 }
    00133
    00134 void KPanelMenu::reinitialize()
    00135 {
    00136     deinitialize();
    00137     // Yes, reinitialize must call initialize(). Otherwise, menus
    00138     // may not appear in the right place. Don't change this! If
    00139     // you want delayed initialization, use deinitialize() instead.
    00140     internalInitialize();
    00141 }
    00142
    00143 void KPanelMenu::deinitialize()
    00144 {
    00145     slotClear();
    00146 }
    00147
    00148 void KPanelMenu::internalInitialize()
    00149 {
    00150     if( initialized() )
    00151         return;
    00152     initialize();
    00153     setInitialized( true );
    00154 }
    00155
    00156 void KPanelMenu::virtual_hook( int id, void* data )
    00157 { KPopupMenu::virtual_hook( id, data ); }
    00158

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:57:28 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001