From 817d7b7d8db9a75cb3a8ffc05c9fc237706afc0e Mon Sep 17 00:00:00 2001 From: maifeeulasad Date: Fri, 18 Dec 2020 12:13:41 +0600 Subject: [PATCH 01/15] #18 flip; todo : works only once --- sources/additionaltools.cpp | 7 +++++-- sources/additionaltools.h | 2 +- sources/imagearea.cpp | 6 +++--- sources/imagearea.h | 2 +- sources/mainwindow.cpp | 38 ++++++++++++++++++++++++++++++++++++- sources/mainwindow.h | 4 ++++ 6 files changed, 51 insertions(+), 8 deletions(-) diff --git a/sources/additionaltools.cpp b/sources/additionaltools.cpp index 4a7b334..9848838 100644 --- a/sources/additionaltools.cpp +++ b/sources/additionaltools.cpp @@ -144,9 +144,12 @@ bool AdditionalTools::zoomImage(qreal factor) } } -bool AdditionalTools::rotateImage(int x, int y) +bool AdditionalTools::rotateImage(int x, int y,int z) { - QTransform transform = QTransform().rotate(x, Qt::Axis::XAxis).rotate(y, Qt::Axis::YAxis); + QTransform transform = QTransform() + .rotate(x, Qt::Axis::XAxis) + .rotate(y, Qt::Axis::YAxis) + .rotate(z,Qt::Axis::ZAxis); mPImageArea->setImage(mPImageArea->getImage()->transformed(transform)); mPImageArea->resize((mPImageArea->getImage()->rect().width()), (mPImageArea->getImage()->rect().height())); diff --git a/sources/additionaltools.h b/sources/additionaltools.h index bcf74f4..0cf18fe 100644 --- a/sources/additionaltools.h +++ b/sources/additionaltools.h @@ -85,7 +85,7 @@ class AdditionalTools : public QObject * @return returns true in case of success */ bool zoomImage(qreal factor); - bool rotateImage(int x,int y); + bool rotateImage(int x,int y,int z); private: ImageArea *mPImageArea; /**< A pointer to ImageArea */ diff --git a/sources/imagearea.cpp b/sources/imagearea.cpp index d19102e..e3f4f2b 100644 --- a/sources/imagearea.cpp +++ b/sources/imagearea.cpp @@ -341,9 +341,10 @@ void ImageArea::rotateImage(bool flag) emit sendNewImageSize(mImage->size()); } -void ImageArea::rotateImage(int x,int y) +void ImageArea::rotateImage(int x,int y,int z) { - mAdditionalTools->rotateImage(x,y); + mAdditionalTools->rotateImage(x,y,z); + emit sendNewImageSize(mImage->size()); } void ImageArea::applyEffect(EffectsEnum effect) @@ -424,7 +425,6 @@ void ImageArea::mouseMoveEvent(QMouseEvent *event) if(instrument != NONE_INSTRUMENT) { - //todo : fix segmentation-fault in color picker palette mInstrumentHandler->mouseMoveEvent(event, *this); } } diff --git a/sources/imagearea.h b/sources/imagearea.h index 5ff4577..8dbd952 100644 --- a/sources/imagearea.h +++ b/sources/imagearea.h @@ -97,7 +97,7 @@ class ImageArea : public QWidget * @param flag Rotate to left or to right. */ void rotateImage(bool flag); - void rotateImage(int x,int y); + void rotateImage(int x,int y,int z); inline QString getFileName() { return (mFilePath.isEmpty() ? mFilePath : mFilePath.split('/').last()); } diff --git a/sources/mainwindow.cpp b/sources/mainwindow.cpp index 138396e..b8662a2 100644 --- a/sources/mainwindow.cpp +++ b/sources/mainwindow.cpp @@ -54,6 +54,10 @@ A copy of the License : https://github.com/maifeeulasad/Paint/blob/main/LICENSE MainWindow::MainWindow(QStringList filePaths, QWidget *parent) : QMainWindow(parent), mPrevInstrumentSetted(false) { + mRotX = 0; + mRotY = 0; + mRotZ = 0; + QSize winSize = DataSingleton::Instance()->getWindowSize(); if (DataSingleton::Instance()->getIsRestoreWindowSize() && winSize.isValid()) { resize(winSize); @@ -394,6 +398,23 @@ void MainWindow::initializeMainMenu() mToolsMenu->addMenu(rotateMenu); + QMenu *flipMenu = new QMenu(tr("Flip")); + + QAction *flipVAction = new QAction(tr("Vertically"), this); + flipVAction->setIcon(QIcon::fromTheme("object-rotate-left", QIcon(":/media/actions-icons/object-rotate-left.png"))); + flipVAction->setIconVisibleInMenu(true); + connect(flipVAction, &QAction::triggered, this, &MainWindow::flipVerticalAct); + flipMenu->addAction(flipVAction); + + QAction *flipHAction = new QAction(tr("Horizontally"), this); + flipHAction->setIcon(QIcon::fromTheme("object-rotate-right", QIcon(":/media/actions-icons/object-rotate-right.png"))); + flipHAction->setIconVisibleInMenu(true); + connect(flipHAction, &QAction::triggered, this, &MainWindow::flipHorizontalAct); + flipMenu->addAction(flipHAction); + + mToolsMenu->addMenu(flipMenu); + + QMenu *zoomMenu = new QMenu(tr("Zoom")); mZoomInAction = new QAction(tr("Zoom In"), this); @@ -645,7 +666,22 @@ void MainWindow::rotateRightImageAct() getCurrentImageArea()->rotateImage(true); } -//todo : rotate degree input, or options +void MainWindow::rotateImageAct() +{ + getCurrentImageArea()->rotateImage(mRotX,mRotY,mRotZ); +} + +void MainWindow::flipVerticalAct() +{ + mRotX += 180; + getCurrentImageArea()->rotateImage(mRotX,mRotY,mRotZ); +} + +void MainWindow::flipHorizontalAct() +{ + mRotY += 180; + getCurrentImageArea()->rotateImage(mRotX,mRotY,mRotZ); +} void MainWindow::zoomInAct() { diff --git a/sources/mainwindow.h b/sources/mainwindow.h index 81278ba..db634e9 100644 --- a/sources/mainwindow.h +++ b/sources/mainwindow.h @@ -111,6 +111,7 @@ class MainWindow : public QMainWindow QMenu *mInstrumentsMenu, *mEffectsMenu, *mToolsMenu; QUndoGroup *mUndoStackGroup; bool mPrevInstrumentSetted; /**< Used for magnifier */ + int mRotX,mRotY,mRotZ; private slots: void activateTab(const int &index); void setNewSizeToSizeLabel(const QSize &size); @@ -133,6 +134,9 @@ private slots: void resizeCanvasAct(); void rotateLeftImageAct(); void rotateRightImageAct(); + void rotateImageAct(); + void flipVerticalAct(); + void flipHorizontalAct(); void zoomInAct(); void zoomOutAct(); void advancedZoomAct(); From 9779c0e230eb575bf9172a6c154d047e19d66367 Mon Sep 17 00:00:00 2001 From: maifeeulasad Date: Fri, 18 Dec 2020 14:24:19 +0600 Subject: [PATCH 02/15] #15 - style not working --- sources/main.cpp | 2 ++ .../actions-icons/object-flip-horizontal.png | Bin 0 -> 665 bytes .../media/actions-icons/object-flip-vertical.png | Bin 0 -> 720 bytes 3 files changed, 2 insertions(+) create mode 100644 sources/media/actions-icons/object-flip-horizontal.png create mode 100644 sources/media/actions-icons/object-flip-vertical.png diff --git a/sources/main.cpp b/sources/main.cpp index a2616d9..97f90f4 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -34,6 +34,7 @@ A copy of the License : https://github.com/maifeeulasad/Paint/blob/main/LICENSE #include #include #include +#include #include "mainwindow.h" #include "datasingleton.h" @@ -57,6 +58,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); a.setApplicationName("Paint"); a.setApplicationVersion("0.1.1"); + a.setStyle(QStyleFactory::create("Macintosh")); QStringList args = a.arguments(); diff --git a/sources/media/actions-icons/object-flip-horizontal.png b/sources/media/actions-icons/object-flip-horizontal.png new file mode 100644 index 0000000000000000000000000000000000000000..b9f414d584ed93e81cf7140e0f64e7e97d4c5fe2 GIT binary patch literal 665 zcmV;K0%rY*P)If46&1UlffQR!Cr5@S6e*!=N{l&A!7y{_o&vpx-wQiBDUZWyw zTI<%%0RWuDhAGwGDL|vqI8sU-uW7l{Xf%#?22dyzVsD?OCli3@d50ph@i!Kcmgjkg zxdQ;`k=)pCdwRJ7Xs!1}q@6TWMB1L`-OLSuWS68PS9PAC-w~0=xd6DXTOrv201=$Kt#@c-+z}Dz*Zk?Bozw~kD*mPEsoYW-;>GYmG z!LK|3;v{tqKt%dhD3kGc{5+50K)j@u0JPTo0A}y)+u?BdBQF48wWO8+7Nvu$S1;FE zC8;?;R62vfAjliQLM%yY4zPuE($}@M*00000NkvXXu0mjf)C(p_ literal 0 HcmV?d00001 diff --git a/sources/media/actions-icons/object-flip-vertical.png b/sources/media/actions-icons/object-flip-vertical.png new file mode 100644 index 0000000000000000000000000000000000000000..d94f8bfa1b04efec57b93ed50c68a765a37728de GIT binary patch literal 720 zcmV;>0x$iEP)H*q1VLNfq}ZhnP4{jR9K}sn9kn2$IOtNSkTjxpanb2YE0yZf zqIaKzxe{vHCh;!yHyy`&_y58B-h1Bx2gJz8$Z-HY>}F`8P)OOfJx+3lWFZX07hMs^ z=kvK-E;k8an&eRQUPOXK1w7BwB66GLB!DB$#v~%(dEO}znE^0C(%x%qtOAbXoK;HA z0w|JHt;~r-fX0|2$yt)4ZBOnrwV|R*B!@fwPTK;zRdnJ4tyFX(0_{|EtOA`>bQ}US z#uSxOB>-bdg+_?TW>5XO#~5=xI-`>gZr}+4z;T?bmSs(eNVhJhKtvXUAeie?-ha&Y z5|F%=WVP>LdkLa7kBac0j@5P%k;hH9;cgd;h Date: Fri, 18 Dec 2020 23:58:21 +0600 Subject: [PATCH 03/15] #28 - flip --- sources/additionaltools.cpp | 1 + sources/mainwindow.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sources/additionaltools.cpp b/sources/additionaltools.cpp index 9848838..9d818f0 100644 --- a/sources/additionaltools.cpp +++ b/sources/additionaltools.cpp @@ -153,6 +153,7 @@ bool AdditionalTools::rotateImage(int x, int y,int z) mPImageArea->setImage(mPImageArea->getImage()->transformed(transform)); mPImageArea->resize((mPImageArea->getImage()->rect().width()), (mPImageArea->getImage()->rect().height())); + mPImageArea->update(); mPImageArea->setEdited(true); mPImageArea->clearSelection(); return true; diff --git a/sources/mainwindow.cpp b/sources/mainwindow.cpp index 61c23a2..b9a7175 100644 --- a/sources/mainwindow.cpp +++ b/sources/mainwindow.cpp @@ -673,14 +673,14 @@ void MainWindow::rotateImageAct() void MainWindow::flipVerticalAct() { - mRotX += 180; - getCurrentImageArea()->rotateImage(mRotX,mRotY,mRotZ); + //mRotX += 180; + getCurrentImageArea()->rotateImage(180,0,0); } void MainWindow::flipHorizontalAct() { - mRotY += 180; - getCurrentImageArea()->rotateImage(mRotX,mRotY,mRotZ); + //mRotY += 180; + getCurrentImageArea()->rotateImage(0,180,0); } void MainWindow::zoomInAct() From e540f1d7d2e289d96dc8ab1b72bb85deb7ed7169 Mon Sep 17 00:00:00 2001 From: maifeeulasad Date: Sat, 19 Dec 2020 00:00:50 +0600 Subject: [PATCH 04/15] #28 - flip icon --- sources/mainwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/mainwindow.cpp b/sources/mainwindow.cpp index b9a7175..8588157 100644 --- a/sources/mainwindow.cpp +++ b/sources/mainwindow.cpp @@ -401,13 +401,13 @@ void MainWindow::initializeMainMenu() QMenu *flipMenu = new QMenu(tr("Flip")); QAction *flipVAction = new QAction(tr("Vertically"), this); - flipVAction->setIcon(QIcon::fromTheme("object-rotate-left", QIcon(":/media/actions-icons/object-rotate-left.png"))); + flipVAction->setIcon(QIcon::fromTheme("object-flip-vertical", QIcon(":/media/actions-icons/object-flip-vertical.png"))); flipVAction->setIconVisibleInMenu(true); connect(flipVAction, &QAction::triggered, this, &MainWindow::flipVerticalAct); flipMenu->addAction(flipVAction); QAction *flipHAction = new QAction(tr("Horizontally"), this); - flipHAction->setIcon(QIcon::fromTheme("object-rotate-right", QIcon(":/media/actions-icons/object-rotate-right.png"))); + flipHAction->setIcon(QIcon::fromTheme("object-flip-horizontal", QIcon(":/media/actions-icons/object-flip-horizontal.png"))); flipHAction->setIconVisibleInMenu(true); connect(flipHAction, &QAction::triggered, this, &MainWindow::flipHorizontalAct); flipMenu->addAction(flipHAction); From d172adfb4fae9ce7eae0667d7559e70a91bd662b Mon Sep 17 00:00:00 2001 From: maifeeulasad Date: Sat, 19 Dec 2020 00:07:01 +0600 Subject: [PATCH 05/15] refactor : color picker palette is written by me --- sources/instruments/colorpickerpaletteinstrument.cpp | 3 --- sources/instruments/colorpickerpaletteinstrument.h | 3 --- 2 files changed, 6 deletions(-) diff --git a/sources/instruments/colorpickerpaletteinstrument.cpp b/sources/instruments/colorpickerpaletteinstrument.cpp index 7c5916b..950fd33 100644 --- a/sources/instruments/colorpickerpaletteinstrument.cpp +++ b/sources/instruments/colorpickerpaletteinstrument.cpp @@ -3,9 +3,6 @@ MIT License Copyright (c) 2020 Maifee Ul Asad -Copyright (c) 2012 EasyPaint https://github.com/Gr1N/EasyPaint - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights diff --git a/sources/instruments/colorpickerpaletteinstrument.h b/sources/instruments/colorpickerpaletteinstrument.h index f3cbd56..bca5ddb 100644 --- a/sources/instruments/colorpickerpaletteinstrument.h +++ b/sources/instruments/colorpickerpaletteinstrument.h @@ -3,9 +3,6 @@ MIT License Copyright (c) 2020 Maifee Ul Asad -Copyright (c) 2012 EasyPaint https://github.com/Gr1N/EasyPaint - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights From 0eb13794854dd9069c80a4d6823e665031d79928 Mon Sep 17 00:00:00 2001 From: maifeeulasad Date: Sat, 19 Dec 2020 00:42:37 +0600 Subject: [PATCH 06/15] #22 - crop tool//wip --- sources/datasingleton.cpp | 3 +- sources/imagearea.cpp | 8 +- sources/instruments/cropinstrument.cpp | 226 +++++++++++++++++++++++ sources/instruments/cropinstrument.h | 94 ++++++++++ sources/josspaintenums.h | 1 + sources/mainwindow.cpp | 9 +- sources/media/instruments-icons/crop.png | Bin 0 -> 191 bytes sources/paint.pro | 2 + sources/resources.qrc | 1 + sources/widgets/toolbar.cpp | 2 + sources/widgets/toolbar.h | 2 +- 11 files changed, 343 insertions(+), 5 deletions(-) create mode 100644 sources/instruments/cropinstrument.cpp create mode 100644 sources/instruments/cropinstrument.h create mode 100644 sources/media/instruments-icons/crop.png diff --git a/sources/datasingleton.cpp b/sources/datasingleton.cpp index fbb0b2a..a3e91cb 100644 --- a/sources/datasingleton.cpp +++ b/sources/datasingleton.cpp @@ -96,7 +96,7 @@ void DataSingleton::readSetting() mInstrumentsShortcuts.insert("Ellipse", settings.value("/Shortcuts/Instruments/Ellipse", "Ctrl+0").value()); mInstrumentsShortcuts.insert("Curve", settings.value("/Shortcuts/Instruments/Curve", "").value()); mInstrumentsShortcuts.insert("Text", settings.value("/Shortcuts/Instruments/Text", "").value()); - // TODO: Add shortcuts for new instruments here + mInstrumentsShortcuts.insert("Crop", settings.value("/Shortcuts/Instruments/Crop", "").value()); //read shortcuts for tools menu mToolsShortcuts.insert("ZoomIn", settings.value("/Shortcuts/Tools/Zoom/ZoomIn", QKeySequence(QKeySequence::ZoomIn)).value()); @@ -141,6 +141,7 @@ void DataSingleton::writeSettings() settings.setValue("/Shortcuts/Instruments/Fill", mInstrumentsShortcuts["Fill"]); settings.setValue("/Shortcuts/Instruments/Rect", mInstrumentsShortcuts["Rect"]); settings.setValue("/Shortcuts/Instruments/Ellipse", mInstrumentsShortcuts["Ellipse"]); + settings.setValue("/Shortcuts/Instruments/Crop", mInstrumentsShortcuts["Crop"]); //write shortcuts for tools menu settings.setValue("/Shortcuts/Tools/Zoom/ZoomIn", mToolsShortcuts["ZoomIn"]); diff --git a/sources/imagearea.cpp b/sources/imagearea.cpp index e3f4f2b..213e54f 100644 --- a/sources/imagearea.cpp +++ b/sources/imagearea.cpp @@ -46,6 +46,7 @@ A copy of the License : https://github.com/maifeeulasad/Paint/blob/main/LICENSE #include "instruments/selectioninstrument.h" #include "instruments/curvelineinstrument.h" #include "instruments/textinstrument.h" +#include "instruments/cropinstrument.h" #include "dialogs/resizedialog.h" #include "effects/abstracteffect.h" @@ -155,6 +156,7 @@ ImageArea::ImageArea(const bool &isOpen, const QString &filePath, QWidget *paren mInstrumentsHandlers[COLORPICKERPALETTE] = new ColorpickerPaletteInstrument(this); mInstrumentsHandlers[CURVELINE] = new CurveLineInstrument(this); mInstrumentsHandlers[TEXT] = new TextInstrument(this); + mInstrumentsHandlers[CROP] = new CropInstrument(this); // Effects handlers mEffectsHandlers.fill(0, (int)EFFECTS_COUNT); @@ -506,6 +508,8 @@ void ImageArea::restoreCursor() mCurrentCursor = new QCursor(*mPixmap); setCursor(*mCurrentCursor); break; + case CROP: + break; } } @@ -516,7 +520,7 @@ void ImageArea::drawCursor() QPoint center(13, 13); switch(DataSingleton::Instance()->getInstrument()) { - case NONE_INSTRUMENT: case LINE: case COLORPICKERPALETTE: case MAGNIFIER: case SPRAY: + case NONE_INSTRUMENT: case LINE: case COLORPICKERPALETTE: case MAGNIFIER: case SPRAY: case CROP: case FILL: case RECTANGLE: case ELLIPSE: case CURSOR: case INSTRUMENTS_COUNT: case CURVELINE: case TEXT: break; @@ -528,7 +532,7 @@ void ImageArea::drawCursor() switch(DataSingleton::Instance()->getInstrument()) { case NONE_INSTRUMENT: case LINE: case COLORPICKERPALETTE: case MAGNIFIER: case SPRAY: - case FILL: case RECTANGLE: case ELLIPSE: case CURSOR: case INSTRUMENTS_COUNT: + case FILL: case RECTANGLE: case ELLIPSE: case CURSOR: case INSTRUMENTS_COUNT: case CROP: case CURVELINE: case TEXT: break; case PEN: diff --git a/sources/instruments/cropinstrument.cpp b/sources/instruments/cropinstrument.cpp new file mode 100644 index 0000000..6829f87 --- /dev/null +++ b/sources/instruments/cropinstrument.cpp @@ -0,0 +1,226 @@ +/* +MIT License + +Copyright (c) 2020 Maifee Ul Asad + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +GitHub repo : https://github.com/maifeeulasad/Paint + +A copy of the License : https://github.com/maifeeulasad/Paint/blob/main/LICENSE +*/ + +#include "cropinstrument.h" +#include "../imagearea.h" +#include "../undocommand.h" +#include "math.h" + +#include +#include +#include + +CropInstrument::CropInstrument(QObject *parent) : + AbstractSelection(parent) +{ +} + +void CropInstrument::copyImage(ImageArea &imageArea) +{ + if (mIsSelectionExists) + { + imageArea.setImage(mImageCopy); + QClipboard *globalClipboard = QApplication::clipboard(); + QImage copyImage; + if(mIsImageSelected) + { + copyImage = mSelectedImage; + } + else + { + copyImage = imageArea.getImage()->copy(mTopLeftPoint.x(), mTopLeftPoint.y(), mWidth, mHeight); + } + globalClipboard->setImage(copyImage, QClipboard::Clipboard); + } +} + +void CropInstrument::cutImage(ImageArea &imageArea) +{ + if (mIsSelectionExists) + { + copyImage(imageArea); + if(mIsSelectionExists) + { + imageArea.setImage(mImageCopy); + paint(imageArea); + } + makeUndoCommand(imageArea); + if (/*mSelectedImage != mPasteImage || !*/mIsImageSelected) + { + imageArea.setImage(mImageCopy); + } + else + { + clearSelectionBackground(imageArea); + } + mTopLeftPoint = QPoint(0, 0); + mBottomRightPoint = QPoint(0, 0); + mImageCopy = *imageArea.getImage(); + imageArea.update(); + mIsSelectionExists = false; + imageArea.restoreCursor(); + emit sendEnableCopyCutActions(false); + } +} + +void CropInstrument::pasteImage(ImageArea &imageArea) +{ + QClipboard *globalClipboard = QApplication::clipboard(); + if(mIsSelectionExists) + { + imageArea.setImage(mImageCopy); + paint(imageArea); + mImageCopy = *imageArea.getImage(); + } + makeUndoCommand(imageArea); + mPasteImage = globalClipboard->image(); + if (!mPasteImage.isNull()) + { + mSelectedImage = mPasteImage; + mImageCopy = *imageArea.getImage(); + mTopLeftPoint = QPoint(0, 0); + mBottomRightPoint = QPoint(mPasteImage.width(), mPasteImage.height()) - QPoint(1, 1); + mHeight = mPasteImage.height(); + mWidth = mPasteImage.width(); + mIsImageSelected = mIsSelectionExists = true; + paint(imageArea); + drawBorder(imageArea); + imageArea.restoreCursor(); + emit sendEnableCopyCutActions(true); + } +} + +void CropInstrument::startAdjusting(ImageArea &imageArea) +{ + mImageCopy = *imageArea.getImage(); + mIsImageSelected = false; +} + +void CropInstrument::startSelection(ImageArea &) +{ +} + +void CropInstrument::startResizing(ImageArea &imageArea) +{ + if (!mIsImageSelected) + { + clearSelectionBackground(imageArea); + } + if (mIsSelectionAdjusting) + { + mIsImageSelected = false; + } +} + +void CropInstrument::startMoving(ImageArea &imageArea) +{ + clearSelectionBackground(imageArea); + if (mIsSelectionAdjusting) + { + mIsImageSelected = false; + } +} + +void CropInstrument::select(ImageArea &) +{ +} + +void CropInstrument::resize(ImageArea &) +{ +} + +void CropInstrument::move(ImageArea &) +{ +} + +void CropInstrument::completeSelection(ImageArea &imageArea) +{ + mSelectedImage = imageArea.getImage()->copy(mTopLeftPoint.x(), + mTopLeftPoint.y(), + mWidth, mHeight); + emit sendEnableCopyCutActions(true); +} + +void CropInstrument::completeResizing(ImageArea &imageArea) +{ + mSelectedImage = imageArea.getImage()->copy(mTopLeftPoint.x(), + mTopLeftPoint.y(), + mWidth, mHeight); +} + +void CropInstrument::completeMoving(ImageArea &imageArea) +{ + if (mIsSelectionAdjusting) + { + mSelectedImage = imageArea.getImage()->copy(mTopLeftPoint.x(), + mTopLeftPoint.y(), + mWidth, mHeight); + } + +} + +void CropInstrument::clearSelectionBackground(ImageArea &imageArea) +{ + if (!mIsSelectionAdjusting) + { + QPainter blankPainter(imageArea.getImage()); + blankPainter.setPen(Qt::white); + blankPainter.setBrush(QBrush(Qt::white)); + blankPainter.setBackgroundMode(Qt::OpaqueMode); + blankPainter.drawRect(QRect(mTopLeftPoint, mBottomRightPoint - QPoint(1, 1))); + blankPainter.end(); + mImageCopy = *imageArea.getImage(); + } +} + +void CropInstrument::clear() +{ + mSelectedImage = QImage(); + emit sendEnableCopyCutActions(false); +} + +void CropInstrument::paint(ImageArea &imageArea, bool, bool) +{ + if (mIsSelectionExists && !mIsSelectionAdjusting) + { + if(mTopLeftPoint != mBottomRightPoint) + { + QPainter painter(imageArea.getImage()); + QRect source(0, 0, mSelectedImage.width(), mSelectedImage.height()); + QRect target(mTopLeftPoint, mBottomRightPoint); + painter.drawImage(target, mSelectedImage, source); + painter.end(); + } + imageArea.setEdited(true); + imageArea.update(); + } +} + +void CropInstrument::showMenu(ImageArea &) +{ +} diff --git a/sources/instruments/cropinstrument.h b/sources/instruments/cropinstrument.h new file mode 100644 index 0000000..e624de4 --- /dev/null +++ b/sources/instruments/cropinstrument.h @@ -0,0 +1,94 @@ +/* +MIT License + +Copyright (c) 2020 Maifee Ul Asad + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +GitHub repo : https://github.com/maifeeulasad/Paint + +A copy of the License : https://github.com/maifeeulasad/Paint/blob/main/LICENSE +*/ + +#ifndef CROPINSTRUMENT_H +#define CROPINSTRUMENT_H + +#include "abstractselection.h" + +QT_BEGIN_NAMESPACE +class QUndoStack; +QT_END_NAMESPACE + +class CropInstrument : public AbstractSelection +{ + Q_OBJECT + +public: + explicit CropInstrument(QObject *parent = 0); + + /** + * @brief Clears background image at selection area. + * + * @param imageArea ImageArea for applying changes. + */ + void clearSelectionBackground(ImageArea &imageArea); + /** + * @brief Copying image to the clipboard. + * + * @param imageArea ImageArea for applying changes. + */ + void copyImage(ImageArea &imageArea); + /** + * @brief Paste image from the clipboard. + * + * @param imageArea ImageArea for applying changes. + */ + void pasteImage(ImageArea &imageArea); + /** + * @brief Cut image to the clipboard. + * + * @param imageArea ImageArea for applying changes. + */ + void cutImage(ImageArea &imageArea); + +private: + void startAdjusting(ImageArea &imageArea); + void startSelection(ImageArea &); + void startResizing(ImageArea &imageArea); + void startMoving(ImageArea &imageArea); + void select(ImageArea &); + void resize(ImageArea &); + void move(ImageArea &); + void completeSelection(ImageArea &imageArea); + void completeResizing(ImageArea &imageArea); + void completeMoving(ImageArea &imageArea); + void clear(); + void paint(ImageArea &imageArea, bool = false, bool = false); + void showMenu(ImageArea &); + + QImage mSelectedImage, /**< Copy of selected image. */ + mPasteImage; /**< Image to paste */ + +signals: + void sendEnableCopyCutActions(bool enable); + void sendEnableSelectionInstrument(bool enable); + +}; + +#endif // CROPINSTRUMENT_H diff --git a/sources/josspaintenums.h b/sources/josspaintenums.h index 3828ac6..3112471 100644 --- a/sources/josspaintenums.h +++ b/sources/josspaintenums.h @@ -51,6 +51,7 @@ typedef enum ELLIPSE, CURVELINE, TEXT, + CROP, // Don't use it. (Used to know count of current instrument) INSTRUMENTS_COUNT diff --git a/sources/mainwindow.cpp b/sources/mainwindow.cpp index 8588157..85bf7b5 100644 --- a/sources/mainwindow.cpp +++ b/sources/mainwindow.cpp @@ -333,6 +333,13 @@ void MainWindow::initializeMainMenu() mInstrumentsMenu->addAction(mTextAction); mInstrumentsActMap.insert(TEXT, mTextAction); + QAction *mCropAction = new QAction(tr("Crop"), this); + mCropAction->setCheckable(true); + mCropAction->setIcon(QIcon::fromTheme("tool-crop", QIcon(":/media/instruments-icons/crop.png"))); + connect(mCropAction, &QAction::triggered, this, &MainWindow::instumentsAct); + mInstrumentsMenu->addAction(mCropAction); + mInstrumentsActMap.insert(CROP, mCropAction); + // TODO: Add new instrument action here mEffectsMenu = menuBar()->addMenu(tr("E&ffects")); @@ -634,7 +641,7 @@ void MainWindow::updateShortcuts() mInstrumentsActMap[ELLIPSE]->setShortcut(DataSingleton::Instance()->getInstrumentShortcutByKey("Ellipse")); mInstrumentsActMap[CURVELINE]->setShortcut(DataSingleton::Instance()->getInstrumentShortcutByKey("Curve")); mInstrumentsActMap[TEXT]->setShortcut(DataSingleton::Instance()->getInstrumentShortcutByKey("Text")); - // TODO: Add new instruments' shorcuts here + mInstrumentsActMap[CROP]->setShortcut(DataSingleton::Instance()->getInstrumentShortcutByKey("Crop")); mZoomInAction->setShortcut(DataSingleton::Instance()->getToolShortcutByKey("ZoomIn")); mZoomOutAction->setShortcut(DataSingleton::Instance()->getToolShortcutByKey("ZoomOut")); diff --git a/sources/media/instruments-icons/crop.png b/sources/media/instruments-icons/crop.png new file mode 100644 index 0000000000000000000000000000000000000000..874298e023405f212dd4dc44027e8b6c7e8c5dfe GIT binary patch literal 191 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjEX7WqAsj$Z!;#Vf4nJ za0`PlBg3pYARURGE{-7{oyiFj3LoUVG}(Nv7^I{`e30i|%v@4g@~5k@@u2*C*BvH8 z*$3;{*xIHq`O$MFq$T+8ht4N~+-)0KbwZ5V1*acrV7-{F;p-#V$p4t-AJ2qMt!ZKt gxZF-Ja^zvSvBh2E;vD6NK+70BUHx3vIVCg!0AB(-djJ3c literal 0 HcmV?d00001 diff --git a/sources/paint.pro b/sources/paint.pro index 675ea08..915c1ff 100644 --- a/sources/paint.pro +++ b/sources/paint.pro @@ -47,6 +47,7 @@ SOURCES += main.cpp\ instruments/selectioninstrument.cpp \ instruments/curvelineinstrument.cpp \ instruments/colorpickerpaletteinstrument.cpp \ + instruments/cropinstrument.cpp \ instruments/textinstrument.cpp \ effects/abstracteffect.cpp \ effects/negativeeffect.cpp \ @@ -88,6 +89,7 @@ HEADERS += mainwindow.h \ instruments/curvelineinstrument.h \ instruments/textinstrument.h \ instruments/colorpickerpaletteinstrument.h \ + instruments/cropinstrument.h \ effects/abstracteffect.h \ effects/negativeeffect.h \ effects/grayeffect.h \ diff --git a/sources/resources.qrc b/sources/resources.qrc index a7dee71..cf8ea85 100644 --- a/sources/resources.qrc +++ b/sources/resources.qrc @@ -16,6 +16,7 @@ media/instruments-icons/cursor_pipette.png media/instruments-icons/cursor_spray.png media/instruments-icons/cursor_fill.png + media/instruments-icons/crop.png media/textures/transparent.jpg media/actions-icons/application-exit.png media/actions-icons/document-new.png diff --git a/sources/widgets/toolbar.cpp b/sources/widgets/toolbar.cpp index a4bbb01..4de14e7 100644 --- a/sources/widgets/toolbar.cpp +++ b/sources/widgets/toolbar.cpp @@ -71,6 +71,7 @@ void ToolBar::initializeItems() mEllipseButton = createToolButton(mActMap[ELLIPSE]); mCurveButton = createToolButton(mActMap[CURVELINE]); mTextButton = createToolButton(mActMap[TEXT]); + mCropButton = createToolButton(mActMap[CROP]); QGridLayout *bLayout = new QGridLayout(); bLayout->setMargin(3); @@ -86,6 +87,7 @@ void ToolBar::initializeItems() bLayout->addWidget(mEllipseButton, 4, 1); bLayout->addWidget(mCurveButton, 5, 0); bLayout->addWidget(mTextButton, 5, 1); + bLayout->addWidget(mCropButton, 6, 0); QWidget *bWidget = new QWidget(); bWidget->setLayout(bLayout); diff --git a/sources/widgets/toolbar.h b/sources/widgets/toolbar.h index 8cce102..e1d7f9f 100644 --- a/sources/widgets/toolbar.h +++ b/sources/widgets/toolbar.h @@ -70,7 +70,7 @@ class ToolBar : public QToolBar QToolButton *mCursorButton, *mEraserButton, *mPenButton, *mLineButton, *mColorPickerButton,*mColorPickerPaletteButton, *mMagnifierButton, *mSprayButton, *mFillButton, - *mRectangleButton, *mEllipseButton, *mCurveButton, *mTextButton; + *mRectangleButton, *mEllipseButton, *mCurveButton, *mTextButton, *mCropButton; ColorChooser *mPColorChooser, *mSColorChooser; bool mPrevInstrumentSetted; const QMap &mActMap; From 96f8cff2e12f032f5ee40235d7d53b30cc645c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9=20=D0=A1=D0=BC?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D1=8F=D0=BD=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Sat, 19 Dec 2020 00:42:49 +0300 Subject: [PATCH 07/15] #29 --- sources/widgets/colorchooser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/widgets/colorchooser.cpp b/sources/widgets/colorchooser.cpp index 8da6f2f..8a0d566 100644 --- a/sources/widgets/colorchooser.cpp +++ b/sources/widgets/colorchooser.cpp @@ -40,14 +40,14 @@ A copy of the License : https://github.com/maifeeulasad/Paint/blob/main/LICENSE ColorChooser::ColorChooser(const int &r, const int &g, const int &b, QWidget *parent) : QLabel(parent) { - setFrameStyle(QFrame::Raised | QFrame::Box); + setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); mCurrentColor = new QColor(r, g, b); mPixmapColor = new QPixmap(20, 20); mPainterColor = new QPainter(mPixmapColor); mPainterColor->fillRect(0, 0, 20, 20, *mCurrentColor); mPainterColor->end(); setMargin(3); - setAlignment(Qt::AlignHCenter); + setAlignment(Qt::AlignBottom); setPixmap(*mPixmapColor); } From 9eddf940ff8d5d1e932dc4398195ad66c5b0f610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9=20=D0=A1=D0=BC?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D1=8F=D0=BD=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Sat, 19 Dec 2020 01:46:52 +0300 Subject: [PATCH 08/15] Crop for selection tool --- sources/datasingleton.cpp | 1 + sources/imagearea.cpp | 5 +++++ sources/imagearea.h | 1 + sources/mainwindow.cpp | 16 ++++++++++++++++ sources/mainwindow.h | 3 ++- 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/sources/datasingleton.cpp b/sources/datasingleton.cpp index a3e91cb..0897f78 100644 --- a/sources/datasingleton.cpp +++ b/sources/datasingleton.cpp @@ -82,6 +82,7 @@ void DataSingleton::readSetting() mEditShortcuts.insert("Copy", settings.value("/Shortcuts/Edit/Copy", QKeySequence(QKeySequence::Copy)).value()); mEditShortcuts.insert("Paste", settings.value("/Shortcuts/Edit/Paste", QKeySequence(QKeySequence::Paste)).value()); mEditShortcuts.insert("Cut", settings.value("/Shortcuts/Edit/Cut", QKeySequence(QKeySequence::Cut)).value()); + mEditShortcuts.insert("Crop", settings.value("/Shortcuts/Edit/Crop", QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_X)).value()); //read shortcuts for instruments menu mInstrumentsShortcuts.insert("Cursor", settings.value("/Shortcuts/Instruments/Cursor", "Ctrl+1").value()); diff --git a/sources/imagearea.cpp b/sources/imagearea.cpp index 213e54f..2a308cf 100644 --- a/sources/imagearea.cpp +++ b/sources/imagearea.cpp @@ -380,6 +380,11 @@ void ImageArea::cutImage() instrument->cutImage(*this); } +void ImageArea::cropImage() +{ + SelectionInstrument *instrument = static_cast (mInstrumentsHandlers.at(CURSOR)); + instrument->cropImage(*this); +} void ImageArea::mousePressEvent(QMouseEvent *event) { if(event->button() == Qt::LeftButton && diff --git a/sources/imagearea.h b/sources/imagearea.h index 8dbd952..5a9488b 100644 --- a/sources/imagearea.h +++ b/sources/imagearea.h @@ -157,6 +157,7 @@ class ImageArea : public QWidget * */ void cutImage(); + void cropImage(); /** * @brief Save all image changes to image copy. * diff --git a/sources/mainwindow.cpp b/sources/mainwindow.cpp index 85bf7b5..518fad0 100644 --- a/sources/mainwindow.cpp +++ b/sources/mainwindow.cpp @@ -238,6 +238,14 @@ void MainWindow::initializeMainMenu() connect(mCutAction, &QAction::triggered, this, &MainWindow::cutAct); editMenu->addAction(mCutAction); + mCropAction = new QAction(tr("Crop S&election")); + mCropAction->setIcon(QIcon::fromTheme("transform-crop")); + mCropAction->setIconVisibleInMenu(true); + mCropAction->setEnabled(false); + connect(mCropAction, &QAction::triggered, this, &MainWindow::cropAct); + editMenu->addAction(mCropAction); + + editMenu->addSeparator(); QAction *settingsAction = new QAction(tr("&Settings"), this); @@ -613,6 +621,12 @@ void MainWindow::cutAct() imageArea->cutImage(); } +void MainWindow::cropAct() +{ + if (ImageArea *imageArea = getCurrentImageArea()) + imageArea->cropImage(); +} + void MainWindow::updateShortcuts() { mNewAction->setShortcut(DataSingleton::Instance()->getFileShortcutByKey("New")); @@ -628,6 +642,7 @@ void MainWindow::updateShortcuts() mCopyAction->setShortcut(DataSingleton::Instance()->getEditShortcutByKey("Copy")); mPasteAction->setShortcut(DataSingleton::Instance()->getEditShortcutByKey("Paste")); mCutAction->setShortcut(DataSingleton::Instance()->getEditShortcutByKey("Cut")); + mCropAction->setShortcut(DataSingleton::Instance()->getEditShortcutByKey("Crop")); mInstrumentsActMap[CURSOR]->setShortcut(DataSingleton::Instance()->getInstrumentShortcutByKey("Cursor")); mInstrumentsActMap[ERASER]->setShortcut(DataSingleton::Instance()->getInstrumentShortcutByKey("Lastic")); @@ -870,6 +885,7 @@ void MainWindow::enableCopyCutActions(bool enable) { mCopyAction->setEnabled(enable); mCutAction->setEnabled(enable); + mCropAction->setEnabled(enable); } void MainWindow::clearImageSelection() diff --git a/sources/mainwindow.h b/sources/mainwindow.h index db634e9..81b180d 100644 --- a/sources/mainwindow.h +++ b/sources/mainwindow.h @@ -106,7 +106,7 @@ class MainWindow : public QMainWindow QMap mInstrumentsActMap; QMap mEffectsActMap; QAction *mSaveAction, *mSaveAsAction, *mCloseAction, *mPrintAction, - *mUndoAction, *mRedoAction, *mCopyAction, *mCutAction, + *mUndoAction, *mRedoAction, *mCopyAction, *mCutAction, *mCropAction, *mNewAction, *mOpenAction, *mExitAction, *mPasteAction, *mZoomInAction, *mZoomOutAction; QMenu *mInstrumentsMenu, *mEffectsMenu, *mToolsMenu; QUndoGroup *mUndoStackGroup; @@ -128,6 +128,7 @@ private slots: void copyAct(); void pasteAct(); void cutAct(); + void cropAct(); void settingsAct(); void effectsAct(); void resizeImageAct(); From be1dc820c16fd3d2c7848301d9b626cdf9ec4c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9=20=D0=A1=D0=BC?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D1=8F=D0=BD=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Sat, 19 Dec 2020 01:48:48 +0300 Subject: [PATCH 09/15] Crop for selection tool 1. Select an area of the image with the Selection tool. 2. Press CTRL + SHIFT + X or choose Crop Selection from the Edit menu. --- sources/instruments/selectioninstrument.cpp | 11 +++++++++++ sources/instruments/selectioninstrument.h | 1 + 2 files changed, 12 insertions(+) diff --git a/sources/instruments/selectioninstrument.cpp b/sources/instruments/selectioninstrument.cpp index 152758d..9274f36 100644 --- a/sources/instruments/selectioninstrument.cpp +++ b/sources/instruments/selectioninstrument.cpp @@ -91,6 +91,17 @@ void SelectionInstrument::cutImage(ImageArea &imageArea) } } +void SelectionInstrument::cropImage(ImageArea &imageArea) +{ + QImage cropArea = imageArea.getImage()->copy(mTopLeftPoint.x(), mTopLeftPoint.y(), mWidth, mHeight); + makeUndoCommand(imageArea); + imageArea.setImage(cropArea); + imageArea.update(); + mIsSelectionExists = false; + imageArea.restoreCursor(); + emit sendEnableCopyCutActions(false); +} + void SelectionInstrument::pasteImage(ImageArea &imageArea) { QClipboard *globalClipboard = QApplication::clipboard(); diff --git a/sources/instruments/selectioninstrument.h b/sources/instruments/selectioninstrument.h index 839ff12..f3b8866 100644 --- a/sources/instruments/selectioninstrument.h +++ b/sources/instruments/selectioninstrument.h @@ -69,6 +69,7 @@ class SelectionInstrument : public AbstractSelection * @param imageArea ImageArea for applying changes. */ void cutImage(ImageArea &imageArea); + void cropImage(ImageArea &imageArea); private: void startAdjusting(ImageArea &imageArea); From 7ba44d02ff33a2ff4e1773c9d4b3afcf620dc867 Mon Sep 17 00:00:00 2001 From: maifeeulasad Date: Sat, 19 Dec 2020 13:26:37 +0600 Subject: [PATCH 10/15] #22 on enter crop//wip --- sources/instruments/cropinstrument.cpp | 16 ++++++++++++++-- sources/instruments/cropinstrument.h | 3 +++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/sources/instruments/cropinstrument.cpp b/sources/instruments/cropinstrument.cpp index 6829f87..6552cd8 100644 --- a/sources/instruments/cropinstrument.cpp +++ b/sources/instruments/cropinstrument.cpp @@ -36,8 +36,8 @@ A copy of the License : https://github.com/maifeeulasad/Paint/blob/main/LICENSE #include CropInstrument::CropInstrument(QObject *parent) : - AbstractSelection(parent) -{ + AbstractSelection(parent){ + this->installEventFilter(this); } void CropInstrument::copyImage(ImageArea &imageArea) @@ -223,4 +223,16 @@ void CropInstrument::paint(ImageArea &imageArea, bool, bool) void CropInstrument::showMenu(ImageArea &) { + +} + +bool CropInstrument::eventFilter(QObject *obj, QEvent *ev) +{ + (void)obj; + QKeyEvent *keyEvent = static_cast(ev); + if (keyEvent->key() == Qt::Key_Enter){ + //crop here + return true; + } + return false; } diff --git a/sources/instruments/cropinstrument.h b/sources/instruments/cropinstrument.h index e624de4..7e5d33a 100644 --- a/sources/instruments/cropinstrument.h +++ b/sources/instruments/cropinstrument.h @@ -85,6 +85,9 @@ class CropInstrument : public AbstractSelection QImage mSelectedImage, /**< Copy of selected image. */ mPasteImage; /**< Image to paste */ +protected: + bool eventFilter(QObject *obj, QEvent *ev); + signals: void sendEnableCopyCutActions(bool enable); void sendEnableSelectionInstrument(bool enable); From ff90f193dd64f9d2d534935aac57c0e1cc206975 Mon Sep 17 00:00:00 2001 From: maifeeulasad Date: Sun, 20 Dec 2020 19:06:13 +0600 Subject: [PATCH 11/15] added qss submodule from GTRONICK --- .gitmodules | 3 +++ sources/QSS | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 sources/QSS diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4730979 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "sources/QSS"] + path = sources/QSS + url = https://github.com/GTRONICK/QSS.git diff --git a/sources/QSS b/sources/QSS new file mode 160000 index 0000000..bc3dd27 --- /dev/null +++ b/sources/QSS @@ -0,0 +1 @@ +Subproject commit bc3dd27617e2518c52aecf45536832ecc4be22d9 From 8c391f2d2ecd9b1013a9c33af10157f1be33309b Mon Sep 17 00:00:00 2001 From: maifeeulasad Date: Sun, 20 Dec 2020 19:14:47 +0600 Subject: [PATCH 12/15] some beautiful styles #37 --- sources/main.cpp | 11 +++++++++-- sources/resources.qrc | 11 +++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/sources/main.cpp b/sources/main.cpp index 97f90f4..fe666ad 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -56,9 +56,16 @@ void printVersion() int main(int argc, char *argv[]) { QApplication a(argc, argv); - a.setApplicationName("Paint"); + a.setApplicationName("Joss Paint"); a.setApplicationVersion("0.1.1"); - a.setStyle(QStyleFactory::create("Macintosh")); + + QFile styleFile( ":/QSS/Ubuntu.qss" ); + styleFile.open( QFile::ReadOnly ); + + QString style( styleFile.readAll() ); + a.setStyleSheet( style ); + + //a.setStyle(QStyleFactory::create("Macintosh")); QStringList args = a.arguments(); diff --git a/sources/resources.qrc b/sources/resources.qrc index cf8ea85..9c63b3e 100644 --- a/sources/resources.qrc +++ b/sources/resources.qrc @@ -39,5 +39,16 @@ media/logo/josspaint_64.png media/instruments-icons/curve.png media/actions-icons/clear-gray.png + + + QSS/Ubuntu.qss + QSS/AMOLED.qss + QSS/Aqua.qss + QSS/ConsoleStyle.qss + QSS/ElegantDark.qss + QSS/ConsoleStyle.qss + QSS/ManjaroMix.qss + QSS/MaterialDark.qss + QSS/NeonButtons.qss From 41998df8e04905f07af5f4e8c9045653634e734d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9=20=D0=A1=D0=BC?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D1=8F=D0=BD=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Mon, 21 Dec 2020 16:32:38 +0300 Subject: [PATCH 13/15] New toolbar layout --- sources/widgets/toolbar.cpp | 63 +++++++++++++++++++++---------------- sources/widgets/toolbar.h | 26 +++++---------- 2 files changed, 44 insertions(+), 45 deletions(-) diff --git a/sources/widgets/toolbar.cpp b/sources/widgets/toolbar.cpp index 4de14e7..1128e12 100644 --- a/sources/widgets/toolbar.cpp +++ b/sources/widgets/toolbar.cpp @@ -38,6 +38,7 @@ A copy of the License : https://github.com/maifeeulasad/Paint/blob/main/LICENSE #include #include #include +#include ToolBar::ToolBar(const QMap &actMap, QWidget *parent) : QToolBar(tr("Instruments"), parent), mActMap(actMap) @@ -59,6 +60,7 @@ QToolButton* ToolBar::createToolButton(QAction *act) void ToolBar::initializeItems() { + QLabel *InstrumentText = new QLabel(tr("Instruments"), this); mCursorButton = createToolButton(mActMap[CURSOR]); mEraserButton = createToolButton(mActMap[ERASER]); mPenButton = createToolButton(mActMap[PEN]); @@ -73,25 +75,36 @@ void ToolBar::initializeItems() mTextButton = createToolButton(mActMap[TEXT]); mCropButton = createToolButton(mActMap[CROP]); + textPenSize = new QLabel(tr("Pen size: 1 "), this); + mPenSize = new QSlider(Qt::Horizontal); + mPenSize->setMinimum(1); + mPenSize->setMaximum(25); + mPenSize->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); + connect(mPenSize, &QAbstractSlider::valueChanged, this, &ToolBar::valuePenSize); + QGridLayout *bLayout = new QGridLayout(); - bLayout->setMargin(3); - bLayout->addWidget(mPenButton, 0, 0); - bLayout->addWidget(mEraserButton, 0, 1); - bLayout->addWidget(mColorPickerPaletteButton, 1, 0); - bLayout->addWidget(mMagnifierButton, 1, 1); - bLayout->addWidget(mCursorButton, 2, 0); - bLayout->addWidget(mLineButton, 2, 1); - bLayout->addWidget(mSprayButton, 3, 0); - bLayout->addWidget(mFillButton, 3, 1); - bLayout->addWidget(mRectangleButton, 4, 0); - bLayout->addWidget(mEllipseButton, 4, 1); - bLayout->addWidget(mCurveButton, 5, 0); - bLayout->addWidget(mTextButton, 5, 1); - bLayout->addWidget(mCropButton, 6, 0); + bLayout->setMargin(1); + bLayout->addWidget(InstrumentText, 0, 0, 1, 4, Qt::AlignCenter); + bLayout->addWidget(mPenButton, 1, 0); + bLayout->addWidget(mSprayButton, 1, 1); + bLayout->addWidget(mEraserButton, 1, 2); + bLayout->addWidget(mLineButton, 1, 3); + bLayout->addWidget(mCurveButton, 2, 0); + bLayout->addWidget(mRectangleButton, 2, 1); + bLayout->addWidget(mEllipseButton, 2, 2); + bLayout->addWidget(mCropButton, 2, 3); + bLayout->addWidget(mCursorButton, 3, 0); + bLayout->addWidget(mMagnifierButton, 3, 1); + bLayout->addWidget(mTextButton, 3, 2); + bLayout->addWidget(textPenSize, 4, 0, 1, 4); + bLayout->addWidget(mPenSize, 5, 0, 1, 4); + QWidget *bWidget = new QWidget(); bWidget->setLayout(bLayout); + QLabel *ColorText = new QLabel(tr("Color"), this); + mPColorChooser = new ColorChooser(0, 0, 0, this); mPColorChooser->setStatusTip(tr("Primary color")); mPColorChooser->setToolTip(tr("Primary color")); @@ -102,18 +115,13 @@ void ToolBar::initializeItems() mSColorChooser->setToolTip(tr("Secondary color")); connect(mSColorChooser, &ColorChooser::sendColor, this, &ToolBar::secondaryColorChanged); - QSpinBox *penSizeSpin = new QSpinBox(); - penSizeSpin->setRange(1, 20); - penSizeSpin->setValue(1); - penSizeSpin->setStatusTip(tr("Pen size")); - penSizeSpin->setToolTip(tr("Pen size")); - connect(penSizeSpin, SIGNAL(valueChanged(int)), this, SLOT(penValueChanged(int))); - QGridLayout *tLayout = new QGridLayout(); - tLayout->setMargin(3); - tLayout->addWidget(mPColorChooser, 0, 0); - tLayout->addWidget(mSColorChooser, 0, 1); - tLayout->addWidget(penSizeSpin, 1, 0, 1, 2); + tLayout->setMargin(1); + tLayout->addWidget(ColorText, 0, 0, 1, 4, Qt::AlignCenter); + tLayout->addWidget(mColorPickerPaletteButton, 1, 0); + tLayout->addWidget(mFillButton, 1, 1); + tLayout->addWidget(mPColorChooser, 1, 2); + tLayout->addWidget(mSColorChooser, 1, 3); QWidget *tWidget = new QWidget(); tWidget->setLayout(tLayout); @@ -123,9 +131,10 @@ void ToolBar::initializeItems() addWidget(tWidget); } -void ToolBar::penValueChanged(const int &value) +void ToolBar::valuePenSize(const int &value) { - DataSingleton::Instance()->setPenSize(value); + DataSingleton::Instance()->setPenSize(value); + textPenSize->setText(QString(tr("Pen size: %1")).arg(mPenSize->value())); } void ToolBar::primaryColorChanged(const QColor &color) diff --git a/sources/widgets/toolbar.h b/sources/widgets/toolbar.h index e1d7f9f..344b3fc 100644 --- a/sources/widgets/toolbar.h +++ b/sources/widgets/toolbar.h @@ -32,8 +32,10 @@ A copy of the License : https://github.com/maifeeulasad/Paint/blob/main/LICENSE #ifndef TOOLBAR_H #define TOOLBAR_H +#include "palettebutton.h" #include "../josspaintenums.h" - +#include +#include #include QT_BEGIN_NAMESPACE @@ -41,10 +43,6 @@ class QToolButton; class ColorChooser; QT_END_NAMESPACE -/** - * @brief Toolbar with instrumets buttons, color choosers and etc. - * - */ class ToolBar : public QToolBar { Q_OBJECT @@ -53,25 +51,17 @@ class ToolBar : public QToolBar explicit ToolBar(const QMap &actMap, QWidget *parent = 0); private: - /** - * @brief Initialize all buttons, color choosers and etc. - * - */ void initializeItems(); - /** - * @brief Create new QToolButton - * - * @param name Name of button - * @param iconPath Path to button icon. - * @return QToolButton Created QToolButton. - */ - QToolButton* createToolButton(QAction *act); + QToolButton* createToolButton(QAction *act); QToolButton *mCursorButton, *mEraserButton, *mPenButton, *mLineButton, *mColorPickerButton,*mColorPickerPaletteButton, *mMagnifierButton, *mSprayButton, *mFillButton, *mRectangleButton, *mEllipseButton, *mCurveButton, *mTextButton, *mCropButton; ColorChooser *mPColorChooser, *mSColorChooser; + QSlider *mPenSize; + QLabel *textPenSize; + bool mPrevInstrumentSetted; const QMap &mActMap; @@ -84,7 +74,7 @@ public slots: void setSecondaryColorView(); private slots: - void penValueChanged(const int &value); + void valuePenSize(const int &value); void primaryColorChanged(const QColor &color); void secondaryColorChanged(const QColor &color); From b3b4554381d9a39650816dc258316b3c62066744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9=20=D0=A1=D0=BC?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D1=8F=D0=BD=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Tue, 22 Dec 2020 08:22:04 +0300 Subject: [PATCH 14/15] "tool-crop" is missing from Breeze... ...so it should be replaced with "transform-crop" --- sources/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/mainwindow.cpp b/sources/mainwindow.cpp index 518fad0..c90fee8 100644 --- a/sources/mainwindow.cpp +++ b/sources/mainwindow.cpp @@ -343,7 +343,7 @@ void MainWindow::initializeMainMenu() QAction *mCropAction = new QAction(tr("Crop"), this); mCropAction->setCheckable(true); - mCropAction->setIcon(QIcon::fromTheme("tool-crop", QIcon(":/media/instruments-icons/crop.png"))); + mCropAction->setIcon(QIcon::fromTheme("transform-crop", QIcon(":/media/instruments-icons/crop.png"))); connect(mCropAction, &QAction::triggered, this, &MainWindow::instumentsAct); mInstrumentsMenu->addAction(mCropAction); mInstrumentsActMap.insert(CROP, mCropAction); From 34cd1cd9682b6c0ddfc5f99f4d6edd3d9a06693e Mon Sep 17 00:00:00 2001 From: maifeeulasad Date: Sat, 2 Jan 2021 16:11:41 +0600 Subject: [PATCH 15/15] new updates mac like look and feel --- sources/JossPaint.pro | 2 ++ sources/QSS | 2 +- sources/main.cpp | 4 +--- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sources/JossPaint.pro b/sources/JossPaint.pro index ed213f9..cd947b5 100644 --- a/sources/JossPaint.pro +++ b/sources/JossPaint.pro @@ -47,6 +47,7 @@ SOURCES += main.cpp\ instruments/selectioninstrument.cpp \ instruments/curvelineinstrument.cpp \ instruments/colorpickerpaletteinstrument.cpp \ + instruments/cropinstrument.cpp \ instruments/textinstrument.cpp \ effects/abstracteffect.cpp \ effects/negativeeffect.cpp \ @@ -88,6 +89,7 @@ HEADERS += mainwindow.h \ instruments/curvelineinstrument.h \ instruments/textinstrument.h \ instruments/colorpickerpaletteinstrument.h \ + instruments/cropinstrument.h \ effects/abstracteffect.h \ effects/negativeeffect.h \ effects/grayeffect.h \ diff --git a/sources/QSS b/sources/QSS index bc3dd27..3be409c 160000 --- a/sources/QSS +++ b/sources/QSS @@ -1 +1 @@ -Subproject commit bc3dd27617e2518c52aecf45536832ecc4be22d9 +Subproject commit 3be409c2c784a837ebc142f7a70499e15e0c3d27 diff --git a/sources/main.cpp b/sources/main.cpp index fe666ad..aecb30c 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -59,14 +59,12 @@ int main(int argc, char *argv[]) a.setApplicationName("Joss Paint"); a.setApplicationVersion("0.1.1"); - QFile styleFile( ":/QSS/Ubuntu.qss" ); + QFile styleFile( ":/QSS/MacOS.qss" ); styleFile.open( QFile::ReadOnly ); QString style( styleFile.readAll() ); a.setStyleSheet( style ); - //a.setStyle(QStyleFactory::create("Macintosh")); - QStringList args = a.arguments(); QRegExp rxArgHelp("--help");