PageRenderTime 68ms CodeModel.GetById 52ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

/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
 22#include <iostream>
 23using namespace std;
 24
 25#include <QAction>
 26#include <QGridLayout>
 27#include <QLCDNumber>
 28
 29EWIListWidget::EWIListWidget( QWidget *parent )
 30	: QWidget( parent )
 31{
 32	/* The body of EWI_tab will be a grid of 10(col/2)s x 20rows containing patch
 33	numbers and names */ 
 34	
 35	QAction *editAct[100],
 36			*copyAct[100],
 37			*pasteAct[100],
 38			*renameAct[100];
 39	
 40	edit_signal_mapper = new QSignalMapper( this );
 41	copy_signal_mapper = new QSignalMapper( this );
 42	paste_signal_mapper = new QSignalMapper( this );
 43	rename_signal_mapper = new QSignalMapper( this );
 44			
 45	QGridLayout *EWI_grid = new QGridLayout();
 46
 47	QFont font( "Helvetica", 8 );
 48	
 49	for (int col = 0; col < 10; col = col + 2 ) {
 50		for (int row = 0; row < 20; row++) {
 51			// first the LCD-style patch number (displayed as real number + 1)
 52			QLCDNumber *EWI_patch_num = new QLCDNumber( 3 );
 53			EWI_patch_num->setSegmentStyle(QLCDNumber::Filled);
 54			EWI_patch_num->display( (col/2)*20 + row + 1 );
 55			EWI_patch_num->setFrameStyle( QFrame::NoFrame );
 56			EWI_grid->addWidget( EWI_patch_num, row, (col/2)*2 );
 57            EWI_patch_num->setFixedHeight( 18 );
 58			//EWI_patch_num->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
 59			
 60			// now the name button
 61			QPushButton *name_button = new QPushButton( QString( "          <Empty " + QString().setNum( row + 20*(col/2) + 1 ) + ">          ") );
 62			//name_button->resize( 60, 10 );
 63            name_button->setFixedHeight( 22 );
 64			name_button->setFont( font );
 65			patch_button_list.append( name_button );
 66			name_button->setCheckable( false );		// makes it a 'toggle' button
 67			//name_button->setContextMenuPolicy( Qt::ActionsContextMenu );
 68			
 69			// the context menu
 70			editAct[row + 20*(col/2)] = new QAction( tr( "&Edit" ), this );
 71			copyAct[row + 20*(col/2)] = new QAction( tr( "&Copy" ), this );
 72			pasteAct[row + 20*(col/2)] = new QAction( tr( "&Paste" ), this );
 73			renameAct[row + 20*(col/2)] = new QAction( tr( "&Rename" ), this );
 74			
 75			name_button->addAction( editAct[row + 20*(col/2)] );
 76			name_button->addAction( copyAct[row + 20*(col/2)] );
 77			name_button->addAction( pasteAct[row + 20*(col/2)] );
 78			name_button->addAction( renameAct[row + 20*(col/2)] );
 79			
 80			edit_signal_mapper->setMapping( editAct[row + 20*(col/2)], row + 20*(col/2) );
 81			connect( editAct[row + 20*(col/2)], SIGNAL( triggered() ), edit_signal_mapper, SLOT( map() ) );
 82			copy_signal_mapper->setMapping( copyAct[row + 20*(col/2)], row + 20*(col/2) );
 83			connect( copyAct[row + 20*(col/2)], SIGNAL( triggered() ), copy_signal_mapper, SLOT( map() ) );
 84			paste_signal_mapper->setMapping( pasteAct[row + 20*(col/2)], row + 20*(col/2) );
 85			connect( pasteAct[row + 20*(col/2)], SIGNAL( triggered() ), paste_signal_mapper, SLOT( map() ) );
 86			rename_signal_mapper->setMapping( renameAct[row + 20*(col/2)], row + 20*(col/2) );
 87			connect( renameAct[row + 20*(col/2)], SIGNAL( triggered() ), rename_signal_mapper, SLOT( map() ) );
 88			
 89			EWI_grid->addWidget( name_button, row, ((col/2)*2)+1 );
 90			// disable the context menu (until button is populated with a meaningful value via setLabel() )
 91			//name_button->setContextMenuPolicy( Qt::NoContextMenu );
 92			//name_button->setAcceptDrops( true );
 93		}
 94	}
 95	
 96	connect( edit_signal_mapper, SIGNAL( mapped( int ) ), this, SIGNAL( edit_signal( int ) ) );
 97	connect( copy_signal_mapper, SIGNAL( mapped( int ) ), this, SIGNAL( copy_signal( int ) ) );
 98	connect( paste_signal_mapper, SIGNAL( mapped( int ) ), this, SIGNAL( paste_signal( int ) ) );
 99	connect( rename_signal_mapper, SIGNAL( mapped( int ) ), this, SIGNAL( rename_signal( int ) ) );
100	
101	setLayout( EWI_grid );
102}
103
104
105EWIListWidget::~EWIListWidget()
106{
107}
108
109void EWIListWidget::setLabel( int patch_num, QString patch_name) {
110	patch_button_list.at( patch_num )->setText( patch_name );
111	patch_button_list.at( patch_num )->setContextMenuPolicy( Qt::ActionsContextMenu );
112}
113
114QString EWIListWidget::getLabel( int patch_num ) {
115	return patch_button_list.at( patch_num )->text();
116}