aboutsummaryrefslogtreecommitdiff
path: root/demos/widgetsgallery/mlistpage.cpp
blob: bf699ebb378a47ee30091e7ee6e35864aa76a4c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include "mlistpage.h"

#include <QDir>
#include <QTime>
#include <QGraphicsLinearLayout>
#include <QGraphicsGridLayout>
#include <QTextCodec>


#include <MLayout>
#include <MLinearLayoutPolicy>
#include <MAbstractCellCreator>
#include <MLocale>
#include <MList>
#include <MLabel>
#include <MImageWidget>
#include <MButton>
#include <MTheme>
#include <MAction>
#include <MSortFilterProxyModel>
#include <MDialog>
#include <MSceneManager>
#include <MObjectMenu>

#include <MComboBox>
#include <MDebug>

#include <MWidgetAction>

#include "phonebookcell.h"
#include "phonebookheader.h"

#include <MListFilter>
#include <MTextEdit>
#include <MPannableViewport>

#include "utils.h"

#include "phonebookmodel.h"

MListPage::MListPage()
  : TemplatePage(TemplatePage::ListsGridsAndPopups),
    model(NULL),
    proxyModel(NULL),
    imageLoader(NULL),
    comboListMode(NULL),
    objectMenu(NULL),
    objectMenuHolder(NULL),
    actionAdvancedConfiguration(NULL),
    dialogAdvancedConfiguration(NULL),
    list(NULL),
    cellCreator(NULL),
    longTappedIndex(),
    currentSortingIndex(0),
    currentListModeIndex(0)
{
}

MListPage::~MListPage()
{
    delete model;
    delete imageLoader;
}

QString MListPage::timedemoTitle()
{
    return "List";
}

class MListAdvancedCustomHeaderCreator : public MAbstractCellCreator<PhoneBookHeader>
{
public:
    void updateCell(const QModelIndex &index, MWidget *cell) const {
        PhoneBookHeader *header = qobject_cast<PhoneBookHeader*>(cell);
        QString title = index.data(Qt::DisplayRole).toString();

        header->setGroupTitle(title);
        header->setGroupCount(index.model()->rowCount(index));
    }

    QSizeF cellSize() const {
        return QSizeF(-1, 100);
    }
};

class MListCustomHeaderCreator : public MAbstractCellCreator<MButton>
{
public:
    void updateCell(const QModelIndex &index, MWidget *cell) const {
        MButton *header = qobject_cast<MButton*>(cell);
        QString title = index.data(Qt::DisplayRole).toString();

        header->setText(title);
    }
};

class MListContentItemCreator : public MAbstractCellCreator<PhoneBookCell>
{
public:
    MListContentItemCreator() : amountOfColumns(1), highlightText("") {
    }

    MWidget *createCell(const QModelIndex &index, MWidgetRecycler &recycler) const
    {
        // FIXME: It's a workaround against a bug, that if the layout is created and
        // set in constructor then the pixmaps are properly loaded.
        PhoneBookCell *cell = dynamic_cast<PhoneBookCell *>(recycler.take(PhoneBookCell::staticMetaObject.className()));
        if (cell == NULL) {
            cell = new PhoneBookCell;
        }
        updateCell(index, cell);
        return cell;
    }

    void updateCell(const QModelIndex &index, MWidget *cell) const {
        PhoneBookCell *listCell = qobject_cast<PhoneBookCell*>(cell);
        if (listCell == NULL) // TODO This is shouldn't happen, list must know what it doing, but with multiple columns it happens sometimes
            return;

        QVariant data = index.data(Qt::DisplayRole);
        PhoneBookEntry *entry = static_cast<PhoneBookEntry *>(data.value<void *>());

        if(highlightText == "") {
            listCell->setTitle(entry->fullName);
        } else {
            QString highlightedTitle = entry->fullName;
            int matchingIndex = highlightedTitle.indexOf(highlightText, 0, Qt::CaseInsensitive);
            if(matchingIndex != -1) {
                highlightedTitle.insert(matchingIndex+highlightText.length(), "</b>");
                highlightedTitle.insert(matchingIndex, "<b>");
            }
            listCell->setTitle(highlightedTitle);
        }

        listCell->setSubtitle(entry->phoneNumber);
        listCell->setImage(entry->thumbnail);

        updateContentItemMode(index, listCell);
    }

