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

« back to all changes in this revision

Viewing changes to kwin/kcmkwin/kwindesktop/desktopnameswidget.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 Martin Gräßlin <kde@martin-graesslin.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 "desktopnameswidget.h"
 
22
#include "main.h"
 
23
 
 
24
#include <QLabel>
 
25
#include <QGridLayout>
 
26
 
 
27
#include <KLocale>
 
28
#include <KLineEdit>
 
29
 
 
30
namespace KWin
 
31
{
 
32
 
 
33
DesktopNamesWidget::DesktopNamesWidget(QWidget *parent)
 
34
    : QWidget(parent)
 
35
    , m_maxDesktops(0)
 
36
{
 
37
    m_namesLayout = new QGridLayout;
 
38
    m_namesLayout->setMargin(0);
 
39
 
 
40
    setLayout(m_namesLayout);
 
41
}
 
42
 
 
43
DesktopNamesWidget::~DesktopNamesWidget()
 
44
{
 
45
}
 
46
 
 
47
void DesktopNamesWidget::numberChanged(int number)
 
48
{
 
49
    if ((number < 1) || (number > m_maxDesktops))
 
50
        return;
 
51
    if (m_nameInputs.size() != number) {
 
52
        if (number < m_nameInputs.size()) {
 
53
            // remove widgets
 
54
            while (number != m_nameInputs.size()) {
 
55
                KLineEdit* edit = m_nameInputs.last();
 
56
                m_nameInputs.removeLast();
 
57
                delete edit;
 
58
                QLabel* label = m_nameLabels.last();
 
59
                m_nameLabels.removeLast();
 
60
                delete label;
 
61
            }
 
62
        } else {
 
63
            // add widgets
 
64
            while (number != m_nameInputs.size()) {
 
65
                int desktop = m_nameInputs.size();
 
66
                QLabel* label = new QLabel(i18n("Desktop %1:", desktop + 1), this);
 
67
                KLineEdit* edit = new KLineEdit(this);
 
68
                label->setWhatsThis(i18n("Here you can enter the name for desktop %1", desktop + 1));
 
69
                edit->setWhatsThis(i18n("Here you can enter the name for desktop %1", desktop + 1));
 
70
 
 
71
                m_namesLayout->addWidget(label, desktop % 10, 0 + 2 *(desktop >= 10), 1, 1);
 
72
                m_namesLayout->addWidget(edit, desktop % 10, 1 + 2 *(desktop >= 10), 1, 1);
 
73
                m_nameInputs << edit;
 
74
                m_nameLabels << label;
 
75
 
 
76
                setDefaultName(desktop + 1);
 
77
                if (desktop > 1) {
 
78
                    setTabOrder(m_nameInputs[desktop - 1], m_nameInputs[desktop]);
 
79
                }
 
80
                connect(edit, SIGNAL(textChanged(const QString&)), SIGNAL(changed()));
 
81
            }
 
82
        }
 
83
    }
 
84
}
 
85
 
 
86
QString DesktopNamesWidget::name(int desktop)
 
87
{
 
88
    if ((desktop < 1) || (desktop > m_maxDesktops) || (desktop > m_nameInputs.size()))
 
89
        return QString();
 
90
    return m_nameInputs[ desktop -1 ]->text();
 
91
}
 
92
 
 
93
 
 
94
void DesktopNamesWidget::setName(int desktop, QString desktopName)
 
95
{
 
96
    if ((desktop < 1) || (desktop > m_maxDesktops) || (desktop > m_nameInputs.size()))
 
97
        return;
 
98
    m_nameInputs[ desktop-1 ]->setText(desktopName);
 
99
}
 
100
 
 
101
void DesktopNamesWidget::setDefaultName(int desktop)
 
102
{
 
103
    if ((desktop < 1) || (desktop > m_maxDesktops))
 
104
        return;
 
105
    QString name = m_desktopConfig->cachedDesktopName(desktop);
 
106
    if (name.isEmpty())
 
107
        name = i18n("Desktop %1", desktop);
 
108
    m_nameInputs[ desktop -1 ]->setText(name);
 
109
}
 
110
 
 
111
 
 
112
void DesktopNamesWidget::setMaxDesktops(int maxDesktops)
 
113
{
 
114
    m_maxDesktops = maxDesktops;
 
115
}
 
116
 
 
117
void DesktopNamesWidget::setDesktopConfig(KWinDesktopConfig* desktopConfig)
 
118
{
 
119
    m_desktopConfig = desktopConfig;
 
120
}
 
121
 
 
122
} // namespace
 
123
 
 
124
#include "desktopnameswidget.moc"