nine_button_selector.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * nine_button_selector.cpp
  3. *
  4. * Copyright (c) 2006-2007 Danny McRae <khjklujn/at/yahoo/com>
  5. * Copyright (c) 2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  6. *
  7. * This file is part of LMMS - https://lmms.io
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public
  20. * License along with this program (see COPYING); if not, write to the
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301 USA.
  23. *
  24. */
  25. #include "nine_button_selector.h"
  26. #include "CaptionMenu.h"
  27. #include "embed.h"
  28. nineButtonSelector::nineButtonSelector( QPixmap _button0_on,
  29. QPixmap _button0_off,
  30. QPixmap _button1_on,
  31. QPixmap _button1_off,
  32. QPixmap _button2_on,
  33. QPixmap _button2_off,
  34. QPixmap _button3_on,
  35. QPixmap _button3_off,
  36. QPixmap _button4_on,
  37. QPixmap _button4_off,
  38. QPixmap _button5_on,
  39. QPixmap _button5_off,
  40. QPixmap _button6_on,
  41. QPixmap _button6_off,
  42. QPixmap _button7_on,
  43. QPixmap _button7_off,
  44. QPixmap _button8_on,
  45. QPixmap _button8_off,
  46. int _default,
  47. int _x, int _y,
  48. QWidget * _parent ):
  49. QWidget( _parent ),
  50. IntModelView( new nineButtonSelectorModel(0, 8, _default, NULL,
  51. QString(), true ), this )
  52. {
  53. setFixedSize( 50, 50 );
  54. move( _x, _y );
  55. m_button = new PixmapButton( this, NULL );
  56. m_button->move( 1, 1 );
  57. m_button->setActiveGraphic( _button0_on );
  58. m_button->setInactiveGraphic( _button0_off );
  59. m_button->setChecked( false );
  60. connect( m_button, SIGNAL ( clicked () ),
  61. this, SLOT ( button0Clicked() ) );
  62. m_buttons.append( m_button );
  63. m_button = new PixmapButton( this, NULL );
  64. m_button->move( 18, 1 );
  65. m_button->setActiveGraphic( _button1_on );
  66. m_button->setInactiveGraphic( _button1_off );
  67. m_button->setChecked( false );
  68. connect( m_button, SIGNAL ( clicked () ),
  69. this, SLOT ( button1Clicked() ) );
  70. m_buttons.append( m_button );
  71. m_button = new PixmapButton( this, NULL );
  72. m_button->move( 35, 1 );
  73. m_button->setActiveGraphic( _button2_on );
  74. m_button->setInactiveGraphic( _button2_off );
  75. m_button->setChecked( false );
  76. connect( m_button, SIGNAL ( clicked () ),
  77. this, SLOT ( button2Clicked() ) );
  78. m_buttons.append( m_button );
  79. m_button = new PixmapButton( this, NULL );
  80. m_button->move( 1, 18 );
  81. m_button->setActiveGraphic( _button3_on );
  82. m_button->setInactiveGraphic( _button3_off );
  83. m_button->setChecked( false );
  84. connect( m_button, SIGNAL ( clicked () ),
  85. this, SLOT ( button3Clicked() ) );
  86. m_buttons.append( m_button );
  87. m_button = new PixmapButton( this, NULL );
  88. m_button->move( 18, 18 );
  89. m_button->setActiveGraphic( _button4_on );
  90. m_button->setInactiveGraphic( _button4_off );
  91. m_button->setChecked( false );
  92. connect( m_button, SIGNAL ( clicked () ),
  93. this, SLOT ( button4Clicked() ) );
  94. m_buttons.append( m_button );
  95. m_button = new PixmapButton( this, NULL );
  96. m_button->move( 35, 18 );
  97. m_button->setActiveGraphic( _button5_on );
  98. m_button->setInactiveGraphic( _button5_off );
  99. m_button->setChecked( false );
  100. connect( m_button, SIGNAL ( clicked () ),
  101. this, SLOT ( button5Clicked() ) );
  102. m_buttons.append( m_button );
  103. m_button = new PixmapButton( this, NULL );
  104. m_button->move( 1, 35 );
  105. m_button->setActiveGraphic( _button6_on );
  106. m_button->setInactiveGraphic( _button6_off );
  107. m_button->setChecked( false );
  108. connect( m_button, SIGNAL ( clicked () ),
  109. this, SLOT ( button6Clicked() ) );
  110. m_buttons.append( m_button );
  111. m_button = new PixmapButton( this, NULL );
  112. m_button->move( 18, 35 );
  113. m_button->setActiveGraphic( _button7_on );
  114. m_button->setInactiveGraphic( _button7_off );
  115. m_button->setChecked( false );
  116. connect( m_button, SIGNAL ( clicked () ),
  117. this, SLOT ( button7Clicked() ) );
  118. m_buttons.append( m_button );
  119. m_button = new PixmapButton( this, NULL );
  120. m_button->move( 35, 35 );
  121. m_button->setActiveGraphic( _button8_on );
  122. m_button->setInactiveGraphic( _button8_off );
  123. m_button->setChecked( false );
  124. connect( m_button, SIGNAL ( clicked () ),
  125. this, SLOT ( button8Clicked() ) );
  126. m_buttons.append( m_button );
  127. m_lastBtn = m_buttons[_default];
  128. m_lastBtn->setChecked( true );
  129. }
  130. nineButtonSelector::~ nineButtonSelector()
  131. {
  132. for( int i = 0; i < 9; i++ )
  133. {
  134. delete m_buttons[i];
  135. }
  136. }
  137. void nineButtonSelector::button0Clicked()
  138. {
  139. setSelected( 0 );
  140. }
  141. void nineButtonSelector::button1Clicked()
  142. {
  143. setSelected( 1 );
  144. }
  145. void nineButtonSelector::button2Clicked()
  146. {
  147. setSelected( 2 );
  148. }
  149. void nineButtonSelector::button3Clicked()
  150. {
  151. setSelected( 3 );
  152. }
  153. void nineButtonSelector::button4Clicked()
  154. {
  155. setSelected( 4 );
  156. }
  157. void nineButtonSelector::button5Clicked()
  158. {
  159. setSelected( 5 );
  160. }
  161. void nineButtonSelector::button6Clicked()
  162. {
  163. setSelected( 6 );
  164. }
  165. void nineButtonSelector::button7Clicked()
  166. {
  167. setSelected( 7 );
  168. }
  169. void nineButtonSelector::button8Clicked()
  170. {
  171. setSelected( 8 );
  172. }
  173. void nineButtonSelector::modelChanged()
  174. {
  175. updateButton( model()->value() );
  176. }
  177. void nineButtonSelector::setSelected( int _new_button )
  178. {
  179. model()->setValue(_new_button);
  180. updateButton( _new_button );
  181. }
  182. void nineButtonSelector::updateButton( int _new_button )
  183. {
  184. m_lastBtn->setChecked( false );
  185. m_lastBtn->update();
  186. m_lastBtn = m_buttons[_new_button];
  187. m_lastBtn->setChecked( true );
  188. m_lastBtn->update();
  189. emit nineButtonSelection( _new_button );
  190. }
  191. void nineButtonSelector::contextMenuEvent( QContextMenuEvent * )
  192. {
  193. CaptionMenu contextMenu( windowTitle(), this );
  194. contextMenu.exec( QCursor::pos() );
  195. }