Skip to content

Commit

Permalink
add WizDevToolsDialog Class.
Browse files Browse the repository at this point in the history
  • Loading branch information
altairwei committed Aug 15, 2018
1 parent 1871f68 commit 5c387c0
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ OSX 端能提供系统本地对高分屏的支持,除了替换高分辨率图
### 已知BUG

- [x] 非系统标题栏样式下切换笔记视图会导致软件崩溃
- [ ] QWebEnginePage 渲染Markdown速度太慢(Linux端不会),光标快速选择时会产生卡顿和性能问题?可能是因为选择引起了重绘?
- [ ] 同步操作完成前无法正常退出
2 changes: 2 additions & 0 deletions share/files/mainmenu.ini
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
1=actionPreference
2=actionResetSearch
3=actionSearch
4=-
5=actionOpenDevTools

[&Window]
0=actionViewMinimize
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ set(wiznote_SOURCES

WizCategoryView.cpp
WizCategoryViewItem.cpp
WizDevToolsDialog.cpp
WizDocumentListView.cpp
WizDocumentListViewItem.cpp
WizDocumentView.cpp
Expand Down Expand Up @@ -264,6 +265,7 @@ set(wiznote_HEADERS
WizNoteStyle.h
WizCategoryView.h
WizCategoryViewItem.h
WizDevToolsDialog.h
WizDocumentListView.h
WizDocumentListViewItem.h
WizDocumentView.h
Expand Down
18 changes: 13 additions & 5 deletions src/WizActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,29 +145,37 @@ WIZACTION* WizActions::actionsData()
{WIZACTION_FORMAT_INSERT_IMAGE, QObject::tr("Insert Image"), "", QKeySequence("Shift+Ctrl+I")},
{WIZACTION_FORMAT_REMOVE_FORMAT, QObject::tr("Remove Format"), "", QKeySequence()},
{WIZACTION_FORMAT_SCREEN_SHOT, QObject::tr("Screen Shot..."), "", QKeySequence()},
{"actionOpenDevTools", QObject::tr("Open DevTools"), QObject::tr("Inspect Current Web Page."), QKeySequence("F1")},


// 用于结束循环
{"", "", "", QKeySequence()}
};

return arrayActions;
}

