-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathClickLabel.cpp
105 lines (83 loc) · 2.37 KB
/
ClickLabel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
Stratofier Stratux AHRS Display
(c) 2018 Allen K. Lair, Sky Fun
*/
#include <QWindow>
#include <QGuiApplication>
#include <QTimer>
#include "ClickLabel.h"
#include "Keypad.h"
#include "Keyboard.h"
#include "Canvas.h"
extern Keyboard *g_pKeyboard;
ClickLabel::ClickLabel( QWidget *pParent, bool bTop )
: QLabel( pParent ),
m_iDecimals( 2 ),
m_bFullKeyboard( false ),
m_bTop( bTop )
{
}
ClickLabel::~ClickLabel()
{
if( g_pKeyboard != nullptr )
{
delete g_pKeyboard;
g_pKeyboard = nullptr;
}
}
void ClickLabel::mousePressEvent( QMouseEvent *pEvent )
{
if( g_pKeyboard != nullptr )
keyboardComplete2();
if( m_bFullKeyboard )
{
QWindow *pWindow = QGuiApplication::topLevelAt( QPoint( 0, parentWidget()->height() + 2 ) );
QSize screenSize = pWindow->size();
g_pKeyboard = new Keyboard( this );
// Landscape
if( screenSize.width() > screenSize.height() )
g_pKeyboard->setGeometry( 0, 0, screenSize.width(), screenSize.height() / 2 );
// Portrait
else
{
if( m_bTop )
g_pKeyboard->setGeometry( 0, 0, screenSize.width(), screenSize.height() / 3 );
else
g_pKeyboard->setGeometry( 0, screenSize.height() * 2 / 3, screenSize.width(), screenSize.height() / 3 );
}
connect( g_pKeyboard, SIGNAL( key( const QString& ) ), this, SLOT( key( const QString& ) ) );
connect( g_pKeyboard, SIGNAL( accepted() ), this, SLOT( keyboardComplete() ) );
g_pKeyboard->show();
}
else
{
Keypad keypad( this, m_qsTitle );
m_pCanvas->setKeypadGeometry( &keypad );
if( keypad.exec() == QDialog::Accepted )
{
if( m_iDecimals == 0 )
setText( QString::number( static_cast<int>( keypad.value() ) ) );
else
setText( QString::number( keypad.value(), 'f', m_iDecimals ) );
}
QLabel::mousePressEvent( pEvent );
}
}
void ClickLabel::key( const QString &qsKey )
{
QString qs( text() );
if( qsKey == "_" )
qs.chop( 1 );
else
qs.append( qsKey );
setText( qs );
}
void ClickLabel::keyboardComplete()
{
QTimer::singleShot( 100, this, SLOT( keyboardComplete2() ) );
}
void ClickLabel::keyboardComplete2()
{
delete g_pKeyboard;
g_pKeyboard = nullptr;
}