kplato

kptintervaledit.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 - 2006 Dag Andersen <danders@get2net.dk>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation;
00007    version 2 of the License.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kptintervaledit.h"
00021 #include "intervalitem.h"
00022 
00023 #include <qpushbutton.h>
00024 #include <qcombobox.h>
00025 #include <qheader.h>
00026 #include <qlabel.h>
00027 #include <qlineedit.h>
00028 #include <qdatetimeedit.h>
00029 #include <qdatetime.h>
00030 #include <qlistview.h>
00031 #include <qpair.h>
00032 #include <qdatetime.h>
00033 
00034 #include <klocale.h>
00035 #include <kdebug.h>
00036 
00037 namespace KPlato
00038 {
00039 
00040 IntervalEdit::IntervalEdit(QWidget *parent, const char *name)
00041     : IntervalEditImpl(parent)
00042 {
00043     //kdDebug()<<k_funcinfo<<endl;
00044 
00045 }
00046 
00047 //--------------------------------------------
00048 IntervalEditImpl::IntervalEditImpl(QWidget *parent)
00049     : IntervalEditBase(parent) {
00050 
00051     intervalList->header()->setStretchEnabled(true);
00052     intervalList->setSortColumn(0);
00053 
00054     connect(bClear, SIGNAL(clicked()), SLOT(slotClearClicked()));
00055     connect(bAddInterval, SIGNAL(clicked()), SLOT(slotAddIntervalClicked()));
00056     connect(intervalList, SIGNAL(selectionChanged(QListViewItem*)), SLOT(slotIntervalSelectionChanged(QListViewItem*)));
00057 
00058 }
00059 
00060 void IntervalEditImpl::slotClearClicked() {
00061     bool c = intervalList->firstChild() != 0;
00062     intervalList->clear();
00063     if (c)
00064         emit changed();
00065 }
00066 
00067 void IntervalEditImpl::slotAddIntervalClicked() {
00068     new IntervalItem(intervalList, startTime->time(), endTime->time());
00069     emit changed();
00070 }
00071 
00072 void IntervalEditImpl::slotIntervalSelectionChanged(QListViewItem *item) {
00073     IntervalItem *ii = dynamic_cast<IntervalItem *>(item);
00074     if (!ii)
00075         return;
00076     startTime->setTime(ii->interval().first);
00077     endTime->setTime(ii->interval().second);
00078 }
00079 
00080 QPtrList<QPair<QTime, QTime> > IntervalEditImpl::intervals() const {
00081     QPtrList<QPair<QTime, QTime> > l;
00082     QListViewItem *i = intervalList->firstChild();
00083     for (; i; i = i->nextSibling()) {
00084         IntervalItem *item = dynamic_cast<IntervalItem*>(i);
00085         if (i)
00086             l.append(new QPair<QTime, QTime>(item->interval().first, item->interval().second));
00087     }
00088     return l;
00089 }
00090 
00091 void IntervalEditImpl::setIntervals(const QPtrList<QPair<QTime, QTime> > &intervals) const {
00092     intervalList->clear();
00093     QPtrListIterator<QPair<QTime, QTime> > it =intervals;
00094     for (; it.current(); ++it) {
00095         new IntervalItem(intervalList, it.current()->first, it.current()->second);
00096     }
00097 }
00098 
00099 }  //KPlato namespace
00100 
00101 #include "kptintervaledit.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys