kspread

kspread_insertcalendardialog.cpp
1 /***************************************************************************
2 * Copyright (C) 2005 by Raphael Langerhorst *
3 * raphael-langerhorst@gmx.at *
4 * *
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: *
12 * *
13 * The above copyright notice and this permission notice shall be *
14 * included in all copies or substantial portions of the Software. *
15 * *
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 ***************************************************************************/
24
25#include <kspread_insertcalendardialog.h>
26
27#include <kdatepicker.h>
28#include <kdatewidget.h>
29#include <kdebug.h>
30
31#include <tqpushbutton.h>
32
33namespace KSpread
34{
35
36InsertCalendarDialog::InsertCalendarDialog(TQWidget* parent, const char* name)
37: InsertCalendarDialogBase(parent,name)
38{
39 this->m_datePicker = NULL;
40
41 //we start with a default calendar for the current month;
42
43 TQDate first_day_in_month = TQDate::currentDate();
44 first_day_in_month.setYMD(first_day_in_month.year(),first_day_in_month.month(),1);
45
46 TQDate last_day_in_month(first_day_in_month.year(),first_day_in_month.month(),first_day_in_month.daysInMonth());
47
48 this->m_startDateWidget->setDate(first_day_in_month);
49 this->m_endDateWidget->setDate(last_day_in_month);
50
51 connect(this->m_selectStartDateButton,TQ_SIGNAL(clicked()),this,TQ_SLOT(showStartDatePicker()));
52 connect(this->m_selectEndDateButton,TQ_SIGNAL(clicked()),this,TQ_SLOT(showEndDatePicker()));
53
54 connect(this->m_insertButton,TQ_SIGNAL(clicked()),this,TQ_SLOT(accept()));
55 connect(this->m_cancelButton,TQ_SIGNAL(clicked()),this,TQ_SLOT(reject()));
56}
57
58InsertCalendarDialog::~InsertCalendarDialog()
59{
60}
61
62bool InsertCalendarDialog::buildDatePickerFrame()
63{
64 if (m_datePicker)
65 {
66 delete m_datePicker; //destroyed signal is connected to datePickerDeleted()
67 }
68
69 m_datePicker = new KDatePicker(NULL,"date picker");
70
71 Q_ASSERT(m_datePicker);
72
73 if (!m_datePicker)
74 return false;
75
76 connect(m_datePicker,TQ_SIGNAL(destroyed()),this,TQ_SLOT(datePickerDeleted()));
77
78 m_datePicker->setCloseButton(true);
79 m_datePicker->move(this->x()+this->width(),this->y());
80 m_datePicker->show();
81
82 return true;
83}
84
85void InsertCalendarDialog::datePickerDeleted()
86{
87 kdDebug() << "date picker deleted" << endl;
88 m_datePicker = NULL;
89}
90
91void InsertCalendarDialog::accept()
92{
93 if (m_datePicker)
94 m_datePicker->deleteLater();
95 kdDebug() << "insert calendar dialog accepted (insert button clicked)" << endl;
96 done(TQDialog::Accepted);
97 emit insertCalendar(startDate(),endDate());
98}
99
100void InsertCalendarDialog::reject()
101{
102 if (m_datePicker)
103 m_datePicker->deleteLater();
104 kdDebug() << "insert calendar dialog rejected (cancel button clicked)" << endl;
105 done(TQDialog::Rejected);
106}
107
108void InsertCalendarDialog::showStartDatePicker()
109{
110 if (buildDatePickerFrame())
111 {
112 connect(m_datePicker,TQ_SIGNAL(dateSelected(TQDate)),this,TQ_SLOT(setStartDate(TQDate)));
113 connect(m_datePicker,TQ_SIGNAL(dateEntered(TQDate)),this,TQ_SLOT(setStartDate(TQDate)));
114 m_datePicker->setDate(startDate());
115 }
116}
117
118void InsertCalendarDialog::showEndDatePicker()
119{
120 if (buildDatePickerFrame())
121 {
122 connect(m_datePicker,TQ_SIGNAL(dateSelected(TQDate)),this,TQ_SLOT(setEndDate(TQDate)));
123 connect(m_datePicker,TQ_SIGNAL(dateEntered(TQDate)),this,TQ_SLOT(setEndDate(TQDate)));
124 m_datePicker->setDate(endDate());
125 }
126}
127
128void InsertCalendarDialog::setStartDate(TQDate date)
129{
130 this->m_startDateWidget->setDate(date);
131}
132
133void InsertCalendarDialog::setEndDate(TQDate date)
134{
135 this->m_endDateWidget->setDate(date);
136}
137
138TQDate InsertCalendarDialog::startDate() const
139{
140 return this->m_startDateWidget->date();
141}
142
143TQDate InsertCalendarDialog::endDate() const
144{
145 return this->m_endDateWidget->date();
146}
147
148}
149
150#include "kspread_insertcalendardialog.moc"
The KSpread namespace.
Definition commands.h:39