From f09a9ed4359ee06d068242a3a2a2357b713a510b Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sat, 25 Jan 2014 09:08:56 -0700 Subject: [PATCH] Apply a number of fixes to the main window - Fix the size issue with list boxes on mac. Was displaying the list boxes with an improper size. Turns out it was just the wrong size policies on the frame below. - Ensure the main windows are fully displayed *before* initializing subsystems. This ensures that the graphics system will properly start up on macos, and allows the glitch fix. - Made a workaround for weird QT glitch that would happen to the parent of a pure native widget that also has internal painting fully disabled. (Should definitely write an example and report this bug on the QT forums) --- obs/forms/OBSBasic.ui | 15 +++++++++++++++ obs/obs-app.cpp | 24 ++++++++--------------- obs/obs-app.hpp | 14 ++++++++------ obs/settings-basic.cpp | 31 ------------------------------ obs/settings-basic.hpp | 36 ----------------------------------- obs/settings.hpp | 34 --------------------------------- obs/window-basic-main.cpp | 18 ++++++++++++++++-- obs/window-basic-main.hpp | 12 +++++++----- obs/window-basic-settings.cpp | 4 ++++ obs/window-main.hpp | 12 ++++++++++++ 10 files changed, 70 insertions(+), 130 deletions(-) delete mode 100644 obs/settings-basic.cpp delete mode 100644 obs/settings-basic.hpp delete mode 100644 obs/settings.hpp create mode 100644 obs/window-main.hpp diff --git a/obs/forms/OBSBasic.ui b/obs/forms/OBSBasic.ui index 20227cc6d..814a01787 100644 --- a/obs/forms/OBSBasic.ui +++ b/obs/forms/OBSBasic.ui @@ -110,6 +110,12 @@ + + + 0 + 0 + + QFrame::StyledPanel @@ -186,6 +192,12 @@ + + + 0 + 0 + + QFrame::StyledPanel @@ -311,6 +323,9 @@ + + 4 + 0 diff --git a/obs/obs-app.cpp b/obs/obs-app.cpp index 8a5c9bb83..af0d4e4d4 100644 --- a/obs/obs-app.cpp +++ b/obs/obs-app.cpp @@ -165,20 +165,6 @@ bool OBSApp::InitLocale() return true; } -bool OBSApp::InitOBSBasic() -{ - try { - mainWindow = move(unique_ptr(new OBSBasic())); - mainWindow->show(); - return true; - - } catch (const char *error) { - blog(LOG_ERROR, "%s", error); - } - - return false; -} - OBSApp::OBSApp(int &argc, char **argv) : QApplication(argc, argv) { @@ -190,8 +176,8 @@ OBSApp::OBSApp(int &argc, char **argv) throw "Failed to initialize global config"; if (!InitLocale()) throw "Failed to load locale"; - if (!InitOBSBasic()) - throw "Failed to create main window"; + + mainWindow = move(unique_ptr(new OBSBasic())); } void OBSApp::GetFPSCommon(uint32_t &num, uint32_t &den) const @@ -268,6 +254,11 @@ const char *OBSApp::GetRenderModule() const return "libobs-opengl"; } +void OBSApp::OBSInit() +{ + mainWindow->OBSInit(); +} + int main(int argc, char *argv[]) { int ret = -1; @@ -276,6 +267,7 @@ int main(int argc, char *argv[]) try { OBSApp program(argc, argv); + program.OBSInit(); ret = program.exec(); } catch (const char *error) { diff --git a/obs/obs-app.hpp b/obs/obs-app.hpp index 8cd5d9d57..e0f74e4af 100644 --- a/obs/obs-app.hpp +++ b/obs/obs-app.hpp @@ -18,25 +18,25 @@ #pragma once #include -#include #include #include #include +#include "window-main.hpp" + class OBSApp : public QApplication { Q_OBJECT private: - std::string locale; - ConfigFile globalConfig; - TextLookup textLookup; - std::unique_ptr mainWindow; + std::string locale; + ConfigFile globalConfig; + TextLookup textLookup; + std::unique_ptr mainWindow; bool InitGlobalConfig(); bool InitGlobalConfigDefaults(); bool InitConfigDefaults(); bool InitLocale(); - bool InitOBSBasic(); void GetFPSCommon(uint32_t &num, uint32_t &den) const; void GetFPSInteger(uint32_t &num, uint32_t &den) const; @@ -46,6 +46,8 @@ private: public: OBSApp(int &argc, char **argv); + void OBSInit(); + inline QMainWindow *GetMainWindow() const {return mainWindow.get();} inline config_t GlobalConfig() const {return globalConfig;} diff --git a/obs/settings-basic.cpp b/obs/settings-basic.cpp deleted file mode 100644 index d33ceff91..000000000 --- a/obs/settings-basic.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/****************************************************************************** - Copyright (C) 2013 by Hugh Bailey - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -******************************************************************************/ - -#include "settings-basic.hpp" -#include "window-basic-settings.hpp" - -void BasicSettingsData::SetChanged() -{ - dataChanged = true; - window->applyButton->Enable(); -} - -void BasicSettingsData::SetSaved() -{ - dataChanged = false; - window->applyButton->Disable(); -} diff --git a/obs/settings-basic.hpp b/obs/settings-basic.hpp deleted file mode 100644 index 39a649599..000000000 --- a/obs/settings-basic.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/****************************************************************************** - Copyright (C) 2013 by Hugh Bailey - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -******************************************************************************/ - -#pragma once - -#include "settings.hpp" - -class OBSBasicSettings; - -class BasicSettingsData : public SettingsData { -protected: - OBSBasicSettings *window; - -public: - inline BasicSettingsData(OBSBasicSettings *window) : window(window) {} - - virtual void SetChanged(); - virtual void SetSaved(); -}; - -BasicSettingsData *CreateBasicGeneralSettings(OBSBasicSettings *window); -BasicSettingsData *CreateBasicVideoSettings(OBSBasicSettings *window); diff --git a/obs/settings.hpp b/obs/settings.hpp deleted file mode 100644 index 3a1e42005..000000000 --- a/obs/settings.hpp +++ /dev/null @@ -1,34 +0,0 @@ -/****************************************************************************** - Copyright (C) 2013 by Hugh Bailey - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -******************************************************************************/ - -#pragma once - -#include - -class SettingsData : public wxEvtHandler { -protected: - bool dataChanged; - -public: - inline SettingsData() : dataChanged(false) {} - virtual void Apply()=0; - - virtual void SetChanged()=0; - virtual void SetSaved()=0; - - inline bool DataChanged() const {return dataChanged;} -}; diff --git a/obs/window-basic-main.cpp b/obs/window-basic-main.cpp index 759610a34..76f99e0ff 100644 --- a/obs/window-basic-main.cpp +++ b/obs/window-basic-main.cpp @@ -18,6 +18,7 @@ #include #include +#include #include "obs-app.hpp" #include "window-basic-settings.hpp" @@ -202,10 +203,17 @@ void OBSBasic::ChannelChanged(void *data, calldata_t params) /* Main class functions */ OBSBasic::OBSBasic(QWidget *parent) - : QMainWindow (parent), - ui (new Ui::OBSBasic) + : OBSMainWindow (parent), + ui (new Ui::OBSBasic) { ui->setupUi(this); +} + +void OBSBasic::OBSInit() +{ + /* make sure it's fully displayed before doing any initialization */ + show(); + App()->processEvents(); if (!obs_startup()) throw "Failed to initialize libobs"; @@ -223,6 +231,12 @@ OBSBasic::OBSBasic(QWidget *parent) /* TODO: this is a test */ obs_load_module("test-input"); + +#ifdef _WIN32 + /* HACK: fixes a windows qt bug with native widgets with native + * repaint */ + ui->previewContainer->repaint(); +#endif } OBSBasic::~OBSBasic() diff --git a/obs/window-basic-main.hpp b/obs/window-basic-main.hpp index 8200c1ffa..7c98ff293 100644 --- a/obs/window-basic-main.hpp +++ b/obs/window-basic-main.hpp @@ -20,13 +20,13 @@ #include #include #include -#include +#include "window-main.hpp" class QListWidgetItem; #include "ui_OBSBasic.h" -class OBSBasic : public QMainWindow { +class OBSBasic : public OBSMainWindow { Q_OBJECT private: @@ -60,9 +60,9 @@ private: void LoadProject(); protected: - virtual void closeEvent(QCloseEvent *event); - virtual void changeEvent(QEvent *event); - virtual void resizeEvent(QResizeEvent *event); + virtual void closeEvent(QCloseEvent *event) override; + virtual void changeEvent(QEvent *event) override; + virtual void resizeEvent(QResizeEvent *event) override; private slots: void on_action_New_triggered(); @@ -88,6 +88,8 @@ public: explicit OBSBasic(QWidget *parent = 0); ~OBSBasic(); + virtual void OBSInit() override; + private: std::unique_ptr ui; }; diff --git a/obs/window-basic-settings.cpp b/obs/window-basic-settings.cpp index 411a294d3..987d8cec2 100644 --- a/obs/window-basic-settings.cpp +++ b/obs/window-basic-settings.cpp @@ -15,6 +15,7 @@ along with this program. If not, see . ******************************************************************************/ +#include "obs-app.hpp" #include "window-basic-settings.hpp" OBSBasicSettings::OBSBasicSettings(QWidget *parent) @@ -22,6 +23,9 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent) ui (new Ui::OBSBasicSettings) { ui->setupUi(this); + + /*ui->language = config_get_string(GetGlobalConfig(), "General", + "Language");*/ } void OBSBasicSettings::closeEvent(QCloseEvent *event) diff --git a/obs/window-main.hpp b/obs/window-main.hpp new file mode 100644 index 000000000..2f5cfbc71 --- /dev/null +++ b/obs/window-main.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include + +class OBSMainWindow : public QMainWindow { + Q_OBJECT + +public: + inline OBSMainWindow(QWidget *parent) : QMainWindow(parent) {} + + virtual void OBSInit()=0; +};