Locations editing made possible
[ptas] / zouba / src / ui.cpp
index 7660ee0..3c75406 100644 (file)
@@ -1,7 +1,7 @@
 #include "ui.h"
 
-#include "messagetable.h"
 #include "locations.h"
+#include "ytv.h"
 
 #include <QMainWindow>
 #include <QRadioButton>
 #include <QMenuBar>
 #include <QHBoxLayout>
 #include <QVBoxLayout>
+#include <QGridLayout>
 #include <QSizePolicy>
 #include <QInputDialog>
 #include <QDebug>
-
-MessageTable *Ui::messageTable = 0;
+#include <QMenu>
+#include <QPushButton>
+#include <QMaemo5ValueButton>
+#include <QMaemo5ListPickSelector>
+#include <QStandardItemModel>
 
 Ui::Ui() :
-  centralWidget(0),
-  destinationButtons(0),
-  routeTable(0),
-  usingFakeGps( false ),
-  messagesShown( false ),
-  fakeLocation()
+        m_centralWidget(NULL),
+        m_routeStack(NULL),
+        m_locDisp(NULL)
 {
-  Locations *locations = Locations::instance();
-  Location *workLocation = locations->location( "work" );
-  fakeLocation = new Location();
-  *fakeLocation = *workLocation;
-  fakeLocation->setLabel( "fakegps" );
 }
 
 Ui::~Ui()
 {
+    delete m_locDisp;
 }
 
 void Ui::setupUi( QMainWindow *mainWindow )
 {
-  mainWindow->resize(800,480);
-  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);
-
-  connect(
-      setHomeAddressAction, SIGNAL(triggered()),
-      this, SLOT(setHomeAddress())
-      );
-  connect(
-      setWorkAddressAction, SIGNAL(triggered()),
-      this, SLOT(setWorkAddress())
-      );
-  connect(
-      toggleMessagesAction, SIGNAL(triggered()),
-      this, SLOT(toggleMessages())
-      );
-  connect(
-      toggleFakeGpsAction, SIGNAL(triggered()),
-      this, SLOT(toggleFakeGps())
-      );
-
-  centralWidget = new QWidget( mainWindow );
-  mainWindow->setCentralWidget(centralWidget);
-
-  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") );
-  messageTable->hide();
-
-  QVBoxLayout *mainLayout = new QVBoxLayout();
-  mainLayout->addLayout( topLayout );
-  mainLayout->addWidget( messageTable );
-
-  centralWidget->setLayout( mainLayout );
-}
+    m_mainWindow = mainWindow;
+    m_mainWindow->setAttribute(Qt::WA_Maemo5StackedWindow);
+    //m_mainWindow->resize(800,480);
+
+    m_locDisp = new LocationsDisplay(mainWindow);
+
+    m_menu = mainWindow->menuBar();
+
+    /*QAction *setHomeAddressAction = new QAction("Set home address", this);
+    QAction *setWorkAddressAction = new QAction("Set work address", this);*/
+    QAction *modifyLocationsAction = new QAction("Modify locations", this);
+    m_UseGpsAction  = new QAction("Use GPS", this);
+    m_UseGpsAction->setCheckable(true);
+    m_UseGpsAction->setChecked(true);
+    /*m_menu->addAction(setHomeAddressAction);
+    m_menu->addAction(setWorkAddressAction);*/
+    m_menu->addAction(m_UseGpsAction);
+    m_menu->addAction(modifyLocationsAction);
+
+    /*connect(
+            setHomeAddressAction, SIGNAL(triggered()),
+            this, SLOT(setHomeAddress())
+            );
+    connect(
+            setWorkAddressAction, SIGNAL(triggered()),
+            this, SLOT(setWorkAddress())
+            );*/
+
+    connect(modifyLocationsAction, SIGNAL(triggered()), m_locDisp, SLOT(show()));
+
+    Locations* locations = Locations::GetInstance();
+    connect(locations, SIGNAL(locationsChanged()), this, SLOT(setLocations()));
+
+    m_centralWidget = new QWidget( m_mainWindow );
+    m_mainWindow->setCentralWidget( m_centralWidget);
+
+    m_locationsModel = new QStandardItemModel(0,1);
+    this->setLocations();
+
+    m_fromButton = new QMaemo5ValueButton(QString::fromUtf8("From"));
+    m_fromButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
+    QMaemo5ListPickSelector *fromSelector = new QMaemo5ListPickSelector();
+    fromSelector->setModel(m_locationsModel);
+    m_fromButton->setPickSelector(fromSelector);
+
+    m_toButton = new QMaemo5ValueButton(QString::fromUtf8("To"));
+    m_toButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
+    QMaemo5ListPickSelector *toSelector = new QMaemo5ListPickSelector();
+    toSelector->setModel(m_locationsModel);
+    m_toButton->setPickSelector(toSelector);
+
+    m_routeButton = new QPushButton("Route");
+
+    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 );
+
+        m_routeStack->addWidget( button, i );
+        m_routeButtons->addButton( button, i );
+    }
+    m_routeStack->addStretch();
 
