├── .gitignore ├── LICENSE.BSD ├── LICENSE.LGPL ├── README.md ├── bin └── empty.txt ├── doc ├── design.md ├── install.md ├── memory.md └── readme.md ├── examples ├── application │ ├── application.qrc │ ├── application_qrc.go │ ├── build.bat │ ├── build.sh │ ├── images │ │ ├── copy.png │ │ ├── cut.png │ │ ├── new.png │ │ ├── open.png │ │ ├── paste.png │ │ └── save.png │ ├── main.go │ └── mainwindow.go ├── calculatorbuilder │ ├── build.bat │ ├── build.sh │ ├── calculatorbuilder.qrc │ ├── calculatorbuilder_qrc.go │ ├── calculatorform.go │ ├── calculatorform.ui │ └── main.go ├── codeedit │ ├── build.bat │ ├── build.sh │ ├── codeedit.go │ └── main.go ├── minimal │ ├── build.bat │ ├── build.sh │ └── main.go ├── task │ ├── build.bat │ ├── build.sh │ └── main.go ├── version │ ├── build.bat │ ├── build.sh │ └── main.go └── wiggly │ ├── build.bat │ ├── build.sh │ └── main.go ├── id └── id.go ├── qtdrv ├── callback.cpp ├── callback.h ├── cdrv.cpp ├── cdrv.h ├── cdrv_event.cpp ├── cdrv_event.h ├── cdrv_model.cpp ├── cdrv_model.h ├── cdrv_signal.h ├── drv_event.cpp ├── drv_event.h ├── qsyntaxhighlighterhook.cpp ├── qsyntaxhighlighterhook.h ├── qtdrv.pro ├── qtdrv_global.h ├── qurl │ ├── qurl_p.h │ ├── qurlquery.cpp │ ├── qurlquery.h │ ├── qurlrecode.cpp │ └── url_help.h ├── uiapplication.cpp ├── uiapplication.h ├── uidrv.cpp ├── uidrv.h ├── uievent.cpp ├── uievent.h ├── uilib.cpp ├── uilib.h ├── uisignal.cpp ├── uisignal.h ├── uiutil.cpp └── uiutil.h ├── tools └── rcc │ ├── main.cpp │ ├── rcc.cpp │ ├── rcc.h │ ├── rcc.pri │ └── rcc.pro └── ui ├── app.go ├── cdrv.go ├── cdrv_def.h ├── cdrv_init.go ├── cdrv_windows.go ├── qt_enum.go ├── qt_event.go ├── qt_gui.go ├── qt_interface.go └── qt_signal.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | build- 10 | 11 | # Architecture specific extensions/prefixes 12 | *.[568vq] 13 | [568vq].out 14 | 15 | *.cgo1.go 16 | *.cgo2.c 17 | _cgo_defun.c 18 | _cgo_gotypes.go 19 | _cgo_export.* 20 | 21 | _testmain.go 22 | 23 | *.exe 24 | -------------------------------------------------------------------------------- /LICENSE.BSD: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 visualfc . All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 18 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GoQt 2 | ==== 3 | 4 | ## Introduction 5 | 6 | _GoQt is golang bindings to the Qt cross-platform application framework._ 7 | 8 | * Version: 0.1.2 9 | * Author: [visualfc](mailto:visualfc@gmail.com) 10 | 11 | 12 | ## Experiment 13 | GoQt project current is experiment. 14 | 15 | ## What is GoQt 16 | GoQt is a GUI toolkit for the Go programming language. It allows Go programmers to create programs with a robust, highly functional graphical user interface, simply and easily. It is implemented as a Golang extension module (cgo code) that wraps the popular Qt cross platform GUI library, which is written in C++. 17 | 18 | Like Golang and Qt, GoQt is Open Source. The Golang extension module(cgo code) under the BSD license. The C++ bindings library under the LGPL license. 19 | 20 | ## Platforms Support 21 | 22 | ### System 23 | 24 | * Windows x86 (32-bit or 64-bit) 25 | * Linux x86 (32-bit or 64-bit) 26 | * MacOS X10.6 27 | 28 | ### Golang 29 | 30 | * Go1.4.2 31 | * Go1.5.2 32 | 33 | ### ToDo 34 | * Go1.6 cgo check almost completed 35 | 36 | ### Qt Version 37 | 38 | * Qt4.8.5 39 | * Qt5.5.1 40 | 41 | ## Documents 42 | 43 | [GoQt Documents](doc) 44 | 45 | Instructions install GoQt and learning documents. 46 | 47 | ## Examples 48 | 49 | [GoQt Examples](examples) 50 | 51 | Some examples of learning to use GoQt source code. 52 | 53 | ### Website 54 | * Source code 55 | * https://github.com/visualfc/goqt 56 | * LiteIDE 57 | * https://github.com/visualfc/liteide -------------------------------------------------------------------------------- /bin/empty.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/visualfc/goqt/8c774d7992330d283ceaa8477c82c5dd072b3db9/bin/empty.txt -------------------------------------------------------------------------------- /doc/design.md: -------------------------------------------------------------------------------- 1 | # Design 2 | 3 | ## Enum 4 | 5 | * Global 6 | 7 | enum Qt::GlobalColor => ui.Qt_GlobalColor 8 | 9 | Qt::white => ui.Qt_white 10 | 11 | * Class enum 12 | 13 | enum QMessageBox::StandardButton => ui. QMessageBox_StandardButton 14 | 15 | QMessageBox::Save => ui.QMessageBox_Save 16 | 17 | ## Class Name 18 | 19 | ### QObject base class 20 | 21 | QWidget => ui.QWidget 22 | 23 | * c++ 24 | 25 | QWidget *widget = new QWidget(); 26 | widget->show(); 27 | 28 | * go 29 | 30 | widget := ui.NewWidget() 31 | widget.Show() 32 | 33 | ### Plain class 34 | 35 | QPoint => ui.QPoint 36 | 37 | * c++ 38 | 39 | QPoint pt; 40 | pt.setX(100); 41 | pt.setY(100); 42 | 43 | * go 44 | 45 | pt := ui.NewPoint() 46 | pt.SetX(100) 47 | pt.SetY(100) 48 | 49 | ### Class Member Function 50 | 51 | widget->show() => widget.Show() 52 | 53 | ### Class Static Function 54 | 55 | QMessageBox::about() => ui.QMessageBoxAbout() or &ui.QMessageBox{}.About() 56 | 57 | ## Signal Slot 58 | 59 | * c++ 60 | 61 | connect(btn,SIGNAL(clicked()),this,SLOT(onClicked())); 62 | 63 | * go 64 | 65 | btn.OnClicked(func() { 66 | //fmt.Println("clicked") 67 | }) 68 | 69 | 70 | ## Event 71 | 72 | * c++ 73 | 74 | class MyWidget : public QWidget 75 | 76 | virtual MyWidget::paintEvent(e *QPaintEvent) 77 | { 78 | QWidget::paintEvent(e) 79 | 80 | QPainter p(this); 81 | //p.draw 82 | } 83 | 84 | * go 85 | 86 | type MyWidget struct { 87 | *ui.QWidget 88 | } 89 | 90 | func NewMyWidget() *MyWidget { 91 | w := &MyWidget{} 92 | w.QWidget = ui.NewWidget() 93 | w.InstallEventFilter(w) 94 | } 95 | 96 | func (w *MyWidget) OnPaintEvent(e *ui.QPaintEvent) bool { 97 | w.PaintEvent() //w.QWidget.PaintEvent() 98 | 99 | painter := ui.NewPainterWithPaintDevice(w) 100 | defer painter.Delete() 101 | 102 | //painter.Draw ... 103 | 104 | return true 105 | } 106 | 107 | ## Rename 108 | 109 | ### New 110 | QAction::QAction(QObject*) => func NewAction(parent QObjectInterface) *QAction 111 | QAction::QAction(QString const&,QObject*) => func NewActionWithTextParent(text string,parent QObjectInterface) *QAction 112 | QAction::QAction(QIcon const&,QString const&,QObject*) => func NewActionWithIconTextParent(icon *QIcon,text string,parent QObjectInterface) *QAction 113 | 114 | ### Function 115 | 116 | QWidget::resize(QSize const&) => func (q *QWidget) Resize(value *QSize) 117 | QWidget::resize(int,int) => func (q *QWidget) ResizeWithWidthHeight(w int,h int) -------------------------------------------------------------------------------- /doc/install.md: -------------------------------------------------------------------------------- 1 | # Install GoQt 2 | 3 | ## Platforms Support 4 | 5 | ### System 6 | 7 | * Windows x86 (32-bit or 64-bit) 8 | * Linux x86 (32-bit or 64-bit) 9 | * MacOS X10.6 10 | 11 | ### Golang 12 | 13 | * Go1.4.2 14 | * Go1.5.2 15 | 16 | ### Qt Version 17 | 18 | * Qt4.8.5 19 | 20 | * Qt5.5.1 21 | 22 | My test Qt4.8.5 on Windows Linux and MacOS X 23 | My test Qt5.5.1 only on Windows. 24 | 25 | 26 | ## Install GoQt 27 | 28 | 1. Download github.com/visualfc/goqt 29 | 2. Use QtCreator or make build goqt/qtdrv and goqt/tools/rcc, need install QtSDK 30 | 3. Install goqt/ui 31 | 32 | ### Windows 33 | 34 | QtSDK x86_32 build for GOARCH=386 and CGO_ENABLED=1 35 | QtSDK x86_64 build for GOARCH=amd64 and CGO_ENABLED=1 36 | 37 | #### 1.get goqt 38 | > go get github.com/visualfc/goqt 39 | #### 2.build qtdrv, need install QtSDK 40 | > cd goqt\qtdrv 41 | > qmake "CONFIG+=release" 42 | > mingw32-make 43 | #### 3.build rcc 44 | > cd goqt\tools\rcc 45 | > qmake "CONFIG+=release" 46 | > mingw32-make 47 | #### 4.build ui, need CGO_ENABLED=1 and install gcc 48 | > set GOARCH=386 49 | > set CGO_ENABLED=1 50 | > cd goqt\ui 51 | > go install -v 52 | #### 5.build examples 53 | > set GOARCH=386 54 | > set CGO_ENABLED=1 55 | > cd goqt\examples\minimal 56 | > build.bat 57 | > ..\..\bin\minimal.exe 58 | 59 | ### Linux 60 | 61 | #### 1.get goqt 62 | > go get github.com/visualfc/goqt 63 | #### 2.build qtdrv, need install QtSDK 64 | > cd goqt/qtdrv 65 | > qmake "CONFIG+=release" 66 | > make 67 | #### 3.build rcc 68 | > cd goqt/tools/rcc 69 | > qmake "CONFIG+=release" 70 | > make 71 | #### 4.build ui, need CGO_ENABLED=1 and install gcc 72 | > cd goqt/ui 73 | > go install -v 74 | #### 5.build examples 75 | > cd goqt/examples/minimal 76 | > ./build.sh 77 | > ../../bin/minimal 78 | 79 | ### MacOS X 80 | 81 | #### 1.get goqt 82 | > go get github.com/visualfc/goqt 83 | #### 2.build qtdrv, need install QtSDK 84 | > cd goqt/qtdrv 85 | > qmake -spec macx-g++ "CONFIG+=release" 86 | > make 87 | #### 3.build rcc 88 | > cd goqt/tools/rcc 89 | > qmake -spec macx-g++ "CONFIG+=release" 90 | > make 91 | #### 4.build ui, need CGO_ENABLED=1 and install gcc 92 | > cd goqt/ui 93 | > go install -v 94 | #### 5.build examples 95 | > cd goqt/examples/minimal 96 | > ./build.sh 97 | > ../../bin/minimal -------------------------------------------------------------------------------- /doc/memory.md: -------------------------------------------------------------------------------- 1 | # Memory Managements 2 | 3 | ## Go to Qt C++ pointer mapping 4 | 5 | * Non QObject based 6 | 7 | pt := ui.NewQPoint() // create new QPoint c++ pointer 8 | //pt.Delete() // delete c++ pointer. 9 | //The pt can manual delete or use golang auto gc. 10 | //When golang auto gc and clean pt, the c++ pointer auto delete. 11 | 12 | * QObject based 13 | 14 | widget := ui.NewQWidget() // create new QWidget c++ pointer 15 | widget.Delete() // delete c++ pointer and children 16 | 17 | * System resources 18 | 19 | painter := ui.NewQPainterWithPaintDevice(widget) //create new QPinter c++ pointer, resources must delete 20 | defer painter.Delete() //delete c++ pointer and resources 21 | 22 | 23 | ## QObject based struct 24 | 25 | GoQt QObject memory managements similar to Qt. 26 | 27 | QObjects organize themselves in object trees. When you create a QObject with another object as parent, it's added to the parent's children() list, and is deleted when the parent is. It turns out that this approach fits the needs of GUI objects very well. For example, a QShortcut (keyboard shortcut) is a child of the relevant window, so when the user closes that window, the shorcut is deleted too. 28 | 29 | QWidget, the base class of everything that appears on the screen, extends the parent-child relationship. A child normally also becomes a child widget, i.e. it is displayed in its parent's coordinate system and is graphically clipped by its parent's boundaries. For example, when the application deletes a message box after it has been closed, the message box's buttons and label are also deleted, just as we'd want, because the buttons and label are children of the message box. 30 | 31 | You can also delete child objects yourself, and they will remove themselves from their parents. For example, when the user removes a toolbar it may lead to the application deleting one of its QToolBar objects, in which case the tool bar's QMainWindow parent would detect the change and reconfigure its screen space accordingly. 32 | 33 | ## Non QObject struct 34 | 35 | Non QObject struct auto gc or manual management. 36 | 37 | If struct hold memory only, this can golang gc or manually manage. 38 | If struct hold system resources, you need to manually manage and delete. 39 | 40 | * Auto gc for memory only 41 | 42 | pt := ui.NewQPoint() //this can auto gc 43 | //defer pt.Delete() 44 | 45 | * Manual resources managements 46 | 47 | painter := ui.NewQPainterWithPaintDevice(widget) //must delete 48 | defer painter.Delete() 49 | 50 | -------------------------------------------------------------------------------- /doc/readme.md: -------------------------------------------------------------------------------- 1 | ## GoQt Document 2 | 3 | 4 | ### Installing GoQt 5 | 6 | [Getting Started ](install.md) 7 | 8 | Instructions for downloading and installing the GoQt and build. 9 | 10 | ### Learning GoQt 11 | 12 | [Design Document](design.md) 13 | 14 | GoQt naming and conversion design document. 15 | 16 | [Memory Manager] (memory.md) 17 | 18 | GoQt memory manager document. -------------------------------------------------------------------------------- /examples/application/application.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/copy.png 4 | images/cut.png 5 | images/new.png 6 | images/open.png 7 | images/paste.png 8 | images/save.png 9 | 10 | 11 | -------------------------------------------------------------------------------- /examples/application/build.bat: -------------------------------------------------------------------------------- 1 | ..\..\bin\goqt_rcc -go main -o application_qrc.go application.qrc 2 | go build -ldflags "-H windowsgui" -o ..\..\bin\application.exe -------------------------------------------------------------------------------- /examples/application/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ../../bin/goqt_rcc -go main -o application_qrc.go application.qrc 3 | go build -ldflags "-r ." -o ../../bin/application -------------------------------------------------------------------------------- /examples/application/images/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/visualfc/goqt/8c774d7992330d283ceaa8477c82c5dd072b3db9/examples/application/images/copy.png -------------------------------------------------------------------------------- /examples/application/images/cut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/visualfc/goqt/8c774d7992330d283ceaa8477c82c5dd072b3db9/examples/application/images/cut.png -------------------------------------------------------------------------------- /examples/application/images/new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/visualfc/goqt/8c774d7992330d283ceaa8477c82c5dd072b3db9/examples/application/images/new.png -------------------------------------------------------------------------------- /examples/application/images/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/visualfc/goqt/8c774d7992330d283ceaa8477c82c5dd072b3db9/examples/application/images/open.png -------------------------------------------------------------------------------- /examples/application/images/paste.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/visualfc/goqt/8c774d7992330d283ceaa8477c82c5dd072b3db9/examples/application/images/paste.png -------------------------------------------------------------------------------- /examples/application/images/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/visualfc/goqt/8c774d7992330d283ceaa8477c82c5dd072b3db9/examples/application/images/save.png -------------------------------------------------------------------------------- /examples/application/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | 6 | "github.com/visualfc/goqt/ui" 7 | ) 8 | 9 | func main() { 10 | ui.RunEx(os.Args, func() { 11 | app := ui.Application() 12 | app.SetOrganizationName("GoQt") 13 | app.SetApplicationName("Application Example") 14 | 15 | w := NewMainWindow() 16 | w.Show() 17 | }) 18 | } 19 | -------------------------------------------------------------------------------- /examples/application/mainwindow.go: -------------------------------------------------------------------------------- 1 | // mainwindow 2 | package main 3 | 4 | import "github.com/visualfc/goqt/ui" 5 | 6 | type MainWindow struct { 7 | *ui.QMainWindow 8 | edit *ui.QPlainTextEdit 9 | curFile string 10 | } 11 | 12 | func NewMainWindow() *MainWindow { 13 | w := &MainWindow{} 14 | w.QMainWindow = ui.NewMainWindow() 15 | w.InstallEventFilter(w) 16 | 17 | w.edit = ui.NewPlainTextEdit() 18 | w.SetCentralWidget(w.edit) 19 | 20 | w.createActions() 21 | 22 | w.readSettings() 23 | 24 | w.edit.Document().OnContentsChanged(w.documentWasModified) 25 | w.setCurrentFile("") 26 | 27 | return w 28 | } 29 | 30 | func (w *MainWindow) readSettings() { 31 | setting := ui.NewSettingsWithOrganizationApplicationParent("GoQt", "Application Example", w) 32 | defer setting.Delete() 33 | pos := setting.ValueWithKeyDefaultvalue("pos", ui.NewVariantWithPoint(ui.NewPointWithXposYpos(200, 200))).ToPoint() 34 | size := setting.ValueWithKeyDefaultvalue("size", ui.NewVariantWithSize(ui.NewSizeWithWidthHeight(400, 400))).ToSize() 35 | w.Move(pos) 36 | w.Resize(size) 37 | } 38 | 39 | func (w *MainWindow) writeSettings() { 40 | setting := ui.NewSettingsWithOrganizationApplicationParent("GoQt", "Application Example", nil) 41 | setting.SetValue("pos", ui.NewVariantWithPoint(w.Pos())) 42 | setting.SetValue("size", ui.NewVariantWithSize(w.Size())) 43 | } 44 | 45 | func (w *MainWindow) maybeSave() bool { 46 | if w.edit.Document().IsModified() { 47 | ret := ui.QMessageBoxWarningWithParentTitleTextButtonsStandardbutton(w, "Application", 48 | "The document has been modified.\nDo youwant to save your changed?", 49 | ui.QMessageBox_Save|ui.QMessageBox_Discard|ui.QMessageBox_Cancel, 50 | ui.QMessageBox_Save) 51 | if ret == ui.QMessageBox_Save { 52 | return w.save() 53 | } else if ret == ui.QMessageBox_Cancel { 54 | return false 55 | } 56 | } 57 | return true 58 | } 59 | 60 | func (w *MainWindow) save() bool { 61 | if w.curFile == "" { 62 | return w.saveAs() 63 | } 64 | return w.saveFile(w.curFile) 65 | } 66 | 67 | func (w *MainWindow) saveAs() bool { 68 | fileName := ui.QFileDialogGetSaveFileName() 69 | if fileName == "" { 70 | return false 71 | } 72 | return w.saveFile(fileName) 73 | } 74 | 75 | func (w *MainWindow) saveFile(fileName string) bool { 76 | file := ui.NewFileWithName(fileName) 77 | defer file.Delete() 78 | if !file.Open(ui.QIODevice_WriteOnly | ui.QIODevice_Text) { 79 | return false 80 | } 81 | file.Write([]byte(w.edit.ToPlainText())) 82 | w.setCurrentFile(fileName) 83 | w.StatusBar().ShowMessageWithTextTimeout("File saved", 2000) 84 | return true 85 | } 86 | 87 | func (w *MainWindow) OnCloseEvent(ev *ui.QCloseEvent) bool { 88 | if w.maybeSave() { 89 | w.writeSettings() 90 | ev.Accept() 91 | } else { 92 | ev.Ignore() 93 | } 94 | return true 95 | } 96 | 97 | func (w *MainWindow) createActions() { 98 | newAct := ui.NewActionWithTextParent(w.Tr("&New"), w) 99 | newAct.SetIcon(ui.NewIconWithFilename(":/images/new.png")) 100 | newAct.SetShortcuts(ui.QKeySequence_New) 101 | newAct.SetStatusTip("Create a new file") 102 | newAct.OnTriggered(func() { w.newFile() }) 103 | 104 | openAct := ui.NewActionWithTextParent("&Open...", w) 105 | openAct.SetIcon(ui.NewIconWithFilename(":/images/open.png")) 106 | openAct.SetShortcuts(ui.QKeySequence_Open) 107 | openAct.SetStatusTip("Open an existing file") 108 | openAct.OnTriggered(func() { w.open() }) 109 | 110 | saveAct := ui.NewActionWithTextParent("&Save", w) 111 | saveAct.SetIcon(ui.NewIconWithFilename(":/images/save.png")) 112 | saveAct.SetShortcuts(ui.QKeySequence_Save) 113 | saveAct.SetStatusTip("Save the document to disk") 114 | saveAct.OnTriggered(func() { w.save() }) 115 | 116 | saveAsAct := ui.NewActionWithTextParent("&SaveAs...", w) 117 | saveAsAct.SetShortcuts(ui.QKeySequence_SaveAs) 118 | saveAsAct.SetStatusTip("Save the document under a new name") 119 | saveAsAct.OnTriggered(func() { w.saveAs() }) 120 | 121 | exitAct := ui.NewActionWithTextParent("&Exit", w) 122 | exitAct.SetShortcuts(ui.QKeySequence_Quit) 123 | exitAct.SetStatusTip("Exit the application") 124 | exitAct.OnTriggered(func() { w.Close() }) 125 | 126 | copyAct := ui.NewActionWithTextParent("&Copy", w) 127 | copyAct.SetIcon(ui.NewIconWithFilename(":/images/copy.png")) 128 | copyAct.SetShortcuts(ui.QKeySequence_Copy) 129 | copyAct.SetStatusTip("Copy the current selection's contents to the clipboard") 130 | copyAct.OnTriggered(func() { w.edit.Copy() }) 131 | w.edit.OnCopyAvailable(func(b bool) { copyAct.SetEnabled(b) }) 132 | 133 | cutAct := ui.NewActionWithTextParent("&Cut", w) 134 | cutAct.SetIcon(ui.NewIconWithFilename(":/images/cut.png")) 135 | cutAct.SetShortcuts(ui.QKeySequence_Cut) 136 | cutAct.SetStatusTip("Cut the current selection's contents to the clipboard") 137 | cutAct.OnTriggered(func() { w.edit.Cut() }) 138 | w.edit.OnCopyAvailable(func(b bool) { cutAct.SetEnabled(b) }) 139 | 140 | pasteAct := ui.NewActionWithTextParent("&Paste", w) 141 | pasteAct.SetIcon(ui.NewIconWithFilename(":/images/paste.png")) 142 | pasteAct.SetShortcuts(ui.QKeySequence_Paste) 143 | pasteAct.SetStatusTip("Paste the clipboard's contents into the current selection") 144 | pasteAct.OnTriggered(func() { w.edit.Paste() }) 145 | 146 | aboutAct := ui.NewActionWithTextParent("&About", w) 147 | aboutAct.SetStatusTip("Show the application's About box") 148 | aboutAct.OnTriggered(func() { 149 | ui.QMessageBoxAbout(w, "About Application", 150 | w.Tr("The Application example demonstrates how to "+ 151 | "write modern GUI applications using Qt, with a menu bar, "+ 152 | "toolbars, and a status bar.")) 153 | }) 154 | aboutQtAct := ui.NewActionWithTextParent("About &Qt", w) 155 | aboutQtAct.SetStatusTip("Show the Qt library's About box") 156 | aboutQtAct.OnTriggered(func() { ui.QApplicationAboutQt() }) 157 | 158 | fileMenu := w.MenuBar().AddMenuWithTitle("&File") 159 | fileMenu.AddAction(newAct) 160 | fileMenu.AddAction(openAct) 161 | fileMenu.AddAction(saveAct) 162 | fileMenu.AddAction(saveAsAct) 163 | fileMenu.AddSeparator() 164 | fileMenu.AddAction(exitAct) 165 | 166 | editMenu := w.MenuBar().AddMenuWithTitle("&Edit") 167 | editMenu.AddAction(copyAct) 168 | editMenu.AddAction(cutAct) 169 | editMenu.AddAction(pasteAct) 170 | 171 | helpMenu := w.MenuBar().AddMenuWithTitle("&Help") 172 | helpMenu.AddAction(aboutAct) 173 | helpMenu.AddSeparator() 174 | helpMenu.AddAction(aboutQtAct) 175 | 176 | fileToolBar := w.AddToolBar("File") 177 | fileToolBar.AddAction(newAct) 178 | fileToolBar.AddAction(openAct) 179 | fileToolBar.AddAction(saveAct) 180 | 181 | editToolBar := w.AddToolBar("Edit") 182 | editToolBar.AddAction(copyAct) 183 | editToolBar.AddAction(cutAct) 184 | editToolBar.AddAction(pasteAct) 185 | 186 | copyAct.SetEnabled(false) 187 | cutAct.SetEnabled(false) 188 | 189 | w.StatusBar().ShowMessage("Ready") 190 | } 191 | 192 | func (w *MainWindow) newFile() { 193 | if w.maybeSave() { 194 | w.edit.Clear() 195 | w.setCurrentFile("") 196 | } 197 | } 198 | 199 | func (w *MainWindow) open() { 200 | if w.maybeSave() { 201 | filename := ui.QFileDialogGetOpenFileName() 202 | if filename != "" { 203 | w.loadFile(filename) 204 | } 205 | } 206 | } 207 | 208 | func (w *MainWindow) loadFile(filename string) { 209 | file := ui.NewFileWithName(filename) 210 | defer file.Delete() 211 | 212 | if !file.Open(ui.QIODevice_ReadOnly) { 213 | return 214 | } 215 | w.edit.SetPlainText(string(file.ReadAll())) 216 | w.setCurrentFile(filename) 217 | w.StatusBar().ShowMessageWithTextTimeout("File loaded", 2000) 218 | } 219 | 220 | func (w *MainWindow) documentWasModified() { 221 | w.SetWindowModified(w.edit.Document().IsModified()) 222 | } 223 | 224 | func (w *MainWindow) setCurrentFile(filename string) { 225 | w.curFile = filename 226 | w.edit.Document().SetModified(false) 227 | w.SetWindowModified(false) 228 | shownName := w.curFile 229 | if shownName == "" { 230 | shownName = "untitled.txt" 231 | } 232 | w.SetWindowFilePath(shownName) 233 | } 234 | -------------------------------------------------------------------------------- /examples/calculatorbuilder/build.bat: -------------------------------------------------------------------------------- 1 | ..\..\bin\goqt_rcc -go main -o calculatorbuilder_qrc.go calculatorbuilder.qrc 2 | go build -ldflags "-H windowsgui" -o ..\..\bin\calculatorbuilder.exe -------------------------------------------------------------------------------- /examples/calculatorbuilder/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ../../bin/goqt_rcc -go main -o calculatorbuilder_qrc.go calculatorbuilder.qrc 3 | go build -ldflags "-r ." -o ../../bin/calculatorbuilder -------------------------------------------------------------------------------- /examples/calculatorbuilder/calculatorbuilder.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | calculatorform.ui 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/calculatorbuilder/calculatorbuilder_qrc.go: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Resource object code 3 | ** 4 | ** Created by: The Resource Compiler for Qt version 4.8.5 5 | ** 6 | ** WARNING! All changes made in this file will be lost! 7 | *****************************************************************************/ 8 | 9 | package main 10 | 11 | import "github.com/visualfc/goqt/ui" 12 | 13 | var qt_resource_data = []byte{ 14 | // :/forms/calculatorform.ui 15 | 0x0,0x0,0x4,0x67, 16 | 0x0, 17 | 0x0,0x20,0x2b,0x78,0x9c,0xed,0x59,0x51,0x6f,0xdb,0x36,0x10,0x7e,0x1f,0xd0,0xff, 18 | 0x20,0xf8,0xb5,0xc0,0x64,0xbb,0x76,0x12,0x7,0xb2,0x80,0xa6,0x40,0x97,0xd,0x59, 19 | 0xb7,0x2c,0x41,0xfa,0x18,0xd0,0x32,0x63,0xb3,0x91,0x48,0x81,0xa2,0x62,0x2b,0xe8, 20 | 0x8f,0x1f,0x49,0x89,0x12,0x49,0x29,0x96,0xea,0xca,0x4d,0xb,0x18,0x79,0x30,0x79, 21 | 0x47,0x1e,0x8f,0x77,0xdf,0x7d,0xa7,0x48,0x5e,0x8a,0x9c,0x27,0x48,0x13,0x44,0xf0, 22 | 0x7c,0x30,0xf9,0x7d,0x38,0x70,0xfc,0x37,0xbf,0x39,0x1e,0x48,0xd9,0x9a,0x50,0xdf, 23 | 0x73,0x8b,0x81,0x90,0x5,0x24,0x8a,0x20,0x66,0x5c,0xa8,0x46,0x42,0xa,0xb7,0x31, 24 | 0xa1,0x2c,0x2,0x1,0x25,0x5c,0xa3,0xcf,0xe4,0x9e,0x10,0x24,0x89,0xff,0x1,0x84, 25 | 0x41,0x1a,0x2,0x46,0xe8,0x47,0x42,0x23,0xbe,0x5f,0x4a,0x85,0x7e,0x83,0x96,0x2b, 26 | 0xc8,0x1c,0x29,0x98,0xf,0xae,0x3f,0xcb,0xe9,0xc0,0xc1,0x20,0x82,0xf3,0x81,0xb9, 27 | 0x2d,0xf7,0xcc,0xf1,0x62,0x4a,0x62,0x48,0x59,0x56,0x2c,0x22,0x8b,0x2f,0x30,0x60, 28 | 0x9f,0xf8,0xb8,0x58,0xe0,0x78,0x9,0xa3,0x8,0xaf,0x1c,0x4c,0x18,0x9d,0xf,0x18, 29 | 0x4d,0x85,0xc6,0x76,0x21,0x5f,0x93,0x5b,0x74,0x95,0xc9,0xc6,0x3,0x56,0x90,0x44, 30 | 0x90,0xd1,0xac,0x34,0x4f,0xf9,0x79,0xf9,0xd0,0xf1,0xb6,0xfe,0xd0,0x73,0xb7,0x6a, 31 | 0x96,0x89,0x59,0xa6,0x66,0xfc,0x6e,0x6c,0xed,0x8f,0x4f,0x4f,0x3c,0x37,0x1f,0x16, 32 | 0xf2,0x35,0x44,0xab,0x35,0xf3,0x67,0x67,0x9e,0x5b,0xc,0x73,0xbb,0x6e,0x69,0xb8, 33 | 0xc5,0xa3,0x4,0x3d,0xc3,0x7f,0x49,0x88,0x82,0xca,0x27,0x21,0x8a,0xa5,0xa8,0x3c, 34 | 0x45,0x88,0x58,0x16,0x43,0x7f,0xca,0xcf,0x29,0x27,0x85,0xf6,0x49,0xd7,0x3e,0xd9, 35 | 0x5a,0x9e,0x71,0x1e,0x1f,0xc8,0x82,0xb5,0xb8,0x90,0x36,0x53,0xbb,0xa1,0xae,0xd7, 36 | 0x66,0xc5,0x45,0x2c,0x6f,0x5a,0xae,0xb3,0x41,0x78,0x49,0x36,0xb7,0x88,0x85,0x76, 37 | 0xa,0xb5,0xac,0x39,0x17,0x29,0xa,0x97,0x90,0xee,0xcc,0x5c,0x8,0x32,0x92,0x56, 38 | 0x68,0xfa,0x83,0xa2,0xe5,0x95,0x14,0x95,0x76,0x5b,0xc1,0xd3,0x88,0x1e,0x57,0x5d, 39 | 0xcc,0x38,0xae,0x66,0x2d,0x2,0x74,0x85,0x70,0x65,0x9,0xa7,0xd1,0x2,0x52,0x7f, 40 | 0xe6,0xb9,0xc5,0xa8,0x93,0x95,0x24,0x6,0x1,0x77,0xa0,0x66,0xe6,0xa4,0xc5,0xc, 41 | 0x62,0x30,0x72,0x28,0xd9,0xcc,0x7,0xbc,0x88,0x3,0x12,0xa6,0x11,0x96,0x43,0x65, 42 | 0xc6,0xa,0xce,0xe5,0x5,0xd9,0x9a,0xc1,0xe9,0x14,0x9e,0x9d,0x1,0xaa,0x7b,0xd5, 43 | 0x1a,0xa4,0xea,0x7e,0x23,0xf3,0x7e,0x5d,0x6c,0xd9,0xa1,0x7a,0x31,0x58,0x8d,0xc6, 44 | 0x44,0xc0,0xaa,0x8d,0x56,0x78,0xee,0x1a,0xc2,0xd3,0x31,0x40,0x2d,0x21,0x6a,0xf2, 45 | 0xa5,0x43,0x98,0x76,0x4,0xaa,0x9b,0xc5,0x7a,0xb0,0x76,0x84,0xeb,0x5,0x93,0x46, 46 | 0xc8,0x9c,0x1a,0x7d,0x5f,0x81,0x5,0xc,0x15,0x7b,0x87,0xf9,0x44,0x5b,0xde,0x35, 47 | 0x7c,0x2f,0x50,0xb8,0x34,0x68,0xd4,0xff,0xe,0x57,0xdb,0x79,0x5c,0x2d,0xd3,0xe8, 48 | 0x5c,0x89,0xb6,0x22,0xc6,0x5b,0x4b,0x98,0x9,0x61,0x66,0x9,0x73,0x62,0x9f,0x4c, 49 | 0x4d,0x8a,0x57,0xda,0x82,0xde,0x47,0x33,0x93,0xe9,0x4b,0xb7,0xed,0xa3,0xbb,0x5d, 50 | 0x84,0xc1,0x2d,0x6b,0x8e,0x97,0xff,0x27,0x8e,0x39,0x86,0x47,0x9d,0x83,0x24,0xdd, 51 | 0xe6,0x19,0xd4,0xd3,0x6e,0xe6,0xb8,0x2d,0xe5,0x37,0x31,0xc2,0xbc,0x54,0x54,0xd2, 52 | 0x91,0x70,0xa0,0x90,0x8d,0xfa,0x4c,0xbe,0x61,0xf8,0x35,0x41,0x30,0x3e,0xd9,0x13, 53 | 0x5,0xe3,0x69,0xaf,0x28,0x88,0x48,0x9a,0xc0,0x5b,0xa,0x82,0x47,0xbb,0xa8,0xf9, 54 | 0xda,0x5,0x21,0xa1,0x2f,0x22,0xe7,0xb9,0x72,0xf8,0xdd,0x38,0xf0,0xdc,0x9c,0x1f, 55 | 0x2b,0x3a,0xd5,0xd5,0x16,0x95,0xb6,0xb2,0xc2,0xfd,0xbb,0x9e,0x48,0xd5,0x2f,0xcc, 56 | 0xd5,0x1,0xd1,0x85,0x11,0x1b,0xc1,0x50,0x83,0x2,0x7,0xc2,0x74,0x62,0x21,0xa1, 57 | 0x81,0xc,0xa,0x10,0x9c,0x36,0x60,0x40,0x21,0x60,0x3a,0x6e,0x40,0x80,0x9d,0xff, 58 | 0x2e,0x8e,0xd7,0x18,0x40,0xd5,0xff,0xdb,0xfd,0x2,0x1,0x42,0xb4,0xc2,0xe2,0x89, 59 | 0xde,0x32,0xca,0x1,0x71,0xcd,0xce,0xcf,0xdf,0xb,0xf5,0x7,0xae,0x96,0x8f,0x5f, 60 | 0x70,0xb7,0xb3,0x36,0x94,0x76,0x22,0xe5,0xd8,0x74,0xf,0xd1,0x74,0xef,0xc7,0xbd, 61 | 0xb7,0xdd,0xfb,0xf1,0xb1,0xf1,0xb6,0x37,0xde,0xee,0x41,0x3a,0x68,0xe3,0xed,0x35, 62 | 0xfd,0x86,0xe1,0x63,0xe3,0xfd,0xd5,0x1b,0xaf,0xc9,0xd,0x3d,0xb4,0xde,0x26,0x66, 63 | 0xe8,0xb5,0xf9,0x8e,0xc6,0xc3,0x5f,0xa4,0xfb,0xce,0x8f,0xdd,0xf7,0xd8,0x7d,0x79, 64 | 0xab,0x14,0x7f,0x7,0xe8,0xc0,0xe2,0xef,0xa7,0xec,0xc2,0xef,0x9a,0xca,0x4e,0xeb, 65 | 0xc2,0xa7,0x3f,0xaa,0xb,0xff,0x93,0x32,0xde,0xac,0x7e,0x60,0x13,0x36,0xb2,0x4f, 66 | 0xe4,0xe9,0xea,0x15,0x76,0x7f,0xe9,0xd7,0xed,0xbe,0x6a,0x3,0x9e,0xec,0x9,0x80, 67 | 0x71,0xbf,0x0,0x78,0xa0,0xfc,0xe7,0x66,0xd,0xe2,0x5a,0xf4,0x20,0xaf,0x68,0xff, 68 | 0xfa,0xa3,0xd0,0x9f,0x9f,0x73,0x36,0xf3,0x5c,0x29,0xd9,0xfb,0x84,0x25,0xd9,0xec, 69 | 0x3c,0xe2,0x26,0xc5,0x8f,0x10,0xef,0x7b,0xca,0xe,0x20,0xf,0xf7,0xcf,0x73,0x73, 70 | 0x37,0xb1,0xfb,0xc9,0xfb,0x45,0x42,0xc2,0x94,0xc1,0xaf,0xa5,0xe4,0x82,0x30,0x46, 71 | 0xa2,0xaf,0x56,0xc7,0xa9,0xe6,0x97,0x35,0x1,0xa1,0xe8,0x99,0x60,0x6,0xc2,0xfb, 72 | 0xbf,0x41,0xf2,0x58,0x29,0xfe,0x4a,0x13,0x86,0x1e,0xb2,0x4a,0x70,0x5,0xc1,0x92, 73 | 0xdf,0x45,0x17,0x3c,0xb0,0x6a,0xf6,0x9f,0x40,0x46,0x35,0xbd,0x25,0xb1,0x36,0xa1, 74 | 0x0,0x85,0xc6,0xde,0x3b,0xdb,0x8f,0x3b,0x7e,0x79,0x14,0x14,0x5e,0x58,0x1d,0xf2, 75 | 0x20,0x4f,0x5d,0xa6,0x52,0x57,0x69,0xef,0xe0,0x47,0x8d,0xef,0xe0,0x45,0x43,0xd2, 76 | 0xde,0x49,0xef,0xfb,0xba,0xdd,0x7f,0x2a,0xee,0x7c,0x23,0xed,0xd9,0x60,0x69,0x7f, 77 | 0x71,0xde,0x40,0x6,0x16,0x11,0x70,0x12,0x38,0x9b,0x1a,0x2c,0xc0,0x19,0xe0,0x64, 78 | 0x66,0x30,0x80,0xfa,0xc2,0x35,0xac,0x55,0x7f,0x59,0xf9,0xc3,0x5a,0xe5,0x9b,0x55, 79 | 0xdf,0xee,0x2a,0x47,0x19,0x4f,0x38,0x60,0x88,0x18,0x1f,0xd,0xf2,0x3a,0xe4,0x18, 80 | 0x50,0xe9,0x37,0xab,0xb0,0xc3,0xb7,0x3,0xf4,0xc,0x2f,0x91,0x51,0x26,0xf2,0x2b, 81 | 0xda,0xb7,0x5c,0x6f,0xd2,0x74,0x3d,0xdd,0x48,0xcd,0xd,0xae,0xd6,0x20,0xf0,0x2, 82 | 0x76,0xb4,0xef,0x37,0xa3,0xfe,0xb1,0xb3,0x2e,0xeb,0xf6,0xa0,0xe8,0x19,0x9d,0x9d, 83 | 0xd9,0xf0,0xb1,0xfe,0x83,0x53,0xcf,0xec,0xb3,0xd7,0x84,0x4f,0xc5,0x62,0x7,0x3, 84 | 0xd0,0xe4,0x1b,0xeb,0x63,0x3f,0x0,0xe9,0xac,0xa4,0xf3,0x9b,0x17,0xa3,0x6d,0x4, 85 | 0xe2,0x87,0x14,0x7,0x22,0x8,0x3e,0xb7,0x68,0xa,0xc4,0x1a,0xa,0x13,0x92,0xd2, 86 | 0x0,0x26,0xf2,0x91,0xdd,0xb,0x8,0xc6,0x50,0x6a,0xa5,0xc0,0x73,0x53,0xc4,0x7f, 87 | 0xfe,0x7,0x57,0xf4,0xd1,0x99, 88 | 89 | } 90 | 91 | var qt_resource_name = []byte{ 92 | // forms 93 | 0x0,0x5, 94 | 0x0,0x6d,0x69,0x43, 95 | 0x0,0x66, 96 | 0x0,0x6f,0x0,0x72,0x0,0x6d,0x0,0x73, 97 | // calculatorform.ui 98 | 0x0,0x11, 99 | 0x4,0x9f,0xa2,0x19, 100 | 0x0,0x63, 101 | 0x0,0x61,0x0,0x6c,0x0,0x63,0x0,0x75,0x0,0x6c,0x0,0x61,0x0,0x74,0x0,0x6f,0x0,0x72,0x0,0x66,0x0,0x6f,0x0,0x72,0x0,0x6d,0x0,0x2e,0x0,0x75,0x0,0x69, 102 | 103 | 104 | } 105 | 106 | var qt_resource_struct = []byte{ 107 | // : 108 | 0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x1, 109 | // :/forms 110 | 0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x2, 111 | // :/forms/calculatorform.ui 112 | 0x0,0x0,0x0,0x10,0x0,0x1,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0, 113 | 114 | } 115 | 116 | func init() { 117 | if ui.IsLoaded() { 118 | ui.QResHelpRegisterResourceData(0x01, &qt_resource_struct[0], &qt_resource_name[0], &qt_resource_data[0]) 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /examples/calculatorbuilder/calculatorform.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "reflect" 7 | 8 | "github.com/visualfc/goqt/ui" 9 | ) 10 | 11 | type CalclatorForm struct { 12 | *ui.QWidget 13 | spinBox1 *ui.QSpinBox 14 | spinBox2 *ui.QSpinBox 15 | outputLable *ui.QLabel 16 | } 17 | 18 | func IsValidDriver(v ui.Driver) bool { 19 | return !reflect.ValueOf(v).IsNil() 20 | } 21 | 22 | func NewCalclatorForm() (*CalclatorForm, error) { 23 | w := &CalclatorForm{} 24 | w.QWidget = ui.NewWidget() 25 | 26 | file := ui.NewFileWithName(":/forms/calculatorform.ui") 27 | if !file.Open(ui.QIODevice_ReadOnly) { 28 | return nil, errors.New("error load ui") 29 | } 30 | 31 | loader := ui.NewUiLoader() 32 | formWidget := loader.Load(file) 33 | if formWidget == nil { 34 | return nil, errors.New("error load form widget") 35 | } 36 | 37 | w.spinBox1 = ui.NewSpinBoxFromDriver(formWidget.FindChild("inputSpinBox1")) 38 | w.spinBox2 = ui.NewSpinBoxFromDriver(formWidget.FindChild("inputSpinBox2")) 39 | w.outputLable = ui.NewLabelFromDriver(formWidget.FindChild("outputWidget")) 40 | 41 | if ui.IsValidDriver(w.spinBox1) && ui.IsValidDriver(w.spinBox2) && ui.IsValidDriver(w.outputLable) { 42 | fnChanged := func() { 43 | w.outputLable.SetText(fmt.Sprintf("%d", w.spinBox1.Value()+w.spinBox2.Value())) 44 | } 45 | 46 | w.spinBox1.OnValueChanged(func(string) { 47 | fnChanged() 48 | }) 49 | w.spinBox2.OnValueChanged(func(string) { 50 | fnChanged() 51 | }) 52 | } 53 | 54 | layout := ui.NewVBoxLayout() 55 | layout.AddWidget(formWidget) 56 | w.SetLayout(layout) 57 | 58 | w.SetWindowTitle("Calculator Builder") 59 | return w, nil 60 | } 61 | -------------------------------------------------------------------------------- /examples/calculatorbuilder/calculatorform.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CalculatorForm 6 | 7 | 8 | CalculatorForm 9 | 10 | 11 | 12 | 0 13 | 0 14 | 276 15 | 98 16 | 17 | 18 | 19 | 20 | 5 21 | 5 22 | 0 23 | 0 24 | 25 | 26 | 27 | Calculator Builder 28 | 29 | 30 | 31 | 32 | 33 | 34 | 9 35 | 36 | 37 | 6 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 1 46 | 47 | 48 | 6 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 1 57 | 58 | 59 | 6 60 | 61 | 62 | 63 | 64 | label 65 | 66 | 67 | 68 | 1 69 | 1 70 | 45 71 | 19 72 | 73 | 74 | 75 | Input 1 76 | 77 | 78 | 79 | 80 | 81 | 82 | inputSpinBox1 83 | 84 | 85 | 86 | 1 87 | 26 88 | 45 89 | 25 90 | 91 | 92 | 93 | true 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | label_3 103 | 104 | 105 | 106 | 54 107 | 1 108 | 7 109 | 52 110 | 111 | 112 | 113 | + 114 | 115 | 116 | Qt::AlignCenter 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 1 127 | 128 | 129 | 6 130 | 131 | 132 | 133 | 134 | label_2 135 | 136 | 137 | 138 | 1 139 | 1 140 | 45 141 | 19 142 | 143 | 144 | 145 | Input 2 146 | 147 | 148 | 149 | 150 | 151 | 152 | inputSpinBox2 153 | 154 | 155 | 156 | 1 157 | 26 158 | 45 159 | 25 160 | 161 | 162 | 163 | true 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | label_3_2 173 | 174 | 175 | 176 | 120 177 | 1 178 | 7 179 | 52 180 | 181 | 182 | 183 | = 184 | 185 | 186 | Qt::AlignCenter 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 1 197 | 198 | 199 | 6 200 | 201 | 202 | 203 | 204 | label_2_2_2 205 | 206 | 207 | 208 | 1 209 | 1 210 | 37 211 | 17 212 | 213 | 214 | 215 | Output 216 | 217 | 218 | 219 | 220 | 221 | 222 | outputWidget 223 | 224 | 225 | 226 | 1 227 | 24 228 | 37 229 | 27 230 | 231 | 232 | 233 | QFrame::Box 234 | 235 | 236 | QFrame::Sunken 237 | 238 | 239 | 0 240 | 241 | 242 | Qt::AlignAbsolute|Qt::AlignBottom|Qt::AlignCenter|Qt::AlignHCenter|Qt::AlignHorizontal_Mask|Qt::AlignJustify|Qt::AlignLeading|Qt::AlignLeft|Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing|Qt::AlignVCenter|Qt::AlignVertical_Mask 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | verticalSpacer 254 | 255 | 256 | 257 | 85 258 | 69 259 | 20 260 | 20 261 | 262 | 263 | 264 | Qt::Vertical 265 | 266 | 267 | 268 | 20 269 | 40 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | horizontalSpacer 278 | 279 | 280 | 281 | 188 282 | 26 283 | 79 284 | 20 285 | 286 | 287 | 288 | Qt::Horizontal 289 | 290 | 291 | 292 | 40 293 | 20 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | -------------------------------------------------------------------------------- /examples/calculatorbuilder/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "os" 6 | 7 | "github.com/visualfc/goqt/ui" 8 | ) 9 | 10 | func main() { 11 | ui.RunEx(os.Args, func() { 12 | w, err := NewCalclatorForm() 13 | if err != nil { 14 | log.Fatalln(err) 15 | } 16 | w.Show() 17 | }) 18 | } 19 | -------------------------------------------------------------------------------- /examples/codeedit/build.bat: -------------------------------------------------------------------------------- 1 | go build -o ..\..\bin\codeedit.exe -------------------------------------------------------------------------------- /examples/codeedit/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | go build -ldflags "-r ." -o ../../bin/codeedit -------------------------------------------------------------------------------- /examples/codeedit/codeedit.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "strconv" 5 | "strings" 6 | 7 | "github.com/visualfc/goqt/ui" 8 | ) 9 | 10 | type CodeEdit struct { 11 | *ui.QWidget 12 | edit *ui.QPlainTextEdit 13 | lineArea *ui.QWidget 14 | syntax *ui.QSyntaxHighlighterHook 15 | rules map[*ui.QRegExp]*ui.QTextCharFormat 16 | } 17 | 18 | func NewCodeEdit() *CodeEdit { 19 | w := &CodeEdit{} 20 | w.QWidget = ui.NewWidget() 21 | w.edit = ui.NewPlainTextEdit() 22 | w.edit.SetLineWrapMode(ui.QPlainTextEdit_NoWrap) 23 | w.syntax = ui.NewSyntaxHighlighterHookWithDoc(w.edit.Document()) 24 | w.lineArea = ui.NewWidget() 25 | w.lineArea.SetFixedWidth(0) 26 | 27 | hbox := ui.NewHBoxLayout() 28 | hbox.SetMargin(0) 29 | hbox.SetSpacing(0) 30 | hbox.AddWidget(w.lineArea) 31 | hbox.AddWidget(w.edit) 32 | w.SetLayout(hbox) 33 | 34 | w.lineArea.InstallEventFilter(w) 35 | 36 | w.edit.OnBlockCountChanged(func(int32) { 37 | w.UpdateLineNumberAreaWidth() 38 | w.lineArea.Update() 39 | }) 40 | w.edit.OnUpdateRequest(func(*ui.QRect, int32) { 41 | w.lineArea.Update() 42 | }) 43 | 44 | w.UpdateLineNumberAreaWidth() 45 | 46 | w.MakeRules() 47 | 48 | w.syntax.OnHighlightBlock(w.OnHighlightBlock) 49 | 50 | font := w.edit.Font() 51 | font.SetPointSize(12) 52 | w.edit.SetFont(font) 53 | w.lineArea.SetFont(font) 54 | 55 | return w 56 | } 57 | 58 | var keywords = ` 59 | break default func interface select 60 | case defer go map struct 61 | chan else goto package switch 62 | const fallthrough if range type 63 | continue for import return var 64 | ` 65 | 66 | func (w *CodeEdit) MakeRules() { 67 | w.rules = make(map[*ui.QRegExp]*ui.QTextCharFormat) 68 | keyword := ui.NewTextCharFormat() 69 | b := ui.NewBrush() 70 | b.SetStyle(ui.Qt_SolidPattern) 71 | b.SetColorWithGlobalcolor(ui.Qt_darkBlue) 72 | keyword.SetForeground(b) 73 | keyword.SetFontWeight(int32(ui.QFont_Bold)) 74 | for _, line := range strings.Split(keywords, "\n") { 75 | for _, v := range strings.Split(line, " ") { 76 | if len(v) == 0 { 77 | continue 78 | } 79 | r := ui.NewRegExp() 80 | r.SetPattern("\\b" + v + "\\b") 81 | w.rules[r] = keyword 82 | } 83 | } 84 | } 85 | 86 | func (w *CodeEdit) OnHighlightBlock(text string) { 87 | for k, v := range w.rules { 88 | index := k.IndexIn(text) 89 | for index >= 0 { 90 | length := k.MatchedLength() 91 | w.syntax.SetFormatWithStartCountFormat(index, length, v) 92 | index = k.IndexInWithTextOffsetCaretmode(text, index+length, ui.QRegExp_CaretAtOffset) 93 | } 94 | } 95 | } 96 | 97 | func (w *CodeEdit) UpdateLineNumberAreaWidth() { 98 | var digits int32 = 1 99 | var max int32 = 1 100 | count := w.edit.BlockCount() 101 | if count > max { 102 | max = count 103 | } 104 | for max >= 10 { 105 | max /= 10 106 | digits++ 107 | } 108 | space := 10 + w.edit.FontMetrics().Width('9')*digits 109 | w.lineArea.SetFixedWidth(space) 110 | } 111 | 112 | func (w *CodeEdit) OnPaintEvent(obj *ui.QObject, e *ui.QPaintEvent) bool { 113 | if ui.Equal(obj, w.lineArea) { 114 | w.paintLineArea(e) 115 | } 116 | return true 117 | } 118 | 119 | func (w *CodeEdit) paintLineArea(event *ui.QPaintEvent) { 120 | painter := ui.NewPainterWithPaintDevice(w.lineArea) 121 | defer painter.Delete() 122 | painter.FillRectWithRectColor(w.lineArea.Rect(), ui.NewColorWithGlobalcolor(ui.Qt_lightGray)) 123 | 124 | block := w.edit.FirstVisibleBlock() 125 | blockNumber := block.BlockNumber() + 1 126 | top := w.edit.BlockBoundingGeometry(block).Translated(w.edit.ContentOffset()).Top() 127 | bottom := top + w.edit.BlockBoundingRect(block).Height() 128 | height := w.lineArea.FontMetrics().Height() 129 | for block.IsValid() && int32(top) < event.Rect().Bottom() { 130 | if block.IsVisible() && int32(bottom) >= event.Rect().Top() { 131 | painter.SetPen(ui.NewColorWithGlobalcolor(ui.Qt_black)) 132 | painter.DrawTextWithXYWidthHeightFlagsTextRect(0, int32(top), w.lineArea.Width(), int32(height), int32(ui.Qt_AlignRight), strconv.Itoa(int(blockNumber)), ui.NewRect()) 133 | } 134 | block = block.Next() 135 | top = bottom 136 | bottom = top + w.edit.BlockBoundingRect(block).Height() 137 | blockNumber++ 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /examples/codeedit/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | 6 | "github.com/visualfc/goqt/ui" 7 | ) 8 | 9 | func main() { 10 | ui.RunEx(os.Args, func() { 11 | ed := NewCodeEdit() 12 | ed.ResizeWithWidthHeight(400, 400) 13 | ed.Show() 14 | }) 15 | } 16 | -------------------------------------------------------------------------------- /examples/minimal/build.bat: -------------------------------------------------------------------------------- 1 | go build -o ..\..\bin\minimal.exe -------------------------------------------------------------------------------- /examples/minimal/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | go build -ldflags "-r ." -o ../../bin/minimal -------------------------------------------------------------------------------- /examples/minimal/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/visualfc/goqt/ui" 4 | 5 | func main() { 6 | ui.Run(func() { 7 | widget := ui.NewWidget() 8 | widget.Show() 9 | }) 10 | } 11 | -------------------------------------------------------------------------------- /examples/task/build.bat: -------------------------------------------------------------------------------- 1 | go build -ldflags "-H windowsgui" -o ..\..\bin\task.exe -------------------------------------------------------------------------------- /examples/task/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | go build -ldflags "-r ." -o ../../bin/task -------------------------------------------------------------------------------- /examples/task/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "time" 7 | 8 | "github.com/visualfc/goqt/ui" 9 | ) 10 | 11 | func main() { 12 | ui.RunEx(os.Args, main_ui) 13 | } 14 | 15 | func main_ui() { 16 | btn := ui.NewPushButton() 17 | btn.SetText("Async") 18 | 19 | clear := ui.NewPushButton() 20 | clear.SetText("Clear") 21 | 22 | edit := ui.NewPlainTextEdit() 23 | edit.SetReadOnly(true) 24 | 25 | btn.OnClicked(func() { 26 | for i := 0; i < 10; i++ { 27 | go func(i int) { 28 | start := time.Now() 29 | <-time.After(1e7) 30 | offset := time.Now().Sub(start) 31 | ui.Async(func() { 32 | edit.AppendPlainText(fmt.Sprintf("Task %v %v", i, offset)) 33 | }) 34 | }(i) 35 | } 36 | }) 37 | 38 | clear.OnClicked(func() { 39 | edit.Clear() 40 | }) 41 | 42 | hbox := ui.NewHBoxLayout() 43 | hbox.AddWidget(btn) 44 | hbox.AddWidget(clear) 45 | 46 | vbox := ui.NewVBoxLayout() 47 | vbox.AddLayout(hbox) 48 | vbox.AddWidget(edit) 49 | 50 | widget := ui.NewWidget() 51 | widget.SetLayout(vbox) 52 | widget.Show() 53 | } 54 | -------------------------------------------------------------------------------- /examples/version/build.bat: -------------------------------------------------------------------------------- 1 | go build -ldflags "-H windowsgui" -o ..\..\bin\version.exe -------------------------------------------------------------------------------- /examples/version/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | go build -ldflags "-r ." -o ../../bin/version -------------------------------------------------------------------------------- /examples/version/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | 7 | "github.com/visualfc/goqt/ui" 8 | ) 9 | 10 | func main() { 11 | ui.Run(func() { 12 | info := fmt.Sprintf("GoQt Version %v \nQt Version %v\ngo verison %v %v/%v", 13 | ui.Version(), 14 | ui.QtVersion(), 15 | runtime.Version(), runtime.GOOS, runtime.GOARCH) 16 | 17 | lable := ui.NewLabel() 18 | lable.SetText(info) 19 | 20 | hbox := ui.NewHBoxLayout() 21 | hbox.AddWidget(lable) 22 | 23 | widget := ui.NewWidget() 24 | widget.SetLayout(hbox) 25 | widget.Show() 26 | }) 27 | } 28 | -------------------------------------------------------------------------------- /examples/wiggly/build.bat: -------------------------------------------------------------------------------- 1 | go build -ldflags "-H windowsgui" -o ..\..\bin\wiggly.exe -------------------------------------------------------------------------------- /examples/wiggly/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | go build -ldflags "-r ." -o ../../bin/wiggly -------------------------------------------------------------------------------- /examples/wiggly/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | 6 | "github.com/visualfc/goqt/ui" 7 | ) 8 | 9 | type WigglyWidget struct { 10 | *ui.QWidget 11 | step int 12 | text string 13 | exit chan bool 14 | } 15 | 16 | func NewWiggleWidget() *WigglyWidget { 17 | w := &WigglyWidget{ui.NewWidget(), 0, "Hello World", make(chan bool)} 18 | w.SetBackgroundRole(ui.QPalette_Midlight) 19 | w.SetAutoFillBackground(true) 20 | 21 | font := w.Font() 22 | font.SetPointSize(font.PointSize() + 20) 23 | w.SetFont(font) 24 | 25 | w.InstallEventFilter(w) 26 | 27 | t := ui.NewTimer() 28 | t.SetInterval(60) 29 | t.OnTimeout(func() { 30 | w.step++ 31 | w.Update() 32 | }) 33 | t.Start() 34 | 35 | return w 36 | } 37 | 38 | func (w *WigglyWidget) SetText(text string) { 39 | w.text = text 40 | } 41 | 42 | var sineTablep = [16]int32{0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38} 43 | 44 | func (w *WigglyWidget) OnPaintEvent(e *ui.QPaintEvent) bool { 45 | w.PaintEvent(e) 46 | merics := ui.NewFontMetrics(w.Font()) 47 | defer merics.Delete() 48 | 49 | x := (w.Width() - merics.WidthWithString(w.text)) / 2 50 | y := (w.Height() + merics.Ascent() - merics.Descent()) / 2 51 | 52 | color := ui.NewColor() 53 | defer color.Delete() 54 | 55 | painter := ui.NewPainterWithPaintDevice(w) 56 | defer painter.Delete() 57 | 58 | for i, s := range w.text { 59 | index := (w.step + i) % 16 60 | color.SetHsv(int32(15-index)*16, 255, 191, 255) 61 | painter.SetPen(color) 62 | painter.DrawTextWithXYText(x, y-((sineTablep[index]*merics.Height())/400), string(s)) 63 | x += merics.Width(s) 64 | } 65 | return true 66 | } 67 | 68 | type Dialog struct { 69 | *ui.QDialog 70 | widdly *WigglyWidget 71 | } 72 | 73 | func NewDialog() *Dialog { 74 | dlg := &Dialog{} 75 | dlg.QDialog = ui.NewDialog() 76 | 77 | vbox := ui.NewVBoxLayout() 78 | dlg.SetLayout(vbox) 79 | 80 | dlg.widdly = NewWiggleWidget() 81 | edit := ui.NewLineEdit() 82 | 83 | vbox.AddWidget(dlg.widdly) 84 | vbox.AddWidget(edit) 85 | 86 | edit.OnTextChanged(func(text string) { 87 | dlg.widdly.SetText(text) 88 | }) 89 | edit.SetText("Hello World!") 90 | 91 | dlg.ResizeWithWidthHeight(360, 145) 92 | dlg.SetWindowTitle("Wiggly") 93 | 94 | return dlg 95 | } 96 | 97 | func main() { 98 | ui.RunEx(os.Args, func() { 99 | dlg := NewDialog() 100 | dlg.Show() 101 | }) 102 | } 103 | -------------------------------------------------------------------------------- /qtdrv/callback.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2013-2016 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #include "callback.h" 16 | #include "uiapplication.h" 17 | #include "cdrv.h" 18 | #include "cdrv_event.h" 19 | 20 | typedef void (*UTF8_TO_STRING)(void *info,const char *data, int size); 21 | typedef void (*ARRAY_TO_SLICE)(void *slice, const void *array, int size); 22 | typedef void (*APPEND_UTF8_TO_SLICE)(void *string,const char *str, int size); 23 | typedef void (*APPEND_BYTES_TO_SLICE)(void *slice,const void *bytes, int size); 24 | typedef void (*APPEND_OBJECT_TO_SLICE)(void *slice, void *obj, int id, int gc); 25 | typedef void*(*STRING_SLICE_INDEX)(void *slice, int index); 26 | typedef void*(*OBJECT_SLICE_INDEX)(void *slice, int index); 27 | typedef void (*DRV_SIGNAL_CALL)(void *p, void *face, int id, const void *p1, const void *p2, const void *p3, const void *p4); 28 | typedef void (*DRV_REMOVE_SIGNAL_CALL)(void *); 29 | typedef void (*INSERT_STRING2OBJECT_MAP)(void *p, const char *data, int size,int id, int gc, void *obj); 30 | typedef void (*COPY_STRING2OBJECT_MAP)(void *p, void *cp, CALLBACK_INSERT_MAP cb); 31 | typedef void (*INSERT_INT2OBJECT_MAP)(void *p, int key,int id, int gc, void *obj); 32 | typedef void (*COPY_INT2OBJECT_MAP)(void *p, void *cp, CALLBACK_INSERT_MAP cb); 33 | typedef void (*INSERT_OBJECT2OBJECT_MAP)(void *p, int id1, int gc1,void *obj1, int id2, int gc2, void *obj2); 34 | typedef void (*APP_EVENT_INIT)(); 35 | typedef int (*DRV_EVENT_FILTER)(const void *filter, void *face, void *obj, unsigned int evid, void *event); 36 | typedef void (*DRV_REMOVE_EVENT_FILTER)(const void *filter); 37 | typedef void (*APP_ASYNC_TASK)(); 38 | typedef void (*APPEND_UINT32_TO_SLICE)(void *p, unsigned int v); 39 | typedef void (*APPEND_DOUBLE_TO_SLICE)(void *p, double v); 40 | 41 | static ARRAY_TO_SLICE pfn_array_to_slice; 42 | static UTF8_TO_STRING pfn_utf8_to_string; 43 | static APPEND_UTF8_TO_SLICE pfn_append_utf8_to_slice; 44 | static APPEND_BYTES_TO_SLICE pfn_append_bytes_to_slice; 45 | static APPEND_OBJECT_TO_SLICE pfn_append_object_to_slice; 46 | static STRING_SLICE_INDEX pfn_string_slice_index; 47 | static OBJECT_SLICE_INDEX pfn_object_slice_index; 48 | static DRV_SIGNAL_CALL pfn_drv_signal_call; 49 | static DRV_REMOVE_SIGNAL_CALL pfn_drv_remove_signal_call; 50 | static INSERT_STRING2OBJECT_MAP pfn_insert_string2object_map; 51 | static COPY_STRING2OBJECT_MAP pfn_copy_string2object_map; 52 | static INSERT_INT2OBJECT_MAP pfn_insert_int2object_map; 53 | static COPY_INT2OBJECT_MAP pfn_copy_int2object_map; 54 | static INSERT_OBJECT2OBJECT_MAP pfn_insert_object2object_map; 55 | static APP_EVENT_INIT pfn_app_event_init; 56 | static DRV_EVENT_FILTER pfn_drv_event_filter; 57 | static DRV_REMOVE_EVENT_FILTER pfn_drv_remove_event_filter; 58 | static APP_ASYNC_TASK pfn_app_async_task; 59 | static APPEND_UINT32_TO_SLICE pfn_append_uint_to_slice; 60 | static APPEND_DOUBLE_TO_SLICE pfn_append_double_to_slice; 61 | 62 | void utf8_to_string(void *info,const char *data, int size) 63 | { 64 | pfn_utf8_to_string(info,data,size); 65 | } 66 | 67 | void array_to_slice(void *slice, const void *array, int size) 68 | { 69 | pfn_array_to_slice(slice,array,size); 70 | } 71 | 72 | void append_utf8_to_slice(void *string,const char *str, int size) 73 | { 74 | pfn_append_utf8_to_slice(string,str,size); 75 | } 76 | 77 | void append_bytes_to_slice(void *slice,const void *bytes, int size) 78 | { 79 | pfn_append_bytes_to_slice(slice,bytes,size); 80 | } 81 | 82 | void append_object_to_slice(void *slice, void *obj, int id, int gc) 83 | { 84 | pfn_append_object_to_slice(slice,obj,id,gc); 85 | } 86 | 87 | void* string_slice_index(void *slice, int index) 88 | { 89 | return pfn_string_slice_index(slice,index); 90 | } 91 | 92 | void* object_slice_index(void *slice, int index) 93 | { 94 | return pfn_object_slice_index(slice,index); 95 | } 96 | 97 | void drv_signal_call(void *p, void *face, int id, const void *p1, const void *p2, const void *p3, const void *p4) 98 | { 99 | pfn_drv_signal_call(p,face,id,p1,p2,p3,p4); 100 | } 101 | 102 | void drv_remove_signal_call(void *p) 103 | { 104 | pfn_drv_remove_signal_call(p); 105 | } 106 | 107 | void insert_string2object_map(void *p, const char *data, int size,int id, int gc, void *obj) 108 | { 109 | pfn_insert_string2object_map(p,data,size,id,gc,obj); 110 | } 111 | 112 | void copy_string2object_map(void *p, void *cp, CALLBACK_INSERT_MAP cb) 113 | { 114 | pfn_copy_string2object_map(p,cp,cb); 115 | } 116 | 117 | void insert_int2object_map(void *p, int key,int id, int gc, void *obj) 118 | { 119 | pfn_insert_int2object_map(p,key,id,gc,obj); 120 | } 121 | 122 | void copy_int2object_map(void *p, void *cp, CALLBACK_INSERT_MAP cb) 123 | { 124 | pfn_copy_int2object_map(p,cp,cb); 125 | } 126 | 127 | void insert_object2object_map(void *p, int id1, int gc1,void *obj1, int id2, int gc2, void *obj2) 128 | { 129 | pfn_insert_object2object_map(p,id1,gc1,obj1,id2,gc2,obj2); 130 | } 131 | 132 | void app_event_init() 133 | { 134 | pfn_app_event_init(); 135 | } 136 | 137 | void app_async_task() 138 | { 139 | pfn_app_async_task(); 140 | } 141 | 142 | bool drv_event_filter(const void *filter, void *face, void *obj, uint32 evid, void *event) 143 | { 144 | return pfn_drv_event_filter(filter, face, obj, evid, event) != 0; 145 | } 146 | 147 | void drv_remove_event_filter(const void *filter) 148 | { 149 | pfn_drv_remove_event_filter(filter); 150 | } 151 | 152 | void append_uint32_to_slice(void *p, unsigned int v) 153 | { 154 | pfn_append_uint_to_slice(p,v); 155 | } 156 | 157 | void append_double_to_slice(void *p, double v) 158 | { 159 | pfn_append_double_to_slice(p,v); 160 | } 161 | 162 | int init_callback(void *p, int id, void *p1, void *p2, void *p3) 163 | { 164 | switch (id) { 165 | case 1: 166 | pfn_utf8_to_string = (UTF8_TO_STRING)p; 167 | break; 168 | case 2: 169 | pfn_array_to_slice = (ARRAY_TO_SLICE)p; 170 | break; 171 | case 3: 172 | pfn_append_utf8_to_slice = (APPEND_UTF8_TO_SLICE)p; 173 | break; 174 | case 4: 175 | pfn_append_bytes_to_slice = (APPEND_BYTES_TO_SLICE)p; 176 | break; 177 | case 5: 178 | pfn_append_object_to_slice = (APPEND_OBJECT_TO_SLICE)p; 179 | break; 180 | case 6: 181 | pfn_string_slice_index = (STRING_SLICE_INDEX)p; 182 | break; 183 | case 7: 184 | pfn_object_slice_index = (OBJECT_SLICE_INDEX)p; 185 | break; 186 | case 8: 187 | pfn_drv_signal_call = (DRV_SIGNAL_CALL)p; 188 | break; 189 | case 9: 190 | pfn_drv_remove_signal_call = (DRV_REMOVE_SIGNAL_CALL)p; 191 | break; 192 | case 10: 193 | pfn_insert_string2object_map = (INSERT_STRING2OBJECT_MAP)p; 194 | break; 195 | case 11: 196 | pfn_copy_string2object_map = (COPY_STRING2OBJECT_MAP)p; 197 | break; 198 | case 12: 199 | pfn_insert_int2object_map = (INSERT_INT2OBJECT_MAP)p; 200 | break; 201 | case 13: 202 | pfn_copy_int2object_map = (COPY_INT2OBJECT_MAP)p; 203 | break; 204 | case 14: 205 | pfn_insert_object2object_map = (INSERT_OBJECT2OBJECT_MAP)p; 206 | break; 207 | case 15: 208 | pfn_app_event_init = (APP_EVENT_INIT)p; 209 | break; 210 | case 16: 211 | pfn_drv_event_filter = (DRV_EVENT_FILTER)p; 212 | break; 213 | case 17: 214 | pfn_drv_remove_event_filter = (DRV_REMOVE_EVENT_FILTER)p; 215 | break; 216 | case 18: 217 | pfn_app_async_task = (APP_ASYNC_TASK)p; 218 | break; 219 | case 19: 220 | pfn_append_uint_to_slice = (APPEND_UINT32_TO_SLICE)p; 221 | break; 222 | case 20: 223 | pfn_append_double_to_slice = (APPEND_DOUBLE_TO_SLICE)p; 224 | break; 225 | case 100: //QString => string 226 | drvSetString(p,*(QString*)p1); 227 | break; 228 | case 101: //QStringList => []string 229 | drvSetStringArray(p,*(QStringList*)p1); 230 | break; 231 | case 102: //QList => []*QRectF 232 | drvSetListPtr(p,*(int*)p2,*(QList*)p1); 233 | break; 234 | case 103: //QList => []*QModelIndex 235 | drvSetListPtr(p,*(int*)p2,*(QList*)p1); 236 | break; 237 | case 104: //string,T => QMap 238 | (CALLBACK_INSERT_MAP(p3))(p,p1,p2); 239 | break; 240 | case 105: 241 | *(void**)p2 = drvNewFilter(p); 242 | break; 243 | case 106: 244 | drvSetString(p1,qVersion()); 245 | break; 246 | case 200: 247 | uidrv.call_async_task(); 248 | break; 249 | case 201: 250 | uidrv.call_sync_task(); 251 | break; 252 | default: 253 | return -1; 254 | } 255 | return 0; 256 | } 257 | 258 | extern Q_CORE_EXPORT bool qRegisterResourceData 259 | (int, const unsigned char *, const unsigned char *, const unsigned char *); 260 | 261 | extern Q_CORE_EXPORT bool qUnregisterResourceData 262 | (int, const unsigned char *, const unsigned char *, const unsigned char *); 263 | 264 | bool QResHelp::registerResourceData(int version, const unsigned char *tree, const unsigned char *name, const unsigned char *data) 265 | { 266 | return qRegisterResourceData(version,tree,name,data); 267 | } 268 | 269 | bool QResHelp::unregisterResourceData(int version, const unsigned char *tree, const unsigned char *name, const unsigned char *data) 270 | { 271 | return qUnregisterResourceData(version,tree,name,data); 272 | } 273 | -------------------------------------------------------------------------------- /qtdrv/callback.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2015-2016 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #ifndef CALLBACK_H 16 | #define CALLBACK_H 17 | 18 | typedef void (*CALLBACK_INSERT_MAP)(void *p, void *p1, void *p2); 19 | 20 | void utf8_to_string(void *info,const char *data, int size); 21 | void array_to_slice(void *slice, const void *array, int size); 22 | void append_utf8_to_slice(void *string,const char *str, int size); 23 | void append_bytes_to_slice(void *slice,const void *bytes, int size); 24 | void append_object_to_slice(void *slice, void *obj, int id, int gc); 25 | void* string_slice_index(void *slice, int index); 26 | void* object_slice_index(void *slice, int index); 27 | void drv_signal_call(void *p, void *face,int id, const void *p1, const void *p2, const void *p3, const void *p4); 28 | void drv_remove_signal_call(void *p); 29 | void insert_string2object_map(void *p, const char *data, int size,int id, int gc, void *obj); 30 | void copy_string2object_map(void *p, void *cp, CALLBACK_INSERT_MAP cb); 31 | void insert_int2object_map(void *p, int key,int id, int gc, void *obj); 32 | void copy_int2object_map(void *p, void *cp, CALLBACK_INSERT_MAP cb); 33 | void insert_object2object_map(void *p, int id1, int gc1,void *obj1, int id2, int gc2, void *obj2); 34 | void app_event_init(); 35 | bool drv_event_filter(const void *filter, void *face, void *obj, unsigned int evid, void *event); 36 | void drv_remove_event_filter(const void *filter); 37 | void app_async_task(); 38 | void append_uint32_to_slice(void *p, unsigned int v); 39 | void append_double_to_slice(void *p, double v); 40 | 41 | int init_callback(void *p, int id, void *p1, void *p2, void *p3); 42 | 43 | class QResHelp 44 | { 45 | public: 46 | static bool registerResourceData(int version, const unsigned char *tree, const unsigned char *name, const unsigned char *data); 47 | static bool unregisterResourceData(int version, const unsigned char *tree, const unsigned char *name, const unsigned char *data); 48 | }; 49 | 50 | #endif // CALLBACK_H 51 | -------------------------------------------------------------------------------- /qtdrv/cdrv.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2015-2016 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #ifndef CDRV_H 16 | #define CDRV_H 17 | 18 | #include "qtdrv_global.h" 19 | #include "uiapplication.h" 20 | #include "callback.h" 21 | #include "uidrv.h" 22 | #include 23 | #include 24 | #include "qsyntaxhighlighterhook.h" 25 | #include "../ui/cdrv_def.h" 26 | 27 | #if QT_VERSION >= 0x050000 28 | #define QTDRV_QT5 1 29 | #endif 30 | 31 | #ifdef QTDRV_QT5 32 | #include 33 | #include 34 | #else 35 | #define QT_DEPRECATED_SINCE(major, minor) 0 36 | #include "./qurl/qurlquery.h" 37 | #endif 38 | 39 | typedef QMap QStringVariantMap; 40 | typedef QMap QIntVariantMap; 41 | 42 | typedef unsigned int uint32; 43 | 44 | typedef struct { 45 | const char **data; 46 | int size; 47 | } __attribute__ ((packed)) string_array_head; 48 | 49 | struct string_head_cache { 50 | const char *data; 51 | int len; 52 | }__attribute__ ((packed)); 53 | 54 | 55 | struct slice_head { 56 | char *data; 57 | uint32 len; 58 | uint32 cap; 59 | }__attribute__ ((packed)); 60 | 61 | template 62 | struct slice_head_t { 63 | T *data; 64 | uint32 len; 65 | uint32 cap; 66 | }__attribute__ ((packed)); 67 | 68 | struct Iface { 69 | void *tab; 70 | void *data; 71 | }__attribute__ ((packed)); 72 | 73 | Q_DECLARE_METATYPE(Iface) 74 | Q_DECLARE_TYPEINFO(Iface, Q_MOVABLE_TYPE); 75 | 76 | inline void drvSetString(void *p, const QString &v) 77 | { 78 | if (p == 0) { 79 | return; 80 | } 81 | /* 82 | const QByteArray & ar = v.toUtf8(); 83 | utf8_to_string(p,ar.constData(),ar.length()); 84 | */ 85 | utf8_cache = v.toUtf8(); 86 | string_head_cache *sh = (string_head_cache*)(p); 87 | sh->data = utf8_cache.constData(); 88 | sh->len = utf8_cache.length(); 89 | } 90 | 91 | inline void drvSetByteArray(void *p, QByteArray v) 92 | { 93 | if (p == 0) { 94 | return; 95 | } 96 | array_to_slice(p,v.constData(),v.size()); 97 | } 98 | 99 | 100 | inline QByteArray drvGetByteArray(void *p) 101 | { 102 | if (p == 0) { 103 | return QByteArray(); 104 | } 105 | slice_head *sh = (slice_head*)p; 106 | return QByteArray((const char*)sh->data,sh->len); 107 | } 108 | 109 | inline void drvSetBitArray(void *p, QBitArray v) 110 | { 111 | if (p == 0) { 112 | return; 113 | } 114 | QVector ar; 115 | ar.resize(v.size()); 116 | for (int i = 0; i < v.size(); i++) { 117 | ar[i] = v[i]; 118 | } 119 | array_to_slice(p,ar.data(),ar.size()); 120 | } 121 | 122 | inline QString drvGetStringHead(void *p) 123 | { 124 | if (p == 0) { 125 | return QString(); 126 | } 127 | string_head *sh = (string_head*)p; 128 | return QString::fromUtf8(sh->data,sh->size); 129 | } 130 | 131 | inline QList drvGetIntArrayHead(void *p) 132 | { 133 | if (p == 0) { 134 | return QList(); 135 | } 136 | int_array_head *sh = (int_array_head*)p; 137 | QList v; 138 | for (int i = 0; i < sh->size; i++) { 139 | v.push_back(sh->data[i]); 140 | } 141 | return v; 142 | } 143 | 144 | template 145 | inline QList drvGetIntArrayHeadT(void *p) 146 | { 147 | if (p == 0) { 148 | return QList(); 149 | } 150 | int_array_head *sh = (int_array_head*)p; 151 | QList v; 152 | for (int i = 0; i < sh->size; i++) { 153 | v.push_back((T)sh->data[i]); 154 | } 155 | return v; 156 | } 157 | 158 | template 159 | inline QList drvGetObjectArrayHeadT(void *p) 160 | { 161 | if (p == 0) { 162 | return QList(); 163 | } 164 | ptr_array_head *sh = (ptr_array_head*)p; 165 | QList v; 166 | for (int i = 0; i < sh->size; i++) { 167 | v.push_back((T)sh->data[i]); 168 | } 169 | return v; 170 | } 171 | 172 | template 173 | inline QList drvGetNoObjectArrayHeadT(void *p) 174 | { 175 | if (p == 0) { 176 | return QList(); 177 | } 178 | ptr_array_head *sh = (ptr_array_head*)p; 179 | QList v; 180 | for (int i = 0; i < sh->size; i++) { 181 | v.push_back(*(T*)sh->data[i]); 182 | } 183 | return v; 184 | } 185 | 186 | inline QList drvGetDoubleArrayHead(void *p) 187 | { 188 | if (p == 0) { 189 | return QList(); 190 | } 191 | double_array_head *sh = (double_array_head*)p; 192 | QList v; 193 | for (int i = 0; i < sh->size; i++) { 194 | v.push_back(sh->data[i]); 195 | } 196 | return v; 197 | } 198 | 199 | template 200 | inline QVector drvGetUintVectorHeadT(void *p) 201 | { 202 | if (p == 0) { 203 | return QVector(); 204 | } 205 | uint_array_head *sh = (uint_array_head*)p; 206 | QVector v; 207 | for (int i = 0; i < sh->size; i++) { 208 | v.push_back((T)sh->data[i]); 209 | } 210 | return v; 211 | } 212 | 213 | inline QVector drvGetDoubleVectorHead(void *p) 214 | { 215 | if (p == 0) { 216 | return QVector(); 217 | } 218 | double_array_head *sh = (double_array_head*)p; 219 | QVector v; 220 | for (int i = 0; i < sh->size; i++) { 221 | v.push_back(sh->data[i]); 222 | } 223 | return v; 224 | } 225 | 226 | template 227 | inline QVector drvGetNoObjectVectorHeadT(void *p) 228 | { 229 | if (p == 0) { 230 | return QVector(); 231 | } 232 | ptr_array_head *sh = (ptr_array_head*)p; 233 | QVector v; 234 | for (int i = 0; i < sh->size; i++) { 235 | v.push_back(*(T*)sh->data[i]); 236 | } 237 | return v; 238 | } 239 | 240 | 241 | inline QBitArray drvGetBoolArrayHead(void *p) 242 | { 243 | if (p == 0) { 244 | return QBitArray(); 245 | } 246 | bool_array_head *sh = (bool_array_head*)p; 247 | QBitArray ar; 248 | ar.resize(sh->size); 249 | for (int i = 0; i < sh->size; i++) { 250 | ar[i] = sh->data[i]; 251 | } 252 | return ar; 253 | } 254 | 255 | inline QByteArray drvGetByteArrayHead(void *p) 256 | { 257 | if (p == 0) { 258 | return QByteArray(); 259 | } 260 | byte_array_head *sh = (byte_array_head*)p; 261 | return QByteArray(sh->data,sh->size); 262 | } 263 | 264 | inline QStringList drvGetStringArray(void *p) 265 | { 266 | if (p == 0) { 267 | return QStringList(); 268 | } 269 | QStringList list; 270 | char **sh = (char**)p; 271 | while (*sh) { 272 | list.append(QString::fromUtf8(*sh)); 273 | sh++; 274 | } 275 | return list; 276 | } 277 | 278 | 279 | inline QString drvGetStringRef(void *p) 280 | { 281 | if (p == 0) { 282 | return QString(); 283 | } 284 | string_head *h = (string_head*)p; 285 | 286 | return QString::fromUtf8(h->data,h->size); 287 | } 288 | 289 | inline void drvSetStringRef(void *p, const QString &v) 290 | { 291 | if (p == 0) { 292 | return; 293 | } 294 | const QByteArray & ar = v.toUtf8(); 295 | utf8_to_string(p,ar.constData(),ar.length()); 296 | } 297 | 298 | inline void drvSetStringArray(void *p, const QStringList &list) 299 | { 300 | if (p == 0) { 301 | return; 302 | } 303 | foreach (QString v, list) { 304 | const QByteArray & ar = v.toUtf8(); 305 | append_utf8_to_slice(p,ar.constData(),ar.size()); 306 | } 307 | } 308 | 309 | inline void drvSetBytesArray(void *p, const QList &list) 310 | { 311 | if (p == 0) { 312 | return; 313 | } 314 | foreach (QByteArray v, list) { 315 | append_bytes_to_slice(p,v.constData(),v.size()); 316 | } 317 | } 318 | 319 | inline void drvSetBytesArray(void *p, char *list[]) 320 | { 321 | if (p == 0) { 322 | return; 323 | } 324 | char *head = list[0]; 325 | while (head++) { 326 | append_bytes_to_slice(p,head,strlen(head)); 327 | } 328 | } 329 | 330 | 331 | inline void drvSetObjectArray(void *p, int id, const QList &list) 332 | { 333 | if (p == 0) { 334 | return; 335 | } 336 | foreach (QObject *v, list) { 337 | append_object_to_slice(p,v,id,false); 338 | } 339 | } 340 | 341 | inline void drvSetRgbArray(void *p, QVector ar) 342 | { 343 | if (p == 0) { 344 | return; 345 | } 346 | array_to_slice(p,&ar[0],ar.size()); 347 | } 348 | 349 | inline void drvSetDoubleArray(void *p, QVector ar) 350 | { 351 | if (p == 0) { 352 | return; 353 | } 354 | array_to_slice(p,&ar[0],ar.size()); 355 | } 356 | 357 | inline QVector drvGetRgbArray(void *p) 358 | { 359 | if (p == 0) { 360 | return QVector(); 361 | } 362 | QVector ar; 363 | slice_head_t *sh = (slice_head_t*)p; 364 | for (uint32 i = 0; i < sh->len; i++) { 365 | ar.append(sh->data[i]); 366 | } 367 | return ar; 368 | } 369 | 370 | inline QVector drvGetDoubleArray(void *p) 371 | { 372 | if (p == 0) { 373 | return QVector(); 374 | } 375 | QVector ar; 376 | slice_head_t *sh = (slice_head_t*)p; 377 | for (uint32 i = 0; i < sh->len; i++) { 378 | ar.append(sh->data[i]); 379 | } 380 | return ar; 381 | } 382 | 383 | inline QBitArray drvGetBitArray(void *p) 384 | { 385 | if (p == 0) { 386 | return QBitArray(); 387 | } 388 | slice_head_t *sh = (slice_head_t*)p; 389 | QBitArray ar(sh->len); 390 | for (uint32 i = 0; i < sh->len; i++) { 391 | ar[i] = sh->data[i]; 392 | } 393 | return ar; 394 | } 395 | 396 | inline char ** drvGetBytesArray(void *p) 397 | { 398 | if (p == 0) { 399 | return 0; 400 | } 401 | slice_head_t *sh = (slice_head_t*)(p); 402 | return &sh->data[0]; 403 | } 404 | 405 | template 406 | inline QVector drvGetVector(void *p) 407 | { 408 | if (p == 0) { 409 | return QVector(); 410 | } 411 | QVector ar; 412 | slice_head_t *sh = (slice_head_t*)p; 413 | for (uint32 i = 0; i < sh->len; i++) { 414 | ar.append(sh->data[i]); 415 | } 416 | return ar; 417 | } 418 | 419 | template 420 | inline void drvSetVector(void *p, QVector ar) 421 | { 422 | if (p == 0) { 423 | return; 424 | } 425 | array_to_slice(p,&ar[0],ar.size()); 426 | } 427 | inline void drvSetVectorQRgb(void *p, QVector ar) 428 | { 429 | if (p == 0) { 430 | return; 431 | } 432 | //array_to_slice(p,&ar[0],ar.size()); 433 | for (int i = 0; i < ar.size(); i++) { 434 | append_uint32_to_slice(p,ar[i]); 435 | } 436 | } 437 | 438 | inline void drvSetVectorDouble(void *p, QVector ar) 439 | { 440 | if (p == 0) { 441 | return; 442 | } 443 | //array_to_slice(p,&ar[0],ar.size()); 444 | for (int i = 0; i < ar.size(); i++) { 445 | append_double_to_slice(p,ar[i]); 446 | } 447 | } 448 | 449 | 450 | 451 | template 452 | inline void drvSetList(void *p, QList ar) 453 | { 454 | if (p == 0) { 455 | return; 456 | } 457 | array_to_slice(p,&ar.toVector()[0],ar.size()); 458 | } 459 | 460 | template 461 | inline QList drvGetList(void *p) 462 | { 463 | if (p == 0) { 464 | return QList(); 465 | } 466 | QList ar; 467 | slice_head_t *sh = (slice_head_t*)p; 468 | for (uint32 i = 0; i < sh->len; i++) { 469 | ar.append(sh->data[i]); 470 | } 471 | return ar; 472 | } 473 | 474 | template 475 | inline QVector drvGetVectorPtr(void *p) 476 | { 477 | if (p == 0) { 478 | return QVector(); 479 | } 480 | QVector ar; 481 | slice_head *sh = (slice_head*)p; 482 | for (uint32 i = 0; i < sh->len; i++) { 483 | ar.append(*(T*)object_slice_index(p,i)); 484 | } 485 | return ar; 486 | } 487 | 488 | template 489 | inline QList drvGetListPtr(void *p) 490 | { 491 | if (p == 0) { 492 | return QList(); 493 | } 494 | QList ar; 495 | slice_head *sh = (slice_head*)p; 496 | for (uint32 i = 0; i < sh->len; i++) { 497 | ar.append(*(T*)object_slice_index(p,i)); 498 | } 499 | return ar; 500 | } 501 | 502 | template 503 | inline QList drvGetListObj(void *p) 504 | { 505 | if (p == 0) { 506 | return QList(); 507 | } 508 | QList ar; 509 | slice_head *sh = (slice_head*)p; 510 | for (uint32 i = 0; i < sh->len; i++) { 511 | ar.append((T)object_slice_index(p,i)); 512 | } 513 | return ar; 514 | } 515 | 516 | template 517 | inline void drvSetVectorObj(void *p, int id, QVector ar) 518 | { 519 | if (p == 0) { 520 | return; 521 | } 522 | foreach (T v, ar) { 523 | append_object_to_slice(p,v,id,false); 524 | } 525 | } 526 | 527 | template 528 | inline void drvSetVectorPtr(void *p, int id, QVector ar) 529 | { 530 | if (p == 0) { 531 | return; 532 | } 533 | foreach (T v, ar) { 534 | append_object_to_slice(p,new T(v),id,true); 535 | } 536 | } 537 | 538 | template 539 | inline void drvSetListPtr(void *p, int id, QList ar) 540 | { 541 | if (p == 0) { 542 | return; 543 | } 544 | foreach (T v, ar) { 545 | append_object_to_slice(p,new T(v),id,true); 546 | } 547 | } 548 | 549 | template 550 | inline void drvSetListObj(void *p, int id, QList ar) 551 | { 552 | if (p == 0) { 553 | return; 554 | } 555 | foreach (T v, ar) { 556 | append_object_to_slice(p,v,id,false); 557 | } 558 | } 559 | 560 | 561 | //template 562 | //inline T drvNative(void *p) 563 | //{ 564 | // if (p == 0) { 565 | // return 0; 566 | // } 567 | // return *(T*)p; 568 | //} 569 | 570 | //template 571 | //inline T* drvNativePtr(void *p) 572 | //{ 573 | // if (p == 0) { 574 | // return 0; 575 | // } 576 | // return (T*)p; 577 | //} 578 | 579 | //template <> 580 | //inline QPaintDevice* drvNativePtr(void *p) 581 | //{ 582 | // qDebug() << "painter"; 583 | // return (QWidget*)p; 584 | //} 585 | 586 | struct pd_head { 587 | void *native; 588 | int isWidget; 589 | }; 590 | 591 | inline QPaintDevice* drvGetPaintDevice(void *p) 592 | { 593 | if (p == 0) { 594 | return 0; 595 | } 596 | pd_head *ph = (pd_head*)p; 597 | if (ph->isWidget) { 598 | return (QWidget*)ph->native; 599 | } 600 | return (QPaintDevice*)ph->native; 601 | } 602 | 603 | extern QList sh_casche; 604 | inline const char *drvGet_const_char(void *p) { 605 | if (p == 0) { 606 | return ""; 607 | } 608 | string_head *sh = (string_head*)p; 609 | 610 | if (sh->size == 0) { 611 | return ""; 612 | } 613 | return sh->data; 614 | } 615 | 616 | template 617 | void drvSetStringToObjectMap(void *p, int id, bool gc, QMap map) 618 | { 619 | QMapIterator i(map); 620 | while (i.hasNext()) { 621 | i.next(); 622 | const QByteArray & ar = i.key().toUtf8(); 623 | insert_string2object_map(p,ar.constData(),ar.size(),id,gc?1:0,new T(i.value())); 624 | } 625 | } 626 | 627 | template 628 | void drvSetIntToObjectMap(void *p, int id, bool gc, QMap map) 629 | { 630 | QMapIterator i(map); 631 | while (i.hasNext()) { 632 | i.next(); 633 | insert_int2object_map(p,i.key(),id,gc?1:0,new T(i.value())); 634 | } 635 | } 636 | 637 | template 638 | void drvSetObjectToObjectMap(void *p, int id1, bool gc1, int id2, bool gc2, QMap map) 639 | { 640 | QMapIterator i(map); 641 | while (i.hasNext()) { 642 | i.next(); 643 | insert_object2object_map(p,id1,gc1?1:0,new T1(i.key()),id2,gc2?1:0,new T2(i.value())); 644 | } 645 | } 646 | template 647 | inline void drvInsertString2Object(void *p, void *p1, void *p2) 648 | { 649 | string_head *sh = (string_head*)p1; 650 | (*((QMap*)p)).insert(QString::fromUtf8(sh->data,sh->size),*(T*)p2); 651 | } 652 | 653 | template 654 | QMap drvGetStringToObjectMap(void *p) 655 | { 656 | if (p == 0) { 657 | return QMap(); 658 | } 659 | QMap m; 660 | copy_string2object_map(p,&m,&drvInsertString2Object); 661 | return m; 662 | } 663 | 664 | template 665 | inline void drvInsertInt2Object(void *p, void *p1, void *p2) 666 | { 667 | (*((QMap*)p)).insert(*(int*)p1,*(T*)p2); 668 | } 669 | 670 | 671 | template 672 | QMap drvGetIntToObjectMap(void *p) 673 | { 674 | if (p == 0) { 675 | return QMap(); 676 | } 677 | QMap m; 678 | copy_int2object_map(p,&m,&drvInsertInt2Object); 679 | return m; 680 | } 681 | 682 | extern "C" 683 | QTUISHARED_EXPORT int qtdrv(void *_p, int _typeid, int funcid, void *p1, void *p2, void *p3, void *p4, void *p5, void *p6, void *p7, void *p8, void *p9, void *p10, void *p11, void *p12); 684 | 685 | 686 | #endif // CDRV_H 687 | -------------------------------------------------------------------------------- /qtdrv/cdrv_event.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2015-2016 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #include "cdrv_event.h" 16 | -------------------------------------------------------------------------------- /qtdrv/cdrv_event.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2015-2016 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #ifndef CDRV_EVENT_H 16 | #define CDRV_EVENT_H 17 | 18 | #include "cdrv.h" 19 | #include "cdrv_event.h" 20 | #include 21 | 22 | class UIEventFilter : public QObject 23 | { 24 | public: 25 | ~UIEventFilter() 26 | { 27 | drv_remove_event_filter(this); 28 | } 29 | bool eventFilter(QObject *obj, QEvent *event) 30 | { 31 | return drv_event_filter(this,0,obj,event->type(),event); 32 | } 33 | }; 34 | 35 | inline void* drvNewFilter(void *obj) 36 | { 37 | QObject *object = (QObject*)obj; 38 | UIEventFilter *filter = new UIEventFilter; 39 | filter->moveToThread(object->thread()); 40 | filter->setParent(object); 41 | object->installEventFilter(filter); 42 | return filter; 43 | } 44 | 45 | 46 | #endif // DRV_EVENT_H 47 | -------------------------------------------------------------------------------- /qtdrv/cdrv_model.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2015-2016 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #include "cdrv_model.h" 16 | 17 | AbstractItemModelFilter::AbstractItemModelFilter() 18 | { 19 | } 20 | -------------------------------------------------------------------------------- /qtdrv/cdrv_model.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2015-2016 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #ifndef CDRV_MODEL_H 16 | #define CDRV_MODEL_H 17 | 18 | #include 19 | 20 | class AbstractItemModelFilter : public QAbstractItemModel 21 | { 22 | public: 23 | AbstractItemModelFilter(); 24 | }; 25 | 26 | #endif // CDRV_MODEL_H 27 | -------------------------------------------------------------------------------- /qtdrv/drv_event.cpp: -------------------------------------------------------------------------------- 1 | #include "drv_event.h" 2 | -------------------------------------------------------------------------------- /qtdrv/drv_event.h: -------------------------------------------------------------------------------- 1 | #ifndef DRV_EVENT_H 2 | #define DRV_EVENT_H 3 | 4 | #include "cdrv.h" 5 | #include "drv_event.h" 6 | #include 7 | 8 | class UIEventFilter : public QObject 9 | { 10 | public: 11 | bool eventFilter(QObject *, QEvent *event) 12 | { 13 | return drv_event_filter(this,event->type(),event); 14 | } 15 | }; 16 | 17 | inline void* drvNewFilter(void *obj) 18 | { 19 | QObject *object = (QObject*)obj; 20 | UIEventFilter *filter = new UIEventFilter; 21 | filter->moveToThread(object->thread()); 22 | filter->setParent(object); 23 | object->installEventFilter(filter); 24 | return filter; 25 | } 26 | 27 | 28 | #endif // DRV_EVENT_H 29 | -------------------------------------------------------------------------------- /qtdrv/qsyntaxhighlighterhook.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2015-2016 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #include "qsyntaxhighlighterhook.h" 16 | #include 17 | 18 | QSyntaxHighlighterHook::QSyntaxHighlighterHook(QObject *parent) : QSyntaxHighlighter(parent) 19 | { 20 | 21 | } 22 | 23 | QSyntaxHighlighterHook::QSyntaxHighlighterHook(QTextDocument *parent) : QSyntaxHighlighter(parent) 24 | { 25 | 26 | } 27 | 28 | QSyntaxHighlighterHook::QSyntaxHighlighterHook(QTextEdit *parent) : QSyntaxHighlighter(parent) 29 | { 30 | 31 | } 32 | 33 | void QSyntaxHighlighterHook::highlightBlock(const QString &text) 34 | { 35 | emit hook_highlightBlock(text); 36 | } 37 | -------------------------------------------------------------------------------- /qtdrv/qsyntaxhighlighterhook.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2015-2016 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #ifndef QSYNTAXHIGHLIGHTERHOOK_H 16 | #define QSYNTAXHIGHLIGHTERHOOK_H 17 | 18 | #include 19 | 20 | class QTextEdit; 21 | class QSyntaxHighlighterHook : public QSyntaxHighlighter 22 | { 23 | Q_OBJECT 24 | public: 25 | QSyntaxHighlighterHook(QObject *parent); 26 | QSyntaxHighlighterHook(QTextDocument *parent); 27 | QSyntaxHighlighterHook(QTextEdit *parent); 28 | 29 | virtual void highlightBlock(const QString &text); 30 | signals: 31 | void hook_highlightBlock(const QString &text); 32 | }; 33 | 34 | #endif // QSYNTAXHIGHLIGHTERHOOK_H 35 | -------------------------------------------------------------------------------- /qtdrv/qtdrv.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 4 | # 5 | #------------------------------------------------- 6 | greaterThan(QT_MAJOR_VERSION, 4) { 7 | QT += widgets uitools printsupport 8 | } else { 9 | QT += core gui 10 | CONFIG += uitools 11 | } 12 | 13 | TARGET = qtdrv.ui 14 | TEMPLATE = lib 15 | 16 | CONFIG += app_bundle 17 | 18 | BUILD_SOURCE_TREE = $$PWD 19 | BUILD_LIB_PATH = $$BUILD_SOURCE_TREE/../bin 20 | 21 | DESTDIR = $$BUILD_LIB_PATH 22 | 23 | DEFINES += QTDRV_LIBRARY 24 | 25 | SOURCES += uiapplication.cpp \ 26 | cdrv.cpp \ 27 | callback.cpp \ 28 | cdrv_event.cpp \ 29 | uidrv.cpp \ 30 | cdrv_model.cpp \ 31 | qsyntaxhighlighterhook.cpp 32 | 33 | 34 | HEADERS += qtdrv_global.h \ 35 | uiapplication.h \ 36 | cdrv.h \ 37 | cdrv_signal.h \ 38 | callback.h \ 39 | cdrv_event.h \ 40 | uidrv.h \ 41 | cdrv_model.h \ 42 | qsyntaxhighlighterhook.h 43 | 44 | 45 | greaterThan(QT_MAJOR_VERSION, 4) { 46 | } else { 47 | HEADERS += qurl/url_help.h \ 48 | qurl/qurlquery.h 49 | 50 | SOURCES += qurl/qurlquery.cpp \ 51 | qurl/qurlrecode.cpp 52 | 53 | } 54 | 55 | unix:!symbian { 56 | maemo5 { 57 | target.path = /opt/usr/lib 58 | } else { 59 | target.path = /usr/lib 60 | } 61 | INSTALLS += target 62 | } 63 | -------------------------------------------------------------------------------- /qtdrv/qtdrv_global.h: -------------------------------------------------------------------------------- 1 | #ifndef QTDRV_GLOBAL_H 2 | #define QTDRV_GLOBAL_H 3 | 4 | #include 5 | 6 | #if defined(QTDRV_LIBRARY) 7 | # define QTUISHARED_EXPORT Q_DECL_EXPORT 8 | #else 9 | # define QTUISHARED_EXPORT Q_DECL_IMPORT 10 | #endif 11 | 12 | #endif // QTDRV_GLOBAL_H 13 | -------------------------------------------------------------------------------- /qtdrv/qurl/qurl_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Copyright (C) 2012 Intel Corporation. 5 | ** Contact: http://www.qt-project.org/legal 6 | ** 7 | ** This file is part of the QtCore module of the Qt Toolkit. 8 | ** 9 | ** $QT_BEGIN_LICENSE:LGPL$ 10 | ** Commercial License Usage 11 | ** Licensees holding valid commercial Qt licenses may use this file in 12 | ** accordance with the commercial license agreement provided with the 13 | ** Software or, alternatively, in accordance with the terms contained in 14 | ** a written agreement between you and Digia. For licensing terms and 15 | ** conditions see http://qt.digia.com/licensing. For further information 16 | ** use the contact form at http://qt.digia.com/contact-us. 17 | ** 18 | ** GNU Lesser General Public License Usage 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser 20 | ** General Public License version 2.1 as published by the Free Software 21 | ** Foundation and appearing in the file LICENSE.LGPL included in the 22 | ** packaging of this file. Please review the following information to 23 | ** ensure the GNU Lesser General Public License version 2.1 requirements 24 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 | ** 26 | ** In addition, as a special exception, Digia gives you certain additional 27 | ** rights. These rights are described in the Digia Qt LGPL Exception 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 | ** 30 | ** GNU General Public License Usage 31 | ** Alternatively, this file may be used under the terms of the GNU 32 | ** General Public License version 3.0 as published by the Free Software 33 | ** Foundation and appearing in the file LICENSE.GPL included in the 34 | ** packaging of this file. Please review the following information to 35 | ** ensure the GNU General Public License version 3.0 requirements will be 36 | ** met: http://www.gnu.org/copyleft/gpl.html. 37 | ** 38 | ** 39 | ** $QT_END_LICENSE$ 40 | ** 41 | ****************************************************************************/ 42 | 43 | #ifndef QURL_P_H 44 | #define QURL_P_H 45 | 46 | // 47 | // W A R N I N G 48 | // ------------- 49 | // 50 | // This file is not part of the Qt API. It exists for the convenience of 51 | // qurl*.cpp This header file may change from version to version without 52 | // notice, or even be removed. 53 | // 54 | // We mean it. 55 | // 56 | 57 | #include "qurl.h" 58 | #include "url_help.h" 59 | 60 | QT_BEGIN_NAMESPACE 61 | 62 | // in qurlrecode.cpp 63 | extern Q_AUTOTEST_EXPORT int qt_urlRecode(QString &appendTo, const QChar *begin, const QChar *end, 64 | QUrl2::ComponentFormattingOptions encoding, const ushort *tableModifications = 0); 65 | 66 | // in qurlidna.cpp 67 | enum AceOperation { ToAceOnly, NormalizeAce }; 68 | extern QString qt_ACE_do(const QString &domain, AceOperation op); 69 | extern Q_AUTOTEST_EXPORT void qt_nameprep(QString *source, int from); 70 | extern Q_AUTOTEST_EXPORT bool qt_check_std3rules(const QChar *uc, int len); 71 | extern Q_AUTOTEST_EXPORT void qt_punycodeEncoder(const QChar *s, int ucLength, QString *output); 72 | extern Q_AUTOTEST_EXPORT QString qt_punycodeDecoder(const QString &pc); 73 | extern Q_AUTOTEST_EXPORT QString qt_urlRecodeByteArray(const QByteArray &ba); 74 | 75 | QT_END_NAMESPACE 76 | 77 | #endif // QURL_P_H 78 | -------------------------------------------------------------------------------- /qtdrv/qurl/qurlquery.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2012 Intel Corporation. 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the QtCore module of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #ifndef QURLQUERY_H 43 | #define QURLQUERY_H 44 | 45 | #include 46 | #include 47 | #include 48 | 49 | #include "url_help.h" 50 | 51 | QT_BEGIN_HEADER 52 | 53 | QT_BEGIN_NAMESPACE 54 | 55 | QString fromEncodedComponent_helper(const QByteArray &ba); 56 | inline QByteArray toLatin1_helper(const QString &string) 57 | { 58 | if (string.isEmpty()) 59 | return string.isNull() ? QByteArray() : QByteArray(""); 60 | return string.toLatin1(); 61 | } 62 | 63 | class QUrlQueryPrivate; 64 | class QUrlQuery 65 | { 66 | public: 67 | QUrlQuery(); 68 | explicit QUrlQuery(const QUrl &url); 69 | explicit QUrlQuery(const QString &queryString); 70 | QUrlQuery(const QUrlQuery &other); 71 | QUrlQuery &operator=(const QUrlQuery &other); 72 | #ifdef Q_COMPILER_RVALUE_REFS 73 | QUrlQuery &operator=(QUrlQuery &&other) 74 | { qSwap(d, other.d); return *this; } 75 | #endif 76 | ~QUrlQuery(); 77 | 78 | bool operator==(const QUrlQuery &other) const; 79 | bool operator!=(const QUrlQuery &other) const 80 | { return !(*this == other); } 81 | 82 | void swap(QUrlQuery &other) { qSwap(d, other.d); } 83 | 84 | bool isEmpty() const; 85 | bool isDetached() const; 86 | void clear(); 87 | 88 | QString query(QUrl2::ComponentFormattingOptions encoding = QUrl2::PrettyDecoded) const; 89 | void setQuery(const QString &queryString); 90 | QString toString(QUrl2::ComponentFormattingOptions encoding = QUrl2::PrettyDecoded) const 91 | { return query(encoding); } 92 | 93 | void setQueryDelimiters(QChar valueDelimiter, QChar pairDelimiter); 94 | QChar queryValueDelimiter() const; 95 | QChar queryPairDelimiter() const; 96 | 97 | void setQueryItems(const QList > &query); 98 | QList > queryItems(QUrl2::ComponentFormattingOptions encoding = QUrl2::PrettyDecoded) const; 99 | 100 | bool hasQueryItem(const QString &key) const; 101 | void addQueryItem(const QString &key, const QString &value); 102 | void removeQueryItem(const QString &key); 103 | QString queryItemValue(const QString &key, QUrl2::ComponentFormattingOptions encoding = QUrl2::PrettyDecoded) const; 104 | QStringList allQueryItemValues(const QString &key, QUrl2::ComponentFormattingOptions encoding = QUrl2::PrettyDecoded) const; 105 | void removeAllQueryItems(const QString &key); 106 | 107 | static QChar defaultQueryValueDelimiter() 108 | { return QChar(ushort('=')); } 109 | static QChar defaultQueryPairDelimiter() 110 | { return QChar(ushort('&')); } 111 | 112 | private: 113 | friend class QUrl; 114 | QSharedDataPointer d; 115 | public: 116 | typedef QSharedDataPointer DataPtr; 117 | inline DataPtr &data_ptr() { return d; } 118 | }; 119 | 120 | Q_DECLARE_SHARED(QUrlQuery) 121 | 122 | QT_END_NAMESPACE 123 | 124 | QT_END_HEADER 125 | 126 | #endif // QURLQUERY_H 127 | -------------------------------------------------------------------------------- /qtdrv/qurl/url_help.h: -------------------------------------------------------------------------------- 1 | #ifndef URL_HELP_H 2 | #define URL_HELP_H 3 | 4 | class QUrl2 { 5 | public: 6 | enum ComponentFormattingOption { 7 | PrettyDecoded = 0x000000, 8 | EncodeSpaces = 0x100000, 9 | EncodeUnicode = 0x200000, 10 | EncodeDelimiters = 0x400000 | 0x800000, 11 | EncodeReserved = 0x1000000, 12 | DecodeReserved = 0x2000000, 13 | // 0x4000000 used to indicate full-decode mode 14 | 15 | FullyEncoded = EncodeSpaces | EncodeUnicode | EncodeDelimiters | EncodeReserved, 16 | FullyDecoded = FullyEncoded | DecodeReserved | 0x4000000 17 | }; 18 | 19 | Q_DECLARE_FLAGS(ComponentFormattingOptions, ComponentFormattingOption); 20 | }; 21 | 22 | #endif // URL_HELP_H 23 | -------------------------------------------------------------------------------- /qtdrv/uiapplication.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2015-2016 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #include "uiapplication.h" 16 | #include "cdrv.h" 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | UIApplication::UIApplication(int argc, char **argv) : 24 | QApplication(argc,argv) 25 | { 26 | } 27 | 28 | static bool event_init = false; 29 | 30 | bool UIApplication::event(QEvent *e) 31 | { 32 | if (!event_init && e->type() == QEvent::User+1) { 33 | event_init = true; 34 | app_event_init(); 35 | } 36 | 37 | if (e->type() == QEvent::User+2) { 38 | app_async_task(); 39 | } 40 | 41 | return QApplication::event(e); 42 | } 43 | 44 | void UIApplication::sendAsyncTask() 45 | { 46 | this->postEvent(this,new QEvent(QEvent::Type(QEvent::User+2))); 47 | } 48 | -------------------------------------------------------------------------------- /qtdrv/uiapplication.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2015-2016 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #ifndef UIAPPLICATION_H 16 | #define UIAPPLICATION_H 17 | 18 | #include 19 | #include 20 | 21 | class UIApplication : public QApplication 22 | { 23 | Q_OBJECT 24 | public: 25 | explicit UIApplication(int argc = 0, char **argv = 0); 26 | virtual bool event(QEvent *); 27 | public: 28 | void sendAsyncTask(); 29 | }; 30 | 31 | #endif // UIAPPLICATION_H 32 | -------------------------------------------------------------------------------- /qtdrv/uidrv.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2015-2016 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #include "uidrv.h" 16 | #include "cdrv.h" 17 | #include 18 | #include 19 | 20 | UIDrv uidrv; 21 | QByteArray utf8_cache; 22 | 23 | UIDrv::UIDrv(QObject *parent) : 24 | QObject(parent), drv_index(0) 25 | { 26 | m_thread = this->thread(); 27 | connect(this,SIGNAL(asyncDrv(void*,int,int,void*,void*,void*,void*,void*,void*,void*,void*,void*,void*,void*,void*,int*)),this,SLOT(slotDrv(void*,int,int,void*,void*,void*,void*,void*,void*,void*,void*,void*,void*,void*,void*,int*)),Qt::BlockingQueuedConnection); 28 | connect(this,SIGNAL(asyncTask()),this,SLOT(slotAsyncTask())); 29 | connect(this,SIGNAL(syncTask()),this,SLOT(slotAsyncTask()),Qt::BlockingQueuedConnection); 30 | } 31 | 32 | void UIDrv::call_async_task() 33 | { 34 | if (m_thread == QThread::currentThread()) { 35 | slotAsyncTask(); 36 | } else { 37 | emit asyncTask(); 38 | } 39 | } 40 | 41 | void UIDrv::call_sync_task() 42 | { 43 | if (m_thread == QThread::currentThread()) { 44 | slotAsyncTask(); 45 | } else { 46 | emit syncTask(); 47 | } 48 | } 49 | 50 | int UIDrv::drv(void *_p, int _typeid, int funcid, void *p1, void *p2, void *p3, void *p4, void *p5, void *p6, void *p7, void *p8, void *p9, void *p10, void *p11, void *p12) 51 | { 52 | if (drv_index >= 1000) { 53 | // return -3; 54 | } 55 | drv_index++; 56 | int r = 0; 57 | if (QThread::currentThread() == m_thread ) { 58 | slotDrv(_p,_typeid,funcid,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,&r); 59 | } else { 60 | emit asyncDrv(_p,_typeid,funcid,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,&r); 61 | } 62 | qDebug() << drv_index; 63 | return r; 64 | } 65 | 66 | void UIDrv::slotDrv(void *_p, int _typeid, int funcid, void *p1, void *p2, void *p3, void *p4, void *p5, void *p6, void *p7, void *p8, void *p9, void *p10, void *p11, void *p12, int *r) 67 | { 68 | drv_index--; 69 | *r = qtdrv(_p,_typeid,funcid,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12); 70 | } 71 | 72 | void UIDrv::slotAsyncTask() 73 | { 74 | app_async_task(); 75 | } 76 | -------------------------------------------------------------------------------- /qtdrv/uidrv.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | ** Copyright 2015-2016 visualfc . All rights reserved. 3 | ** 4 | ** This library is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU Lesser General Public 6 | ** License as published by the Free Software Foundation; either 7 | ** version 2.1 of the License, or (at your option) any later version. 8 | ** 9 | ** This library is distributed in the hope that it will be useful, 10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | ** Lesser General Public License for more details. 13 | *********************************************************************/ 14 | 15 | #ifndef UIDRV_H 16 | #define UIDRV_H 17 | 18 | #include 19 | #include 20 | 21 | class UIDrv : public QObject 22 | { 23 | Q_OBJECT 24 | public: 25 | explicit UIDrv(QObject *parent = 0); 26 | public: 27 | void call_async_task(); 28 | void call_sync_task(); 29 | int drv(void *_p, int _typeid, int funcid, void *p1, void *p2, void *p3, void *p4, void *p5, void *p6, void *p7, void *p8, void *p9, void *p10, void *p11, void *p12); 30 | signals: 31 | void asyncDrv(void *_p, int _typeid, int funcid, void *p1, void *p2, void *p3, void *p4, void *p5, void *p6, void *p7, void *p8, void *p9, void *p10, void *p11, void *p12, int *r); 32 | void asyncTask(); 33 | void syncTask(); 34 | public slots: 35 | void slotDrv(void *_p, int _typeid, int funcid, void *p1, void *p2, void *p3, void *p4, void *p5, void *p6, void *p7, void *p8, void *p9, void *p10, void *p11, void *p12, int *r); 36 | void slotAsyncTask(); 37 | protected: 38 | int drv_index; 39 | QThread *m_thread; 40 | }; 41 | 42 | extern UIDrv uidrv; 43 | extern QByteArray utf8_cache; 44 | 45 | #endif // UIDRV_H 46 | -------------------------------------------------------------------------------- /qtdrv/uievent.cpp: -------------------------------------------------------------------------------- 1 | #include "uievent.h" 2 | #include "uiapplication.h" 3 | #include "uiutil.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | UIEvent::UIEvent(QObject *parent, int type, void *context) : 17 | QObject(parent), m_type(type), m_context(context) 18 | { 19 | } 20 | 21 | UIEvent::~UIEvent() 22 | { 23 | theApp.fnEventRelease(this,m_context); 24 | } 25 | 26 | UIEvent *UIEvent::createUIEvent(QObject *sender, int st, void *context) 27 | { 28 | UIEvent *event = new UIEvent(sender,st,context); 29 | sender->installEventFilter(event); 30 | return event; 31 | } 32 | 33 | bool UIEvent::eventFilter(QObject *obj, QEvent *event) 34 | { 35 | if (m_type == event->type()) { 36 | int accept = event->isAccepted() ? 1 : 0; 37 | switch(m_type) { 38 | case QEvent::Create: 39 | case QEvent::Close: 40 | case QEvent::Show: 41 | case QEvent::Hide: 42 | case QEvent::Enter: 43 | case QEvent::Leave: { 44 | Event ev = {accept,0}; 45 | theApp.fnEventCall(obj,this,m_type,&ev,m_context); 46 | event->setAccepted(ev.Accept != 0); 47 | return ev.Filter; 48 | } 49 | case QEvent::FocusIn: 50 | case QEvent::FocusOut: { 51 | QFocusEvent *e = (QFocusEvent*)event; 52 | FocusEvent ev = {accept,0,e->reason()}; 53 | theApp.fnEventCall(obj,this,m_type,&ev,m_context); 54 | event->setAccepted(ev.Accept != 0); 55 | return ev.Filter; 56 | } 57 | case QEvent::Timer: { 58 | QTimerEvent *e = (QTimerEvent*)event; 59 | TimerEvent ev = {accept,0,e->timerId()}; 60 | theApp.fnEventCall(obj,this,m_type,&ev,m_context); 61 | event->setAccepted(ev.Accept != 0); 62 | return ev.Filter; 63 | } 64 | case QEvent::HoverEnter: 65 | case QEvent::HoverLeave: 66 | case QEvent::HoverMove: { 67 | QHoverEvent *e = (QHoverEvent*)event; 68 | const QPoint &pt = e->pos(); 69 | const QPoint &opt = e->oldPos(); 70 | HoverEvent ev = {accept,0,pt.x(),pt.y(),opt.x(),opt.y()}; 71 | theApp.fnEventCall(obj,this,m_type,&ev,m_context); 72 | event->setAccepted(ev.Accept != 0); 73 | return ev.Filter; 74 | } 75 | case QEvent::KeyPress: 76 | case QEvent::KeyRelease: { 77 | QKeyEvent *e = (QKeyEvent*)event; 78 | //KeyEvent ev = {accept,0,e->modifiers(),e->count(),e->isAutoRepeat()?1:0,e->key(),e->nativeModifiers(),e->nativeScanCode(),e->nativeVirtualKey(),toString(e->text())}; 79 | //theApp.fnEventCall(obj,this,m_type,&ev,m_context); 80 | //event->setAccepted(ev.Accept != 0); 81 | //return ev.Filter; 82 | } 83 | case QEvent::MouseButtonPress: 84 | case QEvent::MouseButtonRelease: 85 | case QEvent::MouseButtonDblClick: 86 | case QEvent::MouseMove: { 87 | QMouseEvent *e = (QMouseEvent*)event; 88 | const QPoint &gpt = e->globalPos(); 89 | const QPoint &pt = e->pos(); 90 | MouseEvent ev = {accept,0,e->modifiers(),e->button(),e->buttons(),gpt.x(),gpt.y(),pt.x(),pt.y()}; 91 | theApp.fnEventCall(obj,this,m_type,&ev,m_context); 92 | event->setAccepted(ev.Accept != 0); 93 | return ev.Filter; 94 | } 95 | case QEvent::Move: { 96 | QMoveEvent *e = (QMoveEvent*)event; 97 | const QPoint &pt = e->pos(); 98 | const QPoint &opt = e->oldPos(); 99 | MoveEvent ev = {accept,0,pt.x(),pt.y(),opt.x(),opt.y()}; 100 | theApp.fnEventCall(obj,this,m_type,&ev,m_context); 101 | event->setAccepted(ev.Accept != 0); 102 | return ev.Filter; 103 | } 104 | case QEvent::Resize: { 105 | QResizeEvent *e = (QResizeEvent*)event; 106 | const QSize &sz = e->size(); 107 | const QSize &osz = e->oldSize(); 108 | ResizeEvent ev = {accept,0,sz.width(),sz.height(),osz.width(),osz.height()}; 109 | theApp.fnEventCall(obj,this,m_type,&ev,m_context); 110 | event->setAccepted(ev.Accept != 0); 111 | return ev.Filter; 112 | } 113 | case QEvent::Paint: { 114 | QPaintEvent *e = (QPaintEvent*)event; 115 | const QRect &rc = e->rect(); 116 | PaintEvent ev = {accept,rc.x(),rc.y(),rc.width(),rc.height()}; 117 | theApp.fnEventCall(obj,this,m_type,&ev,m_context); 118 | event->setAccepted(ev.Accept != 0); 119 | return ev.Filter; 120 | } 121 | default: 122 | Event ev = {event->isAccepted(),0}; 123 | theApp.fnEventCall(obj,this,m_type,&ev,m_context); 124 | event->setAccepted(ev.Accept != 0); 125 | return ev.Filter; 126 | } 127 | } 128 | return QObject::eventFilter(obj, event); 129 | } 130 | -------------------------------------------------------------------------------- /qtdrv/uievent.h: -------------------------------------------------------------------------------- 1 | #ifndef UIEVENT_H 2 | #define UIEVENT_H 3 | 4 | #include 5 | 6 | class UIEvent : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit UIEvent(QObject *parent = 0, int type = 0,void *context = 0); 11 | virtual ~UIEvent(); 12 | public: 13 | static UIEvent *createUIEvent(QObject *sender, int st, void *context); 14 | protected: 15 | virtual bool eventFilter(QObject *, QEvent *); 16 | int m_type; 17 | void *m_context; 18 | }; 19 | 20 | #endif // UIEVENT_H 21 | -------------------------------------------------------------------------------- /qtdrv/uilib.cpp: -------------------------------------------------------------------------------- 1 | #include "uilib.h" 2 | #include "uiapplication.h" 3 | #include "uisignal.h" 4 | #include 5 | #include 6 | 7 | void InitList(List *list, int size) 8 | { 9 | list->count = size; 10 | list->data = new const void*[size]; 11 | } 12 | 13 | void FreeList(List *list) 14 | { 15 | delete[] list->data; 16 | list->count = 0; 17 | list->data = 0; 18 | } 19 | 20 | 21 | UIOBJECT Instance() 22 | { 23 | return (UIOBJECT)&theApp; 24 | } 25 | 26 | int RunLoop() 27 | { 28 | return theApp.exec(); 29 | } 30 | 31 | void Quit() 32 | { 33 | theApp.quit(); 34 | } 35 | 36 | UIHANDLE CreateHandle(int id, void *param) 37 | { 38 | return theApp.createHandle(id,param); 39 | } 40 | 41 | void DestroyHandle(int id, UIHANDLE uih) 42 | { 43 | } 44 | 45 | int HandleFunction(int id, UIHANDLE uih, int fn, void *p1, void *p2, void *p3, void *p4, void *p5, void *p6) 46 | { 47 | return 0; 48 | } 49 | 50 | UIOBJECT CreateObject(int id, UIOBJECT parent) 51 | { 52 | return theApp.createObject(id,(QObject*)parent); 53 | } 54 | 55 | void ReleaseObject(int id, UIOBJECT obj) 56 | { 57 | theApp.destroyObject(id, (QObject*)obj); 58 | } 59 | 60 | int ObjectFunction(int id, void *obj, int fn, void *p1, void *p2, void *p3, void *p4, void *p5, void *p6) 61 | { 62 | return 0; 63 | } 64 | 65 | 66 | int SetSignalCallback(SignalCallProc fc, SignalReleaseProc fr) 67 | { 68 | if (fc != 0) 69 | theApp.fnSignalCall = fc; 70 | if (fr != 0) 71 | theApp.fnSignalRelease = fr; 72 | return 0; 73 | } 74 | 75 | UISIGNAL CreateSignal(UIOBJECT uio, int st, const char *signal, void *context) 76 | { 77 | return theApp.createSignal((QObject*)uio,st,signal,context); 78 | } 79 | 80 | void EnableSignal(UISIGNAL uis, bool b) 81 | { 82 | ((UISignal*)uis)->setEnable(b); 83 | } 84 | 85 | 86 | UIEVENT _CreateEvent(UIOBJECT object, int type, void *context) 87 | { 88 | return theApp.createEvent((QObject*)object,type,context); 89 | } 90 | 91 | 92 | void SetEventCallback(EventCallProc fc, EventReleaseProc fr) 93 | { 94 | if (fc != 0) { 95 | theApp.fnEventCall = fc; 96 | } 97 | if (fr != 0) { 98 | theApp.fnEventRelease = fr; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /qtdrv/uilib.h: -------------------------------------------------------------------------------- 1 | #ifndef UILIB_H 2 | #define UILIB_H 3 | 4 | #include "qtui_global.h" 5 | 6 | typedef int INT; 7 | typedef double REAL; 8 | typedef unsigned char BYTE; 9 | typedef unsigned short USHORT; 10 | 11 | typedef void *UIOBJECT; 12 | typedef void *UIHANDLE; 13 | typedef void *UISIGNAL; 14 | typedef void *UIEVENT; 15 | 16 | enum SignalType { 17 | ST_None, 18 | ST_Bool, //bool& 19 | ST_Int, //int& 20 | ST_String, //UIString& 21 | ST_Action //void* 22 | }; 23 | 24 | typedef struct _ByteArray { 25 | const char *data; 26 | int size; 27 | } ByteArray; 28 | 29 | typedef struct _String { 30 | const ushort *data; 31 | int size; 32 | } String; 33 | 34 | typedef struct _List { 35 | const void **data; 36 | int count; 37 | } List; 38 | 39 | typedef struct _Point { 40 | INT X; 41 | INT Y; 42 | } Point; 43 | 44 | typedef struct _PointF { 45 | REAL X; 46 | REAL Y; 47 | } PointF; 48 | 49 | typedef struct _Size { 50 | INT Width; 51 | INT Height; 52 | } Size; 53 | 54 | typedef struct _SizeF { 55 | REAL Width; 56 | REAL Height; 57 | } SizeF; 58 | 59 | typedef struct _Rect { 60 | INT X; 61 | INT Y; 62 | INT Widht; 63 | INT Height; 64 | } Rect; 65 | 66 | typedef struct _RectF { 67 | REAL X; 68 | REAL Y; 69 | REAL Width; 70 | REAL Height; 71 | } RectF; 72 | 73 | typedef struct _PathData { 74 | INT Count; 75 | Point* Points; 76 | BYTE* Types; 77 | } PathData; 78 | 79 | typedef struct _PathDataF { 80 | INT Count; 81 | PointF* Points; 82 | BYTE* Types; 83 | } PathDataF; 84 | 85 | typedef struct _Event { 86 | int Accept; 87 | int Filter; 88 | } Event; 89 | 90 | typedef struct _TimerEvent { 91 | int Accept; 92 | int Filter; 93 | int Timerid; 94 | } TimerEvent; 95 | 96 | typedef struct _MoveEvent { 97 | int Accept; 98 | int Filter; 99 | int X; 100 | int Y; 101 | int OX; 102 | int OY; 103 | } MoveEvent; 104 | 105 | typedef struct _HoverEvent { 106 | int Accept; 107 | int Filter; 108 | int X; 109 | int Y; 110 | int OX; 111 | int OY; 112 | } HoverEvent; 113 | 114 | typedef struct ResizeEvent { 115 | int Accept; 116 | int Filter; 117 | int W; 118 | int H; 119 | int OW; 120 | int OH; 121 | } ResizeEvent; 122 | 123 | typedef struct _MouseEvent { 124 | int Accept; 125 | int Filter; 126 | int Modify; 127 | int Button; 128 | int Buttons; 129 | int GX; 130 | int GY; 131 | int X; 132 | int Y; 133 | } MouseEvent; 134 | 135 | typedef struct _KeyEvent { 136 | int Accept; 137 | int Filter; 138 | int Modify; 139 | int Count; 140 | int Autorepeat; 141 | int Key; 142 | quint32 NativeModifiers; 143 | quint32 NativeScanCode; 144 | quint32 NativeVirtualKey; 145 | String text; 146 | } KeyEvent; 147 | 148 | typedef struct _PaintEvent { 149 | int Accept; 150 | int Filter; 151 | int X; 152 | int Y; 153 | int W; 154 | int H; 155 | } PaintEvent; 156 | 157 | typedef struct _FocusEvent { 158 | int Accept; 159 | int Filter; 160 | int Reason; 161 | } FocusEvent; 162 | 163 | typedef void (*SignalCallProc)(UIOBJECT obj, UISIGNAL uis, int type, void *p1, void *p2, void *context); 164 | typedef void (*SignalReleaseProc)(UISIGNAL uis, void *context); 165 | typedef void (*EventCallProc)(UIOBJECT obj, UIEVENT uie, int type, void *event, void *context); 166 | typedef void (*EventReleaseProc)(UIEVENT uie, void *context); 167 | 168 | extern "C" { 169 | QTUISHARED_EXPORT void InitList(List *list, int size); 170 | QTUISHARED_EXPORT void FreeList(List *list); 171 | 172 | //Application 173 | QTUISHARED_EXPORT UIOBJECT Instance(); 174 | QTUISHARED_EXPORT int RunLoop(); 175 | QTUISHARED_EXPORT void Quit(); 176 | 177 | //widget signal 178 | QTUISHARED_EXPORT int SetSignalCallback(SignalCallProc fc, SignalReleaseProc fr); 179 | QTUISHARED_EXPORT UISIGNAL CreateSignal(UIOBJECT uio, int st, const char *signal, void *context); 180 | QTUISHARED_EXPORT void EnableSignal(UISIGNAL signal, bool b); 181 | 182 | //safe thread ui object 183 | QTUISHARED_EXPORT UIOBJECT CreateObject(int id, UIOBJECT parent); 184 | QTUISHARED_EXPORT int ObjectFunction(int id, UIOBJECT object, int fn, void *p1, void *p2, void *p3, void *p4, void *p5, void *p6); 185 | QTUISHARED_EXPORT void ReleaseObject(int id, UIOBJECT obj); 186 | 187 | //widget event 188 | QTUISHARED_EXPORT void SetEventCallback(EventCallProc fc, EventReleaseProc fr); 189 | QTUISHARED_EXPORT UIEVENT _CreateEvent(UIOBJECT object, int type, void *context); 190 | 191 | //util tool handle 192 | QTUISHARED_EXPORT UIHANDLE CreateHandle(int id, void *param); 193 | QTUISHARED_EXPORT void DestroyHandle(int id, UIHANDLE uih); 194 | QTUISHARED_EXPORT int HandleFunction(int id, UIHANDLE uih, int fn, void *p1, void *p2, void *p3, void *p4, void *p5, void *p6); 195 | 196 | } 197 | 198 | #endif // UILIB_H 199 | -------------------------------------------------------------------------------- /qtdrv/uisignal.cpp: -------------------------------------------------------------------------------- 1 | #include "uisignal.h" 2 | #include "uiapplication.h" 3 | #include "uiutil.h" 4 | #include 5 | 6 | UISignal::UISignal(QObject *sender, int type) : 7 | QObject(sender), m_type(type), m_enable(true) 8 | { 9 | this->setObjectName("UISignal"); 10 | } 11 | 12 | UISignal::~UISignal() 13 | { 14 | theApp.fnSignalRelease(this,m_context); 15 | } 16 | 17 | void UISignal::setEnable(bool b) 18 | { 19 | if (m_enable == b) { 20 | return; 21 | } 22 | m_enable = b; 23 | if (m_enable) { 24 | QObject::connect(this->parent(),m_signal,this,m_method); 25 | } else { 26 | QObject::disconnect(this->parent(),m_signal,this,m_method); 27 | } 28 | } 29 | 30 | void UISignal::call() 31 | { 32 | theApp.fnSignalCall(this->parent(),this,m_type,0,0,m_context); 33 | } 34 | 35 | void UISignal::call(bool v) 36 | { 37 | theApp.fnSignalCall(this->parent(),this,m_type,&v,0,m_context); 38 | } 39 | 40 | void UISignal::call(int v) 41 | { 42 | theApp.fnSignalCall(this->parent(),this,m_type,&v,0,m_context); 43 | } 44 | 45 | void UISignal::call(const QString& v) 46 | { 47 | //String s = toString(v); 48 | //theApp.fnSignalCall(this->parent(),this,m_type,&s,0,m_context); 49 | } 50 | 51 | void UISignal::call(QAction* v) 52 | { 53 | theApp.fnSignalCall(this->parent(),this,m_type,v,0,m_context); 54 | } 55 | 56 | UISignal *UISignal::createUISignal(QObject *sender, int type, const char *signal,void *context) 57 | { 58 | UISignal *uis = new UISignal(sender); 59 | switch (type) { 60 | case ST_None: 61 | uis->m_method = SLOT(call()); 62 | break; 63 | case ST_Int: 64 | uis->m_method = SLOT(call(int)); 65 | break; 66 | case ST_Bool: 67 | uis->m_method = SLOT(call(bool)); 68 | case ST_String: 69 | uis->m_method = SLOT(call(QString)); 70 | break; 71 | case ST_Action: 72 | uis->m_method = SLOT(call(QAction*)); 73 | break; 74 | default: 75 | goto end; 76 | break; 77 | } 78 | if (QObject::connect(sender,signal,uis,uis->m_method)) { 79 | uis->m_type = type; 80 | uis->m_signal = signal; 81 | uis->m_context = context; 82 | return uis; 83 | } 84 | end: 85 | delete uis; 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /qtdrv/uisignal.h: -------------------------------------------------------------------------------- 1 | #ifndef UISIGNAL_H 2 | #define UISIGNAL_H 3 | 4 | #include 5 | #include 6 | 7 | class UISignal : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit UISignal(QObject *sender = 0, int type = 0); 12 | virtual ~UISignal(); 13 | void setEnable(bool b); 14 | public: 15 | static UISignal *createUISignal(QObject *sender, int type, const char *signal, void *context); 16 | public slots: 17 | void call(); 18 | void call(bool); 19 | void call(int); 20 | void call(const QString&); 21 | void call(QAction*); 22 | protected: 23 | int m_type; 24 | bool m_enable; 25 | const char *m_signal; 26 | const char *m_method; 27 | void *m_context; 28 | }; 29 | 30 | #endif // UISIGNAL_H 31 | -------------------------------------------------------------------------------- /qtdrv/uiutil.cpp: -------------------------------------------------------------------------------- 1 | #include "uiutil.h" 2 | -------------------------------------------------------------------------------- /qtdrv/uiutil.h: -------------------------------------------------------------------------------- 1 | #ifndef UIUTIL_H 2 | #define UIUTIL_H 3 | 4 | #include "uilib.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | /* 15 | inline QByteArray fromByteArray(const ByteArray &v) 16 | { 17 | return QByteArray(v.data,v.size); 18 | } 19 | 20 | inline QByteArray fromByteArray(void *p) 21 | { 22 | ByteArray *pb = (ByteArray*)p; 23 | return QByteArray(pb->data,pb->size); 24 | } 25 | 26 | inline ByteArray toByteArray(const QByteArray &v) 27 | { 28 | return (ByteArray){v.constData(),v.size()}; 29 | } 30 | 31 | inline ByteArray toByteArray(const void *p) 32 | { 33 | QByteArray *v = (QByteArray*)p; 34 | return (ByteArray){v->constData(),v->size()}; 35 | } 36 | 37 | inline ByteArray toByteArray(void *p) 38 | { 39 | QByteArray *v = (QByteArray*)p; 40 | return (ByteArray){v->constData(),v->size()}; 41 | } 42 | 43 | inline void toByteArray(void *p, const QByteArray &v) 44 | { 45 | ByteArray *pb = (ByteArray*)p; 46 | pb->data = v.constData(); 47 | pb->size = v.size(); 48 | } 49 | 50 | inline QString fromString(const String &v) 51 | { 52 | return QString::fromUtf16(v.data,v.size); 53 | } 54 | 55 | inline String toString(const QString &v) 56 | { 57 | return (String){v.utf16(),v.size()}; 58 | } 59 | 60 | inline void toString(void *p, const QString &v) 61 | { 62 | String *ps = (String*)p; 63 | ps->data = v.utf16(); 64 | ps->size = v.size(); 65 | } 66 | 67 | inline QPoint fromPoint(const Point &v) 68 | { 69 | return QPoint(v.X,v.Y); 70 | } 71 | 72 | inline Point toPoint(const QPoint &v) 73 | { 74 | return (Point){v.x(),v.y()}; 75 | } 76 | 77 | inline QPointF fromPointF(const PointF &v) 78 | { 79 | return QPointF(v.X,v.Y); 80 | } 81 | 82 | inline PointF toPointF(const QPointF &v) 83 | { 84 | return (PointF){v.x(),v.y()}; 85 | } 86 | 87 | inline QSize fromSize(const Size &v) 88 | { 89 | return QSize(v.Width,v.Height); 90 | } 91 | 92 | inline Size toSize(const QSize &v) 93 | { 94 | return (Size){v.width(),v.height()}; 95 | } 96 | 97 | inline QSizeF fromSizeF(const SizeF &v) 98 | { 99 | return QSizeF(v.Width,v.Height); 100 | } 101 | 102 | inline SizeF toSizeF(const QSizeF &v) 103 | { 104 | return (SizeF){v.width(),v.height()}; 105 | } 106 | 107 | inline QRect fromRect(const Rect &v) 108 | { 109 | return QRect(v.X,v.Y,v.Widht,v.Height); 110 | } 111 | 112 | inline Rect toRect(const QRect &v) 113 | { 114 | return (Rect){v.x(),v.y(),v.width(),v.height()}; 115 | } 116 | 117 | inline QRectF fromRectF(const RectF &v) 118 | { 119 | return QRectF(v.X,v.Y,v.Width,v.Height); 120 | } 121 | 122 | inline RectF toRect(const QRectF &v) 123 | { 124 | return (RectF){v.x(),v.y(),v.width(),v.height()}; 125 | } 126 | 127 | template 128 | inline List toList(const QList ar) 129 | { 130 | List list; 131 | InitList(&list,ar.size()); 132 | for (int i = 0; i < ar.size(); i++) { 133 | list.data[i] = (void*)&ar[i]; 134 | } 135 | return list; 136 | } 137 | */ 138 | 139 | #endif // UIUTIL_H 140 | -------------------------------------------------------------------------------- /tools/rcc/main.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #include 43 | //#include 44 | 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | QT_BEGIN_NAMESPACE 52 | 53 | void showHelp(const QString &argv0, const QString &error) 54 | { 55 | fprintf(stderr, "Qt resource compiler\n"); 56 | if (!error.isEmpty()) 57 | fprintf(stderr, "%s: %s\n", qPrintable(argv0), qPrintable(error)); 58 | fprintf(stderr, "Usage: %s [options] \n\n" 59 | "Options:\n" 60 | " -o file write output to file rather than stdout\n" 61 | " -go pkg write output to go source format with pkg\n" 62 | " -name name create an external initialization function with name\n" 63 | " -threshold level threshold to consider compressing files\n" 64 | " -compress level compress input files by level\n" 65 | " -root path prefix resource access path with root path\n" 66 | " -no-compress disable all compression\n" 67 | " -binary output a binary file for use as a dynamic resource\n" 68 | " -namespace turn off namespace macros\n" 69 | " -project Output a resource file containing all\n" 70 | " files from the current directory\n" 71 | " -version display version\n" 72 | " -help display this information\n", 73 | qPrintable(argv0)); 74 | } 75 | 76 | void dumpRecursive(const QDir &dir, QTextStream &out) 77 | { 78 | QFileInfoList entries = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot 79 | | QDir::NoSymLinks); 80 | foreach (QFileInfo entry, entries) { 81 | if (entry.isDir()) { 82 | dumpRecursive(entry.filePath(), out); 83 | } else { 84 | out << QLatin1String("") 85 | << entry.filePath() 86 | << QLatin1String("\n"); 87 | } 88 | } 89 | } 90 | 91 | int createProject(const QString &outFileName) 92 | { 93 | QDir currentDir = QDir::current(); 94 | QString currentDirName = currentDir.dirName(); 95 | if (currentDirName.isEmpty()) 96 | currentDirName = QLatin1String("root"); 97 | 98 | QFile file; 99 | bool isOk = false; 100 | if (outFileName.isEmpty()) { 101 | isOk = file.open(stdout, QFile::WriteOnly | QFile::Text); 102 | } else { 103 | file.setFileName(outFileName); 104 | isOk = file.open(QFile::WriteOnly | QFile::Text); 105 | } 106 | if (!isOk) { 107 | fprintf(stderr, "Unable to open %s: %s\n", 108 | outFileName.isEmpty() ? qPrintable(outFileName) : "standard output", 109 | qPrintable(file.errorString())); 110 | return 1; 111 | } 112 | 113 | QTextStream out(&file); 114 | out << QLatin1String("\n" 115 | "\n"); 116 | 117 | // use "." as dir to get relative file pathes 118 | dumpRecursive(QDir(QLatin1String(".")), out); 119 | 120 | out << QLatin1String("\n" 121 | "\n"); 122 | 123 | return 0; 124 | } 125 | 126 | static inline QStringList qCmdLineArgs(int argc, char *argv[]) 127 | { 128 | QStringList args; 129 | for (int i = 0; i != argc; ++i) 130 | args += QString::fromLocal8Bit(argv[i]); 131 | return args; 132 | } 133 | 134 | int runRcc(int argc, char *argv[]) 135 | { 136 | QString outFilename; 137 | bool helpRequested = false; 138 | bool list = false; 139 | bool projectRequested = false; 140 | QStringList filenamesIn; 141 | 142 | QStringList args = qCmdLineArgs(argc, argv); 143 | 144 | RCCResourceLibrary library; 145 | 146 | //parse options 147 | QString errorMsg; 148 | for (int i = 1; i < args.count() && errorMsg.isEmpty(); i++) { 149 | if (args[i].isEmpty()) 150 | continue; 151 | if (args[i][0] == QLatin1Char('-')) { // option 152 | QString opt = args[i]; 153 | if (opt == QLatin1String("-o")) { 154 | if (!(i < argc-1)) { 155 | errorMsg = QLatin1String("Missing output name"); 156 | break; 157 | } 158 | outFilename = args[++i]; 159 | } else if (opt == QLatin1String("-go")) { 160 | if (!(i < argc-1)) { 161 | errorMsg = QLatin1String("Missing go package name"); 162 | break; 163 | } 164 | library.setGoPkg(args[++i]); 165 | } else if (opt == QLatin1String("-name")) { 166 | if (!(i < argc-1)) { 167 | errorMsg = QLatin1String("Missing target name"); 168 | break; 169 | } 170 | library.setInitName(args[++i]); 171 | } else if (opt == QLatin1String("-root")) { 172 | if (!(i < argc-1)) { 173 | errorMsg = QLatin1String("Missing root path"); 174 | break; 175 | } 176 | library.setResourceRoot(QDir::cleanPath(args[++i])); 177 | if (library.resourceRoot().isEmpty() 178 | || library.resourceRoot().at(0) != QLatin1Char('/')) 179 | errorMsg = QLatin1String("Root must start with a /"); 180 | } else if (opt == QLatin1String("-compress")) { 181 | if (!(i < argc-1)) { 182 | errorMsg = QLatin1String("Missing compression level"); 183 | break; 184 | } 185 | library.setCompressLevel(args[++i].toInt()); 186 | } else if (opt == QLatin1String("-threshold")) { 187 | if (!(i < argc-1)) { 188 | errorMsg = QLatin1String("Missing compression threshold"); 189 | break; 190 | } 191 | library.setCompressThreshold(args[++i].toInt()); 192 | } else if (opt == QLatin1String("-binary")) { 193 | library.setFormat(RCCResourceLibrary::Binary); 194 | } else if (opt == QLatin1String("-namespace")) { 195 | library.setUseNameSpace(!library.useNameSpace()); 196 | } else if (opt == QLatin1String("-verbose")) { 197 | library.setVerbose(true); 198 | } else if (opt == QLatin1String("-list")) { 199 | list = true; 200 | } else if (opt == QLatin1String("-version") || opt == QLatin1String("-v")) { 201 | fprintf(stderr, "Qt Resource Compiler version %s\n", QT_VERSION_STR); 202 | return 1; 203 | } else if (opt == QLatin1String("-help") || opt == QLatin1String("-h")) { 204 | helpRequested = true; 205 | } else if (opt == QLatin1String("-no-compress")) { 206 | library.setCompressLevel(-2); 207 | } else if (opt == QLatin1String("-project")) { 208 | projectRequested = true; 209 | } else { 210 | errorMsg = QString::fromLatin1("Unknown option: '%1'").arg(args[i]); 211 | } 212 | } else { 213 | if (!QFile::exists(args[i])) { 214 | qWarning("%s: File does not exist '%s'", 215 | qPrintable(args[0]), qPrintable(args[i])); 216 | return 1; 217 | } 218 | filenamesIn.append(args[i]); 219 | } 220 | } 221 | 222 | if (projectRequested && !helpRequested) { 223 | return createProject(outFilename); 224 | } 225 | 226 | if (!filenamesIn.size() || !errorMsg.isEmpty() || helpRequested) { 227 | showHelp(args[0], errorMsg); 228 | return 1; 229 | } 230 | QFile errorDevice; 231 | errorDevice.open(stderr, QIODevice::WriteOnly|QIODevice::Text); 232 | 233 | if (library.verbose()) 234 | errorDevice.write("Qt resource compiler\n"); 235 | 236 | library.setInputFiles(filenamesIn); 237 | 238 | if (!library.readFiles(list, errorDevice)) 239 | return 1; 240 | 241 | // open output 242 | QFile out; 243 | QIODevice::OpenMode mode = QIODevice::WriteOnly; 244 | if (library.format() == RCCResourceLibrary::C_Code) 245 | mode |= QIODevice::Text; 246 | 247 | if (outFilename.isEmpty() || outFilename == QLatin1String("-")) { 248 | // using this overload close() only flushes. 249 | out.open(stdout, mode); 250 | } else { 251 | out.setFileName(outFilename); 252 | if (!out.open(mode)) { 253 | const QString msg = QString::fromUtf8("Unable to open %1 for writing: %2\n").arg(outFilename).arg(out.errorString()); 254 | errorDevice.write(msg.toUtf8()); 255 | return 1; 256 | } 257 | } 258 | 259 | // do the task 260 | if (list) { 261 | const QStringList data = library.dataFiles(); 262 | for (int i = 0; i < data.size(); ++i) { 263 | out.write(qPrintable(QDir::cleanPath(data.at(i)))); 264 | out.write("\n"); 265 | } 266 | return 0; 267 | } 268 | 269 | return library.output(out, errorDevice) ? 0 : 1; 270 | } 271 | 272 | QT_END_NAMESPACE 273 | 274 | int main(int argc, char *argv[]) 275 | { 276 | return QT_PREPEND_NAMESPACE(runRcc)(argc, argv); 277 | } 278 | -------------------------------------------------------------------------------- /tools/rcc/rcc.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the tools applications of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and Digia. For licensing terms and 14 | ** conditions see http://qt.digia.com/licensing. For further information 15 | ** use the contact form at http://qt.digia.com/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** In addition, as a special exception, Digia gives you certain additional 26 | ** rights. These rights are described in the Digia Qt LGPL Exception 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 | ** 29 | ** GNU General Public License Usage 30 | ** Alternatively, this file may be used under the terms of the GNU 31 | ** General Public License version 3.0 as published by the Free Software 32 | ** Foundation and appearing in the file LICENSE.GPL included in the 33 | ** packaging of this file. Please review the following information to 34 | ** ensure the GNU General Public License version 3.0 requirements will be 35 | ** met: http://www.gnu.org/copyleft/gpl.html. 36 | ** 37 | ** 38 | ** $QT_END_LICENSE$ 39 | ** 40 | ****************************************************************************/ 41 | 42 | #ifndef RCC_H 43 | #define RCC_H 44 | 45 | #include 46 | #include 47 | #include 48 | 49 | QT_BEGIN_NAMESPACE 50 | 51 | class RCCFileInfo; 52 | class QIODevice; 53 | class QTextStream; 54 | 55 | 56 | class RCCResourceLibrary 57 | { 58 | RCCResourceLibrary(const RCCResourceLibrary &); 59 | RCCResourceLibrary &operator=(const RCCResourceLibrary &); 60 | 61 | public: 62 | RCCResourceLibrary(); 63 | ~RCCResourceLibrary(); 64 | 65 | bool output(QIODevice &out, QIODevice &errorDevice); 66 | 67 | bool readFiles(bool ignoreErrors, QIODevice &errorDevice); 68 | 69 | enum Format { Binary, C_Code, Go_Code }; 70 | void setFormat(Format f) { m_format = f; } 71 | Format format() const { return m_format; } 72 | 73 | void setInputFiles(const QStringList &files) { m_fileNames = files; } 74 | QStringList inputFiles() const { return m_fileNames; } 75 | 76 | QStringList dataFiles() const; 77 | 78 | // Return a map of resource identifier (':/newPrefix/images/p1.png') to file. 79 | typedef QHash ResourceDataFileMap; 80 | ResourceDataFileMap resourceDataFileMap() const; 81 | 82 | void setVerbose(bool b) { m_verbose = b; } 83 | bool verbose() const { return m_verbose; } 84 | 85 | void setInitName(const QString &name) { m_initName = name; } 86 | QString initName() const { return m_initName; } 87 | 88 | void setCompressLevel(int c) { m_compressLevel = c; } 89 | int compressLevel() const { return m_compressLevel; } 90 | 91 | void setCompressThreshold(int t) { m_compressThreshold = t; } 92 | int compressThreshold() const { return m_compressThreshold; } 93 | 94 | void setResourceRoot(const QString &root) { m_resourceRoot = root; } 95 | QString resourceRoot() const { return m_resourceRoot; } 96 | 97 | void setUseNameSpace(bool v) { m_useNameSpace = v; } 98 | bool useNameSpace() const { return m_useNameSpace; } 99 | 100 | void setGoPkg(const QString &pkg) {m_format = Go_Code;m_goPkg = pkg;} 101 | 102 | QStringList failedResources() const { return m_failedResources; } 103 | 104 | private: 105 | struct Strings { 106 | Strings(); 107 | const QString TAG_RCC; 108 | const QString TAG_RESOURCE; 109 | const QString TAG_FILE; 110 | const QString ATTRIBUTE_LANG; 111 | const QString ATTRIBUTE_PREFIX; 112 | const QString ATTRIBUTE_ALIAS; 113 | const QString ATTRIBUTE_THRESHOLD; 114 | const QString ATTRIBUTE_COMPRESS; 115 | }; 116 | friend class RCCFileInfo; 117 | void reset(); 118 | bool addFile(const QString &alias, const RCCFileInfo &file); 119 | bool interpretResourceFile(QIODevice *inputDevice, const QString &file, 120 | QString currentPath = QString(), bool ignoreErrors = false); 121 | bool writeHeader(); 122 | bool writeDataBlobs(); 123 | bool writeDataNames(); 124 | bool writeDataStructure(); 125 | bool writeInitializer(); 126 | void writeMangleNamespaceFunction(const QByteArray &name); 127 | void writeAddNamespaceFunction(const QByteArray &name); 128 | void writeHex(quint8 number); 129 | void writeNumber2(quint16 number); 130 | void writeNumber4(quint32 number); 131 | void writeChar(char c) { m_out.append(c); } 132 | void writeByteArray(const QByteArray &); 133 | void write(const char *, int len); 134 | 135 | const Strings m_strings; 136 | RCCFileInfo *m_root; 137 | QStringList m_fileNames; 138 | QString m_resourceRoot; 139 | QString m_initName; 140 | Format m_format; 141 | QString m_goPkg; 142 | bool m_verbose; 143 | int m_compressLevel; 144 | int m_compressThreshold; 145 | int m_treeOffset; 146 | int m_namesOffset; 147 | int m_dataOffset; 148 | bool m_useNameSpace; 149 | QStringList m_failedResources; 150 | QIODevice *m_errorDevice; 151 | QByteArray m_out; 152 | }; 153 | 154 | QT_END_NAMESPACE 155 | 156 | #endif // RCC_H 157 | -------------------------------------------------------------------------------- /tools/rcc/rcc.pri: -------------------------------------------------------------------------------- 1 | INCLUDEPATH += $$PWD 2 | HEADERS += $$PWD/rcc.h 3 | SOURCES += $$PWD/rcc.cpp 4 | -------------------------------------------------------------------------------- /tools/rcc/rcc.pro: -------------------------------------------------------------------------------- 1 | CONFIG += console 2 | CONFIG -= app_bundle 3 | 4 | TEMPLATE = app 5 | TARGET = goqt_rcc 6 | 7 | QT += core xml 8 | QT -= gui 9 | 10 | DESTDIR = ../../bin 11 | DEFINES += QT_RCC 12 | INCLUDEPATH += . 13 | DEPENDPATH += . 14 | 15 | include(rcc.pri) 16 | #HEADERS += ../../corelib/kernel/qcorecmdlineargs_p.h 17 | SOURCES += main.cpp 18 | #include(../bootstrap/bootstrap.pri) 19 | 20 | #target.path=$$[QT_INSTALL_BINS] 21 | #INSTALLS += target 22 | #include(../../qt_targets.pri) 23 | -------------------------------------------------------------------------------- /ui/app.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 visualfc . All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ui 6 | 7 | import ( 8 | "log" 9 | "runtime" 10 | ) 11 | 12 | func init() { 13 | runtime.LockOSThread() 14 | } 15 | 16 | func mainLoop() int32 { 17 | for f := range mainfunc { 18 | return f() 19 | } 20 | return 0 21 | } 22 | 23 | var mainfunc = make(chan func() int32) 24 | 25 | func runInOsMainThread(f func() int32) { 26 | done := make(chan bool, 1) 27 | mainfunc <- func() int32 { 28 | res := f() 29 | done <- true 30 | return res 31 | } 32 | <-done 33 | } 34 | 35 | func Version() string { 36 | return "0.1.1" 37 | } 38 | 39 | func Async(fn func()) { 40 | tasks.Append(fn) 41 | _DirectQtDrv(nil, 1, 200, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) 42 | } 43 | 44 | func Run(fn func()) int32 { 45 | go runInOsMainThread(func() int32 { 46 | if qtdrv_init_error != nil { 47 | log.Println(qtdrv_init_error) 48 | return -2 49 | } 50 | app := NewApplication(nil) 51 | Async(func() { 52 | fn() 53 | }) 54 | return app.Exec() 55 | }) 56 | return mainLoop() 57 | } 58 | 59 | func RunEx(args []string, fn func()) int32 { 60 | go runInOsMainThread(func() int32 { 61 | if qtdrv_init_error != nil { 62 | log.Println(qtdrv_init_error) 63 | return -2 64 | } 65 | app := NewApplication(args) 66 | Async(func() { 67 | fn() 68 | }) 69 | return app.Exec() 70 | }) 71 | return mainLoop() 72 | } 73 | 74 | func Application() *QApplication { 75 | return QApplicationInstance() 76 | } 77 | -------------------------------------------------------------------------------- /ui/cdrv.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 visualfc . All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ui 6 | 7 | /* 8 | #include 9 | #include 10 | #include "cdrv_def.h" 11 | 12 | extern int qtdrv(void *p, int typeid,int funcid, void *p1,void *p2,void *p3,void *p4,void *p5, void *p6,void *p7,void *p8, void *p9, void *p10, void *p11, void *p12); 13 | static void init() 14 | { 15 | extern void utf8_to_string(void *string, void *str, int size); 16 | extern void array_to_slice(void *slice, void *array, int size); 17 | extern void append_utf8_to_slice(void *slice,void *str, int size); 18 | extern void append_bytes_to_slice(void *slice,void *bytes, int size); 19 | extern void append_object_to_slice(void *slice, void *obj, int id, int gc); 20 | extern void* string_slice_index(void *slice, int index); 21 | extern void* object_slice_index(void *slice, int index); 22 | extern void drv_signal_call(void *p,void *face,int id, void *p1,void *p2, void *p3, void *p4); 23 | extern void drv_remove_signal_call(void *p); 24 | extern void insert_string2object_map(void *p, char *data, int size,int id, int gc, void *obj); 25 | extern void copy_string2object_map(void *p, void *cp, void *cb); 26 | extern void insert_int2object_map(void *p, int key,int id, int gc, void *obj); 27 | extern void copy_int2object_map(void *p, void *cp, void *cb); 28 | extern void insert_object2object_map(void *p, int id1, int gc1,void *obj1, int id2, int gc2, void *obj2); 29 | extern void app_event_init(); 30 | extern int drv_event_filter(void *filter, void *face, void *obj, unsigned int evid, void *event); 31 | extern void drv_remove_event_filter(void *filter); 32 | extern void app_async_task(); 33 | extern void append_uint32_to_slice(void *p, unsigned int v); 34 | extern void append_double_to_slice(void *p, double v); 35 | qtdrv(&utf8_to_string,1,1,0,0,0,0,0,0,0,0,0,0,0,0); 36 | qtdrv(&array_to_slice,1,2,0,0,0,0,0,0,0,0,0,0,0,0); 37 | qtdrv(&append_utf8_to_slice,1,3,0,0,0,0,0,0,0,0,0,0,0,0); 38 | qtdrv(&append_bytes_to_slice,1,4,0,0,0,0,0,0,0,0,0,0,0,0); 39 | qtdrv(&append_object_to_slice,1,5,0,0,0,0,0,0,0,0,0,0,0,0); 40 | qtdrv(&string_slice_index,1,6,0,0,0,0,0,0,0,0,0,0,0,0); 41 | qtdrv(&object_slice_index,1,7,0,0,0,0,0,0,0,0,0,0,0,0); 42 | qtdrv(&drv_signal_call,1,8,0,0,0,0,0,0,0,0,0,0,0,0); 43 | qtdrv(&drv_remove_signal_call,1,9,0,0,0,0,0,0,0,0,0,0,0,0); 44 | qtdrv(&insert_string2object_map,1,10,0,0,0,0,0,0,0,0,0,0,0,0); 45 | qtdrv(©_string2object_map,1,11,0,0,0,0,0,0,0,0,0,0,0,0); 46 | qtdrv(&insert_int2object_map,1,12,0,0,0,0,0,0,0,0,0,0,0,0); 47 | qtdrv(©_int2object_map,1,13,0,0,0,0,0,0,0,0,0,0,0,0); 48 | qtdrv(&insert_object2object_map,1,14,0,0,0,0,0,0,0,0,0,0,0,0); 49 | qtdrv(&app_event_init,1,15,0,0,0,0,0,0,0,0,0,0,0,0); 50 | qtdrv(&drv_event_filter,1,16,0,0,0,0,0,0,0,0,0,0,0,0); 51 | qtdrv(&drv_remove_event_filter,1,17,0,0,0,0,0,0,0,0,0,0,0,0); 52 | qtdrv(&app_async_task,1,18,0,0,0,0,0,0,0,0,0,0,0,0); 53 | qtdrv(&append_uint32_to_slice,1,19,0,0,0,0,0,0,0,0,0,0,0,0); 54 | qtdrv(&append_double_to_slice,1,20,0,0,0,0,0,0,0,0,0,0,0,0); 55 | } 56 | #cgo linux LDFLAGS: -L${SRCDIR}/../bin -lqtdrv.ui 57 | #cgo darwin LDFLAGS: -L${SRCDIR}/../bin -lqtdrv.ui 58 | */ 59 | import "C" 60 | import ( 61 | "errors" 62 | "log" 63 | "reflect" 64 | "runtime" 65 | "sync" 66 | "unsafe" 67 | ) 68 | 69 | type Error int 70 | 71 | var ( 72 | ErrInvalid = errors.New("invalid argument") 73 | ErrDrvcall = errors.New("c function call fails") 74 | fnErrHandler func(error, int32, int32, int) = DefaultErrorHandler 75 | ) 76 | 77 | var ( 78 | qtdrv_init_error error 79 | ) 80 | 81 | func InitError() error { 82 | return qtdrv_init_error 83 | } 84 | 85 | func IsLoaded() bool { 86 | return qtdrv_init_error == nil 87 | } 88 | 89 | func (err Error) Error() string { 90 | switch err { 91 | case -1: 92 | return "undefined id" 93 | case -2: 94 | return "invalid argument" 95 | case -3: 96 | return "too many calls" 97 | } 98 | return "unknown error" 99 | } 100 | 101 | func cdrv_init() { 102 | C.init() 103 | } 104 | 105 | func DefaultErrorHandler(err error, typeid, funcid int32, call int) { 106 | pc1, _, _, ok1 := runtime.Caller(call) 107 | fn1 := runtime.FuncForPC(pc1) 108 | pc2, file, line, ok2 := runtime.Caller(call + 1) 109 | fn2 := runtime.FuncForPC(pc2) 110 | if ok1 && ok2 { 111 | log.Printf("err:%s, type:%d, func:%d; %s, %s , %s, %d \n", err, typeid, funcid, fn1.Name(), fn2.Name(), file, line) 112 | } else { 113 | log.Printf("err:%s, type:%d, func:%d\n", err, typeid, funcid) 114 | } 115 | } 116 | 117 | func PanicErrorHandler(err error, typeid, funcid int32, call int) { 118 | log.Panicf("err:%s, type:%d, func:%d\n", err, typeid, funcid) 119 | } 120 | 121 | func SetErrorHandler(fn func(error, int32, int32, int)) { 122 | if fn != nil { 123 | fnErrHandler = fn 124 | } 125 | } 126 | 127 | func DirectQtDrv(p unsafe.Pointer, typeid, funcid int32, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12 unsafe.Pointer) error { 128 | r := C.qtdrv(p, C.int(typeid), C.int(funcid), p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) 129 | if r != 0 { 130 | fnErrHandler(Error(r), typeid, funcid, 2) 131 | return Error(r) 132 | } 133 | return nil 134 | } 135 | 136 | func _DirectQtDrv(p unsafe.Pointer, typeid, funcid int32, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12 unsafe.Pointer) error { 137 | r := C.qtdrv(p, C.int(typeid), C.int(funcid), p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) 138 | if r != 0 { 139 | fnErrHandler(Error(r), typeid, funcid, 4) 140 | return Error(r) 141 | } 142 | return nil 143 | } 144 | 145 | type Driver interface { 146 | Drv(typeid, funcid int32, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12 unsafe.Pointer) error 147 | Delete() error 148 | Native() unsafe.Pointer 149 | SetDriverFrom(Driver) error 150 | IsValidDriver() bool 151 | QtDrv() _qt_drv 152 | } 153 | 154 | func Native(drv Driver) unsafe.Pointer { 155 | if drv == nil { 156 | return nil 157 | } 158 | return drv.Native() 159 | } 160 | 161 | //QPaintDevice 162 | type pd_head struct { 163 | native unsafe.Pointer 164 | isWidget int32 165 | } 166 | 167 | func new_pd_head(i QPaintDeviceInterface) *pd_head { 168 | _, isWidget := i.(QWidgetInterface) 169 | if isWidget { 170 | return &pd_head{Native(i), 1} 171 | } 172 | return &pd_head{Native(i), 0} 173 | } 174 | 175 | func Equal(a, b Driver) bool { 176 | return a.Native() == b.Native() 177 | } 178 | 179 | type BaseDrv struct { 180 | drv _qt_drv 181 | } 182 | 183 | func (b *BaseDrv) QtDrv() _qt_drv { 184 | return b.drv 185 | } 186 | 187 | func isNilDriver(v Driver) bool { 188 | return !reflect.ValueOf(v).IsNil() 189 | } 190 | 191 | func IsValidDriver(v Driver) bool { 192 | return isNilDriver(v) && v.IsValidDriver() 193 | } 194 | 195 | func (b *BaseDrv) SetDriverFrom(v Driver) error { 196 | if !IsValidDriver(v) { 197 | return ErrInvalid 198 | } 199 | b.drv = v.QtDrv() 200 | return nil 201 | } 202 | 203 | func (b *BaseDrv) IsValidDriver() bool { 204 | if b == nil { 205 | return false 206 | } 207 | return b.drv.IsValidDriver() 208 | } 209 | 210 | func (b *BaseDrv) Drv(typeid, funcid int32, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12 unsafe.Pointer) error { 211 | if b == nil { 212 | return ErrInvalid 213 | } 214 | return b.drv.Drv(typeid, funcid, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) 215 | } 216 | 217 | func (b *BaseDrv) Native() unsafe.Pointer { 218 | if b == nil { 219 | return nil 220 | } 221 | return unsafe.Pointer(b.drv.dd) 222 | } 223 | 224 | func (b *BaseDrv) SetDriver(dd uintptr, id int32, gc bool) { 225 | b.drv.dd = dd 226 | b.drv.id = id 227 | b.drv.gc = gc 228 | b.drv.SetAutoGC(gc) 229 | } 230 | 231 | func (b *BaseDrv) SetAutoGC(gc bool) { 232 | b.drv.SetAutoGC(gc) 233 | } 234 | 235 | func (b *BaseDrv) IsAutoGC() bool { 236 | return b.drv.IsAutoGC() 237 | } 238 | 239 | func (b *BaseDrv) Delete() error { 240 | if b == nil { 241 | return ErrInvalid 242 | } 243 | return b.drv.Delete() 244 | } 245 | 246 | type _qt_drv struct { 247 | dd uintptr 248 | id int32 249 | gc bool 250 | } 251 | 252 | func (d *_qt_drv) Native() unsafe.Pointer { 253 | if d == nil { 254 | return nil 255 | } 256 | return unsafe.Pointer(d.dd) 257 | } 258 | 259 | func (d *_qt_drv) IsValidDriver() bool { 260 | return d != nil && d.dd != 0 261 | } 262 | 263 | func (d *_qt_drv) SetAutoGC(b bool) { 264 | d.gc = b 265 | if d.gc { 266 | runtime.SetFinalizer(d, (*_qt_drv).Delete) 267 | } else { 268 | runtime.SetFinalizer(d, nil) 269 | } 270 | } 271 | 272 | func (d *_qt_drv) IsAutoGC() bool { 273 | return d.gc 274 | } 275 | 276 | func (d *_qt_drv) Drv(typeid, funcid int32, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12 unsafe.Pointer) error { 277 | if d == nil || d.dd == 0 { 278 | return ErrInvalid 279 | } 280 | return _DirectQtDrv(unsafe.Pointer(d.dd), typeid, funcid, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) 281 | } 282 | 283 | func (d *_qt_drv) Delete() error { 284 | if d == nil || d.dd == 0 { 285 | return ErrInvalid 286 | } 287 | err := _DirectQtDrv(unsafe.Pointer(d.dd), d.id, d.id+1, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) 288 | d.dd = 0 289 | if d.gc { 290 | runtime.SetFinalizer(d, nil) 291 | } 292 | return err 293 | } 294 | 295 | func UnsafePtrSize() int { 296 | return C.pvoid_size 297 | } 298 | 299 | func NewCWidgetArrayHead(sa []QWidgetInterface) *C.ptr_array_head { 300 | size := len(sa) 301 | if size == 0 { 302 | return &C.ptr_array_head{} 303 | } 304 | var p *C.pvoid 305 | p = (*C.pvoid)(C.malloc(C.size_t(size * C.pvoid_size))) 306 | objs := make([]unsafe.Pointer, size) 307 | for i := 0; i < size; i++ { 308 | objs[i] = Native(sa[i]) 309 | } 310 | C.memcpy(unsafe.Pointer(p), unsafe.Pointer(&objs[0]), C.size_t(size*C.pvoid_size)) 311 | v := &C.ptr_array_head{} 312 | v.data = p 313 | v.size = C.int(size) 314 | return v 315 | } 316 | 317 | func FreeCWidgetArrayHead(h *C.ptr_array_head) { 318 | if h.size == 0 { 319 | return 320 | } 321 | C.free(unsafe.Pointer(h.data)) 322 | } 323 | 324 | func NewCNoObjectArrayHead(sa []*QObject) *C.ptr_array_head { 325 | size := len(sa) 326 | if size == 0 { 327 | return &C.ptr_array_head{} 328 | } 329 | var p *C.pvoid 330 | p = (*C.pvoid)(C.malloc(C.size_t(size * C.pvoid_size))) 331 | objs := make([]unsafe.Pointer, size) 332 | for i := 0; i < size; i++ { 333 | objs[i] = Native(sa[i]) 334 | } 335 | C.memcpy(unsafe.Pointer(p), unsafe.Pointer(&objs[0]), C.size_t(size*C.pvoid_size)) 336 | v := &C.ptr_array_head{} 337 | v.data = p 338 | v.size = C.int(size) 339 | return v 340 | } 341 | 342 | func FreeCNoObjectArrayHead(h *C.ptr_array_head) { 343 | if h.size == 0 { 344 | return 345 | } 346 | C.free(unsafe.Pointer(h.data)) 347 | } 348 | 349 | func NewCObjectArrayHead(sa []*QObject) *C.ptr_array_head { 350 | size := len(sa) 351 | if size == 0 { 352 | return &C.ptr_array_head{} 353 | } 354 | var p *C.pvoid 355 | p = (*C.pvoid)(C.malloc(C.size_t(size * C.pvoid_size))) 356 | objs := make([]unsafe.Pointer, size) 357 | for i := 0; i < size; i++ { 358 | objs[i] = Native(sa[i]) 359 | } 360 | C.memcpy(unsafe.Pointer(p), unsafe.Pointer(&objs[0]), C.size_t(size*C.pvoid_size)) 361 | v := &C.ptr_array_head{} 362 | v.data = p 363 | v.size = C.int(size) 364 | return v 365 | } 366 | 367 | func FreeCObjectArrayHead(h *C.ptr_array_head) { 368 | if h.size == 0 { 369 | return 370 | } 371 | C.free(unsafe.Pointer(h.data)) 372 | } 373 | 374 | func NewCPtrArrayHead(sa []uintptr) *C.ptr_array_head { 375 | size := len(sa) 376 | if size == 0 { 377 | return &C.ptr_array_head{} 378 | } 379 | var p *C.pvoid 380 | p = (*C.pvoid)(C.malloc(C.size_t(size * C.pvoid_size))) 381 | C.memcpy(unsafe.Pointer(p), unsafe.Pointer(&sa[0]), C.size_t(size*C.pvoid_size)) 382 | v := &C.ptr_array_head{} 383 | v.data = p 384 | v.size = C.int(size) 385 | return v 386 | } 387 | 388 | func FreeCPtrArrayHead(h *C.ptr_array_head) { 389 | if h.size == 0 { 390 | return 391 | } 392 | C.free(unsafe.Pointer(h.data)) 393 | } 394 | 395 | func NewCIntArrayHead(sa []int32) *C.int_array_head { 396 | size := len(sa) 397 | if size == 0 { 398 | return &C.int_array_head{} 399 | } 400 | var p *C.int 401 | p = (*C.int)(C.malloc(C.size_t(size * 4))) 402 | C.memcpy(unsafe.Pointer(p), unsafe.Pointer(&sa[0]), C.size_t(size*4)) 403 | v := &C.int_array_head{} 404 | v.data = p 405 | v.size = C.int(size) 406 | return v 407 | } 408 | 409 | func FreeCIntArrayHead(h *C.int_array_head) { 410 | if h.size == 0 { 411 | return 412 | } 413 | C.free(unsafe.Pointer(h.data)) 414 | } 415 | 416 | func NewCUintArrayHead(sa []uint32) *C.uint_array_head { 417 | size := len(sa) 418 | if size == 0 { 419 | return &C.uint_array_head{} 420 | } 421 | var p *C.uint 422 | p = (*C.uint)(C.malloc(C.size_t(size * 4))) 423 | C.memcpy(unsafe.Pointer(p), unsafe.Pointer(&sa[0]), C.size_t(size*4)) 424 | v := &C.uint_array_head{} 425 | v.data = p 426 | v.size = C.int(size) 427 | return v 428 | } 429 | 430 | func FreeCUintArrayHead(h *C.uint_array_head) { 431 | if h.size == 0 { 432 | return 433 | } 434 | C.free(unsafe.Pointer(h.data)) 435 | } 436 | 437 | func NewCDoubleArrayHead(sa []float64) *C.double_array_head { 438 | size := len(sa) 439 | if size == 0 { 440 | return &C.double_array_head{} 441 | } 442 | var p *C.double 443 | p = (*C.double)(C.malloc(C.size_t(size * 8))) 444 | C.memcpy(unsafe.Pointer(p), unsafe.Pointer(&sa[0]), C.size_t(size*8)) 445 | v := &C.double_array_head{} 446 | v.data = p 447 | v.size = C.int(size) 448 | return v 449 | } 450 | 451 | func FreeCDoubleArrayHead(h *C.double_array_head) { 452 | if h.size == 0 { 453 | return 454 | } 455 | C.free(unsafe.Pointer(h.data)) 456 | } 457 | 458 | func NewCBoolArrayHead(sa []bool) *C.bool_array_head { 459 | size := len(sa) 460 | if size == 0 { 461 | return &C.bool_array_head{} 462 | } 463 | var p *C.bool 464 | p = (*C.bool)(C.malloc(C.size_t(size))) 465 | C.memcpy(unsafe.Pointer(p), unsafe.Pointer(&sa[0]), C.size_t(size)) 466 | v := &C.bool_array_head{} 467 | v.data = p 468 | v.size = C.int(size) 469 | return v 470 | } 471 | 472 | func FreeCBoolArrayHead(h *C.bool_array_head) { 473 | if h.size == 0 { 474 | return 475 | } 476 | C.free(unsafe.Pointer(h.data)) 477 | } 478 | 479 | func NewCByteArrayHead(sa []byte) *C.byte_array_head { 480 | size := len(sa) 481 | if size == 0 { 482 | return &C.byte_array_head{} 483 | } 484 | var p *C.char 485 | p = (*C.char)(C.malloc(C.size_t(size))) 486 | C.memcpy(unsafe.Pointer(p), unsafe.Pointer(&sa[0]), C.size_t(size)) 487 | v := &C.byte_array_head{} 488 | v.data = p 489 | v.size = C.int(size) 490 | return v 491 | } 492 | 493 | func FreeCByteArrayHead(h *C.byte_array_head) { 494 | if h.size == 0 { 495 | return 496 | } 497 | C.free(unsafe.Pointer(h.data)) 498 | } 499 | 500 | func NewCStringHead(s string) *C.string_head { 501 | v := &C.string_head{} 502 | v.data = C.CString(s) 503 | v.size = C.int(len(s)) 504 | return v 505 | } 506 | 507 | func FreeCStringHead(s *C.string_head) { 508 | C.free(unsafe.Pointer(s.data)) 509 | } 510 | 511 | func NewCBytesArray(sa [][]byte) ([]*C.char, int) { 512 | max := len(sa) 513 | csa := make([]*C.char, max+1) 514 | for i := 0; i < max; i++ { 515 | csa[i] = C.CString(string(sa[i])) 516 | } 517 | csa[max] = nil 518 | return csa, max 519 | } 520 | 521 | func NewCSArray(sa []string) ([]*C.char, int) { 522 | max := len(sa) 523 | csa := make([]*C.char, max+1) 524 | for i := 0; i < max; i++ { 525 | csa[i] = C.CString(sa[i]) 526 | } 527 | csa[max] = nil 528 | return csa, max 529 | } 530 | 531 | func FreeCSArray(csa []*C.char, max int) { 532 | for i := 0; i < max; i++ { 533 | if csa[i] != nil { 534 | C.free(unsafe.Pointer(csa[i])) 535 | } 536 | } 537 | } 538 | 539 | //func NewQtDriver(dd uintptr, id int32, gc bool) Driver { 540 | // d := &qtdrv{dd, id, gc} 541 | // if gc { 542 | // runtime.SetFinalizer(d, (*qtdrv).Delete) 543 | // } 544 | // return d 545 | //} 546 | 547 | //export utf8_to_string 548 | func utf8_to_string(dst unsafe.Pointer, src unsafe.Pointer, size int32) { 549 | *(*string)(dst) = C.GoStringN((*C.char)(src), C.int(size)) 550 | } 551 | 552 | //export array_to_slice 553 | func array_to_slice(dst, src unsafe.Pointer, size int32) { 554 | *(*[]byte)(dst) = C.GoBytes(src, C.int(size)) 555 | } 556 | 557 | //export append_utf8_to_slice 558 | func append_utf8_to_slice(dst unsafe.Pointer, src unsafe.Pointer, size int32) { 559 | *(*[]string)(dst) = append(*(*[]string)(dst), C.GoStringN((*C.char)(src), C.int(size))) 560 | } 561 | 562 | //export append_bytes_to_slice 563 | func append_bytes_to_slice(dst unsafe.Pointer, src unsafe.Pointer, size int32) { 564 | *(*[][]byte)(dst) = append(*(*[][]byte)(dst), C.GoBytes(src, C.int(size))) 565 | } 566 | 567 | //export append_object_to_slice 568 | func append_object_to_slice(dst unsafe.Pointer, src unsafe.Pointer, id C.int, gc int32) { 569 | obj := &QObject{} 570 | obj.SetDriver(uintptr(src), int32(id), gc != 0) 571 | *(*[]*QObject)(dst) = append(*(*[]*QObject)(dst), obj) 572 | } 573 | 574 | //export string_slice_index 575 | func string_slice_index(slice unsafe.Pointer, index C.int) unsafe.Pointer { 576 | return unsafe.Pointer(&(*(*[]string)(slice))[index]) 577 | } 578 | 579 | //export object_slice_index 580 | func object_slice_index(slice unsafe.Pointer, index C.int) unsafe.Pointer { 581 | return ((*(*[]*QObject)(slice))[index]).Native() 582 | } 583 | 584 | //export append_uint32_to_slice 585 | func append_uint32_to_slice(dst unsafe.Pointer, src C.uint) { 586 | *(*[]uint32)(dst) = append(*(*[]uint32)(dst), uint32(src)) 587 | } 588 | 589 | //export append_double_to_slice 590 | func append_double_to_slice(dst unsafe.Pointer, src C.double) { 591 | *(*[]float64)(dst) = append(*(*[]float64)(dst), float64(src)) 592 | } 593 | 594 | var ( 595 | signalMap = make(map[uintptr]interface{}) 596 | ) 597 | 598 | //export drv_signal_call 599 | func drv_signal_call(p unsafe.Pointer, face unsafe.Pointer, id int32, p1, p2, p3, p4 unsafe.Pointer) { 600 | //fn := (*(*Iface)(face)).Interface() 601 | if fn, ok := signalMap[uintptr(p)]; ok { 602 | drvSignalCall(fn, id, p1, p2, p3, p4) 603 | } 604 | } 605 | 606 | //export drv_remove_signal_call 607 | func drv_remove_signal_call(p unsafe.Pointer) { 608 | delete(signalMap, uintptr(p)) 609 | } 610 | 611 | //export insert_string2object_map 612 | func insert_string2object_map(p unsafe.Pointer, data *C.char, size C.int, id int32, gc int32, src unsafe.Pointer) { 613 | obj := &QObject{} 614 | obj.SetDriver(uintptr(src), id, gc != 0) 615 | (*(*map[string]*QObject)(p))[C.GoStringN(data, size)] = obj 616 | } 617 | 618 | //export copy_string2object_map 619 | func copy_string2object_map(p, cp, cb unsafe.Pointer) { 620 | for k, v := range *(*map[string]*QObject)(p) { 621 | drvInsertMapCb(cp, unsafe.Pointer(&k), v.Native(), cb) 622 | } 623 | } 624 | 625 | //export insert_int2object_map 626 | func insert_int2object_map(p unsafe.Pointer, key int32, id int32, gc int32, src unsafe.Pointer) { 627 | obj := &QObject{} 628 | obj.SetDriver(uintptr(src), id, gc != 0) 629 | (*(*map[int]*QObject)(p))[int(key)] = obj 630 | } 631 | 632 | //export copy_int2object_map 633 | func copy_int2object_map(p, cp, cb unsafe.Pointer) { 634 | for k, v := range *(*map[int]*QObject)(p) { 635 | drvInsertMapCb(cp, unsafe.Pointer(&k), v.Native(), cb) 636 | } 637 | } 638 | 639 | //export insert_object2object_map 640 | func insert_object2object_map(p unsafe.Pointer, id1, gc1 int32, src1 unsafe.Pointer, id2, gc2 int32, src2 unsafe.Pointer) { 641 | obj1 := &QObject{} 642 | obj1.SetDriver(uintptr(src1), id1, gc1 != 0) 643 | obj2 := &QObject{} 644 | obj2.SetDriver(uintptr(src2), id2, gc2 != 0) 645 | (*(*map[*QObject]*QObject)(p))[obj1] = obj2 646 | } 647 | 648 | func defEventInit() { 649 | log.Println("def_event_init") 650 | } 651 | 652 | var fnEventInit func() 653 | 654 | func OnEventInit(fn func()) { 655 | fnEventInit = fn 656 | log.Println("setup init", fnEventInit) 657 | } 658 | 659 | //export app_event_init 660 | func app_event_init() { 661 | log.Println("app_event_init") 662 | if fnEventInit != nil { 663 | go fnEventInit() 664 | } 665 | } 666 | 667 | //string,T => QMap 668 | func drvInsertMapCb(cp, k, v, cb unsafe.Pointer) { 669 | C.qtdrv(cp, 1, 104, k, v, cb, nil, nil, nil, nil, nil, nil, nil, nil, nil) 670 | } 671 | 672 | //QString => string 673 | func drvGetString(p unsafe.Pointer, cp unsafe.Pointer) error { 674 | C.qtdrv(p, 1, 100, cp, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) 675 | return nil 676 | } 677 | 678 | //QStringList => []string 679 | func drvGetStringArray(p unsafe.Pointer, cp unsafe.Pointer) error { 680 | C.qtdrv(p, 1, 101, cp, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) 681 | return nil 682 | } 683 | 684 | //QList => []*QRectF 685 | func drvGetRectFArray(p unsafe.Pointer, cp unsafe.Pointer, id uint32) error { 686 | C.qtdrv(p, 1, 102, cp, unsafe.Pointer(&id), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) 687 | return nil 688 | } 689 | 690 | //QList => []*QModelIndex 691 | func drvGetModelIndexArray(p unsafe.Pointer, cp unsafe.Pointer, id uint32) error { 692 | C.qtdrv(p, 1, 103, cp, unsafe.Pointer(&id), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) 693 | return nil 694 | } 695 | 696 | func drvBytesArrayToC(src [][]byte) []*byte { 697 | dst := make([]*byte, len(src)+1) 698 | for n, v := range src { 699 | cv := make([]byte, len(v)+1) 700 | copy(cv, v) 701 | dst[n] = &cv[0] 702 | } 703 | return dst 704 | } 705 | 706 | func drvStringArrayToC(src []string) []*byte { 707 | dst := make([]*byte, len(src)+1) 708 | for n, v := range src { 709 | cv := make([]byte, len(v)+1) 710 | copy(cv, []byte(v)) 711 | dst[n] = &cv[0] 712 | } 713 | return dst 714 | } 715 | 716 | type QRgb uint32 717 | 718 | type Iface struct { 719 | tab uintptr 720 | data uintptr 721 | } 722 | 723 | func NewIface(i interface{}) Iface { 724 | return *(*Iface)(unsafe.Pointer(&i)) 725 | } 726 | 727 | func drvNewIfaceRef(i interface{}) *Iface { 728 | return (*Iface)(unsafe.Pointer(&i)) 729 | } 730 | 731 | func (face Iface) Interface() interface{} { 732 | var i interface{} 733 | *(*Iface)(unsafe.Pointer(&i)) = face 734 | return i 735 | } 736 | 737 | //export drv_event_filter 738 | func drv_event_filter(filter unsafe.Pointer, face unsafe.Pointer, obj unsafe.Pointer, evid uint32, event unsafe.Pointer) C.int { 739 | // i := ((*Iface)(face)).Interface() 740 | // if drvEventCall(i, drvNewObject(uintptr(obj)), evid, uintptr(event)) { 741 | // return 1 742 | // } 743 | 744 | if i, ok := eventMap[uintptr(filter)]; ok { 745 | if drvEventCall(i, drvNewObject(uintptr(obj)), evid, uintptr(event)) { 746 | return 1 747 | } 748 | } 749 | return 0 750 | } 751 | 752 | //export drv_remove_event_filter 753 | func drv_remove_event_filter(filter unsafe.Pointer) { 754 | delete(eventMap, uintptr(filter)) 755 | } 756 | 757 | var ( 758 | eventMap = make(map[uintptr]interface{}) 759 | ) 760 | 761 | func drvInstallEventFilter(obj QObjectInterface, filter interface{}) uintptr { 762 | if filter == nil { 763 | return 0 764 | } 765 | var __rv uintptr 766 | DirectQtDrv(Native(obj), 1, 105, nil, unsafe.Pointer(&__rv), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) 767 | if __rv != 0 { 768 | eventMap[__rv] = filter 769 | } 770 | return __rv 771 | } 772 | 773 | type TaskList struct { 774 | task []func() 775 | mutex sync.Mutex 776 | } 777 | 778 | func (l *TaskList) Append(fn func()) { 779 | l.mutex.Lock() 780 | l.task = append(l.task, fn) 781 | l.mutex.Unlock() 782 | } 783 | 784 | func (l *TaskList) Run() { 785 | l.mutex.Lock() 786 | for _, fn := range l.task { 787 | fn() 788 | } 789 | l.task = make([]func(), 0) 790 | l.mutex.Unlock() 791 | } 792 | 793 | var ( 794 | tasks TaskList 795 | ) 796 | 797 | //export app_async_task 798 | func app_async_task() { 799 | tasks.Run() 800 | } 801 | 802 | func QtVersion() string { 803 | var __rv string 804 | _DirectQtDrv(nil, 1, 106, unsafe.Pointer(&__rv), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) 805 | return __rv 806 | } 807 | -------------------------------------------------------------------------------- /ui/cdrv_def.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 visualfc . All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #ifndef _CDRV_DEF_H_ 6 | #define _CDRV_DEF_H_ 7 | 8 | #include 9 | 10 | typedef struct { 11 | const char *data; 12 | int size; 13 | } __attribute__ ((packed)) string_head; 14 | 15 | typedef struct { 16 | const char *data; 17 | int size; 18 | } __attribute__ ((packed)) byte_array_head; 19 | 20 | typedef struct { 21 | const bool *data; 22 | int size; 23 | } __attribute__ ((packed)) bool_array_head; 24 | 25 | typedef struct { 26 | const int *data; 27 | int size; 28 | } __attribute__ ((packed)) int_array_head; 29 | 30 | typedef struct { 31 | const unsigned int *data; 32 | int size; 33 | } __attribute__ ((packed)) uint_array_head; 34 | 35 | typedef void* pvoid; 36 | 37 | typedef struct { 38 | const pvoid *data; 39 | int size; 40 | } __attribute__ ((packed)) ptr_array_head; 41 | 42 | typedef struct { 43 | double *data; 44 | int size; 45 | } __attribute__ ((packed)) double_array_head; 46 | 47 | #define pvoid_size sizeof(pvoid) 48 | 49 | #endif //_CDRV_DEF_H_ 50 | -------------------------------------------------------------------------------- /ui/cdrv_init.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | // Copyright 2015-2016 visualfc . All rights reserved. 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file. 6 | 7 | package ui 8 | 9 | func init() { 10 | cdrv_init() 11 | } 12 | -------------------------------------------------------------------------------- /ui/cdrv_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 visualfc . All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ui 6 | 7 | import ( 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | import "C" 13 | 14 | var ( 15 | proc_qtdrv_addr uintptr = 0 16 | ) 17 | 18 | //export qtdrv 19 | func qtdrv(p unsafe.Pointer, typeid, funcid C.int, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12 unsafe.Pointer) C.int { 20 | r0, _, _ := syscall.Syscall15(proc_qtdrv_addr, 15, uintptr(p), uintptr(typeid), uintptr(funcid), uintptr(p1), uintptr(p2), uintptr(p3), uintptr(p4), uintptr(p5), uintptr(p6), uintptr(p7), uintptr(p8), uintptr(p9), uintptr(p10), uintptr(p11), uintptr(p12)) 21 | return C.int(r0) 22 | } 23 | 24 | func load_qtdrv_proc() (uintptr, error) { 25 | lib, err := syscall.LoadDLL("qtdrv.ui.dll") 26 | if err != nil { 27 | return 0, err 28 | } 29 | proc, err := lib.FindProc("qtdrv") 30 | if err != nil { 31 | return 0, err 32 | } 33 | return proc.Addr(), nil 34 | } 35 | 36 | func init() { 37 | proc_qtdrv_addr, qtdrv_init_error = load_qtdrv_proc() 38 | if qtdrv_init_error != nil { 39 | return 40 | } 41 | cdrv_init() 42 | } 43 | -------------------------------------------------------------------------------- /ui/qt_interface.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 visualfc . All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ui 6 | 7 | type QLayoutInterface interface { 8 | QObjectInterface 9 | Activate() bool 10 | AddItem(*QLayoutItem) 11 | AddWidget(QWidgetInterface) 12 | ContentsMargins() *QMargins 13 | ContentsRect() *QRect 14 | Count() int32 15 | GetContentsMargins(*int32, *int32, *int32, *int32) 16 | IndexOf(QWidgetInterface) int32 17 | IsEnabled() bool 18 | ItemAt(int32) *QLayoutItem 19 | Margin() int32 20 | MenuBar() *QWidget 21 | ParentWidget() *QWidget 22 | RemoveItem(*QLayoutItem) 23 | RemoveWidget(QWidgetInterface) 24 | SetAlignment(Qt_AlignmentFlag) 25 | SetAlignmentWithLayoutAlignment(QLayoutInterface, Qt_AlignmentFlag) bool 26 | SetAlignmentWithWidgetAlignment(QWidgetInterface, Qt_AlignmentFlag) bool 27 | SetContentsMargins(*QMargins) 28 | SetContentsMarginsWithLeftTopRightBottom(int32, int32, int32, int32) 29 | SetEnabled(bool) 30 | SetMargin(int32) 31 | SetMenuBar(QWidgetInterface) 32 | SetSizeConstraint(QLayout_SizeConstraint) 33 | SetSpacing(int32) 34 | SizeConstraint() QLayout_SizeConstraint 35 | Spacing() int32 36 | TakeAt(int32) *QLayoutItem 37 | TotalHeightForWidth(int32) int32 38 | TotalMaximumSize() *QSize 39 | TotalMinimumSize() *QSize 40 | TotalSizeHint() *QSize 41 | Update() 42 | } 43 | 44 | type QWidgetInterface interface { 45 | QObjectInterface 46 | AcceptDrops() bool 47 | AccessibleDescription() string 48 | AccessibleName() string 49 | Actions() []*QAction 50 | ActivateWindow() 51 | AddAction(*QAction) 52 | AddActions([]*QAction) 53 | AdjustSize() 54 | AutoFillBackground() bool 55 | BackgroundRole() QPalette_ColorRole 56 | BaseSize() *QSize 57 | ChildAt(*QPoint) *QWidget 58 | ChildAtWithXY(int32, int32) *QWidget 59 | ChildrenRect() *QRect 60 | ChildrenRegion() *QRegion 61 | ClearFocus() 62 | ClearMask() 63 | Close() bool 64 | ColorCount() int32 65 | ContentsMargins() *QMargins 66 | ContentsRect() *QRect 67 | ContextMenuPolicy() Qt_ContextMenuPolicy 68 | CreateWinId() 69 | Cursor() *QCursor 70 | Depth() int32 71 | DevType() int32 72 | EnsurePolished() 73 | FocusPolicy() Qt_FocusPolicy 74 | FocusProxy() *QWidget 75 | FocusWidget() *QWidget 76 | Font() *QFont 77 | FontInfo() *QFontInfo 78 | FontMetrics() *QFontMetrics 79 | ForegroundRole() QPalette_ColorRole 80 | FrameGeometry() *QRect 81 | FrameSize() *QSize 82 | Geometry() *QRect 83 | GetContentsMargins(*int32, *int32, *int32, *int32) 84 | GrabGesture(Qt_GestureType) 85 | GrabGestureWithTypeFlags(Qt_GestureType, Qt_GestureFlag) 86 | GrabKeyboard() 87 | GrabMouse() 88 | GrabMouseWithCursor(*QCursor) 89 | GrabShortcut(*QKeySequence) int32 90 | GrabShortcutWithKeyContext(*QKeySequence, Qt_ShortcutContext) int32 91 | GraphicsEffect() *QGraphicsEffect 92 | GraphicsProxyWidget() *QGraphicsProxyWidget 93 | HasFocus() bool 94 | HasMouseTracking() bool 95 | Height() int32 96 | HeightForWidth(int32) int32 97 | HeightMM() int32 98 | Hide() 99 | InputMethodHints() Qt_InputMethodHint 100 | InputMethodQuery(Qt_InputMethodQuery) *QVariant 101 | InsertAction(*QAction, *QAction) 102 | InsertActions(*QAction, []*QAction) 103 | IsActiveWindow() bool 104 | IsAncestorOf(QWidgetInterface) bool 105 | IsEnabled() bool 106 | IsEnabledTo(QWidgetInterface) bool 107 | IsEnabledToTLW() bool 108 | IsFullScreen() bool 109 | IsHidden() bool 110 | IsLeftToRight() bool 111 | IsMaximized() bool 112 | IsMinimized() bool 113 | IsModal() bool 114 | IsRightToLeft() bool 115 | IsTopLevel() bool 116 | IsVisible() bool 117 | IsVisibleTo(QWidgetInterface) bool 118 | IsWindow() bool 119 | IsWindowModified() bool 120 | Layout() *QLayout 121 | LayoutDirection() Qt_LayoutDirection 122 | Locale() *QLocale 123 | LogicalDpiX() int32 124 | LogicalDpiY() int32 125 | Lower() 126 | MapFrom(QWidgetInterface, *QPoint) *QPoint 127 | MapFromGlobal(*QPoint) *QPoint 128 | MapFromParent(*QPoint) *QPoint 129 | MapTo(QWidgetInterface, *QPoint) *QPoint 130 | MapToGlobal(*QPoint) *QPoint 131 | MapToParent(*QPoint) *QPoint 132 | Mask() *QRegion 133 | MaximumHeight() int32 134 | MaximumSize() *QSize 135 | MaximumWidth() int32 136 | MinimumHeight() int32 137 | MinimumSize() *QSize 138 | MinimumSizeHint() *QSize 139 | MinimumWidth() int32 140 | Move(*QPoint) 141 | MoveWithXY(int32, int32) 142 | NativeParentWidget() *QWidget 143 | NextInFocusChain() *QWidget 144 | NormalGeometry() *QRect 145 | OverrideWindowFlags(Qt_WindowType) 146 | OverrideWindowState(Qt_WindowState) 147 | PaintEngine() *QPaintEngine 148 | PaintingActive() bool 149 | Palette() *QPalette 150 | ParentWidget() *QWidget 151 | PhysicalDpiX() int32 152 | PhysicalDpiY() int32 153 | Pos() *QPoint 154 | PreviousInFocusChain() *QWidget 155 | Raise() 156 | Rect() *QRect 157 | ReleaseKeyboard() 158 | ReleaseMouse() 159 | ReleaseShortcut(int32) 160 | RemoveAction(*QAction) 161 | Render(QPaintDeviceInterface) 162 | RenderWithPaintDeviceTargetoffsetSourceregionRenderflags(QPaintDeviceInterface, *QPoint, *QRegion, QWidget_RenderFlag) 163 | RenderWithPainter(*QPainter) 164 | RenderWithPainterTargetoffsetSourceregionRenderflags(*QPainter, *QPoint, *QRegion, QWidget_RenderFlag) 165 | Repaint() 166 | RepaintWithRect(*QRect) 167 | RepaintWithRegion(*QRegion) 168 | RepaintWithXYWidthHeight(int32, int32, int32, int32) 169 | Resize(*QSize) 170 | ResizeWithWidthHeight(int32, int32) 171 | RestoreGeometry([]byte) bool 172 | SaveGeometry() []byte 173 | ScrollWithDxDy(int32, int32) 174 | ScrollWithDxDyRect(int32, int32, *QRect) 175 | SetAcceptDrops(bool) 176 | SetAccessibleDescription(string) 177 | SetAccessibleName(string) 178 | SetAttribute(Qt_WidgetAttribute) 179 | SetAttributeWithWidgetattributeOn(Qt_WidgetAttribute, bool) 180 | SetAutoFillBackground(bool) 181 | SetBackgroundRole(QPalette_ColorRole) 182 | SetBaseSize(*QSize) 183 | SetBaseSizeWithBasewBaseh(int32, int32) 184 | SetContentsMargins(*QMargins) 185 | SetContentsMarginsWithLeftTopRightBottom(int32, int32, int32, int32) 186 | SetContextMenuPolicy(Qt_ContextMenuPolicy) 187 | SetCursor(*QCursor) 188 | SetDisabled(bool) 189 | SetEnabled(bool) 190 | SetFixedHeight(int32) 191 | SetFixedSize(*QSize) 192 | SetFixedSizeWithWidthHeight(int32, int32) 193 | SetFixedWidth(int32) 194 | SetFocus() 195 | SetFocusPolicy(Qt_FocusPolicy) 196 | SetFocusProxy(QWidgetInterface) 197 | SetFocusWithReason(Qt_FocusReason) 198 | SetFont(*QFont) 199 | SetForegroundRole(QPalette_ColorRole) 200 | SetGeometry(*QRect) 201 | SetGeometryWithXYWidthHeight(int32, int32, int32, int32) 202 | SetGraphicsEffect(*QGraphicsEffect) 203 | SetHidden(bool) 204 | SetInputMethodHints(Qt_InputMethodHint) 205 | SetLayout(QLayoutInterface) 206 | SetLayoutDirection(Qt_LayoutDirection) 207 | SetLocale(*QLocale) 208 | SetMask(*QBitmap) 209 | SetMaskWithRegion(*QRegion) 210 | SetMaximumHeight(int32) 211 | SetMaximumSize(*QSize) 212 | SetMaximumSizeWithMaxwMaxh(int32, int32) 213 | SetMaximumWidth(int32) 214 | SetMinimumHeight(int32) 215 | SetMinimumSize(*QSize) 216 | SetMinimumSizeWithMinwMinh(int32, int32) 217 | SetMinimumWidth(int32) 218 | SetMouseTracking(bool) 219 | SetPalette(*QPalette) 220 | SetParentWidget(QWidgetInterface) 221 | SetParentWidgetWithParentFlags(QWidgetInterface, Qt_WindowType) 222 | SetShortcutAutoRepeat(int32) 223 | SetShortcutAutoRepeatWithIdEnable(int32, bool) 224 | SetShortcutEnabled(int32) 225 | SetShortcutEnabledWithIdEnable(int32, bool) 226 | SetSizeIncrement(*QSize) 227 | SetSizeIncrementWithWidthHeight(int32, int32) 228 | SetSizePolicy(*QSizePolicy) 229 | SetSizePolicyWithHorizontalVertical(QSizePolicy_Policy, QSizePolicy_Policy) 230 | SetStatusTip(string) 231 | SetStyle(*QStyle) 232 | SetStyleSheet(string) 233 | SetToolTip(string) 234 | SetUpdatesEnabled(bool) 235 | SetVisible(bool) 236 | SetWhatsThis(string) 237 | SetWindowFilePath(string) 238 | SetWindowFlags(Qt_WindowType) 239 | SetWindowIcon(*QIcon) 240 | SetWindowIconText(string) 241 | SetWindowModality(Qt_WindowModality) 242 | SetWindowModified(bool) 243 | SetWindowOpacity(float64) 244 | SetWindowRole(string) 245 | SetWindowState(Qt_WindowState) 246 | SetWindowTitle(string) 247 | Show() 248 | ShowFullScreen() 249 | ShowMaximized() 250 | ShowMinimized() 251 | ShowNormal() 252 | Size() *QSize 253 | SizeHint() *QSize 254 | SizeIncrement() *QSize 255 | SizePolicy() *QSizePolicy 256 | StackUnder(QWidgetInterface) 257 | StatusTip() string 258 | Style() *QStyle 259 | StyleSheet() string 260 | TestAttribute(Qt_WidgetAttribute) bool 261 | ToolTip() string 262 | TopLevelWidget() *QWidget 263 | UnderMouse() bool 264 | UngrabGesture(Qt_GestureType) 265 | UnsetCursor() 266 | UnsetLayoutDirection() 267 | UnsetLocale() 268 | Update() 269 | UpdateGeometry() 270 | UpdateWithRect(*QRect) 271 | UpdateWithRegion(*QRegion) 272 | UpdateWithXYWidthHeight(int32, int32, int32, int32) 273 | UpdatesEnabled() bool 274 | VisibleRegion() *QRegion 275 | WhatsThis() string 276 | Width() int32 277 | WidthMM() int32 278 | Window() *QWidget 279 | WindowFilePath() string 280 | WindowFlags() Qt_WindowType 281 | WindowIcon() *QIcon 282 | WindowIconText() string 283 | WindowModality() Qt_WindowModality 284 | WindowOpacity() float64 285 | WindowRole() string 286 | WindowState() Qt_WindowState 287 | WindowTitle() string 288 | WindowType() Qt_WindowType 289 | X() int32 290 | Y() int32 291 | } 292 | 293 | type QObjectInterface interface { 294 | Driver 295 | BlockSignals(bool) bool 296 | Children() []*QObject 297 | DeleteLater() 298 | DynamicPropertyNames() [][]byte 299 | Event(*QEvent) bool 300 | FindChild(string) *QObject 301 | FindChildren(string) []*QObject 302 | FindChildrenWithRegexp(*QRegExp) []*QObject 303 | Inherits(string) bool 304 | IsWidgetType() bool 305 | KillTimer(int32) 306 | MetaObject() *QMetaObject 307 | ObjectName() string 308 | Parent() *QObject 309 | Property(string) *QVariant 310 | SetObjectName(string) 311 | SetParent(QObjectInterface) 312 | SetProperty(string, *QVariant) bool 313 | SignalsBlocked() bool 314 | StartTimer(int32) int32 315 | Tr(string) string 316 | TrWithSourcetextDisambiguation(string, string) string 317 | } 318 | 319 | type QIODeviceInterface interface { 320 | QObjectInterface 321 | AtEnd() bool 322 | BytesAvailable() int64 323 | BytesToWrite() int64 324 | CanReadLine() bool 325 | Close() 326 | ErrorString() string 327 | GetChar(*byte) bool 328 | IsOpen() bool 329 | IsReadable() bool 330 | IsSequential() bool 331 | IsTextModeEnabled() bool 332 | IsWritable() bool 333 | Open(QIODevice_OpenModeFlag) bool 334 | OpenMode() QIODevice_OpenModeFlag 335 | Peek(int64) []byte 336 | PeekWithDataMaxlen(*byte, int64) int64 337 | Pos() int64 338 | PutChar(byte) bool 339 | Read(int64) []byte 340 | ReadAll() []byte 341 | ReadLine() []byte 342 | ReadLineWithDataMaxlen(*byte, int64) int64 343 | ReadLineWithMaxlen(int64) []byte 344 | ReadWithDataMaxlen(*byte, int64) int64 345 | Reset() bool 346 | Seek(int64) bool 347 | SetTextModeEnabled(bool) 348 | Size() int64 349 | UngetChar(byte) 350 | WaitForBytesWritten(int32) bool 351 | WaitForReadyRead(int32) bool 352 | Write([]byte) int64 353 | WriteWithDataLen(*byte, int64) int64 354 | } 355 | 356 | type QPaintDeviceInterface interface { 357 | Driver 358 | ColorCount() int32 359 | Depth() int32 360 | DevType() int32 361 | Height() int32 362 | HeightMM() int32 363 | LogicalDpiX() int32 364 | LogicalDpiY() int32 365 | PaintEngine() *QPaintEngine 366 | PaintingActive() bool 367 | PhysicalDpiX() int32 368 | PhysicalDpiY() int32 369 | Width() int32 370 | WidthMM() int32 371 | } 372 | 373 | type QAbstractItemModelInterface interface { 374 | QObjectInterface 375 | Buddy(*QModelIndex) *QModelIndex 376 | CanFetchMore(*QModelIndex) bool 377 | ColumnCount() int32 378 | ColumnCountWithParent(*QModelIndex) int32 379 | Data(*QModelIndex) *QVariant 380 | DataWithIndexRole(*QModelIndex, int32) *QVariant 381 | DropMimeData(*QMimeData, Qt_DropAction, int32, int32, *QModelIndex) bool 382 | FetchMore(*QModelIndex) 383 | Flags(*QModelIndex) Qt_ItemFlag 384 | HasChildren() bool 385 | HasChildrenWithParent(*QModelIndex) bool 386 | HasIndex(int32, int32, *QModelIndex) bool 387 | HeaderData(int32, Qt_Orientation, int32) *QVariant 388 | Index(int32, int32, *QModelIndex) *QModelIndex 389 | InsertColumn(int32) bool 390 | InsertColumnWithColumnParent(int32, *QModelIndex) bool 391 | InsertColumns(int32, int32, *QModelIndex) bool 392 | InsertRow(int32) bool 393 | InsertRowWithRowParent(int32, *QModelIndex) bool 394 | InsertRows(int32, int32, *QModelIndex) bool 395 | ItemData(*QModelIndex) map[int32]*QVariant 396 | Match(*QModelIndex, int32, *QVariant, int32, Qt_MatchFlag) []*QModelIndex 397 | MimeData([]*QModelIndex) *QMimeData 398 | MimeTypes() []string 399 | RemoveColumn(int32) bool 400 | RemoveColumnWithColumnParent(int32, *QModelIndex) bool 401 | RemoveColumns(int32, int32, *QModelIndex) bool 402 | RemoveRow(int32) bool 403 | RemoveRowWithRowParent(int32, *QModelIndex) bool 404 | RemoveRows(int32, int32, *QModelIndex) bool 405 | Revert() 406 | RowCount() int32 407 | RowCountWithParent(*QModelIndex) int32 408 | SetData(*QModelIndex, *QVariant, int32) bool 409 | SetHeaderData(int32, Qt_Orientation, *QVariant, int32) bool 410 | SetItemData(*QModelIndex, map[int32]*QVariant) bool 411 | Sibling(int32, int32, *QModelIndex) *QModelIndex 412 | Sort(int32) 413 | SortWithColumnOrder(int32, Qt_SortOrder) 414 | Span(*QModelIndex) *QSize 415 | Submit() bool 416 | SupportedDragActions() Qt_DropAction 417 | SupportedDropActions() Qt_DropAction 418 | } 419 | -------------------------------------------------------------------------------- /ui/qt_signal.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 visualfc . All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ui 6 | 7 | import ( 8 | "unsafe" 9 | ) 10 | 11 | func drvSignalCall(fn interface{}, id int32, v1, v2, v3, v4 unsafe.Pointer) error { 12 | switch id { 13 | case 1: 14 | fn.(func())() 15 | case 2: 16 | _v1 := &QAbstractAnimation{} 17 | _v1.SetDriver(uintptr(v1), 194000, false) 18 | fn.(func(*QAbstractAnimation))(_v1) 19 | case 3: 20 | fn.(func(QAbstractAnimation_Direction))(*(*QAbstractAnimation_Direction)(v1)) 21 | case 4: 22 | fn.(func(QAbstractAnimation_State, QAbstractAnimation_State))(*(*QAbstractAnimation_State)(v1), *(*QAbstractAnimation_State)(v2)) 23 | case 5: 24 | _v1 := &QAbstractButton{} 25 | _v1.SetDriver(uintptr(v1), 195000, false) 26 | fn.(func(*QAbstractButton))(_v1) 27 | case 6: 28 | _v1 := &QAction{} 29 | _v1.SetDriver(uintptr(v1), 209000, false) 30 | fn.(func(*QAction))(_v1) 31 | case 7: 32 | _v1 := &QBrush{} 33 | _v1.SetDriver(uintptr(v1), 9000, false) 34 | fn.(func(*QBrush))(_v1) 35 | case 8: 36 | fn.(func(QClipboard_Mode))(*(*QClipboard_Mode)(v1)) 37 | case 9: 38 | _v1 := &QColor{} 39 | _v1.SetDriver(uintptr(v1), 13000, false) 40 | fn.(func(*QColor))(_v1) 41 | case 10: 42 | _v1 := &QDate{} 43 | _v1.SetDriver(uintptr(v1), 19000, false) 44 | fn.(func(*QDate))(_v1) 45 | case 11: 46 | _v1 := &QDateTime{} 47 | _v1.SetDriver(uintptr(v1), 20000, false) 48 | fn.(func(*QDateTime))(_v1) 49 | case 12: 50 | fn.(func(QDockWidget_DockWidgetFeature))(*(*QDockWidget_DockWidgetFeature)(v1)) 51 | case 13: 52 | fn.(func(QGraphicsBlurEffect_BlurHint))(*(*QGraphicsBlurEffect_BlurHint)(v1)) 53 | case 14: 54 | fn.(func(Qt_DockWidgetArea))(*(*Qt_DockWidgetArea)(v1)) 55 | case 15: 56 | fn.(func(Qt_ToolBarArea))(*(*Qt_ToolBarArea)(v1)) 57 | case 16: 58 | fn.(func(Qt_WindowState, Qt_WindowState))(*(*Qt_WindowState)(v1), *(*Qt_WindowState)(v2)) 59 | case 17: 60 | _v1 := &QFont{} 61 | _v1.SetDriver(uintptr(v1), 37000, false) 62 | fn.(func(*QFont))(_v1) 63 | case 18: 64 | fn.(func(QImageReader_ImageReaderError))(*(*QImageReader_ImageReaderError)(v1)) 65 | case 19: 66 | _v1 := &QItemSelection{} 67 | _v1.SetDriver(uintptr(v1), 63000, false) 68 | _v2 := &QItemSelection{} 69 | _v2.SetDriver(uintptr(v2), 63000, false) 70 | fn.(func(*QItemSelection, *QItemSelection))(_v1, _v2) 71 | case 20: 72 | var _v1 []*QModelIndex 73 | drvGetModelIndexArray(unsafe.Pointer(&_v1), v1, 80000) 74 | fn.(func([]*QModelIndex))(_v1) 75 | case 21: 76 | var _v1 []*QRectF 77 | drvGetRectFArray(unsafe.Pointer(&_v1), v1, 112000) 78 | fn.(func([]*QRectF))(_v1) 79 | case 22: 80 | _v1 := &QListWidgetItem{} 81 | _v1.SetDriver(uintptr(v1), 72000, false) 82 | fn.(func(*QListWidgetItem))(_v1) 83 | case 23: 84 | _v1 := &QListWidgetItem{} 85 | _v1.SetDriver(uintptr(v1), 72000, false) 86 | _v2 := &QListWidgetItem{} 87 | _v2.SetDriver(uintptr(v2), 72000, false) 88 | fn.(func(*QListWidgetItem, *QListWidgetItem))(_v1, _v2) 89 | case 24: 90 | _v1 := &QMdiSubWindow{} 91 | _v1.SetDriver(uintptr(v1), 309000, false) 92 | fn.(func(*QMdiSubWindow))(_v1) 93 | case 25: 94 | _v1 := &QModelIndex{} 95 | _v1.SetDriver(uintptr(v1), 80000, false) 96 | fn.(func(*QModelIndex))(_v1) 97 | case 26: 98 | _v1 := &QModelIndex{} 99 | _v1.SetDriver(uintptr(v1), 80000, false) 100 | _v2 := &QModelIndex{} 101 | _v2.SetDriver(uintptr(v2), 80000, false) 102 | fn.(func(*QModelIndex, *QModelIndex))(_v1, _v2) 103 | case 27: 104 | fn.(func(QMovie_MovieState))(*(*QMovie_MovieState)(v1)) 105 | case 28: 106 | _v1 := &QObject{} 107 | _v1.SetDriver(uintptr(v1), 316000, false) 108 | fn.(func(*QObject))(_v1) 109 | case 29: 110 | _v1 := &QPoint{} 111 | _v1.SetDriver(uintptr(v1), 100000, false) 112 | fn.(func(*QPoint))(_v1) 113 | case 30: 114 | _v1 := &QPointF{} 115 | _v1.SetDriver(uintptr(v1), 101000, false) 116 | fn.(func(*QPointF))(_v1) 117 | case 31: 118 | _v1 := &QPrinter{} 119 | _v1.SetDriver(uintptr(v1), 105000, false) 120 | fn.(func(*QPrinter))(_v1) 121 | case 32: 122 | fn.(func(QProcess_ProcessError))(*(*QProcess_ProcessError)(v1)) 123 | case 33: 124 | fn.(func(QProcess_ProcessState))(*(*QProcess_ProcessState)(v1)) 125 | case 34: 126 | _v1 := &QRect{} 127 | _v1.SetDriver(uintptr(v1), 111000, false) 128 | fn.(func(*QRect))(_v1) 129 | case 35: 130 | _v1 := &QRect{} 131 | _v1.SetDriver(uintptr(v1), 111000, false) 132 | fn.(func(*QRect, int32))(_v1, *(*int32)(v2)) 133 | case 36: 134 | _v1 := &QRectF{} 135 | _v1.SetDriver(uintptr(v1), 112000, false) 136 | fn.(func(*QRectF))(_v1) 137 | case 37: 138 | _v1 := &QSessionManager{} 139 | _v1.SetDriver(uintptr(v1), 340000, false) 140 | fn.(func(*QSessionManager))(_v1) 141 | case 38: 142 | _v1 := &QSize{} 143 | _v1.SetDriver(uintptr(v1), 120000, false) 144 | fn.(func(*QSize))(_v1) 145 | case 39: 146 | _v1 := &QSizeF{} 147 | _v1.SetDriver(uintptr(v1), 121000, false) 148 | fn.(func(*QSizeF))(_v1) 149 | case 40: 150 | _v1 := &QStandardItem{} 151 | _v1.SetDriver(uintptr(v1), 124000, false) 152 | fn.(func(*QStandardItem))(_v1) 153 | case 41: 154 | var _v1 string 155 | drvGetString(unsafe.Pointer(&_v1), v1) 156 | fn.(func(string))(_v1) 157 | case 42: 158 | var _v1 string 159 | drvGetString(unsafe.Pointer(&_v1), v1) 160 | var _v2 string 161 | drvGetString(unsafe.Pointer(&_v2), v2) 162 | var _v3 string 163 | drvGetString(unsafe.Pointer(&_v3), v3) 164 | fn.(func(string, string, string))(_v1, _v2, _v3) 165 | case 43: 166 | var _v1 []string 167 | drvGetStringArray(unsafe.Pointer(&_v1), v1) 168 | fn.(func([]string))(_v1) 169 | case 44: 170 | fn.(func(QSystemTrayIcon_ActivationReason))(*(*QSystemTrayIcon_ActivationReason)(v1)) 171 | case 45: 172 | _v1 := &QTableWidgetItem{} 173 | _v1.SetDriver(uintptr(v1), 136000, false) 174 | fn.(func(*QTableWidgetItem))(_v1) 175 | case 46: 176 | _v1 := &QTableWidgetItem{} 177 | _v1.SetDriver(uintptr(v1), 136000, false) 178 | _v2 := &QTableWidgetItem{} 179 | _v2.SetDriver(uintptr(v2), 136000, false) 180 | fn.(func(*QTableWidgetItem, *QTableWidgetItem))(_v1, _v2) 181 | case 47: 182 | _v1 := &QTextBlock{} 183 | _v1.SetDriver(uintptr(v1), 139000, false) 184 | fn.(func(*QTextBlock))(_v1) 185 | case 48: 186 | _v1 := &QTextCharFormat{} 187 | _v1.SetDriver(uintptr(v1), 144000, false) 188 | fn.(func(*QTextCharFormat))(_v1) 189 | case 49: 190 | _v1 := &QTextCursor{} 191 | _v1.SetDriver(uintptr(v1), 147000, false) 192 | fn.(func(*QTextCursor))(_v1) 193 | case 50: 194 | _v1 := &QTime{} 195 | _v1.SetDriver(uintptr(v1), 172000, false) 196 | fn.(func(*QTime))(_v1) 197 | case 51: 198 | fn.(func(QTimeLine_State))(*(*QTimeLine_State)(v1)) 199 | case 52: 200 | _v1 := &QTreeWidgetItem{} 201 | _v1.SetDriver(uintptr(v1), 179000, false) 202 | fn.(func(*QTreeWidgetItem))(_v1) 203 | case 53: 204 | _v1 := &QTreeWidgetItem{} 205 | _v1.SetDriver(uintptr(v1), 179000, false) 206 | _v2 := &QTreeWidgetItem{} 207 | _v2.SetDriver(uintptr(v2), 179000, false) 208 | fn.(func(*QTreeWidgetItem, *QTreeWidgetItem))(_v1, _v2) 209 | case 54: 210 | _v1 := &QTreeWidgetItem{} 211 | _v1.SetDriver(uintptr(v1), 179000, false) 212 | fn.(func(*QTreeWidgetItem, int32))(_v1, *(*int32)(v2)) 213 | case 55: 214 | _v1 := &QUndoStack{} 215 | _v1.SetDriver(uintptr(v1), 391000, false) 216 | fn.(func(*QUndoStack))(_v1) 217 | case 56: 218 | _v1 := &QUrl{} 219 | _v1.SetDriver(uintptr(v1), 182000, false) 220 | fn.(func(*QUrl))(_v1) 221 | case 57: 222 | _v1 := &QVariant{} 223 | _v1.SetDriver(uintptr(v1), 184000, false) 224 | fn.(func(*QVariant))(_v1) 225 | case 58: 226 | _v1 := &QWidget{} 227 | _v1.SetDriver(uintptr(v1), 397000, false) 228 | fn.(func(*QWidget))(_v1) 229 | case 59: 230 | _v1 := &QWidget{} 231 | _v1.SetDriver(uintptr(v1), 397000, false) 232 | fn.(func(*QWidget, QAbstractItemDelegate_EndEditHint))(_v1, *(*QAbstractItemDelegate_EndEditHint)(v2)) 233 | case 60: 234 | _v1 := &QWidget{} 235 | _v1.SetDriver(uintptr(v1), 397000, false) 236 | _v2 := &QWidget{} 237 | _v2.SetDriver(uintptr(v2), 397000, false) 238 | fn.(func(*QWidget, *QWidget))(_v1, _v2) 239 | case 61: 240 | fn.(func(Qt_DockWidgetArea))(*(*Qt_DockWidgetArea)(v1)) 241 | case 62: 242 | fn.(func(Qt_DropAction))(*(*Qt_DropAction)(v1)) 243 | case 63: 244 | fn.(func(Qt_Orientation))(*(*Qt_Orientation)(v1)) 245 | case 64: 246 | fn.(func(Qt_Orientation, int32, int32))(*(*Qt_Orientation)(v1), *(*int32)(v2), *(*int32)(v3)) 247 | case 65: 248 | fn.(func(Qt_ToolButtonStyle))(*(*Qt_ToolButtonStyle)(v1)) 249 | case 66: 250 | fn.(func(bool))(*(*bool)(v1)) 251 | case 67: 252 | fn.(func(float64))(*(*float64)(v1)) 253 | case 68: 254 | fn.(func(int32))(*(*int32)(v1)) 255 | case 69: 256 | fn.(func(int32, QHeaderView_ResizeMode))(*(*int32)(v1), *(*QHeaderView_ResizeMode)(v2)) 257 | case 70: 258 | fn.(func(int32, QProcess_ExitStatus))(*(*int32)(v1), *(*QProcess_ExitStatus)(v2)) 259 | case 71: 260 | fn.(func(int32, Qt_SortOrder))(*(*int32)(v1), *(*Qt_SortOrder)(v2)) 261 | case 72: 262 | fn.(func(int32, int32))(*(*int32)(v1), *(*int32)(v2)) 263 | case 73: 264 | fn.(func(int32, int32, int32))(*(*int32)(v1), *(*int32)(v2), *(*int32)(v3)) 265 | case 74: 266 | fn.(func(int32, int32, int32, int32))(*(*int32)(v1), *(*int32)(v2), *(*int32)(v3), *(*int32)(v4)) 267 | case 75: 268 | fn.(func(int64))(*(*int64)(v1)) 269 | default: 270 | return ErrInvalid 271 | } 272 | return nil 273 | } 274 | --------------------------------------------------------------------------------