]> git.sur5r.net Git - minitube/blobdiff - src/SearchView.cpp
Imported Upstream version 1.3
[minitube] / src / SearchView.cpp
index 191b1bdaabe80579218a2dc2665a4fc7ebb59510..76f7da4abe9980b65789db1f3b7c1b6bda2e717f 100644 (file)
@@ -1,5 +1,6 @@
 #include "SearchView.h"
-#include "Constants.h"
+#include "constants.h"
+#include "fontutils.h"
 
 namespace The {
     QMap<QString, QAction*>* globalActions();
@@ -10,12 +11,14 @@ static const int PADDING = 30;
 
 SearchView::SearchView(QWidget *parent) : QWidget(parent) {
 
-    QFont biggerFont;
-    biggerFont.setPointSize(biggerFont.pointSize()*1.5);
+    QFont biggerFont = FontUtils::big();
+    QFont smallerFont = FontUtils::smallBold();
 
-    QFont smallerFont;
-    smallerFont.setPointSize(smallerFont.pointSize()*.85);
-    smallerFont.setBold(true);
+#ifdef APP_MAC
+    // speedup painting since we'll paint the whole background
+    // by ourselves anyway in paintEvent()
+    setAttribute(Qt::WA_OpaquePaintEvent);
+#endif
 
     QBoxLayout *mainLayout = new QVBoxLayout();
     mainLayout->setMargin(0);
@@ -27,6 +30,7 @@ SearchView::SearchView(QWidget *parent) : QWidget(parent) {
     mainLayout->addWidget(message);
 
     mainLayout->addStretch();
+    mainLayout->addSpacing(PADDING);
 
     QBoxLayout *hLayout = new QHBoxLayout();
     hLayout->setAlignment(Qt::AlignCenter);
@@ -42,21 +46,22 @@ SearchView::SearchView(QWidget *parent) : QWidget(parent) {
     hLayout->addLayout(layout);
 
     QLabel *welcomeLabel =
-            new QLabel("<h1>" +
+            new QLabel("<h1 style='font-weight:normal'>" +
                        tr("Welcome to <a href='%1'>%2</a>,")
-                       .replace("<a ", "<a style='color:palette(text)'")
+                       // .replace("<a ", "<a style='color:palette(text)'")
+                       .replace("<a href", "<a style='text-decoration:none; color:palette(text); font-weight:bold' href")
                        .arg(Constants::WEBSITE, Constants::APP_NAME)
                        + "</h1>", this);
     welcomeLabel->setOpenExternalLinks(true);
     layout->addWidget(welcomeLabel);
 
-    layout->addSpacing(PADDING);
+    layout->addSpacing(PADDING / 2);
 
     QLabel *tipLabel = new QLabel(tr("Enter a keyword to start watching videos."), this);
     tipLabel->setFont(biggerFont);
     layout->addWidget(tipLabel);
 
-    layout->addSpacing(10);
+    layout->addSpacing(PADDING / 2);
 
     QHBoxLayout *searchLayout = new QHBoxLayout();
     searchLayout->setAlignment(Qt::AlignVCenter);
@@ -81,16 +86,23 @@ SearchView::SearchView(QWidget *parent) : QWidget(parent) {
 
     layout->addItem(searchLayout);
 
-    layout->addSpacing(PADDING);
+    layout->addSpacing(PADDING / 2);
 
     QHBoxLayout *otherLayout = new QHBoxLayout();
+    otherLayout->setMargin(0);
 
     recentKeywordsLayout = new QVBoxLayout();
     recentKeywordsLayout->setSpacing(5);
     recentKeywordsLayout->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
     recentKeywordsLabel = new QLabel(tr("Recent keywords").toUpper(), this);
-    recentKeywordsLabel->hide();
+#ifdef APP_MAC
+    QPalette palette = recentKeywordsLabel->palette();
+    palette.setColor(QPalette::WindowText, QColor(0x65, 0x71, 0x80));
+    recentKeywordsLabel->setPalette(palette);
+#else
     recentKeywordsLabel->setForegroundRole(QPalette::Dark);
+#endif
+    recentKeywordsLabel->hide();
     recentKeywordsLabel->setFont(smallerFont);
     recentKeywordsLayout->addWidget(recentKeywordsLabel);
 
@@ -98,6 +110,7 @@ SearchView::SearchView(QWidget *parent) : QWidget(parent) {
 
     layout->addLayout(otherLayout);
 
+    mainLayout->addSpacing(PADDING);
     mainLayout->addStretch();
 
     setLayout(mainLayout);
@@ -122,9 +135,18 @@ void SearchView::updateRecentKeywords() {
     The::globalActions()->value("clearRecentKeywords")->setEnabled(!keywords.isEmpty());
 
     foreach (QString keyword, keywords) {
-        QLabel *itemLabel = new QLabel("<a href=\"" + keyword
+        QString link = keyword;
+        QString display = keyword;
+        if (keyword.startsWith("http://")) {
+            int separator = keyword.indexOf("|");
+            if (separator > 0 && separator + 1 < keyword.length()) {
+                link = keyword.left(separator);
+                display = keyword.mid(separator+1);
+            }
+        }
+        QLabel *itemLabel = new QLabel("<a href=\"" + link
                                        + "\" style=\"color:palette(text); text-decoration:none\">"
-                                       + keyword + "</a>", this);
+                                       + display + "</a>", this);
 
         itemLabel->setMaximumWidth(queryEdit->width() + watchButton->width());
         // itemLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
@@ -184,6 +206,7 @@ void SearchView::checkForUpdate() {
 void SearchView::gotNewVersion(QString version) {
     message->setText(
             tr("A new version of %1 is available. Please <a href='%2'>update to version %3</a>")
+            .replace("<a href", "<a style='text-decoration:none; color:palette(text); font-weight:bold' href")
             .arg(
                     Constants::APP_NAME,
                     QString(Constants::WEBSITE).append("#download"),
@@ -191,9 +214,24 @@ void SearchView::gotNewVersion(QString version) {
             );
     message->setOpenExternalLinks(true);
     message->setMargin(10);
-    message->setBackgroundRole(QPalette::ToolTipBase);
-    message->setForegroundRole(QPalette::ToolTipText);
-    message->setAutoFillBackground(true);
+    message->setAlignment(Qt::AlignCenter);
+    // message->setBackgroundRole(QPalette::ToolTipBase);
+    // message->setForegroundRole(QPalette::ToolTipText);
+    // message->setAutoFillBackground(true);
+    message->setStyleSheet("QLabel { border-bottom: 1px solid palette(mid); }");
     message->show();
     if (updateChecker) delete updateChecker;
 }
+
+void SearchView::paintEvent(QPaintEvent * /*event*/) {
+#ifdef APP_MAC
+    QBrush brush;
+    if (window()->isActiveWindow()) {
+        brush = QBrush(QColor(0xdd, 0xe4, 0xeb));
+    } else {
+        brush = palette().window();
+    }
+    QPainter painter(this);
+    painter.fillRect(0, 0, width(), height(), brush);
+#endif
+}