mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-19 23:41:51 +02:00
* Fixed long artist / track names resizing Tomahawk's main window. Now using ElidedLabel (Qt::ElideMiddle), a class dealing with too long labels.
This commit is contained in:
parent
c0727d25cc
commit
8e48e61843
@ -23,6 +23,6 @@ ELSE()
|
||||
ENDIF( UNIX AND NOT APPLE )
|
||||
|
||||
ADD_SUBDIRECTORY( libportfwd )
|
||||
ADD_SUBDIRECTORY( qxtweb-standalone )
|
||||
ADD_SUBDIRECTORY( qxt )
|
||||
ADD_SUBDIRECTORY( src )
|
||||
|
||||
|
1
qxt/CMakeLists.txt
Normal file
1
qxt/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
ADD_SUBDIRECTORY( qxtweb-standalone )
|
@ -98,6 +98,7 @@ SET( tomahawkSources ${tomahawkSources}
|
||||
SET( tomahawkSourcesGui ${tomahawkSourcesGui}
|
||||
xspfloader.cpp
|
||||
|
||||
utils/elidedlabel.cpp
|
||||
utils/imagebutton.cpp
|
||||
utils/progresstreeview.cpp
|
||||
utils/proxystyle.cpp
|
||||
@ -215,6 +216,7 @@ SET( tomahawkHeaders ${tomahawkHeaders}
|
||||
SET( tomahawkHeadersGui ${tomahawkHeadersGui}
|
||||
xspfloader.h
|
||||
|
||||
utils/elidedlabel.h
|
||||
utils/animatedcounterlabel.h
|
||||
utils/imagebutton.h
|
||||
utils/progresstreeview.h
|
||||
@ -277,7 +279,7 @@ INCLUDE_DIRECTORIES(
|
||||
../rtaudio
|
||||
../alsa-playback
|
||||
../libportfwd/include
|
||||
../qxtweb-standalone/qxtweb/
|
||||
../qxt/qxtweb-standalone/qxtweb
|
||||
|
||||
/usr/include/taglib
|
||||
/usr/local/include/taglib
|
||||
|
@ -28,7 +28,7 @@ SET( OS_SPECIFIC_LINK_LIBRARIES
|
||||
"crypt32.dll"
|
||||
"ws2_32.dll"
|
||||
"dnsapi.dll"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../qxtweb-standalone/libqxtweb-standalone.dll"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../qxt/qxtweb-standalone/libqxtweb-standalone.dll"
|
||||
)
|
||||
|
||||
SET( tomahawkSourcesGui ${tomahawkSourcesGui} audio/rtaudiooutput.cpp )
|
||||
|
@ -28,6 +28,8 @@ AudioControls::AudioControls( QWidget* parent )
|
||||
font.setPixelSize( 12 );
|
||||
|
||||
ui->artistTrackLabel->setFont( font );
|
||||
ui->artistTrackLabel->setElideMode( Qt::ElideMiddle );
|
||||
|
||||
ui->albumLabel->setFont( font );
|
||||
ui->timeLabel->setFont( font );
|
||||
ui->timeLeftLabel->setFont( font );
|
||||
@ -119,7 +121,7 @@ AudioControls::AudioControls( QWidget* parent )
|
||||
connect( ui->repeatButton, SIGNAL( clicked() ), SLOT( onRepeatClicked() ) );
|
||||
connect( ui->shuffleButton, SIGNAL( clicked() ), SLOT( onShuffleClicked() ) );
|
||||
|
||||
connect( ui->artistTrackLabel, SIGNAL( linkActivated( QString ) ), SLOT( onTrackClicked( QString ) ) );
|
||||
connect( ui->artistTrackLabel, SIGNAL( clicked() ), SLOT( onTrackClicked() ) );
|
||||
|
||||
// <From AudioEngine>
|
||||
connect( (QObject*)TomahawkApp::instance()->audioEngine(), SIGNAL( loading( const Tomahawk::result_ptr& ) ), SLOT( onPlaybackLoading( const Tomahawk::result_ptr& ) ) );
|
||||
@ -223,7 +225,7 @@ AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result )
|
||||
|
||||
m_currentTrack = result;
|
||||
|
||||
ui->artistTrackLabel->setText( "<a style='color:black; text-decoration:none;' href='#'>" + QString( "%1 - %2" ).arg( result->artist() ).arg( result->track() ) + "</a>" );
|
||||
ui->artistTrackLabel->setText( QString( "%1 - %2" ).arg( result->artist() ).arg( result->track() ) );
|
||||
ui->albumLabel->setText( result->album() );
|
||||
ui->ownerLabel->setText( result->collection()->source()->friendlyName() );
|
||||
ui->coverImage->setPixmap( m_defaultCover );
|
||||
@ -407,7 +409,7 @@ AudioControls::onShuffleClicked()
|
||||
|
||||
|
||||
void
|
||||
AudioControls::onTrackClicked( const QString& /* link */ )
|
||||
AudioControls::onTrackClicked()
|
||||
{
|
||||
APP->playlistManager()->showCurrentTrack();
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ private slots:
|
||||
|
||||
void onRepeatClicked();
|
||||
void onShuffleClicked();
|
||||
void onTrackClicked( const QString& link );
|
||||
void onTrackClicked();
|
||||
|
||||
void onCoverArtDownloaded();
|
||||
|
||||
|
@ -206,7 +206,7 @@
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="trackLabelLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="artistTrackLabel">
|
||||
<widget class="ElidedLabel" name="artistTrackLabel">
|
||||
<property name="cursor">
|
||||
<cursorShape>PointingHandCursor</cursorShape>
|
||||
</property>
|
||||
@ -455,6 +455,11 @@
|
||||
<extends>QPushButton</extends>
|
||||
<header>imagebutton.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>ElidedLabel</class>
|
||||
<extends>QLabel</extends>
|
||||
<header location="global">elidedlabel.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
@ -85,7 +85,7 @@ TrackView::restoreColumnsState()
|
||||
|
||||
if ( list.count() != 7 ) // FIXME: const
|
||||
{
|
||||
m_columnWeights << 0.19 << 0.25 << 0.18 << 0.07 << 0.07 << 0.10 << 0.14;
|
||||
m_columnWeights << 0.19 << 0.25 << 0.18 << 0.07 << 0.07 << 0.11 << 0.13;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
171
src/utils/elidedlabel.cpp
Normal file
171
src/utils/elidedlabel.cpp
Normal file
@ -0,0 +1,171 @@
|
||||
#include "elidedlabel.h"
|
||||
|
||||
#include <QTime>
|
||||
#include <QEvent>
|
||||
#include <QPainter>
|
||||
#include <QFontMetrics>
|
||||
#include <QApplication>
|
||||
|
||||
|
||||
ElidedLabel::ElidedLabel( QWidget* parent, Qt::WindowFlags flags )
|
||||
: QFrame( parent, flags )
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
ElidedLabel::ElidedLabel( const QString& text, QWidget* parent, Qt::WindowFlags flags )
|
||||
: QFrame( parent, flags )
|
||||
{
|
||||
init(text);
|
||||
}
|
||||
|
||||
|
||||
ElidedLabel::~ElidedLabel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
ElidedLabel::text() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ElidedLabel::setText( const QString& text )
|
||||
{
|
||||
if ( m_text != text )
|
||||
{
|
||||
m_text = text;
|
||||
updateLabel();
|
||||
emit textChanged( text );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Qt::Alignment
|
||||
ElidedLabel::alignment() const
|
||||
{
|
||||
return align;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ElidedLabel::setAlignment( Qt::Alignment alignment )
|
||||
{
|
||||
if ( this->align != alignment )
|
||||
{
|
||||
this->align = alignment;
|
||||
update(); // no geometry change, repaint is sufficient
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Qt::TextElideMode
|
||||
ElidedLabel::elideMode() const
|
||||
{
|
||||
return mode;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ElidedLabel::setElideMode( Qt::TextElideMode mode )
|
||||
{
|
||||
if ( this->mode != mode )
|
||||
{
|
||||
this->mode = mode;
|
||||
updateLabel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ElidedLabel::init( const QString& txt )
|
||||
{
|
||||
m_text = txt;
|
||||
align = Qt::AlignLeft;
|
||||
mode = Qt::ElideMiddle;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ElidedLabel::updateLabel()
|
||||
{
|
||||
updateGeometry();
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
QSize
|
||||
ElidedLabel::sizeHint() const
|
||||
{
|
||||
const QFontMetrics& fm = fontMetrics();
|
||||
QSize size( fm.width( m_text ), fm.height() );
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
QSize
|
||||
ElidedLabel::minimumSizeHint() const
|
||||
{
|
||||
switch ( mode )
|
||||
{
|
||||
case Qt::ElideNone:
|
||||
return sizeHint();
|
||||
|
||||
default:
|
||||
{
|
||||
const QFontMetrics& fm = fontMetrics();
|
||||
QSize size( fm.width( "..." ), fm.height() );
|
||||
return size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ElidedLabel::paintEvent( QPaintEvent* event )
|
||||
{
|
||||
QFrame::paintEvent( event );
|
||||
QPainter p( this );
|
||||
QRect r = contentsRect();
|
||||
const QString elidedText = fontMetrics().elidedText( m_text, mode, r.width() );
|
||||
p.drawText( r, align, elidedText );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ElidedLabel::changeEvent( QEvent* event )
|
||||
{
|
||||
QFrame::changeEvent( event );
|
||||
switch ( event->type() )
|
||||
{
|
||||
case QEvent::FontChange:
|
||||
case QEvent::ApplicationFontChange:
|
||||
updateLabel();
|
||||
break;
|
||||
|
||||
default:
|
||||
// nothing to do
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ElidedLabel::mousePressEvent( QMouseEvent* event )
|
||||
{
|
||||
QFrame::mousePressEvent( event );
|
||||
time.start();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ElidedLabel::mouseReleaseEvent( QMouseEvent* event )
|
||||
{
|
||||
QFrame::mouseReleaseEvent( event );
|
||||
if ( time.elapsed() < qApp->doubleClickInterval() )
|
||||
emit clicked();
|
||||
}
|
53
src/utils/elidedlabel.h
Normal file
53
src/utils/elidedlabel.h
Normal file
@ -0,0 +1,53 @@
|
||||
#ifndef ELIDEDLABEL_H
|
||||
#define ELIDEDLABEL_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QTime>
|
||||
|
||||
class ElidedLabel : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY( QString text READ text WRITE setText NOTIFY textChanged )
|
||||
Q_PROPERTY( Qt::Alignment alignment READ alignment WRITE setAlignment )
|
||||
Q_PROPERTY( Qt::TextElideMode elideMode READ elideMode WRITE setElideMode )
|
||||
|
||||
public:
|
||||
explicit ElidedLabel( QWidget* parent = 0, Qt::WindowFlags flags = 0 );
|
||||
explicit ElidedLabel( const QString& text, QWidget* parent = 0, Qt::WindowFlags flags = 0 );
|
||||
virtual ~ElidedLabel();
|
||||
|
||||
QString text() const;
|
||||
|
||||
Qt::Alignment alignment() const;
|
||||
void setAlignment( Qt::Alignment alignment );
|
||||
|
||||
Qt::TextElideMode elideMode() const;
|
||||
void setElideMode( Qt::TextElideMode mode );
|
||||
|
||||
virtual QSize sizeHint() const;
|
||||
virtual QSize minimumSizeHint() const;
|
||||
|
||||
void init( const QString& txt = QString() );
|
||||
void updateLabel();
|
||||
|
||||
public Q_SLOTS:
|
||||
void setText( const QString& text );
|
||||
|
||||
Q_SIGNALS:
|
||||
void clicked();
|
||||
void textChanged( const QString& text );
|
||||
|
||||
protected:
|
||||
virtual void changeEvent( QEvent* event );
|
||||
virtual void mousePressEvent( QMouseEvent* event );
|
||||
virtual void mouseReleaseEvent( QMouseEvent* event );
|
||||
virtual void paintEvent( QPaintEvent* event );
|
||||
|
||||
private:
|
||||
QTime time;
|
||||
QString m_text;
|
||||
Qt::Alignment align;
|
||||
Qt::TextElideMode mode;
|
||||
};
|
||||
|
||||
#endif // ELIDEDLABEL_H
|
Loading…
x
Reference in New Issue
Block a user