コード例 #1
0
ファイル: collection-delegate.cpp プロジェクト: KDE/palapeli
Palapeli::CollectionDelegate::CollectionDelegate (QObject* parent)
        : QStyledItemDelegate(parent)
{
    QAbstractItemView* view = qobject_cast<QAbstractItemView*>(parent);
    if (view) {
        view->setItemDelegate(this);
        m_viewport = view->viewport();
    }
}
コード例 #2
0
ファイル: pFileDialog.cpp プロジェクト: hlamer/fresh
pFileDialog::pFileDialog( QWidget* parent, const QString& caption, const QString& directory, const QString& filter, bool textCodecEnabled, bool openReadOnlyEnabled )
	: QFileDialog( parent, caption, directory, filter )
{
	setFileMode( QFileDialog::AnyFile );
	setOption( QFileDialog::DontUseNativeDialog );
	
	// get grid layout
	glDialog = qobject_cast<QGridLayout*>( layout() );
	
	// assert on gridlayout
	Q_ASSERT( glDialog );
	
	// relook the dialog to be more friendly
	QLabel* lLookIn = findChild<QLabel*>( "lookInLabel" );
	QComboBox* cbLookIn = findChild<QComboBox*>( "lookInCombo" );
	QToolButton* tbNewFolder = findChild<QToolButton*>( "newFolderButton" );
	QAbstractItemView* sidebar = findChild<QAbstractItemView*>( "sidebar" );
	QFrame* fFrame = findChild<QFrame*>( "frame" );
	QBoxLayout* hLayout = 0;
	
	// search layout containing tbNewFolder
	foreach ( QLayout* layout, findChildren<QLayout*>() ) {
		if ( layout->indexOf( tbNewFolder ) != -1 ) {
			hLayout = qobject_cast<QBoxLayout*>( layout );
			break;
		}
	}
	
	if ( lLookIn ) {
		lLookIn->setVisible( false );
	}
	
	if ( hLayout ) {
		hLayout->setSpacing( 3 );
		hLayout->insertStretch( hLayout->indexOf( tbNewFolder ) );
	}
	
	if ( cbLookIn && fFrame ) {
		QBoxLayout* vLayout = qobject_cast<QBoxLayout*>( fFrame->layout() );
		
		if ( vLayout ) {
			vLayout->setSpacing( 3 );
			vLayout->insertWidget( 0, cbLookIn );
			
			if ( hLayout ) {
				glDialog->removeItem( hLayout );
				hLayout->setParent( 0 );
				vLayout->insertLayout( 0, hLayout );
			}
		}
	}
	
	if ( sidebar ) {
		QWidget* viewport = sidebar->viewport();
		QPalette pal = viewport->palette();
		pal.setColor( viewport->backgroundRole(), QColor( Qt::transparent ) );
		viewport->setPalette( pal );
		sidebar->setFrameStyle( QFrame::NoFrame | QFrame::Plain );
		sidebar->setIconSize( QSize( 16, 16 ) );
	}
	
	// text codec
	mTextCodecEnabled = true;
	
	lCodec = new QLabel( tr( "Codec:" ), this );
	cbCodec = new QComboBox( this );
	cbCodec->addItems( pCoreUtils::textCodecs() );
	setTextCodec( QTextCodec::codecForLocale()->name() );
	
	glDialog->addWidget( lCodec, 4, 0 );
	glDialog->addWidget( cbCodec, 4, 1 );
	
	// read only
	mOpenReadOnlyEnabled = true;
	
	cbOpenReadOnly = new QCheckBox( tr( "Open in read only." ), this );
	
	glDialog->addWidget( cbOpenReadOnly, 5, 1 );
	
	// configuration
	setTextCodecEnabled( textCodecEnabled );
	setOpenReadOnlyEnabled( openReadOnlyEnabled );
}