FmFileView::FmFileView() : FmViewBase( EFileView ), mWidget( 0 ),
    mStyleAction( 0 ), mSelectableAction( 0 ),
    mFindAction( 0 ), mSortExtension( 0 ), 
    mOperationService( 0 ), mMenu( 0 ), mIsFindDisabled( false )
{
    mOperationService = FmViewManager::viewManager()->operationService();
	initMenu();
	initMainWidget();
    initToolBar();

	QMetaObject::connectSlotsByName( this );
}
void FLFormRecordDB::setMainWidget( QWidget * w ) {
    if ( !cursor_ || !w )
        return ;

    if ( !cursor_->metadata() )
        return ;

    if ( showed ) {
        if ( mainWidget_ && mainWidget_ != w )
            initMainWidget( w );
    } else
        w->hide();

    if ( pushButtonAcceptContinue )
        pushButtonAcceptContinue->hide();

    if ( pushButtonAccept )
        pushButtonAccept->hide();

    if ( pushButtonCancel )
        pushButtonCancel->hide();

    if ( pushButtonFirst )
        pushButtonFirst->hide();

    if ( pushButtonPrevious )
        pushButtonPrevious->hide();

    if ( pushButtonNext )
        pushButtonNext->hide();

    if ( pushButtonLast )
        pushButtonLast->hide();

    if ( layoutButtons )
        delete layoutButtons;

    if ( layout )
        delete layout;

    w->setFont( qApp->font() );
    layout = new QVBoxLayout( this, 2, 3, "vlay" + name_ );

    layout->add( w );

    layoutButtons = new QHBoxLayout( layout, 3, "hlay" + name_ ) ;
    QSpacerItem *spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding,
            QSizePolicy::Minimum );

    QSize pbSize( 26, 26 );

#ifdef FL_DEBUGGER
    if ( !pushButtonIDE ) {
        pushButtonIDE = new QPushButton( this, "pushButtonIDE" );
        connect( pushButtonIDE, SIGNAL( clicked() ), this, SLOT( openIde() ) );
    }
    pushButtonIDE->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0,
                                  pushButtonIDE->sizePolicy().hasHeightForWidth() ) );
    pushButtonIDE->setMinimumSize( pbSize );
    pushButtonIDE->setMaximumSize( pbSize );
    QPixmap qsa( QPixmap::fromMimeSource( "bug.png" ) );
    pushButtonIDE->setIconSet( qsa );
    pushButtonIDE->setAccel( QKeySequence( Qt::Key_F3 ) );
    QToolTip::add( pushButtonIDE, tr( "Abrir Depurador (F3)" ) );
    QWhatsThis::add( pushButtonIDE, tr( "Abrir Depurador (F3)" ) );
    pushButtonIDE->setFocusPolicy( QWidget::NoFocus );
    layoutButtons->addWidget( pushButtonIDE );
    connect( pushButtonIDE, SIGNAL( clicked() ), this, SLOT( openIde() ) );
