Update to v106r48 release.

byuu says:

The problems with the Windows and Qt4 ports have all been resolved,
although there's a fairly gross hack on a few Qt widgets to not destruct
once Application::quit() is called to avoid a double free crash (I'm
unsure where Qt is destructing the widgets internally.) The Cocoa port
compiles again at least, though it's bound to have endless problems. I
improved the Label painting in the GTK ports, which fixes the background
color on labels inside TabFrame widgets.

I've optimized the Makefile system even further.

I added a "redo state" command to bsnes, which is created whenever you
load the undo state. There are also hotkeys for both now, although I
don't think they're really something you want to map hotkeys to.

I moved the nall::Locale object inside hiro::Application, so that it can
be used to translate the BrowserDialog and MessageDialog window strings.

I improved the Super Game Boy emulation of `MLT_REQ`, fixing Pokemon
Yellow's custom border and probably more stuff.

Lots of other small fixes and improvements. Things are finally stable
once again after the harrowing layout redesign catastrophe.

Errata:

  - ICD::joypID should be set to 3 on reset(). joypWrite() may as well
    take uint1 instead of bool.
  - hiro/Qt: remove pWindow::setMaximumSize() comment; found a
    workaround for it
  - nall/GNUmakefile: don't set object.path if it's already set (allow
    overrides before including the file)
This commit is contained in:
Tim Allen
2018-07-16 16:16:26 +10:00
parent 6090c63958
commit 393c2395bb
78 changed files with 701 additions and 658 deletions

View File

