Browse Source

WebPreview ui redesign

cl-refactor
yann300 10 years ago
parent
commit
ece46d70ea
  1. 3
      mix/qml/CodeEditorView.qml
  2. 124
      mix/qml/WebPreview.qml
  3. 14
      mix/qml/WebPreviewStyle.qml
  4. BIN
      mix/qml/img/available_updates.png
  5. 1
      mix/qml/qmldir
  6. 2
      mix/res.qrc

3
mix/qml/CodeEditorView.qml

@ -19,7 +19,8 @@ Item {
function isDocumentOpen(documentId) { function isDocumentOpen(documentId) {
for (var i = 0; i < editorListModel.count; i++) for (var i = 0; i < editorListModel.count; i++)
if (editorListModel.get(i).documentId === documentId) if (editorListModel.get(i).documentId === documentId &&
editors.itemAt(i).item)
return true; return true;
return false; return false;
} }

124
mix/qml/WebPreview.qml

@ -6,6 +6,7 @@ import QtQuick.Controls.Styles 1.1
import QtWebEngine 1.0 import QtWebEngine 1.0
import QtWebEngine.experimental 1.0 import QtWebEngine.experimental 1.0
import HttpServer 1.0 import HttpServer 1.0
import "."
Item { Item {
id: webPreview id: webPreview
@ -38,7 +39,7 @@ Item {
function updateDocument(documentId, action) { function updateDocument(documentId, action) {
for (var i = 0; i < pageListModel.count; i++) for (var i = 0; i < pageListModel.count; i++)
if (pageListModel.get(i).documentId === i) if (pageListModel.get(i).documentId === documentId)
action(i); action(i);
} }
@ -82,10 +83,22 @@ Item {
onDocumentRemoved: { onDocumentRemoved: {
updateDocument(documentId, function(i) { pageListModel.remove(i) } ) updateDocument(documentId, function(i) { pageListModel.remove(i) } )
} }
onDocumentUpdated: { onDocumentUpdated: {
updateDocument(documentId, function(i) { pageListModel.set(i, projectModel.getDocument(documentId)) } ) updateDocument(documentId, function(i) { pageListModel.set(i, projectModel.getDocument(documentId)) } )
} }
onDocumentOpened: {
if (!document.isHtml)
return;
for (var i = 0; i < pageListModel.count; i++) {
var doc = pageListModel.get(i);
if (doc.documentId === document.documentId) {
pageCombo.currentIndex = i;
}
}
}
onProjectLoading: { onProjectLoading: {
for (var i = 0; i < target.listModel.count; i++) { for (var i = 0; i < target.listModel.count; i++) {
var document = target.listModel.get(i); var document = target.listModel.get(i);
@ -146,45 +159,86 @@ Item {
ColumnLayout { ColumnLayout {
anchors.fill: parent anchors.fill: parent
spacing: 0
RowLayout { Rectangle
anchors.top: parent.top {
Layout.fillWidth: true; SourceSansProLight
Text { {
text: qsTr("Page") id: regularFont
}
ComboBox {
id: pageCombo
model: pageListModel
textRole: "name"
currentIndex: -1
onCurrentIndexChanged: changePage()
}
Button {
text: qsTr("Reload")
onClicked: reload()
} }
CheckBox {
id: autoReloadOnSave anchors.leftMargin: 4
checked: true color: WebPreviewStyle.general.headerBackgroundColor
text: qsTr("Auto reload on save") Layout.preferredWidth: parent.width
Layout.preferredHeight: 32
Row {
anchors.top: parent.top
anchors.fill: parent
anchors.leftMargin: 3
spacing: 3
DefaultLabel {
text: qsTr("Preview of")
anchors.verticalCenter: parent.verticalCenter
}
ComboBox {
id: pageCombo
model: pageListModel
textRole: "name"
currentIndex: -1
onCurrentIndexChanged: changePage()
anchors.verticalCenter: parent.verticalCenter
style: ComboBoxStyle {
font: regularFont.name
}
}
Action {
tooltip: qsTr("Reload")
id: buttonReloadAction
onTriggered: {
reload();
}
}
Button {
iconSource: "qrc:/qml/img/available_updates.png"
action: buttonReloadAction
anchors.verticalCenter: parent.verticalCenter
width: 26
height: 26
}
CheckBox {
id: autoReloadOnSave
checked: true
anchors.verticalCenter: parent.verticalCenter
style: CheckBoxStyle {
label: DefaultLabel {
text: qsTr("Auto reload on save")
}
}
}
} }
} }
WebEngineView { Rectangle
Layout.fillWidth: true {
Layout.preferredWidth: parent.width
Layout.fillHeight: true Layout.fillHeight: true
id: webView WebEngineView {
experimental.settings.localContentCanAccessRemoteUrls: true anchors.fill: parent
onJavaScriptConsoleMessage: { id: webView
console.log(sourceID + ":" + lineNumber + ":" + message); experimental.settings.localContentCanAccessRemoteUrls: true
} onJavaScriptConsoleMessage: {
onLoadingChanged: { console.log(sourceID + ":" + lineNumber + ":" + message);
if (!loading) { }
initialized = true; onLoadingChanged: {
webView.runJavaScript("init(\"" + httpServer.url + "/rpc/\")"); if (!loading) {
if (pendingPageUrl) initialized = true;
setPreviewUrl(pendingPageUrl); webView.runJavaScript("init(\"" + httpServer.url + "/rpc/\")");
if (pendingPageUrl)
setPreviewUrl(pendingPageUrl);
}
} }
} }
} }

14
mix/qml/WebPreviewStyle.qml

@ -0,0 +1,14 @@
pragma Singleton
import QtQuick 2.0
QtObject {
function absoluteSize(rel)
{
return systemPointSize + rel;
}
property QtObject general: QtObject {
property string headerBackgroundColor: "#f0f0f0"
}
}

BIN
mix/qml/img/available_updates.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 889 B

1
mix/qml/qmldir

@ -4,3 +4,4 @@ singleton ProjectFilesStyle 1.0 ProjectFilesStyle.qml
singleton DebuggerPaneStyle 1.0 DebuggerPaneStyle.qml singleton DebuggerPaneStyle 1.0 DebuggerPaneStyle.qml
singleton StateStyle 1.0 StateStyle.qml singleton StateStyle 1.0 StateStyle.qml
singleton StatusPaneStyle 1.0 StatusPaneStyle.qml singleton StatusPaneStyle 1.0 StatusPaneStyle.qml
singleton WebPreviewStyle 1.0 WebPreviewStyle.qml

2
mix/res.qrc

@ -97,5 +97,7 @@
<file>qml/DefaultTextField.qml</file> <file>qml/DefaultTextField.qml</file>
<file>qml/CommonSeparator.qml</file> <file>qml/CommonSeparator.qml</file>
<file>qml/Style.qml</file> <file>qml/Style.qml</file>
<file>qml/WebPreviewStyle.qml</file>
<file>qml/img/available_updates.png</file>
</qresource> </qresource>
</RCC> </RCC>

Loading…
Cancel
Save