forked from Mudlet/Mudlet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTConsole.cpp
2376 lines (2122 loc) · 91.6 KB
/
TConsole.cpp
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
/***************************************************************************
* Copyright (C) 2008-2013 by Heiko Koehn - KoehnHeiko@googlemail.com *
* Copyright (C) 2014-2024 by Stephen Lyons - slysven@virginmedia.com *
* Copyright (C) 2014 by Ahmed Charles - acharles@outlook.com *
* Copyright (C) 2016 by Ian Adkins - ieadkins@gmail.com *
* Copyright (C) 2021 by Vadim Peretokin - vperetokin@gmail.com *
* Copyright (C) 2022 by Thiago Jung Bauermann - bauermann@kolabnow.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "TConsole.h"
#include "Host.h"
#include "TCommandLine.h"
#include "TDebug.h"
#include "TDockWidget.h"
#include "TEvent.h"
#include "TLabel.h"
#include "TMainConsole.h"
#include "TMap.h"
#include "TRoomDB.h"
#include "TSplitter.h"
#include "TTextEdit.h"
#include "dlgMapper.h"
#include "mudlet.h"
#include "pre_guard.h"
#include <QAccessibleInterface>
#include <QAccessibleWidget>
#include <QLineEdit>
#include <QMessageBox>
#include <QMimeData>
#include <QScrollBar>
#include <QShortcut>
#include <QTextBoundaryFinder>
#include <QTextCodec>
#include <QPainter>
#include "post_guard.h"
const QString TConsole::cmLuaLineVariable("line");
// A high-performance text widget with split screen ability for scrolling back
// Contains two TTextEdits, and is backed by a TBuffer
TConsole::TConsole(Host* pH, const QString& name, const ConsoleType type, QWidget* parent)
: QWidget(parent)
, mpHost(pH)
, buffer(pH, this)
, emergencyStop(new QToolButton)
, mConsoleName(name)
, mpBaseVFrame(new QWidget(this))
, mpTopToolBar(new QWidget(mpBaseVFrame))
, mpBaseHFrame(new QWidget(mpBaseVFrame))
, mpLeftToolBar(new QWidget(mpBaseHFrame))
, mpMainFrame(new QWidget(mpBaseHFrame))
, mpRightToolBar(new QWidget(mpBaseHFrame))
, mpMainDisplay(new QWidget(mpMainFrame))
, mpScrollBar(new QScrollBar)
, mpHScrollBar(new QScrollBar(Qt::Horizontal))
, mProfileName(mpHost ? mpHost->getName() : qsl("debug console"))
, mpBufferSearchBox(new QLineEdit)
, mpBufferSearchUp(new QToolButton)
, mpBufferSearchDown(new QToolButton)
, mControlCharacter(pH->getControlCharacterMode())
, mType(type)
{
auto quitShortcut = new QShortcut(this);
quitShortcut->setKey(Qt::CTRL | Qt::Key_W);
quitShortcut->setContext(Qt::WidgetShortcut);
if (mType == CentralDebugConsole) {
// Probably will not show up as this is used inside a QMainWindow widget
// which has its own title and icon set.
setWindowTitle(tr("Debug Console"));
mWrapAt = 50;
} else if (mType == MainConsole) {
mBorders = mpHost->borders();
mCommandBgColor = mpHost->mCommandBgColor;
mCommandFgColor = mpHost->mCommandFgColor;
}
setContentsMargins(0, 0, 0, 0);
setAttribute(Qt::WA_DeleteOnClose);
setAttribute(Qt::WA_OpaquePaintEvent); //was disabled
const QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
const QSizePolicy sizePolicy3(QSizePolicy::Expanding, QSizePolicy::Expanding);
const QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Fixed);
const QSizePolicy sizePolicy4(QSizePolicy::Fixed, QSizePolicy::Expanding);
const QSizePolicy sizePolicy5(QSizePolicy::Fixed, QSizePolicy::Fixed);
mpMainFrame->setContentsMargins(0, 0, 0, 0);
QPalette framePalette;
framePalette.setColor(QPalette::Text, QColor(Qt::black));
framePalette.setColor(QPalette::Highlight, QColor(55, 55, 255));
framePalette.setColor(QPalette::Window, QColor(0, 0, 0, 255));
mpMainFrame->setPalette(framePalette);
mpMainFrame->setAutoFillBackground(true);
mpMainFrame->setObjectName(qsl("MainFrame"));
auto centralLayout = new QVBoxLayout;
setLayout(centralLayout);
auto baseVFrameLayout = new QVBoxLayout;
mpBaseVFrame->setLayout(baseVFrameLayout);
baseVFrameLayout->setContentsMargins(0, 0, 0, 0);
baseVFrameLayout->setSpacing(0);
centralLayout->addWidget(mpBaseVFrame);
auto baseHFrameLayout = new QHBoxLayout;
mpBaseHFrame->setLayout(baseHFrameLayout);
baseHFrameLayout->setContentsMargins(0, 0, 0, 0);
baseHFrameLayout->setSpacing(0);
layout()->setSpacing(0);
layout()->setContentsMargins(0, 0, 0, 0);
setContentsMargins(0, 0, 0, 0);
auto topBarLayout = new QHBoxLayout;
mpTopToolBar->setLayout(topBarLayout);
mpTopToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
mpTopToolBar->setContentsMargins(0, 0, 0, 0);
mpTopToolBar->setAutoFillBackground(true);
topBarLayout->setContentsMargins(0, 0, 0, 0);
topBarLayout->setSpacing(0);
auto leftBarLayout = new QVBoxLayout;
mpLeftToolBar->setLayout(leftBarLayout);
mpLeftToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding));
mpLeftToolBar->setAutoFillBackground(true);
leftBarLayout->setContentsMargins(0, 0, 0, 0);
leftBarLayout->setSpacing(0);
mpLeftToolBar->setContentsMargins(0, 0, 0, 0);
auto rightBarLayout = new QVBoxLayout;
mpRightToolBar->setLayout(rightBarLayout);
mpRightToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding));
mpRightToolBar->setAutoFillBackground(true);
rightBarLayout->setContentsMargins(0, 0, 0, 0);
rightBarLayout->setSpacing(0);
mpRightToolBar->setContentsMargins(0, 0, 0, 0);
mpBaseVFrame->setContentsMargins(0, 0, 0, 0);
baseVFrameLayout->setSpacing(0);
baseVFrameLayout->setContentsMargins(0, 0, 0, 0);
mpTopToolBar->setContentsMargins(0, 0, 0, 0);
baseVFrameLayout->addWidget(mpTopToolBar);
baseVFrameLayout->addWidget(mpBaseHFrame);
baseHFrameLayout->addWidget(mpLeftToolBar);
auto mpCorePane = new QWidget(mpBaseHFrame);
auto coreSpreadLayout = new QVBoxLayout;
mpCorePane->setLayout(coreSpreadLayout);
mpCorePane->setContentsMargins(0, 0, 0, 0);
coreSpreadLayout->setContentsMargins(0, 0, 0, 0);
coreSpreadLayout->setSpacing(0);
coreSpreadLayout->addWidget(mpMainFrame);
mpCorePane->setSizePolicy(sizePolicy);
baseHFrameLayout->addWidget(mpCorePane);
baseHFrameLayout->addWidget(mpRightToolBar);
mpTopToolBar->setContentsMargins(0, 0, 0, 0);
mpBaseHFrame->setAutoFillBackground(true);
baseHFrameLayout->setSpacing(0);
baseHFrameLayout->setContentsMargins(0, 0, 0, 0);
setContentsMargins(0, 0, 0, 0);
mpBaseHFrame->setContentsMargins(0, 0, 0, 0);
centralLayout->setSpacing(0);
centralLayout->setContentsMargins(0, 0, 0, 0);
mpMainDisplay->move(mBorders.left(), mBorders.top());
mpMainFrame->show();
mpMainDisplay->show();
mpMainFrame->setContentsMargins(0, 0, 0, 0);
mpMainDisplay->setContentsMargins(0, 0, 0, 0);
auto layout = new QVBoxLayout;
mpMainDisplay->setObjectName(qsl("MainDisplay"));
mpMainDisplay->setLayout(layout);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
mpBaseVFrame->setSizePolicy(sizePolicy);
mpBaseHFrame->setSizePolicy(sizePolicy);
baseVFrameLayout->setContentsMargins(0, 0, 0, 0);
baseHFrameLayout->setContentsMargins(0, 0, 0, 0);
centralLayout->setContentsMargins(0, 0, 0, 0);
if (mType == MainConsole) {
mpCommandLine = new TCommandLine(pH, qsl("main"), TCommandLine::MainCommandLine, this, mpMainDisplay);
mpCommandLine->setContentsMargins(0, 0, 0, 0);
mpCommandLine->setSizePolicy(sizePolicy);
// Setting the focusProxy cannot be done here because things have not
// been completed enough at this point - it has been defered to a
// zero-timer at the end of this constructor
}
layer = new QWidget(mpMainDisplay);
layer->setObjectName(qsl("layer"));
layer->setStyleSheet("QWidget#layer{background-color: rgba(0,0,0,0)}");
layer->setContentsMargins(0, 0, 0, 0);
layer->setSizePolicy(sizePolicy);
auto vLayoutLayer = new QVBoxLayout;
auto layoutLayer = new QHBoxLayout;
layer->setLayout(vLayoutLayer);
layoutLayer->setContentsMargins(0, 0, 0, 0);
layoutLayer->setSpacing(0);
mpScrollBar->setFixedWidth(15);
mpHScrollBar->setFixedHeight(15);
splitter = new TSplitter(Qt::Vertical, layer);
splitter->setObjectName(qsl("splitter_%1_%2").arg(mProfileName, mConsoleName));
splitter->setContentsMargins(0, 0, 0, 0);
splitter->setSizePolicy(sizePolicy);
splitter->setHandleWidth(3);
//QSplitter covers the background if not set to transparent and a new AppStyleSheet is set for example by DarkTheme
auto styleSheet = qsl("QSplitter { background-color: rgba(0,0,0,0) }");
splitter->setStyleSheet(styleSheet);
mUpperPane = new TTextEdit(this, splitter, &buffer, mpHost, false);
mUpperPane->setObjectName(qsl("upperPane_%1_%2").arg(mProfileName, mConsoleName));
mUpperPane->setContentsMargins(0, 0, 0, 0);
mUpperPane->setSizePolicy(sizePolicy3);
mUpperPane->setAccessibleName(tr("main window"));
mLowerPane = new TTextEdit(this, splitter, &buffer, mpHost, true);
mLowerPane->setObjectName(qsl("lowerPane_%1_%2").arg(mProfileName, mConsoleName));
mLowerPane->setContentsMargins(0, 0, 0, 0);
mLowerPane->setSizePolicy(sizePolicy3);
if (mType == MainConsole) {
setFocusProxy(mpCommandLine);
mUpperPane->setFocusProxy(mpCommandLine);
mLowerPane->setFocusProxy(mpCommandLine);
} else if (mType & (UserWindow|SubConsole)) {
// These will need to be changed when the built in TCommandLine is
// enabled or an additional one is added to them:
setFocusProxy(mpHost->mpConsole->mpCommandLine);
mUpperPane->setFocusProxy(mpHost->mpConsole->mpCommandLine);
mLowerPane->setFocusProxy(mpHost->mpConsole->mpCommandLine);
}
splitter->addWidget(mUpperPane);
splitter->addWidget(mLowerPane);
splitter->setCollapsible(1, false);
splitter->setCollapsible(0, false);
splitter->setStretchFactor(0, 6);
splitter->setStretchFactor(1, 1);
layoutLayer->addWidget(splitter);
layoutLayer->addWidget(mpScrollBar);
layoutLayer->setContentsMargins(0, 0, 0, 0);
layoutLayer->setSpacing(1); // not closer, otherwise there could be performance problems when displaying
vLayoutLayer->addLayout(layoutLayer);
vLayoutLayer->addWidget(mpHScrollBar);
vLayoutLayer->setContentsMargins(0, 0, 0, 0);
vLayoutLayer->setSpacing(0);
layerCommandLine = new QWidget; //( mpMainFrame );//layer );
layerCommandLine->setContentsMargins(0, 0, 0, 0);
layerCommandLine->setSizePolicy(sizePolicy2);
layerCommandLine->setMaximumHeight(31);
layerCommandLine->setMinimumHeight(31);
layoutLayer2 = new QHBoxLayout(layerCommandLine);
layoutLayer2->setContentsMargins(0, 0, 0, 0);
layoutLayer2->setSpacing(0);
mpButtonMainLayer = new QWidget;
mpButtonMainLayer->setObjectName(qsl("mpButtonMainLayer"));
mpButtonMainLayer->setSizePolicy(sizePolicy);
mpButtonMainLayer->setContentsMargins(0, 0, 0, 0);
auto layoutButtonMainLayer = new QVBoxLayout(mpButtonMainLayer);
layoutButtonMainLayer->setObjectName(qsl("layoutButtonMainLayer"));
layoutButtonMainLayer->setContentsMargins(0, 0, 0, 0);
layoutButtonMainLayer->setSpacing(0);
/*mpButtonMainLayer->setMinimumHeight(31);
mpButtonMainLayer->setMaximumHeight(31);*/
auto buttonLayer = new QWidget;
buttonLayer->setObjectName(qsl("buttonLayer"));
auto layoutButtonLayer = new QGridLayout(buttonLayer);
layoutButtonLayer->setObjectName(qsl("layoutButtonLayer"));
layoutButtonLayer->setContentsMargins(0, 0, 0, 0);
layoutButtonLayer->setSpacing(0);
auto buttonLayerSpacer = new QWidget(buttonLayer);
buttonLayerSpacer->setSizePolicy(sizePolicy4);
layoutButtonMainLayer->addWidget(buttonLayerSpacer);
layoutButtonMainLayer->addWidget(buttonLayer);
timeStampButton = new QToolButton;
timeStampButton->setCheckable(true);
timeStampButton->setMinimumSize(QSize(30, 30));
timeStampButton->setMaximumSize(QSize(30, 30));
timeStampButton->setSizePolicy(sizePolicy5);
timeStampButton->setFocusPolicy(Qt::NoFocus);
timeStampButton->setToolTip(utils::richText(tr("Show Time Stamps.")));
timeStampButton->setIcon(QIcon(qsl(":/icons/dialog-information.png")));
connect(timeStampButton, &QAbstractButton::toggled, mUpperPane, &TTextEdit::slot_toggleTimeStamps);
connect(timeStampButton, &QAbstractButton::toggled, mLowerPane, &TTextEdit::slot_toggleTimeStamps);
auto replayButton = new QToolButton;
replayButton->setCheckable(true);
replayButton->setMinimumSize(QSize(30, 30));
replayButton->setMaximumSize(QSize(30, 30));
replayButton->setSizePolicy(sizePolicy5);
replayButton->setFocusPolicy(Qt::NoFocus);
replayButton->setToolTip(utils::richText(tr("Record a replay.")));
replayButton->setIcon(QIcon(qsl(":/icons/media-tape.png")));
connect(replayButton, &QAbstractButton::clicked, this, &TConsole::slot_toggleReplayRecording);
logButton = new QToolButton;
logButton->setMinimumSize(QSize(30, 30));
logButton->setMaximumSize(QSize(30, 30));
logButton->setCheckable(true);
logButton->setSizePolicy(sizePolicy5);
logButton->setFocusPolicy(Qt::NoFocus);
logButton->setToolTip(utils::richText(tr("Start logging game output to log file.")));
QIcon logIcon;
logIcon.addPixmap(QPixmap(qsl(":/icons/folder-downloads.png")), QIcon::Normal, QIcon::Off);
logIcon.addPixmap(QPixmap(qsl(":/icons/folder-downloads-red-cross.png")), QIcon::Normal, QIcon::On);
logButton->setIcon(logIcon);
connect(logButton, &QAbstractButton::clicked, this, &TConsole::slot_toggleLogging);
if (mType == MainConsole) {
mpLineEdit_networkLatency = new QLineEdit(this);
mpLineEdit_networkLatency->setReadOnly(true);
mpLineEdit_networkLatency->setSizePolicy(sizePolicy4);
mpLineEdit_networkLatency->setFocusPolicy(Qt::NoFocus);
mpLineEdit_networkLatency->setToolTip(utils::richText(tr("<i>N:</i> is the latency of the game server and network (aka ping, in seconds),<br>"
"<i>S:</i> is the system processing time - how long your triggers took to process the last line(s).")));
mpLineEdit_networkLatency->setMaximumSize(120, 30);
mpLineEdit_networkLatency->setMinimumSize(120, 30);
mpLineEdit_networkLatency->setAutoFillBackground(true);
mpLineEdit_networkLatency->setContentsMargins(0, 0, 0, 0);
mpLineEdit_networkLatency->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
int latencyFontPointSize = 21;
QFont latencyFont = QFont(qsl("Bitstream Vera Sans Mono"), latencyFontPointSize, QFont::Normal);
const int latencyFontSizeMargin = 10;
/*:
The first argument 'N' represents the 'N'etwork latency; the second 'S' the
'S'ystem (processing) time
*/
const QString dummyTextA = tr("N:%1 S:%2")
.arg(0.0, 0, 'f', 3)
.arg(0.0, 0, 'f', 3);
/*:
The argument 'S' represents the 'S'ystem (processing) time, in this situation
the Game Server is not sending "GoAhead" signals so we cannot deduce the
network latency...
*/
const QString dummyTextB = tr("<no GA> S:%1")
.arg(0.0, 0, 'f', 3);
do {
latencyFont.setPointSize(--latencyFontPointSize);
} while (latencyFontPointSize > 6
&& qMax(QFontMetrics(latencyFont).boundingRect(dummyTextA).width(),
QFontMetrics(latencyFont).boundingRect(dummyTextB).width()) + latencyFontSizeMargin
> mpLineEdit_networkLatency->maximumWidth());
mpLineEdit_networkLatency->setFont(latencyFont);
mpLineEdit_networkLatency->setFrame(false);
}
emergencyStop->setMinimumSize(QSize(30, 30));
emergencyStop->setMaximumSize(QSize(30, 30));
emergencyStop->setIcon(QIcon(qsl(":/icons/edit-bomb.png")));
emergencyStop->setSizePolicy(sizePolicy4);
emergencyStop->setFocusPolicy(Qt::NoFocus);
emergencyStop->setCheckable(true);
emergencyStop->setToolTip(utils::richText(tr("Emergency Stop. Stops all timers and triggers.")));
connect(emergencyStop, &QAbstractButton::clicked, this, &TConsole::slot_stopAllItems);
mpBufferSearchBox->setClearButtonEnabled(true);
for (auto child : mpBufferSearchBox->children()) {
auto *pAction_clear(qobject_cast<QAction *>(child));
if (pAction_clear && pAction_clear->objectName() == QLatin1String("_q_qlineeditclearaction")) {
connect(pAction_clear, &QAction::triggered, this, &TConsole::slot_clearSearchResults, Qt::QueuedConnection);
break;
}
}
mpBufferSearchBox->setMinimumSize(QSize(100, 30));
mpBufferSearchBox->setMaximumSize(QSize(150, 30));
mpBufferSearchBox->setSizePolicy(sizePolicy5);
mpBufferSearchBox->setFont(mpHost->mCommandLineFont);
mpBufferSearchBox->setFocusPolicy(Qt::ClickFocus);
mpBufferSearchBox->setPlaceholderText("Search ...");
QPalette commandLinePalette;
commandLinePalette.setColor(QPalette::Text, mpHost->mCommandLineFgColor);
commandLinePalette.setColor(QPalette::Highlight, QColor(0, 0, 192));
commandLinePalette.setColor(QPalette::HighlightedText, QColor(Qt::white));
commandLinePalette.setColor(QPalette::Base, mpHost->mCommandLineBgColor);
commandLinePalette.setColor(QPalette::Window, mpHost->mCommandLineBgColor);
mpBufferSearchBox->setToolTip(utils::richText(tr("Search buffer.")));
connect(mpBufferSearchBox, &QLineEdit::returnPressed, this, &TConsole::slot_searchBufferUp);
mpAction_searchOptions = new QAction(tr("Search Options"), this);
mpAction_searchOptions->setObjectName(qsl("mpAction_searchOptions"));
QMenu* pMenu_searchOptions = new QMenu(tr("Search Options"), this);
pMenu_searchOptions->setObjectName(qsl("pMenu_searchOptions"));
pMenu_searchOptions->setToolTipsVisible(true);
mpAction_searchCaseSensitive = new QAction(tr("Case sensitive"), this);
mpAction_searchCaseSensitive->setObjectName(qsl("mpAction_searchCaseSensitive"));
mpAction_searchCaseSensitive->setToolTip(utils::richText(tr("Match case precisely")));
mpAction_searchCaseSensitive->setCheckable(true);
pMenu_searchOptions->insertAction(nullptr, mpAction_searchCaseSensitive);
setSearchOptions(mSearchOptions);
connect(mpAction_searchCaseSensitive, &QAction::triggered, this, &TConsole::slot_toggleSearchCaseSensitivity);
mpAction_searchOptions->setMenu(pMenu_searchOptions);
mpBufferSearchBox->addAction(mpAction_searchOptions, QLineEdit::LeadingPosition);
mpBufferSearchUp->setMinimumSize(QSize(30, 30));
mpBufferSearchUp->setMaximumSize(QSize(30, 30));
mpBufferSearchUp->setSizePolicy(sizePolicy5);
mpBufferSearchUp->setToolTip(utils::richText(tr("Earlier search result.")));
mpBufferSearchUp->setFocusPolicy(Qt::NoFocus);
mpBufferSearchUp->setIcon(QIcon(qsl(":/icons/export.png")));
connect(mpBufferSearchUp, &QAbstractButton::clicked, this, &TConsole::slot_searchBufferUp);
mpBufferSearchDown->setMinimumSize(QSize(30, 30));
mpBufferSearchDown->setMaximumSize(QSize(30, 30));
mpBufferSearchDown->setSizePolicy(sizePolicy5);
mpBufferSearchDown->setFocusPolicy(Qt::NoFocus);
mpBufferSearchDown->setToolTip(utils::richText(tr("Later search result.")));
mpBufferSearchDown->setIcon(QIcon(qsl(":/icons/import.png")));
connect(mpBufferSearchDown, &QAbstractButton::clicked, this, &TConsole::slot_searchBufferDown);
if (mpCommandLine) {
layoutLayer2->addWidget(mpCommandLine);
}
layoutLayer2->addWidget(mpButtonMainLayer);
layoutButtonLayer->addWidget(mpBufferSearchBox, 0, 0, 0, 4);
layoutButtonLayer->addWidget(mpBufferSearchUp, 0, 5);
layoutButtonLayer->addWidget(mpBufferSearchDown, 0, 6);
layoutButtonLayer->addWidget(timeStampButton, 0, 7);
layoutButtonLayer->addWidget(replayButton, 0, 8);
layoutButtonLayer->addWidget(logButton, 0, 9);
layoutButtonLayer->addWidget(emergencyStop, 0, 10);
if (mType == MainConsole) {
// In fact a whole lot more could be inside this "if"!
layoutButtonLayer->addWidget(mpLineEdit_networkLatency, 0, 11);
}
layoutLayer2->setContentsMargins(0, 0, 0, 0);
layout->addWidget(layer);
layerCommandLine->setAutoFillBackground(true);
centralLayout->addWidget(layerCommandLine);
QList<int> sizeList;
sizeList << 6 << 2;
splitter->setSizes(sizeList);
mUpperPane->show();
mLowerPane->hide();
connect(mpScrollBar, &QAbstractSlider::valueChanged, mUpperPane, &TTextEdit::slot_scrollBarMoved);
connect(mpHScrollBar, &QAbstractSlider::valueChanged, mUpperPane, &TTextEdit::slot_hScrollBarMoved);
mpHScrollBar->hide();
//enable horizontal scrollbar in ErrorConsole
if (mType == ErrorConsole) {
mHScrollBarEnabled = true;
}
if (mType & (ErrorConsole|SubConsole|UserWindow)) {
mpScrollBar->hide();
mLowerPane->hide();
layerCommandLine->hide();
mpMainFrame->move(0, 0);
mpMainDisplay->move(0, 0);
}
if (mType & CentralDebugConsole) {
layerCommandLine->hide();
}
mpBaseVFrame->setContentsMargins(0, 0, 0, 0);
mpBaseHFrame->setContentsMargins(0, 0, 0, 0);
mpBaseVFrame->layout()->setSpacing(0);
mpBaseHFrame->layout()->setSpacing(0);
buttonLayerSpacer->setMinimumHeight(0);
buttonLayerSpacer->setMinimumWidth(100);
buttonLayer->setMaximumHeight(31);
//buttonLayer->setMaximumWidth(31);
buttonLayer->setMinimumWidth(400);
buttonLayer->setMaximumWidth(400);
mpButtonMainLayer->setMinimumWidth(400);
mpButtonMainLayer->setMaximumWidth(400);
mpButtonMainLayer->setAutoFillBackground(true);
mpButtonMainLayer->setPalette(commandLinePalette);
buttonLayer->setAutoFillBackground(true);
changeColors();
// error and debug consoles inherit font of the main console
if (mType & (ErrorConsole | CentralDebugConsole)) {
mDisplayFont = mpHost->getDisplayFont();
mDisplayFontName = mDisplayFont.family();
mDisplayFontSize = mDisplayFont.pointSize();
// They always use "Control Pictures" to show control characters:
mControlCharacter = ControlCharacterMode::Picture;
refreshView();
} else if (mpHost) {
connect(mpHost, &Host::signal_controlCharacterHandlingChanged, this, &TConsole::slot_changeControlCharacterHandling);
}
if (mType & (MainConsole | UserWindow)) {
setAcceptDrops(true);
setMouseTracking(true);
}
if (mType & MainConsole) {
mpButtonMainLayer->setVisible(!mpHost->getCompactInputLine());
}
if (mType & MainConsole) {
mpCommandLine->adjustHeight();
}
connect(mudlet::self(), &mudlet::signal_adjustAccessibleNames, this, &TConsole::slot_adjustAccessibleNames);
slot_adjustAccessibleNames();
// Need to delay doing this because it uses elements that may not have
// been constructed yet:
if (mType == MainConsole) {
QTimer::singleShot(0, this, [this]() { setProxyForFocus(mpCommandLine); });
}
}
TConsole::~TConsole()
{
#if defined(DEBUG_CODEPOINT_PROBLEMS)
if (mType & ~CentralDebugConsole) {
// Codepoint issues reporting is not enabled for the CDC:
mUpperPane->reportCodepointErrors();
}
#endif
}
Host* TConsole::getHost()
{
return mpHost;
}
void TConsole::resizeConsole()
{
const QSize size = QSize(width(), height());
QResizeEvent event(size, size);
QApplication::sendEvent(this, &event);
}
void TConsole::raiseMudletSysWindowResizeEvent(const int overallWidth, const int overallHeight)
{
if (mpHost.isNull()) {
return;
}
TEvent mudletEvent {};
mudletEvent.mArgumentList.append(QLatin1String("sysWindowResizeEvent"));
mudletEvent.mArgumentList.append(QString::number(overallWidth - mBorders.left() - mBorders.right()));
mudletEvent.mArgumentList.append(QString::number(overallHeight - mBorders.top() - mBorders.bottom() - mpCommandLine->height()));
mudletEvent.mArgumentList.append(mConsoleName);
mudletEvent.mArgumentTypeList.append(ARGUMENT_TYPE_STRING);
mudletEvent.mArgumentTypeList.append(ARGUMENT_TYPE_NUMBER);
mudletEvent.mArgumentTypeList.append(ARGUMENT_TYPE_NUMBER);
mudletEvent.mArgumentTypeList.append(ARGUMENT_TYPE_STRING);
mpHost->raiseEvent(mudletEvent);
}
void TConsole::resizeEvent(QResizeEvent* event)
{
if (mType & MainConsole) {
mBorders = mpHost->borders();
}
int x = event->size().width();
int y = event->size().height();
if (mType == MainConsole && !x) {
// When multi-view is NOT active but more than one profile is loaded
// switching between tabs causes the deselected profile to resize its
// main console to a width of zero - but that is not useful from a NAWS
// or event handling system point of view - so abort doing anything
// with the event:
return;
}
if (mType & (MainConsole|SubConsole|UserWindow) && mpCommandLine && !mpCommandLine->isHidden()) {
mpMainFrame->resize(x, y);
mpBaseVFrame->resize(x, y);
mpBaseHFrame->resize(x, y);
x -= (mpLeftToolBar->width() + mpRightToolBar->width());
y -= mpTopToolBar->height();
// The mBorders components will be all zeros for all but the MainConsole:
mpMainDisplay->resize(x - mBorders.left() - mBorders.right(),
y - mBorders.top() - mBorders.bottom() - mpCommandLine->height());
} else {
mpMainFrame->resize(x, y);
mpMainDisplay->resize(x, y);
}
mpMainDisplay->move(mBorders.left(), mBorders.top());
if (mType & (CentralDebugConsole|ErrorConsole)) {
layerCommandLine->hide();
} else if (mType & ~(SubConsole|UserWindow)) {
// does nothing for SubConsole or UserWindows
layerCommandLine->move(0, mpBaseVFrame->height() - layerCommandLine->height());
}
QWidget::resizeEvent(event);
if (mType & MainConsole) {
// don't call event in lua if size didn't change
const bool preventLuaEvent = (getMainWindowSize() == mOldSize);
mOldSize = getMainWindowSize();
if (preventLuaEvent) {
return;
}
if (!mpHost.isNull()) {
TLuaInterpreter* pLua = mpHost->getLuaInterpreter();
const QString func = "handleWindowResizeEvent";
const QString n = "WindowResizeEvent";
pLua->call(func, n);
raiseMudletSysWindowResizeEvent(x, y);
}
}
//create the sysUserWindowResize Event for automatic resizing with Geyser
if (mType & (UserWindow) && !mpHost.isNull()) {
TLuaInterpreter* pLua = mpHost->getLuaInterpreter();
const QString func = "handleWindowResizeEvent";
const QString n = "WindowResizeEvent";
pLua->call(func, n);
TEvent mudletEvent {};
mudletEvent.mArgumentList.append(QLatin1String("sysUserWindowResizeEvent"));
mudletEvent.mArgumentList.append(QString::number(x));
mudletEvent.mArgumentList.append(QString::number(y));
mudletEvent.mArgumentList.append(mConsoleName);
mudletEvent.mArgumentTypeList.append(ARGUMENT_TYPE_STRING);
mudletEvent.mArgumentTypeList.append(ARGUMENT_TYPE_NUMBER);
mudletEvent.mArgumentTypeList.append(ARGUMENT_TYPE_NUMBER);
mudletEvent.mArgumentTypeList.append(ARGUMENT_TYPE_STRING);
mpHost->raiseEvent(mudletEvent);
}
}
void TConsole::refresh()
{
if (mType == MainConsole) {
mBorders = mpHost->borders();
}
int x = width();
int y = height();
mpBaseVFrame->resize(x, y);
mpBaseHFrame->resize(x, y);
x = mpBaseVFrame->width();
if (!mpLeftToolBar->isHidden()) {
x -= mpLeftToolBar->width();
}
if (!mpRightToolBar->isHidden()) {
x -= mpRightToolBar->width();
}
y = mpBaseVFrame->height();
if (!mpTopToolBar->isHidden()) {
y -= mpTopToolBar->height();
}
mpMainDisplay->resize(x - mBorders.left() - mBorders.right(), y - mBorders.top() - mBorders.bottom() - mpCommandLine->height());
if (mType & MainConsole) {
mpCommandLine->adjustHeight();
}
mpMainDisplay->move(mBorders.left(), mBorders.top());
x = width();
y = height();
const QSize s = QSize(x, y);
QResizeEvent event(s, s);
QApplication::sendEvent(this, &event);
}
void TConsole::clearSelection() const
{
mLowerPane->unHighlight();
mUpperPane->unHighlight();
mLowerPane->mSelectedRegion = QRegion(0, 0, 0, 0);
mUpperPane->mSelectedRegion = QRegion(0, 0, 0, 0);
mUpperPane->forceUpdate();
mLowerPane->forceUpdate();
}
void TConsole::closeEvent(QCloseEvent* event)
{
if (mType == CentralDebugConsole) {
if (mudlet::self()->isGoingDown() || mpHost->isClosingDown()) {
event->accept();
return;
}
hide();
mudlet::smpDebugArea->setVisible(false);
mudlet::smDebugMode = false;
mudlet::self()->refreshTabBar();
event->ignore();
return;
}
if (mType & (SubConsole|Buffer)) {
if (mudlet::self()->isGoingDown() || mpHost->isClosingDown()) {
auto pC = mpHost->mpConsole->mSubConsoleMap.take(mConsoleName);
if (pC) {
// As it happens pC will be identical to 'this' it is just that
// we will have removed it from the main TConsole's
// mSubConsoleMap:
mUpperPane->close();
mLowerPane->close();
}
event->accept();
return;
}
hide();
event->ignore();
return;
}
if (mType == UserWindow) {
if (mudlet::self()->isGoingDown() || mpHost->isClosingDown()) {
auto pC = mpHost->mpConsole->mSubConsoleMap.take(mConsoleName);
auto pD = mpHost->mpConsole->mDockWidgetMap.take(mConsoleName);
if (pC) {
// As it happens pC will be identical to 'this' it is just that
// we will have removed it from the main TConsole's
// mSubConsoleMap:
mUpperPane->close();
mLowerPane->close();
}
if (pD) {
pD->setAttribute(Qt::WA_DeleteOnClose);
pD->deleteLater();
} else {
qDebug() << "TConsole::closeEvent(QCloseEvent*) INFO - closing a UserWindow but the TDockWidget pointer was not found to be removed...";
}
// This will also cause the QWidget to be automatically hidden:
event->accept();
return;
}
hide();
event->ignore();
return;
}
if (mType == MainConsole) {
// The event should have been handled by the override in the TMainConsole
Q_ASSERT_X(false, "TConsole::closeEvent()", "Close event not handled by TMainConsole override.");
}
}
int TConsole::getButtonState()
{
return mButtonState;
}
// Converted into a wrapper around a separate toggleLogging() method so that
// calls to turn logging on/off via the toolbar button - which go via this
// wrapper - generate messages on the console. Requests to control logging from
// the Lua interpreter call the wrapped method directly and messages are
// generated for Lua user control by the Lua subsystem.
void TConsole::slot_toggleLogging()
{
if (mType & (CentralDebugConsole|ErrorConsole|SubConsole|UserWindow)) {
return;
// We don't support logging anything other than main console (at present?)
}
mpHost->mpConsole->toggleLogging(true);
}
// FIXME: This needs to move to the TMainConsole class but the button handling
// code is currently defined but not used for all TConsole instances - and some
// of them might be useful to have on the other ones...
void TConsole::slot_toggleReplayRecording()
{
if (mType & CentralDebugConsole) {
return;
}
mRecordReplay = !mRecordReplay;
if (mRecordReplay) {
const QString directoryLogFile = mudlet::getMudletPath(mudlet::profileReplayAndLogFilesPath, mProfileName);
const QString mLogFileName = qsl("%1/%2.dat").arg(directoryLogFile, QDateTime::currentDateTime().toString(qsl("yyyy-MM-dd#HH-mm-ss")));
const QDir dirLogFile;
if (!dirLogFile.exists(directoryLogFile)) {
dirLogFile.mkpath(directoryLogFile);
}
mReplayFile.setFileName(mLogFileName);
mReplayFile.open(QIODevice::WriteOnly);
if (mudlet::scmRunTimeQtVersion >= QVersionNumber(5, 13, 0)) {
mReplayStream.setVersion(mudlet::scmQDataStreamFormat_5_12);
}
mReplayStream.setDevice(&mReplayFile);
mpHost->mTelnet.recordReplay();
printSystemMessage(tr("Replay recording has started. File: %1").arg(mReplayFile.fileName()) % QChar::LineFeed);
} else {
if (!mReplayFile.commit()) {
qDebug() << "TConsole::slot_toggleReplayRecording: error saving replay: " << mReplayFile.errorString();
printSystemMessage(tr("Replay recording has been stopped, but couldn't be saved.") % QChar::LineFeed);
} else {
printSystemMessage(tr("Replay recording has been stopped. File: %1").arg(mReplayFile.fileName()) % QChar::LineFeed);
}
}
}
QString getColorCode(QColor color)
{
return qsl("%1,%2,%3,%4").arg(color.red()).arg(color.green()).arg(color.blue()).arg(color.alpha());
}
void TConsole::changeColors()
{
mDisplayFont.setFixedPitch(true);
if (mType == CentralDebugConsole) {
mDisplayFont.setStyleStrategy((QFont::StyleStrategy)(QFont::NoAntialias | QFont::PreferQuality));
mDisplayFont.setFixedPitch(true);
mUpperPane->setFont(mDisplayFont);
mLowerPane->setFont(mDisplayFont);
} else if (mType & (ErrorConsole|SubConsole|UserWindow|Buffer)) {
mDisplayFont.setStyleStrategy(QFont::StyleStrategy(QFont::NoAntialias | QFont::PreferQuality));
mDisplayFont.setFixedPitch(true);
mUpperPane->setFont(mDisplayFont);
mLowerPane->setFont(mDisplayFont);
if (!mBgImageMode) {
auto styleSheet = qsl("QWidget#MainDisplay{background-color: rgba(%1);}").arg(getColorCode(mBgColor));
mpMainDisplay->setStyleSheet(styleSheet);
} else {
setConsoleBackgroundImage(mBgImagePath, mBgImageMode);
}
} else if (mType == MainConsole) {
if (mpCommandLine) {
auto styleSheet = mpCommandLine->styleSheet();
mpCommandLine->setStyleSheet(QString());
// CHECK: This seems to be a, possibly iffy, attempt to combine a
// QPalette with a style-sheet - though the Qt Documentation does
// seem to say one should not mix QPalettes with styles/stylesheets!
QPalette commandLinePalette;
commandLinePalette.setColor(QPalette::Text, mpHost->mCommandLineFgColor);
commandLinePalette.setColor(QPalette::Highlight, QColor(0, 0, 192));
commandLinePalette.setColor(QPalette::HighlightedText, QColor(Qt::white));
commandLinePalette.setColor(QPalette::Base, mpHost->mCommandLineBgColor);
commandLinePalette.setColor(QPalette::Window, mpHost->mCommandLineBgColor);
mpCommandLine->setPalette(commandLinePalette);
mpButtonMainLayer->setPalette(commandLinePalette);
mpCommandLine->mRegularPalette = commandLinePalette;
mpCommandLine->setStyleSheet(styleSheet);
}
if (mpHost->mNoAntiAlias) {
mpHost->setDisplayFontStyle(QFont::NoAntialias);
} else {
mpHost->setDisplayFontStyle(QFont::StyleStrategy(QFont::PreferAntialias | QFont::PreferQuality));
}
mpHost->setDisplayFontFixedPitch(true);
mDisplayFont.setFixedPitch(true);
mUpperPane->setFont(mpHost->getDisplayFont());
mLowerPane->setFont(mpHost->getDisplayFont());
if (!mBgImageMode) {
auto styleSheet = qsl("QWidget#MainDisplay{background-color: rgba(%1);}").arg(getColorCode(mpHost->mBgColor));
mpMainDisplay->setStyleSheet(styleSheet);
} else {
setConsoleBackgroundImage(mBgImagePath, mBgImageMode);
}
mBgColor = mpHost->mBgColor;
mFgColor = mpHost->mFgColor;
mCommandFgColor = mpHost->mCommandFgColor;
mCommandBgColor = mpHost->mCommandBgColor;
if (mpCommandLine) {
mpCommandLine->setFont(mpHost->getDisplayFont());
}
mFormatCurrent.setColors(mpHost->mFgColor, mpHost->mBgColor);
} else {
Q_ASSERT_X(false, "TConsole::changeColors()", "invalid TConsole type detected");
}
buffer.updateColors();
if (mType & (MainConsole|Buffer)) {
buffer.mWrapAt = mpHost->mWrapAt;
buffer.mWrapIndent = mpHost->mWrapIndentCount;
}
}
void TConsole::setConsoleBgColor(int r, int g, int b, int a)
{
mBgColor = QColor(r, g, b, a);
mUpperPane->setConsoleBgColor(r, g, b, a);
mLowerPane->setConsoleBgColor(r, g, b, a);
changeColors();
}
// Not used:
//void TConsole::setConsoleFgColor(int r, int g, int b)
//{
// mFgColor = QColor(r, g, b);
// mUpperPane->setConsoleFgColor(r, g, b);
// mLowerPane->setConsoleFgColor(r, g, b);
// changeColors();
//}
/*std::string TConsole::getCurrentTime()
{
time_t t;
time(&t);
tm lt;
ostringstream s;
s.str("");
struct timeval tv;
struct timezone tz;
gettimeofday(&tv, &tz);
localtime_r( &t, < );
s << "["<<lt.tm_hour<<":"<<lt.tm_min<<":"<<lt.tm_sec<<":"<<tv.tv_usec<<"]";
string time = s.str();
return time;
} */
/* ANSI color codes: sequence = "ESCAPE + [ code_1; ... ; code_n m"
-----------------------------------------
0 reset
1 intensity bold on
2 intensity faint
3 italics on
4 underline on
5 blink slow
6 blink fast
7 inverse on
9 strikethrough
22 intensity normal (not bold, not faint)
23 italics off
24 underline off
27 inverse off
29 strikethrough off
30 fg black
31 fg red
32 fg green
33 fg yellow
34 fg blue
35 fg magenta
36 fg cyan
37 fg white
39 bg default white
40 bg black
41 bg red
42 bg green
43 bg yellow
44 bg blue
45 bg magenta
46 bg cyan
47 bg white
49 bg black */
void TConsole::scrollDown(int lines)
{
if ((mType & (UserWindow|SubConsole)) && !mScrollingEnabled) {
return;
}
mUpperPane->scrollDown(lines);
if (!mUpperPane->mIsTailMode &&
(mUpperPane->imageTopLine() + mUpperPane->getScreenHeight() >= buffer.lineBuffer.size() - mLowerPane->getRowCount())) {
mUpperPane->scrollDown(mLowerPane->getRowCount() + 100); // Gets to the bottom
mUpperPane->scrollDown(100); // needs another scroll to force mIsTailMode