Skip to content
Permalink
Browse files
enable clicking links in Preview
  • Loading branch information
kevinhendricks committed Mar 28, 2018
1 parent 1fc4f62 commit 15c84166d6c2b7a68be59fd3d96f3a402c364fa6
Showing with 36 additions and 16 deletions.
  1. +1 −0 ChangeLog.txt
  2. +1 −1 src/MainUI/MainWindow.cpp
  3. +25 −2 src/MainUI/PreviewWindow.cpp
  4. +8 −1 src/MainUI/PreviewWindow.h
  5. +1 −9 src/ViewEditors/BookViewPreview.cpp
  6. +0 −3 src/ViewEditors/BookViewPreview.h
@@ -15,6 +15,7 @@ Sigil-pre0.9.10
- extend Insert->Special Characters to include both a Greek letter panel and a mathematical symbol panel
- add support for calibre:series and calibre:series_index to Metadata Editor for epub2
- add support for calibre:title_sort to Metadata Editor for epub2
- add support for clicking internal links in Preview to load the proper destination tab


Sigil-0.9.9
@@ -4767,9 +4767,9 @@ void MainWindow::LoadInitialFile(const QString &openfilepath, bool is_internal)
void MainWindow::ConnectSignalsToSlots()
{
connect(m_PreviewWindow, SIGNAL(Shown()), this, SLOT(UpdatePreview()));
connect(m_PreviewWindow, SIGNAL(GoToPreviewLocationRequest()), this, SLOT(GoToPreviewLocation()));
connect(m_PreviewWindow, SIGNAL(ZoomFactorChanged(float)), this, SLOT(UpdateZoomLabel(float)));
connect(m_PreviewWindow, SIGNAL(ZoomFactorChanged(float)), this, SLOT(UpdateZoomSlider(float)));
connect(m_PreviewWindow, SIGNAL(OpenUrlRequest(const QUrl &)), this, SLOT(OpenUrl(const QUrl &)));
connect(qApp, SIGNAL(focusChanged(QWidget *, QWidget *)), this, SLOT(ApplicationFocusChanged(QWidget *, QWidget *)));
// Setup signal mapping for heading actions.
connect(ui.actionHeading1, SIGNAL(triggered()), m_headingMapper, SLOT(map()));
@@ -45,7 +45,8 @@ PreviewWindow::PreviewWindow(QWidget *parent)
m_Preview(new BookViewPreview(this)),
m_Inspector(new QWebInspector(this)),
m_Splitter(new QSplitter(this)),
m_StackedViews(new QStackedWidget(this))
m_StackedViews(new QStackedWidget(this)),
m_Filepath(QString())
{
SetupView();
LoadSettings();
@@ -228,6 +229,7 @@ void PreviewWindow::UpdatePage(QString filename, QString text, QList<ViewEditor:
}
}

m_Filepath = filename;
m_Preview->CustomSetDocument(filename, text);

// Wait until the preview is loaded before moving cursor.
@@ -272,6 +274,27 @@ void PreviewWindow::SplitterMoved(int pos, int index)
UpdateWindowTitle();
}

void PreviewWindow::LinkClicked(const QUrl &url)
{
if (url.toString().isEmpty()) {
return;
}

QFileInfo finfo(m_Filepath);
QString url_string = url.toString();

// Convert fragments to full filename/fragments
if (url_string.startsWith("#")) {
url_string.prepend(finfo.fileName());
} else if (url.scheme() == "file") {
if (url_string.contains("/#")) {
url_string.insert(url_string.indexOf("/#") + 1, finfo.fileName());
}
}

emit OpenUrlRequest(QUrl(url_string));
}

void PreviewWindow::LoadSettings()
{
SettingsStore settings;
@@ -283,7 +306,7 @@ void PreviewWindow::LoadSettings()
void PreviewWindow::ConnectSignalsToSlots()
{
connect(m_Splitter, SIGNAL(splitterMoved(int, int)), this, SLOT(SplitterMoved(int, int)));
connect(m_Preview, SIGNAL(GoToPreviewLocationRequest()), this, SIGNAL(GoToPreviewLocationRequest()));
connect(m_Preview, SIGNAL(ZoomFactorChanged(float)), this, SIGNAL(ZoomFactorChanged(float)));
connect(m_Preview, SIGNAL(LinkClicked(const QUrl &)), this, SLOT(LinkClicked(const QUrl &)));
}

@@ -48,11 +48,17 @@ public slots:
void UpdatePage(QString filename, QString text, QList<ViewEditor::ElementIndex> location);
void SetZoomFactor(float factor);
void SplitterMoved(int pos, int index);
void LinkClicked(const QUrl &url);

signals:
void Shown();
void GoToPreviewLocationRequest();
void ZoomFactorChanged(float factor);
/**
* Emitted whenever Preview wants to open an URL.
* @param url The URL to open.
*/
void OpenUrlRequest(const QUrl &url);


protected:
virtual void hideEvent(QHideEvent* event);
@@ -72,6 +78,7 @@ public slots:
QWebInspector *m_Inspector;
QSplitter *m_Splitter;
QStackedWidget *m_StackedViews;
QString m_Filepath;
};

#endif // PREVIEWWINDOW_H
@@ -204,14 +204,6 @@ void BookViewPreview::UpdateDisplay()
}
}

void BookViewPreview::mouseReleaseEvent(QMouseEvent *event)
{
// Propagate to base class
QWebView::mouseReleaseEvent(event);

emit GoToPreviewLocationRequest();
}

void BookViewPreview::ScrollToTop()
{
QString caret_location = "var elementList = document.getElementsByTagName(\"body\");"
@@ -776,6 +768,6 @@ void BookViewPreview::ConnectSignalsToSlots()
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(OpenContextMenu(const QPoint &)));
connect(m_InspectElement, SIGNAL(triggered()), this, SLOT(InspectElement()));
connect(page(), SIGNAL(loadFinished(bool)), this, SLOT(UpdateFinishedState(bool)));
connect(page(), SIGNAL(linkClicked(const QUrl &)), SIGNAL(LinkClicked(const QUrl &)));
connect(page(), SIGNAL(linkClicked(const QUrl &)), this, SIGNAL(LinkClicked(const QUrl &)));
connect(page(), SIGNAL(loadFinished(bool)), this, SLOT(WebPageJavascriptOnLoad()));
}
@@ -146,11 +146,8 @@ public slots:

void DocumentLoaded();

void GoToPreviewLocationRequest();

protected:
void mouseReleaseEvent(QMouseEvent *event);

/**
* Evaluates the provided javascript source code
* and returns the result.

0 comments on commit 15c8416

Please sign in to comment.