/* This file is part of the KDE project Copyright (C) 2004 - 2006 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 "kptstandardworktimedialog.h" #include "kptduration.h" #include "kptproject.h" #include "kptcalendar.h" #include "kptcommand.h" #include "kptintervaledit.h" #include "kptpart.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace KPlato { class WeekdayListItem : public TDEListViewItem { public: WeekdayListItem(Calendar *cal, int wd, TDEListView *parent, TQString name, TDEListViewItem *after) : TDEListViewItem(parent, after), original(cal->weekday(wd)), calendar(cal), weekday(wd) { setText(0, name); day = new CalendarDay(original); if (day->state() == Map::NonWorking) { setHours(); } else { setText(1, TDEGlobal::locale()->formatNumber(day->duration().toDouble(Duration::Unit_h))); } } ~WeekdayListItem() { delete day; } void setHours() { setText(1, "-"); day->clearIntervals(); } void setIntervals(TQPtrList > intervals) { day->setIntervals(intervals); setText(1, TDEGlobal::locale()->formatNumber(day->duration().toDouble(Duration::Unit_h))); } void setState(int st) { day->setState(st+1); } KCommand *save(Part *part) { KCommand *cmd=0; if (*original != *day) { cmd = new CalendarModifyWeekdayCmd(part, calendar, weekday, day); day = 0; } return cmd; } CalendarDay *day; CalendarDay *original; Calendar *calendar; int weekday; }; StandardWorktimeDialog::StandardWorktimeDialog(Project &p, TQWidget *parent, const char *name) : KDialogBase( Swallow, i18n("Standard Worktime"), Ok|Cancel, Ok, parent, name, true, true), project(p) { //kdDebug()<year() != dia->inYear()) { if (cmd == 0) cmd = new KMacroCommand(n); cmd->addCommand(new ModifyStandardWorktimeYearCmd(part, m_original, m_original->year(), dia->inYear())); } if (m_original->month() != dia->inMonth()) { if (cmd == 0) cmd = new KMacroCommand(n); cmd->addCommand(new ModifyStandardWorktimeMonthCmd(part, m_original, m_original->month(), dia->inMonth())); } if (m_original->week() != dia->inWeek()) { if (cmd == 0) cmd = new KMacroCommand(n); cmd->addCommand(new ModifyStandardWorktimeWeekCmd(part, m_original, m_original->week(), dia->inWeek())); } if (m_original->day() != dia->inDay()) { if (cmd == 0) cmd = new KMacroCommand(n); cmd->addCommand(new ModifyStandardWorktimeDayCmd(part, m_original, m_original->day(), dia->inDay())); } TQListViewItem *item = dia->weekdayList->firstChild(); for (; item; item = item->nextSibling()) { KCommand *c = static_cast(item)->save(part); if (c) { if (cmd == 0) cmd = new KMacroCommand(n); cmd->addCommand(c); } } return cmd; } void StandardWorktimeDialog::slotOk() { accept(); } StandardWorktimeDialogImpl::StandardWorktimeDialogImpl(StandardWorktime *std, TQWidget *parent) : StandardWorktimeDialogBase(parent), m_std(std) { if (!std) { m_std = new StandardWorktime(); } TQBoxLayout *l = new TQVBoxLayout(intervalBox); m_intervalEdit = new IntervalEdit(intervalBox); l->addWidget(m_intervalEdit); m_year = m_std->year(); m_month = m_std->month(); m_week = m_std->week(); m_day = m_std->day(); year->setValue(m_year); month->setValue(m_month); week->setValue(m_week); day->setValue(m_day); weekdayList->setSorting(-1); weekdayList->header()->setStretchEnabled(true); const KCalendarSystem * cs = TDEGlobal::locale()->calendar(); Calendar *cal = m_std->calendar(); if (cal) { WeekdayListItem *item = 0; for (int i = 0; i < 7; ++i) { CalendarDay *day = cal->weekday(i); if (day == 0) { continue; } item = new WeekdayListItem(cal, i, weekdayList, cs->weekDayName(i+1), item); weekdayList->insertItem(item); } } connect(year, TQ_SIGNAL(valueChanged(double)), TQ_SLOT(slotYearChanged(double))); connect(month, TQ_SIGNAL(valueChanged(double)), TQ_SLOT(slotMonthChanged(double))); connect(week, TQ_SIGNAL(valueChanged(double)), TQ_SLOT(slotWeekChanged(double))); connect(day, TQ_SIGNAL(valueChanged(double)), TQ_SLOT(slotDayChanged(double))); connect(m_intervalEdit, TQ_SIGNAL(changed()), TQ_SLOT(slotIntervalChanged())); connect(bApply, TQ_SIGNAL(clicked()), TQ_SLOT(slotApplyClicked())); connect(weekdayList, TQ_SIGNAL(selectionChanged()), TQ_SLOT(slotWeekdaySelected())); connect(state, TQ_SIGNAL(activated(int)), TQ_SLOT(slotStateChanged(int))); if (weekdayList->firstChild()) { weekdayList->setSelected(weekdayList->firstChild(), true); weekdayList->setCurrentItem(weekdayList->firstChild()); } } void StandardWorktimeDialogImpl::slotEnableButtonApply(bool on) { bApply->setEnabled(on); } void StandardWorktimeDialogImpl::slotEnableButtonOk(bool on) { emit enableButtonOk(on); } void StandardWorktimeDialogImpl::slotCheckAllFieldsFilled() { emit obligatedFieldsFilled(true); } void StandardWorktimeDialogImpl::slotYearChanged(double value) { //kdDebug()<value() > value) month->setValue(value); slotEnableButtonOk(true); } void StandardWorktimeDialogImpl::slotMonthChanged(double value) { m_month = value; if (year->value() < value) year->setValue(value); if (week->value() > value) week->setValue(value); slotEnableButtonOk(true); } void StandardWorktimeDialogImpl::slotWeekChanged(double value) { m_week = value; if (month->value() < value) month->setValue(value); if (day->value() > value) day->setValue(value); slotEnableButtonOk(true); } void StandardWorktimeDialogImpl::slotDayChanged(double value) { m_day = value; if (week->value() < value) week->setValue(value); slotEnableButtonOk(true); } void StandardWorktimeDialogImpl::slotIntervalChanged() { //kdDebug()<(item); wd->setState(state->currentItem()); if (state->currentItem() == 0) { wd->setHours(); } else { wd->setIntervals(m_intervalEdit->intervals()); } slotEnableButtonOk(true); } } } void StandardWorktimeDialogImpl::slotWeekdaySelected() { //kdDebug()<currentItem()<firstChild(); for (; item; item = item->nextSibling()) { if (item->isSelected()) { //kdDebug()<text(0)<<" selected"<(item); state->setCurrentItem(wd->day->state()-1); m_intervalEdit->setIntervals(wd->day->workingIntervals()); slotStateChanged(state->currentItem()); break; } } editBox->setEnabled(item != 0); } void StandardWorktimeDialogImpl::slotStateChanged(int st) { //kdDebug()<currentItem()<setEnabled(st == 1); //Working slotEnableButtonApply(st == 0); } } //KPlato namespace #include "kptstandardworktimedialog.moc"