Naming Convention and clean-up dead code

This commit is contained in:
Sonaion
2019-12-09 19:38:32 +01:00
parent 4c61bae14b
commit 62e144abd4
4 changed files with 171 additions and 189 deletions

View File

@@ -39,7 +39,7 @@ void IntelliPhotoGui::closeEvent(QCloseEvent *event)
// Check if the current image has been changed and then
// open a dialog to open a file
void IntelliPhotoGui::open()
void IntelliPhotoGui::slotOpen()
{
// Check if changes have been made since last save
// maybeSave() returns true if no changes have been made
@@ -54,12 +54,12 @@ void IntelliPhotoGui::open()
// If we have a file name load the image and place
// it in the paintingArea
if (!fileName.isEmpty())
paintingArea->openImage(fileName);
paintingArea->open(fileName);
}
}
// Called when the user clicks Save As in the menu
void IntelliPhotoGui::save()
void IntelliPhotoGui::slotSave()
{
// A QAction represents the action of the user clicking
QAction *action = qobject_cast<QAction *>(sender());
@@ -72,7 +72,7 @@ void IntelliPhotoGui::save()
}
// Opens a dialog that allows the user to create a New Layer
void IntelliPhotoGui::newLayer()
void IntelliPhotoGui::slotCreateNewLayer()
{
// Stores button value
bool ok1, ok2;
@@ -90,12 +90,12 @@ void IntelliPhotoGui::newLayer()
if (ok1&&ok2)
{
int layer = paintingArea->addLayer(width,height,100,100);
paintingArea->activate(layer);
paintingArea->slotActivateLayer(layer);
}
}
// Opens a dialog that allows the user to delete a Layer
void IntelliPhotoGui::deleteLayer()
void IntelliPhotoGui::slotDeleteLayer()
{
// Stores button value
bool ok;
@@ -112,7 +112,7 @@ void IntelliPhotoGui::deleteLayer()
}
void IntelliPhotoGui::onSetAlpha(){
void IntelliPhotoGui::slotSetActiveAlpha(){
// Stores button value
bool ok1, ok2;
@@ -128,41 +128,41 @@ void IntelliPhotoGui::onSetAlpha(){
255,0, 255, 1, &ok2);
if (ok1&&ok2)
{
paintingArea->setAlphaToLayer(layer,alpha);
paintingArea->setAlphaOfLayer(layer,alpha);
}
}
void IntelliPhotoGui::onMoveUp(){
paintingArea->moveActive(0,-2);
void IntelliPhotoGui::slotPositionMoveUp(){
paintingArea->movePositionActive(0,-2);
update();
}
void IntelliPhotoGui::onMoveDown(){
paintingArea->moveActive(0,2);
void IntelliPhotoGui::slotPositionMoveDown(){
paintingArea->movePositionActive(0,2);
update();
}
void IntelliPhotoGui::onMoveLeft(){
paintingArea->moveActive(-2,0);
void IntelliPhotoGui::slotPositionMoveLeft(){
paintingArea->movePositionActive(-2,0);
update();
}
void IntelliPhotoGui::onMoveRight(){
paintingArea->moveActive(2,0);
void IntelliPhotoGui::slotPositionMoveRight(){
paintingArea->movePositionActive(2,0);
update();
}
void IntelliPhotoGui::onMoveLayerUp(){
void IntelliPhotoGui::slotMoveLayerUp(){
paintingArea->moveActiveLayer(1);
update();
}
void IntelliPhotoGui::onMoveLayerDown(){
void IntelliPhotoGui::slotMoveLayerDown(){
paintingArea->moveActiveLayer(-1);
update();
}
void IntelliPhotoGui::onClearedPressed(){
void IntelliPhotoGui::slotClearActiveLayer(){
// Stores button value
bool ok1, ok2, ok3, ok4;
@@ -186,11 +186,11 @@ void IntelliPhotoGui::onClearedPressed(){
255,0, 255, 1, &ok4);
if (ok1&&ok2&&ok3&&ok4)
{
paintingArea->clearImage(red, green, blue, alpha);
paintingArea->floodFill(red, green, blue, alpha);
}
}
void IntelliPhotoGui::onActivePressed(){
void IntelliPhotoGui::slotSetActiveLayer(){
// Stores button value
bool ok1;
@@ -208,7 +208,7 @@ void IntelliPhotoGui::onActivePressed(){
// Open an about dialog
void IntelliPhotoGui::about()
void IntelliPhotoGui::slotAboutDialog()
{
// Window title and text to display
QMessageBox::about(this, tr("About Painting"),
@@ -219,13 +219,13 @@ void IntelliPhotoGui::about()
void IntelliPhotoGui::createActions()
{
// Create the action tied to the menu
openAct = new QAction(tr("&Open..."), this);
actionOpen = new QAction(tr("&Open..."), this);
// Define the associated shortcut key
openAct->setShortcuts(QKeySequence::Open);
actionOpen->setShortcuts(QKeySequence::Open);
// Tie the action to IntelliPhotoGui::open()
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
connect(actionOpen, SIGNAL(triggered()), this, SLOT(slotOpen()));
// Get a list of the supported file formats
// QImageWriter is used to write images to files
@@ -239,80 +239,80 @@ void IntelliPhotoGui::createActions()
action->setData(format);
// When clicked call IntelliPhotoGui::save()
connect(action, SIGNAL(triggered()), this, SLOT(save()));
connect(action, SIGNAL(triggered()), this, SLOT(slotSave()));
// Attach each file format option menu item to Save As
saveAsActs.append(action);
actionSaveAs.append(action);
}
//set exporter to actions
QAction *pngSaveAction = new QAction("PNG-8", this);
pngSaveAction->setData("PNG");
// When clicked call IntelliPhotoGui::save()
connect(pngSaveAction, SIGNAL(triggered()), this, SLOT(save()));
connect(pngSaveAction, SIGNAL(triggered()), this, SLOT(slotSave()));
// Attach each PNG in save Menu
saveAsActs.append(pngSaveAction);
actionSaveAs.append(pngSaveAction);
// Create exit action and tie to IntelliPhotoGui::close()
exitAct = new QAction(tr("&Exit"), this);
exitAct->setShortcuts(QKeySequence::Quit);
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
actionOpen = new QAction(tr("&Exit"), this);
actionOpen->setShortcuts(QKeySequence::Quit);
connect(actionOpen, SIGNAL(triggered()), this, SLOT(close()));
// Create New Layer action and tie to IntelliPhotoGui::newLayer()
newLayerAct = new QAction(tr("&New Layer..."), this);
connect(newLayerAct, SIGNAL(triggered()), this, SLOT(newLayer()));
actionCreateNewLayer = new QAction(tr("&New Layer..."), this);
connect(actionCreateNewLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewLayer()));
// Delete New Layer action and tie to IntelliPhotoGui::deleteLayer()
deleteLayerAct = new QAction(tr("&Delete Layer..."), this);
connect(deleteLayerAct, SIGNAL(triggered()), this, SLOT(deleteLayer()));
actionDeleteLayer = new QAction(tr("&Delete Layer..."), this);
connect(actionDeleteLayer, SIGNAL(triggered()), this, SLOT(slotDeleteLayer()));
// Delete Active Layer action and tie to paintingArea::deleteActiveLayerLayer()
deleteActiveLayerAct = new QAction(tr("&Delete active Layer"), this);
connect(deleteActiveLayerAct, SIGNAL(triggered()), paintingArea, SLOT(deleteActiveLayer()));
actionDeleteActiveLayer = new QAction(tr("&Delete active Layer"), this);
connect(actionDeleteActiveLayer, SIGNAL(triggered()), paintingArea, SLOT(deleteActiveLayer()));
clearedActions = new QAction(tr("&clear Image"), this);
connect(clearedActions, SIGNAL(triggered()), this, SLOT(onClearedPressed()));
actionFloodFill = new QAction(tr("&clear Image"), this);
connect(actionFloodFill, SIGNAL(triggered()), this, SLOT(slotClearActiveLayer()));
setActiveAction = new QAction(tr("&set Active"), this);
connect(setActiveAction, SIGNAL(triggered()), this, SLOT(onActivePressed()));
actionSetActiveLayer = new QAction(tr("&set Active"), this);
connect(actionSetActiveLayer, SIGNAL(triggered()), this, SLOT(slotSetActiveLayer()));
setAlphaAction = new QAction(tr("&set Alpha"), this);
connect(setAlphaAction, SIGNAL(triggered()), this, SLOT(onSetAlpha()));
actionSetActiveAlpha = new QAction(tr("&set Alpha"), this);
connect(actionSetActiveAlpha, SIGNAL(triggered()), this, SLOT(slotSetActiveAlpha()));
moveUpAction = new QAction(tr("&move Up"), this);
moveUpAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up));
connect(moveUpAction, SIGNAL(triggered()), this, SLOT(onMoveUp()));
actionMovePositionUp = new QAction(tr("&move Up"), this);
actionMovePositionUp->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up));
connect(actionMovePositionUp, SIGNAL(triggered()), this, SLOT(slotPositionMoveUp()));
moveDownAction = new QAction(tr("&move Down"), this);
moveDownAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Down));
connect(moveDownAction, SIGNAL(triggered()), this, SLOT(onMoveDown()));
actionMovePositionDown = new QAction(tr("&move Down"), this);
actionMovePositionDown->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Down));
connect(actionMovePositionDown, SIGNAL(triggered()), this, SLOT(slotPositionMoveDown()));
moveLeftAction = new QAction(tr("&move Left"), this);
moveLeftAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left));
connect(moveLeftAction, SIGNAL(triggered()), this, SLOT(onMoveLeft()));
actionMovePositionLeft = new QAction(tr("&move Left"), this);
actionMovePositionLeft->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left));
connect(actionMovePositionLeft, SIGNAL(triggered()), this, SLOT(slotPositionMoveLeft()));
moveRightAction = new QAction(tr("&move Right"), this);
moveRightAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right));
connect(moveRightAction, SIGNAL(triggered()), this, SLOT(onMoveRight()));
actionMovePositionRight = new QAction(tr("&move Right"), this);
actionMovePositionRight->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right));
connect(actionMovePositionRight, SIGNAL(triggered()), this, SLOT(slotPositionMoveRight()));
moveLayerUpAction = new QAction(tr("&move Layer Up"), this);
moveLayerUpAction->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Up));
connect(moveLayerUpAction, SIGNAL(triggered()), this, SLOT(onMoveLayerUp()));
actionMoveLayerUp = new QAction(tr("&move Layer Up"), this);
actionMoveLayerUp->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Up));
connect(actionMoveLayerUp, SIGNAL(triggered()), this, SLOT(slotMoveLayerUp()));
moveLayerDownAction= new QAction(tr("&move Layer Down"), this);
moveLayerDownAction->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Down));
connect(moveLayerDownAction, SIGNAL(triggered()), this, SLOT(onMoveLayerDown()));
actionMoveLayerDown= new QAction(tr("&move Layer Down"), this);
actionMoveLayerDown->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Down));
connect(actionMoveLayerDown, SIGNAL(triggered()), this, SLOT(slotMoveLayerDown()));
// Create about action and tie to IntelliPhotoGui::about()
aboutAct = new QAction(tr("&About"), this);
connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
actionAboutDialog = new QAction(tr("&About"), this);
connect(actionAboutDialog, SIGNAL(triggered()), this, SLOT(slotAboutDialog()));
// Create about Qt action and tie to IntelliPhotoGui::aboutQt()
aboutQtAct = new QAction(tr("About &Qt"), this);
connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
actionAboutQtDialog = new QAction(tr("About &Qt"), this);
connect(actionAboutQtDialog, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
}
// Create the menubar
@@ -320,42 +320,42 @@ void IntelliPhotoGui::createMenus()
{
// Create Save As option and the list of file types
saveAsMenu = new QMenu(tr("&Save As"), this);
foreach (QAction *action, saveAsActs)
foreach (QAction *action, actionSaveAs)
saveAsMenu->addAction(action);
// Attach all actions to File
fileMenu = new QMenu(tr("&File"), this);
fileMenu->addAction(openAct);
fileMenu->addAction(actionOpen);
fileMenu->addMenu(saveAsMenu);
fileMenu->addSeparator();
fileMenu->addAction(exitAct);
fileMenu->addAction(actionOpen);
// Attach all actions to Options
optionMenu = new QMenu(tr("&Options"), this);
optionMenu->addAction(clearedActions);
optionMenu->addAction(setActiveAction);
optionMenu->addAction(setAlphaAction);
optionMenu->addAction(moveUpAction);
optionMenu->addAction(moveDownAction);
optionMenu->addAction(moveLeftAction);
optionMenu->addAction(moveRightAction);
optionMenu->addAction(moveLayerUpAction);
optionMenu->addAction(moveLayerDownAction);
optionMenu->addAction(actionFloodFill);
optionMenu->addAction(actionSetActiveLayer);
optionMenu->addAction(actionSetActiveAlpha);
optionMenu->addAction(actionMovePositionUp);
optionMenu->addAction(actionMovePositionDown);
optionMenu->addAction(actionMovePositionLeft);
optionMenu->addAction(actionMovePositionRight);
optionMenu->addAction(actionMoveLayerUp);
optionMenu->addAction(actionMoveLayerDown);
// Attach all actions to Layer
layerMenu = new QMenu(tr("&Layer"), this);
layerMenu->addAction(newLayerAct);
layerMenu->addAction(deleteLayerAct);
layerMenu->addAction(deleteActiveLayerAct);
layerMenu->addAction(actionCreateNewLayer);
layerMenu->addAction(actionDeleteLayer);
layerMenu->addAction(actionDeleteActiveLayer);
//Attach all Tool Options
toolMenu = new QMenu(tr("&Tools"), this);
// Attach all actions to Help
helpMenu = new QMenu(tr("&Help"), this);
helpMenu->addAction(aboutAct);
helpMenu->addAction(aboutQtAct);
helpMenu->addAction(actionAboutDialog);
helpMenu->addAction(actionAboutQtDialog);
// Add menu items to the menubar
menuBar()->addMenu(fileMenu);
@@ -435,7 +435,7 @@ bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat)
} else {
// Call for the file to be saved
return paintingArea->saveImage(fileName, fileFormat.constData());
return paintingArea->save(fileName, fileFormat.constData());
}
}

