Messagelib

kwindowpositioner.cpp
1/*
2 This file is part of KDE.
3
4 SPDX-FileCopyrightText: 2005 Cornelius Schumacher <schumacher@kde.org>
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
14using namespace MessageComposer;
15KWindowPositioner::KWindowPositioner(QWidget *master, QWidget *slave, Mode mode)
16 : QObject(master)
17 , mMaster(master)
18 , mSlave(slave)
19 , mMode(mode)
20{
21}
22
23void 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}
58
59#include "moc_kwindowpositioner.cpp"
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
void setX(int x)
void setY(int y)
int x() const const
int y() const const
QPoint mapToGlobal(const QPoint &pos) const const
void raise()
QScreen * screen() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.