moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
rotated_header_view.cpp
Go to the documentation of this file.
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2016, CITEC, Bielefeld University
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34
35/* Author: Robert Haschke */
36
38#include <QPainter>
39
40namespace moveit_setup
41{
42namespace srdf_setup
43{
44RotatedHeaderView::RotatedHeaderView(Qt::Orientation orientation, QWidget* parent) : QHeaderView(orientation, parent)
45{
46#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
47 setSectionsClickable(true);
48 setSectionResizeMode(Fixed);
49#else
50 setClickable(true);
51 setResizeMode(Fixed);
52#endif
53 setDefaultSectionSize(27);
54}
55
56void RotatedHeaderView::paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const
57{
58 if (orientation() == Qt::Vertical)
59 {
60 QHeaderView::paintSection(painter, rect, logicalIndex);
61 return;
62 }
63
64 painter->save();
65 // rotate about (x,y)
66 painter->translate(rect.x(), rect.y());
67 painter->rotate(-90);
68 painter->translate(-rect.height(), 0);
69 QHeaderView::paintSection(painter, QRect(0, 0, rect.height(), rect.width()), logicalIndex);
70 painter->restore();
71}
72
73QSize RotatedHeaderView::sectionSizeFromContents(int logicalIndex) const
74{
75 if (orientation() == Qt::Vertical)
76 return QHeaderView::sectionSizeFromContents(logicalIndex);
77
78 Q_ASSERT(logicalIndex >= 0);
79
80 ensurePolished();
81
82 // use SizeHintRole
83 QVariant variant = model()->headerData(logicalIndex, Qt::Vertical, Qt::SizeHintRole);
84 if (variant.isValid())
85 return qvariant_cast<QSize>(variant);
86
87 // otherwise use the contents
88 QStyleOptionHeader opt;
89 initStyleOption(&opt);
90 opt.section = logicalIndex;
91 QVariant var = model()->headerData(logicalIndex, orientation(), Qt::FontRole);
92 QFont fnt;
93 if (var.isValid() && var.canConvert<QFont>())
94 {
95 fnt = qvariant_cast<QFont>(var);
96 }
97 else
98 {
99 fnt = font();
100 }
101 fnt.setBold(true);
102 opt.fontMetrics = QFontMetrics(fnt);
103 opt.text = model()->headerData(logicalIndex, orientation(), Qt::DisplayRole).toString();
104 variant = model()->headerData(logicalIndex, orientation(), Qt::DecorationRole);
105 opt.icon = qvariant_cast<QIcon>(variant);
106 if (opt.icon.isNull())
107 opt.icon = qvariant_cast<QPixmap>(variant);
108 QSize size = style()->sizeFromContents(QStyle::CT_HeaderSection, &opt, QSize(), this);
109 if (isSortIndicatorShown())
110 {
111 int margin = style()->pixelMetric(QStyle::PM_HeaderMargin, &opt, this);
112 if (orientation() == Qt::Horizontal)
113 {
114 size.rwidth() += size.height() + margin;
115 }
116 else
117 {
118 size.rheight() += size.width() + margin;
119 }
120 }
121 return QSize(size.height(), size.width());
122}
123
124int RotatedHeaderView::sectionSizeHint(int logicalIndex) const
125{
126 if (isSectionHidden(logicalIndex))
127 return 0;
128 if (logicalIndex < 0 || logicalIndex >= count())
129 return -1;
130 QSize size;
131 QVariant value = model()->headerData(logicalIndex, orientation(), Qt::SizeHintRole);
132 if (value.isValid())
133 {
134 size = qvariant_cast<QSize>(value);
135 }
136 else
137 {
138 size = sectionSizeFromContents(logicalIndex);
139 }
140 int hint = size.height();
141 return qMax(minimumSectionSize(), hint);
142}
143} // namespace srdf_setup
144} // namespace moveit_setup
void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const override
RotatedHeaderView(Qt::Orientation orientation, QWidget *parent=nullptr)
QSize sectionSizeFromContents(int logicalIndex) const override