Skip to content
Snippets Groups Projects
Commit a63ae69a authored by passscod's avatar passscod
Browse files

abgabe

parent 5a88d581
No related branches found
No related tags found
No related merge requests found
Showing
with 2207 additions and 0 deletions
InteliPhoto:
compillieren:
cd source/
qmake
make
cp imageviewer ../executable/intelliPhoto
ausführen:
cd executable
./intelliPhoto
Bei Fragen bitte wenden sie sich an Gruppe 3 Softwareengeneering oder direkt an pascal.schroeter@s2017.tu-chemnitz.de
#include "ColorDock.h"
ColorDock::ColorDock(InteractionTool *interaction){
interactionTool = interaction;
colorButtons = std::vector<QToolButton*>(); //TODO vector zu Qvector ändern
for(int i = 0; i <256; i++){
colorVect.append(QColor(255,255,255,255).rgba());
colorButtons.push_back(new QToolButton());
QString str;
str.sprintf("padding:0px;background-color: qlineargradient(stop:0 #%02x%02x%02x);",qRed(colorVect[i]),qGreen(colorVect[i]),qBlue(colorVect[i]));
colorButtons[i]->setStyleSheet(str);
colorButtons[i]->setCheckable(true);
connect(colorButtons[i], SIGNAL(clicked()),this, SLOT(changeColor()));
}
addColor(QColor(255,255,255,255),0);
addColor(QColor(127,127,127,255),1);
addColor(QColor(0,0,0,255),2);
addColor(QColor(0,255,255,255),3);
addColor(QColor(0,127,127,255),4);
addColor(QColor(127,255,255,255),5);
addColor(QColor(127,0,0,255),6);
addColor(QColor(255,127,127,255),7);
addColor(QColor(255,0,0,255),8);
addColor(QColor(255,0,255,255),9);
addColor(QColor(127,0,127,255),10);
addColor(QColor(255,127,255,255),11);
addColor(QColor(0,127,0,255),12);
addColor(QColor(127,255,127,255),13);
addColor(QColor(0,255,0,255),14);
addColor(QColor(255,255,0,255),15);
addColor(QColor(127,127,0,255),16);
addColor(QColor(255,255,127,255),17);
addColor(QColor(0,0,127,255),18);
addColor(QColor(127,127,255,255),19);
addColor(QColor(0,0,255,255),20);
addColor(QColor(255,255,255,0),255);
createColorDock();
emit updateColorVect(colorVect);
}
ColorDock::~ColorDock(){
}
void ColorDock::changeColor(){
for (int i = 0; i < colorButtons.size(); i++) {
if (colorButtons[i]->isChecked()){
QPixmap px(20, 20);
QPainter p(&px);
QBrush *br1 = new QBrush(QColor(100,100,100));
QBrush *br2 = new QBrush(QColor(200,200,200));
p.fillRect(0,0,10,10,*br1);
p.fillRect(10,10,10,10,*br1);
p.fillRect(0,10,10,10,*br2);
p.fillRect(10,0,10,10,*br2);
QString str2;
str2.sprintf("Color %d",i);
colorVect[i]=QColorDialog().getColor(Qt::white,nullptr,str2,QColorDialog::ShowAlphaChannel).rgba();
emit updateColorVect(colorVect);
QString str;
str.sprintf("padding:0px;background-color: qlineargradient(stop:0.5 #%02x%02x%02x);",qRed(colorVect[i]),qGreen(colorVect[i]),qBlue(colorVect[i]));
colorButtons[i]->setStyleSheet(str);
p.end();
px.fill(QColor(0,0,0,0));
p.begin(&px);
br1->setColor(QColor(100,100,100,255-qAlpha(colorVect[i])));
br2->setColor(QColor(200,200,200,255-qAlpha(colorVect[i])));
p.fillRect(0,0,10,10,*br1);
p.fillRect(10,10,10,10,*br1);
p.fillRect(0,10,10,10,*br2);
p.fillRect(10,0,10,10,*br2);
colorButtons[i]->setIcon(px);
colorButtons[i]->setChecked(false);
if (interactionTool->getPicture()->hasLayer()){
interactionTool->getPicture()->getCurrentLayerAsQ()->setColor(i,colorVect[i]);
emit updateLayers();
emit updateVisible();
}
p.end();
}
}
}
void ColorDock::createColorDock(){
colorButtons = std::vector<QToolButton*>();
QPixmap px(20, 20);
QPainter p(&px);
QBrush *br1 = new QBrush(QColor(100,100,100));
QBrush *br2 = new QBrush(QColor(200,200,200));
for(int i = 0; i <256; i++){
colorButtons.push_back(new QToolButton());
colorButtons[i]->setCheckable(true);
QString str;
str.sprintf("padding:0px;background-color: qlineargradient(stop:0 #%02x%02x%02x);",qRed(colorVect[i]),qGreen(colorVect[i]),qBlue(colorVect[i]));
colorButtons[i]->setStyleSheet(str);
p.end();
px.fill(QColor(0,0,0,0));
p.begin(&px);
br1->setColor(QColor(100,100,100,255-qAlpha(colorVect[i])));
br2->setColor(QColor(200,200,200,255-qAlpha(colorVect[i])));
p.fillRect(0,0,10,10,*br1);
p.fillRect(10,10,10,10,*br1);
p.fillRect(0,10,10,10,*br2);
p.fillRect(10,0,10,10,*br2);
colorButtons[i]->setIcon(px);
connect(colorButtons[i], SIGNAL(clicked()),this, SLOT(changeColor()));
}
p.end();
colorDock = new QDockWidget(tr("Colortable"));
colorDock->setAllowedAreas(Qt::BottomDockWidgetArea);
colorLayout = new QGridLayout();
for (int i = 0; i < 64; i++) {
colorLayout->addWidget(colorButtons[4*i],0,i);
colorLayout->addWidget(colorButtons[4*i+1],1,i);
colorLayout->addWidget(colorButtons[4*i+2],2,i);
colorLayout->addWidget(colorButtons[4*i+3],3,i);
}
colors = new QWidget(colorDock);
colors->setLayout(colorLayout);
ColorScrollArea = new QScrollArea();
ColorScrollArea->setWidget(colors);
colorDock->setWidget(ColorScrollArea);
colorDock->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
}
void ColorDock::addColor(QColor col, int pos){
QPixmap px(20, 20);
QPainter p(&px);
QBrush *br1 = new QBrush(QColor(100,100,100));
QBrush *br2 = new QBrush(QColor(200,200,200));
colorVect[pos]=col.rgba();
px.fill(colorVect[pos]);
QString str;
str.sprintf("background-color: qlineargradient(stop:0.5 #%02x%02x%02x);",qRed(colorVect[pos]),qGreen(colorVect[pos]),qBlue(colorVect[pos]));
p.end();
px.fill(QColor(0,0,0,0));
p.begin(&px);
br1->setColor(QColor(100,100,100,255-qAlpha(colorVect[pos])));
br2->setColor(QColor(200,200,200,255-qAlpha(colorVect[pos])));
p.fillRect(0,0,10,10,*br1);
p.fillRect(10,10,10,10,*br1);
p.fillRect(0,10,10,10,*br2);
p.fillRect(10,0,10,10,*br2);
colorButtons[pos]->setIcon(px);
colorButtons[pos]->setStyleSheet(str);
colorButtons[pos]->setChecked(false);
if (interactionTool->getPicture()->hasLayer()){
interactionTool->getPicture()->getCurrentLayerAsQ()->setColor(pos,colorVect[pos]);
emit updateLayers();
emit updateVisible();
}
p.end();
emit updateColorVect(colorVect);
}
void ColorDock::updateColors(){
QPixmap px(20, 20);
QPainter p(&px);
QBrush *br1 = new QBrush(QColor(100,100,100));
QBrush *br2 = new QBrush(QColor(200,200,200));
colorVect = interactionTool->getPicture()->getCurrentLayerAsQ()->colorTable();
for(int i = 0; i <256; i++){
px.fill(colorVect[i]);
QString str;
str.sprintf("padding:0px;background-color: qlineargradient(stop:0 #%02x%02x%02x);",qRed(colorVect[i]),qGreen(colorVect[i]),qBlue(colorVect[i]));
colorButtons[i]->setStyleSheet(str);
p.end();
px.fill(QColor(0,0,0,0));
p.begin(&px);
br1->setColor(QColor(100,100,100,255-qAlpha(colorVect[i])));
br2->setColor(QColor(200,200,200,255-qAlpha(colorVect[i])));
p.fillRect(0,0,10,10,*br1);
p.fillRect(10,10,10,10,*br1);
p.fillRect(0,10,10,10,*br2);
p.fillRect(10,0,10,10,*br2);
colorButtons[i]->setIcon(px);
}
emit updateColorVect(colorVect);
if(interactionTool->getPicture()->isShaped()){
addColor(QColor(255,255,255,0),255);
QPainter p(&px);
QPen pen(QColor(255,0,0,255));
pen.setWidth(2);
p.setPen(pen);
p.drawLine(1,1,19,1);
p.drawLine(19,1,19,19);
p.drawLine(19,19,1,19);
p.drawLine(1,19,1,1);
p.drawLine(1,19,19,1);
p.drawLine(19,19,1,1);
colorButtons[255]->setStyleSheet("background-color: #FFFFFF;\n");
colorButtons[255]->setIcon(px);
colorButtons[255]->setEnabled(false);
} else {
colorButtons[255]->setEnabled(true);
px.fill(QColor(255,255,255,0));
colorButtons[255]->setIcon(px);
}
}
QDockWidget *ColorDock::getDockWidget(){
return colorDock;
}
void ColorDock::setColorVect(QVector<QRgb> colorVect){
this->colorVect=colorVect;
}
QVector<QRgb> ColorDock::getColorVect(){
return colorVect;
}
#ifndef COLORDOCK_H
#define COLORDOCK_H
#include "InteractionTool.h"
#include <QDockWidget>
#include <QScrollArea>
#include <QGridLayout>
#include <QToolButton>
#include <QPainter>
#include <QColorDialog>
/*!
* \class ColorDoc
* \brief Verwaltet den ColorDock und managet somit die Aktuelle Farbtabelle.
*/
class ColorDock : public QObject
{
Q_OBJECT
public:
ColorDock(InteractionTool *interaction);
~ColorDock();
QDockWidget *getDockWidget();
void updateColors();
void setColorVect(QVector<QRgb> colorVect);
QVector<QRgb> getColorVect();
signals:
void updateVisible();
void updateLayers();
void updateColorVect(QVector<QRgb> colorVect);
private slots:
void changeColor();
private:
void createColorDock();
void addColor(QColor col, int pos);
QScrollArea *ColorScrollArea;
QWidget *colors;
QDockWidget *colorDock;
QGridLayout* colorLayout;
std::vector<QToolButton*> colorButtons;
QVector<QRgb> colorVect;
InteractionTool *interactionTool;
};
#endif // COLORDOCK_H
#include "ColorMap.h"
#include <stdlib.h>
int ColorMap::addColor(pixel_t pix){
for(int i = 0; i < 256; i++){
if(pixels[i] != nullptr){
pixels[i] = static_cast<pixel_t*>(malloc(sizeof (pixel_t)));
*(pixels[i]) = pix;
return i;
}
}
return -1;
}
bool ColorMap::removeColor(pixel_t pix){
for(int i = 0; i < 256; i++){
if(*(pixels[i]) == pix){
free(pixels[i]);
return true;
}
}
return false;
}
pixel_t *ColorMap::getColor(unsigned char index){
return pixels[index];
}
int ColorMap::getIndex(pixel_t pix){
for(int i = 0; i < 256; i++){
if(*(pixels[i]) == pix){
return i;
}
}
return -1;
}
ColorMap::ColorMap(bool lock){
for(int i = 0; i < 256; i++){
pixels[i] = nullptr;
}
lockPixel = lock;
}
ColorMap::ColorMap::~ColorMap(){
for(int i = 0; i < 256; i++){
if(pixels[i] != nullptr){
free(pixels[i]);
}
}
}
#include "Pixel.h"
#ifndef COLORMAP_H
#define COLORMAP_H
class ColorMap{
public:
int addColor(pixel_t pix);
bool removeColor(pixel_t pix);
pixel_t* getColor(unsigned char index);
int getIndex(pixel_t pix);
ColorMap(bool lock = false);
~ColorMap();
private:
pixel_t *pixels[256];
bool lockPixel;
};
#endif /* !COLORMAP_H */
#include "DrawDock.h"
DrawDock::DrawDock(InteractionTool *interaction){
colorMenu = new QMenu();
colorButton = new QPushButton();
for(int i = 0; i <256; i++){
colorVect.append(QColor(255,255,255,255).rgba());
QString str,str2;
QPixmap px(20,20);
str.sprintf("padding:0px;background-color: qlineargradient(stop:0 #%02x%02x%02x);",qRed(colorVect[i]),qGreen(colorVect[i]),qBlue(colorVect[i]));
if(i==drawColorIndex){
QPixmap px(40, 20);
px.fill(QColor(0,0,0,0));
QPainter p(&px);
QBrush *br1 = new QBrush(QColor(100,100,100));
QBrush *br2 = new QBrush(QColor(200,200,200));
br1->setColor(QColor(100,100,100,255-qAlpha(colorVect[i])));
br2->setColor(QColor(200,200,200,255-qAlpha(colorVect[i])));
p.fillRect(0,0,10,10,*br1);
p.fillRect(10,10,10,10,*br1);
p.fillRect(0,10,10,10,*br2);
p.fillRect(10,0,10,10,*br2);
p.fillRect(20,0,10,10,*br1);
p.fillRect(30,10,10,10,*br1);
p.fillRect(20,10,10,10,*br2);
p.fillRect(30,0,10,10,*br2);
p.end();
colorButton->setStyleSheet(str);
}
str2.sprintf("Color %d",i);
px.fill(colorVect[i]);
colorMenu->addAction(px,str2,this,&DrawDock::setDrawColor);
}
colorAct = colorMenu->actions();
for (int i = 0; i < 256; i++) {
colorAct[i]->setCheckable(true);
}
colorButton->setMenu(colorMenu);
drawSpinbox = new QSpinBox();
drawSpinbox->setValue(3);
connect(drawSpinbox, QOverload<int>::of(&QSpinBox::valueChanged),this, &DrawDock::setWidth);
drawSlider = new QSlider(Qt::Horizontal);
drawSlider->setRange(1,99);
drawSlider->setValue(3);
connect(drawSlider, QOverload<int>::of(&QSlider::valueChanged),this, &DrawDock::setWidth);
drawStartButton = new QPushButton("Start");
drawStartButton->setCheckable(true);
connect(drawStartButton, SIGNAL(clicked()),this, SLOT(startDraw()));
ignoreShaped = new QCheckBox("Ignore Shape");
interactionTool=interaction;
param=nullptr;
}
DrawDock::~DrawDock(){
}
bool DrawDock::mouseEvent(QMouseEvent *event, eventType_e type, int w1, int w2, int h1, int h2){
switch (type) {
case press:{
if (isDraw&& event->button() == Qt::LeftButton) {
switch (actDrawModus) {
case drawModus_e::pencil:{
drawStart = true;
param = new toolParameters_t;
param->tool = paint;
param->i = drawWidth;
param->ignoreShape = ignoreShaped->isChecked();
param->colorIndex =drawColorIndex;
param->startPoint = event->pos()-QPoint(w1-w2,h1-h2);
break;
}
case drawModus_e::lines:{
drawStart = true;
param = new toolParameters_t;
param->tool = paint;
param->i = drawWidth;
param->ignoreShape = ignoreShaped->isChecked();
param->colorIndex =drawColorIndex;
param->startPoint = event->pos()-QPoint(w1-w2,h1-h2);
break;
}
case drawModus_e::filledRect:{
if (param==nullptr){
param = new toolParameters_t;
param->tool = polygon;
param->ignoreShape = ignoreShaped->isChecked();
param->poly = QPolygon();
polyVis = QPolygon();
}
param->isInverse = false;
param->startPoint = event->pos()-QPoint(w1-w2+interactionTool->getPicture()->currentXOffset(),h1-h2+interactionTool->getPicture()->currentYOffset());
break;
}
case drawModus_e::notFilledRect:{
if (param==nullptr){
param = new toolParameters_t;
param->tool = polygon;
param->ignoreShape = ignoreShaped->isChecked();
param->poly = QPolygon();
polyVis = QPolygon();
}
param->isInverse = true;
param->startPoint = event->pos()-QPoint(w1-w2+interactionTool->getPicture()->currentXOffset(),h1-h2+interactionTool->getPicture()->currentYOffset());
break;
}
default:{
break;
}
}
return true;
}
return false;
}
case movee:{
if (drawStart) {
switch (actDrawModus) {
case drawModus_e::pencil:{
param->endPoint = event->pos()-QPoint(w1-w2,h1-h2);
interactionTool->useTool(param);
param = nullptr;
emit updateLayer();
emit updateVisible();
param = new toolParameters_t;
param->tool = paint;
param->ignoreShape = ignoreShaped->isChecked();
param->i = drawWidth;
param->colorIndex =drawColorIndex;
param->startPoint = event->pos()-QPoint(w1-w2,h1-h2);
break;
}
case drawModus_e::lines:{
emit updateLayer();
emit updateVisible();
para1 p;
p.i=drawColorIndex;
p.p=event->pos()-QPoint(w1-w2,h1-h2);
p.q=param->startPoint;
p.w=drawWidth;
emit drawShowI(p);
break;
}
default:{
break;
}
}
return true;
}
return false;
}
case release:{
if (isDraw && event->button() == Qt::LeftButton) {
switch (actDrawModus) {
case drawModus_e::pencil:{
drawStart = false;
param->endPoint = event->pos()-QPoint(w1-w2,h1-h2);
interactionTool->useTool(param);
param = nullptr;
emit updateLayer();
emit updateVisible();
break;
}
case drawModus_e::lines:{
drawStart = false;
param->endPoint = event->pos()-QPoint(w1-w2,h1-h2);
interactionTool->useTool(param);
param = nullptr;
emit updateLayer();
emit updateVisible();
break;
}
case drawModus_e::filledRect:{
//if () TODO: Start & Endpkt vergleichen
param->poly.push_back(event->pos()-QPoint(w1-w2+interactionTool->getPicture()->currentXOffset(),h1-h2+interactionTool->getPicture()->currentYOffset()));
polyVis.push_back(event->pos()-QPoint(w1-w2,h1-h2));
emit updateLayer();
emit updateVisible();
para2 p;
p.i=drawColorIndex;
p.p=polyVis;
emit drawShowII(p);
break;
}
case drawModus_e::notFilledRect:{
//if () TODO: Start & Endpkt vergleichen
param->poly.push_back(event->pos()-QPoint(w1-w2+interactionTool->getPicture()->currentXOffset(),h1-h2+interactionTool->getPicture()->currentYOffset()));
polyVis.push_back(event->pos()-QPoint(w1-w2,h1-h2));
emit updateLayer();
emit updateVisible();
para2 p;
p.i=drawColorIndex;
p.p=polyVis;
emit drawShowII(p);
break;
}
default:{
break;
}
}
return true;
} else if (isDraw && event->button() == Qt::RightButton){
switch (actDrawModus) {
case drawModus_e::filledRect:{
//if () TODO: Start & Endpkt vergleichen
param->colorIndex=drawColorIndex;
interactionTool->useTool(param);
param = nullptr;
emit updateLayer();
emit updateVisible();
break;
}
case drawModus_e::notFilledRect:{
//if () TODO: Start & Endpkt vergleichen
param->colorIndex=drawColorIndex;
interactionTool->useTool(param);
param = nullptr;
emit updateLayer();
emit updateVisible();
break;
}
default:{
break;
}
}
return true;
}
return false;
}
}
}
void DrawDock::pencil(){
actDrawModus = drawModus_e::pencil;
}
void DrawDock::startDraw(){
if(isDraw){
isDraw = false;
drawStartButton->setText("Start");
param = nullptr;
emit updateLayer();
emit updateVisible();
} else {
isDraw = true;
drawStartButton->setText("Stop");
}
}
void DrawDock::lines(){
actDrawModus = drawModus_e::lines;
}
void DrawDock::notFilledRect(){
actDrawModus = drawModus_e::notFilledRect;
}
void DrawDock::filledRect(){
actDrawModus = drawModus_e::filledRect;
}
void DrawDock::setDrawColor(){
for (int i = 0; i < 256; i++) {
if (colorAct[i]->isChecked()){
colorAct[i]->setChecked(false);
drawColorIndex = i;
QString str;
str.sprintf("padding:0px;background-color: qlineargradient(stop:0 #%02x%02x%02x);",qRed(colorVect[i]),qGreen(colorVect[i]),qBlue(colorVect[i]));
colorButton->setStyleSheet(str);
QPixmap px(40, 20);
px.fill(QColor(0,0,0,0));
QPainter p(&px);
QBrush *br1 = new QBrush(QColor(100,100,100));
QBrush *br2 = new QBrush(QColor(200,200,200));
br1->setColor(QColor(100,100,100,255-qAlpha(colorVect[i])));
br2->setColor(QColor(200,200,200,255-qAlpha(colorVect[i])));
p.fillRect(0,0,10,10,*br1);
p.fillRect(10,10,10,10,*br1);
p.fillRect(0,10,10,10,*br2);
p.fillRect(10,0,10,10,*br2);
p.fillRect(20,0,10,10,*br1);
p.fillRect(30,10,10,10,*br1);
p.fillRect(20,10,10,10,*br2);
p.fillRect(30,0,10,10,*br2);
p.end();
}
}
}
void DrawDock::setWidth(int w){
drawSpinbox->setValue(w);
drawSlider->setValue(w);
drawWidth=w;
}
QDockWidget *DrawDock::createDrawDock(){
drawDock = new QDockWidget(tr("Draw"));
drawDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
QGridLayout *drawLayout = new QGridLayout();
QRadioButton *button1 = new QRadioButton("Pencil");
button1->setChecked(true);
drawLayout->addWidget(button1,0,0,1,2);
connect(button1, SIGNAL(clicked()),this, SLOT(pencil()));
QRadioButton *button2 = new QRadioButton("Lines");
drawLayout->addWidget(button2,1,0,1,2);
connect(button2, SIGNAL(clicked()),this, SLOT(lines()));
QRadioButton *button3 = new QRadioButton("Filled polygon");
drawLayout->addWidget(button3,2,0,1,2);
connect(button3, SIGNAL(clicked()),this, SLOT(filledRect()));
QRadioButton *button4 = new QRadioButton("Inverse polygon");
drawLayout->addWidget(button4,3,0,1,2);
connect(button4, SIGNAL(clicked()),this, SLOT(notFilledRect()));
QLabel *color = new QLabel();
color->setText("Color:");
drawLayout->addWidget(color,4,0);
drawLayout->addWidget(colorButton,4,1);
drawLayout->addWidget(ignoreShaped,5,0,1,2);
QLabel *width = new QLabel();
width->setText("Width:");
drawLayout->addWidget(width,6,0);
drawLayout->addWidget(drawSpinbox,6,1);
QDialog *text = new QDialog();
drawLayout->addWidget(text,8,1,1,2);
drawLayout->addWidget(drawSlider,7,0,1,2);
drawLayout->addWidget(drawStartButton,8,0,1,2);
QWidget *drawControl = new QWidget(drawDock);
drawControl->setLayout(drawLayout);
drawDock->setWidget(drawControl);
return drawDock;
}
void DrawDock::setColorVect(QVector<QRgb> colorVect){
this->colorVect=colorVect;
QPixmap px(20, 20);
for(int i = 0; i <256; i++){
QPainter p(&px);
QBrush br1(QColor(100,100,100));
QBrush br2(QColor(200,200,200));
QBrush br3(QColor(qRed(colorVect[i]),qGreen(colorVect[i]),qBlue(colorVect[i]),qAlpha(colorVect[i])));
p.fillRect(0,0,10,10,br1);
p.fillRect(10,10,10,10,br1);
p.fillRect(0,10,10,10,br2);
p.fillRect(10,0,10,10,br2);
p.fillRect(0,0,20,20,br3);
p.end();
QString str;
str.sprintf("padding:0px;background-color: qlineargradient(stop:0 #%02x%02x%02x);",qRed(colorVect[i]),qGreen(colorVect[i]),qBlue(colorVect[i]));
if(i==drawColorIndex){
QString str;
str.sprintf("padding:0px;background-color: qlineargradient(stop:0 #%02x%02x%02x);",qRed(colorVect[i]),qGreen(colorVect[i]),qBlue(colorVect[i]));
QPixmap px(40, 20);
px.fill(QColor(0,0,0,0));
QPainter p(&px);
QBrush *br1 = new QBrush(QColor(100,100,100));
QBrush *br2 = new QBrush(QColor(200,200,200));
br1->setColor(QColor(100,100,100,255-qAlpha(colorVect[i])));
br2->setColor(QColor(200,200,200,255-qAlpha(colorVect[i])));
p.fillRect(0,0,10,10,*br1);
p.fillRect(10,10,10,10,*br1);
p.fillRect(0,10,10,10,*br2);
p.fillRect(10,0,10,10,*br2);
p.fillRect(20,0,10,10,*br1);
p.fillRect(30,10,10,10,*br1);
p.fillRect(20,10,10,10,*br2);
p.fillRect(30,0,10,10,*br2);
p.end();
colorButton->setStyleSheet(str);
}
colorAct[i]->setIcon(px);
}
if(interactionTool->getPicture()->isShaped()){
px.fill(QColor(255,255,255,0));
QPainter p(&px);
QPen pen(QColor(255,0,0,255));
pen.setWidth(2);
p.setPen(pen);
p.drawLine(1,1,19,1);
p.drawLine(19,1,19,19);
p.drawLine(19,19,1,19);
p.drawLine(1,19,1,1);
p.drawLine(1,19,19,1);
p.drawLine(19,19,1,1);
colorAct[255]->setIcon(px);
} else {
colorAct[255]->setEnabled(true);
px.fill(QColor(255,255,255,0));
colorAct[255]->setIcon(px);
}
colorButton->setMenu(colorMenu);
}
#ifndef DRAWDOCK_H
#define DRAWDOCK_H
#include "InteractionTool.h"
#include <QDockWidget>
#include <QPushButton>
#include <QSlider>
#include <QSpinBox>
#include <QCheckBox>
#include <QMenu>
#include <QGridLayout>
#include <QRadioButton>
#include <QLabel>
#include <QDialog>
#include <QMouseEvent>
#include <QScrollArea>
#include <QPainter>
typedef enum drawModus {pencil, lines, notFilledRect, filledRect} drawModus_e;
typedef enum eventType {press,movee, release} eventType_e;
typedef struct para1{
QPoint p;
QPoint q;
int w;
int i;
} para1;
typedef struct para2{
QPolygon p;
int i;
} para2;
/*!
* \class DrawDock
* \brief Managet das DrawDock und koordiniert das Zeichnen.
*/
class DrawDock : public QObject
{
Q_OBJECT
public:
DrawDock(InteractionTool *interaction);
~DrawDock();
bool mouseEvent(QMouseEvent *event,eventType_e type,int w1,int w2,int h1,int h2);
void setColorVect(QVector<QRgb> colorVect);
QDockWidget *createDrawDock();
signals:
void updateLayer();
void updateVisible();
void drawShowI(para1);
void drawShowII(para2);
private slots:
void pencil();
void startDraw();
void lines();
void notFilledRect();
void filledRect();
void setDrawColor();
void setWidth(int w);
private:
QDockWidget *drawDock;
QList<QAction*> colorAct;
QPushButton *colorButton;
QSlider *drawSlider;
QSpinBox *drawSpinbox;
QPushButton *drawStartButton;
QMenu *colorMenu;
drawModus_e actDrawModus = drawModus_e::pencil;
QCheckBox *ignoreShaped;
QPolygon polyVis;
QVector<QRgb> colorVect;
bool isDraw=false;
int drawWidth=3;
int drawColorIndex=0;
bool drawStart=false;
toolParameters_t *param;
InteractionTool *interactionTool;
};
#endif // DRAWDOCK_H
#include "InteractionTool.h"
bool InteractionTool::useTool(toolParameters_t *param){
return tools->useTool(param);
}
Picture *InteractionTool::getPicture(){
return pic;
}
InteractionTool::InteractionTool(){
pic = new Picture();
tools = new ManipulationTool(pic);
}
#include "Picture.h"
#include "ManipulationTool.h"
#ifndef INTERACTION_TOOL_H
#define INTERACTION_TOOL_H
/*!
* \class InteractionTool
* \brief Koordiniert die Verwendung von Picture und ManipulationTool.
*/
class InteractionTool{
public:
bool useTool(toolParameters_t* param);
Picture* getPicture();
InteractionTool();
private:
Picture *pic;
ManipulationTool *tools;
};
#endif /* !INTERACTION_TOOL_H */
#include "LayerDock.h"
LayerDock::LayerDock(InteractionTool *interaction){
interactionTool = interaction;
createLayerDock();
}
LayerDock::~LayerDock(){
}
void LayerDock::updateLayers(){
for (unsigned int i = 0; i < interactionTool->getPicture()->getLayerCount(); i++) {
QPixmap pic;
pic.convertFromImage(*interactionTool->getPicture()->getLayerAsQ(i));
layerButtons[i*5+1]->setIcon(pic);
layerButtons[i*5+1]->setChecked(false);
}
layerButtons[interactionTool->getPicture()->getCurrentLayerIndex()*5+1]->setChecked(true);
if(interactionTool->getPicture()->getLayerCount()>1){
layerButtons[interactionTool->getPicture()->getCurrentLayerIndex()*5+3]->setEnabled(false);
}
}
void LayerDock::updateLayerCount(){
layerButtons = std::vector<QPushButton*>(); //TODO vector zu Qvector ändern
layerCheckboxes = std::vector<QCheckBox*>();
layerDock = new QDockWidget(tr("Layers"));
layerDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
layerLayout = new QGridLayout();
layerButtons.push_back(new QPushButton("+"));
layerLayout->addWidget(layerButtons[0],0,0,2,2);
layerButtons[0]->setMaximumWidth(25);
layerButtons[0]->setCheckable(true);
connect(layerButtons[0], SIGNAL(clicked()),this, SLOT(changeCurrentLayer()));
for (unsigned int i = 0; i < interactionTool->getPicture()->getLayerCount(); i++) {
layerButtons.push_back(new QPushButton);
QPixmap pic(100,100);
pic.convertFromImage(*interactionTool->getPicture()->getLayerAsQ(i));
layerButtons[i*5+1]->setIconSize(QSize(100,100));
layerButtons[i*5+1]->setIcon(pic);
layerLayout->addWidget(layerButtons[i*5+1],i*5+1,2,5,1);
layerButtons[i*5+1]->setCheckable(true);
connect(layerButtons[i*5+1], SIGNAL(clicked()),this, SLOT(changeCurrentLayer()));
layerButtons.push_back(new QPushButton("^"));
layerLayout->addWidget(layerButtons[i*5+2],i*5+2,0,1,2);
layerButtons[i*5+2]->setMaximumWidth(25);
layerButtons[i*5+2]->setCheckable(true);
if (i==0){
layerButtons[i*5+2]->setEnabled(false);
}
connect(layerButtons[i*5+2], SIGNAL(clicked()),this, SLOT(changeCurrentLayer()));
layerButtons.push_back(new QPushButton("-"));
layerLayout->addWidget(layerButtons[i*5+3],i*5+3,0,1,1);
layerButtons[i*5+3]->setMaximumWidth(25);
layerButtons[i*5+3]->setCheckable(true);
connect(layerButtons[i*5+3], SIGNAL(clicked()),this, SLOT(changeCurrentLayer()));
layerCheckboxes.push_back(new QCheckBox());
layerLayout->addWidget(layerCheckboxes[i],i*5+3,1,1,1);
layerCheckboxes[i]->setChecked(true);
connect(layerCheckboxes[i], SIGNAL(clicked()),this, SLOT(updateVisible()));
layerButtons.push_back(new QPushButton("v"));
layerLayout->addWidget(layerButtons[i*5+4],i*5+4,0,1,2);
layerButtons[i*5+4]->setMaximumWidth(25);
layerButtons[i*5+4]->setCheckable(true);
if (i+1==interactionTool->getPicture()->getLayerCount()){
layerButtons[i*5+4]->setEnabled(false);
}
connect(layerButtons[i*5+4], SIGNAL(clicked()),this, SLOT(changeCurrentLayer()));
layerButtons.push_back(new QPushButton("+"));
layerLayout->addWidget(layerButtons[i*5+5],i*5+5,0,2,2);
layerButtons[i*5+5]->setMaximumWidth(25);
layerButtons[i*5+5]->setCheckable(true);
connect(layerButtons[i*5+5], SIGNAL(clicked()),this, SLOT(changeCurrentLayer()));
}
layerButtons[interactionTool->getPicture()->getCurrentLayerIndex()*5+1]->setChecked(true);
layerButtons[interactionTool->getPicture()->getCurrentLayerIndex()*5+3]->setEnabled(false);
//}
layers = new QWidget(layerDock);
layers->setLayout(layerLayout);
layerScrollArea = new QScrollArea();
layerScrollArea->setWidget(layers);
layerDock->setWidget(layerScrollArea);
emit updateLayerDock();
layerDock->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
}
void LayerDock::changeCurrentLayer(){
if (layerButtons[0]->isChecked()){
emit newLayer();
layerButtons[0]->setChecked(false);
}
for (int i = 0; i < interactionTool->getPicture()->getLayerCount(); i++) {
if (layerButtons[i*5+1]->isChecked()&&i!=interactionTool->getPicture()->getCurrentLayerIndex()){
layerButtons[interactionTool->getPicture()->getCurrentLayerIndex()*5+1]->setChecked(false);
layerButtons[interactionTool->getPicture()->getCurrentLayerIndex()*5+3]->setEnabled(true);
interactionTool->getPicture()->setCurrentLayer(i);
emit update();
layerButtons[interactionTool->getPicture()->getCurrentLayerIndex()*5+3]->setEnabled(false);
} else if(layerButtons[i*5+2]->isChecked()){
interactionTool->getPicture()->moveLayer(i,i-1);
updateLayers();
layerButtons[i*5+2]->setChecked(false);
bool h = layerCheckboxes[i]->isChecked();
layerCheckboxes[i]->setChecked(layerCheckboxes[i-1]->isChecked());
layerCheckboxes[i-1]->setChecked(h);
emit update();
} else if(layerButtons[i*5+3]->isChecked()){
layerButtons[i*5+3]->setChecked(false);
interactionTool->getPicture()->removeLayer(i);
if(interactionTool->getPicture()->getLayerCount()==0){//TODO
}
updateLayerCount();
emit update();
} else if(layerButtons[i*5+4]->isChecked()){
interactionTool->getPicture()->moveLayer(i+1,i);
bool h = layerCheckboxes[i]->isChecked();
layerCheckboxes[i]->setChecked(layerCheckboxes[i+1]->isChecked());
layerCheckboxes[i+1]->setChecked(h);
updateLayers();
layerButtons[i*5+4]->setChecked(false);
emit update();
} else if(layerButtons[i*5+5]->isChecked()&&i+1!=interactionTool->getPicture()->getLayerCount()){
layerButtons[i*5+5]->setChecked(false);
param = new toolParameters_t;
param->tool = merge;
param->layerIndex1 = i;
param->layerIndex2 = i+1;
this->i=i;
emit getParams(param);
} else if(layerButtons[i*5+5]->isChecked()&&i+1==interactionTool->getPicture()->getLayerCount()){
newLayer();
layerButtons[i*5+5]->setChecked(false);
}
}
}
void LayerDock::createLayerDock(){
layerDock = new QDockWidget(tr("Layers"));
layerDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
layerLayout = new QGridLayout();
layerButtons.push_back(new QPushButton("+"));
layerLayout->addWidget(layerButtons[0],0,0,2,1);
layerButtons[0]->setMaximumWidth(25);
layerButtons[0]->setCheckable(true);
connect(layerButtons[0], SIGNAL(clicked()),this, SLOT(changeCurrentLayer()));
layers = new QWidget(layerDock);
layers->setLayout(layerLayout);
layerScrollArea = new QScrollArea();
layerScrollArea->setWidget(layers);
layerDock->setWidget(layerScrollArea);
layerDock->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
}
QDockWidget *LayerDock::getDockWidget(){
return layerDock;
}
bool LayerDock::isLayerCheckboxChecked(int i){
return layerCheckboxes[i]->isChecked();
}
void LayerDock::doMergeII(toolParameters_t *param){
interactionTool->useTool(param);
interactionTool->getPicture()->removeLayer(i+1);
interactionTool->getPicture()->removeLayer(i);
param = nullptr;
updateLayerCount();
emit update();
}
void LayerDock::updateVisible(){
emit update();
}
#ifndef LAYERDOCK_H
#define LAYERDOCK_H
#include "InteractionTool.h"
#include <QDockWidget>
#include <QScrollArea>
#include <QGridLayout>
#include <QPushButton>
#include <QCheckBox>
/*!
* \brief LayerDock
* \brief Verwaltet den LayerDock und die sichtbarkeit der einzelnen Layer. Kann das mergen, tauschen und Löschen von Layern initiieren.
*/
class LayerDock : public QObject
{
Q_OBJECT
public:
LayerDock(InteractionTool *interaction);
~LayerDock();
void updateLayers();
void updateLayerCount();
QDockWidget *getDockWidget();
bool isLayerCheckboxChecked(int i);
void doMergeII(toolParameters_t *param);
signals:
void updateLayerDock();
void newLayer();
void update();
void getParams(toolParameters_t *param);
private slots:
void changeCurrentLayer();
void updateVisible();
private:
void createLayerDock();
QScrollArea *layerScrollArea;
QWidget *layers;
QDockWidget *layerDock;
QGridLayout* layerLayout;
std::vector<QPushButton*> layerButtons;
std::vector<QCheckBox*> layerCheckboxes;
toolParameters_t *param;
InteractionTool *interactionTool;
int i;
};
#endif // LAYERDOCK_H
#include "ManipulationTool.h"
#include "tools/newLayer.h"
#include "tools/drawTool.h"
#include "tools/translationTool.h"
#include "tools/merge.h"
#include "tools/polygon.h"
#include "tools/movetool.h"
#include <stdlib.h>
bool ManipulationTool::useTool(toolParameters_t *param){
switch (param->tool) {
case newLayer:{
NewLayer *tool = new NewLayer(pic);
tool->initTool(param);
tool->useTool();
delete tool;
return true;
}
case paint:{
DrawTool *tool = new DrawTool(pic);
tool->initTool(param);
tool->useTool();
delete tool;
return true;
}
case translationTool:{
TranslationTool *tool = new TranslationTool(pic);
tool->initTool(param);
tool->useTool();
delete tool;
return true;
}
case merge:{
MergeTool *tool = new MergeTool(pic);
tool->initTool(param);
tool->useTool();
delete tool;
return true;
}
case polygon:{
PolygonTool *tool = new PolygonTool(pic);
tool->initTool(param);
tool->useTool();
delete tool;
return true;
}
case tools_e::move:{
MoveTool *tool = new MoveTool(pic);
tool->initTool(param);
tool->useTool();
delete tool;
return true;
}
default:{
return false;
}
}
}
ManipulationTool::ManipulationTool(Picture *pic){
this->pic = pic;
}
ManipulationTool::~ManipulationTool(){
}
#include "Tool.h"
#ifndef MANIPULATION_TOOL_H
#define MANIPULATION_TOOL_H
/*!
* \class ManipulationTool
* \brief Koordiniert die Verwendung von Tools.
*/
class ManipulationTool{
public:
bool useTool(toolParameters_t *param);
ManipulationTool(Picture *pic);
~ManipulationTool();
private:
Picture *pic;
};
#endif /* !MANIPULATION_TOOL_H */
This diff is collapsed.
#ifndef NEWLAYERDOCK_H
#define NEWLAYERDOCK_H
#include "InteractionTool.h"
#include <QGridLayout>
#include <QRadioButton>
#include <QPushButton>
#include <QSpinBox>
#include <QSlider>
#include <QDockWidget>
#include <QAction>
#include <QLabel>
#include <QButtonGroup>
#include <QColorDialog>
#include <QMenu>
#include <QPainter>
/*!
* \class NewLayerDock
* \brief Managet das NewLayerDock und koordiniert das anlegen neuer Layer. Hier werden auch die Farbtabellen für neue Layer (auch beim öffnen neuer Bilder).
*/
class NewLayerDock : public QObject
{
Q_OBJECT
public:
NewLayerDock(InteractionTool *interaction);
~NewLayerDock();
void setColorVect(QVector<QRgb> colorVect);
QDockWidget *createNewLayerDock();
signals:
void updateHasLayer(bool b);
void update();
void setNewColorVect(QVector<QRgb> colorVect);
private slots:
void existingColor();
void newColor();
void actualColorVect();
void standartColorVect();
void smallColorVect();
void customColorVect();
void addNewLayer();
void setNewColor();
void setNewLayerX(int w);
void setNewLayerY(int w);
void setNewLayerColor();
private:
toolParameters_t *param;
QDockWidget *dockWidget;
int drawColorIndex=0;
QVector<QRgb> newColorVect;
QList<QAction*> colorAct;
QPushButton *colorButton;
QSlider *newLayerXSlider;
QSpinBox *newLayerXSpinbox;
QSlider *newLayerYSlider;
QSpinBox *newLayerYSpinbox;
QMenu *colorMenu;
QPushButton *newColorButton;
QRgb newLayerColor;
QRadioButton *newColormap[4];
QGridLayout *newLayerLayout;
QVector<QRgb> colorVect;
bool isNewLayerColor = false;
bool actualColor = true;
int newLayerX = 100;
int newLayerY = 100;
InteractionTool *interactionTool;
};
#endif // NEWLAYERDOCK_H
#include "Picture.h"
#include <string>
#include <vector>
#include <stdlib.h>
void Picture::addLayer(layer_t *layer){
layers.push_back(layer);
if(maxX<layer->qImage->size().width()+layer->xOffset){
maxX=layer->qImage->size().width()+layer->xOffset;
}
if(maxY<layer->qImage->size().height()+layer->yOffset){
maxY=layer->qImage->size().height()+layer->yOffset;
}
if(minX>layer->xOffset||minX==-1){
minX=layer->xOffset;
}
if(minY>layer->yOffset||minY==-1){
minY=layer->yOffset;
}
return;
}
void Picture::addLayer(QImage *qImage){
layer_t *layer = new layer_t;
layer->qImage = qImage;
layer->isShaped = false;
layer->isVisible = true;
layer->xOffset = 0;
layer->yOffset = 0;
if(maxX<qImage->size().width()){
maxX=qImage->size().width();
}
if(maxY<qImage->size().height()){
maxY=qImage->size().height();
}
minX=0;
minY=0;
addLayer(layer);
return;
}
void Picture::addLayer(int width, int height){
layer_t *layer = new layer_t;
layer->qImage = new QImage(width,height, QImage::Format_Indexed8);
layer->isShaped =false;
layer->isVisible = true;
layer->xOffset = 0;
layer->yOffset = 0;
if(maxX<width){
maxX=width;
}
if(maxY<height){
maxY=height;
}
minX=0;
minY=0;
addLayer(layer);
return;
}
void Picture::removeLayer(unsigned int index){
if (layers[index]==currentLayer){
currentLayer=nullptr;
}
layers.erase(layers.begin()+index);
maxX=0;
maxY=0;
minX=-1;
minY=-1;
for (int i = 0; i < layers.size(); i++){
if(maxX<layers[i]->qImage->size().width()+layers[i]->xOffset){
maxX=layers[i]->qImage->size().width()+layers[i]->xOffset;
}
if(maxY<layers[i]->qImage->size().height()+layers[i]->yOffset){
maxY=layers[i]->qImage->size().height()+layers[i]->yOffset;
}
if(minX>layers[i]->xOffset||minX==-1){
minX=layers[i]->xOffset;
}
if(minY>layers[i]->yOffset||minY==-1){
minY=layers[i]->yOffset;
}
}
return;
}
QImage* Picture::getLayerAsQ(unsigned int index){
if (currentLayer==nullptr){
return nullptr;
}
return layers[index]->qImage;
}
void Picture::moveLayer(int i, int j){
layer_t *layer = layers[i];
layers[i] = layers[j];
layers[j] = layer;
}
QImage* Picture::getCurrentLayerAsQ(){
if (currentLayer==nullptr){
return nullptr;
}
return currentLayer->qImage;
}
layer_t* Picture::getLayer(unsigned int index){
return layers[index];
}
layer_t* Picture::getCurrentLayer(){
if (currentLayer==nullptr){
return nullptr;
}
return currentLayer;
}
void Picture::setCurrentLayer(unsigned int index){
currentLayer = getLayer(index);
currentLayer->isVisible=true;
return;
}
void Picture::addCurrentLayer(layer_t *layer){
addLayer(layer);
setCurrentLayer(layers.size()-1);
return;
}
void Picture::addCurrentLayer(QImage *layer){
addLayer(layer);
setCurrentLayer(layers.size()-1);
return;
}
unsigned int Picture::getLayerCount(){
return static_cast<unsigned int>(layers.size());
}
unsigned int Picture::getCurrentLayerIndex(){
unsigned int i;
for (i = 0; i < layers.size(); i++){
if (layers[i]==currentLayer){
return i;
}
}
return 0;
}
void Picture::makeShaped(unsigned int index){
layers[index]->isShaped=true;
return;
}
void Picture::makeCurrentLayerShaped(){
currentLayer->isShaped = true;
return;
}
bool Picture::isShaped(unsigned int index){
return layers[index]->isShaped;
}
bool Picture::isShaped(){
if (currentLayer==nullptr){
return false;
}
return currentLayer->isShaped;
}
void Picture::makeVisible(unsigned int index, bool visible){
layers[index]->isVisible=visible;
return;
}
bool Picture::isVisible(unsigned int index){
return layers[index]->isVisible;
}
QSize Picture::getMaxSize(){
return QSize(maxX,maxY);
}
QSize Picture::getMinOffset(){
return QSize(minX,minY);
}
int Picture::currentXOffset(){
return currentLayer->xOffset;
}
int Picture::currentYOffset(){
return currentLayer->yOffset;
}
int Picture::xOffset(unsigned int index){
return layers[index]->xOffset;
}
int Picture::yOffset(unsigned int index){
return layers[index]->yOffset;
}
void Picture::setCurrentXOffset(int offset){
currentLayer->xOffset+=offset;
maxX=0;
minX=-1;
for (int i = 0; i < layers.size(); i++){
if(maxX<layers[i]->qImage->size().width()+layers[i]->xOffset){
maxX=layers[i]->qImage->size().width()+layers[i]->xOffset;
}
if(minX>layers[i]->xOffset||minX==-1){
minX=layers[i]->xOffset;
}
}
return;
}
void Picture::setCurrentYOffset(int offset){
currentLayer->yOffset+=offset;
maxY=0;
minY=-1;
for (int i = 0; i < layers.size(); i++){
if(maxY<layers[i]->qImage->size().height()+layers[i]->yOffset){
maxY=layers[i]->qImage->size().height()+layers[i]->yOffset;
}
if(minY>layers[i]->yOffset||minY==-1){
minY=layers[i]->yOffset;
}
}
return;
}
void Picture::setXOffset(unsigned int index, int offset){
layers[index]->xOffset+=offset;
maxX=0;
minX=-1;
for (int i = 0; i < layers.size(); i++){
if(maxX<layers[i]->qImage->size().width()+layers[i]->xOffset){
maxX=layers[i]->qImage->size().width()+layers[i]->xOffset;
}
if(minX>layers[i]->xOffset||minX==-1){
minX=layers[i]->xOffset;
}
}
return;
}
void Picture::setYOffset(unsigned int index, int offset){
layers[index]->yOffset+=offset;
maxY=0;
minY=-1;
for (int i = 0; i < layers.size(); i++){
if(maxY<layers[i]->qImage->size().height()+layers[i]->yOffset){
maxY=layers[i]->qImage->size().height()+layers[i]->yOffset;
}
if(minY>layers[i]->yOffset||minY==-1){
minY=layers[i]->yOffset;
}
}
return;
}
bool Picture::hasLayer(){
return (layers.size()!=0);
}
Picture::Picture(std::string name){
this->name = name;
currentLayer = nullptr;
layers = std::vector<layer_t*>();
maxX=0;
maxY=0;
minX=-1;
minY=-1;
}
Picture::~Picture(){
for (unsigned int i = 0; i < layers.size(); i++){
delete layers[i];
}
}
#include <QImage>
#include <string>
#include <vector>
#ifndef PICTURE_H
#define PICTURE_H
typedef struct layer_t {
QImage *qImage;
bool isShaped;
bool isVisible;
int xOffset;
int yOffset;
} layer_t;
/*!
* \class Picture
* \brief Koordiniert dei Layer eines Bildes, deren Größe, deren Offset, deren Sichtbarkeit. Kann Layer hinzufügen, löschen und tauschen. Kann sich einen Layer als aktiven Merken.
*/
class Picture{
public:
void addLayer(QImage* qImage);
void addLayer(layer_t* layer);
void addLayer(int width, int height);
void removeLayer(unsigned int index);
QImage* getLayerAsQ(unsigned int index);
QImage* getCurrentLayerAsQ();
layer_t* getLayer(unsigned int index);
layer_t* getCurrentLayer();
void addCurrentLayer(QImage *qImage);
void addCurrentLayer(layer_t *layer);
void setCurrentLayer(unsigned int index);
void makeShaped(unsigned int index);
void makeCurrentLayerShaped();
bool isShaped(unsigned int index);
bool isShaped();
void makeVisible(unsigned int index, bool visible);
bool isVisible(unsigned int index);
QSize getMaxSize();
QSize getMinOffset();
unsigned int getLayerCount();
unsigned int getCurrentLayerIndex();
int currentXOffset();
int currentYOffset();
int xOffset(unsigned int index);
int yOffset(unsigned int index);
void setCurrentXOffset(int offset);
void setCurrentYOffset(int offset);
void setXOffset(unsigned int index, int offset);
void setYOffset(unsigned int index, int offset);
void moveLayer(int i,int j);
bool hasLayer();
Picture(std::string name = "Unbenannt");
~Picture();
private:
std::string name;
std::vector<layer_t*> layers;
layer_t *currentLayer;
int maxX;
int maxY;
int minX;
int minY;
};
#endif /* !PICTURE_H */
#ifndef PIXEL_H
#define PIXEL_H
typedef struct pixel_t{
float r;
float g;
float b;
float a;
bool operator==(pixel_t other){
if( r == other.r &&
g == other.g &&
b == other.b &&
a == other.a){
return true;
}
return false;
}
}pixel_t;
#define DEFAULTCOLOR {0.0f,0.0f,0.0f,1.0f}
#endif /* !PIXEL_H */
#include "RasterImage.h"
#include <stdlib.h>
bool RasterImage::changePixel(size_t x, size_t y, pixel_t pix){
if (x > width || y > height){
return false;
}
int index;
if((index = colormap.getIndex(pix)) == -1){
if((index = colormap.getIndex(pix)) == -1){
return false;
}
}
pixels[y][x] = static_cast<unsigned char>(index);
return true;
}
pixel_t* RasterImage::getPixel(size_t x, size_t y){
return colormap.getColor(pixels[y][x]);
}
size_t RasterImage::getWidth(){
return width;
}
size_t RasterImage::getHeight(){
return height;
}
RasterImage::RasterImage(size_t width, size_t height, pixel_t background){
this->width = width;
this->height = height;
pixels = static_cast<unsigned char**>(malloc(height * sizeof(unsigned char*)));
for(size_t i = 0; i < height; i++){
pixels[i] = static_cast<unsigned char*>(calloc(width,sizeof(unsigned char)));
}
colormap = ColorMap();
colormap.addColor(background);
}
RasterImage::RasterImage::~RasterImage(){
for(size_t i = 0; i < height; i++){
free(pixels[i]);
}
free(pixels);
}
#include "ColorMap.h"
#include <stdlib.h>
#ifndef RASTER_IMAGE_H
#define RASTER_IMAGE_H
class RasterImage{
public:
bool changePixel(size_t x, size_t y, pixel_t pix);
pixel_t* getPixel(size_t x, size_t y);
size_t getWidth();
size_t getHeight();
RasterImage(size_t width, size_t height, pixel_t background = DEFAULTCOLOR);
~RasterImage();
private:
size_t width;
size_t height;
unsigned char** pixels;
ColorMap colormap;
};
#endif /* !RASTER_IMAGE_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment