[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"
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
ImageViewer imageViewer;
imageViewer.show();

View File

@ -40,24 +40,18 @@
#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.
*
*
@ -211,26 +202,21 @@ void ImageViewer::renewLogging()
QTextStream stream(&file); // Set the stream to read from myFile
logBrowser->clear();
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,8 +251,7 @@ 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)
QPrintDialog dialog(&printer, this);
@ -285,46 +267,33 @@ void ImageViewer::print()
#endif
}
void ImageViewer::open()
{
if(image!=NULL)
{
void ImageViewer::open() {
if(image != NULL) {
delete image;
image = NULL;
}
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open File"), QDir::currentPath());
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));
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,24 +303,20 @@ 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) {
@ -360,8 +325,7 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
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 "
@ -377,8 +341,7 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
"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()));
@ -420,8 +383,7 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
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);
@ -444,15 +406,13 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
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());
@ -464,8 +424,6 @@ void ImageViewer::resizeEvent(QResizeEvent * event)
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

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