notes/notesui/notesviews/src/notestodoview.cpp
changeset 45 b6db4fd4947b
parent 23 fd30d51f876b
child 55 2c54b51f39c4
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
    55 	\param parent The parent of type QGraphicsWidget.
    55 	\param parent The parent of type QGraphicsWidget.
    56  */
    56  */
    57 NotesTodoView::NotesTodoView(QGraphicsWidget *parent)
    57 NotesTodoView::NotesTodoView(QGraphicsWidget *parent)
    58 :HbView(parent),
    58 :HbView(parent),
    59  mSelectedItem(0),
    59  mSelectedItem(0),
    60  mDeleteAction(0)
    60  mDeleteAction(0),
       
    61  mIsLongTop(false)
    61 {
    62 {
    62 	// Nothing yet.
    63 	// Nothing yet.
    63 }
    64 }
    64 
    65 
    65 /*!
    66 /*!
   112 	connect(
   113 	connect(
   113 			mListView,
   114 			mListView,
   114 			SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)),
   115 			SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)),
   115 			this,
   116 			this,
   116 			SLOT(handleItemLongPressed(HbAbstractViewItem *, const QPointF &)));
   117 			SLOT(handleItemLongPressed(HbAbstractViewItem *, const QPointF &)));
   117 
   118 	
       
   119 	// Get the empty list string.
       
   120 	mEmptyListLabel = static_cast<HbLabel *> (
       
   121 			mDocLoader->findWidget("emptyListLabel"));
       
   122 	
   118 	// Get the toolbar/menu actions.
   123 	// Get the toolbar/menu actions.
   119 	mAddTodoAction = static_cast<HbAction *> (
   124 	mAddTodoAction = static_cast<HbAction *> (
   120 			mDocLoader->findObject("newTodoAction"));
   125 			mDocLoader->findObject("newTodoAction"));
   121 	connect(
   126 	connect(
   122 			mAddTodoAction, SIGNAL(triggered()),
   127 			mAddTodoAction, SIGNAL(triggered()),
   128 			mAllNotesAction, SIGNAL(triggered()),
   133 			mAllNotesAction, SIGNAL(triggered()),
   129 			this, SLOT(displayAllNotesView()));
   134 			this, SLOT(displayAllNotesView()));
   130 
   135 
   131 	mViewCollectionAction = static_cast<HbAction *> (
   136 	mViewCollectionAction = static_cast<HbAction *> (
   132 			mDocLoader->findObject("displayCollectionsAction"));
   137 			mDocLoader->findObject("displayCollectionsAction"));
   133 	mViewCollectionAction->setCheckable(true);
   138 	
   134 	mViewCollectionAction->setChecked(true);
       
   135 	connect(
   139 	connect(
   136 			mViewCollectionAction, SIGNAL(changed()),
   140 			mViewCollectionAction, SIGNAL(changed()),
   137 			this, SLOT(handleActionStateChanged()));
   141 			this, SLOT(handleActionStateChanged()));
   138 	connect(
   142 	connect(
   139 			mViewCollectionAction, SIGNAL(triggered()),
   143 			mViewCollectionAction, SIGNAL(triggered()),
   147 			this, SLOT(handleOrientationChanged(Qt::Orientation)));
   151 			this, SLOT(handleOrientationChanged(Qt::Orientation)));
   148 
   152 
   149 	mSubTitle = static_cast<HbGroupBox *>(
   153 	mSubTitle = static_cast<HbGroupBox *>(
   150 			mDocLoader->findWidget("subtitleGroupBox"));
   154 			mDocLoader->findWidget("subtitleGroupBox"));
   151 
   155 
   152 	// Update sub heading text for to-do collections view.
       
   153 	updateSubTitle();
       
   154 
       
   155 	connect(
   156 	connect(
   156 			mAgendaUtil, SIGNAL(entryAdded(ulong)),
   157 			mAgendaUtil, SIGNAL(entryAdded(ulong)),
   157 			this,SLOT(updateSubTitle(ulong)));
   158 			this,SLOT(updateSubTitle(ulong)));
   158 	connect(
   159 	connect(
   159 			mAgendaUtil, SIGNAL(entryDeleted(ulong)),
   160 			mAgendaUtil, SIGNAL(entryDeleted(ulong)),
   165 	// Set the graphics size for the icons.
   166 	// Set the graphics size for the icons.
   166 	HbListViewItem *prototype = mListView->listItemPrototype();
   167 	HbListViewItem *prototype = mListView->listItemPrototype();
   167 	prototype->setGraphicsSize(HbListViewItem::SmallIcon);
   168 	prototype->setGraphicsSize(HbListViewItem::SmallIcon);
   168 }
   169 }
   169 
   170 
       
   171 /*
       
   172 	Updates the title text for the first launch
       
   173  */
       
   174 void NotesTodoView::updateTitle()
       
   175 {
       
   176 	updateSubTitle();
       
   177 }
       
   178 
   170 /*!
   179 /*!
   171 	Opens the to-do editor to create a new to-do.
   180 	Opens the to-do editor to create a new to-do.
   172  */
   181  */
   173 void NotesTodoView::createNewTodo()
   182 void NotesTodoView::createNewTodo()
   174 {
   183 {
   188 	\param index Reference to the QModelIndex representing the view item.
   197 	\param index Reference to the QModelIndex representing the view item.
   189 	\sa HbAbstractViewItem
   198 	\sa HbAbstractViewItem
   190  */
   199  */
   191 void NotesTodoView::handleItemReleased(const QModelIndex &index)
   200 void NotesTodoView::handleItemReleased(const QModelIndex &index)
   192 {
   201 {
   193 	// Sanity check.
   202 	if(!mIsLongTop) {
   194 	if (!index.isValid()) {
   203 		// Sanity check.
   195 		return;
   204 		if (!index.isValid()) {
   196 	}
   205 			return;
   197 
   206 		}
   198 	// First get the id of the to-do and get the corresponding information from
   207 
   199 	// agendautil.
   208 		// First get the id of the to-do and get the corresponding information from
   200 	ulong toDoId = index.data(NotesNamespace::IdRole).value<qulonglong>();
   209 		// agendautil.
   201 
   210 		ulong toDoId = index.data(NotesNamespace::IdRole).value<qulonglong>();
   202 	if (0 >= toDoId) {
   211 
   203 		// Something wrong.
   212 		if (0 >= toDoId) {
   204 		return;
   213 			// Something wrong.
   205 	}
   214 			return;
   206 
   215 		}
   207 	// Construct agenda event viewer.
   216 
   208 	mAgendaEventViewer = new AgendaEventViewer(mAgendaUtil, this);
   217 		// Construct agenda event viewer.
   209 
   218 		mAgendaEventViewer = new AgendaEventViewer(mAgendaUtil, this);
   210 	connect(
   219 
   211 			mAgendaEventViewer, SIGNAL(viewingCompleted(const QDate)),
   220 		connect(
   212 			this, SLOT(handleViewingCompleted()));
   221 				mAgendaEventViewer, SIGNAL(viewingCompleted(const QDate)),
   213 	// Launch agenda event viewer
   222 				this, SLOT(handleViewingCompleted()));
   214 	mAgendaEventViewer->view(toDoId, AgendaEventViewer::ActionEditDelete);
   223 		// Launch agenda event viewer
       
   224 		mAgendaEventViewer->view(toDoId, AgendaEventViewer::ActionEditDelete);
       
   225 	}
   215 }
   226 }
   216 
   227 
   217 /*!
   228 /*!
   218 	Displays a list item specific context menu.
   229 	Displays a list item specific context menu.
   219 
   230 
   224  */
   235  */
   225 void NotesTodoView::handleItemLongPressed(
   236 void NotesTodoView::handleItemLongPressed(
   226 		HbAbstractViewItem *item, const QPointF &coords)
   237 		HbAbstractViewItem *item, const QPointF &coords)
   227 {
   238 {
   228 	mSelectedItem = item;
   239 	mSelectedItem = item;
       
   240 	mIsLongTop = true;
   229 
   241 
   230 	// Get the entry of the selected item.
   242 	// Get the entry of the selected item.
   231 	ulong noteId = item->modelIndex().data(
   243 	ulong noteId = item->modelIndex().data(
   232 			NotesNamespace::IdRole).value<qulonglong>();
   244 			NotesNamespace::IdRole).value<qulonglong>();
   233 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   245 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   234 
   246 
   235 	// Display a context specific menu.
   247 	// Display a context specific menu.
   236 	HbMenu *contextMenu = new HbMenu();
   248 	HbMenu *contextMenu = new HbMenu();
       
   249 	connect(
       
   250 			contextMenu,SIGNAL(aboutToClose()),
       
   251 			this, SLOT(handleMenuClosed()));
   237 
   252 
   238 	// Add actions to the context menu.
   253 	// Add actions to the context menu.
   239 	mOpenAction =
   254 	mOpenAction =
   240 			contextMenu->addAction(hbTrId("txt_common_menu_open"));
   255 			contextMenu->addAction(hbTrId("txt_common_menu_open"));
   241 	connect(
       
   242 			mOpenAction, SIGNAL(triggered()),
       
   243 			this, SLOT(openTodo()));
       
   244 
   256 
   245 	mEditAction = contextMenu->addAction(
   257 	mEditAction = contextMenu->addAction(
   246 			hbTrId("txt_common_menu_edit"));
   258 			hbTrId("txt_common_menu_edit"));
   247 	connect(
       
   248 			mEditAction, SIGNAL(triggered()),
       
   249 			this, SLOT(editTodo()));
       
   250 
   259 
   251 	mDeleteAction = contextMenu->addAction(
   260 	mDeleteAction = contextMenu->addAction(
   252 			hbTrId("txt_common_menu_delete"));
   261 			hbTrId("txt_common_menu_delete"));
   253 	connect(
       
   254 			mDeleteAction, SIGNAL(triggered()),
       
   255 			this, SLOT(deleteTodo()));
       
   256 
   262 
   257 	if (AgendaEntry::TypeTodo == entry.type()) {
   263 	if (AgendaEntry::TypeTodo == entry.type()) {
   258 		if (AgendaEntry::TodoNeedsAction == entry.status()) {
   264 		if (AgendaEntry::TodoNeedsAction == entry.status()) {
   259 			mTodoStatusAction = contextMenu->addAction(
   265 			mTodoStatusAction = contextMenu->addAction(
   260 					hbTrId("txt_notes_menu_mark_as_done"));
   266 					hbTrId("txt_notes_menu_mark_as_done"));
   261 			connect(
       
   262 					mTodoStatusAction , SIGNAL(triggered()),
       
   263 					this, SLOT(markTodoStatus()));
       
   264 
       
   265 		} else if (AgendaEntry::TodoCompleted == entry.status()) {
   267 		} else if (AgendaEntry::TodoCompleted == entry.status()) {
   266 			mTodoStatusAction =
   268 			mTodoStatusAction =
   267 					contextMenu->addAction(
   269 					contextMenu->addAction(
   268 							hbTrId("txt_notes_menu_mark_as_not_done"));
   270 							hbTrId("txt_notes_menu_mark_as_not_done"));
   269 			connect(
       
   270 					mTodoStatusAction , SIGNAL(triggered()),
       
   271 					this, SLOT(markTodoStatus()));
       
   272 		}
   271 		}
   273 	}
   272 	}
   274 
   273 
   275 	// Show the menu.
   274 	// Show the menu.
   276 	contextMenu->exec(coords);
   275 	contextMenu->open(this, SLOT(selectedMenuAction(HbAction*)));
       
   276 	contextMenu->setPreferredPos(coords);
   277 }
   277 }
   278 
   278 
   279 /*!
   279 /*!
   280 	Slot to delete a selected to-do.
   280 	Slot to delete a selected to-do.
   281  */
   281  */
   440 	// Get the number of notes and to-do entries.
   440 	// Get the number of notes and to-do entries.
   441 	QList<ulong> entries = mAgendaUtil->entryIds(
   441 	QList<ulong> entries = mAgendaUtil->entryIds(
   442 		AgendaUtil::IncludeIncompletedTodos);
   442 		AgendaUtil::IncludeIncompletedTodos);
   443 	mSubTitle->setHeading(
   443 	mSubTitle->setHeading(
   444 			hbTrId("txt_notes_subhead_todos_ln_pending",entries.count()));
   444 			hbTrId("txt_notes_subhead_todos_ln_pending",entries.count()));
       
   445 	
       
   446 	if (0 >= entries.count()) {
       
   447 		mEmptyListLabel->show();
       
   448 		mListView->hide();
       
   449 	} else {
       
   450 		mEmptyListLabel->hide();
       
   451 		mListView->show();
       
   452 	}
   445 }
   453 }
   446 
   454 
   447 /*
   455 /*
   448 	Opens the to-do viewer to view the to-do.
   456 	Opens the to-do viewer to view the to-do.
   449  */
   457  */
   463 	// Launch agenda event viewer
   471 	// Launch agenda event viewer
   464 	mAgendaEventViewer->view(
   472 	mAgendaEventViewer->view(
   465 			entry, AgendaEventViewer::ActionEditDelete);
   473 			entry, AgendaEventViewer::ActionEditDelete);
   466 }
   474 }
   467 
   475 
       
   476 /*
       
   477 	Slot to handle the context menu actions.
       
   478  */
       
   479 void NotesTodoView::selectedMenuAction(HbAction *action)
       
   480 {
       
   481 	if (action == mOpenAction) {
       
   482 		openTodo();
       
   483 	} else if (action == mEditAction) {
       
   484 		editTodo();
       
   485 	} else if (action == mDeleteAction) {
       
   486 		deleteTodo();
       
   487 	} else if (action == mTodoStatusAction) {
       
   488 		markTodoStatus();
       
   489 	}
       
   490 }
       
   491 
       
   492 
       
   493 /*!
       
   494 	Slot to handle the context menu closed.
       
   495  */
       
   496 void NotesTodoView::handleMenuClosed()
       
   497 {
       
   498 	mIsLongTop = false;
       
   499 }
   468 // End of file	--Don't remove this.
   500 // End of file	--Don't remove this.