diff --git a/IntelliPhoto/Scribble/mainwindow.cpp b/IntelliPhoto/Scribble/IntelliPhotoGui.cpp similarity index 78% rename from IntelliPhoto/Scribble/mainwindow.cpp rename to IntelliPhoto/Scribble/IntelliPhotoGui.cpp index 817eef6..e608c5f 100644 --- a/IntelliPhoto/Scribble/mainwindow.cpp +++ b/IntelliPhoto/Scribble/IntelliPhotoGui.cpp @@ -1,12 +1,12 @@ -// ---------- mainwindow.cpp ---------- +// ---------- IntelliPhotoGui.cpp ---------- #include -#include "mainwindow.h" -#include "scribblearea.h" +#include "IntelliPhotoGui.h" +#include "PaintingArea.h" -// MainWindow constructor -MainWindow::MainWindow() +// IntelliPhotoGui constructor +IntelliPhotoGui::IntelliPhotoGui() { //create Gui elemnts and lay them out createGui(); @@ -23,7 +23,7 @@ MainWindow::MainWindow() // User tried to close the app -void MainWindow::closeEvent(QCloseEvent *event) +void IntelliPhotoGui::closeEvent(QCloseEvent *event) { // If they try to close maybeSave() returns true // if no changes have been made and the app closes @@ -38,7 +38,7 @@ void MainWindow::closeEvent(QCloseEvent *event) // Check if the current image has been changed and then // open a dialog to open a file -void MainWindow::open() +void IntelliPhotoGui::open() { // Check if changes have been made since last save // maybeSave() returns true if no changes have been made @@ -53,12 +53,12 @@ void MainWindow::open() // If we have a file name load the image and place // it in the scribbleArea if (!fileName.isEmpty()) - scribbleArea->openImage(fileName); + paintingArea->openImage(fileName); } } // Called when the user clicks Save As in the menu -void MainWindow::save() +void IntelliPhotoGui::save() { // A QAction represents the action of the user clicking QAction *action = qobject_cast(sender()); @@ -71,18 +71,18 @@ void MainWindow::save() } // Opens a dialog to change the pen color -void MainWindow::penColor() +void IntelliPhotoGui::penColor() { // Store the chosen color from the dialog - QColor newColor = QColorDialog::getColor(scribbleArea->penColor()); + QColor newColor = QColorDialog::getColor(paintingArea->penColor()); // If a valid color set it if (newColor.isValid()) - scribbleArea->setPenColor(newColor); + paintingArea->setPenColor(newColor); } // Opens a dialog that allows the user to change the pen width -void MainWindow::penWidth() +void IntelliPhotoGui::penWidth() { // Stores button value bool ok; @@ -91,28 +91,28 @@ void MainWindow::penWidth() // the next tr is the text to display // Get the current pen width // Define the min, max, step and ok button - int newWidth = QInputDialog::getInt(this, tr("Scribble"), + int newWidth = QInputDialog::getInt(this, tr("Painting"), tr("Select pen width:"), - scribbleArea->penWidth(), + paintingArea->penWidth(), 1, 500, 1, &ok); // Change the pen width if (ok) - scribbleArea->setPenWidth(newWidth); + paintingArea->setPenWidth(newWidth); } // Open an about dialog -void MainWindow::about() +void IntelliPhotoGui::about() { // Window title and text to display - QMessageBox::about(this, tr("About Scribble"), - tr("

The Scribble example is awesome

")); + QMessageBox::about(this, tr("About Painting"), + tr("

The Painting example is awesome

