Mercurial > mercurial > hgweb_searcher03.cgi
annotate src/preview.cpp @ 16:1ba97995f642
Get/Put DB files to shared-directory.
author | pyon@macmini |
---|---|
date | Thu, 19 Jun 2014 18:46:11 +0900 |
parents | de222bc84e48 |
children | 92188f60323d |
rev | line source |
---|---|
9 | 1 // Filename : preview.cpp |
15 | 2 // Last Change: 11-Jun-2014. |
9 | 3 // |
4 | |
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
5 #include "marksheet.h" |
9 | 6 #include "preview.h" |
7 #define THUMB_W 60 | |
8 #define THUMB_H 75 | |
9 | |
10 | 10 // サムネイルパネル |
11 PThumbnailPanel::PThumbnailPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) | |
12 : wxPanel( parent, id, pos, size, style ) | |
13 { | |
14 m_parent = (PreviewDialog*)parent; | |
15 | |
16 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL ); | |
17 this->SetBackgroundColour( wxColour( 192, 192, 192 ) ); | |
18 | |
19 wxString thumb = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("thumbnail.png"); | |
20 wxBitmap bmp = wxBitmap( thumb, wxBITMAP_TYPE_PNG ); | |
21 | |
22 m_bitmap0 = new wxStaticBitmap( this, wxID_ANY, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); | |
23 bSizer->Add( m_bitmap0, 0, wxALL|wxALIGN_CENTER, 5 ); | |
24 m_bitmap0->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick0 ), NULL, this ); | |
25 | |
26 m_bitmap1 = new wxStaticBitmap(this, wxID_ANY, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); | |
27 bSizer->Add( m_bitmap1, 0, wxALL|wxALIGN_CENTER, 5 ); | |
28 m_bitmap1->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick1 ), NULL, this ); | |
29 | |
30 m_bitmap2 = new wxStaticBitmap( this, wxID_ANY, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); | |
31 bSizer->Add( m_bitmap2, 0, wxALL|wxALIGN_CENTER, 5 ); | |
32 m_bitmap2->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick2 ), NULL, this ); | |
33 | |
34 m_bitmap3 = new wxStaticBitmap(this, wxID_ANY, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); | |
35 bSizer->Add( m_bitmap3, 0, wxALL|wxALIGN_CENTER, 5 ); | |
36 m_bitmap3->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick3 ), NULL, this ); | |
37 | |
38 m_bitmap4 = new wxStaticBitmap( this, wxID_ANY, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); | |
39 bSizer->Add( m_bitmap4, 0, wxALL|wxALIGN_CENTER, 5 ); | |
40 m_bitmap4->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick4 ), NULL, this ); | |
41 | |
42 m_bitmap5 = new wxStaticBitmap(this, wxID_ANY, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); | |
43 bSizer->Add( m_bitmap5, 0, wxALL|wxALIGN_CENTER, 5 ); | |
44 m_bitmap5->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick5 ), NULL, this ); | |
45 | |
46 this->SetSizer( bSizer ); | |
47 this->Layout(); | |
48 } | |
49 | |
50 PThumbnailPanel::~PThumbnailPanel() | |
51 { | |
52 m_bitmap0->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick0 ), NULL, this ); | |
53 m_bitmap1->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick1 ), NULL, this ); | |
54 m_bitmap2->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick2 ), NULL, this ); | |
55 m_bitmap3->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick3 ), NULL, this ); | |
56 m_bitmap4->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick4 ), NULL, this ); | |
57 m_bitmap5->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick5 ), NULL, this ); | |
58 } | |
59 | |
60 // Functions | |
15 | 61 /* サムネイル画像作成 */ |
13 | 62 void PThumbnailPanel::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles, int select ) |
10 | 63 { |
64 m_imagefiles = imagefiles; | |
65 | |
66 wxBitmap bmp; | |
13 | 67 m_imageList.Create( THUMB_W, THUMB_H ); |
68 | |
69 bmp.LoadFile( cachefiles[0], wxBITMAP_TYPE_PNG ); m_imageList.Add( bmp ); | |
70 bmp.LoadFile( cachefiles[1], wxBITMAP_TYPE_PNG ); m_imageList.Add( bmp ); | |
71 bmp.LoadFile( cachefiles[2], wxBITMAP_TYPE_PNG ); m_imageList.Add( bmp ); | |
72 bmp.LoadFile( cachefiles[3], wxBITMAP_TYPE_PNG ); m_imageList.Add( bmp ); | |
73 bmp.LoadFile( cachefiles[4], wxBITMAP_TYPE_PNG ); m_imageList.Add( bmp ); | |
74 bmp.LoadFile( cachefiles[5], wxBITMAP_TYPE_PNG ); m_imageList.Add( bmp ); | |
75 SetImageList( select ); | |
10 | 76 } |
77 /* 画像クリックで拡大表示 */ | |
78 void PThumbnailPanel::OnClick0( wxMouseEvent& WXUNUSED(event) ) { Preview( 0 ); } | |
79 void PThumbnailPanel::OnClick1( wxMouseEvent& WXUNUSED(event) ) { Preview( 1 ); } | |
80 void PThumbnailPanel::OnClick2( wxMouseEvent& WXUNUSED(event) ) { Preview( 2 ); } | |
81 void PThumbnailPanel::OnClick3( wxMouseEvent& WXUNUSED(event) ) { Preview( 3 ); } | |
82 void PThumbnailPanel::OnClick4( wxMouseEvent& WXUNUSED(event) ) { Preview( 4 ); } | |
83 void PThumbnailPanel::OnClick5( wxMouseEvent& WXUNUSED(event) ) { Preview( 5 ); } | |
84 void PThumbnailPanel::Preview( int n ) | |
85 { | |
86 if ( m_imagefiles.GetCount() < n + 1 ) return; | |
13 | 87 SetImageList( n ); |
10 | 88 m_parent->SetPreviewImage( n ); |
89 } | |
13 | 90 /* サムネイル表示 */ |
91 void PThumbnailPanel::SetImageList( int selected ) | |
92 { | |
93 m_bitmap0->SetBitmap( m_imageList.GetBitmap(0) ); | |
94 m_bitmap1->SetBitmap( m_imageList.GetBitmap(1) ); | |
95 m_bitmap2->SetBitmap( m_imageList.GetBitmap(2) ); | |
96 m_bitmap3->SetBitmap( m_imageList.GetBitmap(3) ); | |
97 m_bitmap4->SetBitmap( m_imageList.GetBitmap(4) ); | |
98 m_bitmap5->SetBitmap( m_imageList.GetBitmap(5) ); | |
10 | 99 |
13 | 100 wxImage image = m_imageList.GetBitmap( selected ).ConvertToImage(); |
101 unsigned char *data = image.GetData(); | |
102 for ( int y = 0; y < THUMB_H; y++ ) | |
103 for ( int x = 0; x <THUMB_W; x++ ) | |
104 data[ ( y * THUMB_W + x ) * 3 + 2 ] = 255; // 文字色:黒(0,0,0)->青(0,0,255) | |
105 | |
106 wxBitmap bmp_mask( image ); | |
107 | |
108 switch ( selected ) { | |
109 case 0: | |
110 m_bitmap0->SetBitmap( bmp_mask ); | |
111 break; | |
112 case 1: | |
113 m_bitmap1->SetBitmap( bmp_mask ); | |
114 break; | |
115 case 2: | |
116 m_bitmap2->SetBitmap( bmp_mask ); | |
117 break; | |
118 case 3: | |
119 m_bitmap3->SetBitmap( bmp_mask ); | |
120 break; | |
121 case 4: | |
122 m_bitmap4->SetBitmap( bmp_mask ); | |
123 break; | |
124 case 5: | |
125 m_bitmap5->SetBitmap( bmp_mask ); | |
126 break; | |
127 } | |
128 } | |
10 | 129 |
130 //////////////////////////////////////////////////////// | |
131 // プレビューダイアログ | |
9 | 132 PreviewDialog::PreviewDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) |
133 : wxDialog( parent, id, title, pos, size, style ) | |
134 { | |
135 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL ); | |
136 | |
14 | 137 m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL|wxALWAYS_SHOW_SB ); |
15 | 138 m_scrolledWindow->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PreviewDialog::OnWheel ), NULL, this ); |
9 | 139 m_bitmap = new wxStaticBitmap( m_scrolledWindow, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); |
14 | 140 m_bitmap->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( PreviewDialog::OnDClick ), NULL, this ); |
15 | 141 m_bitmap->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( PreviewDialog::OnStartRGesture ), NULL, this ); |
142 m_bitmap->Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( PreviewDialog::OnEndRGesture ), NULL, this ); | |
9 | 143 bSizerTop->Add( m_scrolledWindow, 1, wxALL|wxEXPAND, 5 ); |
144 | |
145 wxBoxSizer* bSizerMenu = new wxBoxSizer( wxVERTICAL ); | |
146 | |
10 | 147 m_thumbPanel = new PThumbnailPanel( this, wxID_ANY, wxDefaultPosition, wxSize( 100, -1 ), wxSUNKEN_BORDER ); |
148 bSizerMenu->Add( m_thumbPanel, 0, wxALL|wxEXPAND, 5 ); | |
9 | 149 |
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
150 m_textInfo = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( -1, 80 ), wxTE_MULTILINE|wxTE_READONLY|wxTE_NO_VSCROLL ); |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
151 m_textInfo->SetBackgroundColour( wxColour( 192, 192, 192 ) ); |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
152 bSizerMenu->Add( m_textInfo, 0, wxRIGHT|wxLEFT|wxBOTTOM, 5 ); |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
153 |
9 | 154 m_buttonPrint = new wxButton( this, ID_PRINT, wxT("印刷"), wxDefaultPosition, wxDefaultSize, 0 ); |
155 bSizerMenu->Add( m_buttonPrint, 0, wxALL, 5 ); | |
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
156 |
11 | 157 bSizerMenu->Add( 0, 0, 0, 0, 5 ); |
9 | 158 |
159 m_buttonClose = new wxButton( this, wxID_CANCEL, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 ); | |
160 m_buttonClose->SetDefault(); | |
161 bSizerMenu->Add( m_buttonClose, 0, wxALL, 5 ); | |
162 | |
163 bSizerTop->Add( bSizerMenu, 0, wxALL|wxEXPAND, 5 ); | |
164 | |
165 this->SetSizer( bSizerTop ); | |
166 this->Layout(); | |
167 } | |
168 | |
169 PreviewDialog::~PreviewDialog() | |
170 { | |
15 | 171 m_scrolledWindow->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PreviewDialog::OnWheel ), NULL, this ); |
14 | 172 m_bitmap->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( PreviewDialog::OnDClick ), NULL, this ); |
15 | 173 m_bitmap->Disconnect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( PreviewDialog::OnStartRGesture ), NULL, this ); |
174 m_bitmap->Disconnect( wxEVT_RIGHT_UP, wxMouseEventHandler( PreviewDialog::OnEndRGesture ), NULL, this ); | |
9 | 175 } |
176 | |
177 // Event Table | |
178 BEGIN_EVENT_TABLE( PreviewDialog, wxDialog ) | |
14 | 179 EVT_BUTTON( ID_PRINT, PreviewDialog::OnPrint ) |
9 | 180 END_EVENT_TABLE() |
181 | |
182 #define WIDTH 2480 | |
183 #define HEIGHT 3509 | |
15 | 184 /* プレビューするファイルをセット */ |
10 | 185 void PreviewDialog::SetPreviewImage( int n ) |
9 | 186 { |
15 | 187 m_preview = n; |
14 | 188 m_zoom = 1.0; |
189 SetZoom( m_zoom ); | |
9 | 190 |
14 | 191 // file info |
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
192 float z; |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
193 long l; |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
194 GetScore( &z, &l, m_imagefiles[n] ); |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
195 wxString info = m_imagefiles[n].AfterLast( wxFILE_SEP_PATH ); |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
196 info += wxString::Format( wxT("\n%z = %f"), z ); |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
197 info += wxString::Format( wxT("\n%l = %ld"), l ); |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
198 m_textInfo->SetValue( info ); |
10 | 199 } |
200 | |
15 | 201 /* 倍率を指定しロード */ |
14 | 202 void PreviewDialog::SetZoom( float zoom ) |
203 { | |
204 int w, h; | |
205 m_scrolledWindow->GetSize( &w, &h ); | |
206 w = (int)( zoom * h * WIDTH / HEIGHT ); | |
207 h = (int)( zoom * h ); | |
208 | |
209 m_bitmap->SetBitmap( wxNullBitmap ); | |
210 wxImage img; | |
15 | 211 img.LoadFile( m_imagefiles[m_preview], wxBITMAP_TYPE_JPEG ); |
14 | 212 wxBitmap bmp( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ); |
213 m_bitmap->SetBitmap( bmp ); | |
214 m_bitmap->Centre( wxHORIZONTAL ); | |
215 | |
216 m_scrolledWindow->Scroll( 0, 0 ); | |
217 m_scrolledWindow->SetScrollbars( 10, 10, 0, h/10 ); | |
218 } | |
219 | |
15 | 220 /* ファイル名を保持 */ |
13 | 221 void PreviewDialog::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles, int select ) |
10 | 222 { |
223 m_imagefiles = imagefiles; | |
224 m_cachefiles = cachefiles; | |
13 | 225 m_thumbPanel->SetFiles( m_imagefiles, m_cachefiles, select ); |
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
226 |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
227 wxString title = wxT("プレビュー @ ") + m_imagefiles[0].BeforeLast( wxFILE_SEP_PATH ); |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
228 this->SetTitle( title ); |
9 | 229 } |
230 | |
15 | 231 /* コントロールキー + マウスホイール で画像を拡大・縮小 */ |
14 | 232 void PreviewDialog::OnWheel( wxMouseEvent& event ) |
233 { | |
234 if ( event.ControlDown() ) { | |
235 if ( event.GetWheelRotation() < 0 ) { | |
236 if ( m_zoom > 2.1 ) return; | |
237 m_zoom *= 1.3; | |
238 } | |
239 else { | |
240 if ( m_zoom <= 1.0 ) return; | |
241 m_zoom /= 1.3; | |
242 } | |
243 SetZoom( m_zoom ); | |
244 return; | |
245 } | |
246 event.Skip(); | |
247 } | |
248 | |
15 | 249 /* 画像のダブルクリックで倍率変更 */ |
14 | 250 void PreviewDialog::OnDClick( wxMouseEvent& WXUNUSED(event) ) |
251 { | |
252 if ( m_zoom > 2.1 ) m_zoom = 1.0; | |
253 else m_zoom *= 1.3; | |
254 | |
255 SetZoom( m_zoom ); | |
256 } | |
257 | |
15 | 258 /* 右ジェスチャー検知開始 */ |
259 void PreviewDialog::OnStartRGesture( wxMouseEvent& event ) | |
260 { | |
261 event.GetPosition( &cx, &cy ); | |
262 } | |
263 | |
264 /* 右ジェスチャー判定 */ | |
265 void PreviewDialog::OnEndRGesture( wxMouseEvent& event ) | |
266 { | |
267 int x, y; | |
268 event.GetPosition( &x, &y ); | |
269 | |
270 int dx = x - cx; | |
271 int dy = y - cy; | |
272 float rad = fabs( atan2( dy, dx ) ); | |
273 float pi = 3.14159; | |
274 | |
275 // 右へジェスチャー | |
276 if ( rad < pi/8 && dx > 0 ) { | |
277 if ( m_preview < m_imagefiles.GetCount() - 1 ) | |
278 m_preview++; | |
279 else | |
280 return; | |
281 m_thumbPanel->Preview( m_preview ); | |
282 } | |
283 // 左へジェスチャー | |
284 else if ( rad > pi/8*7 && rad < pi && dx < 0 ) { | |
285 if ( m_preview > 0 ) | |
286 m_preview--; | |
287 else | |
288 return; | |
289 m_thumbPanel->Preview( m_preview ); | |
290 } | |
291 // 右上ヘジェスチャー | |
292 else if ( rad > pi/8 && rad < pi/8*3 && dx > 0 ) { | |
293 Close(); | |
294 } | |
295 } | |
296 | |
297 /* 印刷 */ | |
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
298 void PreviewDialog::OnPrint( wxCommandEvent& WXUNUSED(event) ) |
9 | 299 { |
300 wxString html; | |
301 html = html + wxT("<html><body>\n"); | |
302 | |
303 wxString tmpjpg = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH + wxT("preview.jpg"); | |
304 | |
15 | 305 wxCopyFile( m_imagefiles[m_preview], tmpjpg, true ); |
9 | 306 |
307 html = html + wxT("<img src=\"") + tmpjpg + wxT("\" width=\"750\" height=\"1060\"/>"); | |
308 html = html + wxT("</body></html>"); | |
309 | |
310 // start printing | |
311 wxHtmlPrintout hpout( wxT("Searcher03") ); | |
312 hpout.SetMargins( 0, 0, 0, 0, 0 ); | |
313 wxPrintDialogData pd; | |
314 wxPrinter p( &pd ); | |
315 | |
316 hpout.SetHtmlText( html, wxEmptyString, false ); | |
317 p.Print( NULL, &hpout, true ); | |
318 } | |
319 |