diff --git a/.drone.yml b/.drone.yml index a543ea8..379ce83 100644 --- a/.drone.yml +++ b/.drone.yml @@ -17,10 +17,7 @@ build: - cp /mingw$$arch/bin/libicudt*.dll dependencies/ - cp /mingw$$arch/bin/libicuin*.dll dependencies/ - cp /mingw$$arch/bin/libicuuc*.dll dependencies/ - - ls -al dependencies/ - for file in dependencies/lib* ; do mv "$file" "${file/lib/}" ; done - - ls -al dependencies/ - - ls -al $PWD/dependencies/ - PATH=$PATH:$PWD/dependencies # Deployment - mkdir deploy diff --git a/.travis.yml b/.travis.yml index 7be99fb..8dd5ee9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,6 @@ script: - qmake -v - qmake -config release EzGraver.pro - make - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ls -alR ; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sudo make install ; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then macdeployqt EzGraverUi/EzGraverUi.app -dmg ; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then mv EzGraverUi/EzGraverUi.dmg EzGraverUi/EzGraver_osx.dmg; fi diff --git a/EzGraverUi/EzGraverUi.pro b/EzGraverUi/EzGraverUi.pro index 72393eb..cf545f3 100644 --- a/EzGraverUi/EzGraverUi.pro +++ b/EzGraverUi/EzGraverUi.pro @@ -18,10 +18,12 @@ TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp \ - clicklabel.cpp + clicklabel.cpp \ + imagelabel.cpp HEADERS += mainwindow.h \ - clicklabel.h + clicklabel.h \ + imagelabel.h FORMS += mainwindow.ui diff --git a/EzGraverUi/clicklabel.cpp b/EzGraverUi/clicklabel.cpp index 661f7bf..90f69e1 100644 --- a/EzGraverUi/clicklabel.cpp +++ b/EzGraverUi/clicklabel.cpp @@ -2,7 +2,7 @@ #include -ClickLabel::ClickLabel(QWidget* parent) : QLabel(parent) {} +ClickLabel::ClickLabel(QWidget* parent) : QLabel{parent} {} ClickLabel::~ClickLabel() {} void ClickLabel::mouseReleaseEvent(QMouseEvent*) { diff --git a/EzGraverUi/clicklabel.h b/EzGraverUi/clicklabel.h index e57dc76..359e271 100644 --- a/EzGraverUi/clicklabel.h +++ b/EzGraverUi/clicklabel.h @@ -16,6 +16,10 @@ class ClickLabel : public QLabel { * \param parent The parent of the label. */ explicit ClickLabel(QWidget* parent=NULL); + + /*! + * Frees all required resources upon deconstruction. + */ virtual ~ClickLabel(); signals: diff --git a/EzGraverUi/imagelabel.cpp b/EzGraverUi/imagelabel.cpp new file mode 100644 index 0000000..32b995d --- /dev/null +++ b/EzGraverUi/imagelabel.cpp @@ -0,0 +1,45 @@ +#include "imagelabel.h" + +#include + +ImageLabel::ImageLabel(QWidget* parent) : ClickLabel{parent}, _image{}, _flags{Qt::DiffuseDither} {} +ImageLabel::~ImageLabel() {} + +QImage ImageLabel::image() const { + return _image; +} + +void ImageLabel::setImage(QImage const& image) { + _image = image; + updateDisplayedImage(); + emit imageLoadedChanged(true); + emit imageChanged(image); +} + +Qt::ImageConversionFlags ImageLabel::conversionFlags() const { + return _flags; +} + +void ImageLabel::setConversionFlags(Qt::ImageConversionFlags const& flags) { + _flags = flags; + updateDisplayedImage(); + emit conversionFlagsChanged(flags); +} + +void ImageLabel::updateDisplayedImage() { + if(!imageLoaded()) { + return; + } + + // Draw white background, otherwise transparency is converted to black. + QImage image{QSize{512, 512}, QImage::Format_ARGB32}; + image.fill(QColor{Qt::white}); + QPainter painter{&image}; + painter.drawImage(0, 0, _image.scaled(image.size())); + + setPixmap(QPixmap::fromImage(image.convertToFormat(QImage::Format_Mono, _flags))); +} + +bool ImageLabel::imageLoaded() const { + return !_image.isNull(); +} diff --git a/EzGraverUi/imagelabel.h b/EzGraverUi/imagelabel.h new file mode 100644 index 0000000..e54edbb --- /dev/null +++ b/EzGraverUi/imagelabel.h @@ -0,0 +1,90 @@ +#ifndef IMAGELABEL_H +#define IMAGELABEL_H + +#include "clicklabel.h" + +class ImageLabel : public ClickLabel { + Q_OBJECT + Q_PROPERTY(QImage image READ image WRITE setImage NOTIFY imageChanged) + Q_PROPERTY(Qt::ImageConversionFlags conversionFlags READ conversionFlags WRITE setConversionFlags NOTIFY conversionFlagsChanged) + Q_PROPERTY(bool imageLoaded READ imageLoaded NOTIFY imageLoadedChanged) + +public: + /*! + * Creates a new instance with the given \a parent. + * + * \param parent The parent of the label. + */ + explicit ImageLabel(QWidget* parent=NULL); + + /*! + * Frees all required resources upon deconstruction. + */ + virtual ~ImageLabel(); + + /*! + * Gets the currently loaded image without the application of + * any conversion. + * + * \return The currently loaded image. + */ + QImage image() const; + + /*! + * Changes the currently displayed image to the given image + * and applies the selected conversion method. + * + * \param image The image to load. + */ + void setImage(QImage const& image); + + /*! + * Gets the currently selected conversion flags. + * + * \return The currently selected conversion flags. + */ + Qt::ImageConversionFlags conversionFlags() const; + + /*! + * Changes the applied conversion flags to the given one and + * updates the currently displayed image. + * + * \param flags The conversion flags to use. + */ + void setConversionFlags(Qt::ImageConversionFlags const& flags); + + /*! + * Gets if an image has been loaded. + * + * \return Returns \c true if an image is loaded. + */ + bool imageLoaded() const; +signals: + /*! + * Fired as soon as the image has been changed. + * + * \param image The new image in its original state (unconverted). + */ + void imageChanged(QImage const& image); + + /*! + * Fired as soon as the conversion flags hav been changed. + * + * \param flags The newly applied conversion flags. + */ + void conversionFlagsChanged(Qt::ImageConversionFlags const& flags); + + /*! + * Fired as soon as an image has been loaded. + * + * \param imageLoaded \c true if an image is loaded. + */ + void imageLoadedChanged(bool imageLoaded); +private: + QImage _image; + Qt::ImageConversionFlags _flags; + + void updateDisplayedImage(); +}; + +#endif // IMAGELABEL_H diff --git a/EzGraverUi/main.cpp b/EzGraverUi/main.cpp index e816734..5e0dc5a 100644 --- a/EzGraverUi/main.cpp +++ b/EzGraverUi/main.cpp @@ -2,8 +2,7 @@ #include #include -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); diff --git a/EzGraverUi/mainwindow.cpp b/EzGraverUi/mainwindow.cpp index 9b8905f..d855620 100644 --- a/EzGraverUi/mainwindow.cpp +++ b/EzGraverUi/mainwindow.cpp @@ -13,14 +13,15 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow{parent}, _ui{new Ui::MainWindow}, - _portTimer{}, _ezGraver{}, _connected{false}, _imageLoaded{false} { + _portTimer{}, _image{}, _ezGraver{}, _connected{false} { _ui->setupUi(this); setAcceptDrops(true); connect(&_portTimer, &QTimer::timeout, this, &MainWindow::updatePorts); _portTimer.start(1000); - setupBindings(); + initBindings(); + initConversionFlags(); setConnected(false); } @@ -28,7 +29,7 @@ MainWindow::~MainWindow() { delete _ui; } -void MainWindow::setupBindings() { +void MainWindow::initBindings() { connect(_ui->burnTime, &QSlider::valueChanged, [this](int const& v) { _ui->burnTimeLabel->setText(QString::number(v)); }); connect(this, &MainWindow::connectedChanged, _ui->ports, &QComboBox::setDisabled); @@ -45,10 +46,20 @@ void MainWindow::setupBindings() { connect(this, &MainWindow::connectedChanged, _ui->start, &QPushButton::setEnabled); connect(this, &MainWindow::connectedChanged, _ui->pause, &QPushButton::setEnabled); connect(this, &MainWindow::connectedChanged, _ui->reset, &QPushButton::setEnabled); + connect(_ui->conversionFlags, static_cast(&QComboBox::currentIndexChanged), [this](int index) { + _ui->image->setConversionFlags(static_cast(_ui->conversionFlags->itemData(index).toInt())); + }); - auto uploadEnabled = [this]() { _ui->upload->setEnabled(_imageLoaded && _connected); }; + auto uploadEnabled = [this]() { _ui->upload->setEnabled(_ui->image->imageLoaded() && _connected); }; connect(this, &MainWindow::connectedChanged, uploadEnabled); - connect(this, &MainWindow::imageLoadedChanged, uploadEnabled); + connect(_ui->image, &ImageLabel::imageLoadedChanged, uploadEnabled); +} + +void MainWindow::initConversionFlags() { + _ui->conversionFlags->addItem("DiffuseDither", Qt::DiffuseDither); + _ui->conversionFlags->addItem("OrderedDither", Qt::OrderedDither); + _ui->conversionFlags->addItem("ThresholdDither", Qt::ThresholdDither); + _ui->conversionFlags->setCurrentIndex(0); } void MainWindow::printVerbose(QString const& verbose) { @@ -76,10 +87,8 @@ void MainWindow::loadImage(QString const& fileName) { printVerbose("failed to load image"); return; } - image = image.scaled(512, 512).convertToFormat(QImage::Format_Mono); - _ui->image->setPixmap(QPixmap::fromImage(image)); - setImageLoaded(true); + _ui->image->setImage(image); } bool MainWindow::connected() const { @@ -91,15 +100,6 @@ void MainWindow::setConnected(bool connected) { emit connectedChanged(connected); } -bool MainWindow::imageLoaded() const { - return _imageLoaded; -} - -void MainWindow::setImageLoaded(bool imageLoaded) { - _imageLoaded = imageLoaded; - emit imageLoadedChanged(imageLoaded); -} - void MainWindow::on_connect_clicked() { try { printVerbose(QString("connecting to port %1").arg(_ui->ports->currentText())); @@ -178,8 +178,10 @@ void MainWindow::on_disconnect_clicked() { } void MainWindow::on_image_clicked() { - auto fileName = QFileDialog::getOpenFileName(this, "Open Image", "", "Image Files (*.png *.jpeg *.jpg *.bmp)"); - loadImage(fileName); + auto fileName = QFileDialog::getOpenFileName(this, "Open Image", "", "Images (*.png *.jpeg *.jpg *.bmp)"); + if(!fileName.isNull()) { + loadImage(fileName); + } } void MainWindow::dragEnterEvent(QDragEnterEvent* event) { diff --git a/EzGraverUi/mainwindow.h b/EzGraverUi/mainwindow.h index 500b664..70253ce 100644 --- a/EzGraverUi/mainwindow.h +++ b/EzGraverUi/mainwindow.h @@ -15,17 +15,14 @@ class MainWindow; class MainWindow : public QMainWindow { Q_OBJECT Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged) - Q_PROPERTY(bool imageLoaded READ imageLoaded NOTIFY imageLoadedChanged) public: explicit MainWindow(QWidget* parent = NULL); ~MainWindow(); bool connected() const; - bool imageLoaded() const; signals: void connectedChanged(bool connected); - void imageLoadedChanged(bool connected); private slots: void on_connect_clicked(); @@ -52,14 +49,15 @@ private slots: private: Ui::MainWindow* _ui; QTimer _portTimer; + QImage _image; std::shared_ptr _ezGraver; bool _connected; - bool _imageLoaded; - void setupBindings(); + void initBindings(); + void initConversionFlags(); + void setConnected(bool connected); - void setImageLoaded(bool imageLoaded); void printVerbose(QString const& verbose); void loadImage(QString const& fileName); }; diff --git a/EzGraverUi/mainwindow.ui b/EzGraverUi/mainwindow.ui index 55eed3c..01ad2a1 100644 --- a/EzGraverUi/mainwindow.ui +++ b/EzGraverUi/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 1078 - 627 + 1086 + 654 @@ -18,7 +18,7 @@ - + 0 @@ -43,8 +43,8 @@ - - + + @@ -66,7 +66,7 @@ - + @@ -82,6 +82,23 @@ + + + + + + + Conversion flags + + + + + + + Burn time + + + @@ -386,7 +403,7 @@ 0 0 - 1078 + 1086 21 @@ -404,12 +421,9 @@ - ClickLabel + ImageLabel QLabel -
clicklabel.h
- - clicked() - +
imagelabel.h
diff --git a/README.md b/README.md index 3b3a988..fc2e922 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ + +| Linux / OSX | Windows | Latest | +|-------------|---------|---------| +|[![Travis Build Status](https://travis-ci.org/camrein/EzGraver.svg?branch=master)](https://travis-ci.org/camrein/EzGraver)|[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/g98wrysmliq4t8d9/branch/master?svg=true)](https://ci.appveyor.com/project/camrein/ezgraver)|[![Latest GitHub Release](https://img.shields.io/github/release/camrein/EzGraver.svg?maxAge=3600)](https://github.com/camrein/EzGraver/releases/latest)| + # About EzGraver is an open source software allowing users to use with laser engravers by NEJE. It supports Linux, OSX and Windows. It provides both a command line interface and a graphical user interface. The latest release is available on the [releases page](https://github.com/camrein/EzGraver/releases/latest). @@ -18,22 +23,16 @@ Available options: u - Uploads the given image to the engraver ``` -# Build Status -| Linux / OSX | Windows | -|-------------|---------| -|[![Build Status](https://travis-ci.org/camrein/EzGraver.svg?branch=master)](https://travis-ci.org/camrein/EzGraver)|[![Build Status](https://ci.appveyor.com/api/projects/status/g98wrysmliq4t8d9/branch/master?svg=true)](https://ci.appveyor.com/project/camrein/ezgraver/branch/master)| - - # Building -EzGraver was developed with QT 5.7. The lowest known API-Requirement is [QT 5.4](http://doc.qt.io/qt-5.7/qtimer.html#singleShot-4). Continuous integration on Travis-CI and Tea-CI is done with at least QT 5.5. +EzGraver was developed with QT 5.7. The lowest known API-Requirement is [QT 5.4](http://doc.qt.io/qt-5.7/qtimer.html#singleShot-4). Continuous integration on Travis-CI, Tea-CI and AppVeyor is done with at least QT 5.5. ## Windows Download the latest QT release and build it using QT Creator. Builds have been tested on the following kits: - Desktop QT 5.7.0 MinGW 32bit -- Desktop QT 5.7.0 MSVC2015_64bit +- Desktop QT 5.7.0 MSVC2015 64bit ## OS X -First install at a sufficient QT version. In this example, QT 5.5 is being installed. +First install a sufficient QT version. In this example, QT 5.5 is being installed. ```bash brew update brew install qt55