00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kptintervaledit.h"
00021 #include "intervalitem.h"
00022
00023 #include <QPushButton>
00024 #include <QComboBox>
00025 #include <QHeaderView>
00026 #include <QLabel>
00027 #include <QLineEdit>
00028 #include <QTreeWidget>
00029 #include <QList>
00030
00031 #include <klocale.h>
00032 #include <kdebug.h>
00033
00034 namespace KPlato
00035 {
00036
00037 IntervalEdit::IntervalEdit(QWidget *parent, const char *name)
00038 : IntervalEditImpl(parent)
00039 {
00040
00041 }
00042
00043
00044
00045 IntervalEditImpl::IntervalEditImpl(QWidget *parent)
00046 : IntervalEditBase(parent) {
00047
00048 intervalList->setSortingEnabled(true);
00049
00050 connect(bClear, SIGNAL(clicked()), SLOT(slotClearClicked()));
00051 connect(bAddInterval, SIGNAL(clicked()), SLOT(slotAddIntervalClicked()));
00052 connect(intervalList, SIGNAL(itemSelectionChanged()), SLOT(slotIntervalSelectionChanged()));
00053
00054 }
00055
00056 void IntervalEditImpl::slotClearClicked() {
00057 bool c = intervalList->topLevelItemCount() > 0;
00058 intervalList->clear();
00059 if (c)
00060 emit changed();
00061 }
00062
00063 void IntervalEditImpl::slotAddIntervalClicked() {
00064 new IntervalItem(intervalList, startTime->time(), endTime->time());
00065 emit changed();
00066 }
00067
00068 void IntervalEditImpl::slotIntervalSelectionChanged() {
00069 QList<QTreeWidgetItem*> lst = intervalList->selectedItems();
00070 if (lst.count() == 0)
00071 return;
00072
00073 IntervalItem *ii = static_cast<IntervalItem *>(lst[0]);
00074 startTime->setTime(ii->interval().first);
00075 endTime->setTime(ii->interval().second);
00076 }
00077
00078 QList<TimeInterval*> IntervalEditImpl::intervals() const {
00079 QList<TimeInterval*> l;
00080 int cnt = intervalList->topLevelItemCount();
00081 for (int i=0; i < cnt; ++i) {
00082 IntervalItem *item = static_cast<IntervalItem*>(intervalList->topLevelItem(i));
00083 l.append(new TimeInterval(item->interval().first, item->interval().second));
00084 }
00085 return l;
00086 }
00087
00088 void IntervalEditImpl::setIntervals(const QList<TimeInterval*> &intervals) const {
00089 intervalList->clear();
00090 foreach (TimeInterval *i, intervals) {
00091 new IntervalItem(intervalList, i->first, i->second);
00092 }
00093 }
00094
00095 }
00096
00097 #include "kptintervaledit.moc"