kplato

kptintervaledit.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 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 <qlabel.h>
00026 #include <qlineedit.h>
00027 #include <qdatetimeedit.h>
00028 #include <qdatetime.h>
00029 #include <qlistview.h>
00030 
00031 #include <klocale.h>
00032 #include <kdebug.h>
00033 
00034 namespace KPlato
00035 {
00036 
00037 IntervalEdit::IntervalEdit(const QPtrList<QPair<QTime, QTime> > &intervals, QWidget *parent, const char *name)
00038     : KDialogBase( Swallow, i18n("Edit Interval"), Ok|Cancel, Ok, parent, name, true, true)
00039 {
00040     //kdDebug()<<k_funcinfo<<endl;
00041     dia = new IntervalEditImpl(intervals, this);
00042 
00043     setMainWidget(dia);
00044     enableButtonOK(false);
00045 
00046     connect(dia, SIGNAL(obligatedFieldsFilled(bool) ), SLOT(enableButtonOK(bool)));
00047     connect(dia, SIGNAL(enableButtonOk(bool)), SLOT(enableButtonOK(bool)));
00048 }
00049 
00050 QPtrList<QPair<QTime, QTime> > IntervalEdit::intervals() const {
00051     return dia->intervals();
00052 }
00053 
00054 
00055 IntervalEditImpl::IntervalEditImpl(const QPtrList<QPair<QTime, QTime> > &intervals, QWidget *parent)
00056     : IntervalEditBase(parent) {
00057 
00058     intervalList->setSortColumn(0);
00059     QPtrListIterator<QPair<QTime, QTime> > it = intervals;
00060     for (; it.current(); ++it) {
00061         new IntervalItem(intervalList, it.current()->first, it.current()->second);
00062     }
00063 
00064     connect(bClear, SIGNAL(clicked()), SLOT(slotClearClicked()));
00065     connect(bAddInterval, SIGNAL(clicked()), SLOT(slotAddIntervalClicked()));
00066     connect(intervalList, SIGNAL(selectionChanged(QListViewItem*)), SLOT(slotIntervalSelectionChanged(QListViewItem*)));
00067 
00068 }
00069 
00070 
00071 void IntervalEditImpl::slotEnableButtonOk(bool on) {
00072     emit enableButtonOk(on);
00073 }
00074 
00075 void IntervalEditImpl::slotCheckAllFieldsFilled() {
00076     emit obligatedFieldsFilled(true); //FIXME
00077 }
00078 
00079 void IntervalEditImpl::slotClearClicked() {
00080     intervalList->clear();
00081 }
00082 
00083 void IntervalEditImpl::slotAddIntervalClicked() {
00084     new IntervalItem(intervalList, startTime->time(), endTime->time());
00085     slotEnableButtonOk(true);
00086 }
00087 
00088 void IntervalEditImpl::slotIntervalSelectionChanged(QListViewItem *item) {
00089     IntervalItem *ii = dynamic_cast<IntervalItem *>(item);
00090     if (!ii)
00091         return;
00092     startTime->setTime(ii->interval().first);
00093     endTime->setTime(ii->interval().second);
00094 }
00095 
00096 QPtrList<QPair<QTime, QTime> > IntervalEditImpl::intervals() const {
00097     QPtrList<QPair<QTime, QTime> > l;
00098     QListViewItem *i = intervalList->firstChild();
00099     for (; i; i = i->nextSibling()) {
00100         IntervalItem *item = dynamic_cast<IntervalItem*>(i);
00101         if (i)
00102             l.append(new QPair<QTime, QTime>(item->interval().first, item->interval().second));
00103     }
00104     return l;
00105 }
00106 
00107 }  //KPlato namespace
00108 
00109 #include "kptintervaledit.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys