diff options
| author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
|---|---|---|
| committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
| commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
| tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /kspread/plugins/insertcalendar | |
| download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip | |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kspread/plugins/insertcalendar')
7 files changed, 950 insertions, 0 deletions
diff --git a/kspread/plugins/insertcalendar/Makefile.am b/kspread/plugins/insertcalendar/Makefile.am new file mode 100644 index 000000000..f8b72e81b --- /dev/null +++ b/kspread/plugins/insertcalendar/Makefile.am @@ -0,0 +1,26 @@ +INCLUDES = -I$(srcdir)/../../../kspread $(KOFFICE_INCLUDES) $(KOTEXT_INCLUDES) -I$(top_srcdir)/lib/koscript -I$(top_builddir)/lib/koscript $(all_includes) + +kde_module_LTLIBRARIES = libkspreadinsertcalendar.la + +libkspreadinsertcalendar_la_SOURCES = kspread_plugininsertcalendar.cc \ + kspread_insertcalendardialogbase.ui \ + kspread_insertcalendardialog.cc +libkspreadinsertcalendar_la_LDFLAGS = $(all_libraries) -avoid-version -module -no-undefined +libkspreadinsertcalendar_la_LIBADD = ../../libkspreadcommon.la + +METASOURCES = AUTO + +# Delete old unused file +#install-data-local: uninstall.desktop +# $(mkinstalldirs) $(DESTDIR)$(kde_servicesdir) +# $(INSTALL_DATA) $(srcdir)/uninstall.desktop $(DESTDIR)$(kde_servicesdir)/kspreadinsertcalendar.desktop + +rc_DATA = insertcalendar.rc +rcdir = $(kde_datadir)/kspread/kpartplugins + + + +SUBDIRS = + +messages: rc.cpp + $(XGETTEXT) rc.cpp *.cc -o $(podir)/kspreadinsertcalendar.pot diff --git a/kspread/plugins/insertcalendar/insertcalendar.rc b/kspread/plugins/insertcalendar/insertcalendar.rc new file mode 100644 index 000000000..c4968254c --- /dev/null +++ b/kspread/plugins/insertcalendar/insertcalendar.rc @@ -0,0 +1,8 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> +<kpartgui name="KSpreadPluginInsertCalendar" library="libkspreadinsertcalendar" version="1"> +<MenuBar> + <Menu name="tools"><text>&Tools</text> + <Action name="kspreadinsertcalendar" /> + </Menu> +</MenuBar> +</kpartgui> diff --git a/kspread/plugins/insertcalendar/kspread_insertcalendardialog.cc b/kspread/plugins/insertcalendar/kspread_insertcalendardialog.cc new file mode 100644 index 000000000..541783b8a --- /dev/null +++ b/kspread/plugins/insertcalendar/kspread_insertcalendardialog.cc @@ -0,0 +1,150 @@ + /*************************************************************************** + * Copyright (C) 2005 by Raphael Langerhorst * + * raphael-langerhorst@gmx.at * + * * + * Permission is hereby granted, free of charge, to any person obtaining * + * a copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to * + * the following conditions: * + * * + * The above copyright notice and this permission notice shall be * + * included in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.* + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * + * OTHER DEALINGS IN THE SOFTWARE. * + ***************************************************************************/ + +#include <kspread_insertcalendardialog.h> + +#include <kdatepicker.h> +#include <kdatewidget.h> +#include <kdebug.h> + +#include <qpushbutton.h> + +namespace KSpread +{ + +InsertCalendarDialog::InsertCalendarDialog(QWidget* parent, const char* name) +: InsertCalendarDialogBase(parent,name) +{ + this->m_datePicker = NULL; + + //we start with a default calendar for the current month; + + QDate first_day_in_month = QDate::currentDate(); + first_day_in_month.setYMD(first_day_in_month.year(),first_day_in_month.month(),1); + + QDate last_day_in_month(first_day_in_month.year(),first_day_in_month.month(),first_day_in_month.daysInMonth()); + + this->m_startDateWidget->setDate(first_day_in_month); + this->m_endDateWidget->setDate(last_day_in_month); + + connect(this->m_selectStartDateButton,SIGNAL(clicked()),this,SLOT(showStartDatePicker())); + connect(this->m_selectEndDateButton,SIGNAL(clicked()),this,SLOT(showEndDatePicker())); + + connect(this->m_insertButton,SIGNAL(clicked()),this,SLOT(accept())); + connect(this->m_cancelButton,SIGNAL(clicked()),this,SLOT(reject())); +} + +InsertCalendarDialog::~InsertCalendarDialog() +{ +} + +bool InsertCalendarDialog::buildDatePickerFrame() +{ + if (m_datePicker) + { + delete m_datePicker; //destroyed signal is connected to datePickerDeleted() + } + + m_datePicker = new KDatePicker(NULL,"date picker"); + + Q_ASSERT(m_datePicker); + + if (!m_datePicker) + return false; + + connect(m_datePicker,SIGNAL(destroyed()),this,SLOT(datePickerDeleted())); + + m_datePicker->setCloseButton(true); + m_datePicker->move(this->x()+this->width(),this->y()); + m_datePicker->show(); + + return true; +} + +void InsertCalendarDialog::datePickerDeleted() +{ + kdDebug() << "date picker deleted" << endl; + m_datePicker = NULL; +} + +void InsertCalendarDialog::accept() +{ + if (m_datePicker) + m_datePicker->deleteLater(); + kdDebug() << "insert calendar dialog accepted (insert button clicked)" << endl; + done(QDialog::Accepted); + emit insertCalendar(startDate(),endDate()); +} + +void InsertCalendarDialog::reject() +{ + if (m_datePicker) + m_datePicker->deleteLater(); + kdDebug() << "insert calendar dialog rejected (cancel button clicked)" << endl; + done(QDialog::Rejected); +} + +void InsertCalendarDialog::showStartDatePicker() +{ + if (buildDatePickerFrame()) + { + connect(m_datePicker,SIGNAL(dateSelected(QDate)),this,SLOT(setStartDate(QDate))); + connect(m_datePicker,SIGNAL(dateEntered(QDate)),this,SLOT(setStartDate(QDate))); + m_datePicker->setDate(startDate()); + } +} + +void InsertCalendarDialog::showEndDatePicker() +{ + if (buildDatePickerFrame()) + { + connect(m_datePicker,SIGNAL(dateSelected(QDate)),this,SLOT(setEndDate(QDate))); + connect(m_datePicker,SIGNAL(dateEntered(QDate)),this,SLOT(setEndDate(QDate))); + m_datePicker->setDate(endDate()); + } +} + +void InsertCalendarDialog::setStartDate(QDate date) +{ + this->m_startDateWidget->setDate(date); +} + +void InsertCalendarDialog::setEndDate(QDate date) +{ + this->m_endDateWidget->setDate(date); +} + +QDate InsertCalendarDialog::startDate() const +{ + return this->m_startDateWidget->date(); +} + +QDate InsertCalendarDialog::endDate() const +{ + return this->m_endDateWidget->date(); +} + +} + +#include "kspread_insertcalendardialog.moc" diff --git a/kspread/plugins/insertcalendar/kspread_insertcalendardialog.h b/kspread/plugins/insertcalendar/kspread_insertcalendardialog.h new file mode 100644 index 000000000..f52c2e93f --- /dev/null +++ b/kspread/plugins/insertcalendar/kspread_insertcalendardialog.h @@ -0,0 +1,165 @@ + /*************************************************************************** + * Copyright (C) 2005 by Raphael Langerhorst * + * raphael-langerhorst@gmx.at * + * * + * Permission is hereby granted, free of charge, to any person obtaining * + * a copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to * + * the following conditions: * + * * + * The above copyright notice and this permission notice shall be * + * included in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.* + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * + * OTHER DEALINGS IN THE SOFTWARE. * + ***************************************************************************/ + +#ifndef KSPREAD_INSERTCALENDARDIALOG_H +#define KSPREAD_INSERTCALENDARDIALOG_H + +#include <kspread_insertcalendardialogbase.h> +#include <koffice_export.h> + +#include <qdatetime.h> + +class KDatePicker; + +namespace KSpread +{ + +class KSPREAD_EXPORT InsertCalendarDialog : public InsertCalendarDialogBase +{ + Q_OBJECT + + private: + + /** + * Stores a pointer to the currently active date picker frame. + * This is useful if we want to delete it manually. + * @see datePickerDeleted + */ + KDatePicker* m_datePicker; + + public: + + /** + * Constructor, initializes functionality. + * The dates in the dialog initialize to a complete calendar for the + * current month. + */ + InsertCalendarDialog(QWidget* parent = 0, const char* name = 0); + + /** + * Virtual destructor. + */ + virtual ~InsertCalendarDialog(); + + protected: + + /** + * Creates a KDatePicker frame that is not connected + * to any date widget. Normally showStartDatePicker + * of showEndDatePicker use this method to build + * a generally usable date picker widget and connect + * it to the appropriate KDateWidget of the dialog. + * + * DatePickerDeleted is already connected! + */ + bool buildDatePickerFrame(); + + protected slots: + + /** + * Sets the currently active KDatePicker frame to NULL. + * It's expected that the date picker frame is deleted. + * @see m_datePicker + */ + void datePickerDeleted(); + + /** + * This slot is reimplemented from QDialog and + * is connected to the insert button. + * It also emits a insertCalendar signal. + * + * The dialog is closed (not deleted) when + * this slot is called. + * + * @see insertCalendar, reject, QDialog::done + */ + virtual void accept(); + + /** + * This slot is reimplemented from QDialog and + * is connected to the cancel button. + * + * The dialog is closed (not deleted) when + * this slot is called. + * + * @see accept, QDialog::done + */ + virtual void reject(); + + public slots: + + /** + * Shows a KDatePicker widget to select the start date. + * This slot is activated by the select date button. + */ + void showStartDatePicker(); + + /** + * Shows a KDatePicker widget to select the end date. + * This slot is activated by the select date button. + */ + void showEndDatePicker(); + + /** + * Slot for setting the start date in the KDateWidget. + * Normally this slot is activated by a KDatePicker widget. + */ + void setStartDate(QDate); + + /** + * Slot for setting the end date in the KDateWidget. + * Normally this slot is activated by a KDatePicker widget. + */ + void setEndDate(QDate); + + public: + + // METHODS for getting data // + + /** + * @returns the selected start date. + */ + QDate startDate() const; + + /** + * @returns the selected end date. + */ + QDate endDate() const; + + signals: + + /** + * This signal is emitted when the dialog is + * accepted - that is, when the Insert button + * is clicked. + * This signal is meant to tell the + * insert calendar plugin to actually insert + * the calendar with the selected dates. + */ + void insertCalendar(const QDate &from, const QDate &to); +}; + +} + +#endif diff --git a/kspread/plugins/insertcalendar/kspread_insertcalendardialogbase.ui b/kspread/plugins/insertcalendar/kspread_insertcalendardialogbase.ui new file mode 100644 index 000000000..9315c38cc --- /dev/null +++ b/kspread/plugins/insertcalendar/kspread_insertcalendardialogbase.ui @@ -0,0 +1,207 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>KSpread::InsertCalendarDialogBase</class> +<widget class="QDialog"> + <property name="name"> + <cstring>KSpread::InsertCalendarDialogBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>429</width> + <height>237</height> + </rect> + </property> + <property name="caption"> + <string>Insert Calendar</string> + </property> + <property name="toolTip" stdset="0"> + <string></string> + </property> + <property name="whatsThis" stdset="0"> + <string>The Insert Calendar dialog lets you set the dates of the calendar you want to insert. When you have choosen the desired dates, simply press the Insert button to insert the calendar into the spreadsheet, starting at the cell you have currently selected.</string> + <comment>This what's this help applies for the entire dialog.</comment> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QGroupBox" row="0" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>m_startDateGroupBox</cstring> + </property> + <property name="title"> + <string>Start Date</string> + </property> + <property name="toolTip" stdset="0"> + <string>Set the start date of the calendar you want to insert.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Here you can choose on which date your calendar should start. The selected date will be the first day of the inserted calendar. You can also choose a date from a calendar dialog by pressing Select Date.</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KDateWidget" row="0" column="0"> + <property name="name"> + <cstring>m_startDateWidget</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QPushButton" row="0" column="1"> + <property name="name"> + <cstring>m_selectStartDateButton</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Date Picker</string> + </property> + <property name="toolTip" stdset="0"> + <string>Use a graphical date picker to select a date.</string> + </property> + </widget> + </grid> + </widget> + <widget class="QGroupBox" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>m_endDateGroupBox</cstring> + </property> + <property name="frameShape"> + <enum>GroupBoxPanel</enum> + </property> + <property name="frameShadow"> + <enum>Sunken</enum> + </property> + <property name="title"> + <string>End Date</string> + </property> + <property name="toolTip" stdset="0"> + <string>Set the end date of the calendar you want to insert.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Here you can choose on which date your calendar should end. The selected date will be the last day of the inserted calendar. You can also choose a date from a calendar dialog by pressing Select Date.</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KDateWidget" row="0" column="0"> + <property name="name"> + <cstring>m_endDateWidget</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + <widget class="QPushButton" row="0" column="1"> + <property name="name"> + <cstring>m_selectEndDateButton</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Date Picker</string> + </property> + <property name="toolTip" stdset="0"> + <string>Use a graphical date picker to select a date.</string> + </property> + </widget> + </grid> + </widget> + <spacer row="2" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>400</width> + <height>19</height> + </size> + </property> + </spacer> + <widget class="QPushButton" row="3" column="0"> + <property name="name"> + <cstring>m_insertButton</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Insert</string> + </property> + <property name="toolTip" stdset="0"> + <string>Insert the calendar at the currently selected cell.</string> + <comment>Tooltip for the insert button of the insert calendar plugin</comment> + </property> + <property name="whatsThis" stdset="0"> + <string>A new calendar will be inserted starting at the currently selected cell.</string> + <comment>What's this for the insert button of the insert calendar plugin</comment> + </property> + </widget> + <widget class="QPushButton" row="3" column="1"> + <property name="name"> + <cstring>m_cancelButton</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + <property name="toolTip" stdset="0"> + <string>Don't insert a calendar.</string> + </property> + <property name="whatsThis" stdset="0"> + <string>Quits the dialog and does not insert a calendar. Use this to cancel this operation.</string> + </property> + </widget> + </grid> +</widget> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kdatewidget.h</includehint> + <includehint>kdatewidget.h</includehint> +</includehints> +</UI> diff --git a/kspread/plugins/insertcalendar/kspread_plugininsertcalendar.cc b/kspread/plugins/insertcalendar/kspread_plugininsertcalendar.cc new file mode 100644 index 000000000..56388af8f --- /dev/null +++ b/kspread/plugins/insertcalendar/kspread_plugininsertcalendar.cc @@ -0,0 +1,281 @@ +/*************************************************************************** + * Copyright (C) 2005 by Raphael Langerhorst * + * raphael-langerhorst@gmx.at * + * * + * Permission is hereby granted, free of charge, to any person obtaining * + * a copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to * + * the following conditions: * + * * + * The above copyright notice and this permission notice shall be * + * included in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.* + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * + * OTHER DEALINGS IN THE SOFTWARE. * + ***************************************************************************/ + +#include "kspread_plugininsertcalendar.h" + +#include "kspread_insertcalendardialog.h" + +#include "../../kspread_view.h" +#include "../../kspread_doc.h" +#include "../../selection.h" +#include "../../kspread_sheet.h" + +#include <kcalendarsystem.h> +#include <kcalendarsystemfactory.h> +#include <kaboutdata.h> +#include <kgenericfactory.h> +#include <klocale.h> +#include <kofficeversion.h> +#include <kmessagebox.h> + +#include <qpoint.h> +#include <qrect.h> + +namespace KSpread +{ + +// make the plugin available +typedef KGenericFactory<PluginInsertCalendar> InsertCalendarFactory; +K_EXPORT_COMPONENT_FACTORY( libkspreadinsertcalendar, InsertCalendarFactory("kspreadinsertcalendar")) + + +PluginInsertCalendar::PluginInsertCalendar( QObject *parent, const char *name, const QStringList& /*args*/ ) +: Plugin(parent,name) +{ + this->m_kspreadView = NULL; + if (parent) + { + if (parent->inherits("KSpread::View")) + { + this->m_kspreadView = (View*)parent; + } + else + { + kdWarning() << "Parent does not inherit View!!!" << endl; + } + } + else + { + kdWarning() << "Plugin created without a parent!!!" << endl; + } + + + this->m_dialog = NULL; + + (void)new KAction( i18n("Insert Calendar..."), KShortcut::null(), + this, SLOT( slotShowDialog() ), actionCollection(), "kspreadinsertcalendar"); +} + +PluginInsertCalendar::~PluginInsertCalendar() +{ +} + +KAboutData* PluginInsertCalendar::createAboutData() +{ + KAboutData * aboutData = new KAboutData( + "kspreadinsertcalendar", //app name + I18N_NOOP("Insert Calendar"), //program name + KOFFICE_VERSION_STRING, //version + I18N_NOOP("KSpread Insert Calendar Plugin"), //short description + KAboutData::License_BSD, //license type + I18N_NOOP("(c) 2005, The KSpread Team"), //copyright + 0,//I18N_NOOP("The Insert Calendar plugin can be used in spreadsheets"), //text + "http://www.koffice.org/kspread/"); + aboutData->addAuthor("Raphael Langerhorst", 0, "Raphael.Langerhorst@kdemail.net"); + + return aboutData; +} + +void PluginInsertCalendar::slotShowDialog() +{ + kdDebug() << "slotShowDialog..." << endl; + + if (this->m_dialog == NULL) + { + this->m_dialog = new InsertCalendarDialog(); + + Q_ASSERT(m_dialog); + + connect(m_dialog,SIGNAL(insertCalendar(const QDate&, const QDate&)), + this,SLOT(slotInsertCalendar(const QDate&, const QDate&))); + } + + //@todo if anyone knows a better way to get a background window to foreground, please change this... + m_dialog->hide(); + m_dialog->show(); + +} + +void PluginInsertCalendar::slotInsertCalendar(const QDate &start, const QDate &end) +{ + //@todo implement + kdDebug() << "slotInsert... still to be implemented" << endl; + + Doc* document = m_kspreadView->doc(); + + if (!document) + { + KMessageBox::error(NULL,i18n("Can't insert calendar because no document is set!"),i18n("Error")); + return; + } + + if (end < start) + { + KMessageBox::error(NULL,i18n("End date is before start date! Please make sure that end date comes after start date."),i18n("Error")); + return; + } + + if (start.daysTo(end) > 3652) + { + KMessageBox::error(NULL,i18n("Calendars shouldn't be longer than 10 years. If you really need such long periods you need to split them up."),i18n("Error")); + return; + } + + if (start == end) + { + if (KMessageBox::No == KMessageBox::warningYesNo(NULL,i18n("Start and end dates are equal! Only one day will be inserted, do you want to continue?"),i18n("Warning"))) + return; + } + + if (start.daysTo(end)> 366) + { + if (KMessageBox::No == KMessageBox::warningYesNo(NULL,i18n("Creating a calendar for a longer period than a year can take up a lot of space, do you want to continue?"),i18n("Warning"))) + return; + } + + Selection* selection_info = m_kspreadView->selectionInfo(); + + Q_ASSERT(selection_info); + + QPoint selection = selection_info->selection().topLeft(); + + Sheet* sheet = m_kspreadView->activeSheet(); + + Q_ASSERT(sheet); + + if (!sheet) + return; + + //now let's check if the area is really empty... + //we use two columns per day and one column for the week number + int sizeX = 15; + //we use two rows per week, some additional space between months... + //so that should be ok, but can be improved of course + //@todo improve calendar size prediction! + int sizeY = 4 + (int)(0.5*(float)(start.daysTo(end))); + + if (!sheet->areaIsEmpty(QRect(selection,QSize(sizeX,sizeY)))) + { + if (KMessageBox::No == KMessageBox::warningYesNo(NULL,i18n("The area where the calendar is inserted is NOT empty, are you sure you want to continue, overwriting existing data? If you choose No the area that would be required for the desired calendar will be selected so you can see what data would be overwritten."),i18n("Warning"))) + { + //select the area so the user knows what's in the way + selection_info->initialize(QRect(selection.x(),selection.y(),sizeX,sizeY));//,sheet); + return; + } + } + + KCalendarSystem* cs = KCalendarSystemFactory::create(); + + Q_ASSERT(cs); + + document->emitBeginOperation(); + + int row = selection.y(); + int col = selection.x(); + int colstart = col; //this is where we get back after each week + sheet->setText(row,colstart,i18n("Calendar from %1 to %2").arg(start.toString()).arg(end.toString())); + + QDate current(start); +// QDate previous(current); + bool yearheader = true; + bool monthheader = true; + bool weekheader = true; + + //this loop creates the actual calendar + //@todo formatting of cells - each day occupies QRect(row,col,row,col+1) + while (current <= end) + { + + //let's see if any header is required + if (cs->dayOfWeek(current)==1) + { + col=colstart; + row++; + weekheader=true; + } + if (cs->day(current)==1) + { + row+=2; + col=colstart + (cs->dayOfWeek(current)-1)*2; + monthheader=true; + weekheader=true; + if (cs->month(current)==1) + { + row++; + yearheader=true; + } + } + + if (yearheader) + { + kdDebug() << "inserting year " + QString::number(current.year()) << endl; + sheet->setText(row,colstart+6,cs->yearString(current,false)); + + row+=2; + yearheader=false; + } + if (monthheader) + { + kdDebug() << "inserting month " + QString::number(current.month()) << endl; + sheet->setText(row,colstart+6,cs->monthName(current,false)); + row+=2; + //we always have the week number in the first column + sheet->setText(row,colstart,i18n("week")); + for (int i=1; i<8; i++) + { + sheet->setText(row,colstart+(i-1)*2+1,cs->weekDayName(i)); + } + row++; + monthheader=false; + } + if (weekheader) + { + sheet->setText(row,colstart,QString::number(cs->weekNumber(current))); + col++; + weekheader=false; + + //if we are at the beginning of the month we might need an offset + if (cs->day(current)==1) + { + col=colstart + (cs->dayOfWeek(current)-1)*2 + 1; + } + } + + sheet->setText(row,col,QString::number(cs->day(current))); + //go to the next date + //@todo isn't there a better way, like current++ or something?? + QDate next = current.addDays(1); + current.setYMD(next.year(),next.month(),next.day()); + col+=2; + + } + + document->emitEndOperation(); + + kdDebug() << "inserting calendar completed" << endl; +} + +} + +#include "kspread_plugininsertcalendar.moc" diff --git a/kspread/plugins/insertcalendar/kspread_plugininsertcalendar.h b/kspread/plugins/insertcalendar/kspread_plugininsertcalendar.h new file mode 100644 index 000000000..9eb6060df --- /dev/null +++ b/kspread/plugins/insertcalendar/kspread_plugininsertcalendar.h @@ -0,0 +1,113 @@ +/*************************************************************************** + * Copyright (C) 2005 by Raphael Langerhorst * + * raphael-langerhorst@gmx.at * + * * + * Permission is hereby granted, free of charge, to any person obtaining * + * a copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to * + * the following conditions: * + * * + * The above copyright notice and this permission notice shall be * + * included in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.* + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * + * OTHER DEALINGS IN THE SOFTWARE. * + ***************************************************************************/ + +#ifndef KSPREAD_PLUGININSERTCALENDAR_H +#define KSPREAD_PLUGININSERTCALENDAR_H + +#include <kparts/plugin.h> + +#include <koffice_export.h> + +#include <qdatetime.h> + +class KAboutData; + +namespace KSpread +{ +class View; + +class InsertCalendarDialog; + +/** + * \class PluginInsertCalender kspread_plugininsertcalendar.h + * \brief Plugin for inserting a calendar into a spreadsheet. + * @author Raphael Langerhorst + * + * The plugin class for the Insert Calendar plugin. + * This plugin is designed to work in KSpread and + * makes it possible to insert calendars into + * the spreadsheet. + */ +class KSPREAD_EXPORT PluginInsertCalendar : public KParts::Plugin +{ + Q_OBJECT + + protected: + + /** + * This is the parent part of the plugin. It is used + * to access the spreadsheet and actually insert the + * calendar. + * + * It is set in the constructor. + */ + View* m_kspreadView; + + /** + * This is the dialog used to select the start/end dates + * of the calendar. It is the user interface of this + * plugin. + * @see InsertCalendarDialog, slotShowDialog, slotInsertCalendar + */ + InsertCalendarDialog* m_dialog; + + public: + + /** + * Constructor. This constructor is usable with KGenericFactory. + */ + PluginInsertCalendar( QObject *parent, const char *name, const QStringList& args ); + + /** + * Virtual destructor. + */ + virtual ~PluginInsertCalendar(); + + public: + + /** + * Creates about data for the Insert Calendar plugin. + */ + static KAboutData* createAboutData(); + + public slots: + + /** + * This is called from the plugin action, it shows a dialog that + * allows start and end date selection and various other + * options. The calendar can then be inserted into a spreadsheet. + */ + void slotShowDialog(); + + /** + * This actually inserts the calendar. It reads the configuration + * from the insert calendar dialog and builds an calendar in the + * spreadsheet accordingly. + */ + void slotInsertCalendar(const QDate &start, const QDate &end); +}; + +} + +#endif |
