summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-02-07 06:10:09 (UTC)
committer zautrix <zautrix>2005-02-07 06:10:09 (UTC)
commit301a4a207171549bd87815705d8dcf32ad15559d (patch) (side-by-side diff)
tree715fde2cd0af0c057f767c25d8e67298425b2c82
parent961fc44f4092c1f981eb3be4284715e6829f885c (diff)
downloadkdepimpi-301a4a207171549bd87815705d8dcf32ad15559d.zip
kdepimpi-301a4a207171549bd87815705d8dcf32ad15559d.tar.gz
kdepimpi-301a4a207171549bd87815705d8dcf32ad15559d.tar.bz2
new cool feature
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp106
-rw-r--r--korganizer/mainwindow.h15
-rw-r--r--microkde/kdatetbl.cpp1091
-rw-r--r--microkde/kdatetbl.h63
4 files changed, 775 insertions, 500 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index 348dd5e..119e28a 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -1,267 +1,267 @@
#include <stdlib.h>
#include <qaction.h>
#include <qpopupmenu.h>
#include <qpainter.h>
#include <qwhatsthis.h>
#include <qpushbutton.h>
#include <qmessagebox.h>
#include <qlineedit.h>
#include <qtextcodec.h>
#include <qfile.h>
#include <qdir.h>
#include <qapp.h>
#include <qfileinfo.h>
#include <qlabel.h>
#include <qspinbox.h>
#include <qcheckbox.h>
#include <qmap.h>
#include <qwmatrix.h>
#include <qtextbrowser.h>
#include <qtextstream.h>
#ifndef DESKTOP_VERSION
#include <qpe/global.h>
#include <qpe/qpemenubar.h>
#include <qpe/qpetoolbar.h>
#include <qpe/resource.h>
#include <qpe/qpeapplication.h>
#include <qtopia/alarmserver.h>
#include <qtopia/qcopenvelope_qws.h>
#include <unistd.h> // for sleep
#else
#include <qmenubar.h>
#include <qtoolbar.h>
#include <qapplication.h>
//#include <resource.h>
#endif
#include <libkcal/calendarlocal.h>
#include <libkcal/todo.h>
#include <libkcal/phoneformat.h>
#include <libkdepim/ksyncprofile.h>
#include <libkdepim/phoneaccess.h>
#include <libkcal/kincidenceformatter.h>
#include <libkdepim/kpimglobalprefs.h>
#include "calendarview.h"
#include "koviewmanager.h"
#include "datenavigator.h"
#include "koagendaview.h"
#include "koagenda.h"
#include "kodialogmanager.h"
#include "kdialogbase.h"
#include "kapplication.h"
#include "kofilterview.h"
#include "kstandarddirs.h"
#include "koprefs.h"
#include "kfiledialog.h"
#include "koglobals.h"
#include "kglobal.h"
#include "klocale.h"
#include "kconfig.h"
#include "simplealarmclient.h"
#include "externalapphandler.h"
using namespace KCal;
#ifndef _WIN32_
#include <unistd.h>
#else
#ifdef _OL_IMPORT_
#include "koimportoldialog.h"
#endif
#endif
#include "mainwindow.h"
+
class KOex2phonePrefs : public QDialog
{
public:
KOex2phonePrefs( QWidget *parent=0, const char *name=0 ) :
QDialog( parent, name, true )
{
setCaption( i18n("Export to phone options") );
QVBoxLayout* lay = new QVBoxLayout( this );
lay->setSpacing( 3 );
lay->setMargin( 3 );
QLabel *lab;
lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) );
lab->setAlignment (AlignHCenter );
QHBox* temphb;
temphb = new QHBox( this );
new QLabel( i18n("I/O device: "), temphb );
mPhoneDevice = new QLineEdit( temphb);
lay->addWidget( temphb );
temphb = new QHBox( this );
new QLabel( i18n("Connection: "), temphb );
mPhoneConnection = new QLineEdit( temphb);
lay->addWidget( temphb );
temphb = new QHBox( this );
new QLabel( i18n("Model(opt.): "), temphb );
mPhoneModel = new QLineEdit( temphb);
lay->addWidget( temphb );
mWriteBackFuture= new QCheckBox( i18n("Write back events in future only"), this );
mWriteBackFuture->setChecked( true );
lay->addWidget( mWriteBackFuture );
temphb = new QHBox( this );
new QLabel( i18n("Max. weeks in future: ") , temphb );
mWriteBackFutureWeeks= new QSpinBox(1,104, 1, temphb);
mWriteBackFutureWeeks->setValue( 8 );
lay->addWidget( temphb );
lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ntodo/calendar data on phone!"), this ) );
lab->setAlignment (AlignHCenter );
QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this );
lay->addWidget( ok );
QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
lay->addWidget( cancel );
connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
resize( 220, 240 );
qApp->processEvents();
int dw = QApplication::desktop()->width();
int dh = QApplication::desktop()->height();
move( (dw-width())/2, (dh - height() )/2 );
}
public:
QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel;
QCheckBox* mWriteBackFuture;
QSpinBox* mWriteBackFutureWeeks;
};
int globalFlagBlockStartup;
MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
QMainWindow( parent, name )
{
#ifdef DESKTOP_VERSION
setFont( QFont("Arial"), 14 );
#endif
mClosed = false;
//QString confFile = KStandardDirs::appDir() + "config/korganizerrc";
QString confFile = locateLocal("config","korganizerrc");
QFileInfo finf ( confFile );
bool showWarning = !finf.exists();
setIcon(SmallIcon( "ko24" ) );
mBlockAtStartup = true;
mFlagKeyPressed = false;
+ setCaption("KOrganizer/Pi");
KOPrefs *p = KOPrefs::instance();
KPimGlobalPrefs::instance()->setGlobalConfig();
- if ( p->mHourSize > 18 )
- p->mHourSize = 18;
+ if ( p->mHourSize > 22 )
+ p->mHourSize = 22;
QMainWindow::ToolBarDock tbd;
if ( p->mToolBarHor ) {
if ( p->mToolBarUp )
tbd = Bottom;
else
tbd = Top;
}
else {
if ( p->mToolBarUp )
tbd = Right;
else
tbd = Left;
}
if ( KOPrefs::instance()->mUseAppColors )
QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
globalFlagBlockStartup = 1;
iconToolBar = new QPEToolBar( this );
addToolBar (iconToolBar , tbd );
mCalendarModifiedFlag = false;
-
- setCaption("KOrganizer/Pi");
QLabel* splash = new QLabel(i18n("KO/Pi is starting ... "), this );
splash->setAlignment ( AlignCenter );
setCentralWidget( splash );
#ifndef DESKTOP_VERSION
showMaximized();
#endif
//qDebug("Mainwidget x %d y %d w %d h %d", x(), y(), width(), height ());
setDefaultPreferences();
mCalendar = new CalendarLocal();
mView = new CalendarView( mCalendar, this,"mCalendar " );
mView->hide();
//mView->resize(splash->size() );
initActions();
mSyncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)mView, KSyncManager::KOPI, KOPrefs::instance(), syncMenu);
mSyncManager->setBlockSave(false);
mView->setSyncManager(mSyncManager);
#ifndef DESKTOP_VERSION
iconToolBar->show();
qApp->processEvents();
#endif
//qDebug("Splashwidget x %d y %d w %d h %d", splash-> x(), splash->y(), splash->width(),splash-> height ());
int vh = height() ;
int vw = width();
//qDebug("Toolbar hei %d ",iconToolBar->height() );
if ( iconToolBar->orientation () == Qt:: Horizontal ) {
vh -= iconToolBar->height();
} else {
vw -= iconToolBar->height();
}
//mView->setMaximumSize( splash->size() );
//mView->resize( splash->size() );
//qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ());
mView->readSettings();
bool newFile = false;
if( !QFile::exists( defaultFileName() ) ) {
QFileInfo finfo ( defaultFileName() );
QString oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/Applications/korganizer/mycalendar.ics");
qDebug("oldfile %s ", oldFile.latin1());
QString message = "You are starting KO/Pi for the\nfirst time after updating to a\nversion >= 1.9.1. The location of the\ndefault calendar file has changed.\nA mycalendar.ics file was detected\nat the old location.\nThis file will be loaded now\nand stored at the new location!\n(Config file location has changed, too!)\nPlease read menu Help-What's New!\n";
finfo.setFile( oldFile );
if (finfo.exists() ) {
KMessageBox::information( this, message);
mView->openCalendar( oldFile );
qApp->processEvents();
} else {
oldFile = QDir::convertSeparators( QDir::homeDirPath()+"/korganizer/mycalendar.ics");
finfo.setFile( oldFile );
if (finfo.exists() ) {
KMessageBox::information( this, message);
mView->openCalendar( oldFile );
qApp->processEvents();
}
}
mView->saveCalendar( defaultFileName() );
newFile = true;
}
QTime neededSaveTime = QDateTime::currentDateTime().time();
mView->openCalendar( defaultFileName() );
int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() );
qDebug("KO: Calendar loading time: %d ms",msNeeded );
if ( KPimGlobalPrefs::instance()->mPreferredLanguage != KOPrefs::instance()->mOldLoadedLanguage ) {
KOPrefs::instance()->setAllDefaults();
int count = mView->addCategories();
}
processIncidenceSelection( 0 );
connect( mView, SIGNAL( incidenceSelected( Incidence * ) ),
SLOT( processIncidenceSelection( Incidence * ) ) );
connect( mView, SIGNAL( modifiedChanged( bool ) ),
SLOT( slotModifiedChanged( bool ) ) );
connect( mView, SIGNAL( tempDisableBR(bool) ),
SLOT( disableBR(bool) ) );
connect( &mSaveTimer, SIGNAL( timeout() ), SLOT( save() ) );
mView->setModified( false );
mBlockAtStartup = false;
mView->setModified( false );
setCentralWidget( mView );
globalFlagBlockStartup = 0;
mView->show();
delete splash;
if ( newFile )
mView->updateConfig();
// qApp->processEvents();
//qDebug("MainView x %d y %d w %d h %d", mView->x(),mView-> y(), mView->width(), mView->height ());
//fillSyncMenu();
connect(mSyncManager , SIGNAL( save() ), this, SLOT( save() ) );
connect(mView , SIGNAL( save() ), this, SLOT( save() ) );
connect(mView , SIGNAL( saveStopTimer() ), this, SLOT( saveStopTimer() ) );
connect(mSyncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) );
connect(mSyncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) );
@@ -464,229 +464,235 @@ void MainWindow::recieve( const QCString& cmsg, const QByteArray& data )
}
if ( msg == "-showList" ) {
mView->viewManager()->showListView();
}
else if ( msg == "-showDay" ) {
mView->viewManager()->showDayView();
}
else if ( msg == "-showWWeek" ) {
mView->viewManager()->showWorkWeekView();
}
else if ( msg == "-ringSync" ) {
mSyncManager->multiSync( false );
}
else if ( msg == "-showWeek" ) {
mView->viewManager()->showWeekView();
}
else if ( msg == "-showTodo" ) {
mView->viewManager()->showTodoView();
}
else if ( msg == "-showJournal" ) {
mView->dateNavigator()->selectDates( 1 );
mView->dateNavigator()->selectToday();
mView->viewManager()->showJournalView();
}
else if ( msg == "-showKO" ) {
mView->viewManager()->showNextXView();
}
else if ( msg == "-showWNext" || msg == "nextView()" ) {
mView->viewManager()->showWhatsNextView();
}
else if ( msg == "-showNextXView" ) {
mView->viewManager()->showNextXView();
}
}
showMaximized();
raise();
}
QPixmap MainWindow::loadPixmap( QString name )
{
return SmallIcon( name );
}
void MainWindow::initActions()
{
//KOPrefs::instance()->mShowFullMenu
iconToolBar->clear();
KOPrefs *p = KOPrefs::instance();
//QPEMenuBar *menuBar1;// = new QPEMenuBar( iconToolBar );
QPopupMenu *viewMenu = new QPopupMenu( this );
QPopupMenu *actionMenu = new QPopupMenu( this );
QPopupMenu *importMenu = new QPopupMenu( this );
selectFilterMenu = new QPopupMenu( this );
selectFilterMenu->setCheckable( true );
syncMenu = new QPopupMenu( this );
configureAgendaMenu = new QPopupMenu( this );
configureToolBarMenu = new QPopupMenu( this );
QPopupMenu *helpMenu = new QPopupMenu( this );
if ( KOPrefs::instance()->mShowFullMenu ) {
QMenuBar *menuBar1;
menuBar1 = menuBar();
menuBar1->insertItem( i18n("File"), importMenu );
menuBar1->insertItem( i18n("View"), viewMenu );
menuBar1->insertItem( i18n("Actions"), actionMenu );
#ifdef DESKTOP_VERSION
menuBar1->insertItem( i18n("Synchronize"), syncMenu );
menuBar1->insertItem( i18n("AgendaSize"),configureAgendaMenu );
#else
menuBar1->insertItem( i18n("Sync"), syncMenu );
menuBar1->insertItem( i18n("Agenda"),configureAgendaMenu );
#endif
//menuBar1->insertItem( i18n("Toolbar"),configureToolBarMenu );
menuBar1->insertItem( i18n("Filter"),selectFilterMenu );
menuBar1->insertItem( i18n("Help"), helpMenu );
} else {
QPEMenuBar *menuBar1;
menuBar1 = new QPEMenuBar( iconToolBar );
QPopupMenu *menuBar = new QPopupMenu( this );
menuBar1->insertItem( i18n("ME"), menuBar);
menuBar->insertItem( i18n("File"), importMenu );
menuBar->insertItem( i18n("View"), viewMenu );
menuBar->insertItem( i18n("Actions"), actionMenu );
menuBar->insertItem( i18n("Synchronize"), syncMenu );
menuBar->insertItem( i18n("AgendaSize"),configureAgendaMenu );
menuBar->insertItem( i18n("Toolbar"),configureToolBarMenu );
menuBar->insertItem( i18n("Filter"),selectFilterMenu );
menuBar->insertItem( i18n("Help"), helpMenu );
//menuBar1->setMaximumWidth( menuBar1->sizeHint().width() );
menuBar1->setMaximumSize( menuBar1->sizeHint( ));
}
connect ( selectFilterMenu, SIGNAL( activated ( int ) ), this, SLOT (selectFilter( int ) ) );
connect ( selectFilterMenu, SIGNAL( aboutToShow() ), this, SLOT (fillFilterMenu() ) );
-
- menuBarWeek = new QPEMenuBar( iconToolBar );
- QPopupMenu * wpo = new QPopupMenu (this);
- QPopupMenu * all = new QPopupMenu (this);
- //wpo->insertItem( i18n("W#"), 0 );
- int first = 1;
- int i;
- for ( i = 1; i < 50; ++i ) {
- if ( !(i%10) ) {
- all->insertItem( i18n("Select week %1-%2" ).arg(first).arg( i-1) ,wpo );
- connect( wpo, SIGNAL( activated(int) ), SIGNAL( selectWeek ( int ) ) );
- first = i;
- wpo = new QPopupMenu (this);
+ QIconSet icon;
+ int pixWid = 22, pixHei = 22;
+ QString pathString = "";
+ if ( !p->mToolBarMiniIcons ) {
+ if ( QApplication::desktop()->width() < 480 ) {
+ pathString += "icons16/";
+ pixWid = 18; pixHei = 16;
}
- wpo->insertItem( QString::number(i), i );
- }
- for ( i = 50; i < 53; ++i ) {
- wpo->insertItem( QString::number(i), i);
+ } else {
+ pathString += "iconsmini/";
+ pixWid = 18; pixHei = 16;
+ }
+ mWeekBgColor = iconToolBar->backgroundColor();
+ mWeekPixmap.resize( pixWid , pixHei );
+ mWeekPixmap.fill( mWeekBgColor );
+ icon = mWeekPixmap;
+ mWeekAction = new QAction( i18n("Select week number"),icon, i18n("Select week number"), 0, this );
+ mWeekAction->addTo( iconToolBar );
+ mWeekFont = font();
+
+ int fontPoint = mWeekFont.pointSize();
+ QFontMetrics f( mWeekFont );
+ int fontWid = f.width( "30" );
+ while ( fontWid > pixWid ) {
+ --fontPoint;
+ mWeekFont.setPointSize( fontPoint );
+ QFontMetrics f( mWeekFont );
+ fontWid = f.width( "30" );
+ qDebug("dec-- ");
}
- all->insertItem( i18n("Select week %1-%2" ).arg(first).arg( i-1) ,wpo );
- connect( wpo, SIGNAL( activated(int) ), SIGNAL( selectWeek ( int ) ) );
- menuBarWeek->insertItem( "00",all,1);
- menuBarWeek->setMaximumSize( menuBarWeek->sizeHint( ));
+
+ connect( mWeekAction, SIGNAL( activated() ),
+ this, SLOT( weekAction() ) );
connect( this, SIGNAL( selectWeek ( int ) ), mView->dateNavigator(), SLOT( selectWeek ( int ) ) );
+
+ //#endif
// ******************
QAction *action;
- QIconSet icon;
// QPopupMenu *configureMenu= new QPopupMenu( menuBar );
configureToolBarMenu->setCheckable( true );
- QString pathString = "";
- if ( !p->mToolBarMiniIcons ) {
- if ( QApplication::desktop()->width() < 480 )
- pathString += "icons16/";
- } else
- pathString += "iconsmini/";
+
configureAgendaMenu->setCheckable( true );
int iii ;
for ( iii = 1;iii<= 10 ;++iii ){
configureAgendaMenu->insertItem(i18n("Size %1").arg(iii), (iii+1)*2 );
}
//configureMenu->insertItem( "AgendaSize",configureAgendaMenu );
connect( configureAgendaMenu, SIGNAL( aboutToShow()),
this, SLOT( showConfigureAgenda( ) ) );
icon = loadPixmap( pathString + "configure" );
action = new QAction( i18n("Configure"),icon, i18n("Configure..."), 0, this );
action->addTo( actionMenu );
connect( action, SIGNAL( activated() ),
mView, SLOT( edit_options() ) );
actionMenu->insertSeparator();
action = new QAction( i18n("Undo Delete"), i18n("Undo Delete..."), 0, this );
action->addTo( actionMenu );
connect( action, SIGNAL( activated() ),
mView, SLOT( undo_delete() ) );
actionMenu->insertSeparator();
icon = loadPixmap( pathString + "newevent" );
configureToolBarMenu->insertItem(i18n("Stretched TB"), 5 );
configureToolBarMenu->insertSeparator();
configureToolBarMenu->insertItem(icon, i18n("New Event..."), 10 );
QAction* ne_action = new QAction( i18n("New Event..."), icon, i18n("New Event..."), 0, this );
ne_action->addTo( actionMenu );
connect( ne_action, SIGNAL( activated() ),
mView, SLOT( newEvent() ) );
icon = loadPixmap( pathString + "newtodo" );
configureToolBarMenu->insertItem(icon, i18n("New Todo..."), 20 );
QAction* nt_action = new QAction( i18n("New Todo..."), icon, i18n("New Todo..."), 0, this );
nt_action->addTo( actionMenu );
connect( nt_action, SIGNAL( activated() ),
mView, SLOT( newTodo() ) );
icon = loadPixmap( pathString + "today" );
QAction* today_action = new QAction( i18n("Go to Today"), icon, i18n("Go to Today"), 0, this );
today_action->addTo( viewMenu );
connect( today_action, SIGNAL( activated() ),
mView, SLOT( goToday() ) );
viewMenu->insertSeparator();
icon = loadPixmap( pathString + "navi" );
action = new QAction( i18n("Toggle DateNavigator"), icon, i18n("Toggle DateNavigator"), 0, this );
action->addTo( viewMenu );
connect( action, SIGNAL( activated() ),
mView, SLOT( toggleDateNavigatorWidget() ) );
mToggleNav = action ;
icon = loadPixmap( pathString + "filter" );
action = new QAction( i18n("Toggle FilterView"), icon, i18n("Toggle FilterView"), 0, this );
action->addTo( viewMenu );
connect( action, SIGNAL( activated() ),
mView, SLOT( toggleFilter() ) );
mToggleFilter = action;
icon = loadPixmap( pathString + "allday" );
action = new QAction( i18n("Toggle Allday"), icon,i18n("Toggle Allday"), 0, this );
action->addTo( viewMenu );
connect( action, SIGNAL( activated() ),
mView, SLOT( toggleAllDaySize() ) );
mToggleAllday = action;
connect( mView->viewManager(), SIGNAL( signalFullScreen( bool ) ),
mToggleNav, SLOT( setEnabled ( bool ) ) );
connect( mView->viewManager(), SIGNAL( signalFullScreen( bool ) ),
mToggleFilter, SLOT( setEnabled ( bool ) ) );
connect( mView->viewManager(), SIGNAL( signalAgendaView( bool ) ),
mToggleAllday, SLOT( setEnabled ( bool ) ) );
viewMenu->insertSeparator();
icon = loadPixmap( pathString + "picker" );
action = new QAction( i18n("Date Picker"), icon, i18n("Date Picker"), 0, this );
action->addTo( viewMenu );
connect( action, SIGNAL( activated() ),
mView, SLOT( showDatePicker() ) );
action->addTo( iconToolBar );
viewMenu->insertSeparator();
icon = loadPixmap( pathString + "list" );
configureToolBarMenu->insertItem(icon, i18n("List View"), 30 );
QAction* showlist_action = new QAction( i18n("List View"), icon, i18n("List View"), 0, this );
showlist_action->addTo( viewMenu );
connect( showlist_action, SIGNAL( activated() ),
mView->viewManager(), SLOT( showListView() ) );
icon = loadPixmap( pathString + "day" );
configureToolBarMenu->insertItem(icon, i18n("Day View"), 40 );
QAction* day1_action = new QAction( i18n("Day View"), icon, i18n("Day View"), 0, this );
day1_action->addTo( viewMenu );
// action->addTo( toolBar );
connect( day1_action, SIGNAL( activated() ),
mView->viewManager(), SLOT( showDayView() ) );
@@ -1277,194 +1283,200 @@ void MainWindow::keyBindings()
i18n("<p><h3>In agenda view:</h3></p>\n") +
i18n("<p><b>up/down</b>: Scroll agenda view</p>\n")+
i18n("<p><b>ctrl+up/down</b>: Scroll small todo view</p>\n")+
i18n("<p><h3>In todo view:</h3></p>\n") +
i18n("<p><b>shift+U</b>: <b>U</b>nparent todo (make root todo)</p>\n")+
i18n("<p><b>shift+S</b>: Make <b>S</b>ubtodo (reparent todo)</p>\n")+
i18n("<p><b>shift+P</b>: Make new <b>P</b>arent for todo selected with shift+S</p>\n")+
i18n("<p><b>Q</b>: Toggle quick todo line edit.</p>\n")+
i18n("<p><b>I</b>: Show info of current item+one step down.</p>\n")+
i18n("<p><b>return</b>: Mark item as completed+one step down.</p>\n")+
i18n("<p><b>return+shift</b>: Mark item as not completed+one step down</p>\n")+
i18n("<p><h3>In list view:</h3></p>\n") +
i18n("<p><b>I</b>: Show info of current item+one step down.</p>\n")+
i18n("<p><b>return</b>: Select item+one step down</p>\n")+
i18n("<p><b>return+shift</b>: Deselect item+one step down</p>\n")+
i18n("<p><b>up/down</b>: Next/prev item</p>\n")+
i18n("<p><b>ctrl+up/down</b>: Goto up/down by 20% of items</p>\n")+
i18n("<p><b>shift+up/down</b>: Goto first/last item</p>\n")+
i18n("<p><h3>In event/todo viewer:</h3></p>\n") +
i18n("<p><b>I,C</b>: Close dialog.</p>\n")+
i18n("<p><b>A</b>: Show agenda view.</p>\n")+
i18n("<p><b>E</b>: Edit item</p>\n") +
i18n("<p><h2>KO/Pi icon colors:</h2></p>\n") +
i18n("<p><b>(for square icons in agenda and month view)</b></p>\n") +
i18n("<p><b>Cross</b>: Item cancelled.([c] in Whats'Next view)</p>\n")+
i18n("<p><b>Red</b>: Alarm set.([a] in Whats'Next view)</p>\n")+
i18n("<p><b>Blue</b>: Recurrent event.([r] in Whats'Next view)</p>\n")+
i18n("<p><b>Dark green</b>: Information(description) available.([i] in WN view)</p>\n")+
i18n("<p><b>Black</b>: Event/todo with attendees. You are the organizer!</p>\n")+
i18n("<p><b>Dark yellow</b>: Event/todo with attendees.</p>\n") +
i18n("<p><b>White</b>: Item readonly</p>\n");
displayText( text, cap);
}
void MainWindow::aboutAutoSaving()
{
QString text = i18n("After changing something, the data is\nautomatically saved to the file\n~/kdepim/apps/korganizer/mycalendar.ics\nafter (configurable) three minutes.\nFor safety reasons there is one autosaving\nafter 10 minutes (of idle time) again. The \ndata is saved automatically when closing KO/Pi\nYou can create a backup file \nwith: File - Save Calendar Backup\n");
KApplication::showText( i18n("Auto Saving in KOrganizer/Pi"), text);
}
void MainWindow::aboutKnownBugs()
{
QMessageBox* msg;
msg = new QMessageBox( i18n("Known Problems in KOrganizer/Pi"),
i18n("1) Importing *.vcs or *.ics files from\nother applications may not work properly,\nif there are events with properties\nKO/Pi does not support.\n")+
i18n("2) Audio alarm daemon\nfor Zaurus is available!\nas an additional small application\n")+
i18n("\nPlease report unexpected behaviour to\nlutz@pi-sync.net\n") +
i18n("\nor report them in the bugtracker on\n") +
i18n("\nhttp://sourceforge.net/projects/kdepimpi\n"),
QMessageBox::NoIcon,
QMessageBox::Ok,
QMessageBox::NoButton,
QMessageBox::NoButton);
msg->exec();
delete msg;
}
QString MainWindow::defaultFileName()
{
return locateLocal( "data", "korganizer/mycalendar.ics" );
}
QString MainWindow::syncFileName()
{
#ifdef DESKTOP_VERSION
return locateLocal( "tmp", "synccalendar.ics" );
#else
return QString( "/tmp/synccalendar.ics" );
#endif
}
void MainWindow::updateWeek(QDate seda)
{
int weekNum = 0;
QDate d = QDate ( seda.year(), 1,1);
seda = seda.addDays( 1-seda.dayOfWeek() );//we are on monday
if ( seda.addDays(6).year() != seda.year() ) {
if ( seda.year() != d.year() ) {
if ( d.dayOfWeek() > 4 )
d = QDate ( seda.year(), 1,1);
else
weekNum = 1;
} else {
QDate dd( seda.year()+1, 1,1);
if ( dd.dayOfWeek() <= 4 )
weekNum = 1;
}
}
if ( weekNum == 0 ){
int dow = d.dayOfWeek();
if ( dow <= 4 )
d = d.addDays( 1-dow );
else // 5,6,7
d = d.addDays( 8-dow );
// we have the first week of the year.we are on monday
weekNum = d.daysTo( seda ) / 7 +1;
}
- //qDebug("weeknum %s ", QString::number( weekNum).latin1());
- menuBarWeek-> changeItem(1, QString::number( weekNum) );
+
+ mWeekPixmap.fill( mWeekBgColor );
+ QPainter p ( &mWeekPixmap );
+ p.setFont( mWeekFont );
+ p.drawText( 0,0,mWeekPixmap.width(), mWeekPixmap.height(),AlignCenter, QString::number( weekNum) );
+ p.end();
+ QIconSet icon3 ( mWeekPixmap );
+ mWeekAction->setIconSet ( icon3 );
}
void MainWindow::updateWeekNum(const DateList &selectedDates)
{
updateWeek( selectedDates.first() );
}
void MainWindow::processIncidenceSelection( Incidence *incidence )
{
if ( !incidence ) {
enableIncidenceActions( false );
mNewSubTodoAction->setEnabled( false );
setCaptionToDates();
return;
}
//KGlobal::locale()->formatDateTime(nextA, true);
QString startString = "";
if ( incidence->type() != "Todo" ) {
if ( incidence->dtStart().date() < incidence->dtEnd().date() ) {
if ( incidence->doesFloat() ) {
startString += ": "+incidence->dtStartDateStr( true );
startString += " --- "+((Event*)incidence)->dtEndDateStr( true );
} else {
startString = ": "+incidence->dtStartStr(true);
startString += " --- "+((Event*)incidence)->dtEndStr(true);
}
} else {
if ( incidence->dtStart().time() != incidence->dtEnd().time() )
startString = ": "+KGlobal::locale()->formatTime(incidence->dtStart().time())+
"-"+KGlobal::locale()->formatTime(incidence->dtEnd().time());
if ( incidence->categories().contains( i18n("Birthday") ) || incidence->categories().contains( i18n("Anniversary") ) ) {
bool ok;
QDateTime noc = incidence->getNextOccurence( mView->startDate().addDays(-1), &ok );
if ( ok ) {
int years = noc.date().year() - incidence->dtStart().date().year();
startString += i18n(" (%1 y.)"). arg( years );
}
}
else
startString +=" "+KGlobal::locale()->formatDate( incidence->dtStart().date(), true);
}
}
else
startString = i18n(": (Prio ") +QString::number( (( KCal::Todo*)incidence)->priority() ) +") "+QString::number( (( KCal::Todo*)incidence)->percentComplete() ) +i18n("\% completed");
if ( !incidence->location().isEmpty() )
startString += " (" +incidence->location()+")";
setCaption( incidence->summary()+startString);
enableIncidenceActions( true );
if ( incidence->type() == "Event" ) {
mShowAction->setText( i18n("Show Event...") );
mEditAction->setText( i18n("Edit Event...") );
mDeleteAction->setText( i18n("Delete Event...") );
mNewSubTodoAction->setEnabled( false );
} else if ( incidence->type() == "Todo" ) {
mShowAction->setText( i18n("Show Todo...") );
mEditAction->setText( i18n("Edit Todo...") );
mDeleteAction->setText( i18n("Delete Todo...") );
mNewSubTodoAction->setEnabled( true );
} else {
mShowAction->setText( i18n("Show...") );
mShowAction->setText( i18n("Edit...") );
mShowAction->setText( i18n("Delete...") );
mNewSubTodoAction->setEnabled( false );
}
}
void MainWindow::enableIncidenceActions( bool enabled )
{
mShowAction->setEnabled( enabled );
mEditAction->setEnabled( enabled );
mDeleteAction->setEnabled( enabled );
mCloneAction->setEnabled( enabled );
mMoveAction->setEnabled( enabled );
mBeamAction->setEnabled( enabled );
mCancelAction->setEnabled( enabled );
}
void MainWindow::importOL()
{
#ifdef _OL_IMPORT_
KOImportOLdialog *id = new KOImportOLdialog("Import from OL - select folder!" , mView->calendar(),this );
id->exec();
delete id;
@@ -1626,193 +1638,193 @@ void MainWindow::keyPressEvent ( QKeyEvent * e )
case Qt::Key_2:
case Qt::Key_3:
case Qt::Key_4:
case Qt::Key_5:
case Qt::Key_6:
case Qt::Key_7:
case Qt::Key_8:
case Qt::Key_9:
pro = e->key()-48;
if ( pro == 0 )
pro = 10;
if ( e->state() == Qt::ControlButton)
pro += 10;
break;
case Qt::Key_M:
mView->viewManager()->showMonthView();
showSelectedDates = true;
break;
case Qt::Key_Insert:
mView->newEvent();
break;
case Qt::Key_S :
if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton)
mView->newSubTodo();
else
mView->dialogManager()->showSearchDialog();
break;
case Qt::Key_Y :
case Qt::Key_Z :
mView->viewManager()->showWorkWeekView();
showSelectedDates = true;
break;
case Qt::Key_U :
mView->viewManager()->showWeekView();
showSelectedDates = true;
break;
case Qt::Key_H :
keyBindings();
break;
case Qt::Key_W:
mView->viewManager()->showWhatsNextView();
break;
case Qt::Key_L:
mView->viewManager()->showListView();
break;
case Qt::Key_N:
mView->viewManager()->showNextXView();
showSelectedDates = true;
break;
case Qt::Key_V:
mView->viewManager()->showTodoView();
break;
case Qt::Key_C:
mView->viewManager()->agendaView()->setStartHour( QTime::currentTime ().hour() );
break;
case Qt::Key_P:
mView->showDatePicker( );
break;
case Qt::Key_F:
if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
mView->editFilters();
else
mView->toggleFilter();
break;
case Qt::Key_X:
mView->toggleDateNavigatorWidget();
break;
case Qt::Key_Space:
mView->toggleExpand();
break;
case Qt::Key_A:
mView->toggleAllDaySize();
break;
case Qt::Key_T:
if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
mView->newTodo();
else {
mView->goToday();
showSelectedDates = true;
}
break;
case Qt::Key_J:
mView->viewManager()->showJournalView();
break;
case Qt::Key_B:
mView->editIncidenceDescription();;
break;
// case Qt::Key_Return:
case Qt::Key_E:
if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
mView->newEvent();
else
mView->editIncidence();
break;
case Qt::Key_Plus:
size = p->mHourSize +2;
- if ( size <= 18 )
+ if ( size <= 22 )
configureAgenda( size );
break;
case Qt::Key_Minus:
size = p->mHourSize - 2;
if ( size >= 4 )
configureAgenda( size );
break;
default:
e->ignore();
}
if ( pro > 0 ) {
mView->selectFilter( pro-1 );
}
if ( showSelectedDates ) {
;// setCaptionToDates();
}
}
void MainWindow::fillFilterMenu()
{
selectFilterMenu->clear();
bool disable = false;
selectFilterMenu->insertItem(i18n ( "Edit Filters" ), 0 );
selectFilterMenu->insertSeparator();
if ( mView->filterView()->filtersEnabled() ) {
selectFilterMenu->insertItem(i18n ( "Turn filter off" ), 1 );
}
else {
selectFilterMenu->insertItem(i18n ( "Turn filter on" ), 1 );
disable = true;
}
selectFilterMenu->insertSeparator();
QPtrList<CalFilter> fili = mView->filters();
CalFilter *curfilter = mView->filterView()->selectedFilter();
CalFilter *filter = fili.first();
int iii = 2;
while(filter) {
selectFilterMenu->insertItem( filter->name(), iii );
if ( filter == curfilter)
selectFilterMenu->setItemChecked( iii, true );
if ( disable )
selectFilterMenu->setItemEnabled( iii, false );
filter = fili.next();
++iii;
}
}
void MainWindow::selectFilter( int fil )
{
if ( fil == 0 ) {
mView->editFilters( );
} else if ( fil == 1 ){
mView->toggleFilerEnabled( );
} else {
mView->selectFilter( fil-2 );
}
}
void MainWindow::configureToolBar( int item )
{
configureToolBarMenu->setItemChecked( item, !configureToolBarMenu-> isItemChecked ( item ) );
KOPrefs *p = KOPrefs::instance();
p-> mShowIconStretch= configureToolBarMenu->isItemChecked( 5 );
p-> mShowIconNewEvent= configureToolBarMenu->isItemChecked( 10 );
p->mShowIconNewTodo = configureToolBarMenu->isItemChecked( 20 );
p-> mShowIconSearch= configureToolBarMenu->isItemChecked( 120 );
p-> mShowIconList= configureToolBarMenu->isItemChecked( 30 );
p-> mShowIconDay1= configureToolBarMenu->isItemChecked( 40 );
p-> mShowIconDay5= configureToolBarMenu->isItemChecked( 50 );
p-> mShowIconDay7= configureToolBarMenu->isItemChecked( 60 );
p-> mShowIconMonth= configureToolBarMenu->isItemChecked( 70 );
p-> mShowIconTodoview= configureToolBarMenu->isItemChecked( 80 );
p-> mShowIconBackFast= configureToolBarMenu->isItemChecked( 200 );
p-> mShowIconBack = configureToolBarMenu->isItemChecked( 210 );
p-> mShowIconToday= configureToolBarMenu->isItemChecked( 130 );
p-> mShowIconForward= configureToolBarMenu->isItemChecked( 220 );
p-> mShowIconForwardFast= configureToolBarMenu->isItemChecked( 230 );
p-> mShowIconNextDays= configureToolBarMenu->isItemChecked( 100 );
p-> mShowIconNext= configureToolBarMenu->isItemChecked( 110 );
p-> mShowIconJournal= configureToolBarMenu->isItemChecked( 90 );
p-> mShowIconWhatsThis= configureToolBarMenu->isItemChecked( 300 );
// initActions();
}
void MainWindow::setCaptionToDates()
{
QString selDates;
selDates = KGlobal::locale()->formatDate(mView->startDate(), true);
if (mView->startDate() < mView->endDate() )
selDates += " - " + KGlobal::locale()->formatDate(mView->endDate(), true);
else {
QString addString;
if ( mView->startDate() == QDateTime::currentDateTime().date() )
addString = i18n("Today");
@@ -1918,96 +1930,120 @@ void MainWindow::importFile( QString fn, bool quick )
int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
mess );
return;
}
int result = 0;
if ( !quick ) {
mess = i18n( "Import file \n...%1\nfrom:\n%2\nDuplicated entries\nwill not be imported!\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
result = QMessageBox::warning( this, "KO/Pi: Warning!",
mess,
"Import", "Cancel", 0,
0, 1 );
}
if ( result == 0 ) {
if ( mView->openCalendar( fn, true )) {
KOPrefs::instance()->mLastImportFile = fn;
setCaption(i18n("Imported file successfully"));
} else {
setCaption(i18n("Error importing file"));
}
}
}
void MainWindow::importIcal()
{
QString fn =KOPrefs::instance()->mLastImportFile;
fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this );
if ( fn == "" )
return;
importFile( fn, true );
}
void MainWindow::exportVCalendar()
{
QString fn = KOPrefs::instance()->mLastVcalFile;
fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this );
if ( fn == "" )
return;
QFileInfo info;
info.setFile( fn );
QString mes;
bool createbup = true;
if ( info. exists() ) {
mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) );
int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
i18n("Overwrite!"), i18n("Cancel"), 0,
0, 1 );
if ( result != 0 ) {
createbup = false;
}
}
if ( createbup ) {
if ( mView->exportVCalendar( fn ) ) {
KOPrefs::instance()->mLastVcalFile = fn;
if ( fn.length() > 20 )
mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ;
else
mes = i18n("KO/Pi:Exported to %1").arg(fn );
setCaption(mes);
}
}
}
void MainWindow::syncFileRequest()
{
if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) {
mSyncManager->slotSyncMenu( 999 );
}
save();
}
void MainWindow::getFile( bool success )
{
if ( ! success ) {
setCaption( i18n("Error receiving file. Nothing changed!") );
return;
}
mView->openCalendar( defaultFileName() );
if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) {
mSyncManager->slotSyncMenu( 999 );
}
setCaption( i18n("Pi-Sync successful!") );
}
void MainWindow::printSel( )
{
mView->viewManager()->agendaView()->agenda()->printSelection();
}
void MainWindow::printCal()
{
mView->print();//mCp->showDialog();
}
+
+#include "libkdepim/kdatepicker.h"
+#include <kdatetbl.h>
+void MainWindow::weekAction()
+{
+ int month;
+ KPopupFrame* popup = new KPopupFrame(this);
+ int size = 12;
+ if ( QApplication::desktop()->width() >= 480 )
+ size = 18;
+ KDateInternalWeekPicker* picker = new KDateInternalWeekPicker(size, popup);
+ // -----
+ picker->resize(picker->sizeHint());
+ popup->setMainWidget(picker);
+ picker->setFocus();
+ connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
+ if(popup->exec(iconToolBar->mapToGlobal(QPoint(0, iconToolBar->height()))))
+ {
+ month = picker->getResult();
+ emit selectWeek ( month );
+ //qDebug("weekSelected %d ", month);
+ }
+ delete popup;
+}
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h
index 076ab94..5b9f903 100644
--- a/korganizer/mainwindow.h
+++ b/korganizer/mainwindow.h
@@ -1,147 +1,158 @@
#ifndef KORGE_MAINWINDOW_H
#define KORGE_MAINWINDOW_H
#include <qmainwindow.h>
#include <qtimer.h>
#include <qdict.h>
#include <qfile.h>
+#include <qmenubar.h>
#include <qtextstream.h>
#include <qregexp.h>
#include <libkcal/incidence.h>
#include "simplealarmclient.h"
#include <ksyncmanager.h>
#ifndef DESKTOP_VERSION
#include <qcopchannel_qws.h>
#endif
class QAction;
class CalendarView;
class KSyncProfile;
#ifdef DESKTOP_VERSION
#define QPEToolBar QToolBar
#define QPEMenuBar QMenuBar
#endif
class QPEToolBar;
-class QPEMenuBar;
namespace KCal {
class CalendarLocal;
}
+class KOMenuBar : public QMenuBar
+{
+ public:
+ KOMenuBar( QWidget *parent=0 ): QMenuBar (parent ) {;}
+ QSize sizeHint () const{ qDebug("sizejint ");return QSize ( 40,25 );}
+};
+
using namespace KCal;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow( QWidget *parent = 0, const char *name = 0, QString command = "");
~MainWindow();
bool beamReceiveEnabled();
static QString defaultFileName();
static QString syncFileName();
static QString resourcePath();
public slots:
void updateWeekNum(const KCal::DateList &);
void updateWeek(QDate);
virtual void showMaximized ();
void configureAgenda( int );
void recieve( const QCString& msg, const QByteArray& data );
protected slots:
void setCaptionToDates();
+ void weekAction();
void about();
void licence();
void faq();
void usertrans();
void features();
void synchowto();
void kdesynchowto();
void multisynchowto();
void whatsNew();
void keyBindings();
void aboutAutoSaving();;
void aboutKnownBugs();
void processIncidenceSelection( Incidence * );
void importQtopia();
void importBday();
void importOL();
void importIcal();
void importFile( QString, bool );
void quickImportIcal();
void slotModifiedChanged( bool );
void save();
void saveStopTimer();
void configureToolBar( int );
void printSel();
void printCal();
void saveCalendar();
void loadCalendar();
void exportVCalendar();
void fillFilterMenu();
void selectFilter( int );
void exportToPhone( int );
void toggleBeamReceive();
void disableBR(bool);
signals:
void selectWeek ( int );
private slots:
void showConfigureAgenda();
void getFile( bool );
void syncFileRequest();
protected:
void displayText( QString, QString);
void enableIncidenceActions( bool );
private:
bool mBRdisabled;
#ifndef DESKTOP_VERSION
QCopChannel* infrared;
#endif
QAction* brAction;
KSyncManager* mSyncManager;
bool mClosed;
void saveOnClose();
bool mFlagKeyPressed;
bool mBlockAtStartup;
QPEToolBar *iconToolBar;
void initActions();
void setDefaultPreferences();
void keyPressEvent ( QKeyEvent * ) ;
void keyReleaseEvent ( QKeyEvent * ) ;
QPopupMenu *configureToolBarMenu;
QPopupMenu *selectFilterMenu;
QPopupMenu *configureAgendaMenu, *syncMenu;
CalendarLocal *mCalendar;
CalendarView *mView;
QAction *mNewSubTodoAction;
- QPEMenuBar *menuBarWeek;
+ QAction *mWeekAction;
+ QFont mWeekFont;
+ QPixmap mWeekPixmap;
+ QColor mWeekBgColor;
QAction *mShowAction;
QAction *mEditAction;
QAction *mDeleteAction;
QAction *mCloneAction;
QAction *mMoveAction;
QAction *mBeamAction;
QAction *mCancelAction;
QAction *mToggleNav;
QAction *mToggleFilter;
QAction *mToggleAllday;
void closeEvent( QCloseEvent* ce );
SimpleAlarmClient mAlarmClient;
QTimer mSaveTimer;
//bool mBlockSaveFlag;
bool mCalendarModifiedFlag;
QPixmap loadPixmap( QString );
};
#endif
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp
index 508ce31..fce0e5a 100644
--- a/microkde/kdatetbl.cpp
+++ b/microkde/kdatetbl.cpp
@@ -1,750 +1,915 @@
/* -*- C++ -*-
This file is part of the KDE libraries
Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
- (C) 1998-2001 Mirko Boehm (mirko@kde.org)
+ (C) 1998-2001 Mirko Boehm (mirko@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.
*/
/////////////////// KDateTable widget class //////////////////////
//
// Copyright (C) 1997 Tim D. Gilman
// (C) 1998-2001 Mirko Boehm
// Written using Qt (http://www.troll.no) for the
// KDE project (http://www.kde.org)
//
// This is a support class for the KDatePicker class. It just
// draws the calender table without titles, but could theoretically
// be used as a standalone.
//
// When a date is selected by the user, it emits a signal:
// dateSelected(QDate)
#include <kglobal.h>
#include <kglobalsettings.h>
#include <kapplication.h>
#include <klocale.h>
#include <kdebug.h>
#include <knotifyclient.h>
#include "kdatetbl.h"
#include <qdatetime.h>
#include <qstring.h>
#include <qpen.h>
#include <qpainter.h>
#include <qdialog.h>
#include <assert.h>
#include <qapplication.h>
KDateValidator::KDateValidator(QWidget* parent, const char* name)
: QValidator(parent, name)
{
}
QValidator::State
KDateValidator::validate(QString& text, int&) const
{
- QDate temp;
- // ----- everything is tested in date():
- return date(text, temp);
+ QDate temp;
+ // ----- everything is tested in date():
+ return date(text, temp);
}
QValidator::State
KDateValidator::date(const QString& text, QDate& d) const
{
- QDate tmp = KGlobal::locale()->readDate(text);
- if (!tmp.isNull())
- {
- d = tmp;
- return Acceptable;
- } else
- return Valid;
+ QDate tmp = KGlobal::locale()->readDate(text);
+ if (!tmp.isNull())
+ {
+ d = tmp;
+ return Acceptable;
+ } else
+ return Valid;
}
void
KDateValidator::fixup( QString& ) const
{
}
KDateTable::KDateTable(QWidget *parent, QDate date_, const char* name, WFlags f)
- : QGridView(parent, name, f)
+ : QGridView(parent, name, f)
{
- setFontSize(10);
- if(!date_.isValid())
- {
- date_=QDate::currentDate();
- }
- setFocusPolicy( QWidget::StrongFocus );
- setNumRows(7); // 6 weeks max + headline
- setNumCols(7); // 7 days a week
- setHScrollBarMode(AlwaysOff);
- setVScrollBarMode(AlwaysOff);
- viewport()->setBackgroundColor(QColor(220,245,255));
+ setFontSize(10);
+ if(!date_.isValid())
+ {
+ date_=QDate::currentDate();
+ }
+ setFocusPolicy( QWidget::StrongFocus );
+ setNumRows(7); // 6 weeks max + headline
+ setNumCols(7); // 7 days a week
+ setHScrollBarMode(AlwaysOff);
+ setVScrollBarMode(AlwaysOff);
+ viewport()->setBackgroundColor(QColor(220,245,255));
#if 0
- viewport()->setEraseColor(lightGray);
+ viewport()->setEraseColor(lightGray);
#endif
- mMarkCurrent = false;
- setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth
+ mMarkCurrent = false;
+ setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth
}
void
KDateTable::paintCell(QPainter *painter, int row, int col)
{
- QRect rect;
- QString text;
- QPen pen;
- int w=cellWidth();
- int h=cellHeight();
- int pos;
- QBrush brushBlue(blue);
- QBrush brushLightblue(QColor(220,245,255));
- QFont font=KGlobalSettings::generalFont();
- // -----
- font.setPointSize(fontsize);
- if(row==0)
- { // we are drawing the headline
- font.setBold(true);
- painter->setFont(font);
- bool normalday = true;
- QString daystr;
- if (KGlobal::locale()->weekStartsMonday())
- {
- daystr = KGlobal::locale()->weekDayName(col+1, true);
- if (col == 5 || col == 6)
- normalday = false;
- } else {
- daystr = KGlobal::locale()->weekDayName(col==0? 7 : col, true);
- if (col == 0 || col == 6)
- normalday = false;
- }
- if (!normalday)
- {
- painter->setPen(QColor(220,245,255));
- painter->setBrush(brushLightblue);
- painter->drawRect(0, 0, w, h);
- painter->setPen(blue);
- } else {
- painter->setPen(blue);
- painter->setBrush(brushBlue);
- painter->drawRect(0, 0, w, h);
- painter->setPen(white);
- }
- painter->drawText(0, 0, w, h-1, AlignCenter,
- daystr, -1, &rect);
- painter->setPen(black);
- painter->moveTo(0, h-1);
- painter->lineTo(w-1, h-1);
- // ----- draw the weekday:
- } else {
- painter->setFont(font);
- pos=7*(row-1)+col;
- if (KGlobal::locale()->weekStartsMonday())
- pos++;
- if(pos<firstday || (firstday+numdays<=pos))
- { // we are either
- // ° painting a day of the previous month or
- // ° painting a day of the following month
- if(pos<firstday)
- { // previous month
- text.setNum(numDaysPrevMonth+pos-firstday+1);
- } else { // following month
- text.setNum(pos-firstday-numdays+1);
+ QRect rect;
+ QString text;
+ QPen pen;
+ int w=cellWidth();
+ int h=cellHeight();
+ int pos;
+ QBrush brushBlue(blue);
+ QBrush brushLightblue(QColor(220,245,255));
+ QFont font=KGlobalSettings::generalFont();
+ // -----
+ font.setPointSize(fontsize);
+ if(row==0)
+ { // we are drawing the headline
+ font.setBold(true);
+ painter->setFont(font);
+ bool normalday = true;
+ QString daystr;
+ if (KGlobal::locale()->weekStartsMonday())
+ {
+ daystr = KGlobal::locale()->weekDayName(col+1, true);
+ if (col == 5 || col == 6)
+ normalday = false;
+ } else {
+ daystr = KGlobal::locale()->weekDayName(col==0? 7 : col, true);
+ if (col == 0 || col == 6)
+ normalday = false;
}
- painter->setPen(gray);
- } else { // paint a day of the current month
- text.setNum(pos-firstday+1);
- painter->setPen(black);
+ if (!normalday)
+ {
+ painter->setPen(QColor(220,245,255));
+ painter->setBrush(brushLightblue);
+ painter->drawRect(0, 0, w, h);
+ painter->setPen(blue);
+ } else {
+ painter->setPen(blue);
+ painter->setBrush(brushBlue);
+ painter->drawRect(0, 0, w, h);
+ painter->setPen(white);
+ }
+ painter->drawText(0, 0, w, h-1, AlignCenter,
+ daystr, -1, &rect);
+ painter->setPen(black);
+ painter->moveTo(0, h-1);
+ painter->lineTo(w-1, h-1);
+ // ----- draw the weekday:
+ } else {
+ painter->setFont(font);
+ pos=7*(row-1)+col;
+ if (KGlobal::locale()->weekStartsMonday())
+ pos++;
+ if(pos<firstday || (firstday+numdays<=pos))
+ { // we are either
+ // ° painting a day of the previous month or
+ // ° painting a day of the following month
+ if(pos<firstday)
+ { // previous month
+ text.setNum(numDaysPrevMonth+pos-firstday+1);
+ } else { // following month
+ text.setNum(pos-firstday-numdays+1);
+ }
+ painter->setPen(gray);
+ } else { // paint a day of the current month
+ text.setNum(pos-firstday+1);
+ painter->setPen(black);
}
- pen=painter->pen();
- if(firstday+date.day()-1==pos)
- {
- if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
- painter->setPen(green);
- else
- painter->setPen(red);
- if(hasFocus())
- {
- painter->setBrush(darkRed);
- pen=white;
+ pen=painter->pen();
+ if(firstday+date.day()-1==pos)
+ {
+ if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
+ painter->setPen(green);
+ else
+ painter->setPen(red);
+ if(hasFocus())
+ {
+ painter->setBrush(darkRed);
+ pen=white;
+ } else {
+ painter->setBrush(darkGray);
+ pen=white;
+ }
} else {
- painter->setBrush(darkGray);
- pen=white;
+ if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
+ {
+ painter->setPen(green);
+ painter->setBrush(darkGreen);
+ pen=white;
+ } else {
+ painter->setBrush(QColor(220,245,255));
+ painter->setPen(QColor(220,245,255));
}
- } else {
- if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
- {
- painter->setPen(green);
- painter->setBrush(darkGreen);
- pen=white;
- } else {
- painter->setBrush(QColor(220,245,255));
- painter->setPen(QColor(220,245,255));
- }
- }
- painter->drawRect(0, 0, w, h);
- painter->setPen(pen);
- painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect);
+ }
+ painter->drawRect(0, 0, w, h);
+ painter->setPen(pen);
+ painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect);
}
- if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width());
- if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height());
+ if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width());
+ if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height());
}
void
KDateTable::keyPressEvent( QKeyEvent *e )
{
/*
// not working properly
if ( e->key() == Qt::Key_Prior ) {
- if ( date.month() == 1 ) {
- KNotifyClient::beep();
- return;
- }
- int day = date.day();
- if ( day > 27 )
- while ( !QDate::isValid( date.year(), date.month()-1, day ) )
- day--;
- setDate(QDate(date.year(), date.month()-1, day));
- return;
+ if ( date.month() == 1 ) {
+ KNotifyClient::beep();
+ return;
+ }
+ int day = date.day();
+ if ( day > 27 )
+ while ( !QDate::isValid( date.year(), date.month()-1, day ) )
+ day--;
+ setDate(QDate(date.year(), date.month()-1, day));
+ return;
}
if ( e->key() == Qt::Key_Next ) {
- if ( date.month() == 12 ) {
- KNotifyClient::beep();
- return;
- }
- int day = date.day();
- if ( day > 27 )
- while ( !QDate::isValid( date.year(), date.month()+1, day ) )
- day--;
- setDate(QDate(date.year(), date.month()+1, day));
- return;
+ if ( date.month() == 12 ) {
+ KNotifyClient::beep();
+ return;
+ }
+ int day = date.day();
+ if ( day > 27 )
+ while ( !QDate::isValid( date.year(), date.month()+1, day ) )
+ day--;
+ setDate(QDate(date.year(), date.month()+1, day));
+ return;
}
*/
int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0;
int temp=firstday+date.day()-dayoff;
int pos = temp;
bool irgnore = true;
if ( e->state() != Qt::ControlButton ) {
- if ( e->key() == Qt::Key_Up ) {
- pos -= 7;
- irgnore = false;
- }
- if ( e->key() == Qt::Key_Down ) {
- pos += 7;
- irgnore = false;
- }
- if ( e->key() == Qt::Key_Left ) {
- pos--;
- irgnore = false;
- }
- if ( e->key() == Qt::Key_Right ) {
- pos++;
- irgnore = false;
- }
+ if ( e->key() == Qt::Key_Up ) {
+ pos -= 7;
+ irgnore = false;
+ }
+ if ( e->key() == Qt::Key_Down ) {
+ pos += 7;
+ irgnore = false;
+ }
+ if ( e->key() == Qt::Key_Left ) {
+ pos--;
+ irgnore = false;
+ }
+ if ( e->key() == Qt::Key_Right ) {
+ pos++;
+ irgnore = false;
+ }
}
if ( irgnore )
e->ignore();
if(pos+dayoff<=firstday)
- { // this day is in the previous month
- KNotifyClient::beep();
- return;
- }
+ { // this day is in the previous month
+ KNotifyClient::beep();
+ return;
+ }
if(firstday+numdays<pos+dayoff)
- { // this date is in the next month
- KNotifyClient::beep(i18n( "Month not long enough" ));
- return;
- }
+ { // this date is in the next month
+ KNotifyClient::beep(i18n( "Month not long enough" ));
+ return;
+ }
if ( pos == temp )
return;
setDate(QDate(date.year(), date.month(), pos-firstday+dayoff));
updateCell(temp/7+1, temp%7); // Update the previously selected cell
updateCell(pos/7+1, pos%7); // Update the selected cell
assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid());
}
void
KDateTable::viewportResizeEvent(QResizeEvent * e)
{
- QGridView::viewportResizeEvent(e);
+ QGridView::viewportResizeEvent(e);
- setCellWidth(viewport()->width()/7);
- setCellHeight(viewport()->height()/7);
+ setCellWidth(viewport()->width()/7);
+ setCellHeight(viewport()->height()/7);
}
void
KDateTable::setFontSize(int size)
{
- int count;
- QRect rect;
- // ----- store rectangles:
- fontsize=size;
- QFont font = KGlobalSettings::generalFont();
- font.setPointSize(fontsize);
- font.setBold( true );
- QFontMetrics metrics(font);
-
- // ----- find largest day name:
- maxCell.setWidth(0);
- maxCell.setHeight(0);
- for(count=0; count<7; ++count)
- {
- rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true));
- maxCell.setWidth(QMAX(maxCell.width(), rect.width()));
- maxCell.setHeight(QMAX(maxCell.height(), rect.height()));
- }
- // ----- compare with a real wide number and add some space:
- rect=metrics.boundingRect(QString::fromLatin1("88"));
- maxCell.setWidth(QMAX(maxCell.width()+2, rect.width()));
- maxCell.setHeight(QMAX(maxCell.height()+4, rect.height()));
- if ( maxCell.width() * 1000 / maxCell.height() > 1900 )
- maxCell.setHeight(maxCell.width() * 1000 / 1900 );
+ int count;
+ QRect rect;
+ // ----- store rectangles:
+ fontsize=size;
+ QFont font = KGlobalSettings::generalFont();
+ font.setPointSize(fontsize);
+ font.setBold( true );
+ QFontMetrics metrics(font);
+
+ // ----- find largest day name:
+ maxCell.setWidth(0);
+ maxCell.setHeight(0);
+ for(count=0; count<7; ++count)
+ {
+ rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true));
+ maxCell.setWidth(QMAX(maxCell.width(), rect.width()));
+ maxCell.setHeight(QMAX(maxCell.height(), rect.height()));
+ }
+ // ----- compare with a real wide number and add some space:
+ rect=metrics.boundingRect(QString::fromLatin1("88"));
+ maxCell.setWidth(QMAX(maxCell.width()+2, rect.width()));
+ maxCell.setHeight(QMAX(maxCell.height()+4, rect.height()));
+ if ( maxCell.width() * 1000 / maxCell.height() > 1900 )
+ maxCell.setHeight(maxCell.width() * 1000 / 1900 );
}
void
KDateTable::contentsMousePressEvent(QMouseEvent *e)
{
- if(e->type()!=QEvent::MouseButtonPress)
- { // the KDatePicker only reacts on mouse press events:
- return;
- }
- if(!isEnabled())
- {
- KNotifyClient::beep();
- return;
- }
+ if(e->type()!=QEvent::MouseButtonPress)
+ { // the KDatePicker only reacts on mouse press events:
+ return;
+ }
+ if(!isEnabled())
+ {
+ KNotifyClient::beep();
+ return;
+ }
- int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0;
- // -----
- int row, col, pos, temp;
- QPoint mouseCoord;
- // -----
- 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
- return;
- }
- pos=7*(row-1)+col+1;
+ int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0;
+ // -----
+ int row, col, pos, temp;
+ QPoint mouseCoord;
+ // -----
+ 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
+ return;
+ }
+ pos=7*(row-1)+col+1;
#if 0
- if(pos+dayoff<=firstday)
- { // this day is in the previous month
- KNotifyClient::beep();
- return;
- }
- if(firstday+numdays<pos+dayoff)
- { // this date is in the next month
- KNotifyClient::beep();
- return;
- }
+ if(pos+dayoff<=firstday)
+ { // this day is in the previous month
+ KNotifyClient::beep();
+ return;
+ }
+ if(firstday+numdays<pos+dayoff)
+ { // this date is in the next month
+ KNotifyClient::beep();
+ return;
+ }
#endif
- temp=firstday+date.day()-dayoff-1;
- QDate da = QDate(date.year(), date.month(),1);
- setDate(da.addDays( pos-firstday+dayoff-1));
- updateCell(temp/7+1, temp%7); // Update the previously selected cell
- updateCell(row, col); // Update the selected cell
- // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid());
- emit(tableClicked());
+ temp=firstday+date.day()-dayoff-1;
+ QDate da = QDate(date.year(), date.month(),1);
+ setDate(da.addDays( pos-firstday+dayoff-1));
+ updateCell(temp/7+1, temp%7); // Update the previously selected cell
+ updateCell(row, col); // Update the selected cell
+ // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid());
+ emit(tableClicked());
}
bool
KDateTable::setDate(const QDate& date_)
{
- bool changed=false;
- QDate temp;
- mMarkCurrent = false;
- // -----
- if(!date_.isValid())
- {
- kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl;
- return false;
- }
- if(date!=date_)
- {
- date=date_;
- changed=true;
- }
- mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() );
- temp.setYMD(date.year(), date.month(), 1);
- firstday=temp.dayOfWeek();
- if(firstday==1) firstday=8;
- numdays=date.daysInMonth();
- if(date.month()==1)
- { // set to december of previous year
- temp.setYMD(date.year()-1, 12, 1);
- } else { // set to previous month
- temp.setYMD(date.year(), date.month()-1, 1);
- }
- numDaysPrevMonth=temp.daysInMonth();
- if(changed)
- {
- repaintContents(false);
+ bool changed=false;
+ QDate temp;
+ mMarkCurrent = false;
+ // -----
+ if(!date_.isValid())
+ {
+ kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl;
+ return false;
+ }
+ if(date!=date_)
+ {
+ date=date_;
+ changed=true;
+ }
+ mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() );
+ temp.setYMD(date.year(), date.month(), 1);
+ firstday=temp.dayOfWeek();
+ if(firstday==1) firstday=8;
+ numdays=date.daysInMonth();
+ if(date.month()==1)
+ { // set to december of previous year
+ temp.setYMD(date.year()-1, 12, 1);
+ } else { // set to previous month
+ temp.setYMD(date.year(), date.month()-1, 1);
}
- emit(dateChanged(date));
- return true;
+ numDaysPrevMonth=temp.daysInMonth();
+ if(changed)
+ {
+ repaintContents(false);
+ }
+ emit(dateChanged(date));
+ return true;
}
const QDate&
KDateTable::getDate() const
{
- return date;
+ return date;
}
void KDateTable::focusInEvent( QFocusEvent *e )
{
repaintContents(false);
QGridView::focusInEvent( e );
}
void KDateTable::focusOutEvent( QFocusEvent *e )
{
repaintContents(false);
QGridView::focusOutEvent( e );
}
QSize
KDateTable::sizeHint() const
{
- if(maxCell.height()>0 && maxCell.width()>0)
- {
- return QSize((maxCell.width()+2)*numCols()+2*frameWidth(),
- (maxCell.height()+4)*numRows()+2*frameWidth());
- } else {
- return QSize(-1, -1);
+ if(maxCell.height()>0 && maxCell.width()>0)
+ {
+ return QSize((maxCell.width()+2)*numCols()+2*frameWidth(),
+ (maxCell.height()+4)*numRows()+2*frameWidth());
+ } else {
+ return QSize(-1, -1);
}
}
KDateInternalMonthPicker::KDateInternalMonthPicker
(int fontsize, QWidget* parent, const char* name)
- : QGridView(parent, name),
- result(0) // invalid
-{
- QRect rect;
- QFont font;
- // -----
- activeCol = -1;
- activeRow = -1;
- font=KGlobalSettings::generalFont();
- font.setPointSize(fontsize);
- setFont(font);
- setHScrollBarMode(AlwaysOff);
- setVScrollBarMode(AlwaysOff);
- setFrameStyle(QFrame::NoFrame);
- setNumRows(4);
- setNumCols(3);
- // enable to find drawing failures:
- // setTableFlags(Tbl_clipCellPainting);
+ : QGridView(parent, name),
+ result(0) // invalid
+{
+ QRect rect;
+ QFont font;
+ // -----
+ activeCol = -1;
+ activeRow = -1;
+ font=KGlobalSettings::generalFont();
+ font.setPointSize(fontsize);
+ setFont(font);
+ setHScrollBarMode(AlwaysOff);
+ setVScrollBarMode(AlwaysOff);
+ setFrameStyle(QFrame::NoFrame);
+ setNumRows(4);
+ setNumCols(3);
+ // enable to find drawing failures:
+ // setTableFlags(Tbl_clipCellPainting);
#if 0
- viewport()->setEraseColor(lightGray); // for consistency with the datepicker
+ viewport()->setEraseColor(lightGray); // for consistency with the datepicker
#endif
- // ----- find the preferred size
- // (this is slow, possibly, but unfortunatly it is needed here):
- QFontMetrics metrics(font);
- for(int i=1; i <= 12; ++i)
- {
- rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false));
- if(max.width()<rect.width()) max.setWidth(rect.width());
- if(max.height()<rect.height()) max.setHeight(rect.height());
- }
+ // ----- find the preferred size
+ // (this is slow, possibly, but unfortunatly it is needed here):
+ QFontMetrics metrics(font);
+ for(int i=1; i <= 12; ++i)
+ {
+ rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false));
+ if(max.width()<rect.width()) max.setWidth(rect.width());
+ if(max.height()<rect.height()) max.setHeight(rect.height());
+ }
}
QSize
KDateInternalMonthPicker::sizeHint() const
{
- return QSize((max.width()+6)*numCols()+2*frameWidth(),
- (max.height()+6)*numRows()+2*frameWidth());
+ return QSize((max.width()+6)*numCols()+2*frameWidth(),
+ (max.height()+6)*numRows()+2*frameWidth());
}
int
KDateInternalMonthPicker::getResult() const
{
- return result;
+ return result;
}
void
KDateInternalMonthPicker::setupPainter(QPainter *p)
{
- p->setPen(black);
+ p->setPen(black);
}
void
KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*)
{
- setCellWidth(width()/3);
- setCellHeight(height()/4);
+ setCellWidth(width()/3);
+ setCellHeight(height()/4);
}
void
KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col)
{
- int index;
- QString text;
- // ----- find the number of the cell:
- index=3*row+col+1;
- text=KGlobal::locale()->monthName(index, false);
- painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
- if ( activeCol == col && activeRow == row )
- painter->drawRect( 0, 0, cellWidth(), cellHeight() );
+ int index;
+ QString text;
+ // ----- find the number of the cell:
+ index=3*row+col+1;
+ text=KGlobal::locale()->monthName(index, false);
+ painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
+ if ( activeCol == col && activeRow == row )
+ painter->drawRect( 0, 0, cellWidth(), cellHeight() );
}
void
KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e)
{
- if(!isEnabled() || e->button() != LeftButton)
- {
- KNotifyClient::beep();
- return;
+ if(!isEnabled() || e->button() != LeftButton)
+ {
+ KNotifyClient::beep();
+ return;
+ }
+ // -----
+ int row, col;
+ QPoint mouseCoord;
+ // -----
+ 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 */ );
}
- // -----
- int row, col;
- QPoint mouseCoord;
- // -----
- 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
KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e)
{
- if (e->state() & LeftButton)
- {
- int row, col;
- QPoint mouseCoord;
- // -----
- 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
+ if (e->state() & LeftButton)
+ {
+ int row, col;
+ QPoint mouseCoord;
+ // -----
+ 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
+ }
}
+ if ( tmpRow > -1 ) // repaint the former active cell
+ updateCell( tmpRow, tmpCol /*, true */ );
}
- if ( tmpRow > -1 ) // repaint the former active cell
- updateCell( tmpRow, tmpCol /*, true */ );
- }
}
void
KDateInternalMonthPicker::contentsMouseReleaseEvent(QMouseEvent *e)
{
- if(!isEnabled())
- {
- return;
- }
- // -----
- int row, col, pos;
- QPoint mouseCoord;
- // -----
- 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));
+ if(!isEnabled())
+ {
+ return;
+ }
+ // -----
+ int row, col, pos;
+ QPoint mouseCoord;
+ // -----
+ 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));
}
KDateInternalYearSelector::KDateInternalYearSelector
(int fontsize, QWidget* parent, const char* name)
- : QLineEdit(parent, name),
- val(new QIntValidator(this)),
- result(0)
-{
- QFont font;
- // -----
- font=KGlobalSettings::generalFont();
- font.setPointSize(fontsize);
- setFont(font);
+ : QLineEdit(parent, name),
+ val(new QIntValidator(this)),
+ result(0)
+{
+ QFont font;
+ // -----
+ font=KGlobalSettings::generalFont();
+ font.setPointSize(fontsize);
+ setFont(font);
#if 0
- setFrameStyle(QFrame::NoFrame);
+ setFrameStyle(QFrame::NoFrame);
#endif
- // we have to respect the limits of QDate here, I fear:
- val->setRange(0, 8000);
- setValidator(val);
- connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot()));
+ // we have to respect the limits of QDate here, I fear:
+ val->setRange(0, 8000);
+ setValidator(val);
+ connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot()));
}
void
KDateInternalYearSelector::yearEnteredSlot()
{
- bool ok;
- int year;
- QDate date;
- // ----- 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));
+ bool ok;
+ int year;
+ QDate date;
+ // ----- 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
KDateInternalYearSelector::getYear()
{
- return result;
+ return result;
}
void
KDateInternalYearSelector::setYear(int year)
{
- QString temp;
- // -----
- temp.setNum(year);
- setText(temp);
+ QString temp;
+ // -----
+ temp.setNum(year);
+ setText(temp);
}
KPopupFrame::KPopupFrame(QWidget* parent, const char* name)
- : QFrame(parent, name, WType_Popup),
- result(0), // rejected
- main(0)
+ : QFrame(parent, name, WType_Popup),
+ result(0), // rejected
+ main(0)
{
- setFrameStyle(QFrame::Box|QFrame::Raised);
- setMidLineWidth(2);
+ setFrameStyle(QFrame::Box|QFrame::Raised);
+ setMidLineWidth(2);
}
void
KPopupFrame::keyPressEvent(QKeyEvent* e)
{
- if(e->key()==Key_Escape)
- {
- result=0; // rejected
- qApp->exit_loop();
- }
+ if(e->key()==Key_Escape)
+ {
+ result=0; // rejected
+ qApp->exit_loop();
+ }
}
void
KPopupFrame::close(int r)
{
- result=r;
- qApp->exit_loop();
+ result=r;
+ qApp->exit_loop();
}
void
KPopupFrame::setMainWidget(QWidget* m)
{
- main=m;
- if(main!=0)
- {
- resize(main->width()+2*frameWidth(), main->height()+2*frameWidth());
- }
+ main=m;
+ if(main!=0)
+ {
+ resize(main->width()+2*frameWidth(), main->height()+2*frameWidth());
+ }
}
void
KPopupFrame::resizeEvent(QResizeEvent*)
{
- if(main!=0)
- {
- main->setGeometry(frameWidth(), frameWidth(),
- width()-2*frameWidth(), height()-2*frameWidth());
- }
+ if(main!=0)
+ {
+ main->setGeometry(frameWidth(), frameWidth(),
+ width()-2*frameWidth(), height()-2*frameWidth());
+ }
}
void
KPopupFrame::popup(const QPoint &pos)
{
- // Make sure the whole popup is visible.
- QRect d = QApplication::desktop()->frameGeometry();
- 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();
+ // Make sure the whole popup is visible.
+ QRect d = QApplication::desktop()->frameGeometry();
+ 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
KPopupFrame::exec(QPoint pos)
{
- popup(pos);
- repaint();
- qApp->enter_loop();
- hide();
- return result;
+ popup(pos);
+ repaint();
+ qApp->enter_loop();
+ hide();
+ return result;
}
int
KPopupFrame::exec(int x, int y)
{
- return exec(QPoint(x, y));
+ return exec(QPoint(x, y));
}
void KPopupFrame::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
void KDateTable::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
//#include "kdatetbl.moc"
+
+
+KDateInternalWeekPicker::KDateInternalWeekPicker
+(int fontsize, QWidget* parent, const char* name)
+ : QGridView(parent, name),
+ result(0) // invalid
+{
+ QRect rect;
+ QFont font;
+ // -----
+ activeCol = -1;
+ activeRow = -1;
+ font=KGlobalSettings::generalFont();
+ font.setPointSize(fontsize);
+ setFont(font);
+ setHScrollBarMode(AlwaysOff);
+ setVScrollBarMode(AlwaysOff);
+ setFrameStyle(QFrame::NoFrame);
+ setNumRows(13);
+ setNumCols(4);
+ // enable to find drawing failures:
+ // setTableFlags(Tbl_clipCellPainting);
+#if 0
+ viewport()->setEraseColor(lightGray); // for consistency with the datepicker
+#endif
+ // ----- find the preferred size
+ // (this is slow, possibly, but unfortunatly it is needed here):
+ QFontMetrics metrics(font);
+ for(int i=1; i <= 52; ++i)
+ {
+ rect=metrics.boundingRect(QString::number( i ));
+ if(max.width()<rect.width()) max.setWidth(rect.width());
+ if(max.height()<rect.height()) max.setHeight(rect.height());
+ }
+
+}
+
+QSize
+KDateInternalWeekPicker::sizeHint() const
+{
+ return QSize((max.width()+6)*numCols()+2*frameWidth(),
+ (max.height()+6)*numRows()+2*frameWidth());
+}
+
+int
+KDateInternalWeekPicker::getResult() const
+{
+ return result;
+}
+
+void
+KDateInternalWeekPicker::setupPainter(QPainter *p)
+{
+ p->setPen(black);
+}
+
+void
+KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*)
+{
+ setCellWidth(width()/4);
+ setCellHeight(height()/13);
+}
+
+void
+KDateInternalWeekPicker::paintCell(QPainter* painter, int row, int col)
+{
+ int index;
+ QString text;
+ // ----- find the number of the cell:
+ index=4*row+col+1;
+ text=QString::number( index );
+ painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
+ if ( activeCol == col && activeRow == row )
+ painter->drawRect( 0, 0, cellWidth(), cellHeight() );
+}
+
+void
+KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e)
+{
+ if(!isEnabled() || e->button() != LeftButton)
+ {
+ KNotifyClient::beep();
+ return;
+ }
+ // -----
+ int row, col;
+ QPoint mouseCoord;
+ // -----
+ 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
+KDateInternalWeekPicker::contentsMouseMoveEvent(QMouseEvent *e)
+{
+ if (e->state() & LeftButton)
+ {
+ int row, col;
+ QPoint mouseCoord;
+ // -----
+ 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
+ }
+ }
+ if ( tmpRow > -1 ) // repaint the former active cell
+ updateCell( tmpRow, tmpCol /*, true */ );
+ }
+}
+
+void
+KDateInternalWeekPicker::contentsMouseReleaseEvent(QMouseEvent *e)
+{
+ if(!isEnabled())
+ {
+ return;
+ }
+ // -----
+ int row, col, pos;
+ QPoint mouseCoord;
+ // -----
+ 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=4*row+col+1;
+ result=pos;
+ emit(closeMe(1));
+}
diff --git a/microkde/kdatetbl.h b/microkde/kdatetbl.h
index b4d3e16..2efa532 100644
--- a/microkde/kdatetbl.h
+++ b/microkde/kdatetbl.h
@@ -214,96 +214,159 @@ public:
* @internal
* @version $Id$
* @author Tim Gilman, Mirko Boehm
*/
class KDateTable : public QGridView
{
Q_OBJECT
public:
/**
* The constructor.
*/
KDateTable(QWidget *parent=0,
QDate date=QDate::currentDate(),
const char* name=0, WFlags f=0);
/**
* Returns a recommended size for the widget.
* To save some time, the size of the largest used cell content is
* calculated in each paintCell() call, since all calculations have
* to be done there anyway. The size is stored in maxCell. The
* sizeHint() simply returns a multiple of maxCell.
*/
virtual QSize sizeHint() const;
/**
* Set the font size of the date table.
*/
void setFontSize(int size);
/**
* Select and display this date.
*/
bool setDate(const QDate&);
const QDate& getDate() const;
protected:
bool mMarkCurrent;
/**
* Paint a cell.
*/
virtual void paintCell(QPainter*, int, int);
/**
* Handle the resize events.
*/
virtual void viewportResizeEvent(QResizeEvent *);
/**
* React on mouse clicks that select a date.
*/
virtual void contentsMousePressEvent(QMouseEvent *);
virtual void keyPressEvent( QKeyEvent *e );
virtual void focusInEvent( QFocusEvent *e );
virtual void focusOutEvent( QFocusEvent *e );
/**
* The font size of the displayed text.
*/
int fontsize;
/**
* The currently selected date.
*/
QDate date;
/**
* The day of the first day in the month [1..7].
*/
int firstday;
/**
* The number of days in the current month.
*/
int numdays;
/**
* The number of days in the previous month.
*/
int numDaysPrevMonth;
/**
* unused
*/
bool unused_hasSelection;
/**
* Save the size of the largest used cell content.
*/
QRect maxCell;
signals:
/**
* The selected date changed.
*/
void dateChanged(QDate);
/**
* A date has been selected by clicking on the table.
*/
void tableClicked();
protected:
virtual void virtual_hook( int id, void* data );
private:
class KDateTablePrivate;
KDateTablePrivate *d;
};
#endif // KDATETBL_H
+class KDateInternalWeekPicker : public QGridView
+{
+ Q_OBJECT
+protected:
+ /**
+ * Store the month that has been clicked [1..12].
+ */
+ int result;
+ /**
+ * the cell under mouse cursor when LBM is pressed
+ */
+ short int activeCol;
+ short int activeRow;
+ /**
+ * Contains the largest rectangle needed by the month names.
+ */
+ QRect max;
+signals:
+ /**
+ * This is send from the mouse click event handler.
+ */
+ void closeMe(int);
+public:
+ /**
+ * The constructor.
+ */
+ KDateInternalWeekPicker(int fontsize, QWidget* parent, const char* name=0);
+ /**
+ * The size hint.
+ */
+ QSize sizeHint() const;
+ /**
+ * Return the result. 0 means no selection (reject()), 1..12 are the
+ * months.
+ */
+ int getResult() const;
+protected:
+ /**
+ * Set up the painter.
+ */
+ void setupPainter(QPainter *p);
+ /**
+ * The resize event.
+ */
+ void viewportResizeEvent(QResizeEvent*);
+ /**
+ * Paint a cell. This simply draws the month names in it.
+ */
+ virtual void paintCell(QPainter* painter, int row, int col);
+ /**
+ * Catch mouse click and move events to paint a rectangle around the item.
+ */
+ void contentsMousePressEvent(QMouseEvent *e);
+ void contentsMouseMoveEvent(QMouseEvent *e);
+ /**
+ * Emit monthSelected(int) when a cell has been released.
+ */
+ void contentsMouseReleaseEvent(QMouseEvent *e);
+
+private:
+ class KDateInternalMonthPrivate;
+ KDateInternalMonthPrivate *d;
+};