~ubuntu-branches/ubuntu/vivid/peg-solitaire/vivid

« back to all changes in this revision

Viewing changes to scr/rellotge.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Innocent De Marchi
  • Date: 2011-01-18 18:06:54 UTC
  • Revision ID: james.westby@ubuntu.com-20110118180654-w1yj9he00r65fvxh
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***********************************************************************
 
2
 *
 
3
 * Copyright (C) 2010 Innocent De Marchi <tangram.peces@gmail.com>
 
4
 *
 
5
 * This program is free software: you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation, either version 3 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 *
 
18
 ***********************************************************************/
 
19
#include <QtGui>
 
20
#include <QTimer>
 
21
 #include <math.h>
 
22
 
 
23
#include "rellotge.h"
 
24
 
 
25
Rellotge::Rellotge(QWidget * parent , Qt::WindowFlags)
 
26
       : QLabel(parent)
 
27
{
 
28
    rellotgeQTimer = new QTimer();
 
29
    connect(rellotgeQTimer, SIGNAL(timeout()), this, SLOT(actualitzaRellotge()));
 
30
    p_rellotgeEnMarxa=false;
 
31
    hores=0;
 
32
    minuts=0;
 
33
    segons=0;
 
34
}
 
35
 
 
36
void Rellotge::actualitzaRellotge(){
 
37
    segons=segons+1;
 
38
    if (segons>=60){
 
39
        segons=segons-60;
 
40
        minuts=minuts+1;
 
41
    }
 
42
    if (minuts>=60){
 
43
        minuts=minuts-60;
 
44
        hores=hores+1;
 
45
    }
 
46
    setText(retornaTemps());
 
47
}
 
48
 
 
49
void Rellotge::iniciaRellotge(){
 
50
  p_rellotgeEnMarxa= true;
 
51
  setText(retornaTemps());
 
52
  rellotgeQTimer->start(1000);
 
53
}
 
54
 
 
55
void Rellotge::aturaRellotge(){
 
56
  rellotgeQTimer->stop();
 
57
  p_rellotgeEnMarxa=false;
 
58
  setText(retornaTemps());
 
59
  update();
 
60
}
 
61
 
 
62
void Rellotge::estableixTemps(QString temps){
 
63
   QStringList list1 = temps.split(":");
 
64
   hores=list1.at(0).toInt();
 
65
   minuts=list1.at(1).toInt();
 
66
   segons=list1.at(2).toInt();
 
67
   setText(retornaTemps());
 
68
   update();
 
69
}
 
70
 
 
71
QString Rellotge::retornaTemps(int tipus){
 
72
 
 
73
    QString sHores,sMinuts,sSegons;
 
74
 
 
75
    if (hores<10){
 
76
      sHores= QString("0%1:").arg(hores);
 
77
    }
 
78
    else sHores= QString("%1:").arg(hores);
 
79
 
 
80
    if (minuts<10){
 
81
      sMinuts= QString("0%1:").arg(minuts);
 
82
    }
 
83
    else sMinuts= QString("%1:").arg(minuts);
 
84
 
 
85
    if (segons<10){
 
86
      sSegons= QString("0%1").arg(segons);
 
87
    }
 
88
    else sSegons= QString("%1").arg(segons);
 
89
 
 
90
if (tipus==0){
 
91
    if(rellotgeQTimer->isActive()){
 
92
       return QString("<h1><font color=red>%1%2%3</font></h1>").arg(sHores,sMinuts,sSegons);
 
93
    }
 
94
    else {
 
95
        return QString("<h1><font color=blue>%1%2%3</font></h1>").arg(sHores,sMinuts,sSegons);
 
96
    }
 
97
}
 
98
else  {
 
99
    return QString("%1%2%3").arg(sHores,sMinuts,sSegons);
 
100
  }
 
101
}
 
102
 
 
103
bool Rellotge::rellotgeEnMarxa(){
 
104
    return p_rellotgeEnMarxa;
 
105
}
 
106