Mercurial > mercurial > hgweb_searcher03.cgi
annotate src/preview.cpp @ 14:ac17a73e39b3
Zoom in / out in Preview Dialog.
author | pyon@macmini |
---|---|
date | Thu, 05 Jun 2014 04:19:03 +0900 |
parents | bbd65edf71d4 |
children | de222bc84e48 |
rev | line source |
---|---|
9 | 1 // Filename : preview.cpp |
14 | 2 // Last Change: 04-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 | |
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 ); |
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 ); |
9 | 141 bSizerTop->Add( m_scrolledWindow, 1, wxALL|wxEXPAND, 5 ); |
142 | |
143 wxBoxSizer* bSizerMenu = new wxBoxSizer( wxVERTICAL ); | |
144 | |
10 | 145 m_thumbPanel = new PThumbnailPanel( this, wxID_ANY, wxDefaultPosition, wxSize( 100, -1 ), wxSUNKEN_BORDER ); |
146 bSizerMenu->Add( m_thumbPanel, 0, wxALL|wxEXPAND, 5 ); | |
9 | 147 |
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
148 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
|
149 m_textInfo->SetBackgroundColour( wxColour( 192, 192, 192 ) ); |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
150 bSizerMenu->Add( m_textInfo, 0, wxRIGHT|wxLEFT|wxBOTTOM, 5 ); |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
151 |
9 | 152 m_buttonPrint = new wxButton( this, ID_PRINT, wxT("印刷"), wxDefaultPosition, wxDefaultSize, 0 ); |
153 bSizerMenu->Add( m_buttonPrint, 0, wxALL, 5 ); | |
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
154 |
11 | 155 bSizerMenu->Add( 0, 0, 0, 0, 5 ); |
9 | 156 |
157 m_buttonClose = new wxButton( this, wxID_CANCEL, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 ); | |
158 m_buttonClose->SetDefault(); | |
159 bSizerMenu->Add( m_buttonClose, 0, wxALL, 5 ); | |
160 | |
161 bSizerTop->Add( bSizerMenu, 0, wxALL|wxEXPAND, 5 ); | |
162 | |
163 this->SetSizer( bSizerTop ); | |
164 this->Layout(); | |
165 } | |
166 | |
167 PreviewDialog::~PreviewDialog() | |
168 { | |
14 | 169 m_scrolledWindow->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PreviewDialog::OnWheel ), NULL, this ); |
170 m_bitmap->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( PreviewDialog::OnDClick ), NULL, this ); | |
9 | 171 } |
172 | |
173 // Event Table | |
174 BEGIN_EVENT_TABLE( PreviewDialog, wxDialog ) | |
14 | 175 EVT_BUTTON( ID_PRINT, PreviewDialog::OnPrint ) |
9 | 176 END_EVENT_TABLE() |
177 | |
178 #define WIDTH 2480 | |
179 #define HEIGHT 3509 | |
10 | 180 void PreviewDialog::SetPreviewImage( int n ) |
9 | 181 { |
14 | 182 m_preview = m_imagefiles[n]; |
183 m_zoom = 1.0; | |
184 SetZoom( m_zoom ); | |
9 | 185 |
14 | 186 // file info |
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
187 float z; |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
188 long l; |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
189 GetScore( &z, &l, m_imagefiles[n] ); |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
190 wxString info = m_imagefiles[n].AfterLast( wxFILE_SEP_PATH ); |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
191 info += wxString::Format( wxT("\n%z = %f"), z ); |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
192 info += wxString::Format( wxT("\n%l = %ld"), l ); |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
193 m_textInfo->SetValue( info ); |
10 | 194 } |
195 | |
14 | 196 void PreviewDialog::SetZoom( float zoom ) |
197 { | |
198 int w, h; | |
199 m_scrolledWindow->GetSize( &w, &h ); | |
200 w = (int)( zoom * h * WIDTH / HEIGHT ); | |
201 h = (int)( zoom * h ); | |
202 | |
203 m_bitmap->SetBitmap( wxNullBitmap ); | |
204 wxImage img; | |
205 img.LoadFile( m_preview, wxBITMAP_TYPE_JPEG ); | |
206 wxBitmap bmp( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ); | |
207 m_bitmap->SetBitmap( bmp ); | |
208 m_bitmap->Centre( wxHORIZONTAL ); | |
209 | |
210 m_scrolledWindow->Scroll( 0, 0 ); | |
211 m_scrolledWindow->SetScrollbars( 10, 10, 0, h/10 ); | |
212 } | |
213 | |
13 | 214 void PreviewDialog::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles, int select ) |
10 | 215 { |
216 m_imagefiles = imagefiles; | |
217 m_cachefiles = cachefiles; | |
13 | 218 m_thumbPanel->SetFiles( m_imagefiles, m_cachefiles, select ); |
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
219 |
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
220 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
|
221 this->SetTitle( title ); |
9 | 222 } |
223 | |
14 | 224 void PreviewDialog::OnWheel( wxMouseEvent& event ) |
225 { | |
226 if ( event.ControlDown() ) { | |
227 if ( event.GetWheelRotation() < 0 ) { | |
228 if ( m_zoom > 2.1 ) return; | |
229 m_zoom *= 1.3; | |
230 } | |
231 else { | |
232 if ( m_zoom <= 1.0 ) return; | |
233 m_zoom /= 1.3; | |
234 } | |
235 SetZoom( m_zoom ); | |
236 return; | |
237 } | |
238 event.Skip(); | |
239 } | |
240 | |
241 void PreviewDialog::OnDClick( wxMouseEvent& WXUNUSED(event) ) | |
242 { | |
243 if ( m_zoom > 2.1 ) m_zoom = 1.0; | |
244 else m_zoom *= 1.3; | |
245 | |
246 SetZoom( m_zoom ); | |
247 } | |
248 | |
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
249 void PreviewDialog::OnPrint( wxCommandEvent& WXUNUSED(event) ) |
9 | 250 { |
251 wxString html; | |
252 html = html + wxT("<html><body>\n"); | |
253 | |
254 wxString tmpjpg = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH + wxT("preview.jpg"); | |
255 | |
256 wxCopyFile( m_preview, tmpjpg, true ); | |
257 | |
258 html = html + wxT("<img src=\"") + tmpjpg + wxT("\" width=\"750\" height=\"1060\"/>"); | |
259 html = html + wxT("</body></html>"); | |
260 | |
261 // start printing | |
262 wxHtmlPrintout hpout( wxT("Searcher03") ); | |
263 hpout.SetMargins( 0, 0, 0, 0, 0 ); | |
264 wxPrintDialogData pd; | |
265 wxPrinter p( &pd ); | |
266 | |
267 hpout.SetHtmlText( html, wxEmptyString, false ); | |
268 p.Print( NULL, &hpout, true ); | |
269 } | |
270 |