Home · All Classes · Main Classes · Deprecated

mlist.cpp

Go to the documentation of this file.
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 libmeegotouch.
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 <QVector>
00021 #include <QGraphicsSceneEvent>
00022 #include <QGraphicsGridLayout>
00023 #include <QItemSelectionModel>
00024 
00025 #include <MDebug>
00026 #include "mlist.h"
00027 #include "mtheme.h"
00028 #include "mbutton.h"
00029 #include "mlist_p.h"
00030 #include "mlabel.h"
00031 #include "mpannableviewport.h"
00032 #include "mlistfilter.h"
00033 
00034 #include "mwidgetcreator.h"
00035 M_REGISTER_WIDGET(MList)
00036 
00037 MListPrivate::MListPrivate() : selectionMode(MList::NoSelection), listFilter(0)
00038 {
00039 }
00040 
00041 MListPrivate::~MListPrivate()
00042 {
00043     delete listFilter;
00044 }
00045 
00046 void MListPrivate::init()
00047 {
00048     Q_Q(MList);
00049 
00050     q->setOptimizationFlags(MList::DontCallCreateCellDuringUpdate);
00051     q->setSelectionMode(MList::NoSelection);
00052     q->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); //grow to available space in both directions
00053 }
00054 
00055 void MListPrivate::updateLongTapConnections()
00056 {
00057     Q_Q(MList);
00058 
00059     if (q->receivers(SIGNAL(itemLongTapped(QModelIndex))) > 0  ||
00060         q->receivers(SIGNAL(itemLongTapped(QModelIndex,QPointF))) > 0) {
00061         q->model()->setLongTapEnabled(true);
00062     } else {
00063         q->model()->setLongTapEnabled(false);
00064     }
00065 }
00066 
00067 MList::MList(MListPrivate *dd, MListModel *model, QGraphicsItem *parent)
00068     : MWidgetController(dd, model, parent)
00069 {
00070     Q_D(MList);
00071     d->init();
00072 }
00073 
00074 MList::MList(QGraphicsItem *parent)
00075     : MWidgetController(new MListPrivate, new MListModel, parent)
00076 
00077 {
00078     Q_D(MList);
00079     d->init();
00080 }
00081 
00082 MList::~MList()
00083 {
00084     delete model()->cellCreator();
00085 }
00086 
00087 void MList::updateData(const QList<const char *>& modifications)
00088 {
00089     const char *member;
00090     for (int i = 0; i < modifications.count(); i++) {
00091         member = modifications[i];
00092         if (member == MListModel::ListIsMoving) {
00093             model()->listIsMoving() ? emit panningStarted() : emit panningStopped();
00094         }
00095     }
00096 }
00097 
00098 void MList::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
00099 {
00100     MWidgetController::contextMenuEvent(event);
00101 }
00102 
00103 void MList::setItemModel(QAbstractItemModel *itemModel)
00104 {
00105     Q_D(MList);
00106     if (d->listFilter && d->listFilter->enabled())
00107         itemModel = d->listFilter->updateItemModel(itemModel);
00108 
00109     setSelectionModel(NULL);
00110 
00111     if (itemModel)
00112         setSelectionModel(new QItemSelectionModel(itemModel));
00113 
00114     model()->setItemModel(itemModel);
00115 }
00116 
00117 
00118 QAbstractItemModel *MList::itemModel() const
00119 {
00120     return model()->itemModel();
00121 }
00122 
00123 void MList::scrollTo(const QModelIndex &index)
00124 {
00125     scrollTo(index, MList::EnsureVisibleHint);
00126 }
00127 
00128 void MList::scrollTo(const QModelIndex &index, ScrollHint hint)
00129 {
00130     emit scrollToIndex(index);
00131 
00132     model()->beginTransaction();
00133     model()->setScrollHint(hint);
00134     model()->setScrollToIndex(index);
00135     model()->commitTransaction();
00136 }
00137 
00138 QItemSelectionModel *MList::selectionModel() const
00139 {
00140     return model()->selectionModel();
00141 }
00142 
00143 void MList::setSelectionModel(QItemSelectionModel *selectionModel)
00144 {
00145     if (selectionModel == this->selectionModel()) {
00146         return;
00147     }
00148 
00149     model()->setSelectionModel(selectionModel);
00150     emit selectionModelChanged(selectionModel);
00151 }
00152 
00153 void MList::selectItem(const QModelIndex &index)
00154 {
00155     QItemSelectionModel *sModel = selectionModel();
00156 
00157     if (index.isValid() && sModel->model() != index.model()) {
00158         qWarning("MList::selectItem() failed: "
00159                  "Trying to select an item that is for"
00160                  " a different model than the view ");
00161         return;
00162     }
00163 
00164     if (sModel != NULL) {
00165         if (selectionMode() == MList::MultiSelection) {
00166             if (sModel->isSelected(index)) {
00167                 sModel->select(index, QItemSelectionModel::Deselect);
00168             } else {
00169                 sModel->select(index, QItemSelectionModel::Select);
00170             }
00171         } else if (selectionMode() == MList::SingleSelection) {
00172             sModel->select(index, QItemSelectionModel::ClearAndSelect);
00173         }
00174     }
00175 
00176     emit itemClicked(index);
00177 }
00178 
00179 void MList::longTapItem(const QModelIndex &index)
00180 {
00181     longTapItem(index, QPointF());
00182 }
00183 
00184 void MList::longTapItem(const QModelIndex &index, const QPointF &position)
00185 {
00186     emit itemLongTapped(index);
00187     emit itemLongTapped(index, position);
00188 }
00189 
00190 void MList::setCellCreator(MCellCreator *itemCreator)
00191 {
00192     delete model()->cellCreator();
00193 
00194     model()->setCellCreator(itemCreator);
00195 }
00196 
00197 const MCellCreator *MList::cellCreator() const
00198 {
00199     return model()->cellCreator();
00200 }
00201 
00202 void MList::setHeaderCreator(MCellCreator *headerCreator)
00203 {
00204     model()->setHeaderCreator(headerCreator);
00205 }
00206 
00207 const MCellCreator *MList::headerCreator() const
00208 {
00209     return model()->headerCreator();
00210 }
00211 
00212 const QModelIndex MList::firstVisibleItem() const
00213 {
00214     return model()->firstVisibleItem();
00215 }
00216 
00217 const QModelIndex MList::lastVisibleItem() const
00218 {
00219     return model()->lastVisibleItem();
00220 }
00221 
00222 bool MList::showGroups() const
00223 {
00224     return model()->showGroups();
00225 }
00226 
00227 void MList::setShowGroups(bool showGroups)
00228 {
00229     model()->setShowGroups(showGroups);
00230 }
00231 
00232 void MList::setIndexVisible(bool visible)
00233 {
00234     if (visible)
00235         setIndexDisplayMode(MList::Show);
00236     else
00237         setIndexDisplayMode(MList::Hide);
00238 }
00239 
00240 void MList::setIndexDisplayMode(MList::DisplayMode displayMode)
00241 {
00242     model()->setListIndexDisplayMode(displayMode);
00243 
00244     if(displayMode == MList::Hide)
00245         model()->setListIndexVisible(false);
00246     else
00247         model()->setListIndexVisible(true);
00248 }
00249 
00250 MList::DisplayMode MList::indexDisplayMode() const
00251 {
00252     return static_cast<MList::DisplayMode>(model()->listIndexDisplayMode());
00253 }
00254 
00255 bool MList::indexVisible()
00256 {
00257     return model()->listIndexVisible();
00258 }
00259 
00260 int MList::columns() const
00261 {
00262     return model()->columns();
00263 }
00264 
00265 void MList::setColumns(int columns)
00266 {
00267     model()->setColumns(columns);
00268 }
00269 
00270 void MList::setSelectionMode(MList::SelectionMode mode)
00271 {
00272     Q_D(MList);
00273     d->selectionMode = mode;
00274 
00275     QItemSelectionModel *sModel = selectionModel();
00276 
00277     if (sModel)
00278         sModel->clearSelection();
00279 }
00280 
00281 MList::SelectionMode MList::selectionMode() const
00282 {
00283     Q_D(const MList);
00284     return d->selectionMode;
00285 }
00286 
00287 MListFilter *MList::filtering() const
00288 {
00289     MListPrivate* d = static_cast<MListPrivate*>(d_ptr);
00290     if (d->listFilter == 0) {
00291         // Postpone the creation of the list filter until it is requested
00292         // to speedup the startup performance
00293         d->listFilter = new MListFilter(const_cast<MList*>(this));
00294         d->listFilter->setEnabled(false);
00295     }
00296     return d->listFilter;
00297 }
00298 
00299 void MList::keyPressEvent(QKeyEvent *event)
00300 {
00301     Q_D(MList);
00302 
00303     if (d->listFilter && d->listFilter->enabled())
00304         d->listFilter->keyPressEvent(event);
00305 }
00306 
00307 void MList::connectNotify(const char *signal)
00308 {
00309     Q_D(MList);
00310     if (QLatin1String(signal) == SIGNAL(itemLongTapped(QModelIndex)) ||
00311         QLatin1String(signal) == SIGNAL(itemLongTapped(QModelIndex,QPointF))) {
00312         d->updateLongTapConnections();
00313     }
00314 }
00315 
00316 void MList::disconnectNotify(const char *signal)
00317 {
00318     Q_D(MList);
00319     if (QLatin1String(signal) == SIGNAL(itemLongTapped(QModelIndex)) ||
00320         QLatin1String(signal) == SIGNAL(itemLongTapped(QModelIndex,QPointF))) {
00321         d->updateLongTapConnections();
00322     }
00323 }
00324 
00325 MList::ListOptimizationFlags MList::optimizationFlags() const
00326 {
00327     Q_D(const MList);
00328     return ListOptimizationFlags(d->optimizationFlags);
00329 }
00330 
00331 void MList::setOptimizationFlag(ListOptimizationFlag optimizationFlag, bool enabled)
00332 {
00333     Q_D(MList);
00334     if (enabled)
00335         setOptimizationFlags(ListOptimizationFlags(d->optimizationFlags) | optimizationFlag);
00336     else
00337         setOptimizationFlags(ListOptimizationFlags(d->optimizationFlags) & ~optimizationFlag);
00338 }
00339 
00340 void MList::setOptimizationFlags(ListOptimizationFlags optimizationFlags)
00341 {
00342     Q_D(MList);
00343     d->optimizationFlags = optimizationFlags;
00344 }

Copyright © 2010 Nokia Corporation Generated on Thu Nov 4 2010 18:14:21 (PDT)
Doxygen 1.7.1
MeeGo Touch