Fixed UI crash by replacing snippets QDialog with a QWidget...

This commit is contained in:
Jean-Francois Dockes 2012-10-29 18:47:10 +01:00
parent 98ba87f024
commit 09ff4ef393
2 changed files with 58 additions and 21 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>Snippets</class> <class>Snippets</class>
<widget class="QDialog" name="Snippets"> <widget class="QWidget" name="Snippets">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
@ -13,14 +13,11 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Snippets</string> <string>Snippets</string>
</property> </property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QWebView" name="webView"> <widget class="QWebView" name="browser">
<property name="url"> <property name="url">
<url> <url>
<string>about:blank</string> <string>about:blank</string>

View file

@ -16,6 +16,11 @@
*/ */
#include "autoconfig.h" #include "autoconfig.h"
// Use textBrowser or webview. Tried using textbrowser to solve a
// crash at a point, kept the code. Search did not work, but this
// should be easy to fix by looking at the preview code.
#define SNIPPETS_WEBKIT
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
@ -24,8 +29,12 @@
#include <sstream> #include <sstream>
using namespace std; using namespace std;
#ifdef SNIPPETS_WEBKIT
#include <QWebSettings> #include <QWebSettings>
#include <QWebFrame> #include <QWebFrame>
#else
#include <QTextBrowser>
#endif
#include <QShortcut> #include <QShortcut>
#include "debuglog.h" #include "debuglog.h"
@ -56,9 +65,6 @@ void SnippetsW::init()
return; return;
searchFM->hide(); searchFM->hide();
webView->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal,
Qt::ScrollBarAlwaysOff);
new QShortcut(QKeySequence::Find, this, SLOT(slotEditFind())); new QShortcut(QKeySequence::Find, this, SLOT(slotEditFind()));
new QShortcut(QKeySequence(Qt::Key_Slash), this, SLOT(slotEditFind())); new QShortcut(QKeySequence(Qt::Key_Slash), this, SLOT(slotEditFind()));
@ -70,9 +76,32 @@ void SnippetsW::init()
connect(nextPB, SIGNAL(clicked()), this, SLOT(slotEditFindNext())); connect(nextPB, SIGNAL(clicked()), this, SLOT(slotEditFindNext()));
new QShortcut(QKeySequence(Qt::Key_F3), this, SLOT(slotEditFindNext())); new QShortcut(QKeySequence(Qt::Key_F3), this, SLOT(slotEditFindNext()));
connect(prevPB, SIGNAL(clicked()), this, SLOT(slotEditFindPrevious())); connect(prevPB, SIGNAL(clicked()), this, SLOT(slotEditFindPrevious()));
connect(webView, SIGNAL(linkClicked(const QUrl &)),
#ifdef SNIPPETS_WEBKIT
connect(browser, SIGNAL(linkClicked(const QUrl &)),
this, SLOT(linkWasClicked(const QUrl &))); this, SLOT(linkWasClicked(const QUrl &)));
webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); browser->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
browser->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal,
Qt::ScrollBarAlwaysOff);
QWebSettings *ws = browser->page()->settings();
if (prefs.reslistfontfamily != "") {
ws->setFontFamily(QWebSettings::StandardFont, prefs.reslistfontfamily);
ws->setFontSize(QWebSettings::DefaultFontSize, prefs.reslistfontsize);
}
#else
connect(browser, SIGNAL(anchorClicked(const QUrl &)),
this, SLOT(linkWasClicked(const QUrl &)));
browser->setReadOnly(TRUE);
browser->setUndoRedoEnabled(FALSE);
browser->setOpenLinks(FALSE);
browser->setTabChangesFocus(true);
if (prefs.reslistfontfamily.length()) {
QFont nfont(prefs.reslistfontfamily, prefs.reslistfontsize);
browser->setFont(nfont);
} else {
browser->setFont(QFont());
}
#endif
// Make title out of file name if none yet // Make title out of file name if none yet
string titleOrFilename; string titleOrFilename;
@ -116,14 +145,11 @@ void SnippetsW::init()
oss << "</td><td>" << lr.front().c_str() << "</td></tr>" << endl; oss << "</td><td>" << lr.front().c_str() << "</td></tr>" << endl;
} }
oss << "</body></html>"; oss << "</body></html>";
#ifdef SNIPPETS_WEBKIT
QWebSettings *ws = webView->page()->settings(); browser->setHtml(QString::fromUtf8(oss.str().c_str()));
if (prefs.reslistfontfamily != "") { #else
ws->setFontFamily(QWebSettings::StandardFont, prefs.reslistfontfamily); browser->insertHtml(QString::fromUtf8(oss.str().c_str()));
ws->setFontSize(QWebSettings::DefaultFontSize, prefs.reslistfontsize); #endif
}
webView->setHtml(QString::fromUtf8(oss.str().c_str()));
} }
void SnippetsW::slotEditFind() void SnippetsW::slotEditFind()
@ -132,17 +158,31 @@ void SnippetsW::slotEditFind()
searchLE->selectAll(); searchLE->selectAll();
searchLE->setFocus(); searchLE->setFocus();
} }
void SnippetsW::slotEditFindNext() void SnippetsW::slotEditFindNext()
{ {
webView->findText(searchLE->text()); #ifdef SNIPPETS_WEBKIT
browser->findText(searchLE->text());
#else
browser->find(searchLE->text(), 0);
#endif
} }
void SnippetsW::slotEditFindPrevious() void SnippetsW::slotEditFindPrevious()
{ {
webView->findText(searchLE->text(), QWebPage::FindBackward); #ifdef SNIPPETS_WEBKIT
browser->findText(searchLE->text(), QWebPage::FindBackward);
#else
browser->find(searchLE->text(), QTextDocument::FindBackward);
#endif
} }
void SnippetsW::slotSearchTextChanged(const QString& txt) void SnippetsW::slotSearchTextChanged(const QString& txt)
{ {
webView->findText(txt); #ifdef SNIPPETS_WEBKIT
browser->findText(txt);
#else
browser->find(txt, 0);
#endif
} }
void SnippetsW::linkWasClicked(const QUrl &url) void SnippetsW::linkWasClicked(const QUrl &url)