Browse Source

small usability fixes

cl-refactor
arkpar 10 years ago
parent
commit
2a39486972
  1. 1
      mix/CodeModel.cpp
  2. 120
      mix/qml/CodeEditor.qml
  3. 13
      mix/qml/CodeEditorView.qml
  4. 17
      mix/qml/NewProjectDialog.qml
  5. 20
      mix/qml/ProjectList.qml
  6. 2
      mix/qml/StateDialog.qml
  7. 98
      mix/qml/WebCodeEditor.qml
  8. 6
      mix/qml/html/WebContainer.html

1
mix/CodeModel.cpp

@ -46,6 +46,7 @@ CompilationResult::CompilationResult():
m_successful(false),
m_codeHash(qHash(QString())),
m_contract(new QContractDefinition()),
m_contractInterface("[]"),
m_codeHighlighter(new CodeHighlighter())
{}

120
mix/qml/CodeEditor.qml

@ -4,78 +4,76 @@ import QtQuick.Layouts 1.0
import QtQuick.Controls 1.0
import QtQuick.Controls.Styles 1.1
Component {
Item {
signal editorTextChanged
Item {
signal editorTextChanged
function setText(text) {
codeEditor.text = text;
}
function setText(text) {
codeEditor.text = text;
}
function getText() {
return codeEditor.text;
}
function getText() {
return codeEditor.text;
}
anchors.fill: parent
id: contentView
width: parent.width
height: parent.height * 0.7
Rectangle {
id: lineColumn
property int rowHeight: codeEditor.font.pixelSize + 3
color: "#202020"
width: 50
height: parent.height
Column {
y: -codeEditor.flickableItem.contentY + 4
width: parent.width
Repeater {
model: Math.max(codeEditor.lineCount + 2, (lineColumn.height/lineColumn.rowHeight))
delegate: Text {
id: text
color: codeEditor.textColor
font: codeEditor.font
width: lineColumn.width - 4
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
height: lineColumn.rowHeight
renderType: Text.NativeRendering
text: index + 1
}
anchors.fill: parent
id: contentView
width: parent.width
height: parent.height * 0.7
Rectangle {
id: lineColumn
property int rowHeight: codeEditor.font.pixelSize + 3
color: "#202020"
width: 50
height: parent.height
Column {
y: -codeEditor.flickableItem.contentY + 4
width: parent.width
Repeater {
model: Math.max(codeEditor.lineCount + 2, (lineColumn.height/lineColumn.rowHeight))
delegate: Text {
id: text
color: codeEditor.textColor
font: codeEditor.font
width: lineColumn.width - 4
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
height: lineColumn.rowHeight
renderType: Text.NativeRendering
text: index + 1
}
}
}
}
TextArea {
id: codeEditor
textColor: "#EEE8D5"
style: TextAreaStyle {
backgroundColor: "#002B36"
}
TextArea {
id: codeEditor
textColor: "#EEE8D5"
style: TextAreaStyle {
backgroundColor: "#002B36"
}
anchors.left: lineColumn.right
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
wrapMode: TextEdit.NoWrap
frameVisible: false
anchors.left: lineColumn.right
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
wrapMode: TextEdit.NoWrap
frameVisible: false
height: parent.height
font.family: "Monospace"
font.pointSize: 12
width: parent.width
height: parent.height
font.family: "Monospace"
font.pointSize: 12
width: parent.width
tabChangesFocus: false
Keys.onPressed: {
if (event.key === Qt.Key_Tab) {
codeEditor.insert(codeEditor.cursorPosition, "\t");
event.accepted = true;
}
tabChangesFocus: false
Keys.onPressed: {
if (event.key === Qt.Key_Tab) {
codeEditor.insert(codeEditor.cursorPosition, "\t");
event.accepted = true;
}
onTextChanged: {
editorTextChanged();
}
}
onTextChanged: {
editorTextChanged();
}
}
}

13
mix/qml/CodeEditorView.qml

@ -56,18 +56,15 @@ Item {
}
}
CodeEditor {
id: codeEditor
}
Repeater {
id: editors
model: editorListModel
delegate: Loader {
active: false;
id: loader
active: false
asynchronous: true
anchors.fill: parent
sourceComponent: codeEditor
source: "CodeEditor.qml"
visible: (index >= 0 && index < editorListModel.count && currentDocumentId === editorListModel.get(index).documentId)
onVisibleChanged: {
loadIfNotLoaded()
@ -75,7 +72,9 @@ Item {
Component.onCompleted: {
loadIfNotLoaded()
}
onLoaded: { doLoadDocument(item, editorListModel.get(index)) }
onLoaded: {
doLoadDocument(loader.item, editorListModel.get(index))
}
function loadIfNotLoaded () {
if(visible && !active) {

17
mix/qml/NewProjectDialog.qml

@ -26,6 +26,11 @@ Window {
visible = false;
}
function acceptAndClose() {
close();
accepted();
}
GridLayout {
id: dialogContent
columns: 2
@ -41,6 +46,10 @@ Window {
id: titleField
focus: true
Layout.fillWidth: true
Keys.onReturnPressed: {
if (okButton.enabled)
acceptAndClose();
}
}
Label {
@ -50,6 +59,10 @@ Window {
TextField {
id: pathField
Layout.fillWidth: true
Keys.onReturnPressed: {
if (okButton.enabled)
acceptAndClose();
}
}
Button {
text: qsTr("Browse")
@ -63,11 +76,11 @@ Window {
anchors.right: parent.right;
Button {
id: okButton;
enabled: titleField.text != "" && pathField.text != ""
text: qsTr("OK");
onClicked: {
close();
accepted();
acceptAndClose();
}
}
Button {

20
mix/qml/ProjectList.qml

@ -10,7 +10,7 @@ Item {
Text {
Layout.fillWidth: true
color: "blue"
text: projectModel.projectData ? projectModel.projectData.title : ""
text: projectModel.projectTitle
horizontalAlignment: Text.AlignHCenter
visible: !projectModel.isEmpty;
}
@ -117,12 +117,18 @@ Item {
contextMenu.popup();
}
}
Connections {
target: projectModel
onProjectLoaded: {
projectList.currentIndex = 0;
}
}
}
}
Connections {
target: projectModel
onProjectLoaded: {
projectList.currentIndex = 0;
if (projectList.currentIndex >= 0 && projectList.currentIndex < projectModel.listModel.count)
projectModel.openDocument(projectModel.listModel.get(projectList.currentIndex).documentId);
}
onProjectClosed: {
projectList.currentIndex = -1;
}
}
}

2
mix/qml/StateDialog.qml

@ -184,7 +184,7 @@ Window {
if (transactionDialog.transactionIndex < transactionsModel.count) {
transactionsModel.set(transactionDialog.transactionIndex, item);
stateTransactions[index] = item;
stateTransactions[transactionDialog.transactionIndex] = item;
} else {
transactionsModel.append(item);
stateTransactions.push(item);

98
mix/qml/WebCodeEditor.qml

@ -5,64 +5,62 @@ import QtQuick.Controls.Styles 1.1
import CodeEditorExtensionManager 1.0
import QtWebEngine 1.0
Component {
Item {
signal editorTextChanged
property string currentText: ""
property string currentMode: ""
property bool initialized: false
Item {
signal editorTextChanged
property string currentText: ""
property string currentMode: ""
property bool initialized: false
function setText(text, mode) {
currentText = text;
currentMode = mode;
if (initialized) {
editorBrowser.runJavaScript("setTextBase64(\"" + Qt.btoa(text) + "\")");
editorBrowser.runJavaScript("setMode(\"" + mode + "\")");
}
editorBrowser.forceActiveFocus();
function setText(text, mode) {
currentText = text;
currentMode = mode;
if (initialized) {
editorBrowser.runJavaScript("setTextBase64(\"" + Qt.btoa(text) + "\")");
editorBrowser.runJavaScript("setMode(\"" + mode + "\")");
}
editorBrowser.forceActiveFocus();
}
function getText() {
return currentText;
}
function getText() {
return currentText;
}
anchors.top: parent.top
id: codeEditorView
anchors.top: parent.top
id: codeEditorView
anchors.fill: parent
WebEngineView {
id: editorBrowser
url: "qrc:///qml/html/codeeditor.html"
anchors.fill: parent
WebEngineView {
id: editorBrowser
url: "qrc:///qml/html/codeeditor.html"
anchors.fill: parent
onJavaScriptConsoleMessage: {
console.log("editor: " + sourceID + ":" + lineNumber + ":" + message);
}
onJavaScriptConsoleMessage: {
console.log("editor: " + sourceID + ":" + lineNumber + ":" + message);
}
onLoadingChanged:
{
if (!loading) {
initialized = true;
setText(currentText, currentMode);
runJavaScript("getTextChanged()", function(result) { });
pollTimer.running = true;
}
onLoadingChanged:
{
if (!loading) {
initialized = true;
setText(currentText, currentMode);
runJavaScript("getTextChanged()", function(result) { });
pollTimer.running = true;
}
}
Timer
{
id: pollTimer
interval: 30
running: false
repeat: true
onTriggered: {
editorBrowser.runJavaScript("getTextChanged()", function(result) {
if (result === true) {
editorBrowser.runJavaScript("getText()" , function(textValue) {
currentText = textValue;
editorTextChanged();
});
}
});
}
Timer
{
id: pollTimer
interval: 30
running: false
repeat: true
onTriggered: {
editorBrowser.runJavaScript("getTextChanged()", function(result) {
if (result === true) {
editorBrowser.runJavaScript("getText()" , function(textValue) {
currentText = textValue;
editorTextChanged();
});
}
});
}
}
}

6
mix/qml/html/WebContainer.html

@ -16,11 +16,11 @@ reloadPage = function() {
preview.contentWindow.location.reload();
};
updateContract = function(address, definition) {
updateContract = function(address, contractFace) {
if (window.web3) {
window.contractAddress = address;
window.contractDefinition = definition;
window.contract = window.web3.eth.contract(address, definition);
window.contractInterface = contractFace;
window.contract = window.web3.eth.contract(address, contractFace);
}
};

Loading…
Cancel
Save