LUAEditorFindResults.hxx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #if !defined(Q_MOC_RUN)
  9. #include <AzCore/base.h>
  10. #include <AzCore/Asset/AssetCommon.h>
  11. #include <QSyntaxHighlighter>
  12. #include <QWidget>
  13. #endif
  14. #pragma once
  15. namespace Ui
  16. {
  17. class LUAEditorFindResults;
  18. }
  19. namespace LUAEditor
  20. {
  21. class FindResultsHighlighter
  22. : public QSyntaxHighlighter
  23. {
  24. Q_OBJECT
  25. public:
  26. AZ_CLASS_ALLOCATOR(FindResultsHighlighter, AZ::SystemAllocator);
  27. FindResultsHighlighter(QTextDocument* parent) : QSyntaxHighlighter(parent) {}
  28. ~FindResultsHighlighter() {}
  29. void highlightBlock(const QString& text) override;
  30. void SetFont(QFont font) { m_font = font; }
  31. void SetSearchString(const QString& searchString, bool regEx, bool wholeWord, bool caseSensitive);
  32. private:
  33. QFont m_font{"OpenSans", 10};
  34. QString m_searchString;
  35. bool m_regEx;
  36. bool m_wholeWord;
  37. bool m_caseSensitive;
  38. };
  39. class FindResultsBlockInfo : public QTextBlockUserData
  40. {
  41. public:
  42. AZ_CLASS_ALLOCATOR(FindResultsBlockInfo, AZ::SystemAllocator);
  43. typedef AZStd::function<void(const AZStd::string&, const AZStd::string&)> AssignAssetIdType;
  44. FindResultsBlockInfo(const AZStd::string& assetId, const char* assetName, int lineNumber, int firstMatchPosition, AssignAssetIdType assignAssetId)
  45. : m_assetId(assetId)
  46. , m_assetName(assetName)
  47. , m_lineNumber(lineNumber)
  48. , m_firstMatchPosition(firstMatchPosition)
  49. , m_assignAssetId(assignAssetId)
  50. {}
  51. FindResultsBlockInfo(const FindResultsBlockInfo& rhs)
  52. : m_assetId(rhs.m_assetId)
  53. , m_assetName(rhs.m_assetName)
  54. , m_lineNumber(rhs.m_lineNumber)
  55. , m_firstMatchPosition(rhs.m_firstMatchPosition)
  56. , m_assignAssetId(rhs.m_assignAssetId)
  57. {
  58. }
  59. AZStd::string m_assetId;
  60. AZStd::string m_assetName;
  61. int m_lineNumber;
  62. int m_firstMatchPosition;
  63. AssignAssetIdType m_assignAssetId;
  64. };
  65. class FindResults : public QWidget
  66. {
  67. Q_OBJECT
  68. public:
  69. AZ_CLASS_ALLOCATOR(FindResults, AZ::SystemAllocator);
  70. FindResults(QWidget *parent = 0);
  71. ~FindResults();
  72. void Clear();
  73. QTextDocument* Document();
  74. void AppendPlainText(const QString& text);
  75. void AssignAssetId(const AZStd::string& assetName, const AZStd::string& assetId);
  76. void FinishedAddingText(const QString& searchString, bool regEx, bool wholeWord, bool caseSensitive);
  77. signals:
  78. void ResultSelected(const FindResultsBlockInfo& result);
  79. public slots:
  80. void OnBlockDoubleClicked(QMouseEvent* event, const QTextBlock& block);
  81. private:
  82. Ui::LUAEditorFindResults* m_gui;
  83. class FindResultsHighlighter* m_highlighter;
  84. QColor m_resultLineHighlightColor;
  85. };
  86. }