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 
37 #include "rotated_header_view.h"
38 #include <QPainter>
39 
40 namespace moveit_setup_assistant
41 {
42 RotatedHeaderView::RotatedHeaderView(Qt::Orientation orientation, QWidget* parent) : QHeaderView(orientation, parent)
43 {
44 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
45  setSectionsClickable(true);
46  setSectionResizeMode(Fixed);
47 #else
48  setClickable(true);
49  setResizeMode(Fixed);
50 #endif
51  setDefaultSectionSize(27);
52 }
53 
54 void RotatedHeaderView::paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const
55 {
56  if (orientation() == Qt::Vertical)
57  {
58  QHeaderView::paintSection(painter, rect, logicalIndex);
59  return;
60  }
61 
62  painter->save();
63  // rotate about (x,y)
64  painter->translate(rect.x(), rect.y());
65  painter->rotate(-90);
66  painter->translate(-rect.height(), 0);
67  QHeaderView::paintSection(painter, QRect(0, 0, rect.height(), rect.width()), logicalIndex);
68  painter->restore();
69 }
70 
71 QSize RotatedHeaderView::sectionSizeFromContents(int logicalIndex) const
72 {
73  if (orientation() == Qt::Vertical)
74  return QHeaderView::sectionSizeFromContents(logicalIndex);
75 
76  Q_ASSERT(logicalIndex >= 0);
77 
78  ensurePolished();
79 
80  // use SizeHintRole
81  QVariant variant = model()->headerData(logicalIndex, Qt::Vertical, Qt::SizeHintRole);
82  if (variant.isValid())
83  return qvariant_cast<QSize>(variant);
84 
85  // otherwise use the contents
86  QStyleOptionHeader opt;
87  initStyleOption(&opt);
88  opt.section = logicalIndex;
89  QVariant var = model()->headerData(logicalIndex, orientation(), Qt::FontRole);
90  QFont fnt;
91  if (var.isValid() && var.canConvert<QFont>())
92  fnt = qvariant_cast<QFont>(var);
93  else
94  fnt = font();
95  fnt.setBold(true);
96  opt.fontMetrics = QFontMetrics(fnt);
97  opt.text = model()->headerData(logicalIndex, orientation(), Qt::DisplayRole).toString();
98  variant = model()->headerData(logicalIndex, orientation(), Qt::DecorationRole);
99  opt.icon = qvariant_cast<QIcon>(variant);
100  if (opt.icon.isNull())
101  opt.icon = qvariant_cast<QPixmap>(variant);
102  QSize size = style()->sizeFromContents(QStyle::CT_HeaderSection, &opt, QSize(), this);
103  if (isSortIndicatorShown())
104  {
105  int margin = style()->pixelMetric(QStyle::PM_HeaderMargin, &opt, this);
106  if (orientation() == Qt::Horizontal)
107  size.rwidth() += size.height() + margin;
108  else
109  size.rheight() += size.width() + margin;
110  }
111  return QSize(size.height(), size.width());
112 }
113 
114 int RotatedHeaderView::sectionSizeHint(int logicalIndex) const
115 {
116  if (isSectionHidden(logicalIndex))
117  return 0;
118  if (logicalIndex < 0 || logicalIndex >= count())
119  return -1;
120  QSize size;
121  QVariant value = model()->headerData(logicalIndex, orientation(), Qt::SizeHintRole);
122  if (value.isValid())
123  size = qvariant_cast<QSize>(value);
124  else
125  size = sectionSizeFromContents(logicalIndex);
126  int hint = size.height();
127  return qMax(minimumSectionSize(), hint);
128 }
129 } // namespace moveit_setup_assistant
moveit_setup_assistant::RotatedHeaderView::sectionSizeHint
int sectionSizeHint(int logicalIndex) const
Definition: rotated_header_view.cpp:146
value
float value
moveit_setup_assistant::RotatedHeaderView::paintSection
void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const override
Definition: rotated_header_view.cpp:86
moveit_setup_assistant
Definition: compute_default_collisions.h:46
moveit_setup_assistant::RotatedHeaderView::sectionSizeFromContents
QSize sectionSizeFromContents(int logicalIndex) const override
Definition: rotated_header_view.cpp:103
rotated_header_view.h
moveit_setup_assistant::RotatedHeaderView::RotatedHeaderView
RotatedHeaderView(Qt::Orientation orientation, QWidget *parent=nullptr)
Definition: rotated_header_view.cpp:74


moveit_setup_assistant
Author(s): Dave Coleman
autogenerated on Sat May 3 2025 02:28:04