[TASK] Fix indentation.
This commit is contained in:
parent
305df52433
commit
18807593c4
|
@ -38,14 +38,13 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QApplication>
|
||||
#include <QApplication>
|
||||
|
||||
#include "imageviewer-qt4.h"
|
||||
#include "imageviewer-qt4.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
ImageViewer imageViewer;
|
||||
imageViewer.show();
|
||||
return app.exec();
|
||||
}
|
||||
int main(int argc, char *argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
ImageViewer imageViewer;
|
||||
imageViewer.show();
|
||||
return app.exec();
|
||||
}
|
||||
|
|
|
@ -38,26 +38,20 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "imageviewer-qt4.h"
|
||||
#include "imageviewer-qt4.h"
|
||||
|
||||
ImageViewer::ImageViewer()
|
||||
{
|
||||
image=NULL;
|
||||
|
||||
startLogging();
|
||||
|
||||
generateMainGui();
|
||||
renewLogging();
|
||||
|
||||
generateControlPanels();
|
||||
createActions();
|
||||
createMenus();
|
||||
|
||||
resize(1600, 600);
|
||||
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);
|
||||
|
@ -98,8 +91,8 @@ void ImageViewer::drawRainbowCross(int initialHue=0) {
|
|||
for(int i=0;i<std::min(image->width(),image->height());i++) {
|
||||
int color = myColor.rgba();
|
||||
for(int r=0; r<range; r++) {
|
||||
image->setPixel(i+r,i,color);
|
||||
image->setPixel((image_width-i)-r,i,color);
|
||||
image->setPixel(i+r,i,color);
|
||||
image->setPixel((image_width-i)-r,i,color);
|
||||
}
|
||||
h++;
|
||||
if(h > 359) h = 0;
|
||||
|
@ -123,73 +116,71 @@ 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()
|
||||
{
|
||||
// first tab
|
||||
void ImageViewer::generateControlPanels() {
|
||||
// first tab
|
||||
m_option_panel1 = new QWidget();
|
||||
m_option_layout1 = new QVBoxLayout();
|
||||
m_option_panel1->setLayout(m_option_layout1);
|
||||
|
||||
m_option_panel1 = new QWidget();
|
||||
m_option_layout1 = new QVBoxLayout();
|
||||
m_option_panel1->setLayout(m_option_layout1);
|
||||
button1 = new QPushButton();
|
||||
button1->setText("Draw a black line");
|
||||
|
||||
button1 = new QPushButton();
|
||||
button1->setText("Draw a black line");
|
||||
button2 = new QPushButton();
|
||||
button2->setText("Draw a rainbow cross");
|
||||
|
||||
button2 = new QPushButton();
|
||||
button2->setText("Draw a rainbow cross");
|
||||
button3 = new QPushButton();
|
||||
button3->setText("Start the neverending acid trip!");
|
||||
|
||||
button3 = new QPushButton();
|
||||
button3->setText("Start the neverending acid trip!");
|
||||
|
||||
button4 = new QPushButton();
|
||||
button4->setText("Draw a diagonal cross");
|
||||
|
||||
lineSlider = new QSlider(Qt::Horizontal);
|
||||
lineSlider->setMinimum(1);
|
||||
lineSlider->setMaximum(150);
|
||||
lineSlider->setValue(3);
|
||||
button4 = new QPushButton();
|
||||
button4->setText("Draw a diagonal cross");
|
||||
|
||||
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()));
|
||||
lineSlider = new QSlider(Qt::Horizontal);
|
||||
lineSlider->setMinimum(1);
|
||||
lineSlider->setMaximum(150);
|
||||
lineSlider->setValue(3);
|
||||
|
||||
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()));
|
||||
|
||||
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."));
|
||||
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(m_option_panel1,"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);
|
||||
// another tab
|
||||
m_option_panel2 = new QWidget();
|
||||
m_option_layout2 = new QVBoxLayout();
|
||||
m_option_panel2->setLayout(m_option_layout2);
|
||||
|
||||
spinbox1 = new QSpinBox(tabWidget);
|
||||
spinbox1 = new QSpinBox(tabWidget);
|
||||
|
||||
m_option_layout2->addWidget(new QLabel("Here we put some more controls later."));
|
||||
m_option_layout2->addWidget(spinbox1);
|
||||
m_option_layout2->addWidget(new QLabel("Here we put some more controls later."));
|
||||
m_option_layout2->addWidget(spinbox1);
|
||||
|
||||
tabWidget->addTab(m_option_panel2,"Task #2");
|
||||
tabWidget->show();
|
||||
tabWidget->addTab(m_option_panel2,"Task #2");
|
||||
tabWidget->show();
|
||||
|
||||
// Hinweis: Es bietet sich an pro Aufgabe jeweils einen solchen Tab zu erstellen
|
||||
// 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
|
||||
* Ab hier kommen technische Details, die nicht notwenig für das Verständnis und die
|
||||
* Bearbeitung sind.
|
||||
*
|
||||
*
|
||||
|
@ -197,275 +188,242 @@ void ImageViewer::generateControlPanels()
|
|||
|
||||
void ImageViewer::startLogging()
|
||||
{
|
||||
//LogFile
|
||||
logFile.open("log.txt", std::ios::out);
|
||||
logFile << "Logging: \n" << std::endl;
|
||||
//LogFile
|
||||
logFile.open("log.txt", std::ios::out);
|
||||
logFile << "Logging: \n" << std::endl;
|
||||
}
|
||||
|
||||
void ImageViewer::renewLogging()
|
||||
{
|
||||
QFile file("log.txt"); // Create a file handle for the file named
|
||||
QString line;
|
||||
file.open(QIODevice::ReadOnly); // Open the file
|
||||
QFile file("log.txt"); // Create a file handle for the file named
|
||||
QString line;
|
||||
file.open(QIODevice::ReadOnly); // Open the file
|
||||
|
||||
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);
|
||||
}
|
||||
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()
|
||||
{
|
||||
imageLabel->setPixmap(QPixmap::fromImage(*image));
|
||||
void ImageViewer::updateImageDisplay() {
|
||||
imageLabel->setPixmap(QPixmap::fromImage(*image));
|
||||
}
|
||||
|
||||
|
||||
void ImageViewer::generateMainGui()
|
||||
{
|
||||
/* Tab widget */
|
||||
tabWidget = new QTabWidget(this);
|
||||
tabWidget->setObjectName("tabWidget");
|
||||
|
||||
void ImageViewer::generateMainGui() {
|
||||
/* Tab widget */
|
||||
tabWidget = new QTabWidget(this);
|
||||
tabWidget->setObjectName("tabWidget");
|
||||
|
||||
/* Center widget */
|
||||
centralwidget = new QWidget(this);
|
||||
centralwidget->setObjectName("centralwidget");
|
||||
//centralwidget->setFixedSize(200,200);
|
||||
//setCentralWidget(centralwidget);
|
||||
|
||||
/* Center widget */
|
||||
centralwidget = new QWidget(this);
|
||||
centralwidget->setObjectName("centralwidget");
|
||||
//centralwidget->setFixedSize(200,200);
|
||||
//setCentralWidget(centralwidget);
|
||||
imageLabel = new QLabel;
|
||||
imageLabel->setBackgroundRole(QPalette::Base);
|
||||
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
||||
imageLabel->setScaledContents(true);
|
||||
|
||||
imageLabel = new QLabel;
|
||||
imageLabel->setBackgroundRole(QPalette::Base);
|
||||
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
||||
imageLabel->setScaledContents(true);
|
||||
|
||||
/* Center widget */
|
||||
scrollArea = new QScrollArea;
|
||||
scrollArea->setBackgroundRole(QPalette::Dark);
|
||||
scrollArea->setWidget(imageLabel);
|
||||
setCentralWidget(scrollArea);
|
||||
|
||||
/* Center widget */
|
||||
scrollArea = new QScrollArea;
|
||||
scrollArea->setBackgroundRole(QPalette::Dark);
|
||||
scrollArea->setWidget(imageLabel);
|
||||
|
||||
|
||||
setCentralWidget(scrollArea);
|
||||
/* HBox layout */
|
||||
QGridLayout* gLayout = new QGridLayout(centralwidget);
|
||||
gLayout->setObjectName("hboxLayout");
|
||||
gLayout->addWidget(new QLabel(),1,1);
|
||||
gLayout->setVerticalSpacing(50);
|
||||
gLayout->addWidget(tabWidget,2,1);
|
||||
gLayout->addWidget(scrollArea,2,2);
|
||||
|
||||
/* HBox layout */
|
||||
QGridLayout* gLayout = new QGridLayout(centralwidget);
|
||||
gLayout->setObjectName("hboxLayout");
|
||||
gLayout->addWidget(new QLabel(),1,1);
|
||||
gLayout->setVerticalSpacing(50);
|
||||
gLayout->addWidget(tabWidget,2,1);
|
||||
gLayout->addWidget(scrollArea,2,2);
|
||||
|
||||
logBrowser= new QTextEdit(this);
|
||||
logBrowser->setMinimumHeight(100);
|
||||
logBrowser->setMaximumHeight(200);
|
||||
logBrowser->setMinimumWidth(width());
|
||||
logBrowser->setMaximumWidth(width());
|
||||
gLayout->addWidget(logBrowser,3,1,1,2);
|
||||
gLayout->setVerticalSpacing(50);
|
||||
logBrowser= new QTextEdit(this);
|
||||
logBrowser->setMinimumHeight(100);
|
||||
logBrowser->setMaximumHeight(200);
|
||||
logBrowser->setMinimumWidth(width());
|
||||
logBrowser->setMaximumWidth(width());
|
||||
gLayout->addWidget(logBrowser,3,1,1,2);
|
||||
gLayout->setVerticalSpacing(50);
|
||||
}
|
||||
|
||||
void ImageViewer::print()
|
||||
{
|
||||
Q_ASSERT(imageLabel->pixmap());
|
||||
#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG)
|
||||
QPrintDialog dialog(&printer, this);
|
||||
if (dialog.exec()) {
|
||||
QPainter painter(&printer);
|
||||
QRect rect = painter.viewport();
|
||||
QSize size = imageLabel->pixmap()->size();
|
||||
size.scale(rect.size(), Qt::KeepAspectRatio);
|
||||
painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
|
||||
painter.setWindow(imageLabel->pixmap()->rect());
|
||||
painter.drawPixmap(0, 0, *imageLabel->pixmap());
|
||||
void ImageViewer::print() {
|
||||
Q_ASSERT(imageLabel->pixmap());
|
||||
#if !defined(QT_NO_PRINTER) && !defined(QT_NO_PRINTDIALOG)
|
||||
QPrintDialog dialog(&printer, this);
|
||||
if (dialog.exec()) {
|
||||
QPainter painter(&printer);
|
||||
QRect rect = painter.viewport();
|
||||
QSize size = imageLabel->pixmap()->size();
|
||||
size.scale(rect.size(), Qt::KeepAspectRatio);
|
||||
painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
|
||||
painter.setWindow(imageLabel->pixmap()->rect());
|
||||
painter.drawPixmap(0, 0, *imageLabel->pixmap());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ImageViewer::open() {
|
||||
if(image != NULL) {
|
||||
delete image;
|
||||
image = NULL;
|
||||
}
|
||||
|
||||
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));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ImageViewer::open()
|
||||
{
|
||||
if(image!=NULL)
|
||||
{
|
||||
delete image;
|
||||
image=NULL;
|
||||
}
|
||||
|
||||
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));
|
||||
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)
|
||||
{
|
||||
QMainWindow::resizeEvent(event);
|
||||
centralwidget->setMinimumWidth(width());
|
||||
centralwidget->setMinimumHeight(height());
|
||||
centralwidget->setMaximumWidth(width());
|
||||
centralwidget->setMaximumHeight(height());
|
||||
logBrowser->setMinimumWidth(width()-40);
|
||||
logBrowser->setMaximumWidth(width()-40);
|
||||
void ImageViewer::resizeEvent(QResizeEvent* event) {
|
||||
QMainWindow::resizeEvent(event);
|
||||
centralwidget->setMinimumWidth(width());
|
||||
centralwidget->setMinimumHeight(height());
|
||||
centralwidget->setMaximumWidth(width());
|
||||
centralwidget->setMaximumHeight(height());
|
||||
logBrowser->setMinimumWidth(width()-40);
|
||||
logBrowser->setMaximumWidth(width()-40);
|
||||
}
|
||||
|
||||
void ImageViewer::zoomIn()
|
||||
{
|
||||
scaleImage(1.25);
|
||||
}
|
||||
void ImageViewer::zoomIn() {
|
||||
scaleImage(1.25);
|
||||
}
|
||||
|
||||
void ImageViewer::zoomOut()
|
||||
{
|
||||
scaleImage(0.8);
|
||||
}
|
||||
void ImageViewer::zoomOut() {
|
||||
scaleImage(0.8);
|
||||
}
|
||||
|
||||
void ImageViewer::normalSize()
|
||||
{
|
||||
imageLabel->adjustSize();
|
||||
scaleFactor = 1.0;
|
||||
}
|
||||
void ImageViewer::normalSize() {
|
||||
imageLabel->adjustSize();
|
||||
scaleFactor = 1.0;
|
||||
}
|
||||
|
||||
void ImageViewer::fitToWindow()
|
||||
{
|
||||
bool fitToWindow = fitToWindowAct->isChecked();
|
||||
scrollArea->setWidgetResizable(fitToWindow);
|
||||
if (!fitToWindow) {
|
||||
normalSize();
|
||||
}
|
||||
updateActions();
|
||||
}
|
||||
void ImageViewer::fitToWindow() {
|
||||
bool fitToWindow = fitToWindowAct->isChecked();
|
||||
scrollArea->setWidgetResizable(fitToWindow);
|
||||
if(!fitToWindow) {
|
||||
normalSize();
|
||||
}
|
||||
updateActions();
|
||||
}
|
||||
|
||||
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 "
|
||||
"for displaying a text, but it can also display an image. "
|
||||
"QScrollArea provides a scrolling view around another widget. "
|
||||
"If the child widget exceeds the size of the frame, QScrollArea "
|
||||
"automatically provides scroll bars. </p><p>The example "
|
||||
"demonstrates how QLabel's ability to scale its contents "
|
||||
"(QLabel::scaledContents), and QScrollArea's ability to "
|
||||
"automatically resize its contents "
|
||||
"(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::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 "
|
||||
"for displaying a text, but it can also display an image. "
|
||||
"QScrollArea provides a scrolling view around another widget. "
|
||||
"If the child widget exceeds the size of the frame, QScrollArea "
|
||||
"automatically provides scroll bars. </p><p>The example "
|
||||
"demonstrates how QLabel's ability to scale its contents "
|
||||
"(QLabel::scaledContents), and QScrollArea's ability to "
|
||||
"automatically resize its contents "
|
||||
"(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()
|
||||
{
|
||||
openAct = new QAction(tr("&Open..."), this);
|
||||
openAct->setShortcut(tr("Ctrl+O"));
|
||||
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
|
||||
void ImageViewer::createActions() {
|
||||
openAct = new QAction(tr("&Open..."), this);
|
||||
openAct->setShortcut(tr("Ctrl+O"));
|
||||
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
|
||||
|
||||
printAct = new QAction(tr("&Print..."), this);
|
||||
printAct->setShortcut(tr("Ctrl+P"));
|
||||
printAct->setEnabled(false);
|
||||
connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
|
||||
printAct = new QAction(tr("&Print..."), this);
|
||||
printAct->setShortcut(tr("Ctrl+P"));
|
||||
printAct->setEnabled(false);
|
||||
connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
|
||||
|
||||
exitAct = new QAction(tr("E&xit"), this);
|
||||
exitAct->setShortcut(tr("Ctrl+Q"));
|
||||
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
|
||||
exitAct = new QAction(tr("E&xit"), this);
|
||||
exitAct->setShortcut(tr("Ctrl+Q"));
|
||||
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
|
||||
|
||||
zoomInAct = new QAction(tr("Zoom &In (25%)"), this);
|
||||
zoomInAct->setShortcut(tr("Ctrl++"));
|
||||
zoomInAct->setEnabled(false);
|
||||
connect(zoomInAct, SIGNAL(triggered()), this, SLOT(zoomIn()));
|
||||
zoomInAct = new QAction(tr("Zoom &In (25%)"), this);
|
||||
zoomInAct->setShortcut(tr("Ctrl++"));
|
||||
zoomInAct->setEnabled(false);
|
||||
connect(zoomInAct, SIGNAL(triggered()), this, SLOT(zoomIn()));
|
||||
|
||||
zoomOutAct = new QAction(tr("Zoom &Out (25%)"), this);
|
||||
zoomOutAct->setShortcut(tr("Ctrl+-"));
|
||||
zoomOutAct->setEnabled(false);
|
||||
connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(zoomOut()));
|
||||
zoomOutAct = new QAction(tr("Zoom &Out (25%)"), this);
|
||||
zoomOutAct->setShortcut(tr("Ctrl+-"));
|
||||
zoomOutAct->setEnabled(false);
|
||||
connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(zoomOut()));
|
||||
|
||||
normalSizeAct = new QAction(tr("&Normal Size"), this);
|
||||
normalSizeAct->setShortcut(tr("Ctrl+S"));
|
||||
normalSizeAct->setEnabled(false);
|
||||
connect(normalSizeAct, SIGNAL(triggered()), this, SLOT(normalSize()));
|
||||
normalSizeAct = new QAction(tr("&Normal Size"), this);
|
||||
normalSizeAct->setShortcut(tr("Ctrl+S"));
|
||||
normalSizeAct->setEnabled(false);
|
||||
connect(normalSizeAct, SIGNAL(triggered()), this, SLOT(normalSize()));
|
||||
|
||||
fitToWindowAct = new QAction(tr("&Fit to Window"), this);
|
||||
fitToWindowAct->setEnabled(false);
|
||||
fitToWindowAct->setCheckable(true);
|
||||
fitToWindowAct->setShortcut(tr("Ctrl+F"));
|
||||
connect(fitToWindowAct, SIGNAL(triggered()), this, SLOT(fitToWindow()));
|
||||
fitToWindowAct = new QAction(tr("&Fit to Window"), this);
|
||||
fitToWindowAct->setEnabled(false);
|
||||
fitToWindowAct->setCheckable(true);
|
||||
fitToWindowAct->setShortcut(tr("Ctrl+F"));
|
||||
connect(fitToWindowAct, SIGNAL(triggered()), this, SLOT(fitToWindow()));
|
||||
|
||||
aboutAct = new QAction(tr("&About"), this);
|
||||
connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
|
||||
aboutAct = new QAction(tr("&About"), this);
|
||||
connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
|
||||
|
||||
aboutQtAct = new QAction(tr("About &Qt"), this);
|
||||
connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
|
||||
}
|
||||
aboutQtAct = new QAction(tr("About &Qt"), this);
|
||||
connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
|
||||
}
|
||||
|
||||
void ImageViewer::createMenus()
|
||||
{
|
||||
fileMenu = new QMenu(tr("&File"), this);
|
||||
fileMenu->addAction(openAct);
|
||||
fileMenu->addAction(printAct);
|
||||
fileMenu->addSeparator();
|
||||
fileMenu->addAction(exitAct);
|
||||
void ImageViewer::createMenus() {
|
||||
fileMenu = new QMenu(tr("&File"), this);
|
||||
fileMenu->addAction(openAct);
|
||||
fileMenu->addAction(printAct);
|
||||
fileMenu->addSeparator();
|
||||
fileMenu->addAction(exitAct);
|
||||
|
||||
viewMenu = new QMenu(tr("&View"), this);
|
||||
viewMenu->addAction(zoomInAct);
|
||||
viewMenu->addAction(zoomOutAct);
|
||||
viewMenu->addAction(normalSizeAct);
|
||||
viewMenu->addSeparator();
|
||||
viewMenu->addAction(fitToWindowAct);
|
||||
viewMenu = new QMenu(tr("&View"), this);
|
||||
viewMenu->addAction(zoomInAct);
|
||||
viewMenu->addAction(zoomOutAct);
|
||||
viewMenu->addAction(normalSizeAct);
|
||||
viewMenu->addSeparator();
|
||||
viewMenu->addAction(fitToWindowAct);
|
||||
|
||||
helpMenu = new QMenu(tr("&Help"), this);
|
||||
helpMenu->addAction(aboutAct);
|
||||
helpMenu->addAction(aboutQtAct);
|
||||
helpMenu = new QMenu(tr("&Help"), this);
|
||||
helpMenu->addAction(aboutAct);
|
||||
helpMenu->addAction(aboutQtAct);
|
||||
|
||||
menuBar()->addMenu(fileMenu);
|
||||
menuBar()->addMenu(viewMenu);
|
||||
menuBar()->addMenu(helpMenu);
|
||||
}
|
||||
menuBar()->addMenu(fileMenu);
|
||||
menuBar()->addMenu(viewMenu);
|
||||
menuBar()->addMenu(helpMenu);
|
||||
}
|
||||
|
||||
void ImageViewer::updateActions()
|
||||
{
|
||||
zoomInAct->setEnabled(!fitToWindowAct->isChecked());
|
||||
zoomOutAct->setEnabled(!fitToWindowAct->isChecked());
|
||||
normalSizeAct->setEnabled(!fitToWindowAct->isChecked());
|
||||
}
|
||||
void ImageViewer::updateActions() {
|
||||
zoomInAct->setEnabled(!fitToWindowAct->isChecked());
|
||||
zoomOutAct->setEnabled(!fitToWindowAct->isChecked());
|
||||
normalSizeAct->setEnabled(!fitToWindowAct->isChecked());
|
||||
}
|
||||
|
||||
void ImageViewer::scaleImage(double factor)
|
||||
{
|
||||
Q_ASSERT(imageLabel->pixmap());
|
||||
scaleFactor *= factor;
|
||||
imageLabel->resize(scaleFactor * imageLabel->pixmap()->size());
|
||||
void ImageViewer::scaleImage(double factor) {
|
||||
Q_ASSERT(imageLabel->pixmap());
|
||||
scaleFactor *= factor;
|
||||
imageLabel->resize(scaleFactor * imageLabel->pixmap()->size());
|
||||
|
||||
adjustScrollBar(scrollArea->horizontalScrollBar(), factor);
|
||||
adjustScrollBar(scrollArea->verticalScrollBar(), factor);
|
||||
adjustScrollBar(scrollArea->horizontalScrollBar(), factor);
|
||||
adjustScrollBar(scrollArea->verticalScrollBar(), factor);
|
||||
|
||||
zoomInAct->setEnabled(scaleFactor < 3.0);
|
||||
zoomOutAct->setEnabled(scaleFactor > 0.333);
|
||||
}
|
||||
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)));
|
||||
}
|
||||
|
|
|
@ -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,61 +62,53 @@ class QTabWidget;
|
|||
class QPushButton;
|
||||
class QSpinBox;
|
||||
|
||||
class ImageViewer : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
class ImageViewer : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
private:
|
||||
// Beispiel für GUI Elemente
|
||||
QWidget* m_option_panel1;
|
||||
QVBoxLayout* m_option_layout1;
|
||||
|
||||
// Beispiel für GUI Elemente
|
||||
QWidget* m_option_panel1;
|
||||
QVBoxLayout* m_option_layout1;
|
||||
QWidget* m_option_panel2;
|
||||
QVBoxLayout* m_option_layout2;
|
||||
|
||||
QWidget* m_option_panel2;
|
||||
QVBoxLayout* m_option_layout2;
|
||||
QPushButton* button1;
|
||||
QPushButton* button2;
|
||||
QPushButton* button3;
|
||||
QPushButton* button4;
|
||||
QSpinBox* spinbox1;
|
||||
|
||||
QPushButton* button1;
|
||||
QPushButton* button2;
|
||||
QPushButton* button3;
|
||||
QPushButton* button4;
|
||||
QSpinBox* spinbox1;
|
||||
// hier können weitere GUI Objekte hin wie Buttons Slider etc.
|
||||
QSlider* lineSlider;
|
||||
|
||||
// hier können weitere GUI Objekte hin wie Buttons Slider etc.
|
||||
private slots:
|
||||
// Beispiel für einen Algorithmus
|
||||
void drawBlackLine();
|
||||
|
||||
QSlider* lineSlider;
|
||||
|
||||
private slots:
|
||||
|
||||
// Beispiel für einen Algorithmus
|
||||
void drawBlackLine();
|
||||
|
||||
// hier können weitere als SLOTS definierte Funktionen hin, die auf Knopfdruck etc. aufgerufen werden.
|
||||
void drawRainbowCross();
|
||||
void drawDiagonalCross();
|
||||
void acidTrippin();
|
||||
|
||||
void open();
|
||||
void print();
|
||||
void zoomIn();
|
||||
void zoomOut();
|
||||
void normalSize();
|
||||
void fitToWindow();
|
||||
void about();
|
||||
// hier können weitere als SLOTS definierte Funktionen hin, die auf Knopfdruck etc. aufgerufen werden.
|
||||
void drawRainbowCross();
|
||||
void drawDiagonalCross();
|
||||
void acidTrippin();
|
||||
|
||||
void open();
|
||||
void print();
|
||||
void zoomIn();
|
||||
void zoomOut();
|
||||
void normalSize();
|
||||
void fitToWindow();
|
||||
void about();
|
||||
|
||||
public:
|
||||
ImageViewer();
|
||||
bool loadFile(const QString &);
|
||||
void updateImageDisplay();
|
||||
|
||||
protected:
|
||||
public:
|
||||
ImageViewer();
|
||||
bool loadFile(const QString &);
|
||||
void updateImageDisplay();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent * event);
|
||||
|
||||
private:
|
||||
|
||||
void drawRainbowCross(int h);
|
||||
|
||||
private:
|
||||
void drawRainbowCross(int h);
|
||||
// in diesen Beiden Methoden sind Änderungen nötig bzw. sie dienen als
|
||||
// Vorlage für eigene Methoden.
|
||||
void generateControlPanels();
|
||||
|
@ -125,13 +117,13 @@ protected:
|
|||
void startLogging();
|
||||
void generateMainGui();
|
||||
|
||||
void createActions();
|
||||
void createMenus();
|
||||
void updateActions();
|
||||
void scaleImage(double factor);
|
||||
void adjustScrollBar(QScrollBar *scrollBar, double factor);
|
||||
void createActions();
|
||||
void createMenus();
|
||||
void updateActions();
|
||||
void scaleImage(double factor);
|
||||
void adjustScrollBar(QScrollBar *scrollBar, double factor);
|
||||
|
||||
void renewLogging();
|
||||
void renewLogging();
|
||||
|
||||
QTabWidget* tabWidget;
|
||||
QTextEdit* logBrowser;
|
||||
|
@ -141,27 +133,24 @@ protected:
|
|||
double scaleFactor;
|
||||
QImage* image;
|
||||
|
||||
|
||||
|
||||
std::fstream logFile;
|
||||
|
||||
#ifndef QT_NO_PRINTER
|
||||
QPrinter printer;
|
||||
#endif
|
||||
|
||||
QAction *openAct;
|
||||
QAction *printAct;
|
||||
QAction *exitAct;
|
||||
QAction *zoomInAct;
|
||||
QAction *zoomOutAct;
|
||||
QAction *normalSizeAct;
|
||||
QAction *fitToWindowAct;
|
||||
QAction *aboutAct;
|
||||
QAction *aboutQtAct;
|
||||
QAction *openAct;
|
||||
QAction *printAct;
|
||||
QAction *exitAct;
|
||||
QAction *zoomInAct;
|
||||
QAction *zoomOutAct;
|
||||
QAction *normalSizeAct;
|
||||
QAction *fitToWindowAct;
|
||||
QAction *aboutAct;
|
||||
QAction *aboutQtAct;
|
||||
|
||||
QMenu *fileMenu;
|
||||
QMenu *viewMenu;
|
||||
QMenu *helpMenu;
|
||||
};
|
||||
|
||||
#endif
|
||||
QMenu *fileMenu;
|
||||
QMenu *viewMenu;
|
||||
QMenu *helpMenu;
|
||||
};
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue