QtBase  v6.3.1
simplelist.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2020 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the examples of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
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 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 #include <QDebug>
30 #include <QGraphicsLinearLayout>
31 #include <QFont>
32 #include <QElapsedTimer>
33 
34 #include "simplelist.h"
35 static const int MinItemWidth = 276;
36 
38  : GvbWidget(parent),
39  m_list(new ListWidget(this))
40 {
42  layout->setContentsMargins(0,0,0,0);
43  setContentsMargins(0,0,0,0);
45  layout->addItem(m_list);
46  setObjectName("SimpleList");
47 }
48 
49 /*virtual*/
51 {
52 }
53 
55 {
56  item->setMinimumWidth(MinItemWidth);
57  m_list->addItem(item);
58 }
59 
61 {
62  item->setMinimumWidth(MinItemWidth);
63  m_list->insertItem(index, item);
64 }
65 
67 {
68  return static_cast<ListItem*>(m_list->takeItem(row));
69 }
70 
72 {
73  return static_cast<ListItem*>(m_list->itemAt(row));
74 }
75 
77 {
78  if (m_list)
79  return m_list->itemCount();
80  return 0;
81 }
82 
84 {
85  if (m_list)
86  return m_list->verticalScrollBar();
87  return 0;
88 }
89 
91 {
92  return m_list->listItemCaching();
93 }
94 
96 {
97  m_list->setListItemCaching(enable);
98 }
99 
101 {
102  static QElapsedTimer keyPressInterval;
103  static qreal step = 0.0;
104  static bool repeat = false;
105  int interval = keyPressInterval.isValid() ? keyPressInterval.elapsed() : 0;
106 
109 
110  if(interval < 250 ) {
111  if(!repeat) step = 0.0;
112  step = step + 2.0;
113  if(step > 100) step = 100;
114  repeat = true;
115  }
116  else {
117  step = 1.0;
118  if(itemAt(0))
119  step = itemAt(0)->size().height();
120  repeat = false;
121  }
122 
123  if(event->key() == Qt::Key_Up ) { //Up Arrow
125  }
126 
127  if(event->key() == Qt::Key_Down ) { //Down Arrow
129  }
130  keyPressInterval.start();
131 }
132 
133 
134 void SimpleList::setTwoColumns(const bool twoColumns)
135 {
136  m_list->setTwoColumns(twoColumns);
137 }
138 
140 {
141  return m_list->twoColumns();
142 }
143 
bool twoColumns()
Definition: listwidget.cpp:114
bool listItemCaching() const
Definition: listwidget.cpp:99
QGraphicsWidget * itemAt(int row)
Definition: listwidget.cpp:74
void setTwoColumns(const bool twoColumns)
Definition: listwidget.cpp:109
QGraphicsWidget * takeItem(int row)
Definition: listwidget.cpp:69
void insertItem(int index, QGraphicsWidget *item)
Definition: listwidget.cpp:64
void setListItemCaching(bool enable)
Definition: listwidget.cpp:104
void addItem(QGraphicsWidget *item)
Definition: listwidget.cpp:59
int itemCount() const
Definition: listwidget.cpp:85
ScrollBar * verticalScrollBar() const
Definition: listwidget.cpp:92
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:49
qint64 elapsed() const noexcept
void start() noexcept
bool isValid() const noexcept
void setContentsMargins(qreal left, qreal top, qreal right, qreal bottom)
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
void setLayout(QGraphicsLayout *layout)
void setContentsMargins(qreal left, qreal top, qreal right, qreal bottom)
QGraphicsLayout * layout
The layout of the widget.
QSizeF size
the size of the widget
The QKeyEvent class describes a key event.
Definition: qevent.h:471
void setObjectName(const QString &name)
Definition: qobject.cpp:1261
constexpr qreal height() const noexcept
Definition: qsize.h:352
qreal sliderPosition() const
Definition: scrollbar.cpp:176
void setSliderPosition(qreal pos)
Definition: scrollbar.cpp:167
ScrollBar * verticalScrollBar() const
Definition: simplelist.cpp:83
virtual void keyPressEvent(QKeyEvent *event)
Definition: simplelist.cpp:100
bool twoColumns()
Definition: simplelist.cpp:139
void addItem(ListItem *item)
Definition: simplelist.cpp:54
virtual ~SimpleList()
Definition: simplelist.cpp:50
void insertItem(int index, ListItem *item)
Definition: simplelist.cpp:60
void setListItemCaching(bool enable)
Definition: simplelist.cpp:95
ListItem * takeItem(int row)
Definition: simplelist.cpp:66
void setTwoColumns(const bool twoColumns)
Definition: simplelist.cpp:134
SimpleList(QGraphicsWidget *parent=0)
Definition: simplelist.cpp:37
bool listItemCaching() const
Definition: simplelist.cpp:90
ListItem * itemAt(int row)
Definition: simplelist.cpp:71
int itemCount() const
Definition: simplelist.cpp:76
float step
#define this
Definition: dialogs.cpp:56
GeneratorWrapper< T > repeat(size_t repeats, GeneratorWrapper< T > &&generator)
Definition: catch_p_p.h:4251
@ Key_Up
Definition: qnamespace.h:699
@ Key_Down
Definition: qnamespace.h:701
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
GLuint index
[2]
GLboolean enable
struct _cl_event * event
Definition: qopenglext.h:2998
GLenum GLenum GLsizei void * row
Definition: qopenglext.h:2747
QGraphicsItem * item
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent