mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	desktop/image: allow larger range for manual time shift
The QTimeEdit field is severely limited when it comes to the supported time range. By coding our own input / validation we can allow far larger time shifts. For simplicity, this always assumes hours:minutes format. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									6ea4cfcc02
								
							
						
					
					
						commit
						4167b2ff14
					
				
					 3 changed files with 30 additions and 87 deletions
				
			
		|  | @ -31,72 +31,11 @@ | ||||||
|    <item> |    <item> | ||||||
|     <widget class="QGroupBox" name="groupBox"> |     <widget class="QGroupBox" name="groupBox"> | ||||||
|      <property name="title"> |      <property name="title"> | ||||||
|       <string>Shift times of image(s) by</string> |       <string>Manually shift times of image(s) by hours:minutes</string> | ||||||
|      </property> |      </property> | ||||||
|      <layout class="QVBoxLayout" name="verticalLayout"> |      <layout class="QVBoxLayout" name="verticalLayout"> | ||||||
|       <item> |       <item> | ||||||
|        <widget class="QTimeEdit" name="timeEdit"> |        <widget class="QLineEdit" name="timeEdit"> | ||||||
|         <property name="date"> |  | ||||||
|          <date> |  | ||||||
|           <year>2000</year> |  | ||||||
|           <month>1</month> |  | ||||||
|           <day>1</day> |  | ||||||
|          </date> |  | ||||||
|         </property> |  | ||||||
|         <property name="maximumDateTime"> |  | ||||||
|          <datetime> |  | ||||||
|           <hour>23</hour> |  | ||||||
|           <minute>59</minute> |  | ||||||
|           <second>59</second> |  | ||||||
|           <year>2010</year> |  | ||||||
|           <month>12</month> |  | ||||||
|           <day>31</day> |  | ||||||
|          </datetime> |  | ||||||
|         </property> |  | ||||||
|         <property name="minimumDateTime"> |  | ||||||
|          <datetime> |  | ||||||
|           <hour>0</hour> |  | ||||||
|           <minute>0</minute> |  | ||||||
|           <second>0</second> |  | ||||||
|           <year>2000</year> |  | ||||||
|           <month>1</month> |  | ||||||
|           <day>1</day> |  | ||||||
|          </datetime> |  | ||||||
|         </property> |  | ||||||
|         <property name="maximumDate"> |  | ||||||
|          <date> |  | ||||||
|           <year>2010</year> |  | ||||||
|           <month>12</month> |  | ||||||
|           <day>31</day> |  | ||||||
|          </date> |  | ||||||
|         </property> |  | ||||||
|         <property name="minimumDate"> |  | ||||||
|          <date> |  | ||||||
|           <year>2000</year> |  | ||||||
|           <month>1</month> |  | ||||||
|           <day>1</day> |  | ||||||
|          </date> |  | ||||||
|         </property> |  | ||||||
|         <property name="maximumTime"> |  | ||||||
|          <time> |  | ||||||
|           <hour>23</hour> |  | ||||||
|           <minute>59</minute> |  | ||||||
|           <second>59</second> |  | ||||||
|          </time> |  | ||||||
|         </property> |  | ||||||
|         <property name="minimumTime"> |  | ||||||
|          <time> |  | ||||||
|           <hour>0</hour> |  | ||||||
|           <minute>0</minute> |  | ||||||
|           <second>0</second> |  | ||||||
|          </time> |  | ||||||
|         </property> |  | ||||||
|         <property name="displayFormat"> |  | ||||||
|          <string>h:mm</string> |  | ||||||
|         </property> |  | ||||||
|         <property name="timeSpec"> |  | ||||||
|          <enum>Qt::LocalTime</enum> |  | ||||||
|         </property> |  | ||||||
|        </widget> |        </widget> | ||||||
|       </item> |       </item> | ||||||
|       <item> |       <item> | ||||||
|  |  | ||||||
|  | @ -177,9 +177,10 @@ ShiftImageTimesDialog::ShiftImageTimesDialog(QWidget *parent, QStringList fileNa | ||||||
| 	matchAllImages(false) | 	matchAllImages(false) | ||||||
| { | { | ||||||
| 	ui.setupUi(this); | 	ui.setupUi(this); | ||||||
|  | 	ui.timeEdit->setValidator(new QRegExpValidator(QRegExp("\\d{0,6}:[0-5]\\d"))); | ||||||
| 	connect(ui.syncCamera, SIGNAL(clicked()), this, SLOT(syncCameraClicked())); | 	connect(ui.syncCamera, SIGNAL(clicked()), this, SLOT(syncCameraClicked())); | ||||||
| 	connect(ui.timeEdit, SIGNAL(timeChanged(const QTime &)), this, SLOT(timeEditChanged(const QTime &))); | 	connect(ui.timeEdit, &QLineEdit::textEdited, this, &ShiftImageTimesDialog::timeEdited); | ||||||
| 	connect(ui.backwards, SIGNAL(toggled(bool)), this, SLOT(timeEditChanged())); | 	connect(ui.backwards, &QCheckBox::toggled, this, &ShiftImageTimesDialog::backwardsChanged); | ||||||
| 	connect(ui.matchAllImages, SIGNAL(toggled(bool)), this, SLOT(matchAllImagesToggled(bool))); | 	connect(ui.matchAllImages, SIGNAL(toggled(bool)), this, SLOT(matchAllImagesToggled(bool))); | ||||||
| 	dcImageEpoch = (time_t)0; | 	dcImageEpoch = (time_t)0; | ||||||
| 
 | 
 | ||||||
|  | @ -198,13 +199,13 @@ time_t ShiftImageTimesDialog::amount() const | ||||||
| 
 | 
 | ||||||
| void ShiftImageTimesDialog::setOffset(time_t offset) | void ShiftImageTimesDialog::setOffset(time_t offset) | ||||||
| { | { | ||||||
| 	if (offset >= 0) { | 	int sign = offset >= 0 ? 1 : -1; | ||||||
|  | 	time_t value = sign * offset; | ||||||
|  | 	ui.timeEdit->setText(QString("%1:%2").arg(value / 3600).arg((value % 3600) / 60, 2, 10, QLatin1Char('0'))); | ||||||
|  | 	if (offset >= 0) | ||||||
| 		ui.forward->setChecked(true); | 		ui.forward->setChecked(true); | ||||||
| 	} else { | 	else | ||||||
| 		ui.backwards->setChecked(true); | 		ui.backwards->setChecked(true); | ||||||
| 		offset *= -1; |  | ||||||
| 	} |  | ||||||
| 	ui.timeEdit->setTime(QTime(offset / 3600, (offset % 3600) / 60, offset % 60)); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void ShiftImageTimesDialog::updateInvalid() | void ShiftImageTimesDialog::updateInvalid() | ||||||
|  | @ -242,25 +243,28 @@ void ShiftImageTimesDialog::updateInvalid() | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void ShiftImageTimesDialog::timeEditChanged(const QTime &time) | void ShiftImageTimesDialog::timeEdited(const QString &timeText) | ||||||
| { | { | ||||||
| 	QDateTimeEdit::Section timeEditSection = ui.timeEdit->currentSection(); | 	// simplistic indication of whether the string is valid
 | ||||||
| 	ui.timeEdit->setEnabled(false); | 	if (ui.timeEdit->hasAcceptableInput()) { | ||||||
| 	m_amount = time.hour() * 3600 + time.minute() * 60; | 		ui.timeEdit->setStyleSheet(""); | ||||||
| 	if (ui.backwards->isChecked()) | 		// parse based on the same reg exp used to validate...
 | ||||||
| 		m_amount *= -1; | 		QRegExp re("(\\d{0,6}):(\\d\\d)"); | ||||||
|  | 		if (re.indexIn(timeText) != -1) { | ||||||
|  | 			time_t hours = re.cap(1).toInt(); | ||||||
|  | 			time_t minutes = re.cap(2).toInt(); | ||||||
|  | 			m_amount = (ui.backwards->isChecked() ? -1 : 1) * (3600 * hours + 60 * minutes); | ||||||
| 			updateInvalid(); | 			updateInvalid(); | ||||||
| 	ui.timeEdit->setEnabled(true); | 		} | ||||||
| 	ui.timeEdit->setFocus(); | 	} else { | ||||||
| 	ui.timeEdit->setSelectedSection(timeEditSection); | 		ui.timeEdit->setStyleSheet("QLineEdit { color: red;}"); | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void ShiftImageTimesDialog::timeEditChanged() | void ShiftImageTimesDialog::backwardsChanged(bool) | ||||||
| { | { | ||||||
| 	if ((m_amount > 0) == ui.backwards->isChecked()) | 	// simply use the timeEdit slot to deal with the sign change
 | ||||||
| 		m_amount *= -1; | 	timeEdited(ui.timeEdit->text()); | ||||||
| 	if (m_amount) |  | ||||||
| 		updateInvalid(); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| URLDialog::URLDialog(QWidget *parent) : QDialog(parent) | URLDialog::URLDialog(QWidget *parent) : QDialog(parent) | ||||||
|  |  | ||||||
|  | @ -77,8 +77,8 @@ private | ||||||
| slots: | slots: | ||||||
| 	void syncCameraClicked(); | 	void syncCameraClicked(); | ||||||
| 	void dcDateTimeChanged(const QDateTime &); | 	void dcDateTimeChanged(const QDateTime &); | ||||||
| 	void timeEditChanged(const QTime &time); | 	void timeEdited(const QString &timeText); | ||||||
| 	void timeEditChanged(); | 	void backwardsChanged(bool); | ||||||
| 	void updateInvalid(); | 	void updateInvalid(); | ||||||
| 	void matchAllImagesToggled(bool); | 	void matchAllImagesToggled(bool); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue