31 #include <QWebElementCollection>
35 : ComposerEditorNG::ComposerEditor(view,parent),
38 QList<ComposerEditorNG::ComposerView::ComposerViewAction> lstActions;
39 lstActions<<ComposerEditorNG::ComposerView::Separator;
40 lstActions<<ComposerEditorNG::ComposerView::Bold;
41 lstActions<<ComposerEditorNG::ComposerView::Italic;
42 lstActions<<ComposerEditorNG::ComposerView::Underline;
43 lstActions<<ComposerEditorNG::ComposerView::StrikeOut;
44 lstActions<<ComposerEditorNG::ComposerView::Separator;
45 lstActions<<ComposerEditorNG::ComposerView::FormatType;
46 lstActions<<ComposerEditorNG::ComposerView::FontSize;
47 lstActions<<ComposerEditorNG::ComposerView::TextForegroundColor;
48 lstActions<<ComposerEditorNG::ComposerView::FormatReset;
49 lstActions<<ComposerEditorNG::ComposerView::BlockQuote;
50 lstActions<<ComposerEditorNG::ComposerView::Separator;
51 lstActions<<ComposerEditorNG::ComposerView::InsertLink;
52 lstActions<<ComposerEditorNG::ComposerView::InsertImage;
53 lstActions<<ComposerEditorNG::ComposerView::Separator;
54 lstActions<<ComposerEditorNG::ComposerView::AlignLeft;
55 lstActions<<ComposerEditorNG::ComposerView::AlignCenter;
56 lstActions<<ComposerEditorNG::ComposerView::AlignRight;
57 lstActions<<ComposerEditorNG::ComposerView::AlignJustify;
58 lstActions<<ComposerEditorNG::ComposerView::Separator;
59 lstActions<<ComposerEditorNG::ComposerView::DirectionRtl;
60 lstActions<<ComposerEditorNG::ComposerView::OrderedList;
61 lstActions<<ComposerEditorNG::ComposerView::UnorderedList;
62 lstActions<<ComposerEditorNG::ComposerView::Separator;
63 lstActions<<ComposerEditorNG::ComposerView::InsertTable;
66 QList<ComposerEditorNG::ComposerView::ComposerViewAction> toolBarActions;
67 toolBarActions<<lstActions;
69 QList<ComposerEditorNG::ComposerView::ComposerViewAction> lstActionsFormat;
70 lstActionsFormat<<ComposerEditorNG::ComposerView::SubScript;
71 lstActionsFormat<<ComposerEditorNG::ComposerView::SuperScript;
72 lstActionsFormat<<ComposerEditorNG::ComposerView::Separator;
73 lstActionsFormat<<ComposerEditorNG::ComposerView::ListIndent;
74 lstActionsFormat<<ComposerEditorNG::ComposerView::ListDedent;
75 lstActionsFormat<<ComposerEditorNG::ComposerView::Separator;
76 lstActionsFormat<<ComposerEditorNG::ComposerView::TextBackgroundColor;
79 createActions(lstActions<<ComposerEditorNG::ComposerView::PasteWithoutFormatting<<lstActionsFormat);
81 KToolBar *mainToolBar = createToolBar(toolBarActions);
84 mActSplitPost =
new KAction( KIcon( QLatin1String(
"insert-more-mark") ), i18n(
"Split text" ),
this );
85 connect( mActSplitPost, SIGNAL(triggered(
bool)),
this, SLOT(slotAddPostSplitter()) );
86 addActionInToolBar(mActSplitPost, mainToolBar);
88 mActCode =
new KAction( KIcon( QLatin1String(
"format-text-code") ), i18nc(
"Sets text font to code style",
90 connect( mActCode, SIGNAL(triggered(
bool)),
this, SLOT(slotToggleCode(
bool)) );
91 addActionInToolBar(mActCode, mainToolBar);
93 createToolBar(lstActionsFormat);
103 if (readOnly != _readOnly) {
104 readOnly = _readOnly;
105 view()->evaluateJavascript( QString::fromLatin1(
"setReadOnly(%1)" ).arg ( readOnly ? QLatin1String(
"true") : QLatin1String(
"false") ) );
112 QList< BilboMedia* > list;
113 QWebElementCollection images = view()->page()->mainFrame()->findAllElements(QLatin1String(
"img"));
114 Q_FOREACH (
const QWebElement& elm, images){
115 if (elm.attribute(QLatin1String(
"src")).startsWith(QLatin1String(
"file://"))){
118 KUrl mediaUrl (elm.attribute(QLatin1String(
"src")));
120 media->
setMimeType( KMimeType::findByUrl( mediaUrl, 0,
true )->name() );
121 media->
setName(mediaUrl.fileName());
131 const QString cmd = QString::fromLatin1(
"replaceImageSrc('%1','%2')").arg(src).arg(dest);
132 view()->evaluateJavascript(cmd);
135 void BlogiloComposerEditor::slotAddPostSplitter()
137 execCommand(QLatin1String(
"insertHTML"), QLatin1String(
"<hr/><!--split-->"));
140 void BlogiloComposerEditor::slotToggleCode(
bool )
142 const QString selection = view()->selectedText();
143 if(selection.isEmpty())
145 const QString html = QString::fromLatin1(
"<code>%1</code>" ).arg ( selection );
146 execCommand(QLatin1String(
"insertHtml"), html);
150 QString TextEditor::getHtml()
const
152 QString html =
const_cast<TextEditor*
>( this )->evaluateJavaScript(
"getHtml()",
false ).toString();
153 html.remove(
" xmlns=\"http://www.w3.org/1999/xhtml\"", Qt::CaseInsensitive);
163 void BlogiloComposerEditor::execCommand (
const QString &cmd )
165 QWebFrame *frame = view()->page()->mainFrame();
166 const QString js = QString::fromLatin1(
"document.execCommand(\"%1\", false, null)" ).arg ( cmd );
167 frame->evaluateJavaScript ( js );
170 void BlogiloComposerEditor::execCommand(
const QString &cmd,
const QString &arg )
172 QWebFrame *frame = view()->page()->mainFrame();
173 const QString js = QString::fromLatin1(
"document.execCommand(\"%1\", false, \"%2\")" ).arg ( cmd ).arg ( arg );
174 frame->evaluateJavaScript ( js );
180 #include "blogilocomposereditor.moc"
void setReadOnly(bool _readOnly)
void replaceImageSrc(const QString &src, const QString &dest)
int __currentBlogId
Global variables.
BlogiloComposerEditor(BlogiloComposerView *view, QWidget *parent)
QList< BilboMedia * > getLocalImages()