Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
CTA-LAPP
PHOENIX_LIBS
PhoenixClockTimer
Commits
c9d62ef4
Commit
c9d62ef4
authored
Jul 29, 2017
by
Pierre Aubert
Browse files
Finish clock timer
parent
a34f964d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
153 additions
and
14 deletions
+153
-14
PClockTimer.cpp
PClockTimer.cpp
+114
-10
PClockTimer.h
PClockTimer.h
+39
-4
No files found.
PClockTimer.cpp
View file @
c9d62ef4
#include <sstream>
#include "PClockTimer.h"
#include <QLabel>
...
...
@@ -5,18 +7,120 @@
#include <QMenuBar>
#include <QAction>
PClockTimer
::
PClockTimer
()
{
QLabel
*
label
=
new
QLabel
(
this
);
label
->
setText
(
"Hello World!"
);
setCentralWidget
(
label
);
QAction
*
action
=
new
QAction
(
this
);
action
->
setText
(
"Quit"
);
connect
(
action
,
SIGNAL
(
triggered
()),
SLOT
(
close
())
);
menuBar
()
->
addMenu
(
"File"
)
->
addAction
(
action
);
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QHBoxLayout>
///PClockTimer constructor
PClockTimer
::
PClockTimer
(){
initialisationPClockTimer
();
}
///PClockTimer destructor
PClockTimer
::~
PClockTimer
()
{}
#include "PClockTimer.moc"
///Set the clock value to zero
void
PClockTimer
::
slotZero
(){
p_hour
=
0
;
p_minute
=
0
;
p_second
=
0
;
setLCDnumber
();
}
///Update the LCD print
void
PClockTimer
::
slotUpdateLCD
(){
++
p_second
;
if
(
p_second
>=
60
){
++
p_minute
;
p_second
=
0
;
}
if
(
p_minute
>=
60
){
++
p_hour
;
p_minute
=
0
;
}
setLCDnumber
();
}
///Init the PClockTimer
void
PClockTimer
::
initialisationPClockTimer
(){
p_timer
=
new
QTimer
;
p_timer
->
setInterval
(
1000
);
p_timer
->
setTimerType
(
Qt
::
VeryCoarseTimer
);
connect
(
p_timer
,
SIGNAL
(
timeout
()),
this
,
SLOT
(
slotUpdateLCD
()));
initialisationWidget
();
slotZero
();
// QLabel* label = new QLabel( this );
// label->setText( "Hello World!" );
// setCentralWidget( label );
// QAction* action = new QAction(this);
// action->setText( "Quit" );
// connect(action, SIGNAL(triggered()), SLOT(close()) );
// menuBar()->addMenu( "File" )->addAction( action );
}
///Init the widgets
void
PClockTimer
::
initialisationWidget
(){
initialisationButton
();
p_lcdNumber
=
new
QLCDNumber
;
p_lcdNumber
->
setDigitCount
(
8
);
setLCDnumber
();
QHBoxLayout
*
layoutButton
=
new
QHBoxLayout
;
layoutButton
->
addWidget
(
p_buttonZero
);
layoutButton
->
addWidget
(
p_buttonStart
);
layoutButton
->
addWidget
(
p_buttonStop
);
QVBoxLayout
*
mainLayout
=
new
QVBoxLayout
;
mainLayout
->
addWidget
(
p_lcdNumber
);
mainLayout
->
addLayout
(
layoutButton
);
QWidget
*
mainWidget
=
new
QWidget
;
mainWidget
->
setLayout
(
mainLayout
);
setCentralWidget
(
mainWidget
);
}
///Init the button
void
PClockTimer
::
initialisationButton
(){
p_buttonStart
=
new
QPushButton
(
"Start"
);
p_buttonStop
=
new
QPushButton
(
"Stop"
);
p_buttonZero
=
new
QPushButton
(
"Zero"
);
connect
(
p_buttonStart
,
SIGNAL
(
pressed
()),
p_timer
,
SLOT
(
start
()));
connect
(
p_buttonStop
,
SIGNAL
(
pressed
()),
p_timer
,
SLOT
(
stop
()));
connect
(
p_buttonZero
,
SIGNAL
(
pressed
()),
this
,
SLOT
(
slotZero
()));
}
///Set the LCD number
void
PClockTimer
::
setLCDnumber
(){
std
::
stringstream
strTime
;
if
(
p_hour
<
10
){
strTime
<<
"0"
<<
p_hour
;
}
else
{
strTime
<<
p_hour
;
}
strTime
<<
":"
;
if
(
p_minute
<
10
){
strTime
<<
"0"
<<
p_minute
;
}
else
{
strTime
<<
p_minute
;
}
strTime
<<
":"
;
if
(
p_second
<
10
){
strTime
<<
"0"
<<
p_second
;
}
else
{
strTime
<<
p_second
;
}
// strTime << p_hour << ":" << p_minute << ":" << p_second;
p_lcdNumber
->
display
(
QString
(
strTime
.
str
().
c_str
()));
}
// #include "PClockTimer.moc"
PClockTimer.h
View file @
c9d62ef4
...
...
@@ -2,14 +2,49 @@
#define PClockTimer_H
#include <QMainWindow>
#include <QTimer>
#include <QtWidgets/QLCDNumber>
#include <QtWidgets/QPushButton>
class
PClockTimer
:
public
QMainWindow
{
Q_OBJECT
Q_OBJECT
public:
PClockTimer
();
virtual
~
PClockTimer
();
public:
PClockTimer
();
virtual
~
PClockTimer
();
private
slots
:
void
slotZero
();
void
slotUpdateLCD
();
private:
void
initialisationPClockTimer
();
void
initialisationWidget
();
void
initialisationButton
();
void
setLCDnumber
();
///Start button
QPushButton
*
p_buttonStart
;
///Stop button
QPushButton
*
p_buttonStop
;
///Set to zero button
QPushButton
*
p_buttonZero
;
///Current ellapsed time
QLCDNumber
*
p_lcdNumber
;
///Clock timer
QTimer
*
p_timer
;
///hours
int
p_hour
;
///minutes
int
p_minute
;
///seconds
int
p_second
;
};
#endif // PClockTimer_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment