author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 15 Mar 2010 12:43:09 +0200 | |
branch | RCL_3 |
changeset 6 | dee5afe5301f |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the examples of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <QtGui> |
|
43 |
||
44 |
#include "freezetablewidget.h" |
|
45 |
||
46 |
//! [constructor] |
|
47 |
FreezeTableWidget::FreezeTableWidget(QAbstractItemModel * model) |
|
48 |
{ |
|
49 |
setModel(model); |
|
50 |
frozenTableView = new QTableView(this); |
|
51 |
||
52 |
init(); |
|
53 |
||
54 |
//connect the headers and scrollbars of both tableviews together |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
55 |
connect(horizontalHeader(),SIGNAL(sectionResized(int,int,int)), this, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
56 |
SLOT(updateSectionWidth(int,int,int))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
57 |
connect(verticalHeader(),SIGNAL(sectionResized(int,int,int)), this, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
58 |
SLOT(updateSectionHeight(int,int,int))); |
0 | 59 |
|
60 |
connect(frozenTableView->verticalScrollBar(), SIGNAL(valueChanged(int)), |
|
61 |
verticalScrollBar(), SLOT(setValue(int))); |
|
62 |
connect(verticalScrollBar(), SIGNAL(valueChanged(int)), |
|
63 |
frozenTableView->verticalScrollBar(), SLOT(setValue(int))); |
|
64 |
||
65 |
||
66 |
} |
|
67 |
//! [constructor] |
|
68 |
||
69 |
FreezeTableWidget::~FreezeTableWidget() |
|
70 |
{ |
|
71 |
delete frozenTableView; |
|
72 |
} |
|
73 |
||
74 |
//! [init part1] |
|
75 |
void FreezeTableWidget::init() |
|
76 |
{ |
|
77 |
frozenTableView->setModel(model()); |
|
78 |
frozenTableView->setFocusPolicy(Qt::NoFocus); |
|
79 |
frozenTableView->verticalHeader()->hide(); |
|
80 |
frozenTableView->horizontalHeader()->setResizeMode(QHeaderView::Fixed); |
|
81 |
||
82 |
viewport()->stackUnder(frozenTableView); |
|
83 |
//! [init part1] |
|
84 |
||
85 |
//! [init part2] |
|
86 |
frozenTableView->setStyleSheet("QTableView { border: none;" |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
"background-color: #8EDE21;" |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
"selection-background-color: #999}"); //for demo purposes |
0 | 89 |
frozenTableView->setSelectionModel(selectionModel()); |
90 |
for(int col=1; col<model()->columnCount(); col++) |
|
91 |
frozenTableView->setColumnHidden(col, true); |
|
92 |
||
93 |
frozenTableView->setColumnWidth(0, columnWidth(0) ); |
|
94 |
||
95 |
frozenTableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
96 |
frozenTableView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
97 |
frozenTableView->show(); |
|
98 |
||
99 |
updateFrozenTableGeometry(); |
|
100 |
||
101 |
setHorizontalScrollMode(ScrollPerPixel); |
|
102 |
setVerticalScrollMode(ScrollPerPixel); |
|
103 |
frozenTableView->setVerticalScrollMode(ScrollPerPixel); |
|
104 |
} |
|
105 |
//! [init part2] |
|
106 |
||
107 |
||
108 |
//! [sections] |
|
109 |
void FreezeTableWidget::updateSectionWidth(int logicalIndex, int, int newSize) |
|
110 |
{ |
|
111 |
if(logicalIndex==0){ |
|
112 |
frozenTableView->setColumnWidth(0,newSize); |
|
113 |
updateFrozenTableGeometry(); |
|
114 |
} |
|
115 |
} |
|
116 |
||
117 |
void FreezeTableWidget::updateSectionHeight(int logicalIndex, int, int newSize) |
|
118 |
{ |
|
119 |
frozenTableView->setRowHeight(logicalIndex, newSize); |
|
120 |
} |
|
121 |
//! [sections] |
|
122 |
||
123 |
||
124 |
//! [resize] |
|
125 |
void FreezeTableWidget::resizeEvent(QResizeEvent * event) |
|
126 |
{ |
|
127 |
QTableView::resizeEvent(event); |
|
128 |
updateFrozenTableGeometry(); |
|
129 |
} |
|
130 |
//! [resize] |
|
131 |
||
132 |
||
133 |
//! [navigate] |
|
134 |
QModelIndex FreezeTableWidget::moveCursor(CursorAction cursorAction, |
|
135 |
Qt::KeyboardModifiers modifiers) |
|
136 |
{ |
|
137 |
QModelIndex current = QTableView::moveCursor(cursorAction, modifiers); |
|
138 |
||
139 |
if(cursorAction == MoveLeft && current.column()>0 |
|
140 |
&& visualRect(current).topLeft().x() < frozenTableView->columnWidth(0) ){ |
|
141 |
||
142 |
const int newValue = horizontalScrollBar()->value() + visualRect(current).topLeft().x() |
|
143 |
- frozenTableView->columnWidth(0); |
|
144 |
horizontalScrollBar()->setValue(newValue); |
|
145 |
} |
|
146 |
return current; |
|
147 |
} |
|
148 |
//! [navigate] |
|
149 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
void FreezeTableWidget::scrollTo (const QModelIndex & index, ScrollHint hint){ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
if(index.column()>0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
QTableView::scrollTo(index, hint); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
155 |
|
0 | 156 |
|
157 |
//! [geometry] |
|
158 |
void FreezeTableWidget::updateFrozenTableGeometry() |
|
159 |
{ |
|
160 |
frozenTableView->setGeometry( verticalHeader()->width()+frameWidth(), |
|
161 |
frameWidth(), columnWidth(0), |
|
162 |
viewport()->height()+horizontalHeader()->height()); |
|
163 |
} |
|
164 |
//! [geometry] |
|
165 |
||
166 |