rqt_image_view/ratio_layouted_frame.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, Dirk Thomas, TU Darmstadt
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following
13  * disclaimer in the documentation and/or other materials provided
14  * with the distribution.
15  * * Neither the name of the TU Darmstadt nor the names of its
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
34 
35 #include <assert.h>
36 
37 namespace rqt_image_view {
38 
39 RatioLayoutedFrame::RatioLayoutedFrame(QWidget* parent, Qt::WFlags flags)
40  : QFrame()
41  , aspect_ratio_(4, 3)
42 {
43 }
44 
46 {
47 }
48 
50 {
51  QRect rect = contentsRect();
52 
53  // reduce longer edge to aspect ration
54  double width = double(rect.width());
55  double height = double(rect.height());
56  if (width * aspect_ratio_.height() / height > aspect_ratio_.width())
57  {
58  // too large width
59  width = height * aspect_ratio_.width() / aspect_ratio_.height();
60  rect.setWidth(int(width));
61  }
62  else
63  {
64  // too large height
65  height = width * aspect_ratio_.height() / aspect_ratio_.width();
66  rect.setHeight(int(height));
67  }
68 
69  // resize taking the border line into account
70  int border = lineWidth();
71  resize(rect.width() + 2 * border, rect.height() + 2 * border);
72 }
73 
75 {
76  int border = lineWidth();
77  QSize new_size = size;
78  new_size += QSize(2 * border, 2 * border);
79  setMinimumSize(new_size);
80  update();
81 }
82 
84 {
85  int border = lineWidth();
86  QSize new_size = size;
87  new_size += QSize(2 * border, 2 * border);
88  setMaximumSize(new_size);
89  update();
90 }
91 
93 {
96 }
97 
98 void RatioLayoutedFrame::setAspectRatio(unsigned short width, unsigned short height)
99 {
100  int divisor = greatestCommonDivisor(width, height);
101  if (divisor != 0) {
102  aspect_ratio_.setWidth(width / divisor);
103  aspect_ratio_.setHeight(height / divisor);
104  }
105 }
106 
108 {
109  if (b==0)
110  {
111  return a;
112  }
113  return greatestCommonDivisor(b, a % b);
114 }
115 
116 }
RatioLayoutedFrame(QWidget *parent, Qt::WFlags flags=0)
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
void setAspectRatio(unsigned short width, unsigned short height)


hector_rqt_plugins
Author(s): Dirk Thomas, Thorsten Graber, Gregor Gebhardt
autogenerated on Mon Jun 10 2019 13:36:34