2010-11-10 19:21:56 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2010 Thomas Lübking <thomas.luebking@web.de>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
#include "windowgeometry.h"
|
|
|
|
#include <QStringBuilder>
|
|
|
|
#include <kwinconfig.h>
|
|
|
|
#include <kconfiggroup.h>
|
|
|
|
#include <kwindowsystem.h>
|
|
|
|
#include <KActionCollection>
|
|
|
|
#include <kaction.h>
|
2011-02-17 18:35:08 +00:00
|
|
|
#include <KDE/KLocale>
|
2010-11-10 19:21:56 +00:00
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWIN_EFFECT(windowgeometry, WindowGeometry)
|
2010-11-10 19:21:56 +00:00
|
|
|
|
|
|
|
WindowGeometry::WindowGeometry()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-11-10 19:21:56 +00:00
|
|
|
iAmActivated = true;
|
|
|
|
iAmActive = false;
|
|
|
|
myResizeWindow = 0L;
|
2011-03-03 03:37:17 +00:00
|
|
|
#define myResizeString "Window geometry display, %1 and %2 are the new size," \
|
|
|
|
" %3 and %4 are pixel increments - avoid reformatting or suffixes like 'px'", \
|
|
|
|
"Width: %1 (%3)\nHeight: %2 (%4)"
|
|
|
|
#define myCoordString_0 "Window geometry display, %1 and %2 are the cartesian x and y coordinates" \
|
|
|
|
" - avoid reformatting or suffixes like 'px'", \
|
|
|
|
"X: %1\nY: %2"
|
|
|
|
#define myCoordString_1 "Window geometry display, %1 and %2 are the cartesian x and y coordinates," \
|
|
|
|
" %3 and %4 are the resp. increments - avoid reformatting or suffixes like 'px'", \
|
|
|
|
"X: %1 (%3)\nY: %2 (%4)"
|
2011-01-30 14:34:42 +00:00
|
|
|
reconfigure(ReconfigureAll);
|
2010-11-10 19:21:56 +00:00
|
|
|
QFont fnt; fnt.setBold(true); fnt.setPointSize(12);
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
myMeasure[i] = effects->effectFrame(EffectFrameUnstyled, false);
|
|
|
|
myMeasure[i]->setFont(fnt);
|
2010-11-10 19:21:56 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
myMeasure[0]->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
|
|
|
myMeasure[1]->setAlignment(Qt::AlignCenter);
|
|
|
|
myMeasure[2]->setAlignment(Qt::AlignRight | Qt::AlignBottom);
|
|
|
|
|
|
|
|
KActionCollection* actionCollection = new KActionCollection(this);
|
|
|
|
KAction* a = static_cast< KAction* >(actionCollection->addAction("WindowGeometry"));
|
|
|
|
a->setText(i18n("Toggle window geometry display (effect only)"));
|
|
|
|
a->setGlobalShortcut(KShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_F11));
|
|
|
|
connect(a, SIGNAL(triggered(bool)), this, SLOT(toggle()));
|
2011-03-13 11:41:30 +00:00
|
|
|
connect(effects, SIGNAL(windowStartUserMovedResized(EffectWindow*)), this, SLOT(slotWindowStartUserMovedResized(EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(windowFinishUserMovedResized(EffectWindow*)), this, SLOT(slotWindowFinishUserMovedResized(EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(windowStepUserMovedResized(EffectWindow*,QRect)), this, SLOT(slotWindowStepUserMovedResized(EffectWindow*,QRect)));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-10 19:21:56 +00:00
|
|
|
|
|
|
|
WindowGeometry::~WindowGeometry()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < 3; ++i)
|
2010-11-10 19:21:56 +00:00
|
|
|
delete myMeasure[i];
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-10 19:21:56 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void WindowGeometry::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
|
|
|
KConfigGroup conf = effects->effectConfig("WindowGeometry");
|
|
|
|
iHandleMoves = conf.readEntry("Move", true);
|
|
|
|
iHandleResizes = conf.readEntry("Resize", true);
|
|
|
|
}
|
2010-11-10 19:21:56 +00:00
|
|
|
|
|
|
|
void WindowGeometry::paintScreen(int mask, QRegion region, ScreenPaintData &data)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
effects->paintScreen(mask, region, data);
|
|
|
|
if (iAmActivated && iAmActive) {
|
|
|
|
for (int i = 0; i < 3; ++i)
|
2010-11-10 19:21:56 +00:00
|
|
|
myMeasure[i]->render(infiniteRegion(), 1.0, .66);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-10 19:21:56 +00:00
|
|
|
|
|
|
|
void WindowGeometry::toggle()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-11-10 19:21:56 +00:00
|
|
|
iAmActivated = !iAmActivated;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-10 19:21:56 +00:00
|
|
|
|
2011-03-13 11:41:30 +00:00
|
|
|
void WindowGeometry::slotWindowStartUserMovedResized(EffectWindow *w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-03-13 11:41:30 +00:00
|
|
|
if (!iAmActivated)
|
|
|
|
return;
|
|
|
|
if (w->isUserResize() && !iHandleResizes)
|
|
|
|
return;
|
|
|
|
if (w->isUserMove() && !iHandleMoves)
|
2010-11-10 19:21:56 +00:00
|
|
|
return;
|
|
|
|
|
2011-03-13 11:41:30 +00:00
|
|
|
iAmActive = true;
|
|
|
|
myResizeWindow = w;
|
|
|
|
myOriginalGeometry = w->geometry();
|
|
|
|
myCurrentGeometry = w->geometry();
|
|
|
|
effects->addRepaint(myCurrentGeometry.adjusted(-20, -20, 20, 20));
|
|
|
|
}
|
2010-11-10 19:21:56 +00:00
|
|
|
|
2011-03-13 11:41:30 +00:00
|
|
|
void WindowGeometry::slotWindowFinishUserMovedResized(EffectWindow *w)
|
|
|
|
{
|
|
|
|
if (iAmActive && w == myResizeWindow) {
|
2010-11-10 19:21:56 +00:00
|
|
|
iAmActive = false;
|
|
|
|
myResizeWindow = 0L;
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->addRepaint(myCurrentGeometry.adjusted(-20, -20, 20, 20));
|
|
|
|
}
|
2010-11-10 19:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline QString number(int n)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-05-13 15:37:07 +00:00
|
|
|
QString sign;
|
|
|
|
if (n >= 0) {
|
|
|
|
sign = KGlobal::locale()->positiveSign();
|
2011-08-03 05:56:30 +00:00
|
|
|
if (sign.isEmpty()) sign = '+';
|
2011-05-13 15:37:07 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
n = -n;
|
|
|
|
sign = KGlobal::locale()->negativeSign();
|
2011-08-03 05:56:30 +00:00
|
|
|
if (sign.isEmpty()) sign = '-';
|
2011-05-13 15:37:07 +00:00
|
|
|
}
|
|
|
|
return sign + QString::number(n);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 19:21:56 +00:00
|
|
|
|
2011-03-13 11:41:30 +00:00
|
|
|
void WindowGeometry::slotWindowStepUserMovedResized(EffectWindow *w, const QRect &geometry)
|
2010-11-10 19:21:56 +00:00
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
if (iAmActivated && iAmActive && w == myResizeWindow) {
|
2010-11-10 19:21:56 +00:00
|
|
|
myCurrentGeometry = geometry;
|
|
|
|
const QRect &r = geometry;
|
|
|
|
const QRect &r2 = myOriginalGeometry;
|
|
|
|
|
|
|
|
// sufficient for moves, resizes calculated otherwise
|
|
|
|
int dx = r.x() - r2.x();
|
|
|
|
int dy = r.y() - r2.y();
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2010-11-10 19:21:56 +00:00
|
|
|
// upper left ----------------------
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w->isUserResize())
|
2011-03-03 03:37:17 +00:00
|
|
|
myMeasure[0]->setText( i18nc(myCoordString_1, r.x(), r.y(), number(dx), number(dy) ) );
|
2010-11-10 19:21:56 +00:00
|
|
|
else
|
2011-03-03 03:37:17 +00:00
|
|
|
myMeasure[0]->setText( i18nc(myCoordString_0, r.x(), r.y() ) );
|
2011-01-30 14:34:42 +00:00
|
|
|
myMeasure[0]->setPosition(geometry.topLeft());
|
|
|
|
|
2010-11-10 19:21:56 +00:00
|
|
|
// center ----------------------
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w->isUserResize()) {
|
2010-11-10 19:21:56 +00:00
|
|
|
// calc width for center element, otherwise the current dx/dx remains right
|
|
|
|
dx = r.width() - r2.width();
|
|
|
|
dy = r.height() - r2.height();
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2011-03-03 03:37:17 +00:00
|
|
|
myMeasure[1]->setText( i18nc(myResizeString, r.width(), r.height(), number(dx), number(dy) ) );
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2011-01-01 09:39:02 +00:00
|
|
|
// calc width for bottomright element, superfluous otherwise
|
2010-11-10 19:21:56 +00:00
|
|
|
dx = r.right() - r2.right();
|
|
|
|
dy = r.bottom() - r2.bottom();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else
|
2011-03-03 03:37:17 +00:00
|
|
|
myMeasure[1]->setText( i18nc(myCoordString_0, number(dx), number(dy) ) );
|
2010-11-10 19:21:56 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
myMeasure[1]->setPosition(geometry.center());
|
2010-11-10 19:21:56 +00:00
|
|
|
|
|
|
|
// lower right ----------------------
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w->isUserResize())
|
2011-03-03 03:37:17 +00:00
|
|
|
myMeasure[2]->setText( i18nc(myCoordString_1, r.right(), r.bottom(), number(dx), number(dy) ) );
|
2010-11-10 19:21:56 +00:00
|
|
|
else
|
2011-03-03 03:37:17 +00:00
|
|
|
myMeasure[2]->setText( i18nc(myCoordString_0, r.right(), r.bottom() ) );
|
2011-01-30 14:34:42 +00:00
|
|
|
myMeasure[2]->setPosition(geometry.bottomRight());
|
2010-11-10 19:21:56 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->addRepaint(geometry.adjusted(-20, -20, 20, 20));
|
2010-11-10 19:21:56 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-10 19:21:56 +00:00
|
|
|
|