You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
604 lines
17 KiB
604 lines
17 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
|
||
|
(C) 1998-2001 Mirko Boehm (mirko@kde.org)
|
||
|
(C) 2004 Dag Andersen <danders@get2net.dk>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
/* This is based on KDatePicker. */
|
||
|
|
||
|
#include "kptcalendarpanel.h"
|
||
|
#include "kptdatetable.h"
|
||
|
#include "kptcalendar.h"
|
||
|
|
||
|
|
||
12 years ago
|
#include <tdeglobal.h>
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <kcalendarsystem.h>
|
||
|
#include <kiconloader.h>
|
||
14 years ago
|
#include <tqframe.h>
|
||
|
#include <tqpainter.h>
|
||
|
#include <tqdialog.h>
|
||
|
#include <tqstyle.h>
|
||
|
#include <tqtoolbutton.h>
|
||
|
#include <tqtooltip.h>
|
||
|
#include <tqfont.h>
|
||
15 years ago
|
#include <klineedit.h>
|
||
14 years ago
|
#include <tqvalidator.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
#include <knotifyclient.h>
|
||
|
|
||
|
namespace KPlato
|
||
|
{
|
||
|
|
||
|
class CalendarPanel::CalendarPanelPrivate
|
||
|
{
|
||
|
public:
|
||
|
CalendarPanelPrivate() : closeButton(0L), selectWeek(0L) {}
|
||
|
|
||
14 years ago
|
TQToolButton *closeButton;
|
||
|
TQToolButton *selectWeek;
|
||
15 years ago
|
};
|
||
|
|
||
|
|
||
14 years ago
|
CalendarPanel::CalendarPanel(TQWidget *parent, TQDate dt, const char *name, WFlags f)
|
||
|
: TQFrame(parent,name, f)
|
||
15 years ago
|
{
|
||
|
init( dt );
|
||
|
}
|
||
|
|
||
14 years ago
|
CalendarPanel::CalendarPanel( TQWidget *parent, const char *name )
|
||
|
: TQFrame(parent,name)
|
||
15 years ago
|
{
|
||
13 years ago
|
init( TQDate::currentDate() );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void CalendarPanel::init( const TQDate &dt )
|
||
15 years ago
|
{
|
||
14 years ago
|
yearForward = new TQToolButton(this);
|
||
|
yearBackward = new TQToolButton(this);
|
||
|
monthForward = new TQToolButton(this);
|
||
|
monthBackward = new TQToolButton(this);
|
||
|
selectMonth = new TQToolButton(this);
|
||
|
selectYear = new TQToolButton(this);
|
||
15 years ago
|
line = new KLineEdit(this);
|
||
|
val = new DateValidator(this);
|
||
|
table = new DateTable(this, dt, "Calendar table", 0);
|
||
|
fontsize = 10;
|
||
|
|
||
|
d = new CalendarPanelPrivate();
|
||
14 years ago
|
d->selectWeek = new TQToolButton( this );
|
||
15 years ago
|
|
||
14 years ago
|
TQToolTip::add(yearForward, i18n("Next year"));
|
||
|
TQToolTip::add(yearBackward, i18n("Previous year"));
|
||
|
TQToolTip::add(monthForward, i18n("Next month"));
|
||
|
TQToolTip::add(monthBackward, i18n("Previous month"));
|
||
|
TQToolTip::add(d->selectWeek, i18n("Select a week"));
|
||
|
TQToolTip::add(selectMonth, i18n("Select a month"));
|
||
|
TQToolTip::add(selectYear, i18n("Select a year"));
|
||
15 years ago
|
|
||
|
// -----
|
||
|
setFontSize(10);
|
||
|
line->setValidator(val);
|
||
|
line->installEventFilter( this );
|
||
13 years ago
|
yearForward->setPixmap(BarIcon(TQString::fromLatin1("2rightarrow")));
|
||
|
yearBackward->setPixmap(BarIcon(TQString::fromLatin1("2leftarrow")));
|
||
|
monthForward->setPixmap(BarIcon(TQString::fromLatin1("1rightarrow")));
|
||
|
monthBackward->setPixmap(BarIcon(TQString::fromLatin1("1leftarrow")));
|
||
15 years ago
|
setDate(dt); // set button texts
|
||
14 years ago
|
connect(table, TQT_SIGNAL(dateChanged(TQDate)), TQT_SLOT(dateChangedSlot(TQDate)));
|
||
|
connect(table, TQT_SIGNAL(tableClicked()), TQT_SLOT(tableClickedSlot()));
|
||
|
connect(monthForward, TQT_SIGNAL(clicked()), TQT_SLOT(monthForwardClicked()));
|
||
|
connect(monthBackward, TQT_SIGNAL(clicked()), TQT_SLOT(monthBackwardClicked()));
|
||
|
connect(yearForward, TQT_SIGNAL(clicked()), TQT_SLOT(yearForwardClicked()));
|
||
|
connect(yearBackward, TQT_SIGNAL(clicked()), TQT_SLOT(yearBackwardClicked()));
|
||
|
connect(d->selectWeek, TQT_SIGNAL(clicked()), TQT_SLOT(selectWeekClicked()));
|
||
|
connect(selectMonth, TQT_SIGNAL(clicked()), TQT_SLOT(selectMonthClicked()));
|
||
|
connect(selectYear, TQT_SIGNAL(clicked()), TQT_SLOT(selectYearClicked()));
|
||
|
connect(line, TQT_SIGNAL(returnPressed()), TQT_SLOT(lineEnterPressed()));
|
||
|
|
||
|
connect(table, TQT_SIGNAL(weekdaySelected(int)), TQT_SLOT(slotWeekdaySelected(int)));
|
||
|
connect(table, TQT_SIGNAL(weekSelected(int, int)), TQT_SLOT(slotWeekSelected(int, int)));
|
||
|
connect(table, TQT_SIGNAL(selectionCleared()), TQT_SLOT(slotSelectionCleared()));
|
||
15 years ago
|
|
||
|
table->setFocus();
|
||
|
}
|
||
|
|
||
|
CalendarPanel::~CalendarPanel()
|
||
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
|
bool
|
||
14 years ago
|
CalendarPanel::eventFilter(TQObject *o, TQEvent *e )
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( e->type() == TQEvent::KeyPress ) {
|
||
|
TQKeyEvent *k = (TQKeyEvent *)e;
|
||
15 years ago
|
|
||
14 years ago
|
if ( (k->key() == TQt::Key_Prior) ||
|
||
|
(k->key() == TQt::Key_Next) ||
|
||
|
(k->key() == TQt::Key_Up) ||
|
||
|
(k->key() == TQt::Key_Down) )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQApplication::sendEvent( table, e );
|
||
15 years ago
|
table->setFocus();
|
||
|
return TRUE; // eat event
|
||
|
}
|
||
|
}
|
||
14 years ago
|
return TQFrame::eventFilter( o, e );
|
||
15 years ago
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
CalendarPanel::resizeEvent(TQResizeEvent*)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQWidget *buttons[] = {
|
||
15 years ago
|
yearBackward,
|
||
|
monthBackward,
|
||
|
selectMonth,
|
||
|
selectYear,
|
||
|
monthForward,
|
||
|
yearForward,
|
||
|
d->closeButton
|
||
|
};
|
||
|
const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
|
||
14 years ago
|
TQSize sizes[NoOfButtons];
|
||
15 years ago
|
int buttonHeight=0;
|
||
|
int count;
|
||
|
int w=0;
|
||
|
int x=0;
|
||
|
// ----- calculate button row height:
|
||
|
for(count=0; count<NoOfButtons; ++count) {
|
||
|
if ( buttons[count] ) { // closeButton may be 0L
|
||
13 years ago
|
sizes[count]=buttons[count]->sizeHint();
|
||
14 years ago
|
buttonHeight=TQMAX(buttonHeight, sizes[count].height());
|
||
15 years ago
|
}
|
||
|
else
|
||
14 years ago
|
sizes[count] = TQSize(0,0); // closeButton
|
||
15 years ago
|
}
|
||
|
|
||
|
// ----- calculate size of the month button:
|
||
|
for(count=0; count<NoOfButtons; ++count) {
|
||
|
if(buttons[count]==selectMonth) {
|
||
13 years ago
|
TQSize metricBound = style().tqsizeFromContents(TQStyle::CT_ToolButton, selectMonth, maxMonthRect);
|
||
|
sizes[count].setWidth(TQMAX(metricBound.width(), maxMonthRect.width()+2*TQApplication::style().pixelMetric(TQStyle::PM_ButtonMargin)));
|
||
15 years ago
|
}
|
||
|
}
|
||
|
// ----- center buttons
|
||
|
w=0;
|
||
|
for(count=0; count<NoOfButtons; ++count)
|
||
|
{
|
||
|
w +=sizes[count].width();
|
||
|
}
|
||
14 years ago
|
x = (TQMAX(w, width())-w)/2;
|
||
15 years ago
|
|
||
|
// ----- place the buttons:
|
||
|
for(count=0; count<NoOfButtons; ++count)
|
||
|
{
|
||
|
w=sizes[count].width();
|
||
|
if ( buttons[count] )
|
||
|
buttons[count]->setGeometry(x, 0, w, buttonHeight);
|
||
|
x+=w;
|
||
|
}
|
||
|
// ----- place the line edit for direct input:
|
||
13 years ago
|
sizes[0]=line->sizeHint();
|
||
15 years ago
|
int week_width=d->selectWeek->fontMetrics().width(i18n("Week XX"))+((d->closeButton != 0L) ? 50 : 20);
|
||
|
line->setGeometry(0, height()-sizes[0].height(), width()-week_width, sizes[0].height());
|
||
|
d->selectWeek->setGeometry(width()-week_width, height()-sizes[0].height(), week_width, sizes[0].height());
|
||
|
// ----- adjust the table:
|
||
|
table->setGeometry(0, buttonHeight, width(),
|
||
|
height()-buttonHeight-sizes[0].height());
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
CalendarPanel::dateChangedSlot(TQDate date)
|
||
15 years ago
|
{
|
||
|
//kdDebug() << "CalendarPanel::dateChangedSlot: date changed (" << date.year() << "/" << date.month() << "/" << date.day() << ")." << endl;
|
||
12 years ago
|
line->setText(TDEGlobal::locale()->formatDate(date, true));
|
||
13 years ago
|
d->selectWeek->setText(i18n("Week %1").arg(weekOfYear(date)));
|
||
12 years ago
|
selectMonth->setText(TDEGlobal::locale()->calendar()->monthName(date.month(), false));
|
||
15 years ago
|
selectYear->setText(date.toString("yyyy"));
|
||
|
emit(dateChanged(date));
|
||
|
}
|
||
|
|
||
|
void
|
||
|
CalendarPanel::tableClickedSlot()
|
||
|
{
|
||
|
//kdDebug() << "CalendarPanel::tableClickedSlot: table clicked." << endl;
|
||
|
emit(dateSelected(table->getDate()));
|
||
|
emit(tableClicked());
|
||
|
}
|
||
|
|
||
14 years ago
|
const TQDate&
|
||
15 years ago
|
CalendarPanel::getDate() const
|
||
|
{
|
||
|
return table->getDate();
|
||
|
}
|
||
|
|
||
14 years ago
|
const TQDate &
|
||
15 years ago
|
CalendarPanel::date() const
|
||
|
{
|
||
|
return table->getDate();
|
||
|
}
|
||
|
|
||
|
bool
|
||
14 years ago
|
CalendarPanel::setDate(const TQDate& date)
|
||
15 years ago
|
{
|
||
|
if(date.isValid()) {
|
||
14 years ago
|
TQString temp;
|
||
15 years ago
|
// -----
|
||
|
table->setDate(date);
|
||
13 years ago
|
d->selectWeek->setText(i18n("Week %1").arg(weekOfYear(date)));
|
||
12 years ago
|
selectMonth->setText(TDEGlobal::locale()->calendar()->monthName(date.month(), false));
|
||
15 years ago
|
temp.setNum(date.year());
|
||
|
selectYear->setText(temp);
|
||
12 years ago
|
line->setText(TDEGlobal::locale()->formatDate(date, true));
|
||
15 years ago
|
return true;
|
||
|
} else {
|
||
|
kdDebug() << "CalendarPanel::setDate: refusing to set invalid date." << endl;
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
|
CalendarPanel::monthForwardClicked()
|
||
|
{
|
||
|
setDate( table->getDate().addMonths(1) );
|
||
|
}
|
||
|
|
||
|
void
|
||
|
CalendarPanel::monthBackwardClicked()
|
||
|
{
|
||
|
setDate( table->getDate().addMonths(-1) );
|
||
|
}
|
||
|
|
||
|
void
|
||
|
CalendarPanel::yearForwardClicked()
|
||
|
{
|
||
|
setDate( table->getDate().addYears(1) );
|
||
|
}
|
||
|
|
||
|
void
|
||
|
CalendarPanel::yearBackwardClicked()
|
||
|
{
|
||
|
setDate( table->getDate().addYears(-1) );
|
||
|
}
|
||
|
|
||
|
void
|
||
|
CalendarPanel::selectWeekClicked()
|
||
|
{
|
||
|
int week;
|
||
|
PopupFrame* popup = new PopupFrame(this);
|
||
|
DateInternalWeekSelector* picker = new DateInternalWeekSelector(fontsize, popup);
|
||
|
// -----
|
||
13 years ago
|
picker->resize(picker->sizeHint());
|
||
15 years ago
|
popup->setMainWidget(picker);
|
||
14 years ago
|
connect(picker, TQT_SIGNAL(closeMe(int)), popup, TQT_SLOT(close(int)));
|
||
15 years ago
|
picker->setFocus();
|
||
14 years ago
|
if(popup->exec(d->selectWeek->mapToGlobal(TQPoint(0, d->selectWeek->height()))))
|
||
15 years ago
|
{
|
||
14 years ago
|
TQDate date;
|
||
15 years ago
|
int year;
|
||
|
// -----
|
||
|
week=picker->getWeek();
|
||
|
date=table->getDate();
|
||
|
year=date.year();
|
||
|
// ----- find the first selectable day in this week (hacky solution :)
|
||
|
date.setYMD(year, 1, 1);
|
||
|
while (weekOfYear(date)>50)
|
||
|
date=date.addDays(1);
|
||
|
while (weekOfYear(date)<week && (week!=53 || (week==53 &&
|
||
|
(weekOfYear(date)!=52 || weekOfYear(date.addDays(1))!=1))))
|
||
|
date=date.addDays(1);
|
||
|
if (week==53 && weekOfYear(date)==52)
|
||
|
while (weekOfYear(date.addDays(-1))==52)
|
||
|
date=date.addDays(-1);
|
||
|
// ----- set this date
|
||
|
setDate(date);
|
||
|
} else {
|
||
|
KNotifyClient::beep();
|
||
|
}
|
||
|
delete popup;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
CalendarPanel::selectMonthClicked()
|
||
|
{
|
||
|
int month;
|
||
|
PopupFrame* popup = new PopupFrame(this);
|
||
|
DateInternalMonthPicker* picker = new DateInternalMonthPicker(fontsize, popup);
|
||
|
// -----
|
||
13 years ago
|
picker->resize(picker->sizeHint());
|
||
15 years ago
|
popup->setMainWidget(picker);
|
||
|
picker->setFocus();
|
||
14 years ago
|
connect(picker, TQT_SIGNAL(closeMe(int)), popup, TQT_SLOT(close(int)));
|
||
|
if(popup->exec(selectMonth->mapToGlobal(TQPoint(0, selectMonth->height()))))
|
||
15 years ago
|
{
|
||
14 years ago
|
TQDate date;
|
||
15 years ago
|
int day;
|
||
|
// -----
|
||
|
month=picker->getResult();
|
||
|
date=table->getDate();
|
||
|
day=date.day();
|
||
|
// ----- construct a valid date in this month:
|
||
|
date.setYMD(date.year(), month, 1);
|
||
14 years ago
|
date.setYMD(date.year(), month, TQMIN(day, date.daysInMonth()));
|
||
15 years ago
|
// ----- set this month
|
||
|
setDate(date);
|
||
|
} else {
|
||
|
KNotifyClient::beep();
|
||
|
}
|
||
|
delete popup;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
CalendarPanel::selectYearClicked()
|
||
|
{
|
||
|
int year;
|
||
|
PopupFrame* popup = new PopupFrame(this);
|
||
|
DateInternalYearSelector* picker = new DateInternalYearSelector(fontsize, popup);
|
||
|
// -----
|
||
13 years ago
|
picker->resize(picker->sizeHint());
|
||
15 years ago
|
popup->setMainWidget(picker);
|
||
14 years ago
|
connect(picker, TQT_SIGNAL(closeMe(int)), popup, TQT_SLOT(close(int)));
|
||
15 years ago
|
picker->setFocus();
|
||
14 years ago
|
if(popup->exec(selectYear->mapToGlobal(TQPoint(0, selectMonth->height()))))
|
||
15 years ago
|
{
|
||
14 years ago
|
TQDate date;
|
||
15 years ago
|
int day;
|
||
|
// -----
|
||
|
year=picker->getYear();
|
||
|
date=table->getDate();
|
||
|
day=date.day();
|
||
|
// ----- construct a valid date in this month:
|
||
|
date.setYMD(year, date.month(), 1);
|
||
14 years ago
|
date.setYMD(year, date.month(), TQMIN(day, date.daysInMonth()));
|
||
15 years ago
|
// ----- set this month
|
||
|
setDate(date);
|
||
|
} else {
|
||
|
KNotifyClient::beep();
|
||
|
}
|
||
|
delete popup;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
CalendarPanel::setEnabled(bool enable)
|
||
|
{
|
||
14 years ago
|
TQWidget *widgets[]= {
|
||
15 years ago
|
yearForward, yearBackward, monthForward, monthBackward,
|
||
|
selectMonth, selectYear,
|
||
|
line, table, d->selectWeek };
|
||
|
const int Size=sizeof(widgets)/sizeof(widgets[0]);
|
||
|
int count;
|
||
|
// -----
|
||
|
for(count=0; count<Size; ++count)
|
||
|
{
|
||
|
widgets[count]->setEnabled(enable);
|
||
|
}
|
||
|
table->setEnabled(enable);
|
||
|
}
|
||
|
|
||
|
void
|
||
|
CalendarPanel::lineEnterPressed()
|
||
|
{
|
||
14 years ago
|
TQDate temp;
|
||
15 years ago
|
// -----
|
||
14 years ago
|
if(val->date(line->text(), temp)==TQValidator::Acceptable)
|
||
15 years ago
|
{
|
||
|
//kdDebug() << "CalendarPanel::lineEnterPressed: valid date entered." << endl;
|
||
|
emit(dateEntered(temp));
|
||
|
setDate(temp);
|
||
|
} else {
|
||
|
KNotifyClient::beep();
|
||
|
//kdDebug() << "CalendarPanel::lineEnterPressed: invalid date entered." << endl;
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
TQSize
|
||
13 years ago
|
CalendarPanel::sizeHint() const
|
||
15 years ago
|
{
|
||
13 years ago
|
TQSize tableSize=table->sizeHint();
|
||
14 years ago
|
TQWidget *buttons[]={
|
||
15 years ago
|
yearBackward,
|
||
|
monthBackward,
|
||
|
selectMonth,
|
||
|
selectYear,
|
||
|
monthForward,
|
||
|
yearForward,
|
||
|
d->closeButton
|
||
|
};
|
||
|
const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
|
||
14 years ago
|
TQSize sizes[NoOfButtons];
|
||
15 years ago
|
int cx=0, cy=0, count;
|
||
|
// ----- store the size hints:
|
||
|
for(count=0; count<NoOfButtons; ++count) {
|
||
|
if ( buttons[count] )
|
||
13 years ago
|
sizes[count]=buttons[count]->sizeHint();
|
||
15 years ago
|
else
|
||
14 years ago
|
sizes[count] = TQSize(0,0);
|
||
15 years ago
|
|
||
|
if(buttons[count]==selectMonth) {
|
||
13 years ago
|
TQSize metricBound = style().tqsizeFromContents(TQStyle::CT_ToolButton, selectMonth, maxMonthRect);
|
||
|
cx+=TQMAX(metricBound.width(), maxMonthRect.width()+2*TQApplication::style().pixelMetric(TQStyle::PM_ButtonMargin));
|
||
15 years ago
|
} else {
|
||
|
cx+=sizes[count].width();
|
||
|
}
|
||
14 years ago
|
cy=TQMAX(sizes[count].height(), cy);
|
||
15 years ago
|
}
|
||
|
// ----- calculate width hint:
|
||
14 years ago
|
cx=TQMAX(cx, tableSize.width()); // line edit ignored
|
||
15 years ago
|
// ----- calculate height hint:
|
||
13 years ago
|
cy+=tableSize.height()+line->sizeHint().height();
|
||
14 years ago
|
return TQSize(cx, cy);
|
||
15 years ago
|
}
|
||
|
|
||
|
void
|
||
|
CalendarPanel::setFontSize(int s)
|
||
|
{
|
||
14 years ago
|
TQWidget *buttons[]= {
|
||
15 years ago
|
// yearBackward,
|
||
|
// monthBackward,
|
||
|
selectMonth,
|
||
|
selectYear,
|
||
|
// monthForward,
|
||
|
// yearForward
|
||
|
};
|
||
|
const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
|
||
|
int count;
|
||
14 years ago
|
TQFont font;
|
||
|
TQRect r;
|
||
15 years ago
|
// -----
|
||
|
fontsize=s;
|
||
|
for(count=0; count<NoOfButtons; ++count)
|
||
|
{
|
||
|
font=buttons[count]->font();
|
||
|
font.setPointSize(s);
|
||
|
buttons[count]->setFont(font);
|
||
|
}
|
||
14 years ago
|
TQFontMetrics metrics(selectMonth->fontMetrics());
|
||
15 years ago
|
for(int i=1; i <= 12; ++i)
|
||
13 years ago
|
{ // maxMonthRect is used by sizeHint()
|
||
12 years ago
|
r=metrics.boundingRect(TDEGlobal::locale()->calendar()->monthName(i, false));
|
||
14 years ago
|
maxMonthRect.setWidth(TQMAX(r.width(), maxMonthRect.width()));
|
||
|
maxMonthRect.setHeight(TQMAX(r.height(), maxMonthRect.height()));
|
||
15 years ago
|
}
|
||
|
table->setFontSize(s);
|
||
|
}
|
||
|
|
||
|
void
|
||
|
CalendarPanel::setCloseButton( bool enable )
|
||
|
{
|
||
|
if ( enable == (d->closeButton != 0L) )
|
||
|
return;
|
||
|
|
||
|
if ( enable ) {
|
||
14 years ago
|
d->closeButton = new TQToolButton( this );
|
||
|
TQToolTip::add(d->closeButton, i18n("Close"));
|
||
15 years ago
|
d->closeButton->setPixmap( SmallIcon("remove") );
|
||
14 years ago
|
connect( d->closeButton, TQT_SIGNAL( clicked() ),
|
||
13 years ago
|
topLevelWidget(), TQT_SLOT( close() ) );
|
||
15 years ago
|
}
|
||
|
else {
|
||
|
delete d->closeButton;
|
||
|
d->closeButton = 0L;
|
||
|
}
|
||
|
|
||
|
updateGeometry();
|
||
|
}
|
||
|
|
||
|
bool CalendarPanel::hasCloseButton() const
|
||
|
{
|
||
|
return (d->closeButton != 0L);
|
||
|
}
|
||
|
|
||
14 years ago
|
int CalendarPanel::weekOfYear(TQDate date)
|
||
15 years ago
|
{
|
||
|
// Calculate ISO 8601 week number (taken from glibc/Gnumeric)
|
||
|
int year, week, wday, jan1wday, nextjan1wday;
|
||
14 years ago
|
TQDate jan1date, nextjan1date;
|
||
15 years ago
|
|
||
|
year=date.year();
|
||
|
wday=date.dayOfWeek();
|
||
|
|
||
14 years ago
|
jan1date=TQDate(year,1,1);
|
||
15 years ago
|
jan1wday=jan1date.dayOfWeek();
|
||
|
|
||
|
week = (date.dayOfYear()-1 + jan1wday-1)/7 + ((jan1wday-1) == 0 ? 1 : 0);
|
||
|
|
||
|
/* Does date belong to last week of previous year? */
|
||
|
if ((week == 0) && (jan1wday > 4 /*THURSDAY*/)) {
|
||
14 years ago
|
TQDate tmpdate=TQDate(year-1,12,31);
|
||
15 years ago
|
return weekOfYear(tmpdate);
|
||
|
}
|
||
|
|
||
|
if ((jan1wday <= 4 /*THURSDAY*/) && (jan1wday > 1 /*MONDAY*/))
|
||
|
week++;
|
||
|
|
||
|
if (week == 53) {
|
||
14 years ago
|
nextjan1date=TQDate(year+1, 1, 1);
|
||
15 years ago
|
nextjan1wday = nextjan1date.dayOfWeek();
|
||
|
if (nextjan1wday <= 4 /*THURSDAY*/)
|
||
|
week = 1;
|
||
|
}
|
||
|
|
||
|
return week;
|
||
|
}
|
||
|
|
||
|
void CalendarPanel::slotWeekdaySelected(int day) {
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
emit weekdaySelected(day);
|
||
|
}
|
||
|
|
||
|
void CalendarPanel::slotWeekSelected(int week, int year) {
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
emit weekSelected(week, year);
|
||
|
}
|
||
|
|
||
|
void CalendarPanel::setCalendar(Calendar *cal) {
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
table->clear();
|
||
|
if (cal) {
|
||
|
table->setMarkedWeekdays(cal->weekdaysMap());
|
||
14 years ago
|
TQPtrListIterator<CalendarDay> it = cal->days();
|
||
15 years ago
|
//kdDebug()<<k_funcinfo<<"Days="<<it.count()<<endl;
|
||
|
for (; it.current(); ++it) {
|
||
|
if (it.current()->state() != Map::None) {
|
||
|
table->addMarkedDate(it.current()->date(), it.current()->state());
|
||
|
//kdDebug()<<k_funcinfo<<"Added day: "<<it.current()->date().toString()<<"="<<it.current()->state()<<endl;
|
||
|
}
|
||
|
}
|
||
|
setEnabled(true);
|
||
|
table->setFocus();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
DateMap CalendarPanel::selectedDates() {
|
||
|
return table->selectedDates();
|
||
|
}
|
||
|
|
||
|
IntMap CalendarPanel::selectedWeekdays() {
|
||
|
return table->selectedWeekdays();
|
||
|
}
|
||
|
|
||
|
DateMap CalendarPanel::markedDates() {
|
||
|
return table->markedDates();
|
||
|
}
|
||
|
|
||
|
IntMap CalendarPanel::markedWeekdays() {
|
||
|
return table->markedWeekdays();
|
||
|
}
|
||
|
|
||
|
void CalendarPanel::clear() {
|
||
|
table->clear();
|
||
|
setEnabled(false);
|
||
|
}
|
||
|
|
||
|
void CalendarPanel::markSelected(int state) {
|
||
|
table->markSelected(state);
|
||
|
}
|
||
|
|
||
|
void CalendarPanel::slotSelectionCleared() {
|
||
|
emit selectionCleared();
|
||
|
}
|
||
|
|
||
|
void CalendarPanel::virtual_hook( int /*id*/, void* /*data*/ )
|
||
|
{ /*BASE::virtual_hook( id, data );*/ }
|
||
|
|
||
|
} //KPlato namespace
|
||
|
|
||
|
#include "kptcalendarpanel.moc"
|