Libksieve

sievetexteditwidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2015-2021 Laurent Montel <[email protected]>
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 <KPIMTextEdit/PlainTextEditFindBar>
12 #include <KPIMTextEdit/SlideContainer>
13 using namespace KSieveUi;
14 
15 class KSieveUi::SieveTextEditWidgetPrivate
16 {
17 public:
18  SieveTextEditWidgetPrivate()
19  {
20  }
21 
22  KSieveUi::SieveTextEdit *mTextEdit = nullptr;
23  KPIMTextEdit::SlideContainer *mSliderContainer = nullptr;
24  KPIMTextEdit::PlainTextEditFindBar *mFindBar = nullptr;
25 };
26 
27 SieveTextEditWidget::SieveTextEditWidget(KSieveUi::SieveTextEdit *customTextEdit, QWidget *parent)
28  : QWidget(parent)
29  , d(new KSieveUi::SieveTextEditWidgetPrivate)
30 {
31  initialize(customTextEdit);
32 }
33 
34 SieveTextEditWidget::SieveTextEditWidget(QWidget *parent)
35  : QWidget(parent)
36  , d(new KSieveUi::SieveTextEditWidgetPrivate)
37 {
38  initialize();
39 }
40 
41 SieveTextEditWidget::~SieveTextEditWidget()
42 {
43 }
44 
45 void SieveTextEditWidget::initialize(KSieveUi::SieveTextEdit *custom)
46 {
47  auto mainLayout = new QVBoxLayout(this);
48  mainLayout->setContentsMargins({});
49  if (custom) {
50  d->mTextEdit = custom;
51  } else {
52  d->mTextEdit = new KSieveUi::SieveTextEdit;
53  }
54  d->mTextEdit->setObjectName(QStringLiteral("textedit"));
55  d->mTextEdit->setShowHelpMenu(false);
56  mainLayout->addWidget(d->mTextEdit);
57 
58  d->mSliderContainer = new KPIMTextEdit::SlideContainer(this);
59  d->mSliderContainer->setObjectName(QStringLiteral("slidercontainer"));
60  d->mFindBar = new KPIMTextEdit::PlainTextEditFindBar(d->mTextEdit, this);
61  d->mFindBar->setObjectName(QStringLiteral("findbar"));
62  d->mFindBar->setHideWhenClose(false);
63  connect(d->mFindBar, &KPIMTextEdit::TextEditFindBarBase::hideFindBar, d->mSliderContainer, &KPIMTextEdit::SlideContainer::slideOut);
64  d->mSliderContainer->setContent(d->mFindBar);
65  mainLayout->addWidget(d->mSliderContainer);
66  connect(d->mTextEdit, &SieveTextEdit::findText, this, &SieveTextEditWidget::slotFind);
67  connect(d->mTextEdit, &SieveTextEdit::replaceText, this, &SieveTextEditWidget::slotReplace);
68 }
69 
70 void SieveTextEditWidget::setReadOnly(bool readOnly)
71 {
72  d->mTextEdit->setReadOnly(readOnly);
73 }
74 
75 void SieveTextEditWidget::slotReplace()
76 {
77  if (d->mTextEdit->textCursor().hasSelection()) {
78  d->mFindBar->setText(d->mTextEdit->textCursor().selectedText());
79  }
80  d->mFindBar->showReplace();
81  d->mSliderContainer->slideIn();
82  d->mFindBar->focusAndSetCursor();
83 }
84 
85 void SieveTextEditWidget::slotFind()
86 {
87  if (d->mTextEdit->textCursor().hasSelection()) {
88  d->mFindBar->setText(d->mTextEdit->textCursor().selectedText());
89  }
90  d->mTextEdit->moveCursor(QTextCursor::Start);
91  d->mFindBar->showFind();
92  d->mSliderContainer->slideIn();
93  d->mFindBar->focusAndSetCursor();
94 }
95 
96 SieveTextEdit *SieveTextEditWidget::textEdit() const
97 {
98  return d->mTextEdit;
99 }
KCRASH_EXPORT void initialize()
The SieveTextEdit class.
Definition: sievetextedit.h:20
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Apr 16 2021 23:09:34 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.