/** 添加动作的同时,链接信号到父组件的槽函数
*
* @param action 待添加的动作,是一个聚合类
* @param bUseExtraShortcut 指向描述测试信息的字符串
* @return 带有快捷键的动作
*/
WizShortcutAction *WizActions::addAction(WIZACTION& action, bool bUseExtraShortcut)
{
QString strText = action.strText;
QString strIconName = action.strName ;
QKeySequence strShortcut = action.strShortcut;
// 组合槽函数的名称
QString strSlot = "1on_" + action.strName + "_triggered()";

WizShortcutAction* pAction = new WizShortcutAction(strText, m_parent);

// 设置图标
if (!strIconName.isEmpty()) {
pAction->setIcon(::WizLoadSkinIcon(m_app.userSettings().skin(), strIconName));
}

// 设置快捷键
pAction->setShortcut(strShortcut);

// 设置特殊动作的角色,主要用于macOS
if (action.strName == "actionAbout")
pAction->setMenuRole(QAction::AboutRole);
else if (action.strName == "actionPreference")
Expand All @@ -187,7 +195,7 @@ WizShortcutAction *WizActions::addAction(WIZACTION& action, bool bUseExtraShortc
QObject::connect(shortcut, SIGNAL(activated()), m_parent, strSlot.toUtf8());
pAction->setShortcut(shortcut);
}

// 以字符串的形式链接槽函数
QObject::connect(pAction, "2triggered()", m_parent, strSlot.toUtf8());

return pAction;
Expand Down
42 changes: 42 additions & 0 deletions src/WizDevToolsDialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "WizDevToolsDialog.h"

#include "sync/WizToken.h"
#include "WizMainWindow.h"
#include "share/WizGlobal.h"
#include "utils/WizPathResolve.h"
#include "widgets/WizLocalProgressWebView.h"

#include <QMovie>
#include <QVBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QApplication>
#include <QNetworkReply>
#include <QWebEngineView>
#include "share/WizWebEngineView.h"


WizDevToolsDialog::WizDevToolsDialog(QSize sz, QWidget *parent)
: WizWebEngineViewContainerDialog(parent)
, m_web(new WizWebEngineView(this))
{
// 设置长宽和边界
setContentsMargins(0, 0, 0, 0);
setFixedSize(sz);

QPalette pal = palette();
pal.setBrush(backgroundRole(), QBrush("#FFFFFF"));
setPalette(pal);
//

// 将页面嵌入布局
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(m_web);
setLayout(layout);
}

WizWebEngineView* WizDevToolsDialog::getWeb() {
return m_web;
}
27 changes: 27 additions & 0 deletions src/WizDevToolsDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef WIZDEVTOOLSDIALOG_H
#define WIZDEVTOOLSDIALOG_H

#include <QDialog>
#include "share/WizWebEngineView.h"

class QUrl;
class QLabel;
class QMovie;
class WizWebEngineView;
class QPushButton;
class QNetworkReply;
class WizLocalProgressWebView;

class WizDevToolsDialog : public WizWebEngineViewContainerDialog
{
Q_OBJECT
private:
WizWebEngineView* m_web;
public:
WizDevToolsDialog(QSize sz, QWidget *parent = 0);
WizWebEngineView* getWeb();


};

#endif // WIZDEVTOOLSDIALOG_H
6 changes: 5 additions & 1 deletion src/WizDocumentWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ WizDocumentWebView::WizDocumentWebView(WizExplorerApp& app, QWidget* parent)
, m_nWindowID(nWindowIDCounter ++)
, m_searchReplaceWidget(nullptr)
, m_ignoreActiveWindowEvent(false)
, m_page(new WizDocumentWebViewPage(this))
{
WizDocumentWebViewPage* page = new WizDocumentWebViewPage(this);
WizDocumentWebViewPage* page = m_page;
setPage(page);

connect(page, SIGNAL(actionTriggered(QWebEnginePage::WebAction)), SLOT(onActionTriggered(QWebEnginePage::WebAction)));
Expand Down Expand Up @@ -193,6 +194,9 @@ void WizDocumentWebView::waitForDone()
}
}

WizDocumentWebViewPage* WizDocumentWebView::getPage() {
return m_page;
}

bool WizDocumentWebView::onPasteCommand()
{
Expand Down
3 changes: 3 additions & 0 deletions src/WizDocumentWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ class WizDocumentWebView : public WizWebEngineView
void setInSeperateWindow(bool inSeperateWindow);
bool isInSeperateWindow() const;

WizDocumentWebViewPage* getPage();

// initialize editor style before render, only invoke once.
void replaceDefaultCss(QString& strHtml);

Expand Down Expand Up @@ -298,6 +300,7 @@ class WizDocumentWebView : public WizWebEngineView
QPointer<WizEditorInsertLinkForm> m_editorInsertLinkForm;

WizSearchReplaceWidget* m_searchReplaceWidget;
WizDocumentWebViewPage* m_page;

public:
Q_INVOKABLE void onNoteLoadFinished(); // editor callback
Expand Down
16 changes: 15 additions & 1 deletion src/WizMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@

#include "share/jsoncpp/json/json.h"

#include "WizDevToolsDialog.h"

#define MAINWINDOW "MainWindow"


Expand Down Expand Up @@ -261,7 +263,7 @@ WizMainWindow::WizMainWindow(WizDatabaseManager& dbMgr, QWidget *parent)
// 在编译时因为定义了Q_OS_WIN系统变量,所以m_useSystemBasedStyle(false)被初始化为否。
initMenuBar();
} else {
// 不使用系统菜单风格,而使用Wiz自定义菜单风格
// Wiz自定义菜单风格
// 执行此分支对菜单进行初始化,将会导致m_viewTypeActions和m_sortTypeActions为空,产生BUG
initMenuList();
}
Expand Down Expand Up @@ -3328,6 +3330,17 @@ void WizMainWindow::on_actionGoForward_triggered()
m_doc->setFocus();
}

