/ewilistwidget.cpp

http://ewitool.googlecode.com/ · C++ · 116 lines · 67 code · 19 blank · 30 comment · 2 complexity · f3050372d36cd65be5dd2f9a11d523b3 MD5 · raw file

  1. /***************************************************************************
  2. * Copyright (C) 2008 by Steve Merrony *
  3. * steve@brahma *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 3 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #include "ewilistwidget.h"
  21. #include <iostream>
  22. using namespace std;
  23. #include <QAction>
  24. #include <QGridLayout>
  25. #include <QLCDNumber>
  26. EWIListWidget::EWIListWidget( QWidget *parent )
  27. : QWidget( parent )
  28. {
  29. /* The body of EWI_tab will be a grid of 10(col/2)s x 20rows containing patch
  30. numbers and names */
  31. QAction *editAct[100],
  32. *copyAct[100],
  33. *pasteAct[100],
  34. *renameAct[100];
  35. edit_signal_mapper = new QSignalMapper( this );
  36. copy_signal_mapper = new QSignalMapper( this );
  37. paste_signal_mapper = new QSignalMapper( this );
  38. rename_signal_mapper = new QSignalMapper( this );
  39. QGridLayout *EWI_grid = new QGridLayout();
  40. QFont font( "Helvetica", 8 );
  41. for (int col = 0; col < 10; col = col + 2 ) {
  42. for (int row = 0; row < 20; row++) {
  43. // first the LCD-style patch number (displayed as real number + 1)
  44. QLCDNumber *EWI_patch_num = new QLCDNumber( 3 );
  45. EWI_patch_num->setSegmentStyle(QLCDNumber::Filled);
  46. EWI_patch_num->display( (col/2)*20 + row + 1 );
  47. EWI_patch_num->setFrameStyle( QFrame::NoFrame );
  48. EWI_grid->addWidget( EWI_patch_num, row, (col/2)*2 );
  49. EWI_patch_num->setFixedHeight( 18 );
  50. //EWI_patch_num->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
  51. // now the name button
  52. QPushButton *name_button = new QPushButton( QString( " <Empty " + QString().setNum( row + 20*(col/2) + 1 ) + "> ") );
  53. //name_button->resize( 60, 10 );
  54. name_button->setFixedHeight( 22 );
  55. name_button->setFont( font );
  56. patch_button_list.append( name_button );
  57. name_button->setCheckable( false ); // makes it a 'toggle' button
  58. //name_button->setContextMenuPolicy( Qt::ActionsContextMenu );
  59. // the context menu
  60. editAct[row + 20*(col/2)] = new QAction( tr( "&Edit" ), this );
  61. copyAct[row + 20*(col/2)] = new QAction( tr( "&Copy" ), this );
  62. pasteAct[row + 20*(col/2)] = new QAction( tr( "&Paste" ), this );
  63. renameAct[row + 20*(col/2)] = new QAction( tr( "&Rename" ), this );
  64. name_button->addAction( editAct[row + 20*(col/2)] );
  65. name_button->addAction( copyAct[row + 20*(col/2)] );
  66. name_button->addAction( pasteAct[row + 20*(col/2)] );
  67. name_button->addAction( renameAct[row + 20*(col/2)] );
  68. edit_signal_mapper->setMapping( editAct[row + 20*(col/2)], row + 20*(col/2) );
  69. connect( editAct[row + 20*(col/2)], SIGNAL( triggered() ), edit_signal_mapper, SLOT( map() ) );
  70. copy_signal_mapper->setMapping( copyAct[row + 20*(col/2)], row + 20*(col/2) );
  71. connect( copyAct[row + 20*(col/2)], SIGNAL( triggered() ), copy_signal_mapper, SLOT( map() ) );
  72. paste_signal_mapper->setMapping( pasteAct[row + 20*(col/2)], row + 20*(col/2) );
  73. connect( pasteAct[row + 20*(col/2)], SIGNAL( triggered() ), paste_signal_mapper, SLOT( map() ) );
  74. rename_signal_mapper->setMapping( renameAct[row + 20*(col/2)], row + 20*(col/2) );
  75. connect( renameAct[row + 20*(col/2)], SIGNAL( triggered() ), rename_signal_mapper, SLOT( map() ) );
  76. EWI_grid->addWidget( name_button, row, ((col/2)*2)+1 );
  77. // disable the context menu (until button is populated with a meaningful value via setLabel() )
  78. //name_button->setContextMenuPolicy( Qt::NoContextMenu );
  79. //name_button->setAcceptDrops( true );
  80. }
  81. }
  82. connect( edit_signal_mapper, SIGNAL( mapped( int ) ), this, SIGNAL( edit_signal( int ) ) );
  83. connect( copy_signal_mapper, SIGNAL( mapped( int ) ), this, SIGNAL( copy_signal( int ) ) );
  84. connect( paste_signal_mapper, SIGNAL( mapped( int ) ), this, SIGNAL( paste_signal( int ) ) );
  85. connect( rename_signal_mapper, SIGNAL( mapped( int ) ), this, SIGNAL( rename_signal( int ) ) );
  86. setLayout( EWI_grid );
  87. }
  88. EWIListWidget::~EWIListWidget()
  89. {
  90. }
  91. void EWIListWidget::setLabel( int patch_num, QString patch_name) {
  92. patch_button_list.at( patch_num )->setText( patch_name );
  93. patch_button_list.at( patch_num )->setContextMenuPolicy( Qt::ActionsContextMenu );
  94. }
  95. QString EWIListWidget::getLabel( int patch_num ) {
  96. return patch_button_list.at( patch_num )->text();
  97. }