From 471ac7ba1f5ff73cd3055cf35614b726e4178364 Mon Sep 17 00:00:00 2001 From: nowrep Date: Fri, 16 Mar 2012 23:28:23 +0100 Subject: [PATCH] Fixed building with NONBLOCK_JS_DIALOGS + other small fixes. --- src/lib/app/mainapplication.cpp | 8 ++++---- src/lib/downloads/downloaditem.cpp | 2 ++ src/lib/other/sourceviewer.cpp | 13 ++++++------- src/lib/tools/plaineditwithlines.cpp | 23 +++++++++++++++++++---- src/lib/tools/plaineditwithlines.h | 4 ++++ src/lib/webview/tabwidget.cpp | 14 ++++++++++++-- src/lib/webview/tabwidget.h | 2 +- src/lib/webview/webpage.cpp | 13 ++++++++----- 8 files changed, 56 insertions(+), 23 deletions(-) diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index bf0d17542..84abbb79b 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -155,8 +155,8 @@ MainApplication::MainApplication(const QList &cm m_postLaunchActions.append(PrivateBrowsing); break; case Qz::CL_OpenUrl: - startUrl = QUrl::fromEncoded(pair.text.toUtf8()); - messages.append("URL:" + startUrl.toString()); + startUrl = QUrl(pair.text.toUtf8()); + messages.append("URL:" + pair.text); break; default: break; @@ -440,8 +440,8 @@ void MainApplication::receiveAppMessage(QString message) { QWidget* actWin = getWindow(); if (message.startsWith("URL:")) { - QString url(message.remove("URL:")); - addNewTab(QUrl::fromUserInput(url)); + QUrl url = QUrl::fromEncoded(message.mid(4).toUtf8()); + addNewTab(url); actWin = getWindow(); } else if (message.startsWith("ACTION:")) { diff --git a/src/lib/downloads/downloaditem.cpp b/src/lib/downloads/downloaditem.cpp index 3b552c92a..09812b0c6 100644 --- a/src/lib/downloads/downloaditem.cpp +++ b/src/lib/downloads/downloaditem.cpp @@ -145,6 +145,8 @@ void DownloadItem::finished() ui->frame->hide(); m_outputFile.close(); + m_reply->deleteLater(); + m_item->setSizeHint(sizeHint()); #if QT_VERSION == 0x040700 // Workaround ui->button->show(); diff --git a/src/lib/other/sourceviewer.cpp b/src/lib/other/sourceviewer.cpp index 178193c57..7689893d5 100644 --- a/src/lib/other/sourceviewer.cpp +++ b/src/lib/other/sourceviewer.cpp @@ -48,6 +48,7 @@ SourceViewer::SourceViewer(QWebFrame* frame, const QString &selectedHtml) m_statusBar = new QStatusBar(this); m_statusBar->showMessage(frame->url().toString()); + QMenuBar* menuBar = new QMenuBar(this); m_layout->addWidget(m_sourceEdit); m_layout->addWidget(m_statusBar); @@ -55,8 +56,6 @@ SourceViewer::SourceViewer(QWebFrame* frame, const QString &selectedHtml) m_layout->setSpacing(0); m_layout->setMenuBar(menuBar); - resize(650, 600); - QFont font; font.setFamily("Tahoma"); font.setFixedPitch(true); @@ -65,6 +64,9 @@ SourceViewer::SourceViewer(QWebFrame* frame, const QString &selectedHtml) m_sourceEdit->setFont(font); new HtmlHighlighter(m_sourceEdit->document()); + resize(650, 600); + qz_centerWidgetToParent(this, frame->page()->view()); + QMenu* menuFile = new QMenu(tr("File")); menuFile->addAction(QIcon::fromTheme("document-save"), tr("Save as..."), this, SLOT(save()))->setShortcut(QKeySequence("Ctrl+S")); menuFile->addSeparator(); @@ -99,8 +101,6 @@ SourceViewer::SourceViewer(QWebFrame* frame, const QString &selectedHtml) menuView->actions().at(3)->setChecked(true); menuBar->addMenu(menuView); - qz_centerWidgetToParent(this, frame->page()->view()); - connect(m_sourceEdit, SIGNAL(copyAvailable(bool)), this, SLOT(copyAvailable(bool))); connect(m_sourceEdit, SIGNAL(redoAvailable(bool)), this, SLOT(redoAvailable(bool))); connect(m_sourceEdit, SIGNAL(undoAvailable(bool)), this, SLOT(undoAvailable(bool))); @@ -144,9 +144,8 @@ void SourceViewer::loadSource() if (!m_selectedHtml.isEmpty()) { m_sourceEdit->find(m_selectedHtml, QTextDocument::FindWholeWords); } - else { - m_sourceEdit->moveCursor(QTextCursor::Start); - } + + m_sourceEdit->setShowingCursor(true); } void SourceViewer::save() diff --git a/src/lib/tools/plaineditwithlines.cpp b/src/lib/tools/plaineditwithlines.cpp index 6d9e2b0ce..23466e0ba 100644 --- a/src/lib/tools/plaineditwithlines.cpp +++ b/src/lib/tools/plaineditwithlines.cpp @@ -62,6 +62,7 @@ PlainEditWithLines::PlainEditWithLines(QWidget* parent) : QPlainTextEdit(parent) , m_lineNumberArea(new LineNumberArea(this)) + , m_isShowingCursor(false) , m_countCache(-1, -1) { connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); @@ -86,6 +87,16 @@ int PlainEditWithLines::lineNumberAreaWidth() return space; } +void PlainEditWithLines::setShowingCursor(bool show) +{ + m_isShowingCursor = show; +} + +bool PlainEditWithLines::isShowingCursor() const +{ + return m_isShowingCursor; +} + void PlainEditWithLines::setReadOnly(bool ro) { QPlainTextEdit::setReadOnly(ro); @@ -138,17 +149,21 @@ void PlainEditWithLines::resizeEvent(QResizeEvent* e) void PlainEditWithLines::highlightCurrentLine() { - QList extraSelections; + if (!m_isShowingCursor) { + return; + } + + const QColor &lineColor = palette().color(QPalette::Highlight).lighter(); + QList selectionsList; QTextEdit::ExtraSelection selection; - QColor lineColor = palette().color(QPalette::Highlight).lighter(); selection.format.setBackground(lineColor); selection.format.setProperty(QTextFormat::FullWidthSelection, true); selection.cursor = textCursor(); selection.cursor.clearSelection(); - extraSelections.append(selection); + selectionsList.append(selection); - setExtraSelections(extraSelections); + setExtraSelections(selectionsList); } void PlainEditWithLines::lineNumberAreaPaintEvent(QPaintEvent* event) diff --git a/src/lib/tools/plaineditwithlines.h b/src/lib/tools/plaineditwithlines.h index fdfa369e3..4d527324a 100644 --- a/src/lib/tools/plaineditwithlines.h +++ b/src/lib/tools/plaineditwithlines.h @@ -79,6 +79,9 @@ public: void lineNumberAreaPaintEvent(QPaintEvent* event); int lineNumberAreaWidth(); + void setShowingCursor(bool show); + bool isShowingCursor() const; + void setReadOnly(bool ro); public slots: @@ -95,6 +98,7 @@ private slots: private: QWidget* m_lineNumberArea; + bool m_isShowingCursor; QPair m_countCache; }; diff --git a/src/lib/webview/tabwidget.cpp b/src/lib/webview/tabwidget.cpp index ebf4bff02..c9ccaba1b 100644 --- a/src/lib/webview/tabwidget.cpp +++ b/src/lib/webview/tabwidget.cpp @@ -82,6 +82,7 @@ TabWidget::TabWidget(QupZilla* mainClass, QWidget* parent) , m_lastTabIndex(0) , m_lastBackgroundTabIndex(-1) , m_isClosingToLastTabIndex(false) + , m_isRestoringState(false) , m_closedTabsManager(new ClosedTabsManager) , m_locationBars(new QStackedWidget) { @@ -376,7 +377,7 @@ void TabWidget::closeTab(int index) void TabWidget::currentTabChanged(int index) { - if (index < 0) { + if (index < 0 || m_isRestoringState) { return; } @@ -516,12 +517,13 @@ int TabWidget::duplicateTab(int index) WebTab* webTab = weTab(index); const QUrl &url = webTab->url(); + const QString &title = webTab->title(); const QByteArray &history = webTab->historyData(); QNetworkRequest req(url); req.setRawHeader("Referer", url.toEncoded()); - int id = addView(req, tabText(index), Qz::NT_CleanNotSelectedTab); + int id = addView(req, title, Qz::NT_CleanNotSelectedTab); weTab(id)->setHistoryData(history); return id; @@ -661,6 +663,8 @@ void TabWidget::restorePinnedTabs() QList tabHistory; stream >> tabHistory; + m_isRestoringState = true; + for (int i = 0; i < pinnedTabs.count(); ++i) { QUrl url = QUrl::fromEncoded(pinnedTabs.at(i).toUtf8()); @@ -686,6 +690,8 @@ void TabWidget::restorePinnedTabs() m_tabBar->updateCloseButton(addedIndex); m_tabBar->moveTab(addedIndex, i); } + + m_isRestoringState = false; } QByteArray TabWidget::saveState() @@ -728,6 +734,8 @@ bool TabWidget::restoreState(const QByteArray &state) stream >> tabListCount; + m_isRestoringState = true; + for (int i = 0; i < tabListCount; ++i) { WebTab::SavedTab tab; stream >> tab; @@ -738,6 +746,8 @@ bool TabWidget::restoreState(const QByteArray &state) stream >> currentTab; + m_isRestoringState = false; + setCurrentIndex(currentTab); currentTabChanged(currentTab); diff --git a/src/lib/webview/tabwidget.h b/src/lib/webview/tabwidget.h index 4af713b46..6c8fdfcb8 100644 --- a/src/lib/webview/tabwidget.h +++ b/src/lib/webview/tabwidget.h @@ -131,9 +131,9 @@ private: int m_lastTabIndex; int m_lastBackgroundTabIndex; bool m_isClosingToLastTabIndex; + bool m_isRestoringState; TabBar* m_tabBar; - QMenu* m_menuTabs; ToolButton* m_buttonListTabs; AddTabButton* m_buttonAddTab; diff --git a/src/lib/webview/webpage.cpp b/src/lib/webview/webpage.cpp index fb28d5ba8..8bb864e81 100644 --- a/src/lib/webview/webpage.cpp +++ b/src/lib/webview/webpage.cpp @@ -22,11 +22,6 @@ #include "downloadmanager.h" #include "webpluginfactory.h" #include "mainapplication.h" -#ifdef NONBLOCK_JS_DIALOGS -#include "ui_jsconfirm.h" -#include "ui_jsalert.h" -#include "ui_jsprompt.h" -#endif #include "checkboxdialog.h" #include "widget.h" #include "globalfunctions.h" @@ -37,6 +32,14 @@ #include "networkmanagerproxy.h" #include "adblockicon.h" +#ifdef NONBLOCK_JS_DIALOGS +#include "ui_jsconfirm.h" +#include "ui_jsalert.h" +#include "ui_jsprompt.h" + +#include +#endif + #include #include #include