diff --git a/gambatte_qt/src/cheatdialog.cpp b/gambatte_qt/src/cheatdialog.cpp index f0d05ebf..f3aa96d0 100644 --- a/gambatte_qt/src/cheatdialog.cpp +++ b/gambatte_qt/src/cheatdialog.cpp @@ -37,40 +37,44 @@ namespace { struct CheatItemLess { - bool operator()(const CheatListItem &lhs, const CheatListItem &rhs) const { + bool operator()(CheatListItem const &lhs, CheatListItem const &rhs) const { return lhs.label + lhs.code < rhs.label + rhs.code; } }; class CheatListModel : public QAbstractListModel { - std::vector items_; - public: explicit CheatListModel(QObject *parent = 0) : QAbstractListModel(parent) {} - explicit CheatListModel(const std::vector &items, QObject *parent = 0) + explicit CheatListModel(std::vector const &items, QObject *parent = 0) : QAbstractListModel(parent), items_(items) { } - virtual int rowCount(const QModelIndex&) const { return items_.size(); } + virtual int rowCount(QModelIndex const &) const { return items_.size(); } - virtual Qt::ItemFlags flags(const QModelIndex &index) const { + virtual Qt::ItemFlags flags(QModelIndex const &index) const { return QAbstractListModel::flags(index) | Qt::ItemIsUserCheckable; } - virtual QVariant data(const QModelIndex &index, const int role) const { + virtual QVariant data(QModelIndex const &index, int const role) const { if (static_cast(index.row()) < items_.size()) { switch (role) { - case Qt::DisplayRole: return items_[index.row()].label + " (" + items_[index.row()].code + ")"; - case Qt::CheckStateRole: return items_[index.row()].checked ? Qt::Checked : Qt::Unchecked; + case Qt::DisplayRole: + return items_[index.row()].label + + " (" + items_[index.row()].code + ')'; + case Qt::CheckStateRole: + return items_[index.row()].checked + ? Qt::Checked + : Qt::Unchecked; } } return QVariant(); } - virtual bool setData(const QModelIndex &index, const QVariant &value, const int role) { - if (static_cast(index.row()) < items_.size() && role == Qt::CheckStateRole) { + virtual bool setData(QModelIndex const &index, QVariant const &value, int role) { + if (static_cast(index.row()) < items_.size() + && role == Qt::CheckStateRole) { items_[index.row()].checked = value.toBool(); return true; } @@ -78,16 +82,19 @@ public: return false; } - const std::vector & items() const { return items_; } + std::vector const & items() const { return items_; } + +private: + std::vector items_; }; } -GetCheatInput::GetCheatInput(const QString &desc, const QString &code, QWidget *const parent) -: QDialog(parent), - codeEdit_(new QLineEdit(code)), - descEdit_(new QLineEdit(desc)), - okButton_(new QPushButton(tr("OK"))) +GetCheatInput::GetCheatInput(QString const &desc, QString const &code, QWidget *parent) +: QDialog(parent) +, codeEdit_(new QLineEdit(code)) +, descEdit_(new QLineEdit(desc)) +, okButton_(new QPushButton(tr("OK"))) { QVBoxLayout *const l = new QVBoxLayout; setLayout(l); @@ -96,8 +103,9 @@ GetCheatInput::GetCheatInput(const QString &desc, const QString &code, QWidget * l->addWidget(new QLabel(tr("GG/GS Code:"))); l->addWidget(codeEdit_); - const QString cheatre("((01[0-9a-fA-F]{6,6})|([0-9a-fA-F]{3,3}-[0-9a-fA-F]{3,3}(-[0-9a-fA-F]{3,3})?))"); - codeEdit_->setValidator(new QRegExpValidator(QRegExp(cheatre + "(;" + cheatre + ")*"), codeEdit_)); + QString const cheatre("((01[0-9a-fA-F]{6,6})|([0-9a-fA-F]{3,3}-[0-9a-fA-F]{3,3}(-[0-9a-fA-F]{3,3})?))"); + codeEdit_->setValidator(new QRegExpValidator(QRegExp(cheatre + "(;" + cheatre + ")*"), + codeEdit_)); codeEdit_->setToolTip(tr("Game Genie: hhh-hhh-hhh;...\nGame Shark: 01hhhhhh;...")); codeEdit_->setWhatsThis(codeEdit_->toolTip()); @@ -109,29 +117,30 @@ GetCheatInput::GetCheatInput(const QString &desc, const QString &code, QWidget * hl->addWidget(cancelButton); okButton_->setEnabled(codeEdit_->hasAcceptableInput()); - connect(codeEdit_, SIGNAL(textChanged(const QString&)), this, SLOT(codeTextEdited(const QString&))); + connect(codeEdit_, SIGNAL(textChanged(QString const &)), + this, SLOT(codeTextEdited(QString const &))); connect(okButton_, SIGNAL(clicked()), this, SLOT(accept())); connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); } -void GetCheatInput::codeTextEdited(const QString&) { +void GetCheatInput::codeTextEdited(QString const &) { okButton_->setEnabled(codeEdit_->hasAcceptableInput()); } -const QString GetCheatInput::codeText() const { +QString const GetCheatInput::codeText() const { return codeEdit_->text().toUpper(); } -const QString GetCheatInput::descText() const { +QString const GetCheatInput::descText() const { return descEdit_->text(); } -CheatDialog::CheatDialog(const QString &savefile, QWidget *const parent) -: QDialog(parent), - view_(new QListView()), - editButton_(new QPushButton(tr("Edit..."))), - rmButton_(new QPushButton(tr("Remove"))), - savefile_(savefile) +CheatDialog::CheatDialog(QString const &savefile, QWidget *parent) +: QDialog(parent) +, view_(new QListView()) +, editButton_(new QPushButton(tr("Edit..."))) +, rmButton_(new QPushButton(tr("Remove"))) +, savefile_(savefile) { setWindowTitle("Cheats"); @@ -150,16 +159,13 @@ CheatDialog::CheatDialog(const QString &savefile, QWidget *const parent) viewLayout->addWidget(editButton_); connect(editButton_, SIGNAL(clicked()), this, SLOT(editCheat())); - viewLayout->addWidget(rmButton_); connect(rmButton_, SIGNAL(clicked()), this, SLOT(removeCheat())); { QPushButton *const okButton = new QPushButton(tr("OK")); QPushButton *const cancelButton = new QPushButton(tr("Cancel")); - okButton->setDefault(true); - connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); @@ -182,11 +188,13 @@ void CheatDialog::loadFromSettingsFile() { QSettings settings(savefile_, QSettings::IniFormat); settings.beginGroup(gamename_); - foreach (const QString &key, settings.childKeys()) { - const QStringList &l = settings.value(key).toStringList(); - - if (1 < l.size()) - items_.push_back(CheatListItem(l[0], l[1], 2 < l.size() && l[2] == "on")); + foreach (QString const &key, settings.childKeys()) { + QStringList const &l = settings.value(key).toStringList(); + if (1 < l.size()) { + CheatListItem item(l[0], l[1], + 2 < l.size() && l[2] == "on"); + items_.push_back(item); + } } std::sort(items_.begin(), items_.end(), CheatItemLess()); @@ -205,7 +213,6 @@ void CheatDialog::saveToSettingsFile() { QStringList l; l.append(items_[i].label); l.append(items_[i].code); - if (items_[i].checked) l.append("on"); @@ -214,49 +221,57 @@ void CheatDialog::saveToSettingsFile() { } } -void CheatDialog::resetViewModel(const std::vector &items) { +void CheatDialog::resetViewModel(std::vector const &items) { resetViewModel(items, view_->currentIndex().row()); } -void CheatDialog::resetViewModel(const std::vector &items, const int newCurRow) { - const scoped_ptr oldModel(view_->model()); +void CheatDialog::resetViewModel(std::vector const &items, int const newCurRow) { + scoped_ptr const oldModel(view_->model()); view_->setModel(new CheatListModel(items, this)); view_->setCurrentIndex(view_->model()->index(newCurRow, 0, QModelIndex())); selectionChanged(view_->selectionModel()->currentIndex(), QModelIndex()); - connect(view_->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), - this, SLOT(selectionChanged(const QModelIndex&, const QModelIndex&))); + connect(view_->selectionModel(), + SIGNAL(currentChanged(QModelIndex const &, QModelIndex const &)), + this, SLOT(selectionChanged(QModelIndex const &, QModelIndex const &))); } void CheatDialog::addCheat() { - const scoped_ptr getCheatDialog(new GetCheatInput(QString(), QString(), this)); + scoped_ptr const getCheatDialog(new GetCheatInput(QString(), QString(), this)); getCheatDialog->setWindowTitle(tr("Add Cheat")); if (getCheatDialog->exec()) { - std::vector items = reinterpret_cast(view_->model())->items(); - const CheatListItem item(getCheatDialog->descText(), getCheatDialog->codeText(), false); - const std::vector::iterator it = - items.insert(std::lower_bound(items.begin(), items.end(), item, CheatItemLess()), item); - + std::vector items = + static_cast(view_->model())->items(); + CheatListItem const item(getCheatDialog->descText(), + getCheatDialog->codeText(), + false); + std::vector::iterator it = + items.insert(std::lower_bound(items.begin(), items.end(), item, + CheatItemLess()), + item); resetViewModel(items, it - items.begin()); } } void CheatDialog::editCheat() { - const std::size_t row = view_->selectionModel()->currentIndex().row(); - std::vector items = reinterpret_cast(view_->model())->items(); + std::size_t const row = view_->selectionModel()->currentIndex().row(); + std::vector items = static_cast(view_->model())->items(); if (row < items.size()) { - const scoped_ptr getCheatDialog( + scoped_ptr const getCheatDialog( new GetCheatInput(items[row].label, items[row].code, this)); getCheatDialog->setWindowTitle(tr("Edit Cheat")); if (getCheatDialog->exec()) { - const CheatListItem item(getCheatDialog->descText(), getCheatDialog->codeText(), items[row].checked); + CheatListItem const item(getCheatDialog->descText(), + getCheatDialog->codeText(), + items[row].checked); items.erase(items.begin() + row); - const std::vector::iterator it = - items.insert(std::lower_bound(items.begin(), items.end(), item, CheatItemLess()), item); - + std::vector::iterator it = + items.insert(std::lower_bound(items.begin(), items.end(), item, + CheatItemLess()), + item); resetViewModel(items, it - items.begin()); } } @@ -264,9 +279,9 @@ void CheatDialog::editCheat() { void CheatDialog::removeCheat() { if (view_->selectionModel()->currentIndex().isValid()) { - const std::size_t row = view_->selectionModel()->currentIndex().row(); - std::vector items = reinterpret_cast(view_->model())->items(); - + std::size_t const row = view_->selectionModel()->currentIndex().row(); + std::vector items = + static_cast(view_->model())->items(); if (row < items.size()) { items.erase(items.begin() + row); resetViewModel(items, row); @@ -274,14 +289,13 @@ void CheatDialog::removeCheat() { } } -void CheatDialog::selectionChanged(const QModelIndex ¤t, const QModelIndex&) { +void CheatDialog::selectionChanged(QModelIndex const ¤t, QModelIndex const &) { editButton_->setEnabled(current.isValid()); rmButton_->setEnabled(current.isValid()); } -const QString CheatDialog::cheats() const { +QString const CheatDialog::cheats() const { QString s; - for (std::size_t i = 0; i < items_.size(); ++i) { if (items_[i].checked) s += items_[i].code + ";"; @@ -290,14 +304,14 @@ const QString CheatDialog::cheats() const { return s; } -void CheatDialog::setGameName(const QString &name) { +void CheatDialog::setGameName(QString const &name) { saveToSettingsFile(); gamename_ = name; loadFromSettingsFile(); } void CheatDialog::accept() { - items_ = reinterpret_cast(view_->model())->items(); + items_ = static_cast(view_->model())->items(); QDialog::accept(); } diff --git a/gambatte_qt/src/cheatdialog.h b/gambatte_qt/src/cheatdialog.h index 0a922fd1..8c67fd54 100644 --- a/gambatte_qt/src/cheatdialog.h +++ b/gambatte_qt/src/cheatdialog.h @@ -28,13 +28,19 @@ struct CheatListItem { QString code; bool checked; - CheatListItem(const QString &label, const QString &code, const bool checked) + CheatListItem(QString const &label, QString const &code, bool checked) : label(label), code(code), checked(checked) { } }; class GetCheatInput : public QDialog { +public: + explicit GetCheatInput(QString const &desc, QString const &code, QWidget *parent); + QString const codeText() const; + QString const descText() const; + +private: Q_OBJECT class QLineEdit *const codeEdit_; @@ -42,44 +48,40 @@ class GetCheatInput : public QDialog { class QPushButton *const okButton_; private slots: - void codeTextEdited(const QString&); - -public: - explicit GetCheatInput(const QString &desc, const QString &code, QWidget *parent); - const QString codeText() const; - const QString descText() const; + void codeTextEdited(QString const &); }; class CheatDialog : public QDialog { +public: + explicit CheatDialog(QString const &savefile, QWidget *parent = 0); + ~CheatDialog(); + QString const cheats() const; + void setGameName(QString const &name); + +public slots: + virtual void accept(); + virtual void reject(); + +private: Q_OBJECT class QListView *const view_; class QPushButton *const editButton_; class QPushButton *const rmButton_; std::vector items_; - const QString savefile_; + QString const savefile_; QString gamename_; void loadFromSettingsFile(); void saveToSettingsFile(); - void resetViewModel(const std::vector &items); - void resetViewModel(const std::vector &items, int newCurRow); + void resetViewModel(std::vector const &items); + void resetViewModel(std::vector const &items, int newCurRow); private slots: void addCheat(); void editCheat(); void removeCheat(); - void selectionChanged(const class QModelIndex ¤t, const class QModelIndex &last); - -public: - explicit CheatDialog(const QString &savefile, QWidget *parent = 0); - ~CheatDialog(); - const QString cheats() const; - void setGameName(const QString &name); - -public slots: - virtual void accept(); - virtual void reject(); + void selectionChanged(class QModelIndex const ¤t, class QModelIndex const &last); }; #endif diff --git a/gambatte_qt/src/fpsselector.cpp b/gambatte_qt/src/fpsselector.cpp index 46d9836b..120bd139 100644 --- a/gambatte_qt/src/fpsselector.cpp +++ b/gambatte_qt/src/fpsselector.cpp @@ -21,18 +21,17 @@ #include #include -static int getCustomIndex(const QComboBox *const comboBox) { +static int getCustomIndex(QComboBox const *comboBox) { return comboBox->findText(QString("Other...")); } -static void setFps(QComboBox *const comboBox, const QSize &value) { - const int valueIndex = comboBox->findData(value); - +static void setFps(QComboBox *const comboBox, QSize const &value) { + int const valueIndex = comboBox->findData(value); if (valueIndex < 0) { - comboBox->addItem(QString::number(static_cast(value.width()) / value.height()) + " fps", value); - - const int customIndex = getCustomIndex(comboBox); + comboBox->addItem(QString::number(double(value.width()) / value.height()) + " fps", + value); + int const customIndex = getCustomIndex(comboBox); if (customIndex + 4 < comboBox->count()) comboBox->removeItem(customIndex + 1); @@ -42,18 +41,20 @@ static void setFps(QComboBox *const comboBox, const QSize &value) { } FpsSelector::FpsSelector() -: comboBox_(new QComboBox), - value_(262144, 4389) +: comboBox_(new QComboBox) +, value_(262144, 4389) { - comboBox_->addItem("GB/GBC (" + QString::number(262144.0 / 4389.0) + " fps)", QSize(262144, 4389)); + comboBox_->addItem("GB/GBC (" + QString::number(262144.0 / 4389.0) + " fps)", + QSize(262144, 4389)); comboBox_->addItem(QString("Other...")); - const QSize &loadedValue = QSettings().value("misc/fps", value_).toSize(); - value_ = loadedValue.width() > 0 && loadedValue.height() > 0 - && loadedValue.width() / loadedValue.height() > 0 ? loadedValue : value_; - + QSize const &loadedValue = QSettings().value("misc/fps", value_).toSize(); + value_ = loadedValue.width() > 0 + && loadedValue.height() > 0 + && loadedValue.width() / loadedValue.height() > 0 + ? loadedValue + : value_; reject(); - connect(comboBox_, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int))); } @@ -74,14 +75,17 @@ QWidget * FpsSelector::widget() const { return comboBox_; } -void FpsSelector::indexChanged(const int index) { +void FpsSelector::indexChanged(int const index) { if (getCustomIndex(comboBox_) == index) { bool ok = false; - - const QSize v(static_cast( - QInputDialog::getDouble(comboBox_, tr("Set Frame Rate"), tr("Frame rate (fps):"), - static_cast(value_.width()) / value_.height(), 30.0, 120.0, 4, &ok) * 10000 + 0.5), 10000); - - setFps(comboBox_, ok ? v : value_); + double const fps = + QInputDialog::getDouble(comboBox_, tr("Set Frame Rate"), + tr("Frame rate (fps):"), + double(value_.width()) / value_.height(), + 30.0, 120.0, 4, &ok); + setFps(comboBox_, + ok + ? QSize(int(fps * 10000 + 0.5), 10000) + : value_); } } diff --git a/gambatte_qt/src/fpsselector.h b/gambatte_qt/src/fpsselector.h index 055e70ef..ce7fd425 100644 --- a/gambatte_qt/src/fpsselector.h +++ b/gambatte_qt/src/fpsselector.h @@ -26,6 +26,15 @@ class QComboBox; class QWidget; class FpsSelector : public QObject { +public: + FpsSelector(); + ~FpsSelector(); + void accept(); + void reject(); + QSize const value() const { return value_; } + QWidget * widget() const; + +private: Q_OBJECT QComboBox *const comboBox_; @@ -33,14 +42,6 @@ class FpsSelector : public QObject { private slots: void indexChanged(int index); - -public: - FpsSelector(); - ~FpsSelector(); - void accept(); - void reject(); - const QSize & value() const { return value_; } - QWidget * widget() const; }; #endif diff --git a/gambatte_qt/src/gambattemenuhandler.cpp b/gambatte_qt/src/gambattemenuhandler.cpp index dc3935eb..3cea94e3 100644 --- a/gambatte_qt/src/gambattemenuhandler.cpp +++ b/gambatte_qt/src/gambattemenuhandler.cpp @@ -17,31 +17,33 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "gambattemenuhandler.h" - -#include +#include "blitterconf.h" +#include "cheatdialog.h" +#include "gambattesource.h" +#include "mainwindow.h" +#include "miscdialog.h" +#include "palettedialog.h" +#include "sounddialog.h" +#include "videodialog.h" #include #include #include -#include "palettedialog.h" -#include "blitterconf.h" -#include "mainwindow.h" -#include "sounddialog.h" -#include "videodialog.h" -#include "gambattesource.h" -#include "miscdialog.h" -#include "cheatdialog.h" +#include #include -static const QString strippedName(const QString &fullFileName) { +namespace { + +static QString const strippedName(QString const &fullFileName) { return QFileInfo(fullFileName).fileName(); } -namespace { struct TmpPauser : private Uncopyable { MainWindow *const mw; - const unsigned inc; + unsigned const inc; - explicit TmpPauser(MainWindow *const mw, const unsigned inc = 4) : mw(mw), inc(inc) { + explicit TmpPauser(MainWindow *mw, unsigned inc = 4) + : mw(mw), inc(inc) + { mw->incPause(inc); } @@ -49,33 +51,34 @@ struct TmpPauser : private Uncopyable { mw->decPause(inc); } }; + } -FrameRateAdjuster::FrameTime::FrameTime(unsigned baseNum, unsigned baseDenom) : index(STEPS) { +FrameRateAdjuster::FrameTime::FrameTime(unsigned baseNum, unsigned baseDenom) +: index_(num_steps) +{ setBaseFrameTime(baseNum, baseDenom); } -void FrameRateAdjuster::FrameTime::setBaseFrameTime(const unsigned baseNum, const unsigned baseDenom) { - frameTimes[STEPS] = Rational(baseNum, baseDenom); +void FrameRateAdjuster::FrameTime::setBaseFrameTime(unsigned const baseNum, unsigned const baseDenom) { + frameTimes_[num_steps] = Rational(baseNum, baseDenom); - const unsigned bnum = baseNum * 0x10000 / baseDenom; - - for (unsigned i = STEPS, num = bnum; i < STEPS * 2; ++i) - frameTimes[i + 1] = Rational(num = num * 11 / 10, 0x10000); - - for (unsigned i = STEPS, num = bnum; i; --i) - frameTimes[i - 1] = Rational(num = num * 10 / 11, 0x10000); + unsigned const bnum = baseNum * 0x10000 / baseDenom; + for (unsigned i = num_steps, num = bnum; i < num_steps * 2; ++i) + frameTimes_[i + 1] = Rational(num = num * 11 / 10, 0x10000); + for (unsigned i = num_steps, num = bnum; i; --i) + frameTimes_[i - 1] = Rational(num = num * 10 / 11, 0x10000); } -FrameRateAdjuster::FrameRateAdjuster(const MiscDialog &miscDialog, MainWindow &mw, QObject *const parent) -: QObject(parent), - frameTime_(miscDialog.baseFps().height(), miscDialog.baseFps().width()), - miscDialog_(miscDialog), - mw_(mw), - decFrameRateAction_(new QAction(tr("&Decrease Frame Rate"), &mw)), - incFrameRateAction_(new QAction(tr("&Increase Frame Rate"), &mw)), - resetFrameRateAction_(new QAction(tr("&Reset Frame Rate"), &mw)), - enabled_(true) +FrameRateAdjuster::FrameRateAdjuster(MiscDialog const &miscDialog, MainWindow &mw, QObject *parent) +: QObject(parent) +, frameTime_(miscDialog.baseFps().height(), miscDialog.baseFps().width()) +, miscDialog_(miscDialog) +, mw_(mw) +, decFrameRateAction_(new QAction(tr("&Decrease Frame Rate"), &mw)) +, incFrameRateAction_(new QAction(tr("&Increase Frame Rate"), &mw)) +, resetFrameRateAction_(new QAction(tr("&Reset Frame Rate"), &mw)) +, enabled_(true) { decFrameRateAction_->setShortcut(QString("Ctrl+D")); incFrameRateAction_->setShortcut(QString("Ctrl+I")); @@ -85,12 +88,11 @@ FrameRateAdjuster::FrameRateAdjuster(const MiscDialog &miscDialog, MainWindow &m connect(incFrameRateAction_, SIGNAL(triggered()), this, SLOT(incFrameRate())); connect(resetFrameRateAction_, SIGNAL(triggered()), this, SLOT(resetFrameRate())); connect(&miscDialog, SIGNAL(accepted()), this, SLOT(miscDialogChange())); - changed(); } -const QList FrameRateAdjuster::actions() { - QList l; +QList const FrameRateAdjuster::actions() { + QList l; l.append(decFrameRateAction_); l.append(incFrameRateAction_); l.append(resetFrameRateAction_); @@ -98,12 +100,12 @@ const QList FrameRateAdjuster::actions() { } void FrameRateAdjuster::miscDialogChange() { - const QSize &baseFps = miscDialog_.baseFps(); + QSize const &baseFps = miscDialog_.baseFps(); frameTime_.setBaseFrameTime(baseFps.height(), baseFps.width()); changed(); } -void FrameRateAdjuster::setDisabled(const bool disabled) { +void FrameRateAdjuster::setDisabled(bool disabled) { enabled_ = !disabled; changed(); } @@ -134,25 +136,24 @@ void FrameRateAdjuster::changed() { decFrameRateAction_->setEnabled(enabled_ && frameTime_.incPossible()); resetFrameRateAction_->setEnabled(enabled_ && frameTime_.resetPossible()); - const FrameTime::Rational &ft = enabled_ ? frameTime_.get() : frameTime_.base(); + FrameTime::Rational const &ft = enabled_ ? frameTime_.get() : frameTime_.base(); mw_.setFrameTime(ft.num, ft.denom); } -WindowSizeMenu::WindowSizeMenu(MainWindow *const mw, const VideoDialog *const vd) -: mw_(mw), - menu_(new QMenu(tr("&Window Size"), mw)), - group_(new QActionGroup(menu_)), - maxSize_(QApplication::desktop()->screen()->size()) +WindowSizeMenu::WindowSizeMenu(MainWindow &mw, VideoDialog const &vd) +: mw_(mw) +, menu_(new QMenu(tr("&Window Size"), &mw)) +, group_(new QActionGroup(menu_)) +, maxSize_(QApplication::desktop()->screen()->size()) { - fillMenu(vd->sourceSize(), vd->scalingMethod()); + fillMenu(vd.sourceSize(), vd.scalingMethod()); setCheckedSize(QSettings().value("video/windowSize", QSize(-1, -1)).toSize()); - connect(group_, SIGNAL(triggered(QAction*)), this, SLOT(triggered(QAction*))); - - const QSize &size = checkedSize(); - mw_->setWindowSize(size); + connect(group_, SIGNAL(triggered(QAction *)), this, SLOT(triggered(QAction *))); + QSize const &size = checkedSize(); + mw_.setWindowSize(size); if (size == QSize(-1, -1)) - mw_->resize(QSettings().value("mainwindow/size", QSize(160, 144)).toSize()); + mw_.resize(QSettings().value("mainwindow/size", QSize(160, 144)).toSize()); } WindowSizeMenu::~WindowSizeMenu() { @@ -160,46 +161,34 @@ WindowSizeMenu::~WindowSizeMenu() { settings.setValue("video/windowSize", checkedSize()); } -void WindowSizeMenu::videoDialogChange(const VideoDialog *const vd) { - const QSize &oldSize = checkedSize(); - disconnect(group_, SIGNAL(triggered(QAction*)), this, SLOT(triggered(QAction*))); +void WindowSizeMenu::videoDialogChange(VideoDialog const &vd) { + QSize const &oldSize = checkedSize(); + disconnect(group_, SIGNAL(triggered(QAction *)), this, SLOT(triggered(QAction *))); menu_->clear(); delete group_; group_ = new QActionGroup(menu_); - fillMenu(vd->sourceSize(), vd->scalingMethod()); + fillMenu(vd.sourceSize(), vd.scalingMethod()); setCheckedSize(oldSize); - connect(group_, SIGNAL(triggered(QAction*)), this, SLOT(triggered(QAction*))); - - const QSize &newSize = checkedSize(); + connect(group_, SIGNAL(triggered(QAction *)), this, SLOT(triggered(QAction *))); + QSize const &newSize = checkedSize(); if (newSize != oldSize) - mw_->setWindowSize(newSize); + mw_.setWindowSize(newSize); } void WindowSizeMenu::triggered(QAction *) { - mw_->setWindowSize(checkedSize()); + mw_.setWindowSize(checkedSize()); } -void WindowSizeMenu::fillMenu(const QSize &sourceSize, const ScalingMethod scalingMethod) { - const QSize aspectRatio(160, 144); - const QSize basesz(scalingMethod == INTEGER ? sourceSize : aspectRatio); - - /*if (scalingMethod != INTEGER) { - const unsigned scale = std::max(sourceSize.width() / aspectRatio.width(), sourceSize.height() / aspectRatio.height()); - - basesz = QSize(aspectRatio.width() * scale, aspectRatio.height() * scale); - - if (basesz.width() < sourceSize.width() || basesz.height() < sourceSize.height()) - basesz += aspectRatio; - }*/ - +void WindowSizeMenu::fillMenu(QSize const &sourceSize, ScalingMethod const scalingMethod) { + QSize const aspectRatio(160, 144); + QSize const basesz(scalingMethod == INTEGER ? sourceSize : aspectRatio); QSize sz(basesz); - while (sz.width() <= maxSize_.width() && sz.height() <= maxSize_.height()) { if (sz.width() >= sourceSize.width() && sz.height() >= sourceSize.height()) { - QAction *const a = menu_->addAction( - "&" + QString::number(sz.width()) + "x" + QString::number(sz.height())); + QAction *a = menu_->addAction( + "&" + QString::number(sz.width()) + "x" + QString::number(sz.height())); a->setData(sz); a->setCheckable(true); group_->addAction(a); @@ -208,16 +197,15 @@ void WindowSizeMenu::fillMenu(const QSize &sourceSize, const ScalingMethod scali sz += basesz; } - QAction *const a = menu_->addAction(tr("&Variable")); + QAction *a = menu_->addAction(tr("&Variable")); a->setData(QSize(-1, -1)); a->setCheckable(true); group_->addAction(a); } -void WindowSizeMenu::setCheckedSize(const QSize &size) { - const QList &actions = group_->actions(); - - foreach (QAction *const a, actions) { +void WindowSizeMenu::setCheckedSize(QSize const &size) { + QList const &actions = group_->actions(); + foreach (QAction *a, actions) { if (a->data() == size) { a->setChecked(true); return; @@ -228,30 +216,32 @@ void WindowSizeMenu::setCheckedSize(const QSize &size) { actions.front()->setChecked(true); } -const QSize WindowSizeMenu::checkedSize() const { +QSize const WindowSizeMenu::checkedSize() const { return group_->checkedAction() ? group_->checkedAction()->data().toSize() : QSize(-1, -1); } -static const QString settingsPath() { +static QString const settingsPath() { QString path = QSettings(QSettings::IniFormat, QSettings::UserScope, - QCoreApplication::organizationName(), QCoreApplication::applicationName()).fileName(); + QCoreApplication::organizationName(), QCoreApplication::applicationName()).fileName(); path.truncate(path.lastIndexOf("/")); return path; } -static const QString toCmdString(const QAction *const a) { +static QString const toCmdString(QAction const *a) { QString text = a->text().toLower(); text.replace("&", ""); text.replace(" ", "-"); return text; } -static char toCmdChar(const QAction *const a) { - return a->shortcut().count() == 1 ? (a->shortcut()[0] - Qt::Key_A + 'a') & 0xff : 0; +static char toCmdChar(QAction const *a) { + return a->shortcut().count() == 1 + ? (a->shortcut()[0] - Qt::Key_A + 'a') & 0xff + : 0; } -static QAction * findCmdStringAction(const QList &l, const QString &cmdstr) { - foreach (QAction *const a, l) { +static QAction * findCmdStringAction(QList const &l, QString const &cmdstr) { + foreach (QAction *a, l) { if (cmdstr == toCmdString(a)) return a; } @@ -259,8 +249,8 @@ static QAction * findCmdStringAction(const QList &l, const QString &cm return 0; } -static QAction * findCmdCharAction(const QList &l, const char c) { - foreach (QAction *const a, l) { +static QAction * findCmdCharAction(QList const &l, char const c) { + foreach (QAction *a, l) { if (c == toCmdChar(a)) return a; } @@ -268,72 +258,84 @@ static QAction * findCmdCharAction(const QList &l, const char c) { return 0; } -static void printUsage(const char *const arg0, const QList &actions) { +static void printUsage(char const *const arg0, QList const &actions) { std::cout << "Usage: " << arg0 << " [OPTION]... [romfile]\n"; - foreach (const QAction *const a, actions) { + foreach (QAction const *const a, actions) { if (a->isCheckable() && a->isEnabled()) { - const std::string &text = toCmdString(a).toStdString(); - const char c = toCmdChar(a); - std::cout << (" " + (c ? "-" + std::string(1, c) + ", " : std::string(" ")) + "--" + text + "[=0]\n"); + std::string const &text = toCmdString(a).toStdString(); + char const c = toCmdChar(a); + std::cout << " " + << (c ? "-" + std::string(1, c) + ", " : std::string(" ")) + << "--" << text << "[=0]\n"; } } } GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw, - GambatteSource *const source, const int argc, const char *const argv[]) -: mw(mw), - source(source), - soundDialog(new SoundDialog(mw, mw)), - videoDialog(new VideoDialog(mw, source->generateVideoSourceInfos(), QString("Video filter:"), mw)), - miscDialog(new MiscDialog(settingsPath() + "/saves", mw)), - cheatDialog(new CheatDialog(settingsPath() + "/cheats.ini", mw)), - stateSlotGroup(new QActionGroup(mw)), - windowSizeMenu(mw, videoDialog), - pauseInc(4) + GambatteSource *const source, + int const argc, + char const *const argv[]) +: mw_(mw) +, source_(source) +, soundDialog_(new SoundDialog(mw, mw)) +, videoDialog_(new VideoDialog(mw, source->generateVideoSourceInfos(), QString("Video filter:"), mw)) +, miscDialog_(new MiscDialog(settingsPath() + "/saves", mw)) +, cheatDialog_(new CheatDialog(settingsPath() + "/cheats.ini", mw)) +, recentFileActs_() +, pauseAction_() +, syncFrameRateAction_() +, gbaCgbAction_() +, forceDmgAction_() +, fsAct_() +, recentMenu_() +, globalPaletteDialog_() +, romPaletteDialog_() +, stateSlotGroup_(new QActionGroup(mw)) +, windowSizeMenu_(*mw, *videoDialog_) +, pauseInc_(4) { mw->setWindowTitle("Gambatte"); source->inputDialog()->setParent(mw, source->inputDialog()->windowFlags()); { - const QString &settingspath = settingsPath(); - const QString &palpath = settingspath + "/palettes"; + QString const &settingspath = settingsPath(); + QString const &palpath = settingspath + "/palettes"; QDir::root().mkpath(settingspath + "/saves"); QDir::root().mkpath(palpath); - globalPaletteDialog = new PaletteDialog(palpath, 0, mw); - romPaletteDialog = new PaletteDialog(palpath, globalPaletteDialog, mw); - connect(globalPaletteDialog, SIGNAL(accepted()), this, SLOT(globalPaletteChange())); - connect(romPaletteDialog, SIGNAL(accepted()), this, SLOT(romPaletteChange())); + globalPaletteDialog_ = new PaletteDialog(palpath, 0, mw); + romPaletteDialog_ = new PaletteDialog(palpath, globalPaletteDialog_, mw); + connect(globalPaletteDialog_, SIGNAL(accepted()), this, SLOT(globalPaletteChange())); + connect(romPaletteDialog_, SIGNAL(accepted()), this, SLOT(romPaletteChange())); } QActionGroup *const romLoadedActions = new QActionGroup(mw); romLoadedActions->setExclusive(false); { - for (int i = 0; i < MaxRecentFiles; ++i) { - recentFileActs[i] = new QAction(mw); - recentFileActs[i]->setVisible(false); - connect(recentFileActs[i], SIGNAL(triggered()), this, SLOT(openRecentFile())); + for (int i = 0; i < max_recent_files; ++i) { + recentFileActs_[i] = new QAction(mw); + recentFileActs_[i]->setVisible(false); + connect(recentFileActs_[i], SIGNAL(triggered()), this, SLOT(openRecentFile())); } QMenu *fileMenu = mw->menuBar()->addMenu(tr("&File")); fileMenu->addAction(tr("&Open..."), this, SLOT(open()), tr("Ctrl+O")); - recentMenu = fileMenu->addMenu(tr("Open Re¢")); - - for (int i = 0; i < MaxRecentFiles; ++i) - recentMenu->addAction(recentFileActs[i]); + recentMenu_ = fileMenu->addMenu(tr("Open Re¢")); + for (int i = 0; i < max_recent_files; ++i) + recentMenu_->addAction(recentFileActs_[i]); fileMenu->addSeparator(); romLoadedActions->addAction(fileMenu->addAction(tr("&Reset"), this, SLOT(reset()), tr("Ctrl+R"))); fileMenu->addSeparator(); - romLoadedActions->addAction(fileMenu->addAction(tr("Save State &As..."), this, SLOT(saveStateAs()))); romLoadedActions->addAction(fileMenu->addAction(tr("Load State &From..."), this, SLOT(loadStateFrom()))); fileMenu->addSeparator(); - - romLoadedActions->addAction(fileMenu->addAction(tr("&Save State"), this, SLOT(saveState()), QString("Ctrl+S"))); - romLoadedActions->addAction(fileMenu->addAction(tr("&Load State"), this, SLOT(loadState()), QString("Ctrl+L"))); + romLoadedActions->addAction(fileMenu->addAction(tr("&Save State"), + this, SLOT(saveState()), QString("Ctrl+S"))); + romLoadedActions->addAction(fileMenu->addAction(tr("&Load State"), + this, SLOT(loadState()), QString("Ctrl+L"))); { QMenu *const stateSlotMenu = fileMenu->addMenu(tr("S&elect State Slot")); @@ -343,84 +345,78 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw, stateSlotMenu->addSeparator(); for (int i = 0; i < 10; ++i) { - const int no = i == 9 ? 0 : i + 1; - const QString &strno = QString::number(no); - QAction *const action = stateSlotMenu->addAction("Slot &" + strno, this, SLOT(selectStateSlot()), strno); + int const no = i == 9 ? 0 : i + 1; + QString const &strno = QString::number(no); + QAction *action = stateSlotMenu->addAction( + "Slot &" + strno, this, SLOT(selectStateSlot()), strno); action->setCheckable(true); action->setData(no); - stateSlotGroup->addAction(action); + stateSlotGroup_->addAction(action); } connect(this, SIGNAL(romLoaded(bool)), stateSlotMenu, SLOT(setEnabled(bool))); } fileMenu->addSeparator(); - fileMenu->addAction(tr("&Quit"), qApp, SLOT(closeAllWindows()), tr("Ctrl+Q")); updateRecentFileActions(); } - FrameRateAdjuster *const frameRateAdjuster = new FrameRateAdjuster(*miscDialog, *mw, this); - QList cmdactions; + FrameRateAdjuster *const frameRateAdjuster = new FrameRateAdjuster(*miscDialog_, *mw, this); + QList cmdactions; { QMenu *const playm = mw->menuBar()->addMenu(tr("&Play")); - - romLoadedActions->addAction(pauseAction = playm->addAction(tr("&Pause"), this, SLOT(pauseChange()), QString("Ctrl+P"))); - pauseAction->setCheckable(true); - romLoadedActions->addAction(playm->addAction(tr("Frame &Step"), this, SLOT(frameStep()), QString("Ctrl+."))); + romLoadedActions->addAction(pauseAction_ = playm->addAction( + tr("&Pause"), this, SLOT(pauseChange()), QString("Ctrl+P"))); + pauseAction_->setCheckable(true); + romLoadedActions->addAction(playm->addAction(tr("Frame &Step"), + this, SLOT(frameStep()), QString("Ctrl+."))); playm->addSeparator(); - syncFrameRateAction = playm->addAction(tr("&Sync Frame Rate to Refresh Rate")); - syncFrameRateAction->setCheckable(true); - connect(syncFrameRateAction, SIGNAL(triggered(bool)), frameRateAdjuster, SLOT(setDisabled(bool))); - connect(syncFrameRateAction, SIGNAL(triggered(bool)), mw , SLOT(setSyncToRefreshRate(bool))); + syncFrameRateAction_ = playm->addAction(tr("&Sync Frame Rate to Refresh Rate")); + syncFrameRateAction_->setCheckable(true); + connect(syncFrameRateAction_, SIGNAL(triggered(bool)), + frameRateAdjuster, SLOT(setDisabled(bool))); + connect(syncFrameRateAction_, SIGNAL(triggered(bool)), + mw, SLOT(setSyncToRefreshRate(bool))); - foreach (QAction *const action, frameRateAdjuster->actions()) + foreach (QAction *action, frameRateAdjuster->actions()) playm->addAction(romLoadedActions->addAction(action)); cmdactions += playm->actions(); } QMenu *const settingsm = mw->menuBar()->addMenu(tr("&Settings")); - settingsm->addAction(tr("&Input..."), this, SLOT(execInputDialog())); settingsm->addAction(tr("&Miscellaneous..."), this, SLOT(execMiscDialog())); settingsm->addAction(tr("&Sound..."), this, SLOT(execSoundDialog())); settingsm->addAction(tr("&Video..."), this, SLOT(execVideoDialog())); settingsm->addSeparator(); - settingsm->addMenu(windowSizeMenu.menu()); + settingsm->addMenu(windowSizeMenu_.menu()); settingsm->addSeparator(); - - gbaCgbAction = settingsm->addAction(tr("GB&A CGB Mode")); - gbaCgbAction->setCheckable(true); - gbaCgbAction->setChecked(QSettings().value("gbacgb", false).toBool()); - forceDmgAction = settingsm->addAction(tr("Force &DMG Mode")); - forceDmgAction->setCheckable(true); + gbaCgbAction_ = settingsm->addAction(tr("GB&A CGB Mode")); + gbaCgbAction_->setCheckable(true); + gbaCgbAction_->setChecked(QSettings().value("gbacgb", false).toBool()); + forceDmgAction_ = settingsm->addAction(tr("Force &DMG Mode")); + forceDmgAction_->setCheckable(true); { QMenu *const palm = settingsm->addMenu(tr("DMG &Palette")); - palm->addAction(tr("&Global..."), this, SLOT(execGlobalPaletteDialog())); - QAction *const romPaletteAct = palm->addAction(tr("Current &ROM..."), this, SLOT(execRomPaletteDialog())); + QAction *romPaletteAct = palm->addAction(tr("Current &ROM..."), this, SLOT(execRomPaletteDialog())); romPaletteAct->setEnabled(false); connect(this, SIGNAL(dmgRomLoaded(bool)), romPaletteAct, SLOT(setEnabled(bool))); } settingsm->addSeparator(); - -#ifndef Q_WS_MAC - QAction *fsAct; -#endif - fsAct = settingsm->addAction(tr("&Full Screen"), this, SLOT(toggleFullScreen()), tr("Ctrl+F")); - fsAct->setCheckable(true); - -// settingsm->addAction(hideMenuAct); + fsAct_ = settingsm->addAction(tr("&Full Screen"), this, SLOT(toggleFullScreen()), tr("Ctrl+F")); + fsAct_->setCheckable(true); cmdactions += settingsm->actions(); - romLoadedActions->addAction(mw->menuBar()->addMenu(tr("&Tools"))->addAction(tr("&Cheats..."), cheatDialog, SLOT(exec()))); + romLoadedActions->addAction(mw->menuBar()->addMenu(tr("&Tools"))->addAction(tr("&Cheats..."), + cheatDialog_, SLOT(exec()))); romLoadedActions->setEnabled(false); - mw->menuBar()->addSeparator(); QMenu *const helpMenu = mw->menuBar()->addMenu(tr("&Help")); @@ -429,7 +425,7 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw, mw->addActions(mw->menuBar()->actions()); { - QAction *const escAct = new QAction(mw); + QAction *escAct = new QAction(mw); escAct->setShortcut(tr("Esc")); connect(escAct, SIGNAL(triggered()), this, SLOT(escPressed())); mw->addAction(escAct); @@ -437,7 +433,7 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw, mw->setSamplesPerFrame(35112); connect(source, SIGNAL(setTurbo(bool)), mw, SLOT(setFastForward(bool))); - connect(source, SIGNAL(togglePause()), pauseAction, SLOT(trigger())); + connect(source, SIGNAL(togglePause()), pauseAction_, SLOT(trigger())); connect(source, SIGNAL(frameStep()), this, SLOT(frameStep())); connect(source, SIGNAL(decFrameRate()), frameRateAdjuster, SLOT(decFrameRate())); connect(source, SIGNAL(incFrameRate()), frameRateAdjuster, SLOT(incFrameRate())); @@ -447,16 +443,16 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw, connect(source, SIGNAL(saveStateSignal()), this, SLOT(saveState())); connect(source, SIGNAL(loadStateSignal()), this, SLOT(loadState())); connect(source, SIGNAL(quit()), qApp, SLOT(closeAllWindows())); - connect(videoDialog, SIGNAL(accepted()), this, SLOT(videoDialogChange())); - connect(soundDialog, SIGNAL(accepted()), this, SLOT(soundDialogChange())); - connect(miscDialog, SIGNAL(accepted()), this, SLOT(miscDialogChange())); - connect(cheatDialog, SIGNAL(accepted()), this, SLOT(cheatDialogChange())); + connect(videoDialog_, SIGNAL(accepted()), this, SLOT(videoDialogChange())); + connect(soundDialog_, SIGNAL(accepted()), this, SLOT(soundDialogChange())); + connect(miscDialog_, SIGNAL(accepted()), this, SLOT(miscDialogChange())); + connect(cheatDialog_, SIGNAL(accepted()), this, SLOT(cheatDialogChange())); connect(mw, SIGNAL(videoBlitterFailure()), this, SLOT(videoBlitterFailure())); connect(mw, SIGNAL(audioEngineFailure()), this, SLOT(audioEngineFailure())); connect(mw, SIGNAL(closing()), this, SLOT(saveWindowSizeIfNotFullScreen())); connect(mw, SIGNAL(dwmCompositionChange()), this, SLOT(reconsiderSyncFrameRateActionEnable())); connect(this, SIGNAL(romLoaded(bool)), romLoadedActions, SLOT(setEnabled(bool))); - connect(this, SIGNAL(romLoaded(bool)), stateSlotGroup->actions().at(0), SLOT(setChecked(bool))); + connect(this, SIGNAL(romLoaded(bool)), stateSlotGroup_->actions().at(0), SLOT(setChecked(bool))); mw->setAspectRatio(QSize(160, 144)); videoDialogChange(); @@ -467,9 +463,9 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw, for (int i = 1; i < argc; ++i) { if (argv[i][0] == '-' && argv[i][1]) { - const QString argstr(argv[i] + 2); + QString const argstr(argv[i] + 2); - if (QAction *const a = argv[i][1] == '-' + if (QAction *a = argv[i][1] == '-' ? findCmdStringAction(cmdactions, argstr.left(argstr.lastIndexOf('='))) : findCmdCharAction(cmdactions, argv[i][1])) { if (argstr.endsWith("=0") == a->isChecked() && a->isEnabled()) @@ -484,7 +480,7 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw, for (int i = 1; i < argc; ++i) { if (argv[i][0] != '-') { - if (fsAct->isChecked()) + if (fsAct_->isChecked()) mw->menuBar()->hide(); loadFile(QFileInfo(QString(argv[i])).absoluteFilePath()); @@ -495,265 +491,269 @@ GambatteMenuHandler::GambatteMenuHandler(MainWindow *const mw, GambatteMenuHandler::~GambatteMenuHandler() { QSettings settings; - settings.setValue("gbacgb", gbaCgbAction->isChecked()); + settings.setValue("gbacgb", gbaCgbAction_->isChecked()); } void GambatteMenuHandler::updateRecentFileActions() { QSettings settings; QStringList files = settings.value("recentFileList").toStringList(); - const int numRecentFiles = qMin(files.size(), static_cast(MaxRecentFiles)); + int const numRecentFiles = qMin(files.size(), static_cast(max_recent_files)); for (int i = 0; i < numRecentFiles; ++i) { - const QString &text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i])); - recentFileActs[i]->setText(text); - recentFileActs[i]->setData(files[i]); - recentFileActs[i]->setVisible(true); + QString const &text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i])); + recentFileActs_[i]->setText(text); + recentFileActs_[i]->setData(files[i]); + recentFileActs_[i]->setVisible(true); } - for (int j = numRecentFiles; j < MaxRecentFiles; ++j) - recentFileActs[j]->setVisible(false); + for (int j = numRecentFiles; j < max_recent_files; ++j) + recentFileActs_[j]->setVisible(false); - recentMenu->setEnabled(numRecentFiles > 0); + recentMenu_->setEnabled(numRecentFiles > 0); } -void GambatteMenuHandler::setCurrentFile(const QString &fileName) { +void GambatteMenuHandler::setCurrentFile(QString const &fileName) { QSettings settings; QStringList files = settings.value("recentFileList").toStringList(); files.removeAll(fileName); files.prepend(fileName); - - while (files.size() > MaxRecentFiles) + while (files.size() > max_recent_files) files.removeLast(); settings.setValue("recentFileList", files); updateRecentFileActions(); } -void GambatteMenuHandler::loadFile(const QString &fileName) { - TmpPauser tmpPauser(mw, 4); - pauseAction->setChecked(false); +void GambatteMenuHandler::loadFile(QString const &fileName) { + TmpPauser tmpPauser(mw_, 4); + pauseAction_->setChecked(false); pauseChange(); - mw->waitUntilPaused(); + mw_->waitUntilPaused(); if (gambatte::LoadRes const error = - source->load(fileName.toLocal8Bit().constData(), - gbaCgbAction->isChecked() * gambatte::GB::GBA_CGB - + forceDmgAction->isChecked() * gambatte::GB::FORCE_DMG - + miscDialog->multicartCompat() * gambatte::GB::MULTICART_COMPAT)) { - mw->stop(); + source_->load(fileName.toLocal8Bit().constData(), + gbaCgbAction_->isChecked() * gambatte::GB::GBA_CGB + + forceDmgAction_->isChecked() * gambatte::GB::FORCE_DMG + + miscDialog_->multicartCompat() * gambatte::GB::MULTICART_COMPAT)) { + mw_->stop(); emit dmgRomLoaded(false); emit romLoaded(false); QMessageBox::critical( - mw, + mw_, tr("File Load Error"), tr("Failed to load file\n") + fileName + ".\n\n" + gambatte::to_string(error).c_str() + "."); return; } - const QString &romTitle = QString::fromStdString(source->romTitle()).trimmed(); - cheatDialog->setGameName(romTitle.isEmpty() ? QFileInfo(fileName).completeBaseName() : romTitle); + QString const &romTitle = QString::fromStdString(source_->romTitle()).trimmed(); + cheatDialog_->setGameName(romTitle.isEmpty() ? QFileInfo(fileName).completeBaseName() : romTitle); cheatDialogChange(); - if (!source->isCgb()) { - romPaletteDialog->setSettingsFile( + if (!source_->isCgb()) { + romPaletteDialog_->setSettingsFile( QFileInfo(fileName).completeBaseName() + ".pal", romTitle); setDmgPaletteColors(); } - gambatte::PakInfo const &pak = source->pakInfo(); + gambatte::PakInfo const &pak = source_->pakInfo(); std::cout << romTitle.toStdString() << '\n' << "GamePak type: " << pak.mbc() << " rambanks: " << pak.rambanks() << " rombanks: " << pak.rombanks() << '\n' << "header checksum: " << (pak.headerChecksumOk() ? "ok" : "bad") << '\n' - << "cgb: " << source->isCgb() << std::endl; + << "cgb: " << source_->isCgb() << std::endl; - mw->setWindowTitle(strippedName(fileName) + (pak.headerChecksumOk() ? "" : " [bad]") + " - Gambatte"); + mw_->setWindowTitle(strippedName(fileName) + (pak.headerChecksumOk() ? "" : " [bad]") + " - Gambatte"); setCurrentFile(fileName); emit romLoaded(true); - emit dmgRomLoaded(!source->isCgb()); + emit dmgRomLoaded(!source_->isCgb()); - mw->resetAudio(); - mw->run(); + mw_->resetAudio(); + mw_->run(); } void GambatteMenuHandler::open() { - TmpPauser tmpPauser(mw, 4); - mw->waitUntilPaused(); - - const QString &fileName = QFileDialog::getOpenFileName(mw, tr("Open"), recentFileActs[0]->data().toString(), - tr("Game Boy ROM Images (*.dmg *.gb *.gbc *.sgb *.zip *.gz);;All Files (*)")); + TmpPauser tmpPauser(mw_, 4); + mw_->waitUntilPaused(); + QString const &fileName = QFileDialog::getOpenFileName( + mw_, tr("Open"), recentFileActs_[0]->data().toString(), + tr("Game Boy ROM Images (*.dmg *.gb *.gbc *.sgb *.zip *.gz);;All Files (*)")); if (!fileName.isEmpty()) loadFile(fileName); - // giving back focus after getOpenFileName seems to fail at times, which can be problematic with current exclusive mode handling. - mw->setFocus(); + // giving back focus after getOpenFileName seems to fail at times, which + // can be problematic with current exclusive mode handling. + mw_->setFocus(); } void GambatteMenuHandler::openRecentFile() { - if (const QAction *const action = qobject_cast(sender())) + if (QAction const *action = qobject_cast(sender())) loadFile(action->data().toString()); } void GambatteMenuHandler::about() { - TmpPauser tmpPauser(mw, pauseInc); - + TmpPauser tmpPauser(mw_, pauseInc_); QMessageBox::about( - mw, - "About Gambatte", - QString::fromUtf8("

Gambatte Qt SVN

\ -

Homepage: http://sourceforge.net/projects/gambatte

\ -

Gambatte is an accuracy-focused, open-source, cross-platform Game Boy Color emulator written in C++. It is based on a few thousand corner-case hardware tests, as well as previous documentation and reverse engineering efforts.

") - ); + mw_, + "About Gambatte", + QString::fromUtf8( + "

Gambatte Qt (git)

" + "

" + "Homepage: " + "" + "https://github.com/sinamas/gambatte" + "" + "

" + "

" + "Gambatte is an accuracy-focused, open-source, cross-platform Game " + "Boy Color emulator written in C++. It is based on a few thousand " + "corner-case hardware tests, as well as previous documentation and " + "reverse engineering efforts." + "

") + ); } void GambatteMenuHandler::globalPaletteChange() { - romPaletteDialog->externalChange(); + romPaletteDialog_->externalChange(); setDmgPaletteColors(); } void GambatteMenuHandler::romPaletteChange() { - globalPaletteDialog->externalChange(); + globalPaletteDialog_->externalChange(); setDmgPaletteColors(); } namespace { + struct SetDmgPaletteColorFun { GambatteSource *source; unsigned palnum; unsigned colornum; unsigned rgb32; void operator()() const { source->setDmgPaletteColor(palnum, colornum, rgb32); } }; -} -void GambatteMenuHandler::setDmgPaletteColors() { - for (unsigned palnum = 0; palnum < 3; ++palnum) - for (unsigned colornum = 0; colornum < 4; ++colornum) { - const SetDmgPaletteColorFun fun = { source, palnum, colornum, romPaletteDialog->getColor(palnum, colornum) }; - mw->callInWorkerThread(fun); - } -} - -namespace { struct SetVideoSourceFun { GambatteSource *source; unsigned sourceIndex; void operator()() const { source->setVideoSource(sourceIndex); } }; -} -void GambatteMenuHandler::videoDialogChange() { - { - const SetVideoSourceFun fun = { source, videoDialog->sourceIndex() }; - mw->callInWorkerThread(fun); - } - - applySettings(mw, videoDialog); - windowSizeMenu.videoDialogChange(videoDialog); - reconsiderSyncFrameRateActionEnable(); -} - -void GambatteMenuHandler::soundDialogChange() { - SoundDialog::applySettings(mw, soundDialog); -} - -namespace { struct SetSaveDirFun { GambatteSource *source; QString path; void operator()() const { source->setSavedir(path.toLocal8Bit().constData()); } }; + +} // anon ns + +void GambatteMenuHandler::setDmgPaletteColors() { + for (unsigned palnum = 0; palnum < 3; ++palnum) + for (unsigned colornum = 0; colornum < 4; ++colornum) { + SetDmgPaletteColorFun fun = { source_, palnum, colornum, + romPaletteDialog_->color(palnum, colornum) }; + mw_->callInWorkerThread(fun); + } +} + +void GambatteMenuHandler::videoDialogChange() { + { + SetVideoSourceFun fun = { source_, videoDialog_->sourceIndex() }; + mw_->callInWorkerThread(fun); + } + + applySettings(mw_, videoDialog_); + windowSizeMenu_.videoDialogChange(*videoDialog_); + reconsiderSyncFrameRateActionEnable(); +} + +void GambatteMenuHandler::soundDialogChange() { + SoundDialog::applySettings(mw_, soundDialog_); } void GambatteMenuHandler::miscDialogChange() { - const SetSaveDirFun setSaveDirFun = { source, miscDialog->savePath() }; - mw->callInWorkerThread(setSaveDirFun); - mw->setDwmTripleBuffer(miscDialog->dwmTripleBuf()); - mw->setFastForwardSpeed(miscDialog->turboSpeed()); - mw->setPauseOnFocusOut(miscDialog->pauseOnFocusOut() ? 2 : 0); - pauseInc = miscDialog->pauseOnDialogs() ? 4 : 0; + SetSaveDirFun const setSaveDirFun = { source_, miscDialog_->savePath() }; + mw_->callInWorkerThread(setSaveDirFun); + mw_->setDwmTripleBuffer(miscDialog_->dwmTripleBuf()); + mw_->setFastForwardSpeed(miscDialog_->turboSpeed()); + mw_->setPauseOnFocusOut(miscDialog_->pauseOnFocusOut() ? 2 : 0); + pauseInc_ = miscDialog_->pauseOnDialogs() ? 4 : 0; } void GambatteMenuHandler::cheatDialogChange() { std::string gameGenieCodes; std::string gameSharkCodes; - foreach (const QString &s, cheatDialog->cheats().split(';', QString::SkipEmptyParts)) { + foreach (QString const &s, cheatDialog_->cheats().split(';', QString::SkipEmptyParts)) { if (s.contains('-')) { gameGenieCodes += s.toStdString() + ";"; } else gameSharkCodes += s.toStdString() + ";"; } - source->setGameGenie(gameGenieCodes); - source->setGameShark(gameSharkCodes); + source_->setGameGenie(gameGenieCodes); + source_->setGameShark(gameSharkCodes); } void GambatteMenuHandler::reconsiderSyncFrameRateActionEnable() { - if (mw->blitterConf(videoDialog->blitterNo()).maxSwapInterval() && !MainWindow::isDwmCompositionEnabled()) { - syncFrameRateAction->setEnabled(true); + if (mw_->blitterConf(videoDialog_->blitterNo()).maxSwapInterval() + && !MainWindow::isDwmCompositionEnabled()) { + syncFrameRateAction_->setEnabled(true); } else { - if (syncFrameRateAction->isChecked()) - syncFrameRateAction->trigger(); + if (syncFrameRateAction_->isChecked()) + syncFrameRateAction_->trigger(); - syncFrameRateAction->setEnabled(false); + syncFrameRateAction_->setEnabled(false); } } void GambatteMenuHandler::execGlobalPaletteDialog() { - TmpPauser tmpPauser(mw, pauseInc); - globalPaletteDialog->exec(); + TmpPauser tmpPauser(mw_, pauseInc_); + globalPaletteDialog_->exec(); } void GambatteMenuHandler::execRomPaletteDialog() { - TmpPauser tmpPauser(mw, pauseInc); - romPaletteDialog->exec(); + TmpPauser tmpPauser(mw_, pauseInc_); + romPaletteDialog_->exec(); } void GambatteMenuHandler::execInputDialog() { - TmpPauser tmpPauser(mw, pauseInc); - source->inputDialog()->exec(); + TmpPauser tmpPauser(mw_, pauseInc_); + source_->inputDialog()->exec(); } void GambatteMenuHandler::execSoundDialog() { - TmpPauser tmpPauser(mw, pauseInc); - soundDialog->exec(); + TmpPauser tmpPauser(mw_, pauseInc_); + soundDialog_->exec(); } void GambatteMenuHandler::execVideoDialog() { - TmpPauser tmpPauser(mw, pauseInc); - videoDialog->exec(); + TmpPauser tmpPauser(mw_, pauseInc_); + videoDialog_->exec(); } void GambatteMenuHandler::execMiscDialog() { - TmpPauser tmpPauser(mw, pauseInc); - miscDialog->exec(); + TmpPauser tmpPauser(mw_, pauseInc_); + miscDialog_->exec(); } void GambatteMenuHandler::prevStateSlot() { - stateSlotGroup->actions().at(source->currentState() < 2 ? source->currentState() + 8 : source->currentState() - 2)->trigger(); + stateSlotGroup_->actions().at(source_->currentState() < 2 + ? source_->currentState() + 8 + : source_->currentState() - 2)->trigger(); } void GambatteMenuHandler::nextStateSlot() { - stateSlotGroup->actions().at(source->currentState())->trigger(); + stateSlotGroup_->actions().at(source_->currentState())->trigger(); } namespace { + struct SelectStateFun { GambatteSource *source; int i; void operator()() const { source->selectState(i); } }; -} -void GambatteMenuHandler::selectStateSlot() { - if (QAction *action = stateSlotGroup->checkedAction()) { - const SelectStateFun fun = { source, action->data().toInt() }; - mw->callInWorkerThread(fun); - } -} - -namespace { struct SaveStateFun { GambatteSource *source; MainWindow::FrameBuffer fb; @@ -761,50 +761,22 @@ struct SaveStateFun { source->saveState(MainWindow::FrameBuffer::Locked(fb).get()); } }; -} -void GambatteMenuHandler::saveState() { - const SaveStateFun fun = { source, MainWindow::FrameBuffer(mw) }; - mw->callInWorkerThread(fun); -} - -namespace { struct LoadStateFun { GambatteSource *source; void operator()() const { source->loadState(); } }; -} -void GambatteMenuHandler::loadState() { - const LoadStateFun fun = { source }; - mw->callInWorkerThread(fun); -} - -namespace { struct SaveStateAsFun { GambatteSource *source; MainWindow::FrameBuffer fb; QString fileName; void operator()() const { - source->saveState(MainWindow::FrameBuffer::Locked(fb).get(), fileName.toLocal8Bit().constData()); + source->saveState(MainWindow::FrameBuffer::Locked(fb).get(), + fileName.toLocal8Bit().constData()); } }; -} -void GambatteMenuHandler::saveStateAs() { - TmpPauser tmpPauser(mw, 4); - mw->waitUntilPaused(); - - const QString &fileName = QFileDialog::getSaveFileName(mw, tr("Save State"), - QString(), tr("Gambatte Quick Save Files (*.gqs);;All Files (*)")); - - if (!fileName.isEmpty()) { - const SaveStateAsFun fun = { source, MainWindow::FrameBuffer(mw), fileName }; - mw->callInWorkerThread(fun); - } -} - -namespace { struct LoadStateFromFun { GambatteSource *source; QString fileName; @@ -812,81 +784,110 @@ struct LoadStateFromFun { source->loadState(fileName.toLocal8Bit().constData()); } }; -} -void GambatteMenuHandler::loadStateFrom() { - TmpPauser tmpPauser(mw, 4); - mw->waitUntilPaused(); - - const QString &fileName = QFileDialog::getOpenFileName(mw, tr("Load State"), - QString(), tr("Gambatte Quick Save Files (*.gqs);;All Files (*)")); - - if (!fileName.isEmpty()) { - const LoadStateFromFun fun = { source, fileName }; - mw->callInWorkerThread(fun); - } -} - -namespace { struct ResetFun { GambatteSource *source; void operator()() const { source->reset(); } }; + +} // anon ns + +void GambatteMenuHandler::selectStateSlot() { + if (QAction *action = stateSlotGroup_->checkedAction()) { + SelectStateFun fun = { source_, action->data().toInt() }; + mw_->callInWorkerThread(fun); + } +} + +void GambatteMenuHandler::saveState() { + SaveStateFun fun = { source_, MainWindow::FrameBuffer(mw_) }; + mw_->callInWorkerThread(fun); +} + +void GambatteMenuHandler::loadState() { + LoadStateFun fun = { source_ }; + mw_->callInWorkerThread(fun); +} + +void GambatteMenuHandler::saveStateAs() { + TmpPauser tmpPauser(mw_, 4); + mw_->waitUntilPaused(); + + QString const &fileName = QFileDialog::getSaveFileName( + mw_, tr("Save State"), QString(), + tr("Gambatte Quick Save Files (*.gqs);;All Files (*)")); + if (!fileName.isEmpty()) { + SaveStateAsFun fun = { source_, MainWindow::FrameBuffer(mw_), fileName }; + mw_->callInWorkerThread(fun); + } +} + +void GambatteMenuHandler::loadStateFrom() { + TmpPauser tmpPauser(mw_, 4); + mw_->waitUntilPaused(); + + QString const &fileName = QFileDialog::getOpenFileName( + mw_, tr("Load State"), QString(), + tr("Gambatte Quick Save Files (*.gqs);;All Files (*)")); + if (!fileName.isEmpty()) { + LoadStateFromFun fun = { source_, fileName }; + mw_->callInWorkerThread(fun); + } } void GambatteMenuHandler::reset() { - const ResetFun fun = { source }; - mw->callInWorkerThread(fun); + ResetFun fun = { source_ }; + mw_->callInWorkerThread(fun); } void GambatteMenuHandler::pauseChange() { - if (pauseAction->isChecked()) - mw->pause(); + if (pauseAction_->isChecked()) + mw_->pause(); else - mw->unpause(); + mw_->unpause(); } void GambatteMenuHandler::frameStep() { - if (pauseAction->isChecked()) - mw->frameStep(); + if (pauseAction_->isChecked()) + mw_->frameStep(); else - pauseAction->trigger(); + pauseAction_->trigger(); } void GambatteMenuHandler::escPressed() { #ifdef Q_WS_MAC - if (fsAct->isChecked()) - fsAct->trigger(); + if (fsAct_->isChecked()) + fsAct_->trigger(); #else - mw->menuBar()->setVisible(!mw->menuBar()->isVisible()); + mw_->menuBar()->setVisible(!mw_->menuBar()->isVisible()); - if (!mw->menuBar()->isVisible()) - mw->hideCursor(); + if (!mw_->menuBar()->isVisible()) + mw_->hideCursor(); #endif } void GambatteMenuHandler::videoBlitterFailure() { - TmpPauser tmpPauser(mw, pauseInc); - QMessageBox::critical(mw, tr("Video engine failure"), + TmpPauser tmpPauser(mw_, pauseInc_); + QMessageBox::critical(mw_, tr("Video engine failure"), tr("Failed to update video output. This may be fixed by changing the video engine settings.")); - videoDialog->exec(); + videoDialog_->exec(); } void GambatteMenuHandler::audioEngineFailure() { - TmpPauser tmpPauser(mw, pauseInc); - QMessageBox::critical(mw, tr("Sound engine failure"), + TmpPauser tmpPauser(mw_, pauseInc_); + QMessageBox::critical(mw_, tr("Sound engine failure"), tr("Failed to output audio. This may be fixed by changing the sound settings.")); - soundDialog->exec(); + soundDialog_->exec(); } void GambatteMenuHandler::toggleFullScreen() { saveWindowSizeIfNotFullScreen(); - mw->toggleFullScreen(); + mw_->toggleFullScreen(); } void GambatteMenuHandler::saveWindowSizeIfNotFullScreen() { - if (!mw->isFullScreen()) { + if (!mw_->isFullScreen()) { QSettings settings; - settings.setValue("mainwindow/size", mw->size()); + settings.setValue("mainwindow/size", mw_->size()); } } diff --git a/gambatte_qt/src/gambattemenuhandler.h b/gambatte_qt/src/gambattemenuhandler.h index 7883e15c..ee503c29 100644 --- a/gambatte_qt/src/gambattemenuhandler.h +++ b/gambatte_qt/src/gambattemenuhandler.h @@ -20,8 +20,8 @@ #define GAMBATTEMENUHANDLER_H #include "scalingmethod.h" -#include #include +#include #include class MainWindow; @@ -37,6 +37,17 @@ class MiscDialog; class CheatDialog; class FrameRateAdjuster : public QObject { +public: + FrameRateAdjuster(MiscDialog const &miscDialog, MainWindow &mw, QObject *parent = 0); + QList const actions(); + +public slots: + void setDisabled(bool disabled); + void decFrameRate(); + void incFrameRate(); + void resetFrameRate(); + +private: Q_OBJECT class FrameTime { @@ -47,36 +58,32 @@ class FrameRateAdjuster : public QObject { Rational(unsigned num = 0, unsigned denom = 1) : num(num), denom(denom) {} }; - private: - enum { STEPS = 16 }; - - Rational frameTimes[STEPS * 2 + 1]; - unsigned index; - - public: FrameTime(unsigned baseNum, unsigned baseDenom); void setBaseFrameTime(unsigned baseNum, unsigned baseDenom); - - bool incPossible() const { return index < STEPS * 2; } - bool decPossible() const { return index; } - bool resetPossible() const { return index != STEPS; } + bool incPossible() const { return index_ < num_steps * 2; } + bool decPossible() const { return index_; } + bool resetPossible() const { return index_ != num_steps; } void inc() { - if (index < STEPS * 2) - ++index; + if (index_ < num_steps * 2) + ++index_; } void dec() { - if (index) - --index; + if (index_) + --index_; } - void reset() { index = STEPS; } - const Rational& get() const { return frameTimes[index]; } - const Rational& base() const { return frameTimes[STEPS]; } - } frameTime_; + void reset() { index_ = num_steps; } + Rational const & get() const { return frameTimes_[index_]; } + Rational const & base() const { return frameTimes_[num_steps]; } - const MiscDialog &miscDialog_; + private: + enum { num_steps = 16 }; + Rational frameTimes_[num_steps * 2 + 1]; + unsigned index_; + } frameTime_; + MiscDialog const &miscDialog_; MainWindow &mw_; QAction *const decFrameRateAction_; QAction *const incFrameRateAction_; @@ -87,68 +94,63 @@ class FrameRateAdjuster : public QObject { private slots: void miscDialogChange(); - -public: - FrameRateAdjuster(const MiscDialog &miscDialog, MainWindow &mw, QObject *parent = 0); - const QList actions(); - -public slots: - void setDisabled(bool disabled); - void decFrameRate(); - void incFrameRate(); - void resetFrameRate(); }; class WindowSizeMenu : public QObject { +public: + WindowSizeMenu(MainWindow &mw, VideoDialog const &videoDialog); + ~WindowSizeMenu(); + QMenu * menu() const { return menu_; } + void videoDialogChange(VideoDialog const &vd); + +private: Q_OBJECT - MainWindow *const mw_; + MainWindow &mw_; QMenu *const menu_; QActionGroup *group_; - const QSize maxSize_; + QSize const maxSize_; - void fillMenu(const QSize &sourceSize, ScalingMethod scalingMethod); - void setCheckedSize(const QSize &size); - const QSize checkedSize() const; + void fillMenu(QSize const &sourceSize, ScalingMethod scalingMethod); + void setCheckedSize(QSize const &size); + QSize const checkedSize() const; private slots: - void triggered(QAction*); - -public: - WindowSizeMenu(MainWindow *mw, const VideoDialog *videoDialog); - ~WindowSizeMenu(); - QMenu* menu() const { return menu_; } - void videoDialogChange(const VideoDialog *vd); + void triggered(QAction *); }; class GambatteMenuHandler : public QObject { +public: + GambatteMenuHandler(MainWindow *mw, GambatteSource *source, + int argc, char const *const argv[]); + ~GambatteMenuHandler(); + +private: Q_OBJECT - enum { MaxRecentFiles = 9 }; + enum { max_recent_files = 9 }; - MainWindow *const mw; - GambatteSource *const source; - SoundDialog *const soundDialog; - VideoDialog *const videoDialog; - MiscDialog *const miscDialog; - CheatDialog *const cheatDialog; - QAction *recentFileActs[MaxRecentFiles]; - QAction *pauseAction; - QAction *syncFrameRateAction; - QAction *gbaCgbAction; - QAction *forceDmgAction; -#ifdef Q_WS_MAC - QAction *fsAct; -#endif - QMenu *recentMenu; - PaletteDialog *globalPaletteDialog; - PaletteDialog *romPaletteDialog; - QActionGroup *const stateSlotGroup; - WindowSizeMenu windowSizeMenu; - unsigned pauseInc; + MainWindow *const mw_; + GambatteSource *const source_; + SoundDialog *const soundDialog_; + VideoDialog *const videoDialog_; + MiscDialog *const miscDialog_; + CheatDialog *const cheatDialog_; + QAction *recentFileActs_[max_recent_files]; + QAction *pauseAction_; + QAction *syncFrameRateAction_; + QAction *gbaCgbAction_; + QAction *forceDmgAction_; + QAction *fsAct_; + QMenu *recentMenu_; + PaletteDialog *globalPaletteDialog_; + PaletteDialog *romPaletteDialog_; + QActionGroup *const stateSlotGroup_; + WindowSizeMenu windowSizeMenu_; + unsigned pauseInc_; - void loadFile(const QString &fileName); - void setCurrentFile(const QString &fileName); + void loadFile(QString const &fileName); + void setCurrentFile(QString const &fileName); void setDmgPaletteColors(); void updateRecentFileActions(); @@ -188,10 +190,6 @@ private slots: void audioEngineFailure(); void toggleFullScreen(); void saveWindowSizeIfNotFullScreen(); - -public: - GambatteMenuHandler(MainWindow *mw, GambatteSource *source, int argc, const char *const argv[]); - ~GambatteMenuHandler(); }; #endif diff --git a/gambatte_qt/src/gambattesource.cpp b/gambatte_qt/src/gambattesource.cpp index 10038d35..b68d784f 100644 --- a/gambatte_qt/src/gambattesource.cpp +++ b/gambatte_qt/src/gambattesource.cpp @@ -19,32 +19,15 @@ #include "gambattesource.h" #include "videolink/rgb32conv.h" #include "videolink/vfilterinfo.h" -#include - -using namespace gambatte; - -GambatteSource::GambatteSource() -: MediaSource(2064), - inputDialog_(createInputDialog()), - pxformat(PixelBuffer::RGB32), - vsrci(0), - dpadUp(false), - dpadDown(false), - dpadLeft(false), - dpadRight(false), - dpadUpLast(false), - dpadLeftLast(false) -{ - gb.setInputGetter(&inputGetter); - std::memset(inputState, 0, sizeof inputState); -} namespace { -static const InputDialog::Button makeButtonInfo(InputDialog::Button::Action *action, const char *label, - const char *category, int defaultKey = Qt::Key_unknown, int defaultAltKey = Qt::Key_unknown, +using namespace gambatte; + +static InputDialog::Button makeButtonInfo(InputDialog::Button::Action *action, char const *label, + char const *category, int defaultKey = Qt::Key_unknown, int defaultAltKey = Qt::Key_unknown, unsigned char defaultFpp = 0) { - const InputDialog::Button b = { label: label, category: category, defaultKey: defaultKey, + InputDialog::Button b = { label: label, category: category, defaultKey: defaultKey, defaultAltKey: defaultAltKey, action: action, defaultFpp: defaultFpp }; return b; } @@ -52,7 +35,7 @@ static const InputDialog::Button makeButtonInfo(InputDialog::Button::Action *act template struct CallAct : InputDialog::Button::Action { GambatteSource *const source; - explicit CallAct(GambatteSource *const source) : source(source) {} + explicit CallAct(GambatteSource *source) : source(source) {} virtual void buttonPressed() { (source->*fun)(); } }; @@ -64,13 +47,27 @@ struct GbDirAct : InputDialog::Button::Action { virtual void buttonReleased() { a = false; } }; -enum { A_BUT, B_BUT, SELECT_BUT, START_BUT, RIGHT_BUT, LEFT_BUT, UP_BUT, DOWN_BUT }; +enum { a_but, b_but, select_but, start_but, right_but, left_but, up_but, down_but }; +} // anon ns + +GambatteSource::GambatteSource() +: MediaSource(2064) +, inputDialog_(createInputDialog()) +, pxformat_(PixelBuffer::RGB32) +, vsrci_(0) +, inputState_() +, dpadUp_(false) +, dpadDown_(false) +, dpadLeft_(false) +, dpadRight_(false) +, dpadUpLast_(false) +, dpadLeftLast_(false) +{ + gb_.setInputGetter(&inputGetter_); } -InputDialog* GambatteSource::createInputDialog() { - std::vector v; - +InputDialog * GambatteSource::createInputDialog() { struct GbButAct : InputDialog::Button::Action { bool &a; explicit GbButAct(bool &a) : a(a) {} @@ -80,19 +77,20 @@ InputDialog* GambatteSource::createInputDialog() { struct FastForwardAct : InputDialog::Button::Action { GambatteSource *const source; - explicit FastForwardAct(GambatteSource *const source) : source(source) {} + explicit FastForwardAct(GambatteSource *source) : source(source) {} virtual void buttonPressed() { source->emitSetTurbo(true); } virtual void buttonReleased() { source->emitSetTurbo(false); } }; - v.push_back(makeButtonInfo(new GbDirAct(dpadUp, dpadUpLast), "Up", "Game", Qt::Key_Up)); - v.push_back(makeButtonInfo(new GbDirAct(dpadDown, dpadUpLast), "Down", "Game", Qt::Key_Down)); - v.push_back(makeButtonInfo(new GbDirAct(dpadLeft, dpadLeftLast), "Left", "Game", Qt::Key_Left)); - v.push_back(makeButtonInfo(new GbDirAct(dpadRight, dpadLeftLast), "Right", "Game", Qt::Key_Right)); - v.push_back(makeButtonInfo(new GbButAct(inputState[A_BUT]), "A", "Game", Qt::Key_D)); - v.push_back(makeButtonInfo(new GbButAct(inputState[B_BUT]), "B", "Game", Qt::Key_C)); - v.push_back(makeButtonInfo(new GbButAct(inputState[START_BUT]), "Start", "Game", Qt::Key_Return)); - v.push_back(makeButtonInfo(new GbButAct(inputState[SELECT_BUT]), "Select", "Game", Qt::Key_Shift)); + std::vector v; + v.push_back(makeButtonInfo(new GbDirAct(dpadUp_, dpadUpLast_), "Up", "Game", Qt::Key_Up)); + v.push_back(makeButtonInfo(new GbDirAct(dpadDown_, dpadUpLast_), "Down", "Game", Qt::Key_Down)); + v.push_back(makeButtonInfo(new GbDirAct(dpadLeft_, dpadLeftLast_), "Left", "Game", Qt::Key_Left)); + v.push_back(makeButtonInfo(new GbDirAct(dpadRight_, dpadLeftLast_), "Right", "Game", Qt::Key_Right)); + v.push_back(makeButtonInfo(new GbButAct(inputState_[a_but]), "A", "Game", Qt::Key_D)); + v.push_back(makeButtonInfo(new GbButAct(inputState_[b_but]), "B", "Game", Qt::Key_C)); + v.push_back(makeButtonInfo(new GbButAct(inputState_[start_but]), "Start", "Game", Qt::Key_Return)); + v.push_back(makeButtonInfo(new GbButAct(inputState_[select_but]), "Select", "Game", Qt::Key_Shift)); v.push_back(makeButtonInfo(new CallAct<&GambatteSource::emitPause>(this), "Pause", "Play", Qt::Key_Pause)); v.push_back(makeButtonInfo(new CallAct<&GambatteSource::emitFrameStep>(this), "Frame step", "Play", Qt::Key_F1)); v.push_back(makeButtonInfo(new CallAct<&GambatteSource::emitDecFrameRate>(this), @@ -108,21 +106,20 @@ InputDialog* GambatteSource::createInputDialog() { "Previous state slot", "State", Qt::Key_F6)); v.push_back(makeButtonInfo(new CallAct<&GambatteSource::emitNextStateSlot>(this), "Next state slot", "State", Qt::Key_F7)); - v.push_back(makeButtonInfo(new GbButAct(inputState[8 + A_BUT]), "Turbo A", "Other", + v.push_back(makeButtonInfo(new GbButAct(inputState_[8 + a_but]), "Turbo A", "Other", Qt::Key_unknown, Qt::Key_unknown, 1)); - v.push_back(makeButtonInfo(new GbButAct(inputState[8 + B_BUT]), "Turbo B", "Other", + v.push_back(makeButtonInfo(new GbButAct(inputState_[8 + b_but]), "Turbo B", "Other", Qt::Key_unknown, Qt::Key_unknown, 1)); v.push_back(makeButtonInfo(new CallAct<&GambatteSource::emitQuit>(this), "Quit", "Other")); return new InputDialog(v); } -const std::vector GambatteSource::generateVideoSourceInfos() { +std::vector const GambatteSource::generateVideoSourceInfos() { std::vector v(VfilterInfo::numVfilters()); - for (std::size_t i = 0; i < v.size(); ++i) { - const VideoDialog::VideoSourceInfo vsi = { label: VfilterInfo::get(i).handle, - width: VfilterInfo::get(i).outWidth, height: VfilterInfo::get(i).outHeight }; + VideoDialog::VideoSourceInfo vsi = { label: VfilterInfo::get(i).handle, + width: VfilterInfo::get(i).outWidth, height: VfilterInfo::get(i).outHeight }; v[i] = vsi; } @@ -130,15 +127,15 @@ const std::vector GambatteSource::generateVideoSou return v; } -void GambatteSource::keyPressEvent(const QKeyEvent *e) { +void GambatteSource::keyPressEvent(QKeyEvent const *e) { inputDialog_->keyPressEvent(e); } -void GambatteSource::keyReleaseEvent(const QKeyEvent *e) { +void GambatteSource::keyReleaseEvent(QKeyEvent const *e) { inputDialog_->keyReleaseEvent(e); } -void GambatteSource::joystickEvent(const SDL_Event &e) { +void GambatteSource::joystickEvent(SDL_Event const &e) { inputDialog_->joystickEvent(e); } @@ -147,22 +144,23 @@ struct GambatteSource::GbVidBuf { GbVidBuf(uint_least32_t *pixels, std::ptrdiff_t pitch) : pixels(pixels), pitch(pitch) {} }; -const GambatteSource::GbVidBuf GambatteSource::setPixelBuffer( +GambatteSource::GbVidBuf GambatteSource::setPixelBuffer( void *pixels, PixelBuffer::PixelFormat format, std::ptrdiff_t pitch) { - if (pxformat != format && pixels) { - pxformat = format; - cconvert.reset(); - cconvert.reset(Rgb32Conv::create(static_cast(pxformat), - VfilterInfo::get(vsrci).outWidth, VfilterInfo::get(vsrci).outHeight)); + if (pxformat_ != format && pixels) { + pxformat_ = format; + cconvert_.reset(); + cconvert_.reset(Rgb32Conv::create(static_cast(pxformat_), + VfilterInfo::get(vsrci_).outWidth, + VfilterInfo::get(vsrci_).outHeight)); } - if (VideoLink *const gblink = vfilter.get() ? vfilter.get() : cconvert.get()) - return GbVidBuf(static_cast(gblink->inBuf()), gblink->inPitch()); + if (VideoLink *gblink = vfilter_ ? vfilter_.get() : cconvert_.get()) + return GbVidBuf(static_cast(gblink->inBuf()), gblink->inPitch()); - return GbVidBuf(static_cast(pixels), pitch); + return GbVidBuf(static_cast(pixels), pitch); } -static void setGbDir(bool &a, bool &b, const bool aPressed, const bool bPressed, const bool preferA) { +static void setGbDir(bool &a, bool &b, bool const aPressed, bool const bPressed, bool const preferA) { if (aPressed & bPressed) { a = aPressed & preferA; b = (aPressed & preferA) ^ 1; @@ -172,38 +170,36 @@ static void setGbDir(bool &a, bool &b, const bool aPressed, const bool bPressed, } } -static unsigned packedInputState(const bool inputState[], const std::size_t len) { +static unsigned packedInputState(bool const inputState[], std::size_t const len) { unsigned is = 0; - for (std::size_t i = 0; i < len; ++i) is |= inputState[i] << (i & 7); return is; } -static void* getpbdata(const PixelBuffer &pb, const unsigned vsrci) { +static void * getpbdata(PixelBuffer const &pb, unsigned vsrci) { return pb.width == VfilterInfo::get(vsrci).outWidth && pb.height == VfilterInfo::get(vsrci).outHeight ? pb.data : 0; } -long GambatteSource::update(const PixelBuffer &pb, qint16 *const soundBuf, long &samples) { - const GbVidBuf gbvidbuf = setPixelBuffer(getpbdata(pb, vsrci), pb.pixelFormat, pb.pitch); +long GambatteSource::update(PixelBuffer const &pb, qint16 *const soundBuf, long &samples) { + GbVidBuf const gbvidbuf = setPixelBuffer(getpbdata(pb, vsrci_), pb.pixelFormat, pb.pitch); samples -= overupdate; - if (samples < 0) { samples = 0; return -1; } - setGbDir(inputState[UP_BUT], inputState[DOWN_BUT], dpadUp, dpadDown, dpadUpLast); - setGbDir(inputState[LEFT_BUT], inputState[RIGHT_BUT], dpadLeft, dpadRight, dpadLeftLast); - inputGetter.is = packedInputState(inputState, sizeof inputState / sizeof inputState[0]); + setGbDir(inputState_[up_but], inputState_[down_but], dpadUp_, dpadDown_, dpadUpLast_); + setGbDir(inputState_[left_but], inputState_[right_but], dpadLeft_, dpadRight_, dpadLeftLast_); + inputGetter_.is = packedInputState(inputState_, sizeof inputState_ / sizeof inputState_[0]); unsigned usamples = samples; - const long retval = gb.runFor(gbvidbuf.pixels, gbvidbuf.pitch, - reinterpret_cast(soundBuf), usamples); + long const retval = gb_.runFor(gbvidbuf.pixels, gbvidbuf.pitch, + reinterpret_cast(soundBuf), usamples); samples = usamples; if (retval >= 0) @@ -212,38 +208,39 @@ long GambatteSource::update(const PixelBuffer &pb, qint16 *const soundBuf, long return retval; } -void GambatteSource::generateVideoFrame(const PixelBuffer &pb) { - if (void *const pbdata = getpbdata(pb, vsrci)) { +void GambatteSource::generateVideoFrame(PixelBuffer const &pb) { + if (void *const pbdata = getpbdata(pb, vsrci_)) { setPixelBuffer(pbdata, pb.pixelFormat, pb.pitch); - if (vfilter.get()) { - if (cconvert.get()) { - vfilter->draw(cconvert->inBuf(), cconvert->inPitch()); - cconvert->draw(pbdata, pb.pitch); + if (vfilter_) { + if (cconvert_) { + vfilter_->draw(cconvert_->inBuf(), cconvert_->inPitch()); + cconvert_->draw(pbdata, pb.pitch); } else - vfilter->draw(pbdata, pb.pitch); - } else if (cconvert.get()) - cconvert->draw(pbdata, pb.pitch); + vfilter_->draw(pbdata, pb.pitch); + } else if (cconvert_) + cconvert_->draw(pbdata, pb.pitch); } } -void GambatteSource::setVideoSource(unsigned videoSourceIndex) { - if (videoSourceIndex != vsrci) { - vsrci = videoSourceIndex; - vfilter.reset(); - cconvert.reset(); - vfilter.reset(VfilterInfo::get(vsrci).create()); - cconvert.reset(Rgb32Conv::create(static_cast(pxformat), - VfilterInfo::get(vsrci).outWidth, VfilterInfo::get(vsrci).outHeight)); +void GambatteSource::setVideoSource(unsigned const videoSourceIndex) { + if (videoSourceIndex != vsrci_) { + vsrci_ = videoSourceIndex; + vfilter_.reset(); + cconvert_.reset(); + vfilter_.reset(VfilterInfo::get(vsrci_).create()); + cconvert_.reset(Rgb32Conv::create(static_cast(pxformat_), + VfilterInfo::get(vsrci_).outWidth, + VfilterInfo::get(vsrci_).outHeight)); } } -void GambatteSource::saveState(const PixelBuffer &pb) { - const GbVidBuf gbvidbuf = setPixelBuffer(getpbdata(pb, vsrci), pb.pixelFormat, pb.pitch); - gb.saveState(gbvidbuf.pixels, gbvidbuf.pitch); +void GambatteSource::saveState(PixelBuffer const &pb) { + GbVidBuf gbvidbuf = setPixelBuffer(getpbdata(pb, vsrci_), pb.pixelFormat, pb.pitch); + gb_.saveState(gbvidbuf.pixels, gbvidbuf.pitch); } -void GambatteSource::saveState(const PixelBuffer &pb, const std::string &filepath) { - const GbVidBuf gbvidbuf = setPixelBuffer(getpbdata(pb, vsrci), pb.pixelFormat, pb.pitch); - gb.saveState(gbvidbuf.pixels, gbvidbuf.pitch, filepath); +void GambatteSource::saveState(PixelBuffer const &pb, std::string const &filepath) { + GbVidBuf gbvidbuf = setPixelBuffer(getpbdata(pb, vsrci_), pb.pixelFormat, pb.pitch); + gb_.saveState(gbvidbuf.pixels, gbvidbuf.pitch, filepath); } diff --git a/gambatte_qt/src/gambattesource.h b/gambatte_qt/src/gambattesource.h index 5f73c76f..65fdfbba 100644 --- a/gambatte_qt/src/gambattesource.h +++ b/gambatte_qt/src/gambattesource.h @@ -31,76 +31,36 @@ #include class GambatteSource : public QObject, public MediaSource { - Q_OBJECT - - struct GbVidBuf; - struct GetInput : public gambatte::InputGetter { - unsigned is; - GetInput() : is(0) {} - unsigned operator()() { return is; } - }; - - gambatte::GB gb; - GetInput inputGetter; - InputDialog *const inputDialog_; - scoped_ptr cconvert; - scoped_ptr vfilter; - PixelBuffer::PixelFormat pxformat; - unsigned vsrci; - bool inputState[10]; - bool dpadUp, dpadDown; - bool dpadLeft, dpadRight; - bool dpadUpLast, dpadLeftLast; - - InputDialog* createInputDialog(); - const GbVidBuf setPixelBuffer(void *pixels, PixelBuffer::PixelFormat format, std::ptrdiff_t pitch); - - void emitSetTurbo(bool on) { emit setTurbo(on); } - void emitPause() { emit togglePause(); } - void emitFrameStep() { emit frameStep(); } - void emitDecFrameRate() { emit decFrameRate(); } - void emitIncFrameRate() { emit incFrameRate(); } - void emitResetFrameRate() { emit resetFrameRate(); } - void emitPrevStateSlot() { emit prevStateSlot(); } - void emitNextStateSlot() { emit nextStateSlot(); } - void emitSaveState() { emit saveStateSignal(); } - void emitLoadState() { emit loadStateSignal(); } - void emitQuit() { emit quit(); } - public: GambatteSource(); - - const std::vector generateVideoSourceInfos(); - - gambatte::LoadRes load(std::string const &romfile, unsigned flags) { return gb.load(romfile, flags); } - void setGameGenie(const std::string &codes) { gb.setGameGenie(codes); } - void setGameShark(const std::string &codes) { gb.setGameShark(codes); } - void reset() { gb.reset(); } + std::vector const generateVideoSourceInfos(); + gambatte::LoadRes load(std::string const &romfile, unsigned flags) { return gb_.load(romfile, flags); } + void setGameGenie(std::string const &codes) { gb_.setGameGenie(codes); } + void setGameShark(std::string const &codes) { gb_.setGameShark(codes); } + void reset() { gb_.reset(); } void setDmgPaletteColor(unsigned palNum, unsigned colorNum, unsigned rgb32) { - gb.setDmgPaletteColor(palNum, colorNum, rgb32); + gb_.setDmgPaletteColor(palNum, colorNum, rgb32); } - void setSavedir(const std::string &sdir) { gb.setSaveDir(sdir); } + void setSavedir(std::string const &sdir) { gb_.setSaveDir(sdir); } void setVideoSource(unsigned videoSourceIndex); - bool isCgb() const { return gb.isCgb(); } - const std::string romTitle() const { return gb.romTitle(); } - gambatte::PakInfo const pakInfo() const { return gb.pakInfo(); } - void selectState(int n) { gb.selectState(n); } - int currentState() const { return gb.currentState(); } - void saveState(const PixelBuffer &fb, const std::string &filepath); - void loadState(const std::string &filepath) { gb.loadState(filepath); } - QDialog* inputDialog() const { return inputDialog_; } + bool isCgb() const { return gb_.isCgb(); } + std::string const romTitle() const { return gb_.romTitle(); } + gambatte::PakInfo pakInfo() const { return gb_.pakInfo(); } + void selectState(int n) { gb_.selectState(n); } + int currentState() const { return gb_.currentState(); } + void saveState(PixelBuffer const &fb, std::string const &filepath); + void loadState(std::string const &filepath) { gb_.loadState(filepath); } + QDialog * inputDialog() const { return inputDialog_; } + void saveState(PixelBuffer const &fb); + void loadState() { gb_.loadState(); } - //overrides - virtual void keyPressEvent(const QKeyEvent *); - virtual void keyReleaseEvent(const QKeyEvent *); - virtual void joystickEvent(const SDL_Event&); - virtual long update(const PixelBuffer &fb, qint16 *soundBuf, long &samples); - virtual void generateVideoFrame(const PixelBuffer &fb); - - void saveState(const PixelBuffer &fb); - void loadState() { gb.loadState(); } + virtual void keyPressEvent(QKeyEvent const *); + virtual void keyReleaseEvent(QKeyEvent const *); + virtual void joystickEvent(SDL_Event const &); + virtual long update(PixelBuffer const &fb, qint16 *soundBuf, long &samples); + virtual void generateVideoFrame(PixelBuffer const &fb); signals: void setTurbo(bool on); @@ -114,6 +74,42 @@ signals: void saveStateSignal(); void loadStateSignal(); void quit(); + +private: + Q_OBJECT + + struct GbVidBuf; + struct GetInput : gambatte::InputGetter { + unsigned is; + GetInput() : is(0) {} + virtual unsigned operator()() { return is; } + }; + + gambatte::GB gb_; + GetInput inputGetter_; + InputDialog *const inputDialog_; + scoped_ptr cconvert_; + scoped_ptr vfilter_; + PixelBuffer::PixelFormat pxformat_; + unsigned vsrci_; + bool inputState_[10]; + bool dpadUp_, dpadDown_; + bool dpadLeft_, dpadRight_; + bool dpadUpLast_, dpadLeftLast_; + + InputDialog * createInputDialog(); + GbVidBuf setPixelBuffer(void *pixels, PixelBuffer::PixelFormat format, std::ptrdiff_t pitch); + void emitSetTurbo(bool on) { emit setTurbo(on); } + void emitPause() { emit togglePause(); } + void emitFrameStep() { emit frameStep(); } + void emitDecFrameRate() { emit decFrameRate(); } + void emitIncFrameRate() { emit incFrameRate(); } + void emitResetFrameRate() { emit resetFrameRate(); } + void emitPrevStateSlot() { emit prevStateSlot(); } + void emitNextStateSlot() { emit nextStateSlot(); } + void emitSaveState() { emit saveStateSignal(); } + void emitLoadState() { emit loadStateSignal(); } + void emitQuit() { emit quit(); } }; #endif diff --git a/gambatte_qt/src/main.cpp b/gambatte_qt/src/main.cpp index c55b132e..ce8c952d 100644 --- a/gambatte_qt/src/main.cpp +++ b/gambatte_qt/src/main.cpp @@ -16,22 +16,20 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ - +#include "gambattemenuhandler.h" +#include "gambattesource.h" +#include "mainwindow.h" #include #include -#include "mainwindow.h" -#include "gambattesource.h" -#include "gambattemenuhandler.h" int main(int argc, char *argv[]) { -// Q_INIT_RESOURCE(application); QApplication app(argc, argv); QCoreApplication::setOrganizationName("gambatte"); QCoreApplication::setApplicationName("gambatte_qt"); + GambatteSource source; MainWindow mw(&source); GambatteMenuHandler mh(&mw, &source, argc, argv); - mw.show(); return app.exec(); } diff --git a/gambatte_qt/src/miscdialog.cpp b/gambatte_qt/src/miscdialog.cpp index a87325fd..f4417c81 100755 --- a/gambatte_qt/src/miscdialog.cpp +++ b/gambatte_qt/src/miscdialog.cpp @@ -18,39 +18,39 @@ ***************************************************************************/ #include "miscdialog.h" #include "mainwindow.h" -#include #include #include -#include -#include #include +#include #include #include +#include +#include template -static ChildLayout * addLayout(Parent *const parent, ChildLayout *const child) { +static ChildLayout * addLayout(Parent *parent, ChildLayout *child) { parent->addLayout(child); return child; } template -static ChildLayout * addLayout(Parent *const parent, ChildLayout *const child, const Qt::Alignment alignment) { +static ChildLayout * addLayout(Parent *parent, ChildLayout *child, Qt::Alignment alignment) { parent->addLayout(child); parent->setAlignment(child, alignment); return child; } -MiscDialog::MiscDialog(const QString &savepath, QWidget *const parent) -: QDialog(parent), - turboSpeedBox(new QSpinBox(this)), - savepathSelector_("Choose Save Path:", "misc/savepath", +MiscDialog::MiscDialog(QString const &savepath, QWidget *parent) +: QDialog(parent) +, turboSpeedBox(new QSpinBox(this)) +, savepathSelector_("Choose Save Path:", "misc/savepath", std::make_pair(QDir::toNativeSeparators(savepath), savepath), - std::make_pair(tr("Same folder as ROM image"), QString())), - pauseOnDialogs_(new QCheckBox(tr("Pause when displaying dialogs"), this), "misc/pauseOnDialogs", true), - pauseOnFocusOut_(new QCheckBox(tr("Pause on focus out"), this), "misc/pauseOnFocusOut", false), - dwmTripleBuf_(new QCheckBox(tr("DWM triple buffering"), this), "misc/dwmTripleBuf", true), - multicartCompat_(new QCheckBox(tr("Multicart compatibility"), this), "misc/multicartCompat", false), - turboSpeed_(8) + std::make_pair(tr("Same folder as ROM image"), QString())) +, pauseOnDialogs_(new QCheckBox(tr("Pause when displaying dialogs"), this), "misc/pauseOnDialogs", true) +, pauseOnFocusOut_(new QCheckBox(tr("Pause on focus out"), this), "misc/pauseOnFocusOut", false) +, dwmTripleBuf_(new QCheckBox(tr("DWM triple buffering"), this), "misc/dwmTripleBuf", true) +, multicartCompat_(new QCheckBox(tr("Multicart compatibility"), this), "misc/multicartCompat", false) +, turboSpeed_(8) { setWindowTitle(tr("Miscellaneous Settings")); turboSpeedBox->setRange(2, 16); @@ -60,7 +60,7 @@ MiscDialog::MiscDialog(const QString &savepath, QWidget *const parent) QVBoxLayout *const topLayout = addLayout(mainLayout, new QVBoxLayout); { - QHBoxLayout *const hLayout = addLayout(topLayout, new QHBoxLayout); + QHBoxLayout *hLayout = addLayout(topLayout, new QHBoxLayout); hLayout->addWidget(new QLabel(tr("Fast-forward speed:"))); hLayout->addWidget(turboSpeedBox); } @@ -69,22 +69,24 @@ MiscDialog::MiscDialog(const QString &savepath, QWidget *const parent) addLayout(topLayout, new QHBoxLayout)->addWidget(pauseOnFocusOut_.checkBox()); { - QHBoxLayout *const hLayout = addLayout(topLayout, new QHBoxLayout); + QHBoxLayout *hLayout = addLayout(topLayout, new QHBoxLayout); hLayout->addWidget(new QLabel(tr("Base frame rate:"))); hLayout->addWidget(fpsSelector_.widget()); } if (MainWindow::hasDwmCapability()) { - dwmTripleBuf_.checkBox()->setToolTip(tr("Avoids excessive frame duplication when DWM composition is active. Recommended.")); + dwmTripleBuf_.checkBox()->setToolTip(tr( + "Avoids excessive frame duplication when DWM composition is active. Recommended.")); addLayout(topLayout, new QHBoxLayout)->addWidget(dwmTripleBuf_.checkBox()); } else dwmTripleBuf_.checkBox()->hide(); - multicartCompat_.checkBox()->setToolTip(tr("Support certain multicart ROM images by not strictly respecting ROM header MBC type.")); + multicartCompat_.checkBox()->setToolTip(tr( + "Support certain multicart ROM images by not strictly respecting ROM header MBC type.")); addLayout(topLayout, new QHBoxLayout)->addWidget(multicartCompat_.checkBox()); { - QHBoxLayout *const hLayout = addLayout(topLayout, new QHBoxLayout); + QHBoxLayout *hLayout = addLayout(topLayout, new QHBoxLayout); hLayout->addWidget(new QLabel(tr("Save path:"))); hLayout->addWidget(savepathSelector_.widget()); } @@ -92,18 +94,17 @@ MiscDialog::MiscDialog(const QString &savepath, QWidget *const parent) { QPushButton *const okButton = new QPushButton(tr("OK"), this); QPushButton *const cancelButton = new QPushButton(tr("Cancel"), this); - QHBoxLayout *const hLayout = addLayout(mainLayout, new QHBoxLayout, Qt::AlignBottom | Qt::AlignRight); - + QHBoxLayout *const hLayout = addLayout(mainLayout, new QHBoxLayout, + Qt::AlignBottom | Qt::AlignRight); hLayout->addWidget(okButton); hLayout->addWidget(cancelButton); - okButton->setDefault(true); - connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); } - turboSpeed_ = std::min(std::max(QSettings().value("misc/turboSpeed", turboSpeed_).toInt(), 2), 16); + turboSpeed_ = std::min(std::max(QSettings().value("misc/turboSpeed", turboSpeed_).toInt(), 2), + 16); restore(); } diff --git a/gambatte_qt/src/miscdialog.h b/gambatte_qt/src/miscdialog.h index f01eb6db..abab50dc 100755 --- a/gambatte_qt/src/miscdialog.h +++ b/gambatte_qt/src/miscdialog.h @@ -19,14 +19,30 @@ #ifndef MISCDIALOG_H #define MISCDIALOG_H -class QSpinBox; - #include "fpsselector.h" #include "pathselector.h" #include "persistcheckbox.h" #include +class QSpinBox; + class MiscDialog : public QDialog { +public: + explicit MiscDialog(QString const &savePath, QWidget *parent = 0); + virtual ~MiscDialog(); + int turboSpeed() const { return turboSpeed_; } + bool pauseOnDialogs() const { return pauseOnDialogs_.value() | pauseOnFocusOut_.value(); } + bool pauseOnFocusOut() const { return pauseOnFocusOut_.value(); } + bool dwmTripleBuf() const { return dwmTripleBuf_.value(); } + bool multicartCompat() const { return multicartCompat_.value(); } + QSize const baseFps() const { return fpsSelector_.value(); } + QString const & savePath() const { return savepathSelector_.value(); } + +public slots: + virtual void accept(); + virtual void reject(); + +private: QSpinBox *const turboSpeedBox; FpsSelector fpsSelector_; PathSelector savepathSelector_; @@ -38,21 +54,6 @@ class MiscDialog : public QDialog { void store(); void restore(); - -public: - explicit MiscDialog(const QString &savePath, QWidget *parent = 0); - ~MiscDialog(); - int turboSpeed() const { return turboSpeed_; } - bool pauseOnDialogs() const { return pauseOnDialogs_.value() | pauseOnFocusOut_.value(); } - bool pauseOnFocusOut() const { return pauseOnFocusOut_.value(); } - bool dwmTripleBuf() const { return dwmTripleBuf_.value(); } - bool multicartCompat() const { return multicartCompat_.value(); } - const QSize & baseFps() const { return fpsSelector_.value(); } - const QString & savePath() const { return savepathSelector_.value(); } - -public slots: - void accept(); - void reject(); }; #endif diff --git a/gambatte_qt/src/palettedialog.cpp b/gambatte_qt/src/palettedialog.cpp index 78a2a43b..b300dfd3 100644 --- a/gambatte_qt/src/palettedialog.cpp +++ b/gambatte_qt/src/palettedialog.cpp @@ -17,28 +17,29 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "palettedialog.h" -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include #include +#include +#include #include -#include -#include #include -#include +#include +#include +#include #include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include #include #include +#include namespace { @@ -47,307 +48,307 @@ namespace { #define PACK15_4(c0, c1, c2, c3) \ PACK15_1(c0), PACK15_1(c1), PACK15_1(c2), PACK15_1(c3) -static const unsigned short p005[] = { +static unsigned short const p005[] = { PACK15_4(0xFFFFFF, 0x52FF00, 0xFF4200, 0x000000), PACK15_4(0xFFFFFF, 0x52FF00, 0xFF4200, 0x000000), PACK15_4(0xFFFFFF, 0x52FF00, 0xFF4200, 0x000000) }; -static const unsigned short p006[] = { +static unsigned short const p006[] = { PACK15_4(0xFFFFFF, 0xFF9C00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0xFF9C00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0xFF9C00, 0xFF0000, 0x000000) }; -static const unsigned short p007[] = { +static unsigned short const p007[] = { PACK15_4(0xFFFFFF, 0xFFFF00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0xFFFF00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0xFFFF00, 0xFF0000, 0x000000) }; -static const unsigned short p008[] = { +static unsigned short const p008[] = { PACK15_4(0xA59CFF, 0xFFFF00, 0x006300, 0x000000), PACK15_4(0xA59CFF, 0xFFFF00, 0x006300, 0x000000), PACK15_4(0xA59CFF, 0xFFFF00, 0x006300, 0x000000) }; -static const unsigned short p012[] = { +static unsigned short const p012[] = { PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000), PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000), PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000) }; -static const unsigned short p013[] = { +static unsigned short const p013[] = { PACK15_4(0x000000, 0x008484, 0xFFDE00, 0xFFFFFF), PACK15_4(0x000000, 0x008484, 0xFFDE00, 0xFFFFFF), PACK15_4(0x000000, 0x008484, 0xFFDE00, 0xFFFFFF) }; -static const unsigned short p016[] = { +static unsigned short const p016[] = { PACK15_4(0xFFFFFF, 0xA5A5A5, 0x525252, 0x000000), PACK15_4(0xFFFFFF, 0xA5A5A5, 0x525252, 0x000000), PACK15_4(0xFFFFFF, 0xA5A5A5, 0x525252, 0x000000) }; -static const unsigned short p017[] = { +static unsigned short const p017[] = { PACK15_4(0xFFFFA5, 0xFF9494, 0x9494FF, 0x000000), PACK15_4(0xFFFFA5, 0xFF9494, 0x9494FF, 0x000000), PACK15_4(0xFFFFA5, 0xFF9494, 0x9494FF, 0x000000) }; -static const unsigned short p01B[] = { +static unsigned short const p01B[] = { PACK15_4(0xFFFFFF, 0xFFCE00, 0x9C6300, 0x000000), PACK15_4(0xFFFFFF, 0xFFCE00, 0x9C6300, 0x000000), PACK15_4(0xFFFFFF, 0xFFCE00, 0x9C6300, 0x000000) }; -static const unsigned short p100[] = { +static unsigned short const p100[] = { PACK15_4(0xFFFFFF, 0xADAD84, 0x42737B, 0x000000), PACK15_4(0xFFFFFF, 0xFF7300, 0x944200, 0x000000), PACK15_4(0xFFFFFF, 0xADAD84, 0x42737B, 0x000000) }; -static const unsigned short p10B[] = { +static unsigned short const p10B[] = { PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) }; -static const unsigned short p10D[] = { +static unsigned short const p10D[] = { PACK15_4(0xFFFFFF, 0x8C8CDE, 0x52528C, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x8C8CDE, 0x52528C, 0x000000) }; -static const unsigned short p110[] = { +static unsigned short const p110[] = { PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; -static const unsigned short p11C[] = { +static unsigned short const p11C[] = { PACK15_4(0xFFFFFF, 0x7BFF31, 0x0063C5, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x0063C5, 0x000000) }; -static const unsigned short p20B[] = { +static unsigned short const p20B[] = { PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; -static const unsigned short p20C[] = { +static unsigned short const p20C[] = { PACK15_4(0xFFFFFF, 0x8C8CDE, 0x52528C, 0x000000), PACK15_4(0xFFFFFF, 0x8C8CDE, 0x52528C, 0x000000), PACK15_4(0xFFC542, 0xFFD600, 0x943A00, 0x4A0000) }; -static const unsigned short p300[] = { +static unsigned short const p300[] = { PACK15_4(0xFFFFFF, 0xADAD84, 0x42737B, 0x000000), PACK15_4(0xFFFFFF, 0xFF7300, 0x944200, 0x000000), PACK15_4(0xFFFFFF, 0xFF7300, 0x944200, 0x000000) }; -static const unsigned short p304[] = { +static unsigned short const p304[] = { PACK15_4(0xFFFFFF, 0x7BFF00, 0xB57300, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; -static const unsigned short p305[] = { +static unsigned short const p305[] = { PACK15_4(0xFFFFFF, 0x52FF00, 0xFF4200, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; -static const unsigned short p306[] = { +static unsigned short const p306[] = { PACK15_4(0xFFFFFF, 0xFF9C00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; -static const unsigned short p308[] = { +static unsigned short const p308[] = { PACK15_4(0xA59CFF, 0xFFFF00, 0x006300, 0x000000), PACK15_4(0xFF6352, 0xD60000, 0x630000, 0x000000), PACK15_4(0xFF6352, 0xD60000, 0x630000, 0x000000) }; -static const unsigned short p30A[] = { +static unsigned short const p30A[] = { PACK15_4(0xB5B5FF, 0xFFFF94, 0xAD5A42, 0x000000), PACK15_4(0x000000, 0xFFFFFF, 0xFF8484, 0x943A3A), PACK15_4(0x000000, 0xFFFFFF, 0xFF8484, 0x943A3A) }; -static const unsigned short p30C[] = { +static unsigned short const p30C[] = { PACK15_4(0xFFFFFF, 0x8C8CDE, 0x52528C, 0x000000), PACK15_4(0xFFC542, 0xFFD600, 0x943A00, 0x4A0000), PACK15_4(0xFFC542, 0xFFD600, 0x943A00, 0x4A0000) }; -static const unsigned short p30D[] = { +static unsigned short const p30D[] = { PACK15_4(0xFFFFFF, 0x8C8CDE, 0x52528C, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; -static const unsigned short p30E[] = { +static unsigned short const p30E[] = { PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; -static const unsigned short p30F[] = { +static unsigned short const p30F[] = { PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) }; -static const unsigned short p312[] = { +static unsigned short const p312[] = { PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000) }; -static const unsigned short p319[] = { +static unsigned short const p319[] = { PACK15_4(0xFFE6C5, 0xCE9C84, 0x846B29, 0x5A3108), PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000), PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000) }; -static const unsigned short p31C[] = { +static unsigned short const p31C[] = { PACK15_4(0xFFFFFF, 0x7BFF31, 0x0063C5, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; -static const unsigned short p405[] = { +static unsigned short const p405[] = { PACK15_4(0xFFFFFF, 0x52FF00, 0xFF4200, 0x000000), PACK15_4(0xFFFFFF, 0x52FF00, 0xFF4200, 0x000000), PACK15_4(0xFFFFFF, 0x5ABDFF, 0xFF0000, 0x0000FF) }; -static const unsigned short p406[] = { +static unsigned short const p406[] = { PACK15_4(0xFFFFFF, 0xFF9C00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0xFF9C00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0x5ABDFF, 0xFF0000, 0x0000FF ) }; -static const unsigned short p407[] = { +static unsigned short const p407[] = { PACK15_4(0xFFFFFF, 0xFFFF00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0xFFFF00, 0xFF0000, 0x000000), PACK15_4(0xFFFFFF, 0x5ABDFF, 0xFF0000, 0x0000FF) }; -static const unsigned short p500[] = { +static unsigned short const p500[] = { PACK15_4(0xFFFFFF, 0xADAD84, 0x42737B, 0x000000), PACK15_4(0xFFFFFF, 0xFF7300, 0x944200, 0x000000), PACK15_4(0xFFFFFF, 0x5ABDFF, 0xFF0000, 0x0000FF) }; -static const unsigned short p501[] = { +static unsigned short const p501[] = { PACK15_4(0xFFFF9C, 0x94B5FF, 0x639473, 0x003A3A), PACK15_4(0xFFC542, 0xFFD600, 0x943A00, 0x4A0000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; -static const unsigned short p502[] = { +static unsigned short const p502[] = { PACK15_4(0x6BFF00, 0xFFFFFF, 0xFF524A, 0x000000), PACK15_4(0xFFFFFF, 0xFFFFFF, 0x63A5FF, 0x0000FF), PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000) }; -static const unsigned short p503[] = { +static unsigned short const p503[] = { PACK15_4(0x52DE00, 0xFF8400, 0xFFFF00, 0xFFFFFF), PACK15_4(0xFFFFFF, 0xFFFFFF, 0x63A5FF, 0x0000FF), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000) }; -static const unsigned short p508[] = { +static unsigned short const p508[] = { PACK15_4(0xA59CFF, 0xFFFF00, 0x006300, 0x000000), PACK15_4(0xFF6352, 0xD60000, 0x630000, 0x000000), PACK15_4(0x0000FF, 0xFFFFFF, 0xFFFF7B, 0x0084FF) }; -static const unsigned short p509[] = { +static unsigned short const p509[] = { PACK15_4(0xFFFFCE, 0x63EFEF, 0x9C8431, 0x5A5A5A), PACK15_4(0xFFFFFF, 0xFF7300, 0x944200, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) }; -static const unsigned short p50B[] = { +static unsigned short const p50B[] = { PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0xFFFF7B, 0x0084FF, 0xFF0000) }; -static const unsigned short p50C[] = { +static unsigned short const p50C[] = { PACK15_4(0xFFFFFF, 0x8C8CDE, 0x52528C, 0x000000), PACK15_4(0xFFC542, 0xFFD600, 0x943A00, 0x4A0000), PACK15_4(0xFFFFFF, 0x5ABDFF, 0xFF0000, 0x0000FF) }; -static const unsigned short p50D[] = { +static unsigned short const p50D[] = { PACK15_4(0xFFFFFF, 0x8C8CDE, 0x52528C, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000) }; -static const unsigned short p50E[] = { +static unsigned short const p50E[] = { PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) }; -static const unsigned short p50F[] = { +static unsigned short const p50F[] = { PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000) }; -static const unsigned short p510[] = { +static unsigned short const p510[] = { PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) }; -static const unsigned short p511[] = { +static unsigned short const p511[] = { PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x00FF00, 0x318400, 0x004A00), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) }; -static const unsigned short p512[] = { +static unsigned short const p512[] = { PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) }; -static const unsigned short p514[] = { +static unsigned short const p514[] = { PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFF00, 0xFF0000, 0x630000, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000) }; -static const unsigned short p515[] = { +static unsigned short const p515[] = { PACK15_4(0xFFFFFF, 0xADAD84, 0x42737B, 0x000000), PACK15_4(0xFFFFFF, 0xFFAD63, 0x843100, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) }; -static const unsigned short p518[] = { +static unsigned short const p518[] = { PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000) }; -static const unsigned short p51A[] = { +static unsigned short const p51A[] = { PACK15_4(0xFFFFFF, 0xFFFF00, 0x7B4A00, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000), PACK15_4(0xFFFFFF, 0x7BFF31, 0x008400, 0x000000) }; -static const unsigned short p51C[] = { +static unsigned short const p51C[] = { PACK15_4(0xFFFFFF, 0x7BFF31, 0x0063C5, 0x000000), PACK15_4(0xFFFFFF, 0xFF8484, 0x943A3A, 0x000000), PACK15_4(0xFFFFFF, 0x63A5FF, 0x0000FF, 0x000000) @@ -357,9 +358,9 @@ static const unsigned short p51C[] = { #undef PACK15_1 #undef TO5BIT -struct GbcPaletteEntry { const char *title; const unsigned short *p; }; +struct GbcPaletteEntry { char const *title; unsigned short const *p; }; -static const GbcPaletteEntry gbcDirPalettes[] = { +static GbcPaletteEntry const gbcDirPalettes[] = { { "GBC - Blue", p518 }, { "GBC - Brown", p012 }, { "GBC - Dark Blue", p50D }, @@ -374,7 +375,7 @@ static const GbcPaletteEntry gbcDirPalettes[] = { { "GBC - Yellow", p51A }, }; -static const GbcPaletteEntry gbcTitlePalettes[] = { +static GbcPaletteEntry const gbcTitlePalettes[] = { { "ALLEY WAY", p008 }, { "ASTEROIDS/MISCMD", p30E }, { "BA.TOSHINDEN", p50F }, @@ -481,52 +482,61 @@ static const GbcPaletteEntry gbcTitlePalettes[] = { }; static inline std::size_t gbcDirPalettesSize() { return sizeof gbcDirPalettes / sizeof gbcDirPalettes[0]; } -static inline const struct GbcPaletteEntry * gbcDirPalettesEnd() { return gbcDirPalettes + gbcDirPalettesSize(); } +static inline GbcPaletteEntry const * gbcDirPalettesEnd() { return gbcDirPalettes + gbcDirPalettesSize(); } static inline std::size_t gbcTitlePalettesSize() { return sizeof gbcTitlePalettes / sizeof gbcTitlePalettes[0]; } -static inline const struct GbcPaletteEntry * gbcTitlePalettesEnd() { return gbcTitlePalettes + gbcTitlePalettesSize(); } +static inline GbcPaletteEntry const * gbcTitlePalettesEnd() { return gbcTitlePalettes + gbcTitlePalettesSize(); } struct GbcPaletteEntryLess { - bool operator()(const GbcPaletteEntry &lhs, const char *const rhstitle) const { + bool operator()(GbcPaletteEntry const &lhs, char const *rhstitle) const { return std::strcmp(lhs.title, rhstitle) < 0; } }; -static const unsigned short * findGbcDirPal(const char *const title) { - const GbcPaletteEntry *const r = std::lower_bound(gbcDirPalettes, gbcDirPalettesEnd(), title, GbcPaletteEntryLess()); - return r < gbcDirPalettesEnd() && !std::strcmp(r->title, title) ? r->p : 0; +static unsigned short const * findGbcDirPal(char const *title) { + GbcPaletteEntry const *r = std::lower_bound(gbcDirPalettes, gbcDirPalettesEnd(), + title, GbcPaletteEntryLess()); + return r < gbcDirPalettesEnd() && !std::strcmp(r->title, title) + ? r->p + : 0; } -static const unsigned short * findGbcTitlePal(const char *const title) { - const GbcPaletteEntry *const r = std::lower_bound(gbcTitlePalettes, gbcTitlePalettesEnd(), title, GbcPaletteEntryLess()); - return r < gbcTitlePalettesEnd() && !std::strcmp(r->title, title) ? r->p : 0; +static unsigned short const * findGbcTitlePal(char const *title) { + GbcPaletteEntry const *r = std::lower_bound(gbcTitlePalettes, gbcTitlePalettesEnd(), + title, GbcPaletteEntryLess()); + return r < gbcTitlePalettesEnd() && !std::strcmp(r->title, title) + ? r->p + : 0; } -static const unsigned short * findGbcPal(const char *const title) { - if (const unsigned short *const pal = findGbcDirPal(title)) +static unsigned short const * findGbcPal(char const *title) { + if (unsigned short const *pal = findGbcDirPal(title)) return pal; return findGbcTitlePal(title); } -static unsigned long gbcToRgb32(const unsigned rgb15) { - const unsigned long r = rgb15 >> 10 & 0x1F; - const unsigned long g = rgb15 >> 5 & 0x1F; - const unsigned long b = rgb15 & 0x1F; +static unsigned long gbcToRgb32(unsigned const rgb15) { + unsigned long r = rgb15 >> 10 & 0x1F; + unsigned long g = rgb15 >> 5 & 0x1F; + unsigned long b = rgb15 & 0x1F; - return ((r * 13 + g * 2 + b) >> 1) << 16 | (g * 3 + b) << 9 | (r * 3 + g * 2 + b * 11) >> 1; + return ((r * 13 + g * 2 + b) >> 1) << 16 + | (g * 3 + b) << 9 + | (r * 3 + g * 2 + b * 11) >> 1; } -} +} // anon ns ColorPicker::ColorPicker(QRgb color, QWidget *parent) -: QFrame(parent), w(new QWidget) +: QFrame(parent) +, w_(new QWidget) { setAcceptDrops(true); - w->setAutoFillBackground(true); + w_->setAutoFillBackground(true); setLayout(new QVBoxLayout); layout()->setMargin(0); - layout()->addWidget(w); + layout()->addWidget(w_); setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); @@ -534,23 +544,22 @@ ColorPicker::ColorPicker(QRgb color, QWidget *parent) setColor(color); } -const QColor& ColorPicker::getQColor() const { - return w->palette().color(QPalette::Background); +QColor const & ColorPicker::getQColor() const { + return w_->palette().color(QPalette::Background); } void ColorPicker::requestColor() { - QColor c = QColorDialog::getColor(QColor(getColor()), this); - + QColor c = QColorDialog::getColor(QColor(color()), this); if (c.isValid()) { setColor(c); emit colorChanged(); } } -void ColorPicker::setColor(const QColor &color) { - QPalette p(w->palette()); +void ColorPicker::setColor(QColor const &color) { + QPalette p(w_->palette()); p.setColor(QPalette::Background, color); - w->setPalette(p); + w_->setPalette(p); } void ColorPicker::dragEnterEvent(QDragEnterEvent *e) { @@ -566,11 +575,11 @@ void ColorPicker::dropEvent(QDropEvent *e) { } void ColorPicker::mousePressEvent(QMouseEvent *e) { - dragStartPosition = e->pos(); + dragStartPosition_ = e->pos(); } void ColorPicker::mouseMoveEvent(QMouseEvent *e) { - if ((e->pos() - dragStartPosition).manhattanLength() < QApplication::startDragDistance()) + if ((e->pos() - dragStartPosition_).manhattanLength() < QApplication::startDragDistance()) return; QDrag *const drag = new QDrag(this); @@ -598,7 +607,7 @@ void ColorPicker::keyReleaseEvent(QKeyEvent *e) { } } -QRgb ColorPicker::getColor() const { +QRgb ColorPicker::color() const { return getQColor().rgb() & 0xFFFFFF; } @@ -606,18 +615,16 @@ void ColorPicker::setColor(QRgb rgb32) { setColor(QColor(rgb32)); } -ColorQuad::ColorQuad(const QString &label, QWidget *parent) +ColorQuad::ColorQuad(QString const &label, QWidget *parent) : QGroupBox(label, parent) { setAcceptDrops(true); setLayout(new QHBoxLayout); - for (int i = 0; i < 4; ++i) { - layout()->addWidget(picker[i] = new ColorPicker); - connect(picker[i], SIGNAL(colorChanged()), this, SLOT(pickerChanged())); + for (std::size_t i = 0; i < sizeof picker_ / sizeof *picker_; ++i) { + layout()->addWidget(picker_[i] = new ColorPicker); + connect(picker_[i], SIGNAL(colorChanged()), this, SLOT(pickerChanged())); } - -// setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); } void ColorQuad::pickerChanged() { @@ -635,8 +642,7 @@ void ColorQuad::dropEvent(QDropEvent *e) { QDataStream dataStream(e->mimeData()->data("application/x-colorquad")); QRgb color; - - for (int i = 0; i < 4; ++i) { + for (std::size_t i = 0; i < sizeof picker_ / sizeof *picker_; ++i) { dataStream >> color; setColor(i, color); } @@ -644,12 +650,11 @@ void ColorQuad::dropEvent(QDropEvent *e) { pickerChanged(); } -void ColorQuad::mousePressEvent(QMouseEvent */*e*/) { +void ColorQuad::mousePressEvent(QMouseEvent *) { QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); - - for (int i = 0; i < 4; ++i) - dataStream << getColor(i); + for (std::size_t i = 0; i < sizeof picker_ / sizeof *picker_; ++i) + dataStream << color(i); QMimeData *const mimeData = new QMimeData; mimeData->setData("application/x-colorquad", itemData); @@ -663,66 +668,76 @@ namespace { class ImmutableStringListModel : public QStringListModel { public: - ImmutableStringListModel(QObject *parent = 0) : QStringListModel(parent) {} - ImmutableStringListModel(const QStringList &strings, QObject *parent = 0) : QStringListModel(strings, parent) {} - Qt::ItemFlags flags(const QModelIndex &index) const { return QStringListModel::flags(index) & ~Qt::ItemIsEditable; } + explicit ImmutableStringListModel(QObject *parent = 0) + : QStringListModel(parent) + { + } + + explicit ImmutableStringListModel(QStringList const &strings, QObject *parent = 0) + : QStringListModel(strings, parent) + { + } + + Qt::ItemFlags flags(QModelIndex const &index) const { + return QStringListModel::flags(index) & ~Qt::ItemIsEditable; + } }; -static const QStringList makeStaticStringList(const bool hasGlobal) { +static QStringList const makeStaticStringList(bool const hasGlobal) { QStringList sl; - if (hasGlobal) sl.append("Global Palette"); sl.append("Current Scheme"); sl.append("Default Gray"); - for (std::size_t i = 0; i < gbcDirPalettesSize(); ++i) sl.append(gbcDirPalettes[i].title); - for (std::size_t i = 0; i < gbcTitlePalettesSize(); ++i) sl.append(gbcTitlePalettes[i].title); return sl; } -static void setSchemeList(const QString &savedir, const bool hasGlobal, QStringListModel *const model) { - QDir dir(savedir, "*.pal", QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::Readable); +static void setSchemeList(QStringListModel &model, QString const &savedir, bool hasGlobal) { + QDir dir(savedir, "*.pal", + QDir::Name | QDir::IgnoreCase, + QDir::Files | QDir::Readable); QStringList dirlisting(dir.entryList()); - - for (QStringList::iterator it = dirlisting.begin(); it != dirlisting.end(); ++it) - it->chop(4); - - model->setStringList(makeStaticStringList(hasGlobal) + dirlisting); + std::for_each(dirlisting.begin(), dirlisting.end(), + std::bind2nd(std::mem_fun_ref(&QString::chop), 4)); + model.setStringList(makeStaticStringList(hasGlobal) + dirlisting); } -static const QModelIndex schemeIndexOf(const QAbstractItemModel *const model, const QString &schemeStr) { - const int rows = model->rowCount(); +static QModelIndex schemeIndexOf(QAbstractItemModel const &model, QString const &schemeStr) { + int const rows = model.rowCount(); for (int i = 0; i < rows; ++i) { - if (model->index(i, 0).data().toString() == schemeStr) - return model->index(i, 0); + if (model.index(i, 0).data().toString() == schemeStr) + return model.index(i, 0); } for (int i = 0; i < rows; ++i) { - if (model->index(i, 0).data().toString() == "Current Scheme") - return model->index(i, 0); + if (model.index(i, 0).data().toString() == "Current Scheme") + return model.index(i, 0); } return QModelIndex(); } -} +} // anon ns -PaletteDialog::PaletteDialog(const QString &savepath, const PaletteDialog *global, QWidget *parent) -: QDialog(parent), - global(global), - listView(new QListView), - rmSchemeButton(new QPushButton("Remove Scheme")), - defaultScheme(global ? "Global Palette" : "Default Gray"), - schemeString(defaultScheme) +PaletteDialog::PaletteDialog(QString const &savepath, + PaletteDialog const *const global, + QWidget *const parent) +: QDialog(parent) +, global_(global) +, listView_(new QListView) +, rmSchemeButton_(new QPushButton("Remove Scheme")) +, quads_() +, currentColors_() +, defaultScheme_(global ? "Global Palette" : "Default Gray") +, schemeString_(defaultScheme_) { - std::memset(currentColors, 0, sizeof currentColors); setWindowTitle(global ? "Current ROM Palette" : "Global Palette"); QBoxLayout *const mainLayout = new QVBoxLayout; @@ -733,32 +748,30 @@ PaletteDialog::PaletteDialog(const QString &savepath, const PaletteDialog *globa { QGroupBox *const lframe = new QGroupBox("Scheme"); QBoxLayout *const frameLayout = new QVBoxLayout; - savedir = savepath + "/"; - QDir::root().mkpath(savedir + "stored/"); - listView->setModel(new ImmutableStringListModel(this)); + savedir_ = savepath + "/"; + QDir::root().mkpath(savedir_ + "stored/"); + listView_->setModel(new ImmutableStringListModel(this)); setSchemeList(); - frameLayout->addWidget(listView); + frameLayout->addWidget(listView_); { - QPushButton *const saveButton = new QPushButton("Save Scheme..."); + QPushButton *saveButton = new QPushButton("Save Scheme..."); connect(saveButton, SIGNAL(clicked()), this, SLOT(saveScheme())); frameLayout->addWidget(saveButton); } - connect(rmSchemeButton, SIGNAL(clicked()), this, SLOT(rmScheme())); - frameLayout->addWidget(rmSchemeButton); - + connect(rmSchemeButton_, SIGNAL(clicked()), this, SLOT(rmScheme())); + frameLayout->addWidget(rmSchemeButton_); lframe->setLayout(frameLayout); topLayout->addWidget(lframe); } { - QBoxLayout *const vLayout = new QVBoxLayout; - vLayout->addWidget(quads[0] = new ColorQuad("Background")); - vLayout->addWidget(quads[1] = new ColorQuad("Sprite 1")); - vLayout->addWidget(quads[2] = new ColorQuad("Sprite 2")); + QBoxLayout *vLayout = new QVBoxLayout; + vLayout->addWidget(quads_[0] = new ColorQuad("Background")); + vLayout->addWidget(quads_[1] = new ColorQuad("Sprite 1")); + vLayout->addWidget(quads_[2] = new ColorQuad("Sprite 2")); topLayout->addLayout(vLayout); -// topLayout->setAlignment(vLayout, Qt::AlignTop); } mainLayout->addLayout(topLayout); @@ -767,9 +780,7 @@ PaletteDialog::PaletteDialog(const QString &savepath, const PaletteDialog *globa { QPushButton *const okButton = new QPushButton(tr("OK")); QPushButton *const cancelButton = new QPushButton(tr("Cancel")); - okButton->setDefault(true); - connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); @@ -782,10 +793,12 @@ PaletteDialog::PaletteDialog(const QString &savepath, const PaletteDialog *globa setLayout(mainLayout); - for (int i = 0; i < 3; ++i) - connect(quads[i], SIGNAL(colorChanged()), listView->selectionModel(), SLOT(clear())); + for (std::size_t i = 0; i < sizeof quads_ / sizeof *quads_; ++i) + connect(quads_[i], SIGNAL(colorChanged()), listView_->selectionModel(), SLOT(clear())); - connect(listView->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(schemeChanged(const QModelIndex&, const QModelIndex&))); + connect(listView_->selectionModel(), + SIGNAL(currentChanged(QModelIndex const &, QModelIndex const &)), + this, SLOT(schemeChanged(QModelIndex const &, QModelIndex const &))); if (global) { restore(); @@ -799,7 +812,7 @@ PaletteDialog::PaletteDialog(const QString &savepath, const PaletteDialog *globa } PaletteDialog::~PaletteDialog() { - if (global) { + if (global_) { saveToSettingsFile(); } else { QSettings settings; @@ -810,123 +823,126 @@ PaletteDialog::~PaletteDialog() { } void PaletteDialog::saveSettings(QSettings &settings) { - settings.setValue("slectedScheme", schemeString); + settings.setValue("slectedScheme", schemeString_); - for (unsigned i = 0; i < 3; ++i) - for (unsigned j = 0; j < 4; ++j) - settings.setValue(quads[i]->title() + QString::number(j), currentColors[i][j]); + for (std::size_t i = 0; i < sizeof currentColors_ / sizeof *currentColors_; ++i) + for (std::size_t j = 0; j < sizeof *currentColors_ / sizeof **currentColors_; ++j) + settings.setValue(quads_[i]->title() + QString::number(j), currentColors_[i][j]); } void PaletteDialog::loadSettings(QSettings &settings) { - schemeString = settings.value("slectedScheme", defaultScheme).toString(); + schemeString_ = settings.value("slectedScheme", defaultScheme_).toString(); - for (unsigned i = 0; i < 3; ++i) - for (unsigned j = 0; j < 4; ++j) - currentColors[i][j] = qvariant_cast(settings.value(quads[i]->title() + QString::number(j), (3 - (j & 3)) * 85 * 0x010101)); + for (std::size_t i = 0; i < sizeof currentColors_ / sizeof *currentColors_; ++i) + for (std::size_t j = 0; j < sizeof *currentColors_ / sizeof **currentColors_; ++j) { + currentColors_[i][j] = qvariant_cast( + settings.value(quads_[i]->title() + QString::number(j), + (3 - (j & 3)) * 85 * 0x010101)); + } restore(); store(); } void PaletteDialog::saveToSettingsFile() { - if (!settingsFile.isEmpty()) { - if (schemeString == defaultScheme) { - QDir(savedir).remove(settingsFile); + if (!settingsFile_.isEmpty()) { + if (schemeString_ == defaultScheme_) { + QDir(savedir_).remove(settingsFile_); } else { - QSettings settings(savedir + settingsFile, QSettings::IniFormat); + QSettings settings(savedir_ + settingsFile_, QSettings::IniFormat); saveSettings(settings); } } } void PaletteDialog::setSchemeList() { - ::setSchemeList(savedir + "stored/", global, reinterpret_cast(listView->model())); + ::setSchemeList(*static_cast(listView_->model()), + savedir_ + "stored/", global_); } void PaletteDialog::rmScheme() { - { - QDir(savedir + "stored/").remove(listView->currentIndex().data().toString() + ".pal"); - } - - listView->selectionModel()->clear(); + { QDir(savedir_ + "stored/").remove(listView_->currentIndex().data().toString() + ".pal"); } + listView_->selectionModel()->clear(); setSchemeList(); } void PaletteDialog::saveScheme() { bool ok; - const QString &text = QInputDialog::getText(this, "Save Scheme", "Scheme name:", + QString const &text = QInputDialog::getText(this, "Save Scheme", "Scheme name:", QLineEdit::Normal, QString(), &ok); - if (!ok) return; - if (text.isEmpty() || makeStaticStringList(true).contains(text) - || text.size() > 200 || text.contains(QRegExp("[" + QRegExp::escape("<>:\"/\\|?*") + "]"))) { + if (text.isEmpty() + || makeStaticStringList(true).contains(text) + || text.size() > 200 + || text.contains(QRegExp("[" + QRegExp::escape("<>:\"/\\|?*") + "]"))) { QMessageBox::information(this, "Invalid scheme name", "Invalid scheme name."); return; } { - QSettings settings(savedir + "stored/" + text + ".pal", QSettings::IniFormat); + QSettings settings(savedir_ + "stored/" + text + ".pal", QSettings::IniFormat); - for (unsigned i = 0; i < 3; ++i) - for (unsigned j = 0; j < 4; ++j) - settings.setValue(quads[i]->title() + QString::number(j), quads[i]->getColor(j)); + for (std::size_t i = 0; i < sizeof quads_ / sizeof *quads_; ++i) + for (std::size_t j = 0; j < sizeof *currentColors_ / sizeof **currentColors_; ++j) + settings.setValue(quads_[i]->title() + QString::number(j), quads_[i]->color(j)); } setSchemeList(); - - listView->setCurrentIndex(schemeIndexOf(listView->model(), text)); + listView_->setCurrentIndex(schemeIndexOf(*listView_->model(), text)); } -void PaletteDialog::schemeChanged(const QModelIndex ¤t, const QModelIndex &/*previous*/) { - rmSchemeButton->setEnabled(false); - +void PaletteDialog::schemeChanged(QModelIndex const ¤t, QModelIndex const &/*previous*/) { + rmSchemeButton_->setEnabled(false); if (!current.isValid()) return; - const QString &str = current.data().toString(); - + QString const &str = current.data().toString(); if ("Global Palette" == str) { - for (unsigned i = 0; i < 3; ++i) - for (unsigned j = 0; j < 4; ++j) - quads[i]->setColor(j, global->getColor(i, j)); + for (std::size_t i = 0; i < sizeof quads_ / sizeof *quads_; ++i) + for (std::size_t j = 0; j < sizeof *currentColors_ / sizeof **currentColors_; ++j) + quads_[i]->setColor(j, global_->color(i, j)); } else if ("Current Scheme" == str) { - for (unsigned i = 0; i < 3; ++i) - for (unsigned j = 0; j < 4; ++j) - quads[i]->setColor(j, currentColors[i][j]); + for (std::size_t i = 0; i < sizeof currentColors_ / sizeof *currentColors_; ++i) + for (std::size_t j = 0; j < sizeof *currentColors_ / sizeof **currentColors_; ++j) + quads_[i]->setColor(j, currentColors_[i][j]); } else if ("Default Gray" == str) { - for (unsigned i = 0; i < 3; ++i) - for (unsigned j = 0; j < 4; ++j) - quads[i]->setColor(j, (3 - (j & 3)) * 85 * 0x010101); - } else if (const unsigned short *const gbcpal = findGbcPal(str.toAscii().data())) { - for (unsigned i = 0; i < 3; ++i) - for (unsigned j = 0; j < 4; ++j) - quads[i]->setColor(j, gbcToRgb32(gbcpal[i * 4 + j])); + for (std::size_t i = 0; i < sizeof quads_ / sizeof *quads_; ++i) + for (std::size_t j = 0; j < sizeof *currentColors_ / sizeof **currentColors_; ++j) + quads_[i]->setColor(j, (3 - (j & 3)) * 85 * 0x010101); + } else if (unsigned short const *gbcpal = findGbcPal(str.toAscii().data())) { + for (std::size_t i = 0; i < sizeof quads_ / sizeof *quads_; ++i) + for (std::size_t j = 0; j < sizeof *currentColors_ / sizeof **currentColors_; ++j) + quads_[i]->setColor(j, gbcToRgb32(gbcpal[i * 4 + j])); } else { - QSettings settings(savedir + "stored/" + str + ".pal", QSettings::IniFormat); + QSettings settings(savedir_ + "stored/" + str + ".pal", QSettings::IniFormat); - for (unsigned i = 0; i < 3; ++i) - for (unsigned j = 0; j < 4; ++j) - quads[i]->setColor(j, qvariant_cast(settings.value(quads[i]->title() + QString::number(j), 0))); + for (std::size_t i = 0; i < sizeof quads_ / sizeof *quads_; ++i) + for (std::size_t j = 0; j < sizeof *currentColors_ / sizeof **currentColors_; ++j) { + QVariant v = settings.value(quads_[i]->title() + QString::number(j), 0); + quads_[i]->setColor(j, qvariant_cast(v)); + } - rmSchemeButton->setEnabled(true); + rmSchemeButton_->setEnabled(true); } } void PaletteDialog::store() { - for (unsigned i = 0; i < 3; ++i) - for (unsigned j = 0; j < 4; ++j) - currentColors[i][j] = quads[i]->getColor(j); + for (std::size_t i = 0; i < sizeof currentColors_ / sizeof *currentColors_; ++i) + for (std::size_t j = 0; j < sizeof *currentColors_ / sizeof **currentColors_; ++j) + currentColors_[i][j] = quads_[i]->color(j); - if (!listView->currentIndex().isValid()) - listView->setCurrentIndex(schemeIndexOf(listView->model(), "Current Scheme")); //obs: will emit currentChanged() + if (!listView_->currentIndex().isValid()) { + // obs: will emit currentChanged() + listView_->setCurrentIndex(schemeIndexOf(*listView_->model(), "Current Scheme")); + } - schemeString = listView->currentIndex().data().toString(); + schemeString_ = listView_->currentIndex().data().toString(); } void PaletteDialog::restore() { - listView->setCurrentIndex(schemeIndexOf(listView->model(), schemeString)); + listView_->setCurrentIndex(schemeIndexOf(*listView_->model(), schemeString_)); } void PaletteDialog::externalChange() { @@ -935,13 +951,13 @@ void PaletteDialog::externalChange() { store(); } -void PaletteDialog::setSettingsFile(const QString &filename, const QString &romTitle) { +void PaletteDialog::setSettingsFile(QString const &filename, QString const &romTitle) { saveToSettingsFile(); - - settingsFile = filename; - defaultScheme = findGbcTitlePal(romTitle.toAscii().data()) ? romTitle : QString("Global Palette"); - - QSettings settings(savedir + settingsFile, QSettings::IniFormat); + settingsFile_ = filename; + defaultScheme_ = findGbcTitlePal(romTitle.toAscii().data()) + ? romTitle + : QString("Global Palette"); + QSettings settings(savedir_ + settingsFile_, QSettings::IniFormat); loadSettings(settings); } diff --git a/gambatte_qt/src/palettedialog.h b/gambatte_qt/src/palettedialog.h index d738e5cc..42d3806c 100644 --- a/gambatte_qt/src/palettedialog.h +++ b/gambatte_qt/src/palettedialog.h @@ -19,81 +19,102 @@ #ifndef PALETTEDIALOG_H #define PALETTEDIALOG_H +#include +#include +#include +#include +#include +#include +#include +#include +#include + class QListView; class QPushButton; class QSettings; -#include -#include -#include -#include -#include -#include -#include -#include - class ColorPicker : public QFrame { - Q_OBJECT - - QWidget *const w; - QPoint dragStartPosition; - - const QColor& getQColor() const; - void requestColor(); - void setColor(const QColor &color); - -protected: - void dragEnterEvent(QDragEnterEvent *e); - void dropEvent(QDropEvent *e); - void mouseMoveEvent(QMouseEvent *e); - void mousePressEvent(QMouseEvent *e); - void mouseReleaseEvent(QMouseEvent *e); - void keyReleaseEvent(QKeyEvent *e); - public: - ColorPicker(QRgb color = 0xFFFFFF, QWidget *parent = 0); - QRgb getColor() const; + explicit ColorPicker(QRgb color = 0xFFFFFF, QWidget *parent = 0); + QRgb color() const; void setColor(QRgb rgb32); - QSize sizeHint() const { return QSize(4*6, 3*6); } + virtual QSize sizeHint() const { return QSize(4 * 6, 3 * 6); } signals: void colorChanged(); + +protected: + virtual void dragEnterEvent(QDragEnterEvent *e); + virtual void dropEvent(QDropEvent *e); + virtual void mouseMoveEvent(QMouseEvent *e); + virtual void mousePressEvent(QMouseEvent *e); + virtual void mouseReleaseEvent(QMouseEvent *e); + virtual void keyReleaseEvent(QKeyEvent *e); + +private: + Q_OBJECT + + QWidget *const w_; + QPoint dragStartPosition_; + + QColor const & getQColor() const; + void requestColor(); + void setColor(QColor const &color); }; class ColorQuad : public QGroupBox { - Q_OBJECT - - ColorPicker* picker[4]; - -private slots: - void pickerChanged(); - -protected: - void dragEnterEvent(QDragEnterEvent *e); - void dropEvent(QDropEvent *e); - void mousePressEvent(QMouseEvent *e); - public: - ColorQuad(const QString &label, QWidget *parent = 0); - QRgb getColor(unsigned index) const { return picker[index & 3]->getColor(); } - void setColor(unsigned index, QRgb color) { picker[index & 3]->setColor(color); } + explicit ColorQuad(QString const &label, QWidget *parent = 0); + QRgb color(unsigned index) const { return picker_[index & 3]->color(); } + void setColor(unsigned index, QRgb color) { picker_[index & 3]->setColor(color); } signals: void colorChanged(); + +protected: + virtual void dragEnterEvent(QDragEnterEvent *e); + virtual void dropEvent(QDropEvent *e); + virtual void mousePressEvent(QMouseEvent *e); + +private: + Q_OBJECT + + ColorPicker * picker_[4]; + +private slots: + void pickerChanged(); }; class PaletteDialog : public QDialog { +public: + explicit PaletteDialog(QString const &savepath, + PaletteDialog const *global = 0, + QWidget *parent = 0); + virtual ~PaletteDialog(); + + QRgb color(unsigned palnum, unsigned colornum) const { + return currentColors_[std::min(palnum, 2u)][colornum & 3]; + } + + void externalChange(); + void setSettingsFile(QString const &filename, QString const &romTitle); + +public slots: + virtual void accept(); + virtual void reject(); + +private: Q_OBJECT - const PaletteDialog *const global; - QListView *const listView; - QPushButton *const rmSchemeButton; - ColorQuad *quads[3]; - QRgb currentColors[3][4]; - QString defaultScheme; - QString schemeString; - QString savedir; - QString settingsFile; + PaletteDialog const *const global_; + QListView *const listView_; + QPushButton *const rmSchemeButton_; + ColorQuad *quads_[3]; + QRgb currentColors_[3][4]; + QString defaultScheme_; + QString schemeString_; + QString savedir_; + QString settingsFile_; void saveSettings(QSettings &settings); void loadSettings(QSettings &settings); @@ -105,18 +126,7 @@ class PaletteDialog : public QDialog { private slots: void rmScheme(); void saveScheme(); - void schemeChanged(const QModelIndex ¤t, const QModelIndex &previous); - -public: - explicit PaletteDialog(const QString &savepath, const PaletteDialog *global = 0, QWidget *parent = 0); - ~PaletteDialog(); - QRgb getColor(unsigned palnum, unsigned colornum) const { return currentColors[palnum < 3 ? palnum : 2][colornum & 3]; } - void externalChange(); - void setSettingsFile(const QString &filename, const QString &romTitle); - -public slots: - void accept(); - void reject(); + void schemeChanged(QModelIndex const ¤t, QModelIndex const &previous); }; #endif diff --git a/gambatte_qt/src/pathselector.cpp b/gambatte_qt/src/pathselector.cpp index e4e5f1e1..c62dd1bf 100644 --- a/gambatte_qt/src/pathselector.cpp +++ b/gambatte_qt/src/pathselector.cpp @@ -22,18 +22,16 @@ #include #include -static int getCustomIndex(const QComboBox *const comboBox) { +static int getCustomIndex(QComboBox const *comboBox) { return comboBox->findText(QObject::tr("Other...")); } -static void setPath(QComboBox *const comboBox, const QString &value) { - const int valueIndex = comboBox->findData(value); - +static void setPath(QComboBox *const comboBox, QString const &value) { + int const valueIndex = comboBox->findData(value); if (valueIndex < 0) { comboBox->addItem(QDir::toNativeSeparators(value), value); - const int customIndex = getCustomIndex(comboBox); - + int const customIndex = getCustomIndex(comboBox); if (comboBox->count() > customIndex + 2) comboBox->removeItem(customIndex + 1); @@ -42,15 +40,16 @@ static void setPath(QComboBox *const comboBox, const QString &value) { comboBox->setCurrentIndex(valueIndex); } -PathSelector::PathSelector(const QString &caption, const QString &settingskey, - const Mapping &default1, const Mapping &default2) -: comboBox_(new QComboBox), - value_(default1.second), - caption_(caption), - key_(settingskey) +PathSelector::PathSelector(QString const &caption, + QString const &settingskey, + Mapping const &default1, + Mapping const &default2) +: comboBox_(new QComboBox) +, value_(default1.second) +, caption_(caption) +, key_(settingskey) { comboBox_->addItem(default1.first, default1.second); - if (default2 != Mapping()) comboBox_->addItem(default2.first, default2.second); @@ -58,7 +57,6 @@ PathSelector::PathSelector(const QString &caption, const QString &settingskey, value_ = QSettings().value(key_, value_).toString(); reject(); - connect(comboBox_, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int))); } @@ -79,9 +77,9 @@ QWidget * PathSelector::widget() const { return comboBox_; } -void PathSelector::indexChanged(const int index) { +void PathSelector::indexChanged(int const index) { if (getCustomIndex(comboBox_) == index) { - const QString &dir = QFileDialog::getExistingDirectory(comboBox_, caption_, value_); + QString const &dir = QFileDialog::getExistingDirectory(comboBox_, caption_, value_); setPath(comboBox_, dir.isEmpty() ? value_ : dir); } } diff --git a/gambatte_qt/src/pathselector.h b/gambatte_qt/src/pathselector.h index 7152dd93..84b3de5e 100644 --- a/gambatte_qt/src/pathselector.h +++ b/gambatte_qt/src/pathselector.h @@ -27,26 +27,29 @@ class QComboBox; class QWidget; class PathSelector : public QObject { +public: + typedef std::pair Mapping; + + PathSelector(QString const &caption, + QString const &settingskey, + Mapping const &default1, + Mapping const &default2 = Mapping()); + ~PathSelector(); + void accept(); + void reject(); + QString const & value() const { return value_; } + QWidget * widget() const; + +private: Q_OBJECT QComboBox *const comboBox_; QString value_; - const QString caption_; - const QString key_; + QString const caption_; + QString const key_; private slots: void indexChanged(int index); - -public: - typedef std::pair Mapping; - - PathSelector(const QString &caption, const QString &settingskey, - const Mapping &default1, const Mapping &default2 = Mapping()); - ~PathSelector(); - void accept(); - void reject(); - const QString & value() const { return value_; } - QWidget * widget() const; }; #endif