Files
raDIYo/swdialcontrol.cpp
2025-08-05 22:36:00 +02:00

108 lines
2.7 KiB
C++

/***************************************************************************
source::worx raDIYo
Copyright © 2020-2022 c.holzheuer
chris@sourceworx.org
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
***************************************************************************/
#include <swdialcontrol.h>
SWDialControl::SWDialControl( QWidget* parent, QSettings* settings )
: SWBaseControl( parent, settings )
{
}
/**
* @brief Sammelt alle Kindwidgets, die den Aspekt 'SWDialWidget' implementieren.
* Wird im Konstruktor aufgerufen.
* @see SWDialWidget
*/
void SWDialControl::collectDialWidgets()
{
// speichert die Dialwidgets sortiert nach ihrem AccessibleName
// über den namen wird eine 'KlickOrder' im Sinne einer TabOrder simuliert
QMap<QString, SWDialWidget*> tmpMap;
QList<QWidget*> widgets = findChildren<QWidget*>();
for( QWidget* entry : widgets )
{
SWDialWidget* dialWdgt = dynamic_cast<SWDialWidget*>( entry );
if( nullptr != dialWdgt )
{
tmpMap.insert( entry->accessibleName(), dialWdgt );
_crntIdx = 0;
}
}
// die nach namen sortierten DialWidgets unter beibehaltung der Reihenfolge
// ins _dialWidgets Array übernehmen
for( SWDialWidget* dialWdgt : tmpMap )
_dialWidgets.append( dialWdgt );
}
/**
* @brief Gibt das aktuell aktive DialWidget zurück
*/
SWDialWidget& SWDialControl::current()
{
Q_ASSERT( _crntIdx > -1 && _crntIdx < _dialWidgets.size() );
return *_dialWidgets[ _crntIdx ];
}
/**
* @brief Wird beim Drücken des RotaryDials aufgerufen.
* Das Signal wir an das aktuell aktive Control
* weitergereicht.
*/
void SWDialControl::onDialPushed()
{
if( current().acceptDial() )
current().toggleDialInput();
onWidgetClicked( &current() );
update();
}
/**
* @brief Wird beim Drehen des RotaryDials aufgerufen.
* @param value die Winkelstellung, also der Zahlenwert, des RotaryDials.
* Wird an das aktuell aktive Dial weitergereicht.
*/
void SWDialControl::onDialDeltaChanged( int delta )
{
// weiterreichen falls erwünscht...
if( current().hasDialInput() )
return current().onDialDeltaChanged( delta );
// ...sonst zum nächtsten Handler 'weiterdrehen'
current().setHightlighted( false );
_crntIdx = ( _crntIdx + delta ) % _dialWidgets.size();
if( _crntIdx < 0 )
_crntIdx = _dialWidgets.size() - 1;
current().setHightlighted( true );
update();
}