notes/notesui/notesviews/src/notestodoview.cpp
changeset 26 a949c2543c15
parent 23 fd30d51f876b
child 50 579cc610882e
equal deleted inserted replaced
23:fd30d51f876b 26:a949c2543c15
    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 /*!
   147 			this, SLOT(handleOrientationChanged(Qt::Orientation)));
   148 			this, SLOT(handleOrientationChanged(Qt::Orientation)));
   148 
   149 
   149 	mSubTitle = static_cast<HbGroupBox *>(
   150 	mSubTitle = static_cast<HbGroupBox *>(
   150 			mDocLoader->findWidget("subtitleGroupBox"));
   151 			mDocLoader->findWidget("subtitleGroupBox"));
   151 
   152 
   152 	// Update sub heading text for to-do collections view.
       
   153 	updateSubTitle();
       
   154 
       
   155 	connect(
   153 	connect(
   156 			mAgendaUtil, SIGNAL(entryAdded(ulong)),
   154 			mAgendaUtil, SIGNAL(entryAdded(ulong)),
   157 			this,SLOT(updateSubTitle(ulong)));
   155 			this,SLOT(updateSubTitle(ulong)));
   158 	connect(
   156 	connect(
   159 			mAgendaUtil, SIGNAL(entryDeleted(ulong)),
   157 			mAgendaUtil, SIGNAL(entryDeleted(ulong)),
   165 	// Set the graphics size for the icons.
   163 	// Set the graphics size for the icons.
   166 	HbListViewItem *prototype = mListView->listItemPrototype();
   164 	HbListViewItem *prototype = mListView->listItemPrototype();
   167 	prototype->setGraphicsSize(HbListViewItem::SmallIcon);
   165 	prototype->setGraphicsSize(HbListViewItem::SmallIcon);
   168 }
   166 }
   169 
   167 
       
   168 /*
       
   169 	Updates the title text for the first launch
       
   170  */
       
   171 void NotesTodoView::updateTitle()
       
   172 {
       
   173 	updateSubTitle();
       
   174 }
       
   175 
   170 /*!
   176 /*!
   171 	Opens the to-do editor to create a new to-do.
   177 	Opens the to-do editor to create a new to-do.
   172  */
   178  */
   173 void NotesTodoView::createNewTodo()
   179 void NotesTodoView::createNewTodo()
   174 {
   180 {
   188 	\param index Reference to the QModelIndex representing the view item.
   194 	\param index Reference to the QModelIndex representing the view item.
   189 	\sa HbAbstractViewItem
   195 	\sa HbAbstractViewItem
   190  */
   196  */
   191 void NotesTodoView::handleItemReleased(const QModelIndex &index)
   197 void NotesTodoView::handleItemReleased(const QModelIndex &index)
   192 {
   198 {
   193 	// Sanity check.
   199 	if(!mIsLongTop) {
   194 	if (!index.isValid()) {
   200 		// Sanity check.
   195 		return;
   201 		if (!index.isValid()) {
   196 	}
   202 			return;
   197 
   203 		}
   198 	// First get the id of the to-do and get the corresponding information from
   204 
   199 	// agendautil.
   205 		// First get the id of the to-do and get the corresponding information from
   200 	ulong toDoId = index.data(NotesNamespace::IdRole).value<qulonglong>();
   206 		// agendautil.
   201 
   207 		ulong toDoId = index.data(NotesNamespace::IdRole).value<qulonglong>();
   202 	if (0 >= toDoId) {
   208 
   203 		// Something wrong.
   209 		if (0 >= toDoId) {
   204 		return;
   210 			// Something wrong.
   205 	}
   211 			return;
   206 
   212 		}
   207 	// Construct agenda event viewer.
   213 
   208 	mAgendaEventViewer = new AgendaEventViewer(mAgendaUtil, this);
   214 		// Construct agenda event viewer.
   209 
   215 		mAgendaEventViewer = new AgendaEventViewer(mAgendaUtil, this);
   210 	connect(
   216 
   211 			mAgendaEventViewer, SIGNAL(viewingCompleted(const QDate)),
   217 		connect(
   212 			this, SLOT(handleViewingCompleted()));
   218 				mAgendaEventViewer, SIGNAL(viewingCompleted(const QDate)),
   213 	// Launch agenda event viewer
   219 				this, SLOT(handleViewingCompleted()));
   214 	mAgendaEventViewer->view(toDoId, AgendaEventViewer::ActionEditDelete);
   220 		// Launch agenda event viewer
       
   221 		mAgendaEventViewer->view(toDoId, AgendaEventViewer::ActionEditDelete);
       
   222 	}
   215 }
   223 }
   216 
   224 
   217 /*!
   225 /*!
   218 	Displays a list item specific context menu.
   226 	Displays a list item specific context menu.
   219 
   227 
   224  */
   232  */
   225 void NotesTodoView::handleItemLongPressed(
   233 void NotesTodoView::handleItemLongPressed(
   226 		HbAbstractViewItem *item, const QPointF &coords)
   234 		HbAbstractViewItem *item, const QPointF &coords)
   227 {
   235 {
   228 	mSelectedItem = item;
   236 	mSelectedItem = item;
       
   237 	mIsLongTop = true;
   229 
   238 
   230 	// Get the entry of the selected item.
   239 	// Get the entry of the selected item.
   231 	ulong noteId = item->modelIndex().data(
   240 	ulong noteId = item->modelIndex().data(
   232 			NotesNamespace::IdRole).value<qulonglong>();
   241 			NotesNamespace::IdRole).value<qulonglong>();
   233 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   242 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   234 
   243 
   235 	// Display a context specific menu.
   244 	// Display a context specific menu.
   236 	HbMenu *contextMenu = new HbMenu();
   245 	HbMenu *contextMenu = new HbMenu();
       
   246 	connect(
       
   247 			contextMenu,SIGNAL(aboutToClose()),
       
   248 			this, SLOT(handleMenuClosed()));
   237 
   249 
   238 	// Add actions to the context menu.
   250 	// Add actions to the context menu.
   239 	mOpenAction =
   251 	mOpenAction =
   240 			contextMenu->addAction(hbTrId("txt_common_menu_open"));
   252 			contextMenu->addAction(hbTrId("txt_common_menu_open"));
   241 	connect(
       
   242 			mOpenAction, SIGNAL(triggered()),
       
   243 			this, SLOT(openTodo()));
       
   244 
   253 
   245 	mEditAction = contextMenu->addAction(
   254 	mEditAction = contextMenu->addAction(
   246 			hbTrId("txt_common_menu_edit"));
   255 			hbTrId("txt_common_menu_edit"));
   247 	connect(
       
   248 			mEditAction, SIGNAL(triggered()),
       
   249 			this, SLOT(editTodo()));
       
   250 
   256 
   251 	mDeleteAction = contextMenu->addAction(
   257 	mDeleteAction = contextMenu->addAction(
   252 			hbTrId("txt_common_menu_delete"));
   258 			hbTrId("txt_common_menu_delete"));
   253 	connect(
       
   254 			mDeleteAction, SIGNAL(triggered()),
       
   255 			this, SLOT(deleteTodo()));
       
   256 
   259 
   257 	if (AgendaEntry::TypeTodo == entry.type()) {
   260 	if (AgendaEntry::TypeTodo == entry.type()) {
   258 		if (AgendaEntry::TodoNeedsAction == entry.status()) {
   261 		if (AgendaEntry::TodoNeedsAction == entry.status()) {
   259 			mTodoStatusAction = contextMenu->addAction(
   262 			mTodoStatusAction = contextMenu->addAction(
   260 					hbTrId("txt_notes_menu_mark_as_done"));
   263 					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()) {
   264 		} else if (AgendaEntry::TodoCompleted == entry.status()) {
   266 			mTodoStatusAction =
   265 			mTodoStatusAction =
   267 					contextMenu->addAction(
   266 					contextMenu->addAction(
   268 							hbTrId("txt_notes_menu_mark_as_not_done"));
   267 							hbTrId("txt_notes_menu_mark_as_not_done"));
   269 			connect(
       
   270 					mTodoStatusAction , SIGNAL(triggered()),
       
   271 					this, SLOT(markTodoStatus()));
       
   272 		}
   268 		}
   273 	}
   269 	}
   274 
   270 
   275 	// Show the menu.
   271 	// Show the menu.
   276 	contextMenu->exec(coords);
   272 	contextMenu->open(this, SLOT(selectedMenuAction(HbAction*)));
       
   273 	contextMenu->setPreferredPos(coords);
   277 }
   274 }
   278 
   275 
   279 /*!
   276 /*!
   280 	Slot to delete a selected to-do.
   277 	Slot to delete a selected to-do.
   281  */
   278  */
   463 	// Launch agenda event viewer
   460 	// Launch agenda event viewer
   464 	mAgendaEventViewer->view(
   461 	mAgendaEventViewer->view(
   465 			entry, AgendaEventViewer::ActionEditDelete);
   462 			entry, AgendaEventViewer::ActionEditDelete);
   466 }
   463 }
   467 
   464 
       
   465 /*
       
   466 	Slot to handle the context menu actions.
       
   467  */
       
   468 void NotesTodoView::selectedMenuAction(HbAction *action)
       
   469 {
       
   470 	if (action == mOpenAction) {
       
   471 		openTodo();
       
   472 	} else if (action == mEditAction) {
       
   473 		editTodo();
       
   474 	} else if (action == mDeleteAction) {
       
   475 		deleteTodo();
       
   476 	} else if (action == mTodoStatusAction) {
       
   477 		markTodoStatus();
       
   478 	}
       
   479 }
       
   480 
       
   481 
       
   482 /*!
       
   483 	Slot to handle the context menu closed.
       
   484  */
       
   485 void NotesTodoView::handleMenuClosed()
       
   486 {
       
   487 	mIsLongTop = false;
       
   488 }
   468 // End of file	--Don't remove this.
   489 // End of file	--Don't remove this.