Scale context view backdrops.
This commit is contained in:
committed by
craig.p.drummond
parent
fe4d411007
commit
600ef02054
@@ -7,6 +7,7 @@
|
||||
4. Optionally save scaled covers (used in artist and albums views) to disk.
|
||||
5. Add option to always collapse context into single pane.
|
||||
6. Option to have small sidebar at top or bottom.
|
||||
7. Scale context view backdrops.
|
||||
|
||||
1.2.2
|
||||
-----
|
||||
|
||||
@@ -45,7 +45,9 @@
|
||||
#include <QFile>
|
||||
#include <QWheelEvent>
|
||||
#include <QApplication>
|
||||
#ifndef SCALE_CONTEXT_BGND
|
||||
#include <QDesktopWidget>
|
||||
#endif
|
||||
#include <QComboBox>
|
||||
#include <QStackedWidget>
|
||||
#include <QAction>
|
||||
@@ -185,6 +187,7 @@ ContextWidget::ContextWidget(QWidget *parent)
|
||||
, darkBackground(false)
|
||||
// , useHtBackdrops(0!=constHtbApiKey.latin1())
|
||||
, useFanArt(0!=constFanArtApiKey.latin1())
|
||||
, albumCoverBackdrop(false)
|
||||
, fadeValue(0)
|
||||
, isWide(false)
|
||||
, stack(0)
|
||||
@@ -212,6 +215,8 @@ ContextWidget::ContextWidget(QWidget *parent)
|
||||
setZoom();
|
||||
setWide(true);
|
||||
splitterColor=palette().text().color();
|
||||
|
||||
#ifndef SCALE_CONTEXT_BGND
|
||||
QDesktopWidget *dw=QApplication::desktop();
|
||||
if (dw) {
|
||||
QSize geo=dw->availableGeometry(this).size()-QSize(32, 64);
|
||||
@@ -226,6 +231,7 @@ ContextWidget::ContextWidget(QWidget *parent)
|
||||
minBackdropSize=QSize(1024, 768);
|
||||
maxBackdropSize=QSize(minBackdropSize.width()*2, minBackdropSize.height()*2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ContextWidget::setZoom()
|
||||
@@ -340,6 +346,9 @@ void ContextWidget::resizeEvent(QResizeEvent *e)
|
||||
if (isVisible()) {
|
||||
setWide(width()>minWidth && !alwaysCollapsed);
|
||||
}
|
||||
#ifdef SCALE_CONTEXT_BGND
|
||||
resizeBackdrop();
|
||||
#endif
|
||||
QWidget::resizeEvent(e);
|
||||
}
|
||||
|
||||
@@ -491,19 +500,8 @@ void ContextWidget::updateImage(const QImage &img, bool created)
|
||||
if (!img.isNull()) {
|
||||
currentBackdrop=QPixmap::fromImage(setOpacity(img));
|
||||
}
|
||||
|
||||
if (!currentBackdrop.isNull() && !created) {
|
||||
if (currentBackdrop.width()<minBackdropSize.width() && currentBackdrop.height()<minBackdropSize.height()) {
|
||||
QSize size(minBackdropSize);
|
||||
if (currentBackdrop.width()<minBackdropSize.width()/4 && currentBackdrop.height()<minBackdropSize.height()/4) {
|
||||
size=QSize(minBackdropSize.width()/2, minBackdropSize.height()/2);
|
||||
}
|
||||
currentBackdrop=currentBackdrop.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
} else if (maxBackdropSize.width()>1024 && maxBackdropSize.height()>768 &&
|
||||
(currentBackdrop.width()>maxBackdropSize.width() || currentBackdrop.height()>maxBackdropSize.height())) {
|
||||
currentBackdrop=currentBackdrop.scaled(maxBackdropSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
}
|
||||
albumCoverBackdrop=created;
|
||||
resizeBackdrop();
|
||||
|
||||
fadeValue=0.0;
|
||||
animator.setDuration(250);
|
||||
@@ -1013,6 +1011,29 @@ void ContextWidget::createBackdrop()
|
||||
}
|
||||
}
|
||||
|
||||
void ContextWidget::resizeBackdrop()
|
||||
{
|
||||
#ifdef SCALE_CONTEXT_BGND
|
||||
if (!currentBackdrop.isNull() && !albumCoverBackdrop && currentBackdrop.width()!=width()) {
|
||||
QSize sz(width(), width()*currentBackdrop.height()/currentBackdrop.width());
|
||||
currentBackdrop=currentBackdrop.scaled(sz, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
#else
|
||||
if (!currentBackdrop.isNull() && !albumCoverBackdrop) {
|
||||
if (currentBackdrop.width()<minBackdropSize.width() && currentBackdrop.height()<minBackdropSize.height()) {
|
||||
QSize size(minBackdropSize);
|
||||
if (currentBackdrop.width()<minBackdropSize.width()/4 && currentBackdrop.height()<minBackdropSize.height()/4) {
|
||||
size=QSize(minBackdropSize.width()/2, minBackdropSize.height()/2);
|
||||
}
|
||||
currentBackdrop=currentBackdrop.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
} else if (maxBackdropSize.width()>1024 && maxBackdropSize.height()>768 &&
|
||||
(currentBackdrop.width()>maxBackdropSize.width() || currentBackdrop.height()>maxBackdropSize.height())) {
|
||||
currentBackdrop=currentBackdrop.scaled(maxBackdropSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ContextWidget::backdropCreated(const QString &artist, const QImage &img)
|
||||
{
|
||||
DBUG << artist << img.isNull() << currentArtist;
|
||||
|
||||
@@ -31,6 +31,10 @@
|
||||
#include <QSplitter>
|
||||
#include "song.h"
|
||||
|
||||
#ifndef SCALE_CONTEXT_BGND
|
||||
#define SCALE_CONTEXT_BGND
|
||||
#endif
|
||||
|
||||
class ArtistView;
|
||||
class AlbumView;
|
||||
class SongView;
|
||||
@@ -104,6 +108,7 @@ private:
|
||||
void getMusicbrainzId(const QString &artist);
|
||||
void getDiscoGsImage();
|
||||
void createBackdrop();
|
||||
void resizeBackdrop();
|
||||
NetworkJob * getReply(QObject *obj);
|
||||
|
||||
private:
|
||||
@@ -113,6 +118,7 @@ private:
|
||||
bool darkBackground;
|
||||
// bool useHtBackdrops;
|
||||
bool useFanArt;
|
||||
bool albumCoverBackdrop;
|
||||
Song currentSong;
|
||||
QPixmap oldBackdrop;
|
||||
QPixmap currentBackdrop;
|
||||
@@ -132,8 +138,10 @@ private:
|
||||
BackdropCreator *creator;
|
||||
// QString backdropText;
|
||||
QSet<QString> backdropAlbums;
|
||||
#ifndef SCALE_CONTEXT_BGND
|
||||
QSize minBackdropSize;
|
||||
QSize maxBackdropSize;
|
||||
#endif
|
||||
QList<QString> artistsCreatedBackdropsFor;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user