kpanelapplet.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <qptrlist.h>
00025
00026 #include "kpanelapplet.h"
00027 #include "kpanelapplet.moc"
00028 #include <kapplication.h>
00029 #include <kconfig.h>
00030
00031 class KPanelApplet::KPanelAppletPrivate
00032 {
00033 public:
00034 KPanelAppletPrivate()
00035 : customMenu(0),
00036 hasFocus(false)
00037 {}
00038
00039 const QPopupMenu* customMenu;
00040 KSharedConfig::Ptr sharedConfig;
00041 QPtrList<QObject> watchedForFocus;
00042 bool hasFocus;
00043 };
00044
00045 KPanelApplet::KPanelApplet(const QString& configFile, Type type,
00046 int actions, QWidget *parent, const char *name, WFlags f)
00047 : QFrame(parent, name, f)
00048 , _type(type)
00049 , _position( pBottom )
00050 , _alignment( LeftTop )
00051 , _config(0)
00052 , _actions(actions)
00053 , d(new KPanelApplet::KPanelAppletPrivate())
00054 {
00055 setFrameStyle(NoFrame);
00056 QPalette pal(palette());
00057 if(pal.active().mid() != pal.inactive().mid()){
00058 pal.setInactive(pal.active());
00059 setPalette(pal);
00060 }
00061 setBackgroundOrigin( AncestorOrigin );
00062
00063 d->sharedConfig = KSharedConfig::openConfig(configFile, kapp && kapp->config()->isImmutable());
00064 _config = d->sharedConfig;
00065 }
00066
00067 KPanelApplet::~KPanelApplet()
00068 {
00069 d->watchedForFocus.clear();
00070 needsFocus(false);
00071 delete d;
00072 }
00073
00074 void KPanelApplet::setPosition( Position p )
00075 {
00076 if( _position == p ) return;
00077 _position = p;
00078 positionChange( p );
00079 }
00080
00081 void KPanelApplet::setAlignment( Alignment a )
00082 {
00083 if( _alignment == a ) return;
00084 _alignment = a;
00085 alignmentChange( a );
00086 }
00087
00088
00089 void KPanelApplet::positionChange( Position )
00090 {
00091 orientationChange( orientation() );
00092 QResizeEvent e( size(), size() );
00093 resizeEvent( &e );
00094 popupDirectionChange( popupDirection() );
00095 }
00096
00097 Qt::Orientation KPanelApplet::orientation() const
00098 {
00099 if( _position == pTop || _position == pBottom ) {
00100 return Horizontal;
00101 } else {
00102 return Vertical;
00103 }
00104 }
00105
00106
00107 KPanelApplet::Direction KPanelApplet::popupDirection()
00108 {
00109 switch( _position ) {
00110 case pTop: return Down;
00111 case pRight: return Left;
00112 case pLeft: return Right;
00113 default:
00114 case pBottom: return Up;
00115 }
00116 }
00117
00118 void KPanelApplet::action( Action a )
00119 {
00120 if ( (a & About) )
00121 about();
00122 if ( (a & Help) )
00123 help();
00124 if ( (a & Preferences) )
00125 preferences();
00126 if ( (a & ReportBug) )
00127 reportBug();
00128 }
00129
00130 const QPopupMenu* KPanelApplet::customMenu() const
00131 {
00132 return d->customMenu;
00133 }
00134
00135 void KPanelApplet::setCustomMenu(const QPopupMenu* menu)
00136 {
00137 d->customMenu = menu;
00138 }
00139
00140 void KPanelApplet::watchForFocus(QWidget* widget, bool watch)
00141 {
00142 if (!widget)
00143 {
00144 return;
00145 }
00146
00147 if (watch)
00148 {
00149 if (d->watchedForFocus.find(widget) == -1)
00150 {
00151 d->watchedForFocus.append(widget);
00152 widget->installEventFilter(this);
00153 }
00154 }
00155 else if (d->watchedForFocus.find(widget) != -1)
00156 {
00157 d->watchedForFocus.remove(widget);
00158 widget->removeEventFilter(this);
00159 }
00160 }
00161
00162 void KPanelApplet::needsFocus(bool focus)
00163 {
00164 if (focus == d->hasFocus)
00165 {
00166 return;
00167 }
00168
00169 d->hasFocus = focus;
00170 emit requestFocus(focus);
00171 }
00172
00173 bool KPanelApplet::eventFilter(QObject *o, QEvent * e)
00174 {
00175 if (d->watchedForFocus.find(o) != -1)
00176 {
00177 if (e->type() == QEvent::MouseButtonRelease ||
00178 e->type() == QEvent::FocusIn)
00179 {
00180 needsFocus(true);
00181 }
00182 else if (e->type() == QEvent::FocusOut)
00183 {
00184 needsFocus(false);
00185 }
00186 }
00187
00188 return QFrame::eventFilter(o, e);
00189 }
00190
00191 KSharedConfig::Ptr KPanelApplet::sharedConfig() const
00192 {
00193 return d->sharedConfig;
00194 }
00195
00196 void KPanelApplet::virtual_hook( int, void* )
00197 { }
00198
|