Libksieve

sievetexteditwidget.cpp
1/*
2 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-only
5*/
6
7#include "sievetexteditwidget.h"
8#include "editor/sievetextedit.h"
9#include <QVBoxLayout>
10
11#include <TextAddonsWidgets/SlideContainer>
12#include <TextCustomEditor/PlainTextEditFindBar>
13using namespace KSieveUi;
14
15class KSieveUi::SieveTextEditWidgetPrivate
16{
17public:
18 SieveTextEditWidgetPrivate() = default;
19
20 KSieveUi::SieveTextEdit *mTextEdit = nullptr;
21 TextAddonsWidgets::SlideContainer *mSliderContainer = nullptr;
23};
24
25SieveTextEditWidget::SieveTextEditWidget(KSieveUi::SieveTextEdit *customTextEdit, QWidget *parent)
26 : QWidget(parent)
27 , d(new KSieveUi::SieveTextEditWidgetPrivate)
28{
29 initialize(customTextEdit);
30}
31
32SieveTextEditWidget::SieveTextEditWidget(QWidget *parent)
33 : QWidget(parent)
34 , d(new KSieveUi::SieveTextEditWidgetPrivate)
35{
36 initialize();
37}
38
39SieveTextEditWidget::~SieveTextEditWidget() = default;
40
41void SieveTextEditWidget::initialize(KSieveUi::SieveTextEdit *custom)
42{
43 auto mainLayout = new QVBoxLayout(this);
44 mainLayout->setContentsMargins({});
45 if (custom) {
46 d->mTextEdit = custom;
47 } else {
48 d->mTextEdit = new KSieveUi::SieveTextEdit;
49 }
50 d->mTextEdit->setObjectName(QLatin1StringView("textedit"));
51 d->mTextEdit->setShowHelpMenu(false);
52 mainLayout->addWidget(d->mTextEdit);
53
54 d->mSliderContainer = new TextAddonsWidgets::SlideContainer(this);
55 d->mSliderContainer->setObjectName(QLatin1StringView("slidercontainer"));
56 d->mFindBar = new TextCustomEditor::PlainTextEditFindBar(d->mTextEdit, this);
57 d->mFindBar->setObjectName(QLatin1StringView("findbar"));
58 d->mFindBar->setHideWhenClose(false);
59 connect(d->mFindBar, &TextCustomEditor::TextEditFindBarBase::hideFindBar, d->mSliderContainer, &TextAddonsWidgets::SlideContainer::slideOut);
60 d->mSliderContainer->setContent(d->mFindBar);
61 mainLayout->addWidget(d->mSliderContainer);
62 connect(d->mTextEdit, &SieveTextEdit::findText, this, &SieveTextEditWidget::slotFind);
63 connect(d->mTextEdit, &SieveTextEdit::replaceText, this, &SieveTextEditWidget::slotReplace);
64}
65
66void SieveTextEditWidget::setReadOnly(bool readOnly)
67{
68 d->mTextEdit->setReadOnly(readOnly);
69}
70
71void SieveTextEditWidget::slotReplace()
72{
73 if (d->mTextEdit->textCursor().hasSelection()) {
74 d->mFindBar->setText(d->mTextEdit->textCursor().selectedText());
75 }
76 d->mFindBar->showReplace();
77 d->mSliderContainer->slideIn();
78 d->mFindBar->focusAndSetCursor();
79}
80
81void SieveTextEditWidget::slotFind()
82{
83 if (d->mTextEdit->textCursor().hasSelection()) {
84 d->mFindBar->setText(d->mTextEdit->textCursor().selectedText());
85 }
86 d->mTextEdit->moveCursor(QTextCursor::Start);
87 d->mFindBar->showFind();
88 d->mSliderContainer->slideIn();
89 d->mFindBar->focusAndSetCursor();
90}
91
92SieveTextEdit *SieveTextEditWidget::textEdit() const
93{
94 return d->mTextEdit;
95}
96
97#include "moc_sievetexteditwidget.cpp"
The SieveTextEdit class.
void initialize(StandardShortcut id)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.