notes/notesui/notesviews/src/notesmainview.cpp
changeset 26 a949c2543c15
parent 23 fd30d51f876b
child 49 5de72ea7a065
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 NotesMainView::NotesMainView(QGraphicsWidget *parent)
    57 NotesMainView::NotesMainView(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 /*!
   120 	connect(
   121 	connect(
   121 			mNotesModel, SIGNAL(rowAdded(QModelIndex)),
   122 			mNotesModel, SIGNAL(rowAdded(QModelIndex)),
   122 			this, SLOT(scrollTo(QModelIndex)));
   123 			this, SLOT(scrollTo(QModelIndex)));
   123 
   124 
   124 	// Get the view heading label
   125 	// Get the view heading label
   125 	mViewHeading = static_cast<HbLabel *> (
   126 /*	mViewHeading = static_cast<HbLabel *> (
       
   127 			mDocLoader->findWidget("viewHeading"));*/
       
   128 
       
   129 	mSubTitle = static_cast<HbGroupBox *>(
   126 			mDocLoader->findWidget("viewHeading"));
   130 			mDocLoader->findWidget("viewHeading"));
   127 
   131 
       
   132 	// Handles the orientation change for list items
       
   133 	HbMainWindow *window = hbInstance->allMainWindows().first();
       
   134 	handleOrientationChanged(window->orientation());
       
   135 	connect(
       
   136 			window, SIGNAL(orientationChanged(Qt::Orientation)),
       
   137 			this, SLOT(handleOrientationChanged(Qt::Orientation)));
       
   138 
       
   139 	// Set the graphics size for the icons.
       
   140 	HbListViewItem *prototype = mListView->listItemPrototype();
       
   141 	prototype->setGraphicsSize(HbListViewItem::SmallIcon);
       
   142 }
       
   143 
       
   144 void NotesMainView::setupAfterViewReady()
       
   145 {
   128 	// Get the toolbar/menu actions.
   146 	// Get the toolbar/menu actions.
   129 	mAddNoteAction = static_cast<HbAction *> (
   147 	mAddNoteAction = static_cast<HbAction *> (
   130 			mDocLoader->findObject("newNoteAction"));
   148 			mDocLoader->findObject("newNoteAction"));
   131 	Q_ASSERT_X(
   149 	Q_ASSERT_X(
   132 			mAddNoteAction,
   150 			mAddNoteAction,
   157 
   175 
   158 	connect(
   176 	connect(
   159 			mViewCollectionAction, SIGNAL(triggered()),
   177 			mViewCollectionAction, SIGNAL(triggered()),
   160 			this, SLOT(displayCollectionView()));
   178 			this, SLOT(displayCollectionView()));
   161 
   179 
   162 	mSubTitle = static_cast<HbGroupBox *>(
       
   163 			mDocLoader->findWidget("viewHeading"));
       
   164 
       
   165 	// Handles the orientation change for list items
       
   166 	HbMainWindow *window = hbInstance->allMainWindows().first();
       
   167 	handleOrientationChanged(window->orientation());
       
   168 	connect(
       
   169 			window, SIGNAL(orientationChanged(Qt::Orientation)),
       
   170 			this, SLOT(handleOrientationChanged(Qt::Orientation)));
       
   171 
       
   172 	// Update sub heading text for main view.
       
   173 	updateSubTitle();
       
   174 
       
   175 	connect(
   180 	connect(
   176 			mAgendaUtil, SIGNAL(entryAdded(ulong)),
   181 			mAgendaUtil, SIGNAL(entryAdded(ulong)),
   177 			this,SLOT(updateSubTitle(ulong)));
   182 			this,SLOT(updateSubTitle(ulong)));
   178 	connect(
   183 	connect(
   179 			mAgendaUtil, SIGNAL(entryDeleted(ulong)),
   184 			mAgendaUtil, SIGNAL(entryDeleted(ulong)),
   180 			this,SLOT(updateSubTitle(ulong)));
   185 			this,SLOT(updateSubTitle(ulong)));
   181 	connect(
   186 	connect(
   182 			mAgendaUtil, SIGNAL(entryUpdated(ulong)),
   187 			mAgendaUtil, SIGNAL(entryUpdated(ulong)),
   183 			this, SLOT(updateSubTitle(ulong)));
   188 			this, SLOT(updateSubTitle(ulong)));
   184 
   189 }
   185 	// Set the graphics size for the icons.
   190 
   186 	HbListViewItem *prototype = mListView->listItemPrototype();
   191 /*
   187 	prototype->setGraphicsSize(HbListViewItem::SmallIcon);
   192 	Updates the title text for the first launch
       
   193  */
       
   194 void NotesMainView::updateTitle()
       
   195 {
       
   196 	updateSubTitle();
   188 }
   197 }
   189 
   198 
   190 /*!
   199 /*!
   191 	Slot which gets called when `+ New note' action is triggered from the view
   200 	Slot which gets called when `+ New note' action is triggered from the view
   192 	toolbar. This is responsible for launching the editor to create a new note.
   201 	toolbar. This is responsible for launching the editor to create a new note.
   210 	\param index Reference to the QModelIndex representing the view item.
   219 	\param index Reference to the QModelIndex representing the view item.
   211 	\sa HbAbstractViewItem
   220 	\sa HbAbstractViewItem
   212  */
   221  */
   213 void NotesMainView::handleItemReleased(const QModelIndex &index)
   222 void NotesMainView::handleItemReleased(const QModelIndex &index)
   214 {
   223 {
   215 	// Sanity check.
   224 	if(!mIsLongTop) {
   216 	if (!index.isValid()) {
   225 		// Sanity check.
   217 		return;
   226 		if (!index.isValid()) {
   218 	}
   227 			return;
   219 
   228 		}
   220 	// First get the id of the note and get the corresponding information from
   229 
   221 	// agendautil.
   230 		// First get the id of the note and get the corresponding information from
   222 	ulong noteId = index.data(NotesNamespace::IdRole).value<qulonglong>();
   231 		// agendautil.
   223 
   232 		ulong noteId = index.data(NotesNamespace::IdRole).value<qulonglong>();
   224 	if (0 >= noteId) {
   233 
   225 		// Something wrong.
   234 		if (0 >= noteId) {
   226 		return;
   235 			// Something wrong.
   227 	}
   236 			return;
   228 
   237 		}
   229 	// Get the entry details.
   238 
   230 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   239 		// Get the entry details.
   231 	if (entry.isNull()) {
   240 		AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   232 		// Entry invalid.
   241 		if (entry.isNull()) {
   233 		return;
   242 			// Entry invalid.
   234 	}
   243 			return;
   235 
   244 		}
   236 	if(AgendaEntry::TypeTodo == entry.type()) {
   245 
   237 		// Construct agenda event viewer.
   246 		if(AgendaEntry::TypeTodo == entry.type()) {
   238 		mAgendaEventViewer = new AgendaEventViewer(mAgendaUtil, this);
   247 			// Construct agenda event viewer.
   239 
   248 			mAgendaEventViewer = new AgendaEventViewer(mAgendaUtil, this);
   240 		connect(
   249 
   241 				mAgendaEventViewer, SIGNAL(viewingCompleted(const QDate)),
   250 			connect(
   242 				this, SLOT(handleViewingCompleted()));
   251 					mAgendaEventViewer, SIGNAL(viewingCompleted(const QDate)),
   243 		// Launch agenda event viewer
   252 					this, SLOT(handleViewingCompleted()));
   244 		mAgendaEventViewer->view(
   253 			// Launch agenda event viewer
   245 				entry, AgendaEventViewer::ActionEditDelete);
   254 			mAgendaEventViewer->view(
   246 	}else if(AgendaEntry::TypeNote == entry.type()) {
   255 					entry, AgendaEventViewer::ActionEditDelete);
   247 		// Construct notes editor.
   256 		}else if(AgendaEntry::TypeNote == entry.type()) {
   248 		mNotesEditor = new NotesEditor(mAgendaUtil, this);
   257 			// Construct notes editor.
   249 		connect(
   258 			mNotesEditor = new NotesEditor(mAgendaUtil, this);
   250 				mNotesEditor, SIGNAL(editingCompleted(bool)),
   259 			connect(
   251 				this, SLOT(handleEditingCompleted(bool)));
   260 					mNotesEditor, SIGNAL(editingCompleted(bool)),
   252 
   261 					this, SLOT(handleEditingCompleted(bool)));
   253 		// Launch the notes editor with the obtained info.
   262 
   254 		mNotesEditor->edit(entry);
   263 			// Launch the notes editor with the obtained info.
       
   264 			mNotesEditor->edit(entry);
       
   265 		}
   255 	}
   266 	}
   256 }
   267 }
   257 
   268 
   258 /*!
   269 /*!
   259 	Displays a list item specific context menu.
   270 	Displays a list item specific context menu.
   264 	\sa HbAbstractViewItem, HbListView, HbMenu.
   275 	\sa HbAbstractViewItem, HbListView, HbMenu.
   265  */
   276  */
   266 void NotesMainView::handleItemLongPressed(
   277 void NotesMainView::handleItemLongPressed(
   267 		HbAbstractViewItem *item, const QPointF &coords)
   278 		HbAbstractViewItem *item, const QPointF &coords)
   268 {
   279 {
       
   280 	mIsLongTop = true;
   269 	mSelectedItem = item;
   281 	mSelectedItem = item;
   270 
   282 
   271 	ulong noteId = item->modelIndex().data(
   283 	ulong noteId = item->modelIndex().data(
   272 			NotesNamespace::IdRole).value<qulonglong>();
   284 			NotesNamespace::IdRole).value<qulonglong>();
   273 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   285 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   274 
   286 
   275 	// Display a context specific menu.
   287 	// Display a context specific menu.
   276 	HbMenu *contextMenu = new HbMenu();
   288 	HbMenu *contextMenu = new HbMenu();
       
   289 	connect(
       
   290 			contextMenu,SIGNAL(aboutToClose()),
       
   291 			this, SLOT(handleMenuClosed()));
       
   292 
   277 	mOpenAction =
   293 	mOpenAction =
   278 			contextMenu->addAction(hbTrId("txt_common_menu_open"));
   294 			contextMenu->addAction(hbTrId("txt_common_menu_open"));
   279 	connect(
       
   280 			mOpenAction, SIGNAL(triggered()),
       
   281 			this, SLOT(openNote()));
       
   282 
   295 
   283 	// Add actions to the context menu.
   296 	// Add actions to the context menu.
   284 	if (AgendaEntry::TypeTodo == entry.type()) {
   297 	if (AgendaEntry::TypeTodo == entry.type()) {
   285 		mEditTodoAction =
   298 		mEditTodoAction =
   286 				contextMenu->addAction(hbTrId("txt_common_menu_edit"));
   299 				contextMenu->addAction(hbTrId("txt_common_menu_edit"));
   287 		connect(
       
   288 				mEditTodoAction, SIGNAL(triggered()),
       
   289 				this, SLOT(editTodo()));
       
   290 	}
   300 	}
   291 
   301 
   292 	mDeleteAction =
   302 	mDeleteAction =
   293 			contextMenu->addAction(hbTrId("txt_common_menu_delete"));
   303 			contextMenu->addAction(hbTrId("txt_common_menu_delete"));
   294 	connect(
       
   295 			mDeleteAction, SIGNAL(triggered()),
       
   296 			this, SLOT(deleteNote()));
       
   297 
   304 
   298 	if (AgendaEntry::TypeNote == entry.type()) {
   305 	if (AgendaEntry::TypeNote == entry.type()) {
   299 		if (entry.favourite()) {
   306 		if (entry.favourite()) {
   300 			mMakeFavouriteAction = contextMenu->addAction(
   307 			mMakeFavouriteAction = contextMenu->addAction(
   301 					hbTrId("txt_notes_menu_remove_from_favorites"));
   308 					hbTrId("txt_notes_menu_remove_from_favorites"));
   302 
       
   303 			connect(
       
   304 					mMakeFavouriteAction, SIGNAL(triggered()),
       
   305 					this, SLOT(markNoteAsFavourite()));
       
   306 
       
   307 		} else {
   309 		} else {
   308 			mMakeFavouriteAction = contextMenu->addAction(
   310 			mMakeFavouriteAction = contextMenu->addAction(
   309 					hbTrId("txt_notes_menu_mark_as_favorite"));
   311 					hbTrId("txt_notes_menu_mark_as_favorite"));
   310 
       
   311 			connect(
       
   312 					mMakeFavouriteAction, SIGNAL(triggered()),
       
   313 					this, SLOT(markNoteAsFavourite()));
       
   314 		}
   312 		}
   315 
   313 
   316 		mMarkTodoAction =
   314 		mMarkTodoAction =
   317 				contextMenu->addAction(
   315 				contextMenu->addAction(
   318 						hbTrId("txt_notes_menu_make_it_as_todo_note"));
   316 						hbTrId("txt_notes_menu_make_it_as_todo_note"));
   319 		connect(
       
   320 				mMarkTodoAction, SIGNAL(triggered()),
       
   321 				this, SLOT(markNoteAsTodo()));
       
   322 
   317 
   323 	} else if (AgendaEntry::TypeTodo == entry.type()) {
   318 	} else if (AgendaEntry::TypeTodo == entry.type()) {
   324 		if (AgendaEntry::TodoNeedsAction == entry.status()) {
   319 		if (AgendaEntry::TodoNeedsAction == entry.status()) {
   325 			mTodoStatusAction = contextMenu->addAction(
   320 			mTodoStatusAction = contextMenu->addAction(
   326 					hbTrId("txt_notes_menu_mark_as_done"));
   321 					hbTrId("txt_notes_menu_mark_as_done"));
   327 
       
   328 			connect(
       
   329 					mTodoStatusAction , SIGNAL(triggered()),
       
   330 					this, SLOT(markTodoStatus()));
       
   331 
       
   332 		} else if (AgendaEntry::TodoCompleted == entry.status()) {
   322 		} else if (AgendaEntry::TodoCompleted == entry.status()) {
   333 			mTodoStatusAction = contextMenu->addAction(
   323 			mTodoStatusAction = contextMenu->addAction(
   334 					hbTrId("txt_notes_menu_mark_as_not_done"));
   324 					hbTrId("txt_notes_menu_mark_as_not_done"));
   335 
       
   336 			connect(
       
   337 					mTodoStatusAction , SIGNAL(triggered()),
       
   338 					this, SLOT(markTodoStatus()));
       
   339 		}
   325 		}
   340 	}
   326 	}
   341 
   327 
   342 	// Show the menu.
   328 	// Show the menu.
   343 	contextMenu->exec(coords);
   329 	contextMenu->open(this, SLOT(selectedMenuAction(HbAction*)));
   344 
   330 	contextMenu->setPreferredPos(coords);
   345 }
   331 }
   346 
   332 
   347 /*!
   333 /*!
   348 	Slot to delete a selected note.
   334 	Slot to delete a selected note.
   349  */
   335  */
   451 
   437 
   452 	\param status Indicates the status of viewing
   438 	\param status Indicates the status of viewing
   453  */
   439  */
   454 void NotesMainView::handleViewingCompleted()
   440 void NotesMainView::handleViewingCompleted()
   455 {
   441 {
   456 
       
   457 
       
   458 	mAgendaEventViewer->deleteLater();
   442 	mAgendaEventViewer->deleteLater();
   459 
       
   460 }
   443 }
   461 
   444 
   462 /*!
   445 /*!
   463 	Slot to handle the case when the state of an action has changed.
   446 	Slot to handle the case when the state of an action has changed.
   464  */
   447  */
   471 	Launches the to-do editor to edit the to-do entry
   454 	Launches the to-do editor to edit the to-do entry
   472  */
   455  */
   473 
   456 
   474 void NotesMainView::editTodo()
   457 void NotesMainView::editTodo()
   475 {
   458 {
   476 
       
   477 	// Get the selected list item index
   459 	// Get the selected list item index
   478 	QModelIndex index = mSelectedItem->modelIndex();
   460 	QModelIndex index = mSelectedItem->modelIndex();
   479 	if (!index.isValid()) {
   461 	if (!index.isValid()) {
   480 		return;
   462 		return;
   481 	}
   463 	}
   617 		// Launch agenda event viewer
   599 		// Launch agenda event viewer
   618 		mAgendaEventViewer->view(
   600 		mAgendaEventViewer->view(
   619 				entry, AgendaEventViewer::ActionEditDelete);
   601 				entry, AgendaEventViewer::ActionEditDelete);
   620 	}
   602 	}
   621 }
   603 }
       
   604 
       
   605 /*!
       
   606 	 Slot to handle the selected context menu actions
       
   607  */
       
   608 void NotesMainView::selectedMenuAction(HbAction *action)
       
   609 {
       
   610 	if (action == mOpenAction) {
       
   611 		openNote();
       
   612 	} else if (action == mEditTodoAction) {
       
   613 		editTodo();
       
   614 	} else if (action == mDeleteAction) {
       
   615 		deleteNote();
       
   616 	} else if (action == mMakeFavouriteAction) {
       
   617 		markNoteAsFavourite();
       
   618 	} else if (action == mMarkTodoAction) {
       
   619 		markNoteAsTodo();
       
   620 	} else if (action == mTodoStatusAction) {
       
   621 		markTodoStatus();
       
   622 	}
       
   623 }
       
   624 
       
   625 /*!
       
   626 	Slot to handle the context menu closed.
       
   627  */
       
   628 void NotesMainView::handleMenuClosed()
       
   629 {
       
   630 	mIsLongTop = false;
       
   631 }
       
   632 
   622 // End of file	--Don't remove this.
   633 // End of file	--Don't remove this.