20#include "kptcalendaredit.h"
21#include "kptproject.h"
22#include "kptcalendar.h"
23#include "kptcalendarpanel.h"
25#include "intervalitem.h"
27#include <tqbuttongroup.h>
29#include <tqpushbutton.h>
30#include <tqradiobutton.h>
31#include <tqcombobox.h>
33#include <tqtextedit.h>
34#include <tqlineedit.h>
35#include <tqdatetimeedit.h>
36#include <tqdatetime.h>
37#include <tqtabwidget.h>
38#include <tqtextbrowser.h>
42#include <tdeabc/addressee.h>
43#include <tdeabc/addresseedialog.h>
52CalendarEdit::CalendarEdit (TQWidget *parent,
const char *)
53 : CalendarEditBase(parent),
58 intervalList->header()->setStretchEnabled(
true, 0);
59 intervalList->setShowSortIndicator(
true);
60 intervalList->setSorting(0);
62 connect (calendarPanel, TQ_SIGNAL(dateChanged(TQDate)), TQ_SLOT(slotDateSelected(TQDate)));
63 connect (calendarPanel, TQ_SIGNAL(weekdaySelected(
int)), TQ_SLOT(slotWeekdaySelected(
int)));
64 connect(calendarPanel, TQ_SIGNAL(selectionCleared()), TQ_SLOT(slotSelectionCleared()));
66 connect (state, TQ_SIGNAL(activated(
int)), TQ_SLOT(slotStateActivated(
int)));
67 connect (bClear, TQ_SIGNAL(clicked()), TQ_SLOT(slotClearClicked()));
68 connect (bAddInterval, TQ_SIGNAL(clicked()), TQ_SLOT(slotAddIntervalClicked()));
70 connect (bApply, TQ_SIGNAL(clicked()), TQ_SLOT(slotApplyClicked()));
73void CalendarEdit::slotStateActivated(
int id) {
76 startTime->setEnabled(
false);
77 endTime->setEnabled(
false);
78 bClear->setEnabled(
false);
79 bAddInterval->setEnabled(
false);
80 intervalList->setEnabled(
false);
81 bApply->setEnabled(
true);
83 startTime->setEnabled(
false);
84 endTime->setEnabled(
false);
85 bClear->setEnabled(
false);
86 bAddInterval->setEnabled(
false);
87 intervalList->setEnabled(
false);
88 bApply->setEnabled(
true);
90 startTime->setEnabled(
true);
91 endTime->setEnabled(
true);
92 bClear->setEnabled(
true);
93 bAddInterval->setEnabled(
true);
94 intervalList->setEnabled(
true);
95 bApply->setEnabled(intervalList->firstChild());
99void CalendarEdit::slotClearClicked() {
101 intervalList->clear();
102 bApply->setEnabled(
false);
104void CalendarEdit::slotAddIntervalClicked() {
106 intervalList->insertItem(
new IntervalItem(intervalList, startTime->time(), endTime->time()));
107 bApply->setEnabled(
true);
111void CalendarEdit::slotApplyClicked() {
113 DateMap dates = calendarPanel->selectedDates();
114 for(DateMap::iterator it = dates.begin(); it != dates.end(); ++it) {
115 TQDate date = TQDate::fromString(it.key(), TQt::ISODate);
117 CalendarDay *calDay = m_calendar->findDay(date);
119 calDay =
new CalendarDay(date);
120 m_calendar->addDay(calDay);
122 calDay->setState(state->currentItem());
123 calDay->clearIntervals();
124 if (calDay->state() == Map::Working) {
125 for (TQListViewItem *item = intervalList->firstChild(); item; item = item->nextSibling()) {
127 calDay->addInterval(
static_cast<IntervalItem *
>(item)->interval());
132 IntMap weekdays = calendarPanel->selectedWeekdays();
133 for(IntMap::iterator it = weekdays.begin(); it != weekdays.end(); ++it) {
135 CalendarDay *weekday = m_calendar->weekday(it.key()-1);
136 weekday->setState(state->currentItem());
137 weekday->clearIntervals();
138 if (weekday->state() == Map::Working) {
139 for (TQListViewItem *item = intervalList->firstChild(); item; item = item->nextSibling()) {
141 weekday->addInterval(
static_cast<IntervalItem *
>(item)->interval());
146 calendarPanel->markSelected(state->currentItem());
148 slotCheckAllFieldsFilled();
151void CalendarEdit::slotCheckAllFieldsFilled() {
153 if (state->currentItem() == 0 ||
154 state->currentItem() == 1 ||
155 (state->currentItem() == 2 && intervalList->firstChild()))
157 emit obligatedFieldsFilled(
true);
159 else if (state->currentItem() == 2 && !intervalList->firstChild())
161 emit obligatedFieldsFilled(
false);
165void CalendarEdit::setCalendar(Calendar *cal) {
168 calendarPanel->setCalendar(cal);
171void CalendarEdit::clear() {
176void CalendarEdit::clearPanel() {
177 calendarPanel->clear();
180void CalendarEdit::clearEditPart() {
181 day->setEnabled(
true);
182 intervalList->clear();
183 intervalList->setEnabled(
false);
184 startTime->setEnabled(
false);
185 startTime->setTime(TQTime(8, 0, 0));
186 endTime->setEnabled(
false);
187 endTime->setTime(TQTime(16, 0, 0));
189 bAddInterval->setEnabled(
false);
190 bClear->setEnabled(
false);
191 bApply->setEnabled(
false);
192 state->setEnabled(
false);
195void CalendarEdit::slotDateSelected(TQDate date) {
201 state->insertItem(i18n(
"Undefined"));
202 state->insertItem(i18n(
"Non-working"));
203 state->insertItem(i18n(
"Working"));
205 CalendarDay *calDay = m_calendar->findDay(date);
206 state->setEnabled(
true);
208 TQPtrListIterator<TQPair<TQTime, TQTime> > it = calDay->workingIntervals();
209 for (; it.current(); ++it) {
210 IntervalItem *item =
new IntervalItem(intervalList, it.current()->first, it.current()->second);
211 intervalList->insertItem(item);
213 if (calDay->state() == Map::Working) {
215 state->setCurrentItem(2);
216 slotStateActivated(2);
217 bApply->setEnabled(calDay->workingIntervals().count() > 0);
218 }
else if (calDay->state() == Map::NonWorking){
220 state->setCurrentItem(1);
221 slotStateActivated(1);
222 bApply->setEnabled(
true);
225 state->setCurrentItem(0);
226 slotStateActivated(0);
227 bApply->setEnabled(
true);
231 state->setCurrentItem(0);
232 slotStateActivated(0);
233 bApply->setEnabled(
true);
237void CalendarEdit::slotWeekdaySelected(
int day_) {
238 if (m_calendar == 0 || day_ < 1 || day_ > 7) {
239 kdError()<<k_funcinfo<<
"No calendar or weekday ("<<day_<<
") not defined!"<<endl;
244 CalendarDay *calDay = m_calendar->weekday(day_-1);
246 kdError()<<k_funcinfo<<
"Weekday ("<<day_<<
") not defined!"<<endl;
250 state->insertItem(i18n(
"Undefined"));
251 state->insertItem(i18n(
"Non-working"));
252 state->insertItem(i18n(
"Working"));
253 TQPtrListIterator<TQPair<TQTime, TQTime> > it = calDay->workingIntervals();
254 for (; it.current(); ++it) {
255 IntervalItem *item =
new IntervalItem(intervalList, it.current()->first, it.current()->second);
256 intervalList->insertItem(item);
258 state->setEnabled(
true);
259 if (calDay->state() == Map::Working) {
261 state->setCurrentItem(2);
262 slotStateActivated(2);
263 bApply->setEnabled(calDay->workingIntervals().count() > 0);
264 }
else if (calDay->state() == Map::NonWorking) {
266 state->setCurrentItem(1);
267 slotStateActivated(1);
268 bApply->setEnabled(
true);
271 state->setCurrentItem(0);
272 slotStateActivated(0);
273 bApply->setEnabled(
true);
277void CalendarEdit::slotSelectionCleared() {
283#include "kptcalendaredit.moc"