diff options
| author | Michael Lauer <mickey@vanille-media.de> | 2006-05-21 15:33:23 +0000 |
|---|---|---|
| committer | OpenEmbedded Project <openembedded-devel@lists.openembedded.org> | 2006-05-21 15:33:23 +0000 |
| commit | 007c005529f5cf15d05b076845fbd2cd12a547f4 (patch) | |
| tree | 7d304f223f006545e569686e45eb7f2a4ff34302 | |
| parent | 1c35191af98492f5aad3f217622f3705ea2acb6b (diff) | |
add freenote, an error correcting paint program for Opie. patch based on work by Enodr <nicolasfr@gmail.com>, thanks! closes
#1018
21 files changed, 4729 insertions, 3307 deletions
diff --git a/packages/nonworking/freenote/.mtn2git_empty b/packages/freenote/.mtn2git_empty index e69de29bb2..e69de29bb2 100644 --- a/packages/nonworking/freenote/.mtn2git_empty +++ b/packages/freenote/.mtn2git_empty diff --git a/packages/nonworking/freenote/freenote-1.6.1/.mtn2git_empty b/packages/freenote/files/.mtn2git_empty index e69de29bb2..e69de29bb2 100644 --- a/packages/nonworking/freenote/freenote-1.6.1/.mtn2git_empty +++ b/packages/freenote/files/.mtn2git_empty diff --git a/packages/freenote/files/FreeNote/.mtn2git_empty b/packages/freenote/files/FreeNote/.mtn2git_empty new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/packages/freenote/files/FreeNote/.mtn2git_empty diff --git a/packages/freenote/files/FreeNote/FreeNote/.mtn2git_empty b/packages/freenote/files/FreeNote/FreeNote/.mtn2git_empty new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/packages/freenote/files/FreeNote/FreeNote/.mtn2git_empty diff --git a/packages/freenote/files/FreeNote/FreeNote/FNCanvas.cpp b/packages/freenote/files/FreeNote/FreeNote/FNCanvas.cpp new file mode 100644 index 0000000000..6e7f615600 --- /dev/null +++ b/packages/freenote/files/FreeNote/FreeNote/FNCanvas.cpp @@ -0,0 +1,2244 @@ +/* FreeNote for Sharp SLA300, B500, C7x0, C860 Linux PDA
+ Copyright (C) 2003-2005 Joe Kanemori.<kanemori@ymg.urban.ne.jp>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+/*
+2005/06/04 FreeNote 1.11.12pre
+・グリッドの枠線を実際の選択範囲よりも大きく表示するように変更。
+・範囲選択、グリッド、ガイド、罫線カラーのカスタマイズを可能に。
+・カラーピッカーモードの追加
+
+2005/06/02 FreeNote 1.11.11Apre
+・テキスト移動枠の不具合修正
+・罫線をグリッドの2倍で表示するように変更
+・消しゴム時の範囲指定時に、ペンオフしてワンテンポおいてから範囲確定するように変更
+
+2005/03/18 FreeNote 1.11.10Bpre
+・描画の最適化
+
+2005/02/27 FreeNote 1.11.10pre
+・PDFの出力形式を一部変更
+・インポート時のバグfix
+
+2005/01/04 FreeNote 1.11.6pre
+・カーブモードで8の字がかけるように整形エンジンを改善
+
+2005/01/04 FreeNote 1.11.5Apre
+・バグフィックス
+
+2004/12/25 FreeNote 1.11.5pre
+・レイヤー機能追加
+
+2004/11/24 FreeNote 1.11.0pre
+・テキストペースト機能
+
+2004/10/17 FreeNote 1.10.0リリース
+2004/08/26 ver 1.9.3pre
+・罫線機能を追加
+
+2004/05/23 ver 1.9.1Apre
+・欧文環境対応
+
+2004/02/16 ver 1.7.3pre
+・編集機能強化
+
+2004/02/14 ver 1.7.2pre
+・検索機能追加
+
+2004/02/12 ver 1.7.1pre
+・フォント仕様の変更
+・テキスト処理の高速化
+・テキストボックスの多機能化
+
+2003/02/10 ver 1.7.0pre
+・文字入力
+
+2003/12/23 ver 1.6.1
+・保存情報のサイズ縮小
+
+2003/12/16-19 ver 1.5.5pre
+・ペンサイズの追加(1-8)
+・アンドゥ・リドゥの実装
+
+2003/12/14 ver 1.5.4pre
+・ペンサイズを選択可能に。
+
+2003/12/05 ver 1.5.3Apre
+・グリッドの色を修正
+
+2003/12/04 ver 1.5.3pre
+・グリッドの描画を一部修正
+
+2003/11/10 ver 1.5.1pre
+・曲線整形モード追加
+
+2003/11/09 ver 1.5.0pre
+・自動整形モード追加
+
+2003/09/03 ver 1.3.4pre
+・Use all quadrant OFF時に表示位置がリセットされる場合があるバグ対応。
+
+2003/09/01-03 ver 1.3.3pre
+・スクロールの改良
+・Use all quadrant(全象限を使用する)メニューを追加
+
+2003/08/31 FreeNote 1.3.2pre
+・全方向スクロール
+
+2003/08/23 FreeNote 1.3.0pre
+・CR動作の修正
+
+2003/08/15 FreeNote 1.2.1を公開
+・保存時のバグ修正
+・完了ダイアログの自動消去
+・PNGファイルへの出力
+
+2003/08/15 FreeNote 1.2を公開
+・オプション追加
+・スクロールガイド
+・Freeファイル関連付け
+・アイコンの変更
+
+2003/08/05 FreeNote 1.1.1preを公開
+・高速起動時に閉じた状態を保持
+・描画モード切替え時に消しゴム表示
+・保存時間短縮
+・Viewモードの挙動を変更
+・メニューの見た目を変更
+*/
+#include "fncanvas.h"
+#include <qsjiscodec.h>
+#include <stdio.h>
+#include <qfile.h>
+#include <qmessagebox.h>
+#include <qtextstream.h>
+#include <qpen.h>
+#include <qcolor.h>
+#include <qpoint.h>
+#include <qthread.h>
+#include <qimage.h>
+#include <math.h>
+#include <qtextcodec.h>
+#include <qmultilineedit.h>
+#include <qbitmap.h>
+#include "fnmessagebox.h"
+#include "fmtengine.h"
+#include "fntextdialog.h"
+#include <qfont.h>
+#include <qapplication.h>
+#include <qclipboard.h>
+#include "frmmain.h"
+#include "fnlayerdlg.h"
+#include <stdlib.h>
+
+int snap(int v) {
+ int tv = abs(v);
+ tv = ((int)(tv + SNAP_SIZE / 2) / SNAP_SIZE) * SNAP_SIZE;
+ if (0 > v) {
+ return -tv;
+ } else {
+ return tv;
+ }
+}
+
+FNCanvas::FNCanvas(FNColorDialog* dlg, QWidget* parent, const char* name, WFlags f)
+ :QWidget(parent, name, f),
+ _txtTmp(NULL),
+ _pen(black, 1, SolidLine, RoundCap, RoundJoin),
+ _asMode(AS_NONE),
+ _drawMode(MODE_DRAW),
+ _prevMode(MODE_DRAW),
+ _eraser_l(50),
+ _eraser_s(10),
+ _h_step(100),
+ _v_step(100),
+ _margin(5),
+ _scrollTiming(800),
+ _selIdx(0),
+ _viewMode(false),
+ _isWaiting(false),
+ _isDragging(false),
+ _isDrawing(false),
+ _isHeadingEnables(false),
+ _isShowGuide(false),
+ _isUseAllQuadrant(false),
+ _showRuler(false),
+ _isTinyPaging(false),
+ _scale_x(1.0),
+ _scale_y(1.0),
+ _tboxRect(0, 50, 220, 240),
+ _isEraseWaiting(false),
+ _colorSelector(dlg),
+ _isColorRevision(true)
+{
+ _tracks.setAutoDelete(true);
+ _clipboard.setAutoDelete(true);
+ _current = new FNLayer();
+ _layers.append(_current);
+ _layers.setAutoDelete(true);
+ _undobuf.setAutoDelete(true);
+ _current->Name = "Layer0";
+ this->setBackgroundMode(NoBackground);
+ _timer = new QTimer(this);
+ connect(_timer, SIGNAL(timeout()), this, SLOT(autoScroll()));
+ _dlgFind = new FNFindDialog(this, "Find");
+ connect(_dlgFind, SIGNAL(originChanged(int, int)), this, SLOT(setOrigin(int, int)));
+ connect(_dlgFind, SIGNAL(resetOrigin()), this, SLOT(resetOrigin()));
+
+}
+
+FNCanvas::~FNCanvas()
+{
+ _timer->stop();
+ delete _timer;
+
+ _tracks.clear();
+ _layers.clear();
+ //clearList(_draws);
+
+ delete _dlgFind;
+}
+
+
+void FNCanvas::addLayer()
+{
+ FNLayer* layer = new FNLayer();
+ _current=layer;
+ uint cnt = _layers.count();
+ while (1) {
+ QString name = "Layer";
+ name += QString::number(cnt);
+
+ bool nameExists = false;
+ for (uint i = 0; i < _layers.count(); ++i) {
+ if (_layers.at(i)->Name == name) {
+ nameExists = true;
+ break;
+ }
+ }
+ if (false == nameExists) {
+ layer->Name = name;
+ break;
+ }
+ ++cnt;
+ }
+ _layers.append(layer);
+ _selIdx = _layers.count() - 1;
+ redraw();
+
+}
+
+//表示レイヤーを下に移動する
+void FNCanvas::moveAboveLayer()
+{
+ --_selIdx;
+ if (0 > _selIdx) {
+ _selIdx = 0;
+ }
+ _current = _layers.at(_selIdx);
+ redraw();
+}
+
+//表示レイヤーを上に移動する
+void FNCanvas::moveBelowLayer()
+{
+ ++_selIdx;
+ if (_layers.count() - 1 <= (uint)_selIdx) {
+ _selIdx = _layers.count() - 1;
+ }
+ _current = _layers.at(_selIdx);
+ redraw();
+}
+
+
+void FNCanvas::setScrollTiming(int v)
+{
+ _scrollTiming = v;
+}
+
+
+void FNCanvas::setVStep(int v)
+{
+ _v_step = v;
+}
+
+void FNCanvas::setHStep(int v)
+{
+ _h_step = v;
+}
+
+void FNCanvas::setSEraser(int v)
+{
+ _eraser_s = v;
+}
+
+void FNCanvas::setLEraser(int v)
+{
+ _eraser_l = v;
+}
+
+
+void FNCanvas::setMargin(int v)
+{
+ if (v < 3) {
+ v = 3;
+ }
+ _margin = v;
+}
+void FNCanvas::find()
+{
+ if (_viewMode) {
+ return;
+ }
+ _dlgFind->setElements(_layers);
+ _dlgFind->show();
+ _dlgFind->exec();
+}
+
+void FNCanvas::setScrollMode(int as)
+{
+ _asMode = as;
+ redraw();
+}
+
+void FNCanvas::autoScroll()
+{
+ if (MODE_ERASE == _drawMode) {
+ if (0 < _selection.width()) {
+ int hsn = SNAP_SIZE / 2;
+ int qsn = hsn / 2;
+ int x = ((_selection.x() - qsn) / hsn) * hsn;
+ int y = ((_selection.y() - qsn) / hsn) * hsn;
+ int dx = _selection.x() - x;
+ int dy = _selection.y() - y;
+ int w = ((_selection.width() + dx + hsn) / hsn) * hsn;
+ int h = ((_selection.height() + dy + hsn) / hsn) * hsn;
+ _selection.setRect(x, y, w, h);
+ _isSelected = true;
+ }
+ _last = QPoint(-1, -1);
+ _tracks.clear();
+ _isHeadingEnables = false;
+ _isEraseWaiting = false;
+ redraw();
+ } else {
+ if (AS_NONE == _asMode) {
+ setOrigin(_origin.x(), _origin.y(), false);
+ redraw();
+ return;
+ }
+ bool tmp = _isHeadingEnables;
+ int dx = 0;
+ int dy = 0;
+ if (AS_BOTH == _asMode || AS_HORIZONTAL == _asMode) {
+ if (_last.x() > width() * (_margin - 1) / _margin) {
+ dx = _h_step;
+ } else if (_last.x() < width() / _margin) {
+ dx = -_h_step;
+ }
+ }
+ if (AS_BOTH == _asMode || AS_VERTICAL == _asMode) {
+ if (_last.y() > height() * (_margin - 1) / _margin) {
+ dy = _v_step;
+ } else if (_last.y() < height() / _margin) {
+ dy = -_v_step;
+ }
+ }
+ setOrigin(_origin.x() + dx, _origin.y() + dy, false);
+ _isHeadingEnables = tmp;
+ redraw();
+ }
+}
+
+void FNCanvas::drawRect(QPainter& pa, const QRect& r)
+{
+ int w = width();
+ int h = height();
+ int sx = r.left();
+ int sy = r.top();
+ int ex = r.right();
+ int ey = r.bottom();
+ if (0 > sx) {
+ sx = 0;
+ }
+ if (0 > sy) {
+ sy = 0;
+ }
+ if (h < ey) {
+ ey = h;
+ }
+ if (w < ex) {
+ ex = w;
+ }
+ if (0 <= r.left()) {
+ pa.drawLine(sx, sy, sx, ey);
+ }
+ if (0 <= r.top()) {
+ pa.drawLine(sx, sy, ex, sy);
+ }
+ if (w >= r.right()) {
+ pa.drawLine(ex, sy, ex, ey);
+ }
+ if (h >= r.bottom()) {
+ pa.drawLine(sx, ey, ex, ey);
+ }
+}
+
+void FNCanvas::mousePressEvent(QMouseEvent* evt)
+{
+ if (!_current->IsShow) {
+ return;
+ }
+ setFocus();
+ _timer->stop();
+ _tracks.clear();
+ _txtwait = 10;
+ if (_viewMode) {
+ _isWaiting = true;
+ _viewMode = false;
+ setOrigin((int)((evt->x()) / _scale_x) - width() / 2, (int)((evt->y()) / _scale_y) - height() / 2, false);
+ //redraw();
+ emit resetViewMode();
+ } else if (MODE_CPICK == _drawMode) {
+ QRgb c = _buffer.convertToImage().pixel(evt->pos().x(), evt->pos().y());
+ emit pickColor(c);
+ return;
+ } else if (MODE_TEXT == _drawMode) {
+ _txtTmp = NULL;
+// _last = evt->pos();
+ _last = SnapPoint(evt->pos(), SNAP_SIZE / 4);
+ int x = _last.x();
+ int y = _last.y();
+ for (int i = _current->draws.count() - _current->disp_offset() - 1; i >= 0; --i) {
+ FNPolygon* p = _current->draws.at((uint)i);
+ if (FN_TEXT == p->type()) {
+ QRect r = p->boundingRect();
+ if (r.contains(x, y)) {
+ _txtTmp = (FNText*)p;
+ _selection.setRect(0, 0, -1, -1);
+ _tdx = _last.x() - r.x();
+ _tdy = _last.y() - r.y();
+ break;
+ }
+ }
+ }
+ } else if (MODE_ERASE == _drawMode) {
+ if (_isEraseWaiting) {
+ return;
+ }
+ _last = evt->pos();
+
+ if (0 >= _selection.width() || !_selection.contains(_last)) {
+ _isSelected = false;
+ }
+ if (!_isSelected) {
+ _selection = QRect(0, 0, -1, -1);
+ _selected.clear();
+ redraw();
+
+ int w = _eraser_s;
+ if (PENWIDTH_MAX / 2 < _pen.width()) {
+ w = _eraser_l;
+ }
+ // 大バグ対策:
+ // 0 > xの座標に、縦150位の四角形を書くと、C系ザウのパフォーマンスが激落ちします。
+ // 以降同様のロジックはこの対策のためです。
+ QPainter pwin;
+ pwin.begin(this);
+ pwin.setRasterOp(XorROP);
+ pwin.setPen(QPen(white, 1));
+ _preRect.setRect(_last.x() - w / 2, _last.y() - w / 2, w, w);
+ drawRect(pwin, _preRect);
+ pwin.flush();
+ pwin.end();
+ _selection = QRect(0, 0, -1, -1);
+ _selected.clear();
+ } else {
+ QPainter pwin;
+ pwin.begin(this);
+
+ pwin.setRasterOp(XorROP);
+ pwin.setPen(QPen(white, 1));
+ _preRect.setRect(_selection.x(), _selection.y(), _selection.width(), _selection.height());
+ drawRect(pwin, _preRect);
+
+ pwin.flush();
+ pwin.end();
+ QPoint t = SnapPoint(QPoint(_selection.x(), _selection.y()));
+ _last = SnapPoint(_last);
+
+ _tdx = _last.x() - t.x();
+ _tdy = _last.y() - t.y();
+ }
+ } else {
+ _last = evt->pos();
+ _tracks.append(new QPoint(_last));
+ }
+ _isDragging = true;
+}
+
+void FNCanvas::mouseMoveEvent(QMouseEvent* evt)
+{
+ if (!_current->IsShow) {
+ return;
+ }
+ if (_isWaiting) {
+ return;
+ }
+ if (MODE_TEXT == _drawMode) {
+ if (NULL == _txtTmp) {
+ return;
+ }
+ if (0 < _txtwait) {
+ --_txtwait;
+ return;
+ }
+ QPainter pwin;
+ pwin.begin(this);
+ if (-1 != _selection.width()) {
+ pwin.setRasterOp(XorROP);
+ pwin.setPen(QPen(white, 1));
+ drawRect(pwin, _selection);
+ } else {
+ _selection = _txtTmp->boundingRect();
+ }
+ QPoint tmp = SnapPoint(evt->pos(), SNAP_SIZE / 4);
+ tmp.setX(tmp.x() - _tdx);
+ tmp.setY(tmp.y() - _tdy);
+ if (tmp != _last) {
+ _selection.moveTopLeft(tmp);
+ _last = tmp;
+ }
+ drawRect(pwin, _selection);
+ pwin.flush();
+ pwin.end();
+ } else if (MODE_CPICK == _drawMode) {
+ QRgb c = _buffer.convertToImage().pixel(evt->pos().x(), evt->pos().y());
+ emit pickColor(c);
+ return;
+ } else if (MODE_ERASE == _drawMode) {
+ //redraw();
+ if (_last.x() == -1) {
+ return;
+ }
+ if (!_isSelected) {
+ int w = _eraser_s;
+ if (PENWIDTH_MAX / 2 < _pen.width()) {
+ w = _eraser_l;
+ }
+ QPainter pwin;
+ pwin.begin(this);
+
+ pwin.setRasterOp(XorROP);
+ pwin.setPen(QPen(white, 1));
+ drawRect(pwin, _preRect);
+
+ _last = evt->pos();
+
+ _preRect.setRect(_last.x() - w / 2, _last.y() - w / 2, w, w);
+ pwin.setRasterOp(CopyROP);
+ QRect r = QRect(0, 0, width(), height());
+ for (uint i = 0; i < _current->draws.count() - _current->disp_offset(); ++i) {
+ FNPolygon* p = _current->draws.at(i);
+ QRect bounds = p->boundingRect();
+ if (r.intersects(bounds)) {
+ bool f = false;
+ QRect& selected = _preRect;
+ for (uint j = 0; j < p->points().count(); ++j) {
+ QPoint& pts = p->points().at(j);
+ if (selected.contains(pts)) {
+ f = true;
+ if (-1 == _selection.width()) {
+ _selection = bounds;
+ } else {
+ if (bounds.x() < _selection.x()) {
+ _selection.setX(bounds.x());
+ }
+ if (bounds.y() < _selection.y()) {
+ _selection.setY(bounds.y());
+ }
+ if (bounds.right() > _selection.right()) {
+ _selection.setRight(bounds.right());
+ }
+ if (bounds.bottom() > _selection.bottom()) {
+ _selection.setBottom(bounds.bottom());
+ }
+ }
+ break;
+ }
+ }
+ if (f) {
+ if (0 == _selected.contains(p)) {
+ _selected.append(p);
+ }
+ p->drawShape(pwin, f);
+ }
+ }
+ }
+ pwin.setRasterOp(XorROP);
+ pwin.setPen(QPen(white, 1));
+ drawRect(pwin, _preRect);
+ pwin.flush();
+ pwin.end();
+ } else {
+ if (0 >= _selection.width()) {
+ return;
+ }
+ //選択中(移動処理)
+ QPainter pwin;
+ pwin.begin(this);
+ pwin.setRasterOp(XorROP);
+ pwin.setPen(QPen(white, 1));
+ drawRect(pwin, _preRect);
+ _last = SnapPoint(evt->pos(), SNAP_SIZE / 4);
+ _preRect.setRect(_last.x() - _tdx, _last.y() - _tdy, _selection.width(), _selection.height());
+ drawRect(pwin, _preRect);
+ pwin.flush();
+ pwin.end();
+ }
+ } else {
+ QPainter pwin;
+ pwin.begin(this);
+ pwin.setPen(_pen);
+
+ pwin.drawLine(_last, evt->pos());
+ pwin.flush();
+
+ pwin.end();
+ _last = evt->pos();
+ _tracks.append(new QPoint(_last));
+ }
+}
+
+void FNCanvas::mouseReleaseEvent(QMouseEvent* evt)
+{
+ if (!_current->IsShow) {
+ return;
+ }
+ _isDragging = false;
+ if (_isWaiting) {
+ _isWaiting = false;
+ return;
+ }
+ if (MODE_ERASE == _drawMode) {
+ if (_isSelected) {
+ //_lastへ移動
+ _last = SnapPoint(evt->pos(), SNAP_SIZE / 4);
+ int dx = _last.x() - _tdx - _selection.x();
+ int dy = _last.y() - _tdy - _selection.y();
+ for (uint i = 0; i < _selected.count(); ++i) {
+ FNPolygon* p = _selected.at(i);
+ p->translate(dx, dy);
+ }
+ _selection.moveBy(dx, dy);
+ redraw();
+ } else {
+ if (false == _isEraseWaiting) {
+ _isEraseWaiting = true;
+ }
+ redraw();
+ _timer->start(_scrollTiming, true);
+ }
+ } else if (MODE_CPICK == _drawMode) {
+ QRgb c = _buffer.convertToImage().pixel(evt->pos().x(), evt->pos().y());
+ emit pickColor(c);
+ emit changeMode(_prevMode);
+ return;
+ } else {
+ if (1 < _tracks.count()) {
+ _last = evt->pos();
+ FNPolygon* p = NULL;
+ if (MODE_FORMAT == _drawMode) {
+ p = new FNPolygon(_pen);
+ _tracks = AutoFormat(_tracks);
+ } else if (MODE_CURVE == _drawMode) {
+ QPoint sp = SnapPoint(*_tracks.at(0));
+ QPoint ep = SnapPoint(*_tracks.at(_tracks.count()-1));
+ FNPointList tracks;
+ tracks.setAutoDelete(true);
+ for (uint i = 0; i < _tracks.count(); ++i) {
+ QPoint t = *_tracks.at(i);
+ tracks.append(new QPoint(t.x(), t.y()));
+ }
+ _tracks = AutoCurve(_tracks);
+ bool isEllipse = false;
+ if (sp == ep) {
+ if (0 < _tracks.count()) {
+ int vdconv = 0; //縦方向転換
+ int vdir = 0;
+ int svdir = 0;
+
+ int hdconv = 0; //横方向転換
+ int hdir = 0;
+ int shdir = 0;
+ QPoint* st = _tracks.at(0);
+ QPoint* l = st;
+ for (uint i = 1; i < _tracks.count(); ++i) {
+ QPoint* p = _tracks.at(i);
+ int thdir = sign(p->x() - l->x());
+ if (l->x() != p->x()) {
+ //水平方向転換
+ if (0 != thdir) {
+ if (0 == hdir) {
+ shdir = thdir;
+ } else if (thdir != hdir) {
+ ++hdconv;
+ }
+ hdir = thdir;
+ }
+ }
+ int tvdir = sign(p->y() - l->y());
+ if (l->y() != p->y()) {
+ //垂直方向転換
+ if (0 != tvdir) {
+ if (0 == vdir) {
+ svdir = tvdir;
+ } else if (tvdir != vdir) {
+ ++vdconv;
+ }
+ vdir = tvdir;
+ }
+ }
+ l = p;
+ }
+ if (shdir == hdir) {
+ --hdconv;
+ }
+ if (svdir == vdir) {
+ --vdconv;
+ }
+
+ if (1 >= hdconv && 1 >= vdconv) {
+ isEllipse = true;
+ int dircnt = 0;
+ //もう1判定
+ tracks = AutoFormat(tracks);
+ if (2 < tracks.count()) {
+ int phdir = sign(tracks.at(1)->x() - tracks.at(0)->x());
+ int pvdir = sign(tracks.at(1)->y() - tracks.at(0)->y());
+ l = tracks.at(1);
+ for (uint i = 2; i < tracks.count(); ++i) {
+ QPoint* p = tracks.at(i);
+ int thdir = sign(p->x() - l->x());
+ int tvdir = sign(p->y() - l->y());
+ if ((0 == pvdir && 0 != tvdir && 0 != phdir && 0 == thdir) ||
+ (0 != pvdir && 0 == tvdir && 0 == phdir && 0 != thdir))
+ {
+ if (3 < dircnt) {
+ isEllipse = false;
+ break;
+ }
+ ++dircnt;
+ }
+ l = p;
+ phdir = thdir;
+ pvdir = tvdir;
+ }
+ }
+ }
+ }
+ }
+ if (isEllipse) {
+ QRect r = GetBounds(_tracks);
+ _tracks.clear();
+ sp = SnapPoint(QPoint(r.x(), r.y()));
+ ep = SnapPoint(QPoint(r.x() + r.width(), r.y() + r.height()));
+ _tracks.append(new QPoint(sp.x(), sp.y()));
+ _tracks.append(new QPoint(ep.x(), ep.y()));
+ p = new FNEllipse(_pen);
+ } else if (2 < _tracks.count()) {
+ p = new FNBezier(_pen);
+ } else {
+ p = new FNPolygon(_pen);
+ }
+ } else if (MODE_SMOOTH == _drawMode) {
+ _tracks = Smoothing(_tracks);
+ if (2 < _tracks.count()) {
+ p = new FNBezier(_pen);
+ } else {
+ p = new FNPolygon(_pen);
+ }
+ } else {
+ _tracks = Reduce(_tracks);
+ p = new FNPolygon(_pen);
+ }
+ if (NULL != p) {
+ p->setFill(_fill);
+ if (1 < _tracks.count()) {
+ p->setPoints(_tracks);
+ redobuf_flush();
+ _current->draws.append(p);
+ }
+ }
+ } else if (MODE_TEXT == _drawMode) {
+ if (NULL == _txtTmp) {
+ textEdit(_last.x(), _last.y());
+ } else {
+ QRect r = _txtTmp->boundingRect();
+ if (_selection == r || 0 < _txtwait) {
+ textEdit(r.x(), r.y(), _txtTmp);
+ } else {
+ if (-1 != _selection.width()) {
+ _txtTmp->translate(_last.x() - r.x(), _last.y() - r.y());
+ }
+ }
+ }
+ _txtTmp = NULL;
+ }
+ _tracks.clear();
+ _isHeadingEnables = true;
+ _timer->start(_scrollTiming, true);
+ }
+}
+
+void FNCanvas::textEdit(int x, int y, FNText* obj)
+{
+ FNTextDialog dlg(fontname, _colorSelector, this);
+ dlg.show();
+ /*
+ if (width() < _tboxRect.x()) {
+ _tboxRect.setX(0);
+ }
+ if (50 > _tboxRect.y()) {
+ _tboxRect.setY(50);
+ }
+ if (height() < _tboxRect.height()) {
+ _tboxRect.setHeight(height());
+ }
+ if (width() < _tboxRect.width()) {
+ _tboxRect.setWidth(width());
+ }
+ dlg.move(_tboxRect.x(), _tboxRect.y());
+ dlg.resize(_tboxRect.width(), _tboxRect.height());
+ */
+ dlg.move(width() / 8, height() / 8);
+ dlg.resize(width() * 6 / 8, height() * 6 / 8);
+ QPen pen = _pen;
+ if (NULL != obj) {
+ for (uint i = 0; i < obj->lines.count(); ++i) {
+ dlg.lines->append(obj->lines[i]);
+ }
+ pen = obj->pen();
+ }
+ dlg.setPen(pen);
+
+ int mx = x;
+ int my = y;
+ if (dlg.exec()) {
+ pen = dlg.pen();
+ if (0 < dlg.lines->text().length()) {
+ FNText* p = obj;
+ if (NULL == obj) {
+ p = new FNText(pen);
+ _current->draws.append((FNPolygon*)p);
+ }
+ p->pen() = pen;
+ p->lines.clear();
+ FNPointList l;
+ l.append(new QPoint(x, y));
+ QFont font(fontname);
+ font.setPointSize(FONTSIZE[pen.width()]);
+ QFontMetrics fm(font);
+ int h = fm.height();
+ for (int i = 0; i < dlg.lines->numLines(); ++i) {
+ p->lines.append(dlg.lines->textLine(i));
+ int w = fm.width(dlg.lines->textLine(i)) + x;
+ l.append(new QPoint(w, my));
+ my += h;
+ l.append(new QPoint(w, my));
+ l.append(new QPoint(x, my));
+ if (mx < w) {
+ mx = w;
+ }
+ }
+ p->setPoints(l);
+ redobuf_flush();
+ redraw();
+ } else {
+ if (NULL != obj) {
+ _current->draws.remove(obj);
+ }
+ }
+ }
+ _tboxRect = QRect(dlg.x(), dlg.y(), dlg.width(), dlg.height());
+}
+void FNCanvas::paintEvent(QPaintEvent*)
+{
+ bitBlt(this, 0, 0, &_buffer);
+}
+
+void FNCanvas::resizeEvent(QResizeEvent* evt)
+{
+ QPixmap save(_buffer);
+ _buffer.resize(evt->size());
+ _buffer.fill(white);
+ bitBlt(&_buffer, 0, 0, &save);
+ redraw();
+}
+
+void FNCanvas::setOrigin(QPoint& o)
+{
+ this->setOrigin(o.x(), o.y());
+}
+
+QPoint FNCanvas::getTopLeft()
+{
+ bool hasValue = false;
+ int dx = 0;
+ int dy = 0;
+ if (0 < _current->draws.count()) {
+ dx = ((FNPolygon*)_current->draws.at(0))->boundingRect().x();
+ dy = ((FNPolygon*)_current->draws.at(0))->boundingRect().y();
+ }
+
+ for (uint j = 0; j < _layers.count(); ++j) {
+ FNPolygonList& draws = _layers.at(j)->draws;
+ for (uint i = 0; i < draws.count(); ++i) {
+ FNPolygon* p = draws.at(i);
+ hasValue = true;
+ if (dx > p->boundingRect().x()) {
+ dx = p->boundingRect().x();
+ }
+ if (dy > p->boundingRect().y()) {
+ dy = p->boundingRect().y();
+ }
+ }
+ }
+ if (!hasValue || !_isUseAllQuadrant) {
+ return _origin;
+ }
+ return QPoint(snap(dx), snap(dy));
+}
+
+
+void FNCanvas::rebuild()
+{
+ if (!_isUseAllQuadrant) {
+ return;
+ }
+
+ QPoint d = getTopLeft();
+ d.setX(d.x() - SNAP_SIZE);
+ d.setY(d.y() - SNAP_SIZE);
+ for (uint j = 0; j < _layers.count(); ++j) {
+ FNPolygonList& draws = _layers.at(j)->draws;
+ for (uint i = 0; i < draws.count(); ++i) {
+ FNPolygon* p = draws.at(i);
+ p->translate(-d.x(), -d.y());
+ }
+ }
+ _origin = QPoint(0, 0);
+}
+
+void FNCanvas::resetOrigin()
+{
+ int ox = 0;
+ int oy = 0;
+ _isHeadingEnables = false;
+ _timer->stop();
+
+
+ int dx = 0;
+ int dy = 0;
+ if (!_isUseAllQuadrant) {
+ if (0 > ox) {
+ ox = 0;
+ }
+ if (0 > oy) {
+ oy = 0;
+ }
+ dx = _origin.x() - ox;
+ dy = _origin.y() - oy;
+ } else {
+ dx = _origin.x() - ox;
+ dy = _origin.y() - oy;
+ if (0 > ox) {
+ ox = 0;
+ }
+ if (0 > oy) {
+ oy = 0;
+ }
+ }
+ for (uint i = 0; i < _tracks.count(); ++i) {
+ QPoint* p = _tracks.at(i);
+ p->setX(p->x() + dx);
+ p->setY(p->y() + dy);
+ }
+
+ for (uint i = 0; i < _layers.count(); ++i) {
+ FNPolygonList& draws = _layers.at(i)->draws;
+ for (uint j = 0; j < draws.count(); ++j) {
+ FNPolygon* p = draws.at(j);
+ p->translate(dx, dy);
+ }
+ }
+ _origin = QPoint(ox, oy);
+}
+
+void FNCanvas::setOrigin(int ox, int oy, bool isRedrawEnabled)
+{
+ ox = snap(ox);
+ oy = snap(oy);
+ _isHeadingEnables = false;
+ _timer->stop();
+
+ int dx = 0;
+ int dy = 0;
+ if (!_isUseAllQuadrant) {
+ if (0 > ox) {
+ ox = 0;
+ }
+ if (0 > oy) {
+ oy = 0;
+ }
+ dx = _origin.x() - ox;
+ dy = _origin.y() - oy;
+ } else {
|
