1 /***************************************************************************tv
2 mainqsoentrywidget.cpp - description
3 -------------------
4 begin : january 2020
5 copyright : (C) 2020 by Jaime Robles
6 email : jaime@robles.es
7 ***************************************************************************/
8
9 /*****************************************************************************
10 * This file is part of KLog. *
11 * *
12 * KLog is free software: you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation, either version 3 of the License, or *
15 * (at your option) any later version. *
16 * *
17 * KLog is distributed in the hope that it will be useful, *
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20 * GNU General Public License for more details. *
21 * *
22 * You should have received a copy of the GNU General Public License *
23 * along with KLog. If not, see <https://www.gnu.org/licenses/>. *
24 * *
25 *****************************************************************************/
26 //https://github.com/ea4k/klog/commit/1ac02c7b779922a8e5907ebee088fa64654cbdf5
27 #include "mainqsoentrywidget.h"
28
MainQSOEntryWidget(DataProxy_SQLite * dp,QWidget * parent)29 MainQSOEntryWidget::MainQSOEntryWidget(DataProxy_SQLite *dp, QWidget *parent) : QWidget(parent)
30 {
31 //qDebug()<< "MainQSOEntryWidget::MainQSOEntryWidget " << QT_ENDL;
32 emit debugLog(Q_FUNC_INFO, "Start", Debug);
33
34 upAndRunning = false;
35 dataProxy = dp;
36 qrzLineEdit = new QLineEdit;
37 bandComboBox = new QComboBox;
38 modeComboBox = new QComboBox;
39 dateEdit = new QDateEdit;
40 timeEdit = new QTimeEdit;
41 realtimeCheckBox = new QCheckBox;
42 enabledCR = realtimeCheckBox->backgroundRole();
43
44 OKButton = new QPushButton(tr("&Add"), this);
45 clearButton = new QPushButton(tr("&Clear"), this);
46 timer = new QTimer(this);
47 util = new Utilities;
48 realTime = true;
49 duplicatedQSOSlotInSecs = 0;
50 delayInputTimer = new QTimer;
51
52
53 createUI();
54 setInitialData();
55 //installEventFilter (this);
56 emit debugLog(Q_FUNC_INFO, "END", Debug);
57 //qDebug()<< "MainQSOEntryWidget::MainQSOEntryWidget: - END" << QT_ENDL;
58 }
59
60 /*
61 void MainQSOEntryWidget::slotRealTimeButtonResize()
62 {
63 int heigh = qrzLineEdit->sizeHint ().height ();
64 realtimeButton->setFixedSize(QSize(heigh, heigh));
65 //realtimeButton->setSizePolicy (QSizePolicy::Fixed);
66
67 }
68 */
createUI()69 void MainQSOEntryWidget::createUI()
70 {
71 //qDebug()<< "MainQSOEntryWidget::createUI" << QT_ENDL;
72 emit debugLog(Q_FUNC_INFO, "Start", Debug);
73 qrzLineEdit->setToolTip(tr("Callsign of the QSO."));
74 bandComboBox->setToolTip(tr("Band of the QSO."));
75 modeComboBox->setToolTip(tr("Mode of the QSO."));
76 dateEdit->setToolTip(tr("Date of the QSO."));
77 timeEdit->setToolTip(tr("Time of the QSO."));
78 OKButton->setToolTip(tr("Add the QSO to the log."));
79 clearButton->setToolTip(tr("Clears the QSO entry."));
80 realtimeCheckBox->setToolTip(tr("KLog will show real time if enabled."));
81 realtimeCheckBox->setText (tr("Real time"));
82 //realtimeButton->setToolTip(tr("KLog will show real time if enabled."));
83 QHBoxLayout *TimeLayout = new QHBoxLayout;
84 TimeLayout->addWidget(dateEdit);
85 TimeLayout->addWidget(timeEdit);
86 //TimeLayout->addWidget(realtimeButton);
87 TimeLayout->addWidget(realtimeCheckBox);
88 TimeLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed));
89
90 QHBoxLayout *BandModeLayout = new QHBoxLayout;
91 BandModeLayout->addWidget(bandComboBox);
92 BandModeLayout->addWidget(modeComboBox);
93
94 QHBoxLayout *QrzBandModeLayout = new QHBoxLayout;
95 QrzBandModeLayout->addWidget(qrzLineEdit);
96 QrzBandModeLayout->addLayout(BandModeLayout);
97
98 qrzgroupBox = new QGroupBox(tr("Callsign"));
99 qrzgroupBox->setFlat(true);
100 QVBoxLayout *qrzvbox = new QVBoxLayout;
101 qrzvbox->addLayout(QrzBandModeLayout);
102 qrzgroupBox->setLayout(qrzvbox);
103
104 QHBoxLayout *buttonsLayout = new QHBoxLayout;
105 buttonsLayout->addWidget(OKButton);
106 buttonsLayout->addWidget(clearButton);
107
108 dateEdit->setDisplayFormat("yyyy-MM-dd");
109 timeEdit->setDisplayFormat("HH:mm:ss");
110
111 QGridLayout *widgetLayout = new QGridLayout;
112 widgetLayout->addWidget(qrzgroupBox, 0, 0, 1, 0);
113 widgetLayout->addLayout(TimeLayout, 1, 0);
114 widgetLayout->addLayout(buttonsLayout,1, 1);
115 //widgetLayout->setSizeConstraint(QLayout::SetFixedSize);
116 setLayout(widgetLayout);
117
118 palRed.setColor(QPalette::Text, Qt::red);
119 palBlack.setColor(QPalette::Text, Qt::black);
120 palWhite.setColor(QPalette::Text, Qt::white);
121
122 connect(qrzLineEdit, SIGNAL(returnPressed()), this, SLOT(slotOKButtonClicked() ) );
123 //connect(qrzLineEdit, SIGNAL(res), this, SLOT(slotOKButtonClicked() ) );
124 //connect(qrzLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotQRZTextChanged() ) );
125 connect(qrzLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotStartDelayInputTimer() ) );
126 connect(delayInputTimer, SIGNAL(timeout()), this, SLOT(slotDelayInputTimedOut() ) );
127
128 connect(bandComboBox, SIGNAL(currentIndexChanged (QString)), this, SLOT(slotBandComboBoxChanged(QString) ) ) ;
129 connect(modeComboBox, SIGNAL(currentIndexChanged (QString)), this, SLOT(slotModeComboBoxChanged(QString) ) ) ;
130
131 connect(OKButton, SIGNAL(clicked()), this, SLOT(slotOKButtonClicked() ) );
132
133 connect(clearButton, SIGNAL(clicked()), this, SLOT(slotClearButtonClicked() ) );
134 connect(timer, SIGNAL(timeout()), this, SLOT(slotUpdateTime()) );
135 //connect(realtimeButton, SIGNAL(clicked()), this, SLOT(slotRealtimeButtonClicked()) );
136 connect(realtimeCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxClicked()));
137 //qDebug()<< "MainQSOEntryWidget::createUI-END" << QT_ENDL;
138
139 QWidget::setTabOrder (qrzLineEdit, dateEdit);
140 QWidget::setTabOrder (dateEdit, timeEdit);
141
142 emit debugLog(Q_FUNC_INFO, "END", Debug);
143
144 //qDebug() << Q_FUNC_INFO << ": (" << QString::number(this->size ().width ()) << "/" << QString::number(this->size ().height ()) << ")" ;
145 }
146
147 /*
148 void MainQSOEntryWidget::resizeEvent(QResizeEvent *event)
149 {
150 //qDebug() << Q_FUNC_INFO;
151 slotRealTimeButtonResize();
152
153 }
154 */
155
156
slotCheckBoxClicked()157 void MainQSOEntryWidget::slotCheckBoxClicked()
158 {
159 //qDebug() << Q_FUNC_INFO;
160 if (realtimeCheckBox->isChecked())
161 {
162 realTime = true;
163 //realtimeButton->setIcon(QIcon(":/img/play.svg"));
164 timeEdit->setBackgroundRole(enabledCR);
165 }
166 else
167 {
168 realTime = false;
169 //realtimeButton->setIcon(QIcon(":/img/stop.svg"));
170 timeEdit->setBackgroundRole(QPalette::BrightText);
171 }
172 }
173
174 /*
175 void MainQSOEntryWidget::slotRealtimeButtonClicked()
176 {
177 emit debugLog(Q_FUNC_INFO, "Start", Debug);
178
179 if (realtimeButton->isChecked())
180 {
181 realTime = true;
182 realtimeButton->setIcon(QIcon(":/img/stop.svg"));
183 timeEdit->setBackgroundRole(enabledCR);
184 }
185 else
186 {
187 realTime = false;
188 realtimeButton->setIcon(QIcon(":/img/play.svg"));
189 timeEdit->setBackgroundRole(QPalette::BrightText);
190 }
191
192 emit debugLog(Q_FUNC_INFO, "END", Debug);
193 }
194 */
setCleaning(const bool _c)195 void MainQSOEntryWidget::setCleaning (const bool _c)
196 {
197 emit debugLog(Q_FUNC_INFO, "Start", Debug);
198 cleaning = _c;
199 emit debugLog(Q_FUNC_INFO, "END", Debug);
200 }
201
slotQRZTextChanged()202 void MainQSOEntryWidget::slotQRZTextChanged()
203 {
204 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: " << qrzLineEdit->text() << " / Length: " << QString::number((qrzLineEdit->text()).size()) << "###### START ######" << QT_ENDL;
205 emit debugLog(Q_FUNC_INFO, "Start", Debug);
206
207 if ((qrzLineEdit->text()).length()<1)
208 {
209 //emit clearForNextQSOSignal();
210 //qDebug() << Q_FUNC_INFO;
211 slotClearButtonClicked();
212 emit debugLog(Q_FUNC_INFO, "END-1", Debug);
213 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: QRZ <1 - END" << QT_ENDL;
214 return;
215 }
216 int cursorP = qrzLineEdit->cursorPosition();
217 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: cursor position: " << QString::number(cursorP) << QT_ENDL;
218 qrzLineEdit->setText((qrzLineEdit->text()).toUpper());
219 if (cleaning)
220 {
221 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: Cleaning - END" << QT_ENDL;
222 emit debugLog(Q_FUNC_INFO, "END-2", Debug);
223 return;
224 }
225
226 if (qrzAutoChanging)
227 {
228 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: qrzAutoChanging - END" << QT_ENDL;
229 qrzAutoChanging = false;
230 emit debugLog(Q_FUNC_INFO, "END-3", Debug);
231 return;
232 }
233
234 qrzAutoChanging = true;
235
236 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: cursor position.1: " << QString::number(cursorP) << QT_ENDL;
237
238 if ( (qrzLineEdit->text()).endsWith(' ') )
239 {/*Remove the space and moves the focus to SRX to write the RX exchange*/
240 previousQRZ = (qrzLineEdit->text()).simplified();
241 qrzLineEdit->setText(previousQRZ);
242 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: Space detected" << QT_ENDL;
243 }
244
245 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: Simplifiying & Capitalizing" << QT_ENDL;
246 qrzLineEdit->setText(((qrzLineEdit->text())).simplified());
247 qrzLineEdit->setText((qrzLineEdit->text()).remove(" "));
248
249 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: checking for invalid chars" << QT_ENDL;
250 //TODO: This validCharactersInCall may be removed?
251 InValidCharsInPrevCall = validCharactersInCall(qrzLineEdit->text());
252 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: checking for invalid chars 00 " << QT_ENDL;
253 if (!util->isValidCall(qrzLineEdit->text()))
254 {
255 qrzLineEdit->setPalette(palRed);
256 //emit showInfoLabel(tr("Callsign not valid"));
257 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: QRZ not valid - Red" << QT_ENDL;
258 emit debugLog(Q_FUNC_INFO, "END-4", Debug);
259 }
260 else
261 {
262 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: QRZ is valid - Black" << QT_ENDL;
263 if (getDarkMode())
264 {
265 qrzLineEdit->setPalette(palWhite);
266 }
267 else
268 {
269 qrzLineEdit->setPalette(palBlack);
270 }
271
272 currentQrz = qrzLineEdit->text();
273 //emit showInfoLabel(tr(""));
274 }
275 /*
276 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: checking for length" << QT_ENDL;
277 if (((qrzLineEdit->text()).length() < 1))
278 { // If QRZ box is blank, Information labels should be cleared.
279 slotClearButtonClicked();
280 emit debugLog(Q_FUNC_INFO, "END-5", Debug);
281 return;
282 }
283 */
284
285 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: checking for modify or length<1" << QT_ENDL;
286 if (qrzSmallModDontCalculate)
287 //if ((modify) || ((qrzLineEdit->text()).length() < 1) || (qrzSmallModDontCalculate))
288 {
289 //qDebug() << "MainQSOEntryWidget::slotQRZTextChanged: qrzSmallModDontCalculate < 1" << QT_ENDL;
290 qrzSmallModDontCalculate=false;
291 emit debugLog(Q_FUNC_INFO, "END-6", Debug);
292 return;
293 }
294
295 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: running..." << QT_ENDL;
296 qrzSmallModDontCalculate = true; // A kind of flag to prevent multiple calls to this method.
297 currentQrz = qrzLineEdit->text();
298
299 if ((currentQrz).count('\\'))
300 { // Replaces \ by / to ease operation.
301 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: Replacing \\ by /" << QT_ENDL;
302 currentQrz.replace(QChar('\\'), QChar('/'));
303 qrzLineEdit->setText(currentQrz);
304 }
305
306 currentQrz = qrzLineEdit->text();
307 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: cursor position.3: " << QString::number(cursorP) << QT_ENDL;
308 if (cursorP>currentQrz.length())
309 {// A Space that has been removed without updating the cursor
310 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: cursorP > currentQRZ.length" << QT_ENDL;
311 }
312 else
313 {
314 if (cursorP==0)
315 {
316
317 }
318 else if ((currentQrz.at(cursorP-1)).isSpace())
319 {
320 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: cursor position.5: " << QString::number(cursorP) << QT_ENDL;
321 previousQRZ = currentQrz.remove(cursorP-1, 1);
322 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: cursor position.6: " << QString::number(cursorP) << QT_ENDL;
323 cursorP--;
324 //qDebug()<< "MainQSOEntryWidget::slotQRZTextChanged: cursor position.7: " << QString::number(cursorP) << QT_ENDL;
325 qrzLineEdit->setText(previousQRZ);
326 }
327 }
328
329 currentQrz = qrzLineEdit->text();
330 //qDebug() << "MainQSOEntryWidget::slotQRZTextChanged: Emitting: " << currentQrz << QT_ENDL;
331 emit currentQRZSignal(currentQrz);
332
333 qrzSmallModDontCalculate = false; // If the text has not been modified in this method
334 //qDebug() << "MainQSOEntryWidget::slotQRZTextChanged: cursorP at the end : " << QString::number(cursorP) << QT_ENDL;
335 qrzLineEdit->setCursorPosition(cursorP);
336 checkIfDupe(Q_FUNC_INFO);
337 qrzAutoChanging = false;
338 emit debugLog(Q_FUNC_INFO, "Start", Debug);
339
340 //qDebug() << "MainQSOEntryWidget::slotQRZTextChanged: END" << QT_ENDL;
341 }
342
setCurrentQRZ(const QString & _qrz)343 void MainQSOEntryWidget::setCurrentQRZ(const QString &_qrz)
344 {
345 emit debugLog(Q_FUNC_INFO, "Start", Debug);
346 currentQrz = _qrz;
347 emit debugLog(Q_FUNC_INFO, "END", Debug);
348 }
349
slotBandComboBoxChanged(const QString & _b)350 void MainQSOEntryWidget::slotBandComboBoxChanged(const QString &_b){
351 //qDebug() << Q_FUNC_INFO << ": " << _b;
352
353 emit debugLog(Q_FUNC_INFO, "Start", Debug);
354 bottomBandLimit = dataProxy->getLowLimitBandFromBandName (_b);
355 upperBandLimit = dataProxy->getUpperLimitBandFromBandName (_b);
356 emit bandChanged(_b);
357 checkIfDupe(Q_FUNC_INFO);
358 emit debugLog(Q_FUNC_INFO, "END", Debug);
359 //qDebug() << Q_FUNC_INFO << " - END";
360 }
361
slotModeComboBoxChanged(const QString & _m)362 void MainQSOEntryWidget::slotModeComboBoxChanged(const QString &_m)
363 {
364 emit debugLog(Q_FUNC_INFO, "Start", Debug);
365
366 emit modeChanged(_m);
367 checkIfDupe(Q_FUNC_INFO);
368 emit debugLog(Q_FUNC_INFO, "END", Debug);
369 }
370
slotOKButtonClicked()371 void MainQSOEntryWidget::slotOKButtonClicked()
372 {
373 emit debugLog(Q_FUNC_INFO, "Start", Debug);
374 if ((qrzLineEdit->text()).length()<1)
375 {
376 return;
377 }
378 emit OKClicked();
379 emit debugLog(Q_FUNC_INFO, "END", Debug);
380 }
381
slotClearButtonClicked()382 void MainQSOEntryWidget::slotClearButtonClicked()
383 {
384 //qDebug() << "MainQSOEntryWidget::slotClearButtonClicked" << QT_ENDL;
385 emit debugLog(Q_FUNC_INFO, "Start", Debug);
386 clear();
387 emit clearForNextQSOSignal();
388 setModify(false);
389 checkIfDupe(Q_FUNC_INFO);
390 emit debugLog(Q_FUNC_INFO, "END", Debug);
391 }
392
clear()393 void MainQSOEntryWidget::clear()
394 {
395 emit debugLog(Q_FUNC_INFO, "Start", Debug);
396
397 //qDebug() << Q_FUNC_INFO << QT_ENDL;
398
399 //cleaning = true;
400
401 OKButton->setText(tr("&Add"));
402 qrzLineEdit->clear();
403 qrzLineEdit->setFocus(Qt::OtherFocusReason);
404
405 //cleaning = false;
406 emit debugLog(Q_FUNC_INFO, "END", Debug);
407 }
408
setInitialData()409 void MainQSOEntryWidget::setInitialData()
410 {
411 //qDebug()<< "MainQSOEntryWidget::setInitialData" << QT_ENDL;
412 emit debugLog(Q_FUNC_INFO, "Start", Debug);
413 //Default band/modes
414 modify = false;
415 qrzAutoChanging = false;
416 InValidCharsInPrevCall = false;
417 qrzSmallModDontCalculate=false;
418 previousQRZ = QString();
419
420 bands.clear();
421 modes.clear();
422 bands << "10M" << "15M" << "20M" << "40M" << "80M" << "160M";
423 modes << "SSB" << "CW" << "RTTY";
424
425
426 setBands(bands);
427 setModes(modes);
428
429 selectDefaultBand(true);
430 selectDefaultMode(true);
431
432 dateEdit->setDate(QDate::currentDate());
433 timeEdit->setTime(QTime::currentTime());
434
435 UTCTime = true;
436 // //qDebug()ime = true;
437
438 timer->start(1000);
439
440 emit debugLog(Q_FUNC_INFO, "END", Debug);
441 //qDebug()<< "MainQSOEntryWidget::setInitialData-END" << QT_ENDL;
442
443 }
444
updateBandComboBox(const QString & _band)445 bool MainQSOEntryWidget::updateBandComboBox(const QString &_band)
446 {
447 //qDebug() << Q_FUNC_INFO << ": " << _band << QT_ENDL;
448
449 //QString _currentBand = getBand();
450 if (!isBandExisting(_band))
451 {// The selected frequency is of a band that is not currently selected
452 QString _currentBand = bandComboBox->currentText ();
453 //qDebug() << Q_FUNC_INFO << ": New band found: " << _band << QT_ENDL;
454 if (dataProxy->getIdFromBandName(_band) > 1)
455 {// Not affected if 0 (light) is the frequency
456 // In this case the user should select the band in the setup
457 //qDebug() << Q_FUNC_INFO << ": Band is valid: " << _band << QT_ENDL;
458 QStringList qsTemp;
459 qsTemp.clear();
460 qsTemp << bands;
461 qsTemp << _band;
462 qsTemp.removeDuplicates();
463 bands.clear();
464 bands = dataProxy->sortBandNamesBottonUp(qsTemp);
465 //qDebug() << Q_FUNC_INFO << ": Before setBands" << QT_ENDL;
466 setBands(bands);
467 bandComboBox->setCurrentIndex(bandComboBox->findText(_currentBand, Qt::MatchCaseSensitive));
468 //qDebug() << Q_FUNC_INFO << ": Band has been added : " << _band << QT_ENDL;
469 }
470 else
471 {
472 //qDebug() << Q_FUNC_INFO << ": (END) Band is NOT valid: " <<_band<< endl;
473 return false;
474 }
475 }
476
477
478 //qDebug() << Q_FUNC_INFO << ": Band already existing, no need to add" << QT_ENDL;
479 return true;
480
481
482
483
484 }
485
setBands(const QStringList _bands)486 void MainQSOEntryWidget::setBands(const QStringList _bands)
487 {
488 emit debugLog(Q_FUNC_INFO, "Start", Debug);
489 //qDebug()<< "MainQSOEntryWidget::setBands" << QT_ENDL;
490 foreach(QString i, _bands)
491 {
492 //qDebug()<< "MainQSOEntryWidget::setBands - received: " << i << QT_ENDL;
493 }
494
495 bands.clear();
496 bands = _bands;
497 bands.removeDuplicates();
498 bands = dataProxy->sortBandNamesBottonUp(bands);
499 bandComboBox->clear();
500 bandComboBox->addItems(bands);
501 emit validBands(_bands);
502 //selectDefaultBand(true);
503 emit debugLog(Q_FUNC_INFO, "END", Debug);
504 //qDebug()<< "MainQSOEntryWidget::setBands-END" << QT_ENDL;
505 }
506
setModes(const QStringList _modes)507 void MainQSOEntryWidget::setModes(const QStringList _modes)
508 {
509 emit debugLog(Q_FUNC_INFO, "Start", Debug);
510 modes.clear();
511 modes = _modes;
512 modes.removeDuplicates();
513 modes.sort();
514 modeComboBox->clear();
515 modeComboBox->addItems(modes);
516 selectDefaultMode(true);
517 emit debugLog(Q_FUNC_INFO, "END", Debug);
518
519 }
520
getModes()521 QStringList MainQSOEntryWidget::getModes()
522 {
523 return modes;
524 }
525
setFreq(const double _f,bool isRX)526 bool MainQSOEntryWidget::setFreq(const double _f, bool isRX)
527 {
528 //qDebug() << Q_FUNC_INFO << ": " << QString::number(_f);
529
530 if (isRX)
531 {
532 if (util->isSameFreq (freqRX, _f))
533 {
534 return true;
535 }
536 freqRX = _f;
537 }
538
539 if (util->isSameFreq (freqTX, _f))
540 {
541 return true;
542 }
543 freqTX = _f;
544
545 if (newBandNeededForFreq (_f))
546 {
547 if ((bottomBandLimit<=freqTX) && (freqTX<= upperBandLimit))
548 {
549 return true;
550 }
551 //qDebug() << Q_FUNC_INFO << ": Freq is not in the current band" << QT_ENDL;
552 QString _newBand = dataProxy->getBandNameFromFreq(_f);
553 //qDebug() << Q_FUNC_INFO << ": before setting band: " << _newBand << QT_ENDL;
554 if (isRX)
555 {
556 //qDebug() << Q_FUNC_INFO << ": RX Freq no more actions " << QT_ENDL;
557 return true;
558 }
559 return setBand(_newBand);
560
561 }
562 return false;
563 }
564
newBandNeededForFreq(const double _f)565 bool MainQSOEntryWidget::newBandNeededForFreq(const double _f)
566 {
567 //qDebug() << Q_FUNC_INFO << ": " << QString::number(_f);
568 QString _newBand = dataProxy->getBandNameFromFreq(_f);
569 if (!updateBandComboBox (_newBand))
570 {
571 emit debugLog(Q_FUNC_INFO, "END-1", Debug);
572 //qDebug() << Q_FUNC_INFO << " - END false";
573 return false;
574 }
575 //qDebug() << Q_FUNC_INFO << " - END true ";
576 emit debugLog(Q_FUNC_INFO, "END", Debug);
577 return true;
578 }
579
setBand(const QString & _band)580 bool MainQSOEntryWidget::setBand(const QString &_band)
581 {
582 //qDebug() << Q_FUNC_INFO << ": " << _band << QT_ENDL;
583
584 emit debugLog(Q_FUNC_INFO, "Start", Debug);
585 if (bandComboBox->findText(_band, Qt::MatchCaseSensitive) < 0)
586 {
587 //qDebug() << "MainQSOEntryWidget::setBand-1: Band not found " << _band << QT_ENDL;
588 if (!updateBandComboBox(_band))
589 {
590 emit debugLog(Q_FUNC_INFO, "END-1", Debug);
591 return false;
592 }
593 }
594 //qDebug() << "MainQSOEntryWidget::setBand-1: Band found " << _band << QT_ENDL;
595 bandComboBox->setCurrentIndex(bandComboBox->findText(_band, Qt::MatchCaseSensitive));
596 emit debugLog(Q_FUNC_INFO, "END-2", Debug);
597 //qDebug() << Q_FUNC_INFO << " - END" << QT_ENDL;
598 return true;
599 }
600
setMode(const QString & _mode)601 bool MainQSOEntryWidget::setMode(const QString &_mode)
602 {
603 emit debugLog(Q_FUNC_INFO, "Start", Debug);
604 //qDebug() << "MainQSOEntryWidget::setMode: " << _mode << QT_ENDL;
605 if (modeComboBox->findText(_mode, Qt::MatchCaseSensitive) < 0)
606 {
607 emit debugLog(Q_FUNC_INFO, "END-1", Debug);
608 return false;
609 }
610 else
611 {
612 modeComboBox->setCurrentIndex(modeComboBox->findText(_mode, Qt::MatchCaseSensitive));
613 emit debugLog(Q_FUNC_INFO, "END", Debug);
614 return true;
615 }
616 }
617
setQRZ(const QString & _qrz)618 bool MainQSOEntryWidget::setQRZ(const QString &_qrz)
619 {
620 emit debugLog(Q_FUNC_INFO, "Start", Debug);
621 //qDebug() << "MainQSOEntryWidget::setQRZ: " << _qrz << QT_ENDL;
622 //TODO: Add validations to prevent that non valid qrz are sent from the outside of this function or at least manage this appropriately.
623 qrzLineEdit->setText(_qrz.toUpper());
624 emit debugLog(Q_FUNC_INFO, "END", Debug);
625 return false;
626 }
627
setDateTime(const QDateTime _date)628 bool MainQSOEntryWidget::setDateTime(const QDateTime _date)
629 {
630 emit debugLog(Q_FUNC_INFO, "Start", Debug);
631 if (_date.isValid())
632 {
633 dateEdit->setDate(_date.date());
634 timeEdit->setTime(_date.time());
635
636 emit debugLog(Q_FUNC_INFO, "END", Debug);
637 return true;
638 }
639 else
640 {
641 //qDebug() << "MainQSOEntryWidget::setDate - NO VALID DATE" << QT_ENDL;
642 emit debugLog(Q_FUNC_INFO, "END", Debug);
643 return false;
644 }
645 }
646
setTime(const QTime _time)647 bool MainQSOEntryWidget::setTime(const QTime _time)
648 {
649 emit debugLog(Q_FUNC_INFO, "Start", Debug);
650 if (_time.isValid())
651 {
652 timeEdit->setTime(_time);
653 emit debugLog(Q_FUNC_INFO, "END", Debug);
654 return true;
655 }
656 else
657 {
658 emit debugLog(Q_FUNC_INFO, "END", Debug);
659 return false;
660 }
661 }
662
getQrz()663 QString MainQSOEntryWidget::getQrz()
664 {
665 emit debugLog(Q_FUNC_INFO, "Start", Debug);
666 emit debugLog(Q_FUNC_INFO, "END", Debug);
667 return (qrzLineEdit->text()).toUpper();
668 }
669
getBand(const int _b)670 QString MainQSOEntryWidget::getBand(const int _b)
671 {
672 emit debugLog(Q_FUNC_INFO, "Start", Debug);
673 if (_b<0)
674 {
675 emit debugLog(Q_FUNC_INFO, "END", Debug);
676 //qDebug() << "MainQSOEntryWidget::getBand(1): " << bandComboBox->currentText()<< QT_ENDL;
677 return bandComboBox->currentText();
678 }
679 else
680 {
681 if (bandComboBox->count()>=_b)
682 {
683 emit debugLog(Q_FUNC_INFO, "END-1", Debug);
684 //qDebug() << "MainQSOEntryWidget::getBand(2): " << bandComboBox->currentText()<< QT_ENDL;
685 return bandComboBox->itemText(_b);
686 }
687 else
688 {
689 emit debugLog(Q_FUNC_INFO, "END-2", Debug);
690 //qDebug() << "MainQSOEntryWidget::getBand(3): " << bandComboBox->currentText()<< QT_ENDL;
691 return bandComboBox->currentText();
692 }
693 }
694 }
695
getMode(const int _m)696 QString MainQSOEntryWidget::getMode(const int _m)
697 {
698 emit debugLog(Q_FUNC_INFO, "Start", Debug);
699 if (_m<0)
700 {
701 emit debugLog(Q_FUNC_INFO, "END", Debug);
702 return modeComboBox->currentText();
703 }
704 else
705 {
706 if (modeComboBox->count()>=_m)
707 {
708 emit debugLog(Q_FUNC_INFO, "END-1", Debug);
709 return modeComboBox->itemText(_m);
710 }
711 else
712 {
713 emit debugLog(Q_FUNC_INFO, "END-2", Debug);
714 return modeComboBox->currentText();
715 }
716 }
717 }
718
getDate()719 QDate MainQSOEntryWidget::getDate()
720 {
721 emit debugLog(Q_FUNC_INFO, "Start", Debug);
722 emit debugLog(Q_FUNC_INFO, "END", Debug);
723 return dateEdit->date();
724 }
725
726
getDateTime()727 QDateTime MainQSOEntryWidget::getDateTime()
728 {
729 emit debugLog(Q_FUNC_INFO, "Start", Debug);
730 //emit debugLog(Q_FUNC_INFO, "END", Debug);
731 QDateTime dateTime;
732 dateTime.setDate(dateEdit->date());
733 dateTime.setTime(timeEdit->time());
734 return dateTime;
735
736 }
737
getTime()738 QTime MainQSOEntryWidget::getTime()
739 {
740 emit debugLog(Q_FUNC_INFO, "Start", Debug);
741 emit debugLog(Q_FUNC_INFO, "END", Debug);
742 return timeEdit->time();
743 }
744
toggleRealTime()745 void MainQSOEntryWidget::toggleRealTime()
746 {
747 //if ( realtimeButton->isChecked ())
748 if ( realtimeCheckBox->isChecked ())
749 {
750 setRealTime (false);
751 }
752 else {
753 setRealTime (true);
754 }
755 }
756
getRealTime()757 bool MainQSOEntryWidget::getRealTime()
758 {
759 //return realtimeButton->isChecked ();
760 return realtimeCheckBox->isChecked ();
761
762 }
763
setRealTime(const bool _realTime)764 void MainQSOEntryWidget::setRealTime(const bool _realTime)
765 {
766 emit debugLog(Q_FUNC_INFO, "Start", Debug);
767 //qDebug << Q_FUNC_INFO << ": " << util->boolToQString (_realTime);
768
769 realTime = _realTime;
770 realtimeCheckBox->setChecked(realTime);
771 /*
772 * if (_realTime)
773 {
774 realtimeButton->setIcon(QIcon(":/img/play.svg"));
775 }
776 else
777 {
778 realtimeButton->setIcon(QIcon(":/img/stop.svg"));
779 }
780 */
781 //realTime = _realTime;
782 emit debugLog(Q_FUNC_INFO, "END", Debug);
783 }
784
785
setUTC(const bool _utc)786 void MainQSOEntryWidget::setUTC(const bool _utc)
787 {
788 emit debugLog(Q_FUNC_INFO, "Start", Debug);
789 UTCTime = _utc;
790 setDateAndTimeInternally();
791 emit debugLog(Q_FUNC_INFO, "END", Debug);
792 }
793
setModify(const bool _modify)794 void MainQSOEntryWidget::setModify(const bool _modify)
795 {
796 emit debugLog(Q_FUNC_INFO, "Start", Debug);
797 modify = _modify;
798
799 if (modify)
800 {
801 OKButton->setText(tr("&Modify"));
802 realtimeCheckBox->setChecked (false);
803 }
804 else
805 {
806 OKButton->setText(tr("&Add"));
807 }
808 emit debugLog(Q_FUNC_INFO, "END", Debug);
809 }
810
getModifying()811 bool MainQSOEntryWidget::getModifying()
812 {
813 return modify;
814 }
815
slotUpdateTime()816 void MainQSOEntryWidget::slotUpdateTime()
817 {
818 //qDebug()<< "MainQSOEntryWidget::slotUpdateTime" << QT_ENDL;
819 //emit debugLog(Q_FUNC_INFO, "Start", Debug);
820
821 //if ( (!modify) && (realtimeButton->isChecked()) )
822 if ( (!modify) && (realtimeCheckBox->isChecked()) )
823 {
824 //qDebug()<< "MainQSOEntryWidget::slotUpdateTime - Real Time & update" << QT_ENDL;
825 setDateAndTimeInternally();
826 }
827
828 //emit debugLog(Q_FUNC_INFO, "END", Debug);
829 }
830
setDateAndTimeInternally()831 void MainQSOEntryWidget::setDateAndTimeInternally()
832 {
833 if (UTCTime)
834 {
835 dateEdit->setDate(QDateTime::currentDateTime().toUTC().date());
836 timeEdit->setTime(QDateTime::currentDateTime().toUTC().time());
837 }
838 else
839 {
840 dateEdit->setDate(QDateTime::currentDateTime().date());
841 timeEdit->setTime(QDateTime::currentDateTime().time());
842 }
843 }
844
validCharactersInCall(const QString & _qrz)845 bool MainQSOEntryWidget::validCharactersInCall(const QString &_qrz)
846 {
847 //qDebug()<< "MainQSOEntryWidget::validCharactersInCall: " << _qrz << QT_ENDL;
848 emit debugLog(Q_FUNC_INFO, "Start", Debug);
849 for (int i = 0; i<_qrz.size()-1;i++)
850 {
851 if (!( ((_qrz.at(i)).isLetterOrNumber()) || (_qrz.at(i)=='\\') || (_qrz.at(i)=='/') ))
852 {
853 emit debugLog(Q_FUNC_INFO, "END-1", Debug);
854 return false;
855 }
856
857 }
858 emit debugLog(Q_FUNC_INFO, "END", Debug);
859 return true;
860 }
861
isModeExisting(const QString & _m)862 bool MainQSOEntryWidget::isModeExisting(const QString &_m)
863 {
864 emit debugLog(Q_FUNC_INFO, "Start", Debug);
865 if (modeComboBox->findText(_m, Qt::MatchCaseSensitive) >= 0)
866 {
867 emit debugLog(Q_FUNC_INFO, "END-1", Debug);
868 return true;
869 }
870 else
871 {
872 emit debugLog(Q_FUNC_INFO, "END-2", Debug);
873 return false;
874 }
875
876 }
877
isBandExisting(const QString & _b)878 bool MainQSOEntryWidget::isBandExisting(const QString &_b)
879 {
880 emit debugLog(Q_FUNC_INFO, "Start", Debug);
881 //qDebug() << Q_FUNC_INFO << ": " << _b << QT_ENDL;
882 if (bandComboBox->findText(_b, Qt::MatchCaseSensitive) >= 0)
883 {
884 emit debugLog(Q_FUNC_INFO, "END-1", Debug);
885 //qDebug() << Q_FUNC_INFO << " - END true" << QT_ENDL;
886 return true;
887 }
888 else
889 {
890 emit debugLog(Q_FUNC_INFO, "END-2", Debug);
891 //qDebug() << Q_FUNC_INFO << " - END false" << QT_ENDL;
892 return false;
893 }
894 }
895
setUpAndRunning(const bool _u)896 void MainQSOEntryWidget::setUpAndRunning(const bool _u)
897 {
898 emit debugLog(Q_FUNC_INFO, "Start", Debug);
899 upAndRunning = _u;
900 emit debugLog(Q_FUNC_INFO, "END", Debug);
901 }
902
selectDefaultBand(const bool _init)903 void MainQSOEntryWidget::selectDefaultBand(const bool _init)
904 {
905 //qDebug() << "MainQSOEntryWidget::selectDefaultBand" << QT_ENDL;
906 emit debugLog(Q_FUNC_INFO, "Start", Debug);
907 if ((upAndRunning) || (!_init))
908 {
909 emit debugLog(Q_FUNC_INFO, "END-1", Debug);
910 //qDebug() << "MainQSOEntryWidgetselectDefaultBand-END-1" << QT_ENDL;
911 return;
912 }
913 QString aux;
914 aux = QString();
915 int defaultBand = dataProxy->getMostUsedBand(-1); //TODO: The log could be defined here
916 //qDebug() << "MainQSOEntryWidget::selectDefaultBand: " << QString::number(defaultBand) << dataProxy->getNameFromBandId (defaultBand)<< QT_ENDL;
917 if (defaultBand<1)
918 {
919
920 defaultBand = dataProxy->getIdFromBandName(getBand(0));
921
922 }
923
924 aux = dataProxy->getNameFromBandId(defaultBand);
925 //qDebug() << Q_FUNC_INFO << ": before setting band: " << aux << QT_ENDL;
926 setBand(aux);
927 emit debugLog(Q_FUNC_INFO, "END", Debug);
928
929 //qDebug() << "MainQSOEntryWidgetselectDefaultBand_END" << QT_ENDL;
930 }
931
selectDefaultMode(const bool _init)932 void MainQSOEntryWidget::selectDefaultMode(const bool _init)
933 {
934 //qDebug() << "MainQSOEntryWidgetselectDefaultMode" << QT_ENDL;
935 emit debugLog(Q_FUNC_INFO, "Start", Debug);
936 if ((upAndRunning) || (!_init))
937 {
938 emit debugLog(Q_FUNC_INFO, "END-1", Debug);
939 return;
940 }
941 int defaultMode = dataProxy->getMostUsedMode(-1); //TODO: The log could be defined here
942 //qDebug() << "MainQSOEntryWidgetselectDefaultMode: " << QString::number(defaultMode) << QT_ENDL;
943
944 if (defaultMode < 1)
945 {
946 defaultMode = dataProxy->getSubModeIdFromSubMode(getBand(0));
947 }
948 setMode(dataProxy->getNameFromSubModeId(defaultMode));
949 //modeComboBox->setCurrentIndex(modeComboBox->findText(dataProxy->getNameFromSubModeId(defaultMode)));
950
951 //qDebug() << "MainQSOEntryWidgetselectDefaultMode3: " << QString::number(defaultMode) << QT_ENDL;
952 emit debugLog(Q_FUNC_INFO, "END", Debug);
953 //qDebug() << "MainQSOEntryWidgetselectDefaultMode-END" << QT_ENDL;
954 }
955
setDuplicatedQSOSlot(const int _secs)956 void MainQSOEntryWidget::setDuplicatedQSOSlot (const int _secs)
957 {
958 if (_secs >= 0)
959 {
960 duplicatedQSOSlotInSecs = _secs;
961 }
962 }
963
checkIfDupe(const QString & _func)964 void MainQSOEntryWidget::checkIfDupe(const QString &_func)
965 {
966
967 #ifdef QT_DEBUG
968 //qDebug() << Q_FUNC_INFO << "(" << _func << ")" << QT_ENDL;
969 #else
970 #endif
971
972 QDateTime _dateTime;
973 _dateTime.setDate(dateEdit->date());
974 _dateTime.setTime(timeEdit->time());
975
976 if ((dataProxy->isThisQSODuplicated(Q_FUNC_INFO, qrzLineEdit->text(), _dateTime, dataProxy->getIdFromBandName(bandComboBox->currentText()), dataProxy->getIdFromModeName(modeComboBox->currentText()), duplicatedQSOSlotInSecs).length()<2) || modify)
977 {
978 //qDebug() << Q_FUNC_INFO << " - NOT DUPE " << QT_ENDL;
979 //qDebug() << Q_FUNC_INFO << " - Modify: " << util->boolToQString(modify) << QT_ENDL;
980
981 qrzgroupBox->setTitle(tr("Callsign"));
982 }
983 else
984 {
985 //qDebug() << Q_FUNC_INFO << " - NOT DUPE " << QT_ENDL;
986 qrzgroupBox->setTitle(tr("DUPE", "Translator: DUPE is a common world for hams. Do not translate of not sure"));
987 }
988 }
989
slotStartDelayInputTimer()990 void MainQSOEntryWidget::slotStartDelayInputTimer()
991 {
992 if (cleaning)
993 {
994 return;
995 }
996 if (qrzLineEdit->text ().length ()<1)
997 {
998 //qDebug() << Q_FUNC_INFO;
999 slotClearButtonClicked ();
1000 return;
1001 }
1002
1003 int cursor = qrzLineEdit->cursorPosition ();
1004 QString aux = util->getClearSQLi (qrzLineEdit->text ());
1005 qrzLineEdit->setText (aux.toUpper());
1006 qrzLineEdit->setCursorPosition (cursor);
1007 delayInputTimer->start(300);
1008 }
1009
slotDelayInputTimedOut()1010 void MainQSOEntryWidget::slotDelayInputTimedOut()
1011 {
1012 delayInputTimer->stop();
1013 QString text = qrzLineEdit->text();
1014 if( text != lastQrz)
1015 {
1016 text = lastQrz;
1017 slotQRZTextChanged();
1018 }
1019 }
1020
getDarkMode()1021 bool MainQSOEntryWidget::getDarkMode()
1022 {
1023 if (OKButton->palette().color (QPalette::Base) == "#646464")
1024 {
1025 return true;
1026 }
1027 else
1028 {
1029 return false;
1030 }
1031 }
1032
1033 /*
1034 void MainQSOEntryWidget::keyPressEvent( QKeyEvent *event)
1035 {
1036 //qDebug() << Q_FUNC_INFO;
1037 if(event->key()==Qt::Key_Enter)
1038 {
1039 //qDebug() << Q_FUNC_INFO << " TAB...";
1040 }
1041
1042 }
1043 */
1044
eventFilter(QObject * object,QEvent * event)1045 bool MainQSOEntryWidget::eventFilter(QObject *object, QEvent *event)
1046 {
1047 if (!(event->type() == QEvent::Paint ))
1048 {
1049 //qDebug() << Q_FUNC_INFO << ": " << QString::number(event->type ());
1050 }
1051
1052 if ((event->type() == QEvent::KeyPress) || (event->type() == QEvent::ShortcutOverride)) {
1053 //qDebug() << Q_FUNC_INFO << "KEY PRESSED";
1054 QKeyEvent *ke = static_cast<QKeyEvent *>(event);
1055 if (ke->key() == Qt::Key_Tab) {
1056 //qDebug() << Q_FUNC_INFO << "KEY PRESSED TAB";
1057 if ((realtimeCheckBox->isChecked ()) && (qrzLineEdit->hasFocus ()))
1058 {
1059 //qDebug() << Q_FUNC_INFO << "KEY PRESSED TAB AND REAL TIME CHECKED";
1060 //qDebug() << Q_FUNC_INFO << "emitting to hand over to QSO TAB-1";
1061 emit handOverFocusSignal();
1062 }
1063 else if((!realtimeCheckBox->isChecked ()) && timeEdit->hasFocus () && (timeEdit->currentSection() == QTimeEdit::SecondSection))
1064 {
1065 //qDebug() << Q_FUNC_INFO << "emitting to hand over to QSO TAB-2";
1066 emit handOverFocusSignal();
1067 }
1068
1069 // special tab handling here
1070 return true;
1071 }
1072 }
1073
1074 return QWidget::event(event);
1075 }
1076
setFocusToOK()1077 void MainQSOEntryWidget::setFocusToOK()
1078 {
1079 OKButton->setFocus ();
1080 }
1081