diff --git a/colorpicker/colorpickerscene.cpp b/colorpicker/colorpickerscene.cpp index 5899e8f..10118f7 100644 --- a/colorpicker/colorpickerscene.cpp +++ b/colorpicker/colorpickerscene.cpp @@ -1,6 +1,7 @@ #include "colorpickerscene.hpp" #include #include +#include #include #include #include @@ -76,9 +77,11 @@ void ColorPickerScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { void ColorPickerScene::keyPressEvent(QKeyEvent *event) { if (event->key() == Qt::Key_Return) QApplication::clipboard()->setText(color.name()); if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Escape) close(); + qInfo().noquote() << tr("Copied hex code to clipboard."); } void ColorPickerScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *) { QApplication::clipboard()->setText(color.name()); close(); + qInfo().noquote() << tr("Copied hex code to clipboard."); } diff --git a/cropeditor/cropscene.cpp b/cropeditor/cropscene.cpp index 1c70f71..6125ebe 100644 --- a/cropeditor/cropscene.cpp +++ b/cropeditor/cropscene.cpp @@ -33,6 +33,7 @@ CropScene::CropScene(QObject *parent, QPixmap pixmap) brush().setColor(settings::settings().value("brushColor", brush().color()).value()); brush().setStyle( static_cast(settings::settings().value("brushStyle", static_cast(Qt::SolidPattern)).toInt())); + _highlight = settings::settings().value("highlightColor", QColor(Qt::cyan)).value(); menu = new QMenuBar; addDrawingAction(menu, tr("Free draw"), ":/icons/pencil.png", [] { return new PathItem; }); @@ -105,20 +106,19 @@ CropScene::CropScene(QObject *parent, QPixmap pixmap) cursorItem->setZValue(3); magnifier = addPixmap(QPixmap(110, 110)); - magnifierBox = addRect(magnifier->boundingRect(), QPen(Qt::cyan)); + magnifierBox = addRect(magnifier->boundingRect(), QPen(_highlight)); magnifier->setZValue(3); magnifierBox->setZValue(1.1); magnifierBox->setParentItem(magnifier); magnifierHint = addText("ptr: (0, 0)\nsel: (-1, -1, 0, 0)"); magnifierHint->setParentItem(magnifier); magnifierHint->setY(magnifier->boundingRect().height()); - QColor c(Qt::cyan); + QColor c(_highlight); c.setAlphaF(.25); magnifierHintBox = addRect(magnifierHint->boundingRect(), Qt::NoPen, c); magnifierHintBox->setParentItem(magnifierHint); magnifierHintBox->setZValue(1); magnifierHint->setZValue(1.1); - initMagnifierGrid(); updateMag(); addItem(hint); @@ -153,6 +153,7 @@ CropScene::CropScene(QObject *parent, QPixmap pixmap) int w = screen->geometry().width(); widget->setPos(views()[0]->mapToScene( QPoint(screen->geometry().x() + (w - widget->boundingRect().width()) / 2, screen->geometry().y() + 100))); + setGrid(settings::settings().value("gridEnabled", true).toBool()); }); } @@ -172,6 +173,19 @@ QFont &CropScene::font() { return _font; } +void CropScene::setHighlight(QColor highlight) { + _highlight = highlight; + QColor c = highlight; + c.setAlphaF(.4); + magnifierHintBox->setBrush(c); + if (grid()) setGrid(true); + if (rect) rect->setPen(highlight); + int i = settings::settings().value("magnifierPixelCount", 11).toInt() / 2; + if (gridRectsX.isEmpty() || gridRectsY.isEmpty()) return; + gridRectsX[i]->setBrush(c); + gridRectsY[i]->setBrush(c); +} + void CropScene::setDrawingSelection(QString name, std::function drawAction) { this->setFocus(); drawingSelectionMaker = drawAction; @@ -229,7 +243,7 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { QCursor::setPos(views()[0]->mapToGlobal(cursorPos.toPoint())); } else cursorPos = e->scenePos(); - hint->setVisible(!hint->sceneBoundingRect().contains(cursorPos)); + hint->setVisible(settings::settings().value("crophint").toBool() && !hint->sceneBoundingRect().contains(cursorPos)); cursorItem->setPos(cursorPos); updateMag(); @@ -248,7 +262,7 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) { rect = new QGraphicsRectItem(p.x(), p.y(), 1, 1); initPos = p; QPen pen(Qt::NoBrush, 1); - pen.setColor(Qt::cyan); + pen.setColor(_highlight); rect->setPen(pen); rect->setZValue(1); addItem(rect); @@ -322,7 +336,7 @@ void CropScene::wheelEvent(QGraphicsSceneWheelEvent *event) { for (auto item : gridRectsY) delete item; gridRectsY.clear(); - initMagnifierGrid(); + if (grid()) initMagnifierGrid(); updateMag(); if (!(event->modifiers() & Qt::ControlModifier)) QGraphicsScene::wheelEvent(event); @@ -378,7 +392,9 @@ void CropScene::updateMag() { } void CropScene::initMagnifierGrid() { - QColor c(Qt::cyan); + if (!gridRectsX.isEmpty() || !gridRectsY.isEmpty()) return; + + QColor c(_highlight); c.setAlphaF(.25); int pixCnt = settings::settings().value("magnifierPixelCount", 11).toInt(); if (pixCnt % 2 == 0) pixCnt++; @@ -387,8 +403,8 @@ void CropScene::initMagnifierGrid() { auto gridRectY = addRect(i * 110. / pixCnt, 0, 110. / pixCnt, 110, QPen(Qt::black, 0.5)); gridRectX->setParentItem(magnifierBox); gridRectY->setParentItem(magnifierBox); - gridRectX->setZValue(1); - gridRectY->setZValue(1); + gridRectX->setZValue(5); + gridRectY->setZValue(5); gridRectsX.append(gridRectX); gridRectsY.append(gridRectY); if (i == (pixCnt / 2)) { diff --git a/cropeditor/cropscene.hpp b/cropeditor/cropscene.hpp index c965153..6ad2191 100644 --- a/cropeditor/cropscene.hpp +++ b/cropeditor/cropscene.hpp @@ -23,6 +23,24 @@ public: QPen &pen(); QBrush &brush(); QFont &font(); + QColor highlight() { + return _highlight; + } + void setHighlight(QColor highlight); + bool grid() { + return _grid; + } + void setGrid(bool grid) { + _grid = grid; + if (grid) { + initMagnifierGrid(); + } else { + for (auto r : gridRectsX) delete r; + gridRectsX.clear(); + for (auto r : gridRectsY) delete r; + gridRectsY.clear(); + } + } void setDrawingSelection(QString name, std::function drawAction); QPixmap pixmap() { return _pixmap; @@ -74,6 +92,8 @@ private: QPen _pen; QBrush _brush; QFont _font; + QColor _highlight; + bool _grid; QGraphicsPolygonItem *polyItem = nullptr; DrawItem *drawingSelection = nullptr; QMenuBar *menu = nullptr; diff --git a/cropeditor/drawing/bluritem.cpp b/cropeditor/drawing/bluritem.cpp index 23005f1..1964075 100644 --- a/cropeditor/drawing/bluritem.cpp +++ b/cropeditor/drawing/bluritem.cpp @@ -16,7 +16,7 @@ bool BlurItem::init(CropScene *) { void BlurItem::mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) { if (pos.isNull()) { pos = scene->cursorPosition(); - rect = scene->addRect(QRect(scene->cursorPosition().toPoint(), QSize(1, 1)), QPen(Qt::cyan), Qt::NoBrush); + rect = scene->addRect(QRect(scene->cursorPosition().toPoint(), QSize(1, 1)), QPen(scene->highlight()), Qt::NoBrush); pixmap = scene->addPixmap(scene->pixmap().copy(rect->rect().toRect())); pixmap->setPos(scene->cursorPosition()); pixmap->setZValue(rect->zValue() - 0.1); diff --git a/cropeditor/settings/brushpenselection.cpp b/cropeditor/settings/brushpenselection.cpp index b26a681..02a7f9e 100644 --- a/cropeditor/settings/brushpenselection.cpp +++ b/cropeditor/settings/brushpenselection.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -20,6 +21,8 @@ BrushPenSelection::BrushPenSelection(CropScene *scene) : QDialog(), ui(new Ui::B ui->radSlider->setValue(settings::settings().value("blur/radius", 5.).toDouble() * 100); ui->radSpinner->setValue(settings::settings().value("blur/radius", 5.).toDouble()); + ui->gridBox->setChecked(scene->grid()); + ui->cosmetic->setChecked(scene->pen().isCosmetic()); ui->widthSlider->setValue(scene->pen().width()); ui->widthSpinner->setValue(scene->pen().widthF()); @@ -36,6 +39,7 @@ BrushPenSelection::BrushPenSelection(CropScene *scene) : QDialog(), ui(new Ui::B brush = scene->brush().color(); ui->alphaSlider->setValue(brush.alpha()); ui->alphaSpin->setValue(brush.alpha()); + highlight = scene->highlight(); setWindowTitle(tr("Crop editor settings")); this->scene = scene; @@ -60,12 +64,16 @@ void BrushPenSelection::on_buttonBox_accepted() { scene->pen().setCosmetic(ui->cosmetic->isChecked()); scene->pen().setWidthF(ui->widthSpinner->value()); scene->brush().setColor(brush); + scene->setHighlight(highlight); + scene->setGrid(ui->gridBox->isChecked()); scene->brush().setStyle((Qt::BrushStyle)ui->brushStyle->currentIndex()); settings::settings().setValue("penColor", scene->pen().color()); settings::settings().setValue("penCosmetic", scene->pen().isCosmetic()); settings::settings().setValue("penWidth", scene->pen().widthF()); settings::settings().setValue("brushColor", scene->brush().color()); + settings::settings().setValue("highlightColor", scene->highlight()); + settings::settings().setValue("gridEnabled", scene->grid()); settings::settings().setValue("brushStyle", (int)scene->brush().style()); settings::settings().setValue("brushPath", ui->pathItemHasBrush->isChecked()); settings::settings().setValue("blur/radius", ui->radSpinner->value()); @@ -104,3 +112,7 @@ void BrushPenSelection::on_alphaSpin_valueChanged(int arg1) { void BrushPenSelection::on_penAlphaSpin_valueChanged(int arg1) { pen.setAlpha(arg1); } + +void BrushPenSelection::on_highlightColor_clicked() { + highlight = QColorDialog::getColor(highlight, this, tr("Highlight color")); +} diff --git a/cropeditor/settings/brushpenselection.hpp b/cropeditor/settings/brushpenselection.hpp index 3ae277d..eaad6e4 100644 --- a/cropeditor/settings/brushpenselection.hpp +++ b/cropeditor/settings/brushpenselection.hpp @@ -27,10 +27,12 @@ private slots: void on_widthSpinner_valueChanged(double arg1); void on_penAlphaSpin_valueChanged(int arg1); + void on_highlightColor_clicked(); + private: Ui::BrushPenSelection *ui; CropScene *scene; - QColor brush, pen; + QColor brush, pen, highlight; }; #endif // BRUSHPENSELECTION_HPP diff --git a/cropeditor/settings/brushpenselection.ui b/cropeditor/settings/brushpenselection.ui index 3688e28..74f5ec6 100644 --- a/cropeditor/settings/brushpenselection.ui +++ b/cropeditor/settings/brushpenselection.ui @@ -7,7 +7,7 @@ 0 0 442 - 493 + 550 @@ -84,7 +84,7 @@ - + QDialogButtonBox::Cancel|QDialogButtonBox::Ok @@ -100,6 +100,16 @@ Blur settings + + + + 3000 + + + Qt::Horizontal + + + @@ -107,6 +117,20 @@ + + + + Animated Hint + + + + + + + Quality Hint + + + @@ -123,6 +147,13 @@ + + + + Blur Radius + + + @@ -133,54 +164,10 @@ - - - - 3000 - - - Qt::Horizontal - - - - - - - Blur Radius - - - - - - - Animated Hint - - - - - - - Quality Hint - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - + Brush settings @@ -306,7 +293,7 @@ - + Arrow settings @@ -342,6 +329,29 @@ + + + + Other editor settings + + + + + + Enable grid + + + + + + + Highligh color + + + + + +