-void Ui::setHomeAddress()
-{
-  setAddress( "home" );
-}
+    QStringList headers( QStringList() << "How" << "Time" << "Dist" << "Dep" << "Arr" );
+    m_routeDetailTable = new QTableWidget();
+    m_routeDetailTable->setColumnCount( headers.count() );
+    m_routeDetailTable->setHorizontalHeaderLabels( headers );
+    m_routeDetailTable->resizeColumnsToContents();
+    m_routeDetailTable->setSelectionMode( QAbstractItemView::NoSelection );
 
-void Ui::setWorkAddress()
-{
-  setAddress( "work" );
-}
+    QHBoxLayout *topLayout = new QHBoxLayout();
+    topLayout->addLayout( m_routeStack );
+    topLayout->addWidget( m_routeDetailTable );
 
-void Ui::toggleMessages()
-{
-  messagesShown = !messagesShown;
+    m_buttonLayout = new QGridLayout();
+    m_buttonLayout->addWidget(m_fromButton, 0, 0);
+    m_buttonLayout->addWidget(m_toButton, 0, 1);
+    m_buttonLayout->addWidget(m_routeButton, 0, 2);
 
-  if ( messagesShown ) {
-    showMessages();
-  } else {
-    hideMessages();
-  }
+    m_mainLayout = new QVBoxLayout();
+    m_mainLayout->addLayout( topLayout );
+    m_mainLayout->addLayout( m_buttonLayout );
+
+    m_centralWidget->setLayout( m_mainLayout );
 }
 
-void Ui::hideMessages()
+void Ui::setLocations()
 {
-  messageTable->hide();
-  toggleMessagesAction->setText( "Show messages" );
+    qDebug() << "Setting locations for main menu selectors.";
+    Locations *locations = Locations::GetInstance();
+
+    m_locationsModel->clear();
+    QStandardItem *item = new QStandardItem(QString("GPS"));
+    item->setTextAlignment(Qt::AlignCenter);
+    item->setEditable(false);
+    m_locationsModel->appendRow(item);
+
+    for (int index = 1; index <= locations->size(); ++index)
+    {
+        item = new QStandardItem(locations->getLocation(index)->label());
+        item->setTextAlignment(Qt::AlignCenter);
+        item->setEditable(false);
+        m_locationsModel->appendRow(item);
+    }
 }
 
-void Ui::showMessages()
+void Ui::setHomeAddress()
 {
-  messageTable->show();
-  toggleMessagesAction->setText( "Hide messages" );
+    setAddress( "home" );
 }
 
-void Ui::toggleFakeGps()
+void Ui::setWorkAddress()
 {
-  usingFakeGps = !usingFakeGps;
-
-  if ( usingFakeGps ) {
-    useFakeGps();
-  } else {
-    useLiveGps();
-  }
+    setAddress( "work" );
 }
 
-void Ui::useFakeGps()
+void Ui::setAddress( const QString &label )
 {
-  emit fakeGpsPressed( fakeLocation );
-  toggleFakeGpsAction->setText( "Use Live GPS" );
+    /*Locations locations;
+    Location *location=locations.location( label );
+
+    bool ok;
+    QString address = QInputDialog::getText(
+            m_centralWidget,
+            tr("Enter address for \""+QString(label).toLatin1()+"\""),
+            tr("Address"),
+            QLineEdit::Normal,
+            location->address(),
+            &ok
+            );
+
+    if ( ok ) {
+        qDebug() << "new address" << address;
+        Locations locations;
+        Location  *location  = locations.location( label );
+        qDebug() << "location" << location;
+        if ( location ) {
+            //location->resolveAddress( address );
+        }
+    }*/
 }
 
-void Ui::useLiveGps()
+/*void Ui::modifyLocations()
 {
-  emit liveGpsPressed();
-  toggleFakeGpsAction->setText( "Use Fake GPS" );
-}
+    LocationsDisplay
+}*/
 
-void Ui::setAddress( const QString &label )
+void Ui::setBusy( bool busy )
 {
-  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
-     );
-
-  if ( ok ) {
-    qDebug() << "new address" << address;
-    Locations *locations = Locations::instance();
-    Location  *location  = locations->location( label );
-    qDebug() << "location" << location;
-    if ( location ) {
-      location->resolveAddress( address );
-    }
-  }
+    m_mainWindow->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
 }