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