[Digikam-devel] extragear/graphics/digikam/utilities/fuzzysearch
Andi Clemens
andi.clemens at gmx.net
Fri Nov 12 15:36:22 GMT 2010
SVN commit 1196102 by aclemens:
Make the SketchWidget a little bit more user-friendly:
- Use the CTRL+mouse wheel to increase / decrease the pen size
- Use the SHIFT+CTRL+mouse wheel to increase / decrease the pen size (single step)
- Use the CTRL key and left mouse click to sample the underlying color
We could do the same thing for the liquid rescale plugin??
CCMAIL: digikam-devel at kde.org
M +13 -1 fuzzysearchview.cpp
M +1 -0 fuzzysearchview.h
M +102 -17 sketchwidget.cpp
M +6 -0 sketchwidget.h
--- trunk/extragear/graphics/digikam/utilities/fuzzysearch/fuzzysearchview.cpp #1196101:1196102
@@ -379,7 +379,7 @@
QLabel* brushLabel = new QLabel(i18n("Pen:"));
d->penSize = new QSpinBox();
- d->penSize->setRange(1, 40);
+ d->penSize->setRange(1, 64);
d->penSize->setSingleStep(1);
d->penSize->setValue(10);
d->penSize->setWhatsThis(i18n("Set here the brush size in pixels used to draw sketch."));
@@ -471,6 +471,12 @@
connect(d->resetButton, SIGNAL(clicked()),
this, SLOT(slotClearSketch()));
+ connect(d->sketchWidget, SIGNAL(signalPenSizeChanged(int)),
+ d->penSize, SLOT(setValue(int)));
+
+ connect(d->sketchWidget, SIGNAL(signalPenColorChanged(const QColor&)),
+ this, SLOT(slotPenColorChanged(const QColor&)));
+
connect(d->sketchWidget, SIGNAL(signalSketchChanged(const QImage&)),
this, SLOT(slotDirtySketch()));
@@ -704,6 +710,12 @@
setColor(color);
}
+void FuzzySearchView::slotPenColorChanged(const QColor& color)
+{
+ slotHSChanged(color.hue(), color.saturation());
+ slotVChanged(color.value());
+}
+
void FuzzySearchView::setColor(QColor c)
{
if (c.isValid())
--- trunk/extragear/graphics/digikam/utilities/fuzzysearch/fuzzysearchview.h #1196101:1196102
@@ -88,6 +88,7 @@
void slotHSChanged(int h, int s);
void slotVChanged(int v);
+ void slotPenColorChanged(const QColor&);
void slotClearSketch();
void slotSaveSketchSAlbum();
void slotCheckNameEditSketchConditions();
--- trunk/extragear/graphics/digikam/utilities/fuzzysearch/sketchwidget.cpp #1196101:1196102
@@ -26,6 +26,7 @@
// Qt includes
+#include <QCursor>
#include <QMap>
#include <QPainter>
#include <QPainterPath>
@@ -47,18 +48,17 @@
{
public:
- DrawEvent()
- {
- penWidth = 10;
- penColor = Qt::black;
- };
+ DrawEvent() :
+ penWidth(10),
+ penColor(Qt::black)
+ {};
- DrawEvent(int width, const QColor& color)
- {
- penWidth = width;
- penColor = color;
- };
+ DrawEvent(int width, const QColor& color) :
+ penWidth(width),
+ penColor(color)
+ {};
+
void lineTo(const QPoint &pos)
{
path.lineTo(pos);
@@ -77,14 +77,14 @@
{
public:
- SketchWidgetPriv()
+ SketchWidgetPriv() :
+ isClear(true),
+ drawing(false),
+ penWidth(10),
+ eventIndex(-1),
+ penColor(Qt::black)
{
- isClear = true;
- drawing = false;
- penWidth = 10;
- penColor = Qt::black;
pixmap = QPixmap(256, 256);
- eventIndex = -1;
}
bool isClear;
@@ -100,6 +100,8 @@
QPoint lastPoint;
QTime drawEventCreationTime;
+ QCursor drawCursor;
+
QList<DrawEvent> drawEventList;
void startDrawEvent(const QPoint& pos)
@@ -149,6 +151,7 @@
setAttribute(Qt::WA_StaticContents);
setMouseTracking(true);
setFixedSize(256, 256);
+ setFocusPolicy(Qt::StrongFocus);
slotClear();
}
@@ -186,6 +189,7 @@
void SketchWidget::setPenWidth(int newWidth)
{
d->penWidth = newWidth;
+ updateDrawCursor();
d->ensureNewDrawEvent();
}
@@ -431,8 +435,17 @@
update();
}
+ // sample color
+ if (e->modifiers() & Qt::CTRL)
+ {
+ QImage img = d->pixmap.toImage();
+ emit signalPenColorChanged((img.pixel(e->pos())));
+ return;
+ }
+
d->lastPoint = e->pos();
d->drawing = true;
+ setCursor(d->drawCursor);
d->startDrawEvent(e->pos());
}
@@ -442,9 +455,18 @@
{
if (rect().contains(e->x(), e->y()))
{
+ setFocus();
+
+ if (d->drawing || e->modifiers() & Qt::CTRL)
+ {
+ setCursor(d->drawCursor);
+ }
+ else
+ {
setCursor(Qt::CrossCursor);
+ }
- if ((e->buttons() & Qt::LeftButton) && d->drawing)
+ if ((e->buttons() & Qt::LeftButton))
{
QPoint currentPos = e->pos();
d->currentDrawEvent().lineTo(currentPos);
@@ -454,9 +476,30 @@
else
{
unsetCursor();
+ clearFocus();
}
}
+void SketchWidget::wheelEvent (QWheelEvent* e)
+{
+ if (rect().contains(e->x(), e->y()) && e->modifiers() & Qt::CTRL)
+ {
+ int size = d->penWidth;
+ int decr = (e->modifiers() & Qt::SHIFT) ? 1 : 10;
+
+ if (e->delta() > 0)
+ {
+ size += decr;
+ }
+ else
+ {
+ size -= decr;
+ }
+ emit signalPenSizeChanged(size);
+ setCursor(d->drawCursor);
+ }
+}
+
void SketchWidget::mouseReleaseEvent(QMouseEvent* e)
{
if (e->button() == Qt::LeftButton && d->drawing)
@@ -464,11 +507,32 @@
QPoint currentPos = e->pos();
d->currentDrawEvent().lineTo(currentPos);
d->drawing = false;
+ setCursor(Qt::CrossCursor);
emit signalSketchChanged(sketchImage());
emit signalUndoRedoStateChanged(true, false);
}
}
+void SketchWidget::keyPressEvent(QKeyEvent* e)
+{
+ QWidget::keyPressEvent(e);
+
+ if (e->modifiers() == Qt::CTRL)
+ {
+ setCursor(d->drawCursor);
+ }
+}
+
+void SketchWidget::keyReleaseEvent(QKeyEvent* e)
+{
+ QWidget::keyReleaseEvent(e);
+
+ if (e->key() == Qt::Key_Control)
+ {
+ setCursor(Qt::CrossCursor);
+ }
+}
+
void SketchWidget::paintEvent(QPaintEvent*)
{
QPainter p(this);
@@ -510,4 +574,25 @@
d->lastPoint = path.currentPosition().toPoint();
}
+void SketchWidget::updateDrawCursor()
+{
+ int size = d->penWidth;
+ if (size > 64)
+ size = 64;
+
+ QPixmap pix(size, size);
+ pix.fill(Qt::transparent);
+
+ QPainter p(&pix);
+ if (size > 4)
+ {
+ int middle = size / 2;
+ p.drawLine(middle - 2, middle, middle + 2, middle);
+ p.drawLine(middle, middle - 2, middle, middle + 2);
+ }
+ p.drawEllipse( 0, 0, size-1, size-1);
+
+ d->drawCursor = QCursor(pix);
+}
+
} // namespace Digikam
--- trunk/extragear/graphics/digikam/utilities/fuzzysearch/sketchwidget.h #1196101:1196102
@@ -66,6 +66,8 @@
Q_SIGNALS:
void signalSketchChanged(const QImage&);
+ void signalPenSizeChanged(int);
+ void signalPenColorChanged(const QColor&);
void signalUndoRedoStateChanged(bool hasUndo, bool hasRedo);
public Q_SLOTS:
@@ -80,11 +82,15 @@
void mousePressEvent(QMouseEvent*);
void mouseMoveEvent(QMouseEvent*);
+ void wheelEvent (QWheelEvent*);
void mouseReleaseEvent(QMouseEvent*);
+ void keyPressEvent (QKeyEvent*);
+ void keyReleaseEvent(QKeyEvent*);
void paintEvent(QPaintEvent*);
private:
+ void updateDrawCursor();
void replayEvents(int index);
void drawLineTo(const QPoint& endPoint);
void drawLineTo(int width, const QColor& color, const QPoint& start, const QPoint& end);
More information about the Digikam-devel
mailing list