kpanelapplet.cpp
/*****************************************************************
Copyright (c) 2000 Matthias Elter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************/
#include <qptrlist.h>
#include "kpanelapplet.h"
#include "kpanelapplet.moc"
#include <kapplication.h>
#include <kconfig.h>
class KPanelApplet::KPanelAppletPrivate
{
public:
KPanelAppletPrivate()
: customMenu(0),
hasFocus(false)
{}
const QPopupMenu* customMenu;
KSharedConfig::Ptr sharedConfig;
QPtrList<QObject> watchedForFocus;
bool hasFocus;
};
KPanelApplet::KPanelApplet(const QString& configFile, Type type,
int actions, QWidget *parent, const char *name, WFlags f)
: QFrame(parent, name, f)
, _type(type)
, _position( pBottom )
, _alignment( LeftTop )
, _config(0)
, _actions(actions)
, d(new KPanelApplet::KPanelAppletPrivate())
{
setFrameStyle(NoFrame);
QPalette pal(palette());
if(pal.active().mid() != pal.inactive().mid()){
pal.setInactive(pal.active());
setPalette(pal);
}
setBackgroundOrigin( AncestorOrigin );
d->sharedConfig = KSharedConfig::openConfig(configFile, kapp && kapp->config()->isImmutable());
_config = d->sharedConfig;
}
KPanelApplet::~KPanelApplet()
{
d->watchedForFocus.clear();
needsFocus(false);
delete d;
}
void KPanelApplet::setPosition( Position p )
{
if( _position == p ) return;
_position = p;
positionChange( p );
}
void KPanelApplet::setAlignment( Alignment a )
{
if( _alignment == a ) return;
_alignment = a;
alignmentChange( a );
}
// FIXME: Remove implementation for KDE 4
void KPanelApplet::positionChange( Position )
{
orientationChange( orientation() );
QResizeEvent e( size(), size() );
resizeEvent( &e );
popupDirectionChange( popupDirection() );
}
Qt::Orientation KPanelApplet::orientation() const
{
if( _position == pTop || _position == pBottom ) {
return Horizontal;
} else {
return Vertical;
}
}
// FIXME: Remove for KDE 4
KPanelApplet::Direction KPanelApplet::popupDirection()
{
switch( _position ) {
case pTop: return Down;
case pRight: return Left;
case pLeft: return Right;
default:
case pBottom: return Up;
}
}
void KPanelApplet::action( Action a )
{
if ( (a & About) )
about();
if ( (a & Help) )
help();
if ( (a & Preferences) )
preferences();
if ( (a & ReportBug) )
reportBug();
}
const QPopupMenu* KPanelApplet::customMenu() const
{
return d->customMenu;
}
void KPanelApplet::setCustomMenu(const QPopupMenu* menu)
{
d->customMenu = menu;
}
void KPanelApplet::watchForFocus(QWidget* widget, bool watch)
{
if (!widget)
{
return;
}
if (watch)
{
if (d->watchedForFocus.find(widget) == -1)
{
d->watchedForFocus.append(widget);
widget->installEventFilter(this);
}
}
else if (d->watchedForFocus.find(widget) != -1)
{
d->watchedForFocus.remove(widget);
widget->removeEventFilter(this);
}
}
void KPanelApplet::needsFocus(bool focus)
{
if (focus == d->hasFocus)
{
return;
}
d->hasFocus = focus;
emit requestFocus(focus);
}
bool KPanelApplet::eventFilter(QObject *o, QEvent * e)
{
if (d->watchedForFocus.find(o) != -1)
{
if (e->type() == QEvent::MouseButtonRelease ||
e->type() == QEvent::FocusIn)
{
needsFocus(true);
}
else if (e->type() == QEvent::FocusOut)
{
needsFocus(false);
}
}
return QFrame::eventFilter(o, e);
}
KSharedConfig::Ptr KPanelApplet::sharedConfig() const
{
return d->sharedConfig;
}
void KPanelApplet::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
KPanelApplet::~KPanelApplet
~KPanelApplet()
Destructor.
Definition: kpanelapplet.cpp:67
KPanelApplet::help
virtual void help()
Is called when the user selects "Help" from the applet's RMB menu.
Definition: kpanelapplet.h:281
KPanelApplet::orientationChange
virtual KDE_DEPRECATED void orientationChange(Orientation)
The orientation changed to orientation.
Definition: kpanelapplet.h:364
KPanelApplet::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: kpanelapplet.cpp:140
KPanelApplet::about
virtual void about()
Is called when the user selects "About" from the applet's RMB menu.
Definition: kpanelapplet.h:272
KPanelApplet
KDE Panel Applet class
Definition: kpanelapplet.h:97
KPanelApplet::setAlignment
void setAlignment(Alignment a)
Definition: kpanelapplet.cpp:81
KPanelApplet::alignmentChange
virtual void alignmentChange(Alignment)
The panel on which this applet resides has changed its alignment.
Definition: kpanelapplet.h:327
KPanelApplet::Type
Type
This enum describes the type of the applet.
Definition: kpanelapplet.h:106
KPanelApplet::Action
Action
This enum holds flags which can be ORed together to describe which items the context menu over the ap...
Definition: kpanelapplet.h:112
KPanelApplet::KPanelApplet
KPanelApplet(const QString &configFile, Type t=Normal, int actions=0, QWidget *parent=0, const char *name=0, WFlags f=0)
Constructs a KPanelApplet just like any other widget.
Definition: kpanelapplet.cpp:45
KPanelApplet::setCustomMenu
void setCustomMenu(const QPopupMenu *)
Use this method to set the custom menu for this applet so that it can be shown in the applet handle m...
Definition: kpanelapplet.cpp:135
KPanelApplet::setPosition
void setPosition(Position p)
Definition: kpanelapplet.cpp:74
KPanelApplet::preferences
virtual void preferences()
Is called when the user selects "Preferences" from the applet's RMB menu.
Definition: kpanelapplet.h:290
KPanelApplet::customMenu
const QPopupMenu * customMenu() const
Definition: kpanelapplet.cpp:130
KPanelApplet::orientation
Orientation orientation() const
Definition: kpanelapplet.cpp:97
KPanelApplet::popupDirection
Direction popupDirection()
A convenience method that translates the position of the applet into which direction to show a popup...
Definition: kpanelapplet.cpp:107
KPanelApplet::action
virtual void action(Action a)
Generic action dispatcher.
Definition: kpanelapplet.cpp:118
KPanelApplet::reportBug
virtual void reportBug()
Is called when the user selects "Report bug" from the applet's RMB menu.
Definition: kpanelapplet.h:300
KPanelApplet::popupDirectionChange
virtual KDE_DEPRECATED void popupDirectionChange(Direction)
The popup direction changed to direction.
Definition: kpanelapplet.h:379
KPanelApplet::needsFocus
void needsFocus(bool focus)
Call this whenever focus is needed or not needed.
Definition: kpanelapplet.cpp:162
KPanelApplet::requestFocus
void requestFocus()
Request keyboard focus from the panel.
KSharedConfig::openConfig
static KSharedConfig::Ptr openConfig(const QString &fileName, bool readOnly=false, bool bUseKDEGlobals=true)
KPanelApplet::positionChange
virtual void positionChange(Position p)
The panel on which this applet resides has changed its position.
Definition: kpanelapplet.cpp:89

KDE Home | KDE Accessibility Home | Description of Access Keys