raDIYo 0.4
swbuttongroup.cpp
1/***************************************************************************
2
3 source::worx raDIYo
4 Copyright © 2020-2022 c.holzheuer
5 c.holzheuer@sourceworx.org
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12***************************************************************************/
13
14
15#include <swbuttongroup.h>
16#include <QAbstractButton>
17#include <QDebug>
18
19SWButtonGroup::SWButtonGroup( QWidget* parent )
20 : QButtonGroup( parent )
21{
22 //setExclusive( false );
23 connect( this, SIGNAL( buttonClicked(QAbstractButton*) ), this, SLOT( onButtonClicked(QAbstractButton*) ) );
24}
25
26
27SWButtonGroup::~SWButtonGroup()
28{
29
30}
31
32void SWButtonGroup::addKeyButton( QPushButton* button, int ID, const QString& key )
33{
34 _buttonKeys[ ID ] = key;
35 addButton( button, ID );
36}
37
38
39void SWButtonGroup::onButtonClicked( QAbstractButton* button )
40{
41
42 qDebug() << "group: on button clicked: " << id( button );
43 //emit idClicked( id( button ) );
44 emit idSelected( id( button ) ); // workaround
45}
46
47
53{
54 //emit buttonClicked(QAbstractButton *button)
55 //idClicked(int id);
56}
57
58
65{
66
67 qDebug() << "SWButtonGroup::onDialValueChanged: FIXME!" << value;
68
69
70 QList<QAbstractButton*> buttList = buttons();
71 int listSize = buttList.size();
72
73 int newID = value % listSize;
74 // nix passiert?
75 if( _curID == newID )
76 return;
77
78 //_itemList->setCurrentRow( _idx, QItemSelectionModel::ClearAndSelect );
79
80
81 /*
82 // QUARK!
83 int diff = qAbs( value - _value );
84 if( diff < 10 )
85 return;
86
87 bool directionForward = value > _value;
88 _value = value;
89 shiftHover( directionForward );
90 */
91
92}
93
94
104void SWButtonGroup::shiftHover( bool forward )
105{
106 QList<QAbstractButton*> buttList = buttons();
107 int listSize = buttList.size();
108
109 unHover( _curID );
110
111 int nxtHover = _curID - 1;
112 if( forward )
113 {
114 nxtHover = ( _curID + 1 ) % listSize;
115 }
116 else if( nxtHover < 0 )
117 {
118 nxtHover = listSize - 1;
119 }
120 QAbstractButton* butt = buttList.at( nxtHover );
121 //_lstStyleSheet = butt->styleSheet();
122 //QString newStyle( "background-image: url( ':/images/radiyo.%1.hover.png' );" );
123 QString newStyle( ":/images/radiyo.%1.hover.png" );
124 QString key = _buttonKeys[ id( butt ) ];
125 //butt->setStyleSheet( newStyle.arg( key ) );
126
127 butt->setIcon( QIcon( newStyle.arg( key ) ) );
128
129 qDebug() << key << ": " << newStyle.arg( key ) ;
130
131 //QString().arg( nxtHover ) nxtHover
132 _curID = nxtHover;
133
134
135
136}
137
138
145void SWButtonGroup::unHover( int buttonID )
146{
147 // hatten wir schon einen butten gehovert?
148 // dann ebendiesen restaurieren
149
150 if( buttonID > -1 && buttonID < buttons().size() )
151 {
152 //buttons().at( _curID )->setStyleSheet( _lstStyleSheet );
153 buttons().at( buttonID )->setIcon( QIcon() );
154 }
155}
156
157/*
158void SWButtonGroup::addToggleButton( SWToggleButton* button, int id, const QString& name )
159{
160
161 QButtonGroup::addButton( button, id );
162 button->setIconName( name );
163
164}
165*/
166
167
168
169
void onDialValueChanged(int value)
von aussen
void idSelected(int newID)
Das ist identisch zu idClicked, das gibts aber im 'alten' Qt5 auf dem RasPI nicht.
void onDialClicked()
von aussen
void unHover(int buttonID)
Button 'ent-hovern', also das Hover-Icon entfernen.
void shiftHover(bool forward)
Schiebt den 'Hover'-Anzeigestatus zum nächsten Button innerhalb der Buttongroup.