    void updateContentItemMode(const QModelIndex &index, MListItem *contentItem) const {
        int flatRow = index.row();
        int row = flatRow / amountOfColumns;
        int column = flatRow % amountOfColumns;
        int totalItems = index.model()->rowCount(index.parent());

        int columns = amountOfColumns;
        int rows = totalItems / amountOfColumns;
        if (totalItems % amountOfColumns)
            rows += 1;

        bool last = (row == (rows - 1) && flatRow == (totalItems - 1));

        if (columns == 1) {
            if (rows > 1){
                if (row == 0)
                    contentItem->setLayoutPosition(M::VerticalTopPosition);
                else if (row < rows - 1)
                    contentItem->setLayoutPosition(M::VerticalCenterPosition);
                else
                    contentItem->setLayoutPosition(M::VerticalBottomPosition);
            } else {
                contentItem->setLayoutPosition(M::DefaultPosition);
            }
        } else if (columns > 1) {
            if (rows > 1) {
                if (row == 0) {
                    if (column == 0)
                        contentItem->setLayoutPosition(M::TopLeftPosition);
                    else if (column > 0 && column < columns - 1 && !last)
                        contentItem->setLayoutPosition(M::TopCenterPosition);
                    else
                        contentItem->setLayoutPosition(M::TopRightPosition);
                } else if (row < rows - 1) {
                    if (column == 0)
                        contentItem->setLayoutPosition(M::CenterLeftPosition);
                    else if (column > 0 && column < columns - 1 && !last)
                        contentItem->setLayoutPosition(M::CenterPosition);
                    else if (flatRow + columns > totalItems)
                        contentItem->setLayoutPosition(M::BottomRightPosition);
                    else
                        contentItem->setLayoutPosition(M::CenterRightPosition);
                }
                else {
                    if (column == 0)
                        contentItem->setLayoutPosition(M::BottomLeftPosition);
                    else if (column > 0 && column < columns - 1 && !last)
                        contentItem->setLayoutPosition(M::BottomCenterPosition);
                    else
                        contentItem->setLayoutPosition(M::BottomRightPosition);
                }
            } else {
                if (column == 0)
                    contentItem->setLayoutPosition(M::HorizontalLeftPosition);
                else if (column > 0 && column < columns - 1 && !last)
                    contentItem->setLayoutPosition(M::HorizontalCenterPosition);
                else
                    contentItem->setLayoutPosition(M::HorizontalRightPosition);
            }
        }
    }

    void setColumns(int columns) {
        Q_ASSERT(columns > 0 && columns < 5);
        amountOfColumns = columns;
    }

    void highlightByText(QString text) {
        highlightText = text;
    }

private:
    int amountOfColumns;
    QString highlightText;
};

void MListPage::loadPicturesInVisibleItems()
{
    imageLoader->loadPictures(list->firstVisibleItem(), list->lastVisibleItem());
}

void MListPage::setPlainListModel()
{
    cellCreator = new MListContentItemCreator();
    list->setCellCreator(cellCreator);

    model = new PhoneBookModel();

    proxyModel = new MSortFilterProxyModel();
    proxyModel->setSortRole(PhoneBookModel::PhoneBookSortRole);
    proxyModel->setFilterRole(PhoneBookModel::PhoneBookFilterRole);
    proxyModel->setSourceModel(model);


    list->setItemModel(proxyModel);

    imageLoader = new PhoneBookImageLoader;

    // when list is moving we shouldn't do any processing, which may happen
    connect(list, SIGNAL(panningStarted()), imageLoader, SLOT(stopLoadingPictures()));
    // when list is stopped, lets load pictures if needed
    connect(list, SIGNAL(panningStopped()), this, SLOT(loadPicturesInVisibleItems()));
    // when list is moving hide empty live filtering editor
    connect(list, SIGNAL(panningStarted()), this, SLOT(hideEmptyTextEdit()));
    // trigger initial pictures loading
    QTimer::singleShot(1500, this, SLOT(loadPicturesInVisibleItems()));


    changeAmountOfItemInList(3);
}

MComboBox *MListPage::createComboBoxAction(const QString &title, const QStringList &itemsList)
{
    MWidgetAction *widgetAction = new MWidgetAction(centralWidget());
    widgetAction->setLocation(MAction::ApplicationMenuLocation);
    MComboBox *comboBox = new MComboBox;
    comboBox->setTitle(title);
    comboBox->setIconVisible(false);
    comboBox->addItems(itemsList);
    comboBox->setCurrentIndex(0);
    widgetAction->setWidget(comboBox);
    addAction(widgetAction);

    return comboBox;
}

