Added Qt port related files in src/platforms ( guiqt.cpp and qglmainwindow.h

pull/1451/head
shingen75 2023-09-15 21:51:23 +09:00 committed by Karl Robillard
parent 562dba9e6c
commit 63e389ebdc
3 changed files with 1923 additions and 171 deletions

View File

@ -19,6 +19,16 @@ endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h) ${CMAKE_CURRENT_BINARY_DIR}/config.h)
if(USE_QT_GUI)
#Including QT
set(CMAKE_AUTOMOC ON)
find_package(Qt5 COMPONENTS Core Gui Widgets OpenGL REQUIRED)
include (../extlib/tinyxml2/CMakeLists.txt)
#including code from PoCAE
set(GitPath ${CMAKE_CURRENT_LIST_DIR}/../..)
endif()
# solvespace dependencies # solvespace dependencies
add_library(slvs_deps INTERFACE) add_library(slvs_deps INTERFACE)
target_include_directories(slvs_deps INTERFACE SYSTEM target_include_directories(slvs_deps INTERFACE SYSTEM
@ -34,7 +44,7 @@ target_link_libraries(slvs_deps INTERFACE
${ZLIB_LIBRARY} ${ZLIB_LIBRARY}
${PNG_LIBRARY} ${PNG_LIBRARY}
${FREETYPE_LIBRARY} ${FREETYPE_LIBRARY}
${CAIRO_LIBRARIES} #${CAIRO_LIBRARIES}
mimalloc-static) mimalloc-static)
if(Backtrace_FOUND) if(Backtrace_FOUND)
@ -111,68 +121,131 @@ set(every_platform_SOURCES
set(solvespace_core_gl_SOURCES set(solvespace_core_gl_SOURCES
solvespace.cpp) solvespace.cpp)
add_library(solvespace-core STATIC if (NOT USE_QT_GUI)
dsc.h add_library(solvespace-core STATIC
expr.h dsc.h
polygon.h expr.h
sketch.h polygon.h
solvespace.h sketch.h
ui.h solvespace.h
platform/platform.h ui.h
render/render.h platform/platform.h
render/gl3shader.h render/render.h
srf/surface.h render/gl3shader.h
bsp.cpp render/render2d.cpp
clipboard.cpp srf/surface.h
confscreen.cpp bsp.cpp
constraint.cpp clipboard.cpp
constrainteq.cpp confscreen.cpp
describescreen.cpp constraint.cpp
draw.cpp constrainteq.cpp
drawconstraint.cpp describescreen.cpp
drawentity.cpp draw.cpp
entity.cpp drawconstraint.cpp
export.cpp drawentity.cpp
exportstep.cpp entity.cpp
exportvector.cpp export.cpp
expr.cpp exportstep.cpp
file.cpp exportvector.cpp
generate.cpp expr.cpp
graphicswin.cpp file.cpp
group.cpp generate.cpp
groupmesh.cpp graphicswin.cpp
importdxf.cpp group.cpp
importidf.cpp groupmesh.cpp
importmesh.cpp importdxf.cpp
mesh.cpp importidf.cpp
modify.cpp importmesh.cpp
mouse.cpp mesh.cpp
polyline.cpp modify.cpp
polygon.cpp mouse.cpp
resource.cpp polyline.cpp
request.cpp polygon.cpp
style.cpp resource.cpp
system.cpp request.cpp
textscreens.cpp style.cpp
textwin.cpp system.cpp
toolbar.cpp textscreens.cpp
ttf.cpp textwin.cpp
undoredo.cpp toolbar.cpp
util.cpp ttf.cpp
view.cpp undoredo.cpp
platform/platform.cpp util.cpp
platform/gui.cpp view.cpp
render/render.cpp platform/platform.cpp
render/render2d.cpp platform/gui.cpp
srf/boolean.cpp render/render.cpp
srf/curve.cpp srf/boolean.cpp
srf/merge.cpp srf/curve.cpp
srf/ratpoly.cpp srf/merge.cpp
srf/raycast.cpp srf/ratpoly.cpp
srf/shell.cpp srf/raycast.cpp
srf/surface.cpp srf/shell.cpp
srf/surfinter.cpp srf/surface.cpp
srf/triangulate.cpp) srf/surfinter.cpp
srf/triangulate.cpp)
else()
add_library(solvespace-core STATIC
dsc.h
expr.h
polygon.h
sketch.h
solvespace.h
ui.h
platform/platform.h
render/render.h
srf/surface.h
bsp.cpp
clipboard.cpp
confscreen.cpp
constraint.cpp
constrainteq.cpp
describescreen.cpp
draw.cpp
drawconstraint.cpp
drawentity.cpp
entity.cpp
export.cpp
exportstep.cpp
exportvector.cpp
expr.cpp
file.cpp
generate.cpp
graphicswin.cpp
group.cpp
groupmesh.cpp
importdxf.cpp
importidf.cpp
importmesh.cpp
mesh.cpp
modify.cpp
mouse.cpp
polyline.cpp
polygon.cpp
resource.cpp
request.cpp
style.cpp
system.cpp
textscreens.cpp
textwin.cpp
toolbar.cpp
ttf.cpp
undoredo.cpp
util.cpp
view.cpp
platform/platform.cpp
platform/gui.cpp
render/render.cpp
srf/boolean.cpp
srf/curve.cpp
srf/merge.cpp
srf/ratpoly.cpp
srf/raycast.cpp
srf/shell.cpp
srf/surface.cpp
srf/surfinter.cpp
srf/triangulate.cpp)
endif()
target_link_libraries(solvespace-core PUBLIC slvs_deps) target_link_libraries(solvespace-core PUBLIC slvs_deps)
@ -262,128 +335,188 @@ endif()
# solvespace graphical executable # solvespace graphical executable
if(ENABLE_GUI) if(ENABLE_GUI)
add_executable(solvespace WIN32 MACOSX_BUNDLE if(NOT USE_QT_GUI)
${solvespace_core_gl_SOURCES} add_executable(solvespace WIN32 MACOSX_BUNDLE
platform/entrygui.cpp ${solvespace_core_gl_SOURCES}
$<TARGET_PROPERTY:resources,EXTRA_SOURCES>) platform/entrygui.cpp
$<TARGET_PROPERTY:resources,EXTRA_SOURCES>)
add_dependencies(solvespace add_dependencies(solvespace
resources) resources)
target_link_libraries(solvespace target_link_libraries(solvespace
PRIVATE PRIVATE
solvespace-core solvespace-core
${OPENGL_LIBRARIES}) ${OPENGL_LIBRARIES})
# OpenGL version # OpenGL version
if(OPENGL STREQUAL 3) if(OPENGL STREQUAL 3)
target_sources(solvespace PRIVATE target_sources(solvespace PRIVATE
render/gl3shader.cpp render/gl3shader.cpp
render/rendergl3.cpp) render/rendergl3.cpp)
elseif(OPENGL STREQUAL 1) elseif(OPENGL STREQUAL 1)
target_sources(solvespace PRIVATE target_sources(solvespace PRIVATE
render/rendergl1.cpp) render/rendergl1.cpp)
else() else()
message(FATAL_ERROR "Unsupported OpenGL version ${OPENGL}") message(FATAL_ERROR "Unsupported OpenGL version ${OPENGL}")
endif() endif()
# Platform-specific # Platform-specific
if(WIN32) if(WIN32)
target_sources(solvespace PRIVATE target_sources(solvespace PRIVATE
platform/guiwin.cpp) platform/guiwin.cpp)
target_link_libraries(solvespace PRIVATE comctl32) target_link_libraries(solvespace PRIVATE comctl32)
elseif(APPLE) elseif(APPLE)
target_compile_options(solvespace PRIVATE -fobjc-arc) target_compile_options(solvespace PRIVATE -fobjc-arc)
target_compile_definitions(solvespace PRIVATE GL_SILENCE_DEPRECATION) target_compile_definitions(solvespace PRIVATE GL_SILENCE_DEPRECATION)
target_sources(solvespace PRIVATE target_sources(solvespace PRIVATE
platform/guimac.mm) platform/guimac.mm)
set_target_properties(solvespace PROPERTIES set_target_properties(solvespace PROPERTIES
OUTPUT_NAME SolveSpace OUTPUT_NAME SolveSpace
XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME "YES" XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME "YES"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.solvespace" XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.solvespace"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
elseif(EMSCRIPTEN) elseif(EMSCRIPTEN)
set(SHELL ${CMAKE_CURRENT_SOURCE_DIR}/platform/html/emshell.html) set(SHELL ${CMAKE_CURRENT_SOURCE_DIR}/platform/html/emshell.html)
set(LINK_FLAGS set(LINK_FLAGS
--bind --shell-file ${SHELL} --bind --shell-file ${SHELL}
--no-heap-copy -s ALLOW_MEMORY_GROWTH=1 -s WASM=1 -s ASYNCIFY=1 --no-heap-copy -s ALLOW_MEMORY_GROWTH=1 -s WASM=1 -s ASYNCIFY=1
-s DYNCALLS=1 -s ASSERTIONS=1 -s DYNCALLS=1 -s ASSERTIONS=1
-s TOTAL_STACK=33554432 -s TOTAL_MEMORY=134217728) -s TOTAL_STACK=33554432 -s TOTAL_MEMORY=134217728)
get_target_property(resource_names resources NAMES) get_target_property(resource_names resources NAMES)
foreach(resource ${resource_names}) foreach(resource ${resource_names})
list(APPEND LINK_FLAGS --preload-file ${resource}) list(APPEND LINK_FLAGS --preload-file ${resource})
endforeach() endforeach()
if(CMAKE_BUILD_TYPE STREQUAL Debug) if(CMAKE_BUILD_TYPE STREQUAL Debug)
list(APPEND LINK_FLAGS list(APPEND LINK_FLAGS
--emrun --emit-symbol-map --emrun --emit-symbol-map
-s DEMANGLE_SUPPORT=1 -s DEMANGLE_SUPPORT=1
-s SAFE_HEAP=1) -s SAFE_HEAP=1)
endif() endif()
target_sources(solvespace PRIVATE target_sources(solvespace PRIVATE
platform/guihtml.cpp) platform/guihtml.cpp)
string(REPLACE ";" " " LINK_FLAGS "${LINK_FLAGS}") string(REPLACE ";" " " LINK_FLAGS "${LINK_FLAGS}")
set_target_properties(solvespace PROPERTIES set_target_properties(solvespace PROPERTIES
LINK_FLAGS "${LINK_FLAGS}") LINK_FLAGS "${LINK_FLAGS}")
set_source_files_properties(platform/guihtml.cpp PROPERTIES set_source_files_properties(platform/guihtml.cpp PROPERTIES
OBJECT_DEPENDS ${SHELL}) OBJECT_DEPENDS ${SHELL})
add_custom_command( add_custom_command(
TARGET solvespace POST_BUILD TARGET solvespace POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/platform/html/solvespaceui.css ${CMAKE_CURRENT_SOURCE_DIR}/platform/html/solvespaceui.css
${EXECUTABLE_OUTPUT_PATH}/solvespaceui.css ${EXECUTABLE_OUTPUT_PATH}/solvespaceui.css
COMMENT "Copying UI stylesheet" COMMENT "Copying UI stylesheet"
VERBATIM) VERBATIM)
add_custom_command( add_custom_command(
TARGET solvespace POST_BUILD TARGET solvespace POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/platform/html/solvespaceui.js ${CMAKE_CURRENT_SOURCE_DIR}/platform/html/solvespaceui.js
${EXECUTABLE_OUTPUT_PATH}/solvespaceui.js ${EXECUTABLE_OUTPUT_PATH}/solvespaceui.js
COMMENT "Copying UI script solvespaceui.js" COMMENT "Copying UI script solvespaceui.js"
VERBATIM) VERBATIM)
add_custom_command( add_custom_command(
TARGET solvespace POST_BUILD TARGET solvespace POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/platform/html/filemanagerui.js ${CMAKE_CURRENT_SOURCE_DIR}/platform/html/filemanagerui.js
${EXECUTABLE_OUTPUT_PATH}/filemanagerui.js ${EXECUTABLE_OUTPUT_PATH}/filemanagerui.js
COMMENT "Copying UI script filemanagerui.sj" COMMENT "Copying UI script filemanagerui.sj"
VERBATIM) VERBATIM)
else() else()
target_sources(solvespace PRIVATE target_sources(solvespace PRIVATE
platform/guigtk.cpp) platform/guigtk.cpp)
target_include_directories(solvespace PRIVATE SYSTEM target_include_directories(solvespace PRIVATE SYSTEM
${GTKMM_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS}
${JSONC_INCLUDE_DIRS} ${JSONC_INCLUDE_DIRS}
${FONTCONFIG_INCLUDE_DIRS}) ${FONTCONFIG_INCLUDE_DIRS})
target_link_directories(solvespace PRIVATE target_link_directories(solvespace PRIVATE
${GTKMM_LIBRARY_DIRS} ${GTKMM_LIBRARY_DIRS}
${JSONC_LIBRARY_DIRS} ${JSONC_LIBRARY_DIRS}
${FONTCONFIG_LIBRARY_DIRS}) ${FONTCONFIG_LIBRARY_DIRS})
target_link_libraries(solvespace PRIVATE target_link_libraries(solvespace PRIVATE
${GTKMM_LIBRARIES} ${GTKMM_LIBRARIES}
${JSONC_LIBRARIES} ${JSONC_LIBRARIES}
${FONTCONFIG_LIBRARIES}) ${FONTCONFIG_LIBRARIES})
endif() endif()
if(MSVC) if(MSVC)
set_target_properties(solvespace PROPERTIES set_target_properties(solvespace PROPERTIES
LINK_FLAGS "/MANIFEST:NO /SAFESEH:NO /INCREMENTAL:NO /OPT:REF") LINK_FLAGS "/MANIFEST:NO /SAFESEH:NO /INCREMENTAL:NO /OPT:REF")
endif() endif()
endif()
if(USE_QT_GUI)
add_executable(solvespaceQt WIN32 MACOSX_BUNDLE
${solvespace_core_gl_SOURCES}
platform/entrygui.cpp
$<TARGET_PROPERTY:resources,EXTRA_SOURCES>)
add_dependencies(solvespaceQt
resources)
target_link_libraries(solvespaceQt
PRIVATE
solvespace-core
${OPENGL_LIBRARIES})
# OpenGL version
if(OPENGL STREQUAL 3)
target_sources(solvespaceQt PRIVATE
render/gl3shader.cpp
render/rendergl3.cpp)
elseif(OPENGL STREQUAL 1)
target_sources(solvespaceQt PRIVATE
render/rendergl1.cpp)
else()
message(FATAL_ERROR "Unsupported OpenGL version ${OPENGL}")
endif()
# Platform-specific
target_sources(solvespaceQt PRIVATE
#platform/guiwin.cpp
platform/guiqt.cpp
platform/QGLMainWindow.h
${TinyXmlIncludes}
)
target_link_libraries(solvespaceQt PRIVATE #comctl32
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::OpenGL
)
set(QT_DEBUG_ENV "${_qt5_install_prefix}/../../bin\\\;")
set(QT_RELEASE_ENV "${_qt5_install_prefix}/../../bin\\\;")
set(QT_PLUGIN_PATH "${_qt5_install_prefix}/../../plugins\\\;")
GenUserProp(solvespaceQt ${QT_DEBUG_ENV} ${QT_RELEASE_ENV} ${QT_PLUGIN_PATH})
if(MSVC)
set_target_properties(solvespaceQt PROPERTIES
LINK_FLAGS "/MANIFEST:NO /SAFESEH:NO /INCREMENTAL:NO /OPT:REF")
endif()
endif()
endif() endif()
# solvespace headless library # solvespace headless library
add_library(solvespace-headless STATIC EXCLUDE_FROM_ALL if(NOT USE_QT_GUI)
${solvespace_core_gl_SOURCES} add_library(solvespace-headless STATIC EXCLUDE_FROM_ALL
platform/guinone.cpp ${solvespace_core_gl_SOURCES}
render/rendercairo.cpp) platform/guinone.cpp
render/rendercairo.cpp
)
else()
add_library(solvespace-headless STATIC EXCLUDE_FROM_ALL
${solvespace_core_gl_SOURCES}
)
endif()
target_compile_definitions(solvespace-headless target_compile_definitions(solvespace-headless
PRIVATE HEADLESS) PRIVATE HEADLESS)
@ -419,10 +552,18 @@ endif()
# solvespace unix package # solvespace unix package
if(NOT (WIN32 OR APPLE OR EMSCRIPTEN)) if(NOT (WIN32 OR APPLE OR EMSCRIPTEN))
if(ENABLE_GUI) if(NOT USE_QT_GUI)
install(TARGETS solvespace if(ENABLE_GUI)
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(TARGETS solvespace
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
else()
if(ENABLE_GUI)
install(TARGETS solvespaceQt
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
endif() endif()
if(ENABLE_CLI) if(ENABLE_CLI)
install(TARGETS solvespace-cli install(TARGETS solvespace-cli
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

1126
src/platform/guiqt.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,485 @@
#ifndef QGlMainWindow_h
#define QGlMainWindow_h
#include <solvespace.h>
#include <QApplication>
#include <QWidget>
#include <QOpenGLWidget>
#include <QOpenGLFunctions_1_0>
//#include <gl/GLU.h>
//#include <gl/GL.h>
#include <QMainWindow>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QScrollArea>
#include <QScrollBar>
#include <QLineEdit>
#include <QToolTip>
#include <QMessageBox>
#include <QScreen>
#include <iostream>
using namespace SolveSpace::Platform;
class GLWidget : public QOpenGLWidget, public QOpenGLFunctions_1_0
{
Q_OBJECT
public:
GLWidget(QWidget* parent = 0)
: QOpenGLWidget(parent) {
entry = new QLineEdit(this);
entry->setGeometry(QRect(0, 0, 200, 40));
QFont entryFont("Arial", 16);
entry->setFont(entryFont);
entry->setVisible(false);
connect(entry, SIGNAL(returnPressed()), this, SLOT(entryFinished()));
this->setFocusPolicy(Qt::FocusPolicy::StrongFocus);
this->setMouseTracking(true);
}
~GLWidget()
{
delete entry;
}
void startEditing(int x, int y, int fontHeight, int minWidth, bool isMonoSpace,
const std::string& val) {
entry->setGeometry(QRect(x, y, minWidth, fontHeight));
entry->setText(QString::fromStdString(val));
if (!entry->isVisible()) {
entry->show();
entry->setFocus();
entry->setCursorPosition(0);
}
}
void stopEditing() {
if (entry->isVisible()) {
entry->hide();
this->setFocus();
}
}
QSize minimumSizeHint() const {
return QSize(50, 50);
}
QSize sizeHint() const {
return QSize(400, 400);
}
protected slots:
void entryFinished()
{
std::string entryText = entry->text().toStdString();
emit editingDoneSignal(entryText);
}
protected:
void initializeGL() {
initializeOpenGLFunctions();
}
void paintGL() {
if(true == QOpenGLContext::currentContext()->isValid())
emit renderOccuredSignal();
}
void resizeGL(int width, int height) {
// end of remove
if(true == QOpenGLContext::currentContext()->isValid())
emit renderOccuredSignal();
}
//----Mouse Events--------
void wheelEvent(QWheelEvent* event)
{
int wheelDelta=120;
slvMouseEvent.button = MouseEvent::Button::NONE;
slvMouseEvent.type = MouseEvent::Type::SCROLL_VERT;
if (!event->angleDelta().isNull())
slvMouseEvent.scrollDelta = (double)event->delta() / (double)wheelDelta;
emit mouseEventOccuredSignal(slvMouseEvent);
}
void mouseReleaseEvent(QMouseEvent* event) override{
this->updateSlvSpaceMouseEvent(event);
QWidget::mouseReleaseEvent(event);
}
virtual void mousePressEvent(QMouseEvent* event) override{
this->updateSlvSpaceMouseEvent(event);
QWidget::mousePressEvent(event);
}
void mouseMoveEvent(QMouseEvent* event) override{
this->updateSlvSpaceMouseEvent(event);
QWidget::mouseMoveEvent(event);
}
void updateSlvSpaceMouseEvent(QMouseEvent* event)
{
slvMouseEvent.shiftDown = false;
slvMouseEvent.controlDown = false;
switch (event->type())
{
case QEvent::MouseMove:
slvMouseEvent.type = MouseEvent::Type::MOTION;
break;
case QEvent::MouseButtonPress:
slvMouseEvent.type = MouseEvent::Type::PRESS;
break;
case QEvent::MouseButtonDblClick:
slvMouseEvent.type = MouseEvent::Type::DBL_PRESS;
break;
case QEvent::MouseButtonRelease:
slvMouseEvent.type = MouseEvent::Type::RELEASE;
slvMouseEvent.button = MouseEvent::Button::NONE;
break;
case QEvent::Wheel:
slvMouseEvent.type = MouseEvent::Type::SCROLL_VERT;
//slvMouseEvent.scrollDelta = event->
break;
case QEvent::Leave:
slvMouseEvent.type = MouseEvent::Type::LEAVE;
slvMouseEvent.button = MouseEvent::Button::NONE;
break;
default:
slvMouseEvent.type = MouseEvent::Type::RELEASE;
slvMouseEvent.button = MouseEvent::Button::NONE;
}
Qt::MouseButtons buttonState = (slvMouseEvent.type == MouseEvent::Type::MOTION) ? event->buttons() : event->button();
switch (buttonState)
{
case Qt::MouseButton::LeftButton:
slvMouseEvent.button = MouseEvent::Button::LEFT;
break;
case Qt::MouseButton::RightButton:
slvMouseEvent.button = MouseEvent::Button::RIGHT;
break;
case Qt::MouseButton::MidButton:
slvMouseEvent.button = MouseEvent::Button::MIDDLE;
break;
default:
slvMouseEvent.button = MouseEvent::Button::NONE;
//slvMouseEvent.button = slvMouseEvent.button;
}
slvMouseEvent.x = event->pos().x();
slvMouseEvent.y = event->pos().y();
Qt::KeyboardModifiers keyModifier = QGuiApplication::keyboardModifiers();
switch (keyModifier)
{
case Qt::ShiftModifier:
slvMouseEvent.shiftDown = true;
break;
case Qt::ControlModifier:
slvMouseEvent.controlDown = true;
break;
}
emit mouseEventOccuredSignal(slvMouseEvent);
}
//----Keyboard Events--------
/*
* Need to override the event method to catch the tab key during a key press event
* Qt does not send a key press event when the tab key is presed. To get that
* we need to overwrite the event functon and check if the tab key was presed during a key press event
* otherwise we send the rest of the event back to the widget for further processes
*/
bool event(QEvent* e)
{
if(e->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(e);
if(keyEvent->key() == Qt::Key_Tab) {
emit tabKeyPressed();
}
} else {
QWidget::event(e);
}
return true;
}
void keyPressEvent(QKeyEvent* keyEvent)
{
slvKeyEvent.type = KeyboardEvent::Type::PRESS;
updateSlvSpaceKeyEvent(keyEvent);
QWidget::keyPressEvent(keyEvent);
}
void keyReleaseEvent(QKeyEvent* keyEvent)
{
slvKeyEvent.type = KeyboardEvent::Type::RELEASE;
updateSlvSpaceKeyEvent(keyEvent);
QWidget::keyReleaseEvent(keyEvent);
}
void updateSlvSpaceKeyEvent(QKeyEvent* event)
{
slvKeyEvent.key = KeyboardEvent::Key(-1);
slvKeyEvent.shiftDown = false;
slvKeyEvent.controlDown = false;
if (event->modifiers() == Qt::ShiftModifier)
slvKeyEvent.shiftDown = true;
if (event->modifiers() == Qt::ControlModifier)
slvKeyEvent.controlDown = true;
if (event->key() >= Qt::Key_F1 && event->key() <= Qt::Key_F35) {
slvKeyEvent.key = KeyboardEvent::Key::FUNCTION;
slvKeyEvent.num = event->key() - Qt::Key_F1 + 1;
}
if (event->key() >= Qt::Key_Space && event->key() <= Qt::Key_yen) {
slvKeyEvent.key = KeyboardEvent::Key::CHARACTER;
QString keyLower = event->text().toLower();
slvKeyEvent.chr = keyLower.toUcs4().at(0);
}
emit keyEventOccuredSignal(slvKeyEvent);
}
void SetTooltip(const std::string& text, double x, double y,
double width, double height) {
this->setToolTip(QString::fromStdString(text));
QPoint pos(x, y);
QToolTip::showText(pos, toolTip());
}
signals:
void mouseEventOccuredSignal(SolveSpace::Platform::MouseEvent mouseEvent);
void keyEventOccuredSignal(SolveSpace::Platform::KeyboardEvent keyEvent);
void renderOccuredSignal();
void editingDoneSignal(std::string);
void tabKeyPressed();
public:
QLineEdit* entry;
SolveSpace::Platform::MouseEvent slvMouseEvent;
SolveSpace::Platform::KeyboardEvent slvKeyEvent;
};
class QtGLMainWindow : public QMainWindow
{
Q_OBJECT
public:
QtGLMainWindow(QWidget* parent = 0)
:QMainWindow(parent) {
glWidget = new GLWidget;
scrollArea = new QScrollArea(this);
gridLayout = new QGridLayout();
glWidget->setLayout(gridLayout);
//scrollArea->setWidget(glWidget);
//scrollArea->setWidgetResizable(true);
this->setCentralWidget(glWidget);
//void QLayout::setContentsMargins(int left, int top, int right, int bottom)
this->wheelDelta=120;
}
~QtGLMainWindow()
{
delete glWidget;
delete scrollArea;
}
#if 0 //ADAM CHECK SCROLL
void resizeEvent(QResizeEvent* event)
{
int glWidth = glWidget->size().width();
int glHeight = glWidget->size().height();
int scrollAreaWidth = scrollArea->size().width();
int scrollAreaHeight = scrollArea->size().height();
QWidget::resizeEvent(event);
}
#endif
void SetScrollbarVisible(bool visible) {
//bool resizable = scrollArea->widgetResizable();
#if 1
if (true == visible)
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
else
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
#endif
}
void ConfigureScrollbar(double min, double max, double pageSize) {
scrollArea->verticalScrollBar()->setMinimum((int)min);
scrollArea->verticalScrollBar()->setMaximum((int)max);
scrollArea->verticalScrollBar()->setPageStep((int)pageSize);
}
double GetScrollbarPosition() {
return (double) scrollArea->verticalScrollBar()->value();
}
void SetScrollbarPosition(double pos) {
return scrollArea->verticalScrollBar()->setValue((int)pos);
}
void Invalidate() {
glWidget->update();
}
void StartEditing(int x, int y, int fontHeight, int minWidth, bool isMonoSpace,
const std::string& val) {
glWidget->startEditing(x, y, fontHeight, minWidth, isMonoSpace, val);
}
void StopEditing(){
glWidget->stopEditing();
}
GLWidget* GetGlWidget() {
return this->glWidget;
}
// Returns physical display DPI.
double GetPixelDensity() {
return QGuiApplication::primaryScreen()->logicalDotsPerInch();
}
// Returns raster graphics and coordinate scale (already applied on the platform side),
// i.e. size of logical pixel in physical pixels, or device pixel ratio.
double GetDevicePixelRatio() {
return this->GetGlWidget()->devicePixelRatio();
}
// Returns (fractional) font scale, to be applied on top of (integral) device pixel ratio.
double GetDeviceFontScale() {
return GetPixelDensity() / GetDevicePixelRatio() / 96.0;
}
bool IsVisible() {
return this->isVisible();
}
void SetVisible(bool visible) {
this->setVisible(visible);
}
void Focus() {
this->setFocus();
}
bool IsFullScreen() {
return this->isFullScreen();
}
void SetFullScreen(bool fullScreen) {
if (true == fullScreen)
this->setWindowState(Qt::WindowFullScreen);
else
this->setWindowState(Qt::WindowNoState); //The window has no state set (in normal state).
}
void SetTitle(const std::string& title) {
this->setWindowTitle(QString::fromStdString(title));
}
void GetContentSize(double* width, double* height) {
double pixelRatio = GetDevicePixelRatio();
QRect rc = this->GetGlWidget()->geometry();
*width = rc.width() / pixelRatio;
*height = rc.height() / pixelRatio;
}
void SetMinContentSize(double width, double height) {
this->resize((int)width, (int)height);
this->GetGlWidget()->resize(width, height);
}
void SetTooltip(const std::string& text, double x, double y,
double width, double height) {
this->glWidget->setToolTip(QString::fromStdString(text));
}
bool IsEditorVisible() {
return this->glWidget->entry->isVisible();
}
void ShowEditor(double x, double y, double fontHeight, double minWidth,
bool isMonospace, const std::string& text) {
// font size from Solvespace is very small and hard to see
// hard coded 20 for height and 100 for width
// using Arial font of size 16
// font decalred and set to the entry QLabel in the constructor
// Raed Marwan
this->glWidget->startEditing(x, y, 20, 100, isMonospace, text);
}
void HideEditor() {
this->glWidget->stopEditing();
}
protected:
void closeEvent(QCloseEvent* ev)
{
emit windowClosedSignal();
ev->ignore();
}
signals:
void windowClosedSignal();
private:
GLWidget* glWidget;
QScrollArea* scrollArea;
QGridLayout* gridLayout;
double wheelDelta;
};
#endif