deskflow/src/lib/gui/config/Screen.cpp

132 lines
3.9 KiB
C++
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* Deskflow -- mouse and keyboard sharing utility
* Copyright (C) 2012 Symless Ltd.
2012-06-10 16:50:54 +00:00
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
2012-06-10 16:50:54 +00:00
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
2012-06-10 16:50:54 +00:00
* This package 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 "Screen.h"
#include "config/ScreenConfig.h"
2012-06-10 16:50:54 +00:00
using namespace deskflow::gui::proxy;
using enum ScreenConfig::Modifier;
using enum ScreenConfig::SwitchCorner;
using enum ScreenConfig::Fix;
2012-06-10 16:50:54 +00:00
Screen::Screen()
{
init();
}
Screen::Screen(const QString &name)
{
init();
setName(name);
2012-06-10 16:50:54 +00:00
}
void Screen::init()
{
name().clear();
aliases().clear();
modifiers().clear();
switchCorners().clear();
fixes().clear();
setSwitchCornerSize(0);
// m_Modifiers, m_SwitchCorners and m_Fixes are QLists we use like fixed-size
// arrays, thus we need to make sure to fill them with the required number of
// elements.
for (int i = 0; i < static_cast<int>(NumModifiers); i++)
modifiers() << i;
for (int i = 0; i < static_cast<int>(NumSwitchCorners); i++)
switchCorners() << false;
for (int i = 0; i < static_cast<int>(NumFixes); i++)
fixes() << false;
2012-06-10 16:50:54 +00:00
}
void Screen::loadSettings(QSettingsProxy &settings)
{
setName(settings.value("name").toString());
2012-06-10 16:50:54 +00:00
if (name().isEmpty())
return;
2012-06-10 16:50:54 +00:00
setSwitchCornerSize(settings.value("switchCornerSize").toInt());
2012-06-10 16:50:54 +00:00
readSettings(settings, aliases(), "alias", QString(""));
readSettings(settings, modifiers(), "modifier", static_cast<int>(DefaultMod), static_cast<int>(NumModifiers));
readSettings(settings, switchCorners(), "switchCorner", 0, static_cast<int>(NumSwitchCorners));
readSettings(settings, fixes(), "fix", 0, static_cast<int>(NumFixes));
2012-06-10 16:50:54 +00:00
}
void Screen::saveSettings(QSettingsProxy &settings) const
{
settings.setValue("name", name());
2012-06-10 16:50:54 +00:00
if (name().isEmpty())
return;
2012-06-10 16:50:54 +00:00
settings.setValue("switchCornerSize", switchCornerSize());
2012-06-10 16:50:54 +00:00
writeSettings(settings, aliases(), "alias");
writeSettings(settings, modifiers(), "modifier");
writeSettings(settings, switchCorners(), "switchCorner");
writeSettings(settings, fixes(), "fix");
2012-06-10 16:50:54 +00:00
}
QTextStream &Screen::writeScreensSection(QTextStream &outStream) const
{
outStream << "\t" << name() << ":" << Qt::endl;
2012-06-10 16:50:54 +00:00
for (int i = 0; i < modifiers().size(); i++)
if (modifier(i) != i)
outStream << "\t\t" << modifierName(i) << " = " << modifierName(modifier(i)) << Qt::endl;
2012-06-10 16:50:54 +00:00
for (int i = 0; i < fixes().size(); i++)
outStream << "\t\t" << fixName(i) << " = " << (fixes()[i] ? "true" : "false") << Qt::endl;
2012-06-10 16:50:54 +00:00
outStream << "\t\t"
<< "switchCorners = none ";
for (int i = 0; i < switchCorners().size(); i++)
if (switchCorners()[i])
outStream << "+" << switchCornerName(i) << " ";
outStream << Qt::endl;
2012-06-10 16:50:54 +00:00
outStream << "\t\t"
<< "switchCornerSize = " << switchCornerSize() << Qt::endl;
2012-06-10 16:50:54 +00:00
return outStream;
2012-06-10 16:50:54 +00:00
}
QTextStream &Screen::writeAliasesSection(QTextStream &outStream) const
{
if (!aliases().isEmpty()) {
outStream << "\t" << name() << ":" << Qt::endl;
2012-06-10 16:50:54 +00:00
for (const QString &alias : aliases())
outStream << "\t\t" << alias << Qt::endl;
}
2012-06-10 16:50:54 +00:00
return outStream;
2012-06-10 16:50:54 +00:00
}
bool Screen::operator==(const Screen &screen) const
{
return m_Name == screen.m_Name && m_Aliases == screen.m_Aliases && m_Modifiers == screen.m_Modifiers &&
m_SwitchCorners == screen.m_SwitchCorners && m_SwitchCornerSize == screen.m_SwitchCornerSize &&
m_Fixes == screen.m_Fixes && m_Swapped == screen.m_Swapped && m_isServer == screen.m_isServer;
}