2 Copyright (c) 2012-2015 Montel Laurent <montel@kde.org>
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include "composereditor.h"
22 #include "composerview.h"
23 #include "widgets/findreplacebar.h"
27 #include "composereditorng_debug.h"
28 #include <QVBoxLayout>
31 namespace ComposerEditorNG
34 class ComposerEditorPrivate
37 ComposerEditorPrivate(ComposerEditor
*qq
)
48 QVBoxLayout
*vlay
= new QVBoxLayout
;
50 toolBarLayout
= new QVBoxLayout
;
51 toolBarLayout
->setMargin(0);
52 vlay
->addLayout(toolBarLayout
);
56 vlay
->addWidget(view
);
57 findReplaceBar
= new FindReplaceBar(view
);
58 vlay
->addWidget(findReplaceBar
);
60 q
->connect(view
, SIGNAL(showFindBar()), findReplaceBar
, SLOT(showAndFocus()));
61 q
->connect(view
, SIGNAL(openLink(QUrl
)), SIGNAL(openLink(QUrl
)));
62 q
->connect(view
->page(), SIGNAL(contentsChanged()), q
, SIGNAL(textChanged()));
65 KToolBar
*createToolBar(const QList
<ComposerView::ComposerViewAction
> &lstActions
)
67 KToolBar
*toolbar
= new KToolBar(q
);
68 toolbar
->setIconSize(QSize(22, 22));
69 toolbar
->setToolButtonStyle(Qt::ToolButtonIconOnly
);
70 toolBarLayout
->addWidget(toolbar
);
71 view
->createToolBar(lstActions
, toolbar
);
72 listToolBar
.append(toolbar
);
76 void showToolBars(bool visible
)
78 Q_FOREACH (KToolBar
*toolBar
, listToolBar
) {
79 toolBar
->setVisible(visible
);
83 QList
<KToolBar
*> listToolBar
;
84 QVBoxLayout
*toolBarLayout
;
85 FindReplaceBar
*findReplaceBar
;
92 ComposerEditor::ComposerEditor(ComposerView
*view
, QWidget
*parent
)
93 : QWidget(parent
), d(new ComposerEditorPrivate(this))
99 ComposerEditor::ComposerEditor(QWidget
*parent
)
100 : QWidget(parent
), d(new ComposerEditorPrivate(this))
102 d
->view
= new ComposerView(this);
106 ComposerEditor::~ComposerEditor()
108 //const QString content = d->view->page()->mainFrame()->toHtml();
109 //qCDebug(COMPOSEREDITORNG_LOG)<<" content :"<<content;
113 void ComposerEditor::addCreatedActionsToActionCollection(KActionCollection
*actionCollection
)
115 d
->view
->addCreatedActionsToActionCollection(actionCollection
);
118 QString
ComposerEditor::plainTextContent() const
120 return d
->view
->page()->mainFrame()->toPlainText();
123 void ComposerEditor::setEnableRichText(bool richTextEnabled
)
125 if (d
->richTextEnabled
!= richTextEnabled
) {
126 d
->richTextEnabled
= richTextEnabled
;
127 d
->view
->setActionsEnabled(d
->richTextEnabled
);
128 d
->showToolBars(d
->richTextEnabled
);
132 bool ComposerEditor::enableRichText() const
134 return d
->richTextEnabled
;
137 bool ComposerEditor::isModified() const
139 return d
->view
->page()->isModified();
142 void ComposerEditor::paste()
144 d
->view
->page()->triggerAction(QWebPage::Paste
);
147 void ComposerEditor::cut()
149 d
->view
->page()->triggerAction(QWebPage::Cut
);
152 void ComposerEditor::copy()
154 d
->view
->page()->triggerAction(QWebPage::Copy
);
157 void ComposerEditor::undo()
159 d
->view
->page()->triggerAction(QWebPage::Undo
);
162 void ComposerEditor::redo()
164 d
->view
->page()->triggerAction(QWebPage::Redo
);
167 QAction
*ComposerEditor::action(QWebPage::WebAction action
)
169 return d
->view
->page()->action(action
);
172 ComposerView
*ComposerEditor::view() const
177 void ComposerEditor::setHtmlContent(const QString
&html
)
179 d
->view
->setHtmlContent(html
);
182 QString
ComposerEditor::htmlContent() const
184 return d
->view
->page()->mainFrame()->toHtml();
187 void ComposerEditor::createActions(const QList
<ComposerView::ComposerViewAction
> &lstActions
)
189 d
->view
->createActions(lstActions
);
192 void ComposerEditor::createAllActions()
194 d
->view
->createAllActions();
197 KToolBar
*ComposerEditor::createToolBar(const QList
<ComposerView::ComposerViewAction
> &lstActions
)
199 return d
->createToolBar(lstActions
);
202 void ComposerEditor::addActionInToolBar(QAction
*act
, KToolBar
*toolbar
)
205 toolbar
->addAction(act
);
209 QList
<KToolBar
*> ComposerEditor::toolbars() const
211 return d
->listToolBar
;
214 QMap
<QString
, QString
> ComposerEditor::localImages() const
216 return d
->view
->localImages();