3 #include "messagetable.h"
7 #include <QRadioButton>
8 #include <QTableWidget>
11 #include <QButtonGroup>
12 #include <QHeaderView>
15 #include <QHBoxLayout>
16 #include <QVBoxLayout>
17 #include <QSizePolicy>
18 #include <QInputDialog>
21 MessageTable *Ui::messageTable = 0;
25 destinationButtons(0),
27 usingFakeGps( false ),
28 messagesShown( false ),
31 Locations *locations = Locations::instance();
32 Location *workLocation = locations->location( "work" );
33 fakeLocation = new Location();
34 *fakeLocation = *workLocation;
35 fakeLocation->setLabel( "fakegps" );
42 void Ui::setupUi( QMainWindow *mainWindow )
44 mainWindow->resize(800,480);
45 menu = mainWindow->menuBar()->addMenu("Settings");
47 QAction *setHomeAddressAction = new QAction("Set home address", this);
48 QAction *setWorkAddressAction = new QAction("Set work address", this);
49 toggleMessagesAction = new QAction("Show messages", this);
50 toggleFakeGpsAction = new QAction("Use fake GPS", this);
51 menu->addAction(setHomeAddressAction);
52 menu->addAction(setWorkAddressAction);
53 menu->addAction(toggleMessagesAction);
54 menu->addAction(toggleFakeGpsAction);
57 setHomeAddressAction, SIGNAL(triggered()),
58 this, SLOT(setHomeAddress())
61 setWorkAddressAction, SIGNAL(triggered()),
62 this, SLOT(setWorkAddress())
65 toggleMessagesAction, SIGNAL(triggered()),
66 this, SLOT(toggleMessages())
69 toggleFakeGpsAction, SIGNAL(triggered()),
70 this, SLOT(toggleFakeGps())
73 centralWidget = new QWidget( mainWindow );
74 mainWindow->setCentralWidget(centralWidget);
76 QRadioButton *homeButton = new QRadioButton();
77 homeButton->setObjectName( QString::fromUtf8("homeButton") );
78 homeButton->setText( "GPS->HOME" );
79 homeButton->setEnabled(false);
80 homeButton->setFixedSize( QSize( ButtonWidth, ButtonHeight ) );
82 QRadioButton *workButton = new QRadioButton();
83 workButton->setObjectName( QString::fromUtf8("workButton") );
84 workButton->setText( "GPS->WORK" );
85 workButton->setEnabled(false);
87 destinationButtons = new QButtonGroup();
88 destinationButtons->addButton( homeButton, HomeButtonId );
89 destinationButtons->addButton( workButton, WorkButtonId );
90 destinationButtons->setExclusive( true );
92 buttonLayout = new QVBoxLayout();
93 buttonLayout->addWidget( homeButton );
94 buttonLayout->addWidget( workButton );
95 buttonLayout->addStretch();
97 routeTable = new QTableWidget( 1, 2 );
98 QStringList columnHeaders;
99 columnHeaders << "Time" << "Bus";
100 routeTable->setHorizontalHeaderLabels( columnHeaders );
101 routeTable->verticalHeader()->hide();
103 QHBoxLayout *topLayout = new QHBoxLayout();
104 topLayout->addLayout( buttonLayout );
105 topLayout->addWidget( routeTable );
107 messageTable = new MessageTable();
108 messageTable->setObjectName( QString::fromUtf8("messageTable") );
109 messageTable->hide();
111 QVBoxLayout *mainLayout = new QVBoxLayout();
112 mainLayout->addLayout( topLayout );
113 mainLayout->addWidget( messageTable );
115 centralWidget->setLayout( mainLayout );
118 void Ui::setHomeAddress()
120 setAddress( "home" );
123 void Ui::setWorkAddress()
125 setAddress( "work" );
128 void Ui::toggleMessages()
130 messagesShown = !messagesShown;
132 if ( messagesShown ) {
139 void Ui::hideMessages()
141 messageTable->hide();
142 toggleMessagesAction->setText( "Show messages" );
145 void Ui::showMessages()
147 messageTable->show();
148 toggleMessagesAction->setText( "Hide messages" );
151 void Ui::toggleFakeGps()
153 usingFakeGps = !usingFakeGps;
155 if ( usingFakeGps ) {
162 void Ui::useFakeGps()
164 emit fakeGpsPressed( fakeLocation );
165 toggleFakeGpsAction->setText( "Use Live GPS" );
168 void Ui::useLiveGps()
170 emit liveGpsPressed();
171 toggleFakeGpsAction->setText( "Use Fake GPS" );
174 void Ui::setAddress( const QString &label )
176 Locations *locations=Locations::instance();
177 Location *location=locations->location( label );
180 QString address = QInputDialog::getText(
182 tr("Enter address for \""+QString(label).toLatin1()+"\""),
190 qDebug() << "new address" << address;
191 Locations *locations = Locations::instance();
192 Location *location = locations->location( label );
193 qDebug() << "location" << location;
195 location->resolveAddress( address );