Added dialogs to change home and work locations.
[ptas] / zouba / ui.cpp
1 #include "ui.h"
2
3 #include "messagetable.h"
4 #include "locations.h"
5
6 #include <QMainWindow>
7 #include <QRadioButton>
8 #include <QTableWidget>
9 #include <QString>
10 #include <QRect>
11 #include <QButtonGroup>
12 #include <QHeaderView>
13 #include <QObject>
14 #include <QMenuBar>
15 #include <QHBoxLayout>
16 #include <QVBoxLayout>
17 #include <QSizePolicy>
18 #include <QInputDialog>
19 #include <QDebug>
20
21 MessageTable *Ui::messageTable = 0;
22
23 Ui::Ui() :
24   centralWidget(0),
25   destinationButtons(0),
26   routeTable(0)
27 {
28 }
29
30 Ui::~Ui()
31 {
32 }
33
34 void Ui::setupUi( QMainWindow *mainWindow )
35 {
36   mainWindow->resize(800,480);
37   QMenu *menu = mainWindow->menuBar()->addMenu("Settings");
38
39   QAction *setHomeAddressAction = new QAction("Set home address", this);
40   QAction *setWorkAddressAction = new QAction("Set work address", this);
41   menu->addAction(setHomeAddressAction);
42   menu->addAction(setWorkAddressAction);
43
44   connect(
45       setHomeAddressAction, SIGNAL(triggered()),
46       this, SLOT(setHomeAddress())
47       );
48   connect(
49       setWorkAddressAction, SIGNAL(triggered()),
50       this, SLOT(setWorkAddress())
51       );
52
53   centralWidget = new QWidget( mainWindow );
54   mainWindow->setCentralWidget(centralWidget);
55
56   QRadioButton *homeButton = new QRadioButton();
57   homeButton->setObjectName( QString::fromUtf8("homeButton") );
58   homeButton->setText( "GPS->HOME" );
59   homeButton->setEnabled(false);
60   homeButton->setFixedSize( QSize( ButtonWidth, ButtonHeight ) );
61
62   QRadioButton *workButton = new QRadioButton();
63   workButton->setObjectName( QString::fromUtf8("workButton") );
64   workButton->setText( "GPS->WORK" );
65   workButton->setEnabled(false);
66
67   destinationButtons = new QButtonGroup();
68   destinationButtons->addButton( homeButton, HomeButtonId );
69   destinationButtons->addButton( workButton, WorkButtonId );
70   destinationButtons->setExclusive( true );
71
72   buttonLayout = new QVBoxLayout();
73   buttonLayout->addWidget( homeButton );
74   buttonLayout->addWidget( workButton );
75   buttonLayout->addStretch();
76
77   routeTable = new QTableWidget( 1, 2 );
78   QStringList columnHeaders;
79   columnHeaders << "Time" << "Bus";
80   routeTable->setHorizontalHeaderLabels( columnHeaders );
81   routeTable->verticalHeader()->hide();
82
83   QHBoxLayout *topLayout = new QHBoxLayout();
84   topLayout->addLayout( buttonLayout );
85   topLayout->addWidget( routeTable );
86
87   messageTable = new MessageTable();
88   messageTable->setObjectName( QString::fromUtf8("messageTable") );
89
90   QVBoxLayout *mainLayout = new QVBoxLayout();
91   mainLayout->addLayout( topLayout );
92   mainLayout->addWidget( messageTable );
93
94   centralWidget->setLayout( mainLayout );
95 }
96
97 void Ui::setHomeAddress()
98 {
99   setAddress( "home" );
100 }
101
102 void Ui::setWorkAddress()
103 {
104   setAddress( "work" );
105 }
106
107 void Ui::setAddress( const QString &label )
108 {
109   bool ok;
110   QString address = QInputDialog::getText(
111      centralWidget,
112      tr("Enter address for \""+QString(label).toLatin1()+"\""),
113      tr("Address"),
114      QLineEdit::Normal,
115      "",
116      &ok
117      );
118
119   qDebug() << "ok=" << ok;
120
121   if ( ok ) {
122     qDebug() << "new address" << address;
123     Locations locations;
124     Location *location = locations.location( label );
125     qDebug() << "location" << location;
126     if ( location ) {
127       location->resolveAddress( address );
128     }
129   }
130 }