summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Le Garrec <legarrec.vincent@gmail.com>2018-01-15 23:28:40 +0100
committerVincent Le Garrec <legarrec.vincent@gmail.com>2018-01-15 23:28:40 +0100
commit7fd8902e6b423f76aae473f78b210d175e539433 (patch)
tree88c859aa43845bb7090e8e277b460a32fd93c5c7
parentAdd event to draw checkbox (diff)
downloadcore-7fd8902e6b423f76aae473f78b210d175e539433.tar.gz
core-7fd8902e6b423f76aae473f78b210d175e539433.zip
Allow draw symbol with mouse
Use left click to draw black symbol. Use right click to rub the symbol. Change-Id: I3cb2155f105452f8b0f92a7fe2873ce98168cf2d
-rw-r--r--cui/source/dialogs/cuicharmap.cxx93
-rw-r--r--cui/source/inc/cuicharmap.hxx24
-rw-r--r--cui/uiconfig/ui/specialcharacters.ui6
3 files changed, 118 insertions, 5 deletions
diff --git a/cui/source/dialogs/cuicharmap.cxx b/cui/source/dialogs/cuicharmap.cxx
index 4c6a2b3a3d82..7ca01ffba5b1 100644
--- a/cui/source/dialogs/cuicharmap.cxx
+++ b/cui/source/dialogs/cuicharmap.cxx
@@ -1281,4 +1281,97 @@ void SvxShowText::SetText( const OUString& rText )
}
+VCL_BUILDER_FACTORY(DrawingAreaOcr)
+
+void DrawingAreaOcr::MouseButtonDown (const MouseEvent &rMEvt)
+{
+ if (rMEvt.IsLeft())
+ {
+ state = State::DRAW;
+ }
+ else if (rMEvt.IsRight())
+ {
+ state = State::DELETE;
+ }
+
+ if (state != State::NONE)
+ {
+ const Point & mouse_pos = rMEvt.GetPosPixel();
+
+ data.emplace_back(mouse_pos.X(), mouse_pos.Y(), state);
+ }
+}
+
+void DrawingAreaOcr::MouseMove( const MouseEvent &rMEvt )
+{
+ const Point & mouse_pos = rMEvt.GetPosPixel();
+
+ if (state != State::NONE)
+ {
+ data.emplace_back(mouse_pos.X(), mouse_pos.Y(), state);
+ }
+
+ Invalidate();
+ Update();
+ std::cout << static_cast<int>(state) << std::endl;
+}
+
+void DrawingAreaOcr::MouseButtonUp (const MouseEvent &rMEvt)
+{
+ const Point & mouse_pos = rMEvt.GetPosPixel();
+ state = State::NONE;
+ data.emplace_back(mouse_pos.X(), mouse_pos.Y(), state);
+}
+
+void DrawingAreaOcr::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle&)
+{
+ Color aTextCol = rRenderContext.GetLineColor();
+
+ rRenderContext.SetLineColor(Color( COL_WHITE ));
+ rRenderContext.DrawRect(tools::Rectangle(Point(0, 0), Size(GetOutputSizePixel().Width(), GetOutputSizePixel().Height())));
+
+ const auto * i_1 = &data.front();
+ basegfx::B2DPolygon aB2DPolyLine;
+ for (const auto & i : data)
+ {
+ if (i_1->state == i.state)
+ {
+ aB2DPolyLine.append(basegfx::B2DPoint(i.x, i.y));
+ }
+ else
+ {
+ if (i_1->state == State::DRAW)
+ {
+ rRenderContext.SetLineColor(Color( COL_BLACK ));
+ rRenderContext.DrawPolyLine(aB2DPolyLine, 10.0);
+ }
+ else if (i_1->state == State::DELETE)
+ {
+ rRenderContext.SetLineColor(Color( COL_WHITE ));
+ rRenderContext.DrawPolyLine(aB2DPolyLine, 10.0);
+ }
+ aB2DPolyLine.clear();
+ }
+ i_1 = &i;
+ }
+
+ size_t size = data.size();
+ if (size >= 2)
+ {
+ if (data[size-2].state == State::DRAW)
+ {
+ rRenderContext.SetLineColor(Color( COL_BLACK ));
+ rRenderContext.DrawPolyLine(aB2DPolyLine, 10.0);
+ }
+ else if (data[size-2].state == State::DELETE)
+ {
+ rRenderContext.SetLineColor(Color( COL_WHITE ));
+ rRenderContext.DrawPolyLine(aB2DPolyLine, 10.0);
+ }
+ aB2DPolyLine.clear();
+ }
+
+ rRenderContext.SetTextLineColor(aTextCol);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cui/source/inc/cuicharmap.hxx b/cui/source/inc/cuicharmap.hxx
index 7e2619efc10b..752678e1ad91 100644
--- a/cui/source/inc/cuicharmap.hxx
+++ b/cui/source/inc/cuicharmap.hxx
@@ -39,6 +39,28 @@ namespace svx
struct SvxShowCharSetItem;
}
+class DrawingAreaOcr : public Control
+{
+public:
+ DrawingAreaOcr(vcl::Window* pParent) : Control(pParent, WB_BORDER), state(State::NONE) {}
+ void MouseButtonDown (const MouseEvent &rMEvt) override;
+ void MouseMove( const MouseEvent &rMEvt ) override;
+ void MouseButtonUp (const MouseEvent &rMEvt) override;
+ void Paint( vcl::RenderContext& rRenderContext, const ::tools::Rectangle& ) override;
+
+private:
+ enum class State {DRAW, DELETE, NONE};
+ State state;
+ struct DrawPoint
+ {
+ int x;
+ int y;
+ State state;
+ DrawPoint(int x_, int y_, State state_) : x(x_), y(y_), state(state_) {};
+ };
+ std::vector<DrawPoint> data;
+};
+
class SvxShowText : public Control
{
public:
@@ -79,7 +101,7 @@ private:
VclPtr<ListBox> m_pSubsetLB;
VclPtr<SvxShowText> m_pShowChar;
VclPtr<CheckBox> m_pDrawChk;
- VclPtr<vcl::Window> m_pDrawingArea;
+ VclPtr<DrawingAreaOcr> m_pDrawingArea;
VclPtr<Edit> m_pSearchText;
VclPtr<Edit> m_pHexCodeText;
VclPtr<Edit> m_pDecimalCodeText;
diff --git a/cui/uiconfig/ui/specialcharacters.ui b/cui/uiconfig/ui/specialcharacters.ui
index ca21156de36c..9067d6fbb163 100644
--- a/cui/uiconfig/ui/specialcharacters.ui
+++ b/cui/uiconfig/ui/specialcharacters.ui
@@ -202,17 +202,15 @@
</packing>
</child>
<child>
- <object class="GtkDrawingArea" id="drawingarea">
+ <object class="cuilo-DrawingAreaOcr" id="drawingarea">
<property name="width_request">80</property>
<property name="height_request">150</property>
<property name="visible">False</property>
- <property name="can_focus">True</property>
+ <property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
</object>
<packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>