File indexing completed on 2024-05-05 05:54:22
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 "zerowidgets.h" 0008 0009 #include <QPainter> 0010 0011 #include <KLocalizedString> 0012 0013 #include "dotregexp.h" 0014 #include "myfontmetrics.h" 0015 #include "positionregexp.h" 0016 0017 //-------------------------------------------------------------------------------- 0018 // ZeroWidget 0019 //-------------------------------------------------------------------------------- 0020 ZeroWidget::ZeroWidget(const QString &txt, RegExpEditorWindow *editorWindow, QWidget *parent) 0021 : RegExpWidget(editorWindow, parent) 0022 { 0023 _text = txt; 0024 } 0025 0026 void ZeroWidget::addNewChild(DragAccepter *, RegExpWidget *) 0027 { 0028 qFatal("No children should be added to this widget!"); 0029 } 0030 0031 QSize ZeroWidget::sizeHint() const 0032 { 0033 QFontMetrics metrics = fontMetrics(); 0034 _textSize = HackCalculateFontSize(metrics, _text); 0035 // _textSize = metrics.size(0,_text); 0036 _boxSize = QSize(_textSize.width() + 2 * space, _textSize.height() + 2 * space); 0037 return _boxSize; 0038 } 0039 0040 void ZeroWidget::paintEvent(QPaintEvent *e) 0041 { 0042 // So what is my Size? 0043 QSize mySize = sizeHint(); 0044 0045 QPainter painter(this); 0046 painter.setRenderHint(QPainter::Antialiasing); 0047 drawPossibleSelection(painter, mySize); 0048 0049 // Write the text and the rectangle 0050 painter.drawText(space, space, _textSize.width(), _textSize.height(), 0, _text); 0051 painter.drawRoundedRect(0, 0, _boxSize.width() - 1, _boxSize.height() - 1, 5, 5); 0052 0053 RegExpWidget::paintEvent(e); 0054 } 0055 0056 //-------------------------------------------------------------------------------- 0057 // AnyCharWidget 0058 //-------------------------------------------------------------------------------- 0059 AnyCharWidget::AnyCharWidget(RegExpEditorWindow *editorWindow, QWidget *parent) 0060 : ZeroWidget(i18n("Any\nCharacter"), editorWindow, parent) 0061 { 0062 } 0063 0064 RegExp *AnyCharWidget::regExp() const 0065 { 0066 return new DotRegExp(isSelected()); 0067 } 0068 0069 //-------------------------------------------------------------------------------- 0070 // BegLineWidget 0071 //-------------------------------------------------------------------------------- 0072 BegLineWidget::BegLineWidget(RegExpEditorWindow *editorWindow, QWidget *parent) 0073 : ZeroWidget(i18n("Line\nStart"), editorWindow, parent) 0074 { 0075 } 0076 0077 RegExp *BegLineWidget::regExp() const 0078 { 0079 return new PositionRegExp(isSelected(), PositionRegExp::BEGLINE); 0080 } 0081 0082 //-------------------------------------------------------------------------------- 0083 // EndLineWidget 0084 //-------------------------------------------------------------------------------- 0085 EndLineWidget::EndLineWidget(RegExpEditorWindow *editorWindow, QWidget *parent) 0086 : ZeroWidget(i18n("Line\nEnd"), editorWindow, parent) 0087 { 0088 } 0089 0090 RegExp *EndLineWidget::regExp() const 0091 { 0092 return new PositionRegExp(isSelected(), PositionRegExp::ENDLINE); 0093 } 0094 0095 //-------------------------------------------------------------------------------- 0096 // WordBoundaryWidget 0097 //-------------------------------------------------------------------------------- 0098 WordBoundaryWidget::WordBoundaryWidget(RegExpEditorWindow *editorWindow, QWidget *parent) 0099 : ZeroWidget(i18n("Word\nBoundary"), editorWindow, parent) 0100 { 0101 } 0102 0103 RegExp *WordBoundaryWidget::regExp() const 0104 { 0105 return new PositionRegExp(isSelected(), PositionRegExp::WORDBOUNDARY); 0106 } 0107 0108 //-------------------------------------------------------------------------------- 0109 // NonWordBoundaryWidget 0110 //-------------------------------------------------------------------------------- 0111 NonWordBoundaryWidget::NonWordBoundaryWidget(RegExpEditorWindow *editorWindow, QWidget *parent) 0112 : ZeroWidget(i18n("Non-word\nBoundary"), editorWindow, parent) 0113 { 0114 } 0115 0116 RegExp *NonWordBoundaryWidget::regExp() const 0117 { 0118 return new PositionRegExp(isSelected(), PositionRegExp::NONWORDBOUNDARY); 0119 }