Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

datebookweeklst.cpp

Go to the documentation of this file.
00001 #include "namespace_hack.h"
00002 #include "datebookweeklst.h"
00003 #include "datebookweeklstheader.h"
00004 #include "datebookweeklstview.h"
00005 #include "datebookweeklstdblview.h"
00006 
00007 #include "datebook.h"
00008 
00009 #include <opie2/odebug.h>
00010 
00011 #include <qpe/datebookmonth.h>
00012 #include <qpe/config.h>
00013 
00014 #include <qlayout.h>
00015 #include <qtoolbutton.h>
00016 
00017 using namespace Opie::Ui;
00018 
00019 DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDBHoliday *newDB,
00020                   QWidget *parent,
00021                   const char *name )
00022     : QWidget( parent, name ),
00023       db( newDB ),
00024       startTime( 0 ),
00025       ampm( ap ),
00026       bStartOnMonday(onM)
00027 {
00028     setFocusPolicy(StrongFocus);
00029     dateset = false;
00030     layout = new QVBoxLayout( this );
00031     layout->setMargin(0);
00032 
00033     header=new DateBookWeekLstHeader(onM, this);
00034     layout->addWidget( header );
00035     connect(header, SIGNAL(dateChanged(QDate&)), this, SLOT(dateChanged(QDate&)));
00036     connect(header, SIGNAL(setDbl(bool)), this, SLOT(setDbl(bool)));
00037 
00038     scroll=new QScrollView(this);
00039     scroll->setResizePolicy(QScrollView::AutoOneFit);
00040     layout->addWidget(scroll);
00041 
00042     m_CurrentView=NULL;
00043     Config config("DateBook");
00044     config.setGroup("Main");
00045     dbl=config.readBoolEntry("weeklst_dbl", false);
00046     header->dbl->setOn(dbl);
00047 }
00048 
00049 DateBookWeekLst::~DateBookWeekLst(){
00050     Config config("DateBook");
00051     config.setGroup("Main");
00052     config.writeEntry("weeklst_dbl", dbl);
00053 }
00054 
00055 void DateBookWeekLst::setDate(const QDate &d) {
00056     bdate=d;
00057     header->setDate(d);
00058 }
00059 
00060 void DateBookWeekLst::setDbl(bool on) {
00061     dbl=on;
00062     bool displayed = false;
00063     if (m_CurrentView) {
00064         displayed = m_CurrentView->toggleDoubleView(on);
00065     }
00066     if (!displayed||dbl) {
00067         getEvents();
00068     }
00069 }
00070 
00071 void DateBookWeekLst::redraw() {getEvents();}
00072 
00073 QDate DateBookWeekLst::date() {
00074     return bdate;
00075 }
00076 
00077 // return the date at the beginning of the week...
00078 // copied from DateBookWeek
00079 QDate DateBookWeekLst::weekDate() const
00080 {
00081     QDate d=bdate;
00082 
00083     // Calculate offset to first day of week.
00084     int dayoffset=d.dayOfWeek();
00085     if(bStartOnMonday) dayoffset--;
00086     else if( dayoffset == 7 )
00087         dayoffset = 0;
00088 
00089     return d.addDays(-dayoffset);
00090 }
00091 
00092 void DateBookWeekLst::getEvents() {
00093     if (!dateset) return;
00094     QDate start = weekDate(); //date();
00095     QDate stop = start.addDays(6);
00096     QDate start2;
00097 
00098 
00099     QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop);
00100     QValueList<EffectiveEvent> el2;
00101 
00102     if (dbl) {
00103         start2 = start.addDays(7);
00104         stop = start2.addDays(6);
00105         el2 = db->getEffectiveEvents(start2, stop);
00106     }
00107     if (!m_CurrentView) {
00108         if (dbl) {
00109             m_CurrentView=new DateBookWeekLstDblView(el,el2,start,bStartOnMonday,scroll);
00110         } else {
00111             m_CurrentView=new DateBookWeekLstDblView(el,start,bStartOnMonday,scroll);
00112         }
00113         m_CurrentView->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
00114         connect (m_CurrentView, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&)));
00115         connect (m_CurrentView, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &)));
00116         connect (m_CurrentView, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &)));
00117         connect (m_CurrentView, SIGNAL(beamEvent(const Event &)), this, SIGNAL(beamEvent(const Event &)));
00118         connect (m_CurrentView, SIGNAL(redraw()), this, SLOT(redraw()));
00119         connect (m_CurrentView, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int)));
00120         connect (m_CurrentView, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)),
00121             this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)));
00122         scroll->addChild(m_CurrentView);
00123     } else {
00124         if (dbl) {
00125             m_CurrentView->setEvents(el,el2,start,bStartOnMonday);
00126         } else {
00127             m_CurrentView->setEvents(el,start,bStartOnMonday);
00128         }
00129     }
00130     scroll->updateScrollBars();
00131 }
00132 
00133 void DateBookWeekLst::dateChanged(QDate &newdate) {
00134     dateset = true;
00135     bdate=newdate;
00136     odebug << "Date changed " << oendl;
00137     getEvents();
00138 }
00139 
00140 void DateBookWeekLst::keyPressEvent(QKeyEvent *e)
00141 {
00142     switch(e->key()) {
00143         case Key_Up:
00144             scroll->scrollBy(0, -20);
00145             break;
00146         case Key_Down:
00147             scroll->scrollBy(0, 20);
00148             break;
00149         case Key_Left:
00150             header->prevWeek();
00151             break;
00152         case Key_Right:
00153             header->nextWeek();
00154             break;
00155         default:
00156             e->ignore();
00157     }
00158 }

Generated on Sat Nov 5 16:15:49 2005 for OPIE by  doxygen 1.4.2