aboutsummaryrefslogtreecommitdiffstats
path: root/www/index.html
blob: 393ba5669aa59df9cae52f4af0795e975fa07586 (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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<!doctype html>
<html lang="en-us">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="author" content="The Qt Company">
    <meta name="description" content="The online Qt Design Viewer allows users to view and share Qml-based UI designs. The designs can be either created with the Qt Design Studio or be hand coded.">
    <meta name="keywords" content="Qml, Qt Quick, Qt, Ui, Design Studio, Viewer, WebAssembly">
    <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>Qt Design Viewer</title>
    <style>
      @font-face {
        font-family: Titillium;
        src: url(http://code.qt.io/Titillium-Light.otf);
        font-weight: 300;
      }
      @font-face {
        font-family: Titillium;
        src: url(http://code.qt.io/Titillium-Thin.otf);
        font-weight: 100;
      }
      @font-face {
        font-family: Titillium;
        src: url(http://code.qt.io/Titillium-ThinItalic.otf);
        font-weight: 100;
        font-style: italic;
      }
      html, 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; }
      #topnav { margin: 10px; margin-bottom: 20px; display: none}
      #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; }
      #footer { padding-top: 1.2em; clear: both; font-size: 0.8em; text-align: center; }
    </style>
  </head>
  <body onload="init()">
     <div id="topnav" class="topnav">
       <a class="active" href="/">Qt Design Viewer</a>
       <a id="versioninfo_header"></a>
    </div>
    <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>
    <div id="footer">
      <p>
        Note: This is a static web page. The Qml application that You load runs and remains locally in Your browser, nothing gets uploaded into the cloud.
      </p>
      <p>
        <a href="https://github.com/qt/qtdesignviewer">"Qt Design Viewer" sources</a>
        | Made with: <a href="https://doc.qt.io/qt-5/wasm.html">Qt for WebAssembly</a>
        | Powered by: <a href="https://webassembly.org/">WebAssembly</a> & <a href="https://emscripten.org/">emscripten</a>
      </p>
      <p id="versioninfo_main"></p>
    </div>

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

        function hideStuff() {
           uploadform.style.display = dropzone.style.display = projectsmenu.style.display = footer.style.display = 'none';
        }

        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);
              hideStuff();
              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);
            hideStuff();
            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 showVersionInfo() {
          var request = new XMLHttpRequest();
          request.responseType = "json";
          request.onload = function (oEvent) {
            var json = request.response;
            versionInfo = request.response;
            var version = json.version;
            var buildNumber = json.buildNumber;
            var versionText = "Version: " + version;
            if(buildNumber !== undefined)
              versionText += "." + buildNumber;
            document.querySelector('#versioninfo_header').innerHTML = versionText;
            document.querySelector('#versioninfo_main').innerHTML = versionText;
          }
          request.open("GET", "version.json", true);
          request.send(null);
        }


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

          showVersionInfo();

          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 status = document.querySelector('#qtstatus')
          var topnav = document.querySelector('#topnav')

          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';
                topnav.style.display = 'block';
            },
          });

          // workaround for making sure that self.module is set up before
          // running setScreenSize
          self.moduleConfig.preRun = []
          self.moduleConfig.preRun.push(function(module) {
            self.module = module;
          });

          qtLoader.loadEmscriptenModule("qtdesignviewer");
        }

        function setScreenSize(width, height) {
          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%";
            document.documentElement.style.overflow = document.body.style.overflow = "hidden";
          }
          qtLoader.resizeCanvasElement(canvas);
        }
    </script>
    <script type="text/javascript" src="qtloader.js"></script>
  </body>
</html>