From 22a2fd2f9c81e239869b3db76045b0612d952846 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Wed, 11 Aug 2021 11:14:06 -0400 Subject: [PATCH] 2021-08-11 Fred Gleason * Removed the 'SYSTEM.TIME_FORMAT' field from the database. * Added a 'SYSTEM.SHOW_TWELVE_HOUR_TIME' field to the database. * Incremented the database version 352. * Added 'RDSystem::showTwelveHourTime()' and 'RDSystem::setShowTwelveHourTime()' methods. * Refactored 'RDTimeEdit' to support 12 hour time format. Signed-off-by: Fred Gleason --- ChangeLog | 7 + docs/tables/system.txt | 2 +- lib/dbversion.h | 2 +- lib/rd.h | 13 +- lib/rdcoreapplication.cpp | 31 +- lib/rdcoreapplication.h | 4 +- lib/rdlogeventdialog.cpp | 7 +- lib/rdlogmodel.cpp | 6 +- lib/rdsystem.cpp | 10 +- lib/rdsystem.h | 4 +- lib/rdtimeedit.cpp | 580 ++++++++------------------------ lib/rdtimeedit.h | 62 +--- rdadmin/edit_system.cpp | 23 +- rdadmin/edit_system.h | 2 +- rdadmin/test_datetimes.cpp | 13 +- rdadmin/test_datetimes.h | 2 +- rdairplay/edit_event.cpp | 27 +- rdairplay/edit_event.h | 1 + rdairplay/hourselector.cpp | 12 +- rdairplay/loglinebox.cpp | 4 +- rdlibrary/edit_cart.cpp | 4 +- rdlibrary/record_cut.h | 19 +- rdlogedit/edit_event.cpp | 7 +- rdlogmanager/edit_eventline.cpp | 9 +- utils/rddbmgr/revertschema.cpp | 14 + utils/rddbmgr/schemamap.cpp | 2 +- utils/rddbmgr/updateschema.cpp | 13 + 27 files changed, 301 insertions(+), 579 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9a3e6e06..7da93500 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22193,3 +22193,10 @@ 2021-08-08 Fred Gleason * Fixed a bug in rdservice(8) that could cause a segfault when restarting dropboxes. +2021-08-11 Fred Gleason + * Removed the 'SYSTEM.TIME_FORMAT' field from the database. + * Added a 'SYSTEM.SHOW_TWELVE_HOUR_TIME' field to the database. + * Incremented the database version 352. + * Added 'RDSystem::showTwelveHourTime()' and + 'RDSystem::setShowTwelveHourTime()' methods. + * Refactored 'RDTimeEdit' to support 12 hour time format. diff --git a/docs/tables/system.txt b/docs/tables/system.txt index faa2889e..7e682971 100644 --- a/docs/tables/system.txt +++ b/docs/tables/system.txt @@ -17,4 +17,4 @@ RSS_PROCESSOR_STATION varchar(64) ORIGIN_EMAIL_ADDRESS varchar(64) LONG_DATE_FORMAT varchar(32) Default 'dddd, MMMM d yyyy' SHORT_DATE_FORMAT varchar(32) Default 'MM/dd/yyyy' -TIME_FORMAT varchar(32) Default 'hh:mm:ss' +SHOW_TWELVE_HOUR_TIME enum('N','Y') Default 'N' diff --git a/lib/dbversion.h b/lib/dbversion.h index fa421e82..7ab768e1 100644 --- a/lib/dbversion.h +++ b/lib/dbversion.h @@ -24,7 +24,7 @@ /* * Current Database Version */ -#define RD_VERSION_DATABASE 351 +#define RD_VERSION_DATABASE 352 #endif // DBVERSION_H diff --git a/lib/rd.h b/lib/rd.h index eb2fdc44..1ee5ab2d 100644 --- a/lib/rd.h +++ b/lib/rd.h @@ -650,11 +650,20 @@ #define RD_LISTWIDGET_ITEM_WIDTH_PADDING 20 /* - * Default Date/Time Formats + * Date/Time Formats */ #define RD_DEFAULT_LONG_DATE_FORMAT "dddd, MMMM d yyyy" #define RD_DEFAULT_SHORT_DATE_FORMAT "MM/dd/yy" -#define RD_DEFAULT_TIME_FORMAT "hh:mm:ss" + +#define RD_TWENTYFOUR_HOUR_FORMAT "hh:mm:ss" +#define RD_TWENTYFOUR_HOUR_TENTHS_FORMAT "hh:mm:ss.z" + +#define RD_TWELVE_HOUR_FORMAT "h:mm:ss AP" +#define RD_TWELVE_HOUR_TENTHS_FORMAT "h:mm:ss.z AP" + +#define RD_OFFSET_FORMAT "mm:ss" +#define RD_OFFSET_TENTHS_FORMAT "mm:ss.z" + #endif // RD_H diff --git a/lib/rdcoreapplication.cpp b/lib/rdcoreapplication.cpp index eee8794e..0cac9904 100644 --- a/lib/rdcoreapplication.cpp +++ b/lib/rdcoreapplication.cpp @@ -72,7 +72,7 @@ RDCoreApplication::RDCoreApplication(const QString &module_name, app_user=NULL; app_long_date_format=RD_DEFAULT_LONG_DATE_FORMAT; app_short_date_format=RD_DEFAULT_SHORT_DATE_FORMAT; - app_time_format=RD_DEFAULT_TIME_FORMAT; + app_show_twelve_hour_time=false; atexit(__RDCoreApplication_ExitCallback); } @@ -223,15 +223,15 @@ bool RDCoreApplication::open(QString *err_msg,RDCoreApplication::ErrorType *err_ // Get Date/Time Formats // sql=QString("select ")+ - "`LONG_DATE_FORMAT`,"+ // 00 - "`SHORT_DATE_FORMAT`,"+ // 01 - "`TIME_FORMAT` "+ // 02 + "`LONG_DATE_FORMAT`,"+ // 00 + "`SHORT_DATE_FORMAT`,"+ // 01 + "`SHOW_TWELVE_HOUR_TIME` "+ // 02 "from `SYSTEM`"; q=new RDSqlQuery(sql); if(q->first()) { app_long_date_format=q->value(0).toString().trimmed(); app_short_date_format=q->value(1).toString().trimmed(); - app_time_format=q->value(2).toString().trimmed(); + app_show_twelve_hour_time=q->value(2).toString()=="Y"; } else { syslog(LOG_WARNING,"unable to load date/time formats"); @@ -324,9 +324,9 @@ RDUser *RDCoreApplication::user() } -bool RDCoreApplication::timeFormatIs24Hour() const +bool RDCoreApplication::showTwelveHourTime() const { - return !app_time_format.toLower().contains("ap"); + return app_show_twelve_hour_time; } @@ -344,7 +344,11 @@ QString RDCoreApplication::shortDateString(const QDate &date) const QString RDCoreApplication::timeString(const QTime &time) const { - return time.toString(app_time_format); + if(app_show_twelve_hour_time) { + // return time.toString("h:mm:ss ap"); + return time.toString(RD_TWELVE_HOUR_FORMAT); + } + return time.toString(RD_TWENTYFOUR_HOUR_FORMAT); } @@ -352,16 +356,11 @@ QString RDCoreApplication::tenthsTimeString(const QTime &time) const { QString ret; - if(app_time_format.right(2).toLower()=="ap") { - ret=time.toString(app_time_format); - QString suffix=ret.right(2); - ret=ret.left(ret.length()-2).trimmed(); - ret+= - QString().sprintf(".%d %s",time.msec()/100,suffix.toUtf8().constData()); + if(app_show_twelve_hour_time) { + ret=time.toString(RD_TWELVE_HOUR_TENTHS_FORMAT); } else { - ret=time.toString(app_time_format+".zzz"); - ret=ret.left(ret.length()-2); + ret=time.toString(RD_TWENTYFOUR_HOUR_TENTHS_FORMAT); } return ret; diff --git a/lib/rdcoreapplication.h b/lib/rdcoreapplication.h index 9f62978b..e1117481 100644 --- a/lib/rdcoreapplication.h +++ b/lib/rdcoreapplication.h @@ -70,7 +70,7 @@ class RDCoreApplication : public QObject RDStation *station(); RDSystem *system(); RDUser *user(); - bool timeFormatIs24Hour() const; + bool showTwelveHourTime() const; QString longDateString(const QDate &date) const; QString shortDateString(const QDate &date) const; QString timeString(const QTime &time) const; @@ -111,7 +111,7 @@ class RDCoreApplication : public QObject QString app_usage; QString app_long_date_format; QString app_short_date_format; - QString app_time_format; + bool app_show_twelve_hour_time; }; #endif // RDCOREAPPLICATION_H diff --git a/lib/rdlogeventdialog.cpp b/lib/rdlogeventdialog.cpp index c88e8302..e3abcfff 100644 --- a/lib/rdlogeventdialog.cpp +++ b/lib/rdlogeventdialog.cpp @@ -2,7 +2,7 @@ // // Base class for rdlogedit(1) event editor dialogs // -// (C) Copyright 2002-2020 Fred Gleason +// (C) Copyright 2002-2021 Fred Gleason // // 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 @@ -44,9 +44,8 @@ RDLogEventDialog::RDLogEventDialog(RDLogLine *line,QWidget *parent) // Start Time // edit_time_edit=new RDTimeEdit(this); - edit_time_edit->setDisplay(RDTimeEdit::Hours|RDTimeEdit::Minutes| - RDTimeEdit::Seconds|RDTimeEdit::Tenths); - connect(edit_time_edit,SIGNAL(valueChanged(const QTime &)), + edit_time_edit->setShowTenths(true); + connect(edit_time_edit,SIGNAL(timeChanged(const QTime &)), this,SLOT(timeChangedData(const QTime &))); // diff --git a/lib/rdlogmodel.cpp b/lib/rdlogmodel.cpp index 39da73e1..da07beeb 100644 --- a/lib/rdlogmodel.cpp +++ b/lib/rdlogmodel.cpp @@ -103,11 +103,11 @@ void RDLogModel::setFont(const QFont &font) // // Calculate Minimum Column Widths // - if(rda->timeFormatIs24Hour()) { - d_size_hints[0]=QSize(40+d_bold_fms->width("T00:00:00"),0); + if(rda->showTwelveHourTime()) { + d_size_hints[0]=QSize(40+d_bold_fms->width("T00:00:00.0 AM"),0); } else { - d_size_hints[0]=QSize(40+d_bold_fms->width("T00:00:00 AM"),0); + d_size_hints[0]=QSize(40+d_bold_fms->width("T00:00:00.0"),0); } width=d_bold_fms->width(tr("PLAY")); if(d_bold_fms->width(tr("SEGUE"))>width) { diff --git a/lib/rdsystem.cpp b/lib/rdsystem.cpp index 5b663e5b..b7c7cbcb 100644 --- a/lib/rdsystem.cpp +++ b/lib/rdsystem.cpp @@ -229,15 +229,15 @@ void RDSystem::setShortDateFormat(const QString &str) } -QString RDSystem::timeFormat() const +bool RDSystem::showTwelveHourTime() const { - return GetValue("TIME_FORMAT").toString(); + return RDBool(GetValue("SHOW_TWELVE_HOUR_TIME").toString()); } -void RDSystem::setTimeFormat(const QString &str) +void RDSystem::setShowTwelveHourTime(bool state) const { - SetRow("TIME_FORMAT",str); + SetRow("SHOW_TWELVE_HOUR_TIME",RDYesNo(state)); } @@ -252,7 +252,7 @@ QString RDSystem::xml() const xml+=RDXmlField("tempCartGroup",tempCartGroup()); xml+=RDXmlField("longDateFormat",longDateFormat()); xml+=RDXmlField("shortDateFormat",shortDateFormat()); - xml+=RDXmlField("timeFormat",timeFormat()); + xml+=RDXmlField("showTwelveHourTime",showTwelveHourTime()); xml+="\n"; return xml; diff --git a/lib/rdsystem.h b/lib/rdsystem.h index ee245aa6..90125299 100644 --- a/lib/rdsystem.h +++ b/lib/rdsystem.h @@ -52,8 +52,8 @@ class RDSystem void setLongDateFormat(const QString &str); QString shortDateFormat() const; void setShortDateFormat(const QString &str); - QString timeFormat() const; - void setTimeFormat(const QString &str); + bool showTwelveHourTime() const; + void setShowTwelveHourTime(bool state) const; QString xml() const; private: diff --git a/lib/rdtimeedit.cpp b/lib/rdtimeedit.cpp index 256a7a7b..ff6cad09 100644 --- a/lib/rdtimeedit.cpp +++ b/lib/rdtimeedit.cpp @@ -18,486 +18,188 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // +#include +#include + +#include "rdapplication.h" #include "rdtimeedit.h" RDTimeEdit::RDTimeEdit(QWidget *parent) - : QFrame(parent) + : QTimeEdit(parent) { - edit_display=0; - edit_section=0; - edit_read_only=false; - edit_digit=0; - GetSizeHint(); - setFrameStyle(QFrame::StyledPanel|QFrame::Sunken); - setLineWidth(1); - setMidLineWidth(3); - setFocusPolicy(Qt::StrongFocus); - QPalette p=palette(); - p.setColor(QPalette::Active,QPalette::Background, - p.color(QPalette::Active,QPalette::Base)); - setPalette(p); - edit_labels[0]=new QLabel("00",this); - edit_labels[0]->setAlignment(Qt::AlignCenter); - edit_labels[0]->setAutoFillBackground(true); - edit_labels[1]=new QLabel("00",this); - edit_labels[1]->setAlignment(Qt::AlignCenter); - edit_labels[1]->setAutoFillBackground(true); - edit_labels[2]=new QLabel("00",this); - edit_labels[2]->setAlignment(Qt::AlignCenter); - edit_labels[2]->setAutoFillBackground(true); - edit_labels[3]=new QLabel("0",this); - edit_labels[3]->setAlignment(Qt::AlignCenter); - edit_labels[3]->setAutoFillBackground(true); - edit_sep_labels[0]=new QLabel(":",this); - edit_sep_labels[0]->setAlignment(Qt::AlignCenter); - edit_sep_labels[1]=new QLabel(":",this); - edit_sep_labels[1]->setAlignment(Qt::AlignCenter); - edit_sep_labels[2]=new QLabel(".",this); - edit_sep_labels[2]->setAlignment(Qt::AlignCenter); - edit_up_button=new RDTransportButton(RDTransportButton::Up,this); - edit_up_button->setFocusPolicy(Qt::NoFocus); - connect(edit_up_button,SIGNAL(clicked()),this,SLOT(upClickedData())); - edit_down_button=new RDTransportButton(RDTransportButton::Down,this); - edit_down_button->setFocusPolicy(Qt::NoFocus); - connect(edit_down_button,SIGNAL(clicked()),this,SLOT(downClickedData())); - setDisplay(RDTimeEdit::Hours|RDTimeEdit::Minutes|RDTimeEdit::Seconds); + d_show_hours=true; + d_show_tenths=false; + d_current_step_size=1; + d_step_enabled=StepDownEnabled|StepUpEnabled; + + SetFormat(); } -RDTimeEdit::~RDTimeEdit() +bool RDTimeEdit::showHours() const { - for(unsigned i=0;i<4;i++) { - delete edit_labels[i]; + return d_show_hours; +} + + +void RDTimeEdit::setShowHours(bool state) +{ + if(d_show_hours!=state) { + d_show_hours=state; + SetFormat(); } - for(unsigned i=0;i<3;i++) { - delete edit_sep_labels[i]; +} + + +bool RDTimeEdit::showTenths() const +{ + return d_show_tenths; +} + + +void RDTimeEdit::setShowTenths(bool state) +{ + if(state!=d_show_tenths) { + d_show_tenths=state; + SetFormat(); } - delete edit_up_button; - delete edit_down_button; } -QSize RDTimeEdit::sizeHint() const +QValidator::State RDTimeEdit::validate(QString &input,int &pos) const { - return QSize(edit_widths[0]+edit_widths[1]+edit_widths[2]+ - edit_sep_widths[0]+edit_sep_widths[1], - edit_height); + QValidator::State ret=QTimeEdit::validate(input,pos); + + if((!d_show_tenths)||(ret==QValidator::Invalid)) { + return ret; + } + if(ret==QValidator::Acceptable) { + if(input.length()!=displayFormat().length()) { + return QValidator::Intermediate; + } + } + return ret; } -QSizePolicy RDTimeEdit::sizePolicy() const +void RDTimeEdit::stepBy(int steps) { - return QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); -} + int step_size=1; + int tenths=-1; + int tenths_lo_limit=0; + int tenths_hi_limit=9; + bool ok=false; - -QTime RDTimeEdit::time() const -{ - return QTime(edit_labels[0]->text().toInt(), - edit_labels[1]->text().toInt(), - edit_labels[2]->text().toInt(), - 100*edit_labels[3]->text().toInt()); -} - - -bool RDTimeEdit::isReadOnly() const -{ - return edit_read_only; -} - - -void RDTimeEdit::setFont(const QFont &f) -{ - QFrame::setFont(f); - GetSizeHint(); -} - - -uint RDTimeEdit::display() const -{ - return edit_display; -} - - -void RDTimeEdit::setDisplay(uint disp) -{ - edit_section=-1; - for(unsigned i=0;i<4;i++) { - if((disp&(1<hide(); + if(d_show_tenths) { + if(displayFormat()==RD_TWENTYFOUR_HOUR_TENTHS_FORMAT) { + if(lineEdit()->cursorPosition()>8) { + tenths=lineEdit()->text().mid(9,1).toInt(&ok); + if(!ok) { + return; + } + step_size=100; + } + } + if(displayFormat()==RD_TWELVE_HOUR_TENTHS_FORMAT) { + int offset=7; + if(lineEdit()->text().mid(2,1)==":") { + offset=8; + } + if((lineEdit()->cursorPosition()>offset)&& + (lineEdit()->cursorPosition()<=(offset+2))) { + tenths=lineEdit()->text().mid(offset+1,1).toInt(&ok); + if(!ok) { + return; + } + step_size=100; + } + } + if(displayFormat()==RD_OFFSET_TENTHS_FORMAT) { + if(lineEdit()->cursorPosition()>5) { + tenths=lineEdit()->text().mid(6,1).toInt(&ok); + if(!ok) { + return; + } + step_size=100; + } + } + if(steps>0) { + if(tenths>=9) { + return; + } + QTimeEdit::stepBy(step_size); + tenths_lo_limit=-1; + tenths_hi_limit=8; + } + if(steps<0) { + QTimeEdit::stepBy(-step_size); + tenths_lo_limit=1; + tenths_hi_limit=10; + } + if(tenths<0) { + d_step_enabled=QTimeEdit::stepEnabled(); } else { - edit_labels[i]->show(); - if(edit_section<0) { - edit_section=i; + d_step_enabled=0; + if(tenths>tenths_lo_limit) { + d_step_enabled=d_step_enabled|StepDownEnabled; + } + if(tenthshide(); - } - else { - edit_sep_labels[i-1]->show(); - } - } - edit_display=disp; - GetSizeHint(); - setGeometry(geometry()); -} - - -void RDTimeEdit::setGeometry(int x,int y,int w,int h) -{ - QFrame::setGeometry(x,y,w,h); - QFontMetrics fm(font()); - int fy=h-fm.height(); - int fx=contentsRect().x()+fy; - - edit_labels[0]->setGeometry(fx,fy,edit_widths[0],edit_height); - edit_section_x[0]=fx+edit_widths[0]+edit_sep_widths[0]/2; - edit_sep_labels[0]-> - setGeometry(fx+edit_widths[0],fy,edit_sep_widths[0],edit_height); - edit_labels[1]-> - setGeometry(fx+edit_widths[0]+edit_sep_widths[0],fy,edit_widths[1], - edit_height); - edit_section_x[1]= - fx+edit_widths[0]+edit_sep_widths[0]+edit_widths[1]+edit_sep_widths[0]/2; - edit_sep_labels[1]-> - setGeometry(fx+edit_widths[0]+edit_sep_widths[0]+edit_widths[1],fy, - edit_sep_widths[1],edit_height); - edit_labels[2]-> - setGeometry(fx+edit_widths[0]+edit_widths[1]+ - edit_sep_widths[0]+edit_sep_widths[1],fy, - edit_widths[2],edit_height); - - edit_section_x[2]= - fx+edit_widths[0]+edit_sep_widths[0]+edit_sep_widths[1]+ - edit_widths[1]+edit_widths[2]+edit_sep_widths[2]/2; - edit_sep_labels[2]-> - setGeometry(fx+edit_widths[0]+edit_sep_widths[0]+edit_sep_widths[1]+edit_widths[1]+ - edit_widths[2],fy,edit_sep_widths[2],edit_height); - edit_labels[3]-> - setGeometry(fx+edit_widths[0]+edit_widths[1]+ - edit_sep_widths[0]+edit_sep_widths[1]+ - edit_widths[2]+edit_sep_widths[2],fy, - edit_widths[3],edit_height); - int button_x=fx+edit_widths[0]+edit_widths[1]+edit_widths[2]+ - edit_sep_widths[0]+edit_sep_widths[1]+edit_widths[3]+edit_sep_widths[2]+fy; - edit_up_button->setGeometry(button_x,0,w-button_x,h/2); - edit_down_button->setGeometry(button_x,h/2,w-button_x,h/2); -} - - -void RDTimeEdit::setTime(const QTime &time) -{ - edit_labels[0]->setText(time.toString("hh")); - edit_labels[1]->setText(time.toString("mm")); - edit_labels[2]->setText(time.toString("ss")); - edit_labels[3]->setText(QString().sprintf("%d",time.msec()/100)); -} - - -void RDTimeEdit::setReadOnly(bool state) -{ - if(state) { - setFocusPolicy(Qt::NoFocus); - } else { - setFocusPolicy(Qt::StrongFocus); - } - edit_read_only=state; -} - - -void RDTimeEdit::setFocus() -{ - QPalette p=palette(); - for(int i=0;i<4;i++) { - edit_labels[i]->setPalette(p); - } - p.setColor(QPalette::Active,QPalette::Background, - p.color(QPalette::Active,QPalette::Highlight)); - p.setColor(QPalette::Active,QPalette::Foreground, - p.color(QPalette::Active,QPalette::HighlightedText)); - edit_labels[edit_section]->setPalette(p); - QFrame::setFocus(); -} - - -void RDTimeEdit::setGeometry(const QRect &r) -{ - setGeometry(r.x(),r.y(),r.width(),r.height()); -} - - -void RDTimeEdit::upClickedData() -{ - int value; - - if(edit_read_only) { - return; - } - setFocus(); - switch(edit_section) { - case 0: - if((value=edit_labels[edit_section]->text().toInt())<23) { - value++; - } - else { - value=0; - } - edit_labels[edit_section]->setText(QString().sprintf("%02d",value)); - emit valueChanged(time()); - break; - - case 1: - case 2: - if((value=edit_labels[edit_section]->text().toInt())<59) { - value++; - } - else { - value=0; - } - edit_labels[edit_section]->setText(QString().sprintf("%02d",value)); - emit valueChanged(time()); - break; - - case 3: - if((value=edit_labels[edit_section]->text().toInt())<9) { - value++; - } - else { - value=0; - } - edit_labels[edit_section]->setText(QString().sprintf("%d",value)); - emit valueChanged(time()); - break; + QTimeEdit::stepBy(steps); } } -void RDTimeEdit::downClickedData() +QAbstractSpinBox::StepEnabled RDTimeEdit::stepEnabled() const { - int value; - - if(edit_read_only) { - return; - } - setFocus(); - switch(edit_section) { - case 0: - if((value=edit_labels[edit_section]->text().toInt())>0) { - value--; - } - else { - value=23; - } - edit_labels[edit_section]->setText(QString().sprintf("%02d",value)); - emit valueChanged(time()); - break; - - case 1: - case 2: - if((value=edit_labels[edit_section]->text().toInt())>0) { - value--; - } - else { - value=59; - } - edit_labels[edit_section]->setText(QString().sprintf("%02d",value)); - emit valueChanged(time()); - break; - - case 3: - if((value=edit_labels[edit_section]->text().toInt())>0) { - value--; - } - else { - value=9; - } - edit_labels[edit_section]->setText(QString().sprintf("%d",value)); - emit valueChanged(time()); - break; + if(d_show_tenths) { + return d_step_enabled; } + return QTimeEdit::stepEnabled(); } -void RDTimeEdit::mousePressEvent(QMouseEvent *e) +void RDTimeEdit::SetFormat() { - int section=0; - - if(edit_read_only) { - return; - } - if(e->x()x()x()system()->showTwelveHourTime()) { + if(d_show_tenths) { + if(d_show_hours) { + setDisplayFormat(RD_TWELVE_HOUR_TENTHS_FORMAT); } else { - section=3; + setDisplayFormat(RD_OFFSET_TENTHS_FORMAT); } } - } - if(edit_section!=section) { - edit_section=section; - edit_digit=0; - } - setFocus(); -} - - -void RDTimeEdit::wheelEvent(QWheelEvent *e) -{ - if(e->delta()>=0) { - upClickedData(); - } - else { - downClickedData(); - } - e->accept(); -} - - -void RDTimeEdit::keyPressEvent(QKeyEvent *e) -{ - if(edit_read_only) { - e->ignore(); - return; - } - switch(e->key()) { - case Qt::Key_0: - case Qt::Key_1: - case Qt::Key_2: - case Qt::Key_3: - case Qt::Key_4: - case Qt::Key_5: - case Qt::Key_6: - case Qt::Key_7: - case Qt::Key_8: - case Qt::Key_9: - ProcessNumericKey(e->text().left(1).toInt()); - e->accept(); - break; - - case Qt::Key_Left: - if((edit_section>0)&&(((1<<(edit_section-1))&edit_display)!=0)) { - edit_section--; - edit_digit=0; - setFocus(); - } - e->accept(); - break; - - case Qt::Key_Right: - if(((1<<(edit_section+1))&edit_display)!=0) { - edit_section++; - edit_digit=0; - setFocus(); - } - e->accept(); - break; - - case Qt::Key_Up: - upClickedData(); - break; - - case Qt::Key_Down: - downClickedData(); - break; - - default: - e->ignore(); - break; - } -} - - -void RDTimeEdit::focusInEvent(QFocusEvent *e) -{ - QFrame::focusInEvent(e); -} - - -void RDTimeEdit::focusOutEvent(QFocusEvent *e) -{ - QFrame::focusOutEvent(e); - QPalette p=palette(); - for(int i=0;i<4;i++) { - edit_labels[i]->setPalette(p); - } - QFrame::focusOutEvent(e); -} - - -void RDTimeEdit::GetSizeHint() -{ - QFontMetrics fm(font()); - if((edit_display&RDTimeEdit::Hours)==0) { - edit_widths[0]=0; - edit_sep_widths[0]=0; - } - else { - edit_widths[0]=fm.width("00"); - edit_sep_widths[0]=fm.width(":"); - } - if((edit_display&RDTimeEdit::Minutes)==0) { - edit_widths[1]=0; - edit_sep_widths[1]=0; - } - else { - edit_widths[1]=fm.width("00"); - edit_sep_widths[1]=fm.width(":"); - } - if((edit_display&RDTimeEdit::Seconds)==0) { - edit_widths[2]=0; - edit_sep_widths[2]=0; - } - else { - edit_widths[2]=fm.width("00"); - edit_sep_widths[2]=fm.width("."); - } - if((edit_display&RDTimeEdit::Tenths)==0) { - edit_widths[3]=0; - } - else { - edit_widths[3]=fm.width("0"); - } - edit_height=fm.ascent(); -} - - -void RDTimeEdit::ProcessNumericKey(int num) -{ - int ten; - - switch(edit_section) { - case 0: - case 1: - case 2: - if(edit_digit==0) { - edit_labels[edit_section]->setText(QString().sprintf("0%d",num)); - edit_digit=1; - } else { - ten=edit_labels[edit_section]->text().toInt(); - if(ten>5) { - ten=0; + if(d_show_hours) { + setDisplayFormat(RD_TWELVE_HOUR_FORMAT); + } + else { + setDisplayFormat(RD_OFFSET_FORMAT); + } + } + } + else { + if(d_show_tenths) { + if(d_show_hours) { + setDisplayFormat(RD_TWENTYFOUR_HOUR_TENTHS_FORMAT); + } + else { + setDisplayFormat(RD_OFFSET_TENTHS_FORMAT); + } + } + else { + if(d_show_hours) { + setDisplayFormat(RD_TWENTYFOUR_HOUR_FORMAT); + } + else { + setDisplayFormat(RD_OFFSET_FORMAT); } - edit_labels[edit_section]->setText(QString().sprintf("%d%d",ten,num)); } - break; - - case 3: - edit_labels[3]->setText(QString().sprintf("%d",num)); - break; } - emit valueChanged(time()); } diff --git a/lib/rdtimeedit.h b/lib/rdtimeedit.h index 65257c43..28e34150 100644 --- a/lib/rdtimeedit.h +++ b/lib/rdtimeedit.h @@ -21,62 +21,30 @@ #ifndef RDTIMEEDIT_H #define RDTIMEEDIT_H -#include -#include +#include +#include -#include - -class RDTimeEdit : public QFrame +class RDTimeEdit : public QTimeEdit { Q_OBJECT public: - enum Display {Hours=0x01,Minutes=0x02,Seconds=0x04,Tenths=0x08}; RDTimeEdit(QWidget *parent=0); - ~RDTimeEdit(); - QSize sizeHint() const; - QSizePolicy sizePolicy() const; - QTime time() const; - bool isReadOnly() const; - void setFont(const QFont &f); - uint display() const; - void setDisplay(uint disp); - - public slots: - void setTime(const QTime &time); - void setReadOnly(bool state); - void setFocus(); - void setGeometry(int x,int y,int w,int h); - void setGeometry(const QRect &r); - - signals: - void valueChanged(const QTime &time); - - private slots: - void upClickedData(); - void downClickedData(); + bool showHours() const; + void setShowHours(bool state); + bool showTenths() const; + void setShowTenths(bool state); protected: - void mousePressEvent(QMouseEvent *e); - void wheelEvent(QWheelEvent *e); - void keyPressEvent(QKeyEvent *e); - void focusInEvent(QFocusEvent *e); - void focusOutEvent(QFocusEvent *e); + QValidator::State validate(QString &input,int &pos) const; + void stepBy(int steps); + QAbstractSpinBox::StepEnabled stepEnabled() const; private: - void GetSizeHint(); - void ProcessNumericKey(int num); - QLabel *edit_labels[4]; - QLabel *edit_sep_labels[3]; - RDTransportButton *edit_up_button; - RDTransportButton *edit_down_button; - int edit_widths[4]; - int edit_section_x[3]; - int edit_sep_widths[3]; - int edit_height; - int edit_section; - int edit_digit; - uint edit_display; - bool edit_read_only; + void SetFormat(); + bool d_show_hours; + bool d_show_tenths; + int d_current_step_size; + QAbstractSpinBox::StepEnabled d_step_enabled; }; diff --git a/rdadmin/edit_system.cpp b/rdadmin/edit_system.cpp index 06e19d89..aab24986 100644 --- a/rdadmin/edit_system.cpp +++ b/rdadmin/edit_system.cpp @@ -214,9 +214,10 @@ EditSystem::EditSystem(QWidget *parent) new QLabel(tr("Time Format")+":",edit_datetime_group); edit_time_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); edit_time_label->setFont(labelFont()); - edit_time_edit=new QLineEdit(edit_datetime_group); - edit_time_edit->setFont(defaultFont()); - edit_time_edit->setMaxLength(32); + edit_time_box=new QComboBox(edit_datetime_group); + edit_time_box->setFont(defaultFont()); + edit_time_box->insertItem(0,tr("Twenty Four Hour")); + edit_time_box->insertItem(1,tr("Twelve Hour")); edit_datetime_test_button=new QPushButton(tr("Test"),edit_datetime_group); connect(edit_datetime_test_button,SIGNAL(clicked()), @@ -266,7 +267,12 @@ EditSystem::EditSystem(QWidget *parent) edit_show_user_list_box->setChecked(edit_system->showUserList()); edit_long_date_edit->setText(edit_system->longDateFormat()); edit_short_date_edit->setText(edit_system->shortDateFormat()); - edit_time_edit->setText(edit_system->timeFormat()); + if(edit_system->showTwelveHourTime()) { + edit_time_box->setCurrentIndex(1); + } + else { + edit_time_box->setCurrentIndex(0); + } QString station=edit_system->rssProcessorStation(); for(int i=0;icount();i++) { @@ -381,7 +387,7 @@ void EditSystem::datetimeTestData() { edit_test_datetimes_dialog->exec(edit_long_date_edit->text(), edit_short_date_edit->text(), - edit_time_edit->text()); + edit_time_box->currentIndex()); } @@ -396,7 +402,7 @@ void EditSystem::datetimeDefaultsData() } edit_long_date_edit->setText(RD_DEFAULT_LONG_DATE_FORMAT); edit_short_date_edit->setText(RD_DEFAULT_SHORT_DATE_FORMAT); - edit_time_edit->setText(RD_DEFAULT_TIME_FORMAT); + edit_time_box->setCurrentIndex(0); } @@ -405,7 +411,6 @@ void EditSystem::okData() QString sql; RDSqlQuery *q; RDSqlQuery *q1; - // std::map dups; QMultiMap dups; if(edit_duplicate_carts_box->isChecked()!= @@ -513,7 +518,7 @@ void EditSystem::okData() } edit_system->setLongDateFormat(edit_long_date_edit->text()); edit_system->setShortDateFormat(edit_short_date_edit->text()); - edit_system->setTimeFormat(edit_time_edit->text()); + edit_system->setShowTwelveHourTime(edit_time_box->currentIndex()); done(true); } @@ -587,7 +592,7 @@ void EditSystem::resizeEvent(QResizeEvent *e) edit_short_date_label->setGeometry(110,49,120,20); edit_short_date_edit->setGeometry(235,49,edit_datetime_group->width()-240,20); edit_time_label->setGeometry(110,71,120,20); - edit_time_edit->setGeometry(235,71,edit_datetime_group->width()-240,20); + edit_time_box->setGeometry(235,71,edit_time_box->sizeHint().width(),20); edit_duplicate_hidden_label->setGeometry(15,329,size().width()-30,50); edit_duplicate_view->setGeometry(10,377,size().width()-20,215); diff --git a/rdadmin/edit_system.h b/rdadmin/edit_system.h index e893db7a..343cb9e8 100644 --- a/rdadmin/edit_system.h +++ b/rdadmin/edit_system.h @@ -104,7 +104,7 @@ class EditSystem : public RDDialog QLabel *edit_short_date_label; QLineEdit *edit_short_date_edit; QLabel *edit_time_label; - QLineEdit *edit_time_edit; + QComboBox *edit_time_box; QPushButton *edit_datetime_test_button; QPushButton *edit_datetime_defaults_button; TestDatetimes *edit_test_datetimes_dialog; diff --git a/rdadmin/test_datetimes.cpp b/rdadmin/test_datetimes.cpp index a09633da..c83df511 100644 --- a/rdadmin/test_datetimes.cpp +++ b/rdadmin/test_datetimes.cpp @@ -61,13 +61,18 @@ QSize TestDatetimes::sizeHint() const } -int TestDatetimes::exec(const QString &long_date_fmt,\ - const QString &short_date_fmt, - const QString &time_fmt) +int TestDatetimes::exec(const QString &long_date_fmt, + const QString &short_date_fmt, + bool use12hour) { d_long_date_label->setText(d_sample_datetime.toString(long_date_fmt)); d_short_date_label->setText(d_sample_datetime.toString(short_date_fmt)); - d_time_label->setText(d_sample_datetime.toString(time_fmt)); + if(use12hour) { + d_time_label->setText(d_sample_datetime.toString("h:mm:ss ap")); + } + else { + d_time_label->setText(d_sample_datetime.toString("hh:mm:ss")); + } return QDialog::exec(); } diff --git a/rdadmin/test_datetimes.h b/rdadmin/test_datetimes.h index ad652eed..74963298 100644 --- a/rdadmin/test_datetimes.h +++ b/rdadmin/test_datetimes.h @@ -35,7 +35,7 @@ class TestDatetimes : public RDDialog public slots: int exec(const QString &long_date_fmt,const QString &short_date_fmt, - const QString &time_fmt); + bool use12hour); private slots: void closeData(); diff --git a/rdairplay/edit_event.cpp b/rdairplay/edit_event.cpp index 3f08f2a7..c644db9e 100644 --- a/rdairplay/edit_event.cpp +++ b/rdairplay/edit_event.cpp @@ -41,9 +41,8 @@ EditEvent::EditEvent(RDLogPlay *log,QWidget *parent) // Start Time // edit_time_edit=new RDTimeEdit(this); - edit_time_edit->setDisplay(RDTimeEdit::Hours|RDTimeEdit::Minutes| - RDTimeEdit::Seconds|RDTimeEdit::Tenths); - connect(edit_time_edit,SIGNAL(valueChanged(const QTime &)), + edit_time_edit->setShowTenths(true); + connect(edit_time_edit,SIGNAL(timeChanged(const QTime &)), this,SLOT(timeChangedData(const QTime &))); // @@ -66,9 +65,10 @@ EditEvent::EditEvent(RDLogPlay *log,QWidget *parent) radio_button=new QRadioButton(tr("Wait up to"),edit_grace_group); edit_grace_bgroup->addButton(radio_button,2); radio_button->setFont(subLabelFont()); - edit_grace_edit=new RDTimeEdit(this); - edit_grace_edit->setDisplay(RDTimeEdit::Minutes|RDTimeEdit::Seconds| - RDTimeEdit::Tenths); + edit_grace_edit=new RDTimeEdit(edit_grace_group); + edit_grace_edit->setFont(defaultFont()); + edit_grace_edit->setShowHours(false); + edit_grace_edit->setShowTenths(true); connect(edit_timetype_box,SIGNAL(toggled(bool)), this,SLOT(timeToggledData(bool))); @@ -146,7 +146,8 @@ EditEvent::~EditEvent() QSize EditEvent::sizeHint() const { - return QSize(625,edit_height); + // return QSize(625,edit_height); + return QSize(665,edit_height); } @@ -308,7 +309,7 @@ int EditEvent::exec(int line) // Fix the Window Size // setMinimumSize(sizeHint()); - setMaximumSize(sizeHint()); + // setMaximumSize(sizeHint()); resize(sizeHint()); @@ -447,13 +448,13 @@ void EditEvent::resizeEvent(QResizeEvent *e) { edit_timetype_box->setGeometry(10,22,15,15); edit_timetype_label->setGeometry(30,21,85,17); - edit_time_edit->setGeometry(85,19,85,20); - - edit_grace_group->setGeometry(175,11,435,50); + edit_time_edit->setGeometry(85,19,120,20); + edit_grace_group->setGeometry(215,11,435,50); + edit_width=edit_grace_group->x()+edit_grace_group->width()+400; edit_grace_bgroup->button(0)->setGeometry(10,21,145,20); edit_grace_bgroup->button(1)->setGeometry(155,21,105,20); edit_grace_bgroup->button(2)->setGeometry(265,21,95,20); - edit_grace_edit->setGeometry(538,31,65,20); + edit_grace_edit->setGeometry(345,21,75,20); edit_overlap_box->setGeometry(30,72,15,15); edit_overlap_label->setGeometry(50,68,400,26); @@ -463,7 +464,7 @@ void EditEvent::resizeEvent(QResizeEvent *e) edit_horizrule_label->setGeometry(0,122,size().width(),3); - edit_cue_edit->setGeometry(20,132,edit_cue_edit->sizeHint().width(), + edit_cue_edit->setGeometry(20+25,132,edit_cue_edit->sizeHint().width(), edit_cue_edit->sizeHint().height()); if(edit_using_cue) { edit_cart_notes_label-> diff --git a/rdairplay/edit_event.h b/rdairplay/edit_event.h index 64f34104..c26f0a7c 100644 --- a/rdairplay/edit_event.h +++ b/rdairplay/edit_event.h @@ -78,6 +78,7 @@ class EditEvent : public RDDialog QPushButton *edit_ok_button; QPushButton *edit_cancel_button; QLabel *edit_horizrule_label; + int edit_width; int edit_height; }; diff --git a/rdairplay/hourselector.cpp b/rdairplay/hourselector.cpp index b6782cf0..544c91b1 100644 --- a/rdairplay/hourselector.cpp +++ b/rdairplay/hourselector.cpp @@ -41,12 +41,7 @@ HourSelector::HourSelector(QWidget *parent) mapper->setMapping(hour_button[i],i); connect(hour_button[i],SIGNAL(clicked()),mapper,SLOT(map())); } - if(rda->timeFormatIs24Hour()) { - for(unsigned i=0;i<24;i++) { - hour_button[i]->setText(QString().sprintf("%02u",i)); - } - } - else { + if(rda->showTwelveHourTime()) { hour_button[0]->setText(tr("12a")); hour_button[1]->setText(tr("1a")); hour_button[2]->setText(tr("2a")); @@ -72,6 +67,11 @@ HourSelector::HourSelector(QWidget *parent) hour_button[22]->setText(tr("10p")); hour_button[23]->setText(tr("11p")); } + else { + for(unsigned i=0;i<24;i++) { + hour_button[i]->setText(QString().sprintf("%02u",i)); + } + } // // Update Timer diff --git a/rdairplay/loglinebox.cpp b/rdairplay/loglinebox.cpp index e4f9e369..2a3b5a3e 100644 --- a/rdairplay/loglinebox.cpp +++ b/rdairplay/loglinebox.cpp @@ -839,8 +839,8 @@ void LogLineBox::resizeEvent(QResizeEvent *e) line_icon_label->setGeometry(5,3,16,16); line_cart_label->setGeometry(23,3,48,16); line_cut_label->setGeometry(73,3,24,16); - line_group_label->setGeometry(100,3,90,16); - line_time_label->setGeometry(190,3,95,16); + line_group_label->setGeometry(97,3,90,16); + line_time_label->setGeometry(187,3,98,16); line_talktime_label->setGeometry(287,3,36,16); line_length_label->setGeometry(327,3,50,16); line_trans_label->setGeometry(379,3,48,16); diff --git a/rdlibrary/edit_cart.cpp b/rdlibrary/edit_cart.cpp index 4aeb958f..c8ec485b 100644 --- a/rdlibrary/edit_cart.cpp +++ b/rdlibrary/edit_cart.cpp @@ -182,9 +182,7 @@ EditCart::EditCart(const QList &cartnums,QString *path,bool new_cart, // rdcart_controls.forced_length_edit=new RDTimeEdit(this); rdcart_controls.forced_length_edit->setGeometry(530,36,85,21); - rdcart_controls.forced_length_edit-> - setDisplay(RDTimeEdit::Hours|RDTimeEdit::Minutes|RDTimeEdit::Seconds| - RDTimeEdit::Tenths); + rdcart_controls.forced_length_edit->setShowTenths(true); rdcart_forced_length_ledit=new QLineEdit(this); rdcart_forced_length_ledit->setGeometry(535,36,80,21); rdcart_forced_length_ledit->hide(); diff --git a/rdlibrary/record_cut.h b/rdlibrary/record_cut.h index a024b2a5..3c11e196 100644 --- a/rdlibrary/record_cut.h +++ b/rdlibrary/record_cut.h @@ -2,7 +2,7 @@ // // Record a Rivendell cut. // -// (C) Copyright 2002-2019 Fred Gleason +// (C) Copyright 2002-2021 Fred Gleason // // 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 @@ -23,18 +23,19 @@ #define RECORD_CUT_TIMER_INTERVAL 100 -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include +#include #include #include "globals.h" diff --git a/rdlogedit/edit_event.cpp b/rdlogedit/edit_event.cpp index 57ca3bc5..b807ba2a 100644 --- a/rdlogedit/edit_event.cpp +++ b/rdlogedit/edit_event.cpp @@ -2,7 +2,7 @@ // // Base class for rdlogedit(1) event editor dialogs // -// (C) Copyright 2002-2020 Fred Gleason +// (C) Copyright 2002-2021 Fred Gleason // // 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 @@ -45,9 +45,8 @@ EditEvent::EditEvent(RDLogLine *line,QWidget *parent) // Start Time // edit_time_edit=new RDTimeEdit(this); - edit_time_edit->setDisplay(RDTimeEdit::Hours|RDTimeEdit::Minutes| - RDTimeEdit::Seconds|RDTimeEdit::Tenths); - connect(edit_time_edit,SIGNAL(valueChanged(const QTime &)), + edit_time_edit->setShowTenths(true); + connect(edit_time_edit,SIGNAL(timeChanged(const QTime &)), this,SLOT(timeChangedData(const QTime &))); // diff --git a/rdlogmanager/edit_eventline.cpp b/rdlogmanager/edit_eventline.cpp index 79a9856f..5ffcc758 100644 --- a/rdlogmanager/edit_eventline.cpp +++ b/rdlogmanager/edit_eventline.cpp @@ -19,6 +19,7 @@ // #include +#include #include #include @@ -104,8 +105,8 @@ EditEventLine::EditEventLine(RDEventLine *eventline,RDClockModel *clock, // edit_starttime_edit=new RDTimeEdit(this); edit_starttime_edit->setGeometry(150,40,70,20); - edit_starttime_edit-> - setDisplay(RDTimeEdit::Minutes|RDTimeEdit::Seconds|RDTimeEdit::Tenths); + edit_starttime_edit->setShowHours(false); + edit_starttime_edit->setShowTenths(false); label=new QLabel(tr("Start Time:"),this); label->setGeometry(65,42,80,20); label->setFont(labelFont()); @@ -116,8 +117,8 @@ EditEventLine::EditEventLine(RDEventLine *eventline,RDClockModel *clock, // edit_endtime_edit=new RDTimeEdit(this); edit_endtime_edit->setGeometry(325,40,70,20); - edit_endtime_edit-> - setDisplay(RDTimeEdit::Minutes|RDTimeEdit::Seconds|RDTimeEdit::Tenths); + edit_endtime_edit->setShowHours(false); + edit_endtime_edit->setShowTenths(false); label=new QLabel(tr("End Time:"),this); label->setGeometry(250,42,70,20); label->setFont(labelFont()); diff --git a/utils/rddbmgr/revertschema.cpp b/utils/rddbmgr/revertschema.cpp index 4aa1aecf..6018a5d6 100644 --- a/utils/rddbmgr/revertschema.cpp +++ b/utils/rddbmgr/revertschema.cpp @@ -40,6 +40,20 @@ bool MainObject::RevertSchema(int cur_schema,int set_schema,QString *err_msg) // NEW SCHEMA REVERSIONS GO HERE... + // + // Revert 352 + // + if((cur_schema==352)&&(set_schemacur_schema)) { + DropColumn("SYSTEM","TIME_FORMAT"); + sql=QString("alter table `SYSTEM` ")+ + "add column `SHOW_TWELVE_HOUR_TIME` enum('N','Y') not null default 'N' "+ + "after `SHORT_DATE_FORMAT`"; + if(!RDSqlQuery::apply(sql,err_msg)) { + return false; + } + + WriteSchemaVersion(++cur_schema); + } + + // NEW SCHEMA UPDATES GO HERE...