View File

@@ -27,21 +27,21 @@ protected:
// The events that can be triggered
private slots:
void open();
void save();
void newLayer();
void deleteLayer();
void about();
void slotOpen();
void slotSave();
void slotCreateNewLayer();
void slotDeleteLayer();
void slotAboutDialog();
void onClearedPressed();
void onActivePressed();
void onSetAlpha();
void onMoveUp();
void onMoveDown();
void onMoveLeft();
void onMoveRight();
void onMoveLayerUp();
void onMoveLayerDown();
void slotClearActiveLayer();
void slotSetActiveLayer();
void slotSetActiveAlpha();
void slotPositionMoveUp();
void slotPositionMoveDown();
void slotPositionMoveLeft();
void slotPositionMoveRight();
void slotMoveLayerUp();
void slotMoveLayerDown();
private:
// Will tie user actions to functions
@@ -70,28 +70,28 @@ private:
QMenu *helpMenu;
// All the actions that can occur
QAction *openAct;
QAction *exitAct;
QAction *actionOpen;
QAction *actionExit;
QAction *newLayerAct;
QAction *deleteLayerAct;
QAction *deleteActiveLayerAct;
QAction *actionCreateNewLayer;
QAction *actionDeleteLayer;
QAction *actionDeleteActiveLayer;
QAction *aboutAct;
QAction *aboutQtAct;
QAction *actionAboutDialog;
QAction *actionAboutQtDialog;
QAction* clearedActions;
QAction* setActiveAction;
QAction* setAlphaAction;
QAction* moveUpAction;
QAction* moveDownAction;
QAction* moveLeftAction;
QAction* moveRightAction;
QAction* moveLayerUpAction;
QAction* moveLayerDownAction;
QAction* actionFloodFill;
QAction* actionSetActiveLayer;
QAction* actionSetActiveAlpha;
QAction* actionMovePositionUp;
QAction* actionMovePositionDown;
QAction* actionMovePositionLeft;
QAction* actionMovePositionRight;
QAction* actionMoveLayerUp;
QAction* actionMoveLayerDown;
// Actions tied to specific file formats
QList<QAction *> saveAsActs;
QList<QAction *> actionSaveAs;
//main GUI elements
QWidget* centralGuiWidget;

