~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to messagecomposer/kwindowpositioner.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This file is part of KDE.
 
3
 
 
4
    Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org>
 
5
 
 
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.
 
10
    
 
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.
 
15
    
 
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.
 
20
*/
 
21
 
 
22
 
 
23
#include "kwindowpositioner.h"
 
24
 
 
25
#include <kdebug.h>
 
26
 
 
27
#include <QWidget>
 
28
#include <QApplication>
 
29
#include <QDesktopWidget>
 
30
 
 
31
KWindowPositioner::KWindowPositioner( QWidget *master, QWidget *slave,
 
32
  Mode mode )
 
33
  : QObject( master ), mMaster( master ), mSlave( slave ), mMode( mode )
 
34
{
 
35
}
 
36
 
 
37
void KWindowPositioner::reposition()
 
38
{
 
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";
 
47
  }
 
48
  QPoint pos = mMaster->mapToGlobal( relativePos );
 
49
  
 
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() );
 
59
  }
 
60
  if ( pos.x() < desktopRect.left() )
 
61
    pos.setX( desktopRect.left() );
 
62
  if ( pos.y() < desktopRect.top() )
 
63
    pos.setY( desktopRect.top() );
 
64
 
 
65
  mSlave->move( pos );
 
66
  mSlave->raise();
 
67
}
 
68
 
 
69
#include "kwindowpositioner.moc"