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 /packages | |
parent | 1c35191af98492f5aad3f217622f3705ea2acb6b (diff) |
add freenote, an error correcting paint program for Opie. patch based on work by Enodr <nicolasfr@gmail.com>, thanks! closes
#1018
Diffstat (limited to 'packages')
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 {
+ dx = _origin.x() - ox;
+ dy = _origin.y() - oy;
+ if (0 > ox) {
+ ox = 0;
+ }
+ if (0 > oy) {
+ oy = 0;
+ }
+ }
+ if (dx == 0 && dy == 0) {
+ return;
+ }
+ 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 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(dx, dy);
+ }
+ }
+ if (-1 != _selection.width()) {
+ _selection.moveBy(dx, dy);
+ }
+
+ _origin = QPoint(ox, oy);
+ emit originChanged(ox, oy);
+ if (isRedrawEnabled) {
+ redraw();
+ }
+}
+
+void FNCanvas::redraw()
+{
+ if (_isDrawing) {
+ return;
+ }
+ if (_isDragging) {
+ return;
+ }
+ if (!this->isVisible()) {
+ return;
+ }
+
+ _isDrawing = true;
+ for (uint l = 0; l < _layers.count(); ++l) {
+ FNLayer& layer = *_layers.at(l);
+ if (_isTinyPaging) {
+ if (_current == &layer) {
+ layer.IsShow = true;
+ } else {
+ layer.IsShow = false;
+ }
+ }
+ }
+ int h = height(); //(height() / 40) * 40;
+ _buffer.fill(white);
+ QRect r = QRect(0, 0, width(), height());
+ QPainter pbuf;
+ pbuf.begin(&_buffer);
+ pbuf.setFont(QFont(fontname));
+ pbuf.setClipRect(0, 0, width(), height());
+ if (_viewMode) {
+ float wx = 0;
+ float wy = 0;
+ for (uint l = 0; l < _layers.count(); ++l) {
+ FNLayer& layer = *_layers.at(l);
+ if (layer.IsShow) {
+ FNPolygonList& draws = layer.draws;
+ for (uint i = 0; i < draws.count() - layer.disp_offset(); ++i) {
+ FNPolygon* p = draws.at(i);
+ QRect r = p->boundingRect();
+ if (wx < r.right()) {
+ wx = r.right();
+ }
+ if (wy < r.bottom()) {
+ wy = r.bottom();
+ }
+ }
+ }
+ }
+ wx += SNAP_SIZE;
+ wy += SNAP_SIZE;
+ wx = snap((int)wx);
+ wy = snap((int)wy);
+ wx = wx + _origin.x();
+ wy = wy + _origin.y();
+ _scale_x = (float)width() / wx;
+ _scale_y = (float)height() / wy;
+ if (1.0f < _scale_x) {
+ _scale_x = 1.0f;
+ }
+ if (1.0f < _scale_y) {
+ _scale_y = 1.0f;
+ }
+ if (_scale_x > _scale_y) {
+ _scale_x = _scale_y;
+ } else if (_scale_x < _scale_y) {
+ _scale_y = _scale_x;
+ }
+ for (uint l = 0; l < _layers.count(); ++l) {
+ FNLayer& layer = *_layers.at(l);
+ if (!layer.IsShow) {
+ continue;
+ }
+ FNPolygonList& draws = layer.draws;
+ for (uint i = 0; i < draws.count() - layer.disp_offset(); ++i) {
+ FNPolygon* p = draws.at(i);
+ FNPolygon* t = NULL;
+ if (p->type() == FN_BEZIER) {
+ t = new FNBezier(*(FNBezier*)p);
+ } else if (p->type() == FN_ELLIPSE) {
+ t = new FNEllipse(*(FNEllipse*)p);
+ } else if (p->type() == FN_TEXT) {
+ t = new FNText(*(FNText*)p);
+ } else {
+ t = new FNPolygon(*p);
+ }
+ t->translate(-_origin.x(), -_origin.y());
+ for (uint j = 0; j < t->points().count(); ++j) {
+ QPoint& pts = t->points().at(j);
+ int x = (int)(pts.x() * _scale_x);
+ int y = (int)(pts.y() * _scale_y);
+ pts.setX(x);
+ pts.setY(y);
+ }
+ double pensize = t->pen().width();
+ if (_scale_x > _scale_y) {
+ pensize = pensize * _scale_y;
+ } else {
+ pensize = pensize * _scale_x;
+ }
+ if (0 >= pensize) {
+ pensize = 1;
+ }
+ if (p->type() == FN_TEXT) {
+ FNText* tp = (FNText*)t;
+ QPoint& sp = t->points().at(0);
+
+ //default font size checking...
+ QFont f(fontname, FONTSIZE[p->pen().width()]);
+ QFontMetrics fm(f);
+ int h = fm.height();
+ int wx = 0;
+ int wy = 0;
+ for (uint i = 0; i < tp->lines.count(); ++i) {
+ int tw = fm.width(tp->lines[i]);
+ if (tw > wx) {
+ wx = tw;
+ }
+ wy += h;
+ }
+
+ //create default font image...
+ QRect r = tp->boundingRect();
+ QPixmap tmp(wx + 1, wy + 1);
+ tmp.fill(Qt::white);
+ QPainter pt;
+ pt.begin(&tmp);
+ pt.setFont(f);
+ pt.setPen(p->pen());
+ int y = h + 1;
+ for (uint i = 0; i < tp->lines.count(); ++i) {
+ pt.drawText(1, y, tp->lines[i]);
+ y += h;
+ }
+ pt.flush();
+ pt.end();
+
+ //draw to font image
+ tmp = tmp.convertToImage().smoothScale(r.width(), r.height());
+ tmp.setMask(tmp.createHeuristicMask());
+ pbuf.drawPixmap(sp.x(), sp.y(), tmp);
+ pbuf.flush();
+ } else {
+ t->pen().setWidth(pensize);
+ t->drawShape(pbuf);
+ }
+ delete t;
+ }
+ }
+ } else {
+ if (MODE_ERASE == _drawMode || MODE_FORMAT == _drawMode || MODE_CURVE == _drawMode || MODE_TEXT == _drawMode) {
+ //グリッド描画
+ //QPen pen2(QColor(0, 0, 0), 1);
+ //pbuf.setPen(QPen(QColor(50, 240, 240), 1));
+ pbuf.setPen(QPen(GridColor));
+ for (int x = 0; x < width() + SNAP_SIZE; x += SNAP_SIZE) {
+ pbuf.drawLine(x - SNAP_SIZE / 2, 0, x - SNAP_SIZE / 2, h);
+ for (int y = 0; y < h + SNAP_SIZE; y += SNAP_SIZE) {
+ pbuf.drawLine(0, y - SNAP_SIZE / 2, width(), y - SNAP_SIZE / 2);
+ pbuf.drawRect(x-1,y-1,2,2);
+ }
+ }
+ }
+ if (MODE_ERASE != _drawMode) {
+ if (!(MODE_FORMAT == _drawMode || MODE_CURVE == _drawMode || MODE_TEXT == _drawMode)) {
+ if (_showRuler) {
+ //罫線
+ pbuf.setPen(QPen(RulerColor, 1, SolidLine));
+ int step = SNAP_SIZE * 2; //SNAP_SIZEの2倍に。
+ for (int i = 0; i < height(); i += step) {
+ pbuf.drawLine(0, i, width(), i);
+ }
+ }
+ }
+
+ if (_isShowGuide) {
+ pbuf.setPen(QPen(GuideColor, 1, DashLine));
+ if (AS_HORIZONTAL == _asMode || AS_BOTH == _asMode) {
+ if (0 != _origin.x() || _isUseAllQuadrant) {
+ pbuf.drawLine(width() / _margin, 0, width() / _margin, h);
+ }
+ pbuf.drawLine(width() * (_margin - 1) / _margin, 0, width() * (_margin - 1) / _margin, h);
+ }
+
+ if (AS_VERTICAL == _asMode || AS_BOTH == _asMode) {
+ if (0 != _origin.y() || _isUseAllQuadrant) {
+ pbuf.drawLine(0, h / _margin, width(), h / _margin);
+ }
+ pbuf.drawLine(0, h * (_margin - 1) / _margin, width(), h * (_margin - 1) / _margin);
+ }
+ }
+
+ for (uint l = 0; l < _layers.count(); ++l) {
+ FNLayer& layer = *_layers.at(l);
+ if (layer.IsShow) {
+ FNPolygonList& draws = layer.draws;
+ for (uint i = 0; i < draws.count() - layer.disp_offset(); ++i) {
+ FNPolygon* p = draws.at(i);
+ if (r.intersects(p->boundingRect())) {
+ p->drawShape(pbuf);
+ }
+ }
+ }
+ }
+ } else {
+ for (uint l = 0; l < _layers.count(); ++l) {
+ FNLayer& layer = *_layers.at(l);
+ if (layer.IsShow) {
+ FNPolygonList& draws = layer.draws;
+ for (uint i = 0; i < draws.count() - layer.disp_offset(); ++i) {
+ FNPolygon* p = draws.at(i);
+ if (!_selected.contains(p)) {
+ if (r.intersects(p->boundingRect())) {
+ p->drawShape(pbuf);
+ }
+ }
+ }
+ }
+ }
+ for (uint i = 0; i < _selected.count(); ++i) {
+ _selected.at(i)->drawShape(pbuf, true);
+ }
+ if (_isSelected) {
+ pbuf.setPen(QPen(SelectionFrameColor, 1, DashLine));
+ pbuf.setBrush(NoBrush);
+ pbuf.drawRect(_selection);
+ }
+ }
+ }
+ pbuf.end();
+ _isDrawing = false;
+ repaint();
+}
+
+void FNCanvas::changeColor(QRgb c)
+{
+ _pen.setColor(QColor(c));
+ if (_isSelected && _drawMode == MODE_ERASE) {
+ for (uint i = 0; i < _selected.count(); ++i) {
+ _selected.at(i)->pen().setColor(QColor(c));
+ }
+ }
+}
+
+void FNCanvas::selectionMoveTo(int dx, int dy)
+{
+ if (_isSelected) {
+ for (uint i = 0; i < _selected.count(); ++i) {
+ _selected.at(i)->translate(dx, dy);
+ }
+ _selection.moveBy(dx, dy);
+ }
+ redraw();
+}
+
+void FNCanvas::copy()
+{
+ if (MODE_ERASE != _drawMode || _viewMode) {
+ return;
+ }
+ _clipboard.clear();
+ int size = _selected.count();
+ int a1[size];
+ int a2[size];
+ for (int i = 0; i < size; ++i) {
+ a1[i] = _current->draws.findRef(_selected.at(i));
+ a2[i] = i;
+ }
+
+ //ソート
+ FNPolygonList tmp;
+ for (int i = 0; i < size; ++i) {
+ int min = i;
+ for (int j = i + 1; j < size; ++j) {
+ if (a1[min] > a1[j]) {
+ min = j;
+ }
+ }
+ tmp.append(_selected.at(a2[min]));
+ a1[min] = a1[i];
+ a2[min] = a2[i];
+ }
+
+ //並び順を保証してコピー
+ tmp.clone(_clipboard);
+ tmp.clear();
+}
+
+void FNCanvas::paste()
+{
+ if (_viewMode) {
+ return;
+ }
+ if (MODE_ERASE == _drawMode) {
+ _selected.clear();
+ _clipboard.clone(_selected);
+ _selection = QRect(0, 0, -1, -1);
+ for (uint i = 0; i < _selected.count(); ++i) {
+ FNPolygon* o = _selected.at(i);
+ o->translate(10, 10);
+ QRect bounds = o->boundingRect();
+ 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());
+ }
+ }
+ }
+ _selected.copy(_current->draws);
+ _isSelected = true;
+ } else {
+ int my = 10;
+ int mx = 10;
+ int x = 10;
+ QStringList lines = QStringList::split("\n", QApplication::clipboard()->text());
+ if (0 < lines.count()) {
+ FNText* p = new FNText(_pen);
+ _current->draws.append((FNPolygon*)p);
+ p->lines.clear();
+ FNPointList l;
+ l.append(new QPoint(0, 0));
+ QFont font(fontname);
+ font.setPointSize(FONTSIZE[_pen.width()]);
+ QFontMetrics fm(font);
+ int h = fm.height();
+ for (uint i = 0; i < lines.count(); ++i) {
+ p->lines.append(lines[i]);
+ int w = fm.width(lines[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);
+ }
+ }
+ redraw();
+}
+
+void FNCanvas::redo()
+{
+ if (MODE_ERASE != _drawMode) {
+ _current->redo();
+ }
+ redraw();
+}
+
+void FNCanvas::clearList(FNPolygonList& list)
+{
+ list.setAutoDelete(true);
+ list.clear();
+ list.setAutoDelete(false);
+}
+
+void FNCanvas::resetSelection()
+{
+ _selection = QRect(0, 0, -1, -1);
+ _selected.clear();
+ _isSelected = false;
+}
+
+void FNCanvas::clear()
+{
+ resetSelection();
+ _layers.clear();
+ _current = new FNLayer();
+ _layers.append(_current);
+ _current->Name = "Layer0";
+ _selIdx = 0;
+ _isTinyPaging = false;
+ //_undobuf.clear();
+ setOrigin(0, 0);
+ redraw();
+}
+
+void FNCanvas::undo()
+{
+ _timer->stop();
+ if (MODE_ERASE != _drawMode) {
+ _current->undo();
+ } else {
+ _selected.clear();
+ _isSelected = false;
+ _layers.clear();
+ for (uint i = 0; i < _undobuf.count(); ++i) {
+ _layers.append(new FNLayer(*_undobuf.at(i)));
+ }
+ _current = _layers.at(0);
+ _selIdx = 0;
+ }
+ redraw();
+}
+
+void FNCanvas::viewChanged(bool flg)
+{
+ _tracks.clear();
+ _viewMode = flg;
+ if (_viewMode) {
+ if (_isUseAllQuadrant) {
+ rebuild();
+ }
+ setOrigin(0, 0, false);
+ }
+ redraw();
+}
+
+void FNCanvas::redobuf_flush()
+{
+ _current->redobuf_flush();
+}
+
+void FNCanvas::modeChanged(int mode)
+{
+ _tracks.clear();
+ resetSelection();
+ _drawMode = mode;
+ for (uint i = 0; i < _layers.count(); ++i) {
+ FNLayer* p = _layers.at(i);
+ p->modeChanged();
+ }
+ _undobuf.clear();
+ if (MODE_ERASE == mode) {
+ _isEraseWaiting = false;
+ for (uint i = 0; i < _layers.count(); ++i) {
+ _undobuf.append(new FNLayer(*_layers.at(i)));
+ }
+ }
+ if (MODE_CPICK != mode) {
+ _prevMode = mode;
+ }
+ redraw();
+}
+
+QRect FNCanvas::getMatrix(const QRect& r) const
+{
+ int ox = _origin.x();
+ int oy = _origin.y();
+ const int wide = 100;
+
+ int left = r.left() + ox;
+ int top = r.top() + oy;
+ int right = r.right() + ox;
+ int bottom = r.bottom() + oy;
+
+ left = (int)(left / wide) * wide;
+ top = (int)(top / wide) * wide;
+ right = (right % wide == 0 && left != right) ? right : (int)((right + wide) / wide) * wide;
+ bottom = (bottom % wide == 0 && top != bottom) ? bottom : (int)((bottom + wide) / wide) * wide;
+
+ return QRect(left - ox, top - oy, right - left, bottom - top);
+}
+
+void FNCanvas::CR()
+{
+ if (MODE_ERASE == _drawMode) {
+ return;
+ }
+ int h = height(); //(height() / 40) * 40;
+ int step = snap(h) / _margin;
+ if (_isHeadingEnables) {
+ //lastから、左方向に向けて探索する。
+ QRect r = getMatrix(_current->draws.last()->boundingRect());
+ bool isSearching = true;
+ r.moveBy(-100, 0);
+ while (isSearching) {
+ isSearching = false;
+ for (uint i = 0; i < _current->draws.count(); ++i) {
+ FNPolygon* p = _current->draws.at(i);
+ const QRect& r2 = p->boundingRect();
+ if (r.intersects(r2)) {
+ if (r.left() + 100 > r2.left()) {
+ r = getMatrix(r2);
+ r.moveBy(-100, 0);
+ isSearching = true;
+ break;
+ }
+ }
+ }
+ }
+ r.moveBy(100, 0);
+ //lastが画面の4/5以下ならば、スクロールアップする。
+ //そうでなければ、ヘッディングのみ。
+ if (_last.y() > h * 4 / 5) {
+ setOrigin(_origin.x() + r.x(), _origin.y() + step);
+ } else {
+ setOrigin(_origin.x() + r.x(), _origin.y());
+ }
+ _isHeadingEnables = false;
+ } else {
+ //lastの周囲に何も無い場合は、縦にスクロールする。
+ setOrigin(_origin.x(), _origin.y() + step);
+ }
+}
+
+void FNCanvas::erase()
+{
+ if (MODE_ERASE != _drawMode) {
+ return;
+ }
+ FNPolygonList temp;
+ int w = _eraser_s;
+ if (PENWIDTH_MAX / 2 < _pen.width()) {
+ w = _eraser_l;
+ }
+ for (uint i = 0; i < _selected.count(); ++i) {
+ _current->draws.remove(_selected.at(i));
+ //_marks.append(_selected.at(i));
+ }
+ resetSelection();
+ _tracks.clear();
+ _isEraseWaiting = false;
+ redraw();
+}
+
+void FNCanvas::setPensize(int sz)
+{
+ _pen.setWidth(sz);
+ if (_isSelected) {
+ for (uint i = 0; i < _selected.count(); ++i) {
+ if (FN_TEXT != _selected.at(i)->type()) {
+ _selected.at(i)->pen().setWidth(sz);
+ }
+ }
+ }
+}
+
+bool FNCanvas::exportPNG(const QFileInfo& info, QPixmap& buf)
+{
+ if (0 == info.fileName().length()) {
+ QMessageBox::warning(0,"FreeNoteQt", "file name is empty.");
+ return false;
+ }
+ if (info.extension(false) != "png") {
+ QMessageBox::warning(0,"FreeNoteQt", "extension '.png' expected.");
+ return false;
+ }
+
+ bool ret;
+ if (_isColorRevision) {
+ QImage img = buf.convertToImage();
+ int wd = buf.width();
+ int ht = buf.height();
+ for (int i = 0; i < ht; ++i) {
+ for (int j = 0; j < wd; ++j) {
+ QRgb c = img.pixel(j, i);
+ int r = qRed(c) >> 3;
+ int g = qGreen(c) >> 2;
+ int b = qBlue(c) >> 3;
+ r = (r << 3) | (r >> 2);
+ b = (b << 3) | (b >> 2);
+ g = (g << 2) | (g >> 4);
+ //float f1 = 248f / 255f;
+ //float f2 = 252f / 255f;
+ //img.setPixel(qRed(c) * f1, qGreen(c) * f2, qBlue(c) * f1);
+ img.setPixel(j, i, qRgb(r, g, b));
+ }
+ }
+ ret = img.save(info.absFilePath(), "PNG");
+ } else {
+ ret = buf.save(info.absFilePath(), "PNG");
+ }
+ if (ret) {
+ FNMessageBox::information(0,"FreeNoteQt", "export PNG complete.");
+ } else {
+ QMessageBox::warning(0,"FreeNoteQt", "could not export file.");
+ }
+ return ret;
+}
+
+QString FNCanvas::mkPDFscript(FNPolygon* elm, int wy)
+{
+ QString s ="";
+ char buf[1024];
+ float r;
+ float g;
+ float b;
+ if (_isColorRevision) {
+ r = (float)elm->pen().color().red() / 248.0f;
+ g = (float)elm->pen().color().green() / 252.0f;
+ b = (float)elm->pen().color().blue() / 248.0f;
+ } else {
+ r = (float)elm->pen().color().red() / 255.0f;
+ g = (float)elm->pen().color().green() / 255.0f;
+ b = (float)elm->pen().color().blue() / 255.0f;
+ }
+ if (elm->type() == FN_TEXT) {
+ FNText* t = (FNText*)elm;
+ sprintf(buf, "BT\r\n/F1 %d Tf\r\n", FONTSIZE[elm->pen().width()]);
+ s += buf;
+ sprintf(buf, "0 Tr\r\n%f %f %f rg\r\n", r, g, b);
+ s += buf;
+ QRect r = t->boundingRect();
+ r.moveBy(_origin.x(), _origin.y());
+ QFont font(fontname);
+ font.setPointSize(FONTSIZE[elm->pen().width()]);
+ QFontMetrics fm(font);
+ int h = fm.height();
+ int y = r.y() + h;
+ for (uint i = 0; i < t->lines.count(); ++i) {
+ sprintf(buf, "1 0 0 1 %d %d Tm\r\n", r.x() + 3, wy - y);
+ s += buf;
+ y = y + h;
+ s += "<";
+ for (uint j = 0; j < t->lines[i].length(); ++j) {
+ sprintf(buf, "%04X", (t->lines[i].at(j).unicode() & 0x0ffff));
+ s += buf;
+ }
+ s += "> Tj\r\n";
+ }
+ s += "ET\r\n";
+ } else {
+ s += "q\r\n";
+ if (elm->fill()) {
+ sprintf(buf, "%f %f %f rg\r\n", r, g, b);
+ } else {
+ sprintf(buf, "%f %f %f RG\r\n", r, g, b);
+ }
+ s += buf;
+ QPointArray points = elm->points().copy();
+ points.translate(_origin.x(), _origin.y());
+ if (elm->type() == FN_BEZIER) {
+ sprintf(buf, "%d %d m\r\n", points[0].x(), wy - points[0].y());
+ s += buf;
+ for (uint j = 1; j < points.count(); j += 3) {
+ sprintf(buf, "%d %d %d %d %d %d c\r\n",
+ points[j].x(), wy - points[j].y(),
+ points[j + 1].x(), wy - points[j + 1].y(),
+ points[j + 2].x(), wy - points[j + 2].y()
+ );
+ s += buf;
+ }
+ } else if (elm->type() == FN_ELLIPSE) {
+ int x = points[0].x();
+ int y = points[0].y();
+ int ex = points[1].x();
+ int ey = points[1].y();
+ int w = ex - x;
+ int h = ey - y;
+ int cx = x + w/2;
+ int cy = y;
+ int x1 = x + 3*w/4;
+ int y1 = y;
+ int x2 = x + w;
+ int y2 = y + h/4;
+ int x3 = x + w;
+ int y3 = y + h/2;
+
+ sprintf(buf, "%d %d m\r\n%d %d %d %d %d %d c\r\n", cx, wy - cy, x1, wy - y1, x2, wy - y2, x3, wy - y3);
+ s += buf;
+ x1 = x + w;
+ y1 = y + 3 * h / 4;
+ x2 = x + 3 * w / 4;
+ y2 = y + h;
+ x3 = x + w/2;
+ y3 = y + h;
+ sprintf(buf, "%d %d %d %d %d %d c\r\n", x1, wy - y1, x2, wy - y2, x3, wy - y3);
+ s += buf;
+
+ x1 = x + w / 4;
+ y1 = y + h;
+ x2 = x;
+ y2 = y + 3 * h / 4;
+ x3 = x;
+ y3 = y + h / 2;
+ sprintf(buf, "%d %d %d %d %d %d c\r\n", x1, wy - y1, x2, wy - y2, x3, wy - y3);
+ s += buf;
+ x1 = x;
+ y1 = y + h / 4;
+ x2 = x + w / 4;
+ y2 = y;
+ x3 = x + w / 2;
+ y3 = y;
+ sprintf(buf, "%d %d %d %d %d %d c\r\n", x1, wy - y1, x2, wy - y2, x3, wy - y3);
+ s += buf;
+ } else {
+ sprintf(buf, "%d %d m\r\n", points[0].x(), wy - points[0].y());
+ s += buf;
+ for (uint j = 1; j < points.count(); ++j) {
+ sprintf(buf, "%d %d l\r\n", points[j].x(), wy - points[j].y());
+ s += buf;
+ }
+ }
+ sprintf(buf, "%d w\r\n", elm->pen().width());
+ s += buf;
+ if (elm->fill()) {
+ s += "f*\r\n";
+ } else {
+ s += "S\r\n";
+ }
+ s += "Q\r\n";
+ }
+ return s;
+}
+
+bool FNCanvas::exportPDF(const QFileInfo& info)
+{
+ if (0 == info.fileName().length()) {
+ QMessageBox::warning(0,"FreeNoteQt", "file name is empty.");
+ return false;
+ }
+ if (info.extension(false) != "pdf") {
+ QMessageBox::warning(0,"FreeNoteQt", "extension '.pdf' expected.");
+ return false;
+ }
+
+ FILE* fp = NULL;
+ if (!(fp = fopen(info.absFilePath().utf8(), "wt"))) {
+ QMessageBox::warning(0,"FreeNoteQt", "could not export file.");
+ return false;
+ }
+
+ QPoint o = getTopLeft();
+ rebuild();
+ int wx = 595;
+ int wy = 842;
+ char buf[1024];
+ int bias = 0;
+ if (_isUseAllQuadrant) {
+ bias = SNAP_SIZE;
+ }
+ for (uint l = 0; l < _layers.count(); ++l) {
+ FNLayer& layer = *_layers.at(l);
+ FNPolygonList& draws = layer.draws;
+ for (uint i = 0; i < draws.count() - layer.disp_offset(); ++i) {
+ FNPolygon* p = draws.at(i);
+ QRect r = p->boundingRect();
+ r.moveBy(_origin.x(), _origin.y());
+ if (wx < r.right() + bias) {
+ wx = r.right() + bias;
+ }
+ if (wy < r.bottom() + bias) {
+ wy = r.bottom() + bias;
+ }
+ }
+ }
+
+ int len = 0;
+
+ /*
+ sprintf(buf, "1 0 0 -1 0 %d cm\r\n", wy);
+ QString cm = buf;
+ len += cm.length();
+ */
+ QString cm = "";
+
+ for (uint l = 0; l < _layers.count(); ++l) {
+ FNLayer& layer = *_layers.at(l);
+ if (layer.IsShow) {
+ FNPolygonList& draws = layer.draws;
+ for (uint i = 0; i < draws.count() - layer.disp_offset(); ++i) {
+ QString s = mkPDFscript(draws.at(i), wy);
+ len += s.length();
+ }
+ }
+ }
+
+ //int ref = 0;
+ QString header = "";
+ QStringList xref;
+ xref.append("0000000000 65535 f\r\n");
+
+ header += "%PDF-1.3\r\n";
+ sprintf(buf, "%010d 00000 n\r\n", header.length());
+ xref.append(buf);
+
+ header += "1 0 obj<</Type/Catalog/Outlines 2 0 R/Pages 3 0 R>>\r\n";
+ header += "endobj\r\n";
+ sprintf(buf, "%010d 00000 n\r\n", header.length());
+ xref.append(buf);
+
+
+ header += "2 0 obj<</Type/Outlines/Count 0>>\r\n";
+ header += "endobj\r\n";
+ sprintf(buf, "%010d 00000 n\r\n", header.length());
+ xref.append(buf);
+
+ header += "3 0 obj<</Type/Pages/Kids[4 0 R]/Count 1>>\r\n";
+ header += "endobj\r\n";
+ sprintf(buf, "%010d 00000 n\r\n", header.length());
+ xref.append(buf);
+
+ header += "4 0 obj<</Type/Page/Parent 3 0 R";
+ sprintf(buf, "/MediaBox[0 0 %d %d]", wx, wy);
+ header += buf;
+ header += "/Contents 6 0 R/Resources<</Font<</F1 5 0 R>>/ProcSet[/PDF/Text]>>>>\r\n";
+ header += "endobj\r\n";
+ sprintf(buf, "%010d 00000 n\r\n", header.length());
+ xref.append(buf);
+
+ if (encode == QString("WinAnsiEncoding")) {
+ header += "5 0 obj<</Type/Font/Subtype/Type1/BaseFont/Helvetica/FirstChar 0/LastChar 255/Encoding/WinAnsiEncoding>>\r\n";
+ } else if (encode == QString("UniJIS-UCS2-H")) {
+ header += "5 0 obj<</Type/Font/Encoding/UniJIS-UCS2-H/BaseFont/MSGothic/Subtype/Type0/DescendantFonts[<</W[0[1000] 1 94 500 231 324 500 327 389 500 631 [500] 668 [500]]/Type/Font/BaseFont/MSGothic/Subtype/CIDFontType2/CIDSystemInfo<</Ordering(Japan1)/Registry(Adobe)/Supplement 2>>/FontDescriptor<</Type/FontDescriptor/FontBBox[0 -137 1000 859]/FontName/MSGothic/Flags 32/StemV 92/CapHeight 770/XHeight 543/Ascent 859/Descent -137/ItalicAngle 0>>/DW 1000>>]>>\r\n";
+ }
+ header += "endobj\r\n";
+ sprintf(buf, "%010d 00000 n\r\n", header.length());
+ xref.append(buf);
+
+ sprintf(buf, "6 0 obj<</Length %d>>\r\n", len);
+ header += buf;
+ header += "stream\r\n";
+
+ QString footer = "";
+ footer += "xref\r\n";
+ sprintf(buf, "0 %d\r\n", xref.count());
+ footer += buf;
+ for (uint i = 0; i < xref.count(); ++i) {
+ footer += xref[i];
+ }
+ footer += "trailer\r\n";
+ sprintf(buf, "<</Size %d/Root 1 0 R>>\r\n", xref.count());
+ footer += buf;
+ footer += "startxref\r\n";
+
+ len = cm.length();
+ len += header.length();
+ fputs(header, fp);
+ fputs(cm, fp);
+
+ for (uint l = 0; l < _layers.count(); ++l) {
+ FNLayer& layer = *_layers.at(l);
+ if (layer.IsShow) {
+ FNPolygonList& draws = layer.draws;
+ for (uint i = 0; i < draws.count() - layer.disp_offset(); ++i) {
+ QString s = mkPDFscript(draws.at(i), wy);
+ len += s.length();
+ fputs(s, fp);
+ }
+ }
+ }
+ QString streamfooter = "endstream\r\nendobj\r\n";
+ len += streamfooter.length();
+ fputs(streamfooter, fp);
+
+ fputs(footer, fp);
+ sprintf(buf, "%d\r\n", len);
+ fputs(buf, fp);
+ fputs("%%EOF\r\n", fp);
+ fclose(fp);
+ if (_isUseAllQuadrant) {
+ setOrigin(-o.x(), -o.y());
+ }
+ FNMessageBox::information(0,"FreeNoteQt", "export PDF complete.");
+ return true;
+}
+
+bool FNCanvas::save(const QFileInfo& info)
+{
+ if (0 == info.fileName().length()) {
+ QMessageBox::warning(0,"FreeNoteQt", "file name is empty.");
+ return false;
+ }
+ if (info.extension(false) != "free") {
+ QMessageBox::warning(0,"FreeNoteQt", "extension '.free' expected.");
+ return false;
+ }
+ FILE* fp = NULL;
+ if (!(fp = fopen(info.absFilePath().utf8(), "wt"))) {
+ QMessageBox::warning(0,"FreeNoteQt", "could not save file.");
+ return false;
+ }
+ QPoint o = getTopLeft();
+ rebuild();
+ fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", fp);
+ char buf[1024];
+ sprintf(buf, "<freenote version=\"4.1\" pg=%d idx=\"%d\">\n", _isTinyPaging, _selIdx);
+ fputs(buf, fp);
+ for (uint l = 0; l < _layers.count(); ++l) {
+ FNLayer& layer = *_layers.at(l);
+ FNPolygonList& draws = layer.draws;
+ QString s = "<layer v=";
+ if (layer.IsShow) {
+ s += "1 name=\"";
+ } else {
+ s += "0 name=\"";
+ }
+ s += layer.Name;
+ s += "\">\n";
+ fputs(s.utf8(), fp);
+ for (uint i = 0; i < draws.count() - layer.disp_offset(); ++i) {
+ FNPolygon p(*draws.at(i));
+ p.translate(_origin.x(), _origin.y());
+ if (p.type() == FN_BEZIER) {
+ sprintf(buf, "\t<bz color=\"%x\" width=\"%d\" f=\"%d\">\n", (uint)p.pen().color().rgb(), p.pen().width(), p.fill());
+ } else if (p.type() == FN_ELLIPSE) {
+ sprintf(buf, "\t<el color=\"%x\" width=\"%d\" f=\"%d\">\n", (uint)p.pen().color().rgb(), p.pen().width(), p.fill());
+ } else if (p.type() == FN_TEXT) {
+ sprintf(buf, "\t<tx color=\"%x\" width=\"%d\">\n", (uint)p.pen().color().rgb(), p.pen().width());
+ } else {
+ sprintf(buf, "\t<po color=\"%x\" width=\"%d\" f=\"%d\">\n", (uint)p.pen().color().rgb(), p.pen().width(), p.fill());
+ }
+ fputs(buf, fp);
+ QPointArray& points = p.points();
+ for (uint j = 0; j < points.count(); ++j) {
+ QPoint point = points.point(j);
+ sprintf(buf, "\t\t<p x=\"%d\" y=\"%d\"/>\n", point.x(), point.y());
+ fputs(buf, fp);
+ }
+ if (p.type() == FN_BEZIER) {
+ fputs("\t</bz>\n", fp);
+ } else if (p.type() == FN_ELLIPSE) {
+ fputs("\t</el>\n", fp);
+ } else if (p.type() == FN_TEXT) {
+ FNText* tp = (FNText*)draws.at(i);
+ for (uint j = 0; j < tp->lines.count(); ++j) {
+ s = "\t\t<t v=\"";
+ s += tp->lines[j];
+ s += "\"/>\n";
+ fputs(s.utf8(), fp);
+ }
+ fputs("\t</tx>\n", fp);
+ } else {
+ fputs("\t</po>\n", fp);
+ }
+ }
+ fputs("</layer>\n", fp);
+ }
+ fputs("</freenote>\n", fp);
+ fclose(fp);
+ if (_isUseAllQuadrant) {
+ setOrigin(-o.x()+SNAP_SIZE, -o.y()+SNAP_SIZE);
+ }
+ FNMessageBox::information(0, "FreeNoteQt", "save complete.");
+ return true;
+}
+
+bool FNCanvas::load(const QFileInfo& info)
+{
+ if (0 == info.fileName().length()) {
+ QMessageBox::warning(0,"FreeNoteQt", "file name is empty.");
+ return false;
+ }
+ if (!info.exists()) {
+ QMessageBox::warning(0,"FreeNoteQt", "file not exists.");
+ return false;
+ }
+ FILE* fp = NULL;
+ if (!(fp = fopen(info.absFilePath().utf8(), "rt"))) {
+ QMessageBox::warning(0,"FreeNoteQt", "could not open file.");
+ return false;
+ }
+ clear();
+ open(_layers, fp);
+ if ((uint)_selIdx >= _layers.count()) {
+ _selIdx = 0;
+ }
+ _current = _layers.at(_selIdx);
+ fclose(fp);
+
+ redraw();
+ FNMessageBox::information(0,"FreeNoteQt", "load complete.");
+
+ return true;
+}
+
+bool FNCanvas::import(const QFileInfo& info)
+{
+ if (0 == info.fileName().length()) {
+ QMessageBox::warning(0,"FreeNoteQt", "file name is empty.");
+ return false;
+ }
+ if (!info.exists()) {
+ QMessageBox::warning(0,"FreeNoteQt", "file not exists.");
+ return false;
+ }
+ FILE* fp = NULL;
+ if (!(fp = fopen(info.absFilePath().utf8(), "rt"))) {
+ QMessageBox::warning(0,"FreeNoteQt", "could not open file.");
+ return false;
+ }
+ clearList(_clipboard);
+ open(_clipboard, fp);
+ fclose(fp);
+ if (0 < _clipboard.count()) {
+ int x = _clipboard.at(0)->boundingRect().left();
+ int y = _clipboard.at(0)->boundingRect().top();
+ for (uint i = 1; i < _clipboard.count(); ++i) {
+ if (y > _clipboard.at(i)->boundingRect().top()) {
+ y = _clipboard.at(i)->boundingRect().top();
+ }
+ if (x > _clipboard.at(i)->boundingRect().left()) {
+ x = _clipboard.at(i)->boundingRect().left();
+ }
+ }
+ for (uint i = 0; i < _clipboard.count(); ++i) {
+ _clipboard.at(i)->translate(-x, -y);
+ }
+ }
+ FNMessageBox::information(0,"FreeNoteQt", "import complete.");
+
+ return true;
+}
+void FNCanvas::open(FNPolygonList& list, FILE* fp)
+{
+ clearList(list);
+ FNLayerList layers;
+ open(layers, fp);
+ for (uint i = 0; i < layers.count(); ++i) {
+ FNLayer& layer = *layers.at(i);
+ if (layer.IsShow) {
+ layer.draws.clone(list);
+ /*
+ FNPolygonList& elmlst = layer.draws;
+ for (uint j = 0; j < elmlst.count(); ++j) {
+ list.append(elmlst.at(j));
+ }
+ elmlst.clear();
+ */
+ }
+ }
+ layers.clear();
+}
+
+void FNCanvas::open(FNLayerList& layers, FILE* fp)
+{
+ QString line;
+ FNPointList points;
+ points.setAutoDelete(true);
+ int c;
+ int w;
+ QPen pen(Qt::black, 1);
+ FNPolygon* polygon;
+
+ char rdbuf[1024];
+ char buf[1024];
+ QString type = "";
+ QStringList lines;
+ layers.setAutoDelete(true);
+ layers.clear();
+ layers.setAutoDelete(false);
+ FNLayer* layer = new FNLayer();
+ layer->IsShow = true;
+ layer->Name = "Layer0";
+ //_current = layer;
+ layers.append(layer);
+ FNPolygonList* list = &layer->draws;
+ bool isFirstLayer = true;
+ bool fill = false;
+ while (!feof(fp)) {
+ fgets(rdbuf, sizeof(rdbuf), fp);
+ line = rdbuf;
+ if (-1 != line.find("<freenote")) {
+ if (-1 != line.find("pg=1")) {
+ _isTinyPaging = true;
+ } else {
+ _isTinyPaging = false;
+ }
+ int st = line.find("idx=") + 5;
+ int ed = line.find("\"", st);
+ strcpy(buf, line.mid(st, ed - st));
+ sscanf(buf, "%d", &_selIdx);
+ } else if (-1 != line.find("<layer ")) {
+ if (false == isFirstLayer) {
+ layer = new FNLayer();
+ list = &layer->draws;
+ layers.append(layer);
+ }
+ isFirstLayer = false;
+
+ if (-1 != line.find("v=0")) {
+ layer->IsShow = false;
+ } else if (-1 != line.find("v=1")) {
+ layer->IsShow = true;
+ }
+ int st = line.find("name=") + 6;
+ int ed = line.find("\"", st);
+ strcpy(buf, line.mid(st, ed - st));
+ QTextCodec *codec = QTextCodec::codecForName("utf8");
+ layer->Name = codec->toUnicode(buf);
+ } else if (-1 != line.find("<fnpolygon ") ||
+ -1 != line.find("<po ") ||
+ -1 != line.find("<bz ") ||
+ -1 != line.find("<el ") ||
+ -1 != line.find("<tx ")
+ ) {
+ if (-1 != line.find("<el ")) {
+ type = "Ellipse";
+ } else if (-1 != line.find("<bz ")) {
+ type = "Bezier";
+ } else if (-1 != line.find("<tx ")) {
+ type = "Text";
+ lines.clear();
+ } else {
+ type = "Polygon";
+ }
+ fill = false;
+ points.clear();
+ int st = line.find("color") + 7;
+ int ed = line.find("\"", st);
+ strcpy(buf, line.mid(st, ed - st));
+ sscanf(buf, "%x", &c);
+
+ st = line.find("width") + 7;
+ ed = line.find("\"", st);
+ strcpy(buf, line.mid(st, ed - st));
+ sscanf(buf, "%d", &w);
+
+ if (-1 != line.find(" f=\"1\"")) {
+ fill = true;
+ }
+ } else if (-1 != line.find("<point ") ||
+ -1 != line.find("<p ")
+ ) {
+ int st = line.find("x=") + 3;
+ int ed = line.find("\"", st);
+ strcpy(buf, line.mid(st, ed - st));
+ int x;
+ sscanf(buf, "%d", &x);
+
+ st = line.find("y=") + 3;
+ ed = line.find("\"", st);
+ strcpy(buf, line.mid(st, ed - st));
+ int y;
+ sscanf(buf, "%d", &y);
+ points.append(createPts(x, y)); //バグ対策
+ } else if (-1 != line.find("<t ")) {
+ int st = line.find("v=") + 3;
+ int ed = line.findRev("\"");
+ strcpy(buf, line.mid(st, ed - st));
+ QTextCodec *codec = QTextCodec::codecForName("utf8");
+ lines.append(codec->toUnicode(buf));
+ } else if (-1 != line.find("</fnpolygon") ||
+ -1 != line.find("</bz") ||
+ -1 != line.find("</el") ||
+ -1 != line.find("</po") ||
+ -1 != line.find("</tx")) {
+ pen.setColor((QRgb)c);
+ pen.setWidth(w);
+ if (type == "Bezier") {
+ list->append(polygon = createBezier(pen)); //バグ対策
+ } else if (type == "Ellipse") {
+ list->append(polygon = createEllipse(pen)); //バグ対策
+ } else if (type == "Text") {
+ list->append(polygon = createText(pen, lines));
+ } else {
+ list->append(polygon = createPolygon(pen)); //バグ対策
+ }
+ polygon->setFill(fill);
+ polygon->setPoints(points);
+ points.clear();
+ }
+ }
+}
+
+FNPolygon* FNCanvas::createPolygon(QPen& pen)
+{
+ return new FNPolygon(pen);
+}
+
+FNPolygon* FNCanvas::createBezier(QPen& pen)
+{
+ return new FNBezier(pen);
+}
+
+
+FNPolygon* FNCanvas::createEllipse(QPen& pen)
+{
+ return new FNEllipse(pen);
+}
+
+FNPolygon* FNCanvas::createText(QPen& pen, QStringList& lines)
+{
+ FNText* p = new FNText(pen);
+ p->lines = lines;
+ return p;
+}
+
+QPoint* FNCanvas::createPts(int x, int y)
+{
+ return new QPoint(x, y);
+}
+
+void FNCanvas::setGuide(bool f)
+{
+ _isShowGuide = f;
+ redraw();
+}
+
+void FNCanvas::fillChanged(bool f) {
+ _fill = f;
+ if (_isSelected) {
+ for (uint i = 0; i < _selected.count(); ++i) {
+ _selected.at(i)->setFill(f);
+ }
+ }
+}
diff --git a/packages/freenote/files/FreeNote/FreeNote/FNFindDialog.cpp b/packages/freenote/files/FreeNote/FreeNote/FNFindDialog.cpp new file mode 100644 index 0000000000..9d0998ad04 --- /dev/null +++ b/packages/freenote/files/FreeNote/FreeNote/FNFindDialog.cpp @@ -0,0 +1,143 @@ +/* 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/02/27 FreeNote 1.11.10pre +・PDFの出力形式を一部変更 +・インポート時のバグfix + +2005/01/04 FreeNote 1.11.6pre +・カーブモードで8の字がかけるように整形エンジンを改善 + +2004/10/17 FreeNote 1.10.0リリース +2004/02/14 ver 1.7.2pre +・検索機能の追加 +*/ +#include "fnfinddialog.h" +#include "fmtengine.h" +#include <qlineedit.h> +#include <stdio.h> +#include <qregexp.h> +#include <qcheckbox.h> + +FNFindDialog::FNFindDialog( QWidget* parent, const char* name) + :FNFindDialogBase(parent, name, true, 0), _idx(0) +{ +} + +void FNFindDialog::setElements(FNLayerList& v) +{ + _texts.clear(); + for (uint i = 0; i < v.count(); ++i) { + FNLayer& layer = *v.at(i); + if (layer.IsShow) { + FNPolygonList& draws = layer.draws; + for (uint j = 0; j < draws.count(); ++j) { + FNPolygon* p = draws.at(j); + if (FN_TEXT == p->type()) { + _texts.append(p); + } + } + } + } + _idx = -1; +} + +void FNFindDialog::findPrev() +{ + QString sch = txtSearch->text(); + QRegExp rex(sch); + if (0 == sch.length()) { + return; + } + if (0 > _idx) { + _idx = _texts.count() - 1; + } + if ((uint)_idx >= _texts.count()) { + _idx = _texts.count() - 1; + } + for (; _idx >= 0; --_idx) { + FNText* p = (FNText*)_texts.at(_idx); + for (uint i = 0; i < p->lines.count(); ++i) { + if (ckbIsRegExp->isChecked()) { + for (uint i = 0; i < p->lines.count(); ++i) { + if (-1 != p->lines[i].find(rex)) { + emit resetOrigin(); + QPoint sp = p->points().point(0); + emit originChanged(sp.x() - SNAP_SIZE, sp.y() - SNAP_SIZE); + --_idx; + return; + } + } + } else { + for (uint i = 0; i < p->lines.count(); ++i) { + if (-1 != p->lines[i].find(sch)) { + emit resetOrigin(); + QPoint sp = p->points().point(0); + emit originChanged(sp.x() - SNAP_SIZE, sp.y() - SNAP_SIZE); + --_idx; + return; + } + } + } + } + } +} + +void FNFindDialog::findNext() +{ + QString sch = txtSearch->text(); + QRegExp rex(sch); + if (0 == sch.length()) { + return; + } + if (0 > _idx) { + _idx = 0; + } + if ((uint)_idx >= _texts.count()) { + _idx = 0; + } + for (; (uint)_idx < _texts.count(); ++_idx) { + FNText* p = (FNText*)_texts.at(_idx); + if (ckbIsRegExp->isChecked()) { + for (uint i = 0; i < p->lines.count(); ++i) { + if (-1 != p->lines[i].find(rex)) { + emit resetOrigin(); + QPoint sp = p->points().point(0); + emit originChanged(sp.x() - SNAP_SIZE, sp.y() - SNAP_SIZE); + ++_idx; + return; + } + } + } else { + for (uint i = 0; i < p->lines.count(); ++i) { + if (-1 != p->lines[i].find(sch)) { + emit resetOrigin(); + QPoint sp = p->points().point(0); + emit originChanged(sp.x() - SNAP_SIZE, sp.y() - SNAP_SIZE); + ++_idx; + return; + } + } + } + } +} + + +FNFindDialog::~FNFindDialog() +{ +} diff --git a/packages/freenote/files/FreeNote/FreeNote/FNMessageBox.cpp b/packages/freenote/files/FreeNote/FreeNote/FNMessageBox.cpp new file mode 100644 index 0000000000..1518651338 --- /dev/null +++ b/packages/freenote/files/FreeNote/FreeNote/FNMessageBox.cpp @@ -0,0 +1,243 @@ +/* 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/02/27 FreeNote 1.11.10pre
+・PDFの出力形式を一部変更
+・インポート時のバグfix
+
+2004/10/17 FreeNote 1.10.0リリース
+2003/08/15 FreeNote 1.2.1を公開
+・保存時のバグ修正
+・完了ダイアログの自動消去
+・PNGファイルへの出力
+*/
+#include "fnmessagebox.h"
+int ___fnmessagebox_timing = 1500;
+
+FNMessageBox::FNMessageBox(QWidget *parent, const char* name) : QMessageBox(parent, name)
+{
+ _timer = new QTimer(this);
+ connect(_timer, SIGNAL(timeout()), this, SLOT(timeout()));
+}
+
+FNMessageBox::FNMessageBox(const QString& caption, const QString& text, Icon icon, int button0, int button1, int button2, QWidget* parent, const char* name, bool modal, WFlags f) : QMessageBox(caption, text, icon, button0, button1, button2, parent, name, modal, f)
+{
+ _timer = new QTimer(this);
+ connect(_timer, SIGNAL(timeout()), this, SLOT(timeout()));
+}
+
+FNMessageBox::~FNMessageBox()
+{
+ delete _timer;
+}
+
+int FNMessageBox::information(QWidget* parent, const QString& caption, const QString& text, int button0, int button1, int button2)
+{
+ FNMessageBox dlg(caption, text, QMessageBox::Information, button0, button1, button2, parent);
+ dlg.show();
+ return dlg.exec();
+}
+
+int FNMessageBox::information(QWidget* parent, const QString& caption, const QString& text, const QString& button0Text, const QString& button1Text, const QString& button2Text, int defaultButtonNumber, int escapeButtonNumber)
+{
+ int button0 = 0;
+ int button1 = 0;
+ int button2 = 0;
+ if (QString::null == button0Text) {
+ int id = Ok;
+ if (0 == defaultButtonNumber) {
+ id += Default;
+ }
+ if (0 == escapeButtonNumber) {
+ id += Escape;
+ }
+ button0 = id;
+ }
+ if (QString::null != button1Text) {
+ int id = Cancel;
+ if (1 == defaultButtonNumber) {
+ id += Default;
+ }
+ if (1 == escapeButtonNumber) {
+ id += Escape;
+ }
+ button1 = id;
+ }
+ if (QString::null != button2Text) {
+ int id = Abort;
+ if (2 == defaultButtonNumber) {
+ id += Default;
+ }
+ if (2 == escapeButtonNumber) {
+ id += Escape;
+ }
+ button2 = id;
+ }
+ FNMessageBox dlg(caption, text, QMessageBox::Information, button0, button1, button2, parent);
+ if (0 != button0) {
+ dlg.setButtonText(button0, button0Text);
+ }
+ if (0 != button1) {
+ dlg.setButtonText(button1, button1Text);
+ }
+ if (0 != button2) {
+ dlg.setButtonText(button2, button2Text);
+ }
+ dlg.show();
+ return dlg.exec();
+}
+
+int FNMessageBox::warning(QWidget* parent, const QString& caption, const QString& text, int button0, int button1, int button2)
+{
+ FNMessageBox dlg(caption, text, QMessageBox::Warning, button0, button1, button2, parent);
+ dlg.show();
+ return dlg.exec();
+}
+
+int FNMessageBox::warning(QWidget* parent, const QString& caption, const QString& text, const QString& button0Text, const QString& button1Text, const QString& button2Text, int defaultButtonNumber, int escapeButtonNumber)
+{
+ int button0 = 0;
+ int button1 = 0;
+ int button2 = 0;
+ if (QString::null == button0Text) {
+ int id = Ok;
+ if (0 == defaultButtonNumber) {
+ id += Default;
+ }
+ if (0 == escapeButtonNumber) {
+ id += Escape;
+ }
+ button0 = id;
+ }
+ if (QString::null != button1Text) {
+ int id = Cancel;
+ if (1 == defaultButtonNumber) {
+ id += Default;
+ }
+ if (1 == escapeButtonNumber) {
+ id += Escape;
+ }
+ button1 = id;
+ }
+ if (QString::null != button2Text) {
+ int id = Abort;
+ if (2 == defaultButtonNumber) {
+ id += Default;
+ }
+ if (2 == escapeButtonNumber) {
+ id += Escape;
+ }
+ button2 = id;
+ }
+ FNMessageBox dlg(caption, text, QMessageBox::Warning, button0, button1, button2, parent);
+ if (0 != button0) {
+ dlg.setButtonText(button0, button0Text);
+ }
+ if (0 != button1) {
+ dlg.setButtonText(button1, button1Text);
+ }
+ if (0 != button2) {
+ dlg.setButtonText(button2, button2Text);
+ }
+ dlg.show();
+ return dlg.exec();
+}
+
+int FNMessageBox::critical(QWidget* parent, const QString& caption, const QString& text, int button0, int button1, int button2)
+{
+ FNMessageBox dlg(caption, text, QMessageBox::Critical, button0, button1, button2, parent);
+ dlg.show();
+ return dlg.exec();
+}
+
+int FNMessageBox::critical(QWidget* parent, const QString& caption, const QString& text, const QString& button0Text, const QString& button1Text, const QString& button2Text, int defaultButtonNumber, int escapeButtonNumber)
+{
+ int button0 = 0;
+ int button1 = 0;
+ int button2 = 0;
+ if (QString::null == button0Text) {
+ int id = Ok;
+ if (0 == defaultButtonNumber) {
+ id += Default;
+ }
+ if (0 == escapeButtonNumber) {
+ id += Escape;
+ }
+ button0 = id;
+ }
+ if (QString::null != button1Text) {
+ int id = Cancel;
+ if (1 == defaultButtonNumber) {
+ id += Default;
+ }
+ if (1 == escapeButtonNumber) {
+ id += Escape;
+ }
+ button1 = id;
+ }
+ if (QString::null != button2Text) {
+ int id = Abort;
+ if (2 == defaultButtonNumber) {
+ id += Default;
+ }
+ if (2 == escapeButtonNumber) {
+ id += Escape;
+ }
+ button2 = id;
+ }
+ FNMessageBox dlg(caption, text, QMessageBox::Critical, button0, button1, button2, parent);
+ if (0 != button0) {
+ dlg.setButtonText(button0, button0Text);
+ }
+ if (0 != button1) {
+ dlg.setButtonText(button1, button1Text);
+ }
+ if (0 != button2) {
+ dlg.setButtonText(button2, button2Text);
+ }
+ dlg.show();
+ return dlg.exec();
+}
+
+void FNMessageBox::about(QWidget* parent, const QString& caption, const QString& text)
+{
+ FNMessageBox dlg(caption, text, QMessageBox::NoIcon, 0, 0, 0, parent);
+ dlg.show();
+ dlg.exec();
+}
+
+void FNMessageBox::about(QWidget* parent, const QString& caption)
+{
+ FNMessageBox dlg(caption, QString::null, QMessageBox::NoIcon, 0, 0, 0, parent);
+ dlg.show();
+ dlg.exec();
+}
+
+void FNMessageBox::setTiming(const int v)
+{
+ ___fnmessagebox_timing = v;
+}
+
+void FNMessageBox::timeout() {
+ accept();
+}
+
+void FNMessageBox::showEvent(QShowEvent* ext)
+{
+ _timer->start(___fnmessagebox_timing, true);
+}
diff --git a/packages/freenote/files/FreeNote/FreeNote/FNTextDialog.cpp b/packages/freenote/files/FreeNote/FreeNote/FNTextDialog.cpp new file mode 100644 index 0000000000..b4eea5454c --- /dev/null +++ b/packages/freenote/files/FreeNote/FreeNote/FNTextDialog.cpp @@ -0,0 +1,93 @@ +/* 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/02/27 FreeNote 1.11.10pre +・PDFの出力形式を一部変更 +・インポート時のバグfix + +2005/01/04 FreeNote 1.11.6pre +・カーブモードで8の字がかけるように整形エンジンを改善 + +2004/10/17 FreeNote 1.10.0リリース +2004/02/12 ver 1.7.1pre +・フォント仕様の変更 +・テキスト処理の高速化 +・テキストボックスの多機能化 +*/ +#include "fntextdialog.h" +#include <stdio.h> +#include <qcombobox.h> +#include <qfontdatabase.h> +#include <qcolor.h> +#include <qtoolbutton.h> +#include <qpalette.h> +#include <qmultilineedit.h> +#include "fncolordialog.h" + +FNTextDialog::FNTextDialog(const QString& fontname, FNColorDialog* dlg, QWidget* parent, const char* name ) + :FNTextDialogBase(parent, name, true, 0), _pen(1), _colorSelector(dlg) +{ + static QFontDatabase fbase; + QValueList<int> sizes = fbase.pointSizes(fontname); + char buf[10]; + for (uint i = 0; i < sizes.count(); ++i) { + sprintf(buf, "%d", sizes[i]); + cboFontSize->insertItem(buf); + } + lines->setFont(QFont(fontname, 20)); +} + + +FNTextDialog::~FNTextDialog() +{ +} + +void FNTextDialog::changeColor(QRgb c) +{ + fraColor->setBackgroundColor(QColor(c)); + _pen.setColor(QColor(c)); +} + +void FNTextDialog::choose(int v) +{ + _pen.setWidth(v); +} + +void FNTextDialog::btnColor_Clicked() +{ + _colorSelector->setColor(_pen.color()); + _colorSelector->show(); + if (_colorSelector->exec()) { + changeColor(_colorSelector->color().rgb()); + } +} + +void FNTextDialog::setPen(const QPen& pen) +{ + _pen = pen; + if (cboFontSize->count() <= (int)pen.width()) { + _pen.setWidth(cboFontSize->count()-1); + } + cboFontSize->setCurrentItem(_pen.width()); + fraColor->setBackgroundColor(_pen.color()); +} + +const QPen& FNTextDialog::pen() const +{ + return _pen; +} diff --git a/packages/freenote/files/FreeNote/FreeNote/FmtEngine.cpp b/packages/freenote/files/FreeNote/FreeNote/FmtEngine.cpp new file mode 100644 index 0000000000..dae8a81b3b --- /dev/null +++ b/packages/freenote/files/FreeNote/FreeNote/FmtEngine.cpp @@ -0,0 +1,512 @@ +/* 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/02/27 FreeNote 1.11.10pre
+・PDFの出力形式を一部変更
+・インポート時のバグfix
+
+2005/01/04 FreeNote 1.11.6pre
+・カーブモードで8の字がかけるように整形エンジンを改善
+
+2005/01/09 FNViewer ジェスチャー用ロジック追加
+2004/10/17 FreeNote 1.10.0リリース
+2003/12/16-19 FreeNote ver 1.5.5pre
+・曲線描画ロジックの改良
+
+2003/12/14 FreeNote 1.5.4pre
+・曲線描画ロジックの改良
+
+2003/11/30-2003/12/04 FreeNote 1.5.3pre
+・ベジェ関数のスペルミスを修正
+
+2003/11/16 FreeNote 1.5.2pre
+・円描画のロジックを追加
+
+2003/11/13 FreeNote 1.5.1pre
+・スムージング追加
+2003/11/10-12
+・曲線整形モード追加
+2003/11/09 追加
+*/
+#include "fmtengine.h"
+#include <qpointarray.h>
+#include <qpe/qmath.h>
+#include <math.h>
+#include <qrect.h>
+#include <stdlib.h>
+
+int SNAP_SIZE = 32;
+int PHASE1_ANGLE = 30;
+int PHASE2_ANGLE = 30;
+double Surface(const QPoint& p1, const QPoint& p2)
+{
+ return 0.5 * abs(p1.x() * p2.y() - p1.y() * p2.x());
+}
+
+bool IsLinear(const QPoint& p1, const QPoint& p2, const QPoint& p3)
+{
+ double s1 = Surface(p1, p2);
+ double s2 = Surface(p2, p3);
+ double s3 = Surface(p1, p3);
+ if (s1 + s2 == s3) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+const double Angle(const QPoint& p1, const QPoint& p2)
+{
+ return qATan2((double)(p2.y() - p1.y()), (double)(p2.x() - p1.x()));
+}
+
+const double DiffAngle(double a1, double a2)
+{
+ if (0.0 > a1) {
+ a1 = 2 * M_PI + a1;
+ }
+ if (0.0 > a2) {
+ a2 = 2 * M_PI + a2;
+ }
+ return fabs(a1 - a2);
+}
+
+const double DiffAngle2(double a1, double a2)
+{
+ if (0.0 > a1) {
+ a1 = 360 + a1;
+ }
+ if (0.0 > a2) {
+ a2 = 360 + a2;
+ }
+ return fabs(a1 - a2);
+}
+
+const double DiffAngle(const QPoint& p1, const QPoint& p2, const QPoint& p3)
+{
+ return DiffAngle(Angle(p1, p2), Angle(p2, p3));
+}
+
+const double ToDegree(double t)
+{
+ return t * 180 / M_PI;
+}
+
+const double ToRadian(double d)
+{
+ return d * M_PI / 180;
+}
+
+const double Distance(const QPoint& p1, const QPoint& p2)
+{
+ return hypot(p1.x() - p2.x(), p1.y() - p2.y());
+}
+
+const QPoint SnapPoint(const QPoint& p, int snap)
+{
+ int x = ((int)(p.x() + snap / 2) / snap) * snap;
+ int y = ((int)(p.y() + snap / 2) / snap) * snap;
+ return QPoint(x, y);
+}
+const QPoint SnapPoint(const QPoint& p)
+{
+ return SnapPoint(p, SNAP_SIZE);
+}
+/*
+const QPoint SnapPoint(const QPoint& p)
+{
+ int x = ((int)(p.x() + SNAP_SIZE / 2) / SNAP_SIZE) * SNAP_SIZE;
+ int y = ((int)(p.y() + SNAP_SIZE / 2) / SNAP_SIZE) * SNAP_SIZE;
+ return QPoint(x, y);
+}
+*/
+
+const QPoint ArrangePoint(const QPoint& p1, const QPoint& p2)
+{
+ int x = p2.x();
+ int y = p2.y();
+ if (p1.x() - SNAP_SIZE / 2 <= x && p1.x() + SNAP_SIZE / 2 >= x) {
+ x = p1.x();
+ }
+ if (p1.y() - SNAP_SIZE / 2 <= y && p1.y() + SNAP_SIZE / 2 >= y) {
+ y = p1.y();
+ }
+ return QPoint(x, y);
+}
+
+FNPointList ReducePoints(FNPointList& p)
+{
+ if (2 >= p.count()) {
+ return p;
+ }
+ FNPointList rt;
+ rt.append(p.first());
+ QPoint* p1 = p.first();
+ QPoint* p2 = p.at(1);
+ QPoint* p3 = NULL;
+ for (uint i = 2; i < p.count(); ++i) {
+ p3 = p.at(i);
+ if (false == IsLinear(*p1, *p2, *p3)) {
+ rt.append(p2);
+ p1 = p2;
+ }
+ p2 = p3;
+ }
+ rt.append(p3);
+ return rt;
+}
+
+FNPointList ExtractAngle2(FNPointList& p, const int deg)
+{
+ FNPointList rt;
+ rt.append(p.first());
+ QPoint* st = p.first();
+ QPoint* mp = p.at(1);
+ QPoint* ed = p.last();
+ for (uint i = 2; i < p.count(); ++i) {
+ ed = p.at(i);
+ if (ToRadian(deg) <= DiffAngle(*st, *mp, *ed)) {
+ st = mp;
+ rt.append(mp);
+ }
+ mp = ed;
+ }
+ rt.append(ed);
+ return rt;
+}
+
+FNPointList ExtractAngle(FNPointList& p, const int deg)
+{
+ FNPointList rt;
+ rt.append(p.first());
+ QPoint* st = p.first();
+ QPoint* mp = p.at(1);
+ QPoint* ed = p.last();
+ for (uint i = 2; i < p.count(); ++i) {
+ ed = p.at(i);
+ if (ToRadian(deg) <= DiffAngle(*st, *mp, *ed)) {
+ st = mp;
+ rt.append(mp);
+ }
+ mp = ed;
+ }
+ if (SNAP_SIZE / 2 > Distance(*p.first(), *p.last()) && 3 < p.count()) {
+ rt.append(p.first());
+ } else {
+ rt.append(ed);
+ }
+ return rt;
+}
+
+FNPointList SumupPoints(FNPointList& p)
+{
+ if (3 >= p.count()) {
+ return p;
+ }
+ FNPointList rt;
+ rt.append(p.first());
+ QPoint* p1 = p.first();
+ QPoint* p2 = NULL;
+ double pred = 0;
+ for (uint i = 1; i < p.count() - 1; ++i) {
+ p2 = p.at(i);
+ double d = Distance(*p1, *p2);
+ if (SNAP_SIZE / 2 < d || pred > d) {
+ rt.append(p2);
+ p1 = p2;
+ d = 0;
+ }
+ pred = d;
+ }
+ rt.append(p.last());
+ return rt;
+}
+
+FNPointList SnapPoints(FNPointList& p)
+{
+ FNPointList rt;
+ for (uint i = 0; i < p.count(); ++i) {
+ QPoint tp = SnapPoint(*p.at(i));
+ p.at(i)->setX(tp.x());
+ p.at(i)->setY(tp.y());
+ rt.append(p.at(i));
+ }
+ return rt;
+}
+
+FNPointList ArrangePoints(FNPointList& p)
+{
+ if (3 >= p.count() && 2 != p.count()) {
+ return p;
+ }
+ FNPointList rt;
+ rt.append(p.first());
+ QPoint* p1 = p.first();
+ QPoint* p2 = NULL;
+ for (uint i = 1; i < p.count(); ++i) {
+ p2 = p.at(i);
+ QPoint tp = ArrangePoint(*p1, *p2);
+ p2->setX(tp.x());
+ p2->setY(tp.y());
+ rt.append(p2);
+ p1 = p2;
+ }
+ if (*p.first() == *p.last()) {
+ QPoint tp = ArrangePoint(*p1, *p.first());
+ rt.first()->setX(tp.x());
+ rt.first()->setY(tp.y());
+ }
+ return rt;
+}
+
+FNPointList TuningPoints(FNPointList& p)
+{
+ FNPointList rt;
+ if (3 >= p.count()) {
+ for (uint i = 0; i < p.count(); ++i) {
+ rt.append(new QPoint(*p.at(i)));
+ }
+ return rt;
+ }
+ rt.append(new QPoint(*p.at(0)));
+ for (uint i = 1; i < p.count() - 1; ++i) {
+ QPoint* p1 = p.at(i);
+ QPoint* p2 = p.at(i + 1);
+ rt.append(new QPoint(*p1));
+ if (i < p.count() - 2) {
+ rt.append(new QPoint((p1->x() + p2->x())/2, (p1->y() + p2->y())/2));
+ }
+ }
+ rt.append(new QPoint(*p.at(p.count()-1)));
+ return rt;
+}
+
+FNPointList ToBezier(FNPointList& p) {
+ FNPointList rt;
+ rt.append(new QPoint(*p.at(0)));
+ for (uint i = 0; i < p.count() - 2; i += 2) {
+ int x1 = p.at(i)->x();
+ int xa = p.at(i + 1)->x();
+ int x4 = p.at(i + 2)->x();
+
+ int x2 = (x1 + xa) / 2;
+ int x3 = (xa + x4) / 2;
+
+ int y1 = p.at(i)->y();
+ int ya = p.at(i + 1)->y();
+ int y4 = p.at(i + 2)->y();
+
+ int y2 = (y1 + ya) / 2;
+ int y3 = (ya + y4) / 2;
+
+ rt.append(new QPoint(x2 ,y2));
+ rt.append(new QPoint(x3 ,y3));
+ rt.append(new QPoint(x4 ,y4));
+ }
+ return rt;
+}
+
+FNPointList ToCurves(FNPointList& p) {
+ if (3 <= p.count()) {
+ //ベジェによる補完
+ return ToBezier(p);
+ } else {
+ FNPointList rt;
+ for (uint i = 0; i < p.count(); ++i) {
+ rt.append(new QPoint(*p.at(i)));
+ }
+ return rt;
+ }
+}
+
+FNPointList AutoFormat(FNPointList& p)
+{
+ FNPointList tp = ExtractAngle(p, PHASE1_ANGLE);
+ uint n;
+ do {
+ n = tp.count();
+ tp = SumupPoints(tp);
+ tp = ExtractAngle(tp, PHASE1_ANGLE);
+ tp = ArrangePoints(tp);
+ } while (n > tp.count());
+ tp = SnapPoints(tp);
+ tp = ReducePoints(tp);
+ FNPointList rt;
+ if (2 == tp.count()) {
+ if (*tp.first() == *tp.last()) {
+ return rt;
+ }
+ }
+ for (uint i = 0; i < tp.count(); ++i) {
+ rt.append(new QPoint(*tp.at(i)));
+ }
+ return rt;
+}
+
+FNPointList ToEllipse(int x, int y, int w, int h) {
+ FNPointList rt;
+ QPointArray pa;
+ pa.makeEllipse(x, y, w, h);
+ for (uint i = 0; i < pa.count(); ++i) {
+ rt.append(new QPoint(pa.point(i)));
+ }
+ return rt;
+}
+
+FNPointList AutoCurve(FNPointList& p)
+{
+ FNPointList tp2;
+ tp2.setAutoDelete(true);
+ FNPointList tp4;
+ tp4.setAutoDelete(true);
+ /*
+ QPoint sp = SnapPoint(*p.at(0));
+ QPoint ep = SnapPoint(*p.at(p.count()-1));
+ if (sp == ep) {
+ //楕円
+ int sx = p.at(0)->x();
+ int sy = p.at(0)->y();
+ int ex = sx;
+ int ey = sy;
+ for (uint i = 1; i < p.count(); ++i) {
+ QPoint tp = *p.at(i);
+ if (sx > tp.x()) {
+ sx = tp.x();
+ } else if (ex < tp.x()) {
+ ex = tp.x();
+ }
+ if (sy > tp.y()) {
+ sy = tp.y();
+ } else if (ey < tp.y()) {
+ ey = tp.y();
+ }
+ }
+ sp = SnapPoint(QPoint(sx, sy));
+ ep = SnapPoint(QPoint(ex, ey));
+ tp2.append(new QPoint(sp.x(), sp.y()));
+ tp2.append(new QPoint(ep.x(), ep.y()));
+ } else {
+ */
+ FNPointList tp = ExtractAngle2(p, PHASE2_ANGLE);
+ uint n;
+ do {
+ n = tp.count();
+ tp = SumupPoints(tp);
+ tp = ExtractAngle2(tp, PHASE2_ANGLE);
+ tp = SnapPoints(tp);
+ } while (n > tp.count());
+ tp = SumupPoints(tp);
+ tp = ReducePoints(tp);
+ tp4 = TuningPoints(tp);
+ tp2 = ToCurves(tp4);
+ //}
+ FNPointList rt;
+ if (2 == tp2.count()) {
+ if (*tp2.first() == *tp2.last()) {
+ return rt;
+ }
+ }
+ for (uint i = 0; i < tp2.count(); ++i) {
+ rt.append(new QPoint(*tp2.at(i)));
+ }
+ return rt;
+}
+
+FNPointList Smoothing(FNPointList& p)
+{
+ int tsnap = SNAP_SIZE;
+ SNAP_SIZE=8;
+ FNPointList tp = ExtractAngle2(p, PHASE2_ANGLE);
+ tp = SumupPoints(tp);
+ tp = ReducePoints(tp);
+ FNPointList tp4 = TuningPoints(tp);
+ tp4.setAutoDelete(true);
+ FNPointList tp2 = ToCurves(tp4);
+ tp2.setAutoDelete(true);
+ FNPointList rt;
+ for (uint i = 0; i < tp2.count(); ++i) {
+ rt.append(new QPoint(*tp2.at(i)));
+ }
+ SNAP_SIZE = tsnap;
+ return rt;
+}
+
+FNPointList Reduce(FNPointList& p)
+{
+ FNPointList tp = ReducePoints(p);
+ FNPointList rt;
+ for (uint i = 0; i < tp.count(); ++i) {
+ rt.append(new QPoint(*tp.at(i)));
+ }
+ return rt;
+}
+
+QRect GetBounds(FNPointList& v)
+{
+ if (1 > v.count()) {
+ return QRect(0, 0, 1, 1);
+ }
+ QPoint sp = *v.at(0);
+ QPoint ep = sp;
+ for (uint i = 1; i < v.count(); ++i) {
+ QPoint& p = *v.at(i);
+ if (sp.x() > p.x()) {
+ sp.setX(p.x());
+ }
+ if (sp.y() > p.y()) {
+ sp.setY(p.y());
+ }
+ if (ep.x() < p.x()) {
+ ep.setX(p.x());
+ }
+ if (ep.y() < p.y()) {
+ ep.setY(p.y());
+ }
+ }
+ return QRect(sp, ep);
+}
+
+FNPointList Translate(FNPointList& v, int x, int y, double xs, double ys)
+{
+ FNPointList rt;
+ for (uint i = 0; i < v.count(); ++i) {
+ QPoint& p = *v.at(i);
+ int X = (int)((p.x() - x) * xs);
+ int Y = (int)((p.y() - y) * ys);
+ rt.append(new QPoint(X, Y));
+ }
+ return rt;
+}
+
+double ToStrokeDeg(double v)
+{
+ double d = ((int)(v * 10 / 225)) * 22.5;
+ return d;
+}
+
+int sign(int v)
+{
+ if (0 > v) {
+ return -1;
+ } else if (0 < v) {
+ return 1;
+ } else {
+ return 0;
+ }
+};
+
diff --git a/packages/freenote/files/FreeNote/FreeNote/FrmMain.cpp b/packages/freenote/files/FreeNote/FreeNote/FrmMain.cpp new file mode 100644 index 0000000000..1cb4407d32 --- /dev/null +++ b/packages/freenote/files/FreeNote/FreeNote/FrmMain.cpp @@ -0,0 +1,1442 @@ +/* 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 Foundatibannwaon; 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/07/12 FreeNote 1.12.0 +・Fixリリース + +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/10/17 FreeNote 1.10.0リリース +・ツール機能追2004/08/26 ver 1.9.3Apre +・罫線機能の修正 + +・ツール機能追2004/08/26 ver 1.9.3pre +・罫線機能を追加 + +2004/06/19-25 ver 1.9.2pre +・qcop装備 + +2004/05/19 ver 1.9.1pre +・PDFのテキストをUnicodeへ。 +・オプションにPDF::Encode項目を追加。 + +2004/02/26 ver 1.9.0pre +・インポート機能 + +2004/02/19 ver 1.8.0 fix. +2004/02/16 ver 1.7.3pre +・編集機能強化 + +2004/02/14 ver 1.7.2pre +・検索機能追加 + +2004/02/12 ver 1.7.1pre +・フォント仕様の変更 +・テキスト処理の高速化 +・テキストボックスの多機能化 + +2004/02/10 ver 1.7.0pre +・文字入力 + +2003/12/21 ver 1.6.0 +・フローティングパレットが無効となっていたバグを修正 +・機能をFix + +2003/12/16-19 ver 1.5.5pre +・ペン幅の拡張(1-8) +・アンドゥ、リドゥの実装 +・メニューの処理方法を一部改良 +・高速Quit実装 + +2003/12/14 FreeNote 1.5.4pre +・ペンサイズを選択可能に。 + +2003/11/30-2003/12/04 FreeNote 1.5.3pre +・ExportPNG, ExportPDFの初期ファイル名がfreeファイル名に沿うように修正 + +2003/11/16 FreeNote 1.5.2pre +・曲線整形モード修正 + 円描画のロジックを追加 + +2003/11/10-12 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/17-23 ver 1.3.0pre +・aboutを付与 +・CRボタン追加 +・スクロールモードの保存 +・ガイド状態の保存 + +2003/08/17 FreeNote 1.2.2を公開 +・拡張子.freeの自動付与が失敗するケースを修正 + +2003/08/15 FreeNote 1.2.1を公開 +・保存時のバグ修正 +・完了ダイアログの自動消去 +・PNGファイルへの出力 + +2003/08/15 FreeNote 1.2を公開 +・オプション追加 +・スクロールガイド +・Freeファイル関連付け +・アイコンの変更 + +2003/08/05 FreeNote 1.1.1preを公開 +・高速起動時に閉じた状態を保持 +・描画モード切替え時に消しゴム表示 +・保存時間短縮 +・Viewモードの挙動を変更 +・メニューの見た目を変更 +*/ +#include "frmmain.h" +#include <unistd.h> +#include <stdlib.h> + +#include <qpe/global.h> +#include <qpe/qcopenvelope_qws.h> +#include <qpe/applnk.h> +#include <qpe/mimetype.h> + +#include <qapplication.h> +#include <qtoolbutton.h> +#include <qmessagebox.h> +#include <qgrid.h> +#include <qdir.h> +#include <qstring.h> +#include <qdatetime.h> +#include <qtextcodec.h> +#include <qdatastream.h> +#include <qpixmap.h> + +#include "fnfiledialog.h" +#include "fniconset.h" +#include "fmtengine.h" +#include "fnmessagebox.h" +#include "fnlayerdlg.h" +#include "fnpolygon.h" + +#define VERSION "1.12.0" +/* + * Constructs a FrmMain which is a child of 'parent', with the + * name 'name' and widget flags set to 'f' + */ +FrmMain::FrmMain( QWidget* parent, const char* name, WFlags fl ) + : QMainWindow( parent, name, fl ), + _drawMode(MODE_DRAW), + _scrollMode(AS_BOTH), + _useAllQuadrant(false), + _showRuler(false), + _isFullscreen(false), + _isLocked(true), + _isTinyPaging(false), + _isTracking(true) +{ + connect( qApp, SIGNAL(appMessage( const QCString&, const QByteArray&)), this, SLOT( qcop_receive( const QCString&, const QByteArray& ))); + init(); + setup(); + setTitle(); +} + +void FrmMain::setup() +{ + _options.load(); + setOptions(_options); +} + +void FrmMain::qcop_receive(const QCString& msg, const QByteArray& data) +{ + QDataStream stream(data, IO_ReadOnly ); + + if (msg == "setPensize(int)") { + int v; + stream >> v; + if (0 <= v && v <= 8) { + penSelected(v); + } + } else if (msg == "setup()") { + setup(); + } else if (msg == "modeChanged(int)") { + int v; + stream >> v; + if (0 <= v && v <= MODE_MAX) { + modeChanged(v); + } + } else if (msg == "changeColor(int,int,int)") { + int r; + int g; + int b; + stream >> r; + stream >> g; + stream >> b; + if (0 <= r && r <= 255 && + 0 <= g && g <= 255 && + 0 <= b && b <= 255) + { + changeColor(qRgb(r, g, b)); + } + } else if (msg == "find()") { + _canvas->find(); + } else if (msg == "undo()") { + undo(); + } else if (msg == "redo()") { + _canvas->redo(); + } else if (msg == "erase()") { + _canvas->erase(); + } else if (msg == "copy()") { + _canvas->copy(); + } else if (msg == "paste()") { + _canvas->paste(); + } else if (msg == "clear()") { + clear(); + } else if (msg == "CR()") { + hitRet(); + } else if (msg == "setViewMode(int)") { + int v; + stream >> v; + if (0 == v) { + setViewMode(false); + } else { + setViewMode(true); + } + } else if (msg == "load(QString)") { + QString fname; + stream >> fname; + _canvas->load(QFileInfo(fname)); + } else if (msg == "import(QString)") { + QString fname; + stream >> fname; + _canvas->import(QFileInfo(fname)); + } else if (msg == "save(QString)") { + QString fname; + stream >> fname; + _canvas->save(QFileInfo(fname)); + } else if (msg == "exportPDF(QString)") { + QString fname; + stream >> fname; + _canvas->exportPDF(QFileInfo(fname)); + } else if (msg == "exportPNG(QString)") { + QString fname; + stream >> fname; + QPixmap save(_canvas->wbuffer()); + _canvas->exportPNG(QFileInfo(fname), save); + } else if (msg == "tool(int)") { + int v; + stream >> v; + if (1 <= v && v <= 8) { + tool(v); + } + } +} + + +//描画モードの変更 +void FrmMain::modeChanged(int mode) +{ + _drawMode = mode; + _btnCopy->setEnabled(false); + //_btnPaste->setEnabled(false); + _btnPaste->setEnabled(true); + _btnRedo->setEnabled(true); + _btnUndo->setEnabled(true); + switch (_drawMode) { + case MODE_DRAW: //描画 + _menubar->changeItem(_id_mode, QPixmap((const char**)draw_xpm)); + break; + case MODE_FORMAT: //自動整形 + _menubar->changeItem(_id_mode, QPixmap((const char**)format_xpm)); + break; + case MODE_CURVE: //曲線整形 + _menubar->changeItem(_id_mode, QPixmap((const char**)curve_xpm)); + break; + case MODE_SMOOTH: //スムージング + _menubar->changeItem(_id_mode, QPixmap((const char**)smooth_xpm)); + break; + case MODE_TEXT: //テキスト + _menubar->changeItem(_id_mode, QPixmap((const char**)text_xpm)); + break; + case MODE_ERASE: //編集モード + _btnCopy->setEnabled(true); + _btnRedo->setEnabled(false); + _menubar->changeItem(_id_mode, QPixmap((const char**)eraser_xpm)); + break; + case MODE_CPICK: + _menubar->changeItem(_id_mode, QPixmap((const char**)cpick_xpm)); + break; + } + _canvas->modeChanged(_drawMode); +} + +//描画モードの切り替え +void FrmMain::modeMenuChanged(int id) +{ + modeChanged(_draw_menu->indexOf(id)); +} + +void FrmMain::tool(int id) +{ + QString home = getenv("HOME"); + QString cmd = _options.toolScripts[id]; + if (cmd == "") { + return; + } + QStringList token = QStringList::split(' ', cmd); + QDateTime dtime = QDateTime::currentDateTime(); + QDate dt = dtime.date(); + QTime tm = dtime.time(); + char buf[32]; + sprintf(buf, "%02d%02d%02d%02d%02d%02d", dt.year() % 100, dt.month(), dt.day(), tm.hour(), tm.minute(), tm.second()); + QString wkdir = _options.wkdir; + if (false == QFileInfo(wkdir).isDir()) { + wkdir = home; + } + int st = 0; + for (uint i = st; i < token.count(); ++i) { + if (token[i] == "%file") { + save(); + if (_prefile == "") { + return; + } + token[i] = _prefile; + } else if (token[i] == "%pdf") { + exportPDF(); + if (_prepdf == "") { + return; + } + token[i] = _prepdf; + } else if (token[i] == "%png") { + exportPNG(); + if (_prepng == "") { + return; + } + token[i] = _prepng; + } else if (token[i] == "%tmpfile") { + _canvas->save(QFileInfo(home + "/.tmp.free")); + token[i] = home + "/.tmp.free"; + } else if (token[i] == "%tmppng") { + QPixmap save(_canvas->wbuffer()); + _canvas->exportPNG(QFileInfo(home + "/.tmp.png"), save); + token[i] = home + "/.tmp.png"; + } else if (token[i] == "%tmppdf") { + _canvas->exportPDF(QFileInfo(home + "/.tmp.pdf")); + token[i] = home + "/.tmp.pdf"; + } else if (token[i] == "%newfile") { + token[i] = wkdir + "/" + buf +".free"; + _canvas->save(QFileInfo(token[i])); + } else if (token[i] == "%newpng") { + QPixmap save(_canvas->wbuffer()); + token[i] = wkdir + "/" + buf +".png"; + _canvas->exportPNG(QFileInfo(token[i]), save); + } else if (token[i] == "%newpdf") { + token[i] = wkdir + "/" + buf +".pdf"; + _canvas->exportPDF(QFileInfo(token[i])); + } + } + + QFileInfo exefile(token[0]); + if (exefile.extension() == "desktop") { + const AppLnk *app= new AppLnk(exefile.absFilePath()); + QStringList args; + for (uint i = 1; i < token.count(); ++i) { + args << token[i]; + } + app->execute(args); + delete app; + showMinimized(); + } else if (token[0] == "qcop") { + if (3 <= token.count()) { + QCopEnvelope qcop((const char*)token[1], (const char*)token[2]); + for (uint i = 3; i < token.count(); ++i) { + qcop << token[i]; + } + } + } else { + QString args = token[0]; + for (uint i = 1; i < token.count(); ++i) { + args += " "; + args += token[i]; + } + //Global::invoke(args); + Global::execute(args); + } +} + +//オプションの設定 +void FrmMain::setOptions(const FNOptionData& o) +{ + _tool_menu->changeItem(_id_tool1, "1:" + o.toolNames[0]); + _tool_menu->changeItem(_id_tool2, "2:" + o.toolNames[1]); + _tool_menu->changeItem(_id_tool3, "3:" + o.toolNames[2]); + _tool_menu->changeItem(_id_tool4, "4:" + o.toolNames[3]); + _tool_menu->changeItem(_id_tool5, "5:" + o.toolNames[4]); + _tool_menu->changeItem(_id_tool6, "6:" + o.toolNames[5]); + _tool_menu->changeItem(_id_tool7, "7:" + o.toolNames[6]); + _tool_menu->changeItem(_id_tool8, "8:" + o.toolNames[7]); + + _canvas->setScrollTiming(o.timing); + _canvas->setVStep(o.v_step); + _canvas->setHStep(o.h_step); + _canvas->setSEraser(o.eraser_s); + _canvas->setLEraser(o.eraser_l); + _canvas->setMargin(o.margin); + + _vscb->setPageStep(o.v_step); + _vscb->setLineStep(o.grid_size * 2); + _hscb->setPageStep(o.h_step); + _hscb->setLineStep(o.grid_size * 2); + + SNAP_SIZE = o.grid_size; + PHASE1_ANGLE = o.phase1; + PHASE2_ANGLE = o.phase2; + + if (o.isLMvAOn) { + _btnLMvA->show(); + } else { + _btnLMvA->hide(); + } + if (o.isLMvBOn) { + _btnLMvB->show(); + } else { + _btnLMvB->hide(); + } + if (o.isLAddOn) { + _btnLAdd->show(); + } else { + _btnLAdd->hide(); + } + if (o.isFindOn) { + _btnFind->show(); + } else { + _btnFind->hide(); + } + + if (o.isMaximizedOn) { + _btnMaximized->show(); + } else { + _btnMaximized->hide(); + } + + if (o.isCopyOn) { + _btnCopy->show(); + } else { + _btnCopy->hide(); + } + + if (o.isPasteOn) { + _btnPaste->show(); + } else { + _btnPaste->hide(); + } + + if (o.isImportOn) { + _btnImport->show(); + } else { + _btnImport->hide(); + } + + if (o.isUndoOn) { + _btnUndo->show(); + } else { + _btnUndo->hide(); + } + + if (o.isRedoOn) { + _btnRedo->show(); + } else { + _btnRedo->hide(); + } + + if (o.isZoomOn) { + _btnZoom->show(); + } else { + _btnZoom->hide(); + } + + if (o.isCROn) { + _btnRet->show(); + } else { + _btnRet->hide(); + } + + if (o.isGuideOn) { + _btnGuide->show(); + } else { + _btnGuide->hide(); + } + + if (o.isNewOn) { + _btnNew->show(); + } else { + _btnNew->hide(); + } + + if (o.isClearOn) { + _btnClear->show(); + } else { + _btnClear->hide(); + } + + if (o.isOpenOn) { + _btnLoad->show(); + } else { + _btnLoad->hide(); + } + + if (o.isSaveOn) { + _btnSave->show(); + } else { + _btnSave->hide(); + } + + if (o.isExportOn) { + _btnExportPDF->show(); + } else { + _btnExportPDF->hide(); + } + + if (o.isExportPNGOn) { + _btnExportPNG->show(); + } else { + _btnExportPNG->hide(); + } + + if (o.isLayerOn) { + _btnLayer->show(); + } else { + _btnLayer->hide(); + } + + if (AS_HORIZONTAL == o.scrollMode) { + _as_horz->setOn(true); + } else if (AS_VERTICAL == o.scrollMode) { + _as_vert->setOn(true); + } else if (AS_BOTH == o.scrollMode) { + _as_both->setOn(true); + } + _btnGuide->setOn(o.isAutoScrollEnabled); + this->showGuide(o.isAutoScrollEnabled); + _canvas->setShowRuler(_showRuler = o.isShowRuler); + _canvas->setUseAllQuadrant(_useAllQuadrant = o.useAllQuadrant); + _scroll_menu->setItemChecked(_id_quadrant, _useAllQuadrant); + if (_useAllQuadrant) { + _vscb->setMinValue(-200); + _hscb->setMinValue(-200); + } else { + _vscb->setMinValue(0); + _hscb->setMinValue(0); + } + _scroll_menu->setItemChecked(_id_ruler, _showRuler); + _canvas->setEncode(o.encode); + _canvas->setFontName(o.fontname); + _canvas->setColorRevision(o.isColorRevision); + _canvas->setTxtBoxRect(o.txtBoxRect); + SelectionLineColor = o.selectionLineColor; + SelectionBrushColor = o.selectionBrushColor; + SelectionFrameColor = o.selectionFrameColor; + RulerColor = o.rulerColor; + GuideColor = o.guideColor; + GridColor = o.gridColor; + + _canvas->redraw(); +} + +//罫線を表示する(トグル) +void FrmMain::showRuler() +{ + _showRuler = !_showRuler; + _canvas->setShowRuler(_showRuler); + _options.isShowRuler = _showRuler; + _scroll_menu->setItemChecked(_id_ruler, _showRuler); + _options.save(); +} + +//全象限を使用する(トグル) +void FrmMain::useAllQuadrant() +{ + _useAllQuadrant = !_useAllQuadrant; + if (_useAllQuadrant) { + _vscb->setMinValue(-200); + _hscb->setMinValue(-200); + } else { + _vscb->setMinValue(0); + _hscb->setMinValue(0); + } + _canvas->setUseAllQuadrant(_useAllQuadrant); + _scroll_menu->setItemChecked(_id_quadrant, _useAllQuadrant); + _options.useAllQuadrant = _useAllQuadrant; + _options.save(); +} + +//ファイルを渡してオープン +void FrmMain::setDocument(const QString& fname) +{ + this->open(fname); +} + +void FrmMain::showFullScreen() +{ + showNormal(); + _isFullscreen = true; + QMainWindow::showFullScreen(); +} + +void FrmMain::changeColor(QRgb c) +{ + _btnColor->setBGColor(c); + _canvas->changeColor(c); +} + +//ビューモードの切り替え +void FrmMain::setViewMode(bool flg) +{ + if (MODE_ERASE == _drawMode) { + if (flg) { + _btnCopy->setEnabled(false); + _btnPaste->setEnabled(false); + _btnUndo->setEnabled(false); + _btnRedo->setEnabled(false); + } else { + _btnCopy->setEnabled(true); + _btnPaste->setEnabled(true); + _btnUndo->setEnabled(true); + } + } else { + _btnCopy->setEnabled(false); + _btnPaste->setEnabled(true); + _btnUndo->setEnabled(true); + _btnRedo->setEnabled(true); + } + _canvas->viewChanged(flg); + _vscb->setEnabled(!flg); + _hscb->setEnabled(!flg); +} + +//初期設定 +void FrmMain::init() +{ + _colorSelector = new FNColorDialog(this); + QGrid* grid = new QGrid(2, this); + _canvas = new FNCanvas(_colorSelector, grid); + _canvas->resize(240, 320); + _vscb = new QScrollBar(0, 960, 10, 100, 0, Qt::Vertical, grid); + _hscb = new QScrollBar(0, 960, 10, 100, 0, Qt::Horizontal, grid); + this->setCentralWidget(grid); + this->setToolBarsMovable(false); + connect(_vscb, SIGNAL(valueChanged(int)), this, SLOT(scroll())); + connect(_hscb, SIGNAL(valueChanged(int)), this, SLOT(scroll())); + connect(_canvas, SIGNAL(originChanged(int, int)), this, SLOT( scrollbarChange(int, int))); + //メニューの構築 + bool isVGA = false; + if (320 < QApplication::desktop()->width()) { + isVGA = true; + } + + _page_tool = new QPEToolBar(this); + _page_tool->setHorizontalStretchable(true); + + _btnColor = new FNColorPalette(black, _page_tool); + _chkFill = new QCheckBox(_page_tool); + _chkFill->setText("F"); + _chkFill->setFocusPolicy(NoFocus); + _page_tool->addSeparator(); + if (isVGA) { + _btnColor->setMinimumSize(48, 32); + _btnColor->setMaximumSize(48, 32); + } else { + _btnColor->setMinimumSize(24, 18); + _btnColor->setMaximumSize(24, 18); + } + _btnLMvA = newToolButton(_page_tool, (const char**)movetoabove_xpm, "move to above layer", isVGA); + _btnLMvB = newToolButton(_page_tool, (const char**)movetobelow_xpm, "move to below layer", isVGA); + _btnLAdd = newToolButton(_page_tool, (const char**)addlayer_xpm, "add new layer", isVGA); + _btnFind = newToolButton(_page_tool, (const char**)find_xpm, "find", isVGA); + _btnMaximized = newToolButton(_page_tool, (const char **)maximized_xpm, "maximized", isVGA); + _btnCopy = newToolButton(_page_tool, (const char**)copy_xpm, "copy", isVGA); + _btnPaste = newToolButton(_page_tool, (const char**)paste_xpm, "paste", isVGA); + _btnImport = newToolButton(_page_tool, (const char**)import_xpm, "import", isVGA); + _btnUndo = newToolButton(_page_tool, (const char**)undo_xpm, "undo", isVGA); + _btnRedo = newToolButton(_page_tool, (const char**)redo_xpm, "redo", isVGA); + //_btnColor = newToolButton(_page_tool, (const char **)color_xpm, "select color", isVGA); + + _btnZoom = newToolButton(_page_tool, (const char **)zoom_xpm, "zoom", isVGA, true, false, 48); + _btnRet = newToolButton(_page_tool, (const char**)ret_xpm, "return", isVGA); + _btnGuide = newToolButton(_page_tool, (const char **)guide_xpm, "scroll guide", isVGA, true); + _btnNew = newToolButton(_page_tool, (const char **)new_xpm, "new page", isVGA); + _btnClear = newToolButton(_page_tool, (const char **)clear_xpm, "clear page", isVGA); + _btnLoad = newToolButton(_page_tool, (const char **)open_xpm, "load page", isVGA); + _btnSave = newToolButton(_page_tool, (const char **)save_xpm, "save page", isVGA); + _btnExportPDF = newToolButton(_page_tool, (const char **)pdf_xpm, "export PDF", isVGA); + _btnExportPNG = newToolButton(_page_tool, (const char **)png_xpm, "export PNG", isVGA); + _btnLayer = newToolButton(_page_tool, (const char**)layer_xpm, "layer on", isVGA); + + connect(_btnLMvA, SIGNAL(clicked()), this, SLOT(moveAboveLayer())); + connect(_btnLMvB, SIGNAL(clicked()), this, SLOT(moveBelowLayer())); + connect(_btnLAdd, SIGNAL(clicked()), this, SLOT(addLayer())); + connect(_btnFind, SIGNAL(clicked()), _canvas, SLOT(find())); + connect(_btnColor, SIGNAL(clicked(FNPaletteBase*)), this, SLOT(colorSelectorPopup())); + + connect(_btnRet, SIGNAL(clicked()), this, SLOT(hitRet())); + connect(_btnSave, SIGNAL(clicked()), this, SLOT(save())); + connect(_btnLoad, SIGNAL(clicked()), this, SLOT(load())); + connect(_btnNew, SIGNAL(clicked()), this, SLOT(newPage())); + connect(_btnClear, SIGNAL(clicked()), this, SLOT(clear())); + connect(_btnExportPDF, SIGNAL(clicked()), this, SLOT(exportPDF())); + connect(_btnExportPNG, SIGNAL(clicked()), this, SLOT(exportPNG())); + connect(_btnLayer, SIGNAL(clicked()), this, SLOT(showLayer())); + + connect(_btnMaximized, SIGNAL(clicked()), this, SLOT(showFullScreen())); + connect(_btnZoom, SIGNAL(toggled(bool)), this, SLOT(setViewMode(bool))); + connect(_btnCopy, SIGNAL(clicked()), _canvas, SLOT(copy())); + connect(_btnPaste, SIGNAL(clicked()), _canvas, SLOT(paste())); + connect(_btnImport, SIGNAL(clicked()), this, SLOT(import())); + connect(_btnUndo, SIGNAL(clicked()), this, SLOT(undo())); + connect(_btnRedo, SIGNAL(clicked()), _canvas, SLOT(redo())); + connect(_btnGuide, SIGNAL(toggled(bool)), this, SLOT(showGuide(bool))); + connect(_canvas, SIGNAL(resetViewMode()), _btnZoom, SLOT(toggle())); + connect(_chkFill, SIGNAL(toggled(bool)), _canvas, SLOT(fillChanged(bool))); + connect(_canvas, SIGNAL(pickColor(QRgb)), this, SLOT(changeColor(QRgb))); + + _scroll_menu = new QPopupMenu(); + QActionGroup* scroll_action_group = new QActionGroup(_scroll_menu, "scroll actions", true); + scroll_action_group->insert(_as_horz = new QAction("horz", "&Horizontal", 0, scroll_action_group, 0, true)); + scroll_action_group->insert(_as_vert = new QAction("vert", "&Vertical", 0, scroll_action_group, 0, true)); + scroll_action_group->insert(_as_both = new QAction("both", "&Both", 0, scroll_action_group, 0, true)); + _as_both->setOn(true); + _id_guide = _scroll_menu->insertItem("&Guide", _btnGuide, SLOT(toggle()), CTRL + Key_G); + _id_ruler = _scroll_menu->insertItem("show &Ruler", this, SLOT(showRuler()), CTRL + Key_K); + _id_quadrant = _scroll_menu->insertItem("&Use all quadrant", this, SLOT(useAllQuadrant()), CTRL + Key_U); + _scroll_menu->insertSeparator(); + scroll_action_group->addTo(_scroll_menu); + connect(scroll_action_group, SIGNAL(selected(QAction*)), this, SLOT(scroll_menu_selected(QAction*))); + + _main_menu = new QPopupMenu(); + _main_menu->setCheckable(true); + + _edit_menu = new QPopupMenu(); + _edit_menu->insertItem("&Copy", _canvas, SLOT(copy()), CTRL + Key_C); + _edit_menu->insertItem("&Paste", _canvas, SLOT(paste()), CTRL + Key_V); + _edit_menu->insertItem("&Undo", this, SLOT(undo()), CTRL + Key_Z); + _edit_menu->insertItem("&Redo", _canvas, SLOT(redo()), CTRL + Key_Y); + _edit_menu->insertItem("&Find", _canvas, SLOT(find()), CTRL + Key_F); + + _main_menu->insertItem("&Edit", _edit_menu); + + _layer_menu = new QPopupMenu(); + _layer_menu->insertItem("show", this, SLOT(showLayer()), CTRL + Key_B); + _layer_menu->insertItem("move above", this, SLOT(moveAboveLayer()), Key_A); + _layer_menu->insertItem("move below", this, SLOT(moveBelowLayer()), Key_Z); + _layer_menu->insertItem("add layer", this, SLOT(addLayer()), CTRL + Key_A); + _id_tinyPaging = _layer_menu->insertItem("tiny paging mode", this, SLOT(toggleTinyPaging()), CTRL + Key_T); + _main_menu->insertItem("&Layer", _layer_menu); + + + _tool_menu = new QPopupMenu(); + _id_tool1 = _tool_menu->insertItem("1:", this, SLOT(tool1()), CTRL + Key_1); + _id_tool2 = _tool_menu->insertItem("2:", this, SLOT(tool2()), CTRL + Key_2); + _id_tool3 = _tool_menu->insertItem("3:", this, SLOT(tool3()), CTRL + Key_3); + _id_tool4 = _tool_menu->insertItem("4:", this, SLOT(tool4()), CTRL + Key_4); + _id_tool5 = _tool_menu->insertItem("5:", this, SLOT(tool5()), CTRL + Key_5); + _id_tool6 = _tool_menu->insertItem("6:", this, SLOT(tool6()), CTRL + Key_6); + _id_tool7 = _tool_menu->insertItem("7:", this, SLOT(tool7()), CTRL + Key_7); + _id_tool8 = _tool_menu->insertItem("8:", this, SLOT(tool8()), CTRL + Key_8); + _main_menu->insertItem("&Tool", _tool_menu); + + _main_menu->insertItem("&Zoom", _btnZoom, SLOT(toggle()), Key_Tab); + _main_menu->insertItem("&Maximize", this, SLOT(showFullScreen()), CTRL + Key_M); + _main_menu->insertItem("&Normalize", this, SLOT(showNormal()), CTRL + Key_R); + _main_menu->insertSeparator(); + + _main_menu->insertItem("&Scroll", _scroll_menu); + _main_menu->insertSeparator(); + + _file_menu = new QPopupMenu(); + _file_menu->setCheckable(true); + _file_menu->insertItem("&New", this, SLOT(newPage()), CTRL + Key_N); + _file_menu->insertItem("&Clear", this, SLOT(clear()), CTRL + Key_L); + _file_menu->insertItem("&Import", this, SLOT(import()), CTRL + Key_I); + _file_menu->insertItem("&Load", this, SLOT(load()), CTRL + Key_O); + _file_menu->insertItem("&Save", this, SLOT(save()), CTRL + Key_S); + _file_menu->insertItem("save &As", this, SLOT(saveAs())); + _main_menu->insertItem("&File", _file_menu); + + _export_menu = new QPopupMenu(); + _export_menu->setCheckable(true); + _export_menu->insertItem("PDF", this, SLOT(exportPDF()), CTRL + Key_P); + _export_menu->insertItem("PNG", this, SLOT(exportPNG()), CTRL + Key_E); + _export_menu->insertSeparator(); + _id_saveNPdf = _export_menu->insertItem("save with pdf", this, SLOT(toggleSaveNPdf())); + + _main_menu->insertItem("&Export", _export_menu); + _main_menu->insertSeparator(); + _main_menu->insertItem("&Quit", this, SLOT(quit()), Key_Escape); + _main_menu->insertSeparator(); + _main_menu->insertItem("&About", this, SLOT(about())); + + _menubar = new QPEMenuBar(this); + _menubar->insertItem("&Menu", _main_menu); + + _draw_menu = new QPopupMenu(); + int id_draw; + id_draw = _draw_menu->insertItem(QIconSet(QPixmap((const char**)draw_xpm)), "&Draw"); + _draw_menu->setAccel(Key_D, id_draw); + id_draw = _draw_menu->insertItem(QIconSet(QPixmap((const char**)format_xpm)), "Auto&Format"); + _draw_menu->setAccel(Key_F, id_draw); + id_draw = _draw_menu->insertItem(QIconSet(QPixmap((const char**)curve_xpm)), "Auto&Curve"); + _draw_menu->setAccel(Key_C, id_draw); + id_draw = _draw_menu->insertItem(QIconSet(QPixmap((const char**)smooth_xpm)), "&Smooth"); + _draw_menu->setAccel(Key_S, id_draw); + id_draw = _draw_menu->insertItem(QIconSet(QPixmap((const char**)text_xpm)), "&Text"); + _draw_menu->setAccel(Key_T, id_draw); + id_draw = _draw_menu->insertItem(QIconSet(QPixmap((const char**)eraser_xpm)), "&Eraser"); + _draw_menu->setAccel(Key_E, id_draw); + id_draw = _draw_menu->insertItem(QIconSet(QPixmap((const char**)cpick_xpm)), "Color&Picker"); + _draw_menu->setAccel(Key_P, id_draw); + _id_mode = _menubar->insertItem(QPixmap((const char**)draw_xpm), _draw_menu); + connect(_draw_menu, SIGNAL(activated(int)), this, SLOT(modeMenuChanged(int))); + connect(_canvas, SIGNAL(changeMode(int)), this, SLOT(modeChanged(int))); + + _pen_menu = new QPopupMenu(); + for (int i = 0; i < 8; ++i) { + char buf[5]; + sprintf(buf, "%dpts.", (i + 1)); + int id = _pen_menu->insertItem(QIconSet(makePenPixmap(i + 1)), buf); + _pen_menu->setAccel(Key_1 + i, id); + } + _id_pen = _menubar->insertItem(makePenPixmap(1), _pen_menu); + connect(_pen_menu, SIGNAL(activated(int)), this, SLOT(penSelected(int))); + _menubar->insertItem(_page_tool); + _btnCopy->setEnabled(false); + _btnPaste->setEnabled(true); + _title = ""; +} + +void FrmMain::undo() +{ + _canvas->undo(); + setTitle(); +} + +void FrmMain::addLayer() +{ + _canvas->addLayer(); + setTitle(); +} + +void FrmMain::moveAboveLayer() +{ + _canvas->moveAboveLayer(); + setTitle(); +} + +void FrmMain::moveBelowLayer() +{ + _canvas->moveBelowLayer(); + setTitle(); +} + +//簡易ページモードを切り替える +void FrmMain::toggleTinyPaging() +{ + bool f = _canvas->isTinyPaging(); + _canvas->setTinyPaging(!f); + setTitle(); +} + + +//ペン画像の作成 +QPixmap FrmMain::makePenPixmap(int n) +{ + const char** icons[] = { + (const char**)pt1_xpm, + (const char**)pt2_xpm, + (const char**)pt3_xpm, + (const char**)pt4_xpm, + (const char**)pt5_xpm, + (const char**)pt6_xpm, + (const char**)pt7_xpm, + (const char**)pt8_xpm, + }; + QPixmap pt(icons[n - 1]); + QImage mask = pt.mask()->convertToImage(); + pt = pt.convertToImage().smoothScale(32/*48*/, 16); + QBitmap msk; + msk = mask.smoothScale(32/*48*/, 16); + pt.setMask(msk); + return pt; +} + +//ペンの選択 +void FrmMain::penSelected(int id) +{ + int idx = _pen_menu->indexOf(id); + if (-1 != idx) { + _menubar->changeItem(_id_pen, makePenPixmap(idx + 1)); + _canvas->setPensize(idx + 1); + } +} + +//Save with PDFの切り替え +void FrmMain::toggleSaveNPdf() +{ + if (_export_menu->isItemChecked(_id_saveNPdf)) { + _export_menu->setItemChecked(_id_saveNPdf, false); + } else { + _export_menu->setItemChecked(_id_saveNPdf, true); + } +} + +//ツールボタンの作成 +QToolButton* FrmMain::newToolButton(QWidget* parent, const char** icon1, const char** icon2, const QString& textLabel, const bool isVGA, const bool isToggle, const bool isOn, const int width) +{ + QToolButton* btn = new QToolButton(parent); + if (isVGA) { + btn->setMinimumSize(width, 32); + btn->setMaximumSize(width, 32); + } else { + btn->setMinimumSize(18, 18); + btn->setMaximumSize(18, 18); + } + btn->setOnIconSet(QIconSet(QPixmap(icon1))); + btn->setOffIconSet(QIconSet(QPixmap(icon2))); + btn->setToggleButton(isToggle); + btn->setOn(isOn); + btn->setTextLabel(textLabel); + btn->setAutoRaise(false); + + return btn; +} + +//ツールボタンの作成 +QToolButton* FrmMain::newToolButton(QWidget* parent, const char** icon, const QString& textLabel, const bool isVGA, const bool isToggle, const bool isOn, const int width) +{ + QToolButton* btn = new QToolButton(parent); + if (isVGA) { + btn->setMinimumSize(width, 32); + btn->setMaximumSize(width, 32); + } else { + btn->setMinimumSize(20, 20); + btn->setMaximumSize(20, 20); + } + btn->setPixmap(QPixmap(icon)); + btn->setToggleButton(isToggle); + btn->setOn(isOn); + btn->setTextLabel(textLabel); + btn->setAutoRaise(false); + + return btn; +} + +//スクロールメニューの選択 +void FrmMain::scroll_menu_selected(QAction* act) +{ + if (act->text() == "horz") { + _options.scrollMode = _scrollMode = AS_HORIZONTAL; + } else if (act->text() == "vert") { + _options.scrollMode = _scrollMode = AS_VERTICAL; + } else if (act->text() == "both") { + _options.scrollMode = _scrollMode = AS_BOTH; + } + _options.save(); + if (_btnGuide->isOn()) { + _canvas->setScrollMode(_scrollMode); + } +} + +//ガイドの表示 +void FrmMain::showGuide(bool flg) +{ + _canvas->setGuide(flg); + if (flg) { + _canvas->setScrollMode(_scrollMode); + } else { + _canvas->setScrollMode(AS_NONE); + } + _main_menu->setItemChecked(_id_guide, flg); + if (flg != _options.isAutoScrollEnabled) { + _options.isAutoScrollEnabled = flg; + _options.save(); + } +} + +//スクロールバーの設定 +void FrmMain::scrollbarChange(int x, int y) +{ + //* + if (_useAllQuadrant) { + if (-200 != _vscb->minValue()) { + _vscb->setMinValue(-200); + } + if (-200 != _hscb->minValue()) { + _hscb->setMinValue(-200); + } + } else { + if (0 != _vscb->minValue()) { + _vscb->setMinValue(0); + } + if (0 != _hscb->minValue()) { + _hscb->setMinValue(0); + } + } + //*/ + if (_canvas->isShowGuide()) { + _isTracking = false; + } else { + _isTracking = false; + } + _hscb->setValue(x); + _vscb->setValue(y); +} + +//新規ページ作成 +void FrmMain::newPage() +{ + if (QMessageBox::warning( this, "FreeNote Qt", "OK to create new page ?", "OK", "Cancel", 0, 1, 1 )) { + return; + } + _hscb->setMaxValue(960); + _vscb->setMaxValue(960); + _canvas->clear(); + QDir dir = _file.dir(); + _file.setFile(dir, ""); + _title = ""; + setTitle(); +} + +//ページクリア +void FrmMain::clear() +{ + if (QMessageBox::warning( this, "FreeNote Qt", "OK to clear this page ?", "OK", "Cancel", 0, 1, 1 )) { + return; + } + _hscb->setMaxValue(960); + _vscb->setMaxValue(960); + _canvas->clear(); +} + +//カラーセレクタの表示 +void FrmMain::colorSelectorPopup() +{ + _colorSelector->setColor(_btnColor->color()); + _colorSelector->show(); + if (_colorSelector->exec()) { + changeColor(_colorSelector->color().rgb()); + } +} + +//ファイルオープン +void FrmMain::open(const QString& fname) +{ + _file.setFile(fname); + if (_file.exists()) { + _canvas->load(_file.absFilePath()); + setTitle(&_file); + } else { + _file.setFile(_file.dir(), ""); + } +} + +//ファイル保存 +void FrmMain::save() +{ + _prefile = ""; + if (!_file.exists() || _file.isDir() || _file.extension(false) != "free") { + return saveAs(); + } else { + Config conf("FreeNoteQt"); + conf.setGroup("Format"); + _file.setFile(QDir(conf.readEntry("free", _file.dirPath())), _file.fileName()); + _canvas->save(_file.absFilePath()); + _prefile = _file.absFilePath(); + conf.writeEntry("free", _file.dirPath() + "/"); + setTitle(&_file); + if (_export_menu->isItemChecked(_id_saveNPdf)) { + QFileInfo info = _file; + QString tmpf = _file.absFilePath(); + tmpf = tmpf.left(tmpf.findRev(".free")); + info.setFile(tmpf + ".pdf"); + _canvas->exportPDF(info); + } + } +} + +//別名保存 +void FrmMain::saveAs() +{ + _prefile = ""; + Config conf("FreeNoteQt"); + conf.setGroup("Format"); + if (_file.baseName() == "") { + _file.setFile(QDir(conf.readEntry("free", _file.dirPath())), ""); + } else { + _file.setFile(QDir(conf.readEntry("free", _file.dirPath())), _file.fileName()); + } + + //_frmPalette->close(); + FNFileDialog dlg(this, "*.free", "FreeNote Qt - save", false); + dlg.setCurrentFile(_file); + dlg.showMaximized(); + if (dlg.exec()) { + QFileInfo info = dlg.currentFile(); + if (!info.isDir() && !dlg.isTopDir()) { + if (info.extension(false) != "free") { + QDir dir = info.dir(true); + QString fname = info.fileName(); + info.setFile(dir, fname + ".free"); + } + if (info.exists()) { + if (QMessageBox::warning( this, "FreeNote Qt", "file " + info.fileName() + "\n already exists.\n\n OK to overwrite ?", "OK", "Cancel", 0, 1, 1 )) { + return; + } + } + _file = info; + if (_canvas->save(_file)) { + _prefile = _file.absFilePath(); + conf.writeEntry("free", _file.dirPath() + "/"); + setTitle(&_file); + if (_export_menu->isItemChecked(_id_saveNPdf)) { + QString tmpf = _file.absFilePath(); + tmpf = tmpf.left(tmpf.findRev(".free")); + info.setFile(tmpf + ".pdf"); + _canvas->exportPDF(info); + } + } + } + } +} + +//ファイル読み込み +void FrmMain::load() +{ + Config conf("FreeNoteQt"); + conf.setGroup("Format"); + if (_file.fileName() == "") { + _file.setFile(QDir(conf.readEntry("free", _file.dirPath())), ".free"); + } else { + _file.setFile(QDir(conf.readEntry("free", _file.dirPath())), _file.fileName()); + } + + //_frmPalette->close(); + FNFileDialog dlg(this, "*.free", "FreeNote Qt - load", true); + dlg.setCurrentFile(_file); + dlg.showMaximized(); + if (dlg.exec()) { + QFileInfo info = dlg.currentFile(); + if (info.isFile() && info.exists()) { + _file = info; + if (_canvas->load(_file)) { + _prefile = _file.absFilePath(); + conf.writeEntry("free", _file.dirPath() + "/"); + setTitle(&_file); + } + } + } +} + +//クリップボード読み込み +void FrmMain::import() +{ + Config conf("FreeNoteQt"); + conf.setGroup("Format"); + QFileInfo info = _file; + if (info.fileName() == "") { + info.setFile(QDir(conf.readEntry("import", info.dirPath())), ".free"); + } else { + info.setFile(QDir(conf.readEntry("import", info.dirPath())), info.fileName()); + } + + //_frmPalette->close(); + FNFileDialog dlg(this, "*.free", "FreeNote Qt - import", true); + dlg.setCurrentFile(info); + dlg.showMaximized(); + if (dlg.exec()) { + info = dlg.currentFile(); + if (info.isFile() && info.exists()) { + _canvas->import(info); + conf.writeEntry("import", info.dirPath() + "/"); + } + } +} + +//PNGへの出力 +void FrmMain::exportPNG() +{ + _prepng = ""; + Config conf("FreeNoteQt"); + conf.setGroup("Format"); + QFileInfo info = _file; + if (info.fileName() == "") { + info.setFile(QDir(conf.readEntry("png", info.dirPath())), ""); + } else { + info.setFile(QDir(conf.readEntry("png", info.dirPath())), info.fileName()); + } + + //_frmPalette->close(); + QPixmap save(_canvas->wbuffer()); + FNFileDialog dlg(this, "*.png", "FreeNote Qt - exportPNG", false); + if (info.extension()=="free") { + QString tmpf = info.absFilePath(); + tmpf = tmpf.left(tmpf.findRev(".free")); + info.setFile(tmpf); + } else { + info.setFile(info.dir(), ""); + } + dlg.setCurrentFile(info); + dlg.showMaximized(); + if (dlg.exec() && !dlg.isTopDir()) { + info = dlg.currentFile(); + if (!info.isDir() && !dlg.isTopDir()) { + if (info.extension(false) != "png") { + QDir dir = info.dir(true); + QString fname = info.fileName(); + info.setFile(dir, fname + ".png"); + } + if (info.exists()) { + if (QMessageBox::warning( this, "FreeNote Qt", "file " + info.fileName() + "\n already exists.\n\n OK to overwrite ?", "OK", "Cancel", 0, 1, 1 )) { + return; + } + } + _canvas->exportPNG(info, save); + _prepng = info.absFilePath(); + conf.writeEntry("png", info.dirPath() + "/"); + } + } +} + +//PDFへの出力 +void FrmMain::exportPDF() +{ + _prepdf = ""; + Config conf("FreeNoteQt"); + conf.setGroup("Format"); + + QFileInfo info = _file; + if (info.fileName() == "") { + info.setFile(QDir(conf.readEntry("pdf", info.dirPath())), ""); + } else { + info.setFile(QDir(conf.readEntry("pdf", info.dirPath())), info.fileName()); + } + + //_frmPalette->close(); + FNFileDialog dlg(this, "*.pdf", "FreeNote Qt - exportPDF", false); + if (info.extension()=="free") { + QString tmpf = info.absFilePath(); + tmpf = tmpf.left(tmpf.findRev(".free")); + info.setFile(tmpf); + } else { + info.setFile(info.dir(), ""); + } + + dlg.setCurrentFile(info); + dlg.showMaximized(); + + if (dlg.exec() && !dlg.isTopDir()) { + info = dlg.currentFile(); + if (!info.isDir() && !dlg.isTopDir()) { + if (info.extension(false) != "pdf") { + QDir dir = info.dir(true); + QString fname = info.fileName(); + info.setFile(dir, fname + ".pdf"); + } + if (info.exists()) { + if (QMessageBox::warning( this, "FreeNote Qt", "file " + info.fileName() + "\n already exists.\n\n OK to overwrite ?", "OK", "Cancel", 0, 1, 1 )) { + return; + } + } + _canvas->exportPDF(info); + _prepdf = info.absFilePath(); + conf.writeEntry("pdf", info.dirPath() + "/"); + } + } +} + +//スクロール +void FrmMain::scroll() +{ + if (!_isTracking) { + _isTracking = true; + return; + } + if (_canvas->isDrawing()) { + return; + } + int ox = _hscb->value(); + int oy = _vscb->value(); + _canvas->setOrigin(ox, oy); + int mx = _hscb->maxValue(); + int my = _vscb->maxValue(); + if (ox + 50 > mx) { + _hscb->setMaxValue(mx + 100); + } + if (oy + 50 > my) { + _vscb->setMaxValue(my + 100); + } + this->setFocus(); +} + +//終了 +void FrmMain::quit() +{ + _options.txtBoxRect = _canvas->txtBoxRect(); + _options.save(); + showNormal(); + close(); +} + +//終了前処理 +void FrmMain::closeEvent(QCloseEvent* e) +{ + if (!_options.isQuitQuickly) { + if (QMessageBox::warning( this, "FreeNote Qt", "OK to quit ?", "OK", "Cancel", 0, 1, 1 )) { + return; + } + } + e->accept(); +} + +//リターン押下処理 +void FrmMain::hitRet() +{ + _canvas->erase(); + _canvas->CR(); +} + +//キー押下イベント +void FrmMain::keyPressEvent(QKeyEvent* evt) +{ + if (!_btnZoom->isOn()) { + int key = evt->key(); + switch (key) { + case Qt::Key_Return: + case Qt::Key_Space: + case Qt::Key_F33: + _canvas->erase(); + _canvas->CR(); + break; + case Qt::Key_Left: + if (_canvas->isSelected()) { + _canvas->selectionMoveTo(-1, 0); + } else { + _hscb->subtractPage(); + scroll(); + } + break; + case Qt::Key_Right: + if (_canvas->isSelected()) { + _canvas->selectionMoveTo(1, 0); + } else { + _hscb->addPage(); + scroll(); + } + break; + case Qt::Key_Up: + if (_canvas->isSelected()) { + _canvas->selectionMoveTo(0, -1); + } else { + _vscb->subtractPage(); + scroll(); + } + break; + case Qt::Key_Down: + if (_canvas->isSelected()) { + _canvas->selectionMoveTo(0, 1); + } else { + _vscb->addPage(); + scroll(); + } + break; + default: + break; + } + } +} + +void FrmMain::showLayer() +{ + FNLayerDlg dlg(_canvas); + _canvas->resetSelection(); + dlg.show(); + dlg.exec(); + setTitle(); +} + +/* + * Destroys the object and frees any allocated resources + */ +FrmMain::~FrmMain() +{ + // no need to delete child widgets, Qt does it all for us + delete _colorSelector; +} + +//about boxの表示 +void FrmMain::about() +{ + char buf[1024]; + sprintf(buf, "FreeNote Qt\nversion %s\nCopyright(c) 2003-2005,jojo3", VERSION); + QMessageBox::about(this, "FreeNote Qt", buf); +} + +void FrmMain::setTitle(QFileInfo* file) { + if (NULL != file) { + _title = file->fileName(); + } + QString t = "FreeNote Qt["; + if (_canvas->isTinyPaging()) { + _layer_menu->setItemChecked(_id_tinyPaging, true); + t += "P:"; + } else { + _layer_menu->setItemChecked(_id_tinyPaging, false); + t += "L:"; + } + t += _canvas->currentLayerName(); + t += "] "; + setCaption(t + _title); +} diff --git a/packages/freenote/files/FreeNote/apps/.mtn2git_empty b/packages/freenote/files/FreeNote/apps/.mtn2git_empty new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/packages/freenote/files/FreeNote/apps/.mtn2git_empty diff --git a/packages/freenote/files/FreeNote/apps/Applications/.mtn2git_empty b/packages/freenote/files/FreeNote/apps/Applications/.mtn2git_empty new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/packages/freenote/files/FreeNote/apps/Applications/.mtn2git_empty diff --git a/packages/freenote/files/FreeNote/apps/Applications/FreeNote.desktop b/packages/freenote/files/FreeNote/apps/Applications/FreeNote.desktop new file mode 100644 index 0000000000..46e24cd971 --- /dev/null +++ b/packages/freenote/files/FreeNote/apps/Applications/FreeNote.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Comment= +Exec=FreeNote +Icon=freenote +Type=Application +Name=FreeNoteQt +Display=640x480/144dpi,480x640/144dpi +MimeType=application/freenote +MimeTypeIcons=freenote +CanFastload=1 diff --git a/packages/freenote/files/FreeNote/apps/Settings/.mtn2git_empty b/packages/freenote/files/FreeNote/apps/Settings/.mtn2git_empty new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/packages/freenote/files/FreeNote/apps/Settings/.mtn2git_empty diff --git a/packages/freenote/files/FreeNote/apps/Settings/FreeNoteSetup.desktop b/packages/freenote/files/FreeNote/apps/Settings/FreeNoteSetup.desktop new file mode 100644 index 0000000000..e621c90318 --- /dev/null +++ b/packages/freenote/files/FreeNote/apps/Settings/FreeNoteSetup.desktop @@ -0,0 +1,9 @@ +[Desktop Entry]
+Comment=
+Exec=FreeNoteSetup
+Icon=fnsetup
+Type=Application
+Name=FNSetup
+Name[ja]=FN險ュ螳
+Display=640x480/144dpi,480x640/144dpi
+CanFastload=0
diff --git a/packages/freenote/files/FreeNote/pics/.mtn2git_empty b/packages/freenote/files/FreeNote/pics/.mtn2git_empty new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/packages/freenote/files/FreeNote/pics/.mtn2git_empty diff --git a/packages/freenote/files/FreeNote/pics/fnsetup.png b/packages/freenote/files/FreeNote/pics/fnsetup.png Binary files differnew file mode 100644 index 0000000000..39028e3511 --- /dev/null +++ b/packages/freenote/files/FreeNote/pics/fnsetup.png diff --git a/packages/freenote/files/FreeNote/pics/freenote.png b/packages/freenote/files/FreeNote/pics/freenote.png Binary files differnew file mode 100644 index 0000000000..ebde7765a1 --- /dev/null +++ b/packages/freenote/files/FreeNote/pics/freenote.png diff --git a/packages/freenote/freenote_1.12.0.bb b/packages/freenote/freenote_1.12.0.bb new file mode 100644 index 0000000000..72610c306c --- /dev/null +++ b/packages/freenote/freenote_1.12.0.bb @@ -0,0 +1,33 @@ +DESCRIPTION = "Auto-Correction Paint Program for Opie/Qtopia" +SECTION = "opie/applications" +PRIORITY = "optional" +LICENSE = "GPL" +APPNAME = "FreeNote" +APPTYPE = "binary" +APPDESKTOP = "apps/Applications" + +SRC_URI = "http://www.urban.ne.jp/home/kanemori/zaurus/FreeNote_1.12.0.tar.gz \ + file://FreeNote" +S = "${WORKDIR}/FreeNote" + +inherit opie + +do_configure_prepend() { + mv -f FreeNote subdir1 + mv -f FreeNoteSetup subdir2 + echo -e "TEMPLATE=subdirs\nSUBDIRS=subdir1 subdir2\n" >> freenote.pro + pushd ${S}/subdir1 && rm *.pro && qmake -project && echo "TARGET=FreeNote" >> subdir1.pro && popd + pushd ${S}/subdir2 && rm *.pro && qmake -project && echo "TARGET=FreeNoteSetup" >> subdir2.pro && popd +} + +do_install() { + install -d ${D}${palmtopdir}/bin/ + install -m 0755 FreeNoteSetup ${D}${palmtopdir}/bin/ + install -d ${D}${palmtopdir}/pics/ + install -m 0644 pics/freenote.png ${D}${palmtopdir}/pics + install -m 0644 pics/fnsetup.png ${D}${palmtopdir}/pics + install -d ${D}${palmtopdir}/apps/Applications + install -m 0644 apps/Applications/FreeNote.desktop ${D}${palmtopdir}/apps/Applications + install -d ${D}${palmtopdir}/apps/Settings + install -m 0644 apps/Settings/FreeNoteSetup.desktop ${D}${palmtopdir}/apps/Settings +} diff --git a/packages/nonworking/freenote/freenote-1.6.1/compile.patch b/packages/nonworking/freenote/freenote-1.6.1/compile.patch deleted file mode 100644 index de3e93ac9c..0000000000 --- a/packages/nonworking/freenote/freenote-1.6.1/compile.patch +++ /dev/null @@ -1,3285 +0,0 @@ - -# -# Patch managed by http://www.mn-logistik.de/unsupported/pxa250/patcher -# - ---- FreeNote_1.6.1_arm/FmtEngine.cpp~compile 2003-12-23 15:53:46.000000000 +0100 -+++ FreeNote_1.6.1_arm/FmtEngine.cpp 2004-02-01 18:42:32.000000000 +0100 -@@ -1,409 +1,410 @@ --/* FreeNote for Sharp SLA300, B500, C7x0 Linux PDA -- Copyright (C) 2003 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 --*/ --/* --2003/12/16-19 FreeNote ver 1.5.5pre --・曲線描画ロジックの改良 -- --2003/12/14 FreeNote 1.5.4pre --・曲線描画ロジックの改良 -- --2003/11/30-2003/12/04 FreeNote 1.5.3pre --・ベジェ関数のスペルミスを修正 -- --2003/11/16 FreeNote 1.5.2pre --・円描画のロジックを追加 -- --2003/11/13 FreeNote 1.5.1pre --・スムージング追加 --2003/11/10-12 --・曲線整形モード追加 --2003/11/09 追加 --*/ --#include "fmtengine.h" --#include <qpointarray.h> --#include <qpe/qmath.h> --#include <math.h> --int SNAP_SIZE = 32; --int PHASE1_ANGLE = 30; --int PHASE2_ANGLE = 30; --double Surface(const QPoint& p1, const QPoint& p2) --{ -- return 0.5 * abs(p1.x() * p2.y() - p1.y() * p2.x()); --} -- --bool IsLinear(const QPoint& p1, const QPoint& p2, const QPoint& p3) --{ -- double s1 = Surface(p1, p2); -- double s2 = Surface(p2, p3); -- double s3 = Surface(p1, p3); -- if (s1 + s2 == s3) { -- return true; -- } else { -- return false; -- } --} -- --const double Angle(const QPoint& p1, const QPoint& p2) --{ -- return qATan2((double)(p2.y() - p1.y()), (double)(p2.x() - p1.x())); --} -- --const double DiffAngle(const QPoint& p1, const QPoint& p2, const QPoint& p3) --{ -- return fabs(Angle(p1, p2) - Angle(p2, p3)); --} -- --const double ToDegree(double t) --{ -- return t * 180 / M_PI; --} -- --const double ToRadian(double d) --{ -- return d * M_PI / 180; --} -- --const double Distance(const QPoint& p1, const QPoint& p2) --{ -- return hypot(p1.x() - p2.x(), p1.y() - p2.y()); --} -- --const QPoint SnapPoint(const QPoint& p) --{ -- int x = ((int)(p.x() + SNAP_SIZE / 2) / SNAP_SIZE) * SNAP_SIZE; -- int y = ((int)(p.y() + SNAP_SIZE / 2) / SNAP_SIZE) * SNAP_SIZE; -- return QPoint(x, y); --} -- --const QPoint ArrangePoint(const QPoint& p1, const QPoint& p2) --{ -- int x = p2.x(); -- int y = p2.y(); -- if (p1.x() - SNAP_SIZE / 2 <= x && p1.x() + SNAP_SIZE / 2 >= x) { -- x = p1.x(); -- } -- if (p1.y() - SNAP_SIZE / 2 <= y && p1.y() + SNAP_SIZE / 2 >= y) { -- y = p1.y(); -- } -- return QPoint(x, y); --} -- --FNPointList ReducePoints(FNPointList& p) --{ -- if (3 >= p.count()) { -- return p; -- } -- FNPointList rt; -- rt.append(p.first()); -- QPoint* p1 = p.first(); -- QPoint* p2 = p.at(1); -- QPoint* p3 = NULL; -- for (uint i = 2; i < p.count(); ++i) { -- p3 = p.at(i); -- if (false == IsLinear(*p1, *p2, *p3)) { -- rt.append(p2); -- p1 = p2; -- } -- p2 = p3; -- } -- rt.append(p3); -- return rt; --} -- --FNPointList ExtractAngle2(FNPointList& p, const int deg) --{ -- FNPointList rt; -- rt.append(p.first()); -- QPoint* st = p.first(); -- QPoint* mp = p.at(1); -- QPoint* ed = p.last(); -- for (uint i = 2; i < p.count(); ++i) { -- ed = p.at(i); -- if (ToRadian(deg) <= DiffAngle(*st, *mp, *ed)) { -- st = mp; -- rt.append(mp); -- } -- mp = ed; -- } -- rt.append(ed); -- return rt; --} -- --FNPointList ExtractAngle(FNPointList& p, const int deg) --{ -- FNPointList rt; -- rt.append(p.first()); -- QPoint* st = p.first(); -- QPoint* mp = p.at(1); -- QPoint* ed = p.last(); -- for (uint i = 2; i < p.count(); ++i) { -- ed = p.at(i); -- if (ToRadian(deg) <= DiffAngle(*st, *mp, *ed)) { -- st = mp; -- rt.append(mp); -- } -- mp = ed; -- } -- if (SNAP_SIZE / 2 > Distance(*p.first(), *p.last()) && 3 < p.count()) { -- rt.append(p.first()); -- } else { -- rt.append(ed); -- } -- return rt; --} -- --FNPointList SumupPoints(FNPointList& p) --{ -- if (3 >= p.count()) { -- return p; -- } -- FNPointList rt; -- rt.append(p.first()); -- QPoint* p1 = p.first(); -- QPoint* p2 = NULL; -- double pred = 0; -- for (uint i = 1; i < p.count() - 1; ++i) { -- p2 = p.at(i); -- double d = Distance(*p1, *p2); -- if (SNAP_SIZE / 2 < d || pred > d) { -- rt.append(p2); -- p1 = p2; -- d = 0; -- } -- pred = d; -- } -- rt.append(p.last()); -- return rt; --} -- --FNPointList SnapPoints(FNPointList& p) --{ -- FNPointList rt; -- for (uint i = 0; i < p.count(); ++i) { -- QPoint tp = SnapPoint(*p.at(i)); -- p.at(i)->setX(tp.x()); -- p.at(i)->setY(tp.y()); -- rt.append(p.at(i)); -- } -- return rt; --} -- --FNPointList ArrangePoints(FNPointList& p) --{ -- if (3 >= p.count() && 2 != p.count()) { -- return p; -- } -- FNPointList rt; -- rt.append(p.first()); -- QPoint* p1 = p.first(); -- QPoint* p2 = NULL; -- for (uint i = 1; i < p.count(); ++i) { -- p2 = p.at(i); -- QPoint tp = ArrangePoint(*p1, *p2); -- p2->setX(tp.x()); -- p2->setY(tp.y()); -- rt.append(p2); -- p1 = p2; -- } -- if (*p.first() == *p.last()) { -- QPoint tp = ArrangePoint(*p1, *p.first()); -- rt.first()->setX(tp.x()); -- rt.first()->setY(tp.y()); -- } -- return rt; --} -- --FNPointList TuningPoints(FNPointList& p) --{ -- FNPointList rt; -- if (3 >= p.count()) { -- for (uint i = 0; i < p.count(); ++i) { -- rt.append(new QPoint(*p.at(i))); -- } -- return rt; -- } -- rt.append(new QPoint(*p.at(0))); -- for (uint i = 1; i < p.count() - 1; ++i) { -- QPoint* p1 = p.at(i); -- QPoint* p2 = p.at(i + 1); -- rt.append(new QPoint(*p1)); -- if (i < p.count() - 2) { -- rt.append(new QPoint((p1->x() + p2->x())/2, (p1->y() + p2->y())/2)); -- } -- } -- rt.append(new QPoint(*p.at(p.count()-1))); -- return rt; --} -- --FNPointList ToBezier(FNPointList& p) { -- FNPointList rt; -- rt.append(new QPoint(*p.at(0))); -- for (uint i = 0; i < p.count() - 2; i += 2) { -- int x1 = p.at(i)->x(); -- int xa = p.at(i + 1)->x(); -- int x4 = p.at(i + 2)->x(); -- -- int x2 = (x1 + xa) / 2; -- int x3 = (xa + x4) / 2; -- -- int y1 = p.at(i)->y(); -- int ya = p.at(i + 1)->y(); -- int y4 = p.at(i + 2)->y(); -- -- int y2 = (y1 + ya) / 2; -- int y3 = (ya + y4) / 2; -- -- rt.append(new QPoint(x2 ,y2)); -- rt.append(new QPoint(x3 ,y3)); -- rt.append(new QPoint(x4 ,y4)); -- } -- return rt; --} -- --FNPointList ToCurves(FNPointList& p) { -- if (3 <= p.count()) { -- //ベジェによる補完 -- return ToBezier(p); -- } else { -- FNPointList rt; -- for (uint i = 0; i < p.count(); ++i) { -- rt.append(new QPoint(*p.at(i))); -- } -- return rt; -- } --} -- --FNPointList AutoFormat(FNPointList& p) --{ -- FNPointList tp = ExtractAngle(p, PHASE1_ANGLE); -- uint n; -- do { -- n = tp.count(); -- tp = SumupPoints(tp); -- tp = ExtractAngle(tp, PHASE1_ANGLE); -- tp = ArrangePoints(tp); -- } while (n > tp.count()); -- tp = SnapPoints(tp); -- tp = ReducePoints(tp); -- FNPointList rt; -- if (2 == tp.count()) { -- if (*tp.first() == *tp.last()) { -- return rt; -- } -- } -- for (uint i = 0; i < tp.count(); ++i) { -- rt.append(new QPoint(*tp.at(i))); -- } -- return rt; --} -- --FNPointList ToEllipse(int x, int y, int w, int h) { -- FNPointList rt; -- QPointArray pa; -- pa.makeEllipse(x, y, w, h); -- for (uint i = 0; i < pa.count(); ++i) { -- rt.append(new QPoint(pa.point(i))); -- } -- return rt; --} -- --FNPointList AutoCurve(FNPointList& p) --{ -- FNPointList tp2; -- tp2.setAutoDelete(true); -- FNPointList tp4; -- tp4.setAutoDelete(true); -- QPoint sp = SnapPoint(*p.at(0)); -- QPoint ep = SnapPoint(*p.at(p.count()-1)); -- if (sp == ep) { -- //楕円 -- int sx = p.at(0)->x(); -- int sy = p.at(0)->y(); -- int ex = sx; -- int ey = sy; -- for (uint i = 1; i < p.count(); ++i) { -- QPoint tp = *p.at(i); -- if (sx > tp.x()) { -- sx = tp.x(); -- } else if (ex < tp.x()) { -- ex = tp.x(); -- } -- if (sy > tp.y()) { -- sy = tp.y(); -- } else if (ey < tp.y()) { -- ey = tp.y(); -- } -- } -- sp = SnapPoint(QPoint(sx, sy)); -- ep = SnapPoint(QPoint(ex, ey)); -- tp2.append(new QPoint(sp.x(), sp.y())); -- tp2.append(new QPoint(ep.x(), ep.y())); -- } else { -- FNPointList tp = ExtractAngle2(p, PHASE2_ANGLE); -- uint n; -- do { -- n = tp.count(); -- tp = SumupPoints(tp); -- tp = ExtractAngle2(tp, PHASE2_ANGLE); -- tp = SnapPoints(tp); -- } while (n > tp.count()); -- tp = SumupPoints(tp); -- tp = ReducePoints(tp); -- tp4 = TuningPoints(tp); -- tp2 = ToCurves(tp4); -- } -- FNPointList rt; -- if (2 == tp2.count()) { -- if (*tp2.first() == *tp2.last()) { -- return rt; -- } -- } -- for (uint i = 0; i < tp2.count(); ++i) { -- rt.append(new QPoint(*tp2.at(i))); -- } -- return rt; --} -- --FNPointList Smoothing(FNPointList& p) --{ -- int tsnap = SNAP_SIZE; -- SNAP_SIZE=8; -- FNPointList tp = ExtractAngle2(p, PHASE2_ANGLE); -- tp = SumupPoints(tp); -- tp = ReducePoints(tp); -- FNPointList tp4 = TuningPoints(tp); -- tp4.setAutoDelete(true); -- FNPointList tp2 = ToCurves(tp4); -- tp2.setAutoDelete(true); -- FNPointList rt; -- for (uint i = 0; i < tp2.count(); ++i) { -- rt.append(new QPoint(*tp2.at(i))); -- } -- SNAP_SIZE = tsnap; -- return rt; --} -- --FNPointList Reduce(FNPointList& p) --{ -- FNPointList tp = ReducePoints(p); -- FNPointList rt; -- for (uint i = 0; i < tp.count(); ++i) { -- rt.append(new QPoint(*tp.at(i))); -- } -- return rt; --} -+/* FreeNote for Sharp SLA300, B500, C7x0 Linux PDA -+ Copyright (C) 2003 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 -+*/ -+/* -+2003/12/16-19 FreeNote ver 1.5.5pre -+・曲線描画ロジックの改良 -+ -+2003/12/14 FreeNote 1.5.4pre -+・曲線描画ロジックの改良 -+ -+2003/11/30-2003/12/04 FreeNote 1.5.3pre -+・ベジェ関数のスペルミスを修正 -+ -+2003/11/16 FreeNote 1.5.2pre -+・円描画のロジックを追加 -+ -+2003/11/13 FreeNote 1.5.1pre -+・スムージング追加 -+2003/11/10-12 -+・曲線整形モード追加 -+2003/11/09 追加 -+*/ -+#include "fmtengine.h" -+#include <qpointarray.h> -+#include <qpe/qmath.h> -+#include <math.h> -+#include <stdlib.h> // abs -+int SNAP_SIZE = 32; -+int PHASE1_ANGLE = 30; -+int PHASE2_ANGLE = 30; -+double Surface(const QPoint& p1, const QPoint& p2) -+{ -+ return 0.5 * abs(p1.x() * p2.y() - p1.y() * p2.x()); -+} -+ -+bool IsLinear(const QPoint& p1, const QPoint& p2, const QPoint& p3) -+{ -+ double s1 = Surface(p1, p2); -+ double s2 = Surface(p2, p3); -+ double s3 = Surface(p1, p3); -+ if (s1 + s2 == s3) { -+ return true; -+ } else { -+ return false; -+ } -+} -+ -+const double Angle(const QPoint& p1, const QPoint& p2) -+{ -+ return qATan2((double)(p2.y() - p1.y()), (double)(p2.x() - p1.x())); -+} -+ -+const double DiffAngle(const QPoint& p1, const QPoint& p2, const QPoint& p3) -+{ -+ return fabs(Angle(p1, p2) - Angle(p2, p3)); -+} -+ -+const double ToDegree(double t) -+{ -+ return t * 180 / M_PI; -+} -+ -+const double ToRadian(double d) -+{ -+ return d * M_PI / 180; -+} -+ -+const double Distance(const QPoint& p1, const QPoint& p2) -+{ -+ return hypot(p1.x() - p2.x(), p1.y() - p2.y()); -+} -+ -+const QPoint SnapPoint(const QPoint& p) -+{ -+ int x = ((int)(p.x() + SNAP_SIZE / 2) / SNAP_SIZE) * SNAP_SIZE; -+ int y = ((int)(p.y() + SNAP_SIZE / 2) / SNAP_SIZE) * SNAP_SIZE; -+ return QPoint(x, y); -+} -+ -+const QPoint ArrangePoint(const QPoint& p1, const QPoint& p2) -+{ -+ int x = p2.x(); -+ int y = p2.y(); -+ if (p1.x() - SNAP_SIZE / 2 <= x && p1.x() + SNAP_SIZE / 2 >= x) { -+ x = p1.x(); -+ } -+ if (p1.y() - SNAP_SIZE / 2 <= y && p1.y() + SNAP_SIZE / 2 >= y) { -+ y = p1.y(); -+ } -+ return QPoint(x, y); -+} -+ -+FNPointList ReducePoints(FNPointList& p) -+{ -+ if (3 >= p.count()) { -+ return p; -+ } -+ FNPointList rt; -+ rt.append(p.first()); -+ QPoint* p1 = p.first(); -+ QPoint* p2 = p.at(1); -+ QPoint* p3 = NULL; -+ for (uint i = 2; i < p.count(); ++i) { -+ p3 = p.at(i); -+ if (false == IsLinear(*p1, *p2, *p3)) { -+ rt.append(p2); -+ p1 = p2; -+ } -+ p2 = p3; -+ } -+ rt.append(p3); -+ return rt; -+} -+ -+FNPointList ExtractAngle2(FNPointList& p, const int deg) -+{ -+ FNPointList rt; -+ rt.append(p.first()); -+ QPoint* st = p.first(); -+ QPoint* mp = p.at(1); -+ QPoint* ed = p.last(); -+ for (uint i = 2; i < p.count(); ++i) { -+ ed = p.at(i); -+ if (ToRadian(deg) <= DiffAngle(*st, *mp, *ed)) { -+ st = mp; -+ rt.append(mp); -+ } -+ mp = ed; -+ } -+ rt.append(ed); -+ return rt; -+} -+ -+FNPointList ExtractAngle(FNPointList& p, const int deg) -+{ -+ FNPointList rt; -+ rt.append(p.first()); -+ QPoint* st = p.first(); -+ QPoint* mp = p.at(1); -+ QPoint* ed = p.last(); -+ for (uint i = 2; i < p.count(); ++i) { -+ ed = p.at(i); -+ if (ToRadian(deg) <= DiffAngle(*st, *mp, *ed)) { -+ st = mp; -+ rt.append(mp); -+ } -+ mp = ed; -+ } -+ if (SNAP_SIZE / 2 > Distance(*p.first(), *p.last()) && 3 < p.count()) { -+ rt.append(p.first()); -+ } else { -+ rt.append(ed); -+ } -+ return rt; -+} -+ -+FNPointList SumupPoints(FNPointList& p) -+{ -+ if (3 >= p.count()) { -+ return p; -+ } -+ FNPointList rt; -+ rt.append(p.first()); -+ QPoint* p1 = p.first(); -+ QPoint* p2 = NULL; -+ double pred = 0; -+ for (uint i = 1; i < p.count() - 1; ++i) { -+ p2 = p.at(i); -+ double d = Distance(*p1, *p2); -+ if (SNAP_SIZE / 2 < d || pred > d) { -+ rt.append(p2); -+ p1 = p2; -+ d = 0; -+ } -+ pred = d; -+ } -+ rt.append(p.last()); -+ return rt; -+} -+ -+FNPointList SnapPoints(FNPointList& p) -+{ -+ FNPointList rt; -+ for (uint i = 0; i < p.count(); ++i) { -+ QPoint tp = SnapPoint(*p.at(i)); -+ p.at(i)->setX(tp.x()); -+ p.at(i)->setY(tp.y()); -+ rt.append(p.at(i)); -+ } -+ return rt; -+} -+ -+FNPointList ArrangePoints(FNPointList& p) -+{ -+ if (3 >= p.count() && 2 != p.count()) { -+ return p; -+ } -+ FNPointList rt; -+ rt.append(p.first()); -+ QPoint* p1 = p.first(); -+ QPoint* p2 = NULL; -+ for (uint i = 1; i < p.count(); ++i) { -+ p2 = p.at(i); -+ QPoint tp = ArrangePoint(*p1, *p2); -+ p2->setX(tp.x()); -+ p2->setY(tp.y()); -+ rt.append(p2); -+ p1 = p2; -+ } -+ if (*p.first() == *p.last()) { -+ QPoint tp = ArrangePoint(*p1, *p.first()); -+ rt.first()->setX(tp.x()); -+ rt.first()->setY(tp.y()); -+ } -+ return rt; -+} -+ -+FNPointList TuningPoints(FNPointList& p) -+{ -+ FNPointList rt; -+ if (3 >= p.count()) { -+ for (uint i = 0; i < p.count(); ++i) { -+ rt.append(new QPoint(*p.at(i))); -+ } -+ return rt; -+ } -+ rt.append(new QPoint(*p.at(0))); -+ for (uint i = 1; i < p.count() - 1; ++i) { -+ QPoint* p1 = p.at(i); -+ QPoint* p2 = p.at(i + 1); -+ rt.append(new QPoint(*p1)); -+ if (i < p.count() - 2) { -+ rt.append(new QPoint((p1->x() + p2->x())/2, (p1->y() + p2->y())/2)); -+ } -+ } -+ rt.append(new QPoint(*p.at(p.count()-1))); -+ return rt; -+} -+ -+FNPointList ToBezier(FNPointList& p) { -+ FNPointList rt; -+ rt.append(new QPoint(*p.at(0))); -+ for (uint i = 0; i < p.count() - 2; i += 2) { -+ int x1 = p.at(i)->x(); -+ int xa = p.at(i + 1)->x(); -+ int x4 = p.at(i + 2)->x(); -+ -+ int x2 = (x1 + xa) / 2; -+ int x3 = (xa + x4) / 2; -+ -+ int y1 = p.at(i)->y(); -+ int ya = p.at(i + 1)->y(); -+ int y4 = p.at(i + 2)->y(); -+ -+ int y2 = (y1 + ya) / 2; -+ int y3 = (ya + y4) / 2; -+ -+ rt.append(new QPoint(x2 ,y2)); -+ rt.append(new QPoint(x3 ,y3)); -+ rt.append(new QPoint(x4 ,y4)); -+ } -+ return rt; -+} -+ -+FNPointList ToCurves(FNPointList& p) { -+ if (3 <= p.count()) { -+ //ベジェによる補完 -+ return ToBezier(p); -+ } else { -+ FNPointList rt; -+ for (uint i = 0; i < p.count(); ++i) { -+ rt.append(new QPoint(*p.at(i))); -+ } -+ return rt; -+ } -+} -+ -+FNPointList AutoFormat(FNPointList& p) -+{ -+ FNPointList tp = ExtractAngle(p, PHASE1_ANGLE); -+ uint n; -+ do { -+ n = tp.count(); -+ tp = SumupPoints(tp); -+ tp = ExtractAngle(tp, PHASE1_ANGLE); -+ tp = ArrangePoints(tp); -+ } while (n > tp.count()); -+ tp = SnapPoints(tp); -+ tp = ReducePoints(tp); -+ FNPointList rt; -+ if (2 == tp.count()) { -+ if (*tp.first() == *tp.last()) { -+ return rt; -+ } -+ } -+ for (uint i = 0; i < tp.count(); ++i) { -+ rt.append(new QPoint(*tp.at(i))); -+ } -+ return rt; -+} -+ -+FNPointList ToEllipse(int x, int y, int w, int h) { -+ FNPointList rt; -+ QPointArray pa; -+ pa.makeEllipse(x, y, w, h); -+ for (uint i = 0; i < pa.count(); ++i) { -+ rt.append(new QPoint(pa.point(i))); -+ } -+ return rt; -+} -+ -+FNPointList AutoCurve(FNPointList& p) -+{ -+ FNPointList tp2; -+ tp2.setAutoDelete(true); -+ FNPointList tp4; -+ tp4.setAutoDelete(true); -+ QPoint sp = SnapPoint(*p.at(0)); -+ QPoint ep = SnapPoint(*p.at(p.count()-1)); -+ if (sp == ep) { -+ //楕円 -+ int sx = p.at(0)->x(); -+ int sy = p.at(0)->y(); -+ int ex = sx; -+ int ey = sy; -+ for (uint i = 1; i < p.count(); ++i) { -+ QPoint tp = *p.at(i); -+ if (sx > tp.x()) { -+ sx = tp.x(); -+ } else if (ex < tp.x()) { -+ ex = tp.x(); -+ } -+ if (sy > tp.y()) { -+ sy = tp.y(); -+ } else if (ey < tp.y()) { -+ ey = tp.y(); -+ } -+ } -+ sp = SnapPoint(QPoint(sx, sy)); -+ ep = SnapPoint(QPoint(ex, ey)); -+ tp2.append(new QPoint(sp.x(), sp.y())); -+ tp2.append(new QPoint(ep.x(), ep.y())); -+ } else { -+ FNPointList tp = ExtractAngle2(p, PHASE2_ANGLE); -+ uint n; -+ do { -+ n = tp.count(); -+ tp = SumupPoints(tp); -+ tp = ExtractAngle2(tp, PHASE2_ANGLE); -+ tp = SnapPoints(tp); -+ } while (n > tp.count()); -+ tp = SumupPoints(tp); -+ tp = ReducePoints(tp); -+ tp4 = TuningPoints(tp); -+ tp2 = ToCurves(tp4); -+ } -+ FNPointList rt; -+ if (2 == tp2.count()) { -+ if (*tp2.first() == *tp2.last()) { -+ return rt; -+ } -+ } -+ for (uint i = 0; i < tp2.count(); ++i) { -+ rt.append(new QPoint(*tp2.at(i))); -+ } -+ return rt; -+} -+ -+FNPointList Smoothing(FNPointList& p) -+{ -+ int tsnap = SNAP_SIZE; -+ SNAP_SIZE=8; -+ FNPointList tp = ExtractAngle2(p, PHASE2_ANGLE); -+ tp = SumupPoints(tp); -+ tp = ReducePoints(tp); -+ FNPointList tp4 = TuningPoints(tp); -+ tp4.setAutoDelete(true); -+ FNPointList tp2 = ToCurves(tp4); -+ tp2.setAutoDelete(true); -+ FNPointList rt; -+ for (uint i = 0; i < tp2.count(); ++i) { -+ rt.append(new QPoint(*tp2.at(i))); -+ } -+ SNAP_SIZE = tsnap; -+ return rt; -+} -+ -+FNPointList Reduce(FNPointList& p) -+{ -+ FNPointList tp = ReducePoints(p); -+ FNPointList rt; -+ for (uint i = 0; i < tp.count(); ++i) { -+ rt.append(new QPoint(*tp.at(i))); -+ } -+ return rt; -+} ---- FreeNote_1.6.1_arm/FNCanvas.cpp~compile 2003-12-24 15:20:16.000000000 +0100 -+++ FreeNote_1.6.1_arm/FNCanvas.cpp 2004-02-01 18:43:35.000000000 +0100 -@@ -1,1227 +1,1228 @@ --/* FreeNote for Sharp SLA300, B500, C7x0 Linux PDA -- Copyright (C) 2003 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 --*/ --/* --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 <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 "fnmessagebox.h" --#include "fmtengine.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(QWidget* parent = 0, const char* name = 0, WFlags f = 0) -- :QWidget(parent, name, f), -- _pen(black, 1, SolidLine, RoundCap, RoundJoin), -- _asMode(AS_NONE), -- _drawMode(MODE_DRAW), -- _disp_offset(0), -- _eraser_l(50), -- _eraser_s(10), -- _h_step(100), -- _v_step(100), -- _margin(5), -- _scrollTiming(800), -- _viewMode(false), -- _isWaiting(false), -- _isDragging(false), -- _isHeadingEnables(false), -- _isShowGuide(false), -- _isUseAllQuadrant(false), -- _scale_x(1.0), -- _scale_y(1.0) --{ -- _tracks.setAutoDelete(true); -- this->setBackgroundMode(NoBackground); -- _timer = new QTimer(this); -- connect(_timer, SIGNAL(timeout()), this, SLOT(autoScroll())); --} -- --FNCanvas::~FNCanvas() --{ -- _timer->stop(); -- delete _timer; -- -- _tracks.clear(); -- clearList(_draws); --} -- --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::setScrollMode(int as) --{ -- _asMode = as; -- redraw(); --} -- --void FNCanvas::autoScroll() --{ -- if (AS_NONE == _asMode) { -- if (MODE_FORMAT == _drawMode || MODE_CURVE == _drawMode || MODE_SMOOTH == _drawMode) { -- setOrigin(_origin.x(), _origin.y()); -- } -- 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); -- _isHeadingEnables = tmp; --} -- --void FNCanvas::mousePressEvent(QMouseEvent* evt) --{ -- setFocus(); -- _timer->stop(); -- _tracks.clear(); -- if (_viewMode) { -- _isWaiting = true; -- _viewMode = false; -- setOrigin((int)((evt->x()) / _scale_x) - width() / 2, (int)((evt->y()) / _scale_y) - height() / 2); -- redraw(); -- emit resetViewMode(); -- } else if (MODE_ERASE != _drawMode) { -- _last = evt->pos(); -- _tracks.append(new QPoint(_last)); -- } else { -- redraw(); -- _last = evt->pos(); -- _tracks.append(new QPoint(_last)); -- -- QPainter pbuf; -- QPainter pwin; -- pbuf.begin(&_buffer); -- pwin.begin(this); -- -- int w = _eraser_s; -- if (PENWIDTH_MAX / 2 < _pen.width()) { -- w = _eraser_l; -- } -- pbuf.setRasterOp(XorROP); -- pbuf.setPen(QPen(white, 1)); -- pbuf.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w); -- -- pwin.setRasterOp(XorROP); -- pwin.setPen(QPen(white, 1)); -- pwin.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w); -- -- pbuf.end(); -- pwin.end(); -- } -- _isDragging = true; --} -- --void FNCanvas::mouseMoveEvent(QMouseEvent* evt) --{ -- if (_isWaiting) { -- return; -- } -- if (MODE_ERASE != _drawMode) { -- QPainter pwin; -- QPainter pbuf; -- -- pwin.begin(this); -- pbuf.begin(&_buffer); -- -- pwin.setPen(_pen); -- pbuf.setPen(_pen); -- -- pwin.drawLine(_last, evt->pos()); -- pbuf.drawLine(_last, evt->pos()); -- -- pwin.end(); -- pbuf.end(); -- _last = evt->pos(); -- _tracks.append(new QPoint(_last)); -- } else { -- //redraw(); -- if (_last.x() == -1) { -- return; -- } -- QPainter pbuf; -- QPainter pwin; -- -- pbuf.begin(&_buffer); -- pwin.begin(this); -- -- int w = _eraser_s; -- if (PENWIDTH_MAX / 2 < _pen.width()) { -- w = _eraser_l; -- } -- pbuf.setRasterOp(XorROP); -- pwin.setRasterOp(XorROP); -- pbuf.setPen(QPen(white, 1)); -- pwin.setPen(QPen(white, 1)); -- pbuf.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w); -- pwin.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w); -- -- _tracks.append(new QPoint(evt->pos())); -- _last = evt->pos(); -- -- pbuf.setRasterOp(CopyROP); -- pwin.setRasterOp(CopyROP); -- QRect r = QRect(0, 0, width(), height()); -- for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -- FNPolygon* p = _draws.at(i); -- if (r.intersects(p->boundingRect())) { -- bool f = false; -- QRect selected(_last.x() - w / 2, _last.y() - w / 2, w, w); -- for (uint j = 0; j < p->points().count(); ++j) { -- QPoint& pts = p->points().at(j); -- if (selected.contains(pts)) { -- f = true; -- break; -- } -- } -- if (f) { -- p->drawShape(pbuf, f); -- p->drawShape(pwin, f); -- } -- } -- } -- pbuf.setRasterOp(XorROP); -- pwin.setRasterOp(XorROP); -- pbuf.setPen(QPen(white, 1)); -- pwin.setPen(QPen(white, 1)); -- pbuf.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w); -- pwin.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w); -- pbuf.end(); -- pwin.end(); -- } --} -- --void FNCanvas::mouseReleaseEvent(QMouseEvent* evt) --{ -- _isDragging = false; -- if (_isWaiting) { -- _isWaiting = false; -- return; -- } -- _last = evt->pos(); -- if (MODE_ERASE != _drawMode) { -- if (1 < _tracks.count()) { -- 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)); -- _tracks = AutoCurve(_tracks); -- if (sp == ep) { -- 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 (1 < _tracks.count()) { -- p->setPoints(_tracks); -- redobuf_flush(); -- _draws.append(p); -- } -- } -- _tracks.clear(); -- _isHeadingEnables = true; -- _timer->start(_scrollTiming, true); -- } else { -- _last = QPoint(-1, -1); -- _tracks.append(new QPoint(evt->pos())); -- redraw(); -- } --} -- --void FNCanvas::paintEvent(QPaintEvent* evt) --{ -- 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() --{ -- if (0 == _draws.count() || !_isUseAllQuadrant) { -- return _origin; -- } -- -- int dx = ((FNPolygon*)_draws.at(0))->boundingRect().x(); -- int dy = ((FNPolygon*)_draws.at(0))->boundingRect().y(); -- for (uint i = 1; i < _draws.count(); ++i) { -- FNPolygon* p = _draws.at(i); -- if (dx > p->boundingRect().x()) { -- dx = p->boundingRect().x(); -- } -- if (dy > p->boundingRect().y()) { -- dy = p->boundingRect().y(); -- } -- } -- return QPoint(snap(dx), snap(dy)); --} -- -- --void FNCanvas::rebuild() --{ -- if (0 == _draws.count() || !_isUseAllQuadrant) { -- return; -- } -- -- QPoint d = getTopLeft(); -- 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::setOrigin(int ox, int oy) --{ -- 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 { -- 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 < _draws.count(); ++i) { -- FNPolygon* p = _draws.at(i); -- p->translate(dx, dy); -- } -- _origin = QPoint(ox, oy); -- emit originChanged(ox, oy); -- redraw(); --} -- --void FNCanvas::redraw() --{ -- if (!this->isVisible()) { -- return; -- } -- _buffer.fill(white); -- QPainter pbuf; -- QRect r = QRect(0, 0, width(), height()); -- pbuf.begin(&_buffer); -- if (_viewMode) { -- float wx = 0; -- float wy = 0; -- for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -- FNPolygon* p = _draws.at(i); -- QRect r = p->boundingRect(); -- if (wx < r.right()) { -- wx = r.right(); -- } -- if (wy < r.bottom()) { -- wy = r.bottom(); -- } -- } -- wx += SNAP_SIZE; -- wy += SNAP_SIZE; -- wx = snap((int)wx); -- wy = snap((int)wy); -- wx = wx + _origin.x(); -- wy = wy + _origin.y(); -- _scale_x = (float)width() / wx; -- _scale_y = (float)height() / wy; -- if (1.0f < _scale_x) { -- _scale_x = 1.0f; -- } -- if (1.0f < _scale_y) { -- _scale_y = 1.0f; -- } -- if (_scale_x > _scale_y) { -- _scale_x = _scale_y; -- } else if (_scale_x < _scale_y) { -- _scale_y = _scale_x; -- } -- for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -- FNPolygon* p = _draws.at(i); -- FNPolygon* t = NULL; -- if (p->type() == FN_BEZIER) { -- t = new FNBezier(*(FNBezier*)p); -- } else if (p->type() == FN_ELLIPSE) { -- t = new FNEllipse(*(FNEllipse*)p); -- } else { -- t = new FNPolygon(*p); -- } -- t->translate(-_origin.x(), -_origin.y()); -- for (uint j = 0; j < t->points().count(); ++j) { -- QPoint& pts = t->points().at(j); -- int x = (int)(pts.x() * _scale_x); -- int y = (int)(pts.y() * _scale_y); -- pts.setX(x); -- pts.setY(y); -- } -- double pensize = t->pen().width(); -- if (_scale_x > _scale_y) { -- pensize = pensize * _scale_y; -- } else { -- pensize = pensize * _scale_x; -- } -- if (0 >= pensize) { -- pensize = 1; -- } -- t->pen().setWidth(pensize); -- t->drawShape(pbuf); -- delete t; -- } -- } else if (MODE_ERASE != _drawMode) { -- if (MODE_FORMAT == _drawMode || MODE_CURVE == _drawMode) { -- QPen pen1(QColor(0, 240, 240), 1); -- QPen pen2(QColor(0, 0, 0), 1); -- pbuf.setPen(QPen(QColor(0, 240, 240), 1)); -- pbuf.setPen(pen1); -- for (int x = 0; x < width() + SNAP_SIZE; x += SNAP_SIZE) { -- pbuf.drawLine(x - SNAP_SIZE / 2, 0, x - SNAP_SIZE / 2, height()); -- for (int y = 0; y < height() + SNAP_SIZE; y += SNAP_SIZE) { -- pbuf.drawLine(0, y - SNAP_SIZE / 2, width(), y - SNAP_SIZE / 2); -- pbuf.drawRect(x-1,y-1,2,2); -- } -- } -- } -- if (_isShowGuide) { -- pbuf.setPen(QPen(cyan, 1, DashLine)); -- if (AS_HORIZONTAL == _asMode || AS_BOTH == _asMode) { -- if (0 != _origin.x() || _isUseAllQuadrant) { -- pbuf.drawLine(width() / _margin, 0, width() / _margin, height()); -- } -- pbuf.drawLine(width() * (_margin - 1) / _margin, 0, width() * (_margin - 1) / _margin, height()); -- } -- -- if (AS_VERTICAL == _asMode || AS_BOTH == _asMode) { -- if (0 != _origin.y() || _isUseAllQuadrant) { -- pbuf.drawLine(0, height() / _margin, width(), height() / _margin); -- } -- pbuf.drawLine(0, height() * (_margin - 1) / _margin, width(), height() * (_margin - 1) / _margin); -- } -- } -- -- for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -- FNPolygon* p = _draws.at(i); -- if (r.intersects(p->boundingRect())) { -- p->drawShape(pbuf); -- } -- } -- } else { -- int w = _eraser_s; -- if (PENWIDTH_MAX / 2 < _pen.width()) { -- w = _eraser_l; -- } -- FNPointList removes; -- for (uint i = 0; i < _tracks.count(); ++i) { -- removes.append(_tracks.at(i)); -- } -- for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -- FNPolygon* p = _draws.at(i); -- if (r.intersects(p->boundingRect())) { -- bool f = false; -- for (uint j = 0; j < _tracks.count(); ++j) { -- QPoint* pts = _tracks.at(j); -- QRect selected(pts->x() - w / 2, pts->y() - w / 2, w, w); -- for (uint k = 0; k < p->points().count(); ++k) { -- QPoint& pts2 = p->points().at(k); -- if (selected.contains(pts2)) { -- f = true; -- removes.remove(pts); -- break; -- } -- } -- if (f) { -- break; -- } -- } -- p->drawShape(pbuf, f); -- } -- } -- for (uint i = 0; i < removes.count(); ++i) { -- _tracks.remove(removes.at(i)); -- } -- /* -- if (_isDragging) { -- pbuf.setPen(QPen(black, 1)); -- pbuf.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w); -- } -- */ -- } -- pbuf.end(); -- repaint(); --} -- --void FNCanvas::changeColor(QRgb c) --{ -- _pen.setColor(QColor(c)); --} -- --void FNCanvas::undo() --{ -- if (MODE_ERASE != _drawMode) { -- ++_disp_offset; -- if (_disp_offset > _draws.count()) { -- _disp_offset = _draws.count(); -- } -- } else { -- _draws = _undobuf; -- _marks.clear(); -- } -- redraw(); --} -- --void FNCanvas::redo() --{ -- if (MODE_ERASE != _drawMode) { -- if (0 < _disp_offset) { -- --_disp_offset; -- } -- } -- redraw(); --} -- --void FNCanvas::clearList(FNPolygonList& list) --{ -- list.setAutoDelete(true); -- list.clear(); -- list.setAutoDelete(false); --} -- --void FNCanvas::clear() --{ -- _disp_offset = 0; -- clearList(_draws); -- _undobuf.clear(); -- setOrigin(0, 0); -- redraw(); --} -- --void FNCanvas::viewChanged(bool flg) --{ -- _tracks.clear(); -- _viewMode = flg; -- if (_viewMode) { -- if (_isUseAllQuadrant) { -- rebuild(); -- } -- setOrigin(0, 0); -- } -- redraw(); --} -- --void FNCanvas::redobuf_flush() --{ -- for (uint i = 0; i < _disp_offset; ++i) { -- FNPolygon* p = _draws.last(); -- _draws.remove(p); -- delete p; -- } -- _disp_offset = 0; --} -- --void FNCanvas::modeChanged(int mode) --{ -- _tracks.clear(); -- _drawMode = mode; -- redobuf_flush(); -- if (MODE_ERASE == _drawMode) { -- _marks.clear(); -- _undobuf = _draws; -- } else { -- if (_draws.count() != _undobuf.count()) { -- for (uint i = 0; i < _marks.count(); ++i) { -- FNPolygon* p = _marks.at(i); -- _draws.remove(p); -- } -- clearList(_marks); -- } -- } -- redraw(); --} -- --QRect FNCanvas::getMatrix(const QRect& r) const --{ -- int ox = _origin.x(); -- int oy = _origin.y(); -- const int wide = 100; -- -- int left = r.left() + ox; -- int top = r.top() + oy; -- int right = r.right() + ox; -- int bottom = r.bottom() + oy; -- -- left = (int)(left / wide) * wide; -- top = (int)(top / wide) * wide; -- right = (right % wide == 0 && left != right) ? right : (int)((right + wide) / wide) * wide; -- bottom = (bottom % wide == 0 && top != bottom) ? bottom : (int)((bottom + wide) / wide) * wide; -- -- return QRect(left - ox, top - oy, right - left, bottom - top); --} -- --void FNCanvas::CR() --{ -- if (MODE_ERASE == _drawMode) { -- return; -- } -- if (_isHeadingEnables) { -- //lastから、左方向に向けて探索する。 -- QRect r = getMatrix(_draws.last()->boundingRect()); -- bool isSearching = true; -- r.moveBy(-100, 0); -- while (isSearching) { -- isSearching = false; -- for (uint i = 0; i < _draws.count(); ++i) { -- FNPolygon* p = _draws.at(i); -- const QRect& r2 = p->boundingRect(); -- if (r.intersects(r2)) { -- if (r.left() + 100 > r2.left()) { -- r = getMatrix(r2); -- r.moveBy(-100, 0); -- isSearching = true; -- break; -- } -- } -- } -- } -- r.moveBy(100, 0); -- //lastが画面の4/5以下ならば、スクロールアップする。 -- //そうでなければ、ヘッディングのみ。 -- if (_last.y() > height() * 4 / 5) { -- setOrigin(_origin.x() + r.x(), _origin.y() + 50); -- } else { -- setOrigin(_origin.x() + r.x(), _origin.y()); -- } -- _isHeadingEnables = false; -- } else { -- //lastの周囲に何も無い場合は、縦にスクロールする。 -- setOrigin(_origin.x(), _origin.y() + 50); -- } --} -- --void FNCanvas::erase() --{ -- if (MODE_ERASE != _drawMode) { -- return; -- } -- FNPolygonList temp; -- int w = _eraser_s; -- if (PENWIDTH_MAX / 2 < _pen.width()) { -- w = _eraser_l; -- } -- QRect r = QRect(0, 0, width(), height()); -- for (uint i = 0; i < _draws.count(); ++i) { -- FNPolygon* p = _draws.at(i); -- bool f = false; -- if (r.intersects(p->boundingRect())) { -- for (uint j = 0; j < _tracks.count(); ++j) { -- QPoint* pts = _tracks.at(j); -- QRect selected(pts->x() - w / 2, pts->y() - w / 2, w, w); -- for (uint k = 0; k < p->points().count(); ++k) { -- QPoint& pts2 = p->points().at(k); -- if (selected.contains(pts2)) { -- temp.append(p); -- f = true; -- break; -- } -- } -- if (f) { -- break; -- } -- } -- } -- } -- for (uint i = 0; i < temp.count(); ++i) { -- _draws.remove(temp.at(i)); -- _marks.append(temp.at(i)); -- } -- _tracks.clear(); -- redraw(); --} -- --void FNCanvas::setPensize(int sz) --{ -- _pen.setWidth(sz); --} -- --bool FNCanvas::exportPNG(const QFileInfo& info, QPixmap& buf) --{ -- if (0 == info.fileName().length()) { -- QMessageBox::warning(0,"FreeNoteQt", "file name is empty."); -- return false; -- } -- if (info.extension(false) != "png") { -- QMessageBox::warning(0,"FreeNoteQt", "extension '.png' expected."); -- return false; -- } -- -- bool ret = buf.save(info.absFilePath(), "PNG"); -- if (ret) { -- FNMessageBox::information(0,"FreeNoteQt", "export PNG complete."); -- } else { -- QMessageBox::warning(0,"FreeNoteQt", "could not export file."); -- } -- return ret; --} -- --QString FNCanvas::mkPDFscript(FNPolygon* elm) --{ -- QString s =""; -- char buf[1024]; -- -- float r = (float)elm->pen().color().red() / 255.0f; -- float g = (float)elm->pen().color().green() / 255.0f; -- float b = (float)elm->pen().color().blue() / 255.0f; -- s += "q\n"; -- sprintf(buf, "%f %f %f RG\n", r, g, b); -- s += buf; -- QPointArray points = elm->points().copy(); -- points.translate(_origin.x(), _origin.y()); -- if (elm->type() == FN_BEZIER) { -- sprintf(buf, "%d %d m\n", points[0].x(), points[0].y()); -- s += buf; -- for (uint j = 1; j < points.count(); j += 3) { -- sprintf(buf, "%d %d %d %d %d %d c\n", -- points[j].x(), points[j].y(), -- points[j + 1].x(), points[j + 1].y(), -- points[j + 2].x(), points[j + 2].y() -- ); -- s += buf; -- } -- } else if (elm->type() == FN_ELLIPSE) { -- int x = points[0].x(); -- int y = points[0].y(); -- int ex = points[1].x(); -- int ey = points[1].y(); -- int w = ex - x; -- int h = ey - y; -- int cx = x + w/2; -- int cy = y; -- int x1 = x + 3*w/4; -- int y1 = y; -- int x2 = x + w; -- int y2 = y + h/4; -- int x3 = x + w; -- int y3 = y + h/2; -- -- sprintf(buf, "%d %d m\n%d %d %d %d %d %d c\n", cx, cy, x1, y1, x2, y2, x3, y3); -- s += buf; -- x1 = x + w; -- y1 = y + 3 * h / 4; -- x2 = x + 3 * w / 4; -- y2 = y + h; -- x3 = x + w/2; -- y3 = y + h; -- sprintf(buf, "%d %d %d %d %d %d c\n", x1, y1, x2, y2, x3, y3); -- s += buf; -- -- x1 = x + w / 4; -- y1 = y + h; -- x2 = x; -- y2 = y + 3 * h / 4; -- x3 = x; -- y3 = y + h / 2; -- sprintf(buf, "%d %d %d %d %d %d c\n", x1, y1, x2, y2, x3, y3); -- s += buf; -- x1 = x; -- y1 = y + h / 4; -- x2 = x + w / 4; -- y2 = y; -- x3 = x + w / 2; -- y3 = y; -- sprintf(buf, "%d %d %d %d %d %d c\n", x1, y1, x2, y2, x3, y3); -- s += buf; -- } else { -- sprintf(buf, "%d %d m\n", points[0].x(), points[0].y()); -- s += buf; -- for (uint j = 1; j < points.count(); ++j) { -- sprintf(buf, "%d %d l\n", points[j].x(), points[j].y()); -- s += buf; -- } -- } -- sprintf(buf, "%d w\n", elm->pen().width()); -- s += buf; -- s += "S\n"; -- s += "Q\n"; -- return s; --} -- --bool FNCanvas::exportPDF(const QFileInfo& info) --{ -- if (0 == info.fileName().length()) { -- QMessageBox::warning(0,"FreeNoteQt", "file name is empty."); -- return false; -- } -- if (info.extension(false) != "pdf") { -- QMessageBox::warning(0,"FreeNoteQt", "extension '.pdf' expected."); -- return false; -- } -- -- FILE* fp = NULL; -- if (!(fp = fopen(info.absFilePath().utf8(), "wt"))) { -- QMessageBox::warning(0,"FreeNoteQt", "could not export file."); -- return false; -- } -- -- QPoint o = getTopLeft(); -- rebuild(); -- int wx = 595; -- int wy = 842; -- char buf[1024]; -- for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -- FNPolygon* p = _draws.at(i); -- QRect r = p->boundingRect(); -- r.moveBy(_origin.x(), _origin.y()); -- if (wx < r.right()) { -- wx =r.right(); -- } -- if (wy < r.bottom()) { -- wy = r.bottom(); -- } -- } -- -- int len = 0; -- -- sprintf(buf, "1 0 0 -1 0 %d cm\n", wy); -- QString cm = buf; -- len += cm.length(); -- -- for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -- QString s = mkPDFscript(_draws.at(i)); -- len += s.length(); -- } -- -- QString header = ""; -- header += "%PDF-1.3\n"; -- header += "1 0 obj\n"; -- header += "<<\n"; -- header += "/Type /Page\n"; -- header += "/Parent 3 0 R\n"; -- header += "/Resources\n"; -- header += "<<\n"; -- header += "/ProcSet [ /PDF ]\n"; -- header += ">>\n"; -- sprintf(buf, "/MediaBox [ 0 0 %010d %010d ]\n", wx, wy); -- header += buf; -- header += "/Contents 4 0 R\n"; -- header += ">>\n"; -- header += "endobj\n"; -- header += "2 0 obj\n"; -- header += "<<\n"; -- header += "/Type /Catalog\n"; -- header += "/Pages 3 0 R\n"; -- header += "/PageLayout /OneColumn\n"; -- header += "/OpenAction [1 0 R /XYZ null null 1 ]\n"; -- header += ">>\n"; -- header += "endobj\n"; -- header += "3 0 obj\n"; -- header += "<<\n"; -- header += "/Type /Pages\n"; -- header += "/Kids [ 1 0 R ]\n"; -- header += "/Count 1\n"; -- header += ">>\n"; -- header += "endobj\n"; -- header += "4 0 obj\n"; -- sprintf(buf, "<< /Length %010d >>\n", len); -- header += buf; -- header += "stream\n"; -- -- QString footer = ""; -- footer += "xref\n"; -- footer += "0 5\n"; -- footer += "0000000000 65535 f \n"; -- footer += "0000000009 00000 n \n"; -- footer += "0000000147 00000 n \n"; -- footer += "0000000257 00000 n \n"; -- footer += "0000000316 00000 n \n"; -- footer += "trailer\n"; -- footer += "<<\n"; -- footer += "/Size 5\n"; -- footer += "/Root 2 0 R\n"; -- footer += ">>\n"; -- footer += "startxref\n"; -- -- len = cm.length(); -- len += header.length(); -- fputs(header, fp); -- fputs(cm, fp); -- -- for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -- QString s = mkPDFscript(_draws.at(i)); -- len += s.length(); -- fputs(s, fp); -- } -- QString streamfooter = "endstream\nendobj\n"; -- len += streamfooter.length(); -- fputs(streamfooter, fp); -- -- fputs(footer, fp); -- sprintf(buf, "%d\n", len); -- fputs(buf, fp); -- fputs("%%EOF\n", fp); -- fclose(fp); -- if (_isUseAllQuadrant) { -- setOrigin(-o.x(), -o.y()); -- } -- FNMessageBox::information(0,"FreeNoteQt", "export PDF complete."); -- return true; --} -- --bool FNCanvas::save(const QFileInfo& info) --{ -- if (0 == info.fileName().length()) { -- QMessageBox::warning(0,"FreeNoteQt", "file name is empty."); -- return false; -- } -- if (info.extension(false) != "free") { -- QMessageBox::warning(0,"FreeNoteQt", "extension '.free' expected."); -- return false; -- } -- FILE* fp = NULL; -- if (!(fp = fopen(info.absFilePath().utf8(), "wt"))) { -- QMessageBox::warning(0,"FreeNoteQt", "could not save file."); -- return false; -- } -- QPoint o = getTopLeft(); -- rebuild(); -- fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", fp); -- fputs("<freenote version=\"2.0\">\n", fp); -- char buf[1024]; -- for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -- FNPolygon p(*_draws.at(i)); -- p.translate(_origin.x(), _origin.y()); -- if (p.type() == FN_BEZIER) { -- sprintf(buf, "\t<bz color=\"%x\" width=\"%d\">\n", (uint)p.pen().color().rgb(), p.pen().width()); -- } else if (p.type() == FN_ELLIPSE) { -- sprintf(buf, "\t<el color=\"%x\" width=\"%d\">\n", (uint)p.pen().color().rgb(), p.pen().width()); -- } else { -- sprintf(buf, "\t<po color=\"%x\" width=\"%d\">\n", (uint)p.pen().color().rgb(), p.pen().width()); -- } -- fputs(buf, fp); -- QPointArray& points = p.points(); -- for (uint j = 0; j < points.count(); ++j) { -- QPoint point = points.point(j); -- sprintf(buf, "\t\t<p x=\"%d\" y=\"%d\"/>\n", point.x(), point.y()); -- fputs(buf, fp); -- } -- if (p.type() == FN_BEZIER) { -- fputs("\t</bz>\n", fp); -- } else if (p.type() == FN_ELLIPSE) { -- fputs("\t</el>\n", fp); -- } else { -- fputs("\t</po>\n", fp); -- } -- } -- fputs("</freenote>\n", fp); -- fclose(fp); -- if (_isUseAllQuadrant) { -- setOrigin(-o.x(), -o.y()); -- } -- FNMessageBox::information(0, "FreeNoteQt", "save complete."); -- return true; --} -- --bool FNCanvas::load(const QFileInfo& info) --{ -- if (0 == info.fileName().length()) { -- QMessageBox::warning(0,"FreeNoteQt", "file name is empty."); -- return false; -- } -- if (!info.exists()) { -- QMessageBox::warning(0,"FreeNoteQt", "file not exists."); -- return false; -- } -- FILE* fp = NULL; -- if (!(fp = fopen(info.absFilePath().utf8(), "rt"))) { -- QMessageBox::warning(0,"FreeNoteQt", "could not open file."); -- return false; -- } -- clear(); -- -- QString line; -- FNPointList points; -- points.setAutoDelete(true); -- int c; -- int w; -- QPen pen(Qt::black, 1); -- FNPolygon* polygon; -- -- char rdbuf[1024]; -- char buf[1024]; -- QString type = ""; -- while (!feof(fp)) { -- fgets(rdbuf, sizeof(rdbuf), fp); -- line = rdbuf; -- if (-1 != line.find("<fnpolygon ") || -- -1 != line.find("<po ") || -- -1 != line.find("<bz ") || -- -1 != line.find("<el ") -- ) { -- if (-1 != line.find("<el ")) { -- type = "Ellipse"; -- } else if (-1 != line.find("<bz ")) { -- type = "Bezier"; -- } else { -- type = "Polygon"; -- } -- points.clear(); -- int st = line.find("color") + 7; -- int ed = line.find("\"", st); -- strcpy(buf, line.mid(st, ed - st).utf8()); -- sscanf(buf, "%x", &c); -- st = line.find("width") + 7; -- ed = line.find("\"", st); -- strcpy(buf, line.mid(st, ed - st).utf8()); -- sscanf(buf, "%d", &w); -- } else if (-1 != line.find("<point ") || -- -1 != line.find("<p ") -- ) { -- int st = line.find("x=") + 3; -- int ed = line.find("\"", st); -- strcpy(buf, line.mid(st, ed - st).utf8()); -- int x; -- sscanf(buf, "%d", &x); -- -- st = line.find("y=") + 3; -- ed = line.find("\"", st); -- strcpy(buf, line.mid(st, ed - st).utf8()); -- int y; -- sscanf(buf, "%d", &y); -- points.append(createPts(x, y)); //バグ対策 -- } else if (-1 != line.find("</fnpolygon") || -- -1 != line.find("</bz") || -- -1 != line.find("</el") || -- -1 != line.find("</po")) { -- pen.setColor((QRgb)c); -- pen.setWidth(w); -- if (type == "Bezier") { -- _draws.append(polygon = createBezier(pen)); //バグ対策 -- } else if (type == "Ellipse") { -- _draws.append(polygon = createEllipse(pen)); //バグ対策 -- } else { -- _draws.append(polygon = createPolygon(pen)); //バグ対策 -- } -- polygon->setPoints(points); -- points.clear(); -- } -- } -- fclose(fp); -- int x = 0; -- int y = 0; -- for (uint i = 0; i < _draws.count(); ++i) { -- if (y > _draws.at(i)->boundingRect().top()) { -- y = _draws.at(i)->boundingRect().top(); -- } -- if (x > _draws.at(i)->boundingRect().left()) { -- x = _draws.at(i)->boundingRect().left(); -- } -- } -- for (uint i = 0; i < _draws.count(); ++i) { -- _draws.at(i)->translate(-x, -y); -- } -- redraw(); -- FNMessageBox::information(0,"FreeNoteQt", "load complete."); -- -- return true; --} -- --FNPolygon* FNCanvas::createPolygon(QPen& pen) --{ -- return new FNPolygon(pen); --} -- --FNPolygon* FNCanvas::createBezier(QPen& pen) --{ -- return new FNBezier(pen); --} -- -- --FNPolygon* FNCanvas::createEllipse(QPen& pen) --{ -- return new FNEllipse(pen); --} -- --QPoint* FNCanvas::createPts(int x, int y) --{ -- return new QPoint(x, y); --} -- --void FNCanvas::setGuide(bool f) --{ -- _isShowGuide = f; -- redraw(); --} -+/* FreeNote for Sharp SLA300, B500, C7x0 Linux PDA -+ Copyright (C) 2003 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 -+*/ -+/* -+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 <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 <stdlib.h> // abs -+#include "fnmessagebox.h" -+#include "fmtengine.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(QWidget* parent, const char* name, WFlags f ) -+ :QWidget(parent, name, f), -+ _pen(black, 1, SolidLine, RoundCap, RoundJoin), -+ _asMode(AS_NONE), -+ _drawMode(MODE_DRAW), -+ _disp_offset(0), -+ _eraser_l(50), -+ _eraser_s(10), -+ _h_step(100), -+ _v_step(100), -+ _margin(5), -+ _scrollTiming(800), -+ _viewMode(false), -+ _isWaiting(false), -+ _isDragging(false), -+ _isHeadingEnables(false), -+ _isShowGuide(false), -+ _isUseAllQuadrant(false), -+ _scale_x(1.0), -+ _scale_y(1.0) -+{ -+ _tracks.setAutoDelete(true); -+ this->setBackgroundMode(NoBackground); -+ _timer = new QTimer(this); -+ connect(_timer, SIGNAL(timeout()), this, SLOT(autoScroll())); -+} -+ -+FNCanvas::~FNCanvas() -+{ -+ _timer->stop(); -+ delete _timer; -+ -+ _tracks.clear(); -+ clearList(_draws); -+} -+ -+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::setScrollMode(int as) -+{ -+ _asMode = as; -+ redraw(); -+} -+ -+void FNCanvas::autoScroll() -+{ -+ if (AS_NONE == _asMode) { -+ if (MODE_FORMAT == _drawMode || MODE_CURVE == _drawMode || MODE_SMOOTH == _drawMode) { -+ setOrigin(_origin.x(), _origin.y()); -+ } -+ 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); -+ _isHeadingEnables = tmp; -+} -+ -+void FNCanvas::mousePressEvent(QMouseEvent* evt) -+{ -+ setFocus(); -+ _timer->stop(); -+ _tracks.clear(); -+ if (_viewMode) { -+ _isWaiting = true; -+ _viewMode = false; -+ setOrigin((int)((evt->x()) / _scale_x) - width() / 2, (int)((evt->y()) / _scale_y) - height() / 2); -+ redraw(); -+ emit resetViewMode(); -+ } else if (MODE_ERASE != _drawMode) { -+ _last = evt->pos(); -+ _tracks.append(new QPoint(_last)); -+ } else { -+ redraw(); -+ _last = evt->pos(); -+ _tracks.append(new QPoint(_last)); -+ -+ QPainter pbuf; -+ QPainter pwin; -+ pbuf.begin(&_buffer); -+ pwin.begin(this); -+ -+ int w = _eraser_s; -+ if (PENWIDTH_MAX / 2 < _pen.width()) { -+ w = _eraser_l; -+ } -+ pbuf.setRasterOp(XorROP); -+ pbuf.setPen(QPen(white, 1)); -+ pbuf.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w); -+ -+ pwin.setRasterOp(XorROP); -+ pwin.setPen(QPen(white, 1)); -+ pwin.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w); -+ -+ pbuf.end(); -+ pwin.end(); -+ } -+ _isDragging = true; -+} -+ -+void FNCanvas::mouseMoveEvent(QMouseEvent* evt) -+{ -+ if (_isWaiting) { -+ return; -+ } -+ if (MODE_ERASE != _drawMode) { -+ QPainter pwin; -+ QPainter pbuf; -+ -+ pwin.begin(this); -+ pbuf.begin(&_buffer); -+ -+ pwin.setPen(_pen); -+ pbuf.setPen(_pen); -+ -+ pwin.drawLine(_last, evt->pos()); -+ pbuf.drawLine(_last, evt->pos()); -+ -+ pwin.end(); -+ pbuf.end(); -+ _last = evt->pos(); -+ _tracks.append(new QPoint(_last)); -+ } else { -+ //redraw(); -+ if (_last.x() == -1) { -+ return; -+ } -+ QPainter pbuf; -+ QPainter pwin; -+ -+ pbuf.begin(&_buffer); -+ pwin.begin(this); -+ -+ int w = _eraser_s; -+ if (PENWIDTH_MAX / 2 < _pen.width()) { -+ w = _eraser_l; -+ } -+ pbuf.setRasterOp(XorROP); -+ pwin.setRasterOp(XorROP); -+ pbuf.setPen(QPen(white, 1)); -+ pwin.setPen(QPen(white, 1)); -+ pbuf.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w); -+ pwin.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w); -+ -+ _tracks.append(new QPoint(evt->pos())); -+ _last = evt->pos(); -+ -+ pbuf.setRasterOp(CopyROP); -+ pwin.setRasterOp(CopyROP); -+ QRect r = QRect(0, 0, width(), height()); -+ for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -+ FNPolygon* p = _draws.at(i); -+ if (r.intersects(p->boundingRect())) { -+ bool f = false; -+ QRect selected(_last.x() - w / 2, _last.y() - w / 2, w, w); -+ for (uint j = 0; j < p->points().count(); ++j) { -+ QPoint& pts = p->points().at(j); -+ if (selected.contains(pts)) { -+ f = true; -+ break; -+ } -+ } -+ if (f) { -+ p->drawShape(pbuf, f); -+ p->drawShape(pwin, f); -+ } -+ } -+ } -+ pbuf.setRasterOp(XorROP); -+ pwin.setRasterOp(XorROP); -+ pbuf.setPen(QPen(white, 1)); -+ pwin.setPen(QPen(white, 1)); -+ pbuf.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w); -+ pwin.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w); -+ pbuf.end(); -+ pwin.end(); -+ } -+} -+ -+void FNCanvas::mouseReleaseEvent(QMouseEvent* evt) -+{ -+ _isDragging = false; -+ if (_isWaiting) { -+ _isWaiting = false; -+ return; -+ } -+ _last = evt->pos(); -+ if (MODE_ERASE != _drawMode) { -+ if (1 < _tracks.count()) { -+ 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)); -+ _tracks = AutoCurve(_tracks); -+ if (sp == ep) { -+ 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 (1 < _tracks.count()) { -+ p->setPoints(_tracks); -+ redobuf_flush(); -+ _draws.append(p); -+ } -+ } -+ _tracks.clear(); -+ _isHeadingEnables = true; -+ _timer->start(_scrollTiming, true); -+ } else { -+ _last = QPoint(-1, -1); -+ _tracks.append(new QPoint(evt->pos())); -+ redraw(); -+ } -+} -+ -+void FNCanvas::paintEvent(QPaintEvent* evt) -+{ -+ 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() -+{ -+ if (0 == _draws.count() || !_isUseAllQuadrant) { -+ return _origin; -+ } -+ -+ int dx = ((FNPolygon*)_draws.at(0))->boundingRect().x(); -+ int dy = ((FNPolygon*)_draws.at(0))->boundingRect().y(); -+ for (uint i = 1; i < _draws.count(); ++i) { -+ FNPolygon* p = _draws.at(i); -+ if (dx > p->boundingRect().x()) { -+ dx = p->boundingRect().x(); -+ } -+ if (dy > p->boundingRect().y()) { -+ dy = p->boundingRect().y(); -+ } -+ } -+ return QPoint(snap(dx), snap(dy)); -+} -+ -+ -+void FNCanvas::rebuild() -+{ -+ if (0 == _draws.count() || !_isUseAllQuadrant) { -+ return; -+ } -+ -+ QPoint d = getTopLeft(); -+ 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::setOrigin(int ox, int oy) -+{ -+ 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 { -+ 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 < _draws.count(); ++i) { -+ FNPolygon* p = _draws.at(i); -+ p->translate(dx, dy); -+ } -+ _origin = QPoint(ox, oy); -+ emit originChanged(ox, oy); -+ redraw(); -+} -+ -+void FNCanvas::redraw() -+{ -+ if (!this->isVisible()) { -+ return; -+ } -+ _buffer.fill(white); -+ QPainter pbuf; -+ QRect r = QRect(0, 0, width(), height()); -+ pbuf.begin(&_buffer); -+ if (_viewMode) { -+ float wx = 0; -+ float wy = 0; -+ for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -+ FNPolygon* p = _draws.at(i); -+ QRect r = p->boundingRect(); -+ if (wx < r.right()) { -+ wx = r.right(); -+ } -+ if (wy < r.bottom()) { -+ wy = r.bottom(); -+ } -+ } -+ wx += SNAP_SIZE; -+ wy += SNAP_SIZE; -+ wx = snap((int)wx); -+ wy = snap((int)wy); -+ wx = wx + _origin.x(); -+ wy = wy + _origin.y(); -+ _scale_x = (float)width() / wx; -+ _scale_y = (float)height() / wy; -+ if (1.0f < _scale_x) { -+ _scale_x = 1.0f; -+ } -+ if (1.0f < _scale_y) { -+ _scale_y = 1.0f; -+ } -+ if (_scale_x > _scale_y) { -+ _scale_x = _scale_y; -+ } else if (_scale_x < _scale_y) { -+ _scale_y = _scale_x; -+ } -+ for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -+ FNPolygon* p = _draws.at(i); -+ FNPolygon* t = NULL; -+ if (p->type() == FN_BEZIER) { -+ t = new FNBezier(*(FNBezier*)p); -+ } else if (p->type() == FN_ELLIPSE) { -+ t = new FNEllipse(*(FNEllipse*)p); -+ } else { -+ t = new FNPolygon(*p); -+ } -+ t->translate(-_origin.x(), -_origin.y()); -+ for (uint j = 0; j < t->points().count(); ++j) { -+ QPoint& pts = t->points().at(j); -+ int x = (int)(pts.x() * _scale_x); -+ int y = (int)(pts.y() * _scale_y); -+ pts.setX(x); -+ pts.setY(y); -+ } -+ double pensize = t->pen().width(); -+ if (_scale_x > _scale_y) { -+ pensize = pensize * _scale_y; -+ } else { -+ pensize = pensize * _scale_x; -+ } -+ if (0 >= pensize) { -+ pensize = 1; -+ } -+ t->pen().setWidth(pensize); -+ t->drawShape(pbuf); -+ delete t; -+ } -+ } else if (MODE_ERASE != _drawMode) { -+ if (MODE_FORMAT == _drawMode || MODE_CURVE == _drawMode) { -+ QPen pen1(QColor(0, 240, 240), 1); -+ QPen pen2(QColor(0, 0, 0), 1); -+ pbuf.setPen(QPen(QColor(0, 240, 240), 1)); -+ pbuf.setPen(pen1); -+ for (int x = 0; x < width() + SNAP_SIZE; x += SNAP_SIZE) { -+ pbuf.drawLine(x - SNAP_SIZE / 2, 0, x - SNAP_SIZE / 2, height()); -+ for (int y = 0; y < height() + SNAP_SIZE; y += SNAP_SIZE) { -+ pbuf.drawLine(0, y - SNAP_SIZE / 2, width(), y - SNAP_SIZE / 2); -+ pbuf.drawRect(x-1,y-1,2,2); -+ } -+ } -+ } -+ if (_isShowGuide) { -+ pbuf.setPen(QPen(cyan, 1, DashLine)); -+ if (AS_HORIZONTAL == _asMode || AS_BOTH == _asMode) { -+ if (0 != _origin.x() || _isUseAllQuadrant) { -+ pbuf.drawLine(width() / _margin, 0, width() / _margin, height()); -+ } -+ pbuf.drawLine(width() * (_margin - 1) / _margin, 0, width() * (_margin - 1) / _margin, height()); -+ } -+ -+ if (AS_VERTICAL == _asMode || AS_BOTH == _asMode) { -+ if (0 != _origin.y() || _isUseAllQuadrant) { -+ pbuf.drawLine(0, height() / _margin, width(), height() / _margin); -+ } -+ pbuf.drawLine(0, height() * (_margin - 1) / _margin, width(), height() * (_margin - 1) / _margin); -+ } -+ } -+ -+ for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -+ FNPolygon* p = _draws.at(i); -+ if (r.intersects(p->boundingRect())) { -+ p->drawShape(pbuf); -+ } -+ } -+ } else { -+ int w = _eraser_s; -+ if (PENWIDTH_MAX / 2 < _pen.width()) { -+ w = _eraser_l; -+ } -+ FNPointList removes; -+ for (uint i = 0; i < _tracks.count(); ++i) { -+ removes.append(_tracks.at(i)); -+ } -+ for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -+ FNPolygon* p = _draws.at(i); -+ if (r.intersects(p->boundingRect())) { -+ bool f = false; -+ for (uint j = 0; j < _tracks.count(); ++j) { -+ QPoint* pts = _tracks.at(j); -+ QRect selected(pts->x() - w / 2, pts->y() - w / 2, w, w); -+ for (uint k = 0; k < p->points().count(); ++k) { -+ QPoint& pts2 = p->points().at(k); -+ if (selected.contains(pts2)) { -+ f = true; -+ removes.remove(pts); -+ break; -+ } -+ } -+ if (f) { -+ break; -+ } -+ } -+ p->drawShape(pbuf, f); -+ } -+ } -+ for (uint i = 0; i < removes.count(); ++i) { -+ _tracks.remove(removes.at(i)); -+ } -+ /* -+ if (_isDragging) { -+ pbuf.setPen(QPen(black, 1)); -+ pbuf.drawRect(_last.x() - w / 2, _last.y() - w / 2, w, w); -+ } -+ */ -+ } -+ pbuf.end(); -+ repaint(); -+} -+ -+void FNCanvas::changeColor(QRgb c) -+{ -+ _pen.setColor(QColor(c)); -+} -+ -+void FNCanvas::undo() -+{ -+ if (MODE_ERASE != _drawMode) { -+ ++_disp_offset; -+ if (_disp_offset > _draws.count()) { -+ _disp_offset = _draws.count(); -+ } -+ } else { -+ _draws = _undobuf; -+ _marks.clear(); -+ } -+ redraw(); -+} -+ -+void FNCanvas::redo() -+{ -+ if (MODE_ERASE != _drawMode) { -+ if (0 < _disp_offset) { -+ --_disp_offset; -+ } -+ } -+ redraw(); -+} -+ -+void FNCanvas::clearList(FNPolygonList& list) -+{ -+ list.setAutoDelete(true); -+ list.clear(); -+ list.setAutoDelete(false); -+} -+ -+void FNCanvas::clear() -+{ -+ _disp_offset = 0; -+ clearList(_draws); -+ _undobuf.clear(); -+ setOrigin(0, 0); -+ redraw(); -+} -+ -+void FNCanvas::viewChanged(bool flg) -+{ -+ _tracks.clear(); -+ _viewMode = flg; -+ if (_viewMode) { -+ if (_isUseAllQuadrant) { -+ rebuild(); -+ } -+ setOrigin(0, 0); -+ } -+ redraw(); -+} -+ -+void FNCanvas::redobuf_flush() -+{ -+ for (uint i = 0; i < _disp_offset; ++i) { -+ FNPolygon* p = _draws.last(); -+ _draws.remove(p); -+ delete p; -+ } -+ _disp_offset = 0; -+} -+ -+void FNCanvas::modeChanged(int mode) -+{ -+ _tracks.clear(); -+ _drawMode = mode; -+ redobuf_flush(); -+ if (MODE_ERASE == _drawMode) { -+ _marks.clear(); -+ _undobuf = _draws; -+ } else { -+ if (_draws.count() != _undobuf.count()) { -+ for (uint i = 0; i < _marks.count(); ++i) { -+ FNPolygon* p = _marks.at(i); -+ _draws.remove(p); -+ } -+ clearList(_marks); -+ } -+ } -+ redraw(); -+} -+ -+QRect FNCanvas::getMatrix(const QRect& r) const -+{ -+ int ox = _origin.x(); -+ int oy = _origin.y(); -+ const int wide = 100; -+ -+ int left = r.left() + ox; -+ int top = r.top() + oy; -+ int right = r.right() + ox; -+ int bottom = r.bottom() + oy; -+ -+ left = (int)(left / wide) * wide; -+ top = (int)(top / wide) * wide; -+ right = (right % wide == 0 && left != right) ? right : (int)((right + wide) / wide) * wide; -+ bottom = (bottom % wide == 0 && top != bottom) ? bottom : (int)((bottom + wide) / wide) * wide; -+ -+ return QRect(left - ox, top - oy, right - left, bottom - top); -+} -+ -+void FNCanvas::CR() -+{ -+ if (MODE_ERASE == _drawMode) { -+ return; -+ } -+ if (_isHeadingEnables) { -+ //lastから、左方向に向けて探索する。 -+ QRect r = getMatrix(_draws.last()->boundingRect()); -+ bool isSearching = true; -+ r.moveBy(-100, 0); -+ while (isSearching) { -+ isSearching = false; -+ for (uint i = 0; i < _draws.count(); ++i) { -+ FNPolygon* p = _draws.at(i); -+ const QRect& r2 = p->boundingRect(); -+ if (r.intersects(r2)) { -+ if (r.left() + 100 > r2.left()) { -+ r = getMatrix(r2); -+ r.moveBy(-100, 0); -+ isSearching = true; -+ break; -+ } -+ } -+ } -+ } -+ r.moveBy(100, 0); -+ //lastが画面の4/5以下ならば、スクロールアップする。 -+ //そうでなければ、ヘッディングのみ。 -+ if (_last.y() > height() * 4 / 5) { -+ setOrigin(_origin.x() + r.x(), _origin.y() + 50); -+ } else { -+ setOrigin(_origin.x() + r.x(), _origin.y()); -+ } -+ _isHeadingEnables = false; -+ } else { -+ //lastの周囲に何も無い場合は、縦にスクロールする。 -+ setOrigin(_origin.x(), _origin.y() + 50); -+ } -+} -+ -+void FNCanvas::erase() -+{ -+ if (MODE_ERASE != _drawMode) { -+ return; -+ } -+ FNPolygonList temp; -+ int w = _eraser_s; -+ if (PENWIDTH_MAX / 2 < _pen.width()) { -+ w = _eraser_l; -+ } -+ QRect r = QRect(0, 0, width(), height()); -+ for (uint i = 0; i < _draws.count(); ++i) { -+ FNPolygon* p = _draws.at(i); -+ bool f = false; -+ if (r.intersects(p->boundingRect())) { -+ for (uint j = 0; j < _tracks.count(); ++j) { -+ QPoint* pts = _tracks.at(j); -+ QRect selected(pts->x() - w / 2, pts->y() - w / 2, w, w); -+ for (uint k = 0; k < p->points().count(); ++k) { -+ QPoint& pts2 = p->points().at(k); -+ if (selected.contains(pts2)) { -+ temp.append(p); -+ f = true; -+ break; -+ } -+ } -+ if (f) { -+ break; -+ } -+ } -+ } -+ } -+ for (uint i = 0; i < temp.count(); ++i) { -+ _draws.remove(temp.at(i)); -+ _marks.append(temp.at(i)); -+ } -+ _tracks.clear(); -+ redraw(); -+} -+ -+void FNCanvas::setPensize(int sz) -+{ -+ _pen.setWidth(sz); -+} -+ -+bool FNCanvas::exportPNG(const QFileInfo& info, QPixmap& buf) -+{ -+ if (0 == info.fileName().length()) { -+ QMessageBox::warning(0,"FreeNoteQt", "file name is empty."); -+ return false; -+ } -+ if (info.extension(false) != "png") { -+ QMessageBox::warning(0,"FreeNoteQt", "extension '.png' expected."); -+ return false; -+ } -+ -+ bool ret = buf.save(info.absFilePath(), "PNG"); -+ if (ret) { -+ FNMessageBox::information(0,"FreeNoteQt", "export PNG complete."); -+ } else { -+ QMessageBox::warning(0,"FreeNoteQt", "could not export file."); -+ } -+ return ret; -+} -+ -+QString FNCanvas::mkPDFscript(FNPolygon* elm) -+{ -+ QString s =""; -+ char buf[1024]; -+ -+ float r = (float)elm->pen().color().red() / 255.0f; -+ float g = (float)elm->pen().color().green() / 255.0f; -+ float b = (float)elm->pen().color().blue() / 255.0f; -+ s += "q\n"; -+ sprintf(buf, "%f %f %f RG\n", r, g, b); -+ s += buf; -+ QPointArray points = elm->points().copy(); -+ points.translate(_origin.x(), _origin.y()); -+ if (elm->type() == FN_BEZIER) { -+ sprintf(buf, "%d %d m\n", points[0].x(), points[0].y()); -+ s += buf; -+ for (uint j = 1; j < points.count(); j += 3) { -+ sprintf(buf, "%d %d %d %d %d %d c\n", -+ points[j].x(), points[j].y(), -+ points[j + 1].x(), points[j + 1].y(), -+ points[j + 2].x(), points[j + 2].y() -+ ); -+ s += buf; -+ } -+ } else if (elm->type() == FN_ELLIPSE) { -+ int x = points[0].x(); -+ int y = points[0].y(); -+ int ex = points[1].x(); -+ int ey = points[1].y(); -+ int w = ex - x; -+ int h = ey - y; -+ int cx = x + w/2; -+ int cy = y; -+ int x1 = x + 3*w/4; -+ int y1 = y; -+ int x2 = x + w; -+ int y2 = y + h/4; -+ int x3 = x + w; -+ int y3 = y + h/2; -+ -+ sprintf(buf, "%d %d m\n%d %d %d %d %d %d c\n", cx, cy, x1, y1, x2, y2, x3, y3); -+ s += buf; -+ x1 = x + w; -+ y1 = y + 3 * h / 4; -+ x2 = x + 3 * w / 4; -+ y2 = y + h; -+ x3 = x + w/2; -+ y3 = y + h; -+ sprintf(buf, "%d %d %d %d %d %d c\n", x1, y1, x2, y2, x3, y3); -+ s += buf; -+ -+ x1 = x + w / 4; -+ y1 = y + h; -+ x2 = x; -+ y2 = y + 3 * h / 4; -+ x3 = x; -+ y3 = y + h / 2; -+ sprintf(buf, "%d %d %d %d %d %d c\n", x1, y1, x2, y2, x3, y3); -+ s += buf; -+ x1 = x; -+ y1 = y + h / 4; -+ x2 = x + w / 4; -+ y2 = y; -+ x3 = x + w / 2; -+ y3 = y; -+ sprintf(buf, "%d %d %d %d %d %d c\n", x1, y1, x2, y2, x3, y3); -+ s += buf; -+ } else { -+ sprintf(buf, "%d %d m\n", points[0].x(), points[0].y()); -+ s += buf; -+ for (uint j = 1; j < points.count(); ++j) { -+ sprintf(buf, "%d %d l\n", points[j].x(), points[j].y()); -+ s += buf; -+ } -+ } -+ sprintf(buf, "%d w\n", elm->pen().width()); -+ s += buf; -+ s += "S\n"; -+ s += "Q\n"; -+ return s; -+} -+ -+bool FNCanvas::exportPDF(const QFileInfo& info) -+{ -+ if (0 == info.fileName().length()) { -+ QMessageBox::warning(0,"FreeNoteQt", "file name is empty."); -+ return false; -+ } -+ if (info.extension(false) != "pdf") { -+ QMessageBox::warning(0,"FreeNoteQt", "extension '.pdf' expected."); -+ return false; -+ } -+ -+ FILE* fp = NULL; -+ if (!(fp = fopen(info.absFilePath().utf8(), "wt"))) { -+ QMessageBox::warning(0,"FreeNoteQt", "could not export file."); -+ return false; -+ } -+ -+ QPoint o = getTopLeft(); -+ rebuild(); -+ int wx = 595; -+ int wy = 842; -+ char buf[1024]; -+ for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -+ FNPolygon* p = _draws.at(i); -+ QRect r = p->boundingRect(); -+ r.moveBy(_origin.x(), _origin.y()); -+ if (wx < r.right()) { -+ wx =r.right(); -+ } -+ if (wy < r.bottom()) { -+ wy = r.bottom(); -+ } -+ } -+ -+ int len = 0; -+ -+ sprintf(buf, "1 0 0 -1 0 %d cm\n", wy); -+ QString cm = buf; -+ len += cm.length(); -+ -+ for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -+ QString s = mkPDFscript(_draws.at(i)); -+ len += s.length(); -+ } -+ -+ QString header = ""; -+ header += "%PDF-1.3\n"; -+ header += "1 0 obj\n"; -+ header += "<<\n"; -+ header += "/Type /Page\n"; -+ header += "/Parent 3 0 R\n"; -+ header += "/Resources\n"; -+ header += "<<\n"; -+ header += "/ProcSet [ /PDF ]\n"; -+ header += ">>\n"; -+ sprintf(buf, "/MediaBox [ 0 0 %010d %010d ]\n", wx, wy); -+ header += buf; -+ header += "/Contents 4 0 R\n"; -+ header += ">>\n"; -+ header += "endobj\n"; -+ header += "2 0 obj\n"; -+ header += "<<\n"; -+ header += "/Type /Catalog\n"; -+ header += "/Pages 3 0 R\n"; -+ header += "/PageLayout /OneColumn\n"; -+ header += "/OpenAction [1 0 R /XYZ null null 1 ]\n"; -+ header += ">>\n"; -+ header += "endobj\n"; -+ header += "3 0 obj\n"; -+ header += "<<\n"; -+ header += "/Type /Pages\n"; -+ header += "/Kids [ 1 0 R ]\n"; -+ header += "/Count 1\n"; -+ header += ">>\n"; -+ header += "endobj\n"; -+ header += "4 0 obj\n"; -+ sprintf(buf, "<< /Length %010d >>\n", len); -+ header += buf; -+ header += "stream\n"; -+ -+ QString footer = ""; -+ footer += "xref\n"; -+ footer += "0 5\n"; -+ footer += "0000000000 65535 f \n"; -+ footer += "0000000009 00000 n \n"; -+ footer += "0000000147 00000 n \n"; -+ footer += "0000000257 00000 n \n"; -+ footer += "0000000316 00000 n \n"; -+ footer += "trailer\n"; -+ footer += "<<\n"; -+ footer += "/Size 5\n"; -+ footer += "/Root 2 0 R\n"; -+ footer += ">>\n"; -+ footer += "startxref\n"; -+ -+ len = cm.length(); -+ len += header.length(); -+ fputs(header, fp); -+ fputs(cm, fp); -+ -+ for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -+ QString s = mkPDFscript(_draws.at(i)); -+ len += s.length(); -+ fputs(s, fp); -+ } -+ QString streamfooter = "endstream\nendobj\n"; -+ len += streamfooter.length(); -+ fputs(streamfooter, fp); -+ -+ fputs(footer, fp); -+ sprintf(buf, "%d\n", len); -+ fputs(buf, fp); -+ fputs("%%EOF\n", fp); -+ fclose(fp); -+ if (_isUseAllQuadrant) { -+ setOrigin(-o.x(), -o.y()); -+ } -+ FNMessageBox::information(0,"FreeNoteQt", "export PDF complete."); -+ return true; -+} -+ -+bool FNCanvas::save(const QFileInfo& info) -+{ -+ if (0 == info.fileName().length()) { -+ QMessageBox::warning(0,"FreeNoteQt", "file name is empty."); -+ return false; -+ } -+ if (info.extension(false) != "free") { -+ QMessageBox::warning(0,"FreeNoteQt", "extension '.free' expected."); -+ return false; -+ } -+ FILE* fp = NULL; -+ if (!(fp = fopen(info.absFilePath().utf8(), "wt"))) { -+ QMessageBox::warning(0,"FreeNoteQt", "could not save file."); -+ return false; -+ } -+ QPoint o = getTopLeft(); -+ rebuild(); -+ fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", fp); -+ fputs("<freenote version=\"2.0\">\n", fp); -+ char buf[1024]; -+ for (uint i = 0; i < _draws.count() - _disp_offset; ++i) { -+ FNPolygon p(*_draws.at(i)); -+ p.translate(_origin.x(), _origin.y()); -+ if (p.type() == FN_BEZIER) { -+ sprintf(buf, "\t<bz color=\"%x\" width=\"%d\">\n", (uint)p.pen().color().rgb(), p.pen().width()); -+ } else if (p.type() == FN_ELLIPSE) { -+ sprintf(buf, "\t<el color=\"%x\" width=\"%d\">\n", (uint)p.pen().color().rgb(), p.pen().width()); -+ } else { -+ sprintf(buf, "\t<po color=\"%x\" width=\"%d\">\n", (uint)p.pen().color().rgb(), p.pen().width()); -+ } -+ fputs(buf, fp); -+ QPointArray& points = p.points(); -+ for (uint j = 0; j < points.count(); ++j) { -+ QPoint point = points.point(j); -+ sprintf(buf, "\t\t<p x=\"%d\" y=\"%d\"/>\n", point.x(), point.y()); -+ fputs(buf, fp); -+ } -+ if (p.type() == FN_BEZIER) { -+ fputs("\t</bz>\n", fp); -+ } else if (p.type() == FN_ELLIPSE) { -+ fputs("\t</el>\n", fp); -+ } else { -+ fputs("\t</po>\n", fp); -+ } -+ } -+ fputs("</freenote>\n", fp); -+ fclose(fp); -+ if (_isUseAllQuadrant) { -+ setOrigin(-o.x(), -o.y()); -+ } -+ FNMessageBox::information(0, "FreeNoteQt", "save complete."); -+ return true; -+} -+ -+bool FNCanvas::load(const QFileInfo& info) -+{ -+ if (0 == info.fileName().length()) { -+ QMessageBox::warning(0,"FreeNoteQt", "file name is empty."); -+ return false; -+ } -+ if (!info.exists()) { -+ QMessageBox::warning(0,"FreeNoteQt", "file not exists."); -+ return false; -+ } -+ FILE* fp = NULL; -+ if (!(fp = fopen(info.absFilePath().utf8(), "rt"))) { -+ QMessageBox::warning(0,"FreeNoteQt", "could not open file."); -+ return false; -+ } -+ clear(); -+ -+ QString line; -+ FNPointList points; -+ points.setAutoDelete(true); -+ int c; -+ int w; -+ QPen pen(Qt::black, 1); -+ FNPolygon* polygon; -+ -+ char rdbuf[1024]; -+ char buf[1024]; -+ QString type = ""; -+ while (!feof(fp)) { -+ fgets(rdbuf, sizeof(rdbuf), fp); -+ line = rdbuf; -+ if (-1 != line.find("<fnpolygon ") || -+ -1 != line.find("<po ") || -+ -1 != line.find("<bz ") || -+ -1 != line.find("<el ") -+ ) { -+ if (-1 != line.find("<el ")) { -+ type = "Ellipse"; -+ } else if (-1 != line.find("<bz ")) { -+ type = "Bezier"; -+ } else { -+ type = "Polygon"; -+ } -+ points.clear(); -+ int st = line.find("color") + 7; -+ int ed = line.find("\"", st); -+ strcpy(buf, line.mid(st, ed - st).utf8()); -+ sscanf(buf, "%x", &c); -+ st = line.find("width") + 7; -+ ed = line.find("\"", st); -+ strcpy(buf, line.mid(st, ed - st).utf8()); -+ sscanf(buf, "%d", &w); -+ } else if (-1 != line.find("<point ") || -+ -1 != line.find("<p ") -+ ) { -+ int st = line.find("x=") + 3; -+ int ed = line.find("\"", st); -+ strcpy(buf, line.mid(st, ed - st).utf8()); -+ int x; -+ sscanf(buf, "%d", &x); -+ -+ st = line.find("y=") + 3; -+ ed = line.find("\"", st); -+ strcpy(buf, line.mid(st, ed - st).utf8()); -+ int y; -+ sscanf(buf, "%d", &y); -+ points.append(createPts(x, y)); //バグ対策 -+ } else if (-1 != line.find("</fnpolygon") || -+ -1 != line.find("</bz") || -+ -1 != line.find("</el") || -+ -1 != line.find("</po")) { -+ pen.setColor((QRgb)c); -+ pen.setWidth(w); -+ if (type == "Bezier") { -+ _draws.append(polygon = createBezier(pen)); //バグ対策 -+ } else if (type == "Ellipse") { -+ _draws.append(polygon = createEllipse(pen)); //バグ対策 -+ } else { -+ _draws.append(polygon = createPolygon(pen)); //バグ対策 -+ } -+ polygon->setPoints(points); -+ points.clear(); -+ } -+ } -+ fclose(fp); -+ int x = 0; -+ int y = 0; -+ for (uint i = 0; i < _draws.count(); ++i) { -+ if (y > _draws.at(i)->boundingRect().top()) { -+ y = _draws.at(i)->boundingRect().top(); -+ } -+ if (x > _draws.at(i)->boundingRect().left()) { -+ x = _draws.at(i)->boundingRect().left(); -+ } -+ } -+ for (uint i = 0; i < _draws.count(); ++i) { -+ _draws.at(i)->translate(-x, -y); -+ } -+ redraw(); -+ FNMessageBox::information(0,"FreeNoteQt", "load complete."); -+ -+ return true; -+} -+ -+FNPolygon* FNCanvas::createPolygon(QPen& pen) -+{ -+ return new FNPolygon(pen); -+} -+ -+FNPolygon* FNCanvas::createBezier(QPen& pen) -+{ -+ return new FNBezier(pen); -+} -+ -+ -+FNPolygon* FNCanvas::createEllipse(QPen& pen) -+{ -+ return new FNEllipse(pen); -+} -+ -+QPoint* FNCanvas::createPts(int x, int y) -+{ -+ return new QPoint(x, y); -+} -+ -+void FNCanvas::setGuide(bool f) -+{ -+ _isShowGuide = f; -+ redraw(); -+} diff --git a/packages/nonworking/freenote/freenote_1.6.1.bb b/packages/nonworking/freenote/freenote_1.6.1.bb deleted file mode 100644 index 3e4540a060..0000000000 --- a/packages/nonworking/freenote/freenote_1.6.1.bb +++ /dev/null @@ -1,22 +0,0 @@ -DESCRIPTION="Auto-Correction Paint Program for Opie/Qtopia" -SECTION="base" -PRIORITY="optional" -LICENSE="GPL" - -SRC_URI = http://www.urban.ne.jp/home/kanemori/zaurus/FreeNote_${PV}_arm.tar.gz \ - file://${FILESDIR}/compile.patch;patch=1 -S = ${WORKDIR}/FreeNote_${PV}_arm - -inherit palmtop - -do_configure_prepend() { - qmake -project -o ${PN}.pro -} - -do_install() { - install -d ${D}${palmtopdir}/{bin,apps/Applications,pics} - install -D -m 755 freenoteeintu ${D}${palmtopdir}/bin/freenoteeintu - install -D -m 644 ${FILESDIR}/freenoteeintu.desktop ${D}${palmtopdir}/apps/Applications/freenoteeintu.desktop - install -d ${D}/${palmtopdir}/pics - cp -pPR *.png ${D}${palmtopdir}/pics/ -} |