View File

@@ -16,17 +16,17 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
this->setUp(maxWidth, maxHeight);
//tetsing
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
layerStructure[0].image->floodFill(QColor(255,0,0,255));
layerBundle[0].image->floodFill(QColor(255,0,0,255));
std::vector<QPoint> polygon;
polygon.push_back(QPoint(100,000));
polygon.push_back(QPoint(200,100));
polygon.push_back(QPoint(100,200));
polygon.push_back(QPoint(000,100));
layerStructure[0].image->setPolygon(polygon);
layerBundle[0].image->setPolygon(polygon);
this->addLayer(200,200,150,150);
layerStructure[1].image->floodFill(QColor(0,255,0,255));
layerStructure[1].alpha=200;
layerBundle[1].image->floodFill(QColor(0,255,0,255));
layerBundle[1].alpha=200;
activeLayer=1;
}
@@ -40,73 +40,69 @@ void PaintingArea::setUp(int maxWidth, int maxHeight){
// Roots the widget to the top left even if resized
setAttribute(Qt::WA_StaticContents);
// Set defaults for the monitored variables
scribbling = false;
myPenWidth = 1;
myPenColor = Qt::blue;
}
int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, ImageType type){
LayerObject newLayer;
newLayer.width = width;
newLayer.height = height;
newLayer.hight = height;
newLayer.widthOffset = widthOffset;
newLayer.heightOffset = heightOffset;
newLayer.hightOffset = heightOffset;
if(type==ImageType::Raster_Image){
newLayer.image = new IntelliRasterImage(width,height);
}else if(type==ImageType::Shaped_Image){
newLayer.image = new IntelliShapedImage(width, height);
}
newLayer.alpha = 255;
this->layerStructure.push_back(newLayer);
return static_cast<int>(layerStructure.size())-1;
this->layerBundle.push_back(newLayer);
return static_cast<int>(layerBundle.size())-1;
}
void PaintingArea::deleteLayer(int index){
if(index<static_cast<int>(layerStructure.size())){
this->layerStructure.erase(layerStructure.begin()+index);
if(index<static_cast<int>(layerBundle.size())){
this->layerBundle.erase(layerBundle.begin()+index);
if(activeLayer>=index){
activeLayer--;
}
}
}
void PaintingArea::deleteActiveLayer(){
if(activeLayer>=0 && activeLayer < static_cast<int>(layerStructure.size())){
this->layerStructure.erase(layerStructure.begin()+activeLayer);
void PaintingArea::slotDeleteActiveLayer(){
if(activeLayer>=0 && activeLayer < static_cast<int>(layerBundle.size())){
this->layerBundle.erase(layerBundle.begin()+activeLayer);
activeLayer--;
}
}
void PaintingArea::setLayerToActive(int index) {
if(index>=0&&index<static_cast<int>(layerStructure.size())){
if(index>=0&&index<static_cast<int>(layerBundle.size())){
this->activeLayer=index;
}
}
void PaintingArea::setAlphaToLayer(int index, int alpha){
if(index>=0&&index<static_cast<int>(layerStructure.size())){
layerStructure[static_cast<size_t>(index)].alpha=alpha;
void PaintingArea::setAlphaOfLayer(int index, int alpha){
if(index>=0&&index<static_cast<int>(layerBundle.size())){
layerBundle[static_cast<size_t>(index)].alpha=alpha;
}
}
// Used to load the image and place it in the widget
bool PaintingArea::openImage(const QString &fileName)
bool PaintingArea::open(const QString &fileName)
{
if(this->activeLayer==-1){
return false;
}
IntelliImage* active = layerStructure[static_cast<size_t>(activeLayer)].image;
IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
bool open = active->loadImage(fileName);
update();
return open;
}
// Save the current image
bool PaintingArea::saveImage(const QString &fileName, const char *fileFormat)
bool PaintingArea::save(const QString &fileName, const char *fileFormat)
{
if(layerStructure.size()==0){
if(layerBundle.size()==0){
return false;
}
this->assembleLayers(true);
@@ -130,30 +126,30 @@ bool PaintingArea::saveImage(const QString &fileName, const char *fileFormat)
// Color the image area with white
void PaintingArea::clearImage(int r, int g, int b, int a){
void PaintingArea::floodFill(int r, int g, int b, int a){
if(this->activeLayer==-1){
return;
}
IntelliImage* active = layerStructure[static_cast<size_t>(activeLayer)].image;
IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
active->floodFill(QColor(r, g, b, a));
update();
}
void PaintingArea::moveActive(int x, int y){
layerStructure[static_cast<size_t>(activeLayer)].widthOffset += x;
layerStructure[static_cast<size_t>(activeLayer)].heightOffset += y;
void PaintingArea::movePositionActive(int x, int y){
layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x;
layerBundle[static_cast<size_t>(activeLayer)].hightOffset += y;
}
void PaintingArea::moveActiveLayer(int idx){
if(idx==1){
this->activeLayerUp();
this->activateUpperLayer();
}else if(idx==-1){
this->activeLayerDown();
this->activateLowerLayer();
}
}
void PaintingArea::activate(int a){
if(a>=0 && a < static_cast<int>(layerStructure.size())){
void PaintingArea::slotActivateLayer(int a){
if(a>=0 && a < static_cast<int>(layerBundle.size())){
this->setLayerToActive(a);
}
}
@@ -207,16 +203,16 @@ void PaintingArea::resizeImage(QImage *image_res, const QSize &newSize){
//TODO implement
}
void PaintingArea::activeLayerUp(){
if(activeLayer!=-1 && activeLayer<layerStructure.size()-1){
std::swap(layerStructure[activeLayer], layerStructure[activeLayer+1]);
void PaintingArea::activateUpperLayer(){
if(activeLayer!=-1 && activeLayer<layerBundle.size()-1){
std::swap(layerBundle[activeLayer], layerBundle[activeLayer+1]);
activeLayer++;
}
}
void PaintingArea::activeLayerDown(){
void PaintingArea::activateLowerLayer(){
if(activeLayer!=-1 && activeLayer>0){
std::swap(layerStructure[activeLayer], layerStructure[activeLayer-1]);
std::swap(layerBundle[activeLayer], layerBundle[activeLayer-1]);
activeLayer--;
}
}
@@ -227,18 +223,18 @@ void PaintingArea::assembleLayers(bool forSaving){
}else{
Canvas->fill(Qt::GlobalColor::black);
}
for(size_t i=0; i<layerStructure.size(); i++){
LayerObject layer = layerStructure[i];
for(size_t i=0; i<layerBundle.size(); i++){
LayerObject layer = layerBundle[i];
QImage cpy = layer.image->getDisplayable(layer.alpha);
QColor clr_0;
QColor clr_1;
for(int y=0; y<layer.height; y++){
if(layer.heightOffset+y<0) continue;
if(layer.heightOffset+y>=maxHeight) break;
for(int y=0; y<layer.hight; y++){
if(layer.hightOffset+y<0) continue;
if(layer.hightOffset+y>=maxHeight) break;
for(int x=0; x<layer.width; x++){
if(layer.widthOffset+x<0) continue;
if(layer.heightOffset+y>=maxWidth) break;
clr_0=Canvas->pixelColor(layer.widthOffset+x, layer.heightOffset+y);
if(layer.hightOffset+y>=maxWidth) break;
clr_0=Canvas->pixelColor(layer.widthOffset+x, layer.hightOffset+y);
clr_1=cpy.pixelColor(x,y);
float t = static_cast<float>(clr_1.alpha())/255.f;
int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
@@ -250,7 +246,7 @@ void PaintingArea::assembleLayers(bool forSaving){
clr_0.setBlue(b);
clr_0.setAlpha(a);
Canvas->setPixelColor(layer.widthOffset+x, layer.heightOffset+y, clr_0);
Canvas->setPixelColor(layer.widthOffset+x, layer.hightOffset+y, clr_0);
}
}
}

View File

@@ -12,9 +12,9 @@
struct LayerObject{
IntelliImage* image;
int width;
int height;
int hight;
int widthOffset;
int heightOffset;
int hightOffset;
int alpha=255;
};
@@ -29,15 +29,15 @@ public:
PaintingArea(int maxWidth=600, int maxHeight=600, QWidget *parent = nullptr);
// Handles all events
bool openImage(const QString &fileName);
bool saveImage(const QString &fileName, const char *fileFormat);
bool open(const QString &fileName);
bool save(const QString &fileName, const char *fileFormat);
int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, ImageType type = ImageType::Raster_Image);
void deleteLayer(int index);
void setLayerToActive(int index);
void setAlphaToLayer(int index, int alpha);
void clearImage(int r, int g, int b, int a);
void moveActive(int x, int y);
void setAlphaOfLayer(int index, int alpha);
void floodFill(int r, int g, int b, int a);
void movePositionActive(int x, int y);
void moveActiveLayer(int idx);
// Has the image been modified since last save
@@ -46,11 +46,9 @@ public:
public slots:
// Events to handle
void activate(int a);
void deleteActiveLayer();
void slotActivateLayer(int a);
void slotDeleteActiveLayer();
//void setUp helper for konstruktor
void setUp(int maxWidth, int maxHeight);
protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
@@ -64,14 +62,15 @@ protected:
void resizeEvent(QResizeEvent *event) override;
private:
void activeLayerUp();
void activeLayerDown();
void setUp(int maxWidth, int maxHeight);
void activateUpperLayer();
void activateLowerLayer();
QImage* Canvas;
int maxWidth;
int maxHeight;
std::vector<LayerObject> layerStructure;
std::vector<LayerObject> layerBundle;
int activeLayer=-1;
void assembleLayers(bool forSaving=false);
@@ -81,19 +80,6 @@ private:
// Will be marked true or false depending on if
// we have saved after a change
bool modified=false;
// Marked true or false depending on if the user
// is drawing
bool scribbling;
// Holds the current pen width & color
int myPenWidth;
QColor myPenColor;
// Stores the image being drawn
// Stores the location at the current mouse event
QPoint lastPoint;
};
#endif