]> git.sur5r.net Git - minitube/blobdiff - src/searchview.cpp
Merge tag 'upstream/2.4'
[minitube] / src / searchview.cpp
index 950d342be9a1c620131a58344f103fd530a04bef..a0037a3d48a0b71690ed0bd59a9e6d073a49d5b5 100644 (file)
@@ -1,3 +1,23 @@
+/* $BEGIN_LICENSE
+
+This file is part of Minitube.
+Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
+
+Minitube is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Minitube is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
+
+$END_LICENSE */
+
 #include "searchview.h"
 #include "constants.h"
 #include "fontutils.h"
 #else
 #include "searchlineedit.h"
 #endif
-#ifndef Q_WS_X11
+#ifdef APP_EXTRA
 #include "extra.h"
 #endif
 #ifdef APP_ACTIVATION
 #include "activation.h"
 #endif
 #include "mainwindow.h"
+#include "painterutils.h"
 
 namespace The {
 QHash<QString, QAction*>* globalActions();
@@ -36,6 +57,8 @@ SearchView::SearchView(QWidget *parent) : QWidget(parent) {
     setAttribute(Qt::WA_OpaquePaintEvent);
 #endif
 
+    setAutoFillBackground(true);
+
     QBoxLayout *mainLayout = new QVBoxLayout(this);
     mainLayout->setMargin(PADDING);
     mainLayout->setSpacing(0);
@@ -61,13 +84,25 @@ SearchView::SearchView(QWidget *parent) : QWidget(parent) {
     hLayout->addLayout(layout);
 
     QLabel *welcomeLabel =
-            new QLabel("<h1 style='font-weight:normal'>" +
+            new QLabel("<h1 style='font-weight:100'>" +
                        tr("Welcome to <a href='%1'>%2</a>,")
                        // .replace("<a ", "<a style='color:palette(text)'")
-                       .replace("<a href", "<a style='text-decoration:none; color:palette(text); font-weight:bold' href")
+                       .replace("<a ", "<a style='text-decoration:none; color:palette(text);font-weight:"
+                            #if defined(APP_UBUNTU) || defined(APP_WIN)
+                                "normal"
+                            #else
+                                "normal"
+                            #endif
+                                "' ")
                        .arg(Constants::WEBSITE, Constants::NAME)
                        + "</h1>", this);
     welcomeLabel->setOpenExternalLinks(true);
+#ifdef APP_WIN
+    QFont f = welcomeLabel->font();
+    f.setHintingPreference(QFont::PreferNoHinting);
+    f.setFamily("Segoe UI Light");
+    welcomeLabel->setFont(f);
+#endif
     layout->addWidget(welcomeLabel);
 
     layout->addSpacing(PADDING / 2);
@@ -98,11 +133,12 @@ SearchView::SearchView(QWidget *parent) : QWidget(parent) {
     searchLayout->setAlignment(Qt::AlignVCenter);
 
     queryEdit = new SearchLineEdit(this);
+#ifndef APP_MAC
     queryEdit->setFont(biggerFont);
-    queryEdit->setMinimumWidth(queryEdit->fontInfo().pixelSize()*15);
+#endif
     connect(queryEdit, SIGNAL(search(const QString&)), SLOT(watch(const QString&)));
-    connect(queryEdit, SIGNAL(textChanged(const QString &)), SLOT(textChanged(const QString &)));
-    connect(queryEdit, SIGNAL(suggestionAccepted(const QString&)), SLOT(watch(const QString&)));
+    connect(queryEdit, SIGNAL(textEdited(const QString &)), SLOT(textChanged(const QString &)));
+    connect(queryEdit, SIGNAL(suggestionAccepted(Suggestion*)), SLOT(suggestionAccepted(Suggestion*)));
 
     youtubeSuggest = new YTSuggester(this);
     channelSuggest = new ChannelSuggest(this);
@@ -162,11 +198,14 @@ SearchView::SearchView(QWidget *parent) : QWidget(parent) {
 }
 
 void SearchView::appear() {
+    setUpdatesEnabled(false);
     updateRecentKeywords();
     updateRecentChannels();
     queryEdit->selectAll();
     queryEdit->enableSuggest();
-    QTimer::singleShot(0, queryEdit, SLOT(setFocus()));
+    if (!queryEdit->hasFocus())
+        QTimer::singleShot(10, queryEdit, SLOT(setFocus()));
+    setUpdatesEnabled(true);
 }
 
 void SearchView::updateRecentKeywords() {
@@ -280,8 +319,9 @@ void SearchView::watch(QString query) {
         searchParams->setKeywords(query);
     else {
         // remove spaces from channel name
-        query = query.replace(" ", "");
-        searchParams->setAuthor(query);
+        query = query.simplified();
+        query = query.remove(' ');
+        searchParams->setChannelId(query);
         searchParams->setSortBy(SearchParams::SortByNewest);
     }
 
@@ -289,21 +329,19 @@ void SearchView::watch(QString query) {
     emit search(searchParams);
 }
 
-void SearchView::watchChannel(QString channel) {
-
-    channel = channel.simplified();
-
-    // check for empty query
-    if (channel.length() == 0) {
+void SearchView::watchChannel(const QString &channelId) {
+    if (channelId.length() == 0) {
         queryEdit->setFocus(Qt::OtherFocusReason);
         return;
     }
 
-    // remove spaces from channel name
-    channel = channel.remove(" ");
+    QString id = channelId;
+
+    // Fix old settings
+    if (!id.startsWith("UC")) id = "UC" + id;
 
     SearchParams *searchParams = new SearchParams();
-    searchParams->setAuthor(channel);
+    searchParams->setChannelId(id);
     searchParams->setSortBy(SearchParams::SortByNewest);
 
     // go!
@@ -332,9 +370,8 @@ void SearchView::watchKeywords(QString query) {
     emit search(searchParams);
 }
 
-void SearchView::paintEvent(QPaintEvent * /*event*/) {
-    QPainter painter(this);
-
+void SearchView::paintEvent(QPaintEvent *event) {
+    QWidget::paintEvent(event);
 #if defined(APP_MAC) | defined(APP_WIN)
     QBrush brush;
     if (window()->isActiveWindow()) {
@@ -342,21 +379,17 @@ void SearchView::paintEvent(QPaintEvent * /*event*/) {
     } else {
         brush = palette().window();
     }
+    QPainter painter(this);
     painter.fillRect(0, 0, width(), height(), brush);
+    painter.end();
 #endif
-
-    static QLinearGradient shadow;
-    static const int shadowHeight = 10;
-    if (shadow.stops().count() == 2) {
-        shadow.setFinalStop(0, shadowHeight);
-        const qreal initialOpacity = 96;
-        for (qreal i = 0; i <= 1; i += 1.0/shadowHeight) {
-            qreal opacity = qPow(initialOpacity, (1.0 - i)) - 1;
-            shadow.setColorAt(i, QColor(0x00, 0x00, 0x00, opacity));
-        }
-    }
-    QRect r = rect();
-    painter.fillRect(r.x(), r.y(), r.width(), shadowHeight, QBrush(shadow));
+#ifdef APP_UBUNTU
+    QStyleOption o;
+    o.initFrom(this);
+    QPainter p(this);
+    style()->drawPrimitive(QStyle::PE_Widget, &o, &p, this);
+#endif
+    PainterUtils::topShadow(this);
 }
 
 void SearchView::searchTypeChanged(int index) {
@@ -368,3 +401,9 @@ void SearchView::searchTypeChanged(int index) {
     queryEdit->selectAll();
     queryEdit->setFocus();
 }
+
+void SearchView::suggestionAccepted(Suggestion *suggestion) {
+    if (suggestion->type == QLatin1String("channel")) {
+        watchChannel(suggestion->userData);
+    } else watch(suggestion->value);
+}