3 #include "messagetable.h"
7 #include <QRadioButton>
8 #include <QTableWidget>
11 #include <QButtonGroup>
12 #include <QHeaderView>
15 #include <QHBoxLayout>
16 #include <QVBoxLayout>
17 #include <QGridLayout>
18 #include <QSizePolicy>
19 #include <QInputDialog>
22 MessageTable *Ui::messageTable = 0;
26 destinationButtons(0),
28 usingFakeGps( false ),
29 messagesShown( false ),
32 Locations *locations = Locations::instance();
33 Location *workLocation = locations->location( "work" );
34 fakeLocation = new Location();
35 *fakeLocation = *workLocation;
36 fakeLocation->setLabel( "fakegps" );
43 void Ui::setupUi( QMainWindow *mainWindow )
45 mainWindow->resize(800,480);
46 menu = mainWindow->menuBar()->addMenu("Settings");
48 QAction *setHomeAddressAction = new QAction("Set home address", this);
49 QAction *setWorkAddressAction = new QAction("Set work address", this);
50 toggleMessagesAction = new QAction("Show messages", this);
51 toggleFakeGpsAction = new QAction("Use fake GPS", this);
52 menu->addAction(setHomeAddressAction);
53 menu->addAction(setWorkAddressAction);
54 menu->addAction(toggleMessagesAction);
55 menu->addAction(toggleFakeGpsAction);
58 setHomeAddressAction, SIGNAL(triggered()),
59 this, SLOT(setHomeAddress())
62 setWorkAddressAction, SIGNAL(triggered()),
63 this, SLOT(setWorkAddress())
66 toggleMessagesAction, SIGNAL(triggered()),
67 this, SLOT(toggleMessages())
70 toggleFakeGpsAction, SIGNAL(triggered()),
71 this, SLOT(toggleFakeGps())
74 centralWidget = new QWidget( mainWindow );
75 mainWindow->setCentralWidget(centralWidget);
77 QRadioButton *homeButton = new QRadioButton();
78 homeButton->setObjectName( QString::fromUtf8("homeButton") );
79 homeButton->setText( "GPS->HOME" );
80 homeButton->setEnabled(false);
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 routeTable = new QTableWidget( 1, 2 );
93 QStringList columnHeaders;
94 columnHeaders << "Time" << "Bus";
95 routeTable->setHorizontalHeaderLabels( columnHeaders );
96 routeTable->verticalHeader()->hide();
97 routeTable->setSelectionMode( QAbstractItemView::SingleSelection );
99 QHBoxLayout *topLayout = new QHBoxLayout();
100 topLayout->addWidget( routeTable );
102 buttonLayout = new QGridLayout();
103 buttonLayout->addWidget( homeButton, 0, 0 );
104 buttonLayout->addWidget( workButton, 0, 1 );
106 messageTable = new MessageTable();
107 messageTable->setObjectName( QString::fromUtf8("messageTable") );
108 messageTable->hide();
110 QVBoxLayout *mainLayout = new QVBoxLayout();
111 mainLayout->addLayout( topLayout );
112 mainLayout->addWidget( messageTable );
113 mainLayout->addLayout( buttonLayout );
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 );