kspread Library API Documentation

kspread_insertcalendardialog.cc

00001  /***************************************************************************
00002  *   Copyright (C) 2005 by Raphael Langerhorst                             *
00003  *   raphael-langerhorst@gmx.at                                            *
00004  *                                                                         *
00005  *   Permission is hereby granted, free of charge, to any person obtaining *
00006  *   a copy of this software and associated documentation files (the       *
00007  *   "Software"), to deal in the Software without restriction, including   *
00008  *   without limitation the rights to use, copy, modify, merge, publish,   *
00009  *   distribute, sublicense, and/or sell copies of the Software, and to    *
00010  *   permit persons to whom the Software is furnished to do so, subject to *
00011  *   the following conditions:                                             *
00012  *                                                                         *
00013  *   The above copyright notice and this permission notice shall be        *
00014  *   included in all copies or substantial portions of the Software.       *
00015  *                                                                         *
00016  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       *
00017  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    *
00018  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
00019  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *
00020  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
00021  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
00022  *   OTHER DEALINGS IN THE SOFTWARE.                                       *
00023  ***************************************************************************/
00024  
00025 #include <kspread_insertcalendardialog.h>
00026 
00027 #include <kdatepicker.h>
00028 #include <kdatewidget.h>
00029 #include <kdebug.h>
00030 
00031 #include <qpushbutton.h>
00032 
00033 namespace KSpread
00034 {
00035 
00036 InsertCalendarDialog::InsertCalendarDialog(QWidget* parent, const char* name)
00037 : InsertCalendarDialogBase(parent,name)
00038 {
00039   this->m_datePicker = NULL;
00040   
00041   //we start with a default calendar for the current month;
00042 
00043   QDate first_day_in_month = QDate::currentDate();
00044   first_day_in_month.setYMD(first_day_in_month.year(),first_day_in_month.month(),1);
00045   
00046   QDate last_day_in_month(first_day_in_month.year(),first_day_in_month.month(),first_day_in_month.daysInMonth());
00047   
00048   this->m_startDateWidget->setDate(first_day_in_month);
00049   this->m_endDateWidget->setDate(last_day_in_month);
00050   
00051   connect(this->m_selectStartDateButton,SIGNAL(clicked()),this,SLOT(showStartDatePicker()));
00052   connect(this->m_selectEndDateButton,SIGNAL(clicked()),this,SLOT(showEndDatePicker()));
00053   
00054   connect(this->m_insertButton,SIGNAL(clicked()),this,SLOT(accept()));
00055   connect(this->m_cancelButton,SIGNAL(clicked()),this,SLOT(reject()));
00056 }
00057 
00058 InsertCalendarDialog::~InsertCalendarDialog()
00059 {
00060 }
00061 
00062 bool InsertCalendarDialog::buildDatePickerFrame()
00063 {
00064   if (m_datePicker)
00065   {
00066     delete m_datePicker; //destroyed signal is connected to datePickerDeleted()
00067   }
00068   
00069   m_datePicker = new KDatePicker(NULL,"date picker");
00070   
00071   Q_ASSERT(m_datePicker);
00072   
00073   if (!m_datePicker)
00074     return false;
00075   
00076   connect(m_datePicker,SIGNAL(destroyed()),this,SLOT(datePickerDeleted()));
00077   
00078   m_datePicker->setCloseButton(true);
00079   m_datePicker->move(this->x()+this->width(),this->y());
00080   m_datePicker->show();
00081   
00082   return true;
00083 }
00084 
00085 void InsertCalendarDialog::datePickerDeleted()
00086 {
00087   kdDebug() << "date picker deleted" << endl;
00088   m_datePicker = NULL;
00089 }
00090 
00091 void InsertCalendarDialog::accept()
00092 {
00093   if (m_datePicker)
00094     m_datePicker->deleteLater();
00095   kdDebug() << "insert calendar dialog accepted (insert button clicked)" << endl;
00096   done(QDialog::Accepted);
00097   emit insertCalendar(startDate(),endDate());
00098 }
00099 
00100 void InsertCalendarDialog::reject()
00101 {
00102   if (m_datePicker)
00103     m_datePicker->deleteLater();
00104   kdDebug() << "insert calendar dialog rejected (cancel button clicked)" << endl;
00105   done(QDialog::Rejected);
00106 }
00107 
00108 void InsertCalendarDialog::showStartDatePicker()
00109 {
00110   if (buildDatePickerFrame())
00111   {
00112     connect(m_datePicker,SIGNAL(dateSelected(QDate)),this,SLOT(setStartDate(QDate)));
00113     connect(m_datePicker,SIGNAL(dateEntered(QDate)),this,SLOT(setStartDate(QDate)));
00114     m_datePicker->setDate(startDate());
00115   }
00116 }
00117 
00118 void InsertCalendarDialog::showEndDatePicker()
00119 {
00120   if (buildDatePickerFrame())
00121   {
00122     connect(m_datePicker,SIGNAL(dateSelected(QDate)),this,SLOT(setEndDate(QDate)));
00123     connect(m_datePicker,SIGNAL(dateEntered(QDate)),this,SLOT(setEndDate(QDate)));
00124     m_datePicker->setDate(endDate());
00125   }
00126 }
00127 
00128 void InsertCalendarDialog::setStartDate(QDate date)
00129 {
00130   this->m_startDateWidget->setDate(date);
00131 }
00132 
00133 void InsertCalendarDialog::setEndDate(QDate date)
00134 {
00135   this->m_endDateWidget->setDate(date);
00136 }
00137 
00138 QDate InsertCalendarDialog::startDate() const
00139 {
00140   return this->m_startDateWidget->date();
00141 }
00142 
00143 QDate InsertCalendarDialog::endDate() const
00144 {
00145   return this->m_endDateWidget->date();
00146 }
00147 
00148 }
00149 
00150 #include "kspread_insertcalendardialog.moc"
KDE Logo
This file is part of the documentation for kspread Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:43:13 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003