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 examples 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 | |
51 | #include "slidersgroup.h" |
52 | #include "window.h" |
53 | |
54 | #include <QCheckBox> |
55 | #include <QComboBox> |
56 | #include <QHBoxLayout> |
57 | #include <QLabel> |
58 | #include <QSpinBox> |
59 | #include <QStackedWidget> |
60 | |
61 | //! [0] |
62 | Window::Window(QWidget *parent) |
63 | : QWidget(parent) |
64 | { |
65 | horizontalSliders = new SlidersGroup(Qt::Horizontal, tr(s: "Horizontal" )); |
66 | verticalSliders = new SlidersGroup(Qt::Vertical, tr(s: "Vertical" )); |
67 | |
68 | stackedWidget = new QStackedWidget; |
69 | stackedWidget->addWidget(w: horizontalSliders); |
70 | stackedWidget->addWidget(w: verticalSliders); |
71 | |
72 | createControls(title: tr(s: "Controls" )); |
73 | //! [0] |
74 | |
75 | //! [1] |
76 | connect(sender: horizontalSliders, signal: &SlidersGroup::valueChanged, |
77 | //! [1] //! [2] |
78 | receiver: verticalSliders, slot: &SlidersGroup::setValue); |
79 | connect(sender: verticalSliders, signal: &SlidersGroup::valueChanged, |
80 | receiver: valueSpinBox, slot: &QSpinBox::setValue); |
81 | connect(sender: valueSpinBox, signal: QOverload<int>::of(ptr: &QSpinBox::valueChanged), |
82 | receiver: horizontalSliders, slot: &SlidersGroup::setValue); |
83 | |
84 | QHBoxLayout *layout = new QHBoxLayout; |
85 | layout->addWidget(controlsGroup); |
86 | layout->addWidget(stackedWidget); |
87 | setLayout(layout); |
88 | |
89 | minimumSpinBox->setValue(0); |
90 | maximumSpinBox->setValue(20); |
91 | valueSpinBox->setValue(5); |
92 | |
93 | setWindowTitle(tr(s: "Sliders" )); |
94 | } |
95 | //! [2] |
96 | |
97 | //! [3] |
98 | void Window::createControls(const QString &title) |
99 | //! [3] //! [4] |
100 | { |
101 | controlsGroup = new QGroupBox(title); |
102 | |
103 | minimumLabel = new QLabel(tr(s: "Minimum value:" )); |
104 | maximumLabel = new QLabel(tr(s: "Maximum value:" )); |
105 | valueLabel = new QLabel(tr(s: "Current value:" )); |
106 | |
107 | invertedAppearance = new QCheckBox(tr(s: "Inverted appearance" )); |
108 | invertedKeyBindings = new QCheckBox(tr(s: "Inverted key bindings" )); |
109 | |
110 | //! [4] //! [5] |
111 | minimumSpinBox = new QSpinBox; |
112 | //! [5] //! [6] |
113 | minimumSpinBox->setRange(min: -100, max: 100); |
114 | minimumSpinBox->setSingleStep(1); |
115 | |
116 | maximumSpinBox = new QSpinBox; |
117 | maximumSpinBox->setRange(min: -100, max: 100); |
118 | maximumSpinBox->setSingleStep(1); |
119 | |
120 | valueSpinBox = new QSpinBox; |
121 | valueSpinBox->setRange(min: -100, max: 100); |
122 | valueSpinBox->setSingleStep(1); |
123 | |
124 | orientationCombo = new QComboBox; |
125 | orientationCombo->addItem(atext: tr(s: "Horizontal slider-like widgets" )); |
126 | orientationCombo->addItem(atext: tr(s: "Vertical slider-like widgets" )); |
127 | |
128 | //! [6] //! [7] |
129 | connect(sender: orientationCombo, signal: QOverload<int>::of(ptr: &QComboBox::activated), |
130 | //! [7] //! [8] |
131 | receiver: stackedWidget, slot: &QStackedWidget::setCurrentIndex); |
132 | connect(sender: minimumSpinBox, signal: QOverload<int>::of(ptr: &QSpinBox::valueChanged), |
133 | receiver: horizontalSliders, slot: &SlidersGroup::setMinimum); |
134 | connect(sender: minimumSpinBox, signal: QOverload<int>::of(ptr: &QSpinBox::valueChanged), |
135 | receiver: verticalSliders, slot: &SlidersGroup::setMinimum); |
136 | connect(sender: maximumSpinBox, signal: QOverload<int>::of(ptr: &QSpinBox::valueChanged), |
137 | receiver: horizontalSliders, slot: &SlidersGroup::setMaximum); |
138 | connect(sender: maximumSpinBox, signal: QOverload<int>::of(ptr: &QSpinBox::valueChanged), |
139 | receiver: verticalSliders, slot: &SlidersGroup::setMaximum); |
140 | connect(sender: invertedAppearance, signal: &QCheckBox::toggled, |
141 | receiver: horizontalSliders, slot: &SlidersGroup::invertAppearance); |
142 | connect(sender: invertedAppearance, signal: &QCheckBox::toggled, |
143 | receiver: verticalSliders, slot: &SlidersGroup::invertAppearance); |
144 | connect(sender: invertedKeyBindings, signal: &QCheckBox::toggled, |
145 | receiver: horizontalSliders, slot: &SlidersGroup::invertKeyBindings); |
146 | connect(sender: invertedKeyBindings, signal: &QCheckBox::toggled, |
147 | receiver: verticalSliders, slot: &SlidersGroup::invertKeyBindings); |
148 | |
149 | QGridLayout *controlsLayout = new QGridLayout; |
150 | controlsLayout->addWidget(minimumLabel, row: 0, column: 0); |
151 | controlsLayout->addWidget(maximumLabel, row: 1, column: 0); |
152 | controlsLayout->addWidget(valueLabel, row: 2, column: 0); |
153 | controlsLayout->addWidget(minimumSpinBox, row: 0, column: 1); |
154 | controlsLayout->addWidget(maximumSpinBox, row: 1, column: 1); |
155 | controlsLayout->addWidget(valueSpinBox, row: 2, column: 1); |
156 | controlsLayout->addWidget(invertedAppearance, row: 0, column: 2); |
157 | controlsLayout->addWidget(invertedKeyBindings, row: 1, column: 2); |
158 | controlsLayout->addWidget(orientationCombo, row: 3, column: 0, rowSpan: 1, columnSpan: 3); |
159 | controlsGroup->setLayout(controlsLayout); |
160 | } |
161 | //! [8] |
162 | |