mirror of
https://github.com/opentx/opentx.git
synced 2025-07-26 17:55:19 +03:00
Introduce autotimeedit widget
This commit is contained in:
parent
60ac1550f4
commit
3eed78dbd5
3 changed files with 99 additions and 0 deletions
|
@ -16,6 +16,7 @@ set(shared_HDRS
|
||||||
genericpanel.h
|
genericpanel.h
|
||||||
hexspinbox.h
|
hexspinbox.h
|
||||||
autoprecisioncombobox.h
|
autoprecisioncombobox.h
|
||||||
|
autotimeedit.h
|
||||||
)
|
)
|
||||||
|
|
||||||
qt5_wrap_cpp(shared_SRCS ${shared_HDRS})
|
qt5_wrap_cpp(shared_SRCS ${shared_HDRS})
|
||||||
|
|
97
companion/src/shared/autotimeedit.h
Normal file
97
companion/src/shared/autotimeedit.h
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) OpenTX
|
||||||
|
*
|
||||||
|
* Based on code named
|
||||||
|
* th9x - http://code.google.com/p/th9x
|
||||||
|
* er9x - http://code.google.com/p/er9x
|
||||||
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||||
|
*
|
||||||
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QTimeEdit>
|
||||||
|
#include "genericpanel.h"
|
||||||
|
|
||||||
|
class AutoTimeEdit: public QTimeEdit
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit AutoTimeEdit(QWidget * parent = nullptr):
|
||||||
|
QTimeEdit(parent),
|
||||||
|
field(nullptr),
|
||||||
|
panel(nullptr),
|
||||||
|
lock(false)
|
||||||
|
{
|
||||||
|
connect(this, SIGNAL(timeChanged(QTime)), this, SLOT(onTimeChanged(QTime)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setField(int & field, GenericPanel * panel = nullptr)
|
||||||
|
{
|
||||||
|
this->field = &field;
|
||||||
|
this->panel = panel;
|
||||||
|
updateValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMinimumTime(QTime time)
|
||||||
|
{
|
||||||
|
QTimeEdit::setMinimumTime(QTime time);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMaximumTime(QTime time)
|
||||||
|
{
|
||||||
|
QTimeEdit::setMaximumTime(QTime time);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
QTimeEdit::setEnabled(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateValue()
|
||||||
|
{
|
||||||
|
if (field) {
|
||||||
|
lock = true;
|
||||||
|
int hour = *field / 3600;
|
||||||
|
int min = (*field - (hour * 3600)) / 60;
|
||||||
|
int sec = (*field - (hour * 3600)) % 60;
|
||||||
|
setTime(QTime(hour, min, sec));
|
||||||
|
lock = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void currentDataChanged(unsigned int value);
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void onTimeChanged(QTime time)
|
||||||
|
{
|
||||||
|
if ((panel && panel->lock) || !field || lock)
|
||||||
|
return;
|
||||||
|
|
||||||
|
unsigned int val = time.hour() * 3600 + time.minute() * 60 + time.second();
|
||||||
|
if (*field != val) {
|
||||||
|
*field = val;
|
||||||
|
emit currentDataChanged(val);
|
||||||
|
if (panel)
|
||||||
|
emit panel->modified();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int *field = nullptr;
|
||||||
|
GenericPanel *panel = nullptr;
|
||||||
|
bool lock = false;
|
||||||
|
};
|
||||||
|
|
|
@ -40,6 +40,7 @@ class GenericPanel : public QWidget
|
||||||
friend class GVarGroup;
|
friend class GVarGroup;
|
||||||
friend class AutoPrecisionComboBox;
|
friend class AutoPrecisionComboBox;
|
||||||
friend class AutoBitsetCheckBox;
|
friend class AutoBitsetCheckBox;
|
||||||
|
friend class AutoTimeEdit;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GenericPanel(QWidget *parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware);
|
GenericPanel(QWidget *parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue