slider layout code fixed
This commit is contained in:
parent
cd65adb451
commit
59b88ffd7c
@ -775,7 +775,7 @@ void Editor::setupSlider()
|
||||
using Q = QskSlider;
|
||||
using P = QPalette;
|
||||
|
||||
const qreal extent = 30_px;
|
||||
const qreal extent = 16_px;
|
||||
|
||||
// Panel
|
||||
|
||||
@ -784,6 +784,7 @@ void Editor::setupSlider()
|
||||
setBoxBorderMetrics( Q::Panel, 0 );
|
||||
setGradient( Q::Panel, QskGradient() );
|
||||
|
||||
// space for the handle
|
||||
setPadding( Q::Panel | A::Horizontal, QskMargins( 0.5 * extent, 0 ) );
|
||||
setPadding( Q::Panel | A::Vertical, QskMargins( 0, 0.5 * extent ) );
|
||||
|
||||
@ -832,7 +833,7 @@ void Editor::setupSlider()
|
||||
Combination( { Q::Hovered, Q::Pressed } ) );
|
||||
#endif
|
||||
|
||||
setStrutSize( Q::Handle, 16_px, 16_px );
|
||||
setStrutSize( Q::Handle, extent, extent );
|
||||
|
||||
for ( auto state : { A::NoState, Q::Pressed } )
|
||||
{
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "QskSlider.h"
|
||||
#include "QskAnimationHint.h"
|
||||
#include "QskAspect.h"
|
||||
#include "QskIntervalF.h"
|
||||
#include "QskEvent.h"
|
||||
|
||||
QSK_SUBCONTROL( QskSlider, Panel )
|
||||
@ -23,6 +22,20 @@ static inline QskAspect qskAspectGraduationPolicy()
|
||||
return QskSlider::Tick | QskAspect::Option;
|
||||
}
|
||||
|
||||
static QRectF qskHandleSelectionRect( const QskSlider* slider )
|
||||
{
|
||||
auto rect = slider->subControlRect( QskSlider::Handle );
|
||||
|
||||
#if 1
|
||||
// minimum handle strut size TODO ...
|
||||
const QSizeF strutSize( 60, 60 );
|
||||
const auto w = qMax( ( strutSize.width() - rect.width() ) / 2, 0.0 );
|
||||
const auto h = qMax( ( strutSize.height() - rect.height() ) / 2, 0.0 );
|
||||
#endif
|
||||
|
||||
return rect.marginsAdded( { w, h, w, h } );
|
||||
}
|
||||
|
||||
class QskSlider::PrivateData
|
||||
{
|
||||
public:
|
||||
@ -132,27 +145,9 @@ void QskSlider::aboutToShow()
|
||||
Inherited::aboutToShow();
|
||||
}
|
||||
|
||||
QSizeF QskSlider::handleSize() const
|
||||
{
|
||||
return handleRect().size();
|
||||
}
|
||||
|
||||
QRectF QskSlider::handleRect() const
|
||||
{
|
||||
auto rect = subControlRect( Handle );
|
||||
|
||||
#if 1 // minimum handle strut size hardcoded here for now
|
||||
const QSizeF strutSize( 60, 60 );
|
||||
const auto w = qMax( ( strutSize.width() - rect.width() ) / 2, 0.0 );
|
||||
const auto h = qMax( ( strutSize.height() - rect.height() ) / 2, 0.0 );
|
||||
#endif
|
||||
|
||||
return rect.marginsAdded( { w, h, w, h } );
|
||||
}
|
||||
|
||||
void QskSlider::mousePressEvent( QMouseEvent* event )
|
||||
{
|
||||
if ( handleRect().contains( event->pos() ) )
|
||||
if ( qskHandleSelectionRect( this ).contains( event->pos() ) )
|
||||
{
|
||||
// Case 1: press started in the handle, start sliding
|
||||
|
||||
@ -211,7 +206,7 @@ void QskSlider::mouseReleaseEvent( QMouseEvent* event )
|
||||
{
|
||||
const auto mousePos = qskMousePosition( event );
|
||||
|
||||
const auto szHandle = handleSize();
|
||||
const auto szHandle = qskHandleSelectionRect( this ).size();
|
||||
const auto rect = contentsRect();
|
||||
|
||||
bool up;
|
||||
|
@ -65,9 +65,6 @@ class QSK_EXPORT QskSlider : public QskBoundedValueInput
|
||||
void mouseMoveEvent( QMouseEvent* ) override;
|
||||
void mouseReleaseEvent( QMouseEvent* ) override;
|
||||
|
||||
QSizeF handleSize() const;
|
||||
QRectF handleRect() const;
|
||||
|
||||
void aboutToShow() override;
|
||||
|
||||
private:
|
||||
|
@ -16,29 +16,36 @@ QSK_SYSTEM_STATE( QskSliderSkinlet, Filled, QskAspect::FirstUserState >> 1 )
|
||||
|
||||
using Q = QskSlider;
|
||||
|
||||
static inline qreal qskSubcontrolExtent(
|
||||
const QskSkinnable* skinnable, QskAspect::Subcontrol subControl )
|
||||
{
|
||||
return skinnable->metric( subControl | QskAspect::Size, -1.0 );
|
||||
}
|
||||
|
||||
static QRectF qskInnerRect( const QskSlider* slider,
|
||||
const QRectF& contentsRect, QskAspect::Subcontrol subControl )
|
||||
{
|
||||
auto r = slider->subControlContentsRect( contentsRect, Q::Panel );
|
||||
|
||||
QskSkinHintStatus status;
|
||||
const qreal extent = qskSubcontrolExtent( slider, subControl );
|
||||
|
||||
const qreal extent = slider->metric( subControl | QskAspect::Size, &status );
|
||||
|
||||
if ( slider->orientation() == Qt::Horizontal )
|
||||
if ( extent >= 0.0 )
|
||||
{
|
||||
if ( status.isValid() && ( extent < r.height() ) )
|
||||
if ( slider->orientation() == Qt::Horizontal )
|
||||
{
|
||||
r.setTop( r.center().y() - 0.5 * extent );
|
||||
r.setHeight( extent );
|
||||
if ( extent < r.height() )
|
||||
{
|
||||
r.setTop( r.center().y() - 0.5 * extent );
|
||||
r.setHeight( extent );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( status.isValid() && ( extent < r.width() ) )
|
||||
else
|
||||
{
|
||||
r.setLeft( r.center().x() - 0.5 * extent );
|
||||
r.setWidth( extent );
|
||||
if ( extent < r.width() )
|
||||
{
|
||||
r.setLeft( r.center().x() - 0.5 * extent );
|
||||
r.setWidth( extent );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,15 +220,15 @@ QRectF QskSliderSkinlet::panelRect(
|
||||
{
|
||||
auto r = contentsRect;
|
||||
|
||||
const qreal size = slider->metric( Q::Panel | QskAspect::Size ); // 0: no hint
|
||||
if ( size > 0 && size < r.height() )
|
||||
const qreal extent = qskSubcontrolExtent( slider, Q::Panel );
|
||||
if ( extent >= 0 && extent < r.height() )
|
||||
{
|
||||
const auto alignment = slider->alignmentHint( Q::Panel );
|
||||
|
||||
if ( slider->orientation() == Qt::Horizontal )
|
||||
r = qskAlignedRectF( r, r.width(), size, alignment & Qt::AlignVertical_Mask );
|
||||
r = qskAlignedRectF( r, r.width(), extent, alignment & Qt::AlignVertical_Mask );
|
||||
else
|
||||
r = qskAlignedRectF( r, size, r.height(), alignment & Qt::AlignHorizontal_Mask );
|
||||
r = qskAlignedRectF( r, extent, r.height(), alignment & Qt::AlignHorizontal_Mask );
|
||||
}
|
||||
|
||||
return r;
|
||||
@ -322,10 +329,18 @@ QSizeF QskSliderSkinlet::sizeHint( const QskSkinnable* skinnable,
|
||||
if ( which != Qt::PreferredSize )
|
||||
return QSizeF();
|
||||
|
||||
auto hint = skinnable->strutSizeHint( Q::Panel );
|
||||
hint = hint.expandedTo( skinnable->strutSizeHint( Q::Groove ) );
|
||||
hint = hint.expandedTo( skinnable->strutSizeHint( Q::Fill ) );
|
||||
hint = hint.expandedTo( skinnable->strutSizeHint( Q::Handle ) );
|
||||
auto extent = qskSubcontrolExtent( skinnable, Q::Panel );
|
||||
extent = qMax( extent, qskSubcontrolExtent( skinnable, Q::Groove ) );
|
||||
extent = qMax( extent, qskSubcontrolExtent( skinnable, Q::Fill ) );
|
||||
|
||||
const auto slider = static_cast< const QskSlider* >( skinnable );
|
||||
|
||||
auto hint = skinnable->strutSizeHint( Q::Handle );
|
||||
|
||||
if ( slider->orientation() == Qt::Horizontal )
|
||||
hint.setHeight( qMax( hint.height(), extent ) );
|
||||
else
|
||||
hint.setWidth( qMax( hint.width(), extent ) );
|
||||
|
||||
return hint;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user