kspread
CalendarToolWidget.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <CalendarToolWidget.h>
00025
00026 #include <kdatepicker.h>
00027 #include <kdatewidget.h>
00028 #include <kdebug.h>
00029
00030 #include <QPushButton>
00031
00032 namespace KSpread
00033 {
00034
00035 CalendarToolWidget::CalendarToolWidget(QWidget* parent)
00036 : QDialog(parent)
00037 {
00038 setupUi(this);
00039 this->m_datePicker = 0;
00040
00041
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 this->m_selectStartDateButton->setIcon(KIcon("office-calendar"));
00052 this->m_selectEndDateButton->setIcon(KIcon("office-calendar"));
00053
00054 connect(this->m_selectStartDateButton,SIGNAL(clicked()),this,SLOT(showStartDatePicker()));
00055 connect(this->m_selectEndDateButton,SIGNAL(clicked()),this,SLOT(showEndDatePicker()));
00056
00057 connect(this->m_insertButton, SIGNAL(clicked()), this, SLOT(emitInsertCalendar()));
00058 }
00059
00060 CalendarToolWidget::~CalendarToolWidget()
00061 {
00062 }
00063
00064 bool CalendarToolWidget::buildDatePickerFrame()
00065 {
00066 if (m_datePicker)
00067 {
00068 delete m_datePicker;
00069 }
00070
00071 m_datePicker = new KDatePicker();
00072
00073 Q_ASSERT(m_datePicker);
00074
00075 if (!m_datePicker)
00076 return false;
00077
00078 connect(m_datePicker,SIGNAL(destroyed()),this,SLOT(datePickerDeleted()));
00079
00080 const QPoint position = mapToGlobal(pos());
00081 m_datePicker->move(position.x() + this->width(), position.y());
00082 m_datePicker->show();
00083
00084 return true;
00085 }
00086
00087 void CalendarToolWidget::datePickerDeleted()
00088 {
00089 kDebug() <<"date picker deleted";
00090 m_datePicker = 0;
00091 }
00092
00093 void CalendarToolWidget::emitInsertCalendar()
00094 {
00095 if (m_datePicker)
00096 m_datePicker->deleteLater();
00097 emit insertCalendar(startDate(),endDate());
00098 }
00099
00100 void CalendarToolWidget::showStartDatePicker()
00101 {
00102 if (buildDatePickerFrame())
00103 {
00104 connect(m_datePicker,SIGNAL(dateSelected(QDate)),this,SLOT(setStartDate(QDate)));
00105 connect(m_datePicker,SIGNAL(dateEntered(QDate)),this,SLOT(setStartDate(QDate)));
00106 m_datePicker->setDate(startDate());
00107 }
00108 }
00109
00110 void CalendarToolWidget::showEndDatePicker()
00111 {
00112 if (buildDatePickerFrame())
00113 {
00114 connect(m_datePicker,SIGNAL(dateSelected(QDate)),this,SLOT(setEndDate(QDate)));
00115 connect(m_datePicker,SIGNAL(dateEntered(QDate)),this,SLOT(setEndDate(QDate)));
00116 m_datePicker->setDate(endDate());
00117 }
00118 }
00119
00120 void CalendarToolWidget::setStartDate(const QDate& date)
00121 {
00122 this->m_startDateWidget->setDate(date);
00123 }
00124
00125 void CalendarToolWidget::setEndDate(const QDate& date)
00126 {
00127 this->m_endDateWidget->setDate(date);
00128 }
00129
00130 QDate CalendarToolWidget::startDate() const
00131 {
00132 return this->m_startDateWidget->date();
00133 }
00134
00135 QDate CalendarToolWidget::endDate() const
00136 {
00137 return this->m_endDateWidget->date();
00138 }
00139
00140 }
00141
00142 #include "CalendarToolWidget.moc"
|