2011-06-28 15:25:20 +00:00
/*
2011-06-26 08:30:44 +00:00
MainWindow Implementation
Copyright ( c ) 2011 Mark Watkins < jedimark @ users . sourceforge . net >
License : GPL
2011-06-28 15:25:20 +00:00
*/
2011-06-26 08:30:44 +00:00
# include <QGLFormat>
# include <QFileDialog>
# include <QMessageBox>
# include <QResource>
# include <QProgressBar>
2011-06-27 10:46:33 +00:00
# include <QWebHistory>
2011-06-27 06:26:29 +00:00
# include <QTimer>
2011-06-26 08:30:44 +00:00
# include "mainwindow.h"
# include "ui_mainwindow.h"
# include "daily.h"
# include "overview.h"
# include "Graphs/glcommon.h"
QProgressBar * qprogress ;
QLabel * qstatus ;
2011-07-19 05:05:02 +00:00
QLabel * qstatus2 ;
2011-07-19 02:52:03 +00:00
QStatusBar * qstatusbar ;
2011-06-26 08:30:44 +00:00
2011-07-17 15:57:45 +00:00
void MainWindow : : Log ( QString s )
{
ui - > logText - > appendPlainText ( s ) ;
}
2011-06-26 08:30:44 +00:00
QString subversion = " 0 " ;
MainWindow : : MainWindow ( QWidget * parent ) :
QMainWindow ( parent ) ,
ui ( new Ui : : MainWindow )
{
2011-07-16 13:34:39 +00:00
# ifndef Q_WS_MAC
2011-07-15 13:07:12 +00:00
this - > showMaximized ( ) ;
2011-07-16 13:34:39 +00:00
# endif
2011-06-26 08:30:44 +00:00
ui - > setupUi ( this ) ;
2011-06-27 15:00:00 +00:00
this - > setWindowTitle ( tr ( " SleepyHead " ) + QString ( " v0.8. " ) + subversion ) ;
2011-07-17 15:57:45 +00:00
ui - > tabWidget - > setCurrentIndex ( 0 ) ;
2011-06-27 06:26:29 +00:00
2011-06-26 08:30:44 +00:00
QGLFormat fmt ;
fmt . setDepth ( false ) ;
fmt . setDirectRendering ( true ) ;
fmt . setAlpha ( true ) ;
fmt . setDoubleBuffer ( true ) ;
fmt . setRgba ( true ) ;
fmt . setDefaultFormat ( fmt ) ;
shared_context = new QGLContext ( fmt ) ;
//ui->tabWidget->setCurrentWidget(daily);
2011-07-19 02:52:03 +00:00
qstatusbar = ui - > statusbar ;
2011-06-26 08:30:44 +00:00
qprogress = new QProgressBar ( this ) ;
qprogress - > setMaximum ( 100 ) ;
2011-07-19 05:05:02 +00:00
qstatus2 = new QLabel ( " Welcome " , this ) ;
qstatus2 - > setFrameStyle ( QFrame : : Raised ) ;
qstatus2 - > setFrameShadow ( QFrame : : Sunken ) ;
qstatus2 - > setFrameShape ( QFrame : : Box ) ;
//qstatus2->setMinimumWidth(100);
qstatus2 - > setMaximumWidth ( 100 ) ;
qstatus2 - > setAlignment ( Qt : : AlignRight | Qt : : AlignVCenter ) ;
2011-06-27 06:26:29 +00:00
qstatus = new QLabel ( " " , this ) ;
qprogress - > hide ( ) ;
2011-07-19 05:05:02 +00:00
ui - > statusbar - > setMinimumWidth ( 200 ) ;
ui - > statusbar - > addPermanentWidget ( qstatus2 , 0 ) ;
ui - > statusbar - > addPermanentWidget ( qstatus , 0 ) ;
ui - > statusbar - > addPermanentWidget ( qprogress , 10 ) ;
2011-06-27 06:26:29 +00:00
daily = NULL ;
overview = NULL ;
Profiles : : Scan ( ) ;
2011-07-19 05:05:02 +00:00
qstatusbar - > showMessage ( " Foo Foo Foo " , 10 ) ;
2011-06-27 06:26:29 +00:00
//loader_progress->Show();
2011-06-26 08:30:44 +00:00
2011-06-27 06:26:29 +00:00
//pref["Version"]=wxString(AutoVersion::_FULLVERSION_STRING,wxConvUTF8);
2011-06-27 15:00:00 +00:00
if ( ! pref . Exists ( " AppName " ) ) pref [ " AppName " ] = " SleepyHead " ;
if ( ! pref . Exists ( " Profile " ) ) pref [ " Profile " ] = getUserName ( ) ;
if ( ! pref . Exists ( " LinkGraphMovement " ) ) pref [ " LinkGraphMovement " ] = true ;
else ui - > action_Link_Graphs - > setChecked ( pref [ " LinkGraphMovement " ] . toBool ( ) ) ;
2011-06-27 06:26:29 +00:00
2011-07-17 15:57:45 +00:00
if ( ! pref . Exists ( " ShowDebug " ) ) pref [ " ShowDebug " ] = false ;
else ui - > actionDebug - > setChecked ( pref [ " ShowDebug " ] . toBool ( ) ) ;
2011-07-17 16:07:37 +00:00
if ( ! pref [ " ShowDebug " ] . toBool ( ) ) {
ui - > logText - > hide ( ) ;
}
2011-07-03 08:08:14 +00:00
if ( ! pref . Exists ( " NoonDateSplit " ) ) pref [ " NoonDateSplit " ] = false ;
else ui - > action_Noon_Date_Split - > setChecked ( pref [ " NoonDateSplit " ] . toBool ( ) ) ;
2011-06-27 15:00:00 +00:00
if ( ! pref . Exists ( " fruitsalad " ) ) pref [ " fruitsalad " ] = true ;
if ( ! pref . Exists ( " UseAntiAliasing " ) ) pref [ " UseAntiAliasing " ] = false ;
else ui - > actionUse_AntiAliasing - > setChecked ( pref [ " UseAntiAliasing " ] . toBool ( ) ) ;
2011-06-27 06:26:29 +00:00
first_load = true ;
2011-07-18 03:36:26 +00:00
if ( ! pref . Exists ( " AlwaysShowOverlayBars " ) ) pref [ " AlwaysShowOverlayBars " ] = true ;
else ui - > actionOverlay_Bars - > setChecked ( pref [ " AlwaysShowOverlayBars " ] . toBool ( ) ) ;
2011-06-26 08:30:44 +00:00
}
MainWindow : : ~ MainWindow ( )
{
if ( daily ) {
daily - > close ( ) ;
delete daily ;
}
if ( overview ) {
overview - > close ( ) ;
delete overview ;
}
2011-07-13 05:27:27 +00:00
if ( oximetry ) {
oximetry - > close ( ) ;
delete oximetry ;
}
2011-06-28 01:51:21 +00:00
DoneGraphs ( ) ;
2011-06-26 08:30:44 +00:00
delete ui ;
Profiles : : Done ( ) ;
}
2011-06-27 06:26:29 +00:00
void MainWindow : : Startup ( )
{
2011-06-27 15:00:00 +00:00
qstatus - > setText ( tr ( " Loading Data " ) ) ;
2011-06-27 06:26:29 +00:00
qprogress - > show ( ) ;
2011-06-27 10:23:24 +00:00
profile = Profiles : : Get ( pref [ " Profile " ] . toString ( ) ) ;
2011-06-27 06:26:29 +00:00
profile - > LoadMachineData ( ) ;
daily = new Daily ( ui - > tabWidget , shared_context ) ;
2011-07-17 15:57:45 +00:00
ui - > tabWidget - > insertTab ( 1 , daily , tr ( " Daily " ) ) ;
2011-06-30 04:55:20 +00:00
2011-07-01 02:52:02 +00:00
overview = new Overview ( ui - > tabWidget , shared_context ) ;
2011-07-17 15:57:45 +00:00
ui - > tabWidget - > insertTab ( 2 , overview , tr ( " Overview " ) ) ;
2011-06-27 06:26:29 +00:00
2011-07-13 05:27:27 +00:00
oximetry = new Oximetry ( ui - > tabWidget ) ;
2011-07-17 15:57:45 +00:00
ui - > tabWidget - > insertTab ( 3 , oximetry , tr ( " Oximetry " ) ) ;
2011-07-13 05:27:27 +00:00
2011-06-27 06:26:29 +00:00
qprogress - > hide ( ) ;
2011-06-27 15:00:00 +00:00
qstatus - > setText ( tr ( " Ready " ) ) ;
2011-06-27 06:26:29 +00:00
}
2011-06-26 08:30:44 +00:00
void MainWindow : : on_action_Import_Data_triggered ( )
{
QStringList dirNames ;
QFileDialog qfd ( this ) ;
qfd . setFileMode ( QFileDialog : : DirectoryOnly ) ;
if ( qfd . exec ( ) ) {
qprogress - > setValue ( 0 ) ;
qprogress - > show ( ) ;
2011-06-27 15:00:00 +00:00
qstatus - > setText ( tr ( " Importing Data " ) ) ;
2011-06-26 08:30:44 +00:00
dirNames = qfd . selectedFiles ( ) ;
2011-07-15 13:30:41 +00:00
int c = 0 , d ;
2011-06-26 08:30:44 +00:00
for ( int i = 0 ; i < dirNames . size ( ) ; i + + ) {
2011-07-15 13:30:41 +00:00
d = profile - > Import ( dirNames [ i ] ) ;
if ( ! d ) {
QMessageBox : : warning ( this , " Import Problem " , " Couldn't Find any Machine Data at this location: \n " + dirNames [ i ] , QMessageBox : : Ok ) ;
}
c + = d ;
2011-06-26 08:30:44 +00:00
}
2011-07-15 13:30:41 +00:00
if ( c ) {
profile - > Save ( ) ;
if ( daily ) daily - > ReloadGraphs ( ) ;
if ( overview ) {
overview - > ReloadGraphs ( ) ;
overview - > UpdateGraphs ( ) ;
}
2011-06-30 04:55:20 +00:00
}
2011-06-27 15:00:00 +00:00
qstatus - > setText ( tr ( " Ready " ) ) ;
2011-06-26 08:30:44 +00:00
qprogress - > hide ( ) ;
}
}
void MainWindow : : on_actionView_Welcome_triggered ( )
{
2011-06-27 15:00:00 +00:00
ui - > tabWidget - > setCurrentWidget ( ui - > welcome ) ;
2011-06-26 08:30:44 +00:00
}
void MainWindow : : on_action_Fullscreen_triggered ( )
{
if ( ui - > action_Fullscreen - > isChecked ( ) )
this - > showFullScreen ( ) ;
else
this - > showNormal ( ) ;
}
void MainWindow : : on_homeButton_clicked ( )
{
2011-06-26 11:49:40 +00:00
QString file = " qrc:/docs/index.html " ;
2011-06-26 08:30:44 +00:00
QUrl url ( file ) ;
ui - > webView - > setUrl ( url ) ;
2011-07-05 05:33:06 +00:00
//ui->webView->load(url);
2011-06-26 08:30:44 +00:00
}
void MainWindow : : on_backButton_clicked ( )
{
ui - > webView - > back ( ) ;
}
void MainWindow : : on_forwardButton_clicked ( )
{
ui - > webView - > forward ( ) ;
}
void MainWindow : : on_webView_urlChanged ( const QUrl & arg1 )
{
ui - > urlBar - > setEditText ( arg1 . toString ( ) ) ;
}
void MainWindow : : on_urlBar_activated ( const QString & arg1 )
{
QUrl url ( arg1 ) ;
ui - > webView - > setUrl ( url ) ;
}
void MainWindow : : on_dailyButton_clicked ( )
{
ui - > tabWidget - > setCurrentWidget ( daily ) ;
}
void MainWindow : : on_overviewButton_clicked ( )
{
ui - > tabWidget - > setCurrentWidget ( overview ) ;
}
void MainWindow : : on_webView_loadFinished ( bool arg1 )
{
2011-07-01 10:10:44 +00:00
arg1 = arg1 ;
2011-06-26 08:30:44 +00:00
qprogress - > hide ( ) ;
2011-06-27 06:26:29 +00:00
if ( first_load ) {
QTimer : : singleShot ( 0 , this , SLOT ( Startup ( ) ) ) ;
first_load = false ;
} else {
2011-06-27 15:00:00 +00:00
qstatus - > setText ( tr ( " Ready " ) ) ;
2011-06-27 06:26:29 +00:00
}
2011-06-27 10:46:33 +00:00
ui - > backButton - > setEnabled ( ui - > webView - > history ( ) - > canGoBack ( ) ) ;
ui - > forwardButton - > setEnabled ( ui - > webView - > history ( ) - > canGoForward ( ) ) ;
2011-06-27 06:26:29 +00:00
2011-06-26 08:30:44 +00:00
}
void MainWindow : : on_webView_loadStarted ( )
{
2011-06-27 06:26:29 +00:00
if ( ! first_load ) {
2011-06-27 15:00:00 +00:00
qstatus - > setText ( tr ( " Loading " ) ) ;
2011-06-27 06:26:29 +00:00
qprogress - > reset ( ) ;
qprogress - > show ( ) ;
}
2011-06-26 08:30:44 +00:00
}
void MainWindow : : on_webView_loadProgress ( int progress )
{
qprogress - > setValue ( progress ) ;
}
2011-06-26 16:35:54 +00:00
void MainWindow : : on_action_About_triggered ( )
{
2011-07-15 10:01:28 +00:00
QString msg = tr ( " <html><body><div align='center'><h2>SleepyHead v0.8.0</h2><hr> "
" Copyright ©2011 Mark Watkins (jedimark) <br> \n "
" <a href='http://sleepyhead.sourceforge.net'>http://sleepyhead.sourceforge.net</a> <hr> "
" This software is released under the GNU Public License <br> "
" <i>This software comes with absolutely no warranty, either express of implied. It comes with no guarantee of fitness for any particular purpose. No guarantees are made regarding the accuracy of any data this program displays. "
" </div></body></html> " ) ;
2011-06-27 15:00:00 +00:00
QMessageBox msgbox ( QMessageBox : : Information , tr ( " About SleepyHead " ) , " " , QMessageBox : : Ok , this ) ;
2011-06-26 16:35:54 +00:00
msgbox . setTextFormat ( Qt : : RichText ) ;
msgbox . setText ( msg ) ;
msgbox . exec ( ) ;
}
2011-06-27 15:00:00 +00:00
void MainWindow : : on_action_Link_Graphs_triggered ( bool checked )
{
pref [ " LinkGraphMovement " ] = checked ;
}
void MainWindow : : on_actionUse_AntiAliasing_triggered ( bool checked )
{
pref [ " UseAntiAliasing " ] = checked ;
if ( daily ) daily - > RedrawGraphs ( ) ;
}
2011-07-03 08:08:14 +00:00
void MainWindow : : on_action_Noon_Date_Split_toggled ( bool checked )
{
pref [ " NoonDateSplit " ] = checked ;
}
2011-07-17 15:57:45 +00:00
void MainWindow : : on_actionDebug_toggled ( bool checked )
{
pref [ " ShowDebug " ] = checked ;
if ( checked ) {
2011-07-17 16:05:16 +00:00
ui - > logText - > show ( ) ;
2011-07-17 15:57:45 +00:00
} else {
2011-07-17 16:05:16 +00:00
ui - > logText - > hide ( ) ;
2011-07-17 15:57:45 +00:00
}
}
2011-07-18 03:36:26 +00:00
void MainWindow : : on_actionOverlay_Bars_toggled ( bool checked )
{
pref [ " AlwaysShowOverlayBars " ] = checked ;
if ( daily ) daily - > RedrawGraphs ( ) ;
}