~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/tilinglayoutfactory.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2009 Nikhil Marathe <nsm.nikhil@gmail.com>
 
6
 
 
7
This program is free software; you can redistribute it and/or modify
 
8
it under the terms of the GNU General Public License as published by
 
9
the Free Software Foundation; either version 2 of the License, or
 
10
(at your option) any later version.
 
11
 
 
12
This program is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License
 
18
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*********************************************************************/
 
20
 
 
21
#include "tilinglayoutfactory.h"
 
22
 
 
23
#include <QtGlobal>
 
24
#include <QList>
 
25
#include <klocale.h>
 
26
#include <kdebug.h>
 
27
 
 
28
#include "notifications.h"
 
29
#include "tile.h"
 
30
#include "client.h"
 
31
 
 
32
#include "tilinglayouts/spiral/spiral.h"
 
33
#include "tilinglayouts/columns/columns.h"
 
34
#include "tilinglayouts/floating/floating.h"
 
35
 
 
36
// w is the workspace pointer
 
37
#define ADD_LAYOUT( lay, ctxt_name ) \
 
38
    case lay##Layout:\
 
39
    kDebug(1212) << #lay;\
 
40
    layout = new lay( w );\
 
41
    layout->setLayoutType( lay##Layout );\
 
42
    Notify::raise( Notify::TilingLayoutChanged, \
 
43
                   i18n( "Layout changed to %1", i18nc( ctxt_name ) ) ); \
 
44
    break
 
45
 
 
46
namespace KWin
 
47
{
 
48
 
 
49
TilingLayout* TilingLayoutFactory::createLayout(int type, Workspace *w)
 
50
{
 
51
    Q_ASSERT(type != FirstLayout && type != LastLayout);
 
52
    TilingLayout *layout;
 
53
 
 
54
    /* For new layouts, make a case entry here */
 
55
    switch(type) {
 
56
    case DefaultLayout: // NOTE: fall through makes first layout default
 
57
        layout = createLayout(indexToLayoutIndex(options->tilingLayout), w);
 
58
        break;
 
59
 
 
60
        ADD_LAYOUT(Spiral, I18N_NOOP2_NOSTRIP("Spiral tiling layout", "Spiral"));
 
61
        ADD_LAYOUT(Columns, I18N_NOOP2_NOSTRIP("Two-column horizontal tiling layout", "Columns"));
 
62
        ADD_LAYOUT(Floating, I18N_NOOP2_NOSTRIP("Floating layout, windows aren't tiled at all", "Floating"));
 
63
 
 
64
    default:
 
65
        kDebug(1212) << "INVALID LAYOUT!";
 
66
        return NULL;
 
67
    }
 
68
    return layout;
 
69
}
 
70
 
 
71
// if next, goes next, otherwise previous
 
72
TilingLayout* TilingLayoutFactory::cycleLayout(TilingLayout *curr, bool next)
 
73
{
 
74
    int type = curr->layoutType();
 
75
 
 
76
    if (next) {
 
77
        type++;
 
78
 
 
79
        if (type >= LastLayout)
 
80
            type = FirstLayout + 1;
 
81
    } else {
 
82
        type--;
 
83
 
 
84
        if (type <= FirstLayout)
 
85
            type = LastLayout - 1;
 
86
    }
 
87
 
 
88
    QList<Tile *> tiles = curr->tiles();
 
89
 
 
90
    TilingLayout *l = createLayout(type, curr->workspace());
 
91
 
 
92
    foreach (Tile * t, tiles) {
 
93
        curr->removeTileNoArrange(t);
 
94
    }
 
95
 
 
96
    if (tiles.length() == 0)
 
97
        return l;
 
98
 
 
99
    // so that we don't rearrange after every call
 
100
    Tile *last = tiles.takeLast();
 
101
    foreach (Tile * t, tiles) {
 
102
        l->addTileNoArrange(t);
 
103
    }
 
104
    l->addTile(last);
 
105
 
 
106
    return l;
 
107
}
 
108
 
 
109
/**
 
110
 * Returns the appropriate layout enum item
 
111
 * Meant to be used with a combo box.
 
112
 * This function handles the issues of DefaultL and First and Last layouts
 
113
 */
 
114
int TilingLayoutFactory::indexToLayoutIndex(int index)
 
115
{
 
116
    int layout = DefaultLayout + index + 1;
 
117
    if (layout >= LastLayout)
 
118
        layout = DefaultLayout + 1;
 
119
    if (layout <= FirstLayout)
 
120
        layout = LastLayout - 1;
 
121
    return layout;
 
122
}
 
123
} // end namespace