Added facility to restore and save locations, and set existing location in home and...
[ptas] / zouba / ui.cpp
index d36baab..330b71e 100644 (file)
@@ -1,15 +1,29 @@
 #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),
-  trigger(0),
-  table(0)
+  destinationButtons(0),
+  routeTable(0)
 {
 }
 
@@ -20,16 +34,100 @@ Ui::~Ui()
 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);
 
-  trigger = new QPushButton( centralWidget );
-  trigger->setObjectName( QString::fromUtf8("trigger") );
-  trigger->setText( "HOME" );
-  trigger->setGeometry( QRect( 0, 0, 150, 40 ) );
+  QRadioButton *homeButton = new QRadioButton();
+  homeButton->setObjectName( QString::fromUtf8("homeButton") );
+  homeButton->setText( "GPS->HOME" );
+  homeButton->setEnabled(false);
+  homeButton->setFixedSize( QSize( ButtonWidth, ButtonHeight ) );
+
+  QRadioButton *workButton = new QRadioButton();
+  workButton->setObjectName( QString::fromUtf8("workButton") );
+  workButton->setText( "GPS->WORK" );
+  workButton->setEnabled(false);
+
+  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();
+
+  routeTable = new QTableWidget( 1, 2 );
+  QStringList columnHeaders;
+  columnHeaders << "Time" << "Bus";
+  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;
 
-  table = new QTableWidget( 1, 2, centralWidget );
-  table->setObjectName( QString::fromUtf8("table") );
-  table->setGeometry( QRect( 151, 0, 650, 480 ) );
+  if ( ok ) {
+    qDebug() << "new address" << address;
+    Locations *locations=Locations::instance();
+    Location *location = locations->location( label );
+    qDebug() << "location" << location;
+    if ( location ) {
+      location->resolveAddress( address );
+    }
+  }
 }