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

KDE3Support

  • sources
  • kde-4.14
  • kdelibs
  • kde3support
  • kdeui
k3panelmenu.cpp
Go to the documentation of this file.
1 /*****************************************************************
2 
3 Copyright (c) 1996-2000 the kicker authors. See file AUTHORS.
4  (c) Michael Goffioul <kdeprint@swing.be>
5 
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:
12 
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15 
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.
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 
34 class K3PanelMenu::Private
35 {
36 public:
37  bool init;
38  int clearDelay;
39  QString startPath;
40  QTimer t;
41 };
42 
43 K3PanelMenu::K3PanelMenu(const QString &startDir, QWidget *parent)
44  : KMenu(parent)
45 {
46  init(startDir);
47 }
48 
49 K3PanelMenu::K3PanelMenu(QWidget *parent)
50  : KMenu(parent)
51 {
52  init();
53 }
54 
55 void 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 
73 K3PanelMenu::~K3PanelMenu()
74 {
75  delete d;
76 }
77 
78 void 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 
91 void K3PanelMenu::slotClear()
92 {
93  setInitialized( false );
94  clear();
95 }
96 
97 void 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 
109 void K3PanelMenu::disableAutoClear()
110 {
111  d->clearDelay = 0;
112 }
113 
114 const QString& K3PanelMenu::path() const
115 {
116  return d->startPath;
117 }
118 
119 void K3PanelMenu::setPath(const QString& p)
120 {
121  d->startPath = p;
122 }
123 
124 bool K3PanelMenu::initialized() const
125 {
126  return d->init;
127 }
128 
129 void K3PanelMenu::setInitialized(bool on)
130 {
131  d->init = on;
132 }
133 
134 void 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 
143 void K3PanelMenu::deinitialize()
144 {
145  slotClear();
146 }
147 
148 void K3PanelMenu::internalInitialize()
149 {
150  if( initialized() )
151  return;
152  initialize();
153  setInitialized( true );
154 }
155 
QHideEvent
QWidget
K3PanelMenu::initialize
virtual void initialize()=0
This slots is called to initialize the menu.
KMenu::setKeyboardShortcutsEnabled
void setKeyboardShortcutsEnabled(bool enable)
K3PanelMenu::hideEvent
virtual void hideEvent(QHideEvent *ev)
Re-implemented for internal reasons.
Definition: k3panelmenu.cpp:97
timeout
int timeout
KMenu
KMenu::hideEvent
virtual void hideEvent(QHideEvent *)
K3PanelMenu::setInitialized
void setInitialized(bool on)
Set the initial state.
Definition: k3panelmenu.cpp:129
K3PanelMenu::~K3PanelMenu
virtual ~K3PanelMenu()
Destructor.
Definition: k3panelmenu.cpp:73
QWidget::isTopLevel
bool isTopLevel() const
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
config
KSharedConfigPtr config()
QMenu::clear
void clear()
kglobal.h
QMenu::aboutToShow
void aboutToShow()
QTimer
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::deinitialize
void deinitialize()
Deinitialize the menu: the menu is cleared and the initialized state is set to false.
Definition: k3panelmenu.cpp:143
QString
K3PanelMenu::K3PanelMenu
K3PanelMenu(QWidget *parent)
Construct a K3PanelMenu object.
Definition: k3panelmenu.cpp:49
K3PanelMenu::initialized
bool initialized() const
Tell if the menu has been initialized, that is it already contains items.
Definition: k3panelmenu.cpp:124
k3panelmenu.h
K3PanelMenu::setPath
void setPath(const QString &p)
Set a directory path to be associated with this menu.
Definition: k3panelmenu.cpp:119
K3PanelMenu::slotExec
virtual void slotExec(int id)=0
This is slot is called when an item from the menu has been selected.
K3PanelMenu::disableAutoClear
void disableAutoClear()
Disable the automatic clearing of the menu.
Definition: k3panelmenu.cpp:109
KConfigGroup
K3PanelMenu::slotAboutToShow
virtual void slotAboutToShow()
This slot is called just before the menu is shown.
Definition: k3panelmenu.cpp:78
QMenu::activated
void activated(int itemId)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
K3PanelMenu::init
void init(const QString &path=QString())
For internal use only.
Definition: k3panelmenu.cpp:55
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
K3PanelMenu::slotClear
void slotClear()
Clears the menu, and update the initial state accordingly.
Definition: k3panelmenu.cpp:91
kconfiggroup.h
K3PanelMenu::reinitialize
void reinitialize()
Reinitialize the menu: the menu is first cleared, the initial state is set to false, and finally initialize() is called.
Definition: k3panelmenu.cpp:134
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:26:48 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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