File: rellotge.cpp

package info (click to toggle)
peg-solitaire 2.2-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,136 kB
  • sloc: cpp: 4,893; xml: 32; makefile: 9
file content (124 lines) | stat: -rw-r--r-- 3,239 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/***********************************************************************
 *
 * Copyright (C) 2010-2017 Innocent De Marchi <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 3 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, see <http://www.gnu.org/licenses/>.
 *
 ***********************************************************************/
#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(){
//    milisegons10++;
    segons=segons+1;
//    if (milisegons10>=100){
//        milisegons10=milisegons10-100;
//        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(){
  p_rellotgeEnMarxa= true;
  setText(retornaTemps());
  rellotgeQTimer->start(1000);
}

//Fa que el rellotge aturat segueixi en marxa
void Rellotge::reIniciaRellotge(){
  rellotgeQTimer->start(1000);
  p_rellotgeEnMarxa= true;
  estableixTemps(retornaTemps());
  setText(retornaTemps());
}

void Rellotge::aturaRellotge(){
  rellotgeQTimer->stop();
  p_rellotgeEnMarxa=false;
  setText(retornaTemps());
  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("<h1><font color=red>%1%2%3</font></h1>").arg(sHores,sMinuts,sSegons);
    }
    else {
        return QString("<h1><font color=blue>%1%2%3</font></h1>").arg(sHores,sMinuts,sSegons);
    }
}
else  {
    return QString("%1%2%3").arg(sHores,sMinuts,sSegons);
  }
}

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

/*Retorna el temps marcat en segons totals
  No es fa servir*/
int Rellotge::retornarSegonsTotals(){
  return hores*3600+minuts*60+segons;
}