]> git.sur5r.net Git - minitube/blobdiff - src/sidebarwidget.cpp
New upstream version 3.4.2
[minitube] / src / sidebarwidget.cpp
index 5a5647fe2f83c00cc98053e9109c4a7539e1ed49..2b1d546e1ab3aaa6df3e66f16713b8799af63b22 100644 (file)
@@ -1,23 +1,42 @@
+/* $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 "sidebarwidget.h"
+#include "mainwindow.h"
 #include "refinesearchbutton.h"
 #include "refinesearchwidget.h"
 #include "sidebarheader.h"
-#ifndef Q_WS_X11
+#ifdef APP_EXTRA
 #include "extra.h"
 #endif
 
-namespace The {
-QHash<QString, QAction*>* globalActions();
-}
-
-SidebarWidget::SidebarWidget(QWidget *parent) :
-    QWidget(parent) {
-    playlist = 0;
+SidebarWidget::SidebarWidget(QWidget *parent) : QWidget(parent), playlistWidth(0) {
+    playlist = nullptr;
 
     QBoxLayout *layout = new QVBoxLayout(this);
     layout->setSpacing(0);
     layout->setMargin(0);
 
+    setBackgroundRole(QPalette::Base);
+    setAutoFillBackground(true);
+
     sidebarHeader = new SidebarHeader();
     layout->addWidget(sidebarHeader);
 
@@ -29,11 +48,9 @@ SidebarWidget::SidebarWidget(QWidget *parent) :
     messageLabel->setAutoFillBackground(true);
     messageLabel->setWordWrap(true);
     messageLabel->setTextFormat(Qt::RichText);
-    messageLabel->setTextInteractionFlags(
-                Qt::LinksAccessibleByKeyboard |
-                Qt::LinksAccessibleByMouse);
-    connect(messageLabel, SIGNAL(linkActivated(QString)),
-            SIGNAL(suggestionAccepted(QString)));
+    messageLabel->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard |
+                                          Qt::LinksAccessibleByMouse);
+    connect(messageLabel, SIGNAL(linkActivated(QString)), SIGNAL(suggestionAccepted(QString)));
     messageLabel->hide();
     layout->addWidget(messageLabel);
 
@@ -44,13 +61,10 @@ SidebarWidget::SidebarWidget(QWidget *parent) :
 }
 
 void SidebarWidget::setup() {
-    static bool isSetup = false;
-    if (isSetup) return;
-    isSetup = true;
-
     refineSearchButton = new RefineSearchButton(this);
-    refineSearchButton->setStatusTip(tr("Refine Search")
-                                     + " (" + QKeySequence(Qt::CTRL + Qt::Key_R).toString(QKeySequence::NativeText) + ")");
+    refineSearchButton->setStatusTip(
+            tr("Refine Search") + " (" +
+            QKeySequence(Qt::CTRL + Qt::Key_R).toString(QKeySequence::NativeText) + ")");
     refineSearchButton->hide();
     connect(refineSearchButton, SIGNAL(clicked()), SLOT(showRefineSearchWidget()));
 
@@ -72,47 +86,50 @@ void SidebarWidget::setPlaylist(QListView *playlist) {
 }
 
 void SidebarWidget::showPlaylist() {
-    setup();
     stackedWidget->setCurrentWidget(playlist);
-    The::globalActions()->value("refine-search")->setChecked(false);
+    MainWindow::instance()->getAction("refineSearch")->setChecked(false);
 }
 
 void SidebarWidget::showRefineSearchWidget() {
     if (!refineSearchWidget->isEnabled()) return;
+    playlistWidth = playlist->width();
+    refineSearchWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
     refineSearchWidget->setDirty(false);
     stackedWidget->setCurrentWidget(refineSearchWidget);
-    refineSearchWidget->setFocus();
-#ifndef Q_WS_X11
+    // refineSearchWidget->setFocus();
+#ifdef APP_EXTRA
     Extra::fadeInWidget(playlist, refineSearchWidget);
 #endif
     refineSearchButton->hide();
-    The::globalActions()->value("refine-search")->setChecked(true);
+    MainWindow::instance()->getAction("refineSearch")->setChecked(true);
 }
 
 void SidebarWidget::hideRefineSearchWidget() {
+    refineSearchWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
+    playlist->resize(playlistWidth, playlist->height());
     stackedWidget->setCurrentWidget(playlist);
     playlist->setFocus();
-#ifndef Q_WS_X11
+#ifdef APP_EXTRA
     Extra::fadeInWidget(refineSearchWidget, playlist);
 #endif
-    The::globalActions()->value("refine-search")->setChecked(false);
+    MainWindow::instance()->getAction("refineSearch")->setChecked(false);
 }
 
 void SidebarWidget::toggleRefineSearch(bool show) {
-    if (show) showRefineSearchWidget();
-    else hideRefineSearchWidget();
+    if (show)
+        showRefineSearchWidget();
+    else
+        hideRefineSearchWidget();
 }
 
 void SidebarWidget::resizeEvent(QResizeEvent *event) {
     QWidget::resizeEvent(event);
-    refineSearchButton->move(
-                playlist->viewport()->width() - refineSearchButton->minimumWidth(),
-                height() - refineSearchButton->minimumHeight());
+    refineSearchButton->move(playlist->viewport()->width() - refineSearchButton->minimumWidth(),
+                             height() - refineSearchButton->minimumHeight());
 }
 
 void SidebarWidget::enterEvent(QEvent *) {
-    if (stackedWidget->currentWidget() != refineSearchWidget)
-        showRefineSearchButton();
+    if (stackedWidget->currentWidget() != refineSearchWidget) showRefineSearchButton();
 }
 
 void SidebarWidget::leaveEvent(QEvent *) {
@@ -138,9 +155,8 @@ void SidebarWidget::handleMouseMove() {
 
 void SidebarWidget::showRefineSearchButton() {
     if (!refineSearchWidget->isEnabled()) return;
-    refineSearchButton->move(
-                playlist->viewport()->width() - refineSearchButton->minimumWidth(),
-                height() - refineSearchButton->minimumHeight());
+    refineSearchButton->move(playlist->viewport()->width() - refineSearchButton->minimumWidth(),
+                             height() - refineSearchButton->minimumHeight());
     refineSearchButton->show();
 }
 
@@ -148,18 +164,17 @@ void SidebarWidget::showSuggestions(const QStringList &suggestions) {
     QString message = tr("Did you mean: %1");
 
     QString suggestionLinks;
-    foreach (QString suggestion, suggestions) {
+    for (const QString &suggestion : suggestions) {
         suggestionLinks += "<a href='" + suggestion + "'>" + suggestion + "</a> ";
     }
     message = message.arg(suggestionLinks);
 
-    QString html =
-            "<html>"
-            "<style>"
-            "a { color: palette(text); text-decoration: none; font-weight: bold }"
-            "</style>"
-            "<body>%1</body>"
-            "</html>";
+    QString html = "<html>"
+                   "<style>"
+                   "a { color: palette(text); text-decoration: none; font-weight: bold }"
+                   "</style>"
+                   "<body>%1</body>"
+                   "</html>";
     html = html.arg(message);
     messageLabel->setText(html);
     messageLabel->show();