author | hgs |
Fri, 15 Oct 2010 12:29:39 +0300 | |
changeset 80 | d6dafc5d983f |
parent 35 | 85266cc22c7f |
permissions | -rw-r--r-- |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1 |
/******************************************************************************* |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
2 |
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
3 |
* All rights reserved. This program and the accompanying materials |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
5 |
* which accompanies this distribution, and is available at |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
7 |
* |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
8 |
* Contributors: |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
9 |
* Nokia Corporation - initial implementation |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
10 |
*******************************************************************************/ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
11 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
12 |
#include <QListView> |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
13 |
#include <QModelIndex> |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
14 |
#include <QVariant> |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
15 |
#include <QPixmap> |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
16 |
#include <QString> |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
17 |
#include <QApplication> |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
18 |
#include <QPainter> |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
19 |
#include <QStringMatcher> |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
20 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
21 |
#include "swtlog.h" |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
22 |
#include "listdatamodel.h" |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
23 |
#include "jniutils.h" |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
24 |
#include "swtapplication.h" |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
25 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
26 |
/** |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
27 |
* list type |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
28 |
*/ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
29 |
const static int LISTTYPE_SORTEDLIST = 0x2; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
30 |
const static int LISTTYPE_LISTBOX = 0x8; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
31 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
32 |
/** |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
33 |
* layout styles |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
34 |
*/ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
35 |
const static int LB_STYLE_1LINE_ITEM = 0x1; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
36 |
const static int LB_STYLE_2LINE_ITEM = 0x2; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
37 |
const static int LB_MOD_SHOW_HEADING_ICONS = 0x20; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
38 |
const static int LB_MOD_SHOW_DETAIL_ICONS = 0x40; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
39 |
const static int LISTBASE_SHOW_CHECKBOX = 0x80; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
40 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
41 |
using namespace Java::eSWT; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
42 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
43 |
/** |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
44 |
* ListItem |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
45 |
*/ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
46 |
ListItem::ListItem(const QString& aText) |
80 | 47 |
: txt( aText ) |
48 |
{ |
|
49 |
SWT_LOG_FUNC_CALL(); |
|
50 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
51 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
52 |
ListItem::~ListItem() |
80 | 53 |
{ |
54 |
SWT_LOG_FUNC_CALL(); |
|
55 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
56 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
57 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
58 |
const QString& ListItem::text() const |
80 | 59 |
{ |
60 |
return txt; |
|
61 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
62 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
63 |
const QPixmap* ListItem::image() const |
80 | 64 |
{ |
65 |
return NULL; |
|
66 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
67 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
68 |
void ListItem::setText( const QString& string ) |
80 | 69 |
{ |
70 |
txt = string; |
|
71 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
72 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
73 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
74 |
Qt::CheckState ListItem::checkState() const |
80 | 75 |
{ |
76 |
SWT_LOG_FUNC_CALL(); |
|
77 |
return state; |
|
78 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
79 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
80 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
81 |
void ListItem::setCheckState( Qt::CheckState state ) |
80 | 82 |
{ |
83 |
SWT_LOG_FUNC_CALL(); |
|
84 |
this->state = state; |
|
85 |
} |
|
86 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
87 |
/** |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
88 |
* ListBoxItem |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
89 |
*/ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
90 |
|
80 | 91 |
ListBoxItem::ListBoxItem( const QString& aDetailText, const QPixmap* aDetailImages, const int aDetailImageCount, |
92 |
const QString& aHeadingText, const QPixmap* aHeadingImages, const int aHeadingImageCount ) |
|
93 |
: ListItem(aDetailText), headingTxt(aHeadingText) |
|
94 |
{ |
|
95 |
SWT_LOG_FUNC_CALL(); |
|
96 |
for (int i = 0; i < aDetailImageCount; i++) |
|
97 |
{ |
|
98 |
detailImgs.push_back(aDetailImages[i]); |
|
99 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
100 |
for (int i = 0; i < aHeadingImageCount; i++) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
101 |
{ |
80 | 102 |
headingImgs.push_back(aHeadingImages[i]); |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
103 |
} |
80 | 104 |
} |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
105 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
106 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
107 |
ListBoxItem::~ListBoxItem() |
80 | 108 |
{ |
109 |
SWT_LOG_FUNC_CALL(); |
|
110 |
} |
|
111 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
112 |
const QString& ListBoxItem::headingText() const |
80 | 113 |
{ |
114 |
SWT_LOG_FUNC_CALL(); |
|
115 |
return headingTxt; |
|
116 |
} |
|
117 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
118 |
const QList<QPixmap>& ListBoxItem::detailImages() const |
80 | 119 |
{ |
120 |
SWT_LOG_FUNC_CALL(); |
|
121 |
return detailImgs; |
|
122 |
} |
|
123 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
124 |
const QList<QPixmap>& ListBoxItem::headingImages() const |
80 | 125 |
{ |
126 |
SWT_LOG_FUNC_CALL(); |
|
127 |
return headingImgs; |
|
128 |
} |
|
129 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
130 |
int ListBoxItem::detailImageCount() const |
80 | 131 |
{ |
132 |
SWT_LOG_FUNC_CALL(); |
|
133 |
return detailImgs.count(); |
|
134 |
} |
|
135 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
136 |
int ListBoxItem::headingImageCount() const |
80 | 137 |
{ |
138 |
SWT_LOG_FUNC_CALL(); |
|
139 |
return headingImgs.count(); |
|
140 |
} |
|
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
141 |
|
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
142 |
void ListBoxItem::setContentsToNull() |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
143 |
{ |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
144 |
SWT_LOG_FUNC_CALL(); |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
145 |
setText( QString() ); |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
146 |
headingTxt = QString(); |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
147 |
for (int i = 0; i < detailImgs.count(); i++) |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
148 |
{ |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
149 |
detailImgs.pop_back(); |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
150 |
} |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
151 |
for (int i = 0; i < headingImgs.count(); i++) |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
152 |
{ |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
153 |
headingImgs.pop_back(); |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
154 |
} |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
155 |
} |
80 | 156 |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
157 |
/** |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
158 |
* ListModel |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
159 |
*/ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
160 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
161 |
ListModel::ListModel( int type, int style, QListView *parent ) |
80 | 162 |
: QAbstractListModel( parent ), |
163 |
listType( type ), |
|
164 |
layoutStyle( style ) |
|
165 |
{ |
|
166 |
SWT_LOG_FUNC_CALL(); |
|
167 |
SWT_LOG_DATA_3("listType=%d layoutStyle=%x parent=%x ", style, type, reinterpret_cast<int>(parent) ); |
|
168 |
} |
|
169 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
170 |
ListModel::~ListModel() |
80 | 171 |
{ |
172 |
SWT_LOG_FUNC_CALL(); |
|
173 |
clearList(); |
|
174 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
175 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
176 |
ListModel* ListModel::createDataModel( int type, int style, QListView *parent ) |
80 | 177 |
{ |
178 |
if( ( type & LISTTYPE_LISTBOX ) != 0 ) |
|
179 |
{ |
|
180 |
return new ListBoxModel( type, style, parent ); |
|
181 |
} |
|
182 |
else |
|
183 |
{ |
|
184 |
return new ListModel( type, style, parent ); |
|
185 |
} |
|
186 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
187 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
188 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
189 |
void ListModel::beginInsertRows( const QModelIndex& parent, int first, int last ) |
80 | 190 |
{ |
191 |
Q_ASSERT( first >= 0 && first <= list.size() ); |
|
192 |
Q_ASSERT( last >= first ); |
|
193 |
SWT_LOG_FUNC_CALL(); |
|
194 |
QAbstractItemModel::beginInsertRows( parent, first, last ); |
|
195 |
} |
|
196 |
||
197 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
198 |
void ListModel::endInsertRows() |
80 | 199 |
{ |
200 |
SWT_LOG_FUNC_CALL(); |
|
201 |
QAbstractItemModel::endInsertRows(); |
|
202 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
203 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
204 |
void ListModel::beginRemoveRows( const QModelIndex& parent, int first, int last ) |
80 | 205 |
{ |
206 |
Q_ASSERT( first > -1 && first < list.size() ); |
|
207 |
Q_ASSERT( last >= first && last < list.size() ); |
|
208 |
SWT_LOG_FUNC_CALL(); |
|
209 |
QAbstractItemModel::beginRemoveRows( parent, first, last ); |
|
210 |
} |
|
211 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
212 |
void ListModel::endRemoveRows() |
80 | 213 |
{ |
214 |
SWT_LOG_FUNC_CALL(); |
|
215 |
QAbstractItemModel::endRemoveRows(); |
|
216 |
} |
|
217 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
218 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
219 |
void ListModel::emitLayoutAboutToBeChanged() |
80 | 220 |
{ |
221 |
SWT_LOG_FUNC_CALL(); |
|
222 |
emit layoutAboutToBeChanged(); |
|
223 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
224 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
225 |
void ListModel::emitLayoutChanged() |
80 | 226 |
{ |
227 |
SWT_LOG_FUNC_CALL(); |
|
228 |
emit layoutChanged(); |
|
229 |
} |
|
230 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
231 |
Qt::ItemFlags ListModel::flags( const QModelIndex& index ) const |
80 | 232 |
{ |
233 |
SWT_LOG_FUNC_CALL(); |
|
234 |
Qt::ItemFlags flags = ( QAbstractItemModel::flags(index) | Qt::ItemIsEnabled | Qt::ItemIsSelectable ) & ~Qt::ItemIsUserCheckable; |
|
235 |
if( ( layoutStyle & LISTBASE_SHOW_CHECKBOX ) != 0 ) |
|
236 |
{ |
|
237 |
flags |= Qt::ItemIsUserCheckable; |
|
238 |
} |
|
239 |
return flags; |
|
240 |
} |
|
241 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
242 |
int ListModel::rowCount(const QModelIndex& /*parent*/ ) const |
80 | 243 |
{ |
244 |
SWT_LOG_FUNC_CALL(); |
|
245 |
return list.count(); |
|
246 |
} |
|
247 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
248 |
QVariant ListModel::data(const QModelIndex &index, int role) const |
80 | 249 |
{ |
250 |
SWT_LOG_FUNC_CALL(); |
|
251 |
if(!index.isValid()) |
|
252 |
{ |
|
253 |
SWT_LOG_DATA_1("invalid index %d", -1); |
|
254 |
return QVariant(); |
|
255 |
} |
|
256 |
Q_ASSERT( index.row() > -1 && index.row() < list.size() ); |
|
257 |
||
258 |
if ( role == Qt::DisplayRole ) |
|
259 |
{ |
|
260 |
SWT_LOG_DATA_2("Request data on DisplayRole: row=%d col=%d", index.row(), index.column()); |
|
261 |
return list[index.row()]->text(); |
|
262 |
} |
|
263 |
else if ( role == Qt::DecorationRole ) |
|
264 |
{ |
|
265 |
SWT_LOG_DATA_2("Request data on DecorationRole: row=%d col=%d", index.row(), index.column()); |
|
266 |
const QPixmap* img = list[index.row()]->image(); |
|
267 |
if( img ) |
|
268 |
{ |
|
269 |
return *img; |
|
270 |
} |
|
271 |
} |
|
272 |
else if( role == Qt::CheckStateRole && index.column()==0 ) |
|
273 |
{ |
|
274 |
SWT_LOG_DATA_2("Request checkState: row=%d col=%d", index.row(), index.column()); |
|
275 |
return list[index.row()]->checkState(); |
|
276 |
} |
|
277 |
||
278 |
SWT_LOG_DATA_2("Request something else: row=%d col=%d", index.row(), index.column()); |
|
279 |
return QVariant(); |
|
280 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
281 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
282 |
void ListModel::setCheckState( const QItemSelection& selection, Qt::CheckState state ) |
80 | 283 |
{ |
284 |
SWT_LOG_FUNC_CALL(); |
|
285 |
const QModelIndexList indexes = selection.indexes (); |
|
286 |
for( int i=0; i< indexes.size(); i++) |
|
287 |
{ |
|
288 |
list.at(indexes.at(i).row())->setCheckState( state ); |
|
289 |
} |
|
290 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
291 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
292 |
const QString& ListModel::itemString( const int row ) const |
80 | 293 |
{ |
294 |
SWT_LOG_FUNC_CALL(); |
|
295 |
Q_ASSERT(row > -1 && row < list.size()); |
|
296 |
return list.at(row)->text(); |
|
297 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
298 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
299 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
300 |
jobjectArray ListModel::itemStrings( JNIEnv* aJniEnv ) |
80 | 301 |
{ |
302 |
SWT_LOG_FUNC_CALL(); |
|
303 |
||
304 |
const int count = list.size(); |
|
305 |
jclass stringClass = aJniEnv->FindClass( "java/lang/String" ); |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
306 |
jobjectArray result = aJniEnv->NewObjectArray(count, stringClass, NULL); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
307 |
if( !result ) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
308 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
309 |
throw std::bad_alloc(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
310 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
311 |
|
80 | 312 |
jstring javaString; |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
313 |
for ( int i=0; i<count; ++i ) |
80 | 314 |
{ |
315 |
javaString = swtApp->jniUtils().QStringToJavaString(aJniEnv, list.at(i)->text() ); |
|
316 |
aJniEnv->SetObjectArrayElement( result, i, javaString ); |
|
317 |
aJniEnv->DeleteLocalRef( javaString ); |
|
318 |
} |
|
319 |
aJniEnv->DeleteLocalRef( stringClass ); |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
320 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
321 |
return result; |
80 | 322 |
} |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
323 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
324 |
int ListModel::indexOf(const QString& string, const int start ) const |
80 | 325 |
{ |
326 |
SWT_LOG_FUNC_CALL(); |
|
327 |
Q_ASSERT(start > -1 && start < list.size()); |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
328 |
QStringMatcher matcher(string, Qt::CaseSensitive); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
329 |
for (int i = start; i < list.size(); ++i) |
80 | 330 |
{ |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
331 |
const QString & str = list.at(i)->text(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
332 |
if (string.length() == str.length() && matcher.indexIn(str) == 0) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
333 |
return i; |
80 | 334 |
} |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
335 |
return -1; |
80 | 336 |
} |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
337 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
338 |
int ListModel::itemHeight() |
80 | 339 |
{ |
340 |
SWT_LOG_FUNC_CALL(); |
|
341 |
const QListView* listView = static_cast<const QListView*>( static_cast<QObject*>(this)->parent() ); |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
342 |
|
80 | 343 |
if(list.size() > 0 ) |
344 |
{ |
|
345 |
return listView->sizeHintForRow(0); |
|
346 |
} |
|
347 |
||
348 |
return listView->fontMetrics().height(); |
|
349 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
350 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
351 |
int ListModel::insertPosition(const QString& string, bool ascent ) |
80 | 352 |
{ |
353 |
SWT_LOG_FUNC_CALL(); |
|
354 |
if( listType != LISTTYPE_SORTEDLIST ) |
|
355 |
{ |
|
356 |
throw std::bad_exception(); |
|
357 |
} |
|
358 |
||
359 |
int pos = 0; |
|
360 |
for(int i = list.size() -1; i > -1; i--) |
|
361 |
{ |
|
362 |
if( ascent ) |
|
363 |
{ |
|
364 |
if( string < list.at(i)->text() ) |
|
365 |
continue; |
|
366 |
} |
|
367 |
else |
|
368 |
{ |
|
369 |
if( string > list.at(i)->text() ) |
|
370 |
continue; |
|
371 |
} |
|
372 |
pos = i + 1; |
|
373 |
break; |
|
374 |
} |
|
375 |
return pos; |
|
376 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
377 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
378 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
379 |
void ListModel::remove( const int row ) |
80 | 380 |
{ |
381 |
SWT_LOG_FUNC_CALL(); |
|
382 |
Q_ASSERT(row > -1 && row < list.size()); |
|
383 |
ListItem* item = list.takeAt(row); |
|
384 |
delete item; |
|
385 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
386 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
387 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
388 |
void ListModel::clearList() |
80 | 389 |
{ |
390 |
SWT_LOG_FUNC_CALL(); |
|
391 |
qDeleteAll(list.begin(), list.end()); |
|
392 |
list.clear(); |
|
393 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
394 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
395 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
396 |
void ListModel::appendItem( const QString& string ) |
80 | 397 |
{ |
398 |
SWT_LOG_FUNC_CALL(); |
|
399 |
ListItem* item = createItem( string ); |
|
400 |
list.append(item); |
|
401 |
} |
|
402 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
403 |
void ListModel::appendItem(const QString& string, const QPixmap* pixmap ) |
80 | 404 |
{ |
405 |
SWT_LOG_FUNC_CALL(); |
|
406 |
ListItem* item = createItem( string, pixmap ); |
|
407 |
list.append(item); |
|
408 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
409 |
|
80 | 410 |
|
411 |
void ListModel::appendItem(const QString& /*aDetailText*/, const QPixmap* /*aDetailImages*/, const int /*aDetailImageCount*/, |
|
412 |
const QString& /*aHeadingText*/, const QPixmap* /*aHeadingImages*/, const int /*aHeadingImageCount*/ ) |
|
413 |
{ |
|
414 |
Q_ASSERT( false ); |
|
415 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
416 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
417 |
void ListModel::insertItem( const int row, const QString& string ) |
80 | 418 |
{ |
419 |
SWT_LOG_FUNC_CALL(); |
|
420 |
Q_ASSERT(row > -1 && row <= list.size()); |
|
421 |
ListItem* item = createItem( string ); |
|
422 |
if( row == list.size() ) |
|
423 |
{ |
|
424 |
list.append(item); |
|
425 |
} |
|
426 |
else |
|
427 |
{ |
|
428 |
list.insert( row, item ); |
|
429 |
} |
|
430 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
431 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
432 |
void ListModel::insertItem( const int row, const QString& string, const QPixmap* pixmap ) |
80 | 433 |
{ |
434 |
SWT_LOG_FUNC_CALL(); |
|
435 |
Q_ASSERT(row > -1 && row <= list.size()); |
|
436 |
ListItem* item = createItem( string, pixmap ); |
|
437 |
if( row == list.size() ) |
|
438 |
{ |
|
439 |
list.append(item); |
|
440 |
} |
|
441 |
else |
|
442 |
{ |
|
443 |
list.insert( row, item ); |
|
444 |
} |
|
445 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
446 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
447 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
448 |
int ListModel::style() const |
80 | 449 |
{ |
450 |
SWT_LOG_FUNC_CALL(); |
|
451 |
return layoutStyle; |
|
452 |
} |
|
453 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
454 |
|
80 | 455 |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
456 |
ListItem* ListModel::createItem( const QString& string ) |
80 | 457 |
{ |
458 |
SWT_LOG_FUNC_CALL(); |
|
459 |
ListItem* item = new ListItem(string); |
|
460 |
if( !item ) |
|
461 |
{ |
|
462 |
throw std::bad_alloc(); |
|
463 |
} |
|
464 |
return item; |
|
465 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
466 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
467 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
468 |
ListItem* ListModel::createItem( const QString& /*string*/, const QPixmap* /*pixmap*/ ) |
80 | 469 |
{ |
470 |
SWT_LOG_FUNC_CALL(); |
|
471 |
Q_ASSERT( false ); |
|
472 |
return NULL; |
|
473 |
} |
|
474 |
||
475 |
ListItem* ListModel::createItem(const QString& /*aDetailText*/, const QPixmap* /*aDetailImages*/, const int /*aDetailImageCount*/, |
|
476 |
const QString& /*aHeadingText*/, const QPixmap* /*aHeadingImages*/, const int /*aHeadingImageCount*/ ) |
|
477 |
{ |
|
478 |
SWT_LOG_FUNC_CALL(); |
|
479 |
Q_ASSERT( false ); |
|
480 |
return NULL; |
|
481 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
482 |
|
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
483 |
void ListModel::setItemContentsToNull( const int /*row*/ ) |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
484 |
{ |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
485 |
SWT_LOG_FUNC_CALL(); |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
486 |
Q_ASSERT( false ); |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
487 |
} |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
488 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
489 |
// ListBoxModel |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
490 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
491 |
ListBoxModel::ListBoxModel( int type, int style, QListView *parent ) |
80 | 492 |
: ListModel(type, style, parent ), |
493 |
detailTxtIndex(-1), |
|
494 |
headingTxtIndex(-1), |
|
495 |
detailTxtSize(QPoint(0, 0)), |
|
496 |
headingTxtSize(QPoint(0, 0)), |
|
497 |
detailImgCount(0), |
|
498 |
headingImgCount(0), |
|
499 |
imgHeight(0), |
|
500 |
detailImgWidths(NULL), |
|
501 |
headingImgWidths(NULL), |
|
502 |
rowHeights(NULL), |
|
503 |
detailImgWidth(0), |
|
504 |
headingImgWidth(0) |
|
505 |
{ |
|
506 |
SWT_LOG_FUNC_CALL(); |
|
507 |
} |
|
508 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
509 |
ListBoxModel::~ListBoxModel() |
80 | 510 |
{ |
511 |
SWT_LOG_FUNC_CALL(); |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
512 |
|
80 | 513 |
delete detailImgWidths; |
514 |
delete headingImgWidths; |
|
515 |
delete rowHeights; |
|
516 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
517 |
|
80 | 518 |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
519 |
void ListBoxModel::clearList() |
80 | 520 |
{ |
521 |
SWT_LOG_FUNC_CALL(); |
|
522 |
ListModel::clearList(); |
|
523 |
detailTxtIndex = -1; |
|
524 |
headingTxtIndex = -1; |
|
525 |
detailTxtSize = QPoint(0, 0); |
|
526 |
headingTxtSize = QPoint(0, 0); |
|
527 |
detailImgCount = 0; |
|
528 |
headingImgCount = 0; |
|
529 |
imgHeight = 0; |
|
530 |
delete detailImgWidths; |
|
531 |
detailImgWidths = NULL; |
|
532 |
delete headingImgWidths; |
|
533 |
headingImgWidths = NULL; |
|
534 |
delete rowHeights; |
|
535 |
rowHeights = NULL; |
|
536 |
detailImgWidth = 0; |
|
537 |
headingImgWidth = 0; |
|
538 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
539 |
|
80 | 540 |
void ListBoxModel::appendItem(const QString& aDetailText, const QPixmap* aDetailImages, const int aDetailImageCount, |
541 |
const QString& aHeadingText, const QPixmap* aHeadingImages, const int aHeadingImageCount ) |
|
542 |
{ |
|
543 |
SWT_LOG_FUNC_CALL(); |
|
544 |
ListItem* item = createItem( aDetailText, aDetailImages, aDetailImageCount, |
|
545 |
aHeadingText, aHeadingImages, aHeadingImageCount ); |
|
546 |
list.append(item); |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
547 |
|
80 | 548 |
// remember the index of the item, which has the longest detail text |
549 |
const QListView* listView = static_cast<const QListView*>( static_cast<QObject*>(this)->parent() ); |
|
550 |
if(!aDetailText.isNull()) |
|
551 |
{ |
|
552 |
int textWidth = listView->fontMetrics().boundingRect(aDetailText).width(); |
|
553 |
if( detailTxtSize.x() < textWidth ) |
|
554 |
{ |
|
555 |
detailTxtSize.rx() = textWidth; |
|
556 |
detailTxtIndex = list.size() - 1; |
|
557 |
} |
|
558 |
} |
|
559 |
||
560 |
// remember the index of the item, which has the longest heading text |
|
561 |
if( (layoutStyle | LB_STYLE_1LINE_ITEM) != 0 || (layoutStyle | LB_STYLE_2LINE_ITEM) != 0 ) |
|
562 |
{ |
|
563 |
if(!aHeadingText.isNull()) |
|
564 |
{ |
|
565 |
int textWidth = listView->fontMetrics().boundingRect(aHeadingText).width(); |
|
566 |
if( headingTxtSize.x() < textWidth ) |
|
567 |
{ |
|
568 |
headingTxtSize.rx() = textWidth; |
|
569 |
headingTxtIndex = list.size() - 1; |
|
570 |
} |
|
571 |
} |
|
572 |
} |
|
573 |
||
574 |
// remember the maximum detail image count |
|
575 |
// and remember the maximum widths for every columns of detail images |
|
576 |
if( (layoutStyle | LB_MOD_SHOW_DETAIL_ICONS) != 0 ) |
|
577 |
{ |
|
578 |
if( detailImgCount < aDetailImageCount ) |
|
579 |
{ |
|
580 |
int* alloc = new int[aDetailImageCount]; |
|
581 |
memset(alloc, '\0', sizeof(int)*aDetailImageCount); |
|
582 |
if( !alloc ) |
|
583 |
{ |
|
584 |
throw std::bad_alloc(); |
|
585 |
} |
|
586 |
for(int i = 0; i < detailImgCount; i++) |
|
587 |
{ |
|
588 |
alloc[i] = detailImgWidths[i]; |
|
589 |
} |
|
590 |
delete detailImgWidths; |
|
591 |
detailImgWidths = alloc; |
|
592 |
detailImgCount = aDetailImageCount; |
|
593 |
} |
|
594 |
for(int i = 0; i < aDetailImageCount; i++) |
|
595 |
{ |
|
596 |
if( !aDetailImages[i].isNull() ) |
|
597 |
{ |
|
598 |
QSize size = aDetailImages[i].size(); |
|
599 |
if(detailImgWidths[i] < size.width()) |
|
600 |
{ |
|
601 |
detailImgWidths[i] = size.width(); |
|
602 |
} |
|
603 |
if(imgHeight < size.height()) |
|
604 |
{ |
|
605 |
imgHeight = size.height(); |
|
606 |
} |
|
607 |
} |
|
608 |
} |
|
609 |
} |
|
610 |
||
611 |
// remember the maximum detail image count |
|
612 |
// and remember the maximum widths for every columns of heading images |
|
613 |
if( (layoutStyle | LB_MOD_SHOW_HEADING_ICONS) != 0 ) |
|
614 |
{ |
|
615 |
if( headingImgCount < aHeadingImageCount ) |
|
616 |
{ |
|
617 |
int* alloc = new int[aHeadingImageCount ]; |
|
618 |
memset(alloc, '\0', sizeof(int)*aHeadingImageCount); |
|
619 |
if( !alloc ) |
|
620 |
{ |
|
621 |
throw std::bad_alloc(); |
|
622 |
} |
|
623 |
for(int i = 0; i < headingImgCount; i++) |
|
624 |
{ |
|
625 |
alloc[i] = headingImgWidths[i]; |
|
626 |
} |
|
627 |
delete headingImgWidths; |
|
628 |
headingImgWidths = alloc; |
|
629 |
headingImgCount = aHeadingImageCount; |
|
630 |
} |
|
631 |
for(int i = 0; i < aHeadingImageCount; i++) |
|
632 |
{ |
|
633 |
if( !aHeadingImages[i].isNull() ) |
|
634 |
{ |
|
635 |
QSize size = aHeadingImages[i].size(); |
|
636 |
if(headingImgWidths[i] < size.width()) |
|
637 |
{ |
|
638 |
headingImgWidths[i] = size.width(); |
|
639 |
} |
|
640 |
if(imgHeight < size.height()) |
|
641 |
{ |
|
642 |
imgHeight = size.height(); |
|
643 |
} |
|
644 |
} |
|
645 |
} |
|
646 |
} |
|
647 |
} |
|
648 |
||
649 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
650 |
void ListBoxModel::updateLayoutData( const int row, const int rowHeight, const QPoint detailTxtSize, |
80 | 651 |
const QPoint headingTxtSize, const int detailImgWidth, const int headingImgWidth ) const |
652 |
{ |
|
653 |
SWT_LOG_FUNC_CALL(); |
|
654 |
Q_ASSERT(row > -1 && row < list.size()); |
|
655 |
||
656 |
if(!rowHeights) |
|
657 |
{ |
|
658 |
int count = list.size(); |
|
659 |
rowHeights = new int[count]; |
|
660 |
if( !rowHeights ) |
|
661 |
{ |
|
662 |
throw std::bad_alloc(); |
|
663 |
} |
|
664 |
memset(rowHeights, '\0', sizeof(int)*count); |
|
665 |
} |
|
666 |
||
667 |
rowHeights[row] = rowHeight; |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
668 |
this->detailTxtSize = detailTxtSize; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
669 |
this->headingTxtSize = headingTxtSize; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
670 |
this->detailImgWidth = detailImgWidth; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
671 |
this->headingImgWidth = headingImgWidth; |
80 | 672 |
} |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
673 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
674 |
const QString& ListBoxModel::headingText( const int row ) const |
80 | 675 |
{ |
676 |
SWT_LOG_FUNC_CALL(); |
|
677 |
Q_ASSERT(row > -1 && row < list.size()); |
|
678 |
return static_cast<ListBoxItem*>(list.at(row))->headingText(); |
|
679 |
} |
|
680 |
||
681 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
682 |
int ListBoxModel::detailImageCount() const |
80 | 683 |
{ |
684 |
SWT_LOG_FUNC_CALL(); |
|
685 |
return detailImgCount; |
|
686 |
} |
|
687 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
688 |
int ListBoxModel::headingImageCount() const |
80 | 689 |
{ |
690 |
SWT_LOG_FUNC_CALL(); |
|
691 |
return headingImgCount; |
|
692 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
693 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
694 |
const int& ListBoxModel::detailImageWidth(const int index) const |
80 | 695 |
{ |
696 |
SWT_LOG_FUNC_CALL(); |
|
697 |
Q_ASSERT(index > -1 && index < detailImgCount); |
|
698 |
return detailImgWidths[index]; |
|
699 |
} |
|
700 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
701 |
const int& ListBoxModel::headingImageWidth(const int index) const |
80 | 702 |
{ |
703 |
SWT_LOG_FUNC_CALL(); |
|
704 |
Q_ASSERT(index > -1 && index < headingImgCount); |
|
705 |
return headingImgWidths[index]; |
|
706 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
707 |
|
80 | 708 |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
709 |
int ListBoxModel::detailImageCount( const int row ) const |
80 | 710 |
{ |
711 |
SWT_LOG_FUNC_CALL(); |
|
712 |
Q_ASSERT(row > -1 && row < list.size()); |
|
713 |
return static_cast<ListBoxItem*>(list.at(row))->detailImageCount(); |
|
714 |
} |
|
715 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
716 |
int ListBoxModel::headingImageCount( const int row ) const |
80 | 717 |
{ |
718 |
SWT_LOG_FUNC_CALL(); |
|
719 |
Q_ASSERT(row > -1 && row < list.size()); |
|
720 |
return static_cast<ListBoxItem*>(list.at(row))->headingImageCount(); |
|
721 |
} |
|
722 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
723 |
const QList<QPixmap>& ListBoxModel::detailImages(const int row ) const |
80 | 724 |
{ |
725 |
SWT_LOG_FUNC_CALL(); |
|
726 |
Q_ASSERT(row > -1 && row < list.size()); |
|
727 |
return static_cast<ListBoxItem*>(list.at(row))->detailImages(); |
|
728 |
} |
|
729 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
730 |
const QList<QPixmap>& ListBoxModel::headingImages( const int row ) const |
80 | 731 |
{ |
732 |
SWT_LOG_FUNC_CALL(); |
|
733 |
Q_ASSERT(row > -1 && row < list.size()); |
|
734 |
return static_cast<ListBoxItem*>(list.at(row))->headingImages(); |
|
735 |
} |
|
736 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
737 |
QPoint ListBoxModel::detailTextSize() const |
80 | 738 |
{ |
739 |
SWT_LOG_FUNC_CALL(); |
|
740 |
return detailTxtSize; |
|
741 |
} |
|
742 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
743 |
QPoint ListBoxModel::headingTextSize() const |
80 | 744 |
{ |
745 |
SWT_LOG_FUNC_CALL(); |
|
746 |
return headingTxtSize; |
|
747 |
} |
|
748 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
749 |
QPoint ListBoxModel::detailImageSize(const int row) const |
80 | 750 |
{ |
751 |
SWT_LOG_FUNC_CALL(); |
|
752 |
Q_ASSERT(row > -1 && row < list.size()); |
|
753 |
return QPoint(detailImgWidth, rowHeights[row]); |
|
754 |
} |
|
755 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
756 |
QPoint ListBoxModel::headingImageSize(const int row) const |
80 | 757 |
{ |
758 |
SWT_LOG_FUNC_CALL(); |
|
759 |
Q_ASSERT(row > -1 && row < list.size()); |
|
760 |
return QPoint(headingImgWidth, rowHeights[row]); |
|
761 |
} |
|
762 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
763 |
int ListBoxModel::rowWithMaxDetailTextSize() const |
80 | 764 |
{ |
765 |
SWT_LOG_FUNC_CALL(); |
|
766 |
return detailTxtIndex; |
|
767 |
} |
|
768 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
769 |
int ListBoxModel::rowWithMaxHeadingTextSize() const |
80 | 770 |
{ |
771 |
SWT_LOG_FUNC_CALL(); |
|
772 |
return headingTxtIndex; |
|
773 |
} |
|
26
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
774 |
|
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
775 |
void ListBoxModel::setItemContentsToNull( const int row ) |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
776 |
{ |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
777 |
SWT_LOG_FUNC_CALL(); |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
778 |
Q_ASSERT(row > -1 && row < list.size()); |
dc7c549001d5
Revision: v2.1.26
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
21
diff
changeset
|
779 |
static_cast<ListBoxItem*>(list.at(row))->setContentsToNull( ); |
80 | 780 |
} |
781 |
||
782 |
ListItem* ListBoxModel::createItem(const QString& aDetailText, const QPixmap* aDetailImages, const int aDetailImageCount, |
|
783 |
const QString& aHeadingText, const QPixmap* aHeadingImages, const int aHeadingImageCount ) |
|
784 |
{ |
|
785 |
SWT_LOG_FUNC_CALL(); |
|
786 |
||
787 |
ListItem* item = new ListBoxItem( aDetailText, aDetailImages, aDetailImageCount, aHeadingText, aHeadingImages, aHeadingImageCount ); |
|
788 |
if( !item ) |
|
789 |
{ |
|
790 |
throw std::bad_alloc(); |
|
791 |
} |
|
792 |
||
793 |
return item; |
|
794 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
795 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
796 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
797 |
|
80 | 798 |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
799 |
/** |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
800 |
* ListItemDelegate |
80 | 801 |
*/ |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
802 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
803 |
ListBoxItemDelegate::ListBoxItemDelegate( QObject * parent ) |
80 | 804 |
: QItemDelegate( parent ), |
805 |
headingFont( NULL ) |
|
806 |
{ |
|
807 |
SWT_LOG_FUNC_CALL(); |
|
808 |
QListView* listView = static_cast< QListView* >( parent ); |
|
809 |
dataModel = static_cast < ListBoxModel* > ( listView->model() ); |
|
810 |
} |
|
811 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
812 |
void ListBoxItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const |
80 | 813 |
{ |
814 |
SWT_LOG_FUNC_CALL(); |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
815 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
816 |
Q_ASSERT(index.isValid()); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
817 |
|
80 | 818 |
// setup option |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
819 |
QStyleOptionViewItemV3 opt = setOptions(index, option); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
820 |
const QStyleOptionViewItemV2* v2 = qstyleoption_cast<const QStyleOptionViewItemV2 *>(&option); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
821 |
opt.features = v2 ? v2->features : QStyleOptionViewItemV2::ViewItemFeatures(QStyleOptionViewItemV2::None); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
822 |
const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
823 |
opt.locale = v3 ? v3->locale : QLocale(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
824 |
opt.widget = v3 ? v3->widget : 0; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
825 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
826 |
painter->save(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
827 |
painter->setClipRect(opt.rect); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
828 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
829 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
830 |
// retrieve cached layout data from data model |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
831 |
const int row = index.row(); |
80 | 832 |
QRect headingImageRect(QPoint(0, 0), dataModel->headingImageSize(row)); |
833 |
QRect detailImageRect(QPoint(0, 0), dataModel->detailImageSize(row)); |
|
834 |
QRect headingTextRect(QPoint(0, 0), dataModel->headingTextSize()); |
|
835 |
QRect detailTextRect(QPoint(0, 0), dataModel->detailTextSize()); |
|
836 |
||
837 |
// get check rectangle |
|
838 |
Qt::CheckState checkState = static_cast<Qt::CheckState>(dataModel->data(index, Qt::CheckStateRole).toInt()); |
|
839 |
QRect checkRect = (dataModel->flags(index) & Qt::ItemIsUserCheckable) != 0 ? check( opt, opt.rect, checkState ) : QRect(); |
|
840 |
if(checkRect.isValid()) |
|
841 |
{ |
|
842 |
checkRect.setRight(checkRect.right() + 2 * margin(opt)); |
|
843 |
} |
|
844 |
||
845 |
doLayout( option, &checkRect, &headingImageRect, &detailImageRect, & headingTextRect, &detailTextRect ); |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
846 |
|
80 | 847 |
const int layoutStyle = dataModel->style(); |
848 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
849 |
drawBackground(painter, opt, index); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
850 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
851 |
if(checkRect.isValid()) |
80 | 852 |
{ |
853 |
drawCheck( painter, opt, checkRect, checkState ); |
|
854 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
855 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
856 |
// draw heading images |
80 | 857 |
if ( ( layoutStyle & LB_MOD_SHOW_HEADING_ICONS ) != 0 && dataModel->headingImageCount(row) > 0 ) |
858 |
{ |
|
859 |
drawImages( painter, opt, headingImageRect, dataModel->headingImages(row), &(dataModel->headingImageWidth(0)), dataModel->headingImageCount(row) ); |
|
860 |
} |
|
861 |
||
862 |
// draw detail images |
|
863 |
if ( ( layoutStyle & LB_MOD_SHOW_DETAIL_ICONS ) != 0 && dataModel->detailImageCount(row) > 0 ) |
|
864 |
{ |
|
865 |
drawImages( painter, opt, detailImageRect, dataModel->detailImages(row), &(dataModel->detailImageWidth(0)), dataModel->detailImageCount(row) ); |
|
866 |
} |
|
867 |
||
868 |
// draw detail text |
|
869 |
if(detailTextRect.isValid()) |
|
870 |
{ |
|
871 |
SWT_LOG_DATA_4("Draw detail text; size=(%d, %d); topleft=(%d, %d)", detailTextRect.width(), detailTextRect.height(), detailTextRect.left(), detailTextRect.top() ); |
|
872 |
drawDisplay( painter, opt, detailTextRect, dataModel->data(index, Qt::DisplayRole).toString() ); |
|
873 |
drawFocus( painter, opt, detailTextRect); |
|
874 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
875 |
|
80 | 876 |
// draw heading text |
877 |
if ( headingTextRect.isValid() && ( ( layoutStyle & LB_STYLE_1LINE_ITEM ) != 0 || ( layoutStyle & LB_STYLE_2LINE_ITEM ) != 0 )) |
|
878 |
{ |
|
879 |
if ( headingFont != NULL) |
|
880 |
{ |
|
881 |
opt.font = *headingFont; |
|
882 |
opt.fontMetrics = QFontMetrics( *headingFont ); |
|
883 |
} |
|
884 |
||
885 |
SWT_LOG_DATA_4("Draw heading text; size=(%d, %d); topleft=(%d, %d)", headingTextRect.width(), headingTextRect.height(), headingTextRect.right(), headingTextRect.top() ); |
|
886 |
drawDisplay(painter, opt, headingTextRect, dataModel->headingText(row) ); |
|
887 |
drawFocus(painter, opt, headingTextRect); |
|
888 |
} |
|
889 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
890 |
painter->restore(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
891 |
|
80 | 892 |
} |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
893 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
894 |
void ListBoxItemDelegate::computeSizes( const QModelIndex& index, const QStyleOptionViewItem& option, QSize* checkSize, |
80 | 895 |
QSize *headingImageSize, QSize* detailImageSize, QSize* headingTextSize, QSize* detailTextSize ) const |
896 |
{ |
|
897 |
SWT_LOG_FUNC_CALL(); |
|
898 |
const int layoutStyle = dataModel->style(); |
|
899 |
||
900 |
int imageMargin = margin(option); |
|
901 |
// go through every columns of heading images to get width of entire heading image area |
|
902 |
// go through every heading images in the row to get the height of entire heading image area |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
903 |
if ( ( layoutStyle & LB_MOD_SHOW_HEADING_ICONS ) != 0 && dataModel->headingImageCount() > 0 ) |
80 | 904 |
{ |
905 |
int width = 0; |
|
906 |
int height = 0; |
|
907 |
int headingImageCount = dataModel->headingImageCount(); |
|
908 |
int itemHeadingImageCount = dataModel->headingImageCount(index.row()); |
|
909 |
const QPixmap* pixmap; |
|
910 |
for( int i = 0; i < headingImageCount; i++) |
|
911 |
{ |
|
912 |
width += dataModel->headingImageWidth(i); |
|
913 |
pixmap = &(dataModel->headingImages(index.row())[i]); |
|
914 |
if(i < itemHeadingImageCount && pixmap) |
|
915 |
{ |
|
916 |
if( pixmap->size().height() > height ) |
|
917 |
{ |
|
918 |
height = pixmap->size().height(); |
|
919 |
} |
|
920 |
} |
|
921 |
} |
|
922 |
width += (headingImageCount - 1) * imageMargin; |
|
923 |
*headingImageSize = QSize( width, height ); |
|
924 |
SWT_LOG_DATA_3("heading image rect row=%d; size=(%d, %d);", index.row(), headingImageSize->width(), headingImageSize->height() ); |
|
925 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
926 |
else |
80 | 927 |
{ |
928 |
*headingImageSize = QSize(); |
|
929 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
930 |
|
80 | 931 |
// go through every columns of detail images to get width of entire detail image area |
932 |
// go through every detail images in the row to get height of entire detial image area |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
933 |
if ( ( layoutStyle & LB_MOD_SHOW_DETAIL_ICONS ) != 0 && dataModel->detailImageCount() > 0 ) |
80 | 934 |
{ |
935 |
int width = 0; |
|
936 |
int height = 0; |
|
937 |
int detailImageCount = dataModel->detailImageCount(); |
|
938 |
int itemDetailImageCount = dataModel->detailImageCount(index.row()); |
|
939 |
const QPixmap* pixmap; |
|
940 |
for( int i = 0; i < detailImageCount; i++) |
|
941 |
{ |
|
942 |
width += dataModel->detailImageWidth(i); |
|
943 |
pixmap = &(dataModel->detailImages(index.row())[i]); |
|
944 |
if(i < itemDetailImageCount && pixmap) |
|
945 |
{ |
|
946 |
if( pixmap->size().height() > height ) |
|
947 |
{ |
|
948 |
height = pixmap->size().height(); |
|
949 |
} |
|
950 |
} |
|
951 |
} |
|
952 |
width += (detailImageCount - 1) * imageMargin; |
|
953 |
*detailImageSize = QSize( width, height ); |
|
954 |
SWT_LOG_DATA_3("detail image rect row=%d; size=(%d, %d);", index.row(), detailImageSize->width(), detailImageSize->height() ); |
|
955 |
} |
|
956 |
else |
|
957 |
{ |
|
958 |
*detailImageSize = QSize(); |
|
959 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
960 |
|
80 | 961 |
const QStyleOptionViewItemV2* v2 = qstyleoption_cast< const QStyleOptionViewItemV2* >(&option); |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
962 |
const bool wrapText = v2->features & QStyleOptionViewItemV2::WrapText; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
963 |
const int width = wrapText && option.rect.isValid() ? option.rect.width() : 0xffff; |
80 | 964 |
|
965 |
// compute width of heading text upon the item which has the longest heading text |
|
966 |
int row; |
|
967 |
if ( ( layoutStyle & LB_STYLE_1LINE_ITEM ) != 0 || ( layoutStyle & LB_STYLE_2LINE_ITEM ) != 0 ) |
|
968 |
{ |
|
969 |
row = dataModel->rowWithMaxHeadingTextSize(); |
|
970 |
if( row > -1) |
|
971 |
{ |
|
972 |
const QString& text = dataModel->headingText( row ); |
|
973 |
if( !text.isNull() ) |
|
974 |
{ |
|
975 |
const QFont& font = headingFont ? *headingFont : option.font; |
|
976 |
*headingTextSize = textRectangle( width, font, text ).size(); |
|
977 |
} |
|
978 |
} |
|
979 |
} |
|
980 |
else |
|
981 |
{ |
|
982 |
*headingTextSize = QSize(); |
|
983 |
} |
|
984 |
||
985 |
// compute width of detail text upon the item which has the longest detail text |
|
986 |
row = dataModel->rowWithMaxDetailTextSize(); |
|
987 |
if( row > -1) |
|
988 |
{ |
|
989 |
const QString& text = dataModel->data( index, Qt::DisplayRole).toString(); |
|
990 |
if( !text.isNull() ) |
|
991 |
{ |
|
992 |
*detailTextSize = textRectangle( width, option.font, text ).size(); |
|
993 |
} |
|
994 |
} |
|
995 |
else |
|
996 |
{ |
|
997 |
*detailTextSize = QSize(); |
|
998 |
} |
|
999 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1000 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1001 |
*checkSize = check( option, option.rect, Qt::Unchecked ).size(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1002 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1003 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1004 |
void ListBoxItemDelegate::addMargins( const QStyleOptionViewItem &option, QSize* checkSize, |
80 | 1005 |
QSize* headingImageSize, QSize* detailImageSize, QSize* headingTextSize, QSize* detailTextSize ) const |
1006 |
{ |
|
1007 |
SWT_LOG_FUNC_CALL(); |
|
1008 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1009 |
const bool hasCheck = checkSize->isValid(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1010 |
const bool hasHeadingImage = headingImageSize->isValid(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1011 |
const bool hasDetailImage = detailImageSize->isValid(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1012 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1013 |
const int pixmapMargin = margin(option); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1014 |
const int checkMargin = pixmapMargin; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1015 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1016 |
// don't need to add margin to text since text size includes margin |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1017 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1018 |
// set height for text if text height is 0 and there is no image |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1019 |
if ( detailTextSize->height() == 0 && !hasHeadingImage && !hasDetailImage ) |
80 | 1020 |
{ |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1021 |
detailTextSize->setHeight( option.fontMetrics.height() ); |
80 | 1022 |
} |
1023 |
if ( headingTextSize->height() == 0 && !hasHeadingImage && !hasDetailImage ) |
|
1024 |
{ |
|
1025 |
if ( headingFont ) |
|
1026 |
{ |
|
1027 |
headingTextSize->setHeight( QFontMetrics( *headingFont ).height() ); |
|
1028 |
} |
|
1029 |
else |
|
1030 |
{ |
|
1031 |
headingTextSize->setHeight( detailTextSize->height() ); |
|
1032 |
} |
|
1033 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1034 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1035 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1036 |
if ( hasHeadingImage ) |
80 | 1037 |
{ |
1038 |
headingImageSize->rwidth() += pixmapMargin * 2; |
|
1039 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1040 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1041 |
if ( hasDetailImage ) |
80 | 1042 |
{ |
1043 |
detailImageSize->rwidth() += pixmapMargin * 2; |
|
1044 |
} |
|
1045 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1046 |
if ( hasCheck ) |
80 | 1047 |
{ |
1048 |
checkSize->rwidth() += checkMargin * 2; |
|
1049 |
} |
|
1050 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1051 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1052 |
QSize ListBoxItemDelegate::computeSize( const QStyleOptionViewItem &option, const QSize& check, const QSize& headingImage, |
80 | 1053 |
const QSize& detailImage, const QSize& headingText, const QSize& detailText ) const |
1054 |
{ |
|
1055 |
SWT_LOG_FUNC_CALL(); |
|
1056 |
const int layoutStyle = dataModel->style(); |
|
1057 |
int h, w; |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1058 |
if ( ( layoutStyle & LB_STYLE_2LINE_ITEM ) != 0 ) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1059 |
{ |
80 | 1060 |
const int textWidth = qMax( headingText.width(), detailText.width() ); |
1061 |
const int textMargin = margin(option); |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1062 |
h = qMax( check.height(), qMax( headingText.height() + detailText.height() + textMargin, |
80 | 1063 |
qMax( headingImage.height(), detailImage.height() ) ) ); |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1064 |
w = check.width() + textWidth + headingImage.width() + detailImage.width(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1065 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1066 |
else |
80 | 1067 |
{ |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1068 |
h = qMax( check.height(), qMax( qMax( headingText.height(), detailText.height() ), |
80 | 1069 |
qMax( headingImage.height(), detailImage.height() ) ) ); |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1070 |
w = check.width() + headingText.width() + detailText.width() + headingImage.width() + detailImage.width(); |
80 | 1071 |
} |
1072 |
||
1073 |
return QSize( w, h ); |
|
1074 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1075 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1076 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1077 |
void ListBoxItemDelegate::layoutRects( const QStyleOptionViewItem &option, QRect* check, QRect *headingImage, |
80 | 1078 |
QRect* detailImage, QRect* headingText, QRect* detailText, bool hint ) const |
1079 |
{ |
|
1080 |
SWT_LOG_FUNC_CALL(); |
|
1081 |
||
1082 |
const int layoutStyle = dataModel->style(); |
|
1083 |
int h, w; |
|
1084 |
int textWidth; |
|
1085 |
if( ( layoutStyle & LB_STYLE_2LINE_ITEM ) != 0 ) |
|
1086 |
{ |
|
1087 |
textWidth = qMax( headingText->width(), detailText->width() ); |
|
1088 |
} |
|
1089 |
else |
|
1090 |
{ |
|
1091 |
textWidth = headingText->width() + detailText->width(); |
|
1092 |
} |
|
1093 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1094 |
if ( hint ) |
80 | 1095 |
{ |
1096 |
QSize size = computeSize( option, check->size(), headingImage->size(), detailImage->size(), headingText->size(), detailText->size() ); |
|
1097 |
h = size.height(); |
|
1098 |
w = size.width(); |
|
1099 |
} |
|
1100 |
else |
|
1101 |
{ |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1102 |
w = option.rect.width(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1103 |
h = option.rect.height(); |
80 | 1104 |
} |
1105 |
const int x = option.rect.left(), y = option.rect.top(); |
|
1106 |
SWT_LOG_DATA_4("space for layout: size=(%d, %d); topleft=(%d, %d)", w, h, x, y ); |
|
1107 |
||
1108 |
int leftX = x, rightX = x + w; |
|
1109 |
if ( option.direction == Qt::RightToLeft ) |
|
1110 |
{ |
|
1111 |
if ( check->isValid() ) |
|
1112 |
{ |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1113 |
check->setRect( qMax( rightX - check->width(), leftX ) , y, qMin( check->width(), rightX - leftX ), h ); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1114 |
rightX = check->left(); |
80 | 1115 |
} |
1116 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1117 |
if ( headingImage->isValid() ) |
80 | 1118 |
{ |
1119 |
if ( rightX > leftX ) |
|
1120 |
{ |
|
1121 |
headingImage->setRect( qMax( rightX - headingImage->width(), leftX ), y, qMin( headingImage->width(), rightX - leftX ) , h ); |
|
1122 |
rightX = headingImage->left(); |
|
1123 |
} |
|
1124 |
else |
|
1125 |
{ |
|
1126 |
*headingImage = QRect(); |
|
1127 |
} |
|
1128 |
} |
|
1129 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1130 |
if ( detailImage->isValid() ) |
80 | 1131 |
{ |
1132 |
if ( rightX > leftX ) |
|
1133 |
{ |
|
1134 |
int detailImageX = leftX; |
|
1135 |
int detailImageWidth = detailImage->width(); |
|
1136 |
if( (rightX -leftX) >= (textWidth + detailImageWidth) ) |
|
1137 |
{ |
|
1138 |
detailImageX = rightX - textWidth - detailImageWidth; |
|
1139 |
} |
|
1140 |
else |
|
1141 |
{ |
|
1142 |
detailImageX = qMin( rightX, leftX + detailImageWidth ); |
|
1143 |
} |
|
1144 |
detailImage->setRect( detailImageX, y, qMin( detailImageWidth, rightX - detailImageX ), h ); |
|
1145 |
leftX = detailImage->right(); |
|
1146 |
} |
|
1147 |
else |
|
1148 |
{ |
|
1149 |
*detailImage = QRect(); |
|
1150 |
} |
|
1151 |
} |
|
1152 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1153 |
if ( ( layoutStyle & LB_STYLE_2LINE_ITEM ) != 0 ) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1154 |
{ |
80 | 1155 |
if ( rightX > leftX ) |
1156 |
{ |
|
1157 |
const int textMargin = margin(option); |
|
1158 |
headingText->setRect( qMax( leftX, rightX - textWidth ), y, qMin( textWidth, rightX - leftX ), headingText->height() ); |
|
1159 |
detailText->setRect( headingText->left(), headingText->bottom() + textMargin, headingText->width(), detailText->height() ); |
|
1160 |
} |
|
1161 |
else |
|
1162 |
{ |
|
1163 |
*headingText = QRect(); |
|
1164 |
*detailText = QRect(); |
|
1165 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1166 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1167 |
else |
80 | 1168 |
{ |
1169 |
if ( headingText->isValid() ) |
|
1170 |
{ |
|
1171 |
if ( rightX > leftX ) |
|
1172 |
{ |
|
1173 |
headingText->setRect( qMax( rightX - headingText->width(), leftX ), y, qMin( headingText->width(), rightX - leftX ) , h ); |
|
1174 |
rightX = headingText->left(); |
|
1175 |
} |
|
1176 |
else |
|
1177 |
{ |
|
1178 |
*headingText = QRect(); |
|
1179 |
} |
|
1180 |
} |
|
1181 |
||
1182 |
if ( detailText->isValid() ) |
|
1183 |
{ |
|
1184 |
if ( rightX > leftX ) |
|
1185 |
{ |
|
1186 |
detailText->setRect( qMax( rightX - detailText->width(), leftX ), y, qMin( detailText->width(), rightX - leftX ) , h ); |
|
1187 |
} |
|
1188 |
else |
|
1189 |
{ |
|
1190 |
*detailText = QRect(); |
|
1191 |
} |
|
1192 |
} |
|
1193 |
} |
|
1194 |
} |
|
1195 |
else // left to right |
|
1196 |
{ |
|
1197 |
if (check->isValid() ) |
|
1198 |
{ |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1199 |
check->setRect( leftX, y, qMin( check->width(), rightX - leftX ), h ); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1200 |
leftX = check->right(); |
80 | 1201 |
} |
1202 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1203 |
if ( headingImage->isValid() ) |
80 | 1204 |
{ |
1205 |
if ( rightX > leftX ) |
|
1206 |
{ |
|
1207 |
headingImage->setRect( leftX, y, qMin( headingImage->width(), rightX - leftX ) , h ); |
|
1208 |
leftX = headingImage->right(); |
|
1209 |
} |
|
1210 |
else |
|
1211 |
{ |
|
1212 |
*headingImage = QRect(); |
|
1213 |
} |
|
1214 |
} |
|
1215 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1216 |
if ( detailImage->isValid() ) |
80 | 1217 |
{ |
1218 |
if ( rightX > leftX ) |
|
1219 |
{ |
|
1220 |
int detailImageX = leftX; |
|
1221 |
int detailImageWidth = detailImage->width(); |
|
1222 |
if( (rightX -leftX) >= (textWidth + detailImageWidth) ) |
|
1223 |
{ |
|
1224 |
detailImageX = leftX + textWidth; |
|
1225 |
} |
|
1226 |
else |
|
1227 |
{ |
|
1228 |
detailImageX = qMax( leftX, rightX - detailImageWidth ); |
|
1229 |
} |
|
1230 |
detailImage->setRect( detailImageX, y, qMin( detailImageWidth, rightX - detailImageX ), h ); |
|
1231 |
rightX = detailImage->left(); |
|
1232 |
} |
|
1233 |
else |
|
1234 |
{ |
|
1235 |
*detailImage = QRect(); |
|
1236 |
} |
|
1237 |
} |
|
1238 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1239 |
if ( ( layoutStyle & LB_STYLE_2LINE_ITEM ) != 0 ) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1240 |
{ |
80 | 1241 |
if ( rightX > leftX ) |
1242 |
{ |
|
1243 |
const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option); |
|
1244 |
const QWidget* widget = v3 ? v3->widget : NULL; |
|
1245 |
QStyle* style = widget ? widget->style() : QApplication::style(); |
|
1246 |
const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1; |
|
1247 |
headingText->setRect( leftX , y, qMin( textWidth, rightX - leftX ), headingText->height() ); |
|
1248 |
detailText->setRect( headingText->left(), headingText->bottom() + textMargin, headingText->width(), detailText->height() ); |
|
1249 |
} |
|
1250 |
else |
|
1251 |
{ |
|
1252 |
*headingText = QRect(); |
|
1253 |
*detailText = QRect(); |
|
1254 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1255 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1256 |
else |
80 | 1257 |
{ |
1258 |
if ( headingText->isValid() ) |
|
1259 |
{ |
|
1260 |
if ( rightX > leftX ) |
|
1261 |
{ |
|
1262 |
headingText->setRect( leftX, y, qMin( headingText->width(), rightX - leftX ) , h ); |
|
1263 |
leftX = headingText->right(); |
|
1264 |
} |
|
1265 |
else |
|
1266 |
{ |
|
1267 |
*headingText = QRect(); |
|
1268 |
} |
|
1269 |
} |
|
1270 |
||
1271 |
if ( detailText->isValid() ) |
|
1272 |
{ |
|
1273 |
if ( rightX > leftX ) |
|
1274 |
{ |
|
1275 |
detailText->setRect( leftX, y, qMin( detailText->width(), rightX - leftX ) , h ); |
|
1276 |
} |
|
1277 |
else |
|
1278 |
{ |
|
1279 |
*detailText = QRect(); |
|
1280 |
} |
|
1281 |
} |
|
1282 |
} |
|
1283 |
} |
|
1284 |
SWT_LOG_DATA_4("check rect: size=(%d, %d); topleft=(%d, %d)", check->width(), check->height(), check->left(), check->top() ); |
|
1285 |
SWT_LOG_DATA_4("heading image rect: size=(%d, %d); topleft=(%d, %d)", headingImage->width(), headingImage->height(), headingImage->left(), headingImage->top() ); |
|
1286 |
SWT_LOG_DATA_4("detail image rect: size=(%d, %d); topleft=(%d, %d)", detailImage->width(), detailImage->height(), detailImage->left(), detailImage->top() ); |
|
1287 |
SWT_LOG_DATA_4("heading text rect: size=(%d, %d); topleft=(%d, %d)", headingText->width(), headingText->height(), headingText->left(), headingText->top() ); |
|
1288 |
SWT_LOG_DATA_4("detail text rect: size=(%d, %d); topleft=(%d, %d)", detailText->width(), detailText->height(), detailText->left(), detailText->top() ); |
|
1289 |
||
1290 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1291 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1292 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1293 |
void ListBoxItemDelegate::doLayout( const QStyleOptionViewItem &option, QRect* checkRect, QRect* headingImageRect, |
80 | 1294 |
QRect* detailImageRect, QRect* headingTextRect, QRect* detailTextRect ) const |
1295 |
{ |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1296 |
Q_ASSERT( checkRect && headingImageRect && detailImageRect && headingTextRect && detailTextRect ); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1297 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1298 |
// duplicate rects |
80 | 1299 |
QRect check = *checkRect; |
1300 |
QRect headingImage = *headingImageRect; |
|
1301 |
QRect detailImage = *detailImageRect; |
|
1302 |
QRect headingText = *headingTextRect; |
|
1303 |
QRect detailText = *detailTextRect; |
|
1304 |
||
1305 |
// layout duplicated rects |
|
1306 |
layoutRects( option, &check, &headingImage, &detailImage, &headingText, &detailText, false ); |
|
1307 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1308 |
|
80 | 1309 |
// remove margins |
1310 |
const int mg = margin(option); |
|
1311 |
if( checkRect->isValid() ) |
|
1312 |
{ |
|
1313 |
checkRect->setRight( checkRect->right() - 2 * mg ); |
|
1314 |
} |
|
1315 |
if( headingImageRect->isValid() ) |
|
1316 |
{ |
|
1317 |
headingImageRect->setRight( headingImageRect->right() - 2 * mg ); |
|
1318 |
} |
|
1319 |
if( detailImageRect->isValid() ) |
|
1320 |
{ |
|
1321 |
detailImageRect->setRight( detailImageRect->right() - 2 * mg ); |
|
1322 |
} |
|
1323 |
||
1324 |
// adust rectangles |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1325 |
*checkRect = QStyle::alignedRect( option.direction, Qt::AlignCenter, checkRect->size(), check ); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1326 |
*headingImageRect = QStyle::alignedRect( option.direction, option.decorationAlignment, headingImageRect->size(), headingImage ); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1327 |
*detailImageRect = QStyle::alignedRect( option.direction, option.decorationAlignment, detailImageRect->size().boundedTo(detailImage.size()), detailImage ); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1328 |
if (option.showDecorationSelected) |
80 | 1329 |
{ |
1330 |
// take up entire space |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1331 |
*headingTextRect = headingText; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1332 |
*detailTextRect = detailText; |
80 | 1333 |
} |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1334 |
else |
80 | 1335 |
{ |
1336 |
// aligne to the space |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1337 |
*headingTextRect = QStyle::alignedRect( option.direction, option.displayAlignment, |
80 | 1338 |
headingTextRect->size().boundedTo(headingText.size()), headingText ); |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1339 |
*detailTextRect = QStyle::alignedRect( option.direction, option.displayAlignment, |
80 | 1340 |
detailTextRect->size().boundedTo(detailText.size()), detailText ); |
1341 |
} |
|
1342 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1343 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1344 |
QSize ListBoxItemDelegate::sizeHint(const QStyleOptionViewItem &option, |
80 | 1345 |
const QModelIndex &index) const |
1346 |
{ |
|
1347 |
SWT_LOG_FUNC_CALL(); |
|
1348 |
||
1349 |
QSize checkSize; |
|
1350 |
QSize headingImageSize; |
|
1351 |
QSize detailImageSize; |
|
1352 |
QSize headingTextSize; |
|
1353 |
QSize detailTextSize; |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1354 |
|
80 | 1355 |
computeSizes( index, option, &checkSize, &headingImageSize, &detailImageSize, &headingTextSize, &detailTextSize ); |
1356 |
addMargins( option, &checkSize, &headingImageSize, &detailImageSize, &headingTextSize, &detailTextSize ); |
|
1357 |
SWT_LOG_DATA_2("check size=(%d, %d) ", checkSize.width(), checkSize.height() ); |
|
1358 |
SWT_LOG_DATA_2("heading image size=(%d, %d) ", headingImageSize.width(), headingImageSize.height() ); |
|
1359 |
SWT_LOG_DATA_2("detail imageSize size=(%d, %d) ", detailImageSize.width(), detailImageSize.height() ); |
|
1360 |
SWT_LOG_DATA_2("headingText size=(%d, %d) ", headingTextSize.width(), headingTextSize.height() ); |
|
1361 |
SWT_LOG_DATA_2("detail text size=(%d, %d) ", detailTextSize.width(), detailTextSize.height() ); |
|
1362 |
QSize size = computeSize( option, checkSize, headingImageSize, detailImageSize, headingTextSize, detailTextSize ); |
|
1363 |
SWT_LOG_DATA_2("hint size=(%d, %d) ", size.width(), size.height() ); |
|
1364 |
dataModel->updateLayoutData( index.row(), size.height(), |
|
1365 |
QPoint( detailTextSize.width(), detailTextSize.height() ), |
|
1366 |
QPoint( headingTextSize.width(), headingTextSize.height() ), |
|
1367 |
detailImageSize.width(), headingImageSize.width() ); |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1368 |
return size; |
80 | 1369 |
} |
1370 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1371 |
void ListBoxItemDelegate::setHeadingFont( QFont* font ) |
80 | 1372 |
{ |
1373 |
SWT_LOG_FUNC_CALL(); |
|
1374 |
headingFont = font; |
|
1375 |
} |
|
1376 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1377 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1378 |
QStyleOptionViewItem ListBoxItemDelegate::setOptions(const QModelIndex &index, |
80 | 1379 |
const QStyleOptionViewItem &option) const |
1380 |
{ |
|
1381 |
SWT_LOG_FUNC_CALL(); |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1382 |
QStyleOptionViewItem opt = option; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1383 |
|
80 | 1384 |
// ask data modle for font, alignment and brush, then set them |
1385 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1386 |
// set font |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1387 |
QVariant value = index.data(Qt::FontRole); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1388 |
if (value.isValid()){ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1389 |
opt.font = qvariant_cast<QFont>(value).resolve(opt.font); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1390 |
opt.fontMetrics = QFontMetrics(opt.font); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1391 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1392 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1393 |
// set text alignment |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1394 |
value = index.data(Qt::TextAlignmentRole); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1395 |
if (value.isValid()) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1396 |
opt.displayAlignment = static_cast<Qt::Alignment>(value.toInt()); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1397 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1398 |
// set foreground brush |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1399 |
value = index.data(Qt::ForegroundRole); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1400 |
if (qVariantCanConvert<QBrush>(value)) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1401 |
opt.palette.setBrush(QPalette::Text, qvariant_cast<QBrush>(value)); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1402 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1403 |
return opt; |
80 | 1404 |
} |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1405 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1406 |
QRect ListBoxItemDelegate::textRectangle( const int width, const QFont &font, const QString &text) const |
80 | 1407 |
{ |
1408 |
SWT_LOG_FUNC_CALL(); |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1409 |
QTextOption textOption; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1410 |
textOption.setWrapMode(QTextOption::WordWrap); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1411 |
textLayout.setTextOption( textOption ); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1412 |
textLayout.setFont( font ); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1413 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1414 |
// replace new line char with QChar::LineSeparator |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1415 |
QString replaceText = text; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1416 |
const QChar nl = QLatin1Char('\n'); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1417 |
for (int i = 0; i < text.count(); ++i) |
80 | 1418 |
{ |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1419 |
if (replaceText.at(i) == nl) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1420 |
replaceText[i] = QChar::LineSeparator; |
80 | 1421 |
} |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1422 |
textLayout.setText( replaceText ); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1423 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1424 |
qreal height = 0; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1425 |
qreal widthUsed = 0; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1426 |
textLayout.beginLayout(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1427 |
while (true) |
80 | 1428 |
{ |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1429 |
QTextLine line = textLayout.createLine(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1430 |
if ( !line.isValid() ) |
80 | 1431 |
{ |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1432 |
break; |
80 | 1433 |
} |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1434 |
line.setLineWidth( width ); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1435 |
line.setPosition( QPointF( 0, height ) ); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1436 |
height += line.height(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1437 |
widthUsed = qMax( widthUsed, line.naturalTextWidth() ); |
80 | 1438 |
} |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1439 |
textLayout.endLayout(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1440 |
QSize size = QSizeF(widthUsed, height).toSize(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1441 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1442 |
const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1443 |
return QRect(0, 0, size.width() + 2 * textMargin, size.height()); |
80 | 1444 |
} |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1445 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1446 |
int ListBoxItemDelegate::margin( const QStyleOptionViewItem &option ) const |
80 | 1447 |
{ |
1448 |
const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option); |
|
1449 |
const QWidget* widget = v3 ? v3->widget : NULL; |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1450 |
QStyle* style = widget ? widget->style() : QApplication::style(); |
80 | 1451 |
return style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1; |
1452 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1453 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1454 |
void ListBoxItemDelegate::drawImages( QPainter* painter, const QStyleOptionViewItem &option, |
80 | 1455 |
const QRect imageRect, const QList<QPixmap>& images, const int* imageWidths, const int imageCount ) const |
1456 |
{ |
|
1457 |
SWT_LOG_FUNC_CALL(); |
|
1458 |
SWT_LOG_DATA_4( "Heading image rect, row=%d: size=(%d, %d); topleft=(%d, %d)", imageRect.width(), imageRect.height(), imageRect.left(), imageRect.top() ); |
|
1459 |
const int imageMargin = margin(option); |
|
1460 |
const int top = imageRect.top(); |
|
1461 |
const int height = imageRect.height(); |
|
1462 |
int left = imageRect.left(); |
|
1463 |
int right = left; |
|
1464 |
QRect rect; |
|
1465 |
if( option.direction == Qt::RightToLeft ) |
|
1466 |
{ |
|
1467 |
right = imageRect.right(); |
|
1468 |
left=right; |
|
1469 |
for( int i = 0; i < imageCount; i++) |
|
1470 |
{ |
|
1471 |
left -= imageWidths[i]; |
|
1472 |
rect = QRect( left, top, right - left, height ); |
|
1473 |
if( !rect.isValid() )break; |
|
1474 |
rect = QStyle::alignedRect( option.direction, option.decorationAlignment, images[i].size(), rect ); |
|
1475 |
drawDecoration( painter, option, rect, images[i] ); |
|
1476 |
SWT_LOG_DATA_5("Image No.%d, size=(%d, %d); topleft=(%d, %d)", i, right - left, height, left, top ); |
|
1477 |
right = left - imageMargin; |
|
1478 |
left = right; |
|
1479 |
} |
|
1480 |
} |
|
1481 |
else |
|
1482 |
{ |
|
1483 |
for( int i = 0; i < imageCount; i++) |
|
1484 |
{ |
|
1485 |
right += imageWidths[i]; |
|
1486 |
rect = QRect( left, top, right - left, height ); |
|
1487 |
if( !rect.isValid() )break; |
|
1488 |
rect = QStyle::alignedRect( option.direction, option.decorationAlignment, images[i].size(), rect ); |
|
1489 |
drawDecoration( painter, option, rect, images[i] ); |
|
1490 |
SWT_LOG_DATA_5("Image No.%d, size=(%d, %d); topleft=(%d, %d)", i, right - left, height, left, top ); |
|
1491 |
left = right + imageMargin; |
|
1492 |
right = left; |
|
1493 |
} |
|
1494 |
} |
|
1495 |
} |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1496 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1497 |