| Home · All Namespaces · All Classes |
00001 /*************************************************************************** 00002 ** 00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 00004 ** All rights reserved. 00005 ** Contact: Nokia Corporation (directui@nokia.com) 00006 ** 00007 ** This file is part of mhome. 00008 ** 00009 ** If you have questions regarding the use of this file, please contact 00010 ** Nokia at directui@nokia.com. 00011 ** 00012 ** This library is free software; you can redistribute it and/or 00013 ** modify it under the terms of the GNU Lesser General Public 00014 ** License version 2.1 as published by the Free Software Foundation 00015 ** and appearing in the file LICENSE.LGPL included in the packaging 00016 ** of this file. 00017 ** 00018 ****************************************************************************/ 00019 00020 #include "launcherview.h" 00021 #include "launcher.h" 00022 #include "launchermodel.h" 00023 #include "launcherbutton.h" 00024 #include "pagedviewport.h" 00025 #include "mainwindow.h" 00026 #include "mpositionindicator.h" 00027 #include "pagepositionindicatorview.h" 00028 #include <MLayout> 00029 #include <MLinearLayoutPolicy> 00030 #include <MOverlay> 00031 #include <MButton> 00032 #include <MApplication> 00033 #include <MSceneManager> 00034 00035 LauncherView::LauncherView(Launcher *controller) : 00036 MWidgetView(controller), 00037 layout(new MLayout), 00038 policy(new MLinearLayoutPolicy(layout, Qt::Horizontal)), 00039 pannedWidget(new MWidget) 00040 { 00041 layout->setContentsMargins(0, 0, 0, 0); 00042 pannedWidget->setLayout(layout); 00043 00044 pagedViewport = new PagedViewport(controller); 00045 00046 pagedViewport->positionIndicator()->setObjectName("LauncherPageIndicator"); 00047 00048 pagedViewport->setWidget(pannedWidget); 00049 pagedViewport->setObjectName("LauncherPagedViewport"); 00050 pagedViewport->setPanDirection(Qt::Horizontal); 00051 00052 connect(controller, SIGNAL(panningRequested(uint)), this, SLOT(panToPage(uint))); 00053 connect(controller, SIGNAL(focusToPageRequested(uint)), this, SLOT(focusToPage(uint))); 00054 connect(controller, SIGNAL(focusToButtonRequested(const QString &)), this, SLOT(focusToButton(const QString&))); 00055 } 00056 00057 LauncherView::~LauncherView() 00058 { 00059 // remove pages from layout to avoid multi deletion (pages are in model as QSharedPointer's) 00060 foreach (QSharedPointer<LauncherPage> page, model()->launcherPages()) { 00061 removePageFromLayout(page.data()); 00062 } 00063 } 00064 00065 void LauncherView::updateData(const QList<const char *>& modifications) 00066 { 00067 MWidgetView::updateData(modifications); 00068 const char *member; 00069 foreach(member, modifications) { 00070 if (member == LauncherModel::LauncherPages) { 00071 updateLayoutFromModel(); 00072 00073 pagedViewport->updatePageCount(model()->launcherPages().count()); 00074 } 00075 } 00076 } 00077 00078 void LauncherView::updateLayoutFromModel() 00079 { 00080 // Set of pages in layout 00081 QSet<LauncherPage *> layoutPages; 00082 for (int i = 0; i < layout->count(); i++) { 00083 layoutPages.insert(static_cast<LauncherPage *>(layout->itemAt(i))); 00084 } 00085 00086 // List of pages in model (list needed for the order of pages) 00087 QList<LauncherPage *> modelPagesList; 00088 foreach(QSharedPointer<LauncherPage> modelPage, model()->launcherPages()) { 00089 modelPagesList.append(modelPage.data()); 00090 } 00091 // Set of pages in model 00092 QSet<LauncherPage *> modelPagesSet(modelPagesList.toSet()); 00093 00094 // Remove from layout the pages that doesn't exists any more in model 00095 QSet<LauncherPage *> deletedPages = layoutPages - modelPagesSet; 00096 foreach (LauncherPage *deletedPage, deletedPages) { 00097 removePageFromLayout(deletedPage); 00098 } 00099 00100 // Get pages that are new in model to a map (with model list index as a key) for sorting 00101 QSet<LauncherPage *> newPages = modelPagesSet - layoutPages; 00102 QMap<int, LauncherPage *> newPagesSorted; 00103 foreach (LauncherPage *addedPage, newPages) { 00104 newPagesSorted.insert(modelPagesList.indexOf(addedPage), addedPage); 00105 } 00106 00107 // Add new pages to layout in sorted order 00108 QMapIterator<int, LauncherPage *> iter(newPagesSorted); 00109 while (iter.hasNext()) { 00110 iter.next(); 00111 policy->insertItem(iter.key(), iter.value()); 00112 } 00113 } 00114 00115 void LauncherView::panToPage(uint page) 00116 { 00117 pagedViewport->panToPage(page); 00118 } 00119 00120 void LauncherView::focusToPage(uint page) 00121 { 00122 pagedViewport->setPage(page); 00123 } 00124 00125 void LauncherView::focusToButton(const QString &desktopFileEntry) 00126 { 00127 int pageNum = -1; 00128 uint pageIndex = 0; 00129 QList<QSharedPointer<LauncherPage> > pages = model()->launcherPages(); 00130 foreach (QSharedPointer<LauncherPage> page, pages) { 00131 if (page->launcherButtonPosition(desktopFileEntry) >= 0) { 00132 pageNum = pageIndex; 00133 break; 00134 } 00135 pageIndex++; 00136 } 00137 if (pageNum >= 0) { 00138 pagedViewport->setPage(pageNum); 00139 } 00140 } 00141 00142 void LauncherView::removePageFromLayout(LauncherPage *page) 00143 { 00144 layout->removeItem(page); 00145 // set parent to NULL to avoid double deletion as items are as QSharedPointers in model 00146 page->setParentItem(0); 00147 } 00148 00149 M_REGISTER_VIEW_NEW(LauncherView, Launcher)
| Copyright © 2010 Nokia Corporation | Generated on Thu Nov 4 2010 18:20:42 Doxygen 1.7.1 |
MeeGo Touch |