2009-07-12 12:21:57 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
2013-03-12 12:17:53 +00:00
|
|
|
Copyright (C) 2009 Martin Gräßlin <mgraesslin@kde.org>
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
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 "desktopnameswidget.h"
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QGridLayout>
|
|
|
|
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KLocalizedString>
|
2009-07-12 12:21:57 +00:00
|
|
|
#include <KLineEdit>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
DesktopNamesWidget::DesktopNamesWidget(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, m_maxDesktops(0)
|
2013-04-29 16:14:50 +00:00
|
|
|
, m_desktopConfig(0)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-07-12 12:21:57 +00:00
|
|
|
m_namesLayout = new QGridLayout;
|
2011-01-30 14:34:42 +00:00
|
|
|
m_namesLayout->setMargin(0);
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
setLayout(m_namesLayout);
|
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
DesktopNamesWidget::~DesktopNamesWidget()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void DesktopNamesWidget::numberChanged(int number)
|
|
|
|
{
|
|
|
|
if ((number < 1) || (number > m_maxDesktops))
|
2009-07-12 12:21:57 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_nameInputs.size() != number) {
|
|
|
|
if (number < m_nameInputs.size()) {
|
2009-07-12 12:21:57 +00:00
|
|
|
// remove widgets
|
2011-01-30 14:34:42 +00:00
|
|
|
while (number != m_nameInputs.size()) {
|
2009-07-12 12:21:57 +00:00
|
|
|
KLineEdit* edit = m_nameInputs.last();
|
|
|
|
m_nameInputs.removeLast();
|
|
|
|
delete edit;
|
|
|
|
QLabel* label = m_nameLabels.last();
|
|
|
|
m_nameLabels.removeLast();
|
|
|
|
delete label;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2009-07-12 12:21:57 +00:00
|
|
|
// add widgets
|
2011-01-30 14:34:42 +00:00
|
|
|
while (number != m_nameInputs.size()) {
|
2009-07-12 12:21:57 +00:00
|
|
|
int desktop = m_nameInputs.size();
|
2011-01-30 14:34:42 +00:00
|
|
|
QLabel* label = new QLabel(i18n("Desktop %1:", desktop + 1), this);
|
|
|
|
KLineEdit* edit = new KLineEdit(this);
|
|
|
|
label->setWhatsThis(i18n("Here you can enter the name for desktop %1", desktop + 1));
|
|
|
|
edit->setWhatsThis(i18n("Here you can enter the name for desktop %1", desktop + 1));
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
m_namesLayout->addWidget(label, desktop % 10, 0 + 2 *(desktop >= 10), 1, 1);
|
|
|
|
m_namesLayout->addWidget(edit, desktop % 10, 1 + 2 *(desktop >= 10), 1, 1);
|
2009-07-12 12:21:57 +00:00
|
|
|
m_nameInputs << edit;
|
|
|
|
m_nameLabels << label;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
setDefaultName(desktop + 1);
|
|
|
|
if (desktop > 1) {
|
|
|
|
setTabOrder(m_nameInputs[desktop - 1], m_nameInputs[desktop]);
|
2009-07-12 12:21:57 +00:00
|
|
|
}
|
2011-08-17 21:51:55 +00:00
|
|
|
connect(edit, SIGNAL(textChanged(QString)), SIGNAL(changed()));
|
2009-07-12 12:21:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
QString DesktopNamesWidget::name(int desktop)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if ((desktop < 1) || (desktop > m_maxDesktops) || (desktop > m_nameInputs.size()))
|
2009-07-12 12:21:57 +00:00
|
|
|
return QString();
|
|
|
|
return m_nameInputs[ desktop -1 ]->text();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void DesktopNamesWidget::setName(int desktop, QString desktopName)
|
|
|
|
{
|
|
|
|
if ((desktop < 1) || (desktop > m_maxDesktops) || (desktop > m_nameInputs.size()))
|
2009-07-12 12:21:57 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
m_nameInputs[ desktop-1 ]->setText(desktopName);
|
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void DesktopNamesWidget::setDefaultName(int desktop)
|
|
|
|
{
|
|
|
|
if ((desktop < 1) || (desktop > m_maxDesktops))
|
2009-07-12 12:21:57 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
QString name = m_desktopConfig->cachedDesktopName(desktop);
|
|
|
|
if (name.isEmpty())
|
2009-07-12 12:21:57 +00:00
|
|
|
name = i18n("Desktop %1", desktop);
|
2011-01-30 14:34:42 +00:00
|
|
|
m_nameInputs[ desktop -1 ]->setText(name);
|
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DesktopNamesWidget::setMaxDesktops(int maxDesktops)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-07-12 12:21:57 +00:00
|
|
|
m_maxDesktops = maxDesktops;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void DesktopNamesWidget::setDesktopConfig(KWinDesktopConfig* desktopConfig)
|
|
|
|
{
|
2009-07-12 12:21:57 +00:00
|
|
|
m_desktopConfig = desktopConfig;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-12 12:21:57 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#include "desktopnameswidget.moc"
|