mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 17:14:00 +02:00
Tweak slider and OS X margin fixes
This commit is contained in:
@@ -153,5 +153,6 @@
|
|||||||
<file>data/images/add-contact.png</file>
|
<file>data/images/add-contact.png</file>
|
||||||
<file>data/images/account-none.png</file>
|
<file>data/images/account-none.png</file>
|
||||||
<file>data/images/green-dot.png</file>
|
<file>data/images/green-dot.png</file>
|
||||||
|
<file>data/images/sliderbutton_knob.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
@@ -128,6 +128,11 @@ AccountWidget::AccountWidget( QWidget* parent )
|
|||||||
m_inviteButton->setText( tr( "Invite" ) );
|
m_inviteButton->setText( tr( "Invite" ) );
|
||||||
vLayout->addWidget( m_inviteButton, 1, 1 );
|
vLayout->addWidget( m_inviteButton, 1, 1 );
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
layout()->setContentsMargins( 0, 0, 0, 0 );
|
||||||
|
#endif
|
||||||
|
|
||||||
setInviteWidgetsEnabled( false );
|
setInviteWidgetsEnabled( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -47,6 +47,11 @@ AccountsPopupWidget::AccountsPopupWidget( QWidget* parent )
|
|||||||
|
|
||||||
setContentsMargins( contentsMargins().left() + 2, contentsMargins().top() + 2 ,
|
setContentsMargins( contentsMargins().left() + 2, contentsMargins().top() + 2 ,
|
||||||
contentsMargins().right(), contentsMargins().bottom() );
|
contentsMargins().right(), contentsMargins().bottom() );
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
setContentsMargins( 0, 0, 0, 0 );
|
||||||
|
layout()->setContentsMargins( 0, 0, 0, 0 );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -72,6 +72,11 @@ AccountsToolButton::AccountsToolButton( QWidget* parent )
|
|||||||
separatorLine->setStyleSheet( "QWidget { border-top: 1px solid black; }" );
|
separatorLine->setStyleSheet( "QWidget { border-top: 1px solid black; }" );
|
||||||
wMainLayout->addWidget( separatorLine );
|
wMainLayout->addWidget( separatorLine );
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
w->setContentsMargins( 4, 4, 2, 2 );
|
||||||
|
wMainLayout->setContentsMargins( 4, 4, 2, 2 );
|
||||||
|
#endif
|
||||||
|
|
||||||
m_popup->setWidget( w );
|
m_popup->setWidget( w );
|
||||||
connect( m_popup, SIGNAL( hidden() ), SLOT( popupHidden() ) );
|
connect( m_popup, SIGNAL( hidden() ), SLOT( popupHidden() ) );
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
*
|
*
|
||||||
* Copyright 2012 Teo Mrnjavac <teo@kde.org>
|
* Copyright 2012 Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2012 Leo Franchi <lfranchi@kde.org>
|
||||||
*
|
*
|
||||||
* Tomahawk is free software: you can redistribute it and/or modify
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -18,9 +19,12 @@
|
|||||||
|
|
||||||
#include "SlideSwitchButton.h"
|
#include "SlideSwitchButton.h"
|
||||||
|
|
||||||
|
#include "utils/TomahawkUtils.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QStyleOptionButton>
|
#include <QStyleOptionButton>
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
SlideSwitchButton::SlideSwitchButton( QWidget* parent )
|
SlideSwitchButton::SlideSwitchButton( QWidget* parent )
|
||||||
: QPushButton( parent )
|
: QPushButton( parent )
|
||||||
@@ -44,11 +48,20 @@ void
|
|||||||
SlideSwitchButton::init()
|
SlideSwitchButton::init()
|
||||||
{
|
{
|
||||||
setCheckable( true );
|
setCheckable( true );
|
||||||
|
#ifndef Q_OS_MAC
|
||||||
|
setMouseTracking( true );
|
||||||
|
#endif
|
||||||
|
|
||||||
m_backCheckedColor = QColor( 167, 183, 211 );
|
m_knob.load( RESPATH "images/sliderbutton_knob.png" );
|
||||||
m_backUncheckedColor = QColor( "#d9d9d9" );
|
|
||||||
|
m_backCheckedColorTop = QColor( 8, 54, 134 );
|
||||||
|
m_backCheckedColorBottom = QColor( 118, 172, 240 );
|
||||||
|
m_backUncheckedColorTop = QColor( 128, 128, 128 );
|
||||||
|
m_backUncheckedColorBottom = QColor( 179, 179, 179 );
|
||||||
|
|
||||||
|
m_baseColorTop = m_backUncheckedColorTop;
|
||||||
|
m_baseColorBottom = m_backUncheckedColorBottom;
|
||||||
|
|
||||||
m_baseColor = m_backUncheckedColor;
|
|
||||||
m_textColor = QColor( "#606060" );
|
m_textColor = QColor( "#606060" );
|
||||||
setFocusPolicy( Qt::NoFocus );
|
setFocusPolicy( Qt::NoFocus );
|
||||||
|
|
||||||
@@ -64,15 +77,16 @@ SlideSwitchButton::init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
QSize
|
QSize
|
||||||
SlideSwitchButton::sizeHint()
|
SlideSwitchButton::sizeHint() const
|
||||||
{
|
{
|
||||||
QSize size = QPushButton::sizeHint();
|
// QSize size = QPushButton::sizeHint();
|
||||||
QFontMetrics fm( m_textFont );
|
// QFontMetrics fm( m_textFont );
|
||||||
int maxTextLength = qMax( fm.boundingRect( m_checkedText ).width(),
|
// int maxTextLength = qMax( fm.boundingRect( m_checkedText ).width(),
|
||||||
fm.boundingRect( m_uncheckedText ).width() );
|
// fm.boundingRect( m_uncheckedText ).width() );
|
||||||
size.rwidth() = contentsMargins().left() + contentsMargins().right()
|
// size.rwidth() = contentsMargins().left() + contentsMargins().right()
|
||||||
+ 2 /*a bit of margin*/ + maxTextLength + ( height() - 4 ) * 1.25;
|
// + 2 /*a bit of margin*/ + maxTextLength + ( height() - 4 ) * 1.25;
|
||||||
return size;
|
// return size;
|
||||||
|
return QSize( 70, 20 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -80,83 +94,63 @@ void
|
|||||||
SlideSwitchButton::paintEvent( QPaintEvent* event )
|
SlideSwitchButton::paintEvent( QPaintEvent* event )
|
||||||
{
|
{
|
||||||
QPainter painter( this );
|
QPainter painter( this );
|
||||||
|
painter.setRenderHint( QPainter::Antialiasing );
|
||||||
painter.initFrom( this );
|
|
||||||
painter.setPen( m_baseColor );
|
|
||||||
|
|
||||||
QStyleOptionButton option;
|
|
||||||
option.initFrom( this );
|
|
||||||
|
|
||||||
QPalette palette;
|
QPalette palette;
|
||||||
|
|
||||||
|
QStyleOptionButton option;
|
||||||
|
initStyleOption( &option );
|
||||||
|
|
||||||
|
QPen border;
|
||||||
|
border.setWidth( 1 );
|
||||||
|
#ifndef Q_OS_MAC
|
||||||
if ( option.state & QStyle::State_MouseOver )
|
if ( option.state & QStyle::State_MouseOver )
|
||||||
painter.setPen( palette.color( QPalette::Highlight ) );
|
border.setColor( palette.color( QPalette::Highlight ) );
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
border.setColor( QColor( "#606060" ) );
|
||||||
|
painter.setPen( border );
|
||||||
//TODO: should the whole thing be highlighted or just the knob?
|
//TODO: should the whole thing be highlighted or just the knob?
|
||||||
|
|
||||||
QLinearGradient gradient( 0, 0, 0, 1 );
|
QLinearGradient gradient( 0, 0, 0, 1 );
|
||||||
gradient.setCoordinateMode( QGradient::ObjectBoundingMode );
|
gradient.setCoordinateMode( QGradient::ObjectBoundingMode );
|
||||||
gradient.setColorAt( 0, m_baseColor.lighter( 95 ) );
|
gradient.setColorAt( 0, m_baseColorTop );
|
||||||
gradient.setColorAt( 1, m_baseColor.lighter( 115 ) );
|
gradient.setColorAt( 1, m_baseColorBottom );
|
||||||
|
painter.setBrush( gradient );
|
||||||
|
|
||||||
|
painter.drawRoundedRect( QRect( 0, 0, width() - 0, height() - 0 ).adjusted( 3, 0, -3, 0 ), 2, 2 );
|
||||||
|
|
||||||
painter.setBrush( QBrush( gradient ) );
|
painter.drawPixmap( m_knobX * ( width() - m_knob.width() ), 0, m_knob );
|
||||||
painter.setRenderHints( QPainter::Antialiasing, true );
|
|
||||||
painter.drawRoundedRect( QRect( 0, 0, width() - 0, height() - 0 ),
|
|
||||||
5, 5 );
|
|
||||||
|
|
||||||
//knob
|
qDebug() << "Drawn with knob at:" << m_knobX;
|
||||||
QRect knobRect( 2, 2, ( height() - 4 ) * 1.25, height() - 4 );
|
|
||||||
knobRect.moveTo( QPoint( 2 + m_knobX * ( width() - 4 - knobRect.width() ), knobRect.y() ) );
|
|
||||||
QLinearGradient knobGradient( 0, 0, 0, 1 );
|
|
||||||
knobGradient.setCoordinateMode( QGradient::ObjectBoundingMode );
|
|
||||||
knobGradient.setColorAt( 0, m_backUncheckedColor.lighter( 115 ) );
|
|
||||||
knobGradient.setColorAt( 1, m_backUncheckedColor.lighter( 95 ) );
|
|
||||||
painter.setBrush( QBrush( knobGradient ) );
|
|
||||||
|
|
||||||
painter.drawRoundedRect( knobRect, 1, 1 );
|
if ( m_knobX != 1.0 && m_knobX != 0.0 )
|
||||||
|
return;
|
||||||
// if we ever want to try with primitives...
|
|
||||||
// QStyleOptionButton option;
|
|
||||||
// option.initFrom( this );
|
|
||||||
// option.rect = QRect( m_knobX + 1, 1, ( height() - 2 ) * 1.25, height() - 2 );
|
|
||||||
// style()->drawPrimitive( QStyle::PE_PanelButtonBevel, &option, &painter, this );
|
|
||||||
|
|
||||||
//let's draw some text...
|
//let's draw some text...
|
||||||
QRect textRect = rect().adjusted( 4, 3, -4, -3 );
|
if ( m_baseColorTop == m_backUncheckedColorTop )
|
||||||
painter.setFont( m_textFont );
|
|
||||||
painter.setPen( m_textColor );
|
painter.setPen( m_textColor );
|
||||||
if ( m_knobX == 0. )
|
else
|
||||||
{
|
painter.setPen( Qt::white );
|
||||||
//draw on right
|
|
||||||
painter.drawText( textRect, Qt::AlignRight | Qt::AlignVCenter, m_uncheckedText );
|
|
||||||
}
|
|
||||||
else if ( m_knobX == 1. )
|
|
||||||
{
|
|
||||||
//draw on left
|
|
||||||
painter.drawText( textRect, Qt::AlignLeft | Qt::AlignVCenter, m_checkedText );
|
|
||||||
}
|
|
||||||
//otherwise don't draw because the knob is being animated
|
|
||||||
|
|
||||||
painter.end();
|
painter.setFont( m_textFont );
|
||||||
|
const QRect textRect( m_knobX == 0. ? m_knob.width() : 0, 0, width() - m_knob.width(), height() );
|
||||||
|
painter.drawText( textRect, Qt::AlignCenter, m_knobX == 0 ? m_uncheckedText : m_checkedText );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SlideSwitchButton::onCheckedStateChanged()
|
SlideSwitchButton::onCheckedStateChanged()
|
||||||
{
|
{
|
||||||
QPropertyAnimation *animation = new QPropertyAnimation( this, "knobX" );
|
if ( !m_knobAnimation.isNull() )
|
||||||
animation->setDuration( 50 );
|
m_knobAnimation.data()->stop();
|
||||||
|
|
||||||
if ( isChecked() )
|
m_knobAnimation = QWeakPointer<QPropertyAnimation>( new QPropertyAnimation( this, "knobX" ) );
|
||||||
{
|
m_knobAnimation.data()->setDuration( 50 );
|
||||||
animation->setStartValue( 0. );
|
|
||||||
animation->setEndValue( 1. );
|
m_knobAnimation.data()->setStartValue( isChecked() ? 0 : 1 );
|
||||||
}
|
m_knobAnimation.data()->setEndValue( isChecked() ? 1 : 0 );
|
||||||
else
|
|
||||||
{
|
m_knobAnimation.data()->start( QAbstractAnimation::DeleteWhenStopped );
|
||||||
animation->setStartValue( 1. );
|
|
||||||
animation->setEndValue( 0. );
|
|
||||||
}
|
|
||||||
animation->start( QAbstractAnimation::DeleteWhenStopped );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -165,20 +159,24 @@ SlideSwitchButton::setBackChecked( bool state )
|
|||||||
{
|
{
|
||||||
if ( state != m_backChecked )
|
if ( state != m_backChecked )
|
||||||
{
|
{
|
||||||
|
if ( !m_backTopAnimation.isNull() )
|
||||||
|
m_backTopAnimation.data()->stop();
|
||||||
|
if ( !m_backBottomAnimation.isNull() )
|
||||||
|
m_backBottomAnimation.data()->stop();
|
||||||
|
|
||||||
m_backChecked = state;
|
m_backChecked = state;
|
||||||
QPropertyAnimation *animation = new QPropertyAnimation( this, "baseColor" );
|
m_backTopAnimation = QWeakPointer<QPropertyAnimation>( new QPropertyAnimation( this, "baseColorTop" ) );
|
||||||
animation->setDuration( 300 );
|
m_backBottomAnimation = QWeakPointer<QPropertyAnimation>( new QPropertyAnimation( this, "baseColorBottom" ) );
|
||||||
if ( state )
|
m_backTopAnimation.data()->setDuration( 300 );
|
||||||
{
|
m_backBottomAnimation.data()->setDuration( 300 );
|
||||||
animation->setStartValue( m_backUncheckedColor );
|
|
||||||
animation->setEndValue( m_backCheckedColor );
|
m_backTopAnimation.data()->setStartValue( state ? m_backUncheckedColorTop : m_backCheckedColorTop );
|
||||||
}
|
m_backTopAnimation.data()->setEndValue( state ? m_backCheckedColorTop : m_backUncheckedColorTop );
|
||||||
else
|
m_backBottomAnimation.data()->setStartValue( state ? m_backUncheckedColorBottom : m_backCheckedColorBottom );
|
||||||
{
|
m_backBottomAnimation.data()->setEndValue( state ? m_backCheckedColorBottom : m_backUncheckedColorBottom );
|
||||||
animation->setStartValue( m_backCheckedColor );
|
|
||||||
animation->setEndValue( m_backUncheckedColor );
|
m_backTopAnimation.data()->start( QAbstractAnimation::DeleteWhenStopped );
|
||||||
}
|
m_backBottomAnimation.data()->start( QAbstractAnimation::DeleteWhenStopped );
|
||||||
animation->start( QAbstractAnimation::DeleteWhenStopped );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
*
|
*
|
||||||
* Copyright 2012 Teo Mrnjavac <teo@kde.org>
|
* Copyright 2012 Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2012 Leo Franchi <lfranchi@kde.org>
|
||||||
*
|
*
|
||||||
* Tomahawk is free software: you can redistribute it and/or modify
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -23,10 +24,16 @@
|
|||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
#include <QWeakPointer>
|
||||||
|
|
||||||
|
class QPropertyAnimation;
|
||||||
|
|
||||||
class SlideSwitchButton : public QPushButton
|
class SlideSwitchButton : public QPushButton
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY( qreal knobX READ knobX WRITE setKnobX )
|
||||||
|
Q_PROPERTY( QColor baseColorTop READ baseColorTop WRITE setBaseColorTop )
|
||||||
|
Q_PROPERTY( QColor baseColorBottom READ baseColorBottom WRITE setBaseColorBottom )
|
||||||
public:
|
public:
|
||||||
explicit SlideSwitchButton( QWidget* parent = 0 );
|
explicit SlideSwitchButton( QWidget* parent = 0 );
|
||||||
explicit SlideSwitchButton( const QString& checkedText,
|
explicit SlideSwitchButton( const QString& checkedText,
|
||||||
@@ -35,22 +42,22 @@ public:
|
|||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
virtual QSize sizeHint();
|
virtual QSize sizeHint() const;
|
||||||
virtual QSize minimumSizeHint() { return sizeHint(); }
|
virtual QSize minimumSizeHint() const { return sizeHint(); }
|
||||||
|
|
||||||
//the back check-state cannot be changed by the user, only programmatically
|
//the back check-state cannot be changed by the user, only programmatically
|
||||||
//to notify that the user-requested operation has completed
|
//to notify that the user-requested operation has completed
|
||||||
void setBackChecked( bool state );
|
void setBackChecked( bool state );
|
||||||
bool backChecked() const;
|
bool backChecked() const;
|
||||||
|
|
||||||
void setKnobX( double x ) { m_knobX = x; repaint(); }
|
void setKnobX( qreal x ) { m_knobX = x; repaint(); }
|
||||||
double knobX() const { return m_knobX; }
|
qreal knobX() const { return m_knobX; }
|
||||||
Q_PROPERTY( double knobX READ knobX WRITE setKnobX )
|
|
||||||
|
|
||||||
void setBaseColor( const QColor& color ) { m_baseColor = color; repaint(); }
|
void setBaseColorTop( const QColor& color ) { m_baseColorTop = color; repaint(); }
|
||||||
QColor baseColor() const { return m_baseColor; }
|
QColor baseColorTop() const { return m_baseColorTop; }
|
||||||
Q_PROPERTY( QColor baseColor READ baseColor WRITE setBaseColor )
|
|
||||||
|
|
||||||
|
void setBaseColorBottom( const QColor& color ) { m_baseColorBottom = color; }
|
||||||
|
QColor baseColorBottom() const { return m_baseColorBottom; }
|
||||||
protected:
|
protected:
|
||||||
void paintEvent( QPaintEvent* event );
|
void paintEvent( QPaintEvent* event );
|
||||||
|
|
||||||
@@ -58,15 +65,21 @@ private slots:
|
|||||||
void onCheckedStateChanged();
|
void onCheckedStateChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QPixmap m_knob;
|
||||||
|
|
||||||
QString m_checkedText;
|
QString m_checkedText;
|
||||||
QString m_uncheckedText;
|
QString m_uncheckedText;
|
||||||
QColor m_baseColor;
|
QColor m_baseColorTop, m_baseColorBottom;
|
||||||
QColor m_textColor;
|
QColor m_textColor;
|
||||||
QColor m_backUncheckedColor;
|
QColor m_backUncheckedColorTop, m_backUncheckedColorBottom;
|
||||||
QColor m_backCheckedColor;
|
QColor m_backCheckedColorTop, m_backCheckedColorBottom;
|
||||||
QFont m_textFont; //needed for sizeHint
|
QFont m_textFont; //needed for sizeHint
|
||||||
bool m_backChecked;
|
bool m_backChecked;
|
||||||
double m_knobX;
|
qreal m_knobX;
|
||||||
|
|
||||||
|
QWeakPointer<QPropertyAnimation> m_backTopAnimation;
|
||||||
|
QWeakPointer<QPropertyAnimation> m_backBottomAnimation;
|
||||||
|
QWeakPointer<QPropertyAnimation> m_knobAnimation;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SLIDESWITCHBUTTON_H
|
#endif // SLIDESWITCHBUTTON_H
|
||||||
|
Reference in New Issue
Block a user