File: rellotge.cpp

package info (click to toggle)
glpeces 5.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,696 kB
  • sloc: cpp: 6,821; xml: 33; makefile: 6
file content (105 lines) | stat: -rw-r--r-- 2,669 bytes parent folder | download | duplicates (4)
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
105
/*
 * Copyright (C) 2000-2016  Innocent De Marchi
 * email: tangram.peces@gmail.com
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#include <QtGui>
#include <QTimer>
 #include <math.h>

#include "rellotge.h"

Rellotge::Rellotge(QWidget * parent , Qt::WindowFlags)
       : QLabel(parent)
{
    rellotgeQTimer = new QTimer();
    connect(rellotgeQTimer, SIGNAL(timeout()), this, SLOT(actualitzaRellotge()));
    p_rellotgeEnMarxa=false;
    hores=0;
    minuts=0;
    segons=0;
}

void Rellotge::actualitzaRellotge(){
    segons=segons+1;
    if (segons>=60){
        segons=segons-60;
        minuts=minuts+1;
    }
    if (minuts>=60){
        minuts=minuts-60;
        hores=hores+1;
    }
    setText(retornaTemps());
}

void Rellotge::iniciaRellotge(){
  rellotgeQTimer->start(1000);
  p_rellotgeEnMarxa=true;

}

void Rellotge::aturaRellotge(){
  rellotgeQTimer->stop();
  setText(retornaTemps());
  p_rellotgeEnMarxa=false;
  update();
}

void Rellotge::estableixTemps(QString temps){
   QStringList list1 = temps.split(":");
   hores=list1.at(0).toInt();
   minuts=list1.at(1).toInt();
   segons=list1.at(2).toInt();
   setText(retornaTemps());
   update();
}

QString Rellotge::retornaTemps(int tipus){

    QString sHores,sMinuts,sSegons;

    if (hores<10){
      sHores= QString("0%1:").arg(hores);
    }
    else sHores= QString("%1:").arg(hores);

    if (minuts<10){
      sMinuts= QString("0%1:").arg(minuts);
    }
    else sMinuts= QString("%1:").arg(minuts);

    if (segons<10){
      sSegons= QString("0%1").arg(segons);
    }
    else sSegons= QString("%1").arg(segons);

if (tipus==0){
    if(rellotgeQTimer->isActive()){
       return QString("<h2><font color=red>%1%2%3</font></h2>").arg(sHores,sMinuts,sSegons);
    }
    else {
        return QString("<h2><font color=blue>%1%2%3</font></h2>").arg(sHores,sMinuts,sSegons);
    }
}
else  {
    return QString("%1%2%3").arg(sHores,sMinuts,sSegons);
  }
}

bool Rellotge::rellotgeEnMarxa(){
    return p_rellotgeEnMarxa;
}