kplato

kptintervaledit.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 - 2006 Dag Andersen <danders@get2net.dk>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation;
7 version 2 of the License.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kptintervaledit.h"
21#include "intervalitem.h"
22
23#include <tqpushbutton.h>
24#include <tqcombobox.h>
25#include <tqheader.h>
26#include <tqlabel.h>
27#include <tqlineedit.h>
28#include <tqdatetimeedit.h>
29#include <tqdatetime.h>
30#include <tqlistview.h>
31#include <tqpair.h>
32#include <tqdatetime.h>
33
34#include <tdelocale.h>
35#include <kdebug.h>
36
37namespace KPlato
38{
39
40IntervalEdit::IntervalEdit(TQWidget *parent, const char *name)
41 : IntervalEditImpl(parent)
42{
43 //kdDebug()<<k_funcinfo<<endl;
44
45}
46
47//--------------------------------------------
48IntervalEditImpl::IntervalEditImpl(TQWidget *parent)
49 : IntervalEditBase(parent) {
50
51 intervalList->header()->setStretchEnabled(true);
52 intervalList->setSortColumn(0);
53
54 connect(bClear, TQ_SIGNAL(clicked()), TQ_SLOT(slotClearClicked()));
55 connect(bAddInterval, TQ_SIGNAL(clicked()), TQ_SLOT(slotAddIntervalClicked()));
56 connect(intervalList, TQ_SIGNAL(selectionChanged(TQListViewItem*)), TQ_SLOT(slotIntervalSelectionChanged(TQListViewItem*)));
57
58}
59
60void IntervalEditImpl::slotClearClicked() {
61 bool c = intervalList->firstChild() != 0;
62 intervalList->clear();
63 if (c)
64 emit changed();
65}
66
67void IntervalEditImpl::slotAddIntervalClicked() {
68 new IntervalItem(intervalList, startTime->time(), endTime->time());
69 emit changed();
70}
71
72void IntervalEditImpl::slotIntervalSelectionChanged(TQListViewItem *item) {
73 IntervalItem *ii = dynamic_cast<IntervalItem *>(item);
74 if (!ii)
75 return;
76 startTime->setTime(ii->interval().first);
77 endTime->setTime(ii->interval().second);
78}
79
80TQPtrList<TQPair<TQTime, TQTime> > IntervalEditImpl::intervals() const {
81 TQPtrList<TQPair<TQTime, TQTime> > l;
82 TQListViewItem *i = intervalList->firstChild();
83 for (; i; i = i->nextSibling()) {
84 IntervalItem *item = dynamic_cast<IntervalItem*>(i);
85 if (i)
86 l.append(new TQPair<TQTime, TQTime>(item->interval().first, item->interval().second));
87 }
88 return l;
89}
90
91void IntervalEditImpl::setIntervals(const TQPtrList<TQPair<TQTime, TQTime> > &intervals) const {
92 intervalList->clear();
93 TQPtrListIterator<TQPair<TQTime, TQTime> > it =intervals;
94 for (; it.current(); ++it) {
95 new IntervalItem(intervalList, it.current()->first, it.current()->second);
96 }
97}
98
99} //KPlato namespace
100
101#include "kptintervaledit.moc"