~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to kalarm/lib/timeedit.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include "kalarm.h"
22
22
 
23
 
#include <kglobal.h>
24
 
#include <klocale.h>
25
 
 
26
23
#include "combobox.h"
27
24
#include "timespinbox.h"
28
25
#include "timeedit.moc"
29
26
 
 
27
#include <kglobal.h>
 
28
#include <klocale.h>
 
29
 
30
30
 
31
31
TimeEdit::TimeEdit(QWidget* parent)
32
 
        : KHBox(parent),
33
 
          mAmPm(0),
34
 
          mAmIndex(-1),
35
 
          mPmIndex(-1),
36
 
          mReadOnly(false)
 
32
    : KHBox(parent),
 
33
      mAmPm(0),
 
34
      mAmIndex(-1),
 
35
      mPmIndex(-1),
 
36
      mReadOnly(false)
37
37
{
38
 
        bool use12hour = KGlobal::locale()->use12Clock();
39
 
        mSpinBox = new TimeSpinBox(!use12hour, this);
40
 
        mSpinBox->setFixedSize(mSpinBox->sizeHint());
41
 
        connect(mSpinBox, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
42
 
        if (use12hour)
43
 
        {
44
 
                mAmPm = new ComboBox(this);
45
 
                setAmPmCombo(1, 1);     // add "am" and "pm" options to the combo box
46
 
                mAmPm->setFixedSize(mAmPm->sizeHint());
47
 
                connect(mAmPm, SIGNAL(highlighted(int)), SLOT(slotAmPmChanged(int)));
48
 
        }
 
38
    bool use12hour = KGlobal::locale()->use12Clock();
 
39
    mSpinBox = new TimeSpinBox(!use12hour, this);
 
40
    mSpinBox->setFixedSize(mSpinBox->sizeHint());
 
41
    connect(mSpinBox, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)));
 
42
    if (use12hour)
 
43
    {
 
44
        mAmPm = new ComboBox(this);
 
45
        setAmPmCombo(1, 1);     // add "am" and "pm" options to the combo box
 
46
        mAmPm->setFixedSize(mAmPm->sizeHint());
 
47
        connect(mAmPm, SIGNAL(highlighted(int)), SLOT(slotAmPmChanged(int)));
 
48
    }
49
49
}
50
50
 
51
51
void TimeEdit::setReadOnly(bool ro)
52
52
{
53
 
        if (ro != mReadOnly)
54
 
        {
55
 
                mReadOnly = ro;
56
 
                mSpinBox->setReadOnly(ro);
57
 
                if (mAmPm)
58
 
                        mAmPm->setReadOnly(ro);
59
 
        }
 
53
    if (ro != mReadOnly)
 
54
    {
 
55
        mReadOnly = ro;
 
56
        mSpinBox->setReadOnly(ro);
 
57
        if (mAmPm)
 
58
            mAmPm->setReadOnly(ro);
 
59
    }
60
60
}
61
61
 
62
62
int TimeEdit::value() const
63
63
{
64
 
        return mSpinBox->value();
 
64
    return mSpinBox->value();
65
65
}
66
66
 
67
67
bool TimeEdit::isValid() const
68
68
{
69
 
        return mSpinBox->isValid();
 
69
    return mSpinBox->isValid();
70
70
}
71
71
 
72
72
/******************************************************************************
76
76
 */
77
77
void TimeEdit::setValid(bool valid)
78
78
{
79
 
        bool oldValid = mSpinBox->isValid();
80
 
        if ((valid  &&  !oldValid)
81
 
        ||  (!valid  &&  oldValid))
82
 
        {
83
 
                mSpinBox->setValid(valid);
84
 
                if (mAmPm)
85
 
                        mAmPm->setCurrentIndex(0);
86
 
        }
 
79
    bool oldValid = mSpinBox->isValid();
 
80
    if ((valid  &&  !oldValid)
 
81
    ||  (!valid  &&  oldValid))
 
82
    {
 
83
        mSpinBox->setValid(valid);
 
84
        if (mAmPm)
 
85
            mAmPm->setCurrentIndex(0);
 
86
    }
87
87
}
88
88
 
