From 1a4f88dc6d9116be6e38e70eef82a13e67173171 Mon Sep 17 00:00:00 2001 From: na Date: Thu, 26 Jan 2017 20:58:39 +0100 Subject: changed namespace --- src/app.cpp | 162 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/app.h | 69 ++++++++++++++++++++++++ src/lead.cpp | 154 ------------------------------------------------------ src/lead.h | 61 ---------------------- src/main.cpp | 8 +-- src/sensor.cpp | 4 +- src/sensor.h | 4 +- 7 files changed, 242 insertions(+), 220 deletions(-) create mode 100644 src/app.cpp create mode 100644 src/app.h delete mode 100644 src/lead.cpp delete mode 100644 src/lead.h (limited to 'src') diff --git a/src/app.cpp b/src/app.cpp new file mode 100644 index 0000000..1a34777 --- /dev/null +++ b/src/app.cpp @@ -0,0 +1,162 @@ +/* + +MIT License + +Copyright (c) 2017 Noah Andreas + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + + +#include "app.h" +#include "sensor.h" +#include +#include +#include + + +namespace Lead { + + +App::App(int &argc, char** argv) : + QApplication(argc, argv), + settings("lead", "lead"), + watcher() +{ + loadScreens(); + watchSettings(); +} + + +App::~App() +{ + qDeleteAll(sensors); +} + + +void +App::watchSettings() +{ + watcher.addPath(settings.fileName()); + + connect(&watcher, SIGNAL(fileChanged(QString)), this, SLOT(fileChanged(QString))); +} + + +void +App::fileChanged(QString fileName) +{ + qDebug() << "App::fileChanged() fileName: " << fileName; + + // this reloads the settings from the file + settings.sync(); + + // some editors dont update but delete/create the config file, in this + // case our watcher loses the file so we have to add it again + watcher.addPath( fileName ); + + // simply reload everything + reloadScreens(); +} + + +void +App::screenAdded(QScreen* screen) +{ + loadScreen(screen); +} + + +void +App::screenRemoved(QScreen* screen) +{ + // thats the easiest way + reloadScreens(); +} + + +void +App::reloadScreens() +{ + qDeleteAll(sensors); + sensors.clear(); + + loadScreens(); +} + + +void +App::loadScreens() +{ + foreach (QScreen* screen, screens()) + { + loadScreen(screen); + } +} + + +void +App::loadScreen(QScreen* screen) +{ + qDebug() << "App::loadScreen() " << screen->name(); + + QRect rec = screen->geometry(); + + loadSensor(screen, "top", rec.width() / 3, 0, rec.width() / 3, 10); + loadSensor(screen, "right", rec.width() - 1, rec.height() / 3, 1, rec.height() / 3); + loadSensor(screen, "bottom", rec.width() / 3, rec.height() - 1, rec.width() / 3, 1); + loadSensor(screen, "left", 0, rec.height() / 3, 1, rec.height() / 3); + loadSensor(screen, "topLeft", 0, 0, 1, 1); + loadSensor(screen, "topRight", rec.width() - 1, 0, 1, 1); + loadSensor(screen, "bottomRight", rec.width() - 1, rec.height() - 1, 1, 1); + loadSensor(screen, "bottomLeft", 0, rec.height() - 1, 1, 1); +} + + +void +App::loadSensor(QScreen* screen, QString name, int x, int y, int w, int h) +{ + + QString key = screen->name() + "/" + name; + + + if (!settings.contains(key) ) + { + qDebug() << "App::loadSensor() key " << name << " not found"; + + // restore missing key + settings.setValue(key, QString()); + return; + } + + if (settings.value(key).toString().isEmpty()) + { + qDebug() << "App::loadSensor() key " << name << " is empty"; + return; + } + + + // create sensor and save in list so we can delete all sensors on delete + + sensors.append( new Sensor(x, y, w, h, settings.value(key).toString()) ); +} + + +} // namespace \ No newline at end of file diff --git a/src/app.h b/src/app.h new file mode 100644 index 0000000..0906d5b --- /dev/null +++ b/src/app.h @@ -0,0 +1,69 @@ +/* + +MIT License + +Copyright (c) 2017 Noah Andreas + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + + +#pragma once + + +#include "sensor.h" +#include +#include +#include +#include +#include + + +namespace Lead { + + +class App : public QApplication +{ + Q_OBJECT + +public: + explicit App(int &argc, char** argv); + ~App(); + +private: + QSettings settings; + QFileSystemWatcher watcher; + QList sensors; + + void screenAdded(QScreen* screen); + void screenRemoved(QScreen* screen); + void watchSettings(); + void loadScreens(); + void loadScreen(QScreen* screen); + void loadSensor(QScreen* screen, QString name, int x, int y, int w, int h); + void reloadScreens(); + +public slots: + void fileChanged(QString fileName); + +}; + + +} // namespace \ No newline at end of file diff --git a/src/lead.cpp b/src/lead.cpp deleted file mode 100644 index fb6c3cb..0000000 --- a/src/lead.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* -MIT License - -Copyright (c) 2017 Noah Andreas - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - - -#include "lead.h" -#include "sensor.h" -#include -#include -#include - - -Lead::Lead(int &argc, char** argv) : - QApplication(argc, argv), - settings("lead", "lead"), - watcher() -{ - loadScreens(); - watchSettings(); -} - - -Lead::~Lead() -{ - qDeleteAll(sensors); -} - - -void -Lead::watchSettings() -{ - watcher.addPath(settings.fileName()); - - connect(&watcher, SIGNAL(fileChanged(QString)), this, SLOT(fileChanged(QString))); -} - - -void -Lead::fileChanged(QString fileName) -{ - qDebug() << "Lead::fileChanged() fileName: " << fileName; - - // this reloads the settings from the file - settings.sync(); - - // some editors dont update but delete/create the config file, in this - // case our watcher loses the file so we have to add it again - watcher.addPath( fileName ); - - // simply reload everything - reloadScreens(); -} - - -void -Lead::screenAdded(QScreen* screen) -{ - loadScreen(screen); -} - - -void -Lead::screenRemoved(QScreen* screen) -{ - // thats the easiest way - reloadScreens(); -} - - -void -Lead::reloadScreens() -{ - qDeleteAll(sensors); - sensors.clear(); - - loadScreens(); -} - - -void -Lead::loadScreens() -{ - foreach (QScreen* screen, screens()) - { - loadScreen(screen); - } -} - - -void -Lead::loadScreen(QScreen* screen) -{ - qDebug() << "Lead::loadScreen() " << screen->name(); - - QRect rec = screen->geometry(); - - loadSensor(screen, "top", rec.width() / 3, 0, rec.width() / 3, 10); - loadSensor(screen, "right", rec.width() - 1, rec.height() / 3, 1, rec.height() / 3); - loadSensor(screen, "bottom", rec.width() / 3, rec.height() - 1, rec.width() / 3, 1); - loadSensor(screen, "left", 0, rec.height() / 3, 1, rec.height() / 3); - loadSensor(screen, "topLeft", 0, 0, 1, 1); - loadSensor(screen, "topRight", rec.width() - 1, 0, 1, 1); - loadSensor(screen, "bottomRight", rec.width() - 1, rec.height() - 1, 1, 1); - loadSensor(screen, "bottomLeft", 0, rec.height() - 1, 1, 1); -} - - -void -Lead::loadSensor(QScreen* screen, QString name, int x, int y, int w, int h) -{ - - QString key = screen->name() + "/" + name; - - - if (!settings.contains(key) ) - { - qDebug() << "Lead::loadSensor() key " << name << " not found"; - - // restore missing key - settings.setValue(key, QString()); - return; - } - - if (settings.value(key).toString().isEmpty()) - { - qDebug() << "Lead::loadSensor() key " << name << " is empty"; - return; - } - - - // create sensor and save in list so we can delete all sensors on delete - - sensors.append( new lead::Sensor(x, y, w, h, settings.value(key).toString()) ); -} \ No newline at end of file diff --git a/src/lead.h b/src/lead.h deleted file mode 100644 index 3e7c9bd..0000000 --- a/src/lead.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -MIT License - -Copyright (c) 2017 Noah Andreas - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - - -#pragma once - - -#include "sensor.h" -#include -#include -#include -#include -#include - - -class Lead : public QApplication -{ - Q_OBJECT - -public: - explicit Lead(int &argc, char** argv); - ~Lead(); - -private: - QSettings settings; - QFileSystemWatcher watcher; - QList sensors; - - void screenAdded(QScreen* screen); - void screenRemoved(QScreen* screen); - void watchSettings(); - void loadScreens(); - void loadScreen(QScreen* screen); - void loadSensor(QScreen* screen, QString name, int x, int y, int w, int h); - void reloadScreens(); - -public slots: - void fileChanged(QString fileName); - -}; diff --git a/src/main.cpp b/src/main.cpp index 96ee49e..324604e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ /* + MIT License Copyright (c) 2017 Noah Andreas @@ -20,17 +21,18 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ -#include "lead.h" +#include "app.h" int main(int argc, char *argv[]) { - Lead lead(argc, argv); + Lead::App app(argc, argv); - return lead.exec(); + return app.exec(); } diff --git a/src/sensor.cpp b/src/sensor.cpp index 841a4df..d84f0a2 100644 --- a/src/sensor.cpp +++ b/src/sensor.cpp @@ -1,4 +1,5 @@ /* + MIT License Copyright (c) 2017 Noah Andreas @@ -20,6 +21,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ @@ -29,7 +31,7 @@ SOFTWARE. #include -namespace lead { +namespace Lead { Sensor::Sensor(int x, int y, int w, int h, QString action): diff --git a/src/sensor.h b/src/sensor.h index 8efb7a3..0a400b6 100644 --- a/src/sensor.h +++ b/src/sensor.h @@ -1,4 +1,5 @@ /* + MIT License Copyright (c) 2017 Noah Andreas @@ -20,6 +21,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ @@ -30,7 +32,7 @@ SOFTWARE. #include -namespace lead { +namespace Lead { class Sensor : public QWidget -- cgit v1.2.3