summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-03-25 15:07:31 (UTC)
committer zautrix <zautrix>2005-03-25 15:07:31 (UTC)
commit3326831dbf6f962e97a978781361db5198f6a035 (patch) (side-by-side diff)
tree9bf6e78ba06b0db2e321ee8f8b95e66b66cca852
parent5a0130ffdbf03fa5b881f856b41d081e91e1958b (diff)
downloadkdepimpi-3326831dbf6f962e97a978781361db5198f6a035.zip
kdepimpi-3326831dbf6f962e97a978781361db5198f6a035.tar.gz
kdepimpi-3326831dbf6f962e97a978781361db5198f6a035.tar.bz2
layout fix
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--korganizer/calendarview.cpp2
-rw-r--r--korganizer/datenavigatorcontainer.cpp40
-rw-r--r--korganizer/datenavigatorcontainer.h2
-rw-r--r--korganizer/kdatenavigator.cpp3
4 files changed, 32 insertions, 15 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 9a4e719..6ed6a1c 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1729,392 +1729,392 @@ bool CalendarView::checkFileVersion(QString fn)
//qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
//qDebug("file on disk version %s",dt.toString().latin1());
if ( dt <= loadedFileVersion )
return true;
int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
i18n("KO/Pi Warning"),i18n("Overwrite"),
i18n("Sync+save"));
if ( km == KMessageBox::Cancel )
return false;
if ( km == KMessageBox::Yes )
return true;
setSyncDevice("deleteaftersync" );
mSyncManager->mAskForPreferences = true;
mSyncManager->mSyncAlgoPrefs = 3;
mSyncManager->mWriteBackFile = false;
mSyncManager->mWriteBackExistingOnly = false;
mSyncManager->mShowSyncSummary = false;
syncCalendar( fn, 3 );
Event * e = getLastSyncEvent();
mCalendar->deleteEvent ( e );
updateView();
return true;
}
bool CalendarView::saveCalendar( QString filename )
{
// Store back all unsaved data into calendar object
// qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
if ( mViewManager->currentView() )
mViewManager->currentView()->flushView();
QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
mStorage->setSaveFormat( new ICalFormat() );
mStorage->setFileName( filename );
bool success;
success = mStorage->save();
if ( !success ) {
return false;
}
if ( filename == MainWindow::defaultFileName() ) {
setLoadedFileVersion( lfv );
watchSavedFile();
}
return true;
}
void CalendarView::closeCalendar()
{
// child windows no longer valid
emit closingDown();
mCalendar->close();
setModified(false);
updateView();
}
void CalendarView::archiveCalendar()
{
mDialogManager->showArchiveDialog();
}
void CalendarView::readSettings()
{
// mViewManager->showAgendaView();
QString str;
//qDebug("CalendarView::readSettings() ");
// read settings from the KConfig, supplying reasonable
// defaults where none are to be found
KConfig *config = KOGlobals::config();
#ifndef KORG_NOSPLITTER
config->setGroup("KOrganizer Geometry");
QValueList<int> sizes = config->readIntListEntry("Separator1");
if (sizes.count() != 2) {
sizes << mDateNavigator->minimumSizeHint().width();
sizes << 300;
}
mPanner->setSizes(sizes);
sizes = config->readIntListEntry("Separator2");
if ( ( mResourceView && sizes.count() == 4 ) ||
( !mResourceView && sizes.count() == 3 ) ) {
mLeftSplitter->setSizes(sizes);
}
#endif
globalFlagBlockAgenda = 1;
mViewManager->showAgendaView();
//mViewManager->readSettings( config );
mTodoList->restoreLayout(config,QString("Todo Layout"));
readFilterSettings(config);
#ifdef DESKTOP_VERSION
config->setGroup("WidgetLayout");
QStringList list;
list = config->readListEntry("MainLayout");
int x,y,w,h;
if ( ! list.isEmpty() ) {
x = list[0].toInt();
y = list[1].toInt();
w = list[2].toInt();
h = list[3].toInt();
topLevelWidget()->setGeometry(x,y,w,h);
} else {
topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
}
list = config->readListEntry("EditEventLayout");
if ( ! list.isEmpty() ) {
x = list[0].toInt();
y = list[1].toInt();
w = list[2].toInt();
h = list[3].toInt();
mEventEditor->setGeometry(x,y,w,h);
}
list = config->readListEntry("EditTodoLayout");
if ( ! list.isEmpty() ) {
x = list[0].toInt();
y = list[1].toInt();
w = list[2].toInt();
h = list[3].toInt();
mTodoEditor->setGeometry(x,y,w,h);
}
list = config->readListEntry("ViewerLayout");
if ( ! list.isEmpty() ) {
x = list[0].toInt();
y = list[1].toInt();
w = list[2].toInt();
h = list[3].toInt();
getEventViewerDialog()->setGeometry(x,y,w,h);
}
#endif
config->setGroup( "Views" );
int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
int resetval = 0;
int maxVal = 0;
if (sizes.count() != 3) {
if ( KOPrefs::instance()->mVerticalScreen ) {
resetval = mDateNavigator->sizeHint().width()+2;
} else {
resetval = mDateNavigator->sizeHint().height()+2;
}
}
if ( resetval ) {
sizes.clear();
if ( KOPrefs::instance()->mVerticalScreen ) {
maxVal = QApplication::desktop()->width() -10;
} else {
maxVal = QApplication::desktop()->height()-10;
}
sizes << resetval;
if ( maxVal < resetval + resetval)
resetval = maxVal - resetval;
sizes << resetval;
sizes << 100;
}
mLeftFrame->setSizes(sizes);
sizes = config->readIntListEntry("Main Splitter Frame");
resetval = 0;
maxVal = 0;
if (sizes.count() != 2) {
if ( !KOPrefs::instance()->mVerticalScreen ) {
resetval = mDateNavigator->sizeHint().width()+2;
} else {
resetval = mDateNavigator->sizeHint().height()+2;
}
}
if ( resetval ) {
sizes.clear();
if ( !KOPrefs::instance()->mVerticalScreen ) {
maxVal = QApplication::desktop()->width() -10;
} else {
maxVal = QApplication::desktop()->height()-10;
}
sizes << resetval;
if ( maxVal < resetval + resetval)
resetval = maxVal - resetval;
sizes << resetval;
}
mMainFrame->setSizes(sizes);
-
if ( dateCount == 5 ) mNavigator->selectWorkWeek();
else if ( dateCount == 7 ) mNavigator->selectWeek();
else mNavigator->selectDates( dateCount );
// mViewManager->readSettings( config );
updateConfig();
globalFlagBlockAgenda = 2;
mViewManager->readSettings( config );
+ QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) );
}
void CalendarView::writeSettings()
{
// kdDebug() << "CalendarView::writeSettings" << endl;
KConfig *config = KOGlobals::config();
mViewManager->writeSettings( config );
mTodoList->saveLayout(config,QString("Todo Layout"));
mDialogManager->writeSettings( config );
//KOPrefs::instance()->usrWriteConfig();
KOPrefs::instance()->writeConfig();
writeFilterSettings(config);
config->setGroup( "Views" );
config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
QValueList<int> listINT = mLeftFrame->sizes();
config->writeEntry("Left Splitter Frame",listINT);
QValueList<int> listINT2 = mMainFrame->sizes();
config->writeEntry("Main Splitter Frame",listINT2);
#ifdef DESKTOP_VERSION
config->setGroup("WidgetLayout");
QStringList list ;//= config->readListEntry("MainLayout");
int x,y,w,h;
QWidget* wid;
wid = topLevelWidget();
x = wid->geometry().x();
y = wid->geometry().y();
w = wid->width();
h = wid->height();
list.clear();
list << QString::number( x );
list << QString::number( y );
list << QString::number( w );
list << QString::number( h );
config->writeEntry("MainLayout",list );
wid = mEventEditor;
x = wid->geometry().x();
y = wid->geometry().y();
w = wid->width();
h = wid->height();
list.clear();
list << QString::number( x );
list << QString::number( y );
list << QString::number( w );
list << QString::number( h );
config->writeEntry("EditEventLayout",list );
wid = mTodoEditor;
x = wid->geometry().x();
y = wid->geometry().y();
w = wid->width();
h = wid->height();
list.clear();
list << QString::number( x );
list << QString::number( y );
list << QString::number( w );
list << QString::number( h );
config->writeEntry("EditTodoLayout",list );
wid = getEventViewerDialog();
x = wid->geometry().x();
y = wid->geometry().y();
w = wid->width();
h = wid->height();
list.clear();
list << QString::number( x );
list << QString::number( y );
list << QString::number( w );
list << QString::number( h );
config->writeEntry("ViewerLayout",list );
wid = mDialogManager->getSearchDialog();
if ( wid ) {
x = wid->geometry().x();
y = wid->geometry().y();
w = wid->width();
h = wid->height();
list.clear();
list << QString::number( x );
list << QString::number( y );
list << QString::number( w );
list << QString::number( h );
config->writeEntry("SearchLayout",list );
}
#endif
config->sync();
}
void CalendarView::readFilterSettings(KConfig *config)
{
// kdDebug() << "CalendarView::readFilterSettings()" << endl;
mFilters.clear();
config->setGroup("General");
QStringList filterList = config->readListEntry("CalendarFilters");
QStringList::ConstIterator it = filterList.begin();
QStringList::ConstIterator end = filterList.end();
while(it != end) {
// kdDebug() << " filter: " << (*it) << endl;
CalFilter *filter;
filter = new CalFilter(*it);
config->setGroup("Filter_" + (*it));
//qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
filter->setCriteria(config->readNumEntry("Criteria",0));
filter->setCategoryList(config->readListEntry("CategoryList"));
mFilters.append(filter);
++it;
}
if (mFilters.count() == 0) {
CalFilter *filter = new CalFilter(i18n("Default"));
mFilters.append(filter);
}
mFilterView->updateFilters();
config->setGroup("FilterView");
mFilterView->blockSignals(true);
mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
mFilterView->blockSignals(false);
// We do it manually to avoid it being done twice by the above calls
updateFilter();
}
void CalendarView::writeFilterSettings(KConfig *config)
{
// kdDebug() << "CalendarView::writeFilterSettings()" << endl;
QStringList filterList;
CalFilter *filter = mFilters.first();
while(filter) {
// kdDebug() << " fn: " << filter->name() << endl;
filterList << filter->name();
config->setGroup("Filter_" + filter->name());
config->writeEntry("Criteria",filter->criteria());
config->writeEntry("CategoryList",filter->categoryList());
filter = mFilters.next();
}
config->setGroup("General");
config->writeEntry("CalendarFilters",filterList);
config->setGroup("FilterView");
config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
}
void CalendarView::goToday()
{
if ( mViewManager->currentView()->isMonthView() )
mNavigator->selectTodayMonth();
else
mNavigator->selectToday();
}
void CalendarView::goNext()
{
mNavigator->selectNext();
}
void CalendarView::goPrevious()
{
mNavigator->selectPrevious();
}
void CalendarView::goNextMonth()
{
mNavigator->selectNextMonth();
}
void CalendarView::goPreviousMonth()
{
mNavigator->selectPreviousMonth();
}
void CalendarView::writeLocale()
{
//KPimGlobalPrefs::instance()->setGlobalConfig();
#if 0
KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
diff --git a/korganizer/datenavigatorcontainer.cpp b/korganizer/datenavigatorcontainer.cpp
index 2290c53..11dc592 100644
--- a/korganizer/datenavigatorcontainer.cpp
+++ b/korganizer/datenavigatorcontainer.cpp
@@ -1,415 +1,429 @@
/*
This file is part of KOrganizer.
Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org>
Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 <kdebug.h>
#include <klocale.h>
//#include "koglobals.h"
#include "navigatorbar.h"
#include "kdatenavigator.h"
#include <kcalendarsystem.h>
#include "datenavigatorcontainer.h"
#include "koprefs.h"
DateNavigatorContainer::DateNavigatorContainer( QWidget *parent,
const char *name )
: QWidget( parent, name ), mCalendar( 0 ),
mHorizontalCount( 1 ), mVerticalCount( 1 )
{
+ mResizeEnabled = false;
mExtraViews.setAutoDelete( true );
mNavigatorView = new KDateNavigator( this, name );
-
+ mNavigatorView->hide();
connectNavigatorView( mNavigatorView );
//setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) );
mLastDisplayedDN = 0;
mUpdateTimer;
mUpdateTimer = new QTimer( this );
connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( checkUpdateDayMatrixDates() ));
mFirstSelectedDate = QDate::currentDate();
mSelectedDateCount = 1;
}
DateNavigatorContainer::~DateNavigatorContainer()
{
}
void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v )
{
connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ),
SIGNAL( datesSelected( const KCal::DateList & ) ) );
#if 0
connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ),
SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) );
connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ),
SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) );
#endif
connect( v, SIGNAL( weekClicked( const QDate & ) ),
SIGNAL( weekClicked( const QDate & ) ) );
connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) );
connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) );
connect( v, SIGNAL( goNextMonth() ), SLOT( slotgoNextMonth() ) );
connect( v, SIGNAL( goPrevMonth() ), SLOT( slotgoPrevMonth() ) );
connect( v, SIGNAL( goNextYear() ), SLOT( slotgoNextYear() ) );
connect( v, SIGNAL( goPrevYear() ), SLOT( slotgoPrevYear() ) );
connect( v, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) );
}
void DateNavigatorContainer::slotgoNextYear()
{
jumpMonth( 12 );
emit goNextYear();
}
void DateNavigatorContainer::slotgoPrevYear()
{
jumpMonth( -12 );
emit goPrevYear();
}
void DateNavigatorContainer::slotgoPrevMonth()
{
jumpMonth( -1 );
emit goPrevMonth();
}
void DateNavigatorContainer::slotgoNextMonth()
{
jumpMonth( 1 );
emit goNextMonth();
}
void DateNavigatorContainer::jumpMonth( int month )
{
QDate baseDate = mNavigatorView->baseDate();
computeMonthSelected( baseDate.month() + month, false );
}
void DateNavigatorContainer::slotMonthSelected( int month )
{
computeMonthSelected( month, true );
}
void DateNavigatorContainer::computeMonthSelected( int month , bool forceEmit )
{
//qDebug("slotMonthSelected %d ", month);
QDate baseDate = mNavigatorView->baseDate();
if ( baseDate.month() == month )
return;
//qDebug("month %d %d ",baseDate.month(),month);
QDate date = QDate ( baseDate.year(), baseDate.month() , 15 );
date = date.addDays( -(baseDate.month()-month ) *30 );
QDate newBase = QDate ( date.year(), date.month() , baseDate.day() );
//qDebug("NEW BASE %s", newBase.toString().latin1());
mNavigatorView->setBaseDate( newBase );
QDate last = lastAvailableDate();
QDate first = firstAvailableDate();
QDate selFirst = mFirstSelectedDate;
QDate selLast = selFirst.addDays( mSelectedDateCount-1 );
if ( selFirst >= first && selLast <= last ) {
setBaseDates();
if ( forceEmit )
updateDayMatrixDates();
}
else {
setBaseDates();
if ( forceEmit )
updateDayMatrixDates();
if ( forceEmit )
emit monthSelected( month );
}
}
void DateNavigatorContainer::setCalendar( Calendar *cal )
{
mCalendar = cal;
mNavigatorView->setCalendar( cal );
for( uint i = 0; i < mLastDisplayedDN; ++i ) {
KDateNavigator *n = mExtraViews.at( i );
n->setCalendar( cal );
}
}
void DateNavigatorContainer::checkUpdateDayMatrixDates()
{
//qDebug("KODNC: wid %d hei %d ", width(), height());
mUpdateTimer->stop();
//return;
if ( width() < 3 || height() < 3 )
return;
static int lastWid = 0;
static int lastHei = 0;
if ( lastWid == width() && height() == lastHei ) {
qDebug("KODNC: No layout computing needed. ");
} else {
lastWid = width();
lastHei = height();
QSize minSize = mNavigatorView->yourSizeHint();
int verticalCount = size().height() / minSize.height();
int horizontalCount = size().width() / minSize.width();
//qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() );
//qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount );
bool fontchange = false;
if ( horizontalCount == 1)
horizontalCount = size().width() / mNavigatorView->yourFullSizeHint().width();
QFont fo;
if ( horizontalCount != mHorizontalCount ||
verticalCount != mVerticalCount ) {
uint count = horizontalCount * verticalCount;
if ( count == 0 ) {
bool ok;
fo = mNavigatorView->yourFontHint( size() , &ok );
//mNavigatorView->resize( size() );
//if ( ! ok )
// return;
int butt = 2;
horizontalCount = size().width() / mNavigatorView->sizeHintTwoButtons( ).width();
if ( horizontalCount <= 1 )
minSize = mNavigatorView->sizeHintTwoButtons( 4 );
else
minSize = mNavigatorView->sizeHintTwoButtons();
verticalCount = size().height() / minSize.height();
horizontalCount = size().width() / minSize.width();
if ( horizontalCount == 0 )
horizontalCount = 1;
if ( verticalCount == 0 )
verticalCount = 1;
fontchange = true;
count = horizontalCount * verticalCount;
} else {
if ( mNavigatorView->fontChanged() ) {
fontchange = true;
fo = KOPrefs::instance()->mDateNavigatorFont;
mNavigatorView->changeFont( fo );
mNavigatorView->unsetFontChanged();
}
}
mLastDisplayedDN = horizontalCount*verticalCount-1;
while ( count > ( mExtraViews.count() + 1 ) ) {
KDateNavigator *n = new KDateNavigator( this );
n->setMonthSignalOffset ( mExtraViews.count()+1 );
mExtraViews.append( n );
n->setCalendar( mCalendar );
connectNavigatorView( n );
- n->show();
- }
- int iii = 0;
- while ( iii < ( mExtraViews.count() ) ) {
- if ( iii < count-1 )
- mExtraViews.at( iii )->show();
- else
- mExtraViews.at( iii )->hide();
- ++iii;
+ // n->show();
}
+
setBaseDates();
if ( fontchange ) {
//mNavigatorView->changeFont( fo );
uint i;
for( i = 0; i < mExtraViews.count(); ++i ) {
KDateNavigator *view = mExtraViews.at( i );
view->changeFont( fo );
}
}
mHorizontalCount = horizontalCount;
mVerticalCount = verticalCount;
}
int theight = height() / mVerticalCount;
int twidth = width() / mHorizontalCount;
NavigatorBar *bar = mNavigatorView->navigatorBar();
if ( mHorizontalCount > 1 ) bar->showButtons( true, false );
else bar->showButtons( true, true );
mNavigatorView->setGeometry(0,
0, twidth, theight );
for( uint i = 0; i < mLastDisplayedDN; ++i ) {
int x = ( i + 1 ) % mHorizontalCount;
int y = ( i + 1 ) / mHorizontalCount;
KDateNavigator *view = mExtraViews.at( i );
bar = view->navigatorBar();
if ( y > 0 ) bar->showButtons( false, false );
else {
if ( x + 1 == mHorizontalCount ) bar->showButtons( false, true );
else bar->showButtons( false, false );
}
view->setGeometry( x * twidth,
y * theight, twidth, theight );
}
+ int iii = 0;
+ int ccc = mHorizontalCount * mVerticalCount;
+ mNavigatorView->show();
+ while ( iii < ( mExtraViews.count() ) ) {
+ if ( iii < ccc-1 )
+ mExtraViews.at( iii )->show();
+ else
+ mExtraViews.at( iii )->hide();
+ ++iii;
+ }
}
QDate last = lastAvailableDate();
QDate first = firstAvailableDate();
QDate selFirst = mFirstSelectedDate;
QDate selLast = selFirst.addDays( mSelectedDateCount-1 );
if ( selFirst >= first && selLast <= last ) {
updateDayMatrixDates();
}
else {
updateDayMatrixDates();
emit monthSelected( mFirstSelectedDate.month() );
}
}
void DateNavigatorContainer::updateDayMatrixDates()
{
QDate fDate = mFirstSelectedDate;
QDate lDate = fDate.addDays( mSelectedDateCount - 1 );
mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate );
mNavigatorView->dayMatrix()->repaint( false );
for( uint i = 0; i < mLastDisplayedDN; ++i ) {
KDateNavigator *n = mExtraViews.at( i );
if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) {
n->dayMatrix()->repaint( false );
}
}
}
void DateNavigatorContainer::updateDayMatrix()
{
mNavigatorView->updateDayMatrix();
for( uint i = 0; i < mLastDisplayedDN; ++i ) {
KDateNavigator *n = mExtraViews.at( i );
n->updateDayMatrix();
}
}
void DateNavigatorContainer::updateToday()
{
qDebug("DateNavigatorContainer::updateToday() NOT IMPL ");
#if 0
mNavigatorView->updateToday();
KDateNavigator *n;
for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
n->updateToday();
}
#endif
}
void DateNavigatorContainer::updateView()
{
mNavigatorView->updateView();
for( uint i = 0; i < mLastDisplayedDN; ++i ) {
KDateNavigator *n = mExtraViews.at( i );
n->updateView();
}
}
void DateNavigatorContainer::updateConfig()
{
mNavigatorView->updateConfig();
for( uint i = 0; i < mLastDisplayedDN; ++i ) {
KDateNavigator *n = mExtraViews.at( i );
n->updateConfig();
}
}
QDate DateNavigatorContainer::lastAvailableDate() const
{
QDate date = mNavigatorView->baseDate();
QDate last = QDate ( date.year(), date.month(), date.daysInMonth() );
int iii = mLastDisplayedDN;
if ( mLastDisplayedDN )
last = last.addDays( 1);
while ( iii ) {
last = last.addDays( last.daysInMonth ());
//qDebug("DATE %s ", last.toString().latin1() );
--iii;
}
if ( mLastDisplayedDN )
last = last.addDays( -1);
return last;
}
QDate DateNavigatorContainer::firstAvailableDate() const
{
return QDate ( mNavigatorView->baseDate().year(), mNavigatorView->baseDate().month(), 1 );
}
void DateNavigatorContainer::selectDates( const DateList &dateList )
{
mFirstSelectedDate = dateList.first() ;
mSelectedDateCount = dateList.count() ;
if ( !mLastDisplayedDN ) {
mNavigatorView->selectDates( dateList );
return;
}
QDate fDate = dateList.first();
QDate lDate = dateList.last();
//qDebug("%s %s ", lastAvailableDate().toString().latin1(), firstAvailableDate().toString().latin1() );
//qDebug("End %s %s ",lDate.toString().latin1(),curEnd.toString().latin1() );
if ( lDate <= lastAvailableDate() && firstAvailableDate() <= fDate) {
updateDayMatrixDates();
return;
}
mNavigatorView->selectDates( dateList );
setBaseDates();
if ( mLastDisplayedDN ) {
KDateNavigator *view = mExtraViews.at( 0 );
view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
view->dayMatrix()->repaint( false );
if ( mLastDisplayedDN > 1 ) {
KDateNavigator *view = mExtraViews.at( 1 );
view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
view->dayMatrix()->repaint( false );
}
}
}
void DateNavigatorContainer::setBaseDates()
{
QDate baseDate = mNavigatorView->baseDate();
bool doRepaint = true;
for( uint i = 0; i < mLastDisplayedDN; ++i ) {
KDateNavigator *n = mExtraViews.at( i );
baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 );
n->setBaseDate( baseDate, doRepaint );
}
}
-
+void DateNavigatorContainer::setResizeEnabled()
+{
+ mResizeEnabled = true;
+ //qDebug("DateNavigatorContainer::setResizeEnabled ");
+ checkUpdateDayMatrixDates();
+}
void DateNavigatorContainer::resizeEvent( QResizeEvent * e )
{
-
+ //qDebug("DateNavigatorContainer::resizeEvent %d %d ", width(), height());
//qDebug("COUNT %d ", mExtraViews.count());
-
+ if ( ! mResizeEnabled ) {
+ //qDebug("NOT ResizeEnabled");
+ return;
+ }
+ else
mUpdateTimer->start( 250 );
+
//updateDayMatrixDates();
}
QSize DateNavigatorContainer::minimumSizeHint() const
{
return mNavigatorView->minimumSizeHint();
}
QSize DateNavigatorContainer::sizeHint() const
{
return mNavigatorView->yourSizeHint();
}
diff --git a/korganizer/datenavigatorcontainer.h b/korganizer/datenavigatorcontainer.h
index d2f397d..ac9745d 100644
--- a/korganizer/datenavigatorcontainer.h
+++ b/korganizer/datenavigatorcontainer.h
@@ -1,106 +1,108 @@
/*
This file is part of KOrganizer.
Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
Copyright (C) 2004 Reinhold Kainhofer <reinhold@kainhofer.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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.
*/
#ifndef DATENAVIGATORCONTAINER_H
#define DATENAVIGATORCONTAINER_H
class KDateNavigator;
#include <qwidget.h>
#include <qtimer.h>
#include <libkcal/calendar.h>
using namespace KCal;
class DateNavigatorContainer: public QWidget
{
Q_OBJECT
public:
DateNavigatorContainer( QWidget *parent = 0, const char *name = 0 );
~DateNavigatorContainer();
/**
Associate date navigator with a calendar. It is used by KODayMatrix.
*/
void setCalendar( Calendar * );
QSize minimumSizeHint() const;
QSize sizeHint() const;
KDateNavigator * navigatorView() { return mNavigatorView;}
QDate lastAvailableDate() const ;
QDate firstAvailableDate() const ;
public slots:
void selectDates( const KCal::DateList & );
void updateView();
void updateConfig();
void updateDayMatrix();
void updateDayMatrixDates();
void checkUpdateDayMatrixDates();
void updateToday();
void slotMonthSelected( int month );
void slotgoNextMonth();
void slotgoPrevMonth();
void slotgoNextYear();
void slotgoPrevYear();
+ void setResizeEnabled();
signals:
void datesSelected( const KCal::DateList & );
void incidenceDropped( Incidence *, const QDate & );
void incidenceDroppedMove( Incidence *, const QDate & );
void weekClicked( const QDate &);
void goPrevious();
void goNext();
void goNextMonth();
void goPrevMonth();
void goNextYear();
void goPrevYear();
void monthSelected( int month );
protected:
void computeMonthSelected( int month , bool forceEmit );
void jumpMonth( int month );
void resizeEvent( QResizeEvent * );
void setBaseDates();
void connectNavigatorView( KDateNavigator *v );
private:
+ bool mResizeEnabled;
QTimer* mUpdateTimer;
int mLastDisplayedDN;
QDate mFirstSelectedDate;
int mSelectedDateCount;
KDateNavigator *mNavigatorView;
KCal::Calendar *mCalendar;
QPtrList<KDateNavigator> mExtraViews;
int mHorizontalCount;
int mVerticalCount;
};
#endif
diff --git a/korganizer/kdatenavigator.cpp b/korganizer/kdatenavigator.cpp
index 0cb767f..5eccfd6 100644
--- a/korganizer/kdatenavigator.cpp
+++ b/korganizer/kdatenavigator.cpp
@@ -1,466 +1,467 @@
/*
This file is part of KOrganizer.
Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 <qstring.h>
#include <qkeycode.h>
#include <qlayout.h>
#include <qtimer.h>
#include <qframe.h>
#include <qlabel.h>
#include <qapplication.h>
#include <kdebug.h>
#include <klocale.h>
#include <kglobal.h>
#include "koglobals.h"
#include "koprefs.h"
#ifndef KORG_NOPLUGINS
#include "kocore.h"
#endif
#include <kcalendarsystem.h>
#include "navigatorbar.h"
#include "kdatenavigator.h"
KDateNavigator::KDateNavigator( QWidget *parent, const char *name )
: QFrame(parent, name),
updateTimer(0L)
{
setFrameStyle(QFrame::NoFrame);
QDate startDate = QDate::currentDate();
QGridLayout *topLayout = new QGridLayout(this,8,8);
if (! startDate.isValid()) {
qDebug("KDateNavigator::invalid startdate ");
startDate = QDate::currentDate();
}
mMonthSignalOffset = 0;
mSelectedDates.append(startDate);
m_MthYr = startDate;
m_bShowWeekNums = true;
setFont( KOPrefs::instance()->mDateNavigatorFont );
mNavigatorBar = new NavigatorBar( startDate, this );
topLayout->addMultiCellWidget( mNavigatorBar, 0, 0, 0, 7 );
//mNavigatorBar->resize( 1,1);
connect( mNavigatorBar, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) );
connect( mNavigatorBar, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) );
connect( mNavigatorBar, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) );
connect( mNavigatorBar, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) );
connect( mNavigatorBar, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) );
// get the day of the week on the first day
QDate dayone(m_MthYr.year(), m_MthYr.month(), 1);
m_fstDayOfWk = dayone.dayOfWeek();
int i;
// Set up the heading fields.
for( i = 0; i < 7; i++ ) {
headings[i] = new QLabel("",this);
//headings[i]->setFont(QFont("Arial", 10, QFont::Bold));
headings[i]->setAlignment(AlignCenter);
headings[i]->installEventFilter(this);
topLayout->addWidget(headings[i],1,i+1);
}
// Create the weeknumber labels
for( i = 0; i < 6; i++ ) {
weeknos[i] = new QLabel(this);
weeknos[i]->setAlignment(AlignCenter);
//weeknos[i]->setFont(QFont("Arial", 10));
if(!m_bShowWeekNums) {
weeknos[i]->hide();
}
weeknos[i]->installEventFilter(this);
topLayout->addWidget(weeknos[i],i+2,0);
}
daymatrix = new KODayMatrix( this, "KDateNavigator::DayMatrix");
daymatrix->setFrameStyle(QFrame::Panel|QFrame::Sunken);
daymatrix->setLineWidth(1);
connect( daymatrix, SIGNAL( selected( const KCal::DateList & ) ),
SIGNAL( datesSelected( const KCal::DateList & ) ) );
connect( daymatrix, SIGNAL( eventDropped( Event * ) ),
SIGNAL( eventDropped( Event * ) ) );
topLayout->addMultiCellWidget(daymatrix,2,7,1,7);
// read settings from configuration file.
updateConfig();
enableRollover(FollowMonth);
mySizeHint = sizeHintTwoButtons();
myFullSizeHint = sizeHintTwoButtons( 4 );
mFontChanged = false;
- resize ( 3,3 );
+ //resize ( 3,3 );
}
void KDateNavigator::changeFont ( QFont fo )
{
setFont( fo );
mNavigatorBar->resetFont( fo );
}
QFont KDateNavigator::yourFontHint( QSize si , bool *b)
{
QFont fo = KOPrefs::instance()->mDateNavigatorFont;
*b = false;
int fontPoint = fo.pointSize();
while ( fontPoint > 5 ) {
--fontPoint;
fo.setPointSize( fontPoint );
setFont( fo );
mFontChanged = true;
mNavigatorBar->resetFont( fo );
QSize sh = sizeHintTwoButtons( 2 );
//qDebug("fp %d %d %d %d %d", fontPoint, si.width() , sh.width() , si.height() , sh.height() );
if ( si.width() > sh.width() && si.height() > sh.height()) {
if ( si.width() / sh.width() == 1 ) {
if ( si.width() < sizeHintTwoButtons( 4 ).width())
continue;
}
*b = true;
//qDebug("fooooooooooooooooooooooouuuuund ");
break;
}
}
//qDebug("returnnnnnnnnnnnnnnnnnnn %d", fo.pointSize() );
return fo;
}
QSize KDateNavigator::sizeHint() const
{
QFontMetrics fm ( font() );
QSize day = daymatrix->sizeHint();
QSize nav = mNavigatorBar->sizeHint();
int wid = fm.width( "30") + day.width()+3;
int hei = fm.height() +day.height()+nav.height()+2;
if ( wid < nav.width() )
wid = nav.width() ;
//qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei);
return QSize ( wid, hei );
}
QSize KDateNavigator::sizeHintTwoButtons( int butnum ) const
{
QFontMetrics fm ( font() );
QSize day = daymatrix->sizeHint();
QSize nav = mNavigatorBar->sizeHintTwoButtons( butnum );
int wid = fm.width( "30") + day.width()+3;
int hei = fm.height() +day.height()+nav.height()+2;
if ( wid < nav.width() )
wid = nav.width() ;
//qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei);
return QSize ( wid, hei );
}
void KDateNavigator::slotMonthSelected( int m )
{
if ( m_MthYr.month() <= mMonthSignalOffset)
m += 12;
//qDebug("%d mMonthSignalOffset %d emit %d", m, mMonthSignalOffset, m - mMonthSignalOffset);
emit monthSelected( m - mMonthSignalOffset );
}
void KDateNavigator::setCalendar( Calendar *cal )
{
daymatrix->setCalendar( cal );
}
void KDateNavigator::setBaseDate( const QDate &date , bool doRepaint ) // = true
{
m_MthYr = date;
//qDebug("KDateNavigator::setBaseDate %s ", date.toString().latin1());
updateDates();
updateView();
KCal::DateList dates;
dates.append( date );
mNavigatorBar->selectDates( dates );
daymatrix->clearSelection();
if ( doRepaint )
daymatrix->repaint( false );
}
void KDateNavigator::enableRollover(RolloverType r)
{
switch(r)
{
case None :
if (updateTimer)
{
updateTimer->stop();
delete updateTimer;
updateTimer=0L;
}
break;
case FollowDay :
case FollowMonth :
if (!updateTimer)
{
updateTimer = new QTimer(this);
QObject::connect(updateTimer,SIGNAL(timeout()),
this,SLOT(possiblyPastMidnight()));
}
updateTimer->start(0,true);
lastDayChecked = QDate::currentDate();
}
updateRollover=r;
}
KDateNavigator::~KDateNavigator()
{
}
void KDateNavigator::passedMidnight()
{
QDate today = QDate::currentDate();
bool emitMonth = false;
if (today.month() != lastDayChecked.month())
{
if (updateRollover==FollowMonth &&
daymatrix->isEndOfMonth()) {
goNextMonth();
emitMonth=true;
}
}
daymatrix->recalculateToday();
daymatrix->repaint( false );
emit dayPassed(today);
if (emitMonth) { emit monthPassed(today); }
}
/* slot */ void KDateNavigator::possiblyPastMidnight()
{
if (lastDayChecked!=QDate::currentDate())
{
passedMidnight();
lastDayChecked=QDate::currentDate();
}
// Set the timer to go off 1 second after midnight
// or after 8 minutes, whichever comes first.
if (updateTimer)
{
QTime now = QTime::currentTime();
QTime midnight = QTime(23,59,59);
int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000);
// qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait))
// .arg(now.toString()).arg(midnight.toString()));
updateTimer->stop();
updateTimer->start(msecsWait,true);
}
}
void KDateNavigator::updateDates()
{
// Find the first day of the week of the current month.
//int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr );
QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() );
int d2 = KOGlobals::self()->calendarSystem()->day( dayone );
//int di = d1 - d2 + 1;
dayone = dayone.addDays( -d2 + 1 );
int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone );
// If month begins on Monday and Monday is first day of week,
// month should begin on second line. Sunday doesn't have this problem.
int nextLine = ( ( m_fstDayOfWkCalsys == 1) &&
( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0;
// update the matrix dates
int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine;
daymatrix->updateView(dayone.addDays(index));
//each updateDates is followed by an updateView -> repaint is issued there !
// daymatrix->repaint();
}
void KDateNavigator::updateDayMatrix()
{
daymatrix->updateView();
//daymatrix->repaint();
}
void KDateNavigator::updateView()
{
setUpdatesEnabled( false );
int i;
// kdDebug() << "updateView() -> daymatrix->updateView()" << endl;
daymatrix->updateView();
// set the week numbers.
for(i = 0; i < 6; i++) {
QString weeknum;
// remember, according to ISO 8601, the first week of the year is the
// first week that contains a thursday. Thus we must subtract off 4,
// not just 1.
//ET int dayOfYear = buttons[(i + 1) * 7 - 4]->date().dayOfYear();
int dayOfYear = KOGlobals::self()->calendarSystem()->dayOfYear((daymatrix->getDate((i+1)*7-4)));
int add = 0;
if ( ! KGlobal::locale()->weekStartsMonday() )
++add;
if (dayOfYear % 7 != 0)
weeknum.setNum(dayOfYear / 7 + 1+add);
else
weeknum.setNum(dayOfYear / 7 +add);
weeknos[i]->setText(weeknum);
}
setUpdatesEnabled( true );
// kdDebug() << "updateView() -> repaint()" << endl;
repaint();
// daymatrix->repaint();
}
void KDateNavigator::updateConfig()
{
int day;
for(int i=0; i<7; i++) {
// take the first letter of the day name to be the abbreviation
if (KGlobal::locale()->weekStartsMonday()) {
day = i+1;
} else {
if (i==0) day = 7;
else day = i;
}
QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( day,
true );
if ( KOPrefs::instance()->mCompactDialogs ) dayName = dayName.left( 1 );
headings[i]->setText( dayName );
}
updateDates();
updateView();
}
void KDateNavigator::setShowWeekNums(bool enabled)
{
+ qDebug("KDateNavigator::setShowWeekNums***************************** ");
m_bShowWeekNums = enabled;
for(int i=0; i<6; i++) {
if(enabled)
weeknos[i]->show();
else
weeknos[i]->hide();
}
resize(size());
}
void KDateNavigator::selectDates(const DateList& dateList)
{
if (dateList.count() > 0) {
mNavigatorBar->selectDates( dateList );
mSelectedDates = dateList;
// set our record of the month and year that this datetbl is
// displaying.
m_MthYr = mSelectedDates.first();
// set our record of the first day of the week of the current
// month. This needs to be done before calling dayToIndex, since it
// relies on this information being up to date.
QDate dayone(m_MthYr.year(), m_MthYr.month(), 1);
m_fstDayOfWk = dayone.dayOfWeek();
updateDates();
daymatrix->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
updateView();
}
}
int KDateNavigator::dayNum(int row, int col)
{
return 7 * (row - 1) + (col + 1) - m_fstDayOfWk;
}
int KDateNavigator::dayToIndex(int dayNum)
{
int row, col;
row = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) / 7;
if (KGlobal::locale()->weekStartsMonday() && (m_fstDayOfWk == 1))
row++;
col = (dayNum+m_fstDayOfWk-1-(KGlobal::locale()->weekStartsMonday() ? 1 : 0)) % 7;
return row * 7 + col;
}
void KDateNavigator::wheelEvent (QWheelEvent *e)
{
if(e->delta()>0) emit goPrevious();
else emit goNext();
e->accept();
}
bool KDateNavigator::eventFilter (QObject *o,QEvent *e)
{
if (e->type() == QEvent::MouseButtonPress) {
int i;
for(i=0;i<6;++i) {
if (o == weeknos[i]) {
QDate weekstart = daymatrix->getDate(i*7);
emit weekClicked(weekstart);
break;
}
}
for(i=0;i<7;++i) {
if (o == headings[i]) {
KCal::DateList selDays;
QDate date = daymatrix->getDate(14);
int dio = date.daysInMonth();
int j;
int ye = date.year();
int mo = date.month();
for ( j = 1; j <= dio; ++j ) {
selDays.append( QDate( ye, mo, j ) );
}
emit datesSelected( selDays );
break;
}
}
return true;
} else {
return false;
}
}
//#include "kdatenavigator.moc"