89
89
/******************************************************************************
91
91
 */
92
92
void TimeEdit::setValue(int minutes)
93
93
{
94
 
        if (mAmPm)
95
 
        {
96
 
                int i = (minutes >= 720) ? mPmIndex : mAmIndex;
97
 
                mAmPm->setCurrentIndex(i >= 0 ? i : 0);
98
 
        }
99
 
        mSpinBox->setValue(minutes);
 
94
    if (mAmPm)
 
95
    {
 
96
        int i = (minutes >= 720) ? mPmIndex : mAmIndex;
 
97
        mAmPm->setCurrentIndex(i >= 0 ? i : 0);
 
98
    }
 
99
    mSpinBox->setValue(minutes);
100
100
}
101
101
 
102
102
bool TimeEdit::wrapping() const
103
103
{
104
 
        return mSpinBox->wrapping();
 
104
    return mSpinBox->wrapping();
105
105
}
106
106
 
107
107
void TimeEdit::setWrapping(bool on)
108
108
{
109
 
        mSpinBox->setWrapping(on);
 
109
    mSpinBox->setWrapping(on);
110
110
}
111
111
 
112
112
int TimeEdit::minimum() const
113
113
{
114
 
        return mSpinBox->minimum();
 
114
    return mSpinBox->minimum();
115
115
}
116
116
 
117
117
int TimeEdit::maximum() const
118
118
{
119
 
        return mSpinBox->maximum();
 
119
    return mSpinBox->maximum();
120
120
}
121
121
 
122
122
void TimeEdit::setMinimum(int minutes)
123
123
{
124
 
        if (mAmPm)
125
 
                setAmPmCombo((minutes < 720 ? 1 : 0), -1);   // insert/remove "am" in combo box
126
 
        mSpinBox->setMinimum(minutes);
 
124
    if (mAmPm)
 
125
        setAmPmCombo((minutes < 720 ? 1 : 0), -1);   // insert/remove "am" in combo box
 
126
    mSpinBox->setMinimum(minutes);
127
127
}
128
128
 
129
129
void TimeEdit::setMaximum(int minutes)
130
130
{
131
 
        if (mAmPm)
132
 
                setAmPmCombo(-1, (minutes < 720 ? 0 : 1));   // insert/remove "pm" in combo box
133
 
        mSpinBox->setMaximum(minutes);
 
131
    if (mAmPm)
 
132
        setAmPmCombo(-1, (minutes < 720 ? 0 : 1));   // insert/remove "pm" in combo box
 
133
    mSpinBox->setMaximum(minutes);
134
134
}
135
135
 
136
136
/******************************************************************************
138
138
 */
139
139
void TimeEdit::slotValueChanged(int value)
140
140
{
141
 
        if (mAmPm)
142
 
        {
143
 
                bool pm = (mAmPm->currentIndex() == mPmIndex);
144
 
                if (pm  &&  value < 720)
145
 
                        mAmPm->setCurrentIndex(mAmIndex);
146
 
                else if (!pm  &&  value >= 720)
147
 
                        mAmPm->setCurrentIndex(mPmIndex);
148
 
        }
149
 
        emit valueChanged(value);
 
141
    if (mAmPm)
 
142
    {
 
143
        bool pm = (mAmPm->currentIndex() == mPmIndex);
 
144
        if (pm  &&  value < 720)
 
145
            mAmPm->setCurrentIndex(mAmIndex);
 
146
        else if (!pm  &&  value >= 720)
 
147
            mAmPm->setCurrentIndex(mPmIndex);
 
148
    }
 
149
    emit valueChanged(value);
150
150
}
151
151
 
152
152
/******************************************************************************
155
155
 */
