Skip to content

Commit 3817cca

Browse files
committed
Merge branch 'v1' of https://github.com/tgerring/qml into tgerring-v1
# Conflicts: # cpp/idletimer.cpp
1 parent b752760 commit 3817cca

18 files changed

+289
-13
lines changed

cpp/capi.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#include <QApplication>
2-
#include <QQuickView>
3-
#include <QQuickItem>
4-
#include <QtQml>
5-
#include <QDebug>
6-
#include <QQuickImageProvider>
1+
#include <QtWidgets/QApplication>
2+
#include <QtQuick/QQuickView>
3+
#include <QtQuick/QQuickItem>
4+
#include <QtQml/QtQml>
5+
#include <QtCore/QDebug>
6+
#include <QtQuick/QQuickImageProvider>
7+
#include <QtGui/QIcon>
78

89
#include <string.h>
910

@@ -69,6 +70,12 @@ void applicationFlushAll()
6970
qApp->processEvents();
7071
}
7172

73+
void setWindowIcon(QString_ *path){
74+
QString *str = reinterpret_cast<QString *>(path);
75+
QIcon icon(*str);
76+
qApp->setWindowIcon(icon);
77+
}
78+
7279
void *currentThread()
7380
{
7481
return QThread::currentThread();

cpp/capi.h

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ void newGuiApplication();
110110
void applicationExec();
111111
void applicationExit();
112112
void applicationFlushAll();
113+
void setWindowIcon(QString_ *path);
113114

114115
void idleTimerInit(int32_t *guiIdleRun);
115116
void idleTimerStart();

cpp/connector.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <QObject>
1+
#include <QtCore/QObject>
22

33
#include "connector.h"
44
#include "capi.h"

cpp/connector.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef CONNECTOR_H
22
#define CONNECTOR_H
33

4-
#include <QObject>
4+
#include <QtCore/QObject>
55

66
#include <stdint.h>
77

cpp/govalue.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <QtOpenGL/QGLFunctions>
55

66
#include <QtQml/QtQml>
7-
#include <QQmlEngine>
8-
#include <QDebug>
7+
#include <QtQml/QQmlEngine>
8+
#include <QtCore/QDebug>
99

1010
#include "govalue.h"
1111
#include "capi.h"

cpp/govalue.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// away, and without it this package wouldn't exist.
77
#include <private/qmetaobject_p.h>
88

9-
#include <QQuickPaintedItem>
10-
#include <QPainter>
9+
#include <QtQuick/QQuickPaintedItem>
10+
#include <QtGui/QPainter>
1111

1212
#include "capi.h"
1313

examples/customicon/qrcpath/qrc.go

+58
Large diffs are not rendered by default.
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"gopkg.in/qml.v1"
8+
)
9+
10+
func main() {
11+
if err := qml.Run(run); err != nil {
12+
fmt.Fprintf(os.Stderr, "error: %v\n", err)
13+
os.Exit(1)
14+
}
15+
}
16+
17+
func run() error {
18+
// I genqrc "../res"
19+
qml.SetWindowIcon(":../res/1.ico")
20+
21+
engine := qml.NewEngine()
22+
controls, err := engine.LoadFile("qrc:///../res/main.qml")
23+
if err != nil {
24+
return err
25+
}
26+
27+
window := controls.CreateWindow(nil)
28+
29+
window.Show()
30+
window.Wait()
31+
return nil
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"gopkg.in/qml.v1"
8+
)
9+
10+
func main() {
11+
if err := qml.Run(run); err != nil {
12+
fmt.Fprintf(os.Stderr, "error: %v\n", err)
13+
os.Exit(1)
14+
}
15+
}
16+
17+
func run() error {
18+
qml.SetWindowIcon("../res/1.ico")
19+
20+
engine := qml.NewEngine()
21+
controls, err := engine.LoadFile("../res/main.qml")
22+
if err != nil {
23+
return err
24+
}
25+
26+
window := controls.CreateWindow(nil)
27+
28+
window.Show()
29+
window.Wait()
30+
return nil
31+
}

examples/customicon/res/1.ico

66.1 KB
Binary file not shown.

