Messagelib

kwindowpositioner.cpp
1 /*
2  This file is part of KDE.
3 
4  SPDX-FileCopyrightText: 2005 Cornelius Schumacher <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "kwindowpositioner.h"
10 
11 #include "messagecomposer_debug.h"
12 
13 #include <QApplication>
14 #include <QDesktopWidget>
15 
16 using namespace MessageComposer;
17 KWindowPositioner::KWindowPositioner(QWidget *master, QWidget *slave, Mode mode)
18  : QObject(master)
19  , mMaster(master)
20  , mSlave(slave)
21  , mMode(mode)
22 {
23 }
24 
25 void KWindowPositioner::reposition()
26 {
27  QPoint relativePos;
28  if (mMode == Right) {
29  relativePos = QPoint(mMaster->width(), 0);
30  } else if (mMode == Bottom) {
31  relativePos = QPoint(mMaster->width() - mSlave->frameGeometry().width(), mMaster->height());
32  } else {
33  qCCritical(MESSAGECOMPOSER_LOG) << "KWindowPositioner: Illegal mode";
34  }
35  QPoint pos = mMaster->mapToGlobal(relativePos);
36 
37  // fix position to avoid hiding parts of the window (needed especially when not using KWin)
38  const QRect desktopRect(qApp->desktop()->availableGeometry(mMaster));
39  if ((pos.x() + mSlave->frameGeometry().width()) > desktopRect.width()) {
40  pos.setX(desktopRect.width() - mSlave->frameGeometry().width());
41  }
42  if ((pos.y() + mSlave->frameGeometry().height()) > desktopRect.height()) {
43  pos.setY(desktopRect.height() - mSlave->frameGeometry().height() - mMaster->height());
44  }
45  qCDebug(MESSAGECOMPOSER_LOG) << mMaster->pos() << mMaster->mapToGlobal(mMaster->pos()) << pos.y() << (mMaster->pos().y() - pos.y())
46  << mSlave->frameGeometry().height();
47  if (mMode == Bottom && mMaster->mapToGlobal(mMaster->pos()).y() > pos.y() && (mMaster->pos().y() - pos.y()) < mSlave->frameGeometry().height()) {
48  pos.setY(mMaster->mapToGlobal(QPoint(0, -mSlave->frameGeometry().height())).y());
49  }
50  if (pos.x() < desktopRect.left()) {
51  pos.setX(desktopRect.left());
52  }
53  if (pos.y() < desktopRect.top()) {
54  pos.setY(desktopRect.top());
55  }
56 
57  mSlave->move(pos);
58  mSlave->raise();
59 }
int x() const const
int y() const const
Right
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
void setX(int x)
void setY(int y)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Dec 2 2021 23:06:08 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.