")); } // Define menu actions that call functions -void MainWindow::createActions() +void IntelliPhotoGui::createActions() { //connect signal and slots of gui element - connect(this->clearButton, SIGNAL(clicked()), scribbleArea, SLOT(clearImage())); + connect(this->clearButton, SIGNAL(clicked()), paintingArea, SLOT(clearImage())); // Create the action tied to the menu openAct = new QAction(tr("&Open..."), this); @@ -120,7 +120,7 @@ void MainWindow::createActions() // Define the associated shortcut key openAct->setShortcuts(QKeySequence::Open); - // Tie the action to MainWindow::open() + // Tie the action to IntelliPhotoGui::open() connect(openAct, SIGNAL(triggered()), this, SLOT(open())); // Get a list of the supported file formats @@ -134,7 +134,7 @@ void MainWindow::createActions() // Set an action for each file format action->setData(format); - // When clicked call MainWindow::save() + // When clicked call IntelliPhotoGui::save() connect(action, SIGNAL(triggered()), this, SLOT(save())); // Attach each file format option menu item to Save As @@ -142,36 +142,36 @@ void MainWindow::createActions() } - // Create exit action and tie to MainWindow::close() + // Create exit action and tie to IntelliPhotoGui::close() exitAct = new QAction(tr("E&xit"), this); exitAct->setShortcuts(QKeySequence::Quit); connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); - // Create pen color action and tie to MainWindow::penColor() + // Create pen color action and tie to IntelliPhotoGui::penColor() penColorAct = new QAction(tr("&Pen Color..."), this); connect(penColorAct, SIGNAL(triggered()), this, SLOT(penColor())); - // Create pen width action and tie to MainWindow::penWidth() + // Create pen width action and tie to IntelliPhotoGui::penWidth() penWidthAct = new QAction(tr("Pen &Width..."), this); connect(penWidthAct, SIGNAL(triggered()), this, SLOT(penWidth())); - // Create clear screen action and tie to MainWindow::clearImage() + // Create clear screen action and tie to IntelliPhotoGui::clearImage() clearScreenAct = new QAction(tr("&Clear Screen"), this); clearScreenAct->setShortcut(tr("Ctrl+L")); connect(clearScreenAct, SIGNAL(triggered()), - scribbleArea, SLOT(clearImage())); + paintingArea, SLOT(clearImage())); - // Create about action and tie to MainWindow::about() + // Create about action and tie to IntelliPhotoGui::about() aboutAct = new QAction(tr("&About"), this); connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); - // Create about Qt action and tie to MainWindow::aboutQt() + // Create about Qt action and tie to IntelliPhotoGui::aboutQt() aboutQtAct = new QAction(tr("About &Qt"), this); connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); } // Create the menubar -void MainWindow::createMenus() +void IntelliPhotoGui::createMenus() { // Create Save As option and the list of file types saveAsMenu = new QMenu(tr("&Save As"), this); @@ -203,7 +203,7 @@ void MainWindow::createMenus() menuBar()->addMenu(helpMenu); } -void MainWindow::createGui(){ +void IntelliPhotoGui::createGui(){ //create a central widget to work on centralGuiWidget = new QWidget(this); setCentralWidget(centralGuiWidget); @@ -214,14 +214,14 @@ void MainWindow::createGui(){ //create Gui elements clearButton = new QPushButton("Clear"); - scribbleArea = new ScribbleArea(); + paintingArea = new PaintingArea(); //set gui elemtns position - mainLayout->addWidget(scribbleArea,0,0,10,10); + mainLayout->addWidget(paintingArea,0,0,10,10); mainLayout->addWidget(clearButton,0,10,1,1); } -void MainWindow::setIntelliStyle(){ +void IntelliPhotoGui::setIntelliStyle(){ // Set the title setWindowTitle("IntelliPhoto Prototype"); //set style sheet @@ -230,15 +230,15 @@ void MainWindow::setIntelliStyle(){ this->menuBar()->setStyleSheet("color:rgb(255,255,255)"); } -bool MainWindow::maybeSave() +bool IntelliPhotoGui::maybeSave() { // Check for changes since last save - if (scribbleArea->isModified()) { + if (paintingArea->isModified()) { QMessageBox::StandardButton ret; // Scribble is the title // Add text and the buttons - ret = QMessageBox::warning(this, tr("Scribble"), + ret = QMessageBox::warning(this, tr("Painting"), tr("The image has been modified.\n" "Do you want to save your changes?"), QMessageBox::Save | QMessageBox::Discard @@ -256,7 +256,7 @@ bool MainWindow::maybeSave() return true; } -bool MainWindow::saveFile(const QByteArray &fileFormat) +bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat) { // Define path, name and default file type QString initialPath = QDir::currentPath() + "/untitled." + fileFormat; @@ -275,7 +275,7 @@ bool MainWindow::saveFile(const QByteArray &fileFormat) } else { // Call for the file to be saved - return scribbleArea->saveImage(fileName, fileFormat.constData()); + return paintingArea->saveImage(fileName, fileFormat.constData()); } } diff --git a/IntelliPhoto/Scribble/mainwindow.h b/IntelliPhoto/Scribble/IntelliPhotoGui.h similarity index 89% rename from IntelliPhoto/Scribble/mainwindow.h rename to IntelliPhoto/Scribble/IntelliPhotoGui.h index 97a21df..9e5053a 100644 --- a/IntelliPhoto/Scribble/mainwindow.h +++ b/IntelliPhoto/Scribble/IntelliPhotoGui.h @@ -1,5 +1,5 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H +#ifndef IntelliPhotoGui_H +#define IntelliPhotoGui_H #include #include @@ -7,9 +7,9 @@ #include // ScribbleArea used to paint the image -class ScribbleArea; +class PaintingArea; -class MainWindow : public QMainWindow +class IntelliPhotoGui : public QMainWindow { // Declares our class as a QObject which is the base class // for all Qt objects @@ -17,7 +17,7 @@ class MainWindow : public QMainWindow Q_OBJECT public: - MainWindow(); + IntelliPhotoGui(); protected: // Function used to close an event void closeEvent(QCloseEvent *event) override; @@ -48,7 +48,7 @@ private: bool saveFile(const QByteArray &fileFormat); // What we'll draw on - ScribbleArea *scribbleArea; + PaintingArea *paintingArea; // The menu widgets QMenu *saveAsMenu; diff --git a/IntelliPhoto/Scribble/scribblearea.cpp b/IntelliPhoto/Scribble/PaintingArea.cpp similarity index 83% rename from IntelliPhoto/Scribble/scribblearea.cpp rename to IntelliPhoto/Scribble/PaintingArea.cpp index 5619906..695879e 100644 --- a/IntelliPhoto/Scribble/scribblearea.cpp +++ b/IntelliPhoto/Scribble/PaintingArea.cpp @@ -1,9 +1,9 @@ -// ---------- scribblearea.cpp ---------- +// ---------- PaintingArea.cpp ---------- #include -#include "scribblearea.h" +#include "PaintingArea.h" -ScribbleArea::ScribbleArea(QWidget *parent) +PaintingArea::PaintingArea(QWidget *parent) : QWidget(parent) { // Roots the widget to the top left even if resized @@ -17,7 +17,7 @@ ScribbleArea::ScribbleArea(QWidget *parent) } // Used to load the image and place it in the widget -bool ScribbleArea::openImage(const QString &fileName) +bool PaintingArea::openImage(const QString &fileName) { // Holds the image QImage loadedImage; @@ -35,7 +35,7 @@ bool ScribbleArea::openImage(const QString &fileName) } // Save the current image -bool ScribbleArea::saveImage(const QString &fileName, const char *fileFormat) +bool PaintingArea::saveImage(const QString &fileName, const char *fileFormat) { // Created to hold the image QImage visibleImage = image; @@ -50,19 +50,19 @@ bool ScribbleArea::saveImage(const QString &fileName, const char *fileFormat) } // Used to change the pen color -void ScribbleArea::setPenColor(const QColor &newColor) +void PaintingArea::setPenColor(const QColor &newColor) { myPenColor = newColor; } // Used to change the pen width -void ScribbleArea::setPenWidth(int newWidth) +void PaintingArea::setPenWidth(int newWidth) { myPenWidth = newWidth; } // Color the image area with white -void ScribbleArea::clearImage() +void PaintingArea::clearImage() { image.fill(qRgb(255, 255, 255)); modified = true; @@ -72,7 +72,7 @@ void ScribbleArea::clearImage() // If a mouse button is pressed check if it was the // left button and if so store the current position // Set that we are currently drawing -void ScribbleArea::mousePressEvent(QMouseEvent *event) +void PaintingArea::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { lastPoint = event->pos(); @@ -83,14 +83,14 @@ void ScribbleArea::mousePressEvent(QMouseEvent *event) // When the mouse moves if the left button is clicked // we call the drawline function which draws a line // from the last position to the current -void ScribbleArea::mouseMoveEvent(QMouseEvent *event) +void PaintingArea::mouseMoveEvent(QMouseEvent *event) { if ((event->buttons() & Qt::LeftButton) && scribbling) drawLineTo(event->pos()); } // If the button is released we set variables to stop drawing -void ScribbleArea::mouseReleaseEvent(QMouseEvent *event) +void PaintingArea::mouseReleaseEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton && scribbling) { drawLineTo(event->pos()); @@ -101,7 +101,7 @@ void ScribbleArea::mouseReleaseEvent(QMouseEvent *event) // QPainter provides functions to draw on the widget // The QPaintEvent is sent to widgets that need to // update themselves -void ScribbleArea::paintEvent(QPaintEvent *event) +void PaintingArea::paintEvent(QPaintEvent *event) { QPainter painter(this); @@ -115,7 +115,7 @@ void ScribbleArea::paintEvent(QPaintEvent *event) // Resize the image to slightly larger then the main window // to cut down on the need to resize the image -void ScribbleArea::resizeEvent(QResizeEvent *event) +void PaintingArea::resizeEvent(QResizeEvent *event) { if (width() > image.width() || height() > image.height()) { int newWidth = qMax(width() + 128, image.width()); @@ -126,7 +126,7 @@ void ScribbleArea::resizeEvent(QResizeEvent *event) QWidget::resizeEvent(event); } -void ScribbleArea::drawLineTo(const QPoint &endPoint) +void PaintingArea::drawLineTo(const QPoint &endPoint) { // Used to draw on the widget QPainter painter(&image); @@ -153,7 +153,7 @@ void ScribbleArea::drawLineTo(const QPoint &endPoint) // When the app is resized create a new image using // the changes made to the image -void ScribbleArea::resizeImage(QImage *image, const QSize &newSize) +void PaintingArea::resizeImage(QImage *image, const QSize &newSize) { // Check if we need to redraw the image if (image->size() == newSize) diff --git a/IntelliPhoto/Scribble/scribblearea.h b/IntelliPhoto/Scribble/PaintingArea.h similarity index 93% rename from IntelliPhoto/Scribble/scribblearea.h rename to IntelliPhoto/Scribble/PaintingArea.h index da47416..a15df2a 100644 --- a/IntelliPhoto/Scribble/scribblearea.h +++ b/IntelliPhoto/Scribble/PaintingArea.h @@ -1,4 +1,4 @@ -// ---------- scribblearea.h ---------- +// ---------- PaintingArea.h ---------- #ifndef SCRIBBLEAREA_H #define SCRIBBLEAREA_H @@ -8,7 +8,7 @@ #include #include -class ScribbleArea : public QWidget +class PaintingArea : public QWidget { // Declares our class as a QObject which is the base class // for all Qt objects @@ -16,7 +16,7 @@ class ScribbleArea : public QWidget Q_OBJECT public: - ScribbleArea(QWidget *parent = nullptr); + PaintingArea(QWidget *parent = nullptr); // Handles all events bool openImage(const QString &fileName); diff --git a/IntelliPhoto/Scribble/Scribble.pro b/IntelliPhoto/Scribble/Scribble.pro index 6117311..0234a76 100644 --- a/IntelliPhoto/Scribble/Scribble.pro +++ b/IntelliPhoto/Scribble/Scribble.pro @@ -16,13 +16,13 @@ DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ - main.cpp \ - mainwindow.cpp \ - scribblearea.cpp + IntelliPhotoGui.cpp \ + PaintingArea.cpp \ + main.cpp HEADERS += \ - mainwindow.h \ - scribblearea.h + IntelliPhotoGui.h \ + PaintingArea.h FORMS += \ widget.ui diff --git a/IntelliPhoto/Scribble/Scribble.pro.user b/IntelliPhoto/Scribble/Scribble.pro.user index 1c86583..572799d 100644 --- a/IntelliPhoto/Scribble/Scribble.pro.user +++ b/IntelliPhoto/Scribble/Scribble.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -306,8 +306,8 @@ 2 Scribble - - Qt4ProjectManager.Qt4RunConfiguration:C:/Users/jonas/OneDrive/Desktop/Scribble/Scribble.pro + Scribble2 + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/Scribble/Scribble.pro 3768 false diff --git a/IntelliPhoto/Scribble/main.cpp b/IntelliPhoto/Scribble/main.cpp index 6269b60..63e4ccd 100644 --- a/IntelliPhoto/Scribble/main.cpp +++ b/IntelliPhoto/Scribble/main.cpp @@ -4,7 +4,7 @@ // ---------- main.cpp ---------- -#include "mainwindow.h" +#include "IntelliPhotoGui.h" #include int main(int argc, char *argv[]) @@ -13,7 +13,7 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); // Create and open the main window - MainWindow window; + IntelliPhotoGui window; window.show(); // Display the main window