subtraction of already painted area: be fool and
[kdelibs.git] / kdeui / kpanelmenu.cpp
blobab1ed3d35c04e28f192dddbd698fd4685b8db68b
1 /*****************************************************************
3 Copyright (c) 1996-2000 the kicker authors. See file AUTHORS.
4 (c) Michael Goffioul <kdeprint@swing.be>
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 ******************************************************************/
25 #include <kglobal.h>
26 #include <kconfig.h>
27 #include <qtimer.h>
29 #include "kpanelmenu.h"
30 #include "kpanelmenu.moc"
31 //#include "kaccelmanager.h"
34 class KPanelMenuPrivate
36 public:
37 bool init;
38 int clearDelay;
39 QString startPath;
40 QTimer t;
43 KPanelMenu::KPanelMenu(const QString &startDir, QWidget *parent, const char *name)
44 : KPopupMenu(parent, name)
46 init(startDir);
49 KPanelMenu::KPanelMenu(QWidget *parent, const char *name)
50 : KPopupMenu(parent, name)
52 init();
55 void KPanelMenu::init(const QString& path)
57 d = new KPanelMenuPrivate;
59 setInitialized( false );
60 d->startPath = path;
62 connect(this, SIGNAL(activated(int)), SLOT(slotExec(int)));
63 connect(this, SIGNAL(aboutToShow()), SLOT(slotAboutToShow()));
65 // setup cache timer
66 KConfig *config = KGlobal::config();
67 config->setGroup("menus");
68 d->clearDelay = config->readNumEntry("MenuCacheTime", 60000); // 1 minute
70 //KAcceleratorManager::manage(this);
71 setKeyboardShortcutsEnabled(true);
74 KPanelMenu::~KPanelMenu()
76 delete d;
79 void KPanelMenu::slotAboutToShow()
81 // stop the cache timer
82 if(d->clearDelay)
83 d->t.stop();
85 // teared off ?
86 if ( isTopLevel() )
87 d->clearDelay = 0;
89 internalInitialize();
92 void KPanelMenu::slotClear()
94 setInitialized( false );
95 clear();
98 void KPanelMenu::hideEvent(QHideEvent *ev)
100 // start the cache timer
101 if(d->clearDelay) {
102 disconnect(&(d->t), SIGNAL(timeout()), this, SLOT(slotClear()));
103 connect(&(d->t), SIGNAL(timeout()), this, SLOT(slotClear()));
104 d->t.start(d->clearDelay, true);
106 QPopupMenu::hideEvent(ev);
109 void KPanelMenu::disableAutoClear()
111 d->clearDelay = 0;
114 const QString& KPanelMenu::path() const
116 return d->startPath;
119 void KPanelMenu::setPath(const QString& p)
121 d->startPath = p;
124 bool KPanelMenu::initialized() const
126 return d->init;
129 void KPanelMenu::setInitialized(bool on)
131 d->init = on;
134 void KPanelMenu::reinitialize()
136 deinitialize();
137 // Yes, reinitialize must call initialize(). Otherwise, menus
138 // may not appear in the right place. Don't change this! If
139 // you want delayed initialization, use deinitialize() instead.
140 internalInitialize();
143 void KPanelMenu::deinitialize()
145 slotClear();
148 void KPanelMenu::internalInitialize()
150 if( initialized() )
151 return;
152 initialize();
153 setInitialized( true );
156 void KPanelMenu::virtual_hook( int id, void* data )
157 { KPopupMenu::virtual_hook( id, data ); }