MComboBox *MListPage::createComboBoxLabelButton(const QString &title, const QStringList &itemsList, QGraphicsWidget *parent)
{
    MComboBox *comboBox = new MComboBox(parent);
    comboBox->setViewType("labelButton");
    comboBox->setTitle(title);
    comboBox->setIconVisible(false);
    comboBox->addItems(itemsList);
    comboBox->setCurrentIndex(0);

    return comboBox;
}

void MListPage::createActions()
{
    MComboBox *combo;

    // Uncomment to see actions for showing scrollTo function
    /*
    MAction * action = new MAction("Top", centralWidget());
    connect(action, SIGNAL(triggered()), this, SLOT(scrollToTop()));
    action->setLocation(MAction::ToolBarLocation);
    addAction(action);

    action = new MAction("Bottom", centralWidget());
    connect(action, SIGNAL(triggered()), this, SLOT(scrollToBottom()));
    action->setLocation(MAction::ToolBarLocation);
    addAction(action);
    */

    QStringList amountOfItemsList;
    amountOfItemsList << "50 items" << "100 items" << "200 items" << "1000 items";
    combo = createComboBoxAction("Items in model", amountOfItemsList);
    combo->setCurrentIndex(3); // by default create 1000 items
    connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(changeAmountOfItemInList(int)));

    QStringList sortingOrderList;
    sortingOrderList << "None" << "Ascending" << "Descending";
    combo = createComboBoxAction("Sort", sortingOrderList);
    connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(changeSortingOrder(int)));

    QStringList listModeList;
    listModeList << "Plain" << "Grouped";
    comboListMode = createComboBoxAction("List mode", listModeList);
    connect(comboListMode, SIGNAL(currentIndexChanged(int)), this, SLOT(changeListMode(int)));

    QStringList amountOfColumnList;
    amountOfColumnList << "1 column" << "2 columns" << "3 columns" << "4 columns";
    combo = createComboBoxAction("Amount of columns", amountOfColumnList);
    connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(changeAmountOfColumns(int)));

    QStringList selectionModes;
    selectionModes << "None" << "Single" << "Multi";
    combo = createComboBoxAction("Selection mode", selectionModes);
    connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(changeSelectionMode(int)));

    actionAdvancedConfiguration = new MAction(centralWidget());
    actionAdvancedConfiguration->setLocation(MAction::ApplicationMenuLocation);
    actionAdvancedConfiguration->setText("Advanced Configuration");
    addAction(actionAdvancedConfiguration);
    connect(actionAdvancedConfiguration, SIGNAL(triggered()), SLOT(showAdvancedConfigurationDialog()));
}

void MListPage::scrollToBottom()
{
    list->scrollTo(model->index(model->rowCount() - 1, 0), MList::EnsureVisibleHint);
}

void MListPage::scrollToTop()
{
    list->scrollTo(model->index(0, 0), MList::EnsureVisibleHint);
}

void MListPage::changeSortingOrder(int index)
{
    switch (index) {
    case None:
        break;
    case Ascending:
        proxyModel->sort(0, Qt::AscendingOrder);
        break;
    case Descending:
        proxyModel->sort(0, Qt::DescendingOrder);
        break;
    }
    currentSortingIndex = index;
    QTimer::singleShot(1500, this, SLOT(loadPicturesInVisibleItems()));
}

void MListPage::changeAmountOfItemInList(int index)
{
    Q_ASSERT(index >= 0 && index < 4);

    if(currentListModeIndex == Grouped) {
        list->setShowGroups(false);
    }


    if (model->rowCount() > 0)
        model->removeRows(0, model->rowCount());

    int amountOfItems[4] = {50, 100, 200, 1000};
    model->insertRows(0, amountOfItems[index]);
    changeSortingOrder(currentSortingIndex);
    changeListMode(currentListModeIndex);
}

void MListPage::changeListMode(int index)
{
    switch (index) {
    case Plain:
        list->setShowGroups(false);
        model->setGrouped(false);
        break;

    case Grouped:
        list->setShowGroups(true);
        model->setGrouped(true);
        break;
    }

    currentListModeIndex = index;

    changeSortingOrder(currentSortingIndex);
    QTimer::singleShot(1500, this, SLOT(loadPicturesInVisibleItems()));
}

void MListPage::changeAmountOfColumns(int index)
{
    cellCreator->setColumns(index + 1);
    list->setColumns(index + 1);
}

void MListPage::changeSelectionMode(int index)
{
    switch (index) {
    case 0:
        list->setSelectionMode(MList::NoSelection);
        break;

    case 1:
        list->setSelectionMode(MList::SingleSelection);
        break;

    case 2:
        list->setSelectionMode(MList::MultiSelection);
        break;
    }
}

