kwin/tilinglayoutfactory.cpp

124 lines
3.5 KiB
C++
Raw Normal View History

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2009 Nikhil Marathe <nsm.nikhil@gmail.com>
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 "tilinglayoutfactory.h"
#include <QtGlobal>
#include <QList>
#include <klocale.h>
#include <kdebug.h>
#include "notifications.h"
#include "tiling/tile.h"
#include "client.h"
#include "tilinglayouts/spiral/spiral.h"
#include "tilinglayouts/columns/columns.h"
#include "tilinglayouts/floating/floating.h"
// w is the workspace pointer
#define ADD_LAYOUT( lay, ctxt_name ) \
2011-01-30 14:34:42 +00:00
case lay##Layout:\
kDebug(1212) << #lay;\
layout = new lay( w );\
layout->setLayoutType( lay##Layout );\
Notify::raise( Notify::TilingLayoutChanged, \
i18n( "Layout changed to %1", i18nc( ctxt_name ) ) ); \
break
namespace KWin
{
2011-01-30 14:34:42 +00:00
TilingLayout* TilingLayoutFactory::createLayout(int type, Workspace *w)
{
Q_ASSERT(type != FirstLayout && type != LastLayout);
TilingLayout *layout;
/* For new layouts, make a case entry here */
2011-01-30 14:34:42 +00:00
switch(type) {
case DefaultLayout: // NOTE: fall through makes first layout default
layout = createLayout(indexToLayoutIndex(options->tilingLayout()), w);
2011-01-30 14:34:42 +00:00
break;
ADD_LAYOUT(Spiral, I18N_NOOP2_NOSTRIP("Spiral tiling layout", "Spiral"));
ADD_LAYOUT(Columns, I18N_NOOP2_NOSTRIP("Two-column horizontal tiling layout", "Columns"));
ADD_LAYOUT(Floating, I18N_NOOP2_NOSTRIP("Floating layout, windows aren't tiled at all", "Floating"));
default:
kDebug(1212) << "INVALID LAYOUT!";
return NULL;
}
2011-01-30 14:34:42 +00:00
return layout;
}
// if next, goes next, otherwise previous
2011-01-30 14:34:42 +00:00
TilingLayout* TilingLayoutFactory::cycleLayout(TilingLayout *curr, bool next)
{
int type = curr->layoutType();
2011-01-30 14:34:42 +00:00
if (next) {
type++;
2011-01-30 14:34:42 +00:00
if (type >= LastLayout)
type = FirstLayout + 1;
2011-01-30 14:34:42 +00:00
} else {
type--;
2011-01-30 14:34:42 +00:00
if (type <= FirstLayout)
type = LastLayout - 1;
2011-01-30 14:34:42 +00:00
}
QList<Tile *> tiles = curr->tiles();
2011-01-30 14:34:42 +00:00
TilingLayout *l = createLayout(type, curr->workspace());
2011-01-30 14:34:42 +00:00
foreach (Tile * t, tiles) {
curr->removeTileNoArrange(t);
}
2011-01-30 14:34:42 +00:00
if (tiles.length() == 0)
return l;
// so that we don't rearrange after every call
Tile *last = tiles.takeLast();
2011-01-30 14:34:42 +00:00
foreach (Tile * t, tiles) {
l->addTileNoArrange(t);
}
2011-01-30 14:34:42 +00:00
l->addTile(last);
return l;
2011-01-30 14:34:42 +00:00
}
/**
* Returns the appropriate layout enum item
* Meant to be used with a combo box.
* This function handles the issues of DefaultL and First and Last layouts
*/
2011-01-30 14:34:42 +00:00
int TilingLayoutFactory::indexToLayoutIndex(int index)
{
int layout = DefaultLayout + index + 1;
2011-01-30 14:34:42 +00:00
if (layout >= LastLayout)
layout = DefaultLayout + 1;
2011-01-30 14:34:42 +00:00
if (layout <= FirstLayout)
layout = LastLayout - 1;
return layout;
2011-01-30 14:34:42 +00:00
}
} // end namespace