Skip to content

Commit

Permalink
Refactored Color Pick Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Oct 21, 2024
1 parent c0163dc commit b562250
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 222 deletions.
28 changes: 27 additions & 1 deletion src/app/GUI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ MainWindow::MainWindow(Document& document,
, mViewFillStrokeAct(nullptr)
, mRenderWindow(nullptr)
, mRenderWindowAct(nullptr)
, mColorPickLabel(nullptr)
{
Q_ASSERT(!sInstance);
sInstance = this;
Expand Down Expand Up @@ -188,6 +189,8 @@ MainWindow::MainWindow(Document& document,
this, &MainWindow::openApplyExpressionDialog);
connect(&mDocument, &Document::newVideo,
this, &MainWindow::handleNewVideoClip);
connect(&mDocument, &Document::currentPixelColor,
this, &MainWindow::handleCurrentPixelColor);

setWindowIcon(QIcon::fromTheme(AppSupport::getAppName()));

Expand Down Expand Up @@ -327,6 +330,10 @@ MainWindow::MainWindow(Document& document,

statusBar()->addPermanentWidget(mCanvasToolBar);

mColorPickLabel = new QLabel(this);
mColorPickLabel->setVisible(false);
statusBar()->addWidget(mColorPickLabel);

// final layout
mUI = new UILayout(this);
std::vector<UILayout::Item> docks;
Expand Down Expand Up @@ -1349,6 +1356,11 @@ void MainWindow::updateCanvasModeButtonsChecked()
mToolBoxDraw->setEnabled(drawMode);
mToolBoxDraw->setVisible(drawMode);
mLocalPivotAct->setEnabled(pointMode || boxMode);

if (mColorPickLabel) {
mColorPickLabel->clear();
mColorPickLabel->setVisible(mode == CanvasMode::pickFillStroke);
}
}

void MainWindow::setResolutionValue(const qreal value)
Expand Down Expand Up @@ -2090,4 +2102,18 @@ void MainWindow::handleNewVideoClip(const VideoBox::VideoSpecs &specs)
// open dialog if ask
AdjustSceneDialog dialog(scene, specs, this);
dialog.exec();
}
}

void MainWindow::handleCurrentPixelColor(const QColor &color)
{
if (!color.isValid()) {
mColorPickLabel->clear();
return;
}
mColorPickLabel->setText(QString("&nbsp;&nbsp;<span style=\"background-color: %4;\">"
"&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;"
"<b>RGB</b> %1, %2, %3").arg(QString::number(color.redF()),
QString::number(color.greenF()),
QString::number(color.blueF()),
color.name()));
}
4 changes: 4 additions & 0 deletions src/app/GUI/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ class MainWindow : public QMainWindow

void handleNewVideoClip(const VideoBox::VideoSpecs &specs);

void handleCurrentPixelColor(const QColor &color);

TimelineDockWidget *mTimeline;
RenderWidget *mRenderWidget;

Expand Down Expand Up @@ -380,6 +382,8 @@ class MainWindow : public QMainWindow
void initRenderPresets(const bool reinstall = false);
void askInstallRenderPresets();

QLabel *mColorPickLabel;

protected:
void keyPressEvent(QKeyEvent *event);
bool eventFilter(QObject *obj, QEvent *e);
Expand Down
7 changes: 4 additions & 3 deletions src/app/GUI/toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ void MainWindow::setupToolBoxMain()
mToolBoxGroupMain->addAction(nullModeAct);

// pickMode
/*QAction *pickModeAct = new QAction(QIcon::fromTheme("pick"),
tr("Pick Mode"),
QAction *pickModeAct = new QAction(QIcon::fromTheme("pick"),
tr("Color Pick Mode"),
this);
pickModeAct->setCheckable(true);
pickModeAct->setShortcut(QKeySequence(AppSupport::getSettings("shortcuts",
Expand All @@ -269,7 +269,8 @@ void MainWindow::setupToolBoxMain()
pickModeAct->setChecked(true);
}
});
mToolBoxGroupMain->addAction(pickModeAct);*/

mToolBoxGroupMain->addAction(pickModeAct);

mToolBoxMain->addActions(mToolBoxGroupMain->actions());

