[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

@ -42,8 +42,7 @@
#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();

View File

@ -40,24 +40,18 @@
#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.
* *
* *
@ -211,26 +202,21 @@ void ImageViewer::renewLogging()
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,8 +251,7 @@ 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);
@ -285,46 +267,33 @@ void ImageViewer::print()
#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,24 +303,20 @@ 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) {
@ -360,8 +325,7 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
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 "
@ -377,8 +341,7 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
"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()));
@ -420,8 +383,7 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
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);
@ -444,15 +406,13 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
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());
@ -464,8 +424,6 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
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

@ -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
@ -163,5 +153,4 @@ protected:
QMenu *viewMenu; QMenu *viewMenu;
QMenu *helpMenu; QMenu *helpMenu;
}; };
#endif #endif