kpanelapplet.cpp
00001 /***************************************************************** 00002 00003 Copyright (c) 2000 Matthias Elter 00004 00005 Permission is hereby granted, free of charge, to any person obtaining a copy 00006 of this software and associated documentation files (the "Software"), to deal 00007 in the Software without restriction, including without limitation the rights 00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 copies of the Software, and to permit persons to whom the Software is 00010 furnished to do so, subject to the following conditions: 00011 00012 The above copyright notice and this permission notice shall be included in 00013 all copies or substantial portions of the Software. 00014 00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 00019 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00020 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00021 00022 ******************************************************************/ 00023 00024 #include <tqptrlist.h> 00025 00026 #include "kpanelapplet.h" 00027 #include "kpanelapplet.moc" 00028 #include <tdeapplication.h> 00029 #include <tdeconfig.h> 00030 00031 class KPanelApplet::KPanelAppletPrivate 00032 { 00033 public: 00034 KPanelAppletPrivate() 00035 : customMenu(0), 00036 hasFocus(false) 00037 {} 00038 00039 const TQPopupMenu* customMenu; 00040 TDESharedConfig::Ptr sharedConfig; 00041 TQPtrList<TQObject> watchedForFocus; 00042 bool hasFocus; 00043 }; 00044 00045 KPanelApplet::KPanelApplet(const TQString& configFile, Type type, 00046 int actions, TQWidget *parent, const char *name, WFlags f) 00047 : TQFrame(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 TQPalette 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 = TDESharedConfig::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 // FIXME: Remove implementation for KDE 4 00089 void KPanelApplet::positionChange( Position ) 00090 { 00091 orientationChange( orientation() ); 00092 TQResizeEvent 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 Qt::Horizontal; 00101 } else { 00102 return Qt::Vertical; 00103 } 00104 } 00105 00106 // FIXME: Remove for KDE 4 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 TQPopupMenu* KPanelApplet::customMenu() const 00131 { 00132 return d->customMenu; 00133 } 00134 00135 void KPanelApplet::setCustomMenu(const TQPopupMenu* menu) 00136 { 00137 d->customMenu = menu; 00138 } 00139 00140 void KPanelApplet::watchForFocus(TQWidget* widget, bool watch) 00141 { 00142 if (!widget) 00143 { 00144 return; 00145 } 00146 00147 if (watch) 00148 { 00149 if (d->watchedForFocus.find(TQT_TQOBJECT(widget)) == -1) 00150 { 00151 d->watchedForFocus.append(TQT_TQOBJECT(widget)); 00152 widget->installEventFilter(this); 00153 } 00154 } 00155 else if (d->watchedForFocus.find(TQT_TQOBJECT(widget)) != -1) 00156 { 00157 d->watchedForFocus.remove(TQT_TQOBJECT(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(TQObject *o, TQEvent * e) 00174 { 00175 if (d->watchedForFocus.find(o) != -1) 00176 { 00177 if (e->type() == TQEvent::MouseButtonRelease || 00178 e->type() == TQEvent::FocusIn) 00179 { 00180 needsFocus(true); 00181 } 00182 else if (e->type() == TQEvent::FocusOut) 00183 { 00184 needsFocus(false); 00185 } 00186 } 00187 00188 return TQFrame::eventFilter(o, e); 00189 } 00190 00191 TDESharedConfig::Ptr KPanelApplet::sharedConfig() const 00192 { 00193 return d->sharedConfig; 00194 } 00195 00196 void KPanelApplet::virtual_hook( int, void* ) 00197 { /*BASE::virtual_hook( id, data );*/ } 00198