/******************************************************************************
* Called when the file picker button is clicked.
* Reply = mFile, or null string if dialogue, and 'this', was deleted.
*/
QString PickFileRadio::slotPickFile()
{
    // To avoid crashes on application quit, we need to check whether the
    // dialogue, and hence this PickFileRadio, was deleted while active,
    // before accessing class members.
    QString file = pickFile();
    if (file.isNull())
        return file;   // 'this' is probably invalid now
    if (!file.isEmpty())
    {
        mFile = file;
        if (mEdit)
            mEdit->setText(mFile);
    }
    if (mFile.isEmpty())
    {
        // No file is selected, so revert to the previous radio button selection.
        // But wait a moment before setting the radio button, or it won't work.
        mRevertButton = true;   // prevent picker dialog popping up twice
        QTimer::singleShot(0, this, SLOT(setLastButton()));
    }
    return mFile;
}
Example #2
0
FileChooserView::FileChooserView(   nnet::SerializablePtr   object,
                                    QWidget*                parent,
                                    const char*             name,
                                    WFlags                  fl ) :
    ObjectView( object, parent, name, fl ),
    cstr( object )
{
    if( !name )
    {
        setName( "FileChooserView" );
    }
        
    FileChooserViewLayout = new QHBoxLayout( this, 11, 6, "FileChooserViewLayout" );
    
    label = new QLabel( this, "label" );
    QFont label_font( label->font() );
    label_font.setFamily( "Helvetica" );
    label->setFont( label_font );
    label->setAlignment( int( QLabel::AlignVCenter ) );
    FileChooserViewLayout->addWidget( label );
    
    edit = new QPushButton( cstr->get
                            ().c_str(), this, "edit" );
    QFont edit_font( edit->font() );
    edit_font.setFamily( "Helvetica" );
    edit_font.setPointSize( 10 );
    edit->setFont( edit_font );
    FileChooserViewLayout->addWidget( edit );
    languageChange();
    resize( QSize( 189, 50 ).expandedTo( minimumSizeHint() ) );
    clearWState( WState_Polished );
    
    connect( edit, SIGNAL( clicked() ), this, SLOT( pickFile() ) );
    
    label->setText( cstr->name().c_str() );
    refreshView();
}