notes/notesui/notesviews/src/notesnoteview.cpp
changeset 26 a949c2543c15
parent 23 fd30d51f876b
child 50 579cc610882e
equal deleted inserted replaced
23:fd30d51f876b 26:a949c2543c15
    24 #include <HbMenu>
    24 #include <HbMenu>
    25 #include <HbAbstractViewItem>
    25 #include <HbAbstractViewItem>
    26 #include <HbGroupBox>
    26 #include <HbGroupBox>
    27 #include <HbListViewItem>
    27 #include <HbListViewItem>
    28 #include <HbInstance>
    28 #include <HbInstance>
       
    29 #include <HbNotificationDialog>
    29 
    30 
    30 // User includes
    31 // User includes
    31 #include "notesnoteview.h"
    32 #include "notesnoteview.h"
    32 #include "notescommon.h"
    33 #include "notescommon.h"
    33 #include "notesdocloader.h"
    34 #include "notesdocloader.h"
    51 	\param parent The parent of type QGraphicsWidget.
    52 	\param parent The parent of type QGraphicsWidget.
    52  */
    53  */
    53 NotesNoteView::NotesNoteView(QGraphicsWidget *parent)
    54 NotesNoteView::NotesNoteView(QGraphicsWidget *parent)
    54 :HbView(parent),
    55 :HbView(parent),
    55  mSelectedItem(0),
    56  mSelectedItem(0),
    56  mDeleteAction(0)
    57  mDeleteAction(0),
       
    58  mIsLongTop(false)
    57  {
    59  {
    58 	// Nothing yet.
    60 	// Nothing yet.
    59  }
    61  }
    60 
    62 
    61 /*!
    63 /*!
   168 	\param index Reference to the QModelIndex representing the view item.
   170 	\param index Reference to the QModelIndex representing the view item.
   169 	\sa HbAbstractViewItem
   171 	\sa HbAbstractViewItem
   170  */
   172  */
   171 void NotesNoteView::handleItemReleased(const QModelIndex &index)
   173 void NotesNoteView::handleItemReleased(const QModelIndex &index)
   172 {
   174 {
   173 	// Sanity check.
   175 	if(!mIsLongTop) {
   174 	if (!index.isValid()) {
   176 		// Sanity check.
   175 		return;
   177 		if (!index.isValid()) {
   176 	}
   178 			return;
   177 
   179 		}
   178 	// First get the id of the note and get the corresponding information from
   180 
   179 	// agendautil.
   181 		// First get the id of the note and get the corresponding information from
   180 	ulong noteId = index.data(NotesNamespace::IdRole).value<qulonglong>();
   182 		// agendautil.
   181 
   183 		ulong noteId = index.data(NotesNamespace::IdRole).value<qulonglong>();
   182 	if (0 >= noteId) {
   184 
   183 		// Something wrong.
   185 		if (0 >= noteId) {
   184 		return;
   186 			// Something wrong.
   185 	}
   187 			return;
   186 
   188 		}
   187 	// Get the entry details.
   189 
   188 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   190 		// Get the entry details.
   189 
   191 		AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   190 	if (entry.isNull()) {
   192 
   191 		// Entry invalid.
   193 		if (entry.isNull()) {
   192 		return;
   194 			// Entry invalid.
   193 	}
   195 			return;
   194 
   196 		}
   195 	// Now launch the editor with the obtained info.
   197 
   196 	mNotesEditor = new NotesEditor(mAgendaUtil, this);
   198 		// Now launch the editor with the obtained info.
   197 	connect(
   199 		mNotesEditor = new NotesEditor(mAgendaUtil, this);
   198 			mNotesEditor, SIGNAL(editingCompleted(bool)),
   200 		connect(
   199 			this, SLOT(handleEditingCompleted(bool)));
   201 				mNotesEditor, SIGNAL(editingCompleted(bool)),
   200 	mNotesEditor->edit(entry);
   202 				this, SLOT(handleEditingCompleted(bool)));
       
   203 		mNotesEditor->edit(entry);
       
   204 	}
   201 }
   205 }
   202 
   206 
   203 /*!
   207 /*!
   204 	Displays a list item specific context menu.
   208 	Displays a list item specific context menu.
   205 
   209 
   210  */
   214  */
   211 void NotesNoteView::handleItemLongPressed(
   215 void NotesNoteView::handleItemLongPressed(
   212 		HbAbstractViewItem *item, const QPointF &coords)
   216 		HbAbstractViewItem *item, const QPointF &coords)
   213 {
   217 {
   214 	mSelectedItem = item;
   218 	mSelectedItem = item;
       
   219 	mIsLongTop = true;
   215 
   220 
   216 	ulong noteId = item->modelIndex().data(
   221 	ulong noteId = item->modelIndex().data(
   217 			NotesNamespace::IdRole).value<qulonglong>();
   222 			NotesNamespace::IdRole).value<qulonglong>();
   218 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   223 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   219 
   224 
   220 	// Display a context specific menu.
   225 	// Display a context specific menu.
   221 	HbMenu *contextMenu = new HbMenu();
   226 	HbMenu *contextMenu = new HbMenu();
       
   227 	connect(
       
   228 			contextMenu,SIGNAL(aboutToClose()),
       
   229 			this, SLOT(handleMenuClosed()));
   222 
   230 
   223 	// Add actions to the context menu.
   231 	// Add actions to the context menu.
   224 	mOpenAction =
   232 	mOpenAction =
   225 			contextMenu->addAction(hbTrId("txt_common_menu_open"));
   233 			contextMenu->addAction(hbTrId("txt_common_menu_open"));
   226 	connect(
       
   227 			mOpenAction, SIGNAL(triggered()),
       
   228 			this, SLOT(openNote()));
       
   229 
   234 
   230 	mDeleteAction =
   235 	mDeleteAction =
   231 			contextMenu->addAction(hbTrId("txt_common_menu_delete"));
   236 			contextMenu->addAction(hbTrId("txt_common_menu_delete"));
   232 	connect(
       
   233 			mDeleteAction, SIGNAL(triggered()),
       
   234 			this, SLOT(deleteNote()));
       
   235 
   237 
   236 	if (AgendaEntry::TypeNote == entry.type()) {
   238 	if (AgendaEntry::TypeNote == entry.type()) {
   237 		if (entry.favourite()) {
   239 		if (entry.favourite()) {
   238 			mMakeFavouriteAction =
   240 			mMakeFavouriteAction = contextMenu->addAction(
   239 					contextMenu->addAction(
       
   240 							hbTrId("txt_notes_menu_remove_from_favorites"));
   241 							hbTrId("txt_notes_menu_remove_from_favorites"));
   241 
       
   242 			connect(
       
   243 					mMakeFavouriteAction, SIGNAL(triggered()),
       
   244 					this, SLOT(markNoteAsFavourite()));
       
   245 
       
   246 		} else {
   242 		} else {
   247 			mMakeFavouriteAction =
   243 			mMakeFavouriteAction = contextMenu->addAction(
   248 					contextMenu->addAction(
       
   249 							hbTrId("txt_notes_menu_mark_as_favorite"));
   244 							hbTrId("txt_notes_menu_mark_as_favorite"));
   250 
       
   251 			connect(
       
   252 					mMakeFavouriteAction, SIGNAL(triggered()),
       
   253 					this, SLOT(markNoteAsFavourite()));
       
   254 		}
   245 		}
   255 		mMarkTodoAction = contextMenu->addAction(
   246 		mMarkTodoAction = contextMenu->addAction(
   256 				hbTrId("txt_notes_menu_make_it_as_todo_note"));
   247 				hbTrId("txt_notes_menu_make_it_as_todo_note"));
   257 		connect(
       
   258 				mMarkTodoAction, SIGNAL(triggered()),
       
   259 				this, SLOT(markNoteAsTodo()));
       
   260 	}
   248 	}
   261 
   249 
   262 	// Show the menu.
   250 	// Show the menu.
   263 	contextMenu->exec(coords);
   251 	contextMenu->open(this, SLOT(selectedMenuAction(HbAction*)));
       
   252 	contextMenu->setPreferredPos(coords);
   264 }
   253 }
   265 
   254 
   266 /*!
   255 /*!
   267 	Slot to delete a selected note.
   256 	Slot to delete a selected note.
   268  */
   257  */
   355 			entry, AgendaEntry::TypeTodo);
   344 			entry, AgendaEntry::TypeTodo);
   356 
   345 
   357 	// Delete the old entry.
   346 	// Delete the old entry.
   358 	mAgendaUtil->deleteEntry(entry.id());
   347 	mAgendaUtil->deleteEntry(entry.id());
   359 
   348 
       
   349 	// Show the soft notification.
       
   350 	HbNotificationDialog *notificationDialog = new HbNotificationDialog();
       
   351 	notificationDialog->setTimeout(
       
   352 			HbNotificationDialog::ConfirmationNoteTimeout);
       
   353 	notificationDialog->setTitle(
       
   354 			hbTrId("txt_notes_dpopinfo_note_moved_to_todos"));
       
   355 	notificationDialog->show();
   360 }
   356 }
   361 
   357 
   362 /*!
   358 /*!
   363 	Slot to handle the signal editingCompleted by the notes editor.
   359 	Slot to handle the signal editingCompleted by the notes editor.
   364 
   360 
   435 			this, SLOT(handleEditingCompleted(bool)));
   431 			this, SLOT(handleEditingCompleted(bool)));
   436 
   432 
   437 	// Launch the notes editor with the obtained info.
   433 	// Launch the notes editor with the obtained info.
   438 	mNotesEditor->edit(entry);
   434 	mNotesEditor->edit(entry);
   439 }
   435 }
       
   436 
       
   437 /*!
       
   438 	Slot to handle context menu actions.
       
   439  */
       
   440 void NotesNoteView::selectedMenuAction(HbAction *action)
       
   441 {
       
   442 	if (action == mOpenAction) {
       
   443 		openNote();
       
   444 	} else if (action == mDeleteAction) {
       
   445 		deleteNote();
       
   446 	} else if (action == mMakeFavouriteAction) {
       
   447 		markNoteAsFavourite();
       
   448 	} else if (action == mMarkTodoAction) {
       
   449 		markNoteAsTodo();
       
   450 	}
       
   451 }
       
   452 
       
   453 /*!
       
   454 	Slot to handle the context menu closed.
       
   455  */
       
   456 void NotesNoteView::handleMenuClosed()
       
   457 {
       
   458 	mIsLongTop = false;
       
   459 }
   440 // End of file	--Don't remove this.
   460 // End of file	--Don't remove this.
   441 
   461