libkdepim

overlaywidget.cpp
1 
31 #include "overlaywidget.h"
32 using namespace KPIM;
33 
34 OverlayWidget::OverlayWidget( TQWidget* alignWidget, TQWidget* parent, const char* name )
35  : TQHBox( parent, name ), mAlignWidget( 0 )
36 {
37  setAlignWidget( alignWidget );
38 }
39 
40 OverlayWidget::~OverlayWidget()
41 {
42 }
43 
44 void OverlayWidget::reposition()
45 {
46  if ( !mAlignWidget )
47  return;
48  // p is in the alignWidget's coordinates
49  TQPoint p;
50  // We are always above the alignWidget, right-aligned with it.
51  p.setX( mAlignWidget->width() - width() );
52  p.setY( -height() );
53  // Position in the toplevelwidget's coordinates
54  TQPoint pTopLevel = mAlignWidget->mapTo( topLevelWidget(), p );
55  // Position in the widget's parentWidget coordinates
56  TQPoint pParent = parentWidget()->mapFrom( topLevelWidget(), pTopLevel );
57  // Move 'this' to that position.
58  move( pParent );
59 }
60 
61 void OverlayWidget::setAlignWidget( TQWidget * w )
62 {
63  if (w == mAlignWidget)
64  return;
65 
66  if (mAlignWidget)
67  mAlignWidget->removeEventFilter(this);
68 
69  mAlignWidget = w;
70 
71  if (mAlignWidget)
72  mAlignWidget->installEventFilter(this);
73 
74  reposition();
75 }
76 
77 bool OverlayWidget::eventFilter( TQObject* o, TQEvent* e)
78 {
79  if ( TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(mAlignWidget) &&
80  ( e->type() == TQEvent::Move || e->type() == TQEvent::Resize ) ) {
81  reposition();
82  }
83  return TQFrame::eventFilter(o,e);
84 }
85 
86 void OverlayWidget::resizeEvent( TQResizeEvent* ev )
87 {
88  reposition();
89  TQFrame::resizeEvent( ev );
90 }
91 
92 #include "overlaywidget.moc"