void MListPage::changeSeparatorsMode(int index)
{
    Q_ASSERT(index >= 0 && index <= 1);
    bool enableSeparators = (index == 1);

    if (enableSeparators)
        list->setObjectName("listWithSeparators");
    else
        list->setObjectName("");
}

void MListPage::changeListIndexVisibility(int index)
{
    Q_ASSERT(index >= 0 && index <= 2);

    switch (index) {
    case 1:
        list->setIndexDisplayMode(MList::Show);
        break;
    case 2:
        list->setIndexDisplayMode(MList::Auto);
        break;
    default:
        list->setIndexDisplayMode(MList::Hide);
        break;
    }

    if (index > 0)
        comboListMode->setCurrentIndex(Grouped);

}

void MListPage::changeLiveFilteringMode(int index)
{
    Q_ASSERT(index >= 0 && index <= 1);
    bool enableLF = (index == 1);

    if(enableLF) {
        list->filtering()->setEnabled(true);
        list->filtering()->setFilterRole(PhoneBookModel::PhoneBookFilterRole);
        list->filtering()->editor()->setVisible(false);
        connect(list->filtering(), SIGNAL(listPannedUpFromTop()), this, SLOT(filteringVKB()));
        connect(list->filtering()->editor(), SIGNAL(textChanged()), this, SLOT(liveFilteringTextChanged()));
    } else {
        disconnect(list->filtering(), SIGNAL(listPannedUpFromTop()), this, SLOT(filteringVKB()));
        disconnect(list->filtering()->editor(), SIGNAL(textChanged()), this, SLOT(liveFilteringTextChanged()));
        list->filtering()->setEnabled(false);
        showTextEdit(false);
    }
}

void MListPage::changeGroupHeadersMode(int index)
{
    Q_ASSERT(index >=0 && index <= 2);

    switch (index) {
    case 1:
        list->setHeaderCreator(new MListCustomHeaderCreator);
        break;
    case 2:
        list->setHeaderCreator(new MListAdvancedCustomHeaderCreator);
        break;
    default:
        list->setHeaderCreator(NULL);
        break;
    };

    if (index > 0)
        comboListMode->setCurrentIndex(Grouped);
}

void MListPage::itemClick(const QModelIndex &index)
{
    mDebug("MListPage::itemClick") << "Row was clicked: " << index.row();
}

void MListPage::itemLongTapped(const QModelIndex &index, const QPointF &position)
{
    objectMenu->setCursorPosition(position);
    if (index.parent().isValid()) {
        mDebug("MListPage::itemLongTapped") << "Row: " << index.row() << " Group: " << index.parent().row();
        sceneManager()->appearSceneWindow(objectMenu);
    }
    else if (model->hasChildren(index) > 0)
        mDebug("MListPage::itemLongTapped") << "Group: " << index.row();
    else {
        mDebug("MListPage::itemLongTapped") << "Row: " << index.row();
        sceneManager()->appearSceneWindow(objectMenu);
    }
    longTappedIndex = index;
}

void MListPage::removeListItem()
{
    if(longTappedIndex.isValid()) {
        mDebug("MListPage::removeListItem") << "Row about to be removed: " << longTappedIndex.row();
        proxyModel->removeRow(longTappedIndex.row(), longTappedIndex.parent());
        longTappedIndex = QModelIndex();
    }
}

void MListPage::editListItem()
{
    mDebug("MListPage::editListItem") << "Not implemented yet.";
    longTappedIndex = QModelIndex();
}

void MListPage::liveFilteringTextChanged()
{
    if(!list->filtering()->enabled())
        return;

    // With HWKB live filtering text edit is hidden when empty and shown when user enters text
    if(list->filtering()->editor()->text() == "" && list->filtering()->editor()->isOnDisplay())
        QTimer::singleShot(1500, this, SLOT(hideEmptyTextEdit()));
    else if(list->filtering()->editor()->text() != "" && !list->filtering()->editor()->isOnDisplay())
        showTextEdit(true);

    // Load images for items which match filtering
    imageLoader->stopLoadingPictures();
    loadPicturesInVisibleItems();

    // Highlighting matching live filtering text can be done by
    // passing the text to cell creator and updating visible items
    cellCreator->highlightByText(list->filtering()->editor()->text());
    static_cast<PhoneBookModel*>(model)->updateData(list->firstVisibleItem(), list->lastVisibleItem());
}

void MListPage::filteringVKB()
{
    // With VKB live filtering text edit is shown when user pans the list up starting from top position
    if (!list->filtering()->editor()->isOnDisplay()) {
        showTextEdit(true);
        list->filtering()->editor()->setFocus();
    }
}

