1 #include "regionsview.h"
3 #include "mainwindow.h"
5 RegionsView::RegionsView(QWidget *parent) : QWidget(parent) {
6 QBoxLayout *l = new QVBoxLayout(this);
10 layout = new QGridLayout();
12 layout->setSpacing(0);
15 addRegion(YTRegions::worldwideRegion());
16 foreach(YTRegion region, YTRegions::list())
19 doneButton = new QPushButton(tr("Done"));
20 doneButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
21 doneButton->setDefault(true);
22 doneButton->setProperty("custom", true);
23 doneButton->setProperty("important", true);
24 doneButton->setProperty("big", true);
25 connect(doneButton, SIGNAL(clicked()), MainWindow::instance(), SLOT(goBack()));
26 l->addWidget(doneButton, 0, Qt::AlignCenter);
29 void RegionsView::addRegion(const YTRegion ®ion) {
30 QPushButton *button = new QPushButton(region.name);
31 button->setProperty("regionId", region.id);
32 button->setCheckable(true);
33 button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
34 button->setFocusPolicy(Qt::StrongFocus);
35 button->setIcon(YTRegions::iconForRegionId(region.id));
36 connect(button, SIGNAL(clicked()), SLOT(buttonClicked()));
37 const int i = layout->count();
38 static const int rows = 10;
39 layout->addWidget(button, i % rows, i / rows);
42 void RegionsView::appear() {
43 doneButton->setFocus();
45 QString currentRegionId = YTRegions::currentRegionId();
46 for (int i = 0; i < layout->count(); i++) {
47 QLayoutItem *item = layout->itemAt(i);
48 QPushButton *b = static_cast<QPushButton*>(item->widget());
49 QString regionId = b->property("regionId").toString();
50 b->setChecked(currentRegionId == regionId);
54 void RegionsView::buttonClicked() {
55 QObject* o = sender();
56 QString regionId = o->property("regionId").toString();
57 YTRegions::setRegion(regionId);
61 // uncheck other buttons
63 for (int i = 0; i < layout->count(); i++) {
64 QLayoutItem *item = layout->itemAt(i);
65 QPushButton *b = static_cast<QPushButton*>(item->widget());
66 if (b != o && b->isChecked()) b->setChecked(false);