kwave  18.07.70
HMSTimeWidget.cpp
Go to the documentation of this file.
1 /*************************************************************************
2  HMSTimeWidget.cpp - widget for setting a time in hours, minutes, seconds
3  -------------------
4  begin : Sat Sep 06 2003
5  copyright : (C) 2003 by Thomas Eschenbacher
6  email : Thomas.Eschenbacher@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "config.h"
19 
20 #include <limits.h>
21 
22 #include "libkwave/Utils.h"
23 
24 #include "libgui/HMSTimeWidget.h"
25 
26 //***************************************************************************
28  :QWidget(parent), Ui::HMSTimeWidgetBase(),
29  m_time(0), m_limit(INT_MAX)
30 {
31  setupUi(this);
33  connect();
34 }
35 
36 //***************************************************************************
38 {
39 }
40 
41 //***************************************************************************
43 {
44  return m_time;
45 }
46 
47 //***************************************************************************
49 {
50  if (value < 0) value = 0;
51  if (Kwave::toUint(value) > m_limit) value = m_limit;
52  m_time = value;
53 
54  const int seconds = (m_time % 60);
55  const int minutes = (m_time / 60) % 60;
56  const int hours = (m_time / (60*60));
57 
58  sbHours->setValue(hours);
59  sbMinutes->setValue(minutes);
60  sbSeconds->setValue(seconds);
61 }
62 
63 //***************************************************************************
64 void Kwave::HMSTimeWidget::setLimit(unsigned int limit)
65 {
66  Q_ASSERT(limit <= INT_MAX);
67  if (limit > INT_MAX) limit = INT_MAX;
68  if (limit < m_limit) {
69  m_limit = limit;
71  } else {
72  m_limit = limit;
73  }
74 }
75 
76 //***************************************************************************
78 {
79  // get current time and correct wrap-overs
80  int seconds = sbSeconds->value();
81  int minutes = sbMinutes->value();
82  int hours = sbHours->value();
83 
84  if (seconds < 0) {
85  seconds = 59;
86  minutes--;
87  }
88  if (minutes < 0) {
89  minutes = 59;
90  hours--;
91  }
92  if (hours < 0) {
93  hours = 0;
94  minutes = 0;
95  seconds = 0;
96  }
97 
98  Q_ASSERT((hours >= 0) && (minutes >= 0) && (seconds >= 0));
99  unsigned int time = seconds + (minutes + (hours * 60L)) * 60L;
100 
101  bool changed = (time != m_time);
102 
103  disconnect();
104  setValue(time);
105  connect();
106 
107  if (changed) emit valueChanged(m_time); // emit the change
108 }
109 
110 //***************************************************************************
112 {
113  QObject::connect(sbSeconds, SIGNAL(valueChanged(int)),
114  this, SLOT(timeChanged(int)));
115  QObject::connect(sbMinutes, SIGNAL(valueChanged(int)),
116  this, SLOT(timeChanged(int)));
117  QObject::connect(sbHours, SIGNAL(valueChanged(int)),
118  this, SLOT(timeChanged(int)));
119 }
120 
121 //***************************************************************************
123 {
124  // disconnect the time controls
125  QObject::disconnect(sbSeconds, SIGNAL(valueChanged(int)),
126  this, SLOT(timeChanged(int)));
127  QObject::disconnect(sbMinutes, SIGNAL(valueChanged(int)),
128  this, SLOT(timeChanged(int)));
129  QObject::disconnect(sbHours, SIGNAL(valueChanged(int)),
130  this, SLOT(timeChanged(int)));
131 }
132 
133 //***************************************************************************
134 //***************************************************************************
HMSTimeWidget(QWidget *parent)
virtual void setValue(int value)
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
virtual void setLimit(unsigned int limit)
unsigned int m_limit
Definition: HMSTimeWidget.h:78
unsigned int m_time
Definition: HMSTimeWidget.h:75
unsigned int toUint(T x)
Definition: Utils.h:109
void valueChanged(int value)