File indexing completed on 2024-04-21 05:51:39
0001 /* 0002 * SPDX-FileCopyrightText: 2002-2003 Jesper K. Pedersen <blackie@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-only 0005 **/ 0006 0007 #include "scrollededitorwindow.h" 0008 0009 #include <QDebug> 0010 #include <QResizeEvent> 0011 #include <QScrollArea> 0012 0013 #include "regexpeditorwindow.h" 0014 0015 RegExpScrolledEditorWindow::RegExpScrolledEditorWindow(QWidget *parent) 0016 : QWidget(parent) 0017 { 0018 _scrollArea = new QScrollArea(this); 0019 _editorWindow = new RegExpEditorWindow(this); 0020 _scrollArea->setWidget(_editorWindow); 0021 _scrollArea->setWidgetResizable(true); // Morten Sjøgren: This is for some reason required for pasting to work. 0022 _scrollArea->ensureWidgetVisible(_editorWindow); 0023 0024 connect(_editorWindow, &RegExpEditorWindow::contentChanged, this, &RegExpScrolledEditorWindow::slotUpdateContentSize); 0025 0026 connect(_editorWindow, &RegExpEditorWindow::scrolling, this, &RegExpScrolledEditorWindow::slotScroll); 0027 0028 connect(_editorWindow, &RegExpEditorWindow::doneEditing, this, &RegExpScrolledEditorWindow::doneEditing); 0029 0030 connect(_editorWindow, &RegExpEditorWindow::change, this, &RegExpScrolledEditorWindow::change); 0031 connect(_editorWindow, &RegExpEditorWindow::savedRegexp, this, &RegExpScrolledEditorWindow::savedRegexp); 0032 0033 connect(_editorWindow, &RegExpEditorWindow::anythingSelected, this, &RegExpScrolledEditorWindow::anythingSelected); 0034 connect(_editorWindow, &RegExpEditorWindow::anythingOnClipboard, this, &RegExpScrolledEditorWindow::anythingOnClipboard); 0035 connect(_editorWindow, &RegExpEditorWindow::canSave, this, &RegExpScrolledEditorWindow::canSave); 0036 connect(_editorWindow, &RegExpEditorWindow::verifyRegExp, this, &RegExpScrolledEditorWindow::verifyRegExp); 0037 } 0038 0039 void RegExpScrolledEditorWindow::slotSetRegExp(RegExp *regexp) 0040 { 0041 _editorWindow->slotSetRegExp(regexp); 0042 slotUpdateContentSize(QPoint()); 0043 } 0044 0045 void RegExpScrolledEditorWindow::slotInsertRegExp(int tp) 0046 { 0047 _editorWindow->slotInsertRegExp((RegExpType)tp); 0048 } 0049 0050 void RegExpScrolledEditorWindow::slotInsertRegExp(RegExp *regexp) 0051 { 0052 _editorWindow->slotInsertRegExp(regexp); 0053 } 0054 0055 void RegExpScrolledEditorWindow::slotDeleteSelection() 0056 { 0057 _editorWindow->slotDeleteSelection(); 0058 } 0059 0060 void RegExpScrolledEditorWindow::slotDoSelect() 0061 { 0062 _editorWindow->slotDoSelect(); 0063 } 0064 0065 void RegExpScrolledEditorWindow::slotCut() 0066 { 0067 _editorWindow->slotCut(); 0068 } 0069 0070 void RegExpScrolledEditorWindow::slotCopy() 0071 { 0072 _editorWindow->slotCopy(); 0073 } 0074 0075 void RegExpScrolledEditorWindow::slotPaste() 0076 { 0077 _editorWindow->slotStartPasteAction(); 0078 } 0079 0080 void RegExpScrolledEditorWindow::slotSave() 0081 { 0082 _editorWindow->slotSave(); 0083 } 0084 0085 RegExp *RegExpScrolledEditorWindow::regExp() 0086 { 0087 return _editorWindow->regExp(); 0088 } 0089 0090 void RegExpScrolledEditorWindow::resizeEvent(QResizeEvent *event) 0091 { 0092 _scrollArea->resize(event->size()); 0093 slotUpdateContentSize(QPointF()); 0094 } 0095 0096 void RegExpScrolledEditorWindow::slotUpdateContentSize(QPointF focusPoint) 0097 { 0098 _editorWindow->resize(_editorWindow->sizeHint()); 0099 0100 if (!focusPoint.isNull()) { 0101 _scrollArea->ensureVisible(focusPoint.x(), focusPoint.y(), 250, 250); 0102 } 0103 } 0104 0105 // TODO: add timers, which will make the widget scroll when mouse is located 0106 // outside the QScrollView. 0107 void RegExpScrolledEditorWindow::slotScroll(QPointF focusPoint) 0108 { 0109 _scrollArea->ensureVisible(focusPoint.x(), focusPoint.y()); 0110 } 0111 0112 #include "moc_scrollededitorwindow.cpp"