first re-commit.
This commit is contained in:
126
swbuttongroup.cpp
Normal file
126
swbuttongroup.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
#include <swbuttongroup.h>
|
||||
|
||||
#include <raDIYoglobals.h>
|
||||
#include <swradiobutton.h>
|
||||
|
||||
#include <QAbstractButton>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
|
||||
SWDialButtonGroup::SWDialButtonGroup(QObject *parent)
|
||||
: QButtonGroup{parent}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SWDialButtonGroup::addKeyButton( SWRadioButton* button, int id, const QString& key )
|
||||
{
|
||||
button->setKey( key );
|
||||
QButtonGroup::addButton( button, id );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Gibt den Button mit gegebenen ID zurück
|
||||
*/
|
||||
|
||||
SWRadioButton& SWDialButtonGroup::buttonAt( int id )
|
||||
{
|
||||
// Du HONK! Das ist der Index, _nicht_ die ID
|
||||
//return *( dynamic_cast<SWDialButton*>( buttons().at( id ) ) );
|
||||
return *( dynamic_cast<SWRadioButton*>( button( id ) ) );
|
||||
|
||||
}
|
||||
|
||||
void SWDialButtonGroup::setCurrentActiveId( int newID )
|
||||
{
|
||||
// schon Ok, dass darf vorkommen
|
||||
//Q_ASSERT( newID >= 0 );
|
||||
//Q_ASSERT( newID < buttons().size() );
|
||||
if( newID >= 0 && newID < buttons().size() )
|
||||
{
|
||||
// unhover & uncheck current button
|
||||
if( _hoverdID > -1 )
|
||||
buttonAt( _hoverdID ).unHover();
|
||||
_checkedID = _hoverdID = newID;
|
||||
buttonAt(_checkedID ).setChecked( true );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 'Klick' von aussen, kommt von den RotaryDials.
|
||||
* Wird 'umgewandelt' in SIGNAL 'idClicked'
|
||||
*/
|
||||
|
||||
void SWDialButtonGroup::onDialPushed()
|
||||
{
|
||||
|
||||
Q_ASSERT( _hoverdID >= 0 );
|
||||
Q_ASSERT( _hoverdID < buttons().size() );
|
||||
|
||||
emit idClicked( _hoverdID );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param delta
|
||||
* Schiebt den 'Hover'-Anzeigestatus zum nächsten Button innerhalb der Buttongroup.
|
||||
* @param forward Vorwärts, also auf dem Bildschirm nach rechts oder eben nach links.
|
||||
*
|
||||
* Das ist ein Hack: Ich möchte einem einzelnen Button den Focus, also hier den Hover-Zustand
|
||||
* aus dem Programm heraus zuweisen. Das wird für die Steuerung per RotaryDial gebraucht.
|
||||
* Experimente ::notify( QHoverEvent( QHoverEnter ... ) waren erstmal ohne Wirkung.
|
||||
* Derzeit wird einfach ein ge-hovertes (helleres) Icon gesetzt.
|
||||
*/
|
||||
|
||||
void SWDialButtonGroup::onDialDeltaChanged( int delta )
|
||||
{
|
||||
|
||||
int listSize = buttons().size();
|
||||
if( !listSize )
|
||||
return;
|
||||
|
||||
// hatten wir schon einen button ge-hovert?
|
||||
if( _hoverdID > -1 )
|
||||
buttonAt( _hoverdID ).unHover();
|
||||
|
||||
// wir sucne den nächsten Button zum Hovern, einen,
|
||||
// der nicht 'gecheckt' oder 'unsichtbar' ist.
|
||||
//SWRadioButton* tmpBtn = nullptr;
|
||||
QAbstractButton* tmpBtn = nullptr;
|
||||
|
||||
do
|
||||
{
|
||||
_hoverdID = ( _hoverdID + delta ) % listSize;
|
||||
if( _hoverdID < 0 )
|
||||
_hoverdID = listSize - 1;
|
||||
|
||||
//tmpBtn = buttons().at( _hoverdID );
|
||||
tmpBtn = button( _hoverdID );
|
||||
}
|
||||
while( !tmpBtn->isEnabled()|| tmpBtn->isChecked() || !tmpBtn->isVisible() );
|
||||
//while( !tmpBtn->isVisible() );
|
||||
|
||||
buttonAt( _hoverdID ).hover();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user