Make highlight colors and grid changeable

This commit is contained in:
ArsenArsen 2017-08-05 21:20:24 +02:00
parent c19221cd37
commit db1108079d
No known key found for this signature in database
GPG Key ID: C631EC9C50708CF4
7 changed files with 122 additions and 59 deletions

View File

@ -1,6 +1,7 @@
#include "colorpickerscene.hpp" #include "colorpickerscene.hpp"
#include <QApplication> #include <QApplication>
#include <QClipboard> #include <QClipboard>
#include <QDebug>
#include <QGraphicsEllipseItem> #include <QGraphicsEllipseItem>
#include <QGraphicsPixmapItem> #include <QGraphicsPixmapItem>
#include <QGraphicsTextItem> #include <QGraphicsTextItem>
@ -76,9 +77,11 @@ void ColorPickerScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
void ColorPickerScene::keyPressEvent(QKeyEvent *event) { void ColorPickerScene::keyPressEvent(QKeyEvent *event) {
if (event->key() == Qt::Key_Return) QApplication::clipboard()->setText(color.name()); if (event->key() == Qt::Key_Return) QApplication::clipboard()->setText(color.name());
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Escape) close(); if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Escape) close();
qInfo().noquote() << tr("Copied hex code to clipboard.");
} }
void ColorPickerScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *) { void ColorPickerScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *) {
QApplication::clipboard()->setText(color.name()); QApplication::clipboard()->setText(color.name());
close(); close();
qInfo().noquote() << tr("Copied hex code to clipboard.");
} }

View File

