forked from thoth-medievia/Mudlet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TConsole.cpp
3034 lines (2718 loc) · 110 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-2020 by Stephen Lyons - slysven@virginmedia.com *
* Copyright (C) 2014 by Ahmed Charles - acharles@outlook.com *
* Copyright (C) 2016 by Ian Adkins - ieadkins@gmail.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 "TMap.h"
#include "TRoomDB.h"
#include "TSplitter.h"
#include "TTextEdit.h"
#include "dlgMapper.h"
#include "mudlet.h"
#include "pre_guard.h"
#include <QLineEdit>
#include <QMessageBox>
#include <QMimeData>
#include <QRegularExpression>
#include <QScrollBar>
#include <QShortcut>
#include <QTextBoundaryFinder>
#include <QTextCodec>
#include <QPainter>
#include "post_guard.h"
const QString TConsole::cmLuaLineVariable("line");
TConsole::TConsole(Host* pH, ConsoleType type, QWidget* parent)
: QWidget(parent)
, mpHost(pH)
, mpDockWidget(nullptr)
, mpCommandLine(nullptr)
, buffer(pH)
, emergencyStop(new QToolButton)
, layerCommandLine(nullptr)
, mBgColor(QColor(Qt::black))
, mClipboard(mpHost)
, mCommandBgColor(Qt::black)
, mCommandFgColor(QColor(213, 195, 0))
, mConsoleName("main")
, mDisplayFontName("Bitstream Vera Sans Mono")
, mDisplayFontSize(14)
, mDisplayFont(QFont(mDisplayFontName, mDisplayFontSize, QFont::Normal))
, mFgColor(Qt::black)
, mIndentCount(0)
, mLogFileName(QString(""))
, mLogToLogFile(false)
, mMainFrameBottomHeight(0)
, mMainFrameLeftWidth(0)
, mMainFrameRightWidth(0)
, mMainFrameTopHeight(0)
, mOldX(0)
, mOldY(0)
, 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))
, mpMapper(nullptr)
, mpScrollBar(new QScrollBar)
, mRecordReplay(false)
, mSystemMessageBgColor(mBgColor)
, mSystemMessageFgColor(QColor(Qt::red))
, mTriggerEngineMode(false)
, mWrapAt(100)
, networkLatency(new QLineEdit)
, mProfileName(mpHost ? mpHost->getName() : QStringLiteral("debug console"))
, mIsPromptLine(false)
, mUserAgreedToCloseConsole(false)
, mpBufferSearchBox(new QLineEdit)
, mpBufferSearchUp(new QToolButton)
, mpBufferSearchDown(new QToolButton)
, mCurrentSearchResult(0)
, mSearchQuery()
, mpButtonMainLayer(nullptr)
, mType(type)
, mSpellDic()
, mpHunspell_system(nullptr)
, mpHunspell_shared(nullptr)
, mpHunspell_profile(nullptr)
{
auto ps = new QShortcut(this);
ps->setKey(Qt::CTRL + Qt::Key_W);
ps->setContext(Qt::WidgetShortcut);
if (mType & CentralDebugConsole) {
setWindowTitle(tr("Debug Console"));
// Probably will not show up as this is used inside a QMainWindow widget
// which has it's own title and icon set.
// mIsSubConsole was left false for this
mWrapAt = 50;
mStandardFormat.setTextFormat(mFgColor, mBgColor, TChar::None);
} else {
if (mType & (ErrorConsole|SubConsole|UserWindow)) {
// Orginally this was for TConsole instances with a parent pointer
// This branch for: UserWindows, SubConsole, ErrorConsole
// mIsSubConsole was true for these
mMainFrameTopHeight = 0;
mMainFrameBottomHeight = 0;
mMainFrameLeftWidth = 0;
mMainFrameRightWidth = 0;
} else if (mType & (MainConsole|Buffer)) {
// Orginally this was for TConsole instances without a parent pointer
// This branch for: Buffers, MainConsole
// mIsSubConsole was false for these
mMainFrameTopHeight = mpHost->mBorderTopHeight;
mMainFrameBottomHeight = mpHost->mBorderBottomHeight;
mMainFrameLeftWidth = mpHost->mBorderLeftWidth;
mMainFrameRightWidth = mpHost->mBorderRightWidth;
mCommandBgColor = mpHost->mCommandBgColor;
mCommandFgColor = mpHost->mCommandFgColor;
} else {
Q_ASSERT_X(false, "TConsole::TConsole(...)", "invalid TConsole type detected");
}
mStandardFormat.setTextFormat(mpHost->mFgColor, mpHost->mBgColor, TChar::None);
}
setContentsMargins(0, 0, 0, 0);
mFormatSystemMessage.setBackground(mBgColor);
mFormatSystemMessage.setForeground(Qt::red);
setAttribute(Qt::WA_DeleteOnClose);
setAttribute(Qt::WA_OpaquePaintEvent); //was disabled
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QSizePolicy sizePolicy3(QSizePolicy::Expanding, QSizePolicy::Expanding);
QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Fixed);
QSizePolicy sizePolicy4(QSizePolicy::Fixed, QSizePolicy::Expanding);
QSizePolicy sizePolicy5(QSizePolicy::Fixed, QSizePolicy::Fixed);
QPalette mainPalette;
mainPalette.setColor(QPalette::Text, QColor(Qt::black));
mainPalette.setColor(QPalette::Highlight, QColor(55, 55, 255));
mainPalette.setColor(QPalette::Window, QColor(0, 0, 0, 255));
QPalette splitterPalette;
splitterPalette = mainPalette;
splitterPalette.setColor(QPalette::Button, QColor(0, 0, 255, 255));
splitterPalette.setColor(QPalette::Window, QColor(Qt::green)); //,255) );
splitterPalette.setColor(QPalette::Base, QColor(255, 0, 0, 255));
splitterPalette.setColor(QPalette::Window, QColor(Qt::white));
//setPalette( mainPalette );
//QVBoxLayout * layoutFrame = new QVBoxLayout( mainFrame );
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->setContentsMargins(0, 0, 0, 0);
auto centralLayout = new QVBoxLayout;
setLayout(centralLayout);
auto baseVFrameLayout = new QVBoxLayout;
mpBaseVFrame->setLayout(baseVFrameLayout);
baseVFrameLayout->setMargin(0);
baseVFrameLayout->setSpacing(0);
centralLayout->addWidget(mpBaseVFrame);
auto baseHFrameLayout = new QHBoxLayout;
mpBaseHFrame->setLayout(baseHFrameLayout);
baseHFrameLayout->setMargin(0);
baseHFrameLayout->setSpacing(0);
layout()->setSpacing(0);
layout()->setMargin(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);
QPalette topbarPalette;
topbarPalette.setColor(QPalette::Text, QColor(Qt::white));
topbarPalette.setColor(QPalette::Highlight, QColor(55, 55, 255));
topbarPalette.setColor(QPalette::Window, QColor(0, 255, 0, 255));
topbarPalette.setColor(QPalette::Base, QColor(0, 255, 0, 255));
//mpTopToolBar->setPalette(topbarPalette);
topBarLayout->setMargin(0);
topBarLayout->setSpacing(0);
auto leftBarLayout = new QVBoxLayout;
mpLeftToolBar->setLayout(leftBarLayout);
mpLeftToolBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding));
mpLeftToolBar->setAutoFillBackground(true);
leftBarLayout->setMargin(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->setMargin(0);
rightBarLayout->setSpacing(0);
mpRightToolBar->setContentsMargins(0, 0, 0, 0);
mpBaseVFrame->setContentsMargins(0, 0, 0, 0);
baseVFrameLayout->setSpacing(0);
baseVFrameLayout->setMargin(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->setMargin(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->setMargin(0);
setContentsMargins(0, 0, 0, 0);
mpBaseHFrame->setContentsMargins(0, 0, 0, 0);
centralLayout->setSpacing(0);
centralLayout->setContentsMargins(0, 0, 0, 0);
centralLayout->setMargin(0);
mpMainDisplay->move(mMainFrameLeftWidth, mMainFrameTopHeight);
mpMainFrame->show();
mpMainDisplay->show();
mpMainFrame->setContentsMargins(0, 0, 0, 0);
mpMainDisplay->setContentsMargins(0, 0, 0, 0);
auto layout = new QVBoxLayout;
mpMainDisplay->setLayout(layout);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
mpBaseVFrame->setSizePolicy(sizePolicy);
mpBaseHFrame->setSizePolicy(sizePolicy);
mpBaseVFrame->setFocusPolicy(Qt::NoFocus);
mpBaseHFrame->setFocusPolicy(Qt::NoFocus);
baseVFrameLayout->setMargin(0);
baseHFrameLayout->setMargin(0);
centralLayout->setMargin(0);
if (mType == MainConsole) {
mpCommandLine = new TCommandLine(pH, this, mpMainDisplay);
mpCommandLine->setContentsMargins(0, 0, 0, 0);
mpCommandLine->setSizePolicy(sizePolicy);
mpCommandLine->setFocusPolicy(Qt::StrongFocus);
}
layer = new QWidget(mpMainDisplay);
layer->setContentsMargins(0, 0, 0, 0);
layer->setContentsMargins(0, 0, 0, 0); //neu rc1
layer->setSizePolicy(sizePolicy);
layer->setFocusPolicy(Qt::NoFocus);
auto layoutLayer = new QHBoxLayout;
layer->setLayout(layoutLayer);
layoutLayer->setMargin(0); //neu rc1
layoutLayer->setSpacing(0); //neu rc1
layoutLayer->setMargin(0); //neu rc1
mpScrollBar->setFixedWidth(15);
splitter = new TSplitter(Qt::Vertical);
splitter->setContentsMargins(0, 0, 0, 0);
splitter->setSizePolicy(sizePolicy);
splitter->setOrientation(Qt::Vertical);
splitter->setHandleWidth(3);
splitter->setPalette(splitterPalette);
splitter->setParent(layer);
mUpperPane = new TTextEdit(this, splitter, &buffer, mpHost, false);
mUpperPane->setContentsMargins(0, 0, 0, 0);
mUpperPane->setSizePolicy(sizePolicy3);
mUpperPane->setFocusPolicy(Qt::NoFocus);
mLowerPane = new TTextEdit(this, splitter, &buffer, mpHost, true);
mLowerPane->setContentsMargins(0, 0, 0, 0);
mLowerPane->setSizePolicy(sizePolicy3);
mLowerPane->setFocusPolicy(Qt::NoFocus);
if (mType == MainConsole) {
setFocusProxy(mpCommandLine);
mUpperPane->setFocusProxy(mpCommandLine);
mLowerPane->setFocusProxy(mpCommandLine);
} else if (mType == UserWindow) {
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); // nicht naeher dran, da es sonst performance probleme geben koennte beim display
layerCommandLine = new QWidget; //( mpMainFrame );//layer );
layerCommandLine->setContentsMargins(0, 0, 0, 0);
layerCommandLine->setSizePolicy(sizePolicy2);
layerCommandLine->setMaximumHeight(31);
layerCommandLine->setMinimumHeight(31);
auto layoutLayer2 = new QHBoxLayout(layerCommandLine);
layoutLayer2->setMargin(0);
layoutLayer2->setSpacing(0);
mpButtonMainLayer = new QWidget;
mpButtonMainLayer->setObjectName(QStringLiteral("mpButtonMainLayer"));
mpButtonMainLayer->setSizePolicy(sizePolicy);
mpButtonMainLayer->setContentsMargins(0, 0, 0, 0);
auto layoutButtonMainLayer = new QVBoxLayout(mpButtonMainLayer);
layoutButtonMainLayer->setObjectName(QStringLiteral("layoutButtonMainLayer"));
layoutButtonMainLayer->setMargin(0);
layoutButtonMainLayer->setContentsMargins(0, 0, 0, 0);
layoutButtonMainLayer->setSpacing(0);
/*mpButtonMainLayer->setMinimumHeight(31);
mpButtonMainLayer->setMaximumHeight(31);*/
auto buttonLayer = new QWidget;
buttonLayer->setObjectName(QStringLiteral("buttonLayer"));
auto layoutButtonLayer = new QGridLayout(buttonLayer);
layoutButtonLayer->setObjectName(QStringLiteral("layoutButtonLayer"));
layoutButtonLayer->setMargin(0);
layoutButtonLayer->setSpacing(0);
auto buttonLayerSpacer = new QWidget(buttonLayer);
buttonLayerSpacer->setSizePolicy(sizePolicy4);
layoutButtonMainLayer->addWidget(buttonLayerSpacer);
layoutButtonMainLayer->addWidget(buttonLayer);
auto 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(QStringLiteral("<html><head/><body><p>%1</p></body></html>").arg(
tr("Show Time Stamps.")));
timeStampButton->setIcon(QIcon(QStringLiteral(":/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(QStringLiteral("<html><head/><body><p>%1</p></body></html>").arg(
tr("Record a replay.")));
replayButton->setIcon(QIcon(QStringLiteral(":/icons/media-tape.png")));
connect(replayButton, &QAbstractButton::pressed, 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(QStringLiteral("<html><head/><body><p>%1</p></body></html>").arg(
tr("Start logging game output to log file.")));
QIcon logIcon;
logIcon.addPixmap(QPixmap(QStringLiteral(":/icons/folder-downloads.png")), QIcon::Normal, QIcon::Off);
logIcon.addPixmap(QPixmap(QStringLiteral(":/icons/folder-downloads-red-cross.png")), QIcon::Normal, QIcon::On);
logButton->setIcon(logIcon);
connect(logButton, &QAbstractButton::pressed, this, &TConsole::slot_toggleLogging);
networkLatency->setReadOnly(true);
networkLatency->setSizePolicy(sizePolicy4);
networkLatency->setFocusPolicy(Qt::NoFocus);
networkLatency->setToolTip(QStringLiteral("<html><head/><body><p>%1</p></body></html>").arg(
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).")));
networkLatency->setMaximumSize(120, 30);
networkLatency->setMinimumSize(120, 30);
networkLatency->setAutoFillBackground(true);
networkLatency->setContentsMargins(0, 0, 0, 0);
QPalette basePalette;
basePalette.setColor(QPalette::Text, QColor(Qt::black));
basePalette.setColor(QPalette::Base, QColor(Qt::white));
networkLatency->setPalette(basePalette);
networkLatency->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
QFont latencyFont = QFont("Bitstream Vera Sans Mono", 10, QFont::Normal);
int width;
int maxWidth = 120;
width = QFontMetrics(latencyFont).boundingRect(QString("N:0.000 S:0.000")).width();
if (width < maxWidth) {
networkLatency->setFont(latencyFont);
} else {
QFont latencyFont2 = QFont("Bitstream Vera Sans Mono", 9, QFont::Normal);
width = QFontMetrics(latencyFont2).boundingRect(QString("N:0.000 S:0.000")).width();
if (width < maxWidth) {
networkLatency->setFont(latencyFont2);
} else {
QFont latencyFont3 = QFont("Bitstream Vera Sans Mono", 8, QFont::Normal);
width = QFontMetrics(latencyFont3).boundingRect(QString("N:0.000 S:0.000")).width();
networkLatency->setFont(latencyFont3);
}
}
emergencyStop->setMinimumSize(QSize(30, 30));
emergencyStop->setMaximumSize(QSize(30, 30));
emergencyStop->setIcon(QIcon(QStringLiteral(":/icons/edit-bomb.png")));
emergencyStop->setSizePolicy(sizePolicy4);
emergencyStop->setFocusPolicy(Qt::NoFocus);
emergencyStop->setCheckable(true);
emergencyStop->setToolTip(QStringLiteral("<html><head/><body><p>%1</p></body></html>").arg(
tr("Emergency Stop. Stops all timers and triggers.")));
connect(emergencyStop, &QAbstractButton::clicked, this, &TConsole::slot_stop_all_triggers);
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 __pal;
__pal.setColor(QPalette::Text, mpHost->mCommandLineFgColor); //QColor(0,0,192));
__pal.setColor(QPalette::Highlight, QColor(0, 0, 192));
__pal.setColor(QPalette::HighlightedText, QColor(Qt::white));
__pal.setColor(QPalette::Base, mpHost->mCommandLineBgColor); //QColor(255,255,225));
__pal.setColor(QPalette::Window, mpHost->mCommandLineBgColor);
mpBufferSearchBox->setPalette(__pal);
mpBufferSearchBox->setToolTip(QStringLiteral("<html><head/><body><p>%1</p></body></html>").arg(
tr("Search buffer.")));
connect(mpBufferSearchBox, &QLineEdit::returnPressed, this, &TConsole::slot_searchBufferUp);
mpBufferSearchUp->setMinimumSize(QSize(30, 30));
mpBufferSearchUp->setMaximumSize(QSize(30, 30));
mpBufferSearchUp->setSizePolicy(sizePolicy5);
mpBufferSearchUp->setToolTip(QStringLiteral("<html><head/><body><p>%1</p></body></html>").arg(
tr("Earlier search result.")));
mpBufferSearchUp->setFocusPolicy(Qt::NoFocus);
mpBufferSearchUp->setIcon(QIcon(QStringLiteral(":/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(QStringLiteral("<html><head/><body><p>%1</p></body></html>").arg(
tr("Later search result.")));
mpBufferSearchDown->setIcon(QIcon(QStringLiteral(":/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);
layoutButtonLayer->addWidget(networkLatency, 0, 11);
layoutLayer2->setContentsMargins(0, 0, 0, 0);
layout->addWidget(layer);
networkLatency->setFrame(false);
//QPalette whitePalette;
//whitePalette.setColor( QPalette::Window, baseColor);//,255) );
layerCommandLine->setPalette(basePalette);
layerCommandLine->setAutoFillBackground(true);
centralLayout->addWidget(layerCommandLine);
QList<int> sizeList;
sizeList << 6 << 2;
splitter->setSizes(sizeList);
mUpperPane->show();
mLowerPane->show();
mLowerPane->hide();
connect(mpScrollBar, &QAbstractSlider::valueChanged, mUpperPane, &TTextEdit::slot_scrollBarMoved);
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()->setMargin(0);
mpBaseVFrame->layout()->setSpacing(0);
mpBaseHFrame->layout()->setMargin(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);
setFocusPolicy(Qt::ClickFocus);
mUpperPane->setFocusPolicy(Qt::ClickFocus);
mLowerPane->setFocusPolicy(Qt::ClickFocus);
buttonLayerSpacer->setAutoFillBackground(true);
buttonLayerSpacer->setPalette(__pal);
mpButtonMainLayer->setAutoFillBackground(true);
mpButtonMainLayer->setPalette(__pal);
buttonLayer->setAutoFillBackground(true);
buttonLayer->setPalette(__pal);
layerCommandLine->setPalette(__pal);
changeColors();
if (mType == MainConsole) {
// During first use where mIsDebugConsole IS true mudlet::self() is null
// then - but we rely on that flag to avoid having to also test for a
// non-null mudlet::self() - the connect(...) will produce a debug
// message and not make THAT connection should it indeed be null but it
// is not fatal...
// So, this SHOULD be the main profile mUpperPane - Slysven
connect(mudlet::self(), &mudlet::signal_profileMapReloadRequested, this, &TConsole::slot_reloadMap, Qt::UniqueConnection);
connect(this, &TConsole::signal_newDataAlert, mudlet::self(), &mudlet::slot_newDataOnHost, Qt::UniqueConnection);
// For some odd reason the first seems to get connected twice - the
// last flag prevents multiple ones being made
// Load up the spelling dictionary from the system:
setSystemSpellDictionary(mpHost->getSpellDic());
// Load up the spelling dictionary for the profile - needs to handle the
// absence of files for the first run in a new profile or from an older
// Mudlet version:
setProfileSpellDictionary();
}
// error and debug consoles inherit font of the main console
if (mType & (ErrorConsole | CentralDebugConsole)) {
mDisplayFont = mpHost->getDisplayFont();
mDisplayFontName = mDisplayFont.family();
mDisplayFontSize = mDisplayFont.pointSize();
refreshMiniConsole();
}
if (mType & (MainConsole | UserWindow)) {
setAcceptDrops(true);
}
}
TConsole::~TConsole()
{
if (mpHunspell_system) {
Hunspell_destroy(mpHunspell_system);
mpHunspell_system = nullptr;
}
if (mpHunspell_profile) {
Hunspell_destroy(mpHunspell_profile);
mpHunspell_profile = nullptr;
// Need to commit any changes to personal dictionary
qDebug() << "TCommandLine::~TConsole(...) INFO - Saving profile's own Hunspell dictionary...";
mudlet::self()->saveDictionary(mudlet::self()->getMudletPath(mudlet::profileDataItemPath, mProfileName, QStringLiteral("profile")), mWordSet_profile);
}
}
Host* TConsole::getHost()
{
return mpHost;
}
void TConsole::setLabelStyleSheet(std::string& buf, std::string& sh)
{
QString key = QString::fromUtf8(buf.c_str());
QString sheet = sh.c_str();
if (mLabelMap.find(key) != mLabelMap.end()) {
QLabel* pC = mLabelMap[key];
if (!pC) {
return;
}
pC->setStyleSheet(sheet);
return;
}
}
void TConsole::resizeEvent(QResizeEvent* event)
{
if (mType & (MainConsole|Buffer)) {
mMainFrameTopHeight = mpHost->mBorderTopHeight;
mMainFrameBottomHeight = mpHost->mBorderBottomHeight;
mMainFrameLeftWidth = mpHost->mBorderLeftWidth;
mMainFrameRightWidth = mpHost->mBorderRightWidth;
}
int x = event->size().width();
int y = event->size().height();
if (mType & (MainConsole|Buffer)) {
mpMainFrame->resize(x, y);
mpBaseVFrame->resize(x, y);
mpBaseHFrame->resize(x, y);
x = x - mpLeftToolBar->width() - mpRightToolBar->width();
y = y - mpTopToolBar->height();
mpMainDisplay->resize(x - mMainFrameLeftWidth - mMainFrameRightWidth, y - mMainFrameTopHeight - mMainFrameBottomHeight - mpCommandLine->height());
} else {
mpMainFrame->resize(x, y);
mpMainDisplay->resize(x, y); //x - mMainFrameLeftWidth - mMainFrameRightWidth, y - mMainFrameTopHeight - mMainFrameBottomHeight );
}
mpMainDisplay->move(mMainFrameLeftWidth, mMainFrameTopHeight);
if (mType & (CentralDebugConsole|ErrorConsole|SubConsole|UserWindow)) {
layerCommandLine->hide();
} else {
//layerCommandLine->move(0,mpMainFrame->height()-layerCommandLine->height());
layerCommandLine->move(0, mpBaseVFrame->height() - layerCommandLine->height());
}
QWidget::resizeEvent(event);
if (mType & (MainConsole|Buffer)) {
TLuaInterpreter* pLua = mpHost->getLuaInterpreter();
QString func = "handleWindowResizeEvent";
QString n = "WindowResizeEvent";
pLua->call(func, n);
TEvent mudletEvent {};
mudletEvent.mArgumentList.append(QLatin1String("sysWindowResizeEvent"));
mudletEvent.mArgumentList.append(QString::number(x - mMainFrameLeftWidth - mMainFrameRightWidth));
mudletEvent.mArgumentList.append(QString::number(y - mMainFrameTopHeight - mMainFrameBottomHeight - 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);
}
//create the sysUserWindowResize Event for automatic resizing with Geyser
if (mType & (UserWindow)) {
TLuaInterpreter* pLua = mpHost->getLuaInterpreter();
QString func = "handleWindowResizeEvent";
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 & (ErrorConsole|MainConsole|SubConsole|UserWindow|Buffer)) {
mMainFrameTopHeight = mpHost->mBorderTopHeight;
mMainFrameBottomHeight = mpHost->mBorderBottomHeight;
mMainFrameLeftWidth = mpHost->mBorderLeftWidth;
mMainFrameRightWidth = mpHost->mBorderRightWidth;
}
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 - mMainFrameLeftWidth - mMainFrameRightWidth, y - mMainFrameTopHeight - mMainFrameBottomHeight - mpCommandLine->height());
mpMainDisplay->move(mMainFrameLeftWidth, mMainFrameTopHeight);
x = width();
y = height();
QSize s = QSize(x, y);
QResizeEvent event(s, s);
QApplication::sendEvent(this, &event);
}
void TConsole::closeEvent(QCloseEvent* event)
{
if (mType == CentralDebugConsole) {
if (mudlet::self()->isGoingDown() || mpHost->isClosingDown()) {
event->accept();
return;
} else {
hide();
mudlet::mpDebugArea->setVisible(false);
mudlet::debugMode = false;
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;
} else {
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) {
qDebug() << "TConsole::closeEvent(QCloseEvent*) INFO - closing a UserWindow but the TDockWidget pointer was not found to be removed...";
}
event->accept();
return;
} else {
hide();
event->ignore();
return;
}
}
TEvent conCloseEvent{};
conCloseEvent.mArgumentList.append(QStringLiteral("sysExitEvent"));
conCloseEvent.mArgumentTypeList.append(ARGUMENT_TYPE_STRING);
mpHost->raiseEvent(conCloseEvent);
if (mpHost->mFORCE_SAVE_ON_EXIT) {
mudlet::self()->saveWindowLayout();
mpHost->modulesToWrite.clear();
mpHost->saveProfile();
if (mpHost->mpMap->mpRoomDB->size() > 0) {
QDir dir_map;
QString directory_map = mudlet::getMudletPath(mudlet::profileMapsPath, mProfileName);
// CHECKME: Consider changing datetime spec to more "sortable" "yyyy-MM-dd#HH-mm-ss" (3 of 6)
QString filename_map = mudlet::getMudletPath(mudlet::profileDateTimeStampedMapPathFileName, mProfileName, QDateTime::currentDateTime().toString("dd-MM-yyyy#hh-mm-ss"));
if (!dir_map.exists(directory_map)) {
dir_map.mkpath(directory_map);
}
QFile file_map(filename_map);
if (file_map.open(QIODevice::WriteOnly)) {
QDataStream out(&file_map);
if (mudlet::scmRunTimeQtVersion >= QVersionNumber(5, 13, 0)) {
out.setVersion(mudlet::scmQDataStreamFormat_5_12);
}
mpHost->mpMap->serialize(out);
file_map.close();
}
}
event->accept();
return;
}
if (!mUserAgreedToCloseConsole) {
ASK:
int choice = QMessageBox::question(this, tr("Save profile?"), tr("Do you want to save the profile %1?").arg(mProfileName), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
if (choice == QMessageBox::Cancel) {
event->setAccepted(false);
event->ignore();
return;
}
if (choice == QMessageBox::Yes) {
mudlet::self()->saveWindowLayout();
mpHost->modulesToWrite.clear();
std::tuple<bool, QString, QString> result = mpHost->saveProfile();
if (!std::get<0>(result)) {
QMessageBox::critical(this, tr("Couldn't save profile"), tr("Sorry, couldn't save your profile - got the following error: %1").arg(std::get<2>(result)));
goto ASK;
} else if (mpHost->mpMap && mpHost->mpMap->mpRoomDB->size() > 0) {
QDir dir_map;
QString directory_map = mudlet::getMudletPath(mudlet::profileMapsPath, mProfileName);
// CHECKME: Consider changing datetime spec to more "sortable" "yyyy-MM-dd#HH-mm-ss" (4 of 6)
QString filename_map = mudlet::getMudletPath(mudlet::profileDateTimeStampedMapPathFileName, mProfileName, QDateTime::currentDateTime().toString(QStringLiteral("dd-MM-yyyy#hh-mm-ss")));
if (!dir_map.exists(directory_map)) {
dir_map.mkpath(directory_map);
}
QFile file_map(filename_map);
if (file_map.open(QIODevice::WriteOnly)) {
QDataStream out(&file_map);
if (mudlet::scmRunTimeQtVersion >= QVersionNumber(5, 13, 0)) {
out.setVersion(mudlet::scmQDataStreamFormat_5_12);
}
mpHost->mpMap->serialize(out);
file_map.close();
}
}
event->accept();
return;
} else if (choice == QMessageBox::No) {
mudlet::self()->saveWindowLayout();
event->accept();
return;
} else {
if (!mudlet::self()->isGoingDown()) {
QMessageBox::warning(this, "Aborting exit", "Session exit aborted on user request.");
event->ignore();
return;
} else {
event->accept();
return;
}
}
}
}
int TConsole::getButtonState()
{
return mButtonState;
}
void TConsole::toggleLogging(bool isMessageEnabled)
{
if (mType & (CentralDebugConsole|ErrorConsole|SubConsole|UserWindow)) {
return;
// We don't support logging anything other than main console (at present?)
}
// CHECKME: This path seems suspicious, it is shared amoungst ALL profiles
// but the action is "Per Profile"...!
QFile file(mudlet::getMudletPath(mudlet::mainDataItemPath, QStringLiteral("autolog")));
QDateTime logDateTime = QDateTime::currentDateTime();
if (!mLogToLogFile) {
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&file);
file.close();
QString directoryLogFile;
QString logFileName;
// If no log directory is set, default to Mudlet's replay and log files path
if (mpHost->mLogDir == nullptr || mpHost->mLogDir.isEmpty()) {
directoryLogFile = mudlet::getMudletPath(mudlet::profileReplayAndLogFilesPath, mProfileName);
} else {
directoryLogFile = mpHost->mLogDir;
}
// The format being empty is a signal value that means use a specified
// name:
if (mpHost->mLogFileNameFormat.isEmpty()) {
if (mpHost->mLogFileName.isEmpty()) {
// If no log name is set, use the default placeholder
logFileName = tr("logfile", "Must be a valid default filename for a log-file and is used if the user does not enter any other value (Ensure all instances have the same translation {2 of 2}).");
} else {
// Otherwise a specific name as one is given
logFileName = mpHost->mLogFileName;
}
} else {
logFileName = logDateTime.toString(mpHost->mLogFileNameFormat);
}
// The preset file name formats are derived from date/times so that
// alphabetical filename and date sort order are the same...
QDir dirLogFile;
if (!dirLogFile.exists(directoryLogFile)) {
dirLogFile.mkpath(directoryLogFile);
}
mpHost->mIsCurrentLogFileInHtmlFormat = mpHost->mIsNextLogFileInHtmlFormat;
if (mpHost->mIsCurrentLogFileInHtmlFormat) {
mLogFileName = QStringLiteral("%1/%2.html").arg(directoryLogFile, logFileName);
} else {
mLogFileName = QStringLiteral("%1/%2.txt").arg(directoryLogFile, logFileName);
}
mLogFile.setFileName(mLogFileName);
// We do not want to use WriteOnly here:
// Append = "The device is opened in append mode so that all data is
// written to the end of the file."
// WriteOnly = "The device is open for writing. Note that this mode
// implies Truncate."
if (mpHost->mIsCurrentLogFileInHtmlFormat) {
mLogFile.open(QIODevice::ReadWrite);
} else {
mLogFile.open(QIODevice::Append);
}
mLogStream.setDevice(&mLogFile);
if (isMessageEnabled) {
QString message = tr("Logging has started. Log file is %1\n").arg(mLogFile.fileName());
printSystemMessage(message);
// This puts text onto console that is IMMEDIATELY POSTED into log file so
// must be done BEFORE logging starts - or actually mLogToLogFile gets set!
}
mLogToLogFile = true;
} else {
file.remove();
mLogToLogFile = false;
if (isMessageEnabled) {
QString message = tr("Logging has been stopped. Log file is %1\n").arg(mLogFile.fileName());
printSystemMessage(message);
// This puts text onto console that is IMMEDIATELY POSTED into log file so
// must be done AFTER logging ends - or actually mLogToLogFile gets reset!
}
}
if (mLogToLogFile) {
// Logging is being turned on
if (mpHost->mIsCurrentLogFileInHtmlFormat) {
QString log;
QTextStream logStream(&log);
/*
* From the Qt Documentation:
* 'On Windows, the codec will be based on a system locale. On Unix
* systems, the codec will might fall back to using the iconv
* library if no builtin codec for the locale can be found."
*
* Note that in these cases the codec's name will be "System".'
*
* So if we are going to use UTF-8 as we declare in the HTML
* header we had better set that codec to be used:
*/
QTextCodec* logCodec = QTextCodec::codecForName("UTF-8");
logStream.setCodec(logCodec);
QStringList fontsList; // List of fonts to become the font-family entry for
// the master css in the header
fontsList << this->fontInfo().family(); // Seems to be the best way to get the
// font in use, as different TConsole
// instances within the same profile
// might have different fonts in future,
// and although the font is settable for
// the main profile window, it is not yet
// for user miniConsoles, or the Debug one
fontsList << QStringLiteral("Courier New");
fontsList << QStringLiteral("Monospace");
fontsList << QStringLiteral("Courier");
fontsList.removeDuplicates(); // In case the actual one is one of the defaults here
logStream << "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'>\n";
logStream << "<html>\n";