kplato

kptstandardworktimedialog.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 "kptstandardworktimedialog.h"
00021 #include "kptproject.h"
00022 #include "kptcalendar.h"
00023 #include "kptcommand.h"
00024 #include "kptintervaledit.h"
00025 #include "kptpart.h"
00026 
00027 #include <qpushbutton.h>
00028 #include <qspinbox.h>
00029 #include <qcombobox.h>
00030 #include <qlabel.h>
00031 #include <qlineedit.h>
00032 #include <qdatetimeedit.h>
00033 #include <qdatetime.h>
00034 
00035 #include <kdebug.h>
00036 #include <klocale.h>
00037 #include <knuminput.h>
00038 
00039 namespace KPlato
00040 {
00041 
00042 StandardWorktimeDialog::StandardWorktimeDialog(Project &p, QWidget *parent, const char *name)
00043     : KDialogBase( Swallow, i18n("Standard Worktime"), Ok|Cancel, Ok, parent, name, true, true),
00044       project(p)
00045 {
00046     //kdDebug()<<k_funcinfo<<&p<<endl;
00047     m_original = p.standardWorktime();
00048     dia = new StandardWorktimeDialogImpl(m_original, this);
00049 
00050     setMainWidget(dia);
00051     enableButtonOK(false);
00052 
00053     connect(dia, SIGNAL(obligatedFieldsFilled(bool) ), SLOT(enableButtonOK(bool)));
00054     connect(dia, SIGNAL(enableButtonOk(bool)), SLOT(enableButtonOK(bool)));
00055 }
00056 
00057 KMacroCommand *StandardWorktimeDialog::buildCommand(Part *part) {
00058     kdDebug()<<k_funcinfo<<endl;
00059     QString n = i18n("Modify Standard Worktime");
00060     KMacroCommand *cmd = 0;
00061     if (m_original->year() != dia->inYear()) {
00062         if (cmd == 0) cmd = new KMacroCommand(n);
00063         cmd->addCommand(new ModifyStandardWorktimeYearCmd(part, m_original, m_original->year(), dia->inYear()));
00064     }
00065     if (m_original->month() != dia->inMonth()) {
00066         if (cmd == 0) cmd = new KMacroCommand(n);
00067         cmd->addCommand(new ModifyStandardWorktimeMonthCmd(part, m_original, m_original->month(), dia->inMonth()));
00068     }
00069     if (m_original->week() != dia->inWeek()) {
00070         if (cmd == 0) cmd = new KMacroCommand(n);
00071         cmd->addCommand(new ModifyStandardWorktimeWeekCmd(part, m_original, m_original->week(), dia->inWeek()));
00072     }
00073     if (m_original->day() != dia->inDay()) {
00074         if (cmd == 0) cmd = new KMacroCommand(n);
00075         cmd->addCommand(new ModifyStandardWorktimeDayCmd(part, m_original, m_original->day(), dia->inDay()));
00076     }
00077     return cmd;
00078     
00079 }
00080 
00081 void StandardWorktimeDialog::slotOk() {
00082     accept();
00083 }
00084 
00085 
00086 StandardWorktimeDialogImpl::StandardWorktimeDialogImpl(StandardWorktime *std, QWidget *parent) 
00087     : StandardWorktimeDialogBase(parent),
00088       m_std(std) {
00089     if (!std) {
00090         m_std = new StandardWorktime();
00091     }
00092     m_year = m_std->year();
00093     m_month = m_std->month();
00094     m_week = m_std->week();
00095     m_day = m_std->day();
00096     
00097     year->setValue(m_year);
00098     month->setValue(m_month);
00099     week->setValue(m_week);
00100     day->setValue(m_day);
00101 
00102     connect(year, SIGNAL(valueChanged(double)), SLOT(slotYearChanged(double)));
00103     connect(month, SIGNAL(valueChanged(double)), SLOT(slotMonthChanged(double)));
00104     connect(week, SIGNAL(valueChanged(double)), SLOT(slotWeekChanged(double)));
00105     connect(day, SIGNAL(valueChanged(double)), SLOT(slotDayChanged(double)));
00106     
00107 }
00108 
00109 
00110 void StandardWorktimeDialogImpl::slotEnableButtonOk(bool on) {
00111     emit enableButtonOk(on);
00112 }
00113 
00114 void StandardWorktimeDialogImpl::slotCheckAllFieldsFilled() {
00115     emit obligatedFieldsFilled(true);
00116 }
00117 
00118 void StandardWorktimeDialogImpl::slotYearChanged(double value) {
00119     //kdDebug()<<k_funcinfo<<value<<endl;
00120     m_year = value;
00121     if (month->value() > value)
00122         month->setValue(value);
00123     slotEnableButtonOk(true);
00124 }
00125 
00126 void StandardWorktimeDialogImpl::slotMonthChanged(double value) {
00127     m_month = value;
00128     if (year->value() < value)
00129         year->setValue(value);
00130     if (week->value() > value)
00131         week->setValue(value);
00132     slotEnableButtonOk(true);
00133 }
00134 
00135 void StandardWorktimeDialogImpl::slotWeekChanged(double value) {
00136     m_week = value;
00137     if (month->value() < value)
00138         month->setValue(value);
00139     if (day->value() > value)
00140         day->setValue(value);
00141     slotEnableButtonOk(true);
00142 }
00143 
00144 void StandardWorktimeDialogImpl::slotDayChanged(double value) {
00145     m_day = value;
00146     if (week->value() < value)
00147         week->setValue(value);
00148     slotEnableButtonOk(true);
00149 }
00150 
00151 
00152 }  //KPlato namespace
00153 
00154 #include "kptstandardworktimedialog.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys