From ff7fd64d755b2cc63f9944b1a17a6a2e186da0b6 Mon Sep 17 00:00:00 2001 From: alwin Date: Sat, 19 Mar 2005 18:06:44 +0000 Subject: hopefull speedup the weeklistview. deleting the main widget 4 times when date changed isn't that usefull. After 1.2 OPIE this view should completly rewritten or removed. --- diff --git a/core/pim/datebook/holiday/christian/christian-holidays.pro b/core/pim/datebook/holiday/christian/christian-holidays.pro index db3c777..c943510 100644 --- a/core/pim/datebook/holiday/christian/christian-holidays.pro +++ b/core/pim/datebook/holiday/christian/christian-holidays.pro @@ -12,7 +12,7 @@ INCLUDEPATH += $(OPIEDIR)/include \ DEPENDPATH += $(OPIEDIR)/include \ ../ ../library -LIBS+= -lqpe -lopiecore2 -lopieui2 -opiepim2 +LIBS+= -lqpe -lopiecore2 -lopieui2 -lopiepim2 DESTDIR = $(OPIEDIR)/plugins/holidays TARGET = chrisholidayplugin diff --git a/core/pim/datebook/modules/weeklst/datebookweeklst.cpp b/core/pim/datebook/modules/weeklst/datebookweeklst.cpp index 47bc597..6556373 100644 --- a/core/pim/datebook/modules/weeklst/datebookweeklst.cpp +++ b/core/pim/datebook/modules/weeklst/datebookweeklst.cpp @@ -27,6 +27,7 @@ DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDBHoliday *newDB, bStartOnMonday(onM) { setFocusPolicy(StrongFocus); + dateset = false; layout = new QVBoxLayout( this ); layout->setMargin(0); @@ -39,12 +40,13 @@ DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDBHoliday *newDB, scroll->setResizePolicy(QScrollView::AutoOneFit); layout->addWidget(scroll); - view=NULL; + m_CurrentView=NULL; Config config("DateBook"); config.setGroup("Main"); dbl=config.readBoolEntry("weeklst_dbl", false); header->dbl->setOn(dbl); } + DateBookWeekLst::~DateBookWeekLst(){ Config config("DateBook"); config.setGroup("Main"); @@ -58,8 +60,15 @@ void DateBookWeekLst::setDate(const QDate &d) { void DateBookWeekLst::setDbl(bool on) { dbl=on; - redraw(); + bool displayed = false; + if (m_CurrentView) { + displayed = m_CurrentView->toggleDoubleView(on); + } + if (!displayed||dbl) { + getEvents(); + } } + void DateBookWeekLst::redraw() {getEvents();} QDate DateBookWeekLst::date() { @@ -82,38 +91,50 @@ QDate DateBookWeekLst::weekDate() const } void DateBookWeekLst::getEvents() { + if (!dateset) return; QDate start = weekDate(); //date(); QDate stop = start.addDays(6); + QDate start2; + + QValueList el = db->getEffectiveEvents(start, stop); + QValueList el2; - setUpdatesEnabled(false); - if (view) delete view; if (dbl) { - QDate start2=start.addDays(7); - stop=start2.addDays(6); - QValueList el2 = db->getEffectiveEvents(start2, stop); - view=new DateBookWeekLstDblView(el,el2,start,bStartOnMonday,scroll); + start2 = start.addDays(7); + stop = start2.addDays(6); + el2 = db->getEffectiveEvents(start2, stop); + } + if (!m_CurrentView) { + if (dbl) { + m_CurrentView=new DateBookWeekLstDblView(el,el2,start,bStartOnMonday,scroll); + } else { + m_CurrentView=new DateBookWeekLstDblView(el,start,bStartOnMonday,scroll); + } + m_CurrentView->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); + connect (m_CurrentView, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); + connect (m_CurrentView, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &))); + connect (m_CurrentView, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &))); + connect (m_CurrentView, SIGNAL(beamEvent(const Event &)), this, SIGNAL(beamEvent(const Event &))); + connect (m_CurrentView, SIGNAL(redraw()), this, SLOT(redraw())); + connect (m_CurrentView, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); + connect (m_CurrentView, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), + this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); + scroll->addChild(m_CurrentView); } else { - view=new DateBookWeekLstView(el,start,bStartOnMonday,scroll); + if (dbl) { + m_CurrentView->setEvents(el,el2,start,bStartOnMonday); + } else { + m_CurrentView->setEvents(el,start,bStartOnMonday); + } } - - connect (view, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); - connect (view, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &))); - connect (view, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &))); - connect (view, SIGNAL(beamEvent(const Event &)), this, SIGNAL(beamEvent(const Event &))); - connect (view, SIGNAL(redraw()), this, SLOT(redraw())); - connect (view, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); - connect (view, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), - this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); - - scroll->addChild(view); - view->show(); scroll->updateScrollBars(); - setUpdatesEnabled(true); } void DateBookWeekLst::dateChanged(QDate &newdate) { + dateset = true; bdate=newdate; + odebug << "Date changed " << oendl; getEvents(); } diff --git a/core/pim/datebook/modules/weeklst/datebookweeklst.h b/core/pim/datebook/modules/weeklst/datebookweeklst.h index 3922fa1..505810b 100644 --- a/core/pim/datebook/modules/weeklst/datebookweeklst.h +++ b/core/pim/datebook/modules/weeklst/datebookweeklst.h @@ -10,7 +10,7 @@ class DateBookDB; class DateBookDBHoliday; class DateBookWeekLstHeader; class DateBookWeekLstEvent; -class DateBookWeekLstView; +class DateBookWeekLstDblView; class QVBoxLayout; class QScrollView; @@ -55,9 +55,10 @@ private: QDate bdate; int year, _week,dow; DateBookWeekLstHeader *header; - QWidget *view; QVBoxLayout *layout; QScrollView *scroll; + DateBookWeekLstDblView*m_CurrentView; + bool dateset:1; void getEvents(); }; diff --git a/core/pim/datebook/modules/weeklst/datebookweeklstdblview.cpp b/core/pim/datebook/modules/weeklst/datebookweeklstdblview.cpp index 1cea602..6389822 100644 --- a/core/pim/datebook/modules/weeklst/datebookweeklstdblview.cpp +++ b/core/pim/datebook/modules/weeklst/datebookweeklstdblview.cpp @@ -10,30 +10,120 @@ DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList &ev1, const char* name, WFlags fl) : QWidget( parent, name, fl ) { - QHBoxLayout *layout = new QHBoxLayout( this ); - - DateBookWeekLstView *w=new DateBookWeekLstView(ev1,d,onM,this); - layout->addWidget(w); - connect (w, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); - connect (w, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &))); - connect (w, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &))); - connect (w, SIGNAL(beamEvent(const Event &)), this, SIGNAL(beamEvent(const Event &))); - connect (w, SIGNAL(redraw()), this, SIGNAL(redraw())); - connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); - connect (w, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), - this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); + m_MainLayout = new QHBoxLayout( this ); + leftView = 0; + rightView = 0; + setEvents(ev1,ev2,d,onM); +} - w=new DateBookWeekLstView(ev2,d.addDays(7),onM,this); - layout->addWidget(w); - connect (w, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); - connect (w, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &))); - connect (w, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &))); - connect (w, SIGNAL(beamEvent(const Event &)), this, SIGNAL(beamEvent(const Event &))); - connect (w, SIGNAL(redraw()), this, SIGNAL(redraw())); - connect (w, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); - connect (w, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), +DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList &ev1, + QDate &d, bool onM, + QWidget* parent, + const char* name, WFlags fl) + : QWidget( parent, name, fl ) +{ + m_MainLayout = new QHBoxLayout( this ); + + leftView = 0; + rightView = 0; + setEvents(ev1,d,onM); +} + +/* setting the variant with both views */ +void DateBookWeekLstDblView::setEvents(QValueList &ev1,QValueList &ev2,QDate &d, bool onM) +{ + setUpdatesEnabled(false); + if (!leftView) { + leftView=new DateBookWeekLstView(ev1,d,onM,this); + m_MainLayout->addWidget(leftView); + connect (leftView, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); + connect (leftView, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &))); + connect (leftView, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &))); + connect (leftView, SIGNAL(beamEvent(const Event &)), this, SIGNAL(beamEvent(const Event &))); + connect (leftView, SIGNAL(redraw()), this, SIGNAL(redraw())); + connect (leftView, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); + connect (leftView, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); + + } else { + leftView->hide(); + leftView->setEvents(ev1,d,onM); + } + + if (!rightView) { + rightView=new DateBookWeekLstView(ev2,d.addDays(7),onM,this); + m_MainLayout->addWidget(rightView); + connect (rightView, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); + connect (rightView, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &))); + connect (rightView, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &))); + connect (rightView, SIGNAL(beamEvent(const Event &)), this, SIGNAL(beamEvent(const Event &))); + connect (rightView, SIGNAL(redraw()), this, SIGNAL(redraw())); + connect (rightView, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); + connect (rightView, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), + this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); + } else { + rightView->hide(); + rightView->setEvents(ev2,d.addDays(7),onM); + } + + leftView->show(); + rightView->show(); + setUpdatesEnabled(true); +} + +void DateBookWeekLstDblView::setEvents(QValueList &ev1,QDate &d, bool onM) +{ + if (!leftView) { + leftView=new DateBookWeekLstView(ev1,d,onM,this); + m_MainLayout->addWidget(leftView); + connect (leftView, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); + connect (leftView, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &))); + connect (leftView, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &))); + connect (leftView, SIGNAL(beamEvent(const Event &)), this, SIGNAL(beamEvent(const Event &))); + connect (leftView, SIGNAL(redraw()), this, SIGNAL(redraw())); + connect (leftView, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); + connect (leftView, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), + this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); + } else { + leftView->hide(); + leftView->setEvents(ev1,d,onM); + } + leftView->show(); + + if (rightView) { + rightView->hide(); + } +} + +void DateBookWeekLstDblView::setRightEvents(QValueList &ev1,QDate &d, bool onM) +{ + if (!rightView) { + rightView=new DateBookWeekLstView(ev1,d,onM,this); + m_MainLayout->addWidget(rightView); + connect (leftView, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); + connect (leftView, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &))); + connect (leftView, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &))); + connect (leftView, SIGNAL(beamEvent(const Event &)), this, SIGNAL(beamEvent(const Event &))); + connect (leftView, SIGNAL(redraw()), this, SIGNAL(redraw())); + connect (leftView, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); + connect (leftView, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), + this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); + } else { + rightView->hide(); + rightView->setEvents(ev1,d,onM); + } + rightView->show(); +} + +bool DateBookWeekLstDblView::toggleDoubleView(bool how) +{ + if (rightView) { + if (how) rightView->show(); + else rightView->hide(); + return true; + } + return false; } DateBookWeekLstDblView::~DateBookWeekLstDblView() diff --git a/core/pim/datebook/modules/weeklst/datebookweeklstdblview.h b/core/pim/datebook/modules/weeklst/datebookweeklstdblview.h index 57e9690..808556e 100644 --- a/core/pim/datebook/modules/weeklst/datebookweeklstdblview.h +++ b/core/pim/datebook/modules/weeklst/datebookweeklstdblview.h @@ -8,6 +8,9 @@ #include #include +class DateBookWeekLstView; +class QHBoxLayout; + class DateBookWeekLstDblView: public QWidget { Q_OBJECT public: @@ -16,7 +19,17 @@ public: QDate &d, bool onM, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + DateBookWeekLstDblView(QValueList &ev1, + QDate &d, bool onM, + QWidget* parent = 0, const char* name = 0, + WFlags fl = 0 ); virtual ~DateBookWeekLstDblView(); + void setEvents(QValueList &ev1,QValueList &ev2,QDate &d, bool onM); + void setEvents(QValueList &ev1,QDate &d, bool onM); + void setRightEvents(QValueList &ev1,QDate &d, bool onM); + + bool toggleDoubleView(bool how); + signals: void editEvent(const Event &e); void duplicateEvent(const Event &e); @@ -26,6 +39,10 @@ signals: void showDate(int y, int m, int d); void addEvent(const QDateTime &start, const QDateTime &stop, const QString &str, const QString &location); + +protected: + QHBoxLayout*m_MainLayout; + DateBookWeekLstView *leftView,*rightView; }; #endif diff --git a/core/pim/datebook/modules/weeklst/datebookweeklstview.cpp b/core/pim/datebook/modules/weeklst/datebookweeklstview.cpp index efb4c01..82b9c6d 100644 --- a/core/pim/datebook/modules/weeklst/datebookweeklstview.cpp +++ b/core/pim/datebook/modules/weeklst/datebookweeklstview.cpp @@ -17,6 +17,22 @@ DateBookWeekLstView::DateBookWeekLstView(QValueList &ev, const char* name, WFlags fl) : QWidget( parent, name, fl ) { + childs.clear(); + m_MainLayout = new QVBoxLayout( this ); + setEvents(ev,d,onM); +} + +void DateBookWeekLstView::setEvents(QValueList &ev, const QDate &d, bool onM) +{ + QValueList::Iterator wIter; + for (wIter=childs.begin();wIter!=childs.end();++wIter) { + QObject*w = (*wIter); + delete w; + } + childs.clear(); + + setUpdatesEnabled(false); +// m_MainLayout->deleteAllItems(); Config config("DateBook"); config.setGroup("Main"); int weeklistviewconfig=config.readNumEntry("weeklistviewconfig", NORMAL); @@ -26,8 +42,6 @@ DateBookWeekLstView::DateBookWeekLstView(QValueList &ev, setPalette(white); setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); - QVBoxLayout *layout = new QVBoxLayout( this ); - qBubbleSort(ev); QValueListIterator it; it=ev.begin(); @@ -46,18 +60,23 @@ DateBookWeekLstView::DateBookWeekLstView(QValueList &ev, else if( dayoffset == 7 ) dayoffset = 0; for (int i=0; i<7; i++) { + QWidget*w = new QWidget(this); + w->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); + w->setPalette(white); + QVBoxLayout * tlayout = new QVBoxLayout(w); + childs.append(w); // Header - DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i-dayoffset), bStartOnMonday,this); + DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i-dayoffset), bStartOnMonday,w); connect(hdr, SIGNAL(showDate(int,int,int)), this, SIGNAL(showDate(int,int,int))); connect(hdr, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&)), this, SIGNAL(addEvent(const QDateTime&,const QDateTime&,const QString&,const QString&))); - layout->addWidget(hdr); + tlayout->addWidget(hdr); // Events while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) { if(!(((*it).end().hour()==0) && ((*it).end().minute()==0) && ((*it).startDate()!=(*it).date()))) { // Skip events ending at 00:00 starting at another day. - DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,weeklistviewconfig,this); - layout->addWidget(l); + DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,weeklistviewconfig,w); + tlayout->addWidget(l); connect (l, SIGNAL(editEvent(const Event&)), this, SIGNAL(editEvent(const Event&))); connect (l, SIGNAL(duplicateEvent(const Event &)), this, SIGNAL(duplicateEvent(const Event &))); connect (l, SIGNAL(removeEvent(const Event &)), this, SIGNAL(removeEvent(const Event &))); @@ -66,8 +85,20 @@ DateBookWeekLstView::DateBookWeekLstView(QValueList &ev, } it++; } - layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); + tlayout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); + m_MainLayout->addWidget(w); +/* + QSpacerItem * tmp = new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding); + m_MainLayout->addItem(tmp); +*/ } + setUpdatesEnabled(true); +} + +DateBookWeekLstView::~DateBookWeekLstView() +{} + +void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) +{ + e->ignore(); } -DateBookWeekLstView::~DateBookWeekLstView(){} -void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();} diff --git a/core/pim/datebook/modules/weeklst/datebookweeklstview.h b/core/pim/datebook/modules/weeklst/datebookweeklstview.h index 2428f1f..3d47842 100644 --- a/core/pim/datebook/modules/weeklst/datebookweeklstview.h +++ b/core/pim/datebook/modules/weeklst/datebookweeklstview.h @@ -9,15 +9,18 @@ #include class QKeyEvent; +class QVBoxLayout; class DateBookWeekLstView: public QWidget { Q_OBJECT public: - DateBookWeekLstView(QValueList &ev, const QDate &d, bool onM, - QWidget* parent = 0, const char* name = 0, + DateBookWeekLstView(QValueList &ev, const QDate &d, bool onM, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~DateBookWeekLstView(); + + void setEvents(QValueList &ev, const QDate &d, bool onM); + signals: void editEvent(const Event &e); void duplicateEvent(const Event &e); @@ -27,8 +30,12 @@ signals: void showDate(int y, int m, int d); void addEvent(const QDateTime &start, const QDateTime &stop, const QString &str, const QString &location); -private: +protected: bool bStartOnMonday; + QValueList childs; + + QVBoxLayout*m_MainLayout; + protected slots: void keyPressEvent(QKeyEvent *); }; -- cgit v0.9.0.2