make tickmarks configurable
This commit is contained in:
parent
34a94e52f9
commit
680e176dc8
|
@ -9,4 +9,15 @@ RadialTickmarks::RadialTickmarks( QQuickItem* const parent ) : QskControl( paren
|
||||||
setStrutSizeHint( Lines, 2, 10 );
|
setStrutSizeHint( Lines, 2, 10 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RadialTickmarks::setTickmarks( const QskScaleTickmarks& tickmarks )
|
||||||
|
{
|
||||||
|
m_tickmarks = tickmarks;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
QskScaleTickmarks RadialTickmarks::tickmarks() const
|
||||||
|
{
|
||||||
|
return m_tickmarks;
|
||||||
|
}
|
||||||
|
|
||||||
#include "moc_RadialNodes.cpp"
|
#include "moc_RadialNodes.cpp"
|
|
@ -1,10 +1,16 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QskControl.h>
|
#include <QskControl.h>
|
||||||
|
#include <QskScaleTickmarks.h>
|
||||||
|
|
||||||
class RadialTickmarks : public QskControl
|
class RadialTickmarks : public QskControl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QSK_SUBCONTROLS(Lines)
|
QSK_SUBCONTROLS(Lines)
|
||||||
explicit RadialTickmarks( QQuickItem* parent = nullptr );
|
explicit RadialTickmarks( QQuickItem* parent = nullptr );
|
||||||
|
void setTickmarks(const QskScaleTickmarks& tickmarks);
|
||||||
|
QskScaleTickmarks tickmarks() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QskScaleTickmarks m_tickmarks;
|
||||||
};
|
};
|
|
@ -175,7 +175,8 @@ QRectF RadialTickmarksSkinlet::subControlRect( const QskSkinnable* const skinnab
|
||||||
{
|
{
|
||||||
if ( subControl == RadialTickmarks::Lines )
|
if ( subControl == RadialTickmarks::Lines )
|
||||||
{
|
{
|
||||||
return contentsRect;
|
const auto a = skinnable->strutSizeHint(RadialTickmarks::Lines).height() / 2;
|
||||||
|
return contentsRect.adjusted(+a, +a, -a, -a);
|
||||||
}
|
}
|
||||||
return QskSkinlet::subControlRect( skinnable, contentsRect, subControl );
|
return QskSkinlet::subControlRect( skinnable, contentsRect, subControl );
|
||||||
}
|
}
|
||||||
|
@ -189,22 +190,6 @@ QSGNode* RadialTickmarksSkinlet::updateSubNode(
|
||||||
{
|
{
|
||||||
case Lines: {
|
case Lines: {
|
||||||
const auto* const control = static_cast< const Q* >( skinnable );
|
const auto* const control = static_cast< const Q* >( skinnable );
|
||||||
|
|
||||||
QskScaleTickmarks tickmarks;
|
|
||||||
QVector< qreal > major, medium, minor;
|
|
||||||
for ( int deg = 0; deg < 360; deg += 1 )
|
|
||||||
{
|
|
||||||
if ( deg % 10 == 0 )
|
|
||||||
major << deg;
|
|
||||||
else if ( deg % 5 == 0 )
|
|
||||||
medium << deg;
|
|
||||||
else
|
|
||||||
minor << deg;
|
|
||||||
}
|
|
||||||
tickmarks.setMajorTicks( major );
|
|
||||||
tickmarks.setMediumTicks( medium );
|
|
||||||
tickmarks.setMinorTicks( minor );
|
|
||||||
|
|
||||||
const auto subControlRect = control->subControlContentsRect( Q::Lines );
|
const auto subControlRect = control->subControlContentsRect( Q::Lines );
|
||||||
const auto alignment = control->alignmentHint( Q::Lines );
|
const auto alignment = control->alignmentHint( Q::Lines );
|
||||||
const auto size = control->strutSizeHint( Q::Lines );
|
const auto size = control->strutSizeHint( Q::Lines );
|
||||||
|
@ -221,7 +206,7 @@ QSGNode* RadialTickmarksSkinlet::updateSubNode(
|
||||||
|
|
||||||
auto* const root = QskSGNode::ensureNode< QskRadialTickmarksNode >( node );
|
auto* const root = QskSGNode::ensureNode< QskRadialTickmarksNode >( node );
|
||||||
root->setMaterialProperties( skinnable->color( Q::Lines ) );
|
root->setMaterialProperties( skinnable->color( Q::Lines ) );
|
||||||
root->setGeometryProperties( tickmarks, radius, height, c, alignment, size.width() );
|
root->setGeometryProperties( control->tickmarks(), radius, height, c, alignment, size.width() );
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -6,19 +6,19 @@
|
||||||
#include <SkinnyShapeProvider.h>
|
#include <SkinnyShapeProvider.h>
|
||||||
#include <SkinnyShortcut.h>
|
#include <SkinnyShortcut.h>
|
||||||
|
|
||||||
#include <QskWindow.h>
|
|
||||||
#include <QskObjectCounter.h>
|
|
||||||
#include <QskFocusIndicator.h>
|
|
||||||
#include <QskBox.h>
|
|
||||||
#include <QskLinearBox.h>
|
|
||||||
#include <QskSkinManager.h>
|
|
||||||
#include <QskAnimationHint.h>
|
#include <QskAnimationHint.h>
|
||||||
#include <QskSkinTransition.h>
|
#include <QskBox.h>
|
||||||
|
#include <QskFocusIndicator.h>
|
||||||
|
#include <QskLinearBox.h>
|
||||||
|
#include <QskObjectCounter.h>
|
||||||
|
#include <QskSegmentedBar.h>
|
||||||
#include <QskSetup.h>
|
#include <QskSetup.h>
|
||||||
#include <QskSkin.h>
|
#include <QskSkin.h>
|
||||||
#include <QskSegmentedBar.h>
|
#include <QskSkinManager.h>
|
||||||
|
#include <QskSkinTransition.h>
|
||||||
#include <QskSlider.h>
|
#include <QskSlider.h>
|
||||||
#include <QskTextLabel.h>
|
#include <QskTextLabel.h>
|
||||||
|
#include <QskWindow.h>
|
||||||
|
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
|
||||||
|
@ -35,47 +35,85 @@ int main( int argc, char* argv[] )
|
||||||
|
|
||||||
SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts );
|
SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts );
|
||||||
|
|
||||||
qskSkinManager->setPluginPaths(
|
qskSkinManager->setPluginPaths( { R"(C:\repositories\qskinny_rveh-install-win\plugins)" } );
|
||||||
{ R"(C:\repositories\qskinny_rveh-install-win\plugins)" } );
|
|
||||||
qskSetup->setItemUpdateFlag( QskQuickItem::PreferRasterForTextures, true );
|
qskSetup->setItemUpdateFlag( QskQuickItem::PreferRasterForTextures, true );
|
||||||
|
|
||||||
QskWindow window;
|
QskWindow window;
|
||||||
window.resize( 800, 600 );
|
window.resize( 800, 600 );
|
||||||
|
|
||||||
auto* const layout = new QskLinearBox(Qt::Horizontal, window.contentItem() );
|
auto* const layout = new QskLinearBox( Qt::Horizontal, window.contentItem() );
|
||||||
auto* const left = new QskLinearBox(Qt::Vertical, layout);
|
auto* const left = new QskLinearBox( Qt::Vertical, layout );
|
||||||
auto* const right = new QskLinearBox(Qt::Vertical, layout);
|
auto* const right = new QskLinearBox( Qt::Vertical, layout );
|
||||||
auto* const control = new RadialTickmarks( left );
|
auto* const control = new RadialTickmarks( left );
|
||||||
auto* const skinlet = new RadialTickmarksSkinlet;
|
auto* const skinlet = new RadialTickmarksSkinlet;
|
||||||
{
|
{
|
||||||
(void) new QskTextLabel("Tickmark Alignment", right);
|
( void ) new QskTextLabel( "Tickmark Alignment", right );
|
||||||
auto* const alignment = new QskSegmentedBar(right);
|
auto* const alignment = new QskSegmentedBar( right );
|
||||||
alignment->setOptions( { "Center", "Bottom", "Top" } );
|
alignment->setOptions( { "Center", "Bottom", "Top" } );
|
||||||
QObject::connect(alignment, &QskSegmentedBar::selectedIndexChanged, control, [=](const int i){
|
QObject::connect(
|
||||||
|
alignment, &QskSegmentedBar::selectedIndexChanged, control, [ = ]( const int i ) {
|
||||||
static const Qt::Alignment a[ 3 ]{ Qt::AlignVCenter, Qt::AlignBottom,
|
static const Qt::Alignment a[ 3 ]{ Qt::AlignVCenter, Qt::AlignBottom,
|
||||||
Qt::AlignTop };
|
Qt::AlignTop };
|
||||||
control->setAlignmentHint(RadialTickmarks::Lines, a[i]);
|
control->setAlignmentHint( RadialTickmarks::Lines, a[ i ] );
|
||||||
});
|
} );
|
||||||
|
alignment->setSelectedIndex(0);
|
||||||
|
|
||||||
(void) new QskTextLabel("Tickmark Size", right);
|
( void ) new QskTextLabel( "Tickmark Size W / H", right );
|
||||||
auto* const sliderW = new QskSlider(right);
|
auto* const sliderW = new QskSlider( right );
|
||||||
auto* const sliderH = new QskSlider(right);
|
auto* const sliderH = new QskSlider( right );
|
||||||
|
|
||||||
sliderW->setMinimum(1.0);
|
sliderW->setMinimum( 1.0 );
|
||||||
sliderW->setMaximum(4.0);
|
sliderW->setMaximum( 4.0 );
|
||||||
sliderW->setValue(1.0);
|
sliderW->setValue( 1.0 );
|
||||||
sliderH->setValue( 0.5 );
|
sliderH->setValue( 0.5 );
|
||||||
|
|
||||||
auto updateStrutSizeHint = [=](const qreal){
|
auto updateStrutSizeHint = [ = ]( const qreal ) {
|
||||||
const auto width = sliderW->value();
|
const auto width = sliderW->value();
|
||||||
const auto height = sliderH->value() * control->height();
|
const auto height = sliderH->value() * qMin(control->height(), control->width()) / 2;
|
||||||
control->setStrutSizeHint(RadialTickmarks::Lines, width, height );
|
control->setStrutSizeHint( RadialTickmarks::Lines, width, height );
|
||||||
};
|
};
|
||||||
|
|
||||||
QObject::connect( sliderW, &QskSlider::valueChanged, control, updateStrutSizeHint );
|
QObject::connect( sliderW, &QskSlider::valueChanged, control, updateStrutSizeHint );
|
||||||
QObject::connect( sliderH, &QskSlider::valueChanged, control, updateStrutSizeHint );
|
QObject::connect( sliderH, &QskSlider::valueChanged, control, updateStrutSizeHint );
|
||||||
|
|
||||||
|
( void ) new QskTextLabel( "Tickmarks [min,max]", right );
|
||||||
|
|
||||||
|
auto* const tickmarksMin = new QskSlider( right );
|
||||||
|
tickmarksMin->setMinimum( 0 );
|
||||||
|
tickmarksMin->setMaximum( 360 );
|
||||||
|
|
||||||
|
auto* const tickmarksMax = new QskSlider( right );
|
||||||
|
tickmarksMax->setMinimum( 0 );
|
||||||
|
tickmarksMax->setMaximum( 360 );
|
||||||
|
|
||||||
|
auto updateTickmark = [ control, tickmarksMin, tickmarksMax ]( const qreal v ) {
|
||||||
|
QskScaleTickmarks tickmarks;
|
||||||
|
QVector< qreal > major, medium, minor;
|
||||||
|
|
||||||
|
for ( int deg = tickmarksMin->value(); deg < tickmarksMax->value(); deg += 1 )
|
||||||
|
{
|
||||||
|
if ( deg % 10 == 0 )
|
||||||
|
major << deg;
|
||||||
|
else if ( deg % 5 == 0 )
|
||||||
|
medium << deg;
|
||||||
|
else
|
||||||
|
minor << deg;
|
||||||
|
}
|
||||||
|
|
||||||
|
tickmarks.setMajorTicks( major );
|
||||||
|
tickmarks.setMediumTicks( medium );
|
||||||
|
tickmarks.setMinorTicks( minor );
|
||||||
|
control->setTickmarks( tickmarks );
|
||||||
|
};
|
||||||
|
|
||||||
|
QObject::connect( tickmarksMin, &QskSlider::valueChanged, control, updateTickmark );
|
||||||
|
QObject::connect( tickmarksMax, &QskSlider::valueChanged, control, updateTickmark );
|
||||||
|
|
||||||
|
tickmarksMin->setValue( 0 );
|
||||||
|
tickmarksMax->setValue( 270 );
|
||||||
|
|
||||||
}
|
}
|
||||||
control->setSkinlet(skinlet);
|
control->setSkinlet( skinlet );
|
||||||
skinlet->setOwnedBySkinnable( true );
|
skinlet->setOwnedBySkinnable( true );
|
||||||
|
|
||||||
window.show();
|
window.show();
|
||||||
|
|
Loading…
Reference in New Issue