Added functions to save QPalette color settings to a file and load then on request.
This commit is contained in:
parent
7eb8ea9608
commit
9642be0db1
|
@ -40,13 +40,16 @@
|
||||||
#include "Qt/ConsoleWindow.h"
|
#include "Qt/ConsoleWindow.h"
|
||||||
#include "Qt/ConsoleUtilities.h"
|
#include "Qt/ConsoleUtilities.h"
|
||||||
|
|
||||||
|
static int writeQPaletteToFile( const char *path, QPalette *pal );
|
||||||
|
static int readQPaletteFromFile( const char *path, QPalette *pal );
|
||||||
|
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
GuiConfDialog_t::GuiConfDialog_t(QWidget *parent)
|
GuiConfDialog_t::GuiConfDialog_t(QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
{
|
{
|
||||||
int useNativeFileDialogVal;
|
int useNativeFileDialogVal;
|
||||||
int useNativeMenuBarVal;
|
int useNativeMenuBarVal;
|
||||||
int useCustomQssVal;
|
int useCustomQssVal, useCustomQPalVal;
|
||||||
QVBoxLayout *mainLayout, *vbox1, *vbox2;
|
QVBoxLayout *mainLayout, *vbox1, *vbox2;
|
||||||
QHBoxLayout *hbox;
|
QHBoxLayout *hbox;
|
||||||
QPushButton *closeButton, *button;
|
QPushButton *closeButton, *button;
|
||||||
|
@ -57,10 +60,11 @@ GuiConfDialog_t::GuiConfDialog_t(QWidget *parent)
|
||||||
QStringList styleKeys;
|
QStringList styleKeys;
|
||||||
QString selStyle;
|
QString selStyle;
|
||||||
QGroupBox *frame, *qssFrame;
|
QGroupBox *frame, *qssFrame;
|
||||||
std::string qssFile;
|
QFrame *hline;
|
||||||
|
std::string qssFile, qpalFile;
|
||||||
|
|
||||||
//resize( 512, 600 );
|
//resize( 512, 600 );
|
||||||
printf("Style: %s \n", style()->objectName().toStdString().c_str() );
|
//printf("Style: %s \n", style()->objectName().toStdString().c_str() );
|
||||||
|
|
||||||
selStyle = style()->objectName();
|
selStyle = style()->objectName();
|
||||||
|
|
||||||
|
@ -68,6 +72,7 @@ GuiConfDialog_t::GuiConfDialog_t(QWidget *parent)
|
||||||
g_config->getOption("SDL.UseNativeFileDialog", &useNativeFileDialogVal);
|
g_config->getOption("SDL.UseNativeFileDialog", &useNativeFileDialogVal);
|
||||||
g_config->getOption("SDL.UseNativeMenuBar", &useNativeMenuBarVal);
|
g_config->getOption("SDL.UseNativeMenuBar", &useNativeMenuBarVal);
|
||||||
g_config->getOption("SDL.UseCustomQss", &useCustomQssVal);
|
g_config->getOption("SDL.UseCustomQss", &useCustomQssVal);
|
||||||
|
g_config->getOption("SDL.UseCustomQPal", &useCustomQPalVal);
|
||||||
|
|
||||||
setWindowTitle(tr("GUI Config"));
|
setWindowTitle(tr("GUI Config"));
|
||||||
|
|
||||||
|
@ -135,7 +140,7 @@ GuiConfDialog_t::GuiConfDialog_t(QWidget *parent)
|
||||||
|
|
||||||
if ( selStyle.compare( styleKeys[i], Qt::CaseInsensitive ) == 0 )
|
if ( selStyle.compare( styleKeys[i], Qt::CaseInsensitive ) == 0 )
|
||||||
{
|
{
|
||||||
printf("Style Match: %s \n", selStyle.toStdString().c_str() );
|
//printf("Style Match: %s \n", selStyle.toStdString().c_str() );
|
||||||
styleComboBox->setCurrentIndex(i);
|
styleComboBox->setCurrentIndex(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,12 +161,43 @@ GuiConfDialog_t::GuiConfDialog_t(QWidget *parent)
|
||||||
|
|
||||||
qssFrame = new QGroupBox( tr("QSS") );
|
qssFrame = new QGroupBox( tr("QSS") );
|
||||||
qssFrame->setLayout( vbox2 );
|
qssFrame->setLayout( vbox2 );
|
||||||
|
vbox1->addWidget( qssFrame );
|
||||||
|
|
||||||
|
useCustomPalette = new QCheckBox( tr("Use Custom QPalette") );
|
||||||
|
useCustomPalette->setChecked(useCustomQPalVal);
|
||||||
|
connect(useCustomPalette, SIGNAL(stateChanged(int)), this, SLOT(useCustomQPaletteChanged(int)));
|
||||||
|
|
||||||
|
vbox2->addWidget( useCustomPalette );
|
||||||
|
|
||||||
|
hbox = new QHBoxLayout();
|
||||||
|
button = new QPushButton(tr("Open"));
|
||||||
|
button->setIcon(style()->standardIcon(QStyle::SP_FileDialogStart));
|
||||||
|
connect(button, SIGNAL(clicked(void)), this, SLOT(openQPal(void)));
|
||||||
|
hbox->addWidget(button);
|
||||||
|
|
||||||
|
button = new QPushButton(tr("Clear"));
|
||||||
|
button->setIcon(style()->standardIcon(QStyle::SP_LineEditClearButton));
|
||||||
|
connect(button, SIGNAL(clicked(void)), this, SLOT(clearQPal(void)));
|
||||||
|
hbox->addWidget(button);
|
||||||
|
vbox2->addLayout( hbox );
|
||||||
|
|
||||||
|
g_config->getOption("SDL.QPaletteFile", &qpalFile);
|
||||||
|
|
||||||
|
custom_qpal_path = new QLineEdit();
|
||||||
|
custom_qpal_path->setReadOnly(true);
|
||||||
|
custom_qpal_path->setText(qpalFile.c_str());
|
||||||
|
vbox2->addWidget( custom_qpal_path );
|
||||||
|
|
||||||
|
hline = new QFrame(this);
|
||||||
|
hline->setFrameShape(QFrame::HLine);
|
||||||
|
hline->setFrameShadow(QFrame::Sunken);
|
||||||
|
hline->setLineWidth(2);
|
||||||
|
vbox2->addWidget( hline );
|
||||||
|
|
||||||
useCustomStyle = new QCheckBox( tr("Use Custom Stylesheet") );
|
useCustomStyle = new QCheckBox( tr("Use Custom Stylesheet") );
|
||||||
useCustomStyle->setChecked(useCustomQssVal);
|
useCustomStyle->setChecked(useCustomQssVal);
|
||||||
connect(useCustomStyle, SIGNAL(stateChanged(int)), this, SLOT(useCustomStyleChanged(int)));
|
connect(useCustomStyle, SIGNAL(stateChanged(int)), this, SLOT(useCustomStyleChanged(int)));
|
||||||
|
|
||||||
vbox1->addWidget( qssFrame );
|
|
||||||
vbox2->addWidget( useCustomStyle );
|
vbox2->addWidget( useCustomStyle );
|
||||||
|
|
||||||
hbox = new QHBoxLayout();
|
hbox = new QHBoxLayout();
|
||||||
|
@ -247,6 +283,15 @@ void GuiConfDialog_t::useCustomStyleChanged(int state)
|
||||||
QApplication::setStyle( new fceuStyle() );
|
QApplication::setStyle( new fceuStyle() );
|
||||||
}
|
}
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
|
void GuiConfDialog_t::useCustomQPaletteChanged(int state)
|
||||||
|
{
|
||||||
|
int value = (state == Qt::Unchecked) ? 0 : 1;
|
||||||
|
|
||||||
|
g_config->setOption("SDL.UseCustomQPal", value);
|
||||||
|
|
||||||
|
QApplication::setStyle( new fceuStyle() );
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
void GuiConfDialog_t::styleChanged(int index)
|
void GuiConfDialog_t::styleChanged(int index)
|
||||||
{
|
{
|
||||||
QString s;
|
QString s;
|
||||||
|
@ -355,13 +400,6 @@ void GuiConfDialog_t::openQss(void)
|
||||||
|
|
||||||
custom_qss_path->setText(filename.toStdString().c_str());
|
custom_qss_path->setText(filename.toStdString().c_str());
|
||||||
|
|
||||||
//g_config->getOption("SDL.UseCustomQss", &useCustom);
|
|
||||||
|
|
||||||
//if ( useCustom )
|
|
||||||
//{
|
|
||||||
//loadQss( filename.toStdString().c_str() );
|
|
||||||
//}
|
|
||||||
|
|
||||||
g_config->setOption("SDL.QtStyleSheet", filename.toStdString().c_str() );
|
g_config->setOption("SDL.QtStyleSheet", filename.toStdString().c_str() );
|
||||||
g_config->save();
|
g_config->save();
|
||||||
|
|
||||||
|
@ -370,6 +408,110 @@ void GuiConfDialog_t::openQss(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
|
void GuiConfDialog_t::clearQPal(void)
|
||||||
|
{
|
||||||
|
custom_qpal_path->setText("");
|
||||||
|
|
||||||
|
g_config->setOption("SDL.QPaletteFile", "");
|
||||||
|
g_config->save();
|
||||||
|
|
||||||
|
QApplication::setStyle( new fceuStyle() );
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void GuiConfDialog_t::openQPal(void)
|
||||||
|
{
|
||||||
|
int ret, useNativeFileDialogVal; //, useCustom;
|
||||||
|
QString filename;
|
||||||
|
std::string last, iniPath;
|
||||||
|
char dir[512];
|
||||||
|
char exePath[512];
|
||||||
|
QFileDialog dialog(this, tr("Open Qt QPalette File (QPAL)"));
|
||||||
|
QList<QUrl> urls;
|
||||||
|
QDir d;
|
||||||
|
|
||||||
|
fceuExecutablePath(exePath, sizeof(exePath));
|
||||||
|
|
||||||
|
//urls = dialog.sidebarUrls();
|
||||||
|
urls << QUrl::fromLocalFile(QDir::rootPath());
|
||||||
|
urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first());
|
||||||
|
urls << QUrl::fromLocalFile(QDir(FCEUI_GetBaseDirectory()).absolutePath());
|
||||||
|
|
||||||
|
if (exePath[0] != 0)
|
||||||
|
{
|
||||||
|
d.setPath(QString(exePath) + "/../qss");
|
||||||
|
|
||||||
|
if (d.exists())
|
||||||
|
{
|
||||||
|
urls << QUrl::fromLocalFile(d.absolutePath());
|
||||||
|
iniPath = d.absolutePath().toStdString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef WIN32
|
||||||
|
|
||||||
|
#else
|
||||||
|
d.setPath("/usr/share/fceux/qss");
|
||||||
|
|
||||||
|
if (d.exists())
|
||||||
|
{
|
||||||
|
urls << QUrl::fromLocalFile(d.absolutePath());
|
||||||
|
iniPath = d.absolutePath().toStdString();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
dialog.setFileMode(QFileDialog::ExistingFile);
|
||||||
|
|
||||||
|
dialog.setNameFilter(tr("Qt Stylesheets (*.qpal *.QPAL) ;; All files (*)"));
|
||||||
|
|
||||||
|
dialog.setViewMode(QFileDialog::List);
|
||||||
|
dialog.setFilter(QDir::AllEntries | QDir::AllDirs | QDir::Hidden);
|
||||||
|
dialog.setLabelText(QFileDialog::Accept, tr("Load"));
|
||||||
|
|
||||||
|
g_config->getOption("SDL.QPaletteFile", &last);
|
||||||
|
|
||||||
|
if (last.size() == 0)
|
||||||
|
{
|
||||||
|
last.assign(iniPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
getDirFromFile(last.c_str(), dir);
|
||||||
|
|
||||||
|
dialog.setDirectory(tr(dir));
|
||||||
|
|
||||||
|
// Check config option to use native file dialog or not
|
||||||
|
g_config->getOption("SDL.UseNativeFileDialog", &useNativeFileDialogVal);
|
||||||
|
|
||||||
|
dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal);
|
||||||
|
dialog.setSidebarUrls(urls);
|
||||||
|
|
||||||
|
ret = dialog.exec();
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
QStringList fileList;
|
||||||
|
fileList = dialog.selectedFiles();
|
||||||
|
|
||||||
|
if (fileList.size() > 0)
|
||||||
|
{
|
||||||
|
filename = fileList[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filename.isNull())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qDebug() << "selected file path : " << filename.toUtf8();
|
||||||
|
|
||||||
|
custom_qpal_path->setText(filename.toStdString().c_str());
|
||||||
|
|
||||||
|
g_config->setOption("SDL.QPaletteFile", filename.toStdString().c_str() );
|
||||||
|
g_config->save();
|
||||||
|
|
||||||
|
QApplication::setStyle( new fceuStyle() );
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
void GuiConfDialog_t::openQPalette(void)
|
void GuiConfDialog_t::openQPalette(void)
|
||||||
{
|
{
|
||||||
GuiPaletteEditDialog_t *dialog = new GuiPaletteEditDialog_t(this);
|
GuiPaletteEditDialog_t *dialog = new GuiPaletteEditDialog_t(this);
|
||||||
|
@ -445,35 +587,49 @@ QStyle *fceuStyle::styleBase(QStyle *style) const
|
||||||
|
|
||||||
void fceuStyle::polish(QPalette &palette)
|
void fceuStyle::polish(QPalette &palette)
|
||||||
{
|
{
|
||||||
|
int useCustom;
|
||||||
|
|
||||||
|
g_config->getOption("SDL.UseCustomQPal", &useCustom);
|
||||||
//basePtr->polish(palette);
|
//basePtr->polish(palette);
|
||||||
//QStyle::polish(palette);
|
//QStyle::polish(palette);
|
||||||
|
|
||||||
//printf("Polish Palette Style!!!\n");
|
if ( !useCustom )
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
std::string qPalFilePath;
|
||||||
|
|
||||||
|
g_config->getOption("SDL.QPaletteFile", &qPalFilePath );
|
||||||
|
|
||||||
|
if ( qPalFilePath.size() > 0 )
|
||||||
|
{
|
||||||
|
readQPaletteFromFile( qPalFilePath.c_str(), &palette );
|
||||||
|
}
|
||||||
|
|
||||||
// modify palette to dark
|
// modify palette to dark
|
||||||
palette.setColor(QPalette::Window, QColor(53, 53, 53));
|
//palette.setColor(QPalette::Window, QColor(53, 53, 53));
|
||||||
palette.setColor(QPalette::WindowText, Qt::white);
|
//palette.setColor(QPalette::WindowText, Qt::white);
|
||||||
palette.setColor(QPalette::Disabled, QPalette::WindowText,
|
//palette.setColor(QPalette::Disabled, QPalette::WindowText,
|
||||||
QColor(127, 127, 127));
|
// QColor(127, 127, 127));
|
||||||
palette.setColor(QPalette::Base, QColor(42, 42, 42));
|
//palette.setColor(QPalette::Base, QColor(42, 42, 42));
|
||||||
palette.setColor(QPalette::AlternateBase, QColor(66, 66, 66));
|
//palette.setColor(QPalette::AlternateBase, QColor(66, 66, 66));
|
||||||
palette.setColor(QPalette::ToolTipBase, Qt::white);
|
//palette.setColor(QPalette::ToolTipBase, Qt::white);
|
||||||
palette.setColor(QPalette::ToolTipText, QColor(53, 53, 53));
|
//palette.setColor(QPalette::ToolTipText, QColor(53, 53, 53));
|
||||||
palette.setColor(QPalette::Text, Qt::white);
|
//palette.setColor(QPalette::Text, Qt::white);
|
||||||
palette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127));
|
//palette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127));
|
||||||
palette.setColor(QPalette::Dark, QColor(35, 35, 35));
|
//palette.setColor(QPalette::Dark, QColor(35, 35, 35));
|
||||||
palette.setColor(QPalette::Shadow, QColor(20, 20, 20));
|
//palette.setColor(QPalette::Shadow, QColor(20, 20, 20));
|
||||||
palette.setColor(QPalette::Button, QColor(53, 53, 53));
|
//palette.setColor(QPalette::Button, QColor(53, 53, 53));
|
||||||
palette.setColor(QPalette::ButtonText, Qt::white);
|
//palette.setColor(QPalette::ButtonText, Qt::white);
|
||||||
palette.setColor(QPalette::Disabled, QPalette::ButtonText,
|
//palette.setColor(QPalette::Disabled, QPalette::ButtonText,
|
||||||
QColor(127, 127, 127));
|
// QColor(127, 127, 127));
|
||||||
palette.setColor(QPalette::BrightText, Qt::red);
|
//palette.setColor(QPalette::BrightText, Qt::red);
|
||||||
palette.setColor(QPalette::Link, QColor(42, 130, 218));
|
//palette.setColor(QPalette::Link, QColor(42, 130, 218));
|
||||||
palette.setColor(QPalette::Highlight, QColor(42, 130, 218));
|
//palette.setColor(QPalette::Highlight, QColor(42, 130, 218));
|
||||||
palette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(80, 80, 80));
|
//palette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(80, 80, 80));
|
||||||
palette.setColor(QPalette::HighlightedText, Qt::white);
|
//palette.setColor(QPalette::HighlightedText, Qt::white);
|
||||||
palette.setColor(QPalette::Disabled, QPalette::HighlightedText,
|
//palette.setColor(QPalette::Disabled, QPalette::HighlightedText,
|
||||||
QColor(127, 127, 127));
|
// QColor(127, 127, 127));
|
||||||
}
|
}
|
||||||
|
|
||||||
void fceuStyle::polish(QApplication *app)
|
void fceuStyle::polish(QApplication *app)
|
||||||
|
@ -610,6 +766,180 @@ static const char *getRoleText( QPalette::ColorRole role )
|
||||||
return rTxt;
|
return rTxt;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
|
static int writeQPaletteToFile( const char *path, QPalette *pal )
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
QColor c;
|
||||||
|
QPalette::ColorGroup g;
|
||||||
|
QPalette::ColorRole r;
|
||||||
|
const char *gTxt, *rTxt;
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
fp = fopen( path, "w");
|
||||||
|
|
||||||
|
if ( fp == NULL )
|
||||||
|
{
|
||||||
|
printf("Error: Failed to Open File for writing: '%s'\n", path );
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j=0; j<3; j++)
|
||||||
|
{
|
||||||
|
|
||||||
|
if ( j == 1 )
|
||||||
|
{
|
||||||
|
g = QPalette::Disabled;
|
||||||
|
gTxt = "Disabled";
|
||||||
|
}
|
||||||
|
else if ( j == 2 )
|
||||||
|
{
|
||||||
|
g = QPalette::Inactive;
|
||||||
|
gTxt = "Inactive";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g = QPalette::Active;
|
||||||
|
gTxt = "Active";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i=0; i<30; i++)
|
||||||
|
{
|
||||||
|
r = (QPalette::ColorRole)i;
|
||||||
|
|
||||||
|
rTxt = getRoleText( r );
|
||||||
|
|
||||||
|
if ( rTxt )
|
||||||
|
{
|
||||||
|
c = pal->color( g, r );
|
||||||
|
|
||||||
|
fprintf( fp, "%s::%s = %s \n", gTxt, rTxt, c.name().toStdString().c_str() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
static int readQPaletteFromFile( const char *path, QPalette *pal )
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
char line[512];
|
||||||
|
char gTxt[128], rTxt[256];
|
||||||
|
char colorTxt[128];
|
||||||
|
const char *rTxtMatch;
|
||||||
|
int i,j,k;
|
||||||
|
QColor color;
|
||||||
|
QPalette::ColorGroup g;
|
||||||
|
QPalette::ColorRole r;
|
||||||
|
|
||||||
|
fp = fopen( path, "r");
|
||||||
|
|
||||||
|
if ( fp == NULL )
|
||||||
|
{
|
||||||
|
printf("Error: Failed to Open File for writing: '%s'\n", path );
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
while ( fgets( line, sizeof(line), fp ) != 0 )
|
||||||
|
{
|
||||||
|
printf("%s", line );
|
||||||
|
|
||||||
|
i=0;
|
||||||
|
|
||||||
|
while ( isspace(line[i]) ) i++;
|
||||||
|
|
||||||
|
j=0;
|
||||||
|
while ( isalnum(line[i]) || (line[i] == '_') )
|
||||||
|
{
|
||||||
|
gTxt[j] = line[i]; j++; i++;
|
||||||
|
}
|
||||||
|
gTxt[j] = 0;
|
||||||
|
|
||||||
|
if ( j == 0 ) continue;
|
||||||
|
|
||||||
|
if (line[i] == ':')
|
||||||
|
{
|
||||||
|
while (line[i] == ':') i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
j=0;
|
||||||
|
while ( isalnum(line[i]) || (line[i] == '_'))
|
||||||
|
{
|
||||||
|
rTxt[j] = line[i]; j++; i++;
|
||||||
|
}
|
||||||
|
rTxt[j] = 0;
|
||||||
|
|
||||||
|
if ( j == 0 ) continue;
|
||||||
|
|
||||||
|
while ( isspace(line[i]) ) i++;
|
||||||
|
|
||||||
|
if (line[i] == '=') i++;
|
||||||
|
|
||||||
|
while ( isspace(line[i]) ) i++;
|
||||||
|
|
||||||
|
if ( strcmp( gTxt, "Active") == 0 )
|
||||||
|
{
|
||||||
|
g = QPalette::Active;
|
||||||
|
}
|
||||||
|
else if ( strcmp( gTxt, "Inactive") == 0 )
|
||||||
|
{
|
||||||
|
g = QPalette::Inactive;
|
||||||
|
}
|
||||||
|
else if ( strcmp( gTxt, "Disabled") == 0 )
|
||||||
|
{
|
||||||
|
g = QPalette::Disabled;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
rTxtMatch = NULL;
|
||||||
|
|
||||||
|
for (k=0; k<30; k++)
|
||||||
|
{
|
||||||
|
|
||||||
|
rTxtMatch = getRoleText( (QPalette::ColorRole)k );
|
||||||
|
|
||||||
|
if ( rTxtMatch )
|
||||||
|
{
|
||||||
|
if ( strcmp( rTxt, rTxtMatch ) == 0 )
|
||||||
|
{
|
||||||
|
r = (QPalette::ColorRole)k;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( rTxtMatch == NULL ) continue;
|
||||||
|
|
||||||
|
color = pal->color( g, r );
|
||||||
|
|
||||||
|
j=0;
|
||||||
|
if (line[i] == '#')
|
||||||
|
{
|
||||||
|
colorTxt[j] = line[i]; j++; i++;
|
||||||
|
|
||||||
|
while ( isxdigit( line[i] ) )
|
||||||
|
{
|
||||||
|
colorTxt[j] = line[i]; j++; i++;
|
||||||
|
}
|
||||||
|
colorTxt[j] = 0;
|
||||||
|
|
||||||
|
color.setNamedColor( colorTxt );
|
||||||
|
}
|
||||||
|
|
||||||
|
//printf("Setting Color %s::%s = %s \n", gTxt, rTxt, colorTxt );
|
||||||
|
pal->setColor( g, r, color );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
GuiPaletteEditDialog_t::GuiPaletteEditDialog_t(QWidget *parent)
|
GuiPaletteEditDialog_t::GuiPaletteEditDialog_t(QWidget *parent)
|
||||||
: QDialog( parent )
|
: QDialog( parent )
|
||||||
{
|
{
|
||||||
|
@ -641,6 +971,14 @@ GuiPaletteEditDialog_t::GuiPaletteEditDialog_t(QWidget *parent)
|
||||||
// File
|
// File
|
||||||
fileMenu = menuBar->addMenu(tr("&File"));
|
fileMenu = menuBar->addMenu(tr("&File"));
|
||||||
|
|
||||||
|
// File -> Save As
|
||||||
|
act = new QAction(tr("Save &As"), this);
|
||||||
|
act->setShortcut(QKeySequence::SaveAs);
|
||||||
|
act->setStatusTip(tr("Save As"));
|
||||||
|
connect(act, SIGNAL(triggered()), this, SLOT(paletteSaveAs(void)) );
|
||||||
|
|
||||||
|
fileMenu->addAction(act);
|
||||||
|
|
||||||
// File -> Close
|
// File -> Close
|
||||||
act = new QAction(tr("&Close"), this);
|
act = new QAction(tr("&Close"), this);
|
||||||
act->setShortcut(QKeySequence::Close);
|
act->setShortcut(QKeySequence::Close);
|
||||||
|
@ -740,6 +1078,103 @@ void GuiPaletteEditDialog_t::closeWindow(void)
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
|
void GuiPaletteEditDialog_t::paletteSaveAs(void)
|
||||||
|
{
|
||||||
|
int ret, useNativeFileDialogVal; //, useCustom;
|
||||||
|
QString filename;
|
||||||
|
std::string last, iniPath;
|
||||||
|
char dir[512];
|
||||||
|
char exePath[512];
|
||||||
|
QFileDialog dialog(this, tr("Save QPalette (qpal)"));
|
||||||
|
QList<QUrl> urls;
|
||||||
|
QDir d;
|
||||||
|
QPalette pal = this->palette();
|
||||||
|
|
||||||
|
fceuExecutablePath(exePath, sizeof(exePath));
|
||||||
|
|
||||||
|
//urls = dialog.sidebarUrls();
|
||||||
|
urls << QUrl::fromLocalFile(QDir::rootPath());
|
||||||
|
urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first());
|
||||||
|
urls << QUrl::fromLocalFile(QDir(FCEUI_GetBaseDirectory()).absolutePath());
|
||||||
|
|
||||||
|
if (exePath[0] != 0)
|
||||||
|
{
|
||||||
|
d.setPath(QString(exePath) + "/../qss");
|
||||||
|
|
||||||
|
if (d.exists())
|
||||||
|
{
|
||||||
|
urls << QUrl::fromLocalFile(d.absolutePath());
|
||||||
|
iniPath = d.absolutePath().toStdString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef WIN32
|
||||||
|
|
||||||
|
#else
|
||||||
|
d.setPath("/usr/share/fceux/qss");
|
||||||
|
|
||||||
|
if (d.exists())
|
||||||
|
{
|
||||||
|
urls << QUrl::fromLocalFile(d.absolutePath());
|
||||||
|
iniPath = d.absolutePath().toStdString();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
dialog.setFileMode(QFileDialog::AnyFile);
|
||||||
|
|
||||||
|
dialog.setNameFilter(tr("Qt QPalette Files (*.qpal *.QPAL) ;; All files (*)"));
|
||||||
|
|
||||||
|
dialog.setViewMode(QFileDialog::List);
|
||||||
|
dialog.setFilter(QDir::AllEntries | QDir::AllDirs | QDir::Hidden);
|
||||||
|
dialog.setLabelText(QFileDialog::Accept, tr("Save"));
|
||||||
|
dialog.setDefaultSuffix( tr(".qpal") );
|
||||||
|
|
||||||
|
g_config->getOption("SDL.QPaletteFile", &last);
|
||||||
|
|
||||||
|
if (last.size() == 0)
|
||||||
|
{
|
||||||
|
last.assign(iniPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
getDirFromFile(last.c_str(), dir);
|
||||||
|
|
||||||
|
dialog.setDirectory(tr(dir));
|
||||||
|
|
||||||
|
// Check config option to use native file dialog or not
|
||||||
|
g_config->getOption("SDL.UseNativeFileDialog", &useNativeFileDialogVal);
|
||||||
|
|
||||||
|
dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal);
|
||||||
|
dialog.setSidebarUrls(urls);
|
||||||
|
|
||||||
|
ret = dialog.exec();
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
QStringList fileList;
|
||||||
|
fileList = dialog.selectedFiles();
|
||||||
|
|
||||||
|
if (fileList.size() > 0)
|
||||||
|
{
|
||||||
|
filename = fileList[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filename.isNull())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qDebug() << "selected file path : " << filename.toUtf8();
|
||||||
|
|
||||||
|
writeQPaletteToFile( filename.toStdString().c_str(), &pal );
|
||||||
|
|
||||||
|
//g_config->setOption("SDL.QPaletteFile", filename.toStdString().c_str() );
|
||||||
|
//g_config->save();
|
||||||
|
|
||||||
|
//QApplication::setStyle( new fceuStyle() );
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
//----------------------------------------------------
|
//----------------------------------------------------
|
||||||
GuiPaletteColorSelect::GuiPaletteColorSelect( QPalette::ColorGroup group, QPalette::ColorRole role, QWidget *parent)
|
GuiPaletteColorSelect::GuiPaletteColorSelect( QPalette::ColorGroup group, QPalette::ColorRole role, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
|
|
@ -123,6 +123,7 @@ protected:
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
public slots:
|
public slots:
|
||||||
void closeWindow(void);
|
void closeWindow(void);
|
||||||
|
void paletteSaveAs(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,8 +143,10 @@ protected:
|
||||||
QCheckBox *useNativeFileDialog;
|
QCheckBox *useNativeFileDialog;
|
||||||
QCheckBox *useNativeMenuBar;
|
QCheckBox *useNativeMenuBar;
|
||||||
QCheckBox *useCustomStyle;
|
QCheckBox *useCustomStyle;
|
||||||
|
QCheckBox *useCustomPalette;
|
||||||
QComboBox *styleComboBox;
|
QComboBox *styleComboBox;
|
||||||
QLineEdit *custom_qss_path;
|
QLineEdit *custom_qss_path;
|
||||||
|
QLineEdit *custom_qpal_path;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -151,10 +154,13 @@ public slots:
|
||||||
private slots:
|
private slots:
|
||||||
void useNativeFileDialogChanged(int v);
|
void useNativeFileDialogChanged(int v);
|
||||||
void useNativeMenuBarChanged(int v);
|
void useNativeMenuBarChanged(int v);
|
||||||
|
void useCustomQPaletteChanged(int v);
|
||||||
void useCustomStyleChanged(int v);
|
void useCustomStyleChanged(int v);
|
||||||
void styleChanged(int index);
|
void styleChanged(int index);
|
||||||
void openQss(void);
|
void openQss(void);
|
||||||
void clearQss(void);
|
void clearQss(void);
|
||||||
|
void openQPal(void);
|
||||||
|
void clearQPal(void);
|
||||||
void openQPalette(void);
|
void openQPalette(void);
|
||||||
void openTestWindow(void);
|
void openTestWindow(void);
|
||||||
};
|
};
|
||||||
|
|
|
@ -375,7 +375,9 @@ InitConfig()
|
||||||
config->addOption("_useNativeMenuBar" , "SDL.UseNativeMenuBar", false);
|
config->addOption("_useNativeMenuBar" , "SDL.UseNativeMenuBar", false);
|
||||||
config->addOption("SDL.GuiStyle", "");
|
config->addOption("SDL.GuiStyle", "");
|
||||||
config->addOption("SDL.QtStyleSheet", "");
|
config->addOption("SDL.QtStyleSheet", "");
|
||||||
|
config->addOption("SDL.QPaletteFile", "");
|
||||||
config->addOption("SDL.UseCustomQss", 0);
|
config->addOption("SDL.UseCustomQss", 0);
|
||||||
|
config->addOption("SDL.UseCustomQPal", 0);
|
||||||
|
|
||||||
config->addOption("_setSchedParam" , "SDL.SetSchedParam" , 0);
|
config->addOption("_setSchedParam" , "SDL.SetSchedParam" , 0);
|
||||||
config->addOption("_emuSchedPolicy" , "SDL.EmuSchedPolicy", 0);
|
config->addOption("_emuSchedPolicy" , "SDL.EmuSchedPolicy", 0);
|
||||||
|
|
Loading…
Reference in New Issue