refactoring + focused state
This commit is contained in:
parent
8ecadfc852
commit
ad7a20053c
@ -40,7 +40,7 @@ void SpinBoxPage::populate()
|
||||
const auto x = grid->elementCount() % cols;
|
||||
const auto y = grid->elementCount() / cols;
|
||||
auto* const column = new QskLinearBox(Qt::Vertical, grid);
|
||||
auto* const label = new QskTextLabel(layouts.value(layout), column); // TODO put label either on top or on the bottom
|
||||
auto* const label = new QskTextLabel(layouts.value(layout), column);
|
||||
auto* const spinbox = new QskSpinBox( column );
|
||||
spinbox->setAlignmentHint(QskSpinBox::Layout, layout);
|
||||
grid->addItem(column, y, x);
|
||||
|
@ -682,20 +682,20 @@ void Editor::setupSpinBox()
|
||||
setSpacing(QskSpinBox::Layout, 4_dp);
|
||||
|
||||
setStrutSize(QskSpinBox::TextPanel | QskAspect::Size, {80_dp,40_dp});
|
||||
setStrutSize(QskSpinBox::Inc | QskAspect::Size, {40_dp,40_dp});
|
||||
setStrutSize(QskSpinBox::Dec | QskAspect::Size, {40_dp,40_dp});
|
||||
setStrutSize(QskSpinBox::IncrementPanel | QskAspect::Size, {40_dp,40_dp});
|
||||
setStrutSize(QskSpinBox::DecrementPanel | QskAspect::Size, {40_dp,40_dp});
|
||||
|
||||
setAlignment(QskSpinBox::Layout, Qt::AlignHCenter);
|
||||
setAlignment(Q::Text, Qt::AlignCenter);
|
||||
|
||||
for(const auto& state : {QskSpinBox::Dec, QskSpinBox::Inc, QskSpinBox::TextPanel})
|
||||
for(const auto& state : {QskSpinBox::DecrementPanel, QskSpinBox::IncrementPanel, QskSpinBox::TextPanel})
|
||||
{
|
||||
setBoxShape(state, 4_dp);
|
||||
setBoxBorderColors(state, QColor("#79747E"));
|
||||
setBoxBorderMetrics(state, 1_dp);
|
||||
}
|
||||
|
||||
for(const auto& state : {QskSpinBox::Dec, QskSpinBox::Inc})
|
||||
for(const auto& state : {QskSpinBox::DecrementPanel, QskSpinBox::IncrementPanel})
|
||||
{
|
||||
setGradient( state, m_pal.primary );
|
||||
setGradient( state | Q::Disabled, m_pal.onSurface12 );
|
||||
@ -710,7 +710,7 @@ void Editor::setupSpinBox()
|
||||
setShadowColor( state | Q::Hovered, m_pal.shadow );
|
||||
}
|
||||
|
||||
for(const auto& state : {QskSpinBox::DecText, QskSpinBox::IncText})
|
||||
for(const auto& state : {QskSpinBox::DecrementText, QskSpinBox::IncrementText})
|
||||
{
|
||||
setColor( state, m_pal.onPrimary );
|
||||
setColor( state | Q::Disabled, m_pal.onSurface38 );
|
||||
|
@ -19,22 +19,28 @@
|
||||
#include <QskIntervalF.h>
|
||||
#include <array>
|
||||
|
||||
QSK_SUBCONTROL(QskSpinBox, Inc)
|
||||
QSK_SUBCONTROL(QskSpinBox, Dec)
|
||||
QSK_SUBCONTROL(QskSpinBox, IncText)
|
||||
QSK_SUBCONTROL(QskSpinBox, DecText)
|
||||
QSK_SUBCONTROL(QskSpinBox, IncrementPanel)
|
||||
QSK_SUBCONTROL(QskSpinBox, DecrementPanel)
|
||||
QSK_SUBCONTROL(QskSpinBox, IncrementText)
|
||||
QSK_SUBCONTROL(QskSpinBox, DecrementText)
|
||||
QSK_SUBCONTROL(QskSpinBox, Text)
|
||||
QSK_SUBCONTROL(QskSpinBox, TextPanel)
|
||||
QSK_SUBCONTROL(QskSpinBox, Layout)
|
||||
|
||||
QSK_SYSTEM_STATE(QskSpinBox, Pressed, ( QskAspect::QskAspect::FirstSystemState << 0))
|
||||
|
||||
namespace aliased_enum
|
||||
{
|
||||
constexpr auto D = QskSpinBox::Decrement;
|
||||
constexpr auto T = QskSpinBox::Textbox;
|
||||
constexpr auto I = QskSpinBox::Increment;
|
||||
constexpr auto N = QskSpinBox::None;
|
||||
}
|
||||
|
||||
class QskSpinBox::PrivateData
|
||||
{
|
||||
public:
|
||||
|
||||
enum FocusIndeces : int { Dec = 0, Text = 1, Inc = 2, None = 3 };
|
||||
|
||||
explicit PrivateData(QskSpinBox* const parent) : q(parent)
|
||||
{
|
||||
}
|
||||
@ -57,16 +63,16 @@ public:
|
||||
{
|
||||
const auto layout = q->alignmentHint(QskSpinBox::Layout);
|
||||
|
||||
if(layout == Qt::AlignLeft) return Text;
|
||||
if(layout == Qt::AlignRight) return Dec;
|
||||
if(layout == Qt::AlignHCenter) return Dec;
|
||||
if(layout == Qt::AlignTop) return Text;
|
||||
if(layout == Qt::AlignBottom) return Inc;
|
||||
if(layout == Qt::AlignVCenter) return Inc;
|
||||
if(layout == (Qt::AlignLeft | Qt::AlignVCenter)) return Text;
|
||||
if(layout == (Qt::AlignRight | Qt::AlignVCenter)) return Inc;
|
||||
if(layout == (Qt::AlignTop | Qt::AlignHCenter)) return Text;
|
||||
if(layout == (Qt::AlignBottom | Qt::AlignHCenter)) return Dec;
|
||||
if(layout == Qt::AlignLeft) return QskSpinBox::Textbox;
|
||||
if(layout == Qt::AlignRight) return QskSpinBox::Decrement;
|
||||
if(layout == Qt::AlignHCenter) return QskSpinBox::Decrement;
|
||||
if(layout == Qt::AlignTop) return QskSpinBox::Textbox;
|
||||
if(layout == Qt::AlignBottom) return QskSpinBox::Increment;
|
||||
if(layout == Qt::AlignVCenter) return QskSpinBox::Increment;
|
||||
if(layout == (Qt::AlignLeft | Qt::AlignVCenter)) return QskSpinBox::Textbox;
|
||||
if(layout == (Qt::AlignRight | Qt::AlignVCenter)) return QskSpinBox::Increment;
|
||||
if(layout == (Qt::AlignTop | Qt::AlignHCenter)) return QskSpinBox::Textbox;
|
||||
if(layout == (Qt::AlignBottom | Qt::AlignHCenter)) return QskSpinBox::Decrement;
|
||||
|
||||
return None;
|
||||
}
|
||||
@ -74,20 +80,21 @@ public:
|
||||
FocusIndeces nextFocusIndex() const
|
||||
{
|
||||
const auto layout = q->alignmentHint(QskSpinBox::Layout);
|
||||
using namespace aliased_enum;
|
||||
|
||||
// [0 ][1 ][2 ][3 ]
|
||||
// [Dec][Text][Inc][None]
|
||||
using LUT = std::array<FocusIndeces,4>;
|
||||
if(layout == Qt::AlignLeft) return LUT{Inc,Dec,None,Text}[m_focusIndex];
|
||||
if(layout == Qt::AlignRight) return LUT{Inc,None,Text,Dec}[m_focusIndex];
|
||||
if(layout == Qt::AlignHCenter) return LUT{Text,Inc,None,Dec}[m_focusIndex];
|
||||
if(layout == Qt::AlignTop) return LUT{Inc,Dec,None,Text}[m_focusIndex];
|
||||
if(layout == Qt::AlignBottom) return LUT{Inc,None,Text,Dec}[m_focusIndex];
|
||||
if(layout == Qt::AlignVCenter) return LUT{None,Dec,Text,Inc}[m_focusIndex];
|
||||
if(layout == (Qt::AlignLeft | Qt::AlignVCenter)) return LUT{None,Inc,Dec,Text}[m_focusIndex];
|
||||
if(layout == (Qt::AlignRight | Qt::AlignVCenter)) return LUT{Text,None,Dec,Inc}[m_focusIndex];
|
||||
if(layout == (Qt::AlignTop | Qt::AlignHCenter)) return LUT{Inc,Dec,None,Text}[m_focusIndex];
|
||||
if(layout == (Qt::AlignBottom | Qt::AlignHCenter)) return LUT{Inc,None,Text,Dec}[m_focusIndex];
|
||||
// [0][1][2][3] := index
|
||||
// [D][T][I][N] := control
|
||||
using LUT = std::array<QskSpinBox::FocusIndeces,4>;
|
||||
if(layout == Qt::AlignLeft) return LUT{I,D,N,T}[m_focusIndex];
|
||||
if(layout == Qt::AlignRight) return LUT{I,N,T,D}[m_focusIndex];
|
||||
if(layout == Qt::AlignHCenter) return LUT{T,I,N,D}[m_focusIndex];
|
||||
if(layout == Qt::AlignTop) return LUT{I,D,N,T}[m_focusIndex];
|
||||
if(layout == Qt::AlignBottom) return LUT{I,N,T,D}[m_focusIndex];
|
||||
if(layout == Qt::AlignVCenter) return LUT{N,D,T,I}[m_focusIndex];
|
||||
if(layout == (Qt::AlignLeft | Qt::AlignVCenter)) return LUT{N,I,D,T}[m_focusIndex];
|
||||
if(layout == (Qt::AlignRight | Qt::AlignVCenter)) return LUT{T,N,D,I}[m_focusIndex];
|
||||
if(layout == (Qt::AlignTop | Qt::AlignHCenter)) return LUT{I,D,N,T}[m_focusIndex];
|
||||
if(layout == (Qt::AlignBottom | Qt::AlignHCenter)) return LUT{I,N,T,D}[m_focusIndex];
|
||||
|
||||
return None;
|
||||
}
|
||||
@ -95,20 +102,21 @@ public:
|
||||
FocusIndeces previousFocusIndex() const
|
||||
{
|
||||
const auto layout = q->alignmentHint(QskSpinBox::Layout);
|
||||
using namespace aliased_enum;
|
||||
|
||||
// [0 ][1 ][2 ][3 ]
|
||||
// [Dec][Text][Inc][None]
|
||||
// [0][1][2][3] := index
|
||||
// [D][T][I][N] := control
|
||||
using LUT = std::array<FocusIndeces,4>;
|
||||
if(layout == Qt::AlignLeft) return LUT{None,Dec,Text,Inc}[m_focusIndex];
|
||||
if(layout == Qt::AlignRight) return LUT{None,Inc,Dec,Text}[m_focusIndex];
|
||||
if(layout == Qt::AlignHCenter) return LUT{None,Dec,Text,Inc}[m_focusIndex];
|
||||
if(layout == Qt::AlignTop) return LUT{Text,None,Dec,Inc}[m_focusIndex];
|
||||
if(layout == Qt::AlignBottom) return LUT{None,Inc,Dec,Text}[m_focusIndex];
|
||||
if(layout == Qt::AlignVCenter) return LUT{Text,Inc,None,Dec}[m_focusIndex];
|
||||
if(layout == (Qt::AlignLeft | Qt::AlignVCenter)) return LUT{Inc,None,Text,Dec}[m_focusIndex];
|
||||
if(layout == (Qt::AlignRight | Qt::AlignVCenter)) return LUT{Inc,Dec,None,Text}[m_focusIndex];
|
||||
if(layout == (Qt::AlignTop | Qt::AlignHCenter)) return LUT{Text,None,Dec,Inc}[m_focusIndex];
|
||||
if(layout == (Qt::AlignBottom | Qt::AlignHCenter)) return LUT{None,Inc,Dec,Text}[m_focusIndex];
|
||||
if(layout == Qt::AlignLeft) return LUT{N,D,T,I}[m_focusIndex];
|
||||
if(layout == Qt::AlignRight) return LUT{N,I,D,T}[m_focusIndex];
|
||||
if(layout == Qt::AlignHCenter) return LUT{N,D,T,I}[m_focusIndex];
|
||||
if(layout == Qt::AlignTop) return LUT{T,N,D,I}[m_focusIndex];
|
||||
if(layout == Qt::AlignBottom) return LUT{N,I,D,T}[m_focusIndex];
|
||||
if(layout == Qt::AlignVCenter) return LUT{T,I,N,D}[m_focusIndex];
|
||||
if(layout == (Qt::AlignLeft | Qt::AlignVCenter)) return LUT{I,N,T,D}[m_focusIndex];
|
||||
if(layout == (Qt::AlignRight | Qt::AlignVCenter)) return LUT{I,D,N,T}[m_focusIndex];
|
||||
if(layout == (Qt::AlignTop | Qt::AlignHCenter)) return LUT{T,N,D,I}[m_focusIndex];
|
||||
if(layout == (Qt::AlignBottom | Qt::AlignHCenter)) return LUT{N,I,D,T}[m_focusIndex];
|
||||
|
||||
return None;
|
||||
}
|
||||
@ -137,26 +145,22 @@ public:
|
||||
|
||||
void setFocus(const FocusIndeces index)
|
||||
{
|
||||
Q_ASSERT(index == Dec || index == Text || index == Inc || index == None);
|
||||
if(index == Dec || index == Text || index == Inc || index == None)
|
||||
using namespace aliased_enum;
|
||||
Q_ASSERT(index == D || index == T || index == I || index == N);
|
||||
if(index == D || index == T || index == I || index == N)
|
||||
{
|
||||
m_focusIndex = index;
|
||||
Q_EMIT q->focusIndexChanged(m_focusIndex); // TODO register enum
|
||||
Q_EMIT q->focusIndexChanged(m_focusIndex);
|
||||
}
|
||||
}
|
||||
|
||||
QRectF focusIndicatorRect() const
|
||||
{
|
||||
switch(m_focusIndex)
|
||||
{
|
||||
case PrivateData::FocusIndeces::Dec:
|
||||
return q->subControlRect(QskSpinBox::Dec);
|
||||
case PrivateData::FocusIndeces::Text:
|
||||
return q->subControlRect(QskSpinBox::TextPanel);
|
||||
case PrivateData::FocusIndeces::Inc:
|
||||
return q->subControlRect(QskSpinBox::Inc);
|
||||
default: return {};
|
||||
}
|
||||
using namespace aliased_enum;
|
||||
if(m_focusIndex == D) return q->subControlRect(QskSpinBox::DecrementPanel);
|
||||
if(m_focusIndex == I) return q->subControlRect(QskSpinBox::IncrementPanel);
|
||||
if(m_focusIndex == T) return q->subControlRect(QskSpinBox::TextPanel);
|
||||
return {};
|
||||
}
|
||||
|
||||
void saveMousePosition(const QPointF& pos)
|
||||
@ -209,25 +213,25 @@ void QskSpinBox::mouseReleaseEvent(QMouseEvent *event)
|
||||
|
||||
const auto focus = ( focusPolicy() & Qt::ClickFocus ) == Qt::ClickFocus && !QGuiApplication::styleHints()->setFocusOnTouchRelease();
|
||||
|
||||
if(subControlRect(QskSpinBox::Inc).contains( event->pos() ))
|
||||
if(subControlRect(QskSpinBox::IncrementPanel).contains( event->pos() ))
|
||||
{
|
||||
increment(+stepSize());
|
||||
|
||||
if( focus )
|
||||
{
|
||||
m_data->setFocus(PrivateData::Inc);
|
||||
m_data->setFocus(Increment);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(subControlRect(QskSpinBox::Dec).contains( event->pos() ))
|
||||
if(subControlRect(QskSpinBox::DecrementPanel).contains( event->pos() ))
|
||||
{
|
||||
increment(-stepSize());
|
||||
|
||||
if( focus )
|
||||
{
|
||||
m_data->setFocus(PrivateData::Dec);
|
||||
m_data->setFocus(Decrement);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -237,7 +241,7 @@ void QskSpinBox::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if( focus )
|
||||
{
|
||||
m_data->setFocus(PrivateData::Text);
|
||||
m_data->setFocus(Textbox);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -252,20 +256,20 @@ void QskSpinBox::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
const auto focus = ( focusPolicy() & Qt::ClickFocus ) == Qt::ClickFocus && !QGuiApplication::styleHints()->setFocusOnTouchRelease();
|
||||
|
||||
if(subControlRect(QskSpinBox::Inc).contains( event->pos() ))
|
||||
if(subControlRect(QskSpinBox::IncrementPanel).contains( event->pos() ))
|
||||
{
|
||||
if( focus )
|
||||
{
|
||||
m_data->setFocus(PrivateData::Inc);
|
||||
m_data->setFocus(QskSpinBox::Increment);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(subControlRect(QskSpinBox::Dec).contains( event->pos() ))
|
||||
if(subControlRect(QskSpinBox::DecrementPanel).contains( event->pos() ))
|
||||
{
|
||||
if( focus )
|
||||
{
|
||||
m_data->setFocus(PrivateData::Dec);
|
||||
m_data->setFocus(QskSpinBox::Decrement);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -280,12 +284,12 @@ void QskSpinBox::keyPressEvent(QKeyEvent *event)
|
||||
case Qt::Key_Plus:
|
||||
case Qt::Key_Up:
|
||||
case Qt::Key_Right:
|
||||
// TODO increment
|
||||
increment(+stepSize());
|
||||
break;
|
||||
case Qt::Key_Minus:
|
||||
case Qt::Key_Down:
|
||||
case Qt::Key_Left:
|
||||
// TODO decrement
|
||||
increment(-stepSize());
|
||||
break;
|
||||
case Qt::Key_Select:
|
||||
case Qt::Key_Space:
|
||||
@ -333,7 +337,7 @@ void QskSpinBox::focusInEvent(QFocusEvent *event)
|
||||
break;
|
||||
|
||||
default:
|
||||
if(m_data->focusIndex() == PrivateData::None)
|
||||
if(m_data->focusIndex() == QskSpinBox::None)
|
||||
{
|
||||
m_data->focusDefault();
|
||||
return;
|
||||
@ -357,3 +361,8 @@ qreal QskSpinBox::value() const
|
||||
{
|
||||
return m_data->value();
|
||||
}
|
||||
|
||||
QskSpinBox::FocusIndeces QskSpinBox::focusIndex() const
|
||||
{
|
||||
return m_data->focusIndex();
|
||||
}
|
||||
|
@ -14,8 +14,12 @@ class QSK_EXPORT QskSpinBox : public QskBoundedInput
|
||||
Q_OBJECT
|
||||
using Inherited = QskBoundedInput;
|
||||
public:
|
||||
enum FocusIndeces : int { Decrement = 0, Textbox = 1, Increment = 2, None = 3 };
|
||||
Q_ENUM(FocusIndeces)
|
||||
|
||||
Q_PROPERTY(qreal value READ value NOTIFY valueChanged)
|
||||
QSK_SUBCONTROLS(Inc, Dec, IncText, DecText, TextPanel, Text, Layout)
|
||||
Q_PROPERTY(FocusIndeces focusIndex READ focusIndex NOTIFY focusIndexChanged)
|
||||
QSK_SUBCONTROLS(IncrementPanel, DecrementPanel, IncrementText, DecrementText, TextPanel, Text, Layout)
|
||||
QSK_STATES( Pressed )
|
||||
|
||||
explicit QskSpinBox( QQuickItem* parent = nullptr );
|
||||
@ -24,12 +28,13 @@ public:
|
||||
void increment( qreal offset ) override;
|
||||
qreal value() const;
|
||||
|
||||
FocusIndeces focusIndex() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void valueChanged(qreal value);
|
||||
void focusIndexChanged(int index);
|
||||
|
||||
private:
|
||||
Q_SIGNAL void focusIndexChanged(int index);
|
||||
|
||||
void hoverEnterEvent( QHoverEvent* event) override;
|
||||
void hoverLeaveEvent( QHoverEvent* event) override;
|
||||
void hoverMoveEvent( QHoverEvent* event) override;
|
||||
|
@ -6,11 +6,12 @@
|
||||
#include "QskSpinBoxSkinlet.h"
|
||||
#include "QskSpinBox.h"
|
||||
#include <QFontMetrics>
|
||||
#include <array>
|
||||
|
||||
const auto INC_TEXT = QStringLiteral("+");
|
||||
const auto DEC_TEXT = QStringLiteral("-");
|
||||
const auto INCREMENT_TEXT = QStringLiteral("+");
|
||||
const auto DECREMENT_TEXT = QStringLiteral("-");
|
||||
|
||||
enum SampleIndeces { Dec, Txt, Inc, Count };
|
||||
enum SampleIndeces { Dec = 0, Txt = 1, Inc = 2, Count };
|
||||
|
||||
QskSpinBoxSkinlet::QskSpinBoxSkinlet(QskSkin *)
|
||||
{
|
||||
@ -34,18 +35,26 @@ QRectF QskSpinBoxSkinlet::sampleRect(const QskSkinnable* const skinnable, const
|
||||
|
||||
QskAspect::States QskSpinBoxSkinlet::sampleStates(const QskSkinnable* const skinnable, QskAspect::Subcontrol subControl, int index) const
|
||||
{
|
||||
auto states = Inherited::sampleStates( skinnable, subControl, index );
|
||||
using S = QskSpinBox;
|
||||
auto states = Inherited::sampleStates( skinnable, subControl, index );
|
||||
|
||||
if ( subControl == QskSpinBox::Dec || subControl == QskSpinBox::Inc || subControl == QskSpinBox::TextPanel)
|
||||
if ( subControl == S::DecrementPanel || subControl == S::IncrementPanel || subControl == S::TextPanel)
|
||||
{
|
||||
const auto* const spinbox = static_cast<const QskSpinBox*>(skinnable);
|
||||
const auto cursorPos = spinbox->effectiveSkinHint(QskSpinBox::Layout | QskAspect::Metric | QskAspect::Position).toPointF();
|
||||
const auto* const spinbox = static_cast<const S*>(skinnable);
|
||||
const auto cursorPos = spinbox->effectiveSkinHint(S::Layout | QskAspect::Metric | QskAspect::Position).toPointF();
|
||||
const QPointF cursorPosAbs{qAbs(cursorPos.x()), qAbs(cursorPos.y())};
|
||||
const auto focusIndex = spinbox->focusIndex();
|
||||
|
||||
const auto contain = !cursorPosAbs.isNull() && spinbox->subControlRect(subControl).contains(cursorPosAbs);
|
||||
const auto pressed = contain && (cursorPos.x() < 0 || cursorPos.y() < 0);
|
||||
const auto hovered = contain && !pressed;
|
||||
const auto focused = ( subControl == S::IncrementPanel && focusIndex == S::Increment) ||
|
||||
( subControl == S::DecrementPanel && focusIndex == S::Decrement) ||
|
||||
( subControl == S::TextPanel && focusIndex == S::Textbox);
|
||||
|
||||
states.setFlag(QskControl::Hovered, hovered);
|
||||
states.setFlag(QskSpinBox::Pressed, pressed);
|
||||
states.setFlag(QskControl::Focused, focused);
|
||||
}
|
||||
|
||||
return states;
|
||||
@ -55,11 +64,11 @@ QSizeF QskSpinBoxSkinlet::sizeHint(const QskSkinnable* const skinnable, Qt::Size
|
||||
{
|
||||
using S = QskSpinBox;
|
||||
const auto* const spinbox = static_cast<const S*>(skinnable);
|
||||
const auto layout = spinbox->alignmentHint(QskSpinBox::Layout);
|
||||
const auto spacing = spinbox->spacingHint(QskSpinBox::Layout);
|
||||
const auto layout = spinbox->alignmentHint(S::Layout);
|
||||
const auto spacing = spinbox->spacingHint(S::Layout);
|
||||
|
||||
const auto strutInc = spinbox->strutSizeHint(S::Inc);
|
||||
const auto strutDec = spinbox->strutSizeHint(S::Dec);
|
||||
const auto strutInc = spinbox->strutSizeHint(S::IncrementPanel);
|
||||
const auto strutDec = spinbox->strutSizeHint(S::DecrementPanel);
|
||||
const auto strutTxt = spinbox->strutSizeHint(S::TextPanel);
|
||||
|
||||
if(sizeHint == Qt::MinimumSize || sizeHint == Qt::MaximumSize || Qt::PreferredSize)
|
||||
@ -90,26 +99,25 @@ QSizeF QskSpinBoxSkinlet::sizeHint(const QskSkinnable* const skinnable, Qt::Size
|
||||
}
|
||||
}
|
||||
return Inherited::sizeHint(skinnable, sizeHint, size);
|
||||
|
||||
}
|
||||
|
||||
QRectF QskSpinBoxSkinlet::subControlRect(const QskSkinnable* const skinnable, const QRectF& rect, QskAspect::Subcontrol subControl) const
|
||||
{
|
||||
if(subControl == QskSpinBox::DecText) return subControlRect(skinnable, rect, QskSpinBox::Dec);
|
||||
if(subControl == QskSpinBox::IncText) return subControlRect(skinnable, rect, QskSpinBox::Inc);
|
||||
if(subControl == QskSpinBox::Text) return subControlRect(skinnable, rect, QskSpinBox::TextPanel);
|
||||
|
||||
const auto* const spinbox = static_cast<const QskSpinBox*>(skinnable);
|
||||
const auto layout = spinbox->alignmentHint(QskSpinBox::Layout);
|
||||
const auto spacing = spinbox->spacingHint(QskSpinBox::Layout);
|
||||
|
||||
using S = QskSpinBox;
|
||||
|
||||
QRectF rects[Count] =
|
||||
if(subControl == S::DecrementText) return subControlRect(skinnable, rect, S::DecrementPanel);
|
||||
if(subControl == S::IncrementText) return subControlRect(skinnable, rect, S::IncrementPanel);
|
||||
if(subControl == S::Text) return subControlRect(skinnable, rect, S::TextPanel);
|
||||
|
||||
const auto* const spinbox = static_cast<const S*>(skinnable);
|
||||
const auto layout = spinbox->alignmentHint(S::Layout);
|
||||
const auto spacing = spinbox->spacingHint(S::Layout);
|
||||
|
||||
std::array<QRectF, Count> rects =
|
||||
{
|
||||
{ {}, spinbox->strutSizeHint(S::Dec)},
|
||||
{ {}, spinbox->strutSizeHint(S::TextPanel)},
|
||||
{ {}, spinbox->strutSizeHint(S::Inc)},
|
||||
QRectF{ QPointF{}, spinbox->strutSizeHint(S::DecrementPanel)},
|
||||
QRectF{ QPointF{}, spinbox->strutSizeHint(S::TextPanel)},
|
||||
QRectF{ QPointF{}, spinbox->strutSizeHint(S::IncrementPanel)},
|
||||
};
|
||||
|
||||
const auto center = rect.center();
|
||||
@ -173,14 +181,12 @@ QRectF QskSpinBoxSkinlet::subControlRect(const QskSkinnable* const skinnable, co
|
||||
}
|
||||
else if(layout == (Qt::AlignBottom | Qt::AlignHCenter))
|
||||
{
|
||||
const auto dx = qMax(rects[Inc].width(), rects[Dec].width());
|
||||
const auto dy = qMax(rects[Inc].height(), rects[Dec].height());
|
||||
rects[Txt].moveTopLeft({center.x() - rects[Txt].width() * 0.5, center.y() - rects[Txt].height() * 0.5});
|
||||
rects[Dec].moveTopLeft({center.x() - spacing * 0.5 - rects[Dec].width() , rects[Txt].top() - spacing - rects[Dec].height() });
|
||||
rects[Inc].moveTopLeft({center.x() + spacing * 0.5, rects[Txt].top() - spacing - rects[Inc].height() });
|
||||
}
|
||||
|
||||
if(subControl == S::Dec)
|
||||
if(subControl == S::DecrementPanel)
|
||||
{
|
||||
return rects[Dec];
|
||||
}
|
||||
@ -188,7 +194,7 @@ QRectF QskSpinBoxSkinlet::subControlRect(const QskSkinnable* const skinnable, co
|
||||
{
|
||||
return rects[Txt];
|
||||
}
|
||||
if(subControl == S::Inc)
|
||||
if(subControl == S::IncrementPanel)
|
||||
{
|
||||
return rects[Inc];
|
||||
}
|
||||
@ -198,20 +204,22 @@ QRectF QskSpinBoxSkinlet::subControlRect(const QskSkinnable* const skinnable, co
|
||||
|
||||
QSGNode* QskSpinBoxSkinlet::updateSubNode(const QskSkinnable* const skinnable, const quint8 nodeRole, QSGNode* const node) const
|
||||
{
|
||||
if(nodeRole == IncPanel) { return updateSeriesNode( skinnable, QskSpinBox::Inc, node); }
|
||||
if(nodeRole == DecPanel) { return updateSeriesNode( skinnable, QskSpinBox::Dec, node ); }
|
||||
if(nodeRole == IncText) { return updateTextNode( skinnable, node, INC_TEXT, QskSpinBox::IncText); }
|
||||
if(nodeRole == DecText) { return updateTextNode( skinnable, node, DEC_TEXT, QskSpinBox::DecText ); }
|
||||
if(nodeRole == TextPanel) { return updateSeriesNode( skinnable, QskSpinBox::TextPanel, node ); }
|
||||
if(nodeRole == TextText) { return updateTextNode( skinnable, node, QString::number(static_cast<const QskSpinBox*>(skinnable)->value()), QskSpinBox::Text ); }
|
||||
using S = QskSpinBox;
|
||||
if(nodeRole == IncPanel) { return updateSeriesNode( skinnable, S::IncrementPanel, node); }
|
||||
if(nodeRole == DecPanel) { return updateSeriesNode( skinnable, S::DecrementPanel, node ); }
|
||||
if(nodeRole == IncText) { return updateTextNode( skinnable, node, INCREMENT_TEXT, S::IncrementText); }
|
||||
if(nodeRole == DecText) { return updateTextNode( skinnable, node, DECREMENT_TEXT, S::DecrementText ); }
|
||||
if(nodeRole == TextPanel) { return updateSeriesNode( skinnable, S::TextPanel, node ); }
|
||||
if(nodeRole == TextText) { return updateTextNode( skinnable, node, QString::number(static_cast<const S*>(skinnable)->value()), S::Text ); }
|
||||
return Inherited::updateSubNode(skinnable, nodeRole, node);
|
||||
}
|
||||
|
||||
QSGNode *QskSpinBoxSkinlet::updateSampleNode(const QskSkinnable* const skinnable, QskAspect::Subcontrol subControl, const int index, QSGNode* const node) const
|
||||
QSGNode* QskSpinBoxSkinlet::updateSampleNode(const QskSkinnable* const skinnable, QskAspect::Subcontrol subControl, const int index, QSGNode* const node) const
|
||||
{
|
||||
const auto* const spinbox = static_cast<const QskSpinBox*>(skinnable);
|
||||
using S = QskSpinBox;
|
||||
const auto* const spinbox = static_cast<const S*>(skinnable);
|
||||
|
||||
if ( subControl == QskSpinBox::Dec || subControl == QskSpinBox::Inc || subControl == QskSpinBox::TextPanel )
|
||||
if ( subControl == S::DecrementPanel || subControl == S::IncrementPanel || subControl == S::TextPanel )
|
||||
{
|
||||
const auto rect = sampleRect(spinbox, spinbox->contentsRect(), subControl, index);
|
||||
return updateBoxNode( skinnable, node, rect, subControl );
|
||||
|
Loading…
x
Reference in New Issue
Block a user