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>
23 #include <QMaemo5ValueButton>
24 #include <QMaemo5ListPickSelector>
25 #include <QStandardItemModel>
28 m_centralWidget(NULL),
39 void Ui::setupUi( QMainWindow *mainWindow )
41 m_mainWindow = mainWindow;
42 m_mainWindow->setAttribute(Qt::WA_Maemo5StackedWindow);
43 //m_mainWindow->resize(800,480);
45 m_locDisp = new LocationsDisplay(mainWindow);
47 m_menu = mainWindow->menuBar();
49 /*QAction *setHomeAddressAction = new QAction("Set home address", this);
50 QAction *setWorkAddressAction = new QAction("Set work address", this);*/
51 QAction *modifyLocationsAction = new QAction("Modify locations", this);
52 m_UseGpsAction = new QAction("Use GPS", this);
53 m_UseGpsAction->setCheckable(true);
54 m_UseGpsAction->setChecked(true);
55 /*m_menu->addAction(setHomeAddressAction);
56 m_menu->addAction(setWorkAddressAction);*/
57 m_menu->addAction(m_UseGpsAction);
58 m_menu->addAction(modifyLocationsAction);
61 setHomeAddressAction, SIGNAL(triggered()),
62 this, SLOT(setHomeAddress())
65 setWorkAddressAction, SIGNAL(triggered()),
66 this, SLOT(setWorkAddress())
69 connect(modifyLocationsAction, SIGNAL(triggered()), m_locDisp, SLOT(show()));
71 Locations* locations = Locations::GetInstance();
72 connect(locations, SIGNAL(locationsChanged()), this, SLOT(setLocations()));
74 m_centralWidget = new QWidget( m_mainWindow );
75 m_mainWindow->setCentralWidget( m_centralWidget);
77 m_locationsModel = new QStandardItemModel(0,1);
80 m_fromButton = new QMaemo5ValueButton(QString::fromUtf8("From"));
81 m_fromButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
82 QMaemo5ListPickSelector *fromSelector = new QMaemo5ListPickSelector();
83 fromSelector->setModel(m_locationsModel);
84 m_fromButton->setPickSelector(fromSelector);
86 m_toButton = new QMaemo5ValueButton(QString::fromUtf8("To"));
87 m_toButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
88 QMaemo5ListPickSelector *toSelector = new QMaemo5ListPickSelector();
89 toSelector->setModel(m_locationsModel);
90 m_toButton->setPickSelector(toSelector);
92 m_routeButton = new QPushButton("Route");
94 m_routeButtons = new QButtonGroup();
95 m_routeButtons->setExclusive( true );
96 m_routeStack = new QVBoxLayout();
97 for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
98 QRadioButton *button = new QRadioButton();
99 button->setObjectName( "routeButton"+i );
100 button->setEnabled( false );
102 m_routeStack->addWidget( button, i );
103 m_routeButtons->addButton( button, i );
105 m_routeStack->addStretch();
107 QStringList headers( QStringList() << "How" << "Time" << "Dist" << "Dep" << "Arr" );
108 m_routeDetailTable = new QTableWidget();
109 m_routeDetailTable->setColumnCount( headers.count() );
110 m_routeDetailTable->setHorizontalHeaderLabels( headers );
111 m_routeDetailTable->resizeColumnsToContents();
112 m_routeDetailTable->setSelectionMode( QAbstractItemView::NoSelection );
114 QHBoxLayout *topLayout = new QHBoxLayout();
115 topLayout->addLayout( m_routeStack );
116 topLayout->addWidget( m_routeDetailTable );
118 m_buttonLayout = new QGridLayout();
119 m_buttonLayout->addWidget(m_fromButton, 0, 0);
120 m_buttonLayout->addWidget(m_toButton, 0, 1);
121 m_buttonLayout->addWidget(m_routeButton, 0, 2);
123 m_mainLayout = new QVBoxLayout();
124 m_mainLayout->addLayout( topLayout );
125 m_mainLayout->addLayout( m_buttonLayout );
127 m_centralWidget->setLayout( m_mainLayout );
130 void Ui::setLocations()
132 qDebug() << "Setting locations for main menu selectors.";
133 Locations *locations = Locations::GetInstance();
135 m_locationsModel->clear();
136 QStandardItem *item = new QStandardItem(QString("GPS"));
137 item->setTextAlignment(Qt::AlignCenter);
138 item->setEditable(false);
139 m_locationsModel->appendRow(item);
141 for (int index = 1; index <= locations->size(); ++index)
143 item = new QStandardItem(locations->getLocation(index)->label());
144 item->setTextAlignment(Qt::AlignCenter);
145 item->setEditable(false);
146 m_locationsModel->appendRow(item);
150 void Ui::setHomeAddress()
152 setAddress( "home" );
155 void Ui::setWorkAddress()
157 setAddress( "work" );
160 void Ui::setAddress( const QString &label )
162 /*Locations locations;
163 Location *location=locations.location( label );
166 QString address = QInputDialog::getText(
168 tr("Enter address for \""+QString(label).toLatin1()+"\""),
176 qDebug() << "new address" << address;
178 Location *location = locations.location( label );
179 qDebug() << "location" << location;
181 //location->resolveAddress( address );
186 /*void Ui::modifyLocations()
191 void Ui::setBusy( bool busy )
193 m_mainWindow->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);