/* This file is part of the KDE project Copyright (C) 2004 Dag Andersen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; version 2 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kptcalendaredit.h" #include "kptproject.h" #include "kptcalendar.h" #include "kptcalendarpanel.h" #include "kptmap.h" #include "intervalitem.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace KPlato { CalendarEdit::CalendarEdit (TQWidget *parent, const char */*name*/) : CalendarEditBase(parent), m_calendar(0) { clear(); intervalList->header()->setStretchEnabled(true, 0); intervalList->setShowSortIndicator(true); intervalList->setSorting(0); connect (calendarPanel, TQ_SIGNAL(dateChanged(TQDate)), TQ_SLOT(slotDateSelected(TQDate))); connect (calendarPanel, TQ_SIGNAL(weekdaySelected(int)), TQ_SLOT(slotWeekdaySelected(int))); connect(calendarPanel, TQ_SIGNAL(selectionCleared()), TQ_SLOT(slotSelectionCleared())); connect (state, TQ_SIGNAL(activated(int)), TQ_SLOT(slotStateActivated(int))); connect (bClear, TQ_SIGNAL(clicked()), TQ_SLOT(slotClearClicked())); connect (bAddInterval, TQ_SIGNAL(clicked()), TQ_SLOT(slotAddIntervalClicked())); connect (bApply, TQ_SIGNAL(clicked()), TQ_SLOT(slotApplyClicked())); } void CalendarEdit::slotStateActivated(int id) { //kdDebug()<setEnabled(false); endTime->setEnabled(false); bClear->setEnabled(false); bAddInterval->setEnabled(false); intervalList->setEnabled(false); bApply->setEnabled(true); } else if (id == 1) { // non working startTime->setEnabled(false); endTime->setEnabled(false); bClear->setEnabled(false); bAddInterval->setEnabled(false); intervalList->setEnabled(false); bApply->setEnabled(true); } else if (id == 2) { //working startTime->setEnabled(true); endTime->setEnabled(true); bClear->setEnabled(true); bAddInterval->setEnabled(true); intervalList->setEnabled(true); bApply->setEnabled(intervalList->firstChild()); } } void CalendarEdit::slotClearClicked() { //kdDebug()<clear(); bApply->setEnabled(false); } void CalendarEdit::slotAddIntervalClicked() { //kdDebug()<insertItem(new IntervalItem(intervalList, startTime->time(), endTime->time())); bApply->setEnabled(true); } //NOTE: enum Map::State must match combobox state! void CalendarEdit::slotApplyClicked() { //kdDebug()<selectedDates(); for(DateMap::iterator it = dates.begin(); it != dates.end(); ++it) { TQDate date = TQDate::fromString(it.key(), TQt::ISODate); //kdDebug()<findDay(date); if (!calDay) { calDay = new CalendarDay(date); m_calendar->addDay(calDay); } calDay->setState(state->currentItem()); //NOTE!! calDay->clearIntervals(); if (calDay->state() == Map::Working) { for (TQListViewItem *item = intervalList->firstChild(); item; item = item->nextSibling()) { //kdDebug()<(item)->interval().first.toString()<<"-"<(item)->interval().second.toString()<addInterval(static_cast(item)->interval()); } } } IntMap weekdays = calendarPanel->selectedWeekdays(); for(IntMap::iterator it = weekdays.begin(); it != weekdays.end(); ++it) { //kdDebug()<weekday(it.key()-1); weekday->setState(state->currentItem());//NOTE!! weekday->clearIntervals(); if (weekday->state() == Map::Working) { for (TQListViewItem *item = intervalList->firstChild(); item; item = item->nextSibling()) { //kdDebug()<(item)->interval().first.toString()<<"-"<(item)->interval().second.toString()<addInterval(static_cast(item)->interval()); } } } calendarPanel->markSelected(state->currentItem()); //NOTE!! emit applyClicked(); slotCheckAllFieldsFilled(); } void CalendarEdit::slotCheckAllFieldsFilled() { //kdDebug()<currentItem() == 0 /*undefined*/ || state->currentItem() == 1 /*Non-working*/|| (state->currentItem() == 2 /*Working*/ && intervalList->firstChild())) { emit obligatedFieldsFilled(true); } else if (state->currentItem() == 2 && !intervalList->firstChild()) { emit obligatedFieldsFilled(false); } } void CalendarEdit::setCalendar(Calendar *cal) { m_calendar = cal; clear(); calendarPanel->setCalendar(cal); } void CalendarEdit::clear() { clearPanel(); clearEditPart(); } void CalendarEdit::clearPanel() { calendarPanel->clear(); } void CalendarEdit::clearEditPart() { day->setEnabled(true); intervalList->clear(); intervalList->setEnabled(false); startTime->setEnabled(false); startTime->setTime(TQTime(8, 0, 0)); //FIXME endTime->setEnabled(false); endTime->setTime(TQTime(16, 0, 0)); //FIXME bAddInterval->setEnabled(false); bClear->setEnabled(false); bApply->setEnabled(false); state->setEnabled(false); } void CalendarEdit::slotDateSelected(TQDate date) { if (m_calendar == 0) return; //kdDebug()<clear(); state->insertItem(i18n("Undefined")); state->insertItem(i18n("Non-working")); state->insertItem(i18n("Working")); CalendarDay *calDay = m_calendar->findDay(date); state->setEnabled(true); if (calDay) { TQPtrListIterator > it = calDay->workingIntervals(); for (; it.current(); ++it) { IntervalItem *item = new IntervalItem(intervalList, it.current()->first, it.current()->second); intervalList->insertItem(item); } if (calDay->state() == Map::Working) { //kdDebug()<setCurrentItem(2); slotStateActivated(2); bApply->setEnabled(calDay->workingIntervals().count() > 0); } else if (calDay->state() == Map::NonWorking){ //kdDebug()<setCurrentItem(1); slotStateActivated(1); bApply->setEnabled(true); } else { //kdDebug()<setCurrentItem(0); slotStateActivated(0); bApply->setEnabled(true); } } else { // default state->setCurrentItem(0); slotStateActivated(0); bApply->setEnabled(true); } } void CalendarEdit::slotWeekdaySelected(int day_/* 1..7 */) { if (m_calendar == 0 || day_ < 1 || day_ > 7) { kdError()<weekday(day_-1); // 0..6 if (!calDay) { kdError()<clear(); state->insertItem(i18n("Undefined")); state->insertItem(i18n("Non-working")); state->insertItem(i18n("Working")); TQPtrListIterator > it = calDay->workingIntervals(); for (; it.current(); ++it) { IntervalItem *item = new IntervalItem(intervalList, it.current()->first, it.current()->second); intervalList->insertItem(item); } state->setEnabled(true); if (calDay->state() == Map::Working) { //kdDebug()<setCurrentItem(2); slotStateActivated(2); bApply->setEnabled(calDay->workingIntervals().count() > 0); } else if (calDay->state() == Map::NonWorking) { //kdDebug()<setCurrentItem(1); slotStateActivated(1); bApply->setEnabled(true); } else { //kdDebug()<setCurrentItem(0); slotStateActivated(0); bApply->setEnabled(true); } } void CalendarEdit::slotSelectionCleared() { clearEditPart(); } } //KPlato namespace #include "kptcalendaredit.moc"