• 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
k3panelapplet.cpp
Go to the documentation of this file.
1 /*****************************************************************
2 
3 Copyright (c) 2000 Matthias Elter
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11 
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14 
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 
22 ******************************************************************/
23 
24 #include "k3panelapplet.h"
25 #include "k3panelapplet.moc"
26 #include <ksharedconfig.h>
27 #include <kglobal.h>
28 #include <QResizeEvent>
29 
30 class K3PanelApplet::Private
31 {
32 public:
33  Private()
34  : position( K3PanelApplet::Bottom ),
35  alignment( K3PanelApplet::LeftTop ),
36  customMenu(0),
37  hasFocus(false)
38  {}
39 
40  K3PanelApplet::Type type;
41  K3PanelApplet::Position position;
42  K3PanelApplet::Alignment alignment;
43  int actions;
44 
45  const QMenu* customMenu;
46  KSharedConfig::Ptr sharedConfig;
47  QList<QObject*> watchedForFocus;
48  bool hasFocus;
49 };
50 
51 K3PanelApplet::K3PanelApplet(const QString& configFile, K3PanelApplet::Type type,
52  int actions, QWidget *parent, Qt::WindowFlags f)
53  : QFrame(parent, f),
54  d(new Private())
55 {
56  d->type = type;
57  d->actions = actions;
58 
59  setFrameStyle(NoFrame);
60  QPalette pal(palette());
61  if(pal.active().mid() != pal.inactive().mid()){
62  pal.setInactive(pal.active());
63  setPalette(pal);
64  }
65  setBackgroundOrigin( AncestorOrigin );
66 
67  d->sharedConfig = KSharedConfig::openConfig(configFile);
68 }
69 
70 K3PanelApplet::~K3PanelApplet()
71 {
72  d->watchedForFocus.clear();
73  needsFocus(false);
74  delete d;
75 }
76 
77 KConfig* K3PanelApplet::config() const
78 {
79  return d->sharedConfig.data();
80 }
81 
82 K3PanelApplet::Type K3PanelApplet::type() const
83 {
84  return d->type;
85 }
86 
87 int K3PanelApplet::actions() const
88 {
89  return d->actions;
90 }
91 
92 void K3PanelApplet::setPosition( K3PanelApplet::Position p )
93 {
94  if( d->position == p ) return;
95  d->position = p;
96  positionChange( p );
97 }
98 
99 void K3PanelApplet::setAlignment( K3PanelApplet::Alignment a )
100 {
101  if( d->alignment == a ) return;
102  d->alignment = a;
103  alignmentChange( a );
104 }
105 
106 // FIXME: Remove implementation for KDE 4
107 void K3PanelApplet::positionChange( K3PanelApplet::Position )
108 {
109  orientationChange( orientation() );
110  QResizeEvent e( size(), size() );
111  resizeEvent( &e );
112  popupDirectionChange( popupDirection() );
113 }
114 
115 // FIXME: Remove for KDE 4
116 K3PanelApplet::Position K3PanelApplet::popupDirection()
117 {
118  switch( d->position ) {
119  case K3PanelApplet::Top:
120  return K3PanelApplet::Down;
121  case K3PanelApplet::Right:
122  return K3PanelApplet::Left;
123  case K3PanelApplet::Left:
124  return K3PanelApplet::Right;
125  case K3PanelApplet::Bottom:
126  default:
127  return K3PanelApplet::Up;
128  }
129 }
130 
131 Qt::Orientation K3PanelApplet::orientation() const
132 {
133  if( d->position == K3PanelApplet::Top || d->position == K3PanelApplet::Bottom )
134  {
135  return Qt::Horizontal;
136  }
137  else
138  {
139  return Qt::Vertical;
140  }
141 }
142 
143 K3PanelApplet::Position K3PanelApplet::position() const
144 {
145  return d->position;
146 }
147 
148 K3PanelApplet::Alignment K3PanelApplet::alignment() const
149 {
150  return d->alignment;
151 }
152 
153 void K3PanelApplet::action( K3PanelApplet::Action a )
154 {
155  if ( (a & K3PanelApplet::About) )
156  {
157  about();
158  }
159  if ( (a & K3PanelApplet::Help) )
160  {
161  help();
162  }
163  if ( (a & K3PanelApplet::Preferences) )
164  {
165  preferences();
166  }
167  if ( (a & K3PanelApplet::ReportBug) )
168  {
169  reportBug();
170  }
171 }
172 
173 const QMenu* K3PanelApplet::customMenu() const
174 {
175  return d->customMenu;
176 }
177 
178 void K3PanelApplet::setCustomMenu(const QMenu* menu)
179 {
180  d->customMenu = menu;
181 }
182 
183 void K3PanelApplet::watchForFocus(QWidget* widget, bool watch)
184 {
185  if (!widget)
186  {
187  return;
188  }
189 
190  if (watch)
191  {
192  if (!d->watchedForFocus.contains(widget))
193  {
194  d->watchedForFocus.append(widget);
195  widget->installEventFilter(this);
196  }
197  }
198  else if (!d->watchedForFocus.contains(widget))
199  {
200  d->watchedForFocus.removeAll(widget);
201  widget->removeEventFilter(this);
202  }
203 }
204 
205 void K3PanelApplet::needsFocus(bool focus)
206 {
207  if (focus == d->hasFocus)
208  {
209  return;
210  }
211 
212  d->hasFocus = focus;
213  emit requestFocus(focus);
214 }
215 
216 bool K3PanelApplet::eventFilter(QObject *o, QEvent * e)
217 {
218  if (!d->watchedForFocus.contains(o))
219  {
220  if (e->type() == QEvent::MouseButtonRelease ||
221  e->type() == QEvent::FocusIn)
222  {
223  needsFocus(true);
224  }
225  else if (e->type() == QEvent::FocusOut)
226  {
227  needsFocus(false);
228  }
229  }
230 
231  return QFrame::eventFilter(o, e);
232 }
233 
234 KSharedConfig::Ptr K3PanelApplet::sharedConfig() const
235 {
236  return d->sharedConfig;
237 }
K3PanelApplet::Preferences
Definition: k3panelapplet.h:104
K3PanelApplet::type
Type type() const
Definition: k3panelapplet.cpp:82
KSharedPtr
QEvent
QResizeEvent
QWidget
K3PanelApplet::Top
Definition: k3panelapplet.h:105
QEvent::type
Type type() const
K3PanelApplet
KDE Panel Applet class
Definition: k3panelapplet.h:98
QWidget::palette
const QPalette & palette() const
K3PanelApplet::requestFocus
void requestFocus()
Request keyboard focus from the panel.
K3PanelApplet::Down
Definition: k3panelapplet.h:105
K3PanelApplet::actions
int actions() const
Definition: k3panelapplet.cpp:87
K3PanelApplet::positionChange
virtual void positionChange(Position p)
The panel on which this applet resides has changed its position.
Definition: k3panelapplet.cpp:107
K3PanelApplet::About
Definition: k3panelapplet.h:104
K3PanelApplet::Alignment
Alignment
Definition: k3panelapplet.h:106
K3PanelApplet::d
Private * d
Definition: k3panelapplet.h:370
K3PanelApplet::Help
Definition: k3panelapplet.h:104
K3PanelApplet::alignmentChange
virtual void alignmentChange(Alignment)
The panel on which this applet resides has changed its alignment.
Definition: k3panelapplet.h:315
QWidget::hasFocus
bool hasFocus() const
QFrame::setFrameStyle
void setFrameStyle(int style)
K3PanelApplet::sharedConfig
KSharedConfig::Ptr sharedConfig() const
Definition: k3panelapplet.cpp:234
K3PanelApplet::ReportBug
Definition: k3panelapplet.h:104
QColorGroup::mid
const QColor & mid() const
K3PanelApplet::LeftTop
Definition: k3panelapplet.h:106
K3PanelApplet::alignment
Alignment alignment() const
Definition: k3panelapplet.cpp:148
K3PanelApplet::orientationChange
virtual void orientationChange(Qt::Orientation)
The orientation changed to orientation.
Definition: k3panelapplet.h:350
QWidget::size
QSize size() const
kglobal.h
K3PanelApplet::position
Position position() const
Definition: k3panelapplet.cpp:143
QObject::installEventFilter
void installEventFilter(QObject *filterObj)
K3PanelApplet::reportBug
virtual void reportBug()
Is called when the user selects "Report bug" from the applet's RMB menu.
Definition: k3panelapplet.h:288
K3PanelApplet::popupDirectionChange
virtual void popupDirectionChange(Position)
The popup direction changed to direction.
Definition: k3panelapplet.h:365
QObject
K3PanelApplet::eventFilter
bool eventFilter(QObject *, QEvent *)
Definition: k3panelapplet.cpp:216
K3PanelApplet::Right
Definition: k3panelapplet.h:105
K3PanelApplet::popupDirection
Position popupDirection()
A convenience method that translates the position of the applet into which direction to show a popup...
Definition: k3panelapplet.cpp:116
QWidget::setBackgroundOrigin
void setBackgroundOrigin(BackgroundOrigin background)
QObject::eventFilter
virtual bool eventFilter(QObject *watched, QEvent *event)
ksharedconfig.h
QString
QList< QObject * >
K3PanelApplet::Action
Action
Definition: k3panelapplet.h:104
K3PanelApplet::K3PanelApplet
K3PanelApplet(const QString &configFile, Type t=Normal, int actions=0, QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a K3PanelApplet just like any other widget.
Definition: k3panelapplet.cpp:51
K3PanelApplet::preferences
virtual void preferences()
Is called when the user selects "Preferences" from the applet's RMB menu.
Definition: k3panelapplet.h:278
K3PanelApplet::Type
Type
Definition: k3panelapplet.h:103
K3PanelApplet::watchForFocus
void watchForFocus(QWidget *widget, bool watch=true)
Register widgets that can receive keyboard focus with this this method This call results in an eventF...
Definition: k3panelapplet.cpp:183
QMenu
QFrame
K3PanelApplet::setPosition
void setPosition(Position p)
Definition: k3panelapplet.cpp:92
K3PanelApplet::setCustomMenu
void setCustomMenu(const QMenu *)
Use this method to set the custom menu for this applet so that it can be shown in the applet handle m...
Definition: k3panelapplet.cpp:178
KConfig
K3PanelApplet::Position
Position
Definition: k3panelapplet.h:105
K3PanelApplet::setAlignment
void setAlignment(Alignment a)
Definition: k3panelapplet.cpp:99
QPalette::inactive
QColorGroup inactive() const
K3PanelApplet::about
virtual void about()
Is called when the user selects "About" from the applet's RMB menu.
Definition: k3panelapplet.h:260
K3PanelApplet::config
KConfig * config() const
Always use this KConfig object to save/load your applet's configuration.
Definition: k3panelapplet.cpp:77
Qt::WindowFlags
typedef WindowFlags
QPalette::active
QColorGroup active() const
K3PanelApplet::help
virtual void help()
Is called when the user selects "Help" from the applet's RMB menu.
Definition: k3panelapplet.h:269
QPalette::setInactive
void setInactive(const QColorGroup &colorGroup)
QWidget::resizeEvent
virtual void resizeEvent(QResizeEvent *event)
k3panelapplet.h
KSharedConfig::openConfig
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, const char *resourceType="config")
K3PanelApplet::customMenu
const QMenu * customMenu() const
Definition: k3panelapplet.cpp:173
K3PanelApplet::action
virtual void action(Action a)
Generic action dispatcher.
Definition: k3panelapplet.cpp:153
K3PanelApplet::Left
Definition: k3panelapplet.h:105
K3PanelApplet::needsFocus
void needsFocus(bool focus)
Call this whenever focus is needed or not needed.
Definition: k3panelapplet.cpp:205
QPalette
QObject::removeEventFilter
void removeEventFilter(QObject *obj)
K3PanelApplet::~K3PanelApplet
~K3PanelApplet()
Destructor.
Definition: k3panelapplet.cpp:70
K3PanelApplet::Up
Definition: k3panelapplet.h:105
K3PanelApplet::Bottom
Definition: k3panelapplet.h:105
K3PanelApplet::orientation
Qt::Orientation orientation() const
Definition: k3panelapplet.cpp:131
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