#endif

    layoutButtons->addItem( spacer_2 );

    if ( cursor_->modeAccess() == FLSqlCursor::EDIT ||
            cursor_->modeAccess() == FLSqlCursor::BROWSE ) {
        if ( !pushButtonFirst ) {
            pushButtonFirst = new QPushButton( this, "pushButtonFirst" );
            connect( pushButtonFirst, SIGNAL( clicked() ), this, SLOT( firstRecord() ) );
        }
        pushButtonFirst->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0,
                                        pushButtonFirst->sizePolicy().hasHeightForWidth() ) );
        pushButtonFirst->setMinimumSize( pbSize );
        pushButtonFirst->setMaximumSize( pbSize );
        QPixmap rld( QPixmap::fromMimeSource( "first.png" ) );
        pushButtonFirst->setIconSet( rld );
        pushButtonFirst->setAccel( QKeySequence( Qt::Key_F5 ) );
        QToolTip::add( pushButtonFirst, tr( "Aceptar los cambios e ir al primer registro (F5)" ) );
        QWhatsThis::add( pushButtonFirst, tr( "Aceptar los cambios e ir al primer registro (F5)" ) );
        pushButtonFirst->setFocusPolicy( QWidget::NoFocus );
        layoutButtons->addWidget( pushButtonFirst );
        pushButtonFirst->show();

        if ( !pushButtonPrevious ) {
            pushButtonPrevious = new QPushButton( this, "pushButtonPrevious" );
            connect( pushButtonPrevious, SIGNAL( clicked() ), this, SLOT( previousRecord() ) );
        }
        pushButtonPrevious->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0,
                                           pushButtonPrevious->sizePolicy().hasHeightForWidth() ) );
        pushButtonPrevious->setMinimumSize( pbSize );
        pushButtonPrevious->setMaximumSize( pbSize );
        QPixmap rld2( QPixmap::fromMimeSource( "previous.png" ) );
        pushButtonPrevious->setIconSet( rld2 );
        pushButtonPrevious->setAccel( QKeySequence( Qt::Key_F6 ) );
        QToolTip::add( pushButtonPrevious, tr( "Aceptar los cambios e ir al registro anterior (F6)" ) );
        QWhatsThis::add( pushButtonPrevious, tr( "Aceptar los cambios e ir al registro anterior (F6)" ) );
        pushButtonPrevious->setFocusPolicy( QWidget::NoFocus );
        layoutButtons->addWidget( pushButtonPrevious );
        pushButtonPrevious->show();

        if ( !pushButtonNext ) {
            pushButtonNext = new QPushButton( this, "pushButtonNext" );
            connect( pushButtonNext, SIGNAL( clicked() ), this, SLOT( nextRecord() ) );
        }
        pushButtonNext->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0,
                                       pushButtonNext->sizePolicy().hasHeightForWidth() ) );
        pushButtonNext->setMinimumSize( pbSize );
        pushButtonNext->setMaximumSize( pbSize );
        QPixmap rld3( QPixmap::fromMimeSource( "next.png" ) );
        pushButtonNext->setIconSet( rld3 );
        pushButtonNext->setAccel( QKeySequence( Qt::Key_F7 ) );
        QToolTip::add( pushButtonNext, tr( "Aceptar los cambios e ir al registro siguiente (F7)" ) );
        QWhatsThis::add( pushButtonNext, tr( "Aceptar los cambios e ir al registro siguiente (F7)" ) );
        pushButtonNext->setFocusPolicy( QWidget::NoFocus );
        layoutButtons->addWidget( pushButtonNext );
        pushButtonNext->show();

        if ( !pushButtonLast ) {
            pushButtonLast = new QPushButton( this, "pushButtonLast" );
            connect( pushButtonLast, SIGNAL( clicked() ), this, SLOT( lastRecord() ) );
        }
        pushButtonLast->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0,
                                       pushButtonLast->sizePolicy().hasHeightForWidth() ) );
        pushButtonLast->setMinimumSize( pbSize );
        pushButtonLast->setMaximumSize( pbSize );
        QPixmap rld4( QPixmap::fromMimeSource( "last.png" ) );
        pushButtonLast->setIconSet( rld4 );
        pushButtonLast->setAccel( QKeySequence( Qt::Key_F8 ) );
        QToolTip::add( pushButtonLast, tr( "Aceptar los cambios e ir al último registro (F8)" ) );
        QWhatsThis::add( pushButtonLast, tr( "Aceptar los cambios e ir al último registro (F8)" ) );
        pushButtonLast->setFocusPolicy( QWidget::NoFocus );
        layoutButtons->addWidget( pushButtonLast );
        pushButtonLast->show();
    }

    if ( cursor_->modeAccess() != FLSqlCursor::BROWSE ) {
        if ( showAcceptContinue_ ) {
            if ( !pushButtonAcceptContinue ) {
                pushButtonAcceptContinue = new QPushButton( this, "pushButtonAcceptContinue" );
                connect( pushButtonAcceptContinue, SIGNAL( clicked() ), this, SLOT( acceptContinue() ) );
            }
            pushButtonAcceptContinue->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0,
                    pushButtonAcceptContinue->sizePolicy().hasHeightForWidth() ) );
            pushButtonAcceptContinue->setMinimumSize( pbSize );
            pushButtonAcceptContinue->setMaximumSize( pbSize );
            QPixmap rld( QPixmap::fromMimeSource( "reload.png" ) );
            pushButtonAcceptContinue->setIconSet( rld );
            pushButtonAcceptContinue->setFocusPolicy( QWidget::NoFocus );
            pushButtonAcceptContinue->setAccel( QKeySequence( Qt::Key_F9 ) );
            QToolTip::add( pushButtonAcceptContinue, tr( "Aceptar los cambios y continuar con la edición de un nuevo registro (F9)" ) );
            QWhatsThis::add( pushButtonAcceptContinue, tr( "Aceptar los cambios y continuar con la edición de un nuevo registro (F9)" ) );
            layoutButtons->addWidget( pushButtonAcceptContinue );
            pushButtonAcceptContinue->show();
        }

        if ( !pushButtonAccept ) {
            pushButtonAccept = new QPushButton( this, "pushButtonAccept" );
            connect( pushButtonAccept, SIGNAL( clicked() ), this, SLOT( accept() ) );
        }
        pushButtonAccept->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0,
                                         pushButtonAccept->sizePolicy().hasHeightForWidth() ) );
        pushButtonAccept->setMinimumSize( pbSize );
        pushButtonAccept->setMaximumSize( pbSize );
        QPixmap ok( QPixmap::fromMimeSource( "button_ok.png" ) );
        pushButtonAccept->setIconSet( ok );
        pushButtonAccept->setFocusPolicy( QWidget::NoFocus );
        pushButtonAccept->setAccel( QKeySequence( Qt::Key_F10 ) );
        QToolTip::add( pushButtonAccept, tr( "Aceptar los cambios y cerrar formulario (F10)" ) );
        QWhatsThis::add( pushButtonAccept, tr( "Aceptar los cambios y cerrar formulario (F10)" ) );
        layoutButtons->addWidget( pushButtonAccept );
        pushButtonAccept->show();
    }

    if ( !pushButtonCancel ) {
        pushButtonCancel = new QPushButton( this, "pushButtonCancel" );
        connect( cursor_, SIGNAL( autoCommit() ), this, SLOT( disablePushButtonCancel() ) );
        connect( pushButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
    }
    pushButtonCancel->setSizePolicy( QSizePolicy(( QSizePolicy::SizeType ) 0, ( QSizePolicy::SizeType ) 0, 0, 0,
                                     pushButtonCancel->sizePolicy().hasHeightForWidth() ) );
    pushButtonCancel->setMinimumSize( pbSize );
    pushButtonCancel->setMaximumSize( pbSize );
    QPixmap cancel( QPixmap::fromMimeSource( "button_cancel.png" ) );
    pushButtonCancel->setIconSet( cancel );
    if ( cursor_->modeAccess() != FLSqlCursor::BROWSE ) {
        pushButtonCancel->setFocusPolicy( QWidget::NoFocus );
        pushButtonCancel->setAccel( 4096 );
        QToolTip::add( pushButtonCancel, tr( "Cancelar los cambios y cerrar formulario (Esc)" ) );
        QWhatsThis::add( pushButtonCancel, tr( "Cancelar los cambios y cerrar formulario (Esc)" ) );
    } else {
        QPixmap ok( QPixmap::fromMimeSource( "button_cancel.png" ) );
        pushButtonCancel->setIconSet( ok );
        pushButtonCancel->setFocusPolicy( QWidget::StrongFocus );
        pushButtonCancel->setFocus();
        pushButtonCancel->setAccel( 4096 );
        QToolTip::add( pushButtonCancel, tr( "Aceptar y cerrar formulario (Esc)" ) );
        QWhatsThis::add( pushButtonCancel, tr( "Aceptar y cerrar formulario (Esc)" ) );
    }
    pushButtonCancel->setDefault( true );
    layoutButtons->addWidget( pushButtonCancel );
    pushButtonCancel->show();

    mainWidget_ = w;
    mainWidget_->setFocusPolicy( QWidget::NoFocus );
    int mWidth = mainWidget_->width();
    int mHeight = mainWidget_->height();
    QWidget * actWin = qApp->activeWindow();
    QRect screen = ( actWin ? actWin->geometry() : qApp->mainWidget()->geometry() );
    QRect desk = QApplication::desktop()->geometry();
    QPoint p = screen.center() - QPoint( mWidth / 2, mHeight / 2 );
    if ( p.x() + mWidth > desk.width() )
        p.setX( desk.width() - mWidth );
    if ( p.y() + mHeight > desk.height() )
        p.setY( desk.height() - mHeight );
    if ( p.x() < 0 )
        p.setX( 0 );
    if ( p.y() < 0 )
        p.setY( 0 );
    move( p );
}