[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);
ImageViewer imageViewer;
imageViewer.show();
return app.exec();
}
}

View File

@ -38,26 +38,20 @@
**
****************************************************************************/
#include "imageviewer-qt4.h"
#include "imageviewer-qt4.h"
ImageViewer::ImageViewer()
{
ImageViewer::ImageViewer() {
image=NULL;
startLogging();
generateMainGui();
renewLogging();
generateControlPanels();
createActions();
createMenus();
resize(1600, 600);
}
void ImageViewer::drawBlackLine()
{
void ImageViewer::drawBlackLine() {
if(image!=NULL) {
for(int i=0;i<std::min(image->width(),image->height());i++) {
image->setPixel(i,i,0);
@ -74,7 +68,7 @@ void ImageViewer::drawDiagonalCross() {
int width = image->width();
int height = image->height();
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();
@ -82,7 +76,6 @@ void ImageViewer::drawDiagonalCross() {
renewLogging();
}
//Proxy-Method to actual algorithm
void ImageViewer::drawRainbowCross() {
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-
* tierenden Algorithmen gestatet werden.
* tierenden Algorithmen gestattet werden.
*
*****************************************************************************************/
void ImageViewer::generateControlPanels()
{
void ImageViewer::generateControlPanels() {
// first tab
m_option_panel1 = new QWidget();
m_option_layout1 = new QVBoxLayout();
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.
*
*
@ -208,29 +199,24 @@ void ImageViewer::renewLogging()
QString line;
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();
while(!stream.atEnd()){
while(!stream.atEnd()) {
line = stream.readLine(); // this reads a line (QString) from the file
logBrowser->append(line);
}
}
void ImageViewer::updateImageDisplay()
{
void ImageViewer::updateImageDisplay() {
imageLabel->setPixmap(QPixmap::fromImage(*image));
}
void ImageViewer::generateMainGui()
{
void ImageViewer::generateMainGui() {
/* Tab widget */
tabWidget = new QTabWidget(this);
tabWidget->setObjectName("tabWidget");
/* Center widget */
centralwidget = new QWidget(this);
centralwidget->setObjectName("centralwidget");
@ -242,13 +228,10 @@ void ImageViewer::generateMainGui()
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
imageLabel->setScaledContents(true);
/* Center widget */
scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(imageLabel);
setCentralWidget(scrollArea);
/* HBox layout */
@ -268,10 +251,9 @@ void ImageViewer::generateMainGui()
gLayout->setVerticalSpacing(50);
}
void ImageViewer::print()
{
void ImageViewer::print() {
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);
if (dialog.exec()) {
QPainter painter(&printer);
@ -282,49 +264,36 @@ void ImageViewer::print()
painter.setWindow(imageLabel->pixmap()->rect());
painter.drawPixmap(0, 0, *imageLabel->pixmap());
}
#endif
#endif
}
void ImageViewer::open()
{
if(image!=NULL)
{
void ImageViewer::open() {
if(image != NULL) {
delete image;
image=NULL;
image = NULL;
}
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open File"), QDir::currentPath());
if (!fileName.isEmpty()) {
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath());
if(!fileName.isEmpty()) {
image = new QImage(fileName);
if (image->isNull()) {
QMessageBox::information(this, tr("Image Viewer"),
tr("Cannot load %1.").arg(fileName));
if(image->isNull()) {
QMessageBox::information(this, tr("Image Viewer"), tr("Cannot load %1.").arg(fileName));
return;
}
scaleFactor = 1.0;
updateImageDisplay();
printAct->setEnabled(true);
fitToWindowAct->setEnabled(true);
updateActions();
if (!fitToWindowAct->isChecked())
imageLabel->adjustSize();
if(!fitToWindowAct->isChecked()) imageLabel->adjustSize();
setWindowFilePath(fileName);
logFile << "geladen: " << fileName.toStdString().c_str() << std::endl;
renewLogging();
}
}
void ImageViewer::resizeEvent(QResizeEvent * event)
{
void ImageViewer::resizeEvent(QResizeEvent* event) {
QMainWindow::resizeEvent(event);
centralwidget->setMinimumWidth(width());
centralwidget->setMinimumHeight(height());
@ -334,34 +303,29 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
logBrowser->setMaximumWidth(width()-40);
}
void ImageViewer::zoomIn()
{
void ImageViewer::zoomIn() {
scaleImage(1.25);
}
}
void ImageViewer::zoomOut()
{
void ImageViewer::zoomOut() {
scaleImage(0.8);
}
}
void ImageViewer::normalSize()
{
void ImageViewer::normalSize() {
imageLabel->adjustSize();
scaleFactor = 1.0;
}
}
void ImageViewer::fitToWindow()
{
void ImageViewer::fitToWindow() {
bool fitToWindow = fitToWindowAct->isChecked();
scrollArea->setWidgetResizable(fitToWindow);
if (!fitToWindow) {
if(!fitToWindow) {
normalSize();
}
updateActions();
}
}
void ImageViewer::about()
{
void ImageViewer::about() {
QMessageBox::about(this, tr("About Image Viewer"),
tr("<p>The <b>Image Viewer</b> example shows how to combine QLabel "
"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 "
"zooming and scaling features. </p><p>In addition the example "
"shows how to use QPainter to print an image.</p>"));
}
}
void ImageViewer::createActions()
{
void ImageViewer::createActions() {
openAct = new QAction(tr("&Open..."), this);
openAct->setShortcut(tr("Ctrl+O"));
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
@ -418,10 +381,9 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
aboutQtAct = new QAction(tr("About &Qt"), this);
connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
}
}
void ImageViewer::createMenus()
{
void ImageViewer::createMenus() {
fileMenu = new QMenu(tr("&File"), this);
fileMenu->addAction(openAct);
fileMenu->addAction(printAct);
@ -442,17 +404,15 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
menuBar()->addMenu(fileMenu);
menuBar()->addMenu(viewMenu);
menuBar()->addMenu(helpMenu);
}
}
void ImageViewer::updateActions()
{
void ImageViewer::updateActions() {
zoomInAct->setEnabled(!fitToWindowAct->isChecked());
zoomOutAct->setEnabled(!fitToWindowAct->isChecked());
normalSizeAct->setEnabled(!fitToWindowAct->isChecked());
}
}
void ImageViewer::scaleImage(double factor)
{
void ImageViewer::scaleImage(double factor) {
Q_ASSERT(imageLabel->pixmap());
scaleFactor *= factor;
imageLabel->resize(scaleFactor * imageLabel->pixmap()->size());
@ -462,10 +422,8 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
zoomInAct->setEnabled(scaleFactor < 3.0);
zoomOutAct->setEnabled(scaleFactor > 0.333);
}
}
void ImageViewer::adjustScrollBar(QScrollBar *scrollBar, double factor)
{
scrollBar->setValue(int(factor * scrollBar->value()
+ ((factor - 1) * scrollBar->pageStep()/2)));
}
void ImageViewer::adjustScrollBar(QScrollBar* scrollBar, double factor) {
scrollBar->setValue(int(factor * scrollBar->value() + ((factor - 1) * scrollBar->pageStep()/2)));
}

View File

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