X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fsidebarheader.cpp;h=150db794ef696ee549f0c532439f5db287f1c9c6;hb=8cea1b650a0122369e8a3d60da1f263767b67614;hp=b6fb87a2607bfb165cf89dbb000e2267aedfa63e;hpb=7ca7741e1eb9bc70617fbb4207738e291218c495;p=minitube
diff --git a/src/sidebarheader.cpp b/src/sidebarheader.cpp
index b6fb87a..150db79 100644
--- a/src/sidebarheader.cpp
+++ b/src/sidebarheader.cpp
@@ -19,12 +19,13 @@ along with Minitube. If not, see .
$END_LICENSE */
#include "sidebarheader.h"
+#include "fontutils.h"
#include "iconutils.h"
+#include "mainwindow.h"
#include "mediaview.h"
#include "videosource.h"
-#include "fontutils.h"
-SidebarHeader::SidebarHeader(QWidget *parent) : QToolBar(parent) { }
+SidebarHeader::SidebarHeader(QWidget *parent) : QToolBar(parent) {}
void SidebarHeader::setup() {
static bool isSetup = false;
@@ -33,23 +34,22 @@ void SidebarHeader::setup() {
setIconSize(QSize(16, 16));
- backAction = new QAction(
- IconUtils::icon("go-previous"),
- tr("&Back"), this);
+ backAction = new QAction(tr("&Back"), this);
+ IconUtils::setIcon(backAction, "go-previous");
backAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Left));
connect(backAction, SIGNAL(triggered()), MediaView::instance(), SLOT(goBack()));
addAction(backAction);
- forwardAction = new QAction(
- IconUtils::icon("go-next"),
- tr("&Back"), this);
+ forwardAction = new QAction(tr("&Forward"), this);
+ IconUtils::setIcon(forwardAction, "go-next");
forwardAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Right));
connect(forwardAction, SIGNAL(triggered()), MediaView::instance(), SLOT(goForward()));
addAction(forwardAction);
- foreach (QAction* action, actions()) {
+ const auto a = actions();
+ for (QAction *action : a) {
window()->addAction(action);
- IconUtils::setupAction(action);
+ MainWindow::instance()->setupAction(action);
}
QWidget *spacerWidget = new QWidget(this);
@@ -64,7 +64,7 @@ QSize SidebarHeader::minimumSizeHint() const {
void SidebarHeader::updateInfo() {
setup();
- QList history = MediaView::instance()->getHistory();
+ const QVector &history = MediaView::instance()->getHistory();
int currentIndex = MediaView::instance()->getHistoryIndex();
bool canGoForward = MediaView::instance()->canGoForward();
@@ -72,11 +72,9 @@ void SidebarHeader::updateInfo() {
forwardAction->setEnabled(canGoForward);
if (canGoForward) {
VideoSource *nextVideoSource = history.at(currentIndex + 1);
- forwardAction->setStatusTip(
- tr("Forward to %1")
- .arg(nextVideoSource->getName())
- + " (" + forwardAction->shortcut().toString(QKeySequence::NativeText) + ")"
- );
+ forwardAction->setStatusTip(tr("Forward to %1").arg(nextVideoSource->getName()) + " (" +
+ forwardAction->shortcut().toString(QKeySequence::NativeText) +
+ ")");
}
bool canGoBack = MediaView::instance()->canGoBack();
@@ -85,16 +83,13 @@ void SidebarHeader::updateInfo() {
backAction->setEnabled(canGoBack);
if (canGoBack) {
VideoSource *previousVideoSource = history.at(currentIndex - 1);
- backAction->setStatusTip(
- tr("Back to %1")
- .arg(previousVideoSource->getName())
- + " (" + backAction->shortcut().toString(QKeySequence::NativeText) + ")"
- );
+ backAction->setStatusTip(tr("Back to %1").arg(previousVideoSource->getName()) + " (" +
+ backAction->shortcut().toString(QKeySequence::NativeText) + ")");
}
VideoSource *currentVideoSource = history.at(currentIndex);
- connect(currentVideoSource, SIGNAL(nameChanged(QString)),
- SLOT(updateTitle(QString)), Qt::UniqueConnection);
+ connect(currentVideoSource, SIGNAL(nameChanged(QString)), SLOT(updateTitle(QString)),
+ Qt::UniqueConnection);
setTitle(currentVideoSource->getName());
}
@@ -107,34 +102,30 @@ void SidebarHeader::setTitle(const QString &title) {
this->title = title;
update();
- QList history = MediaView::instance()->getHistory();
+ QVector history = MediaView::instance()->getHistory();
int currentIndex = MediaView::instance()->getHistoryIndex();
VideoSource *currentVideoSource = history.at(currentIndex);
- foreach (QAction* action, videoSourceActions)
+ for (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.setPen(Qt::white);
- p.setFont(FontUtils::small());
+ p.setPen(palette().windowText().color());
const QRect r = rect();
QString t = title;
QRect textBox = p.boundingRect(r, Qt::AlignCenter, t);
int i = 1;
- 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("...");
+ const int margin = forwardAction->isVisible() ? 50 : 25;
+ while (textBox.width() > r.width() - margin * 2 && t.length() > 3) {
+ t = t.left(t.length() - i).trimmed() + QStringLiteral("\u2026");
textBox = p.boundingRect(r, Qt::AlignCenter, t);
i++;
}
p.drawText(r, Qt::AlignCenter, t);
-
-
}