Comments and compile fähig

This commit is contained in:
Sonaion
2019-11-19 22:09:41 +01:00
parent c49c3c5e9c
commit ff2cddfd3c
11 changed files with 113 additions and 51 deletions

View File

@@ -1,8 +1,8 @@
#include "LayerManager.h" #include "LayerManager.h"
LayerManager::LayerManager(){ LayerManager::LayerManager(){
//setup the label for the image
this->imgLabel = new QLabel(""); this->imgLabel = new QLabel("");
} }
LayerManager::~LayerManager(){ LayerManager::~LayerManager(){
@@ -18,6 +18,7 @@ int LayerManager::getLayerCount(){
void LayerManager::setLayerVisbility(int idx, int alpha){ void LayerManager::setLayerVisbility(int idx, int alpha){
//current alpha is ignored, just one image is shown //current alpha is ignored, just one image is shown
//all images should hold on to their current alpha
for(auto &element: this->MetaEbenen){ for(auto &element: this->MetaEbenen){
element.a=0; element.a=0;
} }
@@ -25,6 +26,7 @@ void LayerManager::setLayerVisbility(int idx, int alpha){
} }
void LayerManager::activateLayer(int idx){ void LayerManager::activateLayer(int idx){
//all images should blurr an active layer should show
for(auto& element: this->MetaEbenen){ for(auto& element: this->MetaEbenen){
element.a = 0; element.a = 0;
} }
@@ -32,6 +34,7 @@ void LayerManager::activateLayer(int idx){
} }
void LayerManager::goLayerUp(){ void LayerManager::goLayerUp(){
//at current state, sets the alpha of the higher one up
for(size_t i=0; i<static_cast<size_t>(this->getLayerCount()); i++){ for(size_t i=0; i<static_cast<size_t>(this->getLayerCount()); i++){
if(this->MetaEbenen[i].a==255){ if(this->MetaEbenen[i].a==255){
if(i==static_cast<size_t>(this->getLayerCount())-1){ if(i==static_cast<size_t>(this->getLayerCount())-1){
@@ -45,6 +48,7 @@ void LayerManager::goLayerUp(){
} }
void LayerManager::goLayerDown(){ void LayerManager::goLayerDown(){
//at current state, sets the alpha of the higher one down
for(size_t i=0; i<static_cast<size_t>(this->getLayerCount()); i++){ for(size_t i=0; i<static_cast<size_t>(this->getLayerCount()); i++){
if(this->MetaEbenen[i].a==255){ if(this->MetaEbenen[i].a==255){
if(i==0){ if(i==0){
@@ -58,23 +62,44 @@ void LayerManager::goLayerDown(){
} }
void LayerManager::AddLayerAfer(int idx){ void LayerManager::AddLayerAfer(int idx){
Layer* newLayer = new Layer(100,100); //layer dimension needs to be asked, maybe in seperat window
Layer* newLayer = new Layer(600,400);
//hardcoded layer for test sake
for(int i=0; i<600; i++){
for(int j=0; j<400; j++){
newLayer->setPixel(i,j,255,0,0,255);
}
}
for(int i=0; i<300; i++){
for(int j = 0; j<5; j++)
newLayer->setPixel(i,j,0,255,255,255);
}
maxWidth=100;
maxHeight=100;
Ebenen.insert(Ebenen.begin()+idx, newLayer); Ebenen.insert(Ebenen.begin()+idx, newLayer);
MetaEbenen.insert(MetaEbenen.begin()+idx, EbenenMetaDaten(0,0,0));
} }
void LayerManager::DeleteLayer(int idx){ void LayerManager::DeleteLayer(int idx){
Ebenen.erase(Ebenen.begin()+idx); Ebenen.erase(Ebenen.begin()+idx);
MetaEbenen.erase(MetaEbenen.begin()+idx);
} }
QLabel* LayerManager::getDisplayable(){ QLabel* LayerManager::getDisplayable(){
//Tranzparenz der Ebenen muss möglich sein //Tranzparenz der Ebenen muss möglich sein
QPixmap Map(maxWidth, maxHeight); QPixmap aMap;
for(size_t i=0; i<static_cast<size_t>(this->getLayerCount()); i++){ for(size_t i=0; i<static_cast<size_t>(this->getLayerCount()); i++){
if(MetaEbenen[i].a==255){ if(MetaEbenen[i].a==255){
Map = Ebenen[i]->getAsPixmap(); aMap = Ebenen[i]->getAsPixmap();
break; break;
} }
} }
this->imgLabel->setPixmap(Map);
this->imgLabel->setPixmap(aMap);
return imgLabel; return imgLabel;
} }

View File

@@ -10,6 +10,7 @@
class LayerManager{ class LayerManager{
private: private:
//Uses to handle the Meta Data of each layer in comparission to 'global' propteries
struct EbenenMetaDaten{ struct EbenenMetaDaten{
unsigned int x; unsigned int x;
unsigned int y; unsigned int y;
@@ -20,23 +21,45 @@ private:
this->a = a; this->a = a;
} }
}; };
//max width of the layer (max(EbenenMetaDaten.x+Layer.width))
int maxWidth; int maxWidth;
//max width of the layer (max(EbenenMetaDaten.y+Layer.height))
int maxHeight; int maxHeight;
// The label where the image is shown
QLabel* imgLabel; QLabel* imgLabel;
//all the possible layers in one container
std::vector<Layer*> Ebenen; std::vector<Layer*> Ebenen;
//all the meta data parallel to Ebenen Container
std::vector<EbenenMetaDaten> MetaEbenen; std::vector<EbenenMetaDaten> MetaEbenen;
public: public:
LayerManager(); LayerManager();
~LayerManager(); ~LayerManager();
//gets the count of layers
int getLayerCount(); int getLayerCount();
//set one layer to a given alpha value
void setLayerVisbility(int idx, int alpha); void setLayerVisbility(int idx, int alpha);
//activates one layer to work on it
void activateLayer(int idx); void activateLayer(int idx);
//changes the active layer one up
void goLayerUp(); void goLayerUp();
//changes the active layer one down
void goLayerDown(); void goLayerDown();
//adds a new layer after (on top of) the given idx (-1 create bottom layer)
void AddLayerAfer(int idx); void AddLayerAfer(int idx);
//delets a layer at the given index
void DeleteLayer(int idx); void DeleteLayer(int idx);
//returns the output ready label
QLabel* getDisplayable(); QLabel* getDisplayable();
}; };

View File

@@ -1,36 +1,44 @@
#include "intelligui.h" #include "intelligui.h"
#include "ui_intelligui.h" #include "ui_intelligui.h"
#include<QDebug> #include "LayerManager.h"
#include<QGridLayout>
#include<QLabel>
#include<QColor>
IntelliGUI::IntelliGUI(QWidget *parent) IntelliGUI::IntelliGUI(QWidget *parent)
: QMainWindow(parent), : QMainWindow(parent),
ui(new Ui::IntelliGUI){ ui(new Ui::IntelliGUI){
ui->setupUi(this); ui->setupUi(this);
//Setting up basic IntelliPhoto structure
this->EbenenManager = new LayerManager();
//Test Layer
this->EbenenManager->AddLayerAfer(0);
this->EbenenManager->activateLayer(0);
//Setting up basic IntelliGui Structure
this->GUI = new QWidget();
this->Layout = new QGridLayout(GUI);
this->setCentralWidget(GUI);
//setup all gui elements down here
this->EinKnopf = new QPushButton("Ein Knopf");
//Merge all gui elements to Layout down here
this->Layout->addWidget(this->EinKnopf, 0,10);
this->Layout->addWidget(this->EbenenManager->getDisplayable(),1,1,10,10);
//this->Layout->addWidget(this->EbenenManager->getDisplayable(),0,0,10,10);
//Layout is set in here
this->setLayout(Layout);
} }
IntelliGUI::~IntelliGUI(){ IntelliGUI::~IntelliGUI(){
delete ui; delete ui;
delete GUI;
delete Layout;
delete EbenenManager;
//delete all Gui elements down here
} }
void IntelliGUI::setColor(double R, double G, double B){
R *= 255;
G *= 255;
B *= 255;
QString color = "rgb(";
color += QString::number(R)+ ",";
color += QString::number(G)+ ",";
color += QString::number(B)+ ")";
this->setStyleSheet("background-color:"+color);
}
void IntelliGUI::setColor(int R, int G, int B){
QString color = "rgb(";
color += QString::number(R)+ ",";
color += QString::number(G)+ ",";
color += QString::number(B)+ ")";
this->setStyleSheet("background-color:"+color);
}

View File

@@ -3,6 +3,8 @@
#include <QMainWindow> #include <QMainWindow>
#include <QPushButton> #include <QPushButton>
#include <LayerManager.h>
#include <QGridLayout>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { class IntelliGUI; } namespace Ui { class IntelliGUI; }
@@ -11,20 +13,25 @@ QT_END_NAMESPACE
class IntelliGUI : public QMainWindow class IntelliGUI : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
//basics for programm logic
LayerManager *EbenenManager;
//basics for GUI build
QWidget *GUI; QWidget *GUI;
QGridLayout *Layout;
//Declare all Gui elements down here
QPushButton *EinKnopf;
private: private:
Ui::IntelliGUI *ui; Ui::IntelliGUI *ui;
QString color="rgb(255,255,255)";
public: public:
//Sets up everything to display first loaded projekt, maybe show load window for a project
IntelliGUI(QWidget *parent = nullptr); IntelliGUI(QWidget *parent = nullptr);
//Delets everything in connection to one project
~IntelliGUI(); ~IntelliGUI();
//COlor Values between 0 and 1
void setColor(double R, double G, double B);
void setColor(int R, int G, int B);
private slots: private slots:
}; };
#endif // INTELLIGUI_H #endif // INTELLIGUI_H

View File

@@ -1,20 +1,17 @@
#include "layer.h" #include "layer.h"
Layer::Layer(const int& width,const int& height){ Layer::Layer(const int& width,const int& height){
this->Canvas = new QImage(width, height, QImage::Format::Format_ARGB32); this->Canvas = new QImage(width, height, QImage::Format_RGB32);
this->width=width;
this->height=height;
} }
Layer::~Layer(){ Layer::~Layer(){
delete this->Canvas; delete this->Canvas;
} }
void Layer::setPixel(const int& w,const int& h,const int& a,const int& r,const int& g,const int& b){ void Layer::setPixel(const int& w,const int& h, const int& r,const int& g,const int& b, const int& a){
QRgba64 clr; this->Canvas->setPixelColor(w,h,QColor(r,g,b,a));
clr.setRed(static_cast<quint16>(r));
clr.setGreen(static_cast<quint16>(g));
clr.setBlue(static_cast<quint16>(b));
clr.setAlpha(static_cast<quint16>(a));
this->Canvas->setPixelColor(w,h,QColor(clr));
} }
void Layer::loadImage(const QString& fileName){ void Layer::loadImage(const QString& fileName){

View File

@@ -6,14 +6,26 @@
class Layer{ class Layer{
private: private:
//pixelmap for the image, used because of performance and api reasons
QImage* Canvas; QImage* Canvas;
//width of the image
int width; int width;
//height of the imahe
int height; int height;
public: public:
//setup everything for the image
Layer(const int& width,const int& height); Layer(const int& width,const int& height);
~Layer(); ~Layer();
void setPixel(const int& w,const int& h,const int& a,const int& r,const int& g,const int& b);
//set one pixel with rgba values
void setPixel(const int& w,const int& h,const int& r,const int& g,const int& b, const int& a);
//load an image to the canvas
void loadImage(const QString& fileName); void loadImage(const QString& fileName);
//return the image as QPixmap
QPixmap getAsPixmap(); QPixmap getAsPixmap();
}; };

View File

@@ -11,16 +11,6 @@ int main(int argc, char *argv[])
{ {
QApplication application(argc, argv); QApplication application(argc, argv);
IntelliGUI* win = new IntelliGUI(); IntelliGUI* win = new IntelliGUI();
QWidget *window = new QWidget(win);
win->setCentralWidget(window);
QGridLayout* Layout = new QGridLayout(window);
QPushButton* Button= new QPushButton("Button");
QImage* Canvas = new QImage(200,200, QImage::Format::Format_ARGB32);
QLabel* imgLabel = new QLabel("");
imgLabel->setPixmap(QPixmap::fromImage(*Canvas));
Layout->addWidget(imgLabel,0,0,10,10);
Layout->addWidget(Button,10,0);
win->show(); win->show();
return application.exec(); return application.exec();
} }