Exemple #1
0
void TabWidget::paintEvent( QPaintEvent * pe )
{
	QPainter p( this );
	p.setFont( pointSize<7>( font() ) );

	// Draw background
	QBrush bg_color = p.background();
	p.fillRect( 0, 0, width() - 1, height() - 1, bg_color );

	// Draw external borders
	p.setPen( tabBorder() );
	p.drawRect( 0, 0, width() - 1, height() - 1 );

	// Draw tabs' bar background
	p.fillRect( 1, 1, width() - 2, m_tabheight + 2, tabBackground() );

	// Draw title, if any
	if( ! m_caption.isEmpty() )
	{
		p.setFont( pointSize<8>( p.font() ) );
		p.setPen( tabTitleText() );
		p.drawText( 5, 11, m_caption );
	}

	// Calculate the tabs' x (tabs are painted next to the caption)
	int tab_x_offset = m_caption.isEmpty() ? 4 : 14 + fontMetrics().width( m_caption );

	// Compute tabs' width depending on the number of tabs (only applicable for artwork tabs)
	widgetStack::iterator first = m_widgets.begin();
	widgetStack::iterator last = m_widgets.end();
	int tab_width = width();
	if ( first != last )
	{
		tab_width = ( width() - tab_x_offset ) / std::distance( first, last );
	}

	// Draw all tabs
	p.setPen( tabText() );
	for( widgetStack::iterator it = first ; it != last ; ++it )
	{
		// Draw a text tab or a artwork tab.
		if( m_usePixmap )
		{
			// Fixes tab's width, because original size is only correct for text tabs
			( *it ).nwidth = tab_width;

			// Get artwork
			QPixmap artwork( embed::getIconPixmap( ( *it ).pixmap ) );

			// Highlight active tab
			if( it.key() == m_activeTab )
			{
				p.fillRect( tab_x_offset, 0, ( *it ).nwidth, m_tabbarHeight - 1, tabSelected() );
			}

			// Draw artwork
			p.drawPixmap(tab_x_offset + ( ( *it ).nwidth - artwork.width() ) / 2, 1, artwork );
		}
		else
		{
			// Highlight tab when active
			if( it.key() == m_activeTab )
			{
				p.fillRect( tab_x_offset, 2, ( *it ).nwidth - 6, m_tabbarHeight - 4, tabSelected() );
			}

			// Draw text
			p.drawText( tab_x_offset + 3, m_tabheight + 1, ( *it ).name );
		}

		// Next tab's horizontal position
		tab_x_offset += ( *it ).nwidth;
	}
}
//==============================================================================
InitComponent::InitComponent ()
    : tabbedComponent (0),
      finishButton (0),
	  deviceSelector(0)
{
    addAndMakeVisible (tabbedComponent = new TabbedComponent (TabbedButtonBar::TabsAtTop));
    tabbedComponent->setTabBarDepth (30);
	Colour tabBackground( Colours::aliceblue );

    addAndMakeVisible (finishButton = new TextButton (L"finish button"));
    finishButton->setButtonText (L"Finish");
    finishButton->addListener (this);
	
	deviceManager.initialise (2, 2, 0, true, String::empty, 0);
	
	
	/* Create the app data directory if required */
	File tmpDirFile( File::getSpecialLocation( File::userApplicationDataDirectory ).getFullPathName() + File::separatorString + L"mcha" );
	if ( !tmpDirFile.isDirectory() )
	{
		if ( !tmpDirFile.createDirectory() )
		{
			AlertWindow::showMessageBox( AlertWindow::WarningIcon, L"Error", L"Unable to create directory:\t" + tmpDirFile.getFullPathName(), L"OK", this);
			JUCEApplication::getInstance()->quit();
		}
	}

	File xmlFile = tmpDirFile.getChildFile(L"defaultsettings.xml");
	
	settingsFileName =	xmlFile.getFullPathName();

	if ( xmlFile.existsAsFile() )
	{	
		bool res = audioDeviceSettings.setXmlSettingsFile(settingsFileName);

		if (!res)
		{	
			AlertWindow::showMessageBox( AlertWindow::WarningIcon, L"Warning", audioDeviceSettings.getErrorString(), L"OK", this);
		}
	
	}
	else
	{
		String errorMsg( L"Unable to find settings file:\t");
		errorMsg += settingsFileName + "\n\nThe file will be created.";
		AlertWindow::showMessageBox( AlertWindow::InfoIcon, L"Warning", errorMsg, L"OK", this);
	}

	
	/* Initialise the device configuration tab */
	deviceManager.initialise (	MAXNUMBEROFDEVICECHANNELS,	/* number of input channels */
								MAXNUMBEROFDEVICECHANNELS,	/* number of output channels */
								audioDeviceSettings.getXmlDeviceSettings(),
								false				/* select default device on failure */ );

	deviceSelector = new AudioDeviceSelectorComponent (deviceManager, 0, 2, 0, 2, false, false, false, false);
    tabbedComponent->addTab (L"Audio Device Setup",tabBackground, deviceSelector, true);
    
	/* initialise subjects and stimuli configuration tab */
	mchaSettingsComponent = new MchaSettingsComponent();

	tabbedComponent->addTab (L"MCHA Settings", tabBackground, mchaSettingsComponent, true);
	tabbedComponent->setCurrentTabIndex (0);
    
//    setSize (800, 580);
    setSize (800, 550);
}