@@ -23,6 +23,7 @@ auto pMenuRadioItem::construct() -> void {
}
auto pMenuRadioItem::destruct() -> void {
if(Application::state.quit) return; //TODO: hack
delete qtMenuRadioItem;
delete qtActionGroup;
qtMenuRadioItem = nullptr;
@@ -47,6 +48,7 @@ auto pMenuRadioItem::setGroup(sGroup group) -> void {
}
}
}
_setState();
}
auto pMenuRadioItem::setText(const string& text) -> void {

View File

@@ -23,6 +23,7 @@ auto pMenu::construct() -> void {
}
auto pMenu::destruct() -> void {
if(Application::state.quit) return; //TODO: hack
delete qtMenu;
qtMenu = nullptr;
}

View File

@@ -38,12 +38,10 @@
#include "widget/check-label.cpp"
#include "widget/combo-button.cpp"
#include "widget/combo-button-item.cpp"
#include "widget/console.cpp"
#include "widget/frame.cpp"
#include "widget/hex-edit.cpp"
#include "widget/horizontal-scroll-bar.cpp"
#include "widget/horizontal-slider.cpp"
#include "widget/icon-view.cpp"
#include "widget/label.cpp"
#include "widget/line-edit.cpp"
#include "widget/progress-bar.cpp"

View File

@@ -1,5 +1,3 @@
#include "settings.hpp"
#define Declare(Name, Base) \
p##Name(m##Name& reference) : p##Base(reference) {} \
auto self() const -> m##Name& { return (m##Name&)reference; } \
@@ -8,6 +6,7 @@
auto destruct() -> void override; \
#include "application.hpp"
#include "settings.hpp"
#include "font.hpp"
#include "desktop.hpp"
#include "monitor.hpp"

View File

@@ -15,6 +15,10 @@ static auto CreateBrush(Color color) -> QBrush {
return color ? QColor(color.red(), color.green(), color.blue()) : QBrush();
}
static auto CreateColor(Color color, QColor fallback = {}) -> QColor {
return color ? QColor(color.red(), color.green(), color.blue()) : fallback;
}
static auto CreateIcon(const image& icon, bool scale = false) -> QIcon {
if(!icon) return QIcon();
auto qtBuffer = icon;

View File

@@ -18,7 +18,7 @@ auto pCanvas::destruct() -> void {
}
auto pCanvas::minimumSize() const -> Size {
if(auto& icon = state().icon) return {(int)icon.width(), (int)icon.height()};
if(auto& icon = state().icon) return {icon.width(), icon.height()};
return {0, 0};
}

View File

@@ -10,6 +10,7 @@ auto pComboButton::construct() -> void {
}
auto pComboButton::destruct() -> void {
if(Application::state.quit) return; //TODO: hack
delete qtComboButton;
qtWidget = qtComboButton = nullptr;
}

View File

@@ -1,56 +0,0 @@
#if defined(Hiro_Console)
namespace hiro {
void pConsole::print(string text) {
}
void pConsole::reset() {
}
void pConsole::setBackgroundColor(Color color) {
QPalette palette = qtConsole->palette();
palette.setColor(QPalette::Base, QColor(color.red, color.green, color.blue));
qtConsole->setPalette(palette);
qtConsole->setAutoFillBackground(true);
}
void pConsole::setForegroundColor(Color color) {
QPalette palette = qtConsole->palette();
palette.setColor(QPalette::Text, QColor(color.red, color.green, color.blue));
qtConsole->setPalette(palette);
}
void pConsole::setPrompt(string prompt) {
}
void pConsole::constructor() {
qtWidget = qtConsole = new QtConsole(*this);
pWidget::synchronizeState();
}
void pConsole::destructor() {
delete qtConsole;
qtWidget = qtConsole = nullptr;
}
void pConsole::orphan() {
destructor();
constructor();
}
void pConsole::keyPressEvent(QKeyEvent* event) {
}
void pConsole::QtConsole::keyPressEvent(QKeyEvent* event) {
self.keyPressEvent(event);
}
void pConsole::QtConsole::keyPressEventAcknowledge(QKeyEvent* event) {
QTextEdit::keyPressEvent(event);
}
}
#endif

View File

@@ -22,6 +22,8 @@ auto pHexEdit::construct() -> void {
qtScrollBar->connect(qtScrollBar, SIGNAL(actionTriggered(int)), SLOT(onScroll()));
pWidget::construct();
setBackgroundColor(state().backgroundColor);
setForegroundColor(state().foregroundColor);
_setState();
}
@@ -39,7 +41,12 @@ auto pHexEdit::setAddress(unsigned address) -> void {
}
auto pHexEdit::setBackgroundColor(Color color) -> void {
_setState();
static auto defaultColor = qtHexEdit->palette().color(QPalette::Base);
auto palette = qtHexEdit->palette();
palette.setColor(QPalette::Base, CreateColor(color, defaultColor));
qtHexEdit->setPalette(palette);
qtHexEdit->setAutoFillBackground((bool)color);
}
auto pHexEdit::setColumns(unsigned columns) -> void {
@@ -47,7 +54,11 @@ auto pHexEdit::setColumns(unsigned columns) -> void {
}
auto pHexEdit::setForegroundColor(Color color) -> void {
_setState();
static auto defaultColor = qtHexEdit->palette().color(QPalette::Text);
auto palette = qtHexEdit->palette();
palette.setColor(QPalette::Text, color ? CreateColor(color) : defaultColor);
qtHexEdit->setPalette(palette);
}
auto pHexEdit::setLength(unsigned length) -> void {
@@ -242,29 +253,13 @@ auto pHexEdit::_scrollTo(signed position) -> void {
}
auto pHexEdit::_setState() -> void {
lock();
if(auto color = state().backgroundColor) {
QPalette palette = qtHexEdit->palette();
palette.setColor(QPalette::Base, QColor(color.red(), color.green(), color.blue()));
qtHexEdit->setPalette(palette);
qtHexEdit->setAutoFillBackground(true);
} else {
//todo
}
if(auto color = state().foregroundColor) {
QPalette palette = qtHexEdit->palette();
palette.setColor(QPalette::Text, QColor(color.red(), color.green(), color.blue()));
qtHexEdit->setPalette(palette);
} else {
//todo
}
auto lock = acquire();
//add one if last row is not equal to column length (eg only part of the row is present)
bool indivisible = state().columns == 0 || (state().length % state().columns) != 0;
qtScrollBar->setRange(0, state().length / state().columns + indivisible - state().rows);
qtScrollBar->setSliderPosition(state().address / state().columns);
qtScrollBar->setPageStep(state().rows);
update();
unlock();
}
auto QtHexEdit::keyPressEvent(QKeyEvent* event) -> void {

View File

@@ -1,152 +0,0 @@
#if defined(Hiro_IconView)
namespace hiro {
void pIconView::append() {
lock();
auto item = new QListWidgetItem(qtIconView);
unlock();
}
void pIconView::remove(unsigned selection) {
lock();
if(auto item = qtIconView->item(selection)) {
delete item;
}
unlock();
}
void pIconView::reset() {
lock();
qtIconView->clear();
unlock();
}
void pIconView::setBackgroundColor(Color color) {
QPalette palette = qtIconView->palette();
palette.setColor(QPalette::Base, QColor(color.red, color.green, color.blue));
qtIconView->setPalette(palette);
qtIconView->setAutoFillBackground(true);
}
void pIconView::setFlow(Orientation flow) {
qtIconView->setFlow(flow == Orientation::Horizontal ? QListView::LeftToRight : QListView::TopToBottom);
qtIconView->resize(qtIconView->size()); //adjust visibility of scroll bars
}
void pIconView::setForegroundColor(Color color) {
QPalette palette = qtIconView->palette();
palette.setColor(QPalette::Text, QColor(color.red, color.green, color.blue));
qtIconView->setPalette(palette);
}
void pIconView::setImage(unsigned selection, const image& image) {
if(auto item = qtIconView->item(selection)) {
item->setIcon(CreateIcon(image));
}
}
void pIconView::setOrientation(Orientation orientation) {
qtIconView->setViewMode(orientation == Orientation::Horizontal ? QListView::ListMode : QListView::IconMode);
qtIconView->setWrapping(true);
}
void pIconView::setSelected(unsigned selection, bool selected) {
lock();
if(auto item = qtIconView->item(selection)) {
item->setSelected(selected);
}
unlock();
}
void pIconView::setSelected(const vector<unsigned>& selections) {
lock();
qtIconView->clearSelection();
for(auto& selection : selections) {
if(auto item = qtIconView->item(selection)) {
item->setSelected(true);
}
}
unlock();
}
void pIconView::setSelectedAll() {
lock();
qtIconView->selectAll();
unlock();
}
void pIconView::setSelectedNone() {
lock();
qtIconView->clearSelection();
unlock();
}
void pIconView::setSingleSelection(bool singleSelection) {
qtIconView->setSelectionMode(singleSelection ? QAbstractItemView::SingleSelection : QAbstractItemView::ExtendedSelection);
}
void pIconView::setText(unsigned selection, const string& text) {
if(auto item = qtIconView->item(selection)) {
item->setText(QString::fromUtf8(text));
}
}
void pIconView::constructor() {
qtWidget = qtIconView = new QtListWidget;
qtIconView->setContextMenuPolicy(Qt::CustomContextMenu);
qtIconView->setMovement(QListView::Static);
qtIconView->setResizeMode(QListView::Adjust);
qtIconView->setSelectionRectVisible(true);
qtIconView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
qtIconView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
connect(qtIconView, SIGNAL(itemActivated(QListWidgetItem*)), SLOT(onActivate()));
connect(qtIconView, SIGNAL(itemSelectionChanged()), SLOT(onChange()));
connect(qtIconView, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(onContext()));
setFlow(iconView.state.flow);
setOrientation(iconView.state.orientation);
setSingleSelection(iconView.state.singleSelection);
}
void pIconView::destructor() {
delete qtIconView;
qtWidget = qtIconView = nullptr;
}
void pIconView::orphan() {
destructor();
constructor();
}
void pIconView::onActivate() {
if(!locked() && iconView.onActivate) iconView.onActivate();
}
void pIconView::onChange() {
for(auto& selected : iconView.state.selected) selected = false;
for(unsigned n = 0; n < qtIconView->count(); n++) {
if(auto item = qtIconView->item(n)) {
if(item->isSelected()) iconView.state.selected[n] = true;
}
}
if(!locked() && iconView.onChange) iconView.onChange();
}
void pIconView::onContext() {
if(!locked() && iconView.onContext) iconView.onContext();
}
void pIconView::QtListWidget::resizeEvent(QResizeEvent* event) {
//Qt::ScrollBarAsNeeded results in the scroll bar area being reserved from the icon viewport even when scroll bar is hidden
//this creates the appearance of an invisible gap that wastes precious screen space
//below code simulates a Qt::ScrollBarAsNeeded which uses the extra space when the scroll bar is hidden
setHorizontalScrollBarPolicy(horizontalScrollBar()->maximum() > horizontalScrollBar()->minimum() ? Qt::ScrollBarAlwaysOn : Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(verticalScrollBar()->maximum() > verticalScrollBar()->minimum() ? Qt::ScrollBarAlwaysOn : Qt::ScrollBarAlwaysOff);
return QListWidget::resizeEvent(event);
}
}
#endif

View File

@@ -28,27 +28,20 @@ auto pLabel::setAlignment(Alignment alignment) -> void {
}
auto pLabel::setBackgroundColor(Color color) -> void {
if(!color) color = self().parentWindow(true)->backgroundColor();
if(color) {
QPalette palette = qtLabel->palette();
palette.setColor(QPalette::Base, QColor(color.red(), color.green(), color.blue()));
qtLabel->setBackgroundRole(QPalette::Base);
qtLabel->setPalette(palette);
qtLabel->setAutoFillBackground(true);
} else {
//todo
}
static auto defaultColor = qtLabel->palette().color(QPalette::Base);
auto palette = qtLabel->palette();
palette.setColor(QPalette::Base, CreateColor(color, defaultColor));
qtLabel->setPalette(palette);
qtLabel->setAutoFillBackground((bool)color);
}
auto pLabel::setForegroundColor(Color color) -> void {
if(color) {
QPalette palette = qtLabel->palette();
palette.setColor(QPalette::Text, QColor(color.red(), color.green(), color.blue()));
qtLabel->setForegroundRole(QPalette::Text);
qtLabel->setPalette(palette);
} else {
//todo
}
static auto defaultColor = qtLabel->palette().color(QPalette::Text);
auto palette = qtLabel->palette();
palette.setColor(QPalette::Text, CreateColor(color, defaultColor));
qtLabel->setPalette(palette);
}
auto pLabel::setText(const string& text) -> void {

View File

@@ -8,7 +8,10 @@ auto pLineEdit::construct() -> void {
qtLineEdit->connect(qtLineEdit, SIGNAL(textEdited(const QString&)), SLOT(onChange()));
pWidget::construct();
_setState();
setBackgroundColor(state().backgroundColor);
setEditable(state().editable);
setForegroundColor(state().foregroundColor);
setText(state().text);
}
auto pLineEdit::destruct() -> void {
@@ -22,38 +25,27 @@ auto pLineEdit::minimumSize() const -> Size {
}
auto pLineEdit::setBackgroundColor(Color color) -> void {
_setState();
static auto defaultColor = qtLineEdit->palette().color(QPalette::Base);
auto palette = qtLineEdit->palette();
palette.setColor(QPalette::Base, CreateColor(color, defaultColor));
qtLineEdit->setPalette(palette);
qtLineEdit->setAutoFillBackground((bool)color);
}
auto pLineEdit::setEditable(bool editable) -> void {
_setState();
qtLineEdit->setReadOnly(!state().editable);
}
auto pLineEdit::setForegroundColor(Color color) -> void {
_setState();
static auto defaultColor = qtLineEdit->palette().color(QPalette::Text);
auto palette = qtLineEdit->palette();
palette.setColor(QPalette::Text, CreateColor(color, defaultColor));
qtLineEdit->setPalette(palette);
}
auto pLineEdit::setText(const string& text) -> void {
_setState();
}
auto pLineEdit::_setState() -> void {
if(auto color = state().backgroundColor) {
QPalette palette = qtLineEdit->palette();
palette.setColor(QPalette::Base, QColor(color.red(), color.green(), color.blue()));
qtLineEdit->setPalette(palette);
qtLineEdit->setAutoFillBackground(true);
} else {
//todo
}
qtLineEdit->setReadOnly(!state().editable);
if(auto color = state().foregroundColor) {
QPalette palette = qtLineEdit->palette();
palette.setColor(QPalette::Text, QColor(color.red(), color.green(), color.blue()));
qtLineEdit->setPalette(palette);
} else {
//todo
}
qtLineEdit->setText(QString::fromUtf8(state().text));
}

View File

@@ -11,8 +11,6 @@ struct pLineEdit : pWidget {
auto setForegroundColor(Color color) -> void;
auto setText(const string& text) -> void;
auto _setState() -> void;
QtLineEdit* qtLineEdit = nullptr;
};

View File

@@ -27,7 +27,7 @@ auto pTabFrameItem::setClosable(bool closable) -> void {
auto pTabFrameItem::setGeometry(Geometry geometry) -> void {
if(auto& sizable = state().sizable) {
auto offset = qtTabFrameItem->geometry();
geometry.setPosition({0, 0});
geometry.setPosition();
geometry.setWidth(geometry.width() - (geometry.width() - offset.width()));
geometry.setHeight(geometry.height() - (geometry.height() - offset.height()));
sizable->setGeometry(geometry);
@@ -72,7 +72,7 @@ auto pTabFrameItem::_setState() -> void {
geometry.setWidth(geometry.width() - (geometry.width() - offset.width()));
geometry.setHeight(geometry.height() - (geometry.height() - offset.height()));
sizable->setGeometry(geometry);
sizable->setVisible(sizable->visible(true));
sizable->setVisible(sizable->visible());
}
}
}

View File

@@ -11,6 +11,7 @@ auto pTabFrame::construct() -> void {
}
auto pTabFrame::destruct() -> void {
if(Application::state.quit) return; //TODO: hack
delete qtTabFrame;
qtWidget = qtTabFrame = nullptr;
}

View File

@@ -52,7 +52,7 @@ auto pTableViewItem::_parent() -> maybe<pTableView&> {
auto pTableViewItem::_setState() -> void {
if(auto parent = _parent()) {
parent->lock();
auto lock = parent->acquire();
qtItem->setSelected(state().selected);
if(state().selected) {
parent->qtTableView->setCurrentItem(qtItem);

View File

@@ -32,6 +32,7 @@ auto pTableView::construct() -> void {
}
auto pTableView::destruct() -> void {
if(Application::state.quit) return; //TODO: hack
delete qtTableViewDelegate;
delete qtTableView;
qtWidget = qtTableView = nullptr;
@@ -99,15 +100,13 @@ auto pTableView::setAlignment(Alignment alignment) -> void {
}
auto pTableView::setBackgroundColor(Color color) -> void {
if(color) {
QPalette palette = qtTableView->palette();
palette.setColor(QPalette::Base, QColor(color.red(), color.green(), color.blue()));
palette.setColor(QPalette::AlternateBase, QColor(max(0, (signed)color.red() - 17), max(0, (signed)color.green() - 17), max(0, (signed)color.blue() - 17)));
qtTableView->setPalette(palette);
qtTableView->setAutoFillBackground(true);
} else {
//todo: set default color
}
//note: QPalette::AlternateBase can be used for alternating row colors
static auto defaultColor = qtTableView->palette().color(QPalette::Base);
auto palette = qtTableView->palette();
palette.setColor(QPalette::Base, CreateColor(color, defaultColor));
qtTableView->setPalette(palette);
qtTableView->setAutoFillBackground((bool)color);
}
auto pTableView::setBatchable(bool batchable) -> void {
@@ -121,13 +120,12 @@ auto pTableView::setBordered(bool bordered) -> void {
}
auto pTableView::setForegroundColor(Color color) -> void {
if(color) {
QPalette palette = qtTableView->palette();
palette.setColor(QPalette::Text, QColor(color.red(), color.green(), color.blue()));
qtTableView->setPalette(palette);
} else {
//todo: set default color
}
static auto defaultColor = qtTableView->palette().color(QPalette::Text);
auto palette = qtTableView->palette();
palette.setColor(QPalette::Text, CreateColor(color, defaultColor));
qtTableView->setPalette(palette);
qtTableView->setAutoFillBackground((bool)color);
}
//called on resize/show events

View File

@@ -7,16 +7,24 @@ auto pTextEdit::construct() -> void {
qtTextEdit->connect(qtTextEdit, SIGNAL(textChanged()), SLOT(onChange()));
pWidget::construct();
setBackgroundColor(state().backgroundColor);
setForegroundColor(state().foregroundColor);
_setState();
}
auto pTextEdit::destruct() -> void {
if(Application::state.quit) return; //TODO: hack
delete qtTextEdit;
qtWidget = qtTextEdit = nullptr;
}
auto pTextEdit::setBackgroundColor(Color color) -> void {
_setState();
static auto defaultColor = qtTextEdit->palette().color(QPalette::Base);
auto palette = qtTextEdit->palette();
palette.setColor(QPalette::Base, CreateColor(color, defaultColor));
qtTextEdit->setPalette(palette);
qtTextEdit->setAutoFillBackground((bool)color);
}
auto pTextEdit::setCursor(Cursor cursor) -> void {
@@ -28,7 +36,11 @@ auto pTextEdit::setEditable(bool editable) -> void {
}
auto pTextEdit::setForegroundColor(Color color) -> void {
_setState();
static auto defaultColor = qtTextEdit->palette().color(QPalette::Text);
auto palette = qtTextEdit->palette();
palette.setColor(QPalette::Text, CreateColor(color, defaultColor));
qtTextEdit->setPalette(palette);
}
auto pTextEdit::setText(const string& text) -> void {
@@ -44,14 +56,6 @@ auto pTextEdit::text() const -> string {
}
auto pTextEdit::_setState() -> void {
if(auto color = state().backgroundColor) {
QPalette palette = qtTextEdit->palette();
palette.setColor(QPalette::Base, QColor(color.red(), color.green(), color.blue()));
qtTextEdit->setPalette(palette);
qtTextEdit->setAutoFillBackground(true);
} else {
//todo
}
QTextCursor cursor = qtTextEdit->textCursor();
signed lastCharacter = strlen(qtTextEdit->toPlainText().toUtf8().constData());
cursor.setPosition(max(0, min(lastCharacter, state().cursor.offset())));
@@ -61,13 +65,6 @@ auto pTextEdit::_setState() -> void {
? Qt::TextEditorInteraction
: Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse
);
if(auto color = state().foregroundColor) {
QPalette palette = qtTextEdit->palette();
palette.setColor(QPalette::Text, QColor(color.red(), color.green(), color.blue()));
qtTextEdit->setPalette(palette);
} else {
//todo
}
qtTextEdit->setWordWrapMode(state().wordWrap ? QTextOption::WordWrap : QTextOption::NoWrap);
qtTextEdit->setHorizontalScrollBarPolicy(state().wordWrap ? Qt::ScrollBarAlwaysOff : Qt::ScrollBarAlwaysOn);
qtTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);

View File

@@ -44,6 +44,7 @@ auto pWindow::construct() -> void {
}
auto pWindow::destruct() -> void {
if(Application::state.quit) return; //TODO: hack
delete qtStatusBar;
delete qtContainer;
delete qtMenuBar;
@@ -90,14 +91,14 @@ auto pWindow::remove(sStatusBar statusBar) -> void {
}
auto pWindow::setBackgroundColor(Color color) -> void {
if(color) {
QPalette palette;
palette.setColor(QPalette::Background, QColor(color.red(), color.green(), color.blue() /*, color.alpha() */));
qtContainer->setPalette(palette);
qtContainer->setAutoFillBackground(true);
//translucency results are very unpleasant without a compositor; so disable for now
//qtWindow->setAttribute(Qt::WA_TranslucentBackground, color.alpha() != 255);
}
static auto defaultColor = qtContainer->palette().color(QPalette::Background);
auto palette = qtContainer->palette();
palette.setColor(QPalette::Background, CreateColor(color, defaultColor));
qtContainer->setPalette(palette);
qtContainer->setAutoFillBackground((bool)color);
//translucency results are very unpleasant without a compositor; so disable for now
//qtWindow->setAttribute(Qt::WA_TranslucentBackground, color && color.alpha() != 255);
}
auto pWindow::setDismissable(bool dismissable) -> void {
@@ -133,7 +134,7 @@ auto pWindow::setFullScreen(bool fullScreen) -> void {
}
auto pWindow::setGeometry(Geometry geometry) -> void {
lock();
auto lock = acquire();
Application::processEvents();
#if HIRO_QT==4
QApplication::syncX();
@@ -145,13 +146,14 @@ auto pWindow::setGeometry(Geometry geometry) -> void {
qtWindow->move(geometry.x() - frameMargin().x(), geometry.y() - frameMargin().y());
//qtWindow->adjustSize() fails if larger than 2/3rds screen size
qtWindow->resize(qtWindow->sizeHint());
qtContainer->setMinimumSize(1, 1);
if(state().resizable) {
//required to allow shrinking window from default size
qtWindow->setMinimumSize(1, 1);
qtContainer->setMinimumSize(1, 1);
setMaximumSize(state().maximumSize);
setMinimumSize(state().minimumSize);
} else {
setMaximumSize(geometry.size());
setMinimumSize(geometry.size());
}
unlock();
}
auto pWindow::setMaximized(bool maximized) -> void {
@@ -159,7 +161,14 @@ auto pWindow::setMaximized(bool maximized) -> void {
}
auto pWindow::setMaximumSize(Size size) -> void {
//todo
static auto maximumSize = qtWindow->maximumSize();
if(size) {
//once this is called, no matter what the size is, Qt will no longer allow the window to be maximized
qtWindow->setMaximumSize(size.width(), size.height() + _menuHeight() + _statusHeight());
} else {
qtWindow->setMaximumSize(maximumSize);
}
}
auto pWindow::setMinimized(bool minimized) -> void {
@@ -167,7 +176,7 @@ auto pWindow::setMinimized(bool minimized) -> void {
}
auto pWindow::setMinimumSize(Size size) -> void {
//todo
qtWindow->setMinimumSize(size.width(), size.height() + _menuHeight() + _statusHeight());
}
auto pWindow::setModal(bool modal) -> void {
@@ -200,7 +209,7 @@ auto pWindow::setResizable(bool resizable) -> void {
}
auto pWindow::setTitle(const string& text) -> void {
qtWindow->setWindowTitle(QString::fromUtf8(text));
qtWindow->setWindowTitle(text ? QString::fromUtf8(text) : " ");
}
auto pWindow::setVisible(bool visible) -> void {
@@ -220,8 +229,10 @@ auto pWindow::_append(mWidget& widget) -> void {
}
auto pWindow::_menuHeight() const -> uint {
if(!qtMenuBar->isVisible()) return 0;
return settings.geometry.menuHeight + _menuTextHeight();
if(auto& menuBar = state().menuBar) {
if(menuBar->visible()) return settings.geometry.menuHeight + _menuTextHeight();
}
return 0;
}
auto pWindow::_menuTextHeight() const -> uint {
@@ -235,8 +246,10 @@ auto pWindow::_menuTextHeight() const -> uint {
}
auto pWindow::_statusHeight() const -> uint {
if(!qtStatusBar->isVisible()) return 0;
return settings.geometry.statusHeight + _statusTextHeight();
if(auto& statusBar = state().statusBar) {
if(statusBar->visible()) return settings.geometry.statusHeight + _statusTextHeight();
}
return 0;
}
auto pWindow::_statusTextHeight() const -> uint {
@@ -314,7 +327,7 @@ auto QtWindow::keyReleaseEvent(QKeyEvent* event) -> void {
//if(sym != Keyboard::Keycode::None && self.window.onKeyRelease) self.window.onKeyRelease(sym);
}
auto QtWindow::resizeEvent(QResizeEvent*) -> void {
auto QtWindow::resizeEvent(QResizeEvent* event) -> void {
if(!p.locked() && !p.state().fullScreen && p.qtWindow->isVisible()) {
p.state().geometry.setSize({
p.qtContainer->geometry().width(),
@@ -334,8 +347,8 @@ auto QtWindow::resizeEvent(QResizeEvent*) -> void {
auto QtWindow::sizeHint() const -> QSize {
uint width = p.state().geometry.width();
uint height = p.state().geometry.height();
if(p.qtMenuBar->isVisible()) height += settings.geometry.menuHeight;
if(p.qtStatusBar->isVisible()) height += settings.geometry.statusHeight;
height += p._menuHeight();
height += p._statusHeight();
return QSize(width, height);
}