gambatte_qt: non-framework code formatting/readability/consistency

This commit is contained in:
sinamas 2013-03-28 21:35:51 +01:00
parent cdabdf2897
commit f5e4f6c7ac
15 changed files with 1090 additions and 1050 deletions

View File

@ -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<CheatListItem> items_;
public:
explicit CheatListModel(QObject *parent = 0) : QAbstractListModel(parent) {}
explicit CheatListModel(const std::vector<CheatListItem> &items, QObject *parent = 0)
explicit CheatListModel(std::vector<CheatListItem> 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<std::size_t>(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<std::size_t>(index.row()) < items_.size() && role == Qt::CheckStateRole) {
virtual bool setData(QModelIndex const &index, QVariant const &value, int role) {
if (static_cast<std::size_t>(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<CheatListItem> & items() const { return items_; }
std::vector<CheatListItem> const & items() const { return items_; }
private:
std::vector<CheatListItem> 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<CheatListItem> &items) {
void CheatDialog::resetViewModel(std::vector<CheatListItem> const &items) {
resetViewModel(items, view_->currentIndex().row());
}
void CheatDialog::resetViewModel(const std::vector<CheatListItem> &items, const int newCurRow) {
const scoped_ptr<QAbstractItemModel> oldModel(view_->model());
void CheatDialog::resetViewModel(std::vector<CheatListItem> const &items, int const newCurRow) {
scoped_ptr<QAbstractItemModel> 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<GetCheatInput> getCheatDialog(new GetCheatInput(QString(), QString(), this));
scoped_ptr<GetCheatInput> const getCheatDialog(new GetCheatInput(QString(), QString(), this));
getCheatDialog->setWindowTitle(tr("Add Cheat"));
if (getCheatDialog->exec()) {
std::vector<CheatListItem> items = reinterpret_cast<CheatListModel*>(view_->model())->items();
const CheatListItem item(getCheatDialog->descText(), getCheatDialog->codeText(), false);
const std::vector<CheatListItem>::iterator it =
items.insert(std::lower_bound(items.begin(), items.end(), item, CheatItemLess()), item);
std::vector<CheatListItem> items =
static_cast<CheatListModel *>(view_->model())->items();
CheatListItem const item(getCheatDialog->descText(),
getCheatDialog->codeText(),
false);
std::vector<CheatListItem>::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<CheatListItem> items = reinterpret_cast<CheatListModel*>(view_->model())->items();
std::size_t const row = view_->selectionModel()->currentIndex().row();
std::vector<CheatListItem> items = static_cast<CheatListModel *>(view_->model())->items();
if (row < items.size()) {
const scoped_ptr<GetCheatInput> getCheatDialog(
scoped_ptr<GetCheatInput> 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<CheatListItem>::iterator it =
items.insert(std::lower_bound(items.begin(), items.end(), item, CheatItemLess()), item);
std::vector<CheatListItem>::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<CheatListItem> items = reinterpret_cast<CheatListModel*>(view_->model())->items();
std::size_t const row = view_->selectionModel()->currentIndex().row();
std::vector<CheatListItem> items =
static_cast<CheatListModel *>(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 &current, const QModelIndex&) {
void CheatDialog::selectionChanged(QModelIndex const &current, 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<CheatListModel*>(view_->model())->items();
items_ = static_cast<CheatListModel *>(view_->model())->items();
QDialog::accept();
}

View File

@ -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<CheatListItem> items_;
const QString savefile_;
QString const savefile_;
QString gamename_;
void loadFromSettingsFile();
void saveToSettingsFile();
void resetViewModel(const std::vector<CheatListItem> &items);
void resetViewModel(const std::vector<CheatListItem> &items, int newCurRow);
void resetViewModel(std::vector<CheatListItem> const &items);
void resetViewModel(std::vector<CheatListItem> const &items, int newCurRow);
private slots:
void addCheat();
void editCheat();
void removeCheat();
void selectionChanged(const class QModelIndex &current, 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 &current, class QModelIndex const &last);
};
#endif

View File

@ -21,18 +21,17 @@
#include <QInputDialog>
#include <QSettings>
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<double>(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<int>(
QInputDialog::getDouble(comboBox_, tr("Set Frame Rate"), tr("Frame rate (fps):"),
static_cast<double>(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_);
}
}

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -20,8 +20,8 @@
#define GAMBATTEMENUHANDLER_H
#include "scalingmethod.h"
#include <QObject>
#include <QList>
#include <QObject>
#include <QSize>
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<QAction *> 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<QAction*> 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

View File

@ -19,32 +19,15 @@
#include "gambattesource.h"
#include "videolink/rgb32conv.h"
#include "videolink/vfilterinfo.h"
#include <cstring>
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<void (GambatteSource::*fun)()>
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<InputDialog::Button> 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<true>(dpadUp, dpadUpLast), "Up", "Game", Qt::Key_Up));
v.push_back(makeButtonInfo(new GbDirAct<false>(dpadDown, dpadUpLast), "Down", "Game", Qt::Key_Down));
v.push_back(makeButtonInfo(new GbDirAct<true>(dpadLeft, dpadLeftLast), "Left", "Game", Qt::Key_Left));
v.push_back(makeButtonInfo(new GbDirAct<false>(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<InputDialog::Button> v;
v.push_back(makeButtonInfo(new GbDirAct<true>(dpadUp_, dpadUpLast_), "Up", "Game", Qt::Key_Up));
v.push_back(makeButtonInfo(new GbDirAct<false>(dpadDown_, dpadUpLast_), "Down", "Game", Qt::Key_Down));
v.push_back(makeButtonInfo(new GbDirAct<true>(dpadLeft_, dpadLeftLast_), "Left", "Game", Qt::Key_Left));
v.push_back(makeButtonInfo(new GbDirAct<false>(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<VideoDialog::VideoSourceInfo> GambatteSource::generateVideoSourceInfos() {
std::vector<VideoDialog::VideoSourceInfo> const GambatteSource::generateVideoSourceInfos() {
std::vector<VideoDialog::VideoSourceInfo> 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<VideoDialog::VideoSourceInfo> 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<Rgb32Conv::PixelFormat>(pxformat),
VfilterInfo::get(vsrci).outWidth, VfilterInfo::get(vsrci).outHeight));
if (pxformat_ != format && pixels) {
pxformat_ = format;
cconvert_.reset();
cconvert_.reset(Rgb32Conv::create(static_cast<Rgb32Conv::PixelFormat>(pxformat_),
VfilterInfo::get(vsrci_).outWidth,
VfilterInfo::get(vsrci_).outHeight));
}
if (VideoLink *const gblink = vfilter.get() ? vfilter.get() : cconvert.get())
return GbVidBuf(static_cast<uint_least32_t*>(gblink->inBuf()), gblink->inPitch());
if (VideoLink *gblink = vfilter_ ? vfilter_.get() : cconvert_.get())
return GbVidBuf(static_cast<uint_least32_t *>(gblink->inBuf()), gblink->inPitch());
return GbVidBuf(static_cast<uint_least32_t*>(pixels), pitch);
return GbVidBuf(static_cast<uint_least32_t *>(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<uint_least32_t*>(soundBuf), usamples);
long const retval = gb_.runFor(gbvidbuf.pixels, gbvidbuf.pitch,
reinterpret_cast<quint32 *>(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<Rgb32Conv::PixelFormat>(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<Rgb32Conv::PixelFormat>(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);
}

View File

@ -31,76 +31,36 @@
#include <cstring>
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<VideoLink> cconvert;
scoped_ptr<VideoLink> 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<VideoDialog::VideoSourceInfo> 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<VideoDialog::VideoSourceInfo> 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<VideoLink> cconvert_;
scoped_ptr<VideoLink> 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

View File

@ -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 <QApplication>
#include <QSize>
#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();
}

View File

@ -18,39 +18,39 @@
***************************************************************************/
#include "miscdialog.h"
#include "mainwindow.h"
#include <QSpinBox>
#include <QCheckBox>
#include <QDir>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QSettings>
#include <QSpinBox>
#include <QVBoxLayout>
template<class Parent, class ChildLayout>
static ChildLayout * addLayout(Parent *const parent, ChildLayout *const child) {
static ChildLayout * addLayout(Parent *parent, ChildLayout *child) {
parent->addLayout(child);
return child;
}
template<class Parent, class ChildLayout>
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();
}

View File

@ -19,14 +19,30 @@
#ifndef MISCDIALOG_H
#define MISCDIALOG_H
class QSpinBox;
#include "fpsselector.h"
#include "pathselector.h"
#include "persistcheckbox.h"
#include <QDialog>
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

View File

@ -17,28 +17,29 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "palettedialog.h"
#include <QColor>
#include <QPalette>
#include <QColorDialog>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QApplication>
#include <QDropEvent>
#include <QDragEnterEvent>
#include <QMimeData>
#include <QByteArray>
#include <QColor>
#include <QColorDialog>
#include <QDataStream>
#include <QListView>
#include <QStringListModel>
#include <QDir>
#include <QSettings>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QHBoxLayout>
#include <QInputDialog>
#include <QKeyEvent>
#include <QListView>
#include <QMessageBox>
#include <QMimeData>
#include <QMouseEvent>
#include <QPalette>
#include <QPushButton>
#include <QSettings>
#include <QStringListModel>
#include <QVBoxLayout>
#include <algorithm>
#include <cstring>
#include <functional>
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<QRgb>(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<QRgb>(
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<QStringListModel*>(listView->model()));
::setSchemeList(*static_cast<QStringListModel *>(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 &current, const QModelIndex &/*previous*/) {
rmSchemeButton->setEnabled(false);
void PaletteDialog::schemeChanged(QModelIndex const &current, 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<QRgb>(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<QRgb>(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);
}

View File

@ -19,81 +19,102 @@
#ifndef PALETTEDIALOG_H
#define PALETTEDIALOG_H
#include <QColor>
#include <QDialog>
#include <QFrame>
#include <QGroupBox>
#include <QModelIndex>
#include <QPoint>
#include <QSize>
#include <QString>
#include <algorithm>
class QListView;
class QPushButton;
class QSettings;
#include <QDialog>
#include <QColor>
#include <QFrame>
#include <QPoint>
#include <QSize>
#include <QGroupBox>
#include <QModelIndex>
#include <QString>
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 &current, 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 &current, QModelIndex const &previous);
};
#endif

View File

@ -22,18 +22,16 @@
#include <QFileDialog>
#include <QSettings>
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);
}
}

View File

@ -27,26 +27,29 @@ class QComboBox;
class QWidget;
class PathSelector : public QObject {
public:
typedef std::pair<QString, QString> 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<QString, QString> 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