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.
1077 lines
30 KiB
1077 lines
30 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-2006 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.
|
||
|
*/
|
||
|
|
||
|
#include "kptdatetable.h"
|
||
|
#include "kptmap.h"
|
||
|
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
15 years ago
|
#include <knotifyclient.h>
|
||
|
#include <kcalendarsystem.h>
|
||
|
|
||
14 years ago
|
#include <tqdatetime.h>
|
||
|
#include <tqstring.h>
|
||
|
#include <tqpen.h>
|
||
|
#include <tqpainter.h>
|
||
|
#include <tqdialog.h>
|
||
15 years ago
|
#include <assert.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
14 years ago
|
#include <tqvaluelist.h>
|
||
12 years ago
|
#include <tdeglobalsettings.h>
|
||
15 years ago
|
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
namespace KPlato
|
||
|
{
|
||
|
|
||
14 years ago
|
DateValidator::DateValidator(TQWidget* parent, const char* name)
|
||
|
: TQValidator(TQT_TQOBJECT(parent), name)
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
14 years ago
|
TQValidator::State
|
||
|
DateValidator::validate(TQString& text, int&) const
|
||
15 years ago
|
{
|
||
14 years ago
|
TQDate temp;
|
||
15 years ago
|
// ----- everything is tested in date():
|
||
|
return date(text, temp);
|
||
|
}
|
||
|
|
||
14 years ago
|
TQValidator::State
|
||
|
DateValidator::date(const TQString& text, TQDate& d) const
|
||
15 years ago
|
{
|
||
12 years ago
|
TQDate tmp = TDEGlobal::locale()->readDate(text);
|
||
15 years ago
|
if (!tmp.isNull())
|
||
|
{
|
||
|
d = tmp;
|
||
|
return Acceptable;
|
||
|
} else
|
||
|
return Valid;
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
DateValidator::fixup( TQString& ) const
|
||
15 years ago
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
DateTable::DateTable(TQWidget *parent, TQDate date_, const char* name, WFlags f)
|
||
|
: TQGridView(parent, name, f),
|
||
15 years ago
|
m_enabled(true)
|
||
|
{
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
m_dateStartCol = 1;
|
||
|
m_selectedDates.clear();
|
||
|
m_selectedWeekdays.clear();
|
||
|
|
||
14 years ago
|
TQPair<int, int> p(0,0);
|
||
15 years ago
|
m_weeks.fill(p, 7);
|
||
|
|
||
|
setFontSize(10);
|
||
|
if(!date_.isValid()) {
|
||
|
kdError() <<k_funcinfo<<"Given date is invalid, using current date." << endl;
|
||
13 years ago
|
date_=TQDate::currentDate();
|
||
15 years ago
|
}
|
||
14 years ago
|
setFocusPolicy( TQ_StrongFocus );
|
||
15 years ago
|
setNumCols(7+m_dateStartCol); // 7 days a week + maybe 1 for weeknumbers
|
||
|
setNumRows(7); // 6 weeks max + headline
|
||
|
|
||
|
setHScrollBarMode(AlwaysOff);
|
||
|
setVScrollBarMode(AlwaysOff);
|
||
12 years ago
|
viewport()->setEraseColor(TDEGlobalSettings::baseColor());
|
||
15 years ago
|
setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth
|
||
|
|
||
14 years ago
|
colorBackgroundHoliday = TQColor(0, 245, 255, TQColor::Hsv);
|
||
15 years ago
|
//colorBackgroundHoliday = colorBackgroundHoliday.light();
|
||
14 years ago
|
colorBackgroundWorkday = TQColor(208, 230, 240, TQColor::Hsv);;
|
||
15 years ago
|
//colorBackgroundWorkday = colorBackgroundWorkday.light();
|
||
|
colorTextHoliday = black;
|
||
|
colorTextWorkday = black;
|
||
|
colorLine = black;
|
||
12 years ago
|
backgroundSelectColor = TDEGlobalSettings::highlightColor();
|
||
|
penSelectColor=TDEGlobalSettings::baseColor();
|
||
15 years ago
|
|
||
|
}
|
||
|
|
||
14 years ago
|
void DateTable::paintWeekday(TQPainter *painter, int col) {
|
||
|
TQRect rect;
|
||
15 years ago
|
int w=cellWidth();
|
||
|
int h=cellHeight();
|
||
|
|
||
12 years ago
|
TQFont font = TDEGlobalSettings::generalFont();
|
||
15 years ago
|
font.setBold(true);
|
||
|
if (!m_enabled)
|
||
|
font.setItalic(true);
|
||
|
painter->setFont(font);
|
||
|
|
||
|
int day = weekday(col);
|
||
|
|
||
|
//kdDebug()<<k_funcinfo<<" col="<<col<<" day="<<day<<" name="<<daystr<<endl;
|
||
|
|
||
12 years ago
|
painter->setBrush(TDEGlobalSettings::baseColor());
|
||
|
painter->setPen(TDEGlobalSettings::baseColor());
|
||
15 years ago
|
painter->drawRect(0, 0, w, h);
|
||
12 years ago
|
painter->setPen(TDEGlobalSettings::textColor());
|
||
15 years ago
|
|
||
|
if (m_markedWeekdays.state(day) == Map::Working) {
|
||
|
painter->setPen(colorBackgroundWorkday);
|
||
|
painter->setBrush(colorBackgroundWorkday);
|
||
|
painter->drawRect(0, 0, w, h);
|
||
|
painter->setPen(colorTextWorkday);
|
||
|
} else if (m_markedWeekdays.state(day) == Map::NonWorking) {
|
||
|
painter->setPen(colorBackgroundHoliday);
|
||
|
painter->setBrush(colorBackgroundHoliday);
|
||
|
painter->drawRect(0, 0, w, h);
|
||
|
painter->setPen(colorTextHoliday);
|
||
|
}
|
||
14 years ago
|
if (m_selectedWeekdays.contains(day)) {
|
||
15 years ago
|
painter->setPen(backgroundSelectColor);
|
||
|
painter->setBrush(backgroundSelectColor);
|
||
|
painter->drawRect(2, 2, w-4, h-4);
|
||
|
painter->setPen(penSelectColor);
|
||
|
}
|
||
12 years ago
|
painter->drawText(0, 0, w, h-1, AlignCenter, TDEGlobal::locale()->calendar()->weekDayName(day, true), -1, &rect);
|
||
15 years ago
|
painter->setPen(colorLine);
|
||
|
painter->moveTo(0, h-1);
|
||
|
painter->lineTo(w-1, h-1);
|
||
|
|
||
|
if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width());
|
||
|
if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height());
|
||
|
|
||
|
//kdDebug()<<k_funcinfo<<"headline: row,col=("<<row<<","<<col<<")"<<" day="<<daystr<<endl;
|
||
|
}
|
||
|
|
||
14 years ago
|
void DateTable::paintWeekNumber(TQPainter *painter, int row) {
|
||
|
TQRect rect;
|
||
15 years ago
|
int w=cellWidth();
|
||
|
int h=cellHeight();
|
||
|
|
||
12 years ago
|
TQFont font=TDEGlobalSettings::generalFont();
|
||
15 years ago
|
font.setBold(true);
|
||
|
if (!m_enabled)
|
||
|
font.setItalic(true);
|
||
|
painter->setFont(font);
|
||
|
|
||
12 years ago
|
painter->setBrush(TDEGlobalSettings::baseColor());
|
||
|
painter->setPen(TDEGlobalSettings::baseColor());
|
||
15 years ago
|
painter->drawRect(0, 0, w, h);
|
||
12 years ago
|
painter->setPen(TDEGlobalSettings::textColor());
|
||
15 years ago
|
|
||
13 years ago
|
painter->drawText(0, 0, w, h-1, AlignCenter, TQString("%1").arg(m_weeks[row].first), -1, &rect);
|
||
15 years ago
|
painter->setPen(colorLine);
|
||
|
painter->moveTo(w-1, 0);
|
||
|
painter->lineTo(w-1, h-1);
|
||
|
|
||
|
if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width());
|
||
|
if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height());
|
||
|
}
|
||
|
|
||
14 years ago
|
void DateTable::paintDay(TQPainter *painter, int row, int col) {
|
||
15 years ago
|
//kdDebug()<<k_funcinfo<<"row,col=("<<row<<","<<col<<")"<<" num col="<<numCols()<<endl;
|
||
14 years ago
|
TQRect rect;
|
||
15 years ago
|
int w=cellWidth();
|
||
|
int h=cellHeight();
|
||
|
|
||
12 years ago
|
TQFont font=TDEGlobalSettings::generalFont();
|
||
15 years ago
|
font.setPointSize(fontsize);
|
||
|
if (!m_enabled)
|
||
|
font.setItalic(true);
|
||
|
painter->setFont(font);
|
||
|
|
||
14 years ago
|
TQDate d = getDate(position(row, col));
|
||
15 years ago
|
|
||
12 years ago
|
painter->setBrush(TDEGlobalSettings::baseColor());
|
||
|
painter->setPen(TDEGlobalSettings::baseColor());
|
||
15 years ago
|
painter->drawRect(0, 0, w, h);
|
||
|
|
||
|
// First paint the dates background
|
||
|
if (m_markedDates.state(d) == Map::NonWorking) {
|
||
|
//kdDebug()<<k_funcinfo<<"Marked date: "<<d<<" row,col=("<<row<<","<<col<<")=NonWorking"<<endl;
|
||
|
painter->setPen(colorBackgroundHoliday);
|
||
|
painter->setBrush(colorBackgroundHoliday);
|
||
|
painter->drawRect(0, 0, w, h);
|
||
|
} else if (m_markedDates.state(d) == Map::Working) {
|
||
|
//kdDebug()<<k_funcinfo<<"Marked date: "<<d<<" row,col=("<<row<<","<<col<<")=Working"<<endl;
|
||
|
painter->setPen(colorBackgroundWorkday);
|
||
|
painter->setBrush(colorBackgroundWorkday);
|
||
|
painter->drawRect(0, 0, w, h);
|
||
|
}
|
||
14 years ago
|
if(m_selectedDates.contains(d)) {
|
||
15 years ago
|
//kdDebug()<<k_funcinfo<<"Selected: "<<d<<" row,col=("<<row<<","<<col<<")"<<endl;
|
||
|
painter->setPen(backgroundSelectColor);
|
||
|
painter->setBrush(backgroundSelectColor);
|
||
|
painter->drawRect(2, 2, w-4, h-4);
|
||
|
}
|
||
|
// If weeks or weekdays are selected/marked we draw lines around the date
|
||
14 years ago
|
TQPen pen = painter->pen();
|
||
15 years ago
|
if (m_markedWeekdays.state(weekday(col)) == Map::Working) {
|
||
|
//kdDebug()<<k_funcinfo<<"Marked weekday: row,dayCol=("<<row<<","<<dayCol<<")=Working"<<endl;
|
||
|
pen.setColor(colorBackgroundWorkday);
|
||
|
painter->setPen(pen);
|
||
|
painter->moveTo(0, 0);
|
||
|
painter->lineTo(0, h-1);
|
||
|
painter->moveTo(w-1, 0);
|
||
|
painter->lineTo(w-1, h-1);
|
||
|
}
|
||
|
// then paint square if current date
|
||
13 years ago
|
if (d == TQDate::currentDate()) {
|
||
15 years ago
|
painter->setPen(colorLine);
|
||
|
painter->drawRect(1, 1, w-2, h-2);
|
||
|
}
|
||
|
|
||
|
// and now the day number
|
||
12 years ago
|
d.month() == date.month() ? painter->setPen(TDEGlobalSettings::textColor()) : painter->setPen(gray);
|
||
14 years ago
|
painter->drawText(0, 0, w, h, AlignCenter, TQString().setNum(d.day()), -1, &rect);
|
||
15 years ago
|
|
||
|
if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width());
|
||
|
if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height());
|
||
|
}
|
||
|
|
||
14 years ago
|
void DateTable::paintCell(TQPainter *painter, int row, int col) {
|
||
15 years ago
|
//kdDebug()<<k_funcinfo<<"row,col=("<<row<<","<<col<<")"<<"enabled="<<m_enabled<<endl;
|
||
|
if (row == 0 && col == 0) {
|
||
|
painter->save();
|
||
|
int w=cellWidth();
|
||
|
int h=cellHeight();
|
||
|
painter->setPen(colorLine);
|
||
12 years ago
|
painter->setBrush(TDEGlobalSettings::baseColor());
|
||
15 years ago
|
painter->moveTo(w-1, 0);
|
||
|
painter->lineTo(w-1, h-1);
|
||
|
painter->lineTo(0, h-1);
|
||
|
painter->restore();
|
||
|
return;
|
||
|
}
|
||
|
painter->save();
|
||
|
if(row==0) { // we are drawing the weekdays
|
||
|
paintWeekday(painter, col);
|
||
|
} else if (col == 0) { // draw week numbers
|
||
|
paintWeekNumber(painter, row);
|
||
|
} else { // draw the day
|
||
|
paintDay(painter, row, col);
|
||
|
}
|
||
|
painter->restore();
|
||
|
}
|
||
|
|
||
|
//FIXME
|
||
14 years ago
|
void DateTable::keyPressEvent( TQKeyEvent *e ) {
|
||
15 years ago
|
if (!m_enabled)
|
||
|
return;
|
||
14 years ago
|
if ( e->key() == TQt::Key_Prior ) {
|
||
15 years ago
|
setDate(date.addMonths(-1));
|
||
|
return;
|
||
|
}
|
||
14 years ago
|
if ( e->key() == TQt::Key_Next ) {
|
||
15 years ago
|
setDate(date.addMonths(1));
|
||
|
return;
|
||
|
}
|
||
|
|
||
14 years ago
|
if ( e->key() == TQt::Key_Up ) {
|
||
15 years ago
|
if ( date.day() > 7 ) {
|
||
|
setDate(date.addDays(-7));
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
14 years ago
|
if ( e->key() == TQt::Key_Down ) {
|
||
15 years ago
|
if ( date.day() <= date.daysInMonth()-7 ) {
|
||
|
setDate(date.addDays(7));
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
14 years ago
|
if ( e->key() == TQt::Key_Left ) {
|
||
15 years ago
|
if ( date.day() > 1 ) {
|
||
|
setDate(date.addDays(-1));
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
14 years ago
|
if ( e->key() == TQt::Key_Right ) {
|
||
15 years ago
|
if ( date.day() < date.daysInMonth() ) {
|
||
|
setDate(date.addDays(1));
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
if ( e->key() == TQt::Key_Minus ) {
|
||
15 years ago
|
setDate(date.addDays(-1));
|
||
|
return;
|
||
|
}
|
||
14 years ago
|
if ( e->key() == TQt::Key_Plus ) {
|
||
15 years ago
|
setDate(date.addDays(1));
|
||
|
return;
|
||
|
}
|
||
14 years ago
|
if ( e->key() == TQt::Key_N ) {
|
||
13 years ago
|
setDate(TQDate::currentDate());
|
||
15 years ago
|
return;
|
||
|
}
|
||
14 years ago
|
if ( e->key() == TQt::Key_Control ) {
|
||
15 years ago
|
return;
|
||
|
}
|
||
14 years ago
|
if ( e->key() == TQt::Key_Shift ) {
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
KNotifyClient::beep();
|
||
|
}
|
||
|
|
||
14 years ago
|
void DateTable::viewportResizeEvent(TQResizeEvent * e) {
|
||
|
TQGridView::viewportResizeEvent(e);
|
||
15 years ago
|
|
||
|
setCellWidth(viewport()->width()/numCols());
|
||
|
setCellHeight(viewport()->height()/numRows());
|
||
|
}
|
||
|
|
||
|
void DateTable::setFontSize(int size) {
|
||
|
int count;
|
||
14 years ago
|
TQFontMetrics metrics(fontMetrics());
|
||
|
TQRect rect;
|
||
15 years ago
|
// ----- store rectangles:
|
||
|
fontsize=size;
|
||
|
// ----- find largest day name:
|
||
|
maxCell.setWidth(0);
|
||
|
maxCell.setHeight(0);
|
||
|
for(count=0; count<7; ++count)
|
||
|
{
|
||
12 years ago
|
rect=metrics.boundingRect(TDEGlobal::locale()->calendar()->weekDayName(count+1, true));
|
||
14 years ago
|
maxCell.setWidth(TQMAX(maxCell.width(), rect.width()));
|
||
|
maxCell.setHeight(TQMAX(maxCell.height(), rect.height()));
|
||
15 years ago
|
}
|
||
|
// ----- compare with a real wide number and add some space:
|
||
13 years ago
|
rect=metrics.boundingRect(TQString::fromLatin1("88"));
|
||
14 years ago
|
maxCell.setWidth(TQMAX(maxCell.width()+2, rect.width()));
|
||
|
maxCell.setHeight(TQMAX(maxCell.height()+4, rect.height()));
|
||
15 years ago
|
}
|
||
|
|
||
|
//FIXME
|
||
14 years ago
|
void DateTable::wheelEvent ( TQWheelEvent * e ) {
|
||
15 years ago
|
setDate(date.addMonths( -(int)(e->delta()/120)) );
|
||
|
e->accept();
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void DateTable::contentsMousePressEvent(TQMouseEvent *e) {
|
||
15 years ago
|
if (!m_enabled)
|
||
|
return;
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
14 years ago
|
if(e->type()!=TQEvent::MouseButtonPress) {
|
||
15 years ago
|
return;
|
||
|
}
|
||
14 years ago
|
TQPoint mouseCoord = e->pos();
|
||
15 years ago
|
int row=rowAt(mouseCoord.y());
|
||
|
int col=columnAt(mouseCoord.x());
|
||
|
if (row == 0 && col == 0) { // user clicked on (unused) upper left square
|
||
|
updateSelectedCells();
|
||
|
m_selectedWeekdays.clear();
|
||
|
m_selectedDates.clear();
|
||
14 years ago
|
repaintContents(false);
|
||
15 years ago
|
emit selectionCleared();
|
||
|
return;
|
||
|
}
|
||
|
if (col == 0) { // user clicked on week numbers
|
||
|
updateSelectedCells();
|
||
|
m_selectedWeekdays.clear();
|
||
|
m_selectedDates.clear();
|
||
|
updateSelectedCells();
|
||
14 years ago
|
repaintContents(false);
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
if (row==0 && col>0) { // the user clicked on weekdays
|
||
|
updateSelectedCells();
|
||
|
m_selectedDates.clear();
|
||
|
int day = weekday(col);
|
||
|
if (e->state() & ShiftButton) {
|
||
|
// select all days between this and the furthest away selected day,
|
||
|
// check first downside - then upside, clear all others
|
||
|
bool select = false;
|
||
|
for(int i=m_dateStartCol; i < col; ++i) {
|
||
|
//kdDebug()<<"Down["<<i<<"]: col="<<col<<" day="<<day<<" column(i)="<<column(i)<<endl;
|
||
14 years ago
|
if (m_selectedWeekdays.contains(weekday(i))) {
|
||
15 years ago
|
select = true; // we have hit a selected day; select the rest
|
||
|
} else if (select) {
|
||
|
m_selectedWeekdays.toggle(weekday(i)); // select
|
||
|
}
|
||
|
}
|
||
|
bool selected = select;
|
||
|
select = false;
|
||
|
for(int i=7; i > col; --i) {
|
||
|
//kdDebug()<<"Up["<<i<<"]: col="<<col<<" day="<<day<<" column(i)="<<column(i)<<endl;
|
||
14 years ago
|
if (m_selectedWeekdays.contains(weekday(i))) {
|
||
15 years ago
|
if (selected) m_selectedWeekdays.toggle(weekday(i)); // deselect
|
||
|
else select = true;
|
||
|
} else if (select) {
|
||
|
m_selectedWeekdays.toggle(weekday(i)); // select
|
||
|
}
|
||
|
}
|
||
14 years ago
|
if (!m_selectedWeekdays.contains(day)) {
|
||
15 years ago
|
m_selectedWeekdays.toggle(day); // always select
|
||
|
}
|
||
|
} else if (e->state() & ControlButton) {
|
||
|
// toggle select this date
|
||
|
m_selectedWeekdays.toggle(day);
|
||
|
} else {
|
||
|
// toggle select this, clear all others
|
||
|
m_selectedWeekdays.toggleClear(day);
|
||
|
}
|
||
|
updateSelectedCells();
|
||
14 years ago
|
repaintContents(false);
|
||
15 years ago
|
if (m_enabled) {
|
||
|
//kdDebug()<<k_funcinfo<<"emit weekdaySelected("<<day<<")"<<endl;
|
||
|
emit weekdaySelected(day); // day= 1..7
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (contentsMousePressEvent_internal(e)) {
|
||
|
// Date hit,
|
||
|
m_selectedWeekdays.clear();
|
||
|
if (e->state() & ShiftButton) {
|
||
|
// find first&last date
|
||
14 years ago
|
TQDate first;
|
||
|
TQDate last;
|
||
15 years ago
|
DateMap::ConstIterator it;
|
||
|
for (it = m_selectedDates.constBegin(); it != m_selectedDates.constEnd(); ++it) {
|
||
|
//kdDebug()<<k_funcinfo<<it.key()<<endl;
|
||
14 years ago
|
TQDate d = TQDate::fromString(it.key(), Qt::ISODate);
|
||
15 years ago
|
if (!d.isValid())
|
||
|
continue;
|
||
|
if (!first.isValid() || first > d)
|
||
|
first = d;
|
||
|
if (!last.isValid() || last < d)
|
||
|
last = d;
|
||
|
}
|
||
|
// select between anchor and pressed date inclusive
|
||
|
m_selectedDates.clear();
|
||
|
if (first.isValid() && last.isValid()) {
|
||
14 years ago
|
TQDate anchor = first < date ? first : last;
|
||
15 years ago
|
int i = anchor > date ? -1 : 1;
|
||
|
while (anchor != date) {
|
||
|
//kdDebug()<<k_funcinfo<<anchor.toString(Qt::ISODate)<<endl;
|
||
|
m_selectedDates.toggle(anchor);
|
||
|
anchor = anchor.addDays(i);
|
||
|
}
|
||
|
}
|
||
|
m_selectedDates.toggle(date);
|
||
|
} else if (e->state() & ControlButton) {
|
||
|
// toggle select this date
|
||
|
m_selectedDates.toggle(date);
|
||
|
//kdDebug()<<k_funcinfo<<"toggle date: "<<date.toString()<<" state="<<m_selectedDates.state(date)<<endl;
|
||
|
} else {
|
||
|
// Select this, clear all others
|
||
|
m_selectedDates.clear();
|
||
|
m_selectedDates.toggleClear(date);
|
||
|
//kdDebug()<<k_funcinfo<<"toggleClear date: "<<date.toString()<<" state="<<m_selectedDates.state(date)<<endl;
|
||
|
}
|
||
|
}
|
||
14 years ago
|
repaintContents(false);
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
bool DateTable::contentsMousePressEvent_internal(TQMouseEvent *e) {
|
||
|
TQPoint mouseCoord = e->pos();
|
||
15 years ago
|
int row=rowAt(mouseCoord.y());
|
||
|
int col=columnAt(mouseCoord.x());
|
||
|
if(row<1 || col<0) { // the user clicked on the frame of the table
|
||
|
return false;
|
||
|
}
|
||
|
//kdDebug()<<k_funcinfo<<"pos["<<row<<","<<col<<"]="<<position(row,col)<<" firstday="<<firstday<<endl;
|
||
|
selectDate(getDate(position(row, col)));
|
||
|
return true;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool DateTable::selectDate(const TQDate& date_) {
|
||
15 years ago
|
//kdDebug()<<k_funcinfo<<"date="<<date_.toString()<<endl;
|
||
|
bool changed=false;
|
||
14 years ago
|
TQDate temp;
|
||
15 years ago
|
// -----
|
||
|
if(!date_.isValid()) {
|
||
|
return false;
|
||
|
}
|
||
|
if(date!=date_) {
|
||
|
date=date_;
|
||
|
changed=true;
|
||
|
}
|
||
|
|
||
|
temp.setYMD(date.year(), date.month(), 1);
|
||
12 years ago
|
firstday=column(TDEGlobal::locale()->calendar()->dayOfWeek(temp));
|
||
15 years ago
|
if(firstday==1) firstday=8; // Reserve row 1 for previous month
|
||
|
numdays=date.daysInMonth();
|
||
|
if(date.month()==1) { // set to december of previous year
|
||
|
temp.setYMD(date.year()-1, 12, 1);
|
||
14 years ago
|
setWeekNumbers(TQDate(date.year()-1, 12, 31));
|
||
15 years ago
|
} else { // set to previous month
|
||
|
temp.setYMD(date.year(), date.month()-1, 1);
|
||
14 years ago
|
TQDate d(date.year(), date.month()-1,1);
|
||
15 years ago
|
setWeekNumbers(d.addDays(d.daysInMonth()-1));
|
||
|
}
|
||
|
numDaysPrevMonth=temp.daysInMonth();
|
||
|
if(changed) {
|
||
14 years ago
|
repaintContents(false);
|
||
15 years ago
|
}
|
||
|
if (m_enabled)
|
||
|
emit(dateChanged(date));
|
||
|
return true;
|
||
|
}
|
||
|
|
||
13 years ago
|
bool DateTable::setDate(const TQDate& date_, bool repaint) {
|
||
15 years ago
|
//kdDebug()<<k_funcinfo<<"date="<<date_.toString()<<endl;
|
||
|
bool changed=false;
|
||
14 years ago
|
TQDate temp;
|
||
15 years ago
|
// -----
|
||
|
if(!date_.isValid()) {
|
||
|
//kdDebug() << "DateTable::setDate: refusing to set invalid date." << endl;
|
||
|
return false;
|
||
|
}
|
||
|
if(date!=date_) {
|
||
|
date=date_;
|
||
|
changed=true;
|
||
|
}
|
||
|
//m_selectedDates.clear();
|
||
|
|
||
|
temp.setYMD(date.year(), date.month(), 1);
|
||
12 years ago
|
firstday=column(TDEGlobal::locale()->calendar()->dayOfWeek(temp));
|
||
15 years ago
|
if(firstday==1) firstday=8;
|
||
12 years ago
|
//kdDebug()<<k_funcinfo<<"date="<<temp<<"day="<<(TDEGlobal::locale()->calendar()->dayOfWeek(temp))<<" firstday="<<firstday<<endl;
|
||
15 years ago
|
numdays=date.daysInMonth();
|
||
|
if(date.month()==1) { // set to december of previous year
|
||
|
temp.setYMD(date.year()-1, 12, 1);
|
||
14 years ago
|
setWeekNumbers(TQDate(date.year()-1, 12, 31));
|
||
15 years ago
|
} else { // set to previous month
|
||
|
temp.setYMD(date.year(), date.month()-1, 1);
|
||
14 years ago
|
TQDate d(date.year(), date.month()-1,1);
|
||
15 years ago
|
setWeekNumbers(d.addDays(d.daysInMonth()-1));
|
||
|
}
|
||
|
/* if (m_selectedWeekdays.isEmpty() &&
|
||
14 years ago
|
!m_selectedDates.isEmpty() && !m_selectedDates.contains(date))
|
||
15 years ago
|
{
|
||
|
//kdDebug()<<k_funcinfo<<"date inserted"<<endl;
|
||
|
m_selectedDates.insert(date);
|
||
|
}*/
|
||
|
numDaysPrevMonth=temp.daysInMonth();
|
||
13 years ago
|
if(changed && repaint) {
|
||
14 years ago
|
repaintContents(false);
|
||
15 years ago
|
}
|
||
|
if (m_enabled)
|
||
|
emit(dateChanged(date));
|
||
|
return true;
|
||
|
}
|
||
|
|
||
14 years ago
|
const TQDate& DateTable::getDate() const {
|
||
15 years ago
|
return date;
|
||
|
}
|
||
|
|
||
14 years ago
|
void DateTable::focusInEvent( TQFocusEvent *e ) {
|
||
|
TQGridView::focusInEvent( e );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void DateTable::focusOutEvent( TQFocusEvent *e ) {
|
||
|
TQGridView::focusOutEvent( e );
|
||
15 years ago
|
}
|
||
|
|
||
13 years ago
|
TQSize DateTable::sizeHint() const {
|
||
15 years ago
|
if(maxCell.height()>0 && maxCell.width()>0) {
|
||
14 years ago
|
return TQSize(maxCell.width()*numCols()+2*frameWidth(),
|
||
15 years ago
|
(maxCell.height()+2)*numRows()+2*frameWidth());
|
||
|
} else {
|
||
13 years ago
|
//kdDebug() << "DateTable::sizeHint: obscure failure - " << endl;
|
||
14 years ago
|
return TQSize(-1, -1);
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void DateTable::setWeekNumbers(TQDate date) {
|
||
15 years ago
|
if (!date.isValid()) {
|
||
|
kdError()<<k_funcinfo<<"Invalid date"<<endl;
|
||
|
}
|
||
14 years ago
|
TQDate d(date);
|
||
15 years ago
|
for (int i = 1; i < 7; ++i) {
|
||
|
m_weeks[i].first = d.weekNumber(&(m_weeks[i].second));
|
||
|
//kdDebug()<<k_funcinfo<<"date="<<d.toString()<<" week=("<<m_weeks[i].first<<","<<m_weeks[i].second<<")"<<endl;
|
||
|
d = d.addDays(7);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void DateTable::updateCells() {
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
|
for (int row=0; row < numRows(); ++row) {
|
||
|
for (int col=0; col < numCols(); ++col) {
|
||
|
updateCell(row, col);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void DateTable::updateSelectedCells() {
|
||
|
//kdDebug()<<k_funcinfo<<endl;
|
||
14 years ago
|
TQDate dt(date.year(), date.month(), 1);
|
||
15 years ago
|
dt = dt.addDays(-firstday);
|
||
|
for (int pos=0; pos < 42; ++pos) {
|
||
14 years ago
|
if (m_selectedDates.contains(dt.addDays(pos)) ||
|
||
|
m_selectedWeekdays.contains(pos%7+1))
|
||
15 years ago
|
{
|
||
|
updateCell(pos/7+1, pos%7+1);
|
||
|
//kdDebug()<<k_funcinfo<<" update cell ("<<pos/7+1<<","<<pos%7+1<<") date="<<dt.addDays(pos).toString()<<endl;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void DateTable::updateMarkedCells() {
|
||
14 years ago
|
TQDate dt(date.year(), date.month(), 1);
|
||
15 years ago
|
dt = dt.addDays(-firstday);
|
||
|
for (int pos=0; pos < 42; ++pos) {
|
||
14 years ago
|
if (m_markedDates.contains(dt.addDays(pos)) ||
|
||
|
m_markedWeekdays.contains(pos%7+1))
|
||
15 years ago
|
{
|
||
|
updateCell(pos/7+1, pos%7+1);
|
||
|
//kdDebug()<<k_funcinfo<<" update cell ("<<pos/7+1<<","<<pos%7+1<<") date="<<dt.addDays(pos).toString()<<endl;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void DateTable::setMarkedWeekdays(const IntMap days) {
|
||
|
updateMarkedCells();
|
||
|
m_markedWeekdays.clear();
|
||
|
m_markedWeekdays = days;
|
||
|
updateMarkedCells();
|
||
14 years ago
|
repaintContents(false);
|
||
15 years ago
|
}
|
||
|
|
||
|
bool DateTable::weekdayMarked(int day) {
|
||
14 years ago
|
return m_markedWeekdays.contains(day);
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
bool DateTable::dateMarked(TQDate date) {
|
||
15 years ago
|
return m_markedDates[date.toString()];
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDate DateTable::getDate(int pos) const {
|
||
|
return TQDate(date.year(), date.month(), 1).addDays(pos-firstday);
|
||
15 years ago
|
}
|
||
|
|
||
|
int DateTable::weekday(int col) const {
|
||
12 years ago
|
int day = col - m_dateStartCol + TDEGlobal::locale()->weekStartDay();
|
||
15 years ago
|
if (day > 7) day %= 7;
|
||
12 years ago
|
//kdDebug()<<k_funcinfo<<"col="<<col<<" day="<<day<<" StartCol="<<m_dateStartCol<<" weekStartDay="<<TDEGlobal::locale()->weekStartDay()<<endl;
|
||
15 years ago
|
return day;
|
||
|
}
|
||
|
|
||
|
int DateTable::column(int weekday) const {
|
||
12 years ago
|
int col = weekday - TDEGlobal::locale()->weekStartDay();
|
||
15 years ago
|
if (col < 0) col += 7;
|
||
12 years ago
|
//kdDebug()<<k_funcinfo<<"col="<<col<<" day="<<col<<" StartCol="<<m_dateStartCol<<" weekStartDay="<<TDEGlobal::locale()->weekStartDay()<<endl;
|
||
15 years ago
|
return col + m_dateStartCol;
|
||
|
}
|
||
|
|
||
|
void DateTable::clear() {
|
||
|
clearSelection();
|
||
|
m_markedDates.clear();
|
||
|
m_markedWeekdays.clear();
|
||
14 years ago
|
repaintContents(false);
|
||
15 years ago
|
}
|
||
|
|
||
|
void DateTable::clearSelection() {
|
||
|
m_selectedDates.clear();
|
||
|
m_selectedWeekdays.clear();
|
||
14 years ago
|
repaintContents(false);
|
||
15 years ago
|
}
|
||
|
|
||
|
void DateTable::setEnabled(bool yes) {
|
||
|
if (m_enabled == yes)
|
||
|
return;
|
||
|
m_enabled=yes;
|
||
|
updateCells();
|
||
|
}
|
||
|
|
||
|
void DateTable::markSelected(int state) {
|
||
|
if (!m_selectedDates.isEmpty()) {
|
||
|
DateMap::iterator it;
|
||
|
for(it = m_selectedDates.begin(); it != m_selectedDates.end(); ++it) {
|
||
|
m_markedDates.insert(it.key(), state);
|
||
|
//kdDebug()<<k_funcinfo<<"marked date: "<<it.key()<<"="<<state<<endl;
|
||
|
}
|
||
|
} else if (!m_selectedWeekdays.isEmpty()) {
|
||
|
IntMap::iterator it;
|
||
|
for(it = m_selectedWeekdays.begin(); it != m_selectedWeekdays.end(); ++it) {
|
||
|
m_markedWeekdays.insert(it.key(), state);
|
||
|
//kdDebug()<<k_funcinfo<<"marked weekday: "<<it.key()<<"="<<state<<endl;
|
||
|
}
|
||
|
}
|
||
|
updateSelectedCells();
|
||
14 years ago
|
repaintContents(false);
|
||
15 years ago
|
}
|
||
|
|
||
|
DateInternalWeekSelector::DateInternalWeekSelector
|
||
14 years ago
|
(int fontsize, TQWidget* parent, const char* name)
|
||
|
: TQLineEdit(parent, name),
|
||
14 years ago
|
val(new TQIntValidator(TQT_TQOBJECT(this))),
|
||
15 years ago
|
result(0)
|
||
|
{
|
||
14 years ago
|
TQFont font;
|
||
15 years ago
|
// -----
|
||
12 years ago
|
font=TDEGlobalSettings::generalFont();
|
||
15 years ago
|
font.setPointSize(fontsize);
|
||
|
setFont(font);
|
||
14 years ago
|
setFrameStyle(TQFrame::NoFrame);
|
||
15 years ago
|
val->setRange(1, 53);
|
||
|
setValidator(val);
|
||
14 years ago
|
connect(this, TQT_SIGNAL(returnPressed()), TQT_SLOT(weekEnteredSlot()));
|
||
15 years ago
|
}
|
||
|
|
||
|
void
|
||
|
DateInternalWeekSelector::weekEnteredSlot()
|
||
|
{
|
||
|
bool ok;
|
||
|
int week;
|
||
|
// ----- check if this is a valid week:
|
||
|
week=text().toInt(&ok);
|
||
|
if(!ok)
|
||
|
{
|
||
|
KNotifyClient::beep();
|
||
|
return;
|
||
|
}
|
||
|
result=week;
|
||
|
emit(closeMe(1));
|
||
|
}
|
||
|
|
||
|
int
|
||
|
DateInternalWeekSelector::getWeek() const
|
||
|
{
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
DateInternalWeekSelector::setWeek(int week)
|
||
|
{
|
||
14 years ago
|
TQString temp;
|
||
15 years ago
|
// -----
|
||
|
temp.setNum(week);
|
||
|
setText(temp);
|
||
|
}
|
||
|
|
||
|
DateInternalMonthPicker::DateInternalMonthPicker
|
||
14 years ago
|
(int fontsize, TQWidget* parent, const char* name)
|
||
|
: TQGridView(parent, name),
|
||
15 years ago
|
result(0) // invalid
|
||
|
{
|
||
14 years ago
|
TQRect rect;
|
||
|
TQFont font;
|
||
15 years ago
|
// -----
|
||
|
activeCol = -1;
|
||
|
activeRow = -1;
|
||
12 years ago
|
font=TDEGlobalSettings::generalFont();
|
||
15 years ago
|
font.setPointSize(fontsize);
|
||
|
setFont(font);
|
||
|
setHScrollBarMode(AlwaysOff);
|
||
|
setVScrollBarMode(AlwaysOff);
|
||
14 years ago
|
setFrameStyle(TQFrame::NoFrame);
|
||
15 years ago
|
setNumRows(4);
|
||
|
setNumCols(3);
|
||
|
// enable to find drawing failures:
|
||
|
// setTableFlags(Tbl_clipCellPainting);
|
||
12 years ago
|
viewport()->setEraseColor(TDEGlobalSettings::baseColor()); // for consistency with the datepicker
|
||
15 years ago
|
// ----- find the preferred size
|
||
|
// (this is slow, possibly, but unfortunatly it is needed here):
|
||
14 years ago
|
TQFontMetrics metrics(font);
|
||
15 years ago
|
for(int i=1; i <= 12; ++i)
|
||
|
{
|
||
12 years ago
|
rect=metrics.boundingRect(TDEGlobal::locale()->calendar()->monthName(i, false));
|
||
15 years ago
|
if(max.width()<rect.width()) max.setWidth(rect.width());
|
||
|
if(max.height()<rect.height()) max.setHeight(rect.height());
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
14 years ago
|
TQSize
|
||
13 years ago
|
DateInternalMonthPicker::sizeHint() const
|
||
15 years ago
|
{
|
||
14 years ago
|
return TQSize((max.width()+6)*numCols()+2*frameWidth(),
|
||
15 years ago
|
(max.height()+6)*numRows()+2*frameWidth());
|
||
|
}
|
||
|
|
||
|
int
|
||
|
DateInternalMonthPicker::getResult() const
|
||
|
{
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
DateInternalMonthPicker::setupPainter(TQPainter *p)
|
||
15 years ago
|
{
|
||
12 years ago
|
p->setPen(TDEGlobalSettings::textColor());
|
||
15 years ago
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
DateInternalMonthPicker::viewportResizeEvent(TQResizeEvent*)
|
||
15 years ago
|
{
|
||
|
setCellWidth(width()/3);
|
||
|
setCellHeight(height()/4);
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
DateInternalMonthPicker::paintCell(TQPainter* painter, int row, int col)
|
||
15 years ago
|
{
|
||
|
int index;
|
||
14 years ago
|
TQString text;
|
||
15 years ago
|
// ----- find the number of the cell:
|
||
|
index=3*row+col+1;
|
||
12 years ago
|
text=TDEGlobal::locale()->calendar()->monthName(index, false);
|
||
15 years ago
|
painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
|
||
|
if ( activeCol == col && activeRow == row )
|
||
|
painter->drawRect( 0, 0, cellWidth(), cellHeight() );
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
DateInternalMonthPicker::contentsMousePressEvent(TQMouseEvent *e)
|
||
15 years ago
|
{
|
||
14 years ago
|
if(!isEnabled() || e->button() != Qt::LeftButton)
|
||
15 years ago
|
{
|
||
|
KNotifyClient::beep();
|
||
|
return;
|
||
|
}
|
||
|
// -----
|
||
|
int row, col;
|
||
14 years ago
|
TQPoint mouseCoord;
|
||
15 years ago
|
// -----
|
||
|
mouseCoord = e->pos();
|
||
|
row=rowAt(mouseCoord.y());
|
||
|
col=columnAt(mouseCoord.x());
|
||
|
|
||
|
if(row<0 || col<0)
|
||
|
{ // the user clicked on the frame of the table
|
||
|
activeCol = -1;
|
||
|
activeRow = -1;
|
||
|
} else {
|
||
|
activeCol = col;
|
||
|
activeRow = row;
|
||
|
updateCell( row, col /*, false */ );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
DateInternalMonthPicker::contentsMouseMoveEvent(TQMouseEvent *e)
|
||
15 years ago
|
{
|
||
14 years ago
|
if (e->state() & Qt::LeftButton)
|
||
15 years ago
|
{
|
||
|
int row, col;
|
||
14 years ago
|
TQPoint mouseCoord;
|
||
15 years ago
|
// -----
|
||
|
mouseCoord = e->pos();
|
||
|
row=rowAt(mouseCoord.y());
|
||
|
col=columnAt(mouseCoord.x());
|
||
|
int tmpRow = -1, tmpCol = -1;
|
||
|
if(row<0 || col<0)
|
||
|
{ // the user clicked on the frame of the table
|
||
|
if ( activeCol > -1 )
|
||
|
{
|
||
|
tmpRow = activeRow;
|
||
|
tmpCol = activeCol;
|
||
|
}
|
||
|
activeCol = -1;
|
||
|
activeRow = -1;
|
||
|
} else {
|
||
|
bool differentCell = (activeRow != row || activeCol != col);
|
||
|
if ( activeCol > -1 && differentCell)
|
||
|
{
|
||
|
tmpRow = activeRow;
|
||
|
tmpCol = activeCol;
|
||
|
}
|
||
|
if ( differentCell)
|
||
|
{
|
||
|
activeRow = row;
|
||
|
activeCol = col;
|
||
|
updateCell( row, col /*, false */ ); // mark the new active cell
|
||
|
}
|
||
|
}
|
||
13 years ago
|
if ( tmpRow > -1 ) // repaint the former active cell
|
||
15 years ago
|
updateCell( tmpRow, tmpCol /*, true */ );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
DateInternalMonthPicker::contentsMouseReleaseEvent(TQMouseEvent *e)
|
||
15 years ago
|
{
|
||
|
if(!isEnabled())
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
// -----
|
||
|
int row, col, pos;
|
||
14 years ago
|
TQPoint mouseCoord;
|
||
15 years ago
|
// -----
|
||
|
mouseCoord = e->pos();
|
||
|
row=rowAt(mouseCoord.y());
|
||
|
col=columnAt(mouseCoord.x());
|
||
|
if(row<0 || col<0)
|
||
|
{ // the user clicked on the frame of the table
|
||
|
emit(closeMe(0));
|
||
|
}
|
||
|
pos=3*row+col+1;
|
||
|
result=pos;
|
||
|
emit(closeMe(1));
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
DateInternalYearSelector::DateInternalYearSelector
|
||
14 years ago
|
(int fontsize, TQWidget* parent, const char* name)
|
||
|
: TQLineEdit(parent, name),
|
||
14 years ago
|
val(new TQIntValidator(TQT_TQOBJECT(this))),
|
||
15 years ago
|
result(0)
|
||
|
{
|
||
14 years ago
|
TQFont font;
|
||
15 years ago
|
// -----
|
||
12 years ago
|
font=TDEGlobalSettings::generalFont();
|
||
15 years ago
|
font.setPointSize(fontsize);
|
||
|
setFont(font);
|
||
14 years ago
|
setFrameStyle(TQFrame::NoFrame);
|
||
|
// we have to respect the limits of TQDate here, I fear:
|
||
15 years ago
|
val->setRange(0, 8000);
|
||
|
setValidator(val);
|
||
14 years ago
|
connect(this, TQT_SIGNAL(returnPressed()), TQT_SLOT(yearEnteredSlot()));
|
||
15 years ago
|
}
|
||
|
|
||
|
void
|
||
|
DateInternalYearSelector::yearEnteredSlot()
|
||
|
{
|
||
|
bool ok;
|
||
|
int year;
|
||
14 years ago
|
TQDate date;
|
||
15 years ago
|
// ----- check if this is a valid year:
|
||
|
year=text().toInt(&ok);
|
||
|
if(!ok)
|
||
|
{
|
||
|
KNotifyClient::beep();
|
||
|
return;
|
||
|
}
|
||
|
date.setYMD(year, 1, 1);
|
||
|
if(!date.isValid())
|
||
|
{
|
||
|
KNotifyClient::beep();
|
||
|
return;
|
||
|
}
|
||
|
result=year;
|
||
|
emit(closeMe(1));
|
||
|
}
|
||
|
|
||
|
int
|
||
|
DateInternalYearSelector::getYear() const
|
||
|
{
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
DateInternalYearSelector::setYear(int year)
|
||
|
{
|
||
14 years ago
|
TQString temp;
|
||
15 years ago
|
// -----
|
||
|
temp.setNum(year);
|
||
|
setText(temp);
|
||
|
}
|
||
|
|
||
14 years ago
|
PopupFrame::PopupFrame(TQWidget* parent, const char* name)
|
||
|
: TQFrame(parent, name, WType_Popup),
|
||
15 years ago
|
result(0), // rejected
|
||
|
main(0)
|
||
|
{
|
||
14 years ago
|
setFrameStyle(TQFrame::Box|TQFrame::Raised);
|
||
15 years ago
|
setMidLineWidth(2);
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
PopupFrame::keyPressEvent(TQKeyEvent* e)
|
||
15 years ago
|
{
|
||
|
if(e->key()==Key_Escape)
|
||
|
{
|
||
|
result=0; // rejected
|
||
14 years ago
|
tqApp->exit_loop();
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
|
PopupFrame::close(int r)
|
||
|
{
|
||
|
result=r;
|
||
14 years ago
|
tqApp->exit_loop();
|
||
15 years ago
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
PopupFrame::setMainWidget(TQWidget* m)
|
||
15 years ago
|
{
|
||
|
main=m;
|
||
|
if(main!=0)
|
||
|
{
|
||
|
resize(main->width()+2*frameWidth(), main->height()+2*frameWidth());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
PopupFrame::resizeEvent(TQResizeEvent*)
|
||
15 years ago
|
{
|
||
|
if(main!=0)
|
||
|
{
|
||
|
main->setGeometry(frameWidth(), frameWidth(),
|
||
|
width()-2*frameWidth(), height()-2*frameWidth());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
PopupFrame::popup(const TQPoint &pos)
|
||
15 years ago
|
{
|
||
|
// Make sure the whole popup is visible.
|
||
14 years ago
|
TQRect d = TQApplication::desktop()->screenGeometry(TQApplication::desktop()->screenNumber(pos));
|
||
15 years ago
|
int x = pos.x();
|
||
|
int y = pos.y();
|
||
|
int w = width();
|
||
|
int h = height();
|
||
|
if (x+w > d.x()+d.width())
|
||
|
x = d.width() - w;
|
||
|
if (y+h > d.y()+d.height())
|
||
|
y = d.height() - h;
|
||
|
if (x < d.x())
|
||
|
x = 0;
|
||
|
if (y < d.y())
|
||
|
y = 0;
|
||
|
|
||
|
// Pop the thingy up.
|
||
|
move(x, y);
|
||
|
show();
|
||
|
}
|
||
|
|
||
|
int
|
||
14 years ago
|
PopupFrame::exec(TQPoint pos)
|
||
15 years ago
|
{
|
||
|
popup(pos);
|
||
13 years ago
|
repaint();
|
||
14 years ago
|
tqApp->enter_loop();
|
||
15 years ago
|
hide();
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
int
|
||
|
PopupFrame::exec(int x, int y)
|
||
|
{
|
||
14 years ago
|
return exec(TQPoint(x, y));
|
||
15 years ago
|
}
|
||
|
|
||
|
void PopupFrame::virtual_hook( int, void* )
|
||
|
{ /*BASE::virtual_hook( id, data );*/ }
|
||
|
|
||
|
void DateTable::virtual_hook( int, void* )
|
||
|
{ /*BASE::virtual_hook( id, data );*/ }
|
||
|
|
||
|
} //KPlato namespace
|
||
|
|
||
|
#include "kptdatetable.moc"
|