Skip to content

Commit

Permalink
Add color schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
bweir committed Apr 11, 2015
1 parent a4b15d0 commit a7cb3e8
Show file tree
Hide file tree
Showing 8 changed files with 3,465 additions and 3,416 deletions.
30 changes: 30 additions & 0 deletions color.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <QVector>
#include <QRgb>
#include <QStringList>

class Color
{

public:
Color()
{
colors["Plain"] << 0xFF000000 << 0xFFFFFFFF << 0xFFFF00FF << 0xFF7F7F7F;
colors["White On Blue"] << 0xFF7140FE << 0xFFCCCCCC << 0xFFFF00FF << 0xFFB17DE1;
colors["Red On Black"] << 0xFF6F0000 << 0xFFFF0000 << 0xFF000000 << 0xFFCC0000;
}

QStringList keys()
{
return QStringList(colors.keys());
}

const QVector<QRgb> & operator[](const QString & name)
{
return colors[name];
}


private:
QMap<QString, QVector<QRgb> > colors;

};
4 changes: 1 addition & 3 deletions lspaint.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ SOURCES += \
mainwindow.cpp \
spriteeditor.cpp \
spriteimage.cpp \
sidebar.cpp \
dialogs/newfile.cpp \

HEADERS += \
mainwindow.h \
spriteeditor.h \
spriteimage.h \
sidebar.h \
dialogs/newfile.h \
color.h \

FORMS += \
mainwindow.ui \
spriteeditor.ui \
sidebar.ui \
dialogs/newfile.ui \
38 changes: 36 additions & 2 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QFileInfo>
#include <QFileDialog>

#include "color.h"
#include "spriteeditor.h"

#include "dialogs/newfile.h"
Expand All @@ -16,13 +17,23 @@ MainWindow::MainWindow(QWidget * parent)
{
ui.setupUi(this);

openFile("dagr_2b.png");
qDebug() << " STUFF";
// openFile("dagr_2b.png");

connect(ui.action_New, SIGNAL(triggered()), this, SLOT(newFile()));
connect(ui.action_Open, SIGNAL(triggered()), this, SLOT(open()));
connect(ui.action_Save, SIGNAL(triggered()), this, SLOT(save()));
connect(ui.actionSave_as, SIGNAL(triggered()), this, SLOT(saveAs()));
connect(ui.actionQuit, SIGNAL(triggered()), this, SLOT(close()));

// configure color schemes
foreach (QString key, Color().keys())
ui.colorschemes->addItem(key);

palette = ui.colorschemes->itemText(0);

connect(ui.colorschemes, SIGNAL(currentIndexChanged(const QString &)),
this, SLOT(setColorPalette(const QString &)));

}


Expand Down Expand Up @@ -134,6 +145,12 @@ void MainWindow::openFile(const QString & name)

qDebug() << framew << frameh;

img = img.convertToFormat(QImage::Format_RGB32);
img = img.convertToFormat(QImage::Format_Indexed8, Color()["Plain"]);


img.setColorTable(Color()["Plain"]);

QPixmap pixmap = QPixmap::fromImage(img);
editor->setPixmap(pixmap);

Expand All @@ -150,3 +167,20 @@ void MainWindow::closeFile()
ui.editor->removeTab(0);
}
}


void MainWindow::setColorPalette(const QString & name)
{
SpriteEditor * editor = (SpriteEditor *) ui.editor->currentWidget();
if (!editor) return;

QImage img = editor->pixmap().toImage();

img = img.convertToFormat(QImage::Format_Indexed8, Color()[palette]);
img.setColorTable(Color()[name]);
palette = name;

QPixmap pixmap = QPixmap::fromImage(img);

editor->setPixmap(pixmap);
}
2 changes: 2 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MainWindow : public QMainWindow
private:
Ui::MainWindow ui;
QString filename;
QString palette;
public:
MainWindow(QWidget * parent = 0);

Expand All @@ -23,5 +24,6 @@ public slots:
void saveFile(const QString & filename);
void openFile(const QString & filename);
void closeFile();
void setColorPalette(const QString & name);
};

Loading

0 comments on commit a7cb3e8

Please sign in to comment.