diff options
author | Charles Yin <charles.yin@nokia.com> | 2010-12-02 17:14:52 +1000 |
---|---|---|
committer | Charles Yin <charles.yin@nokia.com> | 2010-12-02 17:16:50 +1000 |
commit | 1b2c4fb620d8837065336d29141b9191dfed00e4 (patch) | |
tree | 891377e482e0a824e70f021353a85cee5c8b416c | |
parent | 163f87e8b826566cc438e3fc1e0f4b9e7ef66dcd (diff) |
more fixes for qmlorganizer
1) add QDOM::containsItems() method
2) add highlight color for event on monthview
Change-Id: I162eb29d02f13919accc74a9476c6c74082bd01a
-rw-r--r-- | examples/qmlorganizer/contents/MenuBar.qml | 10 | ||||
-rw-r--r-- | examples/qmlorganizer/contents/MonthView.qml | 19 | ||||
-rw-r--r-- | examples/qmlorganizer/contents/TimelineView.qml | 28 | ||||
-rw-r--r-- | examples/qmlorganizer/contents/WeekView.qml | 8 | ||||
-rw-r--r-- | examples/qmlorganizer/contents/month.js | 5 | ||||
-rw-r--r-- | examples/qmlorganizer/organizer.qml | 79 | ||||
-rw-r--r-- | plugins/declarative/organizer/qdeclarativeorganizeritem.cpp | 21 | ||||
-rw-r--r-- | plugins/declarative/organizer/qdeclarativeorganizeritem_p.h | 4 | ||||
-rw-r--r-- | plugins/declarative/organizer/qdeclarativeorganizermodel.cpp | 38 | ||||
-rw-r--r-- | plugins/declarative/organizer/qdeclarativeorganizermodel_p.h | 1 |
10 files changed, 141 insertions, 72 deletions
diff --git a/examples/qmlorganizer/contents/MenuBar.qml b/examples/qmlorganizer/contents/MenuBar.qml index 49b0140d7c..5b469a827f 100644 --- a/examples/qmlorganizer/contents/MenuBar.qml +++ b/examples/qmlorganizer/contents/MenuBar.qml @@ -63,11 +63,11 @@ Rectangle { onClicked: Qt.quit() } } - Button {id: todayButton; text: "Today";onClicked:topItem.day = new Date();} - Button { id: monthButton; text: "Month"; onClicked: topItem.state="MonthView";} - Button { id: weekButton; text: "Week";onClicked: topItem.state="WeekView";} - Button { id: dayButton; text: "Day";onClicked: topItem.state="DayView";} - Button { id: timelineButton; text: "Timeline";onClicked: topItem.state="TimelineView";} + Button {id: todayButton; text: "Today";onClicked:calendar.day = new Date();} + Button { id: monthButton; text: "Month"; onClicked: calendar.state="MonthView";} + Button { id: weekButton; text: "Week";onClicked: calendar.state="WeekView";} + Button { id: dayButton; text: "Day";onClicked: calendar.state="DayView";} + Button { id: timelineButton; text: "Timeline";onClicked: calendar.state="TimelineView";} Text { color: "#f5f210";text:info ; font.bold: true; verticalAlignment: Text.AlignVCenter; style: Text.Sunken;font.pointSize: 10} } } diff --git a/examples/qmlorganizer/contents/MonthView.qml b/examples/qmlorganizer/contents/MonthView.qml index 16153dcd77..3a5e38f1c3 100644 --- a/examples/qmlorganizer/contents/MonthView.qml +++ b/examples/qmlorganizer/contents/MonthView.qml @@ -44,8 +44,8 @@ import QtMobility.organizer 1.1 Rectangle { id:monthView - property int month: topItem.day.getMonth() - property int year: topItem.day.getFullYear() + property int month: calendar.day.getMonth() + property int year: calendar.day.getFullYear() property date startDay:new Date(year, month, 1) property int startWeekday:startDay.getDay() @@ -106,7 +106,7 @@ Rectangle { MouseArea { anchors.fill: parent onClicked: { - topItem.state = "WeekView"; + calendar.state = "WeekView"; } } } @@ -117,7 +117,14 @@ Rectangle { id:dayContainer width: container.width / 7 height: (container.height - 35) / 6 - color: Month.isToday(startDay, index - startWeekday +1) ? "lightsteelblue": Month.getColorOfDay(startDay, index - startWeekday +1) + color: { + if (Month.isToday(startDay, index - startWeekday +1)) + return "lightsteelblue"; + else if (calendar.organizer.containsItems(Month.dateOfThisDay(startDay, index - startWeekday +1))) + return "steelblue"; + else + return Month.getColorOfDay(startDay, index - startWeekday +1); + } border.color: "black" Text { color: "#6ba24b"; @@ -140,8 +147,8 @@ Rectangle { dayContainer.border.width = 1; } onClicked: { - topItem.day = new Date(topItem.day.getFullYear(), topItem.day.getMonth(), index - startWeekday +1); - topItem.state = "DayView"; + calendar.day = new Date(calendar.day.getFullYear(), calendar.day.getMonth(), index - startWeekday +1); + calendar.state = "DayView"; } } } diff --git a/examples/qmlorganizer/contents/TimelineView.qml b/examples/qmlorganizer/contents/TimelineView.qml index a6c2e43e28..182293fd25 100644 --- a/examples/qmlorganizer/contents/TimelineView.qml +++ b/examples/qmlorganizer/contents/TimelineView.qml @@ -49,11 +49,11 @@ Rectangle { property int month property int day Connections { - target: topItem + target: calendar onDayChanged : { - year = topItem.day.getFullYear(); - month = topItem.day.getMonth(); - day = topItem.day.getDate(); + year = calendar.day.getFullYear(); + month = calendar.day.getMonth(); + day = calendar.day.getDate(); dayList.currentIndex = day - 1; monthList.currentIndex = month; yearList.currentIndex = year - yearModel.start; @@ -85,9 +85,9 @@ Rectangle { keyNavigationWraps : true onCurrentIndexChanged : { - topItem.day = new Date(topItem.day.getFullYear(), topItem.day.getMonth(), currentIndex + 1); - timelineView.month = topItem.day.getMonth(); - timelineView.day = topItem.day.getDate(); + calendar.day = new Date(calendar.day.getFullYear(), calendar.day.getMonth(), currentIndex + 1); + timelineView.month = calendar.day.getMonth(); + timelineView.day = calendar.day.getDate(); monthList.currentIndex = timelineView.month; currentIndex = timelineView.day - 1; } @@ -188,9 +188,9 @@ Rectangle { var d = Date.parse("Feb 31, 2010"); } onCurrentIndexChanged : { - topItem.day = new Date(topItem.day.getFullYear(), currentIndex, topItem.day.getDate()); - timelineView.month = topItem.day.getMonth(); - timelineView.day = topItem.day.getDate(); + calendar.day = new Date(calendar.day.getFullYear(), currentIndex, calendar.day.getDate()); + timelineView.month = calendar.day.getMonth(); + timelineView.day = calendar.day.getDate(); currentIndex = timelineView.month; dayList.currentIndex = timelineView.day - 1; } @@ -299,10 +299,10 @@ Rectangle { Component.onCompleted: Timeline.extendYearModel(true); onCurrentIndexChanged: { Timeline.extendYearModel(false); - topItem.day = new Date(yearModel.start + currentIndex, topItem.day.getMonth(), topItem.day.getDate()); - timelineView.year = topItem.day.getFullYear(); - timelineView.month = topItem.day.getMonth(); - timelineView.day = topItem.day.getDate(); + calendar.day = new Date(yearModel.start + currentIndex, calendar.day.getMonth(), calendar.day.getDate()); + timelineView.year = calendar.day.getFullYear(); + timelineView.month = calendar.day.getMonth(); + timelineView.day = calendar.day.getDate(); monthList.currentIndex = timelineView.month; dayList.currentIndex = timelineView.day - 1; } diff --git a/examples/qmlorganizer/contents/WeekView.qml b/examples/qmlorganizer/contents/WeekView.qml index 324867ea54..53a645392d 100644 --- a/examples/qmlorganizer/contents/WeekView.qml +++ b/examples/qmlorganizer/contents/WeekView.qml @@ -45,7 +45,7 @@ Rectangle { id:weekView anchors.fill: parent - property int day:topItem.day.getDay() + property int day:calendar.day.getDay() ListView { id : dayList anchors.fill: parent @@ -61,7 +61,7 @@ Rectangle onOpacityChanged: { //when back to week view, select the current day. if (opacity != 0) - currentIndex = topItem.day.getDay(); + currentIndex = calendar.day.getDay(); } model : ListModel { @@ -92,8 +92,8 @@ Rectangle anchors.fill: parent onClicked : dayList.currentIndex = index onDoubleClicked: { - topItem.day = new Date(topItem.day.getFullYear(), topItem.day.getMonth(), topItem.day.getDate() + dayList.currentIndex - weekView.day); - topItem.state = "DayView" + calendar.day = new Date(calendar.day.getFullYear(), calendar.day.getMonth(), calendar.day.getDate() + dayList.currentIndex - weekView.day); + calendar.state = "DayView" } } } diff --git a/examples/qmlorganizer/contents/month.js b/examples/qmlorganizer/contents/month.js index 7f57c5b2f7..886c698b38 100644 --- a/examples/qmlorganizer/contents/month.js +++ b/examples/qmlorganizer/contents/month.js @@ -7,6 +7,11 @@ function getDayOfMonth(startDayOfMonth, offset) { return day.getDate(); } +function dateOfThisDay(startDayOfMonth, offset) { + var day = startDayOfMonth.clone(); + day.setDate(offset); + return day; +} function getColorOfDay(startDayOfMonth, offset) { diff --git a/examples/qmlorganizer/organizer.qml b/examples/qmlorganizer/organizer.qml index 802678af22..71c0d5fb6c 100644 --- a/examples/qmlorganizer/organizer.qml +++ b/examples/qmlorganizer/organizer.qml @@ -43,13 +43,23 @@ import QtMobility.organizer 1.1 import "contents" Rectangle { - id: topItem + id: calendar width: 400 height: 640 property date day: new Date() property string status:day.toDateString() + property OrganizerModel organizer:OrganizerModel{ + id: organizer + startPeriod:new Date(calendar.day.getFullYear(), 1, 1) + endPeriod:new Date(calendar.day.getFullYear(), 12, 31) + autoUpdate:false + Component.onCompleted : { + if (manager == "memory") + organizer.importItems(Qt.resolvedUrl("contents/2010-FIFA-WorldCup.ics")); + } + } onDayChanged: { - topItem.status = day.toDateString(); + calendar.status = day.toDateString(); } color: "#343434"; @@ -59,37 +69,28 @@ Rectangle { SystemPalette { id: activePalette } - OrganizerModel { - id: organizer - startPeriod:new Date(topItem.day.getFullYear(), 1, 1) - endPeriod:new Date(topItem.day.getFullYear(), 12, 31) - autoUpdate:false - Component.onCompleted : { - if (manager == "memory") - organizer.importItems(Qt.resolvedUrl("2010-FIFA-WorldCup.ics")); - } - } + MenuBar { id: menuBar; width: parent.width; height: 35; opacity: 0.9; info: organizer.error + "\nTotal:" + organizer.itemCount } StatusBar { - id: statusBar; status:topItem.status; width: parent.width; height: 35; opacity: 0.9; anchors.bottom: topItem.bottom + id: statusBar; status:calendar.status; width: parent.width; height: 35; opacity: 0.9; anchors.bottom: calendar.bottom onLeftClicked: { - if (topItem.state == "MonthView") { - topItem.day = new Date(topItem.day.getFullYear(), topItem.day.getMonth() - 1, topItem.day.getDate()); - } else if (topItem.state == "WeekView") { - topItem.day = new Date(topItem.day.getFullYear(), topItem.day.getMonth() , topItem.day.getDate() - 7); - } else if (topItem.state == "DayView" || topItem.state == "TimelineView") { - topItem.day = new Date(topItem.day.getFullYear(), topItem.day.getMonth() , topItem.day.getDate() - 1); + if (calendar.state == "MonthView") { + calendar.day = new Date(calendar.day.getFullYear(), calendar.day.getMonth() - 1, calendar.day.getDate()); + } else if (calendar.state == "WeekView") { + calendar.day = new Date(calendar.day.getFullYear(), calendar.day.getMonth() , calendar.day.getDate() - 7); + } else if (calendar.state == "DayView" || calendar.state == "TimelineView") { + calendar.day = new Date(calendar.day.getFullYear(), calendar.day.getMonth() , calendar.day.getDate() - 1); } } onRightClicked: { - if (topItem.state == "MonthView") { - topItem.day = new Date(topItem.day.getFullYear(), topItem.day.getMonth() + 1, topItem.day.getDate()); - } else if (topItem.state == "WeekView") { - topItem.day = new Date(topItem.day.getFullYear(), topItem.day.getMonth() , topItem.day.getDate() + 7); - } else if (topItem.state == "DayView" || topItem.state == "TimelineView") { - topItem.day = new Date(topItem.day.getFullYear(), topItem.day.getMonth() , topItem.day.getDate() + 1); + if (calendar.state == "MonthView") { + calendar.day = new Date(calendar.day.getFullYear(), calendar.day.getMonth() + 1, calendar.day.getDate()); + } else if (calendar.state == "WeekView") { + calendar.day = new Date(calendar.day.getFullYear(), calendar.day.getMonth() , calendar.day.getDate() + 7); + } else if (calendar.state == "DayView" || calendar.state == "TimelineView") { + calendar.day = new Date(calendar.day.getFullYear(), calendar.day.getMonth() , calendar.day.getDate() + 1); } } //rightClick } @@ -116,50 +117,50 @@ Rectangle { Item { id: contentArea; anchors.top: menuBar.bottom; - anchors.left: topItem.left; - anchors.right: topItem.right; + anchors.left: calendar.left; + anchors.right: calendar.right; anchors.bottom: statusBar.top; MonthView { id: monthView; - width: topItem.width; - height: topItem.height - menuBar.height - statusBar.height; + width: calendar.width; + height: calendar.height - menuBar.height - statusBar.height; opacity: 0; anchors.fill: contentArea; } TimelineView { id: timelineView; - width: topItem.width; - height: topItem.height - menuBar.height - statusBar.height; + width: calendar.width; + height: calendar.height - menuBar.height - statusBar.height; opacity: 0; anchors.fill: contentArea; } WeekView { id: weekView; - width: topItem.width; - height: topItem.height - menuBar.height - statusBar.height; + width: calendar.width; + height: calendar.height - menuBar.height - statusBar.height; opacity: 0; anchors.fill: contentArea; } DayView { id: dayView; - width: topItem.width; - height: topItem.height - menuBar.height - statusBar.height; + width: calendar.width; + height: calendar.height - menuBar.height - statusBar.height; opacity: 0; anchors.fill: contentArea; } AgenderView { id: agenderView; - width: topItem.width; - height: topItem.height - menuBar.height - statusBar.height; + width: calendar.width; + height: calendar.height - menuBar.height - statusBar.height; opacity: 0; anchors.fill: contentArea; } DetailsView { id: detailsView; - width: topItem.width; - height: topItem.height - menuBar.height - statusBar.height; + width: calendar.width; + height: calendar.height - menuBar.height - statusBar.height; opacity: 0; anchors.fill: contentArea; } diff --git a/plugins/declarative/organizer/qdeclarativeorganizeritem.cpp b/plugins/declarative/organizer/qdeclarativeorganizeritem.cpp index 06b0663614..7dc522e725 100644 --- a/plugins/declarative/organizer/qdeclarativeorganizeritem.cpp +++ b/plugins/declarative/organizer/qdeclarativeorganizeritem.cpp @@ -263,6 +263,23 @@ QString QDeclarativeOrganizerItem::type() const return d->m_item.type(); } +QDeclarativeOrganizerItem::OrganizerItemType QDeclarativeOrganizerItem::itemType() const +{ + if (d->m_item.type() == QOrganizerItemType::TypeEvent) + return QDeclarativeOrganizerItem::Event; + else if (d->m_item.type() == QOrganizerItemType::TypeEventOccurrence) + return QDeclarativeOrganizerItem::EventOccurrence; + else if (d->m_item.type() == QOrganizerItemType::TypeTodo) + return QDeclarativeOrganizerItem::Todo; + else if (d->m_item.type() == QOrganizerItemType::TypeTodoOccurrence) + return QDeclarativeOrganizerItem::TodoOccurrence; + else if (d->m_item.type() == QOrganizerItemType::TypeJournal) + return QDeclarativeOrganizerItem::Journal; + else if (d->m_item.type() == QOrganizerItemType::TypeNote) + return QDeclarativeOrganizerItem::Note; + return QDeclarativeOrganizerItem::Customized; +} + /*! \qmlproperty string OrganizerItem::displayLabel @@ -333,7 +350,7 @@ QDeclarativeOrganizerEvent::QDeclarativeOrganizerEvent(QObject *parent) :QDeclarativeOrganizerItem(parent) { d->setMetaObject(QDeclarativeOrganizerEvent::staticMetaObject); - m_event = static_cast<QOrganizerEvent*>(&d->m_item); + m_event = reinterpret_cast<QOrganizerEvent*>(&(d->m_item)); connect(this, SIGNAL(valueChanged()), SIGNAL(itemChanged())); } @@ -352,7 +369,7 @@ void QDeclarativeOrganizerEvent::setStartDateTime(const QDateTime& datetime) QDateTime QDeclarativeOrganizerEvent::startDateTime() const { - return m_event->startDateTime(); + return d->m_item.detail<QOrganizerEventTime>().startDateTime(); } /*! diff --git a/plugins/declarative/organizer/qdeclarativeorganizeritem_p.h b/plugins/declarative/organizer/qdeclarativeorganizeritem_p.h index 7a38ac4dea..414fd0f2d2 100644 --- a/plugins/declarative/organizer/qdeclarativeorganizeritem_p.h +++ b/plugins/declarative/organizer/qdeclarativeorganizeritem_p.h @@ -8,7 +8,7 @@ ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage -** This file contains pre-release code and may not be distributed. +** This file Is pre-release code and may not be distributed. ** You may use this file in accordance with the terms and conditions ** contained in the Technology Preview License Agreement accompanying ** this package. @@ -83,6 +83,8 @@ public: explicit QDeclarativeOrganizerItem(const QOrganizerItem& item, const QMap<QString, QOrganizerItemDetailDefinition>& defs, QObject *parent = 0); ~QDeclarativeOrganizerItem(); + OrganizerItemType itemType() const; + QString itemId() const; QString manager() const; bool modified() const; diff --git a/plugins/declarative/organizer/qdeclarativeorganizermodel.cpp b/plugins/declarative/organizer/qdeclarativeorganizermodel.cpp index 64b9d65adb..f6ee57ab1b 100644 --- a/plugins/declarative/organizer/qdeclarativeorganizermodel.cpp +++ b/plugins/declarative/organizer/qdeclarativeorganizermodel.cpp @@ -63,6 +63,31 @@ static QString urlToLocalFileName(const QUrl& url) } +static QDateTime itemEntryDateTime(const QDeclarativeOrganizerItem* item) +{ + switch (item->itemType()) { + case QDeclarativeOrganizerItem::Event: + return static_cast<const QDeclarativeOrganizerEvent*>(item)->startDateTime(); + case QDeclarativeOrganizerItem::EventOccurrence: + return static_cast<const QDeclarativeOrganizerEventOccurrence*>(item)->startDateTime(); + case QDeclarativeOrganizerItem::Todo: + return static_cast<const QDeclarativeOrganizerTodo*>(item)->startDateTime(); + case QDeclarativeOrganizerItem::TodoOccurrence: + return static_cast<const QDeclarativeOrganizerTodoOccurrence*>(item)->startDateTime(); + case QDeclarativeOrganizerItem::Journal: + return static_cast<const QDeclarativeOrganizerJournal*>(item)->dateTime(); + case QDeclarativeOrganizerItem::Note: + default: + break; + } + return item->item().detail<QOrganizerItemTimestamp>().created(); +} + +static bool itemLessThan(const QDeclarativeOrganizerItem* item1, const QDeclarativeOrganizerItem* item2) +{ + return itemEntryDateTime(item1) < itemEntryDateTime(item2); +} + class QDeclarativeOrganizerModelPrivate { public: @@ -458,7 +483,7 @@ void QDeclarativeOrganizerModel::startImport(QVersitReader::State state) importer.importDocument(d->m_reader.results().at(0)); QList<QOrganizerItem> items = importer.items(); - +// qDebug() << "importing..." << items.size() << " items."; delete d->m_reader.device(); d->m_reader.setDevice(0); @@ -490,6 +515,17 @@ void QDeclarativeOrganizerModel::fetchItems(const QList<QString>& itemIds) QMetaObject::invokeMethod(this, "fetchAgain", Qt::QueuedConnection); } +bool QDeclarativeOrganizerModel::containsItems(const QDate& start, const QDate& end) +{ + //TODO: quick search this + QDate endDate = end.isNull()? start:end; + foreach (const QDeclarativeOrganizerItem* item, d->m_items) { + QDate dt = itemEntryDateTime(item).date(); + if ( dt >= start && dt <= endDate) + return true; + } + return false; +} void QDeclarativeOrganizerModel::fetchAgain() { diff --git a/plugins/declarative/organizer/qdeclarativeorganizermodel_p.h b/plugins/declarative/organizer/qdeclarativeorganizermodel_p.h index d436429f1a..af3153fad3 100644 --- a/plugins/declarative/organizer/qdeclarativeorganizermodel_p.h +++ b/plugins/declarative/organizer/qdeclarativeorganizermodel_p.h @@ -126,6 +126,7 @@ public: Q_INVOKABLE void saveItem(QDeclarativeOrganizerItem* item); Q_INVOKABLE void fetchItems(const QList<QString>& ids); + Q_INVOKABLE bool containsItems(const QDate& start, const QDate& end = QDate()); bool autoUpdate() const; void setAutoUpdate(bool autoUpdate); |