@ -33,6 +33,7 @@ CropScene::CropScene(QObject *parent, QPixmap pixmap)
brush().setColor(settings::settings().value("brushColor", brush().color()).value<QColor>()); brush().setColor(settings::settings().value("brushColor", brush().color()).value<QColor>());
brush().setStyle( brush().setStyle(
static_cast<Qt::BrushStyle>(settings::settings().value("brushStyle", static_cast<int>(Qt::SolidPattern)).toInt())); static_cast<Qt::BrushStyle>(settings::settings().value("brushStyle", static_cast<int>(Qt::SolidPattern)).toInt()));
_highlight = settings::settings().value("highlightColor", QColor(Qt::cyan)).value<QColor>();
menu = new QMenuBar; menu = new QMenuBar;
addDrawingAction(menu, tr("Free draw"), ":/icons/pencil.png", [] { return new PathItem; }); addDrawingAction(menu, tr("Free draw"), ":/icons/pencil.png", [] { return new PathItem; });
@ -105,20 +106,19 @@ CropScene::CropScene(QObject *parent, QPixmap pixmap)
cursorItem->setZValue(3); cursorItem->setZValue(3);
magnifier = addPixmap(QPixmap(110, 110)); magnifier = addPixmap(QPixmap(110, 110));
magnifierBox = addRect(magnifier->boundingRect(), QPen(Qt::cyan)); magnifierBox = addRect(magnifier->boundingRect(), QPen(_highlight));
magnifier->setZValue(3); magnifier->setZValue(3);
magnifierBox->setZValue(1.1); magnifierBox->setZValue(1.1);
magnifierBox->setParentItem(magnifier); magnifierBox->setParentItem(magnifier);
magnifierHint = addText("ptr: (0, 0)\nsel: (-1, -1, 0, 0)"); magnifierHint = addText("ptr: (0, 0)\nsel: (-1, -1, 0, 0)");
magnifierHint->setParentItem(magnifier); magnifierHint->setParentItem(magnifier);
magnifierHint->setY(magnifier->boundingRect().height()); magnifierHint->setY(magnifier->boundingRect().height());
QColor c(Qt::cyan); QColor c(_highlight);
c.setAlphaF(.25); c.setAlphaF(.25);
magnifierHintBox = addRect(magnifierHint->boundingRect(), Qt::NoPen, c); magnifierHintBox = addRect(magnifierHint->boundingRect(), Qt::NoPen, c);
magnifierHintBox->setParentItem(magnifierHint); magnifierHintBox->setParentItem(magnifierHint);
magnifierHintBox->setZValue(1); magnifierHintBox->setZValue(1);
magnifierHint->setZValue(1.1); magnifierHint->setZValue(1.1);
initMagnifierGrid();
updateMag(); updateMag();
addItem(hint); addItem(hint);
@ -153,6 +153,7 @@ CropScene::CropScene(QObject *parent, QPixmap pixmap)
int w = screen->geometry().width(); int w = screen->geometry().width();
widget->setPos(views()[0]->mapToScene( widget->setPos(views()[0]->mapToScene(
QPoint(screen->geometry().x() + (w - widget->boundingRect().width()) / 2, screen->geometry().y() + 100))); 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; 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<DrawItem *()> drawAction) { void CropScene::setDrawingSelection(QString name, std::function<DrawItem *()> drawAction) {
this->setFocus(); this->setFocus();
drawingSelectionMaker = drawAction; drawingSelectionMaker = drawAction;
@ -229,7 +243,7 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
QCursor::setPos(views()[0]->mapToGlobal(cursorPos.toPoint())); QCursor::setPos(views()[0]->mapToGlobal(cursorPos.toPoint()));
} else } else
cursorPos = e->scenePos(); cursorPos = e->scenePos();
hint->setVisible(!hint->sceneBoundingRect().contains(cursorPos)); hint->setVisible(settings::settings().value("crophint").toBool() && !hint->sceneBoundingRect().contains(cursorPos));
cursorItem->setPos(cursorPos); cursorItem->setPos(cursorPos);
updateMag(); updateMag();
@ -248,7 +262,7 @@ void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
rect = new QGraphicsRectItem(p.x(), p.y(), 1, 1); rect = new QGraphicsRectItem(p.x(), p.y(), 1, 1);
initPos = p; initPos = p;
QPen pen(Qt::NoBrush, 1); QPen pen(Qt::NoBrush, 1);
pen.setColor(Qt::cyan); pen.setColor(_highlight);
rect->setPen(pen); rect->setPen(pen);
rect->setZValue(1); rect->setZValue(1);
addItem(rect); addItem(rect);
@ -322,7 +336,7 @@ void CropScene::wheelEvent(QGraphicsSceneWheelEvent *event) {
for (auto item : gridRectsY) delete item; for (auto item : gridRectsY) delete item;
gridRectsY.clear(); gridRectsY.clear();
initMagnifierGrid(); if (grid()) initMagnifierGrid();
updateMag(); updateMag();
if (!(event->modifiers() & Qt::ControlModifier)) QGraphicsScene::wheelEvent(event); if (!(event->modifiers() & Qt::ControlModifier)) QGraphicsScene::wheelEvent(event);
@ -378,7 +392,9 @@ void CropScene::updateMag() {
} }
void CropScene::initMagnifierGrid() { void CropScene::initMagnifierGrid() {
QColor c(Qt::cyan); if (!gridRectsX.isEmpty() || !gridRectsY.isEmpty()) return;
QColor c(_highlight);
c.setAlphaF(.25); c.setAlphaF(.25);
int pixCnt = settings::settings().value("magnifierPixelCount", 11).toInt(); int pixCnt = settings::settings().value("magnifierPixelCount", 11).toInt();
if (pixCnt % 2 == 0) pixCnt++; 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)); auto gridRectY = addRect(i * 110. / pixCnt, 0, 110. / pixCnt, 110, QPen(Qt::black, 0.5));
gridRectX->setParentItem(magnifierBox); gridRectX->setParentItem(magnifierBox);
gridRectY->setParentItem(magnifierBox); gridRectY->setParentItem(magnifierBox);
gridRectX->setZValue(1); gridRectX->setZValue(5);
gridRectY->setZValue(1); gridRectY->setZValue(5);
gridRectsX.append(gridRectX); gridRectsX.append(gridRectX);
gridRectsY.append(gridRectY); gridRectsY.append(gridRectY);
if (i == (pixCnt / 2)) { if (i == (pixCnt / 2)) {

View File

@ -23,6 +23,24 @@ public:
QPen &pen(); QPen &pen();
QBrush &brush(); QBrush &brush();
QFont &font(); 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<DrawItem *()> drawAction); void setDrawingSelection(QString name, std::function<DrawItem *()> drawAction);
QPixmap pixmap() { QPixmap pixmap() {
return _pixmap; return _pixmap;
@ -74,6 +92,8 @@ private:
QPen _pen; QPen _pen;
QBrush _brush; QBrush _brush;
QFont _font; QFont _font;
QColor _highlight;
bool _grid;
QGraphicsPolygonItem *polyItem = nullptr; QGraphicsPolygonItem *polyItem = nullptr;
DrawItem *drawingSelection = nullptr; DrawItem *drawingSelection = nullptr;
QMenuBar *menu = nullptr; QMenuBar *menu = nullptr;

View File

@ -16,7 +16,7 @@ bool BlurItem::init(CropScene *) {
void BlurItem::mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) { void BlurItem::mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) {
if (pos.isNull()) { if (pos.isNull()) {
pos = scene->cursorPosition(); 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 = scene->addPixmap(scene->pixmap().copy(rect->rect().toRect()));
pixmap->setPos(scene->cursorPosition()); pixmap->setPos(scene->cursorPosition());
pixmap->setZValue(rect->zValue() - 0.1); pixmap->setZValue(rect->zValue() - 0.1);

View File

@ -8,6 +8,7 @@
#include <QGraphicsBlurEffect> #include <QGraphicsBlurEffect>
#include <QInputDialog> #include <QInputDialog>
#include <QSlider> #include <QSlider>
#include <QTimer>
#include <cropeditor/cropview.hpp> #include <cropeditor/cropview.hpp>
#include <settings.hpp> #include <settings.hpp>
@ -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->radSlider->setValue(settings::settings().value("blur/radius", 5.).toDouble() * 100);
ui->radSpinner->setValue(settings::settings().value("blur/radius", 5.).toDouble()); ui->radSpinner->setValue(settings::settings().value("blur/radius", 5.).toDouble());
ui->gridBox->setChecked(scene->grid());
ui->cosmetic->setChecked(scene->pen().isCosmetic()); ui->cosmetic->setChecked(scene->pen().isCosmetic());
ui->widthSlider->setValue(scene->pen().width()); ui->widthSlider->setValue(scene->pen().width());
ui->widthSpinner->setValue(scene->pen().widthF()); ui->widthSpinner->setValue(scene->pen().widthF());
@ -36,6 +39,7 @@ BrushPenSelection::BrushPenSelection(CropScene *scene) : QDialog(), ui(new Ui::B
brush = scene->brush().color(); brush = scene->brush().color();
ui->alphaSlider->setValue(brush.alpha()); ui->alphaSlider->setValue(brush.alpha());
ui->alphaSpin->setValue(brush.alpha()); ui->alphaSpin->setValue(brush.alpha());
highlight = scene->highlight();
setWindowTitle(tr("Crop editor settings")); setWindowTitle(tr("Crop editor settings"));
this->scene = scene; this->scene = scene;
@ -60,12 +64,16 @@ void BrushPenSelection::on_buttonBox_accepted() {
scene->pen().setCosmetic(ui->cosmetic->isChecked()); scene->pen().setCosmetic(ui->cosmetic->isChecked());
scene->pen().setWidthF(ui->widthSpinner->value()); scene->pen().setWidthF(ui->widthSpinner->value());
scene->brush().setColor(brush); scene->brush().setColor(brush);
scene->setHighlight(highlight);
scene->setGrid(ui->gridBox->isChecked());
scene->brush().setStyle((Qt::BrushStyle)ui->brushStyle->currentIndex()); scene->brush().setStyle((Qt::BrushStyle)ui->brushStyle->currentIndex());
settings::settings().setValue("penColor", scene->pen().color()); settings::settings().setValue("penColor", scene->pen().color());
settings::settings().setValue("penCosmetic", scene->pen().isCosmetic()); settings::settings().setValue("penCosmetic", scene->pen().isCosmetic());
settings::settings().setValue("penWidth", scene->pen().widthF()); settings::settings().setValue("penWidth", scene->pen().widthF());
settings::settings().setValue("brushColor", scene->brush().color()); 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("brushStyle", (int)scene->brush().style());
settings::settings().setValue("brushPath", ui->pathItemHasBrush->isChecked()); settings::settings().setValue("brushPath", ui->pathItemHasBrush->isChecked());
settings::settings().setValue("blur/radius", ui->radSpinner->value()); 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) { void BrushPenSelection::on_penAlphaSpin_valueChanged(int arg1) {
pen.setAlpha(arg1); pen.setAlpha(arg1);
} }
void BrushPenSelection::on_highlightColor_clicked() {
highlight = QColorDialog::getColor(highlight, this, tr("Highlight color"));
}

View File

@ -27,10 +27,12 @@ private slots:
void on_widthSpinner_valueChanged(double arg1); void on_widthSpinner_valueChanged(double arg1);
void on_penAlphaSpin_valueChanged(int arg1); void on_penAlphaSpin_valueChanged(int arg1);
void on_highlightColor_clicked();
private: private:
Ui::BrushPenSelection *ui; Ui::BrushPenSelection *ui;
CropScene *scene; CropScene *scene;
QColor brush, pen; QColor brush, pen, highlight;
}; };
#endif // BRUSHPENSELECTION_HPP #endif // BRUSHPENSELECTION_HPP

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>442</width> <width>442</width>
<height>493</height> <height>550</height>
</rect> </rect>
</property> </property>
<property name="focusPolicy"> <property name="focusPolicy">
@ -84,7 +84,7 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="5" column="0" colspan="2"> <item row="6" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
@ -100,6 +100,16 @@
<string>Blur settings</string> <string>Blur settings</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0" colspan="2">
<widget class="QSlider" name="radSlider">
<property name="maximum">
<number>3000</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3"> <item row="3" column="0" colspan="3">
<widget class="QCheckBox" name="performance"> <widget class="QCheckBox" name="performance">
<property name="text"> <property name="text">
@ -107,6 +117,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="animated">
<property name="text">
<string>Animated Hint</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="quality">
<property name="text">
<string>Quality Hint</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2"> <item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="whatsThis"> <property name="whatsThis">
@ -123,6 +147,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="label">
<property name="text">
<string>Blur Radius</string>
</property>
</widget>
</item>
<item row="1" column="2"> <item row="1" column="2">
<widget class="QDoubleSpinBox" name="radSpinner"> <widget class="QDoubleSpinBox" name="radSpinner">
<property name="suffix"> <property name="suffix">
@ -133,54 +164,10 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="2">
<widget class="QSlider" name="radSlider">
<property name="maximum">
<number>3000</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="label">
<property name="text">
<string>Blur Radius</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="animated">
<property name="text">
<string>Animated Hint</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="quality">
<property name="text">
<string>Quality Hint</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="1" column="0" rowspan="4"> <item row="1" column="0" rowspan="5">
<widget class="QGroupBox" name="groupBox_2"> <widget class="QGroupBox" name="groupBox_2">
<property name="title"> <property name="title">
<string>Brush settings</string> <string>Brush settings</string>
@ -306,7 +293,7 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="3" column="1" rowspan="2"> <item row="4" column="1" rowspan="2">
<widget class="QGroupBox" name="groupBox_4"> <widget class="QGroupBox" name="groupBox_4">
<property name="title"> <property name="title">
<string>Arrow settings</string> <string>Arrow settings</string>
@ -342,6 +329,29 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="3" column="1">
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Other editor settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<widget class="QCheckBox" name="gridBox">
<property name="text">
<string>Enable grid</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="highlightColor">
<property name="text">
<string>Highligh color</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>