QtBase  v6.3.1
doc_src_layout.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the documentation of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** BSD License Usage
18 ** Alternatively, you may use this file under the terms of the BSD license
19 ** as follows:
20 **
21 ** "Redistribution and use in source and binary forms, with or without
22 ** modification, are permitted provided that the following conditions are
23 ** met:
24 ** * Redistributions of source code must retain the above copyright
25 ** notice, this list of conditions and the following disclaimer.
26 ** * Redistributions in binary form must reproduce the above copyright
27 ** notice, this list of conditions and the following disclaimer in
28 ** the documentation and/or other materials provided with the
29 ** distribution.
30 ** * Neither the name of The Qt Company Ltd nor the names of its
31 ** contributors may be used to endorse or promote products derived
32 ** from this software without specific prior written permission.
33 **
34 **
35 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46 **
47 ** $QT_END_LICENSE$
48 **
49 ****************************************************************************/
50 
52 #ifndef CARD_H
53 #define CARD_H
54 
55 #include <QtWidgets>
56 #include <QList>
57 
58 class CardLayout : public QLayout
59 {
60 public:
62  { setSpacing(spacing); }
64  { setSpacing(spacing); }
65  ~CardLayout();
66 
67  void addItem(QLayoutItem *item) override;
68  QSize sizeHint() const override;
69  QSize minimumSize() const override;
70  int count() const override;
71  QLayoutItem *itemAt(int) const override;
72  QLayoutItem *takeAt(int) override;
73  void setGeometry(const QRect &rect) override;
74 
75 private:
76  QList<QLayoutItem *> m_items;
77 };
78 #endif
80 
81 
83 //#include "card.h"
85 
87 int CardLayout::count() const
88 {
89  // QList::size() returns the number of QLayoutItems in m_items
90  return m_items.size();
91 }
93 
96 {
97  // QList::value() performs index checking, and returns nullptr if we are
98  // outside the valid range
99  return m_items.value(idx);
100 }
101 
103 {
104  // QList::take does not do index checking
105  return idx >= 0 && idx < m_items.size() ? m_items.takeAt(idx) : 0;
106 }
108 
109 
112 {
113  m_items.append(item);
114 }
116 
117 
120 {
121  QLayoutItem *item;
122  while ((item = takeAt(0)))
123  delete item;
124 }
126 
127 
130 {
132 
133  if (m_items.size() == 0)
134  return;
135 
136  int w = r.width() - (m_items.count() - 1) * spacing();
137  int h = r.height() - (m_items.count() - 1) * spacing();
138  int i = 0;
139  while (i < m_items.size()) {
140  QLayoutItem *o = m_items.at(i);
141  QRect geom(r.x() + i * spacing(), r.y() + i * spacing(), w, h);
142  o->setGeometry(geom);
143  ++i;
144  }
145 }
147 
148 
151 {
152  QSize s(0, 0);
153  int n = m_items.count();
154  if (n > 0)
155  s = QSize(100, 70); //start with a nice default size
156  int i = 0;
157  while (i < n) {
158  QLayoutItem *o = m_items.at(i);
159  s = s.expandedTo(o->sizeHint());
160  ++i;
161  }
162  return s + n * QSize(spacing(), spacing());
163 }
164 
166 {
167  QSize s(0, 0);
168  int n = m_items.count();
169  int i = 0;
170  while (i < n) {
171  QLayoutItem *o = m_items.at(i);
172  s = s.expandedTo(o->minimumSize());
173  ++i;
174  }
175  return s + n * QSize(spacing(), spacing());
176 }
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
FT_UInt idx
Definition: cffcmap.c:135
void setGeometry(const QRect &rect) override
[5]
QLayoutItem * itemAt(int) const override
[2]
void addItem(QLayoutItem *item) override
[3]
QSize sizeHint() const override
[6]
CardLayout(int spacing)
int count() const override
[0]
QLayoutItem * takeAt(int) override
QSize minimumSize() const override
CardLayout(int spacing, QWidget *parent)
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:62
int spacing
the spacing between widgets inside the layout
Definition: qlayout.h:66
virtual void setSpacing(int)
Definition: qlayout.cpp:303
virtual void setGeometry(const QRect &) override
Definition: qlayout.cpp:488
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:61
qsizetype size() const noexcept
Definition: qlist.h:414
T takeAt(qsizetype i)
Definition: qlist.h:607
const_reference at(qsizetype i) const noexcept
Definition: qlist.h:457
T value(qsizetype i) const
Definition: qlist.h:676
qsizetype count() const noexcept
Definition: qlist.h:415
void append(parameter_type t)
Definition: qlist.h:469
QObject * parent() const
Definition: qobject.h:409
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:55
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
rect
[4]
GLboolean r
[2]
GLfloat GLfloat GLfloat w
[0]
GLfloat n
GLfloat GLfloat GLfloat GLfloat h
GLdouble s
[6]
Definition: qopenglext.h:235
QGraphicsItem * item