Update to v094r43 release.

byuu says:

Updated to compile with all of the new hiro changes. My next step is to
write up hiro API documentation, and move the API from alpha (constantly
changing) to beta (rarely changing), in preparation for the first stable
release (backward-compatible changes only.)

Added "--fullscreen" command-line option. I like this over
a configuration file option. Lets you use the emulator in both modes
without having to modify the config file each time.

Also enhanced the command-line game loading. You can now use any of
these methods:

    higan /path/to/game-folder.sfc
    higan /path/to/game-folder.sfc/
    higan /path/to/game-folder.sfc/program.rom

The idea is to support launchers that insist on loading files only.

Technically, the file can be any name (manifest.bml also works); the
only criteria is that the file actually exists and is a file, and not
a directory. This is a requirement to support the first version (a
directory lacking the trailing / identifier), because I don't want my
nall::string class to query the file system to determine if the string
is an actual existing file or directory for its pathname() / dirname()
functions.

Anyway, every game folder I've made so far has program.rom, and that's
very unlikely to change, so this should be fine.

Now, of course, if you drop a regular "game.sfc" file on the emulator,
it won't even try to load it, unless it's in a folder that ends in .fc,
.sfc, etc. In which case, it'll bail out immediately by being unable to
produce a manifest for what is obviously not really a game folder.
This commit is contained in:
Tim Allen
2015-08-30 12:08:26 +10:00
parent c45633550e
commit 0c87bdabed
230 changed files with 1939 additions and 1408 deletions

View File

