first commit
This commit is contained in:
parent
7ec16b63b9
commit
70ca5d727d
8
CMakeLists.txt
Normal file
8
CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
|
||||||
|
project(CMQT)
|
||||||
|
|
||||||
|
include(path_config.cmake)
|
||||||
|
CMQTSetup(${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
|
add_subdirectory(${CMQT_ROOT_SOURCE_PATH})
|
10
inc/hgl/QT.h
Normal file
10
inc/hgl/QT.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef HGL_QT_INCLUDE
|
||||||
|
#define HGL_QT_INCLUDE
|
||||||
|
|
||||||
|
#include<hgl/type/QTString.h>
|
||||||
|
#include<QObject>
|
||||||
|
|
||||||
|
#define QTConnect(obj,event,class_pointer,slot_func) QObject::connect(obj,SIGNAL(event()),class_pointer,SLOT(slot_func()))
|
||||||
|
|
||||||
|
#endif//HGL_QT_INCLUDE
|
||||||
|
|
28
inc/hgl/platform/QT5.h
Normal file
28
inc/hgl/platform/QT5.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#ifndef HGL_QT5_MAIN_INCLUDE
|
||||||
|
#define HGL_QT5_MAIN_INCLUDE
|
||||||
|
|
||||||
|
#include<hgl/platform/QT5Application.h>
|
||||||
|
#include<hgl/platform/ConsoleSystemInitInfo.h>
|
||||||
|
|
||||||
|
#define HGL_QT_MAIN(sii_name,app_name,arg_name) extern "C" int QT5AppMain(hgl::ConsoleSystemInitInfo &sii_name,hgl::QT5GuiApplication &app_name,const hgl::StringList<hgl::OSString> &arg_name)
|
||||||
|
|
||||||
|
#define QTConnect(obj,event,class_pointer,slot_func) connect(obj,SIGNAL(event()),class_pointer,SLOT(slot_func()))
|
||||||
|
|
||||||
|
#define HGL_QT_MAIN_FUNC() HGL_QT_MAIN(sii,app,args)
|
||||||
|
|
||||||
|
#define HGL_QT_APPLICATION(name,code,start) using namespace hgl; \
|
||||||
|
\
|
||||||
|
HGL_QT_MAIN_FUNC()\
|
||||||
|
{ \
|
||||||
|
sii.info.ProjectName=name; \
|
||||||
|
sii.info.ProjectCode=code; \
|
||||||
|
\
|
||||||
|
if(!app.Init(&sii)) \
|
||||||
|
return(-1); \
|
||||||
|
\
|
||||||
|
app.SetStart(start); \
|
||||||
|
\
|
||||||
|
return app.Run(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif//HGL_QT5_MAIN_INCLUDE
|
33
inc/hgl/platform/QT5Application.h
Normal file
33
inc/hgl/platform/QT5Application.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#ifndef HGL_QT5_APPLICATION_INCLUDE
|
||||||
|
#define HGL_QT5_APPLICATION_INCLUDE
|
||||||
|
|
||||||
|
#include<hgl/QT.h>
|
||||||
|
|
||||||
|
class QApplication;
|
||||||
|
#include<hgl/platform/ConsoleApplication.h>
|
||||||
|
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
class QT5GuiApplication:public ConsoleApplication
|
||||||
|
{
|
||||||
|
QApplication *qt_app;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
QT5GuiApplication(QApplication *);
|
||||||
|
~QT5GuiApplication();
|
||||||
|
|
||||||
|
int exec();
|
||||||
|
};//class QT5GuiApplication
|
||||||
|
}//namespace hgl
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 控制台程序总入口函数
|
||||||
|
* @param sii 系统初始化信息类,需由开发者补充填写一定的信息
|
||||||
|
* @param app 应用程序整体控制管理类
|
||||||
|
* @param args 由命令行或其它程序传来的参数列表
|
||||||
|
* @return 返回值,将会回传给操作系统
|
||||||
|
*/
|
||||||
|
extern "C" int QT5AppMain(hgl::ConsoleSystemInitInfo &sii,hgl::QT5GuiApplication &app,const hgl::StringList<hgl::OSString> &args);
|
||||||
|
|
||||||
|
#endif//HGL_QT5_APPLICATION_INCLUDE
|
73
inc/hgl/type/QTString.h
Normal file
73
inc/hgl/type/QTString.h
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
#ifndef HGL_QT_STRING_INCLUDE
|
||||||
|
#define HGL_QT_STRING_INCLUDE
|
||||||
|
|
||||||
|
#include<hgl/type/String.h>
|
||||||
|
#include<hgl/CodePage.h>
|
||||||
|
#include<QString>
|
||||||
|
|
||||||
|
#if HGL_OS == HGL_OS_Windows
|
||||||
|
inline QString ToQString(const hgl::WideString &ws)
|
||||||
|
{
|
||||||
|
return QString::fromWCharArray(ws.c_str(),ws.Length());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline QString ToQString(const wchar_t *str,int size){return QString::fromWCharArray(str,size);}
|
||||||
|
|
||||||
|
inline hgl::UTF8String ToUTF8String(const QString &str)
|
||||||
|
{
|
||||||
|
QByteArray u8str=str.toUtf8();
|
||||||
|
|
||||||
|
return hgl::UTF8String((hgl::u8char *)u8str.data(),u8str.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline hgl::WideString ToOSString(const QString &str)
|
||||||
|
{
|
||||||
|
return hgl::WideString((wchar_t *)str.utf16(),str.length());
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
template<int WS> QString WCharToQString(const wchar_t *,int);
|
||||||
|
|
||||||
|
template<> inline QString WCharToQString<2>(const wchar_t *str,int size){return QString::fromUtf16((ushort *)str,size);}
|
||||||
|
template<> inline QString WCharToQString<4>(const wchar_t *str,int size){return QString::fromUcs4((uint *)str,size);}
|
||||||
|
|
||||||
|
inline QString ToQString(const wchar_t *str,int size)
|
||||||
|
{
|
||||||
|
return WCharToQString<sizeof(wchar_t)>(str,size);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline QString ToQString(const u16char *str,int size){return QString::fromUtf16((ushort *)str,size);}
|
||||||
|
inline QString ToQString(const char32_t *str,int size){return QString::fromUcs4((uint *)str,size);}
|
||||||
|
|
||||||
|
inline QString ToQString(const hgl::UTF16String &str)
|
||||||
|
{
|
||||||
|
return QString::fromUtf16((ushort *)str.c_str(), str.Length());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline hgl::UTF8String ToUTF8String(const QString &str)
|
||||||
|
{
|
||||||
|
QByteArray u8str=str.toUtf8();
|
||||||
|
|
||||||
|
return hgl::UTF8String(u8str.data(),u8str.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline hgl::UTF8String ToOSString(const QString &str)
|
||||||
|
{
|
||||||
|
return ToUTF8String(str);
|
||||||
|
}
|
||||||
|
#endif//HGL_OS == HGL_OS_Windows
|
||||||
|
|
||||||
|
inline QString ToQString(const hgl::UTF8String &str)
|
||||||
|
{
|
||||||
|
return QString::fromUtf8((char *)str.c_str(),str.Length());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline hgl::UTF16String ToUTF16String(const QString &str)
|
||||||
|
{
|
||||||
|
return hgl::UTF16String((u16char *)str.utf16(),str.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
// inline QString toQString(const hgl::UTF32String &str)
|
||||||
|
// {
|
||||||
|
// return QString::fromUcs4((uint *)str.c_str(),str.Length());
|
||||||
|
// }
|
||||||
|
#endif//HGL_QT_STRING_INCLUDE
|
9
path_config.cmake
Normal file
9
path_config.cmake
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
macro(CMQTSetup CMQT_ROOT_PATH)
|
||||||
|
|
||||||
|
message("CMQT_ROOT_PATH: " ${CMQT_ROOT_PATH})
|
||||||
|
|
||||||
|
set(CMQT_ROOT_INCLUDE_PATH ${CMQT_ROOT_PATH}/inc)
|
||||||
|
set(CMQT_ROOT_SOURCE_PATH ${CMQT_ROOT_PATH}/src)
|
||||||
|
|
||||||
|
include_directories(${CMQT_ROOT_INCLUDE_PATH})
|
||||||
|
endmacro()
|
17
src/CMakeLists.txt
Normal file
17
src/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Gui Widgets)
|
||||||
|
|
||||||
|
SET(CMQT_INCLUDE_PATH ${CMQT_ROOT_INCLUDE_PATH}/hgl/qt)
|
||||||
|
|
||||||
|
SET(CMQT_WIDGET_INCLUDE_PATH ${CMQT_INCLUDE_PATH}/widget)
|
||||||
|
SET(CMQT_DIALOG_INCLUDE_PATH ${CMQT_INCLUDE_PATH}/dialog)
|
||||||
|
|
||||||
|
IF(WIN32)
|
||||||
|
set(CMQT_MAIN_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/QT5WinUCS2.cpp)
|
||||||
|
ELSEIF()
|
||||||
|
set(CMQT_MAIN_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/QT5UnixUTF8.cpp)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_cm_library(CMQT "CM" QT5GuiApplication.cpp)
|
||||||
|
|
||||||
|
SET(CMQT_LIBRARIES CMQT Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||||
|
|
18
src/QT5GuiApplication.cpp
Normal file
18
src/QT5GuiApplication.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include<hgl/platform/QT5Application.h>
|
||||||
|
#include<QApplication>
|
||||||
|
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
QT5GuiApplication::QT5GuiApplication(QApplication *qa):qt_app(qa)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QT5GuiApplication::~QT5GuiApplication()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int QT5GuiApplication::exec()
|
||||||
|
{
|
||||||
|
return qt_app->exec();
|
||||||
|
}
|
||||||
|
}//namespace hgl
|
20
src/QT5UnixUTF8.cpp
Normal file
20
src/QT5UnixUTF8.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include<hgl/Console.h>
|
||||||
|
#include<hgl/platform/QT5Application.h>
|
||||||
|
#include<QApplication>
|
||||||
|
|
||||||
|
using namespace hgl;
|
||||||
|
|
||||||
|
int main(int argc,char **argv)
|
||||||
|
{
|
||||||
|
QApplication qt_app(argc,argv);
|
||||||
|
|
||||||
|
StringList<UTF8String> sl;
|
||||||
|
|
||||||
|
for(int i=0;i<argc;i++)
|
||||||
|
sl.Add(argv[i]);
|
||||||
|
|
||||||
|
ConsoleSystemInitInfo sii;
|
||||||
|
QT5GuiApplication app(&qt_app);
|
||||||
|
|
||||||
|
return QT5AppMain(sii,app,sl);
|
||||||
|
}
|
34
src/QT5WinUCS2.cpp
Normal file
34
src/QT5WinUCS2.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include<hgl/Console.h>
|
||||||
|
#include<windows.h>
|
||||||
|
#include<hgl/platform/QT5Application.h>
|
||||||
|
#include<QApplication>
|
||||||
|
|
||||||
|
extern "C" int WINAPI wWinMain(HINSTANCE,HINSTANCE,wchar_t *cmd_line,int)
|
||||||
|
{
|
||||||
|
wchar_t **w_argv;
|
||||||
|
char **argv;
|
||||||
|
int argc;
|
||||||
|
|
||||||
|
w_argv = CommandLineToArgvW(cmd_line, &argc);
|
||||||
|
|
||||||
|
hgl::StringList<hgl::UTF16String> sl;
|
||||||
|
hgl::StringList<hgl::UTF8String> sl8;
|
||||||
|
|
||||||
|
argv = new char *[argc];
|
||||||
|
|
||||||
|
for (int i = 0; i < argc; i++)
|
||||||
|
{
|
||||||
|
sl.Add(w_argv[i]);
|
||||||
|
sl8.Add(hgl::to_u8(w_argv[i]));
|
||||||
|
|
||||||
|
argv[i] = sl8[i].c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
QApplication qt_app(argc,argv);
|
||||||
|
|
||||||
|
hgl::ConsoleSystemInitInfo sii;
|
||||||
|
hgl::QT5GuiApplication app(&qt_app);
|
||||||
|
|
||||||
|
delete[] argv;
|
||||||
|
return QT5AppMain(sii, app, sl);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user