]> git.sur5r.net Git - minitube/blobdiff - src/sidebarheader.cpp
Upload 2.5.2-2 to unstable
[minitube] / src / sidebarheader.cpp
index 91670a94503c89539f6ae1481a11380715f6f059..b6fb87a2607bfb165cf89dbb000e2267aedfa63e 100644 (file)
@@ -1,5 +1,25 @@
+/* $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 "sidebarheader.h"
-#include "utils.h"
+#include "iconutils.h"
 #include "mediaview.h"
 #include "videosource.h"
 #include "fontutils.h"
@@ -11,15 +31,17 @@ void SidebarHeader::setup() {
     if (isSetup) return;
     isSetup = true;
 
+    setIconSize(QSize(16, 16));
+
     backAction = new QAction(
-                Utils::icon("go-previous"),
+                IconUtils::icon("go-previous"),
                 tr("&Back"), this);
     backAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Left));
     connect(backAction, SIGNAL(triggered()), MediaView::instance(), SLOT(goBack()));
     addAction(backAction);
 
     forwardAction = new QAction(
-                Utils::icon("go-next"),
+                IconUtils::icon("go-next"),
                 tr("&Back"), this);
     forwardAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Right));
     connect(forwardAction, SIGNAL(triggered()), MediaView::instance(), SLOT(goForward()));
@@ -27,19 +49,16 @@ void SidebarHeader::setup() {
 
     foreach (QAction* action, actions()) {
         window()->addAction(action);
-        action->setAutoRepeat(false);
+        IconUtils::setupAction(action);
     }
 
-    /*
     QWidget *spacerWidget = new QWidget(this);
     spacerWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
-    spacerWidget->setVisible(true);
     addWidget(spacerWidget);
-    */
 }
 
-QSize SidebarHeader::minimumSizeHint (void) const {
-    return(QSize(1, QFontMetrics(font()).height() * 1.9));
+QSize SidebarHeader::minimumSizeHint() const {
+    return QSize(160, QFontMetrics(font()).height() * 1.9);
 }
 
 void SidebarHeader::updateInfo() {
@@ -79,34 +98,43 @@ void SidebarHeader::updateInfo() {
     setTitle(currentVideoSource->getName());
 }
 
-void SidebarHeader::updateTitle(QString title) {
+void SidebarHeader::updateTitle(const QString &title) {
     sender()->disconnect(this);
     setTitle(title);
 }
 
-void SidebarHeader::setTitle(QString title) {
+void SidebarHeader::setTitle(const QString &title) {
     this->title = title;
     update();
+
+    QList<VideoSource*> history = MediaView::instance()->getHistory();
+    int currentIndex = MediaView::instance()->getHistoryIndex();
+    VideoSource *currentVideoSource = history.at(currentIndex);
+    foreach (QAction* action, videoSourceActions)
+        removeAction(action);
+    videoSourceActions = currentVideoSource->getActions();
+    addActions(videoSourceActions);
 }
 
 void SidebarHeader::paintEvent(QPaintEvent *event) {
     QToolBar::paintEvent(event);
     if (title.isEmpty()) return;
     QPainter p(this);
-    p.setFont(FontUtils::smallBold());
     p.setPen(Qt::white);
+    p.setFont(FontUtils::small());
 
     const QRect r = rect();
 
     QString t = title;
     QRect textBox = p.boundingRect(r, Qt::AlignCenter, t);
     int i = 1;
-    static const int margin = 100;
-    while (textBox.width() > r.width() - margin) {
-        t = t.left(t.length() - i) + "...";
+    const int margin = forwardAction->isVisible() ? 45 : 20;
+    while (textBox.width() > r.width() - margin*2 && t.length() > 3) {
+        t = t.left(t.length() - i).trimmed() + QLatin1String("...");
         textBox = p.boundingRect(r, Qt::AlignCenter, t);
         i++;
     }
-
     p.drawText(r, Qt::AlignCenter, t);
+
+
 }