nine_button_selector.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 <QWhatsThis>
  27. #include "CaptionMenu.h"
  28. #include "embed.h"
  29. nineButtonSelector::nineButtonSelector( QPixmap _button0_on,
  30. QPixmap _button0_off,
  31. QPixmap _button1_on,
  32. QPixmap _button1_off,
  33. QPixmap _button2_on,
  34. QPixmap _button2_off,
  35. QPixmap _button3_on,
  36. QPixmap _button3_off,
  37. QPixmap _button4_on,
  38. QPixmap _button4_off,
  39. QPixmap _button5_on,
  40. QPixmap _button5_off,
  41. QPixmap _button6_on,
  42. QPixmap _button6_off,
  43. QPixmap _button7_on,
  44. QPixmap _button7_off,
  45. QPixmap _button8_on,
  46. QPixmap _button8_off,
  47. int _default,
  48. int _x, int _y,
  49. QWidget * _parent ):
  50. QWidget( _parent ),
  51. IntModelView( new nineButtonSelectorModel(0, 8, _default, NULL,
  52. QString::null, true ), this )
  53. {
  54. setFixedSize( 50, 50 );
  55. move( _x, _y );
  56. m_button = new PixmapButton( this, NULL );
  57. m_button->move( 1, 1 );
  58. m_button->setActiveGraphic( _button0_on );
  59. m_button->setInactiveGraphic( _button0_off );
  60. m_button->setChecked( false );
  61. connect( m_button, SIGNAL ( clicked () ),
  62. this, SLOT ( button0Clicked() ) );
  63. m_buttons.append( m_button );
  64. m_button = new PixmapButton( this, NULL );
  65. m_button->move( 18, 1 );
  66. m_button->setActiveGraphic( _button1_on );
  67. m_button->setInactiveGraphic( _button1_off );
  68. m_button->setChecked( false );
  69. connect( m_button, SIGNAL ( clicked () ),
  70. this, SLOT ( button1Clicked() ) );
  71. m_buttons.append( m_button );
  72. m_button = new PixmapButton( this, NULL );
  73. m_button->move( 35, 1 );
  74. m_button->setActiveGraphic( _button2_on );
  75. m_button->setInactiveGraphic( _button2_off );
  76. m_button->setChecked( false );
  77. connect( m_button, SIGNAL ( clicked () ),
  78. this, SLOT ( button2Clicked() ) );
  79. m_buttons.append( m_button );
  80. m_button = new PixmapButton( this, NULL );
  81. m_button->move( 1, 18 );
  82. m_button->setActiveGraphic( _button3_on );
  83. m_button->setInactiveGraphic( _button3_off );
  84. m_button->setChecked( false );
  85. connect( m_button, SIGNAL ( clicked () ),
  86. this, SLOT ( button3Clicked() ) );
  87. m_buttons.append( m_button );
  88. m_button = new PixmapButton( this, NULL );
  89. m_button->move( 18, 18 );
  90. m_button->setActiveGraphic( _button4_on );
  91. m_button->setInactiveGraphic( _button4_off );
  92. m_button->setChecked( false );
  93. connect( m_button, SIGNAL ( clicked () ),
  94. this, SLOT ( button4Clicked() ) );
  95. m_buttons.append( m_button );
  96. m_button = new PixmapButton( this, NULL );
  97. m_button->move( 35, 18 );
  98. m_button->setActiveGraphic( _button5_on );
  99. m_button->setInactiveGraphic( _button5_off );
  100. m_button->setChecked( false );
  101. connect( m_button, SIGNAL ( clicked () ),
  102. this, SLOT ( button5Clicked() ) );
  103. m_buttons.append( m_button );
  104. m_button = new PixmapButton( this, NULL );
  105. m_button->move( 1, 35 );
  106. m_button->setActiveGraphic( _button6_on );
  107. m_button->setInactiveGraphic( _button6_off );
  108. m_button->setChecked( false );
  109. connect( m_button, SIGNAL ( clicked () ),
  110. this, SLOT ( button6Clicked() ) );
  111. m_buttons.append( m_button );
  112. m_button = new PixmapButton( this, NULL );
  113. m_button->move( 18, 35 );
  114. m_button->setActiveGraphic( _button7_on );
  115. m_button->setInactiveGraphic( _button7_off );
  116. m_button->setChecked( false );
  117. connect( m_button, SIGNAL ( clicked () ),
  118. this, SLOT ( button7Clicked() ) );
  119. m_buttons.append( m_button );
  120. m_button = new PixmapButton( this, NULL );
  121. m_button->move( 35, 35 );
  122. m_button->setActiveGraphic( _button8_on );
  123. m_button->setInactiveGraphic( _button8_off );
  124. m_button->setChecked( false );
  125. connect( m_button, SIGNAL ( clicked () ),
  126. this, SLOT ( button8Clicked() ) );
  127. m_buttons.append( m_button );
  128. m_lastBtn = m_buttons[_default];
  129. m_lastBtn->setChecked( true );
  130. }
  131. nineButtonSelector::~ nineButtonSelector()
  132. {
  133. for( int i = 0; i < 9; i++ )
  134. {
  135. delete m_buttons[i];
  136. }
  137. }
  138. void nineButtonSelector::button0Clicked()
  139. {
  140. setSelected( 0 );
  141. }
  142. void nineButtonSelector::button1Clicked()
  143. {
  144. setSelected( 1 );
  145. }
  146. void nineButtonSelector::button2Clicked()
  147. {
  148. setSelected( 2 );
  149. }
  150. void nineButtonSelector::button3Clicked()
  151. {
  152. setSelected( 3 );
  153. }
  154. void nineButtonSelector::button4Clicked()
  155. {
  156. setSelected( 4 );
  157. }
  158. void nineButtonSelector::button5Clicked()
  159. {
  160. setSelected( 5 );
  161. }
  162. void nineButtonSelector::button6Clicked()
  163. {
  164. setSelected( 6 );
  165. }
  166. void nineButtonSelector::button7Clicked()
  167. {
  168. setSelected( 7 );
  169. }
  170. void nineButtonSelector::button8Clicked()
  171. {
  172. setSelected( 8 );
  173. }
  174. void nineButtonSelector::modelChanged()
  175. {
  176. updateButton( model()->value() );
  177. }
  178. void nineButtonSelector::setSelected( int _new_button )
  179. {
  180. model()->setValue(_new_button);
  181. updateButton( _new_button );
  182. }
  183. void nineButtonSelector::updateButton( int _new_button )
  184. {
  185. m_lastBtn->setChecked( false );
  186. m_lastBtn->update();
  187. m_lastBtn = m_buttons[_new_button];
  188. m_lastBtn->setChecked( true );
  189. m_lastBtn->update();
  190. emit nineButtonSelection( _new_button );
  191. }
  192. void nineButtonSelector::contextMenuEvent( QContextMenuEvent * )
  193. {
  194. CaptionMenu contextMenu( windowTitle(), this );
  195. contextMenu.addHelpAction();
  196. contextMenu.exec( QCursor::pos() );
  197. }
  198. void nineButtonSelector::displayHelp()
  199. {
  200. QWhatsThis::showText( mapToGlobal( rect().bottomRight() ),
  201. whatsThis() );
  202. }