Example #1
1
HelpWindow::HelpWindow( QWidget * parent ) :
	QWidget( parent )
{
	setWindowTitle( tr("Help") );
	setWindowOpacity( 0.8 );

	QBoxLayout * layout = new QBoxLayout( QBoxLayout::TopToBottom, this );
	layout->addWidget( new QLabel("Controls:\n\nW: Walk forward\nS: Walk backward\nA: Walk left\nD: Walk right\n\nMouse: View\nLeft Mouse: Fire") );
	layout->addSpacerItem( new QSpacerItem( 50, 1, QSizePolicy::Expanding, QSizePolicy::Expanding ) );
	setLayout( layout );
}
void tst_QBoxLayout::insertSpacerItem()
{
    QWidget *window = new QWidget;

    QSpacerItem *spacer1 = new QSpacerItem(20, 10, QSizePolicy::Expanding, QSizePolicy::Expanding);
    QSpacerItem *spacer2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Expanding);

    QBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(new QLineEdit("Foooooooooooooooooooooooooo"));
    layout->addSpacerItem(spacer1);
    layout->addWidget(new QLineEdit("Baaaaaaaaaaaaaaaaaaaaaaaaar"));
    layout->insertSpacerItem(0, spacer2);
    window->setLayout(layout);

    QVERIFY(layout->itemAt(0) == spacer2);
    QVERIFY(layout->itemAt(2) == spacer1);

    window->show();
}
Example #3
0
ShaderEdit::ShaderEdit( QWidget *parent, Parameter *p ) : ParameterWidget( parent, p ), progress( NULL )
{
	box = new QBoxLayout( QBoxLayout::TopToBottom );
	box->setContentsMargins( 0, 0, 0, 0 );
	
	QBoxLayout *allLayout = new QBoxLayout( QBoxLayout::TopToBottom );
	
	QBoxLayout *localLayout = new QBoxLayout( QBoxLayout::LeftToRight );
	localComboLabel = new QLabel( tr("Available effects:") );
	widgets.append( localComboLabel );
	localLayout->addWidget( localComboLabel );
	localShadersCombo = new QComboBox();
	widgets.append( localShadersCombo );
	localLayout->addWidget( localShadersCombo );
	localLayout->addSpacerItem( new QSpacerItem( 10, 1 ) );
	editCheckBox = new QCheckBox( tr("Edit...") );
	widgets.append( editCheckBox );
	localLayout->addWidget( editCheckBox );
	localLayout->setStretch( 0, 1 );
	localLayout->setStretch( 1, 1 );
	localLayout->setStretch( 2, 2 );
	allLayout->addLayout( localLayout );
	
	editor = new QPlainTextEdit();
	//QFont font = QFontDatabase::systemFont( QFontDatabase::FixedFont );
	QFont font( "Sans" );
	//font.setPointSize( 12 );
	editor->setFont( font );
	editor->setStyleSheet( "QPlainTextEdit{ background-color:#FFFEC7; color:black; }" );
	editor->setTabStopWidth( QFontMetrics( font ).averageCharWidth() * 2 );
	highlighter = new Highlighter( editor->document() );
	widgets.append( editor );
	allLayout->addWidget( editor );
	editor->hide();
	
	QBoxLayout *applyLayout = new QBoxLayout( QBoxLayout::LeftToRight );
	applyBtn = new QPushButton( tr("Apply") );
	applyBtn->hide();
	widgets.append( applyBtn );
	helpBtn = new QPushButton( tr("Help") );
	helpBtn->hide();
	widgets.append( helpBtn );
	applyLayout->addWidget( applyBtn );
	applyLayout->insertStretch( 1, 1 );
	applyLayout->addWidget( helpBtn );
	allLayout->addLayout( applyLayout );
	
	localShadersGroup = new QGroupBox();
	localShadersGroup->setLayout( allLayout );
	
	box->addWidget( localShadersGroup );

	editor->setPlainText( p->value.toString() );
	applyBtn->setEnabled( false );

	QStringList list = ShaderCollection::getGlobalInstance()->localShadersNames();
	foreach( const QString & s, list )
		localShadersCombo->addItem( s );

	QString shaderName = Parameter::getShaderName( p->value.toString() );
	for ( int i = 0; i < localShadersCombo->count(); ++i ) {
		if ( localShadersCombo->itemText( i ) == shaderName ) {
			localShadersCombo->setCurrentIndex( i );
			break;
		}
	}	
	
	connect( editor, SIGNAL(textChanged()), this, SLOT(textChanged()) );
	connect( editor, SIGNAL(cursorPositionChanged()), this, SLOT(cursorPositionChanged()) );
	connect( applyBtn, SIGNAL(clicked()), this, SLOT(applyClicked()) );
	connect( helpBtn, SIGNAL(clicked()), this, SLOT(helpClicked()) );
	connect( editCheckBox, SIGNAL(stateChanged(int)), this, SLOT(showEditor(int)) );
	connect( localShadersCombo, SIGNAL(activated(const QString&)), this, SLOT(localShaderChanged(const QString&)) );
}
Example #4
0
void QBoxLayoutProto::addSpacerItem(QSpacerItem *spacerItem)
{
  QBoxLayout *item = qscriptvalue_cast<QBoxLayout*>(thisObject());
  if (item)
    item->addSpacerItem(spacerItem);
}