2 #include "segmentedcontrol.h"
3 #include "searchview.h"
4 #include "standardfeedsview.h"
6 #include "mainwindow.h"
8 #include "ytstandardfeed.h"
10 HomeView::HomeView(QWidget *parent) : QWidget(parent) {
11 standardFeedsView = 0;
14 QBoxLayout *layout = new QVBoxLayout(this);
16 layout->setSpacing(0);
19 layout->addWidget(bar);
21 stackedWidget = new QStackedWidget();
22 layout->addWidget(stackedWidget);
24 searchView = new SearchView();
25 connect(searchView, SIGNAL(search(SearchParams*)),
26 MainWindow::instance(), SLOT(showMedia(SearchParams*)));
27 stackedWidget->addWidget(searchView);
30 void HomeView::setupBar() {
31 bar = new SegmentedControl(this);
33 QAction *action = new QAction(tr("Search"), this);
34 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_1));
35 action->setStatusTip(tr("Find videos and channels by keyword"));
36 connect(action, SIGNAL(triggered()), SLOT(showSearch()));
37 bar->addAction(action);
38 bar->setCheckedAction(action);
40 action = new QAction(tr("Browse"), this);
41 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_2));
42 action->setStatusTip(tr("Browse videos by category"));
43 connect(action, SIGNAL(triggered()), SLOT(showStandardFeeds()));
44 bar->addAction(action);
47 action = new QAction(tr("User"), this);
48 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_3));
49 action->setStatusTip(tr("Your favorite videos, subscriptions and playlists"));
50 connect(action, SIGNAL(triggered()), SLOT(showUser()));
51 bar->addAction(action);
54 foreach (QAction* action, bar->actions()) {
55 // action->setEnabled(false);
57 action->setAutoRepeat(false);
58 if (!action->shortcut().isEmpty())
60 action->statusTip() + " (" +
61 action->shortcut().toString(QKeySequence::NativeText) + ")");
65 void HomeView::showWidget(QWidget *widget) {
66 QWidget* currentWidget = stackedWidget->currentWidget();
67 if (currentWidget == widget) return;
68 QMetaObject::invokeMethod(currentWidget, "disappear");
69 currentWidget->setEnabled(false);
70 stackedWidget->setCurrentWidget(widget);
71 widget->setEnabled(true);
72 QMetaObject::invokeMethod(widget, "appear");
73 bar->setCheckedAction(stackedWidget->currentIndex());
74 // autoChosenView = false;
78 void HomeView::appear() {
79 QMetaObject::invokeMethod(stackedWidget->currentWidget(), "appear");
82 void HomeView::disappear() {
83 QMetaObject::invokeMethod(stackedWidget->currentWidget(), "disappear");
86 void HomeView::showSearch() {
87 showWidget(searchView);
90 void HomeView::showStandardFeeds() {
91 if (!standardFeedsView) {
92 standardFeedsView = new StandardFeedsView();
93 connect(standardFeedsView, SIGNAL(activated(VideoSource*)),
94 MainWindow::instance(),
95 SLOT(showMedia(VideoSource*)));
96 stackedWidget->addWidget(standardFeedsView);
98 showWidget(standardFeedsView);
101 void HomeView::showUser() {
103 userView = new UserView(this);
104 stackedWidget->addWidget(userView);
106 showWidget(userView);