Make highlight colors and grid changeable
This commit is contained in:
parent
c19221cd37
commit
db1108079d
@ -1,6 +1,7 @@
|
||||
#include "colorpickerscene.hpp"
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QDebug>
|
||||
#include <QGraphicsEllipseItem>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QGraphicsTextItem>
|
||||
@ -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.");
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ CropScene::CropScene(QObject *parent, QPixmap pixmap)
|
||||
brush().setColor(settings::settings().value("brushColor", brush().color()).value<QColor>());
|
||||
brush().setStyle(
|
||||
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;
|
||||
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<DrawItem *()> 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)) {
|
||||
|
@ -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<DrawItem *()> 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;
|
||||
|
@ -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);
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <QGraphicsBlurEffect>
|
||||
#include <QInputDialog>
|
||||
#include <QSlider>
|
||||
#include <QTimer>
|
||||
#include <cropeditor/cropview.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->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"));
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>442</width>
|
||||
<height>493</height>
|
||||
<height>550</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
@ -84,7 +84,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<item row="6" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
@ -100,6 +100,16 @@
|
||||
<string>Blur settings</string>
|
||||
</property>
|
||||
<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">
|
||||
<widget class="QCheckBox" name="performance">
|
||||
<property name="text">
|
||||
@ -107,6 +117,20 @@
|
||||
</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="2" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="whatsThis">
|
||||
@ -123,6 +147,13 @@
|
||||
</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="1" column="2">
|
||||
<widget class="QDoubleSpinBox" name="radSpinner">
|
||||
<property name="suffix">
|
||||
@ -133,54 +164,10 @@
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" rowspan="4">
|
||||
<item row="1" column="0" rowspan="5">
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Brush settings</string>
|
||||
@ -306,7 +293,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1" rowspan="2">
|
||||
<item row="4" column="1" rowspan="2">
|
||||
<widget class="QGroupBox" name="groupBox_4">
|
||||
<property name="title">
|
||||
<string>Arrow settings</string>
|
||||
@ -342,6 +329,29 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
Loading…
Reference in New Issue
Block a user