LUAEditorPlainTextEdit.hxx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/Memory/SystemAllocator.h>
  10. #include <AzCore/base.h>
  11. #include <AzCore/std/functional.h>
  12. #include <QtWidgets/QCompleter>
  13. #include <QtWidgets/QPlainTextEdit>
  14. #endif
  15. #pragma once
  16. namespace LUAEditor
  17. {
  18. class LUAEditorPlainTextEdit : public QPlainTextEdit
  19. {
  20. Q_OBJECT
  21. public:
  22. AZ_CLASS_ALLOCATOR(LUAEditorPlainTextEdit, AZ::SystemAllocator);
  23. LUAEditorPlainTextEdit(QWidget *pParent = nullptr);
  24. virtual ~LUAEditorPlainTextEdit();
  25. void SetTabSize(int tabSize) { m_tabSize = tabSize; }
  26. void SetUseSpaces(bool useSpaces) { m_useSpaces = useSpaces; }
  27. void UpdateFont(QFont font, int tabSize);
  28. void SetGetLuaName(AZStd::function<QString(const QTextCursor&)> lambda) { m_getLUAName = lambda; }
  29. QRectF GetBlockBoundingGeometry(const QTextBlock& block) const;
  30. void ForEachVisibleBlock(AZStd::function<void(QTextBlock& block, const QRectF&)> operation) const;
  31. protected:
  32. void focusInEvent(QFocusEvent* pEvent) override;
  33. void focusOutEvent(QFocusEvent* pEvent) override;
  34. void paintEvent(QPaintEvent*) override;
  35. void keyPressEvent(QKeyEvent* event) override;
  36. void wheelEvent(QWheelEvent* event) override;
  37. void dropEvent(QDropEvent *e) override;
  38. private:
  39. class Completer* m_completer;
  40. class CompletionModel* m_completionModel;
  41. AZStd::function<QString(const QTextCursor&)> m_getLUAName;
  42. int m_tabSize = 4;
  43. bool m_useSpaces = false;
  44. bool HandleIndentKeyPress(QKeyEvent* event);
  45. bool HandleHomeKeyPress(QKeyEvent* event);
  46. bool HandleNewline(QKeyEvent* event);
  47. void mouseDoubleClickEvent(QMouseEvent* event) override;
  48. void scrollContentsBy(int, int) override;
  49. signals:
  50. void Scrolled();
  51. void FocusChanged(bool focused);
  52. void ZoomIn();
  53. void ZoomOut();
  54. void BlockDoubleClicked(QMouseEvent* event, const QTextBlock& block);
  55. public slots:
  56. void OnScopeNamesUpdated(const QStringList& scopeNames);
  57. private slots:
  58. void CompletionSelected(const QString& text);
  59. };
  60. }