• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDE3Support

  • kde3support
  • kdeui
k3panelmenu.cpp
Go to the documentation of this file.
1/*****************************************************************
2
3Copyright (c) 1996-2000 the kicker authors. See file AUTHORS.
4 (c) Michael Goffioul <kdeprint@swing.be>
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23******************************************************************/
24
25#include <kglobal.h>
26#include <kconfiggroup.h>
27#include <QTimer>
28
29#include "k3panelmenu.h"
30#include "k3panelmenu.moc"
31//#include "kaccelmanager.h"
32
33
34class K3PanelMenu::Private
35{
36public:
37 bool init;
38 int clearDelay;
39 QString startPath;
40 QTimer t;
41};
42
43K3PanelMenu::K3PanelMenu(const QString &startDir, QWidget *parent)
44 : KMenu(parent)
45{
46 init(startDir);
47}
48
49K3PanelMenu::K3PanelMenu(QWidget *parent)
50 : KMenu(parent)
51{
52 init();
53}
54
55void K3PanelMenu::init(const QString& path)
56{
57 d = new Private;
58
59 setInitialized( false );
60 d->startPath = path;
61
62 connect(this, SIGNAL(activated(int)), SLOT(slotExec(int)));
63 connect(this, SIGNAL(aboutToShow()), SLOT(slotAboutToShow()));
64
65 // setup cache timer
66 KConfigGroup config(KGlobal::config(), "menus");
67 d->clearDelay = config.readEntry("MenuCacheTime", 60000); // 1 minute
68
69 //KAcceleratorManager::manage(this);
70 setKeyboardShortcutsEnabled(true);
71}
72
73K3PanelMenu::~K3PanelMenu()
74{
75 delete d;
76}
77
78void K3PanelMenu::slotAboutToShow()
79{
80 // stop the cache timer
81 if(d->clearDelay)
82 d->t.stop();
83
84 // teared off ?
85 if ( isTopLevel() )
86 d->clearDelay = 0;
87
88 internalInitialize();
89}
90
91void K3PanelMenu::slotClear()
92{
93 setInitialized( false );
94 clear();
95}
96
97void K3PanelMenu::hideEvent(QHideEvent *ev)
98{
99 // start the cache timer
100 if(d->clearDelay) {
101 disconnect(&(d->t), SIGNAL(timeout()), this, SLOT(slotClear()));
102 connect(&(d->t), SIGNAL(timeout()), this, SLOT(slotClear()));
103 d->t.setSingleShot(true);
104 d->t.start(d->clearDelay);
105 }
106 KMenu::hideEvent(ev);
107}
108
109void K3PanelMenu::disableAutoClear()
110{
111 d->clearDelay = 0;
112}
113
114const QString& K3PanelMenu::path() const
115{
116 return d->startPath;
117}
118
119void K3PanelMenu::setPath(const QString& p)
120{
121 d->startPath = p;
122}
123
124bool K3PanelMenu::initialized() const
125{
126 return d->init;
127}
128
129void K3PanelMenu::setInitialized(bool on)
130{
131 d->init = on;
132}
133
134void K3PanelMenu::reinitialize()
135{
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();
141}
142
143void K3PanelMenu::deinitialize()
144{
145 slotClear();
146}
147
148void K3PanelMenu::internalInitialize()
149{
150 if( initialized() )
151 return;
152 initialize();
153 setInitialized( true );
154}
155
K3PanelMenu::~K3PanelMenu
virtual ~K3PanelMenu()
Destructor.
Definition: k3panelmenu.cpp:73
K3PanelMenu::initialized
bool initialized() const
Tell if the menu has been initialized, that is it already contains items.
Definition: k3panelmenu.cpp:124
K3PanelMenu::reinitialize
void reinitialize()
Reinitialize the menu: the menu is first cleared, the initial state is set to false,...
Definition: k3panelmenu.cpp:134
K3PanelMenu::deinitialize
void deinitialize()
Deinitialize the menu: the menu is cleared and the initialized state is set to false.
Definition: k3panelmenu.cpp:143
K3PanelMenu::slotAboutToShow
virtual void slotAboutToShow()
This slot is called just before the menu is shown.
Definition: k3panelmenu.cpp:78
K3PanelMenu::hideEvent
virtual void hideEvent(QHideEvent *ev)
Re-implemented for internal reasons.
Definition: k3panelmenu.cpp:97
K3PanelMenu::setPath
void setPath(const QString &p)
Set a directory path to be associated with this menu.
Definition: k3panelmenu.cpp:119
K3PanelMenu::init
void init(const QString &path=QString())
For internal use only.
Definition: k3panelmenu.cpp:55
K3PanelMenu::K3PanelMenu
K3PanelMenu(QWidget *parent)
Construct a K3PanelMenu object.
Definition: k3panelmenu.cpp:49
K3PanelMenu::initialize
virtual void initialize()=0
This slots is called to initialize the menu.
K3PanelMenu::setInitialized
void setInitialized(bool on)
Set the initial state.
Definition: k3panelmenu.cpp:129
K3PanelMenu::slotExec
virtual void slotExec(int id)=0
This is slot is called when an item from the menu has been selected.
K3PanelMenu::path
const QString & path() const
Get the directory path associated with this menu, or QString() if there's no such associated path.
Definition: k3panelmenu.cpp:114
K3PanelMenu::disableAutoClear
void disableAutoClear()
Disable the automatic clearing of the menu.
Definition: k3panelmenu.cpp:109
K3PanelMenu::slotClear
void slotClear()
Clears the menu, and update the initial state accordingly.
Definition: k3panelmenu.cpp:91
KConfigGroup
KMenu
KMenu::hideEvent
virtual void hideEvent(QHideEvent *)
KMenu::setKeyboardShortcutsEnabled
void setKeyboardShortcutsEnabled(bool enable)
QWidget
k3panelmenu.h
kconfiggroup.h
kglobal.h
timeout
int timeout
config
KSharedConfigPtr config()
clear
KAction * clear(const QObject *recvr, const char *slot, QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDE3Support

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal