3 #include "logic/locations.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 #include <QPushButton>
24 #include <QMaemo5ValueButton>
25 #include <QMaemo5ListPickSelector>
27 #include <QStandardItemModel>
30 m_centralWidget(NULL),
41 void UiClass::setupUi( QMainWindow *mainWindow )
43 m_mainWindow = mainWindow;
45 m_mainWindow->setAttribute(Qt::WA_Maemo5StackedWindow);
47 //m_mainWindow->resize(800,480);
49 m_locDisp = new LocationsDisplayWindow(mainWindow);
51 m_menu = mainWindow->menuBar();
53 /*QAction *setHomeAddressAction = new QAction("Set home address", this);
54 QAction *setWorkAddressAction = new QAction("Set work address", this);*/
55 QAction *modifyLocationsAction = new QAction("Modify locations", this);
56 m_UseGpsAction = new QAction("Use GPS", this);
57 m_UseGpsAction->setCheckable(true);
58 m_UseGpsAction->setChecked(true);
59 connect(this->m_UseGpsAction, SIGNAL(toggled(bool)), this, SLOT(setLocations()));
60 /*m_menu->addAction(setHomeAddressAction);
61 m_menu->addAction(setWorkAddressAction);*/
62 m_menu->addAction(m_UseGpsAction);
63 m_menu->addAction(modifyLocationsAction);
66 setHomeAddressAction, SIGNAL(triggered()),
67 this, SLOT(setHomeAddress())
70 setWorkAddressAction, SIGNAL(triggered()),
71 this, SLOT(setWorkAddress())
74 connect(modifyLocationsAction, SIGNAL(triggered()), m_locDisp, SLOT(show()));
76 Locations* locations = Locations::GetInstance();
77 connect(locations, SIGNAL(locationsChanged()), this, SLOT(setLocations()));
79 m_centralWidget = new QWidget( m_mainWindow );
80 m_mainWindow->setCentralWidget( m_centralWidget);
82 m_locationsModel = new QStandardItemModel(0,1);
86 m_fromButton = new QMaemo5ValueButton(QString::fromUtf8("From"));
87 m_fromButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
88 QMaemo5ListPickSelector *fromSelector = new QMaemo5ListPickSelector();
89 fromSelector->setModel(m_locationsModel);
90 m_fromButton->setPickSelector(fromSelector);
92 m_toButton = new QMaemo5ValueButton(QString::fromUtf8("To"));
93 m_toButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
94 QMaemo5ListPickSelector *toSelector = new QMaemo5ListPickSelector();
95 toSelector->setModel(m_locationsModel);
96 m_toButton->setPickSelector(toSelector);
99 m_routeButton = new QPushButton("Route");
101 m_routeButtons = new QButtonGroup();
102 m_routeButtons->setExclusive( true );
103 m_routeStack = new QVBoxLayout();
104 for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
105 QRadioButton *button = new QRadioButton();
106 button->setObjectName( "routeButton"+i );
107 button->setEnabled( false );
109 m_routeStack->addWidget( button, i );
110 m_routeButtons->addButton( button, i );
112 m_routeStack->addStretch();
114 QStringList headers( QStringList() << "How" << "Time" << "Dist" << "Dep" << "Arr" );
115 m_routeDetailTable = new QTableWidget();
116 m_routeDetailTable->setColumnCount( headers.count() );
117 m_routeDetailTable->setHorizontalHeaderLabels( headers );
118 m_routeDetailTable->resizeColumnsToContents();
119 m_routeDetailTable->setSelectionMode( QAbstractItemView::NoSelection );
121 QHBoxLayout *topLayout = new QHBoxLayout();
122 topLayout->addLayout( m_routeStack );
123 topLayout->addWidget( m_routeDetailTable );
125 m_buttonLayout = new QGridLayout();
127 m_buttonLayout->addWidget(m_fromButton, 0, 0);
128 m_buttonLayout->addWidget(m_toButton, 0, 1);
130 m_buttonLayout->addWidget(m_routeButton, 0, 2);
132 m_mainLayout = new QVBoxLayout();
133 m_mainLayout->addLayout( topLayout );
134 m_mainLayout->addLayout( m_buttonLayout );
136 m_centralWidget->setLayout( m_mainLayout );
139 void UiClass::setLocations()
141 qDebug() << "Setting locations for main menu selectors.";
142 Locations *locations = Locations::GetInstance();
144 m_locationsModel->clear();
146 if (this->m_UseGpsAction->isChecked())
148 item = new QStandardItem(QString("GPS"));
149 item->setTextAlignment(Qt::AlignCenter);
150 item->setEditable(false);
151 m_locationsModel->appendRow(item);
154 for (int index = 1; index <= locations->size(); ++index)
156 item = new QStandardItem(locations->getLocation(index)->label());
157 item->setTextAlignment(Qt::AlignCenter);
158 item->setEditable(false);
159 m_locationsModel->appendRow(item);
163 void UiClass::setHomeAddress()
165 setAddress( "home" );
168 void UiClass::setWorkAddress()
170 setAddress( "work" );
173 void UiClass::setAddress( const QString &label )
175 /*Locations locations;
176 Location *location=locations.location( label );
179 QString address = QInputDialog::getText(
181 tr("Enter address for \""+QString(label).toLatin1()+"\""),
189 qDebug() << "new address" << address;
191 Location *location = locations.location( label );
192 qDebug() << "location" << location;
194 //location->resolveAddress( address );
199 /*void Ui::modifyLocations()
204 void UiClass::setBusy( bool busy )
207 m_mainWindow->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);