guiqt.cpp: Unindent code & match comment style with other gui files.
parent
9d9a30800c
commit
1aabaab696
|
@ -1,3 +1,6 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// The Qt-based implementation of platform-dependent GUI functionality.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <platform/qglmainwindow.h>
|
||||
#include "solvespace.h"
|
||||
|
@ -23,24 +26,27 @@
|
|||
#include <iostream>
|
||||
|
||||
|
||||
namespace SolveSpace
|
||||
namespace SolveSpace {
|
||||
namespace Platform {
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Fatal errors
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void FatalError(const std::string& message)
|
||||
{
|
||||
namespace Platform
|
||||
{
|
||||
/*********** Fatal Error */
|
||||
|
||||
void FatalError(const std::string& message)
|
||||
{
|
||||
QMessageBox::critical(NULL, QString("Fatal Error"), QString::fromStdString(message),
|
||||
QMessageBox::critical(NULL, QString("Fatal Error"),
|
||||
QString::fromStdString(message),
|
||||
QMessageBox::StandardButton::Ok);
|
||||
|
||||
abort();
|
||||
}
|
||||
/*********** Message Dialog */
|
||||
}
|
||||
|
||||
class MessageDialogImplQt final : public MessageDialog {
|
||||
//-----------------------------------------------------------------------------
|
||||
// Message dialogs
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
public:
|
||||
class MessageDialogImplQt final : public MessageDialog {
|
||||
public:
|
||||
QMessageBox* messageBoxQ;
|
||||
|
||||
MessageDialogImplQt() {
|
||||
|
@ -50,9 +56,9 @@ namespace SolveSpace
|
|||
~MessageDialogImplQt() {
|
||||
delete messageBoxQ;
|
||||
}
|
||||
|
||||
#undef ERROR
|
||||
void SetType(Type type) override {
|
||||
|
||||
switch (type) {
|
||||
case Type::INFORMATION:
|
||||
messageBoxQ->setIcon(QMessageBox::Information);
|
||||
|
@ -70,17 +76,14 @@ namespace SolveSpace
|
|||
}
|
||||
|
||||
void SetTitle(std::string title) override {
|
||||
|
||||
messageBoxQ->setWindowTitle(QString::fromStdString(title));
|
||||
}
|
||||
|
||||
void SetMessage(std::string message) override {
|
||||
|
||||
messageBoxQ->setText(QString::fromStdString(message));
|
||||
}
|
||||
|
||||
void SetDescription(std::string description) override {
|
||||
|
||||
messageBoxQ->setInformativeText(QString::fromStdString(description));
|
||||
}
|
||||
|
||||
|
@ -103,7 +106,6 @@ namespace SolveSpace
|
|||
messageBoxQ->addButton(QMessageBox::StandardButton::Ignore);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Response RunModal() {
|
||||
|
@ -126,20 +128,20 @@ namespace SolveSpace
|
|||
|
||||
return Response::NONE;
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
MessageDialogRef CreateMessageDialog(WindowRef parentWindow) {
|
||||
MessageDialogRef CreateMessageDialog(WindowRef parentWindow) {
|
||||
std::shared_ptr<MessageDialogImplQt> dialog = std::make_shared<MessageDialogImplQt>();
|
||||
//dialog->mbp.hwndOwner = std::static_pointer_cast<WindowImplWin32>(parentWindow)->hWindow;
|
||||
return dialog;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// File dialogs
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/*********** File Dilaog */
|
||||
class FileDialogImplQt final : public FileDialog, public QObject {
|
||||
|
||||
public:
|
||||
class FileDialogImplQt final : public FileDialog, public QObject {
|
||||
public:
|
||||
bool isSaveDialog;
|
||||
QStringList filters;
|
||||
QFileDialog* fileDialogQ;
|
||||
|
@ -215,8 +217,7 @@ namespace SolveSpace
|
|||
std::string pathUnixStyle = selectedFiles.at(0).toStdString(); // return first selection.
|
||||
if ('\\' == QDir::separator())
|
||||
filePath.raw = replaceSubstringInString(pathUnixStyle, "/", "\\");
|
||||
else
|
||||
{
|
||||
else {
|
||||
filePath.raw = pathUnixStyle;
|
||||
}
|
||||
return filePath;
|
||||
|
@ -274,37 +275,31 @@ namespace SolveSpace
|
|||
SetExtension(settings->ThawString("Dialog_" + key + "_Filter"));
|
||||
}
|
||||
|
||||
|
||||
bool RunModal() override {
|
||||
|
||||
if (isSaveDialog) {
|
||||
SetTitle("Save file");
|
||||
fileDialogQ->setAcceptMode(QFileDialog::AcceptSave);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
SetTitle("Open file");
|
||||
fileDialogQ->setAcceptMode(QFileDialog::AcceptOpen);
|
||||
}
|
||||
|
||||
fileDialogQ->setNameFilters(filters);
|
||||
return(fileDialogQ->exec());
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
FileDialogRef CreateOpenFileDialog(WindowRef parentWindow) {
|
||||
FileDialogRef CreateOpenFileDialog(WindowRef parentWindow) {
|
||||
std::shared_ptr<FileDialogImplQt> dialog = std::make_shared<FileDialogImplQt>();
|
||||
dialog->isSaveDialog = false;
|
||||
return dialog;
|
||||
}
|
||||
}
|
||||
|
||||
FileDialogRef CreateSaveFileDialog(WindowRef parentWindow) {
|
||||
FileDialogRef CreateSaveFileDialog(WindowRef parentWindow) {
|
||||
std::shared_ptr<FileDialogImplQt> dialog = std::make_shared<FileDialogImplQt>();
|
||||
dialog->isSaveDialog = true;
|
||||
return dialog;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Settings
|
||||
|
@ -358,11 +353,13 @@ SettingsRef GetSettings()
|
|||
return settings;
|
||||
}
|
||||
|
||||
/*******Timer Class ***************************/
|
||||
//-----------------------------------------------------------------------------
|
||||
// Timers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class TimerImplQt final : public Timer, public QObject
|
||||
{
|
||||
public:
|
||||
class TimerImplQt final : public Timer, public QObject
|
||||
{
|
||||
public:
|
||||
TimerImplQt() {}
|
||||
|
||||
void RunAfter(unsigned milliseconds) override {
|
||||
|
@ -376,23 +373,25 @@ SettingsRef GetSettings()
|
|||
#endif
|
||||
QTimer::singleShot(milliseconds, this, &TimerImplQt::runOnTimeOut);
|
||||
}
|
||||
|
||||
void runOnTimeOut() {
|
||||
if(onTimeout) {
|
||||
onTimeout();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
TimerRef CreateTimer() {
|
||||
TimerRef CreateTimer() {
|
||||
std::shared_ptr<TimerImplQt> timer = std::make_shared<TimerImplQt>();
|
||||
return timer;
|
||||
}
|
||||
}
|
||||
|
||||
/**********Menu Item*****************/
|
||||
//-----------------------------------------------------------------------------
|
||||
// Menus
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class MenuItemImplQt final : public MenuItem , public QObject {
|
||||
|
||||
public:
|
||||
class MenuItemImplQt final : public MenuItem , public QObject {
|
||||
public:
|
||||
QAction* actionItemQ;
|
||||
// MenuItemImplQt must set this pointer in order to control exculsivity
|
||||
QActionGroup* actionGroupItemQ;
|
||||
|
@ -409,29 +408,23 @@ SettingsRef GetSettings()
|
|||
}
|
||||
|
||||
void Clear() {
|
||||
|
||||
actionItemQ->disconnect();
|
||||
}
|
||||
|
||||
void SetAccelerator(KeyboardEvent accel) override {
|
||||
|
||||
QString accelKey;
|
||||
|
||||
if (accel.key == KeyboardEvent::Key::CHARACTER) {
|
||||
if (accel.chr == '\t') {
|
||||
accelKey = "Tab";
|
||||
}
|
||||
else if (accel.chr == '\x1b') {
|
||||
} else if (accel.chr == '\x1b') {
|
||||
accelKey = "Escape";
|
||||
}
|
||||
else if (accel.chr == '\x7f') {
|
||||
} else if (accel.chr == '\x7f') {
|
||||
accelKey = "Del";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
accelKey = accel.chr;
|
||||
}
|
||||
}
|
||||
else if (accel.key == KeyboardEvent::Key::FUNCTION) {
|
||||
} else if (accel.key == KeyboardEvent::Key::FUNCTION) {
|
||||
accelKey = "F" + QString::number(accel.num );
|
||||
}
|
||||
|
||||
|
@ -449,8 +442,7 @@ SettingsRef GetSettings()
|
|||
|
||||
if (false == accelMods.isEmpty()) {
|
||||
keySequence = QString(accelMods + "+" + accelKey);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
keySequence = QString(accelKey);
|
||||
}
|
||||
|
||||
|
@ -458,7 +450,6 @@ SettingsRef GetSettings()
|
|||
}
|
||||
|
||||
void SetIndicator(Indicator type) override {
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case Indicator::NONE:
|
||||
|
@ -487,20 +478,16 @@ SettingsRef GetSettings()
|
|||
actionItemQ->setChecked(active);
|
||||
}
|
||||
|
||||
public slots:
|
||||
public slots:
|
||||
void onTriggered(bool value)
|
||||
{
|
||||
if (onTrigger)
|
||||
this->onTrigger();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
/**********************Menu *************************/
|
||||
class MenuImplQt final : public Menu, public QObject {
|
||||
|
||||
public:
|
||||
class MenuImplQt final : public Menu, public QObject {
|
||||
public:
|
||||
QMenu* menuQ;
|
||||
QActionGroup* menuActionGroupQ;
|
||||
bool hasParent;
|
||||
|
@ -518,7 +505,6 @@ SettingsRef GetSettings()
|
|||
hasParent = hasParentParam;
|
||||
}
|
||||
|
||||
|
||||
MenuImplQt(QMenu* menuQParam) {
|
||||
menuQ = menuQParam;
|
||||
// The menu action group is needed for menu items that are checkable and are exclusive
|
||||
|
@ -527,13 +513,11 @@ SettingsRef GetSettings()
|
|||
hasParent = true;
|
||||
}
|
||||
|
||||
~MenuImplQt()
|
||||
{
|
||||
~MenuImplQt() {
|
||||
menuQ->disconnect();
|
||||
this->Clear();
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<MenuItem> AddItem(const std::string& label, std::function<void()> onTrigger,
|
||||
bool /*mnemonics*/) override {
|
||||
|
||||
|
@ -542,27 +526,24 @@ SettingsRef GetSettings()
|
|||
menuItem->onTrigger = onTrigger;
|
||||
menuItem->actionItemQ->setText(QString::fromStdString(label));
|
||||
// I do not think anything is needed for mnemonics flag.
|
||||
// the shortcut key sequence is set in the menuItem class and Qt acts accordingly
|
||||
// with no further activation ... I think
|
||||
// the shortcut key sequence is set in the menuItem class and Qt acts
|
||||
// accordingly with no further activation ... I think
|
||||
menuItems.push_back(menuItem);
|
||||
menuQ->addAction(menuItem->actionItemQ);
|
||||
return menuItem;
|
||||
}
|
||||
|
||||
std::shared_ptr<Menu> AddSubMenu(const std::string& label) override {
|
||||
|
||||
std::shared_ptr<MenuImplQt> subMenu = std::make_shared<MenuImplQt>(menuQ->addMenu(QString::fromStdString(label)));
|
||||
subMenus.push_back(subMenu);
|
||||
return subMenu;
|
||||
}
|
||||
|
||||
void AddSeparator() override {
|
||||
|
||||
menuQ->addSeparator();
|
||||
}
|
||||
|
||||
void PopUp() override {
|
||||
|
||||
if (true == this->hasParent)
|
||||
return;
|
||||
|
||||
|
@ -571,7 +552,6 @@ SettingsRef GetSettings()
|
|||
}
|
||||
|
||||
void Clear() override {
|
||||
|
||||
menuQ->disconnect();
|
||||
menuQ->clear();
|
||||
|
||||
|
@ -582,26 +562,21 @@ SettingsRef GetSettings()
|
|||
for(auto subMenu : subMenus) {
|
||||
subMenu->Clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public slots:
|
||||
void menuAboutToShowEvent()
|
||||
{
|
||||
public slots:
|
||||
void menuAboutToShowEvent() {
|
||||
std::cout.imbue(std::locale::classic());
|
||||
this->menuQ->repaint();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
MenuRef CreateMenu() {
|
||||
MenuRef CreateMenu() {
|
||||
return std::make_shared<MenuImplQt>(false); // false says -> menu has not Qtwidget as a parent
|
||||
}
|
||||
}
|
||||
|
||||
/******************Menu Bar********************************/
|
||||
|
||||
class MenuBarImpQt final : public MenuBar {
|
||||
|
||||
public:
|
||||
class MenuBarImpQt final : public MenuBar {
|
||||
public:
|
||||
QMenuBar* menuBarQ;
|
||||
std::vector<std::shared_ptr<MenuImplQt>> subMenus;
|
||||
std::shared_ptr<MenuItemImplQt> showPropertyBrowserMenuItem;
|
||||
|
@ -612,13 +587,11 @@ SettingsRef GetSettings()
|
|||
showPropertyBrowserMenuItem = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void findShowPropertyBrowserMenuItem() {
|
||||
// loop through the menus
|
||||
// go thorugh each item and check the key sequence
|
||||
// it should be the one with the tab key sequence
|
||||
for(size_t ii = 0; ii < subMenus.size(); ++ii) {
|
||||
|
||||
std::vector<std::shared_ptr<MenuItemImplQt>> menuItems = subMenus[ii]->menuItems;
|
||||
|
||||
for(size_t jj = 0; jj < menuItems.size(); ++jj) {
|
||||
|
@ -631,7 +604,6 @@ SettingsRef GetSettings()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
~MenuBarImpQt() {
|
||||
|
@ -639,7 +611,6 @@ SettingsRef GetSettings()
|
|||
}
|
||||
|
||||
std::shared_ptr<Menu> AddSubMenu(const std::string& label) override {
|
||||
|
||||
std::shared_ptr<MenuImplQt> menu = std::make_shared<MenuImplQt>();
|
||||
menuBarQ->addMenu(menu->menuQ);
|
||||
menu->menuQ->setTitle(QString::fromStdString(label));
|
||||
|
@ -653,31 +624,28 @@ SettingsRef GetSettings()
|
|||
subMenu->Clear();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
std::shared_ptr<MenuBarImpQt> gMenuBarQt = nullptr;
|
||||
|
||||
MenuBarRef GetOrCreateMainMenu(bool* unique) {
|
||||
std::shared_ptr<MenuBarImpQt> gMenuBarQt = nullptr;
|
||||
|
||||
MenuBarRef GetOrCreateMainMenu(bool* unique) {
|
||||
*unique = false;
|
||||
//return std::make_shared<MenuBarImpQt>();
|
||||
if(gMenuBarQt == nullptr) {
|
||||
gMenuBarQt = std::make_shared<MenuBarImpQt>();
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
gMenuBarQt->menuBarQ->clear();
|
||||
gMenuBarQt->Clear();
|
||||
}
|
||||
|
||||
return gMenuBarQt;
|
||||
}
|
||||
}
|
||||
|
||||
/***********Window ***************/
|
||||
//-----------------------------------------------------------------------------
|
||||
// Windows
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
class WindowImplQt final : public Window, public QObject {
|
||||
public:
|
||||
class WindowImplQt final : public Window, public QObject {
|
||||
public:
|
||||
QtGLMainWindow* windowGLQ;
|
||||
Window::Kind windowKind;
|
||||
std::shared_ptr<WindowImplQt> parentWindow;
|
||||
|
@ -694,11 +662,9 @@ SettingsRef GetSettings()
|
|||
connect(windowGLQ->GetGlWidget(), &GLWidget::editingDoneSignal, this, &WindowImplQt::runOnEditingDone);
|
||||
connect(windowGLQ, &QtGLMainWindow::windowClosedSignal, this, &WindowImplQt::runOnClose);
|
||||
connect(windowGLQ->GetGlWidget(), &GLWidget::tabKeyPressed, this, &WindowImplQt::processTabKeyPressed);
|
||||
|
||||
}
|
||||
|
||||
~WindowImplQt() {
|
||||
|
||||
}
|
||||
|
||||
void runOnMouseEvent(SolveSpace::Platform::MouseEvent mouseEvent){
|
||||
|
@ -775,12 +741,9 @@ SettingsRef GetSettings()
|
|||
windowGLQ->setMenuBar(gMenuBarQt->menuBarQ);
|
||||
gMenuBarQt->findShowPropertyBrowserMenuItem();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void GetContentSize(double* width, double* height) override {
|
||||
|
||||
windowGLQ->GetContentSize(width, height);
|
||||
}
|
||||
|
||||
|
@ -791,7 +754,6 @@ SettingsRef GetSettings()
|
|||
}
|
||||
|
||||
void FreezePosition(SettingsRef settings, const std::string& key) override {
|
||||
|
||||
if (!(windowGLQ->isVisible())) return;
|
||||
|
||||
int left, top, width, height;
|
||||
|
@ -890,8 +852,7 @@ SettingsRef GetSettings()
|
|||
return windowGLQ;
|
||||
}
|
||||
|
||||
public slots:
|
||||
|
||||
public slots:
|
||||
void processTabKeyPressed() {
|
||||
|
||||
if(windowGLQ->menuBar() != gMenuBarQt->menuBarQ && gMenuBarQt->showPropertyBrowserMenuItem != nullptr) {
|
||||
|
@ -899,15 +860,13 @@ SettingsRef GetSettings()
|
|||
gMenuBarQt->showPropertyBrowserMenuItem->onTriggered(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
std::shared_ptr<WindowImplQt> gGrahicWindowQt = nullptr;
|
||||
std::shared_ptr<WindowImplQt> gGrahicWindowQt = nullptr;
|
||||
|
||||
#undef CreateWindow
|
||||
WindowRef CreateWindow(Window::Kind kind,
|
||||
WindowRef CreateWindow(Window::Kind kind,
|
||||
WindowRef parentWindow) {
|
||||
|
||||
std::shared_ptr<Window> window;
|
||||
|
||||
if(Window::Kind::TOOL == kind) {
|
||||
|
@ -917,20 +876,21 @@ SettingsRef GetSettings()
|
|||
gGrahicWindowQt =std::static_pointer_cast<WindowImplQt>(window);
|
||||
}
|
||||
return window;
|
||||
}
|
||||
}
|
||||
|
||||
// 3DConnexion support.
|
||||
void Open3DConnexion() {
|
||||
//-----------------------------------------------------------------------------
|
||||
// 3DConnexion support
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
void Close3DConnexion() {
|
||||
void Open3DConnexion() {}
|
||||
void Close3DConnexion() {}
|
||||
void Request3DConnexionEventsForWindow(WindowRef window) {}
|
||||
|
||||
}
|
||||
void Request3DConnexionEventsForWindow(WindowRef window) {
|
||||
//-----------------------------------------------------------------------------
|
||||
// Application-wide APIs
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
std::vector<Platform::Path> GetFontFiles() {
|
||||
std::vector<Platform::Path> GetFontFiles() {
|
||||
#if WIN32
|
||||
std::vector<Platform::Path> fonts;
|
||||
|
||||
|
@ -971,9 +931,9 @@ SettingsRef GetSettings()
|
|||
#endif
|
||||
|
||||
return std::vector<Platform::Path>();
|
||||
}
|
||||
}
|
||||
|
||||
void OpenInBrowser(const std::string& url) {
|
||||
void OpenInBrowser(const std::string& url) {
|
||||
|
||||
std::string urlTemp = url;
|
||||
|
||||
|
@ -981,7 +941,6 @@ SettingsRef GetSettings()
|
|||
{
|
||||
urlTemp = QApplication::applicationDirPath().toStdString();
|
||||
urlTemp += "/" + url;
|
||||
|
||||
}
|
||||
|
||||
if (false == QDesktopServices::openUrl(QUrl(urlTemp.c_str(), QUrl::TolerantMode)))
|
||||
|
@ -989,38 +948,38 @@ SettingsRef GetSettings()
|
|||
std::string errorStr = "Error: unable to open URL path : " + urlTemp;
|
||||
QMessageBox::critical(0,QString("Manual Open Error"),QString::fromStdString(errorStr),QMessageBox::Ok);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QApplication* gQApp;
|
||||
QApplication* gQApp;
|
||||
|
||||
std::vector<std::string> InitGui(int argc, char** argv) {
|
||||
std::vector<std::string> InitGui(int argc, char** argv) {
|
||||
gQApp = new QApplication(argc, argv);
|
||||
std::vector<std::string> args = SolveSpace::Platform::InitCli(argc, argv);
|
||||
return args;
|
||||
}
|
||||
}
|
||||
|
||||
void RunGui() {
|
||||
void RunGui() {
|
||||
QString filePath = QString("./styleSheets/darkorange.qss");
|
||||
QFile File(filePath);
|
||||
bool opened = File.open(QFile::ReadOnly);
|
||||
|
||||
if (opened == false)
|
||||
{
|
||||
if (opened == false) {
|
||||
std::cout << "failed to open qss" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
QString StyleSheet = QLatin1String(File.readAll());
|
||||
gQApp->setStyleSheet(StyleSheet);
|
||||
}
|
||||
gQApp->exec();
|
||||
}
|
||||
void ExitGui() {
|
||||
}
|
||||
|
||||
void ExitGui() {
|
||||
// gQApp->exit;
|
||||
gQApp->quit();
|
||||
}
|
||||
void ClearGui() {
|
||||
delete gQApp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ClearGui() {
|
||||
delete gQApp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue