aboutsummaryrefslogtreecommitdiffstats
path: root/index.html
blob: aae723aba1657650f913cabd38ba922765211e58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<!doctype html>
<html lang="en-us">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width">
    <link rel="icon" href="qtdesignstudioviewer-16.png" sizes="16x16">
    <link rel="icon" href="qtdesignstudioviewer-32.png" sizes="32x32">
    <link rel="icon" href="qtdesignstudioviewer-48.png" sizes="48x48">
    <title>Qml Projector</title>
    <style>
      @font-face {
	    font-family: Titillium;
        src: url(Titillium-Light.otf);
		font-weight: 300;
      }
      @font-face {
	    font-family: Titillium;
        src: url(Titillium-Thin.otf);
		font-weight: 100;
      }
      @font-face {
	    font-family: Titillium;
        src: url(Titillium-ThinItalic.otf);
		font-weight: 100;
		font-style: italic;
      }
      body { padding: 0; margin: 0; background-color: #262525; color: #e0e0e0; font-family: Titillium; font-size: 1.1em; font-weight: 100; font-style: italic; }
      a {color: #e0e0e0; }
      canvas { border: 0px none; height: 0px; width: 0px; margin: auto; outline: 0px solid transparent; caret-color: transparent; cursor: default; }
      #qtspinner { margin: 0; }
      #title { font-size: 2em; font-weight: 300; font-style: normal; font-stretch: condensed; }
      #instruction { font-style: normal; }
      #subtitle { padding-top: 0.4em; padding-bottom: 1.4em; }
      #dropzone { border: 0.18em dashed; text-align: center; background-color: #353535; }
      #dropzone { padding: 1.2em; }
      #dropzone, #projectsmenu { width: 70%; margin: auto; }
      #projectsmenu { display: none; padding: 0; }
      #projectsmenulist { list-style-type: none; background-color: #353535; }
      #projectsmenulist, #projectsmenulist > li { float: left; padding: 0; margin: 0; }
      #projectsmenulist > li { margin: 1em;  }
    </style>
  </head>
  <body onload="init()">
    <figure style="overflow: visible;" id="qtspinner">
      <center style="line-height:150%">
        <img src="qtdesignstudioviewer-128.png" srcset="qtdesignstudioviewer-128.png 1x, qtdesignstudioviewer-256.png 2x, qtdesignstudioviewer-384.png 3x, qtdesignstudioviewer-512.png 4x, " width="128" height="128" style="display: block"/>
        <div id="title">Qt Design Viewer</div>
        <div id="subtitle" class="subtitleclass">powered by web assembly</div>
        <div id="qtstatus"></div>
        <noscript>JavaScript is disabled. Please enable JavaScript to use this application.</noscript>
      </center>
    </figure>
    <div id="dropzone">
      <div id="instruction">drop your qmlrc file or zip file here</div>
      <p>(package with a pure Qml project, containing either a .qmlproject file or a main.qml)</p>
      <form id="uploadform">
      <label><input id="fileinput" type="file" accept=".qmlrc,.zip" style="display:none;" /><img src="uploadIcon.svg" width="32" height="32"/></br>(or load by clicking here)</label>
      </form>
    </div>
    <div id="projectsmenu">
        <p>EXAMPLES</p>
        <ul id="projectsmenulist">
        </ul>
      </div>
   <canvas id="qtcanvas" oncontextmenu="event.preventDefault()" contenteditable="true"></canvas>

    <script type='text/javascript'>
        var contentArray;
        var projectfileName;
        var reader;
        var uploadform = document.querySelector('#uploadform');
        var fileinput = document.querySelector('#fileinput');
        var dropzone = document.querySelector('#dropzone');
        var projectsmenu = document.querySelector('#projectsmenu');
        var qtLoader;

        function loadFileInHash() {
          var filename = location.hash.split('#')[1]
          loadFromServer(filename);
        }

        window.addEventListener('hashchange', function() {
          if (location.hash == "") {
            location.reload(); // E.g. when browsing back
            return;
          }
          loadFileInHash();
        }, false);

        function handleFileSelection(event) {
          reader = new FileReader();
          var file = fileinput.files[0];
          reader.onload = function() {
              contentArray = new Uint8Array(reader.result);
              uploadform.style.display = dropzone.style.display = projectsmenu.style.display = 'none';
              projectfileName = file.name;
              loadProjector();
          };
          reader.readAsArrayBuffer(file);
        }

        function loadFromServer(fileName) {
          var request = new XMLHttpRequest();
          request.responseType = "arraybuffer";
          request.onload = function () {
            if (this.status == 404) {
              alert(this.status + " " + this.statusText);
              location.hash = "";
              return;
            }
            contentArray = new Uint8Array(request.response);
            uploadform.style.display = dropzone.style.display = projectsmenu.style.display = 'none';
            projectfileName = fileName;
            loadProjector();
          }
          request.open("GET", "qmlprojects/" + fileName, true);
          request.send(null);
        }

        function listExamples() {
          var request = new XMLHttpRequest();
          request.responseType = "json";
          request.onload = function (oEvent) {
            var json = request.response;
            if (json.projects.length > 0) {
              var projectsmenulist = document.querySelector('#projectsmenulist');
              for (project in json.projects) {
                var li = document.createElement('li');
                var a = document.createElement('a');
                var filename = json.projects[project].file;
                a.setAttribute("href", '#' + filename);
                a.innerHTML = filename;
                li.appendChild(a);
                projectsmenulist.appendChild(li);
              }
              projectsmenu.style.display = 'block';
            }
          }
          request.open("GET", "qmlprojects/index.json", true);
          request.send(null);
        }

        function init() {
          if (location.hash == '')
            listExamples();
          else
            loadFileInHash();

          fileinput.onchange = handleFileSelection;
          dropzone.ondragover = dropzone.ondragenter = function(event) {
            event.preventDefault();
          };
          dropzone.ondrop = function(event) {
            fileinput.files = event.dataTransfer.files;
            handleFileSelection(event);
            event.preventDefault();
          };
        }

        function loadProjector() {
          var spinner = document.querySelector('#qtspinner');
          var canvas = document.querySelector('#qtcanvas');
          var status = document.querySelector('#qtstatus')

          qtLoader = QtLoader({
            canvasElements : [canvas],
            showLoader: function(loaderStatus) {
                spinner.style.display = 'block';
                canvas.style.display = 'none';
                status.innerHTML = loaderStatus + "...";
            },
            showError: function(errorText) {
                status.innerHTML = errorText;
                spinner.style.display = 'block';
                canvas.style.display = 'none';
            },
            showExit: function() {
                status.innerHTML = "Application exit";
                if (qtLoader.exitCode !== undefined)
                    status.innerHTML += " with code " + qtLoader.exitCode;
                if (qtLoader.exitText !== undefined)
                    status.innerHTML += " (" + qtLoader.exitText + ")";
                spinner.style.display = 'block';
                canvas.style.display = 'none';
            },
            showCanvas: function() {
                spinner.style.display = 'none';
                canvas.style.display = 'block';
            },
          });
          qtLoader.loadEmscriptenModule("qmlprojector");
        }

        function setScreenSize(width, height) {
          var canvas = document.querySelector('#qtcanvas');
          if (width > 1 && height > 1) {
            canvas.style.width = `${width}px`;
            canvas.style.height = `${height}px`;
          } else {
            // undefined root size
            canvas.style.width = canvas.style.height = "100%";
            document.documentElement.style.height = document.body.style.height = "100%";
          }
          qtLoader.resizeCanvasElement(canvas);
        }
    </script>
    <script type="text/javascript" src="qtloader.js"></script>
  </body>
</html>