Skip to content

Commit

Permalink
image panel now shows an image, added mantises for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Wrzesinski committed Jun 23, 2020
1 parent 1952f8e commit cb17f3e
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 16 deletions.
20 changes: 11 additions & 9 deletions color_editor.pro
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
TEMPLATE = app

QT = core widgets gui
QT += widgets

INCLUDEPATH = src/
INCLUDEPATH += src/

SOURCES = src/main.cpp \
src/editor/mainwindow.cpp \
src/editor/image/imagepanel.cpp \
src/editor/tools/toolpanel.cpp
SOURCES += src/main.cpp \
src/editor/mainwindow.cpp \
src/editor/image/imagepanel.cpp \
src/editor/image/imagearea.cpp \
src/editor/tools/toolpanel.cpp

HEADERS = src/editor/mainwindow.cpp \
src/editor/image/imagepanel.cpp \
src/editor/tools/toolpanel.cpp
HEADERS += src/editor/mainwindow.hpp \
src/editor/image/imagepanel.hpp \
src/editor/image/imagearea.hpp \
src/editor/tools/toolpanel.hpp

TARGET = color_editor.exe
DESTDIR = build
Expand Down
Binary file added data/mantis100.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/mantis1000.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/mantis2322.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/mantis30.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/mantis300.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions src/editor/image/imagearea.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "./imagearea.hpp"

#include <QPainter>
#include <QTextStream>

namespace editor{
namespace image {

QTextStream out3(stdout);

image_area::image_area(QWidget* parent) : QWidget(parent) {

}

void image_area::load_image(QString filename) {
out3 << "loading" << Qt::endl;
if(img.load(filename))
out3 << "loaded" << Qt::endl;
else
out3 << "failed" << Qt::endl;

}

QSize image_area::sizeHint() const {
out3 << "sizehint" << Qt::endl;
return img.size();
}

void image_area::paintEvent(QPaintEvent *) {
// out3 << "paitevent" << Qt::endl;
QPainter painter(this);
painter.drawImage(img.rect(), img);
}



} // image
} // editor

30 changes: 30 additions & 0 deletions src/editor/image/imagearea.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include <QWidget>
#include <QPaintEvent>
#include <QImage>

namespace editor{
namespace image {

class image_area : public QWidget {
Q_OBJECT

public:
image_area(QWidget* parent);

void load_image(QString filename);

QSize sizeHint() const override;

protected:
void paintEvent(QPaintEvent *) override;

private:
QImage img;

}; // image_panel

} // image
} // editor

24 changes: 24 additions & 0 deletions src/editor/image/imagepanel.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
#include "./imagepanel.hpp"

#include <QVBoxLayout>
#include <QLabel>
#include <QPixmap>

#include <QTextStream>

namespace editor{
namespace image {

QTextStream out2(stdout);

image_panel::image_panel(QWidget* parent) : QWidget(parent) {
img_area = new image_area(this);
img_area->load_image("../data/mantis300.jpg");

QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(img_area);
setLayout(vbox);
}


} // image
} // editor
17 changes: 14 additions & 3 deletions src/editor/image/imagepanel.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
#pragma once

#include "./imagearea.hpp"

#include <QWidget>
#include <QString>

namespace editor::image {
namespace editor{
namespace image {

class image_panel : public QWidget {
Q_OBJECT

public:
image_panel(QWidget* parent);

private:
image_area *img_area;

}; // image_panel

} // editor::image

} // image
} // editor
27 changes: 27 additions & 0 deletions src/editor/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
#include "./mainwindow.hpp"
#include "image/imagepanel.hpp"
#include "tools/toolpanel.hpp"

#include <QGridLayout>

#include <QTextStream>
QTextStream out1(stdout);

editor::main_window::main_window() {
setWindowTitle("color editor");

// initialization
image_pan = new editor::image::image_panel(this);
//image_pan->load_image("../data/mantis300.jpg");
color_pan = new editor::tools::tool_panel(this, editor::tools::color);
select_pan = new editor::tools::tool_panel(this, editor::tools::select);

// connections


// layout stuff
QGridLayout *grid = new QGridLayout;
grid->addWidget(image_pan, 0, 0, 2, 1);
grid->addWidget(color_pan, 1, 0);
grid->addWidget(select_pan, 1, 1);
setLayout(grid);
}
12 changes: 10 additions & 2 deletions src/editor/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

#include "image/imagepanel.hpp"
#include "tools/toolpanel.hpp"
#include <QMainWindow>
#include <QWidget>

namespace editor {

class main_window : public QMainWindow {
class main_window : public QWidget {
Q_OBJECT

public:
main_window();

image::image_panel *image_pan;
tools::tool_panel *color_pan;
tools::tool_panel *select_pan;

}; // window

Expand Down
6 changes: 6 additions & 0 deletions src/editor/tools/toolpanel.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
#include "./toolpanel.hpp"

editor::tools::tool_panel::tool_panel(QWidget *parent, tool_type type)
: QWidget(parent) {
if (type == editor::tools::select)
return;
}
6 changes: 5 additions & 1 deletion src/editor/tools/toolpanel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

namespace editor::tools {

enum tool_type {color, select};

class tool_panel : public QWidget {
Q_OBJECT

public:
tool_panel(QWidget *parent, tool_type type);
}; // tool_panel

} // editor::image

1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ int main(int argc, char **argv) {
QApplication app(argc, argv);

editor::main_window window;
window.setWindowTitle("color editor");
window.show();

return app.exec();
Expand Down

0 comments on commit cb17f3e

Please sign in to comment.