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 #include <QScreen>
13 
14 using namespace MessageComposer;
15 KWindowPositioner::KWindowPositioner(QWidget *master, QWidget *slave, Mode mode)
16  : QObject(master)
17  , mMaster(master)
18  , mSlave(slave)
19  , mMode(mode)
20 {
21 }
22 
23 void KWindowPositioner::reposition()
24 {
25  QPoint relativePos;
26  if (mMode == Right) {
27  relativePos = QPoint(mMaster->width(), 0);
28  } else if (mMode == Bottom) {
29  relativePos = QPoint(mMaster->width() - mSlave->frameGeometry().width(), mMaster->height());
30  } else {
31  qCCritical(MESSAGECOMPOSER_LOG) << "KWindowPositioner: Illegal mode";
32  }
33  QPoint pos = mMaster->mapToGlobal(relativePos);
34 
35  // fix position to avoid hiding parts of the window (needed especially when not using KWin)
36  const QRect desktopRect(mMaster->screen()->availableGeometry());
37  if ((pos.x() + mSlave->frameGeometry().width()) > desktopRect.width()) {
38  pos.setX(desktopRect.width() - mSlave->frameGeometry().width());
39  }
40  if ((pos.y() + mSlave->frameGeometry().height()) > desktopRect.height()) {
41  pos.setY(desktopRect.height() - mSlave->frameGeometry().height() - mMaster->height());
42  }
43  qCDebug(MESSAGECOMPOSER_LOG) << mMaster->pos() << mMaster->mapToGlobal(mMaster->pos()) << pos.y() << (mMaster->pos().y() - pos.y())
44  << mSlave->frameGeometry().height();
45  if (mMode == Bottom && mMaster->mapToGlobal(mMaster->pos()).y() > pos.y() && (mMaster->pos().y() - pos.y()) < mSlave->frameGeometry().height()) {
46  pos.setY(mMaster->mapToGlobal(QPoint(0, -mSlave->frameGeometry().height())).y());
47  }
48  if (pos.x() < desktopRect.left()) {
49  pos.setX(desktopRect.left());
50  }
51  if (pos.y() < desktopRect.top()) {
52  pos.setY(desktopRect.top());
53  }
54 
55  mSlave->move(pos);
56  mSlave->raise();
57 }
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
int x() const const
int y() const const
void setX(int x)
void setY(int y)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Mar 24 2023 04:08:31 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.