]> git.sur5r.net Git - minitube/blobdiff - src/searchview.cpp
Fixed search widget
[minitube] / src / searchview.cpp
index d09c51e3ba749f194c1522c91992acd20ded9373..5b9add75cdcdcc5d1e96f6f68fc3ba63a1761a2e 100644 (file)
@@ -37,6 +37,7 @@ $END_LICENSE */
 #endif
 #include "mainwindow.h"
 #include "painterutils.h"
+#include "iconutils.h"
 
 namespace The {
 QHash<QString, QAction*>* globalActions();
@@ -46,7 +47,7 @@ static const QString recentKeywordsKey = "recentKeywords";
 static const QString recentChannelsKey = "recentChannels";
 static const int PADDING = 30;
 
-SearchView::SearchView(QWidget *parent) : QWidget(parent) {
+SearchView::SearchView(QWidget *parent) : View(parent) {
 
 #if defined(APP_MAC) | defined(APP_WIN)
     // speedup painting since we'll paint the whole background
@@ -70,7 +71,7 @@ SearchView::SearchView(QWidget *parent) : QWidget(parent) {
     mainLayout->addLayout(hLayout);
 
     QLabel *logo = new QLabel(this);
-    logo->setPixmap(QPixmap(":/images/app.png"));
+    logo->setPixmap(IconUtils::pixmap(":/images/app.png"));
     hLayout->addWidget(logo, 0, Qt::AlignTop);
     hLayout->addSpacing(PADDING);
 
@@ -81,7 +82,6 @@ SearchView::SearchView(QWidget *parent) : QWidget(parent) {
     QLabel *welcomeLabel =
             new QLabel("<h1 style='font-weight:100'>" +
                        tr("Welcome to <a href='%1'>%2</a>,")
-                       // .replace("<a ", "<a style='color:palette(text)'")
                        .replace("<a ", "<a style='text-decoration:none; color:palette(text);font-weight:normal' ")
                        .arg(Constants::WEBSITE, Constants::NAME)
                        + "</h1>", this);
@@ -104,10 +104,13 @@ SearchView::SearchView(QWidget *parent) : QWidget(parent) {
     QBoxLayout *tipLayout = new QHBoxLayout();
     tipLayout->setSpacing(10);
 
+#ifndef APP_MAC
+    const QFont &biggerFont = FontUtils::big();
+#endif
+
     //: "Enter", as in "type". The whole phrase says: "Enter a keyword to start watching videos"
     QLabel *tipLabel = new QLabel(tr("Enter"), this);
 #ifndef APP_MAC
-    const QFont &biggerFont = FontUtils::big();
     tipLabel->setFont(biggerFont);
 #endif
     tipLayout->addWidget(tipLabel);
@@ -133,22 +136,30 @@ SearchView::SearchView(QWidget *parent) : QWidget(parent) {
     QHBoxLayout *searchLayout = new QHBoxLayout();
     searchLayout->setAlignment(Qt::AlignVCenter);
 
-    queryEdit = new SearchLineEdit(this);
-#ifndef APP_MAC_SEARCHFIELD
-    queryEdit->setFont(biggerFont);
+#ifdef APP_MAC_SEARCHFIELD
+    queryEdit = new SearchLineEditMac(this);
+#else
+    SearchLineEdit *sle = new SearchLineEdit(this);
+    sle->setFont(biggerFont);
+    queryEdit = sle;
 #endif
-    connect(queryEdit, SIGNAL(search(const QString&)), SLOT(watch(const QString&)));
-    connect(queryEdit, SIGNAL(textEdited(const QString &)), SLOT(textChanged(const QString &)));
-    connect(queryEdit, SIGNAL(suggestionAccepted(Suggestion*)), SLOT(suggestionAccepted(Suggestion*)));
+
+    qDebug() << "queryEdit->toWidget()" << (queryEdit->toWidget() == 0) << queryEdit->toWidget();
+    connect(queryEdit->toWidget(), SIGNAL(search(const QString&)), SLOT(watch(const QString&)));
+    connect(queryEdit->toWidget(), SIGNAL(textChanged(const QString &)), SLOT(textChanged(const QString &)));
+    connect(queryEdit->toWidget(), SIGNAL(suggestionAccepted(Suggestion*)), SLOT(suggestionAccepted(Suggestion*)));
 
     youtubeSuggest = new YTSuggester(this);
     channelSuggest = new ChannelSuggest(this);
     searchTypeChanged(0);
 
-    searchLayout->addWidget(queryEdit);
+    searchLayout->addWidget(queryEdit->toWidget());
     searchLayout->addSpacing(10);
 
     watchButton = new QPushButton(tr("Watch"), this);
+#ifndef APP_MAC
+    watchButton->setFont(biggerFont);
+#endif
     watchButton->setDefault(true);
     watchButton->setEnabled(false);
     watchButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
@@ -204,7 +215,7 @@ void SearchView::appear() {
     queryEdit->selectAll();
     queryEdit->enableSuggest();
 
-    if (!queryEdit->hasFocus()) queryEdit->setFocus();
+    if (!queryEdit->toWidget()->hasFocus()) queryEdit->toWidget()->setFocus();
 }
 
 void SearchView::disappear() {
@@ -249,8 +260,8 @@ void SearchView::updateRecentKeywords() {
                                        + display + "</a>", this);
         itemLabel->setAttribute(Qt::WA_DeleteOnClose);
         itemLabel->setProperty("recentItem", true);
-        itemLabel->setMaximumWidth(queryEdit->width() + watchButton->width());
-        // itemLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+        itemLabel->setMaximumWidth(queryEdit->toWidget()->width() + watchButton->width());
+        itemLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
         // Make links navigable with the keyboard too
         itemLabel->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard | Qt::LinksAccessibleByMouse);
         if (needStatusTip)
@@ -291,7 +302,7 @@ void SearchView::updateRecentChannels() {
                                        + display + "</a>", this);
         itemLabel->setAttribute(Qt::WA_DeleteOnClose);
         itemLabel->setProperty("recentItem", true);
-        itemLabel->setMaximumWidth(queryEdit->width() + watchButton->width());
+        itemLabel->setMaximumWidth(queryEdit->toWidget()->width() + watchButton->width());
         // itemLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
         // Make links navigable with the keyboard too
         itemLabel->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard | Qt::LinksAccessibleByMouse);
@@ -316,7 +327,7 @@ void SearchView::watch(const QString &query) {
 
     // check for empty query
     if (q.length() == 0) {
-        queryEdit->setFocus(Qt::OtherFocusReason);
+        queryEdit->toWidget()->setFocus(Qt::OtherFocusReason);
         return;
     }
 
@@ -336,7 +347,7 @@ void SearchView::watch(const QString &query) {
 
 void SearchView::watchChannel(const QString &channelId) {
     if (channelId.length() == 0) {
-        queryEdit->setFocus(Qt::OtherFocusReason);
+        queryEdit->toWidget()->setFocus(Qt::OtherFocusReason);
         return;
     }
 
@@ -358,7 +369,7 @@ void SearchView::watchKeywords(const QString &query) {
 
     // check for empty query
     if (query.length() == 0) {
-        queryEdit->setFocus(Qt::OtherFocusReason);
+        queryEdit->toWidget()->setFocus(Qt::OtherFocusReason);
         return;
     }
 
@@ -402,7 +413,7 @@ void SearchView::searchTypeChanged(int index) {
         queryEdit->setSuggester(channelSuggest);
     }
     queryEdit->selectAll();
-    queryEdit->setFocus();
+    queryEdit->toWidget()->setFocus();
 }
 
 void SearchView::suggestionAccepted(Suggestion *suggestion) {