Closed GoogleCodeExporter closed 9 years ago
Okay - so I did some debugging in Latest source code 0.7.3 git clone (from
Oct-24-2013) and here are some of my findings:
---> Keyboard-Shortcut Paste function (CTRL+V or SHIFT+Insert) goes around the
Sigil application and is directly handled by the QT5 library I guess ... this
is causing the clipboard HTML formatting data are pasted to the eBook HTML
according to what you have inserted from another application -> thus causing
mess in your eBook HTML code
=> quick workaround : redirect the CTRL+V and SHIFT-Insert shortcuts on app level and direct them to the same functionality which Sigil uses to Paste to the BookView (menu entry Edit -> Paste, Edit -> Paste from Clipoard History) - see below.
=> THIS WILL ALIGN THE PASTE FUNCTION TO BEHAVE CONSISTENTLY IN SIGIL. IN CURRENT CODCE THIS IS NOT DONE AND THIS ALLOWS UNCONTROLLED FORMATTING DATA TO SNEAK INTO SIGIL GENERATED HTML
=> BUG: In addition - because the keyboard shortcuts are not handled by Sigil -> Undo functionality doesn't work with them
---> Menu entry Edit -> Paste, Edit -> Paste from Clipboard History-> is
processed by coding:
---> For Code View (HTML) - file CodeViewEditor.cpp (line 1973)
void CodeViewEditor::PasteText(const QString &text)
{
InsertText(text);
}
function InsertText:
void CodeViewEditor::InsertText(const QString &text)
{
QTextCursor c = textCursor();
c.insertText(text);
setTextCursor(c);
}
---> For Book View (WYSIWYG) - file BookViewEditor.Cpp (line 626)
void BookViewEditor::paste()
{
page()->triggerAction(QWebPage::Paste);
}
================================ DISCUSSION ================================
Even if the Paste function is processed by Sigil code. There is stile some
nasty HTML code being pasted, in my example I tried I got this included as
additional formatting info: <span style="font-family: 'Times New Roman', serif;
font-size: 12pt;">
Which was much better comparing what I got if I used same clipoard data and
used CTRL+V Paste function.
Question 1 - what would QT5 action - QWebPage::PasteAndMatchStyle - do if used
??? Is it trying to mathc best existing CSS style ???
Question 2 - if we use the pure "Text" Paste from the CodeViewEditor - we will
loose formatting data I guess but maybe the whole user experienece would be
better as we do not want to primarily incldue external formatting information
into our eBook ...
Will continue looking into it ...
Original comment by cal...@gmail.com
on 25 Oct 2013 at 11:09
Ok ... the old function
void BookViewEditor::paste()
{
page()->triggerAction(QWebPage::Paste);
}
if replaced by following code:
class QMessageBoxResize: public QMessageBox
{
public:
QMessageBoxResize() {
setMouseTracking(true);
setSizeGripEnabled(true);
}
private:
virtual bool event(QEvent *e) {
bool res = QMessageBox::event(e);
switch (e->type()) {
case QEvent::MouseMove:
case QEvent::MouseButtonPress:
setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
if (QWidget *textEdit = findChild<QTextEdit *>()) {
textEdit->setMaximumHeight(QWIDGETSIZE_MAX);
}
}
return res;
}
};
void BookViewEditor::paste()
{
// original clipboard format including foreign formatting info:
// page()->triggerAction(QWebPage::Paste);
// text only (ignore foreign formatting info) -> better formatting for eBook editing
// page()->triggerAction(QWebPage::PasteAndMatchStyle);
QClipboard *clipboard = QApplication::clipboard();
if ( clipboard->mimeData()->hasHtml() )
{
// allow resize function to see whole HTML in the Detailed text window
// doesn't work:
// QMessageBox msgBox;
// msgBox.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// msgBox.setSizeGripEnabled(true);
// so using QMessageBoxResize override:
QMessageBoxResize msgBox;
msgBox.setIcon(QMessageBox::Question);
msgBox.setText("Clipboard contains HTML formatting.");
msgBox.setInformativeText("Do you want to paste clipboard data as plain text instead?");
msgBox.setStandardButtons(QMessageBox::Yes| QMessageBox::No| QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Yes);
// populate the detailed text window - by HTML not by the text
msgBox.setDetailedText(clipboard->mimeData()->html());
// show message box
int ret = msgBox.exec();
switch (ret) {
case QMessageBox::Yes:
// Yes was clicked
page()->triggerAction(QWebPage::PasteAndMatchStyle);
break;
case QMessageBox::No:
// No was clicked
page()->triggerAction(QWebPage::Paste);
break;
case QMessageBox::Cancel:
// Cancel was clicked - do nothing
break;
default:
// should never be reached
break;
}
} else {
page()->triggerAction(QWebPage::Paste);
}
}
allows to change the paste function behavior override, it works as this:
If HTML formatted code is contained in the clipboard - a newly added message
box is shown to user allowing the end user to decide whether he wants to either
paste only text without the formatting data - default choice - (invoking
QWebPage::PasteAndMatchStyle) or whether end user want's to continue with
pasting the original HTML formatted code. User has also option to use button
Show details to see the HTML content of the clipboard in resize-able MessageBox.
In addition to allow CTLR+V, Command+V and SHIFT+Insert key shortcuts to work
same way as the conext menu and main menu entries - Paste - additional changes
are needed to be done to BookViewEditor.h and BookViewEditor.cpp.
Original comment by cal...@gmail.com
on 29 Oct 2013 at 4:58
Have created user-none pull request to include the changes into the main Sigil
repository.
https://github.com/user-none/Sigil/pull/8
Original comment by cal...@gmail.com
on 29 Oct 2013 at 5:13
Original comment by john@nachtimwald.com
on 3 Nov 2013 at 2:26
Original issue reported on code.google.com by
cal...@gmail.com
on 23 Oct 2013 at 11:02