void MListPage::hideEmptyTextEdit()
{
    if (list->filtering()->enabled() && list->filtering()->editor()->text() == "") {
        showTextEdit(false);
    }
}

void MListPage::showAdvancedConfigurationDialog()
{
    if (!dialogAdvancedConfiguration) {
        dialogAdvancedConfiguration = new MDialog("Advanced configuration", M::OkButton);

        QGraphicsWidget *panel = dialogAdvancedConfiguration->centralWidget();

        MLayout *layout = new MLayout(panel);
        MLinearLayoutPolicy *landscapePolicy = new MLinearLayoutPolicy(layout, Qt::Vertical);
        // Use the same landscape policy for portrait mode.
        MLinearLayoutPolicy *portraitPolicy = landscapePolicy;

        QStringList separatorsModes;
        separatorsModes << "Off" << "On";
        MComboBox *combo = createComboBoxLabelButton("Separators", separatorsModes, panel);
        connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(changeSeparatorsMode(int)));

        landscapePolicy->addItem(combo);

        QStringList listIndexModes;
        listIndexModes << "Off" << "On" << "Auto";
        combo = createComboBoxLabelButton("List Index", listIndexModes, panel);
        connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(changeListIndexVisibility(int)));

        landscapePolicy->addItem(combo);

        QStringList liveFilteringModes;
        liveFilteringModes << "Off" << "On";
        combo = createComboBoxLabelButton("Live Filtering", liveFilteringModes, panel);
        connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(changeLiveFilteringMode(int)));

        landscapePolicy->addItem(combo);

        QStringList groupHeadersModes;
        groupHeadersModes << "Default - Labels" << "Custom - Buttons" << "Advanced - Custom Widget";
        combo = createComboBoxLabelButton("Group Headers", groupHeadersModes, panel);
        connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(changeGroupHeadersMode(int)));

        landscapePolicy->addItem(combo);

        layout->setLandscapePolicy(landscapePolicy);
        layout->setPortraitPolicy(portraitPolicy);

        dialogAdvancedConfiguration->centralWidget()->setLayout(layout);
    }

    dialogAdvancedConfiguration->appear(MSceneWindow::DestroyWhenDismissed);
}

void MListPage::showTextEdit(bool show)
{
    QGraphicsWidget* panel = centralWidget();
    QGraphicsLinearLayout* layout = (QGraphicsLinearLayout*) panel->layout();
    MTextEdit* textEdit = list->filtering()->editor();
    if (show && !textEdit->isOnDisplay()) {
        layout->insertItem(0, textEdit);
        textEdit->setVisible(true);
        pannableViewport()->setPosition(QPointF(0,0));
    } else if (textEdit->isOnDisplay()) {
        list->setFocus();
        textEdit->setVisible(false);
        layout->removeAt(0);
        textEdit->setText("");
    }
}

void MListPage::createContent()
{
    MApplicationPage::createContent();
    createActions();

    MTheme::addPixmapDirectory(QDir(CONTACTS_DIR).canonicalPath());
    QGraphicsWidget *panel = centralWidget();
    QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
    panel->setLayout(layout);

    list = new MList(panel);
    objectMenuHolder = new MWidget(panel);

    objectMenu = new MObjectMenu(objectMenuHolder);

    //% "Remove"
    MAction *action = new MAction(qtTrId("xx_listpage_list_remove"), objectMenuHolder);
    action->setLocation(MAction::ObjectMenuLocation);
    objectMenuHolder->addAction(action);
    connect(action, SIGNAL(triggered()), this, SLOT(removeListItem()));

    //% "Edit"
    action = new MAction(qtTrId("xx_listpage_list_edit"), objectMenuHolder);
    action->setLocation(MAction::ObjectMenuLocation);
    objectMenuHolder->addAction(action);
    connect(action, SIGNAL(triggered()), this, SLOT(editListItem()));

    setPlainListModel();

    layout->addItem(list);

    connect(list, SIGNAL(itemClicked(QModelIndex)), this, SLOT(itemClick(QModelIndex)));
    connect(list, SIGNAL(itemLongTapped(QModelIndex,QPointF)), this, SLOT(itemLongTapped(QModelIndex,QPointF)));

    retranslateUi();
}

void MListPage::retranslateUi()
{
    //% "List"
    setTitle(qtTrId("xx_listpage_title"));
    if (!isContentCreated())
        return;
    // this file has no other calls to qtTrId() except for the title
    // at the moment. If more qtTrId() calls are needed they should
    // be added here.
}