File indexing completed on 2025-01-05 05:14:51
0001 /* 0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "codeeditorsidebar.h" 0008 #include "codeeditor.h" 0009 0010 #include <QTextBlock> 0011 0012 CodeEditorSidebar::CodeEditorSidebar(CodeEditor *editor) 0013 : QWidget(editor) 0014 , m_codeEditor(editor) 0015 { 0016 setAttribute(Qt::WA_OpaquePaintEvent); 0017 } 0018 0019 QSize CodeEditorSidebar::sizeHint() const 0020 { 0021 return QSize(m_codeEditor->sidebarWidth(), 0); 0022 } 0023 0024 void CodeEditorSidebar::paintEvent(QPaintEvent *event) 0025 { 0026 m_codeEditor->sidebarPaintEvent(event); 0027 } 0028 0029 void CodeEditorSidebar::mouseReleaseEvent(QMouseEvent *event) 0030 { 0031 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 0032 auto x = event->position().x(); 0033 auto y = event->position().y(); 0034 #else 0035 auto x = event->x(); 0036 auto y = event->y(); 0037 #endif 0038 0039 if (x >= width() - m_codeEditor->fontMetrics().lineSpacing()) { 0040 const auto block = m_codeEditor->blockAtPosition(y); 0041 if (!block.isValid() || !m_codeEditor->isFoldable(block)) 0042 return; 0043 m_codeEditor->toggleFold(block); 0044 } 0045 QWidget::mouseReleaseEvent(event); 0046 } 0047 0048 #include "moc_codeeditorsidebar.cpp"