Browse Source

Show web inspector as dock

Kandrashin Denis 13 năm trước cách đây
mục cha
commit
9cf94b5af0
3 tập tin đã thay đổi với 46 bổ sung15 xóa
  1. 3 1
      source/fb2main.cpp
  2. 32 12
      source/fb2view.cpp
  3. 11 2
      source/fb2view.hpp

+ 3 - 1
source/fb2main.cpp

@@ -698,7 +698,7 @@ void Fb2MainWindow::viewText()
     connect(actionZoomIn, SIGNAL(triggered()), textEdit, SLOT(zoomIn()));
     connect(actionZoomOut, SIGNAL(triggered()), textEdit, SLOT(zoomOut()));
     connect(actionZoomReset, SIGNAL(triggered()), textEdit, SLOT(zoomReset()));
-    connect(actionInspect, SIGNAL(triggered()), textEdit, SLOT(showInspector()));
+    connect(actionInspect, SIGNAL(triggered()), textFrame, SLOT(showInspector()));
 
     if (!xml.isEmpty()) textFrame->view.load(curFile, xml);
 
@@ -727,6 +727,8 @@ void Fb2MainWindow::viewHead()
 {
     if (headTree && centralWidget() == headTree) return;
 
+    if (textFrame) textFrame->hideInspector();
+
     QString xml;
     if (codeEdit) xml = codeEdit->text();
 

+ 32 - 12
source/fb2view.cpp

@@ -8,7 +8,9 @@
 
 #include <QAction>
 #include <QBoxLayout>
+#include <QDockWidget>
 #include <QFileDialog>
+#include <QMainWindow>
 #include <QNetworkRequest>
 #include <QStyle>
 #include <QStyleOptionFrame>
@@ -138,7 +140,6 @@ void Fb2WebPage::insertBody()
 
 Fb2WebView::Fb2WebView(QWidget *parent)
     : Fb2BaseWebView(parent)
-    , m_inspector(0)
     , m_noteView(0)
     , m_thread(0)
 {
@@ -152,7 +153,6 @@ Fb2WebView::Fb2WebView(QWidget *parent)
 
 Fb2WebView::~Fb2WebView()
 {
-    FB2DELETE(m_inspector);
     FB2DELETE(m_noteView);
 }
 
@@ -377,16 +377,6 @@ QString Fb2WebView::status()
     return QString();
 }
 
-void Fb2WebView::showInspector()
-{
-    if (!m_inspector) {
-        m_inspector = new QWebInspector();
-        m_inspector->setAttribute(Qt::WA_DeleteOnClose, false);
-        m_inspector->setPage(page());
-    }
-    m_inspector->show();
-}
-
 void Fb2WebView::loadFinished()
 {
     Fb2WebElement element = body().findFirst("div.body");
@@ -409,6 +399,7 @@ void Fb2WebView::insertTitle()
 Fb2WebFrame::Fb2WebFrame(QWidget* parent)
     : QFrame(parent)
     , view(this)
+    , dock(0)
 {
     setFrameShape(QFrame::StyledPanel);
     setFrameShadow(QFrame::Sunken);
@@ -418,3 +409,32 @@ Fb2WebFrame::Fb2WebFrame(QWidget* parent)
     layout->setMargin(0);
     layout->addWidget(&view);
 }
+
+Fb2WebFrame::~Fb2WebFrame()
+{
+    if (dock) dock->deleteLater();
+}
+
+void Fb2WebFrame::showInspector()
+{
+    if (dock) {
+        dock->show();
+        return;
+    }
+
+    QMainWindow * main = qobject_cast<QMainWindow*>(parent());
+    if (!main) return;
+
+    dock = new QDockWidget(tr("Web inspector"), this);
+    dock->setFeatures(QDockWidget::AllDockWidgetFeatures);
+    main->addDockWidget(Qt::BottomDockWidgetArea, dock);
+
+    QWebInspector * inspector = new QWebInspector(this);
+    inspector->setPage(view.page());
+    dock->setWidget(inspector);
+}
+
+void Fb2WebFrame::hideInspector()
+{
+    if (dock) dock->hide();
+}

+ 11 - 2
source/fb2view.hpp

@@ -12,6 +12,7 @@
 
 QT_BEGIN_NAMESPACE
 class QWebInspector;
+class QDockWidget;
 QT_END_NAMESPACE
 
 class Fb2NoteView;
@@ -95,7 +96,6 @@ public slots:
     void data(QString name, QByteArray data);
     void html(QString name, QString html);
     void linkHovered(const QString &link, const QString &title, const QString &textContent);
-    void showInspector();
     void insertImage();
     void insertNote();
     void insertLink();
@@ -117,7 +117,6 @@ private:
     QWebElement doc();
 
 private:
-    QWebInspector * m_inspector;
     Fb2TemporaryList m_files;
     Fb2NoteView *m_noteView;
     QThread *m_thread;
@@ -126,9 +125,19 @@ private:
 
 class Fb2WebFrame : public QFrame
 {
+    Q_OBJECT
+
 public:
     explicit Fb2WebFrame(QWidget* parent = 0);
+    ~Fb2WebFrame();
+    void hideInspector();
     Fb2WebView view;
+
+public slots:
+    void showInspector();
+
+private:
+    QDockWidget * dock;
 };
 
 #endif // FB2VIEW_H