void WizMainWindow::on_actionOpenDevTools_triggered() {
WizDevToolsDialog* devToolsWindow = new WizDevToolsDialog(QSize(800, 600));
// 设置外观
devToolsWindow->setWindowTitle("DevTools - " + m_doc->note().strTitle);
//
WizWebEnginePage* devToolsWebPage = devToolsWindow->getWeb()->getPage();
WizDocumentWebViewPage* docWebPage = m_doc->web()->getPage();
//
devToolsWindow->show();
}

void WizMainWindow::on_category_itemSelectionChanged()
{
WizCategoryBaseView* category = qobject_cast<WizCategoryBaseView *>(sender());
Expand Down Expand Up @@ -3419,6 +3432,7 @@ void WizMainWindow::on_documents_itemSelectionChanged()

if (arrayDocument.size() == 1)
{
// 如果选中单个文档则浏览该文档
if (!m_bUpdatingSelection)
{
viewDocument(arrayDocument[0], true);
Expand Down
2 changes: 2 additions & 0 deletions src/WizMainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ public Q_SLOTS:
void on_actionGoBack_triggered();
void on_actionGoForward_triggered();

void on_actionOpenDevTools_triggered();

void on_category_itemSelectionChanged();
void on_documents_itemSelectionChanged();
void on_documents_itemDoubleClicked(QListWidgetItem * item);
Expand Down
16 changes: 15 additions & 1 deletion src/share/WizWebEngineView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,19 @@ void WizWebEnginePage::triggerAction(WizWebEnginePage::WebAction action, bool ch
}
}

/** WizWebEngineView 构造函数
*
* 创建WizWebEnginePage
*/
WizWebEngineView::WizWebEngineView(QWidget* parent)
: QWebEngineView(parent)
, m_server(NULL)
, m_clientWrapper(NULL)
, m_channel(NULL)
, m_page(new WizWebEnginePage(this))
{
WizWebEnginePage* p = new WizWebEnginePage(this);
// 创建Page设置为到该View
WizWebEnginePage* p = m_page;
setPage(p);
//
connect(p, SIGNAL(openLinkInNewWindow(QUrl)), this, SLOT(openLinkInDefaultBrowser(QUrl)));
Expand Down Expand Up @@ -252,6 +258,14 @@ void WizWebEngineView::openLinkInDefaultBrowser(QUrl url)
QDesktopServices::openUrl(url);
}

/** 下面是一个含有两个参数的函数的注释说明(简述)
*
* @return 获得指向WebPage的指针
*/
WizWebEnginePage* WizWebEngineView::getPage() {
return m_page;
}


static QWebEngineView* getActiveWeb()
{
Expand Down
2 changes: 2 additions & 0 deletions src/share/WizWebEngineView.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class WizWebEngineView : public QWebEngineView
WizWebEngineView(QWidget* parent);
virtual ~WizWebEngineView();
public:
WizWebEnginePage* getPage();
void addToJavaScriptWindowObject(QString name, QObject* obj);
void closeAll();
public Q_SLOTS:
Expand All @@ -51,6 +52,7 @@ public Q_SLOTS:
WebSocketClientWrapper* m_clientWrapper;
QWebChannel* m_channel;
QString m_objectNames;
WizWebEnginePage* m_page;
protected:
void wheelEvent(QWheelEvent *event);
};
Expand Down

0 comments on commit 5c387c0

Please sign in to comment.