Libksieve

sievetexteditwidget.cpp
1 /*
2  Copyright (C) 2015-2020 Laurent Montel <[email protected]>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "sievetexteditwidget.h"
19 #include <QVBoxLayout>
20 #include "editor/sievetextedit.h"
21 
22 #include <KPIMTextEdit/PlainTextEditFindBar>
23 #include <KPIMTextEdit/SlideContainer>
24 using namespace KSieveUi;
25 
26 class KSieveUi::SieveTextEditWidgetPrivate
27 {
28 public:
29  SieveTextEditWidgetPrivate()
30  {
31  }
32 
33  KSieveUi::SieveTextEdit *mTextEdit = nullptr;
34  KPIMTextEdit::SlideContainer *mSliderContainer = nullptr;
35  KPIMTextEdit::PlainTextEditFindBar *mFindBar = nullptr;
36 };
37 
38 SieveTextEditWidget::SieveTextEditWidget(KSieveUi::SieveTextEdit *customTextEdit, QWidget *parent)
39  : QWidget(parent)
40  , d(new KSieveUi::SieveTextEditWidgetPrivate)
41 {
42  initialize(customTextEdit);
43 }
44 
45 SieveTextEditWidget::SieveTextEditWidget(QWidget *parent)
46  : QWidget(parent)
47  , d(new KSieveUi::SieveTextEditWidgetPrivate)
48 {
49  initialize();
50 }
51 
52 SieveTextEditWidget::~SieveTextEditWidget()
53 {
54  delete d;
55 }
56 
57 void SieveTextEditWidget::initialize(KSieveUi::SieveTextEdit *custom)
58 {
59  QVBoxLayout *mainLayout = new QVBoxLayout(this);
60  mainLayout->setContentsMargins(0, 0, 0, 0);
61  if (custom) {
62  d->mTextEdit = custom;
63  } else {
64  d->mTextEdit = new KSieveUi::SieveTextEdit;
65  }
66  d->mTextEdit->setObjectName(QStringLiteral("textedit"));
67  d->mTextEdit->setShowHelpMenu(false);
68  mainLayout->addWidget(d->mTextEdit);
69 
70  d->mSliderContainer = new KPIMTextEdit::SlideContainer(this);
71  d->mSliderContainer->setObjectName(QStringLiteral("slidercontainer"));
72  d->mFindBar = new KPIMTextEdit::PlainTextEditFindBar(d->mTextEdit, this);
73  d->mFindBar->setObjectName(QStringLiteral("findbar"));
74  d->mFindBar->setHideWhenClose(false);
75  connect(d->mFindBar, &KPIMTextEdit::TextEditFindBarBase::hideFindBar, d->mSliderContainer, &KPIMTextEdit::SlideContainer::slideOut);
76  d->mSliderContainer->setContent(d->mFindBar);
77  mainLayout->addWidget(d->mSliderContainer);
78  connect(d->mTextEdit, &SieveTextEdit::findText, this, &SieveTextEditWidget::slotFind);
79  connect(d->mTextEdit, &SieveTextEdit::replaceText, this, &SieveTextEditWidget::slotReplace);
80 }
81 
82 void SieveTextEditWidget::setReadOnly(bool readOnly)
83 {
84  d->mTextEdit->setReadOnly(readOnly);
85 }
86 
87 void SieveTextEditWidget::slotReplace()
88 {
89  if (d->mTextEdit->textCursor().hasSelection()) {
90  d->mFindBar->setText(d->mTextEdit->textCursor().selectedText());
91  }
92  d->mFindBar->showReplace();
93  d->mSliderContainer->slideIn();
94  d->mFindBar->focusAndSetCursor();
95 }
96 
97 void SieveTextEditWidget::slotFind()
98 {
99  if (d->mTextEdit->textCursor().hasSelection()) {
100  d->mFindBar->setText(d->mTextEdit->textCursor().selectedText());
101  }
102  d->mTextEdit->moveCursor(QTextCursor::Start);
103  d->mFindBar->showFind();
104  d->mSliderContainer->slideIn();
105  d->mFindBar->focusAndSetCursor();
106 }
107 
108 SieveTextEdit *SieveTextEditWidget::textEdit() const
109 {
110  return d->mTextEdit;
111 }
void setContentsMargins(int left, int top, int right, int bottom)
KCRASH_EXPORT void initialize()
The SieveTextEdit class.
Definition: sievetextedit.h:33
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
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-2020 The KDE developers.
Generated on Thu Jul 9 2020 23:07:45 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.