1/********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5Copyright (c) 2003, Karol Szwed <kszwed@kde.org>
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>.
19*********************************************************************/
20
21#include "geometrytip.h"
22#include <QX11Info>
23
24namespace KWin
25{
26
27GeometryTip::GeometryTip(const XSizeHints* xSizeHints):
28 QLabel(0)
29{
30 setObjectName(QLatin1String("kwingeometry"));
31 setMargin(1);
32 setIndent(0);
33 setLineWidth(1);
34 setFrameStyle(QFrame::Raised | QFrame::StyledPanel);
35 setAlignment(Qt::AlignCenter | Qt::AlignTop);
36 setWindowFlags(Qt::X11BypassWindowManagerHint);
37 sizeHints = xSizeHints;
38}
39
40GeometryTip::~GeometryTip()
41{
42}
43
44void GeometryTip::setGeometry(const QRect& geom)
45{
46 int w = geom.width();
47 int h = geom.height();
48
49 if (sizeHints) {
50 if (sizeHints->flags & PResizeInc) {
51 w = (w - sizeHints->base_width) / sizeHints->width_inc;
52 h = (h - sizeHints->base_height) / sizeHints->height_inc;
53 }
54 }
55
56 h = qMax(h, 0); // in case of isShade() and PBaseSize
57 QString pos;
58 pos.sprintf("%+d,%+d<br>(<b>%d&nbsp;x&nbsp;%d</b>)",
59 geom.x(), geom.y(), w, h);
60 setText(pos);
61 adjustSize();
62 move(geom.x() + ((geom.width() - width()) / 2),
63 geom.y() + ((geom.height() - height()) / 2));
64}
65
66} // namespace
67
68#include "geometrytip.moc"
69