You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
199 lines
4.7 KiB
199 lines
4.7 KiB
15 years ago
|
/*****************************************************************
|
||
|
|
||
|
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.
|
||
|
|
||
|
******************************************************************/
|
||
|
|
||
15 years ago
|
#include <tqptrlist.h>
|
||
15 years ago
|
|
||
|
#include "kpanelapplet.h"
|
||
|
#include "kpanelapplet.moc"
|
||
|
#include <kapplication.h>
|
||
|
#include <kconfig.h>
|
||
|
|
||
|
class KPanelApplet::KPanelAppletPrivate
|
||
|
{
|
||
|
public:
|
||
|
KPanelAppletPrivate()
|
||
|
: customMenu(0),
|
||
|
hasFocus(false)
|
||
|
{}
|
||
|
|
||
15 years ago
|
const TQPopupMenu* customMenu;
|
||
15 years ago
|
KSharedConfig::Ptr sharedConfig;
|
||
15 years ago
|
TQPtrList<TQObject> watchedForFocus;
|
||
15 years ago
|
bool hasFocus;
|
||
|
};
|
||
|
|
||
15 years ago
|
KPanelApplet::KPanelApplet(const TQString& configFile, Type type,
|
||
|
int actions, TQWidget *parent, const char *name, WFlags f)
|
||
|
: TQFrame(parent, name, f)
|
||
15 years ago
|
, _type(type)
|
||
|
, _position( pBottom )
|
||
14 years ago
|
, _tqalignment( LeftTop )
|
||
15 years ago
|
, _config(0)
|
||
|
, _actions(actions)
|
||
|
, d(new KPanelApplet::KPanelAppletPrivate())
|
||
|
{
|
||
|
setFrameStyle(NoFrame);
|
||
15 years ago
|
TQPalette pal(palette());
|
||
15 years ago
|
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 );
|
||
|
}
|
||
|
|
||
14 years ago
|
void KPanelApplet::tqsetAlignment( Alignment a )
|
||
15 years ago
|
{
|
||
14 years ago
|
if( _tqalignment == a ) return;
|
||
|
_tqalignment = a;
|
||
14 years ago
|
alignmentChange( a );
|
||
15 years ago
|
}
|
||
|
|
||
|
// FIXME: Remove implementation for KDE 4
|
||
|
void KPanelApplet::positionChange( Position )
|
||
|
{
|
||
|
orientationChange( orientation() );
|
||
15 years ago
|
TQResizeEvent e( size(), size() );
|
||
15 years ago
|
resizeEvent( &e );
|
||
|
popupDirectionChange( popupDirection() );
|
||
|
}
|
||
|
|
||
|
Qt::Orientation KPanelApplet::orientation() const
|
||
|
{
|
||
|
if( _position == pTop || _position == pBottom ) {
|
||
14 years ago
|
return Qt::Horizontal;
|
||
15 years ago
|
} else {
|
||
14 years ago
|
return Qt::Vertical;
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
// 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();
|
||
|
}
|
||
|
|
||
15 years ago
|
const TQPopupMenu* KPanelApplet::customMenu() const
|
||
15 years ago
|
{
|
||
|
return d->customMenu;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KPanelApplet::setCustomMenu(const TQPopupMenu* menu)
|
||
15 years ago
|
{
|
||
|
d->customMenu = menu;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KPanelApplet::watchForFocus(TQWidget* widget, bool watch)
|
||
15 years ago
|
{
|
||
|
if (!widget)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (watch)
|
||
|
{
|
||
13 years ago
|
if (d->watchedForFocus.find(TQT_TQOBJECT(widget)) == -1)
|
||
15 years ago
|
{
|
||
14 years ago
|
d->watchedForFocus.append(TQT_TQOBJECT(widget));
|
||
15 years ago
|
widget->installEventFilter(this);
|
||
|
}
|
||
|
}
|
||
13 years ago
|
else if (d->watchedForFocus.find(TQT_TQOBJECT(widget)) != -1)
|
||
15 years ago
|
{
|
||
14 years ago
|
d->watchedForFocus.remove(TQT_TQOBJECT(widget));
|
||
15 years ago
|
widget->removeEventFilter(this);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KPanelApplet::needsFocus(bool focus)
|
||
|
{
|
||
|
if (focus == d->hasFocus)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
d->hasFocus = focus;
|
||
|
emit requestFocus(focus);
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KPanelApplet::eventFilter(TQObject *o, TQEvent * e)
|
||
15 years ago
|
{
|
||
13 years ago
|
if (d->watchedForFocus.find(o) != -1)
|
||
15 years ago
|
{
|
||
15 years ago
|
if (e->type() == TQEvent::MouseButtonRelease ||
|
||
|
e->type() == TQEvent::FocusIn)
|
||
15 years ago
|
{
|
||
|
needsFocus(true);
|
||
|
}
|
||
15 years ago
|
else if (e->type() == TQEvent::FocusOut)
|
||
15 years ago
|
{
|
||
|
needsFocus(false);
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
return TQFrame::eventFilter(o, e);
|
||
15 years ago
|
}
|
||
|
|
||
|
KSharedConfig::Ptr KPanelApplet::sharedConfig() const
|
||
|
{
|
||
|
return d->sharedConfig;
|
||
|
}
|
||
|
|
||
|
void KPanelApplet::virtual_hook( int, void* )
|
||
|
{ /*BASE::virtual_hook( id, data );*/ }
|
||
|
|