[TASK] Fix indentation.

This commit is contained in:
Jan Philipp Timme 2015-10-23 10:40:05 +02:00
parent 305df52433
commit 18807593c4
3 changed files with 318 additions and 372 deletions

View File

@ -38,14 +38,13 @@
** **
****************************************************************************/ ****************************************************************************/
#include <QApplication> #include <QApplication>
#include "imageviewer-qt4.h" #include "imageviewer-qt4.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[]) {
{
QApplication app(argc, argv); QApplication app(argc, argv);
ImageViewer imageViewer; ImageViewer imageViewer;
imageViewer.show(); imageViewer.show();
return app.exec(); return app.exec();
} }

View File

@ -38,26 +38,20 @@
** **
****************************************************************************/ ****************************************************************************/
#include "imageviewer-qt4.h" #include "imageviewer-qt4.h"
ImageViewer::ImageViewer() ImageViewer::ImageViewer() {
{
image=NULL; image=NULL;
startLogging(); startLogging();
generateMainGui(); generateMainGui();
renewLogging(); renewLogging();
generateControlPanels(); generateControlPanels();
createActions(); createActions();
createMenus(); createMenus();
resize(1600, 600); resize(1600, 600);
} }
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++) {
image->setPixel(i,i,0); image->setPixel(i,i,0);
@ -74,7 +68,7 @@ void ImageViewer::drawDiagonalCross() {
int width = image->width(); int width = image->width();
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); //holy shit, ez gg! image->setPixel((1.0*y/height)*width,y,color);
} }
} }
updateImageDisplay(); updateImageDisplay();
@ -82,7 +76,6 @@ void ImageViewer::drawDiagonalCross() {
renewLogging(); renewLogging();
} }
//Proxy-Method to actual algorithm //Proxy-Method to actual algorithm
void ImageViewer::drawRainbowCross() { void ImageViewer::drawRainbowCross() {
drawRainbowCross(0); drawRainbowCross(0);
@ -123,16 +116,14 @@ void ImageViewer::acidTrippin() {
/**************************************************************************************** /****************************************************************************************
* *
* mit dieser Methode können sie sich pro Aufgabe ein Tab anlegen, in der die Ein- * 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- * stellungen per Slider, Button, Checkbox etc. gemacht werden und die zu implemen-
* tierenden Algorithmen gestatet werden. * tierenden Algorithmen gestattet werden.
* *
*****************************************************************************************/ *****************************************************************************************/
void ImageViewer::generateControlPanels() void ImageViewer::generateControlPanels() {
{
// first tab // first tab
m_option_panel1 = new QWidget(); m_option_panel1 = new QWidget();
m_option_layout1 = new QVBoxLayout(); m_option_layout1 = new QVBoxLayout();
m_option_panel1->setLayout(m_option_layout1); m_option_panel1->setLayout(m_option_layout1);
@ -189,7 +180,7 @@ void ImageViewer::generateControlPanels()
/**************************************************************************************** /****************************************************************************************
* *
* ab hier kommen technische Details, die nicht notwenig für das Verständnis und die * Ab hier kommen technische Details, die nicht notwenig für das Verständnis und die
* Bearbeitung sind. * Bearbeitung sind.
* *
* *
@ -208,29 +199,24 @@ void ImageViewer::renewLogging()
QString line; QString line;
file.open(QIODevice::ReadOnly); // Open the file file.open(QIODevice::ReadOnly); // Open the file
QTextStream stream( &file ); // Set the stream to read from myFile QTextStream stream(&file); // Set the stream to read from myFile
logBrowser->clear(); logBrowser->clear();
while(!stream.atEnd()){ while(!stream.atEnd()) {
line = stream.readLine(); // this reads a line (QString) from the file line = stream.readLine(); // this reads a line (QString) from the file
logBrowser->append(line); logBrowser->append(line);
} }
} }
void ImageViewer::updateImageDisplay() void ImageViewer::updateImageDisplay() {
{
imageLabel->setPixmap(QPixmap::fromImage(*image)); imageLabel->setPixmap(QPixmap::fromImage(*image));
} }
void ImageViewer::generateMainGui() void ImageViewer::generateMainGui() {
{
/* Tab widget */ /* Tab widget */
tabWidget = new QTabWidget(this); tabWidget = new QTabWidget(this);
tabWidget->setObjectName("tabWidget"); tabWidget->setObjectName("tabWidget");
/* Center widget */ /* Center widget */
centralwidget = new QWidget(this); centralwidget = new QWidget(this);
centralwidget->setObjectName("centralwidget"); centralwidget->setObjectName("centralwidget");
@ -242,13 +228,10 @@ void ImageViewer::generateMainGui()
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
imageLabel->setScaledContents(true); imageLabel->setScaledContents(true);
/* Center widget */ /* Center widget */
scrollArea = new QScrollArea; scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Dark); scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(imageLabel); scrollArea->setWidget(imageLabel);
setCentralWidget(scrollArea); setCentralWidget(scrollArea);
/* HBox layout */ /* HBox layout */
@ -268,10 +251,9 @@ void ImageViewer::generateMainGui()
gLayout->setVerticalSpacing(50); gLayout->setVerticalSpacing(50);
} }
void ImageViewer::print() void ImageViewer::print() {
{
Q_ASSERT(imageLabel->pixmap()); Q_ASSERT(imageLabel->pixmap());
#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG) #if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG)
QPrintDialog dialog(&printer, this); QPrintDialog dialog(&printer, this);
if (dialog.exec()) { if (dialog.exec()) {
QPainter painter(&printer); QPainter painter(&printer);
@ -282,49 +264,36 @@ void ImageViewer::print()
painter.setWindow(imageLabel->pixmap()->rect()); painter.setWindow(imageLabel->pixmap()->rect());
painter.drawPixmap(0, 0, *imageLabel->pixmap()); painter.drawPixmap(0, 0, *imageLabel->pixmap());
} }
#endif #endif
} }
void ImageViewer::open() void ImageViewer::open() {
{ if(image != NULL) {
if(image!=NULL)
{
delete image; delete image;
image=NULL; image = NULL;
} }
QString fileName = QFileDialog::getOpenFileName(this, QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath());
tr("Open File"), QDir::currentPath()); if(!fileName.isEmpty()) {
if (!fileName.isEmpty()) {
image = new QImage(fileName); image = new QImage(fileName);
if (image->isNull()) { if(image->isNull()) {
QMessageBox::information(this, tr("Image Viewer"), QMessageBox::information(this, tr("Image Viewer"), tr("Cannot load %1.").arg(fileName));
tr("Cannot load %1.").arg(fileName));
return; return;
} }
scaleFactor = 1.0; scaleFactor = 1.0;
updateImageDisplay(); updateImageDisplay();
printAct->setEnabled(true); printAct->setEnabled(true);
fitToWindowAct->setEnabled(true); fitToWindowAct->setEnabled(true);
updateActions(); updateActions();
if(!fitToWindowAct->isChecked()) imageLabel->adjustSize();
if (!fitToWindowAct->isChecked())
imageLabel->adjustSize();
setWindowFilePath(fileName); setWindowFilePath(fileName);
logFile << "geladen: " << fileName.toStdString().c_str() << std::endl; logFile << "geladen: " << fileName.toStdString().c_str() << std::endl;
renewLogging(); renewLogging();
} }
} }
void ImageViewer::resizeEvent(QResizeEvent* event) {
void ImageViewer::resizeEvent(QResizeEvent * event)
{
QMainWindow::resizeEvent(event); QMainWindow::resizeEvent(event);
centralwidget->setMinimumWidth(width()); centralwidget->setMinimumWidth(width());
centralwidget->setMinimumHeight(height()); centralwidget->setMinimumHeight(height());
@ -334,34 +303,29 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
logBrowser->setMaximumWidth(width()-40); logBrowser->setMaximumWidth(width()-40);
} }
void ImageViewer::zoomIn() void ImageViewer::zoomIn() {
{
scaleImage(1.25); scaleImage(1.25);
} }
void ImageViewer::zoomOut() void ImageViewer::zoomOut() {
{
scaleImage(0.8); scaleImage(0.8);
} }
void ImageViewer::normalSize() void ImageViewer::normalSize() {
{
imageLabel->adjustSize(); imageLabel->adjustSize();
scaleFactor = 1.0; scaleFactor = 1.0;
} }
void ImageViewer::fitToWindow() void ImageViewer::fitToWindow() {
{
bool fitToWindow = fitToWindowAct->isChecked(); bool fitToWindow = fitToWindowAct->isChecked();
scrollArea->setWidgetResizable(fitToWindow); scrollArea->setWidgetResizable(fitToWindow);
if (!fitToWindow) { if(!fitToWindow) {
normalSize(); normalSize();
} }
updateActions(); updateActions();
} }
void ImageViewer::about() void ImageViewer::about() {
{
QMessageBox::about(this, tr("About Image Viewer"), QMessageBox::about(this, tr("About Image Viewer"),
tr("<p>The <b>Image Viewer</b> example shows how to combine QLabel " tr("<p>The <b>Image Viewer</b> example shows how to combine QLabel "
"and QScrollArea to display an image. QLabel is typically used " "and QScrollArea to display an image. QLabel is typically used "
@ -375,10 +339,9 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
"(QScrollArea::widgetResizable), can be used to implement " "(QScrollArea::widgetResizable), can be used to implement "
"zooming and scaling features. </p><p>In addition the example " "zooming and scaling features. </p><p>In addition the example "
"shows how to use QPainter to print an image.</p>")); "shows how to use QPainter to print an image.</p>"));
} }
void ImageViewer::createActions() void ImageViewer::createActions() {
{
openAct = new QAction(tr("&Open..."), this); openAct = new QAction(tr("&Open..."), this);
openAct->setShortcut(tr("Ctrl+O")); openAct->setShortcut(tr("Ctrl+O"));
connect(openAct, SIGNAL(triggered()), this, SLOT(open())); connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
@ -418,10 +381,9 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
aboutQtAct = new QAction(tr("About &Qt"), this); aboutQtAct = new QAction(tr("About &Qt"), this);
connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
} }
void ImageViewer::createMenus() void ImageViewer::createMenus() {
{
fileMenu = new QMenu(tr("&File"), this); fileMenu = new QMenu(tr("&File"), this);
fileMenu->addAction(openAct); fileMenu->addAction(openAct);
fileMenu->addAction(printAct); fileMenu->addAction(printAct);
@ -442,17 +404,15 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
menuBar()->addMenu(fileMenu); menuBar()->addMenu(fileMenu);
menuBar()->addMenu(viewMenu); menuBar()->addMenu(viewMenu);
menuBar()->addMenu(helpMenu); menuBar()->addMenu(helpMenu);
} }
void ImageViewer::updateActions() void ImageViewer::updateActions() {
{
zoomInAct->setEnabled(!fitToWindowAct->isChecked()); zoomInAct->setEnabled(!fitToWindowAct->isChecked());
zoomOutAct->setEnabled(!fitToWindowAct->isChecked()); zoomOutAct->setEnabled(!fitToWindowAct->isChecked());
normalSizeAct->setEnabled(!fitToWindowAct->isChecked()); normalSizeAct->setEnabled(!fitToWindowAct->isChecked());
} }
void ImageViewer::scaleImage(double factor) void ImageViewer::scaleImage(double factor) {
{
Q_ASSERT(imageLabel->pixmap()); Q_ASSERT(imageLabel->pixmap());
scaleFactor *= factor; scaleFactor *= factor;
imageLabel->resize(scaleFactor * imageLabel->pixmap()->size()); imageLabel->resize(scaleFactor * imageLabel->pixmap()->size());
@ -462,10 +422,8 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
zoomInAct->setEnabled(scaleFactor < 3.0); zoomInAct->setEnabled(scaleFactor < 3.0);
zoomOutAct->setEnabled(scaleFactor > 0.333); zoomOutAct->setEnabled(scaleFactor > 0.333);
} }
void ImageViewer::adjustScrollBar(QScrollBar *scrollBar, double factor) void ImageViewer::adjustScrollBar(QScrollBar* scrollBar, double factor) {
{ scrollBar->setValue(int(factor * scrollBar->value() + ((factor - 1) * scrollBar->pageStep()/2)));
scrollBar->setValue(int(factor * scrollBar->value() }
+ ((factor - 1) * scrollBar->pageStep()/2)));
}

View File

@ -38,16 +38,16 @@
** **
****************************************************************************/ ****************************************************************************/
#ifndef IMAGEVIEWER_H #ifndef IMAGEVIEWER_H
#define IMAGEVIEWER_H #define IMAGEVIEWER_H
#include <QMainWindow> #include <QMainWindow>
#include <QPrinter> #include <QPrinter>
#include <QtGui> #include <QtGui>
#include <QResizeEvent> #include <QResizeEvent>
#include <QPushButton> #include <QPushButton>
#include <QSlider> #include <QSlider>
#include <QColor> #include <QColor>
#include "fstream" #include "fstream"
@ -62,12 +62,10 @@ class QTabWidget;
class QPushButton; class QPushButton;
class QSpinBox; class QSpinBox;
class ImageViewer : public QMainWindow class ImageViewer : public QMainWindow {
{
Q_OBJECT Q_OBJECT
private: private:
// Beispiel für GUI Elemente // Beispiel für GUI Elemente
QWidget* m_option_panel1; QWidget* m_option_panel1;
QVBoxLayout* m_option_layout1; QVBoxLayout* m_option_layout1;
@ -82,11 +80,9 @@ class QSpinBox;
QSpinBox* spinbox1; QSpinBox* spinbox1;
// hier können weitere GUI Objekte hin wie Buttons Slider etc. // hier können weitere GUI Objekte hin wie Buttons Slider etc.
QSlider* lineSlider; QSlider* lineSlider;
private slots: private slots:
// Beispiel für einen Algorithmus // Beispiel für einen Algorithmus
void drawBlackLine(); void drawBlackLine();
@ -103,20 +99,16 @@ class QSpinBox;
void fitToWindow(); void fitToWindow();
void about(); void about();
public: public:
ImageViewer(); ImageViewer();
bool loadFile(const QString &); bool loadFile(const QString &);
void updateImageDisplay(); void updateImageDisplay();
protected: protected:
void resizeEvent(QResizeEvent * event); void resizeEvent(QResizeEvent * event);
private: private:
void drawRainbowCross(int h); void drawRainbowCross(int h);
// in diesen Beiden Methoden sind Änderungen nötig bzw. sie dienen als // in diesen Beiden Methoden sind Änderungen nötig bzw. sie dienen als
// Vorlage für eigene Methoden. // Vorlage für eigene Methoden.
void generateControlPanels(); void generateControlPanels();
@ -141,8 +133,6 @@ protected:
double scaleFactor; double scaleFactor;
QImage* image; QImage* image;
std::fstream logFile; std::fstream logFile;
#ifndef QT_NO_PRINTER #ifndef QT_NO_PRINTER
@ -162,6 +152,5 @@ protected:
QMenu *fileMenu; QMenu *fileMenu;
QMenu *viewMenu; QMenu *viewMenu;
QMenu *helpMenu; QMenu *helpMenu;
}; };
#endif
#endif