[TASK] Restructure and comment the source.
This commit is contained in:
parent
9a7dce82b1
commit
d8aa33b45d
|
@ -40,6 +40,10 @@
|
||||||
|
|
||||||
#include "imageviewer-qt4.h"
|
#include "imageviewer-qt4.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @brief ImageViewer::ImageViewer
|
||||||
|
*/
|
||||||
ImageViewer::ImageViewer() {
|
ImageViewer::ImageViewer() {
|
||||||
image=NULL;
|
image=NULL;
|
||||||
startLogging();
|
startLogging();
|
||||||
|
@ -51,6 +55,10 @@ ImageViewer::ImageViewer() {
|
||||||
resize(1600, 600);
|
resize(1600, 600);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws a simple, black line.
|
||||||
|
* @brief ImageViewer::drawBlackLine
|
||||||
|
*/
|
||||||
void ImageViewer::drawBlackLine() {
|
void ImageViewer::drawBlackLine() {
|
||||||
if(image!=NULL) {
|
if(image!=NULL) {
|
||||||
for(int i=0;i<std::min(image->width(),image->height());i++) {
|
for(int i=0;i<std::min(image->width(),image->height());i++) {
|
||||||
|
@ -62,6 +70,10 @@ void ImageViewer::drawBlackLine() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws a diagonal cross from edge to edge.
|
||||||
|
* @brief ImageViewer::drawDiagonalCross
|
||||||
|
*/
|
||||||
void ImageViewer::drawDiagonalCross() {
|
void ImageViewer::drawDiagonalCross() {
|
||||||
if(image!=NULL) {
|
if(image!=NULL) {
|
||||||
int color = QColor::fromHsl(120,255,125).rgba();
|
int color = QColor::fromHsl(120,255,125).rgba();
|
||||||
|
@ -69,18 +81,29 @@ void ImageViewer::drawDiagonalCross() {
|
||||||
int height = image->height();
|
int height = image->height();
|
||||||
for(int y=0; y<image->height(); y++) {
|
for(int y=0; y<image->height(); y++) {
|
||||||
image->setPixel((1.0*y/height)*width,y,color);
|
image->setPixel((1.0*y/height)*width,y,color);
|
||||||
|
image->setPixel((1.0-(1.0*y/height))*width,y,color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateImageDisplay();
|
updateImageDisplay();
|
||||||
logFile << "Let's try a diagonal cross now." << std::endl;
|
logFile << "Diagonal edge-to-edge cross drawn." << std::endl;
|
||||||
renewLogging();
|
renewLogging();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Proxy-Method to actual algorithm
|
/**
|
||||||
|
* Proxy method to actual method due to signal param issues.
|
||||||
|
* @brief ImageViewer::drawRainbowCross
|
||||||
|
*/
|
||||||
void ImageViewer::drawRainbowCross() {
|
void ImageViewer::drawRainbowCross() {
|
||||||
drawRainbowCross(0);
|
drawRainbowCross(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws a diagonal cross with variable width and
|
||||||
|
* varying color.
|
||||||
|
* Fetches the width from the slider.
|
||||||
|
* @brief ImageViewer::drawRainbowCross
|
||||||
|
* @param initialHue
|
||||||
|
*/
|
||||||
void ImageViewer::drawRainbowCross(int initialHue=0) {
|
void ImageViewer::drawRainbowCross(int initialHue=0) {
|
||||||
if(image!=NULL) {
|
if(image!=NULL) {
|
||||||
int h = initialHue;
|
int h = initialHue;
|
||||||
|
@ -102,6 +125,11 @@ void ImageViewer::drawRainbowCross(int initialHue=0) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repeatedly draw the rainbow cross forever.
|
||||||
|
* You will need to kill the process manually after triggering this.
|
||||||
|
* @brief ImageViewer::acidTrippin
|
||||||
|
*/
|
||||||
void ImageViewer::acidTrippin() {
|
void ImageViewer::acidTrippin() {
|
||||||
logFile << "There is no stop button yet. Kill the process or keep it." << std::endl;
|
logFile << "There is no stop button yet. Kill the process or keep it." << std::endl;
|
||||||
renewLogging();
|
renewLogging();
|
||||||
|
@ -114,75 +142,73 @@ void ImageViewer::acidTrippin() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
*
|
*
|
||||||
* Mit dieser Methode können sie sich pro Aufgabe ein Tab anlegen, in der die Ein-
|
* GUI elements related to the tasks are set up here.
|
||||||
* stellungen per Slider, Button, Checkbox etc. gemacht werden und die zu implemen-
|
|
||||||
* tierenden Algorithmen gestattet werden.
|
|
||||||
*
|
*
|
||||||
*****************************************************************************************/
|
*****************************************************************************************/
|
||||||
|
|
||||||
void ImageViewer::generateControlPanels() {
|
void ImageViewer::generateControlPanels() {
|
||||||
// first tab
|
// Tab for first task
|
||||||
m_option_panel1 = new QWidget();
|
task_tab_widget1 = new QWidget();
|
||||||
m_option_layout1 = new QVBoxLayout();
|
task_tab1 = new QVBoxLayout();
|
||||||
m_option_panel1->setLayout(m_option_layout1);
|
task_tab_widget1->setLayout(task_tab1);
|
||||||
|
|
||||||
button1 = new QPushButton();
|
button1 = new QPushButton();
|
||||||
button1->setText("Draw a black line");
|
button1->setText("Draw a black line");
|
||||||
|
QObject::connect(button1, SIGNAL(clicked()), this, SLOT (drawBlackLine()));
|
||||||
|
|
||||||
button2 = new QPushButton();
|
button2 = new QPushButton();
|
||||||
button2->setText("Draw a rainbow cross");
|
button2->setText("Draw a rainbow cross");
|
||||||
|
QObject::connect(button2, SIGNAL(clicked()), this, SLOT (drawRainbowCross()));
|
||||||
|
|
||||||
button3 = new QPushButton();
|
button3 = new QPushButton();
|
||||||
button3->setText("Start the neverending acid trip!");
|
button3->setText("Start the neverending acid trip!");
|
||||||
|
QObject::connect(button3, SIGNAL(clicked()), this, SLOT (acidTrippin()));
|
||||||
|
|
||||||
button4 = new QPushButton();
|
button4 = new QPushButton();
|
||||||
button4->setText("Draw a diagonal cross");
|
button4->setText("Draw a diagonal cross");
|
||||||
|
QObject::connect(button4, SIGNAL(clicked()), this, SLOT (drawDiagonalCross()));
|
||||||
|
|
||||||
lineSlider = new QSlider(Qt::Horizontal);
|
lineSlider = new QSlider(Qt::Horizontal);
|
||||||
lineSlider->setMinimum(1);
|
lineSlider->setMinimum(1);
|
||||||
lineSlider->setMaximum(150);
|
lineSlider->setMaximum(150);
|
||||||
lineSlider->setValue(3);
|
lineSlider->setValue(3);
|
||||||
|
//QObject::connect(lineSlider, SIGNAL(valueChanged(int)), this, SLOT (drawRainbowCross()));
|
||||||
|
|
||||||
QObject::connect(button1, SIGNAL (clicked()), this, SLOT (drawBlackLine()));
|
task_tab1->addWidget(new QLabel("Let's draw something!"));
|
||||||
QObject::connect(button2, SIGNAL (clicked()), this, SLOT (drawRainbowCross()));
|
task_tab1->addWidget(button1);
|
||||||
QObject::connect(button3, SIGNAL (clicked()), this, SLOT (acidTrippin()));
|
task_tab1->addWidget(button2);
|
||||||
QObject::connect(button4, SIGNAL (clicked()), this, SLOT (drawDiagonalCross()));
|
task_tab1->addWidget(button3);
|
||||||
//QObject::connect(lineSlider, SIGNAL (valueChanged(int)), this, SLOT (drawRainbowCross()));
|
task_tab1->addWidget(button4);
|
||||||
|
task_tab1->addWidget(new QLabel("This will not stop unless process is killed."));
|
||||||
|
task_tab1->addWidget(lineSlider);
|
||||||
|
task_tab1->addWidget(new QLabel("Sets the width of the cross."));
|
||||||
|
|
||||||
m_option_layout1->addWidget(new QLabel("Let's draw something!"));
|
tabWidget->addTab(task_tab_widget1,"Task #1");
|
||||||
m_option_layout1->addWidget(button1);
|
|
||||||
m_option_layout1->addWidget(button2);
|
|
||||||
m_option_layout1->addWidget(button3);
|
|
||||||
m_option_layout1->addWidget(button4);
|
|
||||||
m_option_layout1->addWidget(new QLabel("This will not stop unless process is killed."));
|
|
||||||
m_option_layout1->addWidget(lineSlider);
|
|
||||||
m_option_layout1->addWidget(new QLabel("Sets the width of the cross."));
|
|
||||||
|
|
||||||
tabWidget->addTab(m_option_panel1,"Task #1");
|
|
||||||
|
|
||||||
// another tab
|
//Tab for second task
|
||||||
m_option_panel2 = new QWidget();
|
task_tab_widget2 = new QWidget();
|
||||||
m_option_layout2 = new QVBoxLayout();
|
task_tab2 = new QVBoxLayout();
|
||||||
m_option_panel2->setLayout(m_option_layout2);
|
task_tab_widget2->setLayout(task_tab2);
|
||||||
|
|
||||||
spinbox1 = new QSpinBox(tabWidget);
|
spinbox1 = new QSpinBox(tabWidget);
|
||||||
|
|
||||||
m_option_layout2->addWidget(new QLabel("Here we put some more controls later."));
|
task_tab2->addWidget(new QLabel("Here we put some more controls later."));
|
||||||
m_option_layout2->addWidget(spinbox1);
|
task_tab2->addWidget(spinbox1);
|
||||||
|
|
||||||
tabWidget->addTab(m_option_panel2,"Task #2");
|
tabWidget->addTab(task_tab_widget2,"Task #2");
|
||||||
tabWidget->show();
|
//tabWidget->show();
|
||||||
|
|
||||||
// Hinweis: Es bietet sich an pro Aufgabe jeweils einen solchen Tab zu erstellen
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
*
|
*
|
||||||
* Ab hier kommen technische Details, die nicht notwenig für das Verständnis und die
|
* The following methods are about the generic image viewer application and do not contain
|
||||||
* Bearbeitung sind.
|
* any special graphics logic.
|
||||||
*
|
|
||||||
*
|
*
|
||||||
*****************************************************************************************/
|
*****************************************************************************************/
|
||||||
|
|
||||||
|
|
|
@ -66,27 +66,27 @@ class ImageViewer : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Beispiel für GUI Elemente
|
// First task tab
|
||||||
QWidget* m_option_panel1;
|
QWidget* task_tab_widget1;
|
||||||
QVBoxLayout* m_option_layout1;
|
QVBoxLayout* task_tab1;
|
||||||
|
|
||||||
QWidget* m_option_panel2;
|
|
||||||
QVBoxLayout* m_option_layout2;
|
|
||||||
|
|
||||||
QPushButton* button1;
|
QPushButton* button1;
|
||||||
QPushButton* button2;
|
QPushButton* button2;
|
||||||
QPushButton* button3;
|
QPushButton* button3;
|
||||||
QPushButton* button4;
|
QPushButton* button4;
|
||||||
QSpinBox* spinbox1;
|
|
||||||
|
|
||||||
// hier können weitere GUI Objekte hin wie Buttons Slider etc.
|
|
||||||
QSlider* lineSlider;
|
QSlider* lineSlider;
|
||||||
|
|
||||||
private slots:
|
// Second task tab
|
||||||
// Beispiel für einen Algorithmus
|
QWidget* task_tab_widget2;
|
||||||
void drawBlackLine();
|
QVBoxLayout* task_tab2;
|
||||||
|
|
||||||
// hier können weitere als SLOTS definierte Funktionen hin, die auf Knopfdruck etc. aufgerufen werden.
|
QSpinBox* spinbox1;
|
||||||
|
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
// Custom slots
|
||||||
|
void drawBlackLine();
|
||||||
void drawRainbowCross();
|
void drawRainbowCross();
|
||||||
void drawDiagonalCross();
|
void drawDiagonalCross();
|
||||||
void acidTrippin();
|
void acidTrippin();
|
||||||
|
@ -108,15 +108,12 @@ class ImageViewer : public QMainWindow {
|
||||||
void resizeEvent(QResizeEvent * event);
|
void resizeEvent(QResizeEvent * event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Custom methods
|
||||||
void drawRainbowCross(int h);
|
void drawRainbowCross(int h);
|
||||||
// in diesen Beiden Methoden sind Änderungen nötig bzw. sie dienen als
|
|
||||||
// Vorlage für eigene Methoden.
|
|
||||||
void generateControlPanels();
|
|
||||||
|
|
||||||
// Ab hier technische Details die nicht für das Verständnis notwendig sind.
|
void generateControlPanels();
|
||||||
void startLogging();
|
void startLogging();
|
||||||
void generateMainGui();
|
void generateMainGui();
|
||||||
|
|
||||||
void createActions();
|
void createActions();
|
||||||
void createMenus();
|
void createMenus();
|
||||||
void updateActions();
|
void updateActions();
|
||||||
|
|
Loading…
Reference in New Issue