Changeset View
Changeset View
Standalone View
Standalone View
secqlineedit.cpp
| Context not available. | |||||
| enum { IdUndo, IdRedo, IdSep1, IdCut, IdCopy, IdPaste, IdClear, IdSep2, IdSelectAll }; | enum { IdUndo, IdRedo, IdSep1, IdCut, IdCopy, IdPaste, IdClear, IdSep2, IdSelectAll }; | ||||
| /*!\reimp | |||||
| */ | |||||
| void SecQLineEdit::contextMenuEvent( QContextMenuEvent * e ) | |||||
| { | |||||
| #ifndef QT_NO_POPUPMENU | |||||
| d->separate(); | |||||
| QGuardedPtr<QPopupMenu> popup = createPopupMenu(); | |||||
| QGuardedPtr<SecQLineEdit> that = this; | |||||
| QPoint pos = e->reason() == QContextMenuEvent::Mouse ? e->globalPos() : | |||||
| mapToGlobal( QPoint(e->pos().x(), 0) ) + QPoint( width() / 2, height() / 2 ); | |||||
| int r = popup->exec( pos ); | |||||
| delete (QPopupMenu*)popup; | |||||
| if ( that && d->menuId ) { | |||||
| switch ( d->menuId - r ) { | |||||
| case IdClear: clear(); break; | |||||
| case IdSelectAll: selectAll(); break; | |||||
| #ifndef SECURE_NO_UNDO | |||||
| case IdUndo: undo(); break; | |||||
| case IdRedo: redo(); break; | |||||
| #endif | |||||
| #ifndef QT_NO_CLIPBOARD | |||||
| case IdCut: cut(); break; | |||||
| case IdCopy: copy(); break; | |||||
| case IdPaste: paste(); break; | |||||
| #endif | |||||
| default: | |||||
| ; // nothing selected or lineedit destroyed. Be careful. | |||||
| } | |||||
| } | |||||
| #endif //QT_NO_POPUPMENU | |||||
| } | |||||
| /*! | |||||
| This function is called to create the popup menu which is shown | |||||
| when the user clicks on the line edit with the right mouse button. | |||||
| If you want to create a custom popup menu, reimplement this | |||||
| function and return the popup menu you create. The popup menu's | |||||
| ownership is transferred to the caller. | |||||
| */ | |||||
| QPopupMenu *SecQLineEdit::createPopupMenu() | |||||
| { | |||||
| #ifndef QT_NO_POPUPMENU | |||||
| QPopupMenu *popup = new QPopupMenu( this, "qt_edit_menu" ); | |||||
| int id = d->menuId = popup->insertItem( QString( "&Undo" ) + ACCEL_KEY( Z ) ); | |||||
| popup->insertItem( QString ("&Redo") + ACCEL_KEY( Y ) ); | |||||
| popup->insertSeparator(); | |||||
| popup->insertItem( QString ("Cu&t") + ACCEL_KEY( X ) ); | |||||
| popup->insertItem( QString ("&Copy") + ACCEL_KEY( C ) ); | |||||
| popup->insertItem( QString ("&Paste") + ACCEL_KEY( V ) ); | |||||
| popup->insertItem( QString ("Clear") ); | |||||
| popup->insertSeparator(); | |||||
| popup->insertItem( QString ("Select All") | |||||
| #ifndef Q_WS_X11 | |||||
| + ACCEL_KEY( A ) | |||||
| #endif | |||||
| ); | |||||
| #ifndef SECURE_NO_UNDO | |||||
| popup->setItemEnabled( id - IdUndo, d->isUndoAvailable() ); | |||||
| popup->setItemEnabled( id - IdRedo, d->isRedoAvailable() ); | |||||
| #else | |||||
| popup->setItemVisible( id - IdUndo, FALSE ); | |||||
| popup->setItemVisible( id - IdRedo, FALSE ); | |||||
| #endif /* SECURE_NO_UNDO */ | |||||
| #ifndef QT_NO_CLIPBOARD | |||||
| popup->setItemEnabled( id - IdCut, !d->readOnly && d->hasSelectedText() ); | |||||
| popup->setItemEnabled( id - IdCopy, d->hasSelectedText() ); | |||||
| popup->setItemEnabled( id - IdPaste, !d->readOnly && !QApplication::clipboard()->text().isEmpty() ); | |||||
| #else | |||||
| popup->setItemVisible( id - IdCut, FALSE ); | |||||
| popup->setItemVisible( id - IdCopy, FALSE ); | |||||
| popup->setItemVisible( id - IdPaste, FALSE ); | |||||
| #endif | |||||
| popup->setItemEnabled( id - IdClear, !d->readOnly && !d->text.isEmpty() ); | |||||
| popup->setItemEnabled( id - IdSelectAll, !d->text.isEmpty() && !d->allSelected() ); | |||||
| return popup; | |||||
| #else | |||||
| return 0; | |||||
| #endif | |||||
| } | |||||
| /*! \reimp */ | /*! \reimp */ | ||||
| void SecQLineEdit::windowActivationChange( bool b ) | void SecQLineEdit::windowActivationChange( bool b ) | ||||
| { | { | ||||
| Context not available. | |||||