comparison src/preview.cpp @ 15:de222bc84e48

Implement Mouse Gesture in Preview Dialog.
author pyon@macmini
date Sun, 15 Jun 2014 16:45:52 +0900
parents ac17a73e39b3
children 92188f60323d
comparison
equal deleted inserted replaced
14:ac17a73e39b3 15:de222bc84e48
1 // Filename : preview.cpp 1 // Filename : preview.cpp
2 // Last Change: 04-Jun-2014. 2 // Last Change: 11-Jun-2014.
3 // 3 //
4 4
5 #include "marksheet.h" 5 #include "marksheet.h"
6 #include "preview.h" 6 #include "preview.h"
7 #define THUMB_W 60 7 #define THUMB_W 60
56 m_bitmap4->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick4 ), 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 ); 57 m_bitmap5->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick5 ), NULL, this );
58 } 58 }
59 59
60 // Functions 60 // Functions
61 /* サムネイル表示 */ 61 /* サムネイル画像作成 */
62 void PThumbnailPanel::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles, int select ) 62 void PThumbnailPanel::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles, int select )
63 { 63 {
64 m_imagefiles = imagefiles; 64 m_imagefiles = imagefiles;
65 65
66 wxBitmap bmp; 66 wxBitmap bmp;
133 : wxDialog( parent, id, title, pos, size, style ) 133 : wxDialog( parent, id, title, pos, size, style )
134 { 134 {
135 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL ); 135 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL );
136 136
137 m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL|wxALWAYS_SHOW_SB ); 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 ); 138 m_scrolledWindow->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PreviewDialog::OnWheel ), NULL, this );
139 m_bitmap = new wxStaticBitmap( m_scrolledWindow, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); 139 m_bitmap = new wxStaticBitmap( m_scrolledWindow, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
140 m_bitmap->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( PreviewDialog::OnDClick ), NULL, this ); 140 m_bitmap->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( PreviewDialog::OnDClick ), NULL, this );
141 m_bitmap->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( PreviewDialog::OnStartRGesture ), NULL, this );
142 m_bitmap->Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( PreviewDialog::OnEndRGesture ), NULL, this );
141 bSizerTop->Add( m_scrolledWindow, 1, wxALL|wxEXPAND, 5 ); 143 bSizerTop->Add( m_scrolledWindow, 1, wxALL|wxEXPAND, 5 );
142 144
143 wxBoxSizer* bSizerMenu = new wxBoxSizer( wxVERTICAL ); 145 wxBoxSizer* bSizerMenu = new wxBoxSizer( wxVERTICAL );
144 146
145 m_thumbPanel = new PThumbnailPanel( this, wxID_ANY, wxDefaultPosition, wxSize( 100, -1 ), wxSUNKEN_BORDER ); 147 m_thumbPanel = new PThumbnailPanel( this, wxID_ANY, wxDefaultPosition, wxSize( 100, -1 ), wxSUNKEN_BORDER );
164 this->Layout(); 166 this->Layout();
165 } 167 }
166 168
167 PreviewDialog::~PreviewDialog() 169 PreviewDialog::~PreviewDialog()
168 { 170 {
169 m_scrolledWindow->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PreviewDialog::OnWheel ), NULL, this ); 171 m_scrolledWindow->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PreviewDialog::OnWheel ), NULL, this );
170 m_bitmap->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( PreviewDialog::OnDClick ), NULL, this ); 172 m_bitmap->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( PreviewDialog::OnDClick ), NULL, this );
173 m_bitmap->Disconnect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( PreviewDialog::OnStartRGesture ), NULL, this );
174 m_bitmap->Disconnect( wxEVT_RIGHT_UP, wxMouseEventHandler( PreviewDialog::OnEndRGesture ), NULL, this );
171 } 175 }
172 176
173 // Event Table 177 // Event Table
174 BEGIN_EVENT_TABLE( PreviewDialog, wxDialog ) 178 BEGIN_EVENT_TABLE( PreviewDialog, wxDialog )
175 EVT_BUTTON( ID_PRINT, PreviewDialog::OnPrint ) 179 EVT_BUTTON( ID_PRINT, PreviewDialog::OnPrint )
176 END_EVENT_TABLE() 180 END_EVENT_TABLE()
177 181
178 #define WIDTH 2480 182 #define WIDTH 2480
179 #define HEIGHT 3509 183 #define HEIGHT 3509
184 /* プレビューするファイルをセット */
180 void PreviewDialog::SetPreviewImage( int n ) 185 void PreviewDialog::SetPreviewImage( int n )
181 { 186 {
182 m_preview = m_imagefiles[n]; 187 m_preview = n;
183 m_zoom = 1.0; 188 m_zoom = 1.0;
184 SetZoom( m_zoom ); 189 SetZoom( m_zoom );
185 190
186 // file info 191 // file info
187 float z; 192 float z;
191 info += wxString::Format( wxT("\n%z = %f"), z ); 196 info += wxString::Format( wxT("\n%z = %f"), z );
192 info += wxString::Format( wxT("\n%l = %ld"), l ); 197 info += wxString::Format( wxT("\n%l = %ld"), l );
193 m_textInfo->SetValue( info ); 198 m_textInfo->SetValue( info );
194 } 199 }
195 200
201 /* 倍率を指定しロード */
196 void PreviewDialog::SetZoom( float zoom ) 202 void PreviewDialog::SetZoom( float zoom )
197 { 203 {
198 int w, h; 204 int w, h;
199 m_scrolledWindow->GetSize( &w, &h ); 205 m_scrolledWindow->GetSize( &w, &h );
200 w = (int)( zoom * h * WIDTH / HEIGHT ); 206 w = (int)( zoom * h * WIDTH / HEIGHT );
201 h = (int)( zoom * h ); 207 h = (int)( zoom * h );
202 208
203 m_bitmap->SetBitmap( wxNullBitmap ); 209 m_bitmap->SetBitmap( wxNullBitmap );
204 wxImage img; 210 wxImage img;
205 img.LoadFile( m_preview, wxBITMAP_TYPE_JPEG ); 211 img.LoadFile( m_imagefiles[m_preview], wxBITMAP_TYPE_JPEG );
206 wxBitmap bmp( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ); 212 wxBitmap bmp( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) );
207 m_bitmap->SetBitmap( bmp ); 213 m_bitmap->SetBitmap( bmp );
208 m_bitmap->Centre( wxHORIZONTAL ); 214 m_bitmap->Centre( wxHORIZONTAL );
209 215
210 m_scrolledWindow->Scroll( 0, 0 ); 216 m_scrolledWindow->Scroll( 0, 0 );
211 m_scrolledWindow->SetScrollbars( 10, 10, 0, h/10 ); 217 m_scrolledWindow->SetScrollbars( 10, 10, 0, h/10 );
212 } 218 }
213 219
220 /* ファイル名を保持 */
214 void PreviewDialog::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles, int select ) 221 void PreviewDialog::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles, int select )
215 { 222 {
216 m_imagefiles = imagefiles; 223 m_imagefiles = imagefiles;
217 m_cachefiles = cachefiles; 224 m_cachefiles = cachefiles;
218 m_thumbPanel->SetFiles( m_imagefiles, m_cachefiles, select ); 225 m_thumbPanel->SetFiles( m_imagefiles, m_cachefiles, select );
219 226
220 wxString title = wxT("プレビュー @ ") + m_imagefiles[0].BeforeLast( wxFILE_SEP_PATH ); 227 wxString title = wxT("プレビュー @ ") + m_imagefiles[0].BeforeLast( wxFILE_SEP_PATH );
221 this->SetTitle( title ); 228 this->SetTitle( title );
222 } 229 }
223 230
231 /* コントロールキー + マウスホイール で画像を拡大・縮小 */
224 void PreviewDialog::OnWheel( wxMouseEvent& event ) 232 void PreviewDialog::OnWheel( wxMouseEvent& event )
225 { 233 {
226 if ( event.ControlDown() ) { 234 if ( event.ControlDown() ) {
227 if ( event.GetWheelRotation() < 0 ) { 235 if ( event.GetWheelRotation() < 0 ) {
228 if ( m_zoom > 2.1 ) return; 236 if ( m_zoom > 2.1 ) return;
236 return; 244 return;
237 } 245 }
238 event.Skip(); 246 event.Skip();
239 } 247 }
240 248
249 /* 画像のダブルクリックで倍率変更 */
241 void PreviewDialog::OnDClick( wxMouseEvent& WXUNUSED(event) ) 250 void PreviewDialog::OnDClick( wxMouseEvent& WXUNUSED(event) )
242 { 251 {
243 if ( m_zoom > 2.1 ) m_zoom = 1.0; 252 if ( m_zoom > 2.1 ) m_zoom = 1.0;
244 else m_zoom *= 1.3; 253 else m_zoom *= 1.3;
245 254
246 SetZoom( m_zoom ); 255 SetZoom( m_zoom );
247 } 256 }
248 257
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 /* 印刷 */
249 void PreviewDialog::OnPrint( wxCommandEvent& WXUNUSED(event) ) 298 void PreviewDialog::OnPrint( wxCommandEvent& WXUNUSED(event) )
250 { 299 {
251 wxString html; 300 wxString html;
252 html = html + wxT("<html><body>\n"); 301 html = html + wxT("<html><body>\n");
253 302
254 wxString tmpjpg = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH + wxT("preview.jpg"); 303 wxString tmpjpg = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH + wxT("preview.jpg");
255 304
256 wxCopyFile( m_preview, tmpjpg, true ); 305 wxCopyFile( m_imagefiles[m_preview], tmpjpg, true );
257 306
258 html = html + wxT("<img src=\"") + tmpjpg + wxT("\" width=\"750\" height=\"1060\"/>"); 307 html = html + wxT("<img src=\"") + tmpjpg + wxT("\" width=\"750\" height=\"1060\"/>");
259 html = html + wxT("</body></html>"); 308 html = html + wxT("</body></html>");
260 309
261 // start printing 310 // start printing