aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app.cpp33
-rw-r--r--src/app.h4
-rw-r--r--src/screenname.cpp60
-rw-r--r--src/screenname.h48
-rw-r--r--src/sensor.cpp27
-rw-r--r--src/sensor.h3
6 files changed, 167 insertions, 8 deletions
diff --git a/src/app.cpp b/src/app.cpp
index bb7c777..a73b812 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -27,6 +27,7 @@ SOFTWARE.
#include "app.h"
#include "sensor.h"
+#include "screenname.h"
#include <QDebug>
#include <QScreen>
#include <QFileSystemWatcher>
@@ -34,6 +35,7 @@ SOFTWARE.
#define SENSOR_WIDTH 5
#define SENSOR_HEIGHT 5
+#define DEBUG_MODE_KEY "systemsettings/debug"
namespace Lead {
@@ -51,6 +53,7 @@ App::App(int &argc, char** argv) :
App::~App()
{
qDeleteAll(sensors);
+ qDeleteAll(screenNames);
}
@@ -99,7 +102,9 @@ void
App::reloadScreens()
{
qDeleteAll(sensors);
+ qDeleteAll(screenNames);
sensors.clear();
+ screenNames.clear();
loadScreens();
}
@@ -108,6 +113,14 @@ App::reloadScreens()
void
App::loadScreens()
{
+ // first load the debug mode flag
+ this->debugMode = false;
+
+ if (settings.contains (DEBUG_MODE_KEY))
+ {
+ this->debugMode = settings.value (DEBUG_MODE_KEY).toInt () > 0;
+ }
+
foreach (QScreen* screen, screens())
{
loadScreen(screen);
@@ -130,6 +143,8 @@ App::loadScreen(QScreen* screen)
loadSensor(screen, "topRight", rec.x() + rec.width() - SENSOR_WIDTH, rec.y(), SENSOR_WIDTH, SENSOR_HEIGHT);
loadSensor(screen, "bottomRight", rec.x() + rec.width() - SENSOR_WIDTH, rec.y() + rec.height() - SENSOR_HEIGHT, SENSOR_WIDTH, SENSOR_HEIGHT);
loadSensor(screen, "bottomLeft", rec.x(), rec.y() + rec.height() - SENSOR_HEIGHT, SENSOR_WIDTH, SENSOR_HEIGHT);
+
+ loadScreenNameDisplay (screen);
}
@@ -168,7 +183,7 @@ App::loadSensor(QScreen* screen, QString name, int x, int y, int w, int h)
if (emptyCount == 2)
{
// to not make this a breaking change, keep compatibility with old configurations
- sensors.append (new Sensor (x, y, w, h, sensorName, "", 0, 0));
+ sensors.append (new Sensor (x, y, w, h, sensorName, "", 0, 0, this->debugMode));
return;
}
@@ -191,10 +206,24 @@ App::loadSensor(QScreen* screen, QString name, int x, int y, int w, int h)
settings.value (sensorEnterAction).toString (),
settings.value (sensorExitAction).toString (),
settings.value (sensorEnterDelay).toInt (),
- settings.value (sensorExitDelay).toInt ()
+ settings.value (sensorExitDelay).toInt (),
+ this->debugMode
)
);
}
+void
+App::loadScreenNameDisplay(QScreen* screen)
+{
+ if (!this->debugMode)
+ {
+ return;
+ }
+
+ qDebug () << "App::loadScreenNameDisplay () loading widget for screen " << screen->name ();
+
+ screenNames.append (new ScreenName (screen));
+}
+
} // namespace
diff --git a/src/app.h b/src/app.h
index 0906d5b..93393aa 100644
--- a/src/app.h
+++ b/src/app.h
@@ -29,6 +29,7 @@ SOFTWARE.
#include "sensor.h"
+#include "screenname.h"
#include <QApplication>
#include <QList>
#include <QSettings>
@@ -51,6 +52,8 @@ private:
QSettings settings;
QFileSystemWatcher watcher;
QList<Sensor*> sensors;
+ QList<ScreenName*> screenNames;
+ bool debugMode;
void screenAdded(QScreen* screen);
void screenRemoved(QScreen* screen);
@@ -58,6 +61,7 @@ private:
void loadScreens();
void loadScreen(QScreen* screen);
void loadSensor(QScreen* screen, QString name, int x, int y, int w, int h);
+ void loadScreenNameDisplay(QScreen* screen);
void reloadScreens();
public slots:
diff --git a/src/screenname.cpp b/src/screenname.cpp
new file mode 100644
index 0000000..6755433
--- /dev/null
+++ b/src/screenname.cpp
@@ -0,0 +1,60 @@
+/*
+
+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 "screenname.h"
+#include <QEvent>
+#include <QDebug>
+#include <QProcess>
+#include <QLabel>
+#include <QHBoxLayout>
+
+#define SCREENNAME_WIDTH 150
+#define SCREENNAME_HEIGHT 45
+
+namespace Lead {
+ ScreenName::ScreenName(QScreen* screen):
+ QWidget()
+ {
+ qDebug()
+ << "lead::ScreenName() " << screen->name ();
+ QRect rec = screen->geometry();
+
+ setGeometry(rec.x(), rec.y(), SCREENNAME_WIDTH, SCREENNAME_HEIGHT);
+ setAttribute(Qt::WA_TranslucentBackground, true);
+ setWindowFlags(windowFlags() | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint );
+
+ // create the text widget and put it in the widget
+ QHBoxLayout *layout = new QHBoxLayout ();
+ QLabel* label = new QLabel ();
+ label->setText (screen->name ());
+ layout->addWidget (label);
+
+ setLayout (layout);
+
+ show();
+ }
+} // namespace
diff --git a/src/screenname.h b/src/screenname.h
new file mode 100644
index 0000000..1887036
--- /dev/null
+++ b/src/screenname.h
@@ -0,0 +1,48 @@
+/*
+
+MIT License
+
+Copyright (c) 2017 Alexis Maiquez
+
+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 <QWidget>
+#include <QScreen>
+
+
+namespace Lead {
+
+
+ class ScreenName : public QWidget
+ {
+ Q_OBJECT
+
+ public:
+ explicit ScreenName(QScreen* screen);
+ virtual ~ScreenName() {}
+ };
+
+
+} // namespace
diff --git a/src/sensor.cpp b/src/sensor.cpp
index 597d4f9..4789175 100644
--- a/src/sensor.cpp
+++ b/src/sensor.cpp
@@ -34,12 +34,13 @@ SOFTWARE.
namespace Lead {
-Sensor::Sensor(int x, int y, int w, int h, QString enterAction, QString exitAction, int enterInterval, int exitInterval):
+Sensor::Sensor(int x, int y, int w, int h, QString enterAction, QString exitAction, int enterInterval, int exitInterval, bool debugMode):
QWidget(),
enterAction(enterAction),
exitAction(exitAction),
enterInterval(enterInterval),
- exitInterval(exitInterval)
+ exitInterval(exitInterval),
+ debugMode(debugMode)
{
qDebug()
<< "lead::Sensor() " << x << "," << y << "," << w << "," << h
@@ -61,9 +62,16 @@ Sensor::Sensor(int x, int y, int w, int h, QString enterAction, QString exitActi
connect(this->enterTimer, SIGNAL(timeout()), this, SLOT(activateEnter()));
connect(this->exitTimer, SIGNAL(timeout()), this, SLOT(activateExit()));
- //setStyleSheet("background-color:red;");
- setGeometry(x, y, w, h);
- setAttribute(Qt::WA_TranslucentBackground, true);
+ if (this->debugMode)
+ {
+ setStyleSheet ("background-color: red");
+ }
+ else
+ {
+ setAttribute(Qt::WA_TranslucentBackground, true);
+ }
+
+ setGeometry(x, y, w, h);
setWindowFlags(windowFlags() | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint );
show();
@@ -87,6 +95,9 @@ Sensor::enterEvent(QEvent * event)
this->enterTimer->start();
this->exitTimer->start();
+
+ if (this->debugMode)
+ setStyleSheet ("background-color: yellow");
}
@@ -103,6 +114,9 @@ Sensor::leaveEvent(QEvent * event)
QProcess::startDetached(exitAction);
}
+ if (this->debugMode)
+ setStyleSheet ("background-color: red");
+
this->enterTimer->stop();
this->exitTimer->stop();
this->canTriggerExit = false;
@@ -114,6 +128,9 @@ Sensor::activateEnter()
{
qDebug() << "lead::Sensor::activateEnter() " << this->x() << ":" << this->y() << " action: " << this->enterAction;
+ if (this->debugMode)
+ setStyleSheet ("background-color: green");
+
QProcess::startDetached(enterAction);
}
diff --git a/src/sensor.h b/src/sensor.h
index bc4857b..4b86690 100644
--- a/src/sensor.h
+++ b/src/sensor.h
@@ -41,7 +41,7 @@ class Sensor : public QWidget
Q_OBJECT
public:
- explicit Sensor(int x, int y, int w, int h, QString enterAction, QString exitAction, int enterInterval, int exitInterval);
+ explicit Sensor(int x, int y, int w, int h, QString enterAction, QString exitAction, int enterInterval, int exitInterval, bool debugMode);
~Sensor();
protected:
@@ -56,6 +56,7 @@ private:
int enterInterval;
int exitInterval;
bool canTriggerExit;
+ bool debugMode;
public slots:
void activateEnter();