Skip to content

Commit

Permalink
Merge branch 'v1' of https://github.com/tgerring/qml into tgerring-v1
Browse files Browse the repository at this point in the history
# Conflicts:
#	cpp/idletimer.cpp
  • Loading branch information
neclepsio committed Apr 5, 2016
1 parent b752760 commit 3817cca
Show file tree
Hide file tree
Showing 18 changed files with 289 additions and 13 deletions.
19 changes: 13 additions & 6 deletions cpp/capi.cpp
@@ -1,9 +1,10 @@
#include <QApplication>
#include <QQuickView>
#include <QQuickItem>
#include <QtQml>
#include <QDebug>
#include <QQuickImageProvider>
#include <QtWidgets/QApplication>
#include <QtQuick/QQuickView>
#include <QtQuick/QQuickItem>
#include <QtQml/QtQml>
#include <QtCore/QDebug>
#include <QtQuick/QQuickImageProvider>
#include <QtGui/QIcon>

#include <string.h>

Expand Down Expand Up @@ -69,6 +70,12 @@ void applicationFlushAll()
qApp->processEvents();
}

void setWindowIcon(QString_ *path){
QString *str = reinterpret_cast<QString *>(path);
QIcon icon(*str);
qApp->setWindowIcon(icon);
}

void *currentThread()
{
return QThread::currentThread();
Expand Down
1 change: 1 addition & 0 deletions cpp/capi.h
Expand Up @@ -110,6 +110,7 @@ void newGuiApplication();
void applicationExec();
void applicationExit();
void applicationFlushAll();
void setWindowIcon(QString_ *path);

void idleTimerInit(int32_t *guiIdleRun);
void idleTimerStart();
Expand Down
2 changes: 1 addition & 1 deletion cpp/connector.cpp
@@ -1,4 +1,4 @@
#include <QObject>
#include <QtCore/QObject>

#include "connector.h"
#include "capi.h"
Expand Down
2 changes: 1 addition & 1 deletion cpp/connector.h
@@ -1,7 +1,7 @@
#ifndef CONNECTOR_H
#define CONNECTOR_H

#include <QObject>
#include <QtCore/QObject>

#include <stdint.h>

Expand Down
4 changes: 2 additions & 2 deletions cpp/govalue.cpp
Expand Up @@ -4,8 +4,8 @@
#include <QtOpenGL/QGLFunctions>

#include <QtQml/QtQml>
#include <QQmlEngine>
#include <QDebug>
#include <QtQml/QQmlEngine>
#include <QtCore/QDebug>

#include "govalue.h"
#include "capi.h"
Expand Down
4 changes: 2 additions & 2 deletions cpp/govalue.h
Expand Up @@ -6,8 +6,8 @@
// away, and without it this package wouldn't exist.
#include <private/qmetaobject_p.h>

#include <QQuickPaintedItem>
#include <QPainter>
#include <QtQuick/QQuickPaintedItem>
#include <QtGui/QPainter>

#include "capi.h"

Expand Down
58 changes: 58 additions & 0 deletions examples/customicon/qrcpath/qrc.go

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions examples/customicon/qrcpath/qrcpath.go
@@ -0,0 +1,32 @@
package main

import (
"fmt"
"os"

"gopkg.in/qml.v1"
)

func main() {
if err := qml.Run(run); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}

func run() error {
// I genqrc "../res"
qml.SetWindowIcon(":../res/1.ico")

engine := qml.NewEngine()
controls, err := engine.LoadFile("qrc:///../res/main.qml")
if err != nil {
return err
}

window := controls.CreateWindow(nil)

window.Show()
window.Wait()
return nil
}
31 changes: 31 additions & 0 deletions examples/customicon/relativepath/relativepath.go
@@ -0,0 +1,31 @@
package main

import (
"fmt"
"os"

"gopkg.in/qml.v1"
)

func main() {
if err := qml.Run(run); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}

func run() error {
qml.SetWindowIcon("../res/1.ico")

engine := qml.NewEngine()
controls, err := engine.LoadFile("../res/main.qml")
if err != nil {
return err
}

window := controls.CreateWindow(nil)

window.Show()
window.Wait()
return nil
}
Binary file added examples/customicon/res/1.ico
Binary file not shown.
52 changes: 52 additions & 0 deletions examples/customicon/res/main.qml
@@ -0,0 +1,52 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Quick Controls module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/





import QtQuick 2.2
import QtQuick.Controls 1.1

ApplicationWindow {
visible: true
width: 50
height: 50
}
27 changes: 27 additions & 0 deletions examples/webengine/webengine.go
@@ -0,0 +1,27 @@
package main

import (
"fmt"
"os"

"gopkg.in/qml.v1"
"gopkg.in/qml.v1/webengine"
)

func main() {
fmt.Println(qml.Run(func() error {
webengine.Initialize()

engine := qml.NewEngine()
engine.On("quit", func() { os.Exit(0) })

component, err := engine.LoadFile("webengine.qml")
if err != nil {
return err
}
win := component.CreateWindow(nil)
win.Show()
win.Wait()
return nil
}))
}
14 changes: 14 additions & 0 deletions examples/webengine/webengine.qml
@@ -0,0 +1,14 @@
import QtQuick 2.1
import QtWebEngine 1.0
import QtQuick.Controls 1.0

ApplicationWindow {
id: root
width: 1024
height: 768

WebEngineView {
anchors.fill: parent
url: "http://codingame.com"
}
}
3 changes: 2 additions & 1 deletion gl/es2/gl.go
Expand Up @@ -4,8 +4,9 @@ package GL

// #cgo CXXFLAGS: -std=c++0x -pedantic-errors -Wall -fno-strict-aliasing
// #cgo LDFLAGS: -lstdc++
// #cgo !darwin LDFLAGS: -lGL
// #cgo !darwin,!windows LDFLAGS: -lGL
// #cgo darwin LDFLAGS: -framework OpenGL
// #cgo windows LDFLAGS: -lopengl32
// #cgo pkg-config: Qt5Core Qt5OpenGL
//
// #include "funcs.h"
Expand Down
13 changes: 13 additions & 0 deletions qml.go
Expand Up @@ -1200,3 +1200,16 @@ func UnloadResources(r *Resources) {
data := (*C.char)(unsafe.Pointer(uintptr(base) + uintptr(r.dataOffset)))
C.unregisterResourceData(C.int(r.version), tree, name, data)
}

// SetWindowIcon sets the Application Icon.
// It should run in the func which is qml.Run param.
// The path can be relative, absolute, or a qrc path.
// If it is a qrc path, it should be like ":/some/path".
func SetWindowIcon(path string) {
cname, cnamelen := unsafeStringData(path)
RunMain(func() {
qname := C.newString(cname, cnamelen)
fmt.Println(qname)
C.setWindowIcon(qname)
})
}
6 changes: 6 additions & 0 deletions webengine/webengine.cpp
@@ -0,0 +1,6 @@
#include <QtWebEngine>
#include "webengine.h"

void webengineInitialize() {
QtWebEngine::initialize();
}
20 changes: 20 additions & 0 deletions webengine/webengine.go
@@ -0,0 +1,20 @@
package webengine

// #cgo CPPFLAGS: -I./
// #cgo CXXFLAGS: -std=c++0x -pedantic-errors -Wall -fno-strict-aliasing
// #cgo LDFLAGS: -lstdc++
// #cgo pkg-config: Qt5WebEngine
//
// #include "webengine.h"
import "C"

import (
"gopkg.in/qml.v1"
)

// Initializes the WebEngine extension.
func Initialize() {
qml.RunMain(func() {
C.webengineInitialize()
})
}
14 changes: 14 additions & 0 deletions webengine/webengine.h
@@ -0,0 +1,14 @@
#ifndef WEBENGINE_H
#define WEBENGINE_H

#ifdef __cplusplus
extern "C" {
#endif

void webengineInitialize();

#ifdef __cplusplus
} // extern "C"
#endif

#endif // WEBENGINE_H

0 comments on commit 3817cca

Please sign in to comment.