|
@@ -83,6 +83,16 @@ FbTextPage::FbTextPage(QObject *parent)
|
|
s->setAttribute(QWebSettings::PluginsEnabled, false);
|
|
s->setAttribute(QWebSettings::PluginsEnabled, false);
|
|
s->setAttribute(QWebSettings::ZoomTextOnly, true);
|
|
s->setAttribute(QWebSettings::ZoomTextOnly, true);
|
|
s->setUserStyleSheetUrl(QUrl::fromLocalFile(":style.css"));
|
|
s->setUserStyleSheetUrl(QUrl::fromLocalFile(":style.css"));
|
|
|
|
+
|
|
|
|
+ setContentEditable(true);
|
|
|
|
+ setNetworkAccessManager(new FbNetworkAccessManager(this));
|
|
|
|
+ connect(this, SIGNAL(loadFinished(bool)), SLOT(loadFinished()));
|
|
|
|
+ connect(this, SIGNAL(contentsChanged()), SLOT(fixContents()));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+FbNetworkAccessManager *FbTextPage::temp()
|
|
|
|
+{
|
|
|
|
+ return qobject_cast<FbNetworkAccessManager*>(networkAccessManager());
|
|
}
|
|
}
|
|
|
|
|
|
bool FbTextPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type)
|
|
bool FbTextPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type)
|
|
@@ -300,6 +310,20 @@ QString FbTextPage::status()
|
|
return mainFrame()->evaluateJavaScript(javascript).toString();
|
|
return mainFrame()->evaluateJavaScript(javascript).toString();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void FbTextPage::loadFinished()
|
|
|
|
+{
|
|
|
|
+ FbTextElement element = body().findFirst("div.body");
|
|
|
|
+ if (element.isNull()) element = body();
|
|
|
|
+ element.select();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void FbTextPage::fixContents()
|
|
|
|
+{
|
|
|
|
+ foreach (QWebElement span, doc().findAll("span.apple-style-span[style]")) {
|
|
|
|
+ span.removeAttribute("style");
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
//---------------------------------------------------------------------------
|
|
//---------------------------------------------------------------------------
|
|
// FbTextBase
|
|
// FbTextBase
|
|
//---------------------------------------------------------------------------
|
|
//---------------------------------------------------------------------------
|
|
@@ -382,16 +406,10 @@ void FbTextBase::addTools(QToolBar *tool)
|
|
|
|
|
|
FbTextEdit::FbTextEdit(QWidget *parent)
|
|
FbTextEdit::FbTextEdit(QWidget *parent)
|
|
: FbTextBase(parent)
|
|
: FbTextBase(parent)
|
|
- , m_files(this)
|
|
|
|
, m_noteView(0)
|
|
, m_noteView(0)
|
|
, m_thread(0)
|
|
, m_thread(0)
|
|
{
|
|
{
|
|
setPage(new FbTextPage(this));
|
|
setPage(new FbTextPage(this));
|
|
- page()->setNetworkAccessManager(&m_files);
|
|
|
|
- page()->setContentEditable(true);
|
|
|
|
- connect(page(), SIGNAL(contentsChanged()), this, SLOT(fixContents()));
|
|
|
|
- connect(page(), SIGNAL(linkHovered(QString,QString,QString)), this, SLOT(linkHovered(QString,QString,QString)));
|
|
|
|
- connect(this, SIGNAL(loadFinished(bool)), SLOT(loadFinished()));
|
|
|
|
}
|
|
}
|
|
|
|
|
|
FbTextEdit::~FbTextEdit()
|
|
FbTextEdit::~FbTextEdit()
|
|
@@ -399,11 +417,16 @@ FbTextEdit::~FbTextEdit()
|
|
if (m_noteView) delete m_noteView;
|
|
if (m_noteView) delete m_noteView;
|
|
}
|
|
}
|
|
|
|
|
|
-FbTextPage * FbTextEdit::page()
|
|
|
|
|
|
+FbTextPage *FbTextEdit::page()
|
|
{
|
|
{
|
|
return qobject_cast<FbTextPage*>(FbTextBase::page());
|
|
return qobject_cast<FbTextPage*>(FbTextBase::page());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+FbNetworkAccessManager *FbTextEdit::files()
|
|
|
|
+{
|
|
|
|
+ return page()->temp();
|
|
|
|
+}
|
|
|
|
+
|
|
FbNoteView & FbTextEdit::noteView()
|
|
FbNoteView & FbTextEdit::noteView()
|
|
{
|
|
{
|
|
if (m_noteView) return *m_noteView;
|
|
if (m_noteView) return *m_noteView;
|
|
@@ -425,13 +448,6 @@ QWebElement FbTextEdit::doc()
|
|
return page()->mainFrame()->documentElement();
|
|
return page()->mainFrame()->documentElement();
|
|
}
|
|
}
|
|
|
|
|
|
-void FbTextEdit::fixContents()
|
|
|
|
-{
|
|
|
|
- foreach (QWebElement span, doc().findAll("span.apple-style-span[style]")) {
|
|
|
|
- span.removeAttribute("style");
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
void FbTextEdit::mouseMoveEvent(QMouseEvent *event)
|
|
void FbTextEdit::mouseMoveEvent(QMouseEvent *event)
|
|
{
|
|
{
|
|
m_point = event->pos();
|
|
m_point = event->pos();
|
|
@@ -473,13 +489,27 @@ void FbTextEdit::load(const QString &filename, const QString &xml)
|
|
if (m_thread) return;
|
|
if (m_thread) return;
|
|
m_thread = new FbReadThread(this, filename, xml);
|
|
m_thread = new FbReadThread(this, filename, xml);
|
|
FbTextPage *page = new FbTextPage(m_thread);
|
|
FbTextPage *page = new FbTextPage(m_thread);
|
|
- FbNetworkAccessManager *temp = new FbNetworkAccessManager(page);
|
|
|
|
- page->setNetworkAccessManager(temp);
|
|
|
|
m_thread->setPage(page);
|
|
m_thread->setPage(page);
|
|
- m_thread->setTemp(temp);
|
|
|
|
|
|
+ m_thread->setTemp(page->temp());
|
|
m_thread->start();
|
|
m_thread->start();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void FbTextEdit::html(QString html)
|
|
|
|
+{
|
|
|
|
+ if (!m_thread) return;
|
|
|
|
+ static int number = 0;
|
|
|
|
+ QWebSettings::clearMemoryCaches();
|
|
|
|
+ QUrl url(QString("fb2:/%1/").arg(number++));
|
|
|
|
+ FbTextPage *page = m_thread->page();
|
|
|
|
+ setPage(page);
|
|
|
|
+ page->setParent(this);
|
|
|
|
+ page->temp()->setPath(url.path());
|
|
|
|
+ setHtml(html, url);
|
|
|
|
+ connect(page, SIGNAL(linkHovered(QString,QString,QString)), SLOT(linkHovered(QString,QString,QString)));
|
|
|
|
+ m_thread->deleteLater();
|
|
|
|
+ m_thread = 0;
|
|
|
|
+}
|
|
|
|
+
|
|
bool FbTextEdit::save(QIODevice *device, const QString &codec)
|
|
bool FbTextEdit::save(QIODevice *device, const QString &codec)
|
|
{
|
|
{
|
|
FbSaveWriter writer(*this, device);
|
|
FbSaveWriter writer(*this, device);
|
|
@@ -507,15 +537,7 @@ bool FbTextEdit::save(QString *string)
|
|
|
|
|
|
void FbTextEdit::data(QString name, QByteArray data)
|
|
void FbTextEdit::data(QString name, QByteArray data)
|
|
{
|
|
{
|
|
- files().data(name, data);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void FbTextEdit::html(QString html)
|
|
|
|
-{
|
|
|
|
- static int number = 0;
|
|
|
|
- setHtml(html, QUrl(QString("fb2:/%1/").arg(number++)));
|
|
|
|
- if (m_thread) m_thread->deleteLater();
|
|
|
|
- m_thread = 0;
|
|
|
|
|
|
+ files()->data(name, data);
|
|
}
|
|
}
|
|
|
|
|
|
void FbTextEdit::zoomIn()
|
|
void FbTextEdit::zoomIn()
|
|
@@ -602,7 +624,7 @@ void FbTextEdit::insertImage()
|
|
if (!file.open(QIODevice::ReadOnly)) return;
|
|
if (!file.open(QIODevice::ReadOnly)) return;
|
|
|
|
|
|
QByteArray data = file.readAll();
|
|
QByteArray data = file.readAll();
|
|
- QString name = files().add(path, data);
|
|
|
|
|
|
+ QString name = files()->add(path, data);
|
|
execCommand("insertImage", name.prepend("#"));
|
|
execCommand("insertImage", name.prepend("#"));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -625,13 +647,6 @@ void FbTextEdit::execCommand(const QString &cmd, const QString &arg)
|
|
page()->mainFrame()->evaluateJavaScript(javascript);
|
|
page()->mainFrame()->evaluateJavaScript(javascript);
|
|
}
|
|
}
|
|
|
|
|
|
-void FbTextEdit::loadFinished()
|
|
|
|
-{
|
|
|
|
- FbTextElement element = body().findFirst("div.body");
|
|
|
|
- if (element.isNull()) element = body();
|
|
|
|
- element.select();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
//---------------------------------------------------------------------------
|
|
//---------------------------------------------------------------------------
|
|
// FbTextFrame
|
|
// FbTextFrame
|
|
//---------------------------------------------------------------------------
|
|
//---------------------------------------------------------------------------
|