libtdepim

overlaywidget.cpp
1/*
2 * overlaywidget.h
3 *
4 * Copyright (c) 2004 David Faure <faure@kde.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 * In addition, as a special exception, the copyright holders give
20 * permission to link the code of this program with any edition of
21 * the TQt library by Trolltech AS, Norway (or with modified versions
22 * of TQt that use the same license as TQt), and distribute linked
23 * combinations including the two. You must obey the GNU General
24 * Public License in all respects for all of the code used other than
25 * TQt. If you modify this file, you may extend this exception to
26 * your version of the file, but you are not obligated to do so. If
27 * you do not wish to do so, delete this exception statement from
28 * your version.
29 */
30
31#include "overlaywidget.h"
32using namespace KPIM;
33
34OverlayWidget::OverlayWidget( TQWidget* alignWidget, TQWidget* parent, const char* name )
35 : TQHBox( parent, name ), mAlignWidget( 0 )
36{
37 setAlignWidget( alignWidget );
38}
39
40OverlayWidget::~OverlayWidget()
41{
42}
43
44void 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
61void 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
77bool OverlayWidget::eventFilter( TQObject* o, TQEvent* e)
78{
79 if ( o == mAlignWidget &&
80 ( e->type() == TQEvent::Move || e->type() == TQEvent::Resize ) ) {
81 reposition();
82 }
83 return TQFrame::eventFilter(o,e);
84}
85
86void OverlayWidget::resizeEvent( TQResizeEvent* ev )
87{
88 reposition();
89 TQFrame::resizeEvent( ev );
90}
91
92#include "overlaywidget.moc"
TDEPIM classes for drag and drop of mails.