@@ -12,7 +12,7 @@ auto pAction::setEnabled(bool enabled) -> void {
_setState();
}
auto pAction::setFont(const string& font) -> void {
auto pAction::setFont(const Font& font) -> void {
_setState();
}

View File

@@ -6,7 +6,7 @@ struct pAction : pObject {
Declare(Action, Object)
auto setEnabled(bool enabled) -> void override;
auto setFont(const string& font) -> void override;
auto setFont(const Font& font) -> void override;
auto setVisible(bool visible) -> void override;
auto _parentMenu() -> maybe<pMenu&>;

View File

@@ -22,7 +22,7 @@ auto pMenuItem::destruct() -> void {
qtMenuItem = nullptr;
}
auto pMenuItem::setIcon(const image& icon) -> void {
auto pMenuItem::setImage(const Image& icon) -> void {
_setState();
}
@@ -31,7 +31,7 @@ auto pMenuItem::setText(const string& text) -> void {
}
auto pMenuItem::_setState() -> void {
qtMenuItem->setIcon(CreateIcon(state().icon));
qtMenuItem->setIcon(CreateImage(state().image));
qtMenuItem->setText(state().text);
}

View File

@@ -5,7 +5,7 @@ namespace hiro {
struct pMenuItem : pAction {
Declare(MenuItem, Action)
auto setIcon(const image& icon) -> void;
auto setImage(const Image& image) -> void;
auto setText(const string& text) -> void;
auto _setState() -> void override;

View File

@@ -18,6 +18,7 @@ auto pMenuRadioItem::construct() -> void {
parent->qtPopupMenu->addAction(qtMenuRadioItem);
}
setGroup(state().group);
_setState();
}
@@ -33,7 +34,19 @@ auto pMenuRadioItem::setChecked() -> void {
}
auto pMenuRadioItem::setGroup(sGroup group) -> void {
_setState();
bool first = true;
if(auto& group = state().group) {
for(auto& weak : group->state.objects) {
if(auto object = weak.acquire()) {
if(auto menuRadioItem = dynamic_cast<mMenuRadioItem*>(object.data())) {
if(auto self = menuRadioItem->self()) {
self->qtMenuRadioItem->setChecked(menuRadioItem->state.checked = first);
first = false;
}
}
}
}
}
}
auto pMenuRadioItem::setText(const string& text) -> void {
@@ -41,7 +54,7 @@ auto pMenuRadioItem::setText(const string& text) -> void {
}
auto pMenuRadioItem::_setState() -> void {
if(auto group = state().group) {
if(auto& group = state().group) {
if(auto object = group->object(0)) {
if(auto menuRadioItem = dynamic_cast<mMenuRadioItem*>(object.data())) {
if(auto self = menuRadioItem->self()) {
@@ -56,7 +69,7 @@ auto pMenuRadioItem::_setState() -> void {
auto QtMenuRadioItem::onActivate() -> void {
if(p.state().checked) return;
p.state().checked = true;
p.self().setChecked();
p.self().doActivate();
}

View File

@@ -33,7 +33,7 @@ auto pMenu::append(sAction action) -> void {
auto pMenu::remove(sAction action) -> void {
}
auto pMenu::setIcon(const image& icon) -> void {
auto pMenu::setImage(const Image& image) -> void {
_setState();
}
@@ -44,7 +44,7 @@ auto pMenu::setText(const string& text) -> void {
auto pMenu::_setState() -> void {
qtMenu->setEnabled(self().enabled());
qtMenu->setFont(pFont::create(self().font(true)));
qtMenu->setIcon(CreateIcon(state().icon));
qtMenu->setIcon(CreateImage(state().image));
qtMenu->setTitle(QString::fromUtf8(state().text));
qtMenu->menuAction()->setVisible(self().visible());

View File

@@ -7,7 +7,7 @@ struct pMenu : public pAction {
auto append(sAction action) -> void;
auto remove(sAction action) -> void;
auto setIcon(const image& icon) -> void;
auto setImage(const Image& image) -> void;
auto setText(const string& text) -> void;
auto _setState() -> void override;

View File

@@ -2,61 +2,34 @@
namespace hiro {
auto pFont::serif(unsigned size, string style) -> string {
if(size == 0) size = 8;
if(style == "") style = "Normal";
return {"Serif, ", size, ", ", style};
}
auto pFont::sans(unsigned size, string style) -> string {
if(size == 0) size = 8;
if(style == "") style = "Normal";
return {"Sans, ", size, ", ", style};
}
auto pFont::monospace(unsigned size, string style) -> string {
if(size == 0) size = 8;
if(style == "") style = "Normal";
return {"Liberation Mono, ", size, ", ", style};
}
auto pFont::size(string font, string text) -> Size {
auto pFont::size(const Font& font, const string& text) -> Size {
return pFont::size(pFont::create(font), text);
}
auto pFont::create(string description) -> QFont {
lstring part = description.split(",", 2L).strip();
string family = "Sans";
unsigned size = 8u;
bool bold = false;
bool italic = false;
if(part[0] != "") family = part[0];
if(part.size() >= 2) size = decimal(part[1]);
if(part.size() >= 3) bold = (bool)part[2].find("Bold");
if(part.size() >= 3) italic = (bool)part[2].find("Italic");
QFont qtFont;
qtFont.setFamily(family);
qtFont.setPointSize(size);
if(bold) qtFont.setBold(true);
if(italic) qtFont.setItalic(true);
return qtFont;
}
auto pFont::size(const QFont& qtFont, const string& text) -> Size {
QFontMetrics metrics(qtFont);
lstring lines;
lines.split(text ? text : " ", "\n");
unsigned maxWidth = 0;
signed maxWidth = 0;
auto lines = text.split("\n");
for(auto& line : lines) {
maxWidth = max(maxWidth, metrics.width(line));
}
return {maxWidth, metrics.height() * (signed)lines.size()};
}
return Size().setWidth(maxWidth).setHeight(metrics.height() * lines.size());
auto pFont::family(const string& family) -> string {
if(family == Font::Sans ) return "Sans";
if(family == Font::Serif) return "Serif";
if(family == Font::Mono ) return "Liberation Mono";
return family ? family : "Sans";
}
auto pFont::create(const Font& font) -> QFont {
QFont qtFont;
qtFont.setFamily(family(font.family()));
qtFont.setPointSize(font.size() ? font.size() : 8);
qtFont.setBold(font.bold());
qtFont.setItalic(font.italic());
return qtFont;
}
}

View File

@@ -3,13 +3,10 @@
namespace hiro {
struct pFont {
static auto serif(unsigned size, string style) -> string;
static auto sans(unsigned size, string style) -> string;
static auto monospace(unsigned size, string style) -> string;
static auto size(string font, string text) -> Size;
static auto create(string description) -> QFont;
static auto size(const Font& font, const string& text) -> Size;
static auto size(const QFont& qtFont, const string& text) -> Size;
static auto family(const string& family) -> string;
static auto create(const Font& font) -> QFont;
};
}

View File

@@ -1,13 +0,0 @@
#if defined(Hiro_Hotkey)
namespace hiro {
auto pHotkey::construct() -> void {
}
auto pHotkey::destruct() -> void {
}
}
#endif

View File

@@ -1,11 +0,0 @@
#if defined(Hiro_Hotkey)
namespace hiro {
struct pHotkey : pObject {
Declare(Hotkey, Object)
};
}
#endif

View File

@@ -19,7 +19,7 @@ auto pMenuBar::setEnabled(bool enabled) -> void {
_setState();
}
auto pMenuBar::setFont(const string& font) -> void {
auto pMenuBar::setFont(const Font& font) -> void {
_setState();
}

View File

@@ -8,7 +8,7 @@ struct pMenuBar : pObject {
auto append(sMenu menu) -> void;
auto remove(sMenu menu) -> void;
auto setEnabled(bool enabled) -> void override;
auto setFont(const string& font) -> void override;
auto setFont(const Font& font) -> void override;
auto setVisible(bool visible) -> void override;
auto _parent() -> maybe<pWindow&>;

View File

@@ -24,7 +24,7 @@ auto pObject::setEnabled(bool enabled) -> void {
auto pObject::setFocused() -> void {
}
auto pObject::setFont(const string& font) -> void {
auto pObject::setFont(const Font& font) -> void {
}
auto pObject::setVisible(bool visible) -> void {

View File

@@ -15,7 +15,7 @@ struct pObject {
virtual auto reset() -> void;
virtual auto setEnabled(bool enabled) -> void;
virtual auto setFocused() -> void;
virtual auto setFont(const string& font) -> void;
virtual auto setFont(const Font& font) -> void;
virtual auto setVisible(bool visible) -> void;
auto locked() const -> bool { return locks != 0; }

View File

@@ -16,7 +16,6 @@
#include "object.cpp"
#include "group.cpp"
#include "hotkey.cpp"
#include "timer.cpp"
#include "window.cpp"
#include "status-bar.cpp"

View File

@@ -19,7 +19,6 @@
#include "object.hpp"
#include "group.hpp"
#include "hotkey.hpp"
#include "timer.hpp"
#include "window.hpp"
#include "status-bar.hpp"

View File

@@ -20,7 +20,7 @@ auto pPopupMenu::remove(sAction action) -> void {
_setState();
}
auto pPopupMenu::setFont(const string& font) -> void {
auto pPopupMenu::setFont(const Font& font) -> void {
_setState();
}

View File

@@ -7,7 +7,7 @@ struct pPopupMenu : pObject {
auto append(sAction action) -> void;
auto remove(sAction action) -> void;
auto setFont(const string& font) -> void override;
auto setFont(const Font& font) -> void override;
auto setVisible(bool visible) -> void override;
auto _setState() -> void;

View File

@@ -13,7 +13,7 @@ auto pStatusBar::setEnabled(bool enabled) -> void {
_setState();
}
auto pStatusBar::setFont(const string& font) -> void {
auto pStatusBar::setFont(const Font& font) -> void {
_setState();
}

View File

@@ -6,7 +6,7 @@ struct pStatusBar : pObject {
Declare(StatusBar, Object)
auto setEnabled(bool enabled) -> void override;
auto setFont(const string& font) -> void override;
auto setFont(const Font& font) -> void override;
auto setText(const string& text) -> void;
auto setVisible(bool visible) -> void override;

View File

@@ -24,6 +24,12 @@ static auto CreateIcon(const nall::image& icon, bool scale = false) -> QIcon {
return QIcon(QPixmap::fromImage(qtImage));
}
static auto CreateImage(const Image& image, bool scale = false) -> QIcon {
if(!image) return QIcon();
QImage qtImage((const uint8_t*)image.data(), image.width(), image.height(), QImage::Format_ARGB32);
return QIcon(QPixmap::fromImage(qtImage));
}
static auto DropPaths(QDropEvent* event) -> lstring {
QList<QUrl> urls = event->mimeData()->urls();
if(urls.size() == 0) return {};

View File

@@ -8,7 +8,7 @@ auto pButton::construct() -> void {
qtButton->connect(qtButton, SIGNAL(released()), SLOT(onActivate()));
setBordered(state().bordered);
setIcon(state().icon);
setImage(state().image);
setOrientation(state().orientation);
setText(state().text);
@@ -21,16 +21,16 @@ auto pButton::destruct() -> void {
}
auto pButton::minimumSize() const -> Size {
auto size = pFont::size(qtWidget->font(), state().text);
auto size = pFont::size(qtWidget->font(), state().text ? state().text : " ");
if(state().orientation == Orientation::Horizontal) {
size.setWidth(size.width() + state().icon.width());
size.setHeight(max(state().icon.height(), size.height()));
size.setWidth(size.width() + state().image.width());
size.setHeight(max(state().image.height(), size.height()));
}
if(state().orientation == Orientation::Vertical) {
size.setWidth(max(state().icon.width(), size.width()));
size.setHeight(size.height() + state().icon.height());
size.setWidth(max(state().image.width(), size.width()));
size.setHeight(size.height() + state().image.height());
}
return {size.width() + (state().text ? 20 : 12), size.height() + 12};
@@ -40,9 +40,9 @@ auto pButton::setBordered(bool bordered) -> void {
qtButton->setAutoRaise(!bordered);
}
auto pButton::setIcon(const image& icon) -> void {
qtButton->setIconSize(QSize(icon.width(), icon.height()));
qtButton->setIcon(CreateIcon(icon));
auto pButton::setImage(const Image& image) -> void {
qtButton->setIconSize(QSize(image.width(), image.height()));
qtButton->setIcon(CreateImage(image));
qtButton->setStyleSheet("text-align: top;");
}

View File

@@ -7,7 +7,7 @@ struct pButton : pWidget {
auto minimumSize() const -> Size override;
auto setBordered(bool bordered) -> void;
auto setIcon(const image& icon) -> void;
auto setImage(const Image& image) -> void;
auto setOrientation(Orientation orientation) -> void;
auto setText(const string& text) -> void;

View File

@@ -18,16 +18,11 @@ auto pCanvas::destruct() -> void {
}
auto pCanvas::minimumSize() const -> Size {
return {max(0, state().size.width()), max(0, state().size.height())};
if(auto& image = state().image) return image.size();
return {0, 0};
}
auto pCanvas::setColor(Color color) -> void {
mode = Mode::Color;
update();
}
auto pCanvas::setData(Size size) -> void {
mode = Mode::Data;
update();
}
@@ -40,13 +35,11 @@ auto pCanvas::setGeometry(Geometry geometry) -> void {
pWidget::setGeometry(geometry);
}
auto pCanvas::setGradient(Color topLeft, Color topRight, Color bottomLeft, Color bottomRight) -> void {
mode = Mode::Gradient;
auto pCanvas::setGradient(Gradient gradient) -> void {
update();
}
auto pCanvas::setIcon(const image& icon) -> void {
mode = Mode::Icon;
auto pCanvas::setImage(const Image& image) -> void {
update();
}
@@ -59,14 +52,13 @@ auto pCanvas::_rasterize() -> void {
signed width = 0;
signed height = 0;
if(mode == Mode::Color || mode == Mode::Gradient) {
if(auto& image = state().image) {
width = image.width();
height = image.height();
} else {
width = pSizable::state().geometry.width();
height = pSizable::state().geometry.height();
} else {
width = state().size.width();
height = state().size.height();
}
if(width <= 0 || height <= 0) return;
if(width != qtImageWidth || height != qtImageHeight) _release();
@@ -76,30 +68,18 @@ auto pCanvas::_rasterize() -> void {
if(!qtImage) qtImage = new QImage(width, height, QImage::Format_ARGB32);
auto buffer = (uint32_t*)qtImage->bits();
if(mode == Mode::Color) {
if(auto& image = state().image) {
memory::copy(buffer, state().image.data(), width * height * sizeof(uint32_t));
} else if(auto& gradient = state().gradient) {
auto& colors = gradient.state.colors;
nall::image fill;
fill.allocate(width, height);
fill.gradient(colors[0].value(), colors[1].value(), colors[2].value(), colors[3].value());
memory::copy(buffer, fill.data(), fill.size());
} else {
uint32_t color = state().color.value();
for(auto n : range(width * height)) buffer[n] = color;
}
if(mode == Mode::Gradient) {
image fill;
fill.allocate(width, height);
fill.gradient(
state().gradient[0].value(), state().gradient[1].value(), state().gradient[2].value(), state().gradient[3].value()
);
memory::copy(buffer, fill.data(), fill.size());
}
if(mode == Mode::Icon) {
auto icon = state().icon;
icon.scale(width, height);
icon.transform();
memory::copy(buffer, icon.data(), icon.size());
}
if(mode == Mode::Data) {
memory::copy(buffer, state().data.data(), state().data.size() * sizeof(uint32_t));
}
}
auto pCanvas::_release() -> void {

View File

@@ -7,15 +7,12 @@ struct pCanvas : pWidget {
auto minimumSize() const -> Size;
auto setColor(Color color) -> void;
auto setData(Size size) -> void;
auto setDroppable(bool droppable) -> void;
auto setGeometry(Geometry geometry) -> void;
auto setGradient(Color topLeft, Color topRight, Color bottomLeft, Color bottomRight) -> void;
auto setIcon(const image& icon) -> void;
auto setGradient(Gradient gradient) -> void;
auto setImage(const Image& image) -> void;
auto update() -> void;
enum class Mode : unsigned { Color, Data, Gradient, Icon };
auto _rasterize() -> void;
auto _release() -> void;
@@ -23,7 +20,6 @@ struct pCanvas : pWidget {
QImage* qtImage = nullptr;
unsigned qtImageWidth = 0;
unsigned qtImageHeight = 0;
Mode mode = Mode::Color;
};
}

View File

@@ -21,13 +21,13 @@ auto pCheckButton::minimumSize() const -> Size {
auto size = pFont::size(qtWidget->font(), state().text);
if(state().orientation == Orientation::Horizontal) {
size.setWidth(size.width() + state().icon.width());
size.setHeight(max(state().icon.height(), size.height()));
size.setWidth(size.width() + state().image.width());
size.setHeight(max(state().image.height(), size.height()));
}
if(state().orientation == Orientation::Vertical) {
size.setWidth(max(state().icon.width(), size.width()));
size.setHeight(size.height() + state().icon.height());
size.setWidth(max(state().image.width(), size.width()));
size.setHeight(size.height() + state().image.height());
}
return {size.width() + 20, size.height() + 12};
@@ -41,7 +41,7 @@ auto pCheckButton::setChecked(bool checked) -> void {
_setState();
}
auto pCheckButton::setIcon(const image& icon) -> void {
auto pCheckButton::setImage(const Image& image) -> void {
_setState();
}
@@ -57,8 +57,8 @@ auto pCheckButton::_setState() -> void {
lock();
qtCheckButton->setAutoRaise(!state().bordered);
qtCheckButton->setChecked(state().checked);
qtCheckButton->setIconSize(QSize(state().icon.width(), state().icon.height()));
qtCheckButton->setIcon(CreateIcon(state().icon));
qtCheckButton->setIconSize(QSize(state().image.width(), state().image.height()));
qtCheckButton->setIcon(CreateImage(state().image));
qtCheckButton->setStyleSheet("text-align: top;");
switch(state().orientation) {
case Orientation::Horizontal: qtCheckButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); break;

View File

@@ -8,7 +8,7 @@ struct pCheckButton : pWidget {
auto minimumSize() const -> Size override;
auto setBordered(bool bordered) -> void;
auto setChecked(bool checked) -> void;
auto setIcon(const image& icon) -> void;
auto setImage(const Image& image) -> void;
auto setOrientation(Orientation orientation) -> void;
auto setText(const string& text) -> void;

View File

@@ -19,7 +19,7 @@ auto pComboButtonItem::destruct() -> void {
}
}
auto pComboButtonItem::setIcon(const image& icon) -> void {
auto pComboButtonItem::setImage(const Image& image) -> void {
_setState();
}
@@ -40,7 +40,7 @@ auto pComboButtonItem::_parent() -> maybe<pComboButton&> {
auto pComboButtonItem::_setState() -> void {
if(auto parent = _parent()) {
parent->qtComboButton->setItemIcon(self().offset(), CreateIcon(state().icon));
parent->qtComboButton->setItemIcon(self().offset(), CreateImage(state().image));
if(state().selected) parent->qtComboButton->setCurrentIndex(self().offset());
parent->qtComboButton->setItemText(self().offset(), QString::fromUtf8(state().text));
}

View File

@@ -5,7 +5,7 @@ namespace hiro {
struct pComboButtonItem : pObject {
Declare(ComboButtonItem, Object)
auto setIcon(const image& icon) -> void;
auto setImage(const Image& image) -> void;
auto setSelected() -> void;
auto setText(const string& text) -> void;

View File

@@ -32,7 +32,7 @@ auto pListViewCell::setForegroundColor(Color color) -> void {
_setState();
}
auto pListViewCell::setIcon(const image& icon) -> void {
auto pListViewCell::setImage(const Image& image) -> void {
_setState();
}
@@ -60,7 +60,7 @@ auto pListViewCell::_setState() -> void {
}
parent->qtItem->setFont(self().offset(), pFont::create(self().font(true)));
parent->qtItem->setForeground(self().offset(), CreateBrush(self().foregroundColor(true)));
parent->qtItem->setIcon(self().offset(), CreateIcon(state().icon));
parent->qtItem->setIcon(self().offset(), CreateImage(state().image));
parent->qtItem->setText(self().offset(), QString::fromUtf8(state().text));
parent->qtItem->setTextAlignment(self().offset(), CalculateAlignment(self().alignment(true)));
grandparent->unlock();

View File

@@ -11,7 +11,7 @@ struct pListViewCell : pObject {
auto setChecked(bool checked) -> void;
auto setFont(const string& font) -> void;
auto setForegroundColor(Color color) -> void;
auto setIcon(const image& icon) -> void;
auto setImage(const Image& image) -> void;
auto setText(const string& text) -> void;
auto _parent() -> maybe<pListViewItem&>;

View File

@@ -28,7 +28,7 @@ auto pListViewColumn::setExpandable(bool expandable) -> void {
_setState();
}
auto pListViewColumn::setFont(const string& font) -> void {
auto pListViewColumn::setFont(const Font& font) -> void {
_setState();
}
@@ -40,7 +40,7 @@ auto pListViewColumn::setHorizontalAlignment(double alignment) -> void {
_setState();
}
auto pListViewColumn::setIcon(const image& icon) -> void {
auto pListViewColumn::setImage(const Image& image) -> void {
//unsupported
}

View File

@@ -10,10 +10,10 @@ struct pListViewColumn : pObject {
auto setBackgroundColor(Color color) -> void;
auto setEditable(bool editable) -> void;
auto setExpandable(bool expandable) -> void;
auto setFont(const string& font) -> void override;
auto setFont(const Font& font) -> void override;
auto setForegroundColor(Color color) -> void;
auto setHorizontalAlignment(double alignment) -> void;
auto setIcon(const image& icon) -> void;
auto setImage(const Image& image) -> void;
auto setResizable(bool resizable) -> void;
auto setSortable(bool sortable) -> void;
auto setText(const string& text) -> void;

View File

@@ -28,7 +28,7 @@ auto pListViewItem::setBackgroundColor(Color color) -> void {
_setState();
}
auto pListViewItem::setFont(const string& font) -> void {
auto pListViewItem::setFont(const Font& font) -> void {
_setState();
}

View File

@@ -9,7 +9,7 @@ struct pListViewItem : pObject {
auto remove(sListViewCell cell) -> void;
auto setAlignment(Alignment alignment) -> void;
auto setBackgroundColor(Color color) -> void;
auto setFont(const string& font) -> void override;
auto setFont(const Font& font) -> void override;
auto setForegroundColor(Color color) -> void;
auto setSelected(bool selected) -> void;

View File

@@ -154,11 +154,11 @@ auto pListView::_widthOfColumn(unsigned _column) -> unsigned {
unsigned width = 8;
if(auto& header = state().header) {
if(auto column = header->column(_column)) {
if(auto& icon = column->state.icon) {
width += icon.width() + 2;
if(auto& image = column->state.image) {
width += image.width() + 2;
}
if(auto& text = column->state.text) {
width += Font::size(column->font(true), text).width();
width += pFont::size(column->font(true), text).width();
}
}
}
@@ -172,11 +172,11 @@ auto pListView::_widthOfCell(unsigned _row, unsigned _column) -> unsigned {
if(cell->state.checkable) {
width += 16 + 2;
}
if(auto& icon = cell->state.icon) {
width += icon.width() + 2;
if(auto& image = cell->state.image) {
width += image.width() + 2;
}
if(auto& text = cell->state.text) {
width += Font::size(cell->font(true), text).width();
width += pFont::size(cell->font(true), text).width();
}
}
}

View File

@@ -9,6 +9,7 @@ auto pRadioButton::construct() -> void {
qtRadioButton->connect(qtRadioButton, SIGNAL(toggled(bool)), SLOT(onActivate()));
pWidget::construct();
setGroup(state().group);
_setState();
}
@@ -21,13 +22,13 @@ auto pRadioButton::minimumSize() const -> Size {
auto size = pFont::size(qtWidget->font(), state().text);
if(state().orientation == Orientation::Horizontal) {
size.setWidth(size.width() + state().icon.width());
size.setHeight(max(state().icon.height(), size.height()));
size.setWidth(size.width() + state().image.width());
size.setHeight(max(state().image.height(), size.height()));
}
if(state().orientation == Orientation::Vertical) {
size.setWidth(max(state().icon.width(), size.width()));
size.setHeight(size.height() + state().icon.height());
size.setWidth(max(state().image.width(), size.width()));
size.setHeight(size.height() + state().image.height());
}
return {size.width() + 20, size.height() + 12};
@@ -41,10 +42,24 @@ auto pRadioButton::setChecked() -> void {
}
auto pRadioButton::setGroup(sGroup group) -> void {
_setState();
bool first = true;
if(auto& group = state().group) {
group->self()->lock();
for(auto& weak : group->state.objects) {
if(auto object = weak.acquire()) {
if(auto radioButton = dynamic_cast<mRadioButton*>(object.data())) {
if(auto self = radioButton->self()) {
self->qtRadioButton->setChecked(radioButton->state.checked = first);
first = false;
}
}
}
}
group->self()->unlock();
}
}
auto pRadioButton::setIcon(const image& icon) -> void {
auto pRadioButton::setImage(const Image& image) -> void {
_setState();
}
@@ -70,8 +85,8 @@ auto pRadioButton::_setState() -> void {
}
group->self()->unlock();
}
qtRadioButton->setIconSize(QSize(state().icon.width(), state().icon.height()));
qtRadioButton->setIcon(CreateIcon(state().icon));
qtRadioButton->setIconSize(QSize(state().image.width(), state().image.height()));
qtRadioButton->setIcon(CreateImage(state().image));
qtRadioButton->setStyleSheet("text-align: top;");
switch(state().orientation) {
case Orientation::Horizontal: qtRadioButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); break;

View File

@@ -9,7 +9,7 @@ struct pRadioButton : pWidget {
auto setBordered(bool bordered) -> void;
auto setChecked() -> void;
auto setGroup(sGroup group) -> void;
auto setIcon(const image& icon) -> void;
auto setImage(const Image& image) -> void;
auto setOrientation(Orientation orientation) -> void;
auto setText(const string& text) -> void;

View File

@@ -8,6 +8,7 @@ auto pRadioLabel::construct() -> void {
qtRadioLabel->connect(qtRadioLabel, SIGNAL(toggled(bool)), SLOT(onActivate()));
pWidget::construct();
setGroup(state().group);
_setState();
}
@@ -26,7 +27,21 @@ auto pRadioLabel::setChecked() -> void {
}
auto pRadioLabel::setGroup(sGroup group) -> void {
_setState();
bool first = true;
if(auto& group = state().group) {
group->self()->lock();
for(auto& weak : group->state.objects) {
if(auto object = weak.acquire()) {
if(auto radioLabel = dynamic_cast<mRadioLabel*>(object.data())) {
if(auto self = radioLabel->self()) {
self->qtRadioLabel->setChecked(radioLabel->state.checked = first);
first = false;
}
}
}
}
group->self()->unlock();
}
}
auto pRadioLabel::setText(const string& text) -> void {

View File

@@ -34,7 +34,7 @@ auto pTabFrameItem::setGeometry(Geometry geometry) -> void {
}
}
auto pTabFrameItem::setIcon(const image& icon) -> void {
auto pTabFrameItem::setImage(const Image& image) -> void {
_setState();
}
@@ -62,7 +62,7 @@ auto pTabFrameItem::_parent() -> maybe<pTabFrame&> {
auto pTabFrameItem::_setState() -> void {
if(auto parent = _parent()) {
parent->qtTabFrame->setTabIcon(self().offset(), CreateIcon(state().icon));
parent->qtTabFrame->setTabIcon(self().offset(), CreateImage(state().image));
if(state().selected) parent->qtTabFrame->setCurrentIndex(self().offset());
parent->qtTabFrame->setTabText(self().offset(), QString::fromUtf8(state().text));
if(auto layout = state().layout) {

View File

@@ -8,7 +8,7 @@ struct pTabFrameItem : pObject {
auto append(sLayout layout) -> void;
auto remove(sLayout layout) -> void;
auto setClosable(bool closable) -> void;
auto setIcon(const image& icon) -> void;
auto setImage(const Image& image) -> void;
auto setGeometry(Geometry geometry) -> void;
auto setMovable(bool movable) -> void;
auto setSelected() -> void;

View File

@@ -22,9 +22,6 @@ auto pTabFrame::append(sTabFrameItem item) -> void {
auto pTabFrame::remove(sTabFrameItem item) -> void {
}
auto pTabFrame::setEdge(Edge edge) -> void {
}
auto pTabFrame::setGeometry(Geometry geometry) -> void {
pWidget::setGeometry(geometry);
@@ -33,7 +30,18 @@ auto pTabFrame::setGeometry(Geometry geometry) -> void {
}
}
auto pTabFrame::setNavigation(Navigation navigation) -> void {
_setState();
}
auto pTabFrame::_setState() -> void {
switch(state().navigation) { default:
case Navigation::Top: qtTabFrame->setTabPosition(QTabWidget::TabPosition::North); break;
case Navigation::Bottom: qtTabFrame->setTabPosition(QTabWidget::TabPosition::South); break;
case Navigation::Left: qtTabFrame->setTabPosition(QTabWidget::TabPosition::West); break;
case Navigation::Right: qtTabFrame->setTabPosition(QTabWidget::TabPosition::East); break;
}
for(auto& item : state().items) {
if(auto self = item->self()) self->_setState();
}

View File

@@ -7,8 +7,8 @@ struct pTabFrame : pWidget {
auto append(sTabFrameItem item) -> void;
auto remove(sTabFrameItem item) -> void;
auto setEdge(Edge edge) -> void;
auto setGeometry(Geometry geometry) -> void override;
auto setNavigation(Navigation navigation) -> void;
auto _setState() -> void;

View File

@@ -19,7 +19,7 @@ auto pTextEdit::setBackgroundColor(Color color) -> void {
_setState();
}
auto pTextEdit::setCursorPosition(unsigned position) -> void {
auto pTextEdit::setCursor(Cursor cursor) -> void {
_setState();
}
@@ -53,8 +53,9 @@ auto pTextEdit::_setState() -> void {
//todo
}
QTextCursor cursor = qtTextEdit->textCursor();
unsigned lastCharacter = strlen(qtTextEdit->toPlainText().toUtf8().constData());
cursor.setPosition(min(state().cursorPosition, lastCharacter));
signed lastCharacter = strlen(qtTextEdit->toPlainText().toUtf8().constData());
cursor.setPosition(max(0, min(lastCharacter, state().cursor.offset())));
cursor.setPosition(max(0, min(lastCharacter, state().cursor.offset() + state().cursor.length())), QTextCursor::KeepAnchor);
qtTextEdit->setTextCursor(cursor);
qtTextEdit->setTextInteractionFlags(state().editable
? Qt::TextEditorInteraction

View File

@@ -6,7 +6,7 @@ struct pTextEdit : pWidget {
Declare(TextEdit, Widget)
auto setBackgroundColor(Color color) -> void;
auto setCursorPosition(unsigned position) -> void;
auto setCursor(Cursor cursor) -> void;
auto setEditable(bool editable) -> void;
auto setForegroundColor(Color color) -> void;
auto setText(const string& text) -> void;

View File

@@ -47,7 +47,7 @@ auto pWidget::setFocused() -> void {
qtWidget->setFocus(Qt::OtherFocusReason);
}
auto pWidget::setFont(const string& font) -> void {
auto pWidget::setFont(const Font& font) -> void {
if(!qtWidget) return;
qtWidget->setFont(pFont::create(font));
}

View File

@@ -8,7 +8,7 @@ struct pWidget : pSizable {
auto focused() const -> bool override;
auto setEnabled(bool enabled) -> void override;
auto setFocused() -> void override;
auto setFont(const string& font) -> void override;
auto setFont(const Font& font) -> void override;
auto setGeometry(Geometry geometry) -> void override;
auto setVisible(bool visible) -> void override;