Qt: Cleanup abstraction layers a bit.

Move some code from header to source.  The header has not been removed
entirely so that Qt MOC files can use it.

 - Rename GLWidget as SSView and QtGLMainWindow as SSMainWindow.
pull/1451/head
Karl Robillard 2024-03-01 15:57:06 -05:00
parent 7e8a7c8ffb
commit a4eb339e6c
2 changed files with 274 additions and 368 deletions

View File

@ -7,15 +7,18 @@
#include "platform.h"
#include "guiqt.h"
#include <QApplication>
#include <QAction>
#include <QActionGroup>
#include <QDesktopServices>
#include <QFileDialog>
#include <QEventLoop>
#include <QHBoxLayout>
#include <QKeySequence>
#include <QMenu>
#include <QMenuBar>
#include <QMessageBox>
#include <QScreen>
#include <QSettings>
#include <QTimer>
@ -638,9 +641,186 @@ MenuBarRef GetOrCreateMainMenu(bool* unique) {
// Windows
//-----------------------------------------------------------------------------
void SSView::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 SSView::stopEditing() {
if (entry->isVisible()) {
entry->hide();
setFocus();
}
}
void SSView::wheelEvent(QWheelEvent* event)
{
const double wheelDelta=120.0;
slvMouseEvent.button = MouseEvent::Button::NONE;
slvMouseEvent.type = MouseEvent::Type::SCROLL_VERT;
slvMouseEvent.scrollDelta = (double)event->angleDelta().y() / wheelDelta;
emit mouseEventOccuredSignal(slvMouseEvent);
}
void SSView::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);
}
/*
* 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 SSView::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 SSView::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);
}
SSMainWindow::SSMainWindow(Platform::Window* pwin,
Platform::Window::Kind kind, QWidget* parent)
: QMainWindow(parent), receiver(pwin)
{
ssView = new SSView;
if (kind == Platform::Window::Kind::TOOL) {
QWidget* group = new QWidget;
scrollBar = new QScrollBar(Qt::Vertical, group);
connect(scrollBar, SIGNAL(valueChanged(int)), SLOT(sliderSlot(int)));
QHBoxLayout* lo = new QHBoxLayout(group);
lo->setContentsMargins(0, 0, 0, 0);
lo->setSpacing(2);
lo->addWidget(ssView);
lo->addWidget(scrollBar);
group->setLayout(lo);
setCentralWidget(group);
//setWindowFlags(Qt::Tool);
} else {
scrollBar = nullptr;
setCentralWidget(ssView);
}
}
void SSMainWindow::sliderSlot(int value)
{
if (receiver->onScrollbarAdjusted)
receiver->onScrollbarAdjusted(double(value));
}
void SSMainWindow::closeEvent(QCloseEvent* ev)
{
emit windowClosedSignal();
ev->ignore();
}
class WindowImplQt final : public Window, public QObject {
public:
QtGLMainWindow* windowGLQ;
SSMainWindow* ssWindow;
Window::Kind windowKind;
std::shared_ptr<WindowImplQt> parentWindow;
//std::shared_ptr<MenuBarImpQt> menuBarQt;
@ -649,15 +829,15 @@ public:
: windowKind(kind),
parentWindow(parent)
{
windowGLQ = new QtGLMainWindow(this, kind, parentWindow ? parentWindow->windowGLQ : nullptr);
connect(windowGLQ, &QtGLMainWindow::windowClosedSignal, this, &WindowImplQt::runOnClose);
ssWindow = new SSMainWindow(this, kind, parentWindow ? parentWindow->ssWindow : nullptr);
connect(ssWindow, &SSMainWindow::windowClosedSignal, this, &WindowImplQt::runOnClose);
GLWidget* view = windowGLQ->GetGlWidget();
connect(view, &GLWidget::mouseEventOccuredSignal, this, &WindowImplQt::runOnMouseEvent);
connect(view, &GLWidget::keyEventOccuredSignal, this, &WindowImplQt::runOnKeyboardEvent);
connect(view, &GLWidget::renderOccuredSignal, this, &WindowImplQt::runOnRender);
connect(view, &GLWidget::editingDoneSignal, this, &WindowImplQt::runOnEditingDone);
connect(view, &GLWidget::tabKeyPressed, this, &WindowImplQt::processTabKeyPressed);
SSView* view = ssWindow->ssView;
connect(view, &SSView::mouseEventOccuredSignal, this, &WindowImplQt::runOnMouseEvent);
connect(view, &SSView::keyEventOccuredSignal, this, &WindowImplQt::runOnKeyboardEvent);
connect(view, &SSView::renderOccuredSignal, this, &WindowImplQt::runOnRender);
connect(view, &SSView::editingDoneSignal, this, &WindowImplQt::runOnEditingDone);
connect(view, &SSView::tabKeyPressed, this, &WindowImplQt::processTabKeyPressed);
}
~WindowImplQt() {
@ -685,13 +865,13 @@ public:
// Returns physical display DPI.
double GetPixelDensity() override {
return windowGLQ->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() override {
return windowGLQ->GetDevicePixelRatio();
return ssWindow->ssView->devicePixelRatio();
}
// Returns (fractional) font scale, to be applied on top of (integral) device pixel ratio.
@ -700,70 +880,69 @@ public:
}
bool IsVisible() override {
return windowGLQ->IsVisible();
return ssWindow->isVisible();
}
void SetVisible(bool visible) override {
windowGLQ->setVisible(visible);
windowGLQ->raise();
ssWindow->setVisible(visible);
ssWindow->raise();
}
void Focus() override {
windowGLQ->setFocus();
ssWindow->setFocus();
}
bool IsFullScreen() override {
return windowGLQ->isFullScreen();
return ssWindow->isFullScreen();
}
void SetFullScreen(bool fullScreen) override {
if (true == fullScreen)
windowGLQ->setWindowState(Qt::WindowFullScreen);
else
windowGLQ->setWindowState(Qt::WindowNoState); //The window has no state set (in normal state).
// Qt::WindowNoState is "normal".
ssWindow->setWindowState(fullScreen ? Qt::WindowFullScreen
: Qt::WindowNoState);
}
void SetTitle(const std::string& title) override {
windowGLQ->setWindowTitle(QString::fromStdString(title));
ssWindow->setWindowTitle(QString::fromStdString(title));
}
void SetMenuBar(MenuBarRef menuBar) override {
// Cast this menu bar to a Qt
//menuBarQt = std::static_pointer_cast<MenuBarImpQt>(menuBar);
//windowGLQ->setMenuBar(menuBarQt->menuBarQ);
//ssWindow->setMenuBar(menuBarQt->menuBarQ);
if(windowGLQ->menuBar() != gMenuBarQt->menuBarQ) {
windowGLQ->setMenuBar(gMenuBarQt->menuBarQ);
if(ssWindow->menuBar() != gMenuBarQt->menuBarQ) {
ssWindow->setMenuBar(gMenuBarQt->menuBarQ);
gMenuBarQt->findShowPropertyBrowserMenuItem();
}
}
void GetContentSize(double* width, double* height) override {
windowGLQ->GetContentSize(width, height);
double pixelRatio = GetDevicePixelRatio();
QSize rc = ssWindow->ssView->size();
*width = rc.width() / pixelRatio;
*height = rc.height() / pixelRatio;
}
void SetMinContentSize(double width, double height) override {
int w = width;
int h = height;
windowGLQ->setGeometry(50,50,w, h);
ssWindow->resize(int(width), int(height));
}
void FreezePosition(SettingsRef settings, const std::string& key) override {
if (!(windowGLQ->isVisible())) return;
if (!(ssWindow->isVisible())) return;
int left, top, width, height;
#if 0
QPoint topLeftPoint = windowGLQ->geometry().topLeft();
QPoint topLeftPoint = ssWindow->geometry().topLeft();
left = topLeftPoint.x();
top = topLeftPoint.y();
#endif
QPoint windowPos = windowGLQ->pos();
QPoint windowPos = ssWindow->pos();
left = windowPos.x();
top = windowPos.y();
width = windowGLQ->geometry().width();
height = windowGLQ->geometry().height();
bool isMaximized = windowGLQ->isMaximized();
width = ssWindow->geometry().width();
height = ssWindow->geometry().height();
bool isMaximized = ssWindow->isMaximized();
settings->FreezeInt(key + "_Left", left);
settings->FreezeInt(key + "_Top", top);
@ -781,13 +960,13 @@ public:
height = settings->ThawInt(key + "_Height", height);
if(width != 0 && height != 0) {
windowGLQ->move(left, top);
windowGLQ->resize(width, height);
ssWindow->move(left, top);
ssWindow->resize(width, height);
}
if (settings->ThawBool(key + "_Maximized", false)) {
// windowGLQ->SetFullScreen(true);
windowGLQ->setWindowState(Qt::WindowMaximized);
// ssWindow->SetFullScreen(true);
ssWindow->setWindowState(Qt::WindowMaximized);
}
}
@ -796,65 +975,81 @@ public:
switch (cursor)
{
case Cursor::POINTER:
windowGLQ->setCursor(Qt::ArrowCursor);
ssWindow->setCursor(Qt::ArrowCursor);
break;
case Cursor::HAND:
windowGLQ->setCursor(Qt::PointingHandCursor);
ssWindow->setCursor(Qt::PointingHandCursor);
break;
default:
windowGLQ->setCursor(Qt::ArrowCursor);
ssWindow->setCursor(Qt::ArrowCursor);
}
}
void SetTooltip(const std::string& text, double x, double y,
double width, double height) override {
windowGLQ->SetTooltip(text, x, y, width, height);
ssWindow->ssView->setToolTip(QString::fromStdString(text));
}
bool IsEditorVisible() override {
return windowGLQ->IsEditorVisible();
return ssWindow->ssView->entry->isVisible();
}
void ShowEditor(double x, double y, double fontHeight, double minWidth,
bool isMonospace, const std::string& text) override {
windowGLQ->ShowEditor(x, y, fontHeight, minWidth, isMonospace, 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
ssWindow->ssView->startEditing(x, y, 20, 100, isMonospace, text);
}
void HideEditor() override {
windowGLQ->HideEditor();
ssWindow->ssView->stopEditing();
}
void SetScrollbarVisible(bool visible) override {
//printf("Scroll vis %d\n", int(visible));
windowGLQ->SetScrollbarVisible(visible);
QScrollBar* scrollBar = ssWindow->scrollBar;
if (scrollBar)
scrollBar->setVisible(visible);
}
void ConfigureScrollbar(double min, double max, double pageSize) override {
//printf("Scroll bar %f %f %f\n", min, max, pageSize);
windowGLQ->ConfigureScrollbar(min, max, pageSize);
QScrollBar* scrollBar = ssWindow->scrollBar;
if (scrollBar) {
scrollBar->setRange(int(min), int(max - pageSize));
scrollBar->setPageStep(int(pageSize));
}
}
double GetScrollbarPosition() override {
return windowGLQ->GetScrollbarPosition();
QScrollBar* scrollBar = ssWindow->scrollBar;
if (scrollBar)
return (double) scrollBar->value();
return 0.0;
}
void SetScrollbarPosition(double pos) override {
//printf("Scroll pos %f\n", pos);
windowGLQ->SetScrollbarPosition(pos);
QScrollBar* scrollBar = ssWindow->scrollBar;
if (scrollBar)
scrollBar->setValue((int) pos);
}
void Invalidate() override {
windowGLQ->Invalidate();
ssWindow->ssView->update();
}
QtGLMainWindow* getQtGLMainWindow() {
return windowGLQ;
SSMainWindow* getQtGLMainWindow() {
return ssWindow;
}
public slots:
void processTabKeyPressed() {
if(windowGLQ->menuBar() != gMenuBarQt->menuBarQ && gMenuBarQt->showPropertyBrowserMenuItem != nullptr) {
if(ssWindow->menuBar() != gMenuBarQt->menuBarQ && gMenuBarQt->showPropertyBrowserMenuItem != nullptr) {
gMenuBarQt->showPropertyBrowserMenuItem->actionItemQ->setChecked(false);
gMenuBarQt->showPropertyBrowserMenuItem->onTriggered(false);
}

View File

@ -4,25 +4,22 @@
#include <solvespace.h>
#include <QApplication>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QMainWindow>
#include <QMouseEvent>
#include <QOpenGLWidget>
#include <QScreen>
#include <QScrollBar>
#include <QToolTip>
using namespace SolveSpace::Platform;
namespace SolveSpace {
namespace Platform {
class GLWidget : public QOpenGLWidget
class SSView : public QOpenGLWidget
{
Q_OBJECT
public:
GLWidget(QWidget* parent = 0)
SSView(QWidget* parent = 0)
: QOpenGLWidget(parent) {
entry = new QLineEdit(this);
@ -35,32 +32,14 @@ public:
setMouseTracking(true);
}
~GLWidget()
~SSView()
{
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();
setFocus();
}
}
void startEditing(int x, int y, int fontHeight, int minWidth,
bool isMonoSpace, const std::string& val);
void stopEditing();
QSize minimumSizeHint() const {
return QSize(50, 50);
@ -90,15 +69,7 @@ protected:
}
//----Mouse Events--------
void wheelEvent(QWheelEvent* event)
{
const double wheelDelta=120.0;
slvMouseEvent.button = MouseEvent::Button::NONE;
slvMouseEvent.type = MouseEvent::Type::SCROLL_VERT;
slvMouseEvent.scrollDelta = (double)event->angleDelta().y() / wheelDelta;
emit mouseEventOccuredSignal(slvMouseEvent);
}
void wheelEvent(QWheelEvent* event);
void mouseReleaseEvent(QMouseEvent* event) override{
updateSlvSpaceMouseEvent(event);
@ -112,95 +83,11 @@ protected:
updateSlvSpaceMouseEvent(event);
}
void updateSlvSpaceMouseEvent(QMouseEvent* event)
{
slvMouseEvent.shiftDown = false;
slvMouseEvent.controlDown = false;
void updateSlvSpaceMouseEvent(QMouseEvent* event);
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;
}
bool event(QEvent* e);
void keyPressEvent(QKeyEvent* keyEvent)
{
@ -216,38 +103,11 @@ protected:
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;
void updateSlvSpaceKeyEvent(QKeyEvent* event);
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 mouseEventOccuredSignal(MouseEvent mouseEvent);
void keyEventOccuredSignal(KeyboardEvent keyEvent);
void renderOccuredSignal();
void editingDoneSignal(std::string);
void tabKeyPressed();
@ -255,184 +115,35 @@ signals:
public:
QLineEdit* entry;
SolveSpace::Platform::MouseEvent slvMouseEvent;
SolveSpace::Platform::KeyboardEvent slvKeyEvent;
MouseEvent slvMouseEvent;
KeyboardEvent slvKeyEvent;
};
class QtGLMainWindow : public QMainWindow
class SSMainWindow : public QMainWindow
{
Q_OBJECT
public:
QtGLMainWindow(Platform::Window* pwin, Platform::Window::Kind kind, QWidget* parent = 0)
: QMainWindow(parent), receiver(pwin)
{
glWidget = new GLWidget;
if (kind == Platform::Window::Kind::TOOL) {
QWidget* group = new QWidget;
scrollBar = new QScrollBar(Qt::Vertical, group);
connect(scrollBar, SIGNAL(valueChanged(int)), SLOT(sliderSlot(int)));
QHBoxLayout* lo = new QHBoxLayout(group);
lo->setContentsMargins(0, 0, 0, 0);
lo->setSpacing(2);
lo->addWidget(glWidget);
lo->addWidget(scrollBar);
group->setLayout(lo);
setCentralWidget(group);
//setWindowFlags(Qt::Tool);
} else {
scrollBar = nullptr;
setCentralWidget(glWidget);
}
}
~QtGLMainWindow() {}
void SetScrollbarVisible(bool visible) {
if (scrollBar)
scrollBar->setVisible(visible);
}
void ConfigureScrollbar(double min, double max, double pageSize) {
if (scrollBar) {
scrollBar->setRange(int(min), int(max - pageSize));
scrollBar->setPageStep(int(pageSize));
}
}
double GetScrollbarPosition() {
if (scrollBar)
return (double) scrollBar->value();
return 0.0;
}
void SetScrollbarPosition(double pos) {
if (scrollBar)
scrollBar->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 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 glWidget->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)
setWindowState(Qt::WindowFullScreen);
else
setWindowState(Qt::WindowNoState); //The window has no state set (in normal state).
}
void SetTitle(const std::string& title) {
setWindowTitle(QString::fromStdString(title));
}
void GetContentSize(double* width, double* height) {
double pixelRatio = GetDevicePixelRatio();
QRect rc = glWidget->geometry();
*width = rc.width() / pixelRatio;
*height = rc.height() / pixelRatio;
}
void SetMinContentSize(double width, double height) {
resize((int)width, (int)height);
glWidget->resize(width, height);
}
void SetTooltip(const std::string& text, double x, double y,
double width, double height) {
glWidget->setToolTip(QString::fromStdString(text));
}
bool IsEditorVisible() {
return 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
glWidget->startEditing(x, y, 20, 100, isMonospace, text);
}
void HideEditor() {
glWidget->stopEditing();
}
SSMainWindow(Platform::Window* pwin, Platform::Window::Kind kind,
QWidget* parent = 0);
protected slots:
void sliderSlot(int value) {
if (receiver->onScrollbarAdjusted)
receiver->onScrollbarAdjusted(double(value));
}
void sliderSlot(int value);
protected:
void closeEvent(QCloseEvent* ev)
{
emit windowClosedSignal();
ev->ignore();
}
void closeEvent(QCloseEvent* ev);
signals:
void windowClosedSignal();
private:
public:
Platform::Window* receiver;
GLWidget* glWidget;
SSView* ssView;
QScrollBar* scrollBar;
};
}
}
#endif