-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathqsopanel.cpp
More file actions
1316 lines (1091 loc) · 49.3 KB
/
qsopanel.cpp
File metadata and controls
1316 lines (1091 loc) · 49.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "qsopanel.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QApplication>
#include <QCursor>
#include <QDebug>
#include <QTimer>
#include <QCompleter>
#include <QDate>
#include <QTime>
#include <QSpacerItem>
#include <QScreen>
QSOPanel::QSOPanel(QMainWindow *mainWindow, Settings *settings, QWidget *parent)
: QWidget(parent),
m_mainWindow(mainWindow),
m_docked(true),
m_dragging(false),
m_dockPos(Top),
m_resizing(false),
m_resizeTop(false), m_resizeBottom(false),
m_resizeLeft(false), m_resizeRight(false),
m_rubberBand(nullptr)
{
setMouseTracking(true);
ui.setupUi(this);
this->settings = settings;
// Чтобы при запуске не раздувалось
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
setMinimumSize(400, 250); // минимальный размер по умолчанию
resize(500, 250); // стартовый размер
ui.groupBox1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
ui.groupBox2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
// GroupBox 1
QVBoxLayout *boxLayout1 = new QVBoxLayout;
boxLayout1->setContentsMargins(0, 0, 0, 0);
boxLayout1->setSpacing(5);
//boxLayout1->addStretch();
// FlowLayout1
QWidget *flowContainer1 = new QWidget;
flowLayout1 = new FlowLayout(flowContainer1, 2, 6, 6);
flowContainer1->setLayout(flowLayout1); // Только один setLayout
flowContainer1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
// FlowLayout2
QWidget *flowContainer2 = new QWidget;
flowLayout2 = new FlowLayout(flowContainer2, 2, 6, 6);
flowContainer2->setLayout(flowLayout2);
flowContainer2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
boxLayout1->addWidget(flowContainer1);
boxLayout1->addWidget(flowContainer2);
ui.groupBox1->setLayout(boxLayout1);
ui.groupBox1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
// Заполнение GroupBox1
stationCallsign = new QComboBox;
<<<<<<< Updated upstream
flowLayout1->addWidget(makeInputPair("Позывной станции:", stationCallsign));
operatorCallsign = new QComboBox;
flowLayout1->addWidget(makeInputPair("Позывной оператора:", operatorCallsign));
=======
stationCallsign->setMinimumWidth(30);
flowLayout1->addWidget(makeInputPair(tr("Позывной станции:"), stationCallsign));
operatorCallsign = new QComboBox;
operatorCallsign->setMinimumWidth(30);
flowLayout1->addWidget(makeInputPair(tr("Позывной оператора:"), operatorCallsign));
>>>>>>> Stashed changes
DateEdit = new QDateEdit;
DateEdit->setCalendarPopup(true);
flowLayout1->addWidget(makeInputPair("Дата:", DateEdit));
TimeEdit = new QTimeEdit;
TimeEdit->setDisplayFormat("HH:mm:ss");
ShowCurrentTime = new QCheckBox("Реальное время");
flowLayout1->addWidget(makeLabelWidgetPair("Время UTC:", TimeEdit, ShowCurrentTime));
BandCombo = new QComboBox;
flowLayout2->addWidget(makeInputPair("Диапазон:", BandCombo));
ModeCombo = new QComboBox;
ModeCombo->setMinimumWidth(100);
flowLayout2->addWidget(makeInputPair("Модуляция:", ModeCombo));
FreqInput = new QLineEdit;
flowLayout2->addWidget(makeInputPair("Частота, МГц:", FreqInput));
QTHLocEdit = new QLineEdit;
flowLayout2->addWidget(makeInputPair("QTH локатор:", QTHLocEdit));
RDAEdit = new QLineEdit;
flowLayout2->addWidget(makeInputPair("RDA/CNTY:", RDAEdit));
// GroupBox 2
QVBoxLayout *boxLayout2 = new QVBoxLayout;
boxLayout2->setContentsMargins(0, 2, 0, 2);
boxLayout2->setSpacing(2);
//boxLayout2->addStretch();
// FlowLayout3
QWidget *flowContainer3 = new QWidget;
flowLayout3 = new FlowLayout(flowContainer3, 2, 6, 6);
flowContainer3->setLayout(flowLayout3);
flowContainer3->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
// FlowLayout4
QWidget *flowContainer4 = new QWidget;
flowLayout4 = new FlowLayout(flowContainer4, 2, 6, 6);
flowContainer4->setLayout(flowLayout4);
flowContainer4->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
// FlowLayout5
QWidget *flowContainer5 = new QWidget;
flowLayout5 = new FlowLayout(flowContainer5, 2, 6, 6);
flowContainer5->setLayout(flowLayout5);
flowContainer5->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
boxLayout2->addWidget(flowContainer3);
boxLayout2->addWidget(flowContainer4);
boxLayout2->addWidget(flowContainer5);
ui.groupBox2->setLayout(boxLayout2);
ui.groupBox2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
// Заполнение GroupBox2
CallInput = new QLineEdit;
CallInput->setFixedHeight(30);
QFont font = CallInput->font();
font.setPointSize(14); // размер шрифта
CallInput->setFont(font);
flowLayout3->addWidget(makeInputPair("Позывной:", CallInput));
NameInput = new QLineEdit;
flowLayout3->addWidget(makeInputPair("Имя:", NameInput));
QTHInput = new QLineEdit;
flowLayout3->addWidget(makeInputPair("QTH:", QTHInput));
GridSquareInput = new QLineEdit;
flowLayout3->addWidget(makeInputPair("Локатор:", GridSquareInput));
CNTYInput = new QLineEdit;
flowLayout3->addWidget(makeInputPair("RDA/CNTY:", CNTYInput));
RstsInput = new QLineEdit;
flowLayout4->addWidget(makeInputPair("RST отпр.:", RstsInput));
RstrInput = new QLineEdit;
flowLayout4->addWidget(makeInputPair("RST прин.:", RstrInput));
CommentInput = new QLineEdit;
flowLayout4->addWidget(makeInputPair("Комментарий:", CommentInput));
QSOSUserIcon = new QLabel;
QSOSUserIcon->setVisible(false);
QSOSUserLabel = new QLabel("Не пользователь QSO.SU");
QSOSUserLabel->setVisible(false);
flowLayout5->addWidget(makeWidgetPair(QSOSUserIcon, QSOSUserLabel));
UserSRRIcon = new QLabel;
UserSRRIcon->setVisible(false);
UserSRRLabel = new QLabel("Член СРР");
UserSRRLabel->setVisible(false);
flowLayout5->addWidget(makeWidgetPair(UserSRRIcon, UserSRRLabel));
connect(ui.closeBtn, &QPushButton::clicked, this, &QSOPanel::toggleDock);
connect(CallInput, SIGNAL(textEdited(const QString&)), this, SLOT(CallsignToUppercase(const QString&)));
connect(stationCallsign, SIGNAL(currentIndexChanged(int)), this, SLOT(on_StationCallsignCurrentIndexChanged(int)));
connect(operatorCallsign, SIGNAL(currentIndexChanged(int)), this, SLOT(on_OperatorCallsignCurrentIndexChanged(int)));
connect(BandCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(on_BandComboCurrentIndexChanged(int)));
connect(BandCombo, SIGNAL(currentTextChanged(const QString&)), this, SLOT(on_BandComboCurrentTextChanged(const QString&)));
connect(ModeCombo, SIGNAL(currentTextChanged(const QString&)), this, SLOT(on_ModeComboCurrentTextChanged(const QString&)));
connect(FreqInput, SIGNAL(textChanged(const QString&)), this, SLOT(on_FreqInputTextChanged(const QString&)));
connect(FreqInput, SIGNAL(editingFinished()), this, SLOT(on_FreqInputEditingFinished()));
connect(GridSquareInput, SIGNAL(textChanged(const QString&)), this, SLOT(on_GridSquareInputTextChanged(const QString&)));
connect(CNTYInput, SIGNAL(textChanged(const QString&)), this, SLOT(on_CNTYInputTextChanged(const QString&)));
connect(RstrInput, SIGNAL(editingFinished()), this, SLOT(on_RstrInputEditingFinished()));
connect(RstsInput, SIGNAL(editingFinished()), this, SLOT(on_RstsInputEditingFinished()));
ui.titleBar->installEventFilter(this);
installEventFilter(this);
//Настройка элементов интерфейса
CallInput->setStyleSheet("font-weight: bold");
CallInput->setValidator(new QRegularExpressionValidator(QRegularExpression("^[a-zA-Z0-9/]*$"), this));
RstrInput->setValidator(new QRegularExpressionValidator(QRegularExpression("^[+-]?[0-9]*$"), this));
RstsInput->setValidator(new QRegularExpressionValidator(QRegularExpression("^[+-]?[0-9]*$"), this));
GridSquareInput->setValidator(new QRegularExpressionValidator(QRegularExpression("^([a-zA-Z]{2})([0-9]{2})(((([a-zA-Z]{2}?)?)([0-9]{2}?)?)([a-zA-Z]{2}?)?)$/"), this));
ModeCombo->setEditable(true); // Включаем встроенный QLineEdit
ModeCombo->setInsertPolicy(QComboBox::NoInsert); // Отключаем вставку новых элементов из QLineEdit
ModeCombo->completer()->setCompletionMode(QCompleter::CompletionMode::PopupCompletion); // устанавливаем модель автодополнения (по умолчанию стоит InlineCompletition)
ModeCombo->completer()->setModelSorting(QCompleter::UnsortedModel);
EverySecondTimer = new QTimer(this);
EverySecondTimer->setInterval(1000);
connect(EverySecondTimer, SIGNAL(timeout()), this, SLOT(UpdateFormDateTime()));
ShowCurrentTime->setChecked(true);
UpdateFormDateTime();
EverySecondTimer->start();
connect(ShowCurrentTime, &QCheckBox::toggled, this, [=](bool checked) {
if (checked) {
UpdateFormDateTime();
EverySecondTimer->start();
} else {
EverySecondTimer->stop();
}
});
CallTypeTimer = new QTimer(this);
CallTypeTimer->setSingleShot(true);
CallTypeTimer->setInterval(1000);
connect(CallTypeTimer, &QTimer::timeout, this, [=]() {
emit findCallTimer();
});
BandCombo->setCurrentText(settings->lastBand);
if(settings->lastMode == "") ModeCombo->setCurrentText("CW");
else ModeCombo->setCurrentText(settings->lastMode);
QTHLocEdit->setText(settings->lastLocator);
RDAEdit->setText(settings->lastRDA);
FreqInput->setText(settings->lastFrequence);
RstrInput->setText(settings->lastRST_RCVD);
RstsInput->setText(settings->lastRST_SENT);
stationCallsign->setCurrentIndex(settings->lastCallsign);
operatorCallsign->setCurrentIndex(settings->lastOperator);
QVBoxLayout *layout = qobject_cast<QVBoxLayout*>(m_mainWindow->centralWidget()->layout());
if (!layout) {
layout = new QVBoxLayout(m_mainWindow->centralWidget());
layout->setContentsMargins(0,0,0,0);
layout->setSpacing(0);
}
layout->insertWidget(0, this);
// фиксируем высоту при доке
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setFixedHeight(250);
// чтобы groupbox не раздувались
for (auto *box : findChildren<QGroupBox*>()) {
box->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
}
updateGeometry();
parentWidget()->updateGeometry();
QTimer::singleShot(0, this, [this]{
dock();
});
}
//------------------------------------------------------------------------------------------------------------------------------------------
bool QSOPanel::eventFilter(QObject *obj, QEvent *event)
{
if (obj == ui.titleBar) {
if (event->type() == QEvent::MouseButtonPress) {
auto *e = static_cast<QMouseEvent*>(event);
if (e->button() == Qt::LeftButton) {
m_dragging = true;
m_dragPosition = e->globalPos() - frameGeometry().topLeft();
}
}
else if (event->type() == QEvent::MouseMove) {
auto *e = static_cast<QMouseEvent*>(event);
if (m_dragging) {
if (m_docked && (e->globalPos() - m_dragPosition).manhattanLength() > 10) {
detach();
m_dragPosition = e->globalPos() - frameGeometry().topLeft();
}
if (!m_docked) {
move(e->globalPos() - m_dragPosition);
// показываем индикатор
showDockIndicator(detectDock());
}
}
}
else if (event->type() == QEvent::MouseButtonRelease) {
if (m_dragging) {
m_dragging = false;
hideDockIndicator();
if (!m_docked) tryDock();
}
}
}
return QWidget::eventFilter(obj, event);
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::resizeEvent(QResizeEvent *event)
{
int w = event->size().width();
//int spacing = qMax(5, w / 50);
int spacing = qBound(4, w / 80, 10);
if (flowLayout1) flowLayout1->setSpacing(spacing);
if (flowLayout2) flowLayout2->setSpacing(spacing);
if (flowLayout3) flowLayout3->setSpacing(spacing);
if (flowLayout4) flowLayout4->setSpacing(spacing);
if (flowLayout5) flowLayout5->setSpacing(spacing);
QWidget::resizeEvent(event);
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::toggleDock()
{
if(m_docked) detach();
else forceDock();
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::setDocked(bool docked)
{
m_docked = docked;
if (flowLayout1) flowLayout1->setWrap(!docked);
if (flowLayout2) flowLayout2->setWrap(!docked);
if (flowLayout3) flowLayout3->setWrap(!docked);
if (flowLayout4) flowLayout4->setWrap(!docked);
if (flowLayout5) flowLayout5->setWrap(!docked);
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::mousePressEvent(QMouseEvent *event)
{
if (!m_docked && windowFlags().testFlag(Qt::FramelessWindowHint) && event->button() == Qt::LeftButton) {
QRect r = rect();
const int margin = 5;
m_resizeTop = (event->pos().y() < margin);
m_resizeBottom = (event->pos().y() > r.height() - margin);
m_resizeLeft = (event->pos().x() < margin);
m_resizeRight = (event->pos().x() > r.width() - margin);
if (m_resizeTop || m_resizeBottom || m_resizeLeft || m_resizeRight) {
m_resizing = true;
m_dragPosition = event->globalPos();
event->accept();
return;
}
}
left_btn_pressed = true;
QWidget::mousePressEvent(event);
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::mouseMoveEvent(QMouseEvent *event)
{
if (!m_docked) {
// Обновляем курсор и resize
QRect r = rect();
const int margin = 5;
if (m_resizing) {
QPoint delta = event->globalPos() - m_dragPosition;
QRect newGeom = geometry();
if (m_resizeLeft) newGeom.setLeft(newGeom.left() + delta.x());
if (m_resizeRight) newGeom.setRight(newGeom.right() + delta.x());
if (m_resizeTop) newGeom.setTop(newGeom.top() + delta.y());
if (m_resizeBottom) newGeom.setBottom(newGeom.bottom() + delta.y());
setGeometry(newGeom);
m_dragPosition = event->globalPos();
return;
}
// курсор
bool left = event->pos().x() < margin;
bool right = event->pos().x() > r.width() - margin;
bool top = event->pos().y() < margin;
bool bottom = event->pos().y() > r.height() - margin;
if (top && left) setCursor(Qt::SizeFDiagCursor);
else if (top && right) setCursor(Qt::SizeBDiagCursor);
else if (bottom && left) setCursor(Qt::SizeBDiagCursor);
else if (bottom && right) setCursor(Qt::SizeFDiagCursor);
else if (top || bottom) setCursor(Qt::SizeVerCursor);
else if (left || right) setCursor(Qt::SizeHorCursor);
else setCursor(Qt::ArrowCursor);
// Проверяем док-позицию
DockPosition pos = detectDock();
if (pos != None && left_btn_pressed)
showDockIndicator(pos);
else
hideDockIndicator();
}
QWidget::mouseMoveEvent(event);
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::mouseReleaseEvent(QMouseEvent *event)
{
if (!m_docked && event->button() == Qt::LeftButton) {
m_resizing = false;
m_resizeTop = m_resizeBottom = m_resizeLeft = m_resizeRight = false;
}
left_btn_pressed = false;
hideDockIndicator();
QWidget::mouseReleaseEvent(event);
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::dock()
{
if (!m_mainWindow->isVisible() || m_mainWindow->isMinimized()) return;
setParent(m_mainWindow->centralWidget());
setWindowFlags(Qt::Widget);
ui.closeBtn->setText("][");
show();
QVBoxLayout *layout = qobject_cast<QVBoxLayout*>(m_mainWindow->centralWidget()->layout());
if (!layout) {
layout = new QVBoxLayout(m_mainWindow->centralWidget());
layout->setContentsMargins(0,0,0,0);
layout->setSpacing(0);
}
layout->insertWidget(0, this);
// фиксируем высоту при доке
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setFixedHeight(300);
setDocked(true);
m_docked = true;
// чтобы groupbox не раздувались
for (auto *box : findChildren<QGroupBox*>()) {
box->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
}
updateGeometry();
parentWidget()->updateGeometry();
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::forceDock()
{
setParent(m_mainWindow->centralWidget());
setWindowFlags(Qt::Widget);
ui.closeBtn->setText("][");
show();
QVBoxLayout *layout = qobject_cast<QVBoxLayout*>(m_mainWindow->centralWidget()->layout());
if (!layout) {
layout = new QVBoxLayout(m_mainWindow->centralWidget());
layout->setContentsMargins(0,0,0,0);
layout->setSpacing(0);
}
layout->insertWidget(0, this);
// фиксируем высоту при доке
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setFixedHeight(300);
setDocked(true);
m_docked = true;
// чтобы groupbox не раздувались
for (auto *box : findChildren<QGroupBox*>()) {
box->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
}
updateGeometry();
parentWidget()->updateGeometry();
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::detach()
{
if (!m_docked) return;
setParent(nullptr);
setWindowFlags(Qt::Window |
Qt::WindowTitleHint |
Qt::WindowSystemMenuHint |
//Qt::WindowMinMaxButtonsHint |
Qt::WindowCloseButtonHint);
setAttribute(Qt::WA_DeleteOnClose, false);
ui.closeBtn->setText("[ ]");
// снимаем фиксацию по высоте
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
setMinimumHeight(0);
setMaximumHeight(QWIDGETSIZE_MAX);
resize(285, 630); // стартовый размер панели
// позиционирование относительно курсора
QPoint desiredPos = QCursor::pos() - QPoint(width()/2, 50); // 50px сверху от курсора
// границы экрана
QRect screenRect = QApplication::primaryScreen()->availableGeometry();
// корректируем, чтобы панель не выходила за экран
if (desiredPos.x() < screenRect.left()) desiredPos.setX(screenRect.left());
if (desiredPos.y() < screenRect.top()) desiredPos.setY(screenRect.top());
if (desiredPos.x() + width() > screenRect.right()) desiredPos.setX(screenRect.right() - width());
if (desiredPos.y() + height() > screenRect.bottom()) desiredPos.setY(screenRect.bottom() - height());
move(desiredPos);
show();
m_docked = false;
setDocked(false); // отключаем wrap
}
//------------------------------------------------------------------------------------------------------------------------------------------
DockPosition QSOPanel::detectDock()
{
if (!m_mainWindow) return None;
// Получаем глобальные координаты главного окна
QRect mainRect = m_mainWindow->geometry();
// Получаем глобальные координаты панели
QPoint panelTopLeft = mapToGlobal(QPoint(0,0));
QRect panelRect(panelTopLeft, size());
const int snap = 40; // расстояние для "притягивания"
// Проверяем только верхнюю док-позицию
bool nearTop = abs(panelRect.top() - mainRect.top()) < snap;
bool horizontallyAligned = panelRect.right() > mainRect.left() + 20 &&
panelRect.left() < mainRect.right() - 20;
if (nearTop && horizontallyAligned) return Top;
return None;
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::tryDock()
{
if (!m_mainWindow->isVisible() || m_mainWindow->isMinimized())
return; // запрещаем докирование если окно свернуто
if(detectDock() == Top) dock();
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::showDockIndicator(DockPosition pos)
{
if (pos == None) {
hideDockIndicator();
return;
}
if (!m_rubberBand)
m_rubberBand = new QRubberBand(QRubberBand::Rectangle, m_mainWindow);
QRect rect;
if (pos == Top) {
// Берём область центрального виджета
QWidget *cw = m_mainWindow->centralWidget();
if (cw) {
QRect cwRect = cw->rect();
// Преобразуем в координаты главного окна
QPoint topLeft = cw->mapTo(m_mainWindow, cwRect.topLeft());
rect = QRect(topLeft, QSize(cwRect.width(), height()));
} else {
// fallback: вся ширина окна
rect = QRect(0, 0, m_mainWindow->width(), height());
}
}
m_rubberBand->setGeometry(rect);
m_rubberBand->show();
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::hideDockIndicator()
{
if(m_rubberBand) m_rubberBand->hide();
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::closeEvent(QCloseEvent *event)
{
forceDock();
event->ignore();
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
if (m_docked) {
for (auto *box : findChildren<QGroupBox*>()) {
box->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
}
updateGeometry();
if (parentWidget()) parentWidget()->updateGeometry();
}
}
//------------------------------------------------------------------------------------------------------------------------------------------
// Создание пары QLabel + input
QWidget* QSOPanel::makeInputPair(const QString &labelText, QWidget *inputWidget)
{
QWidget *pair = new QWidget;
QHBoxLayout *layout = new QHBoxLayout(pair);
layout->setContentsMargins(0,0,0,0);
layout->setSpacing(5); // фиксированное расстояние между QLabel и input
QLabel *label = new QLabel(labelText);
layout->addWidget(label, 0); // QLabel не растягивается
layout->addWidget(inputWidget, 1); // input растягивается горизонтально
layout->addStretch(0); // свободное место после input
pair->setContentsMargins(0,2,0,2); // уменьшенные отступы внутри пары
return pair;
}
//------------------------------------------------------------------------------------------------------------------------------------------
// Создание пары Widget1 + Widget2
QWidget* QSOPanel::makeWidgetPair(QWidget *Widget1, QWidget *Widget2)
{
QWidget *pair = new QWidget;
QHBoxLayout *layout = new QHBoxLayout(pair);
layout->setContentsMargins(0,0,0,0);
layout->setSpacing(5); // фиксированное расстояние между Widget1 и Widget2
layout->addWidget(Widget1, 0); // Widget1 не растягивается
layout->addWidget(Widget2, 1); // Widget2 растягивается горизонтально
layout->addStretch(0); // свободное место после input
pair->setContentsMargins(0,0,0,0); // уменьшенные отступы внутри пары
return pair;
}
//------------------------------------------------------------------------------------------------------------------------------------------
// Создание пары QString + Widget1 + Widget2
QWidget* QSOPanel::makeLabelWidgetPair(const QString &labelText, QWidget *Widget1, QWidget *Widget2)
{
QWidget *pair = new QWidget;
QHBoxLayout *layout = new QHBoxLayout(pair);
layout->setContentsMargins(0,0,0,0);
layout->setSpacing(5); // фиксированное расстояние между Widget1 и Widget2
QLabel *label = new QLabel(labelText);
layout->addWidget(label, 0); // QLabel не растягивается
layout->addWidget(Widget1, 1); // Widget1 не растягивается
layout->addWidget(Widget2, 0); // Widget2 растягивается горизонтально
layout->addStretch(0); // свободное место после input
pair->setContentsMargins(0,0,0,0); // уменьшенные отступы внутри пары
return pair;
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::UpdateFormDateTime()
{
QDateTime DateTimeNow = QDateTime::currentDateTimeUtc().toUTC();
DateEdit->setDate(DateTimeNow.date());
TimeEdit->setTime(DateTimeNow.time());
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::on_SaveQsoButton_clicked()
{
emit saveQSO();
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::on_RefreshButton_clicked()
{
emit updateDB();
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::on_ClearQsoButton_clicked()
{
clearQSO();
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::minimizePanel()
{
if (m_docked) {
this->setVisible(false); // спрятать панель
} else {
this->showMinimized(); // если откреплено — сворачиваем окно
}
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::CallsignToUppercase(const QString &arg)
{
int cursorPos = CallInput->cursorPosition();
QString callsign = arg.toUpper();
CallInput->setText(callsign);
CallInput->setStyleSheet("font-weight: bold");
CallInput->setCursorPosition(cursorPos);
CallTypeTimer->start();
}
//------------------------------------------------------------------------------------------------------------------------------------------
QString QSOPanel::getCallsign()
{
if (!CallInput) return QString();
return CallInput->text().trimmed().toUpper();
}
//------------------------------------------------------------------------------------------------------------------------------------------
QString QSOPanel::getFrequence()
{
return FreqInput->text();
}
//------------------------------------------------------------------------------------------------------------------------------------------
QString QSOPanel::getBand()
{
return BandCombo->currentText();
}
//------------------------------------------------------------------------------------------------------------------------------------------
QString QSOPanel::getMode()
{
if (!ModeCombo) return QString();
return ModeCombo->currentText().trimmed().toUpper();
}
//------------------------------------------------------------------------------------------------------------------------------------------
QString QSOPanel::getRSTR()
{
if (!RstrInput) return QString();
return RstrInput->text();
}
//------------------------------------------------------------------------------------------------------------------------------------------
QString QSOPanel::getRSTS()
{
if (!RstsInput) return QString();
return RstsInput->text();
}
//------------------------------------------------------------------------------------------------------------------------------------------
QString QSOPanel::getName()
{
if (!NameInput) return QString();
return NameInput->text().trimmed();
}
//------------------------------------------------------------------------------------------------------------------------------------------
QString QSOPanel::getQTH()
{
if (!QTHInput) return QString();
return QTHInput->text().trimmed();
}
//------------------------------------------------------------------------------------------------------------------------------------------
QString QSOPanel::getQTHLocator()
{
if (!GridSquareInput) return QString();
return GridSquareInput->text().trimmed().toUpper();
}
//------------------------------------------------------------------------------------------------------------------------------------------
QString QSOPanel::getRDA()
{
if (!CNTYInput) return QString();
return CNTYInput->text().trimmed().toUpper();
}
//------------------------------------------------------------------------------------------------------------------------------------------
QString QSOPanel::getComment()
{
if (!CommentInput) return QString();
return CommentInput->text();
}
//------------------------------------------------------------------------------------------------------------------------------------------
bool QSOPanel::setFrequence(long freq)
{
if (!FreqInput) return false;
if(freq > 0 && freq < 250000000) {
FreqInput->setText(QString::number(freq, 'f', 6));
return true;
}
return false;
}
//------------------------------------------------------------------------------------------------------------------------------------------
void QSOPanel::setFrequenceText(const QString &freq)
{
FreqInput->setText(freq);
}
//------------------------------------------------------------------------------------------------------------------------------------------
bool QSOPanel::setBand(const QString &band)
{
QString b = band.trimmed();
if (b.isEmpty()) return false;
if (!BandCombo) return false;
// Пытаемся найти индекс нужного бэнда в комбобоксе
int idx = BandCombo->findText(b, Qt::MatchFixedString | Qt::MatchCaseSensitive);
if (idx == -1) return false;
BandCombo->setCurrentIndex(idx);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------------------
bool QSOPanel::setMode(const QString &mode)
{
QString m = mode.trimmed();
if (m.isEmpty()) return false;
if (!ModeCombo) return false;
int idx = ModeCombo->findText(m, Qt::MatchFixedString | Qt::MatchCaseSensitive);
if (idx == -1) return false;
ModeCombo->setCurrentIndex(idx);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------------------
bool QSOPanel::setCallsign(const QString &call)
{
QString c = call.trimmed();
if (c.isEmpty()) return false;
if (!CallInput) return false;
CallInput->setText(c);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------------------
bool QSOPanel::setName(const QString &name)
{
QString n = name.trimmed();
if (n.isEmpty()) return false;
if (!NameInput) return false;
NameInput->setText(n);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------------------
bool QSOPanel::setQTH(const QString &qth)
{
QString q = qth.trimmed();
if (q.isEmpty()) return false;
if (!QTHInput) return false;
QTHInput->setText(q);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------------------
bool QSOPanel::setRSTR(const QString &rstr)
{
QString r = rstr.trimmed();
if (r.isEmpty()) return false;
if (!RstrInput) return false;
RstrInput->setText(r);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------------------
bool QSOPanel::setRSTS(const QString &rsts)
{
QString r = rsts.trimmed();
if (r.isEmpty()) return false;
if (!RstsInput) return false;
RstsInput->setText(r);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------------------
bool QSOPanel::setQTHLocator(const QString &loc)
{
QString l = loc.trimmed();
if (l.isEmpty()) return false;
if (!GridSquareInput) return false;
GridSquareInput->setText(l);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------------------
bool QSOPanel::setRDA(const QString &rda)
{
QString r = rda.trimmed();
if (r.isEmpty()) return false;
if (!CNTYInput) return false;
CNTYInput->setText(r);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------------------
bool QSOPanel::setStationQTHLocator(const QString &loc)
{
QString l = loc.trimmed();
if (l.isEmpty()) return false;
if (!QTHLocEdit) return false;
QTHLocEdit->setText(l);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------------------
bool QSOPanel::setStationRDA(const QString &rda)
{
QString r = rda.trimmed();
if (r.isEmpty()) return false;
if (!RDAEdit) return false;
RDAEdit->setText(r);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------------------
bool QSOPanel::setComment(const QString &comment)
{
QString c = comment.trimmed();
if (c.isEmpty()) return false;
if (!CommentInput) return false;
CommentInput->setText(c);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------------------
QString QSOPanel::getStationCallsign()
{
if (!stationCallsign) return QString();
return stationCallsign->currentText().trimmed().toUpper();
}
//------------------------------------------------------------------------------------------------------------------------------------------
QString QSOPanel::getStationOperator()
{
if (!operatorCallsign) return QString();
return operatorCallsign->currentText().trimmed().toUpper();
}
//------------------------------------------------------------------------------------------------------------------------------------------
QString QSOPanel::getStationQTHLocator()
{
if (!QTHLocEdit) return QString();
return QTHLocEdit->text().trimmed().toUpper();
}
//------------------------------------------------------------------------------------------------------------------------------------------
QString QSOPanel::getStationRDA()
{
if (!RDAEdit) return QString();
return RDAEdit->text().trimmed().toUpper();;
}
//------------------------------------------------------------------------------------------------------------------------------------------
QDate QSOPanel::getDate()
{
if (!DateEdit) return QDate(); // вернёт пустую дату, если поле отсутствует
return DateEdit->date();
}
//------------------------------------------------------------------------------------------------------------------------------------------
QTime QSOPanel::getTime()
{
if (!TimeEdit) return QTime(); // вернёт пустое время, если поле отсутствует
return TimeEdit->time();
}
//------------------------------------------------------------------------------------------------------------------------------------------
bool QSOPanel::setDate(const QDate &date)
{
if (!date.isValid()) return false;
DateEdit->setDate(date);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------------------
bool QSOPanel::setTime(const QTime &time)
{
if (!time.isValid()) return false;
TimeEdit->setTime(time);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------------------