overlaywidget.cpp
00001 00031 #include "overlaywidget.h" 00032 using namespace KPIM; 00033 00034 OverlayWidget::OverlayWidget( TQWidget* alignWidget, TQWidget* parent, const char* name ) 00035 : TQHBox( parent, name ), mAlignWidget( 0 ) 00036 { 00037 setAlignWidget( alignWidget ); 00038 } 00039 00040 OverlayWidget::~OverlayWidget() 00041 { 00042 } 00043 00044 void OverlayWidget::reposition() 00045 { 00046 if ( !mAlignWidget ) 00047 return; 00048 // p is in the alignWidget's coordinates 00049 TQPoint p; 00050 // We are always above the alignWidget, right-aligned with it. 00051 p.setX( mAlignWidget->width() - width() ); 00052 p.setY( -height() ); 00053 // Position in the toplevelwidget's coordinates 00054 TQPoint pTopLevel = mAlignWidget->mapTo( topLevelWidget(), p ); 00055 // Position in the widget's parentWidget coordinates 00056 TQPoint pParent = parentWidget()->mapFrom( topLevelWidget(), pTopLevel ); 00057 // Move 'this' to that position. 00058 move( pParent ); 00059 } 00060 00061 void OverlayWidget::setAlignWidget( TQWidget * w ) 00062 { 00063 if (w == mAlignWidget) 00064 return; 00065 00066 if (mAlignWidget) 00067 mAlignWidget->removeEventFilter(this); 00068 00069 mAlignWidget = w; 00070 00071 if (mAlignWidget) 00072 mAlignWidget->installEventFilter(this); 00073 00074 reposition(); 00075 } 00076 00077 bool OverlayWidget::eventFilter( TQObject* o, TQEvent* e) 00078 { 00079 if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(mAlignWidget) && 00080 ( e->type() == TQEvent::Move || e->type() == TQEvent::Resize ) ) { 00081 reposition(); 00082 } 00083 return TQFrame::eventFilter(o,e); 00084 } 00085 00086 void OverlayWidget::resizeEvent( TQResizeEvent* ev ) 00087 { 00088 reposition(); 00089 TQFrame::resizeEvent( ev ); 00090 } 00091 00092 #include "overlaywidget.moc"