@@ -27,6 +27,8 @@ MODULE_IDENTIFICATION("qlog.ui.bandmapwidget");
27
27
// Pixel between each step in BandMap
28
28
#define PIXELSPERSTEP 10
29
29
30
+ #define WIDGET_CENTER ( height()/2 - 50 )
31
+
30
32
BandmapWidget::BandmapWidget (QWidget *parent) :
31
33
QWidget(parent),
32
34
ui(new Ui::BandmapWidget),
@@ -39,19 +41,16 @@ BandmapWidget::BandmapWidget(QWidget *parent) :
39
41
{
40
42
FCT_IDENTIFICATION;
41
43
42
- QSettings settings;
43
-
44
44
ui->setupUi (this );
45
45
46
- double freq = settings.value (" newcontact/frequency" , 3.5 ).toDouble ();
46
+ double newContactFreq = settings.value (" newcontact/frequency" , 3.5 ).toDouble ();
47
+ double ritFreq = newContactFreq + RigProfilesManager::instance ()->getCurProfile1 ().ritOffset ;
48
+ double xitFreq = newContactFreq + RigProfilesManager::instance ()->getCurProfile1 ().xitOffset ;
47
49
const QString &mode = settings.value (" newcontact/mode" , " CW" ).toString ();
48
50
const QString &submode = settings.value (" newcontact/submode" ).toString ();
49
-
50
- freq += RigProfilesManager::instance ()->getCurProfile1 ().ritOffset ;
51
-
52
51
keepRXCenter = settings.value (" bandmap/centerrx" , true ).toBool ();
53
52
54
- setBand (BandPlan::freq2Band (freq ), false );
53
+ setBand (BandPlan::freq2Band (ritFreq ), false );
55
54
56
55
bandmapScene = new GraphicsScene (this );
57
56
bandmapScene->setFocusOnTouch (false );
@@ -72,7 +71,7 @@ BandmapWidget::BandmapWidget(QWidget *parent) :
72
71
update_timer->start (BANDMAP_MAX_REFRESH_TIME);
73
72
74
73
updateMode (VFO1, QString (), mode, submode, 0 );
75
- updateTunedFrequency (VFO1, freq, freq, freq );
74
+ updateTunedFrequency (VFO1, newContactFreq, ritFreq, xitFreq );
76
75
}
77
76
78
77
void BandmapWidget::update ()
@@ -206,7 +205,7 @@ void BandmapWidget::updateStations()
206
205
QMap<double , DxSpot>::iterator lower = spots.lowerBound (currentBand.start );
207
206
QMap<double , DxSpot>::iterator upper = spots.upperBound (currentBand.end );
208
207
209
- for (; lower != upper; lower++ )
208
+ while ( lower != upper )
210
209
{
211
210
double freq_y = ((lower.key () - currentBand.start ) / step) * PIXELSPERSTEP;
212
211
double text_y = std::max (min_y + 5 , freq_y);
@@ -244,6 +243,7 @@ void BandmapWidget::updateStations()
244
243
245
244
text->setDefaultTextColor (Data::statusToColor (lower.value ().status , qApp->palette ().color (QPalette::Text)));
246
245
textItemList.append (text);
246
+ ++lower;
247
247
}
248
248
249
249
pendingSpots = 0 ;
@@ -367,8 +367,6 @@ void BandmapWidget::drawTXRXMarks(double step)
367
367
/* *************************/
368
368
drawFreqMark (rx_freq, step, QColor (30 , 180 , 30 ), &rxMark);
369
369
370
- centerRXFreqPosition ();
371
-
372
370
/* *************************/
373
371
/* Draw TX frequency mark */
374
372
/* *************************/
@@ -517,35 +515,56 @@ void BandmapWidget::setBand(const Band &newBand, bool savePrevBandZoom)
517
515
if ( savePrevBandZoom )
518
516
{
519
517
saveCurrentZoom ();
518
+ saveCurrentScrollFreq ();
520
519
}
521
520
currentBand = newBand;
522
- zoom = savedZoom (newBand);
521
+ zoom = getSavedZoom (newBand);
522
+ zoomFreq = getSavedScrollFreq (newBand);
523
+ zoomWidgetYOffset = WIDGET_CENTER;
523
524
}
524
525
525
526
void BandmapWidget::saveCurrentZoom ()
526
527
{
527
528
FCT_IDENTIFICATION;
528
529
529
- QSettings settings;
530
-
531
530
settings.setValue (" bandmap/zoom/" + currentBand.name , zoom);
532
531
}
533
532
534
- BandmapWidget::BandmapZoom BandmapWidget::savedZoom (Band band)
533
+ BandmapWidget::BandmapZoom BandmapWidget::getSavedZoom (Band band)
535
534
{
536
535
FCT_IDENTIFICATION;
537
536
538
- QSettings settings;
539
-
540
537
QVariant zoomVariant = settings.value (" bandmap/zoom/" + band.name , ZOOM_10KHZ);
541
538
return zoomVariant.value <BandmapWidget::BandmapZoom>();
542
539
}
543
540
544
- void BandmapWidget::spotAgingChanged ( int )
541
+ void BandmapWidget::saveCurrentScrollFreq ( )
545
542
{
546
543
FCT_IDENTIFICATION;
547
544
548
- QSettings settings;
545
+ settings.setValue (" bandmap/scroll/" + currentBand.name , visibleCentreFreq ());
546
+ }
547
+
548
+ double BandmapWidget::getSavedScrollFreq (Band band)
549
+ {
550
+ FCT_IDENTIFICATION;
551
+
552
+ return settings.value (" bandmap/scroll/" + band.name , 0.0 ).toDouble ();
553
+ }
554
+
555
+ double BandmapWidget::visibleCentreFreq () const
556
+ {
557
+ FCT_IDENTIFICATION;
558
+
559
+ QPoint point (0 ,ui->scrollArea ->verticalScrollBar ()->value () + WIDGET_CENTER);
560
+ double ret = ScenePos2Freq (ui->graphicsView ->mapToScene (point));
561
+ qCDebug (runtime) << " Centre freq" << ret;
562
+ return ret;
563
+ }
564
+
565
+ void BandmapWidget::spotAgingChanged (int )
566
+ {
567
+ FCT_IDENTIFICATION;
549
568
550
569
settings.setValue (" bandmap/spot_aging" , ui->clearSpotOlderSpin ->value ());
551
570
}
@@ -565,16 +584,9 @@ void BandmapWidget::zoomIn()
565
584
566
585
if ( zoomFreq == 0.0 )
567
586
{
568
- if ( keepRXCenter )
569
- {
570
- zoomFreq = rx_freq;
571
- }
572
- else
573
- {
574
- QPoint point (0 ,ui->scrollArea ->verticalScrollBar ()->value () + this ->height ()/2 - 50 );
575
- zoomFreq = ScenePos2Freq (ui->graphicsView ->mapToScene (point));
576
- }
577
- zoomWidgetYOffset = this ->height ()/2 - 50 ;
587
+ zoomWidgetYOffset = WIDGET_CENTER;
588
+ zoomFreq = ( keepRXCenter ) ? rx_freq
589
+ : visibleCentreFreq ();
578
590
}
579
591
580
592
if ( zoom > ZOOM_100HZ )
@@ -583,6 +595,7 @@ void BandmapWidget::zoomIn()
583
595
}
584
596
setBandmapAnimation (false );
585
597
update ();
598
+ scrollToFreq (zoomFreq);
586
599
setBandmapAnimation (true );
587
600
}
588
601
@@ -592,16 +605,9 @@ void BandmapWidget::zoomOut()
592
605
593
606
if ( zoomFreq == 0.0 )
594
607
{
595
- if ( keepRXCenter )
596
- {
597
- zoomFreq = rx_freq;
598
- }
599
- else
600
- {
601
- QPoint point (0 ,ui->scrollArea ->verticalScrollBar ()->value () + this ->height ()/2 - 50 );
602
- zoomFreq = ScenePos2Freq (ui->graphicsView ->mapToScene (point));
603
- }
604
- zoomWidgetYOffset = this ->height ()/2 - 50 ;
608
+ zoomWidgetYOffset = WIDGET_CENTER;
609
+ zoomFreq = ( keepRXCenter ) ? rx_freq
610
+ : visibleCentreFreq ();
605
611
}
606
612
607
613
if ( zoom < ZOOM_10KHZ )
@@ -610,6 +616,7 @@ void BandmapWidget::zoomOut()
610
616
}
611
617
setBandmapAnimation (false );
612
618
update ();
619
+ scrollToFreq (zoomFreq);
613
620
setBandmapAnimation (true );
614
621
}
615
622
@@ -699,7 +706,7 @@ void BandmapWidget::showContextMenu(const QPoint &point)
699
706
connect (action, &QAction::triggered, this , [this , enabledBand]()
700
707
{
701
708
setBand (enabledBand);
702
- this -> update ();
709
+ update ();
703
710
});
704
711
bandsMenu.addAction (action);
705
712
}
@@ -715,12 +722,10 @@ void BandmapWidget::showContextMenu(const QPoint &point)
715
722
contextMenu.exec (ui->graphicsView ->mapToGlobal (point));
716
723
}
717
724
718
- void BandmapWidget::updateTunedFrequency (VFOID vfoid , double vfoFreq, double ritFreq, double xitFreq)
725
+ void BandmapWidget::updateTunedFrequency (VFOID, double vfoFreq, double ritFreq, double xitFreq)
719
726
{
720
727
FCT_IDENTIFICATION;
721
728
722
- Q_UNUSED (vfoid)
723
-
724
729
qCDebug (function_parameters) << vfoFreq << ritFreq << xitFreq;
725
730
726
731
/* always show the bandmap for RIT Freq */
@@ -752,6 +757,7 @@ void BandmapWidget::updateTunedFrequency(VFOID vfoid, double vfoFreq, double rit
752
757
/* Draw TX and RX Marks */
753
758
/* ***********************/
754
759
drawTXRXMarks (step);
760
+ scrollToFreq (rx_freq);
755
761
}
756
762
757
763
updateNearestSpot ();
@@ -794,7 +800,7 @@ void BandmapWidget::resizeEvent(QResizeEvent *event)
794
800
795
801
QWidget::resizeEvent (event);
796
802
797
- centerRXFreqPosition ( );
803
+ scrollToFreq (rx_freq );
798
804
}
799
805
800
806
bool BandmapWidget::eventFilter (QObject *, QEvent *event)
@@ -846,27 +852,25 @@ bool BandmapWidget::eventFilter(QObject *, QEvent *event)
846
852
return false ;
847
853
}
848
854
849
- void BandmapWidget::centerRXFreqPosition ( )
855
+ void BandmapWidget::scrollToFreq ( double freq )
850
856
{
851
857
FCT_IDENTIFICATION;
852
858
853
- qreal freqScenePos = Freq2ScenePos (rx_freq ).y ();
859
+ qreal freqScenePos = Freq2ScenePos (freq ).y ();
854
860
855
861
QPropertyAnimation *anim = new QPropertyAnimation (ui->scrollArea ->verticalScrollBar (), " value" , this );
856
862
anim->setDuration ((bandmapAnimation) ? 300 : 0 );
857
863
anim->setStartValue (ui->scrollArea ->verticalScrollBar ()->value ());
858
864
859
865
if ( keepRXCenter )
860
866
{
861
-
862
867
/* If RX freq should be center then center it */
863
- anim->setEndValue (freqScenePos - (this ->height ()/2 ) + 50 );
864
- // ui->scrollArea->verticalScrollBar()->setValue(freqScenePos - (this->height()/2) + 50);
868
+ anim->setEndValue (freqScenePos - (WIDGET_CENTER));
865
869
}
866
870
else
867
871
{
868
872
/* If RX freq is out-of-scene then keep the RX mark visible - this is not centering !!! */
869
- int sceneSize = this -> height () - 60 ;
873
+ int sceneSize = height () - 60 ;
870
874
int sliderSceneMin = ui->scrollArea ->verticalScrollBar ()->value ();
871
875
int sliderSceneMax = ui->scrollArea ->verticalScrollBar ()->value () + sceneSize;
872
876
@@ -941,13 +945,12 @@ void BandmapWidget::centerRXActionChecked(bool state)
941
945
{
942
946
FCT_IDENTIFICATION;
943
947
944
- QSettings settings;
945
-
946
948
keepRXCenter = state;
949
+ zoomFreq = 0.0 ;
947
950
settings.setValue (" bandmap/centerrx" , keepRXCenter);
948
951
949
- zoomFreq = 0.0 ;
950
- centerRXFreqPosition ( );
952
+ if ( keepRXCenter )
953
+ scrollToFreq (rx_freq );
951
954
}
952
955
953
956
void GraphicsScene::mousePressEvent (QGraphicsSceneMouseEvent *evt)
0 commit comments