examples/customicon/res/main.qml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4+
** Contact: http://www.qt-project.org/legal
5+
**
6+
** This file is part of the Qt Quick Controls module of the Qt Toolkit.
7+
**
8+
** $QT_BEGIN_LICENSE:BSD$
9+
** You may use this file under the terms of the BSD license as follows:
10+
**
11+
** "Redistribution and use in source and binary forms, with or without
12+
** modification, are permitted provided that the following conditions are
13+
** met:
14+
** * Redistributions of source code must retain the above copyright
15+
** notice, this list of conditions and the following disclaimer.
16+
** * Redistributions in binary form must reproduce the above copyright
17+
** notice, this list of conditions and the following disclaimer in
18+
** the documentation and/or other materials provided with the
19+
** distribution.
20+
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21+
** of its contributors may be used to endorse or promote products derived
22+
** from this software without specific prior written permission.
23+
**
24+
**
25+
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26+
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27+
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28+
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29+
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30+
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31+
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32+
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33+
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34+
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35+
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36+
**
37+
** $QT_END_LICENSE$
38+
**
39+
****************************************************************************/
40+
41+
42+
43+
44+
45+
import QtQuick 2.2
46+
import QtQuick.Controls 1.1
47+
48+
ApplicationWindow {
49+
visible: true
50+
width: 50
51+
height: 50
52+
}

examples/webengine/webengine.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"gopkg.in/qml.v1"
8+
"gopkg.in/qml.v1/webengine"
9+
)
10+
11+
func main() {
12+
fmt.Println(qml.Run(func() error {
13+
webengine.Initialize()
14+
15+
engine := qml.NewEngine()
16+
engine.On("quit", func() { os.Exit(0) })
17+
18+
component, err := engine.LoadFile("webengine.qml")
19+
if err != nil {
20+
return err
21+
}
22+
win := component.CreateWindow(nil)
23+
win.Show()
24+
win.Wait()
25+
return nil
26+
}))
27+
}

examples/webengine/webengine.qml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import QtQuick 2.1
2+
import QtWebEngine 1.0
3+
import QtQuick.Controls 1.0
4+
5+
ApplicationWindow {
6+
id: root
7+
width: 1024
8+
height: 768
9+
10+
WebEngineView {
11+
anchors.fill: parent
12+
url: "http://codingame.com"
13+
}
14+
}

gl/es2/gl.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ package GL
44

55
// #cgo CXXFLAGS: -std=c++0x -pedantic-errors -Wall -fno-strict-aliasing
66
// #cgo LDFLAGS: -lstdc++
7-
// #cgo !darwin LDFLAGS: -lGL
7+
// #cgo !darwin,!windows LDFLAGS: -lGL
88
// #cgo darwin LDFLAGS: -framework OpenGL
9+
// #cgo windows LDFLAGS: -lopengl32
910
// #cgo pkg-config: Qt5Core Qt5OpenGL
1011
//
1112
// #include "funcs.h"

qml.go

+13
Original file line numberDiff line numberDiff line change
@@ -1200,3 +1200,16 @@ func UnloadResources(r *Resources) {
12001200
data := (*C.char)(unsafe.Pointer(uintptr(base) + uintptr(r.dataOffset)))
12011201
C.unregisterResourceData(C.int(r.version), tree, name, data)
12021202
}
1203+
1204+
// SetWindowIcon sets the Application Icon.
1205+
// It should run in the func which is qml.Run param.
1206+
// The path can be relative, absolute, or a qrc path.
1207+
// If it is a qrc path, it should be like ":/some/path".
1208+
func SetWindowIcon(path string) {
1209+
cname, cnamelen := unsafeStringData(path)
1210+
RunMain(func() {
1211+
qname := C.newString(cname, cnamelen)
1212+
fmt.Println(qname)
1213+
C.setWindowIcon(qname)
1214+
})
1215+
}

webengine/webengine.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <QtWebEngine>
2+
#include "webengine.h"
3+
4+
void webengineInitialize() {
5+
QtWebEngine::initialize();
6+
}

webengine/webengine.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package webengine
2+
3+
// #cgo CPPFLAGS: -I./
4+
// #cgo CXXFLAGS: -std=c++0x -pedantic-errors -Wall -fno-strict-aliasing
5+
// #cgo LDFLAGS: -lstdc++
6+
// #cgo pkg-config: Qt5WebEngine
7+
//
8+
// #include "webengine.h"
9+
import "C"
10+
11+
import (
12+
"gopkg.in/qml.v1"
13+
)
14+
15+
// Initializes the WebEngine extension.
16+
func Initialize() {
17+
qml.RunMain(func() {
18+
C.webengineInitialize()
19+
})
20+
}

webengine/webengine.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef WEBENGINE_H
2+
#define WEBENGINE_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
void webengineInitialize();
9+
10+
#ifdef __cplusplus
11+
} // extern "C"
12+
#endif
13+
14+
#endif // WEBENGINE_H

0 commit comments

Comments
 (0)