[TASK] Restructure and comment the source.

This commit is contained in:
Jan Philipp Timme 2015-10-23 11:33:30 +02:00
parent 9a7dce82b1
commit d8aa33b45d
2 changed files with 78 additions and 55 deletions

View File

@ -40,6 +40,10 @@
#include "imageviewer-qt4.h"
/**
* Constructor
* @brief ImageViewer::ImageViewer
*/
ImageViewer::ImageViewer() {
image=NULL;
startLogging();
@ -51,6 +55,10 @@ ImageViewer::ImageViewer() {
resize(1600, 600);
}
/**
* Draws a simple, black line.
* @brief ImageViewer::drawBlackLine
*/
void ImageViewer::drawBlackLine() {
if(image!=NULL) {
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() {
if(image!=NULL) {
int color = QColor::fromHsl(120,255,125).rgba();
@ -69,18 +81,29 @@ void ImageViewer::drawDiagonalCross() {
int height = image->height();
for(int y=0; y<image->height(); y++) {
image->setPixel((1.0*y/height)*width,y,color);
image->setPixel((1.0-(1.0*y/height))*width,y,color);
}
}
updateImageDisplay();
logFile << "Let's try a diagonal cross now." << std::endl;
logFile << "Diagonal edge-to-edge cross drawn." << std::endl;
renewLogging();
}
//Proxy-Method to actual algorithm
/**
* Proxy method to actual method due to signal param issues.
* @brief ImageViewer::drawRainbowCross
*/
void ImageViewer::drawRainbowCross() {
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) {
if(image!=NULL) {
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() {
logFile << "There is no stop button yet. Kill the process or keep it." << std::endl;
renewLogging();
@ -114,75 +142,73 @@ void ImageViewer::acidTrippin() {
}
}
/****************************************************************************************
*
* Mit dieser Methode können sie sich pro Aufgabe ein Tab anlegen, in der die Ein-
* stellungen per Slider, Button, Checkbox etc. gemacht werden und die zu implemen-
* tierenden Algorithmen gestattet werden.
* GUI elements related to the tasks are set up here.
*
*****************************************************************************************/
void ImageViewer::generateControlPanels() {
// first tab
m_option_panel1 = new QWidget();
m_option_layout1 = new QVBoxLayout();
m_option_panel1->setLayout(m_option_layout1);
// Tab for first task
task_tab_widget1 = new QWidget();
task_tab1 = new QVBoxLayout();
task_tab_widget1->setLayout(task_tab1);
button1 = new QPushButton();
button1->setText("Draw a black line");
QObject::connect(button1, SIGNAL(clicked()), this, SLOT (drawBlackLine()));
button2 = new QPushButton();
button2->setText("Draw a rainbow cross");
QObject::connect(button2, SIGNAL(clicked()), this, SLOT (drawRainbowCross()));
button3 = new QPushButton();
button3->setText("Start the neverending acid trip!");
QObject::connect(button3, SIGNAL(clicked()), this, SLOT (acidTrippin()));
button4 = new QPushButton();
button4->setText("Draw a diagonal cross");
QObject::connect(button4, SIGNAL(clicked()), this, SLOT (drawDiagonalCross()));
lineSlider = new QSlider(Qt::Horizontal);
lineSlider->setMinimum(1);
lineSlider->setMaximum(150);
lineSlider->setValue(3);
//QObject::connect(lineSlider, SIGNAL(valueChanged(int)), this, SLOT (drawRainbowCross()));
QObject::connect(button1, SIGNAL (clicked()), this, SLOT (drawBlackLine()));
QObject::connect(button2, SIGNAL (clicked()), this, SLOT (drawRainbowCross()));
QObject::connect(button3, SIGNAL (clicked()), this, SLOT (acidTrippin()));
QObject::connect(button4, SIGNAL (clicked()), this, SLOT (drawDiagonalCross()));
//QObject::connect(lineSlider, SIGNAL (valueChanged(int)), this, SLOT (drawRainbowCross()));
task_tab1->addWidget(new QLabel("Let's draw something!"));
task_tab1->addWidget(button1);
task_tab1->addWidget(button2);
task_tab1->addWidget(button3);
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!"));
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(task_tab_widget1,"Task #1");
tabWidget->addTab(m_option_panel1,"Task #1");
// another tab
m_option_panel2 = new QWidget();
m_option_layout2 = new QVBoxLayout();
m_option_panel2->setLayout(m_option_layout2);
//Tab for second task
task_tab_widget2 = new QWidget();
task_tab2 = new QVBoxLayout();
task_tab_widget2->setLayout(task_tab2);
spinbox1 = new QSpinBox(tabWidget);
m_option_layout2->addWidget(new QLabel("Here we put some more controls later."));
m_option_layout2->addWidget(spinbox1);
task_tab2->addWidget(new QLabel("Here we put some more controls later."));
task_tab2->addWidget(spinbox1);
tabWidget->addTab(m_option_panel2,"Task #2");
tabWidget->show();
tabWidget->addTab(task_tab_widget2,"Task #2");
//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
* Bearbeitung sind.
*
* The following methods are about the generic image viewer application and do not contain
* any special graphics logic.
*
*****************************************************************************************/

View File

@ -66,27 +66,27 @@ class ImageViewer : public QMainWindow {
Q_OBJECT
private:
// Beispiel für GUI Elemente
QWidget* m_option_panel1;
QVBoxLayout* m_option_layout1;
QWidget* m_option_panel2;
QVBoxLayout* m_option_layout2;
// First task tab
QWidget* task_tab_widget1;
QVBoxLayout* task_tab1;
QPushButton* button1;
QPushButton* button2;
QPushButton* button3;
QPushButton* button4;
QSpinBox* spinbox1;
// hier können weitere GUI Objekte hin wie Buttons Slider etc.
QSlider* lineSlider;
private slots:
// Beispiel für einen Algorithmus
void drawBlackLine();
// Second task tab
QWidget* task_tab_widget2;
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 drawDiagonalCross();
void acidTrippin();
@ -108,15 +108,12 @@ class ImageViewer : public QMainWindow {
void resizeEvent(QResizeEvent * event);
private:
// Custom methods
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 generateMainGui();
void createActions();
void createMenus();
void updateActions();