#include "ui.h"
+#include "messagetable.h"
+#include "locations.h"
+
#include <QMainWindow>
-#include <QPushButton>
+#include <QRadioButton>
#include <QTableWidget>
#include <QString>
#include <QRect>
#include <QButtonGroup>
#include <QHeaderView>
+#include <QObject>
+#include <QMenuBar>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QSizePolicy>
+#include <QInputDialog>
+#include <QDebug>
+
+MessageTable *Ui::messageTable = 0;
Ui::Ui() :
centralWidget(0),
destinationButtons(0),
- table(0)
+ routeTable(0)
{
}
void Ui::setupUi( QMainWindow *mainWindow )
{
mainWindow->resize(800,480);
+ QMenu *menu = mainWindow->menuBar()->addMenu("Settings");
+
+ QAction *setHomeAddressAction = new QAction("Set home address", this);
+ QAction *setWorkAddressAction = new QAction("Set work address", this);
+ menu->addAction(setHomeAddressAction);
+ menu->addAction(setWorkAddressAction);
+
+ connect(
+ setHomeAddressAction, SIGNAL(triggered()),
+ this, SLOT(setHomeAddress())
+ );
+ connect(
+ setWorkAddressAction, SIGNAL(triggered()),
+ this, SLOT(setWorkAddress())
+ );
centralWidget = new QWidget( mainWindow );
mainWindow->setCentralWidget(centralWidget);
- QPushButton *homeButton = new QPushButton( centralWidget );
+ QRadioButton *homeButton = new QRadioButton();
homeButton->setObjectName( QString::fromUtf8("homeButton") );
- homeButton->setText( "HOME" );
- homeButton->setGeometry( QRect( 0, 0, ButtonWidth, ButtonHeight ) );
+ homeButton->setText( "GPS->HOME" );
homeButton->setEnabled(false);
+ homeButton->setFixedSize( QSize( ButtonWidth, ButtonHeight ) );
- QPushButton *workButton = new QPushButton( centralWidget );
+ QRadioButton *workButton = new QRadioButton();
workButton->setObjectName( QString::fromUtf8("workButton") );
- workButton->setText( "WORK" );
- workButton->setGeometry( QRect( 0, ButtonHeight, ButtonWidth, ButtonHeight ) );
+ workButton->setText( "GPS->WORK" );
workButton->setEnabled(false);
- destinationButtons = new QButtonGroup( centralWidget );
+ destinationButtons = new QButtonGroup();
destinationButtons->addButton( homeButton, HomeButtonId );
destinationButtons->addButton( workButton, WorkButtonId );
+ destinationButtons->setExclusive( true );
+
+ buttonLayout = new QVBoxLayout();
+ buttonLayout->addWidget( homeButton );
+ buttonLayout->addWidget( workButton );
+ buttonLayout->addStretch();
- table = new QTableWidget( 1, 2, centralWidget );
- table->setObjectName( QString::fromUtf8("table") );
- table->setGeometry( QRect( ButtonWidth+1, 0, ScreenWidth-ButtonWidth, ScreenHeight ) );
+ routeTable = new QTableWidget( 1, 2 );
QStringList columnHeaders;
columnHeaders << "Time" << "Bus";
- table->setHorizontalHeaderLabels( columnHeaders );
- table->verticalHeader()->hide();
+ routeTable->setHorizontalHeaderLabels( columnHeaders );
+ routeTable->verticalHeader()->hide();
+
+ QHBoxLayout *topLayout = new QHBoxLayout();
+ topLayout->addLayout( buttonLayout );
+ topLayout->addWidget( routeTable );
+
+ messageTable = new MessageTable();
+ messageTable->setObjectName( QString::fromUtf8("messageTable") );
+
+ QVBoxLayout *mainLayout = new QVBoxLayout();
+ mainLayout->addLayout( topLayout );
+ mainLayout->addWidget( messageTable );
+
+ centralWidget->setLayout( mainLayout );
+}
+
+void Ui::setHomeAddress()
+{
+ setAddress( "home" );
+}
+
+void Ui::setWorkAddress()
+{
+ setAddress( "work" );
+}
+
+void Ui::setAddress( const QString &label )
+{
+ Locations *locations=Locations::instance();
+ Location *location=locations->location( label );
+
+ bool ok;
+ QString address = QInputDialog::getText(
+ centralWidget,
+ tr("Enter address for \""+QString(label).toLatin1()+"\""),
+ tr("Address"),
+ QLineEdit::Normal,
+ location->address(),
+ &ok
+ );
+
+ qDebug() << "ok=" << ok;
+
+ if ( ok ) {
+ qDebug() << "new address" << address;
+ Locations *locations=Locations::instance();
+ Location *location = locations->location( label );
+ qDebug() << "location" << location;
+ if ( location ) {
+ location->resolveAddress( address );
+ }
+ }
}