2024-02-08 Fred Gleason <fredg@paravelsystems.com>

* Added 'RDTimeEdit::Mode' enumeration.
	* Added 'RDTimeEdit::mode()', 'RDTimeEdit::setMode()',
	'RDTimeEdit::length()' and 'RDTimeEdit::setLength()' methods.
	* Fixed a regression in rdlibrary(1) that caused the 'Forced Length'
	control in the 'Edit Cart' dialog to be misformatted when the
	system was configured to use 12 hour time format.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason
2024-02-08 10:04:46 -05:00
parent ae5d20cbe9
commit 38ef094ba3
5 changed files with 95 additions and 49 deletions

View File

@@ -2,7 +2,7 @@
//
// A QTimeEdit with tenth-second precision.
//
// (C) Copyright 2003-2021 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2003-2024 Fred Gleason <fredg@paravelsystems.com>
//
// 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
@@ -27,6 +27,7 @@
RDTimeEdit::RDTimeEdit(QWidget *parent)
: QTimeEdit(parent)
{
d_mode=RDTimeEdit::TimeMode;
d_show_hours=true;
d_show_tenths=false;
d_step_enabled=StepDownEnabled|StepUpEnabled;
@@ -37,6 +38,19 @@ RDTimeEdit::RDTimeEdit(QWidget *parent)
}
RDTimeEdit::Mode RDTimeEdit::mode() const
{
return d_mode;
}
void RDTimeEdit::setMode(Mode mode)
{
d_mode=mode;
SetFormat();
}
bool RDTimeEdit::showHours() const
{
return d_show_hours;
@@ -73,6 +87,18 @@ bool RDTimeEdit::isReadOnly() const
}
int RDTimeEdit::length() const
{
return QTime(0,0,0).msecsTo(time());
}
void RDTimeEdit::setLength(int msec)
{
setTime(QTime(0,0,0).addMSecs(100*(msec/100)));
}
void RDTimeEdit::setReadOnly(bool state)
{
if(d_read_only!=state) {
@@ -206,48 +232,60 @@ QAbstractSpinBox::StepEnabled RDTimeEdit::stepEnabled() const
void RDTimeEdit::SetFormat()
{
if(rda->system()->showTwelveHourTime()) {
if(d_show_tenths) {
if(d_show_hours) {
setDisplayFormat(RD_TWELVE_HOUR_TENTHS_FORMAT);
d_width_variance=1;
if(d_mode==RDTimeEdit::TimeMode) {
if(rda->system()->showTwelveHourTime()) {
if(d_show_tenths) {
if(d_show_hours) {
setDisplayFormat(RD_TWELVE_HOUR_TENTHS_FORMAT);
d_width_variance=1;
}
else {
setDisplayFormat(RD_OFFSET_TENTHS_FORMAT);
d_width_variance=0;
}
}
else {
setDisplayFormat(RD_OFFSET_TENTHS_FORMAT);
d_width_variance=0;
if(d_show_hours) {
setDisplayFormat(RD_TWELVE_HOUR_FORMAT);
d_width_variance=0;
}
else {
setDisplayFormat(RD_OFFSET_FORMAT);
d_width_variance=0;
}
}
}
else {
if(d_show_hours) {
setDisplayFormat(RD_TWELVE_HOUR_FORMAT);
d_width_variance=0;
if(d_show_tenths) {
if(d_show_hours) {
setDisplayFormat(RD_TWENTYFOUR_HOUR_TENTHS_FORMAT);
d_width_variance=0;
}
else {
setDisplayFormat(RD_OFFSET_TENTHS_FORMAT);
d_width_variance=0;
}
}
else {
setDisplayFormat(RD_OFFSET_FORMAT);
d_width_variance=0;
if(d_show_hours) {
setDisplayFormat(RD_TWENTYFOUR_HOUR_FORMAT);
d_width_variance=0;
}
else {
setDisplayFormat(RD_OFFSET_FORMAT);
d_width_variance=0;
}
}
}
}
else {
if(d_mode==RDTimeEdit::LengthMode) {
if(d_show_tenths) {
if(d_show_hours) {
setDisplayFormat(RD_TWENTYFOUR_HOUR_TENTHS_FORMAT);
d_width_variance=0;
}
else {
setDisplayFormat(RD_OFFSET_TENTHS_FORMAT);
d_width_variance=0;
}
setDisplayFormat(RD_OFFSET_TENTHS_FORMAT);
d_width_variance=0;
}
else {
if(d_show_hours) {
setDisplayFormat(RD_TWENTYFOUR_HOUR_FORMAT);
d_width_variance=0;
}
else {
setDisplayFormat(RD_OFFSET_FORMAT);
d_width_variance=0;
}
setDisplayFormat(RD_OFFSET_FORMAT);
d_width_variance=0;
}
}
}