Fixed Threshold Button Not Applying Threshold
[EconoBoard.git] / src / application.cpp
blob493bdec32d37b1f8e26dd19ed49e92d2a1db9519
1 /*************************************************************************
2 Copyright 2009, Matthew Thompson, Lee Hicks
4 This file is part of EconoBoard.
6 EconoBoard is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 EconoBoard is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with EconoBoard. If not, see <http://www.gnu.org/licenses/>.
18 *************************************************************************/
20 #include "application.h"
21 #include "camerathread.h"
22 #include "cameraview.h"
23 #include "setupdialog.h"
25 #include <QSystemTrayIcon>
26 #include <QSettings>
27 #include <QAction>
28 #include <QMenu>
29 #include <QPixmap>
31 using namespace eb;
33 Application::Application(int &argc, char **argv)
34 : QApplication(argc, argv)
36 setQuitOnLastWindowClosed(false);
38 camThread = new CameraThread();
40 createWidgets();
41 createMenus();
42 systemTray->show();
44 QCoreApplication::setOrganizationName("EconoSoft");
45 QCoreApplication::setApplicationName("EconoBoard");
46 restoreSettings();
48 camThread->start();
51 Application::~Application()
53 camThread->quit();
54 camThread->wait();
56 delete setupDialog;
58 delete camThread;
61 void Application::createMenus()
63 QAction *act;
65 trayMenu = new QMenu();
66 systemTray->setContextMenu(trayMenu);
68 trayMenu->addAction(tr("&Setup"), this, SLOT(setup()));
69 trayMenu->addAction(tr("&Quit"), this, SLOT(quit()));
72 void Application::createWidgets()
74 systemTray = new QSystemTrayIcon(QIcon(":tray-img.png"));
76 setupDialog = new SetupDialog(camThread);
77 connect(setupDialog, SIGNAL(settingsChanged(int,int)), this, SLOT(saveSetup(int,int)));
80 void Application::setup()
82 setupDialog->show();
83 setupDialog->raise();
84 setupDialog->activateWindow();
87 void Application::saveSetup(int threshold, int cameraIdx)
89 QSettings settings;
90 settings.setValue("filter/threshold", threshold);
91 settings.setValue("camera/index", cameraIdx);
93 qDebug("Settings were saved");
96 void Application::restoreSettings()
98 QSettings settings;
100 camThread->setThreshold(settings.value("filter/threshold").toInt());
101 camThread->setCamera(settings.value("camera/index").toInt());