mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-17 19:37:09 +02:00
Draw tiled background in FlexibleHeader as well as InfoBar
This commit is contained in:
@@ -98,7 +98,7 @@ InfoBar::InfoBar( QWidget* parent )
|
|||||||
setAutoFillBackground( true );
|
setAutoFillBackground( true );
|
||||||
|
|
||||||
setFixedHeight( 80 );
|
setFixedHeight( 80 );
|
||||||
createTile();
|
m_bgTile = TomahawkUtils::createTiledPixmap( 2000, height(), QImage( RESPATH "images/playlist-header-tiled.png" ) );
|
||||||
|
|
||||||
connect( ViewManager::instance(), SIGNAL( filterAvailable( bool ) ), SLOT( setFilterAvailable( bool ) ) );
|
connect( ViewManager::instance(), SIGNAL( filterAvailable( bool ) ), SLOT( setFilterAvailable( bool ) ) );
|
||||||
}
|
}
|
||||||
@@ -282,54 +282,13 @@ InfoBar::onFilterEdited()
|
|||||||
emit filterTextChanged( m_searchWidget->text() );
|
emit filterTextChanged( m_searchWidget->text() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
InfoBar::createTile( int w )
|
|
||||||
{
|
|
||||||
QImage tile = QImage( RESPATH "images/playlist-header-tiled.png" );
|
|
||||||
|
|
||||||
if ( tile.isNull() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ( tile.height() < height() )
|
|
||||||
{
|
|
||||||
// image must be at least as tall as we are
|
|
||||||
QImage taller( tile.width(), height(), QImage::Format_ARGB32_Premultiplied );
|
|
||||||
QPainter p( &taller );
|
|
||||||
int curY = 0;
|
|
||||||
while ( curY < taller.height() )
|
|
||||||
{
|
|
||||||
const int thisHeight = (curY + tile.height() > height()) ? height() - curY : tile.height();
|
|
||||||
p.drawImage( QRect( 0, curY, tile.width(), thisHeight ), tile, QRect( 0, 0, tile.width(), thisHeight ) );
|
|
||||||
curY += tile.height();
|
|
||||||
}
|
|
||||||
tile = taller;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_bgTile = QPixmap( w, height() );
|
|
||||||
m_bgTile.fill( Qt::transparent );
|
|
||||||
|
|
||||||
int curWidth = 0;
|
|
||||||
QPainter p( &m_bgTile );
|
|
||||||
while ( curWidth < w )
|
|
||||||
{
|
|
||||||
const int thisWidth = (curWidth + tile.width() > w) ? w - curWidth : tile.width();
|
|
||||||
|
|
||||||
const QRect source( 0, 0, thisWidth, m_bgTile.height() );
|
|
||||||
const QRect dest( curWidth, 0, thisWidth, m_bgTile.height() );
|
|
||||||
p.drawImage( dest, tile, source );
|
|
||||||
curWidth += thisWidth;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
InfoBar::paintEvent( QPaintEvent* e )
|
InfoBar::paintEvent( QPaintEvent* e )
|
||||||
{
|
{
|
||||||
Q_UNUSED( e );
|
Q_UNUSED( e );
|
||||||
|
|
||||||
if ( m_bgTile.isNull() || width() > m_bgTile.width() )
|
if ( m_bgTile.isNull() || width() > m_bgTile.width() )
|
||||||
createTile( width() );
|
m_bgTile = TomahawkUtils::createTiledPixmap( width(), height(), QImage( RESPATH "images/playlist-header-tiled.png" ) );
|
||||||
|
|
||||||
if ( m_bgTile.isNull() )
|
if ( m_bgTile.isNull() )
|
||||||
return;
|
return;
|
||||||
|
@@ -76,8 +76,6 @@ private slots:
|
|||||||
void artistClicked();
|
void artistClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createTile( int width = 2000 );
|
|
||||||
|
|
||||||
Ui::InfoBar* ui;
|
Ui::InfoBar* ui;
|
||||||
|
|
||||||
QPixmap m_bgTile;
|
QPixmap m_bgTile;
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
QPixmap* FlexibleHeader::s_tiledHeader = 0;
|
||||||
|
|
||||||
FlexibleHeader::FlexibleHeader( FlexibleView* parent )
|
FlexibleHeader::FlexibleHeader( FlexibleView* parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
@@ -78,6 +79,9 @@ FlexibleHeader::FlexibleHeader( FlexibleView* parent )
|
|||||||
setPalette( pal );
|
setPalette( pal );
|
||||||
setAutoFillBackground( true );
|
setAutoFillBackground( true );
|
||||||
|
|
||||||
|
if ( !s_tiledHeader )
|
||||||
|
s_tiledHeader = new QPixmap( TomahawkUtils::createTiledPixmap( 2000, height(), QImage( RESPATH "images/playlist-header-tiled.png" ) ) );
|
||||||
|
|
||||||
connect( &m_filterTimer, SIGNAL( timeout() ), SLOT( applyFilter() ) );
|
connect( &m_filterTimer, SIGNAL( timeout() ), SLOT( applyFilter() ) );
|
||||||
connect( ui->filter, SIGNAL( textChanged( QString ) ), SLOT( onFilterEdited() ) );
|
connect( ui->filter, SIGNAL( textChanged( QString ) ), SLOT( onFilterEdited() ) );
|
||||||
|
|
||||||
@@ -89,6 +93,8 @@ FlexibleHeader::FlexibleHeader( FlexibleView* parent )
|
|||||||
|
|
||||||
FlexibleHeader::~FlexibleHeader()
|
FlexibleHeader::~FlexibleHeader()
|
||||||
{
|
{
|
||||||
|
delete s_tiledHeader;
|
||||||
|
s_tiledHeader = 0;
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,3 +160,22 @@ FlexibleHeader::changeEvent( QEvent* e )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FlexibleHeader::paintEvent( QPaintEvent* )
|
||||||
|
{
|
||||||
|
if ( !s_tiledHeader || s_tiledHeader->isNull() || width() > s_tiledHeader->width() )
|
||||||
|
{
|
||||||
|
delete s_tiledHeader;
|
||||||
|
s_tiledHeader = new QPixmap( TomahawkUtils::createTiledPixmap( width(), height(), QImage( RESPATH "images/playlist-header-tiled.png" ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !s_tiledHeader || s_tiledHeader->isNull() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QPainter p( this );
|
||||||
|
|
||||||
|
// Truncate bg pixmap and paint into bg
|
||||||
|
p.drawPixmap( rect(), *s_tiledHeader, rect() );
|
||||||
|
}
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
#include "Artist.h"
|
#include "Artist.h"
|
||||||
|
|
||||||
|
class QPaintEvent;
|
||||||
class FlexibleView;
|
class FlexibleView;
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
@@ -52,6 +53,7 @@ signals:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void changeEvent( QEvent* e );
|
void changeEvent( QEvent* e );
|
||||||
|
void paintEvent( QPaintEvent* e );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onFilterEdited();
|
void onFilterEdited();
|
||||||
@@ -63,6 +65,8 @@ private:
|
|||||||
|
|
||||||
QString m_filter;
|
QString m_filter;
|
||||||
QTimer m_filterTimer;
|
QTimer m_filterTimer;
|
||||||
|
|
||||||
|
static QPixmap* s_tiledHeader;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -543,4 +543,49 @@ styleScrollBar( QScrollBar* scrollBar )
|
|||||||
"border: 0px; width: 0px; height: 0px; background: none; background-color: transparent; }" );
|
"border: 0px; width: 0px; height: 0px; background: none; background-color: transparent; }" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QPixmap
|
||||||
|
createTiledPixmap( int width, int height, const QImage& inputTile )
|
||||||
|
{
|
||||||
|
if ( inputTile.isNull() )
|
||||||
|
return QPixmap();
|
||||||
|
|
||||||
|
|
||||||
|
QImage localTile = inputTile;
|
||||||
|
|
||||||
|
if ( localTile.height() < height )
|
||||||
|
{
|
||||||
|
// image must be at least as tall as we are
|
||||||
|
QImage taller( localTile.width(), height, QImage::Format_ARGB32_Premultiplied );
|
||||||
|
QPainter p( &taller );
|
||||||
|
int curY = 0;
|
||||||
|
while ( curY < taller.height() )
|
||||||
|
{
|
||||||
|
const int thisHeight = (curY + localTile.height() > height) ? height - curY : localTile.height();
|
||||||
|
p.drawImage( QRect( 0, curY, localTile.width(), thisHeight ), localTile, QRect( 0, 0, localTile.width(), thisHeight ) );
|
||||||
|
curY += localTile.height();
|
||||||
|
}
|
||||||
|
localTile = taller;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QPixmap tiledImage = QPixmap( width, height );
|
||||||
|
tiledImage.fill( Qt::transparent );
|
||||||
|
|
||||||
|
int curWidth = 0;
|
||||||
|
QPainter p( &tiledImage );
|
||||||
|
while ( curWidth < width )
|
||||||
|
{
|
||||||
|
const int thisWidth = (curWidth + localTile.width() > width) ? width - curWidth : localTile.width();
|
||||||
|
|
||||||
|
const QRect source( 0, 0, thisWidth, tiledImage.height() );
|
||||||
|
const QRect dest( curWidth, 0, thisWidth, tiledImage.height() );
|
||||||
|
p.drawImage( dest, localTile, source );
|
||||||
|
curWidth += thisWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tiledImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // ns
|
} // ns
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
#include <QTextOption>
|
#include <QTextOption>
|
||||||
|
#include <QImage>
|
||||||
|
|
||||||
#include "TomahawkUtils.h"
|
#include "TomahawkUtils.h"
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
@@ -68,6 +69,8 @@ namespace TomahawkUtils
|
|||||||
DLLEXPORT void drawRoundedButton( QPainter* painter, const QRect& btnRect, const QColor& color, const QColor &gradient1bottom = QColor(), const QColor& gradient2top = QColor(), const QColor& gradient2bottom = QColor() );
|
DLLEXPORT void drawRoundedButton( QPainter* painter, const QRect& btnRect, const QColor& color, const QColor &gradient1bottom = QColor(), const QColor& gradient2top = QColor(), const QColor& gradient2bottom = QColor() );
|
||||||
|
|
||||||
DLLEXPORT void styleScrollBar( QScrollBar* scrollBar );
|
DLLEXPORT void styleScrollBar( QScrollBar* scrollBar );
|
||||||
|
|
||||||
|
DLLEXPORT QPixmap createTiledPixmap( int width, int height, const QImage& src );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TOMAHAWKUTILSGUI_H
|
#endif // TOMAHAWKUTILSGUI_H
|
||||||
|
Reference in New Issue
Block a user