Build with non-standard boost locations.
[kdepim.git] / messagecomposer / kwindowpositioner.cpp
blobebbff1aa367542414a4432b0535138a23f31680d
1 /*
2 This file is part of KDE.
4 Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
23 #include "kwindowpositioner.h"
25 #include <kdebug.h>
27 #include <QWidget>
28 #include <QApplication>
29 #include <QDesktopWidget>
31 KWindowPositioner::KWindowPositioner( QWidget *master, QWidget *slave,
32 Mode mode )
33 : QObject( master ), mMaster( master ), mSlave( slave ), mMode( mode )
37 void KWindowPositioner::reposition()
39 QPoint relativePos;
40 if ( mMode == Right ) {
41 relativePos = QPoint( mMaster->width(), 0 );
42 } else if ( mMode == Bottom ) {
43 relativePos = QPoint( mMaster->width() - mSlave->frameGeometry().width(),
44 mMaster->height() );
45 } else {
46 kError() <<"KWindowPositioner: Illegal mode";
48 QPoint pos = mMaster->mapToGlobal( relativePos );
50 // fix position to avoid hiding parts of the window (needed especially when not using KWin)
51 const QRect desktopRect( qApp->desktop()->availableGeometry( mMaster ) );
52 if ( ( pos.x() + mSlave->frameGeometry().width() ) > desktopRect.width() )
53 pos.setX( desktopRect.width() - mSlave->frameGeometry().width() );
54 if ( ( pos.y() + mSlave->frameGeometry().height() ) > desktopRect.height() )
55 pos.setY( desktopRect.height() - mSlave->frameGeometry().height() - mMaster->height() );
56 kDebug() << mMaster->pos() << mMaster->mapToGlobal(mMaster->pos()) << pos.y() << (mMaster->pos().y() - pos.y()) << mSlave->frameGeometry().height();
57 if ( mMode == Bottom && mMaster->mapToGlobal(mMaster->pos()).y() > pos.y() && (mMaster->pos().y() - pos.y()) < mSlave->frameGeometry().height() ) {
58 pos.setY( mMaster->mapToGlobal( QPoint( 0, -mSlave->frameGeometry().height() ) ).y() );
60 if ( pos.x() < desktopRect.left() )
61 pos.setX( desktopRect.left() );
62 if ( pos.y() < desktopRect.top() )
63 pos.setY( desktopRect.top() );
65 mSlave->move( pos );
66 mSlave->raise();
69 #include "kwindowpositioner.moc"