Kstars

mountmotionwidget.cpp
1/* Widget to control the mount motion.
2 SPDX-FileCopyrightText: Wolfgang Reissenberger <sterne-jaeger@openfuture.de>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7
8#include "mountmotionwidget.h"
9#include "klocalizedstring.h"
10
11#include <QKeyEvent>
12
13extern const char *libindi_strings_context;
14
15namespace Ekos
16{
17MountMotionWidget::MountMotionWidget(QWidget *parent)
18 : QWidget{parent}
19{
20 setupUi(this);
21 // North West
22 northWest->setIcon(QIcon(":/icons/go-northwest"));
23 connect(northWest, &QAbstractButton::pressed, this, [this]()
24 {
25 emit newMotionCommand(0, 0, 0);
26 });
27 connect(northWest, &QAbstractButton::released, this, [this]()
28 {
29 emit newMotionCommand(1, 0, 0);
30 });
31
32 // North
33 north->setIcon(QIcon(":/icons/go-north"));
34 connect(north, &QAbstractButton::pressed, this, [this]()
35 {
36 emit newMotionCommand(0, 0, -1);
37 });
38 connect(north, &QAbstractButton::released, this, [this]()
39 {
40 emit newMotionCommand(1, 0, -1);
41 });
42
43 // North East
44 northEast->setIcon(QIcon(":/icons/go-northeast"));
45 connect(northEast, &QAbstractButton::pressed, this, [this]()
46 {
47 emit newMotionCommand(0, 0, 1);
48 });
49 connect(northEast, &QAbstractButton::released, this, [this]()
50 {
51 emit newMotionCommand(1, 0, 1);
52 });
53
54 // West
55 west->setIcon(QIcon(":/icons/go-west"));
56 connect(west, &QAbstractButton::pressed, this, [this]()
57 {
58 emit newMotionCommand(0, -1, 0);
59 });
60 connect(west, &QAbstractButton::released, this, [this]()
61 {
62 emit newMotionCommand(1, -1, 0);
63 });
64
65 // Stop
66 stop->setIcon(QIcon(":/icons/stop"));
67 connect(stop, &QAbstractButton::pressed, this, [this]()
68 {
69 emit aborted();
70 });
71
72 // East
73 east->setIcon(QIcon(":/icons/go-east"));
74 connect(east, &QAbstractButton::pressed, this, [this]()
75 {
76
77 emit newMotionCommand(0, -1, 1);
78 });
79 connect(east, &QAbstractButton::released, this, [this]()
80 {
81 emit newMotionCommand(1, -1, 1);
82 });
83
84 // South West
85 southWest->setIcon(QIcon(":/icons/go-southwest"));
86 connect(southWest, &QAbstractButton::pressed, this, [this]()
87 {
88
89 emit newMotionCommand(0, 1, 0);
90 });
91 connect(southWest, &QAbstractButton::released, this, [this]()
92 {
93 emit newMotionCommand(1, 1, 0);
94 });
95
96 // South
97 south->setIcon(QIcon(":/icons/go-south"));
98 connect(south, &QAbstractButton::pressed, this, [this]()
99 {
100
101 emit newMotionCommand(0, 1, -1);
102 });
103 connect(south, &QAbstractButton::released, this, [this]()
104 {
105 emit newMotionCommand(1, 1, -1);
106 });
107
108 // South East
109 southEast->setIcon(QIcon(":/icons/go-southeast"));
110 connect(southEast, &QAbstractButton::pressed, this, [this]()
111 {
112 emit newMotionCommand(0, 1, 1);
113
114 });
115 connect(southEast, &QAbstractButton::released, this, [this]()
116 {
117 emit newMotionCommand(1, 1, 1);
118 });
119
120 // Slew Rate
121 connect(speedSliderObject, &QSlider::sliderReleased, this, [this]()
122 {
123 emit newSlewRate(speedSliderObject->value());
124 });
125
126 // Up/down Reverse
127 connect(upDownCheckObject, &QCheckBox::toggled, this, &MountMotionWidget::updownReversed);
128
129 // Left/Right Reverse
130 connect(leftRightCheckObject, &QCheckBox::toggled, this, &MountMotionWidget::leftrightReversed);
131}
132
133/////////////////////////////////////////////////////////////////////////////////////////
134///
135/////////////////////////////////////////////////////////////////////////////////////////
136void MountMotionWidget::syncSpeedInfo(INDI::PropertyView<ISwitch> *svp)
137{
138 if (svp != nullptr)
139 {
140 int index = svp->findOnSwitchIndex();
141 speedSliderObject->setEnabled(true);
142 speedSliderObject->setMaximum(svp->count() - 1);
143 speedSliderObject->setValue(index);
144
145 speedLabelObject->setText(i18nc(libindi_strings_context, svp->at(index)->getLabel()));
146 speedLabelObject->setEnabled(true);
147 }
148 else
149 {
150 // QtQuick
151 speedSliderObject->setEnabled(false);
152 speedLabelObject->setEnabled(false);
153 }
154}
155
156/////////////////////////////////////////////////////////////////////////////////////////
157///
158/////////////////////////////////////////////////////////////////////////////////////////
159void MountMotionWidget::updateSpeedInfo(INDI::PropertyView<ISwitch> *svp)
160{
161 if (svp != nullptr)
162 {
163 auto index = svp->findOnSwitchIndex();
164 speedSliderObject->setProperty("value", index);
165 speedLabelObject->setProperty("text", i18nc(libindi_strings_context, svp->at(index)->getLabel()));
166 }
167}
168
169/////////////////////////////////////////////////////////////////////////////////////////
170///
171/////////////////////////////////////////////////////////////////////////////////////////
172void MountMotionWidget::keyPressEvent(QKeyEvent *event)
173{
174 if (event->isAutoRepeat())
175 return;
176
177 switch (event->key())
178 {
179 case Qt::Key_Up:
180 {
181 north->setDown(true);
182 emit newMotionCommand(0, 0, -1);
183 break;
184 }
185 case Qt::Key_Down:
186 {
187 south->setDown(true);
188 emit newMotionCommand(0, 1, -1);
189 break;
190 }
191 case Qt::Key_Right:
192 {
193 east->setDown(true);
194 emit newMotionCommand(0, -1, 1);
195 break;
196 }
197 case Qt::Key_Left:
198 {
199 west->setDown(true);
200 emit newMotionCommand(0, -1, 0);
201 break;
202 }
203 case Qt::Key_Space:
204 {
205 break;
206 }
207 }
208
209 event->ignore();
210}
211
212/////////////////////////////////////////////////////////////////////////////////////////
213///
214/////////////////////////////////////////////////////////////////////////////////////////
215void MountMotionWidget::keyReleaseEvent(QKeyEvent *event)
216{
217 if (event->isAutoRepeat())
218 return;
219
220 switch (event->key())
221 {
222 case Qt::Key_Up:
223 {
224 north->setDown(false);
225 emit newMotionCommand(1, 0, -1);
226 break;
227 }
228 case Qt::Key_Down:
229 {
230 south->setDown(false);
231 emit newMotionCommand(1, 1, -1);
232 break;
233 }
234 case Qt::Key_Right:
235 {
236 east->setDown(false);
237 emit newMotionCommand(1, -1, 1);
238 break;
239 }
240 case Qt::Key_Left:
241 {
242 west->setDown(false);
243 emit newMotionCommand(1, -1, 0);
244 break;
245 }
246 case Qt::Key_Space:
247 {
248 stop->click();
249 break;
250 }
251 }
252
253 event->ignore();
254}
255
256} // namespace
void setIcon(const QIcon &iconset)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
KGuiItem stop()
void toggled(bool checked)
void sliderReleased()
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.