| 278 |
david |
1 |
/*============================================================================
|
|
|
2 |
** Copyright (C) 1998-2012 Vix Technology, All rights reserved
|
|
|
3 |
**============================================================================
|
|
|
4 |
**
|
|
|
5 |
** Project/Product :
|
|
|
6 |
** Filename : qmteamselector.cpp
|
|
|
7 |
** Author(s) : DDP
|
|
|
8 |
**
|
|
|
9 |
** Description : Based on a QSpinBox with features
|
|
|
10 |
** Return - will emit signal
|
|
|
11 |
** All text is selected on focus
|
|
|
12 |
**
|
|
|
13 |
** Information :
|
|
|
14 |
** Compiler : ANSI C++
|
|
|
15 |
** Target :
|
|
|
16 |
**
|
|
|
17 |
***==========================================================================*/
|
|
|
18 |
|
| 277 |
david |
19 |
#include "qmteamselector.h"
|
|
|
20 |
#include <QKeyEvent>
|
|
|
21 |
|
| 278 |
david |
22 |
/*----------------------------------------------------------------------------
|
|
|
23 |
** FUNCTION : Constructor
|
|
|
24 |
**
|
|
|
25 |
** DESCRIPTION :
|
|
|
26 |
**
|
|
|
27 |
**
|
|
|
28 |
** INPUTS :
|
|
|
29 |
**
|
|
|
30 |
** RETURNS :
|
|
|
31 |
**
|
|
|
32 |
----------------------------------------------------------------------------*/
|
|
|
33 |
|
|
|
34 |
|
| 279 |
david |
35 |
QmTeamSelector::QmTeamSelector(QWidget *parent): QSpinBox(parent)
|
| 277 |
david |
36 |
{
|
| 278 |
david |
37 |
/*
|
|
|
38 |
** Create a single shot timer to assist in selecting text in the Widget
|
|
|
39 |
** Use an interval of zero for immediate action
|
|
|
40 |
*/
|
|
|
41 |
timer.setSingleShot(true);
|
|
|
42 |
timer.setInterval(0);
|
|
|
43 |
connect(&timer, SIGNAL(timeout()), this, SLOT(selectControl()));
|
| 277 |
david |
44 |
}
|
|
|
45 |
|
| 278 |
david |
46 |
/*----------------------------------------------------------------------------
|
|
|
47 |
** FUNCTION : focusInEvent
|
|
|
48 |
**
|
|
|
49 |
** DESCRIPTION : Overide the parent function of the same name
|
|
|
50 |
** Used to trigger a timer to select all text once
|
|
|
51 |
** The user has entered the Widget
|
|
|
52 |
**
|
|
|
53 |
** Calling selectALL() directly does not select all the text
|
|
|
54 |
** It is called on a zero-length timer as that works.
|
|
|
55 |
**
|
|
|
56 |
** INPUTS :
|
|
|
57 |
**
|
|
|
58 |
** RETURNS :
|
|
|
59 |
**
|
|
|
60 |
----------------------------------------------------------------------------*/
|
|
|
61 |
|
|
|
62 |
|
| 277 |
david |
63 |
void QmTeamSelector::focusInEvent(QFocusEvent * event)
|
|
|
64 |
{
|
| 278 |
david |
65 |
//qDebug("QmTeamSelector::focusInEvent");
|
|
|
66 |
timer.start();
|
| 277 |
david |
67 |
}
|
|
|
68 |
|
| 278 |
david |
69 |
/*----------------------------------------------------------------------------
|
|
|
70 |
** FUNCTION : selectControl
|
|
|
71 |
**
|
|
|
72 |
** DESCRIPTION : Timer call back function
|
|
|
73 |
** Select all text in the Widget
|
|
|
74 |
**
|
|
|
75 |
** INPUTS :
|
|
|
76 |
**
|
|
|
77 |
** RETURNS :
|
|
|
78 |
**
|
|
|
79 |
----------------------------------------------------------------------------*/
|
|
|
80 |
|
|
|
81 |
void QmTeamSelector::selectControl(void)
|
|
|
82 |
{
|
|
|
83 |
//qDebug("QmTeamSelector::selectControl");
|
|
|
84 |
selectAll();
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
/*----------------------------------------------------------------------------
|
|
|
88 |
** FUNCTION : keyPressEvent
|
|
|
89 |
**
|
|
|
90 |
** DESCRIPTION : Detect and report "RETURN" key
|
|
|
91 |
** Force all text in the Widget to be selected
|
|
|
92 |
**
|
|
|
93 |
** INPUTS :
|
|
|
94 |
**
|
|
|
95 |
** RETURNS :
|
|
|
96 |
**
|
|
|
97 |
----------------------------------------------------------------------------*/
|
|
|
98 |
|
| 277 |
david |
99 |
void QmTeamSelector::keyPressEvent(QKeyEvent * event)
|
|
|
100 |
{
|
| 278 |
david |
101 |
//qDebug("QmTeamSelector::keyPressEvent");
|
| 277 |
david |
102 |
if(event->key() == Qt::Key_Return)
|
|
|
103 |
{
|
| 278 |
david |
104 |
//qDebug("QmTeamSelector::keyPressEvent - return Pressed");
|
| 277 |
david |
105 |
emit teamSelected( );
|
| 278 |
david |
106 |
timer.start();
|
| 277 |
david |
107 |
}
|
|
|
108 |
else
|
|
|
109 |
{
|
|
|
110 |
QSpinBox::keyPressEvent(event);
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
|