From 1206fcebbddd346acda5719d0fb21d52fa8bf2a3 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Fri, 10 Jul 2020 10:59:07 -0400 Subject: [PATCH] Successful build of QT gui using cmake instead of qmake. --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 75 ++++++++++++++++--------------- src/drivers/Qt/ConsoleWindow.cpp | 77 ++++++++++++++++++++++++++++++++ src/drivers/Qt/ConsoleWindow.h | 2 + 4 files changed, 119 insertions(+), 37 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cbc07cf..fe75fad4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.1) project(fceux) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c1a07e18..d7c4f21c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,8 @@ +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + if(WIN32) set(SOURCES ${SRC_CORE} ${SRC_DRIVERS_COMMON} ${SRC_DRIVERS_WIN}) include_directories( ${CMAKE_SOURCE_DIR}/src/drivers/win/directx ${CMAKE_SOURCE_DIR}/src/drivers/win/zlib ) @@ -15,28 +19,13 @@ else(WIN32) # Non Windows System # Use the package PkgConfig to detect headers/library files find_package(PkgConfig REQUIRED) + find_package(Qt5 COMPONENTS Widgets OpenGL REQUIRED) - # Check for GTK+3 - pkg_check_modules(GTK3 REQUIRED gtk+-3.0) + add_definitions( ${Qt5Widgets_DEFINITIONS} ) + include_directories( ${Qt5Widgets_INCLUDE_DIRS} ) - if ( ${GTK3_FOUND} ) - add_definitions( -D_GTK ${GTK3_CFLAGS} ) - endif() + add_definitions( -D__QT_DRIVER__ -Wall -Wno-write-strings -Wno-sign-compare -Wno-parentheses -Wno-unused-local-typedefs -fPIC -DQT_DEPRECATED_WARNINGS ) - # Check for X11 - pkg_check_modules( X11 x11 ) - - if ( ${X11_FOUND} ) - add_definitions( ${X11_CFLAGS} ) - endif() - - # Check for OpenGL - pkg_check_modules( GL REQUIRED gl) - - if ( ${GL_FOUND} ) - add_definitions( -DOPENGL ${GL_CFLAGS} ) - endif() - # Check for libminizip pkg_check_modules( MINIZIP REQUIRED minizip) @@ -44,6 +33,13 @@ else(WIN32) add_definitions( -D_SYSTEM_MINIZIP ${MINIZIP_CFLAGS} ) endif() + pkg_check_modules( GL REQUIRED gl) + + # Check for OpenGL + if ( ${GL_FOUND} ) + add_definitions( ${GL_CFLAGS} ) + endif() + pkg_check_modules( ZLIB REQUIRED zlib) # Check for zlib @@ -72,6 +68,9 @@ else(WIN32) endif(WIN32) +include_directories( ${CMAKE_SOURCE_DIR}/src ) +include_directories( ${CMAKE_SOURCE_DIR}/src/drivers ) + if(APPLE) add_definitions( -DPSS_STYLE=4 ) else(APPLE) @@ -323,20 +322,24 @@ set(SRC_DRIVERS_COMMON ) set(SRC_DRIVERS_SDL - ${CMAKE_CURRENT_SOURCE_DIR}/drivers/sdl/config.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drivers/sdl/input.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drivers/sdl/gui.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drivers/sdl/cheat.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drivers/sdl/debugger.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drivers/sdl/memview.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drivers/sdl/ramwatch.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drivers/sdl/sdl.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drivers/sdl/sdl-joystick.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drivers/sdl/sdl-sound.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drivers/sdl/sdl-throttle.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drivers/sdl/sdl-video.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drivers/sdl/glxwin.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drivers/sdl/unix-netplay.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/main.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleWindow.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleViewerGL.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleViewerSDL.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/GamePadConf.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/HotKeyConf.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleVideoConf.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleSoundConf.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/fceuWrapper.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/config.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/input.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/nes_shm.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/keyscan.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/sdl-sound.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/sdl-video.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/sdl-joystick.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/sdl-throttle.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/unix-netplay.cpp ) set(SOURCES ${SRC_CORE} ${SRC_DRIVERS_COMMON} ${SRC_DRIVERS_SDL}) @@ -344,9 +347,9 @@ set(SOURCES ${SRC_CORE} ${SRC_DRIVERS_COMMON} ${SRC_DRIVERS_SDL}) add_executable( fceux ${SOURCES} ) target_link_libraries( fceux - ${GTK3_LDFLAGS} - ${X11_LDFLAGS} - ${GL_LDFLAGS} + ${Qt5Widgets_LIBRARIES} + ${Qt5OpenGL_LIBRARIES} + ${GL_LDFLAGS} ${SDL2_LDFLAGS} ${MINIZIP_LDFLAGS} ${ZLIB_LDFLAGS} ${LUA_LDFLAGS} diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 487e6b31..38626b02 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -3,6 +3,11 @@ #include #include "../../fceu.h" + +#ifdef _S9XLUA_H +#include "../../fceulua.h" +#endif + #include "Qt/main.h" #include "Qt/dface.h" #include "Qt/input.h" @@ -202,6 +207,20 @@ void consoleWin_t::createMainMenu(void) fileMenu->addSeparator(); +#ifdef _S9XLUA_H + // File -> Quick Save + loadLuaAct = new QAction(tr("Load Lua Script"), this); + //loadLuaAct->setShortcut( QKeySequence(tr("F5"))); + loadLuaAct->setStatusTip(tr("Load Lua Script")); + connect(loadLuaAct, SIGNAL(triggered()), this, SLOT(loadLua(void)) ); + + fileMenu->addAction(loadLuaAct); + + fileMenu->addSeparator(); +#else + loadLuaAct = NULL; +#endif + // File -> Quit quitAct = new QAction(tr("Quit"), this); quitAct->setShortcut( QKeySequence(tr("Ctrl+Q"))); @@ -582,6 +601,64 @@ void consoleWin_t::changeState9(void) fceuWrapperUnLock(); } +void consoleWin_t::loadLua(void) +{ +#ifdef _S9XLUA_H + int ret; + QString filename; + std::string last; + QFileDialog dialog(this, tr("Open LUA Script") ); + + dialog.setFileMode(QFileDialog::ExistingFile); + + dialog.setNameFilter(tr("LUA Scripts (*.lua)(*.LUA) ;; All files (*)")); + + dialog.setViewMode(QFileDialog::List); + + g_config->getOption ("SDL.LastLoadLua", &last ); + + if ( last.size() == 0 ) + { + last.assign( "/usr/share/fceux/luaScripts" ); + } + + dialog.setDirectory( tr(last.c_str()) ); + + // the gnome default file dialog is not playing nice with QT. + // TODO make this a config option to use native file dialog. + dialog.setOption(QFileDialog::DontUseNativeDialog, true); + + dialog.show(); + ret = dialog.exec(); + + if ( ret ) + { + QStringList fileList; + fileList = dialog.selectedFiles(); + + if ( fileList.size() > 0 ) + { + filename = fileList[0]; + } + } + + if ( filename.isNull() ) + { + return; + } + qDebug() << "selected file path : " << filename.toUtf8(); + + g_config->setOption ("SDL.LastLoadLua", filename.toStdString().c_str() ); + + fceuWrapperLock(); + if ( FCEU_LoadLuaCode( filename.toStdString().c_str() ) ) + { + printf("Error: Could not open the selected lua script: '%s'\n", filename.toStdString().c_str() ); + } + fceuWrapperUnLock(); +#endif +} + void consoleWin_t::openGamePadConfWin(void) { if ( gamePadConfWin != NULL ) diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index 16612467..b1e5b60a 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -58,6 +58,7 @@ class consoleWin_t : public QMainWindow QAction *saveStateAct; QAction *quickLoadAct; QAction *quickSaveAct; + QAction *loadLuaAct; QAction *quitAct; QAction *gamePadConfig; QAction *gameSoundConfig; @@ -108,6 +109,7 @@ class consoleWin_t : public QMainWindow void changeState7(void); void changeState8(void); void changeState9(void); + void loadLua(void); };