Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[3e4acc]: libgui / HMSTimeWidget.cpp Maximize Restore History

Download this file

HMSTimeWidget.cpp    136 lines (115 with data), 4.4 kB

  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
125
126
127
128
129
130
131
132
133
134
135
/*************************************************************************
HMSTimeWidget.cpp - widget for setting a time in hours, minutes, seconds
-------------------
begin : Sat Sep 06 2003
copyright : (C) 2003 by Thomas Eschenbacher
email : Thomas.Eschenbacher@gmx.de
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include "config.h"
#include <limits.h>
#include <knuminput.h>
#include "HMSTimeWidget.h"
//***************************************************************************
HMSTimeWidget::HMSTimeWidget(QWidget *parent)
:QWidget(parent), Ui::HMSTimeWidgetBase(),
m_time(0), m_limit(INT_MAX)
{
setupUi(this);
setValue(m_time);
connect();
}
//***************************************************************************
HMSTimeWidget::~HMSTimeWidget()
{
}
//***************************************************************************
int HMSTimeWidget::value()
{
return m_time;
}
//***************************************************************************
void HMSTimeWidget::setValue(int value)
{
if (value < 0) value = 0;
if (static_cast<unsigned int>(value) > m_limit) value = m_limit;
m_time = value;
const int seconds = (m_time % 60);
const int minutes = (m_time / 60) % 60;
const int hours = (m_time / (60*60));
sbHours->setValue(hours);
sbMinutes->setValue(minutes);
sbSeconds->setValue(seconds);
}
//***************************************************************************
void HMSTimeWidget::setLimit(unsigned int limit)
{
Q_ASSERT(limit <= INT_MAX);
if (limit > INT_MAX) limit = INT_MAX;
if (limit < m_limit) {
m_limit = limit;
setValue(m_limit);
} else {
m_limit = limit;
}
}
//***************************************************************************
void HMSTimeWidget::timeChanged(int)
{
// get current time and correct wrap-overs
int seconds = sbSeconds->value();
int minutes = sbMinutes->value();
int hours = sbHours->value();
if (seconds < 0) {
seconds = 59;
minutes--;
}
if (minutes < 0) {
minutes = 59;
hours--;
}
if (hours < 0) {
hours = 0;
minutes = 0;
seconds = 0;
}
Q_ASSERT((hours >= 0) && (minutes >= 0) && (seconds >= 0));
unsigned int time = seconds + (minutes + (hours * 60L)) * 60L;
bool changed = (time != m_time);
disconnect();
setValue(time);
connect();
if (changed) emit valueChanged(m_time); // emit the change
}
//***************************************************************************
void HMSTimeWidget::connect()
{
QObject::connect(sbSeconds, SIGNAL(valueChanged(int)),
this, SLOT(timeChanged(int)));
QObject::connect(sbMinutes, SIGNAL(valueChanged(int)),
this, SLOT(timeChanged(int)));
QObject::connect(sbHours, SIGNAL(valueChanged(int)),
this, SLOT(timeChanged(int)));
}
//***************************************************************************
void HMSTimeWidget::disconnect()
{
// disconnect the time controls
QObject::disconnect(sbSeconds, SIGNAL(valueChanged(int)),
this, SLOT(timeChanged(int)));
QObject::disconnect(sbMinutes, SIGNAL(valueChanged(int)),
this, SLOT(timeChanged(int)));
QObject::disconnect(sbHours, SIGNAL(valueChanged(int)),
this, SLOT(timeChanged(int)));
}
//***************************************************************************
#include "HMSTimeWidget.moc"
//***************************************************************************
//***************************************************************************