156
156
void TimeEdit::slotAmPmChanged(int item)
157
157
{
158
 
        if (mAmPm)
159
 
        {
160
 
                int value = mSpinBox->value();
161
 
                if (item == mPmIndex  &&  value < 720)
162
 
                        mSpinBox->setValue(value + 720);
163
 
                else if (item != mPmIndex  &&  value >= 720)
164
 
                        mSpinBox->setValue(value - 720);
165
 
        }
 
158
    if (mAmPm)
 
159
    {
 
160
        int value = mSpinBox->value();
 
161
        if (item == mPmIndex  &&  value < 720)
 
162
            mSpinBox->setValue(value + 720);
 
163
        else if (item != mPmIndex  &&  value >= 720)
 
164
            mSpinBox->setValue(value - 720);
 
165
    }
166
166
}
167
167
 
168
168
/******************************************************************************
170
170
 */
171
171
void TimeEdit::setAmPmCombo(int am, int pm)
172
172
{
173
 
        if (am > 0  &&  mAmIndex < 0)
174
 
        {
175
 
                // Insert "am"
176
 
                mAmIndex = 0;
177
 
                mAmPm->insertItem(mAmIndex, i18nc("@item:inlistbox Morning, as in 2am", "am"));
178
 
                if (mPmIndex >= 0)
179
 
                        mPmIndex = 1;
180
 
                mAmPm->setCurrentIndex(mPmIndex >= 0 ? mPmIndex : mAmIndex);
181
 
        }
182
 
        else if (am == 0  &&  mAmIndex >= 0)
183
 
        {
184
 
                // Remove "am"
185
 
                mAmPm->removeItem(mAmIndex);
186
 
                mAmIndex = -1;
187
 
                if (mPmIndex >= 0)
188
 
                        mPmIndex = 0;
189
 
                mAmPm->setCurrentIndex(mPmIndex);
190
 
        }
 
173
    if (am > 0  &&  mAmIndex < 0)
 
174
    {
 
175
        // Insert "am"
 
176
        mAmIndex = 0;
 
177
        mAmPm->insertItem(mAmIndex, i18nc("@item:inlistbox Morning, as in 2am", "am"));
 
178
        if (mPmIndex >= 0)
 
179
            mPmIndex = 1;
 
180
        mAmPm->setCurrentIndex(mPmIndex >= 0 ? mPmIndex : mAmIndex);
 
181
    }
 
182
    else if (am == 0  &&  mAmIndex >= 0)
 
183
    {
 
184
        // Remove "am"
 
185
        mAmPm->removeItem(mAmIndex);
 
186
        mAmIndex = -1;
 
187
        if (mPmIndex >= 0)
 
188
            mPmIndex = 0;
 
189
        mAmPm->setCurrentIndex(mPmIndex);
 
190
    }
191
191
 
192
 
        if (pm > 0  &&  mPmIndex < 0)
193
 
        {
194
 
                // Insert "pm"
195
 
                mPmIndex = mAmIndex + 1;
196
 
                mAmPm->insertItem(mPmIndex, i18nc("@item:inlistbox Afternoon, as in 2pm", "pm"));
197
 
                if (mAmIndex < 0)
198
 
                        mAmPm->setCurrentIndex(mPmIndex);
199
 
        }
200
 
        else if (pm == 0  &&  mPmIndex >= 0)
201
 
        {
202
 
                // Remove "pm"
203
 
                mAmPm->removeItem(mPmIndex);
204
 
                mPmIndex = -1;
205
 
                mAmPm->setCurrentIndex(mAmIndex);
206
 
        }
 
192
    if (pm > 0  &&  mPmIndex < 0)
 
193
    {
 
194
        // Insert "pm"
 
195
        mPmIndex = mAmIndex + 1;
 
196
        mAmPm->insertItem(mPmIndex, i18nc("@item:inlistbox Afternoon, as in 2pm", "pm"));
 
197
        if (mAmIndex < 0)
 
198
            mAmPm->setCurrentIndex(mPmIndex);
 
199
    }
 
200
    else if (pm == 0  &&  mPmIndex >= 0)
 
201
    {
 
202
        // Remove "pm"
 
203
        mAmPm->removeItem(mPmIndex);
 
204
        mPmIndex = -1;
 
205
        mAmPm->setCurrentIndex(mAmIndex);
 
206
    }
207
207
}
 
208
 
 
209
// vim: et sw=4: