1
/***************************************************************************
2
* Copyright (C) 2005 by Raphael Langerhorst *
3
* raphael-langerhorst@gmx.at *
5
* Permission is hereby granted, free of charge, to any person obtaining *
6
* a copy of this software and associated documentation files (the *
7
* "Software"), to deal in the Software without restriction, including *
8
* without limitation the rights to use, copy, modify, merge, publish, *
9
* distribute, sublicense, and/or sell copies of the Software, and to *
10
* permit persons to whom the Software is furnished to do so, subject to *
11
* the following conditions: *
13
* The above copyright notice and this permission notice shall be *
14
* included in all copies or substantial portions of the Software. *
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
17
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
19
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR *
20
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
21
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
22
* OTHER DEALINGS IN THE SOFTWARE. *
23
***************************************************************************/
25
#include <kspread_insertcalendardialog.h>
27
#include <kdatepicker.h>
28
#include <kdatewidget.h>
31
#include <qpushbutton.h>
36
InsertCalendarDialog::InsertCalendarDialog(QWidget* parent, const char* name)
37
: InsertCalendarDialogBase(parent,name)
39
this->m_datePicker = NULL;
41
//we start with a default calendar for the current month;
43
QDate first_day_in_month = QDate::currentDate();
44
first_day_in_month.setYMD(first_day_in_month.year(),first_day_in_month.month(),1);
46
QDate last_day_in_month(first_day_in_month.year(),first_day_in_month.month(),first_day_in_month.daysInMonth());
48
this->m_startDateWidget->setDate(first_day_in_month);
49
this->m_endDateWidget->setDate(last_day_in_month);
51
connect(this->m_selectStartDateButton,SIGNAL(clicked()),this,SLOT(showStartDatePicker()));
52
connect(this->m_selectEndDateButton,SIGNAL(clicked()),this,SLOT(showEndDatePicker()));
54
connect(this->m_insertButton,SIGNAL(clicked()),this,SLOT(accept()));
55
connect(this->m_cancelButton,SIGNAL(clicked()),this,SLOT(reject()));
58
InsertCalendarDialog::~InsertCalendarDialog()
62
bool InsertCalendarDialog::buildDatePickerFrame()
66
delete m_datePicker; //destroyed signal is connected to datePickerDeleted()
69
m_datePicker = new KDatePicker(NULL,"date picker");
71
Q_ASSERT(m_datePicker);
76
connect(m_datePicker,SIGNAL(destroyed()),this,SLOT(datePickerDeleted()));
78
m_datePicker->setCloseButton(true);
79
m_datePicker->move(this->x()+this->width(),this->y());
85
void InsertCalendarDialog::datePickerDeleted()
87
kdDebug() << "date picker deleted" << endl;
91
void InsertCalendarDialog::accept()
94
m_datePicker->deleteLater();
95
kdDebug() << "insert calendar dialog accepted (insert button clicked)" << endl;
96
done(QDialog::Accepted);
97
emit insertCalendar(startDate(),endDate());
100
void InsertCalendarDialog::reject()
103
m_datePicker->deleteLater();
104
kdDebug() << "insert calendar dialog rejected (cancel button clicked)" << endl;
105
done(QDialog::Rejected);
108
void InsertCalendarDialog::showStartDatePicker()
110
if (buildDatePickerFrame())
112
connect(m_datePicker,SIGNAL(dateSelected(QDate)),this,SLOT(setStartDate(QDate)));
113
connect(m_datePicker,SIGNAL(dateEntered(QDate)),this,SLOT(setStartDate(QDate)));
114
m_datePicker->setDate(startDate());
118
void InsertCalendarDialog::showEndDatePicker()
120
if (buildDatePickerFrame())
122
connect(m_datePicker,SIGNAL(dateSelected(QDate)),this,SLOT(setEndDate(QDate)));
123
connect(m_datePicker,SIGNAL(dateEntered(QDate)),this,SLOT(setEndDate(QDate)));
124
m_datePicker->setDate(endDate());
128
void InsertCalendarDialog::setStartDate(QDate date)
130
this->m_startDateWidget->setDate(date);
133
void InsertCalendarDialog::setEndDate(QDate date)
135
this->m_endDateWidget->setDate(date);
138
QDate InsertCalendarDialog::startDate() const
140
return this->m_startDateWidget->date();
143
QDate InsertCalendarDialog::endDate() const
145
return this->m_endDateWidget->date();
150
#include "kspread_insertcalendardialog.moc"