EnhancedTreeWidget.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 *
19 * @package ArmarX::RobotAPI
20 * @author Raphael Grimm <raphael dot grimm at kit dot edu>
21 * @date 2017
22 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
23 * GNU General Public License
24 */
25
26#include "EnhancedTreeWidget.h"
27
28#include <QHeaderView>
29#include <QScrollBar>
30#include <QWheelEvent>
31
32namespace armarx
33{
34
35 int
37 {
38 int sz = 0;
39 for (int i = 0; i < topLevelItemCount(); ++i)
40 {
41 sz += calcHeight(topLevelItem(i));
42 }
43 if (!isHeaderHidden())
44 {
45 sz += header()->height();
46 }
47 return sz + 2;
48 }
49
50 void
52 {
53 this->wheelTicksPerScrollTick = wheelTicksPerScrollTick;
54 }
55
56 void
58 {
59 if (event->orientation() == Qt::Horizontal)
60 {
61 if (horizontalScrollMode() == QAbstractItemView::ScrollPerPixel)
62 {
63 hdelta += event->delta();
64 horizontalScrollBar()->setValue(horizontalScrollBar()->value() -
65 (hdelta / wheelTicksPerScrollTick));
66 hdelta = hdelta % wheelTicksPerScrollTick;
67 }
68 else
69 {
70 QTreeWidget::wheelEvent(event);
71 }
72 }
73 else
74 {
75 if (verticalScrollMode() == QAbstractItemView::ScrollPerPixel)
76 {
77 vdelta += event->delta();
78 verticalScrollBar()->setValue(verticalScrollBar()->value() -
79 (vdelta / wheelTicksPerScrollTick));
80 vdelta = hdelta % wheelTicksPerScrollTick;
81 }
82 else
83 {
84 QTreeWidget::wheelEvent(event);
85 }
86 }
87 event->accept();
88 }
89
90 void
92 {
93 setSizePolicy(sizePolicy().horizontalPolicy(), QSizePolicy::Fixed);
94 setFixedHeight(getHeight());
95 }
96
97 void
99 {
100 if (active)
101 {
102 expand();
103 connect(this, SIGNAL(collapsed(QModelIndex)), this, SLOT(expand()));
104 connect(this, SIGNAL(expanded(QModelIndex)), this, SLOT(expand()));
105 }
106 else
107 {
108 disconnect(this, SIGNAL(collapsed(QModelIndex)), this, SLOT(expand()));
109 disconnect(this, SIGNAL(expanded(QModelIndex)), this, SLOT(expand()));
110 }
111 }
112
113 int
114 EnhancedTreeWidget::calcHeight(QTreeWidgetItem* it)
115 {
116 int sz = 0;
117 if (it->isHidden())
118 {
119 return sz;
120 }
121 for (int i = 0; i < it->columnCount(); ++i)
122 {
123 sz = std::max(sz, rowHeight(indexFromItem(it, i)));
124 }
125 if (it->isExpanded())
126 {
127 for (int i = 0; i < it->childCount(); ++i)
128 {
129 sz += calcHeight(it->child(i));
130 }
131 }
132 return sz;
133 }
134
135} // namespace armarx
void setWheelTicksPerScrollTick(int wheelTicksPerScrollTick)
void wheelEvent(QWheelEvent *event) override
This file offers overloads of toIce() and fromIce() functions for STL container types.