#include "location.h"
#include "gpscontroller.h"
#include "ytv.h"
-#include "messagetable.h"
-#include "messagehandler.h"
#include <QDebug>
#include <QObject>
int main(int argc, char *argv[] )
{
- //qInstallMsgHandler( messageHandler );
QApplication app(argc, argv);
QMainWindow *mainWindow = new QMainWindow;
gpsController, SLOT( useLiveGps() )
);
+ QObject::connect(
+ route, SIGNAL( busy( bool ) ),
+ ui, SLOT( setBusy( bool ) )
+ );
+
mainWindow->show();
return app.exec();
+++ /dev/null
-#include "messagehandler.h"
-
-#include "messagetable.h"
-#include <QString>
-#include <QtGlobal>
-#include <QTime>
-
-void messageHandler( QtMsgType type, const char *msg )
-{
- Q_UNUSED( type );
-
- if ( Ui::messageTable != 0 ) {
- Ui::messageTable->displayMessage(
- QTime::currentTime().toString()+" "+QString::fromLatin1( msg )
- );
- }
-}
-
+++ /dev/null
-#ifndef MESSAGEHANDLER_H
-#define MESSAGEHANDLER_H
-
-#include "ui.h"
-
-#include <QtGlobal>
-
-void messageHandler( QtMsgType type, const char *msg );
-
-#endif //MESSAGEHANDLER_H
+++ /dev/null
-#include "messagetable.h"
-
-#include <QHeaderView>
-#include <QString>
-#include <QStringList>
-#include <QDebug>
-#include <QResizeEvent>
-
-MessageTable::MessageTable( QWidget *parent ) :
- QTableWidget( NumberOfRows, OneColumn, parent )
-{
- setHorizontalHeaderLabels( QStringList() << "Messages" );
- verticalHeader()->hide();
- setSelectionMode( QAbstractItemView::NoSelection );
-
- for ( int row=0; row<NumberOfRows; ++row ) {
- QTableWidgetItem *newRow = new QTableWidgetItem();
- setItem( row,0, newRow );
- }
-}
-
-MessageTable::~MessageTable()
-{
-}
-
-void MessageTable::displayMessage( const QString &message )
-{
- // scroll items down from bottom to top
- for ( int row=NumberOfRows-1; row>0; --row ) {
- QTableWidgetItem *fromItem = item(0,row-1);
- QTableWidgetItem *toItem = item(0,row);
- QString text=fromItem->text();
- toItem->setText( text );
- }
-
- itemAt(0,0)->setText( message );
-}
-
-void MessageTable::resizeEvent( QResizeEvent *event )
-{
- int width = event->size().width() / columnCount();
- for ( int i = 0; i < columnCount(); ++i ) {
- setColumnWidth( i, width );
- }
-}
+++ /dev/null
-#ifndef MESSAGETABLE_H
-#define MESSAGETABLE_H
-
-#include <QWidget>
-#include <QTableWidget>
-class QResizeEvent;
-
-class MessageTable : public QTableWidget
-{
- Q_OBJECT
-
- enum {
- NumberOfRows=100,
- OneColumn=1
- };
-
-public:
- MessageTable( QWidget *parent=0 );
- ~MessageTable();
-
- void displayMessage( const QString &message );
-
-protected:
- void resizeEvent( QResizeEvent *event );
-};
-#endif //MESSAGETABLE_H
#include <QStringList>
#include <QString>
#include <QXmlStreamReader>
+#include <QWidget>
#include "ytv.h"
manager->get( QNetworkRequest( fullUrl ) );
qDebug() << "getting url" << fullUrl.toEncoded();
qDebug() << "waiting for reply from Ytv";
+ emit( busy( true ) );
}
void Route::replyFinished( QNetworkReply * reply )
QList<RouteData> routeData = q->parseReply( reply->readAll() );
emit( routeReady( routeData ) );
+ emit( busy( false ) );
}
void Route::setFromLocation( Location *location )
} else {
qDebug() << "ERROR:From is not valid";
qDebug() << "location=" << location;
+ if ( location ) {
+ qDebug() << "location->isValid()=" << location->isValid();
+ }
}
}
qDebug() << "From not valid - waiting";
}
} else {
- qDebug() << "To is not valid";
- qDebug() << "ERROR:location is zero; cast failed";
+ qDebug() << "ERROR:From is not valid";
+ qDebug() << "location=" << location;
+ if ( location ) {
+ qDebug() << "location->isValid()=" << location->isValid();
+ }
}
}
Q_SIGNALS:
void routeReady( QList<RouteData> );
+ void busy( bool busy );
private Q_SLOTS:
void replyFinished( QNetworkReply* );
#include "ui.h"
-#include "messagetable.h"
#include "locations.h"
#include "ytv.h"
#include <QInputDialog>
#include <QDebug>
-MessageTable *Ui::messageTable = 0;
-
Ui::Ui() :
- centralWidget(0),
- destinationButtons(0),
- routeStack(0),
- usingFakeGps( false ),
- messagesShown( false ),
- fakeLocationLabel( "work" )
+ m_centralWidget(0),
+ m_destinationButtons(0),
+ m_routeStack(0),
+ m_usingFakeGps( false ),
+ m_fakeLocationLabel( "work" )
{
}
void Ui::setupUi( QMainWindow *mainWindow )
{
- mainWindow->resize(800,480);
- menu = mainWindow->menuBar()->addMenu("Settings");
+ m_mainWindow = mainWindow;
+ m_mainWindow->resize(800,480);
+
+ m_menu = mainWindow->menuBar()->addMenu("Settings");
QAction *setHomeAddressAction = new QAction("Set home address", this);
QAction *setWorkAddressAction = new QAction("Set work address", this);
- toggleMessagesAction = new QAction("Show messages", this);
- toggleFakeGpsAction = new QAction("Use fake GPS", this);
- menu->addAction(setHomeAddressAction);
- menu->addAction(setWorkAddressAction);
- menu->addAction(toggleMessagesAction);
- menu->addAction(toggleFakeGpsAction);
+ m_toggleFakeGpsAction = new QAction("Use fake GPS", this);
+ m_menu->addAction(setHomeAddressAction);
+ m_menu->addAction(setWorkAddressAction);
+ m_menu->addAction(m_toggleFakeGpsAction);
connect(
setHomeAddressAction, SIGNAL(triggered()),
this, SLOT(setWorkAddress())
);
connect(
- toggleMessagesAction, SIGNAL(triggered()),
- this, SLOT(toggleMessages())
- );
- connect(
- toggleFakeGpsAction, SIGNAL(triggered()),
+ m_toggleFakeGpsAction, SIGNAL(triggered()),
this, SLOT(toggleFakeGps())
);
- centralWidget = new QWidget( mainWindow );
- mainWindow->setCentralWidget(centralWidget);
+ m_centralWidget = new QWidget( m_mainWindow );
+ m_mainWindow->setCentralWidget( m_centralWidget);
QRadioButton *homeButton = new QRadioButton();
homeButton->setObjectName( QString::fromUtf8("homeButton") );
workButton->setText( "GPS->WORK" );
workButton->setEnabled(false);
- destinationButtons = new QButtonGroup();
- destinationButtons->addButton( homeButton, HomeButtonId );
- destinationButtons->addButton( workButton, WorkButtonId );
- destinationButtons->setExclusive( true );
+ m_destinationButtons = new QButtonGroup();
+ m_destinationButtons->addButton( homeButton, HomeButtonId );
+ m_destinationButtons->addButton( workButton, WorkButtonId );
+ m_destinationButtons->setExclusive( true );
- routeStack = new QVBoxLayout();
+ m_routeButtons = new QButtonGroup();
+ m_routeButtons->setExclusive( true );
+ m_routeStack = new QVBoxLayout();
for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
QRadioButton *button = new QRadioButton();
button->setObjectName( "routeButton"+i );
button->setEnabled( false );
- routeStack->addWidget( button, i );
+ m_routeStack->addWidget( button, i );
+ m_routeButtons->addButton( button, i );
}
- routeStack->addStretch();
+ m_routeStack->addStretch();
- QHBoxLayout *topLayout = new QHBoxLayout();
- topLayout->addLayout( routeStack );
- topLayout->addStretch();
+ m_routeDetailTable = new QTableWidget();
+ m_routeDetailTable->setColumnCount(6);
- buttonLayout = new QGridLayout();
- buttonLayout->addWidget( homeButton, 0, 0 );
- buttonLayout->addWidget( workButton, 0, 1 );
+ QHBoxLayout *topLayout = new QHBoxLayout();
+ topLayout->addLayout( m_routeStack );
+ topLayout->addWidget( m_routeDetailTable );
- messageTable = new MessageTable();
- messageTable->setObjectName( QString::fromUtf8("messageTable") );
- messageTable->hide();
+ m_buttonLayout = new QGridLayout();
+ m_buttonLayout->addWidget( homeButton, 0, 0 );
+ m_buttonLayout->addWidget( workButton, 0, 1 );
- QVBoxLayout *mainLayout = new QVBoxLayout();
- mainLayout->addLayout( topLayout );
- mainLayout->addWidget( messageTable );
- mainLayout->addLayout( buttonLayout );
+ m_mainLayout = new QVBoxLayout();
+ m_mainLayout->addLayout( topLayout );
+ m_mainLayout->addLayout( m_buttonLayout );
- centralWidget->setLayout( mainLayout );
+ m_centralWidget->setLayout( m_mainLayout );
}
void Ui::setHomeAddress()
setAddress( "work" );
}
-void Ui::toggleMessages()
-{
- messagesShown = !messagesShown;
-
- if ( messagesShown ) {
- showMessages();
- } else {
- hideMessages();
- }
-}
-
-void Ui::hideMessages()
-{
- messageTable->hide();
- toggleMessagesAction->setText( "Show messages" );
-}
-
-void Ui::showMessages()
-{
- messageTable->show();
- toggleMessagesAction->setText( "Hide messages" );
-}
-
void Ui::toggleFakeGps()
{
- usingFakeGps = !usingFakeGps;
+ m_usingFakeGps = !m_usingFakeGps;
- if ( usingFakeGps ) {
+ if ( m_usingFakeGps ) {
useFakeGps();
} else {
useLiveGps();
void Ui::useFakeGps()
{
- emit fakeGpsPressed( fakeLocationLabel );
- toggleFakeGpsAction->setText( "Use Live GPS" );
+ emit fakeGpsPressed( m_fakeLocationLabel );
+ m_toggleFakeGpsAction->setText( "Use Live GPS" );
}
void Ui::useLiveGps()
{
emit liveGpsPressed();
- toggleFakeGpsAction->setText( "Use Fake GPS" );
+ m_toggleFakeGpsAction->setText( "Use Fake GPS" );
}
void Ui::setAddress( const QString &label )
bool ok;
QString address = QInputDialog::getText(
- centralWidget,
+ m_centralWidget,
tr("Enter address for \""+QString(label).toLatin1()+"\""),
tr("Address"),
QLineEdit::Normal,
}
}
}
+
+void Ui::setBusy( bool busy )
+{
+ m_mainWindow->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
+}
class QWidget;
class QTableWidget;
class QButtonGroup;
-class MessageTable;
class QHBoxLayout;
class QVBoxLayout;
class QGridLayout;
ScreenHeight=480
};
- QWidget *centralWidget;
- QButtonGroup *destinationButtons;
- QVBoxLayout *routeStack;
- static MessageTable *messageTable;
- QHBoxLayout *mainLayout;
- QGridLayout *buttonLayout;
- QMenu *menu;
- QAction *toggleMessagesAction;
- QAction *toggleFakeGpsAction;
- QAction *useLiveGpsAction;
- bool usingFakeGps;
- bool messagesShown;
- QString fakeLocationLabel;
+ QMainWindow *m_mainWindow;
+ QWidget *m_centralWidget;
+ QButtonGroup *m_destinationButtons;
+ QButtonGroup *m_routeButtons;
+ QVBoxLayout *m_routeStack;
+ QTableWidget *m_routeDetailTable;
+ QVBoxLayout *m_mainLayout;
+ QGridLayout *m_buttonLayout;
+ QMenu *m_menu;
+ QAction *m_toggleFakeGpsAction;
+ QAction *m_useLiveGpsAction;
+ bool m_usingFakeGps;
+ QString m_fakeLocationLabel;
Q_SIGNALS:
void homeAddressChanged( QString address );
private Q_SLOTS:
void setHomeAddress();
void setWorkAddress();
- void toggleMessages();
void toggleFakeGps();
+ void setBusy( bool busy );
private:
void useFakeGps();
void useLiveGps();
- void hideMessages();
- void showMessages();
void setAddress( const QString &label );
};
#endif //UI_H
#include "ui.h"
#include "ytv.h"
#include "location.h"
-#include "messagetable.h"
#include "locations.h"
#include <QObject>
#include <QButtonGroup>
#include <QRadioButton>
#include <QVBoxLayout>
+#include <QTableWidgetItem>
UiController::UiController( Ui *ui ) :
- ui(ui)
+ m_routeData(),
+ m_destination(),
+ m_ui(ui),
+ m_currentDestination(-1),
+ m_currentRoute(-1)
{
Locations *locations = Locations::instance();
Location *homeLocation = locations->location( "home" );
locations, SLOT( saveLocation() )
);
- destination.append( homeLocation );
- destination.append( workLocation );
+ m_destination.append( homeLocation );
+ m_destination.append( workLocation );
connect(
- ui->destinationButtons, SIGNAL( buttonClicked( int ) ),
+ m_ui->m_destinationButtons, SIGNAL( buttonClicked( int ) ),
this, SLOT( changeDestination( int ) )
);
+
+ connect(
+ m_ui->m_routeButtons, SIGNAL( buttonClicked( int ) ),
+ this, SLOT( changeRoute( int ) )
+ );
}
UiController::~UiController()
void UiController::setButtonValid( int id )
{
- ui->destinationButtons->button( id )->setEnabled(true);
+ m_ui->m_destinationButtons->button( id )->setEnabled(true);
}
void UiController::changeDestination( int id )
{
- qDebug() << "Button "+QString::number(id)+" clicked";
+ qDebug() << "Destination button "+QString::number(id)+" clicked";
- bool destinationHasChanged = ( currentDestination != id );
+ bool destinationHasChanged = ( m_currentDestination != id );
+ qDebug() << "Destination has changed=" << destinationHasChanged;
if ( destinationHasChanged ) {
- emit destinationChanged( destination[id] );
+ qDebug() << "Emitting destination changed (" << m_destination[id]->label() << ")";
+ emit destinationChanged( m_destination[id] );
}
// always want to emit this so that the gps position is update
emit buttonClicked();
}
+void UiController::changeRoute( int id )
+{
+ qDebug() << "Route button "+QString::number(id)+" clicked";
+
+ bool routeHasChanged = ( m_currentRoute != id );
+ if ( routeHasChanged ) {
+ displayRouteDetail( id );
+ }
+}
+
+void UiController::displayRouteDetail( int id )
+{
+ QTableWidget *table = m_ui->m_routeDetailTable;
+
+ if ( id < m_routeData.count() ) {
+ QList<LegData> &legDataList = m_routeData[ id ].m_legData;
+ table->setRowCount( legDataList.count() );
+
+ int row=0;
+ foreach( LegData thisLegData, legDataList ) {
+
+ QStringList tableStrings;
+ tableStrings
+ << thisLegData.m_how
+ << thisLegData.m_tripTime
+ << thisLegData.m_tripDistance
+ << thisLegData.m_departureTime
+ << thisLegData.m_arrivalTime
+ << thisLegData.m_lineCode;
+
+ int col=0;
+ foreach( QString thisString, tableStrings ) {
+ QTableWidgetItem *newItem = new QTableWidgetItem();
+ newItem->setText( thisString );
+ table->setItem( row,col, newItem );
+ ++col;
+ }
+
+ ++row;
+ }
+ } else {
+ table->setRowCount( 0 );
+ }
+ table->resizeColumnsToContents();
+}
+
void UiController::displayRoute( const QList<RouteData> &routeData )
{
+ m_routeData = routeData;
+
qDebug() << "displaying route";
for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
QString label;
- QWidget *widget = ui->routeStack->itemAt( i )->widget();
+ QWidget *widget = m_ui->m_routeStack->itemAt( i )->widget();
QRadioButton *button = qobject_cast<QRadioButton *>(widget);
if ( i<routeData.count() ) {
button->setText( label );
}
+ QTableWidget *table = m_ui->m_routeDetailTable;
+ table->setRowCount( 0 );
+ table->resizeColumnsToContents();
}
private Q_SLOTS:
void changeDestination( int id );
+ void changeRoute( int id );
void setHomeButtonValid();
void setWorkButtonValid();
+ void displayRouteDetail( int id );
private:
void setButtonValid( int id );
private:
- QList<Location*> destination;
- Ui *ui;
- int currentDestination;
+ QList<RouteData> m_routeData;
+ QList<Location*> m_destination;
+ Ui *m_ui;
+ int m_currentDestination;
+ int m_currentRoute;
};
#endif // UICONTROLLER_H
gpscontroller.cpp \
gpscontroller_p.cpp \
ui.cpp \
- messagetable.cpp \
- messagehandler.cpp \
HEADERS += \
route.h \
gpscontroller.h \
gpscontroller_p.h \
ui.h \
- messagetable.h \
- messagehandler.h \
FORMS +=
LEXSOURCES += #LEXS#
YACCSOURCES += #YACCS#
INCLUDEPATH += include
+DEPENDSPATH += INCLUDEPATH
#QMAKE_LIBDIR_QT = qt4-maemo5/lib
#QMAKE_INCDIR_QT = qt4-maemo5/include
LIBS += -Llib -lQtBearer -lQtLocation