-rw-r--r-- | microkde/KDGanttMinimizeSplitter.cpp | 8 | ||||
-rw-r--r-- | microkde/kcalendarsystemgregorian.cpp | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/microkde/KDGanttMinimizeSplitter.cpp b/microkde/KDGanttMinimizeSplitter.cpp index 60b8bc7..567ae54 100644 --- a/microkde/KDGanttMinimizeSplitter.cpp +++ b/microkde/KDGanttMinimizeSplitter.cpp @@ -1,136 +1,136 @@ /* -*- Mode: C++ -*- $Id$ */ /**************************************************************************** ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved. ** ** This file is part of the KDGantt library. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** Licensees holding valid commercial KDGantt licenses may use this file in ** accordance with the KDGantt Commercial License Agreement provided with ** the Software. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for ** information about KDGantt Commercial License Agreements. ** ** Contact info@klaralvdalens-datakonsult.se if any conditions of this ** licensing are not clear to you. ** ** As a special exception, permission is given to link this program ** with any edition of Qt, and distribute the resulting executable, ** without including the source code for Qt in the source distribution. ** **********************************************************************/ #include "KDGanttMinimizeSplitter.h" #ifndef QT_NO_SPLITTER___ #include "qpainter.h" #include "qdrawutil.h" #include "qbitmap.h" -#if QT_VERSION >= 300 +#if QT_VERSION >= 0x030000 #include "qptrlist.h" #include "qmemarray.h" #else #include <qlist.h> #include <qarray.h> #define QPtrList QList #define QMemArray QArray #endif #include "qlayoutengine_p.h" #include "qobjectlist.h" #include "qstyle.h" #include "qapplication.h" //sendPostedEvents #include <qvaluelist.h> #include <qcursor.h> #ifndef KDGANTT_MASTER_CVS //#include "KDGanttMinimizeSplitter.moc" #endif #ifndef DOXYGEN_SKIP_INTERNAL #if QT_VERSION >= 232 static int mouseOffset; static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky KDGanttSplitterHandle::KDGanttSplitterHandle( Qt::Orientation o, KDGanttMinimizeSplitter *parent, const char * name ) : QWidget( parent, name ), _activeButton( 0 ), _collapsed( false ) { if ( QApplication::desktop()->width() > 320 && QApplication::desktop()->width() < 650 ) { mSizeHint = QSize(7,7); mUseOffset = true; } else { mSizeHint = QSize(6,6); mUseOffset = false; } s = parent; setOrientation(o); setMouseTracking( true ); //setMaximumHeight( 5 ); // test only } QSize KDGanttSplitterHandle::sizeHint() const { return mSizeHint; } void KDGanttSplitterHandle::setOrientation( Qt::Orientation o ) { orient = o; #ifndef QT_NO_CURSOR if ( o == KDGanttMinimizeSplitter::Horizontal ) setCursor( splitHCursor ); else setCursor( splitVCursor ); #endif } void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) { updateCursor( e->pos() ); if ( !(e->state()&LeftButton) ) return; if ( _activeButton != 0) return; QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) - mouseOffset; if ( true /*opaque()*/ ) { s->moveSplitter( pos, id() ); } else { int min = pos; int max = pos; s->getRange( id(), &min, &max ); s->setRubberband( QMAX( min, QMIN(max, pos ))); } _collapsed = false; } void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) { if ( e->button() == LeftButton ) { _activeButton = onButton( e->pos() ); mouseOffset = s->pick(e->pos()); if ( _activeButton != 0) repaint(); updateCursor( e->pos() ); } } void KDGanttSplitterHandle::updateCursor( const QPoint& p) { @@ -534,193 +534,193 @@ QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool firs QSplitterLayoutStruct *s; KDGanttSplitterHandle *newHandle = 0; if ( data->list.count() > 0 ) { s = new QSplitterLayoutStruct; s->mode = KeepSize; QString tmp = "qt_splithandle_"; tmp += w->name(); newHandle = new KDGanttSplitterHandle( orientation(), this, tmp.latin1() ); if ( ! mFirstHandle ) mFirstHandle = newHandle; s->wid = newHandle; newHandle->setId(data->list.count()); s->isSplitter = TRUE; s->sizer = pick( newHandle->sizeHint() ); if ( first ) data->list.insert( 0, s ); else data->list.append( s ); } s = new QSplitterLayoutStruct; s->mode = Stretch; s->wid = w; if ( !testWState( WState_Resized ) && w->sizeHint().isValid() ) s->sizer = pick( w->sizeHint() ); else s->sizer = pick( w->size() ); s->isSplitter = FALSE; if ( first ) data->list.insert( 0, s ); else data->list.append( s ); if ( newHandle && isVisible() ) newHandle->show(); //will trigger sending of post events return s; } /*! Tells the splitter that a child widget has been inserted or removed. The event is passed in \a c. */ void KDGanttMinimizeSplitter::childEvent( QChildEvent *c ) { if ( c->type() == QEvent::ChildInserted ) { if ( !c->child()->isWidgetType() ) return; if ( ((QWidget*)c->child())->testWFlags( WType_TopLevel ) ) return; QSplitterLayoutStruct *s = data->list.first(); while ( s ) { if ( s->wid == c->child() ) return; s = data->list.next(); } addWidget( (QWidget*)c->child() ); recalc( isVisible() ); } else if ( c->type() == QEvent::ChildRemoved ) { QSplitterLayoutStruct *p = 0; if ( data->list.count() > 1 ) p = data->list.at(1); //remove handle _after_ first widget. QSplitterLayoutStruct *s = data->list.first(); while ( s ) { if ( s->wid == c->child() ) { data->list.removeRef( s ); delete s; if ( p && p->isSplitter ) { data->list.removeRef( p ); delete p->wid; //will call childEvent delete p; } recalcId(); doResize(); return; } p = s; s = data->list.next(); } } } /*! Shows a rubber band at position \a p. If \a p is negative, the rubber band is removed. */ void KDGanttMinimizeSplitter::setRubberband( int p ) { QPainter paint( this ); paint.setPen( gray ); paint.setBrush( gray ); paint.setRasterOp( XorROP ); QRect r = contentsRect(); const int rBord = 3; //Themable???? -#if QT_VERSION >= 300 +#if QT_VERSION >= 0x030000 int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); #else int sw = style().splitterWidth(); #endif if ( orient == Horizontal ) { if ( opaqueOldPos >= 0 ) paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(), 2*rBord, r.height() ); if ( p >= 0 ) paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() ); } else { if ( opaqueOldPos >= 0 ) paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord, r.width(), 2*rBord ); if ( p >= 0 ) paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord ); } opaqueOldPos = p; } /*! \reimp */ bool KDGanttMinimizeSplitter::event( QEvent *e ) { if ( e->type() == QEvent::LayoutHint || ( e->type() == QEvent::Show && data->firstShow ) ) { recalc( isVisible() ); if ( e->type() == QEvent::Show ) data->firstShow = FALSE; } return QWidget::event( e ); } /*! \obsolete Draws the splitter handle in the rectangle described by \a x, \a y, \a w, \a h using painter \a p. \sa QStyle::drawPrimitive() */ void KDGanttMinimizeSplitter::drawSplitter( QPainter *p, QCOORD x, QCOORD y, QCOORD w, QCOORD h ) { #if 0 // LR style().drawPrimitive(QStyle::PE_Splitter, p, QRect(x, y, w, h), colorGroup(), (orientation() == Qt::Horizontal ? QStyle::Style_Horizontal : 0)); #endif } /*! Returns the id of the splitter to the right of or below the widget \a w, or 0 if there is no such splitter (i.e. it is either not in this KDGanttMinimizeSplitter or it is at the end). */ int KDGanttMinimizeSplitter::idAfter( QWidget* w ) const { QSplitterLayoutStruct *s = data->list.first(); bool seen_w = FALSE; while ( s ) { if ( s->isSplitter && seen_w ) return data->list.at(); if ( !s->isSplitter && s->wid == w ) seen_w = TRUE; s = data->list.next(); } return 0; } /*! Moves the left/top edge of the splitter handle with id \a id as close as possible to position \a p, which is the distance from the left (or top) edge of the widget. For Arabic and Hebrew the layout is reversed, and using this function to set the position of the splitter might lead to unexpected results, since in Arabic and Hebrew the position of splitter one is to the left of the position of splitter zero. \sa idAfter() */ void KDGanttMinimizeSplitter::moveSplitter( QCOORD p, int id ) { p = adjustPos( p, id ); QSplitterLayoutStruct *s = data->list.at(id); int oldP = orient == Horizontal ? s->wid->x() : s->wid->y(); bool upLeft; if ( false && orient == Horizontal ) { p += s->wid->width(); upLeft = p > oldP; } else upLeft = p < oldP; @@ -816,193 +816,193 @@ void KDGanttMinimizeSplitter::moveAfter( int pos, int id, bool upLeft ) if( false && orient == Horizontal ) { pos2 = pos - dd; pos1 = pos2 + 1; } else { pos1 = pos; pos2 = pos + dd; } if ( upLeft ) { setG( w, pos1, dd, TRUE ); moveAfter( pos2, id+1, upLeft ); } else { moveAfter( pos2, id+1, upLeft ); setG( w, pos1, dd, TRUE ); } } else { int left = pick( w->pos() ); int right, dd,/* newRight,*/ newLeft, nextPos; if ( false && orient == Horizontal ) { dd = pos - left + 1; dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); newLeft = pos-dd+1; nextPos = newLeft - 1; } else { right = pick( w->geometry().bottomRight() ); dd = right - pos + 1; dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); /*newRight = pos+dd-1;*/ newLeft = pos; nextPos = newLeft + dd; } setG( w, newLeft, dd, TRUE ); /*if( right != newRight )*/ moveAfter( nextPos, id+1, upLeft ); } } void KDGanttMinimizeSplitter::expandPos( int id, int* min, int* max ) { QSplitterLayoutStruct *s = data->list.at(id-1); QWidget* w = s->wid; *min = pick( w->mapToParent( QPoint(0,0) ) ); if ( (uint) id == data->list.count() ) { pick( size() ); } else { QSplitterLayoutStruct *s = data->list.at(id+1); QWidget* w = s->wid; *max = pick( w->mapToParent( QPoint( w->width(), w->height() ) ) ) -8; } } /*! Returns the valid range of the splitter with id \a id in \a *min and \a *max. \sa idAfter() */ void KDGanttMinimizeSplitter::getRange( int id, int *min, int *max ) { int minB = 0; //before int maxB = 0; int minA = 0; int maxA = 0; //after int n = data->list.count(); if ( id < 0 || id >= n ) return; int i; for ( i = 0; i < id; i++ ) { QSplitterLayoutStruct *s = data->list.at(i); if ( s->wid->isHidden() ) { //ignore } else if ( s->isSplitter ) { minB += s->sizer; maxB += s->sizer; } else { minB += pick( minSize(s->wid) ); maxB += pick( s->wid->maximumSize() ); } } for ( i = id; i < n; i++ ) { QSplitterLayoutStruct *s = data->list.at(i); if ( s->wid->isHidden() ) { //ignore } else if ( s->isSplitter ) { minA += s->sizer; maxA += s->sizer; } else { minA += pick( minSize(s->wid) ); maxA += pick( s->wid->maximumSize() ); } } QRect r = contentsRect(); if ( orient == Horizontal && false ) { -#if QT_VERSION >= 300 +#if QT_VERSION >= 0x030000 int splitterWidth = style().pixelMetric(QStyle::PM_SplitterWidth, this); #else int splitterWidth = style().splitterWidth(); #endif if ( min ) *min = pick(r.topRight()) - QMIN( maxB, pick(r.size())-minA ) - splitterWidth; if ( max ) *max = pick(r.topRight()) - QMAX( minB, pick(r.size())-maxA ) - splitterWidth; } else { if ( min ) *min = pick(r.topLeft()) + QMAX( minB, pick(r.size())-maxA ); if ( max ) *max = pick(r.topLeft()) + QMIN( maxB, pick(r.size())-minA ); } } /*! Returns the closest legal position to \a p of the splitter with id \a id. \sa idAfter() */ int KDGanttMinimizeSplitter::adjustPos( int p, int id ) { int min = 0; int max = 0; getRange( id, &min, &max ); p = QMAX( min, QMIN( p, max ) ); return p; } void KDGanttMinimizeSplitter::doResize() { QRect r = contentsRect(); int i; int n = data->list.count(); QMemArray<QLayoutStruct> a( n ); for ( i = 0; i< n; i++ ) { a[i].init(); QSplitterLayoutStruct *s = data->list.at(i); if ( s->wid->isHidden() ) { a[i].stretch = 0; a[i].sizeHint = a[i].minimumSize = 0; a[i].maximumSize = 0; } else if ( s->isSplitter ) { a[i].stretch = 0; a[i].sizeHint = a[i].minimumSize = a[i].maximumSize = s->sizer; a[i].empty = FALSE; } else if ( s->mode == KeepSize ) { a[i].stretch = 0; a[i].minimumSize = pick( minSize(s->wid) ); a[i].sizeHint = s->sizer; a[i].maximumSize = pick( s->wid->maximumSize() ); a[i].empty = FALSE; } else if ( s->mode == FollowSizeHint ) { a[i].stretch = 0; a[i].minimumSize = a[i].sizeHint = pick( s->wid->sizeHint() ); a[i].maximumSize = pick( s->wid->maximumSize() ); a[i].empty = FALSE; } else { //proportional a[i].stretch = s->sizer; a[i].maximumSize = pick( s->wid->maximumSize() ); a[i].sizeHint = a[i].minimumSize = pick( minSize(s->wid) ); a[i].empty = FALSE; } } kdganttGeomCalc( a, 0, n, pick( r.topLeft() ), pick( r.size() ), 0 ); for ( i = 0; i< n; i++ ) { QSplitterLayoutStruct *s = data->list.at(i); setG( s->wid, a[i].pos, a[i].size ); } } void KDGanttMinimizeSplitter::recalc( bool update ) { int fi = 2*frameWidth(); int maxl = fi; int minl = fi; int maxt = QWIDGETSIZE_MAX; int mint = fi; int n = data->list.count(); bool first = TRUE; /* The splitter before a hidden widget is always hidden. The splitter before the first visible widget is hidden. The splitter before any other visible widget is visible. */ for ( int i = 0; i< n; i++ ) { @@ -1294,193 +1294,193 @@ bool KDGanttMinimizeSplitter::isHidden( QWidget *w ) const return !w2show; #ifdef QT_CHECK_RANGE else qWarning( "KDGanttMinimizeSplitter::isHidden(), unknown widget" ); #endif return FALSE; } #endif /*! Returns a list of the size parameters of all the widgets in this splitter. Giving the values to another splitter's setSizes() function will produce a splitter with the same layout as this one. Note that if you want to iterate over the list, you should iterate over a copy, e.g. \code QValueList<int> list = mySplitter.sizes(); QValueList<int>::Iterator it = list.begin(); while( it != list.end() ) { myProcessing( *it ); ++it; } \endcode \sa setSizes() */ QValueList<int> KDGanttMinimizeSplitter::sizes() const { if ( !testWState(WState_Polished) ) { QWidget* that = (QWidget*) this; that->polish(); } QValueList<int> list; QSplitterLayoutStruct *s = data->list.first(); while ( s ) { if ( !s->isSplitter ) list.append( s->sizer ); s = data->list.next(); } return list; } /*! Sets the size parameters to the values given in \a list. If the splitter is horizontal, the values set the sizes from left to right. If it is vertical, the sizes are applied from top to bottom. Extra values in \a list are ignored. If \a list contains too few values, the result is undefined but the program will still be well-behaved. \sa sizes() */ void KDGanttMinimizeSplitter::setSizes( QValueList<int> list ) { processChildEvents(); QValueList<int>::Iterator it = list.begin(); QSplitterLayoutStruct *s = data->list.first(); while ( s && it != list.end() ) { if ( !s->isSplitter ) { s->sizer = *it; ++it; } s = data->list.next(); } doResize(); } /*! Gets all posted child events, ensuring that the internal state of the splitter is consistent. */ void KDGanttMinimizeSplitter::processChildEvents() { QApplication::sendPostedEvents( this, QEvent::ChildInserted ); } /*! \reimp */ void KDGanttMinimizeSplitter::styleChange( QStyle& old ) { -#if QT_VERSION >= 300 +#if QT_VERSION >= 0x030000 int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); #else int sw = style().splitterWidth(); #endif QSplitterLayoutStruct *s = data->list.first(); while ( s ) { if ( s->isSplitter ) s->sizer = sw; s = data->list.next(); } doResize(); QFrame::styleChange( old ); } #endif /*! Specifies the direction of the minimize buttons. If the orientation of the splitter is horizontal then with KDGanttMinimizeSplitter::Left or KDGanttMinimizeSplitter::Right should be used, otherwise either KDGanttMinimizeSplitter::Up or KDGanttMinimizeSplitter::Down should be used. */ void KDGanttMinimizeSplitter::setMinimizeDirection( Direction direction ) { _direction = direction; } /*! Returns the direction of the minimize buttons. */ KDGanttMinimizeSplitter::Direction KDGanttMinimizeSplitter::minimizeDirection() const { return _direction; } /* This is a copy of qGeomCalc() in qlayoutengine.cpp which unfortunately isn't exported. */ static inline int toFixed( int i ) { return i * 256; } static inline int fRound( int i ) { return ( i % 256 < 128 ) ? i / 256 : 1 + i / 256; } void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, int space, int spacer ) { typedef int fixed; int cHint = 0; int cMin = 0; int cMax = 0; int sumStretch = 0; int spacerCount = 0; bool wannaGrow = FALSE; // anyone who really wants to grow? // bool canShrink = FALSE; // anyone who could be persuaded to shrink? int i; for ( i = start; i < start + count; i++ ) { chain[i].done = FALSE; cHint += chain[i].sizeHint; cMin += chain[i].minimumSize; cMax += chain[i].maximumSize; sumStretch += chain[i].stretch; if ( !chain[i].empty ) spacerCount++; wannaGrow = wannaGrow || chain[i].expansive; } int extraspace = 0; if ( spacerCount ) spacerCount--; // only spacers between things if ( space < cMin + spacerCount * spacer ) { // qDebug("not enough space"); for ( i = start; i < start+count; i++ ) { chain[i].size = chain[i].minimumSize; chain[i].done = TRUE; } } else if ( space < cHint + spacerCount*spacer ) { // Less space than sizeHint, but more than minimum. // Currently take space equally from each, like in Qt 2.x. // Commented-out lines will give more space to stretchier items. int n = count; int space_left = space - spacerCount*spacer; int overdraft = cHint - space_left; //first give to the fixed ones: for ( i = start; i < start+count; i++ ) { if ( !chain[i].done && chain[i].minimumSize >= chain[i].sizeHint) { chain[i].size = chain[i].sizeHint; chain[i].done = TRUE; space_left -= chain[i].sizeHint; // sumStretch -= chain[i].stretch; n--; } } bool finished = n == 0; diff --git a/microkde/kcalendarsystemgregorian.cpp b/microkde/kcalendarsystemgregorian.cpp index 7c5b62a..cc12b9f 100644 --- a/microkde/kcalendarsystemgregorian.cpp +++ b/microkde/kcalendarsystemgregorian.cpp @@ -1,344 +1,344 @@ /* Copyright (c) 2002 Carlos Moro <cfmoro@correo.uniovi.es> Copyright (c) 2002 Hans Petter Bieker <bieker@kde.org> 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Derived gregorian kde calendar class // Just a schema. #include <qdatetime.h> #include <qstring.h> #include <klocale.h> #include <kdebug.h> #include "kcalendarsystemgregorian.h" KCalendarSystemGregorian::KCalendarSystemGregorian(const KLocale * locale) : KCalendarSystem(locale) { kdDebug(5400) << "Created gregorian calendar" << endl; } KCalendarSystemGregorian::~KCalendarSystemGregorian() { } int KCalendarSystemGregorian::year(const QDate& date) const { // kdDebug(5400) << "Gregorian year..." << endl; return date.year(); } int KCalendarSystemGregorian::monthsInYear( const QDate & ) const { // kdDebug(5400) << "Gregorian monthsInYear" << endl; return 12; } int KCalendarSystemGregorian::weeksInYear(int year) const { -#if QT_VERSION >= 300 +#if QT_VERSION >= 0x030000 QDate temp; temp.setYMD(year, 12, 31); // If the last day of the year is in the first week, we have to check the // week before if ( temp.weekNumber() == 1 ) temp.addDays(-7); return temp.weekNumber(); #else return 52; #endif } int KCalendarSystemGregorian::weekNumber(const QDate& date, int * yearNum) const { -#if QT_VERSION >= 300 +#if QT_VERSION >= 0x030000 return date.weekNumber(yearNum); #else return 1; #endif } QString KCalendarSystemGregorian::monthName(const QDate& date, bool shortName) const { return monthName(month(date), shortName); } QString KCalendarSystemGregorian::monthNamePossessive(const QDate& date, bool shortName) const { return monthNamePossessive(month(date), shortName); } QString KCalendarSystemGregorian::monthName(int month, bool shortName) const { // kdDebug(5400) << "Gregorian getMonthName" << endl; if ( shortName ) switch ( month ) { case 1: return locale()->translate("January", "Jan"); case 2: return locale()->translate("February", "Feb"); case 3: return locale()->translate("March", "Mar"); case 4: return locale()->translate("April", "Apr"); case 5: return locale()->translate("May short", "May"); case 6: return locale()->translate("June", "Jun"); case 7: return locale()->translate("July", "Jul"); case 8: return locale()->translate("August", "Aug"); case 9: return locale()->translate("September", "Sep"); case 10: return locale()->translate("October", "Oct"); case 11: return locale()->translate("November", "Nov"); case 12: return locale()->translate("December", "Dec"); } else switch ( month ) { case 1: return locale()->translate("January"); case 2: return locale()->translate("February"); case 3: return locale()->translate("March"); case 4: return locale()->translate("April"); case 5: return locale()->translate("May long", "May"); case 6: return locale()->translate("June"); case 7: return locale()->translate("July"); case 8: return locale()->translate("August"); case 9: return locale()->translate("September"); case 10: return locale()->translate("October"); case 11: return locale()->translate("November"); case 12: return locale()->translate("December"); } return QString::null; } QString KCalendarSystemGregorian::monthNamePossessive(int month, bool shortName) const { // kdDebug(5400) << "Gregorian getMonthName" << endl; if ( shortName ) switch ( month ) { case 1: return locale()->translate("of January", "of Jan"); case 2: return locale()->translate("of February", "of Feb"); case 3: return locale()->translate("of March", "of Mar"); case 4: return locale()->translate("of April", "of Apr"); case 5: return locale()->translate("of May short", "of May"); case 6: return locale()->translate("of June", "of Jun"); case 7: return locale()->translate("of July", "of Jul"); case 8: return locale()->translate("of August", "of Aug"); case 9: return locale()->translate("of September", "of Sep"); case 10: return locale()->translate("of October", "of Oct"); case 11: return locale()->translate("of November", "of Nov"); case 12: return locale()->translate("of December", "of Dec"); } else switch ( month ) { case 1: return locale()->translate("of January"); case 2: return locale()->translate("of February"); case 3: return locale()->translate("of March"); case 4: return locale()->translate("of April"); case 5: return locale()->translate("of May long", "of May"); case 6: return locale()->translate("of June"); case 7: return locale()->translate("of July"); case 8: return locale()->translate("of August"); case 9: return locale()->translate("of September"); case 10: return locale()->translate("of October"); case 11: return locale()->translate("of November"); case 12: return locale()->translate("of December"); } return QString::null; } bool KCalendarSystemGregorian::setYMD(QDate & date, int y, int m, int d) const { // We don't want Qt to add 1900 to them if ( y >= 0 && y <= 99 ) return false; // QDate supports gregorian internally return date.setYMD(y, m, d); } QDate KCalendarSystemGregorian::addYears(const QDate & date, int nyears) const { -#if QT_VERSION >= 300 +#if QT_VERSION >= 0x030000 return date.addYears(nyears); #else int year = date.year() + nyears; int month = date.month(); int day = date.day(); QDate newDate( year, month, 1 ); if ( day > newDate.daysInMonth() ) day = newDate.daysInMonth(); return QDate( year, month, day ); #endif } QDate KCalendarSystemGregorian::addMonths(const QDate & date, int nmonths) const { -#if QT_VERSION >= 300 +#if QT_VERSION >= 0x030000 return date.addMonths(nmonths); #else int month = date.month(); int nyears; if ( nmonths >= 0 ) { month += nmonths; nyears = ( month - 1 ) / 12; month = ( ( month - 1 ) % 12 ) + 1; } else { nyears = nmonths / 12; // nmonths += nyears * 12; nmonths = nmonths % 12; month += nmonths; if ( month <= 0 ) { month += 12; --nyears; } } int year = date.year() + nyears; int day = date.day(); QDate newDate( year, month, 1 ); if ( day > newDate.daysInMonth() ) day = newDate.daysInMonth(); return QDate( year, month, day ); #endif } QDate KCalendarSystemGregorian::addDays(const QDate & date, int ndays) const { return date.addDays(ndays); } QString KCalendarSystemGregorian::weekDayName(int col, bool shortName) const { // ### Should this really be different to each calendar system? Or are we // only going to support weeks with 7 days? //kdDebug(5400) << "Gregorian wDayName" << endl; return locale()->weekDayName(col, shortName); } QString KCalendarSystemGregorian::weekDayName(const QDate& date, bool shortName) const { return weekDayName(dayOfWeek(date), shortName); } int KCalendarSystemGregorian::dayOfWeek(const QDate& date) const { return date.dayOfWeek(); } int KCalendarSystemGregorian::dayOfYear(const QDate & date) const { return date.dayOfYear(); } int KCalendarSystemGregorian::daysInMonth(const QDate& date) const { // kdDebug(5400) << "Gregorian daysInMonth" << endl; return date.daysInMonth(); } int KCalendarSystemGregorian::minValidYear() const { return 1753; // QDate limit } int KCalendarSystemGregorian::maxValidYear() const { return 8000; // QDate limit } int KCalendarSystemGregorian::day(const QDate& date) const { return date.day(); } int KCalendarSystemGregorian::month(const QDate& date) const { return date.month(); } int KCalendarSystemGregorian::daysInYear(const QDate& date) const { return date.daysInYear(); } int KCalendarSystemGregorian::weekDayOfPray() const { return 7; // sunday } QString KCalendarSystemGregorian::calendarName() const { return QString::fromLatin1("gregorian"); } |