Expand Down
4 changes: 4 additions & 0 deletions src/core/Private/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ void Document::setActiveScene(Canvas * const scene) {
this, [this](QrealAnimator* const target) {
emit openApplyExpressionDialog(target);
});
conn << connect(fActiveScene, &Canvas::currentHoverColor,
this, [this](const QColor &color) {
emit currentPixelColor(color);
});
emit currentBoxChanged(fActiveScene->getCurrentBox());
emit selectedPaintSettingsChanged();
}
Expand Down
1 change: 1 addition & 0 deletions src/core/Private/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class CORE_EXPORT Document : public SingleWidgetTarget {
void openExpressionDialog(QrealAnimator* const target);
void openApplyExpressionDialog(QrealAnimator* const target);
void newVideo(const VideoBox::VideoSpecs specs);
void currentPixelColor(const QColor &color);
};

#endif // DOCUMENT_H
3 changes: 1 addition & 2 deletions src/core/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,7 @@ void Actions::setRectangleMode() {
}

void Actions::setPickPaintSettingsMode() {
// mDocument.setCanvasMode(CanvasMode::pickFillStroke);
// Disabled, why would anyone use this?
mDocument.setCanvasMode(CanvasMode::pickFillStroke);
}

void Actions::setCircleMode() {
Expand Down
4 changes: 4 additions & 0 deletions src/core/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,10 @@ void Canvas::updatePivot()

void Canvas::setCanvasMode(const CanvasMode mode)
{
if (mCurrentMode == CanvasMode::pickFillStroke) {
emit currentPickedColor(QColor());
emit currentHoverColor(QColor());
}
mCurrentMode = mode;
mSelecting = false;
mStylusDrawing = false;
Expand Down
4 changes: 4 additions & 0 deletions src/core/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ class CORE_EXPORT Canvas : public CanvasBase
void openMarkerEditor();
void openExpressionDialog(QrealAnimator* const target);
void openApplyExpressionDialog(QrealAnimator* const target);
void currentPickedColor(const QColor &color);
void currentHoverColor(const QColor &color);

public:
void makePointCtrlsSymmetric();
Expand Down Expand Up @@ -734,6 +736,8 @@ class CORE_EXPORT Canvas : public CanvasBase
void drawPathClear();
void drawPathFinish(const qreal invScale);

const QColor pickPixelColor(const QPoint &pos);

qreal mLastDRot = 0;
int mRotHalfCycles = 0;
TransformMode mTransMode = TransformMode::none;
Expand Down
35 changes: 24 additions & 11 deletions src/core/canvasmouseevents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,18 @@ void Canvas::mousePressEvent(const eMouseEvent &e) {
}
}

void Canvas::mouseMoveEvent(const eMouseEvent &e) {
if(mStylusDrawing) return;
if(isPreviewingOrRendering()) return;
void Canvas::mouseMoveEvent(const eMouseEvent &e)
{
if (mStylusDrawing) { return; }
if (isPreviewingOrRendering()) { return; }

const bool leftPressed = e.fButtons & Qt::LeftButton;

if(!leftPressed && !e.fMouseGrabbing) {
if (!leftPressed && !e.fMouseGrabbing) {
if (mCurrentMode == CanvasMode::pickFillStroke) {
emit currentHoverColor(pickPixelColor(e.fGlobalPos));
return;
}
const auto lastHoveredBox = mHoveredBox;
const auto lastHoveredPoint = mHoveredPoint_d;
const auto lastNSegment = mHoveredNormalSegment;
Expand Down Expand Up @@ -153,17 +158,25 @@ void Canvas::mouseMoveEvent(const eMouseEvent &e) {
e.fGrabMouse();
}

void Canvas::mouseReleaseEvent(const eMouseEvent &e) {
if(isPreviewingOrRendering()) return;
if(e.fButton == Qt::RightButton) {
if(mCurrentMode == CanvasMode::paint) {
} else if(mCurrentMode == CanvasMode::drawPath) {
void Canvas::mouseReleaseEvent(const eMouseEvent &e)
{
if (isPreviewingOrRendering()) { return; }
if (e.fButton == Qt::RightButton) {
switch(mCurrentMode) {
case CanvasMode::paint:
break;
case CanvasMode::drawPath:
drawPathClear();
} else {
break;
case CanvasMode::pickFillStroke:
emit currentPickedColor(QColor());
emit currentHoverColor(QColor());
break;
default:
handleRightButtonMouseRelease(e);
}
}
if(e.fButton != Qt::LeftButton) return;
if (e.fButton != Qt::LeftButton) { return; }
schedulePivotUpdate();
/*if(mCurrentMode == CanvasMode::paint) {
const auto paintMode = mDocument.fPaintMode;
Expand Down
41 changes: 15 additions & 26 deletions src/core/canvasmouseinteractions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#include "MovablePoints/smartnodepoint.h"
#include "MovablePoints/pathpivot.h"

#include <QDesktopWidget>
#include <QScreen>
#include <QMouseEvent>
#include <QMenu>
#include <QInputDialog>
Expand Down Expand Up @@ -242,7 +244,7 @@ void Canvas::handleLeftButtonMousePress(const eMouseEvent& e) {
mDrawPath.lineTo(e.fPos);
}
} else if(mCurrentMode == CanvasMode::pickFillStroke) {
mPressedBox = getBoxAtFromAllDescendents(e.fPos);
//mPressedBox = getBoxAtFromAllDescendents(e.fPos);
} else if(mCurrentMode == CanvasMode::circleCreate) {
const auto newPath = enve::make_shared<Circle>();
newPath->planCenterPivotPosition();
Expand Down Expand Up @@ -512,6 +514,17 @@ void Canvas::drawPathFinish(const qreal invScale) {
drawPathClear();
}

const QColor Canvas::pickPixelColor(const QPoint &pos)
{
QScreen *screen = QApplication::screenAt(pos);
if (!screen) { return QColor(); }
WId wid = QApplication::desktop()->winId();
QImage img = screen->grabWindow(wid,
pos.x(), pos.y(),
1, 1).toImage();
return QColor(img.pixel(0, 0));
}

void Canvas::handleLeftMouseRelease(const eMouseEvent &e) {
if(e.fMouseGrabbing) e.fReleaseMouse();
if(mCurrentNormalSegment.isValid()) {
Expand Down Expand Up @@ -541,31 +554,7 @@ void Canvas::handleLeftMouseRelease(const eMouseEvent &e) {
drawPathFinish(1/e.fScale);
}
} else if(mCurrentMode == CanvasMode::pickFillStroke) {
if(mPressedBox && enve_cast<PathBox*>(mPressedBox)) {
const auto srcPathBox = static_cast<PathBox*>(mPressedBox.data());
for(const auto& box : mSelectedBoxes) {
if(const auto pathBox = enve_cast<PathBox*>(box)) {
if(e.ctrlMod()) {
if(e.shiftMod()) {
pathBox->duplicateStrokeSettingsFrom(
srcPathBox->getStrokeSettings());
} else {
pathBox->duplicateFillSettingsFrom(
srcPathBox->getFillSettings());
}
} else {
if(e.shiftMod()) {
pathBox->duplicateStrokeSettingsNotAnimatedFrom(
srcPathBox->getStrokeSettings());
} else {
pathBox->duplicateFillSettingsNotAnimatedFrom(
srcPathBox->getFillSettings());
}
}
}
}
}
//mCanvasWindow->setCanvasMode(MOVE_PATH);
emit currentPickedColor(pickPixelColor(e.fGlobalPos));
}
mValueInput.clearAndDisableInput();
mTransMode = TransformMode::none;
Expand Down
2 changes: 0 additions & 2 deletions src/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ set(
widgets/canvassettingswidget.cpp
widgets/canvastoolbar.cpp
widgets/changewidthwidget.cpp
widgets/colorpickingwidget.cpp
widgets/colortoolbar.cpp
widgets/colortoolbutton.cpp
widgets/colorlabel.cpp
Expand Down Expand Up @@ -147,7 +146,6 @@ set(
widgets/canvassettingswidget.h
widgets/canvastoolbar.h
widgets/changewidthwidget.h
widgets/colorpickingwidget.h
widgets/colortoolbar.h
widgets/colortoolbutton.h
widgets/colorlabel.h
Expand Down
Loading

0 comments on commit b562250

Please sign in to comment.