/*============================================================================ ** Copyright (C) 1998-2012 Vix Technology, All rights reserved **============================================================================ ** ** Project/Product : ** Filename : qmteamselector.cpp ** Author(s) : DDP ** ** Description : Based on a QSpinBox with features ** Return - will emit signal ** All text is selected on focus ** ** Information : ** Compiler : ANSI C++ ** Target : ** ***==========================================================================*/ #include "qmteamselector.h" #include /*---------------------------------------------------------------------------- ** FUNCTION : Constructor ** ** DESCRIPTION : ** ** ** INPUTS : ** ** RETURNS : ** ----------------------------------------------------------------------------*/ QmTeamSelector::QmTeamSelector(QWidget *parent): QSpinBox(parent) { /* ** Create a single shot timer to assist in selecting text in the Widget ** Use an interval of zero for immediate action */ timer.setSingleShot(true); timer.setInterval(0); connect(&timer, SIGNAL(timeout()), this, SLOT(selectControl())); } /*---------------------------------------------------------------------------- ** FUNCTION : focusInEvent ** ** DESCRIPTION : Overide the parent function of the same name ** Used to trigger a timer to select all text once ** The user has entered the Widget ** ** Calling selectALL() directly does not select all the text ** It is called on a zero-length timer as that works. ** ** INPUTS : ** ** RETURNS : ** ----------------------------------------------------------------------------*/ void QmTeamSelector::focusInEvent(QFocusEvent * event) { //qDebug("QmTeamSelector::focusInEvent"); timer.start(); } /*---------------------------------------------------------------------------- ** FUNCTION : selectControl ** ** DESCRIPTION : Timer call back function ** Select all text in the Widget ** ** INPUTS : ** ** RETURNS : ** ----------------------------------------------------------------------------*/ void QmTeamSelector::selectControl(void) { //qDebug("QmTeamSelector::selectControl"); selectAll(); } /*---------------------------------------------------------------------------- ** FUNCTION : keyPressEvent ** ** DESCRIPTION : Detect and report "RETURN" key ** Force all text in the Widget to be selected ** ** INPUTS : ** ** RETURNS : ** ----------------------------------------------------------------------------*/ void QmTeamSelector::keyPressEvent(QKeyEvent * event) { //qDebug("QmTeamSelector::keyPressEvent"); if(event->key() == Qt::Key_Return) { //qDebug("QmTeamSelector::keyPressEvent - return Pressed"); emit teamSelected( ); timer.start(); } else { QSpinBox::keyPressEvent(event); } }