Mercurial > mercurial > hgweb_searcher03.cgi
comparison 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 |
comparison
equal
deleted
inserted
replaced
13:bbd65edf71d4 | 14:ac17a73e39b3 |
---|---|
1 // Filename : preview.cpp | 1 // Filename : preview.cpp |
2 // Last Change: 23-May-2014. | 2 // Last Change: 04-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 |
132 PreviewDialog::PreviewDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) | 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 ) | 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, 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_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 ); | |
139 bSizerTop->Add( m_scrolledWindow, 1, wxALL|wxEXPAND, 5 ); | 141 bSizerTop->Add( m_scrolledWindow, 1, wxALL|wxEXPAND, 5 ); |
140 | 142 |
141 wxBoxSizer* bSizerMenu = new wxBoxSizer( wxVERTICAL ); | 143 wxBoxSizer* bSizerMenu = new wxBoxSizer( wxVERTICAL ); |
142 | 144 |
143 m_thumbPanel = new PThumbnailPanel( this, wxID_ANY, wxDefaultPosition, wxSize( 100, -1 ), wxSUNKEN_BORDER ); | 145 m_thumbPanel = new PThumbnailPanel( this, wxID_ANY, wxDefaultPosition, wxSize( 100, -1 ), wxSUNKEN_BORDER ); |
162 this->Layout(); | 164 this->Layout(); |
163 } | 165 } |
164 | 166 |
165 PreviewDialog::~PreviewDialog() | 167 PreviewDialog::~PreviewDialog() |
166 { | 168 { |
169 m_scrolledWindow->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PreviewDialog::OnWheel ), NULL, this ); | |
170 m_bitmap->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( PreviewDialog::OnDClick ), NULL, this ); | |
167 } | 171 } |
168 | 172 |
169 // Event Table | 173 // Event Table |
170 BEGIN_EVENT_TABLE( PreviewDialog, wxDialog ) | 174 BEGIN_EVENT_TABLE( PreviewDialog, wxDialog ) |
171 EVT_BUTTON( ID_PRINT, PreviewDialog::OnPrint ) | 175 EVT_BUTTON( ID_PRINT, PreviewDialog::OnPrint ) |
172 END_EVENT_TABLE() | 176 END_EVENT_TABLE() |
173 | 177 |
174 #define WIDTH 2480 | 178 #define WIDTH 2480 |
175 #define HEIGHT 3509 | 179 #define HEIGHT 3509 |
176 void PreviewDialog::SetPreviewImage( int n ) | 180 void PreviewDialog::SetPreviewImage( int n ) |
177 { | 181 { |
178 int w, h; | |
179 m_scrolledWindow->GetSize( &w, &h ); | |
180 h = h * WIDTH / ( w - 200 ); | |
181 | |
182 wxImage img; | |
183 img.LoadFile( m_imagefiles[n], wxBITMAP_TYPE_JPEG ); | |
184 wxBitmap bmp( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ); | |
185 m_bitmap->SetBitmap( bmp ); | |
186 | |
187 m_scrolledWindow->Scroll( 0, 0 ); | |
188 m_scrolledWindow->SetScrollbars( 10, 10, 0, h/10 ); | |
189 m_preview = m_imagefiles[n]; | 182 m_preview = m_imagefiles[n]; |
190 | 183 m_zoom = 1.0; |
191 // | 184 SetZoom( m_zoom ); |
185 | |
186 // file info | |
192 float z; | 187 float z; |
193 long l; | 188 long l; |
194 GetScore( &z, &l, m_imagefiles[n] ); | 189 GetScore( &z, &l, m_imagefiles[n] ); |
195 wxString info = m_imagefiles[n].AfterLast( wxFILE_SEP_PATH ); | 190 wxString info = m_imagefiles[n].AfterLast( wxFILE_SEP_PATH ); |
196 info += wxString::Format( wxT("\n%z = %f"), z ); | 191 info += wxString::Format( wxT("\n%z = %f"), z ); |
197 info += wxString::Format( wxT("\n%l = %ld"), l ); | 192 info += wxString::Format( wxT("\n%l = %ld"), l ); |
198 m_textInfo->SetValue( info ); | 193 m_textInfo->SetValue( info ); |
199 } | 194 } |
200 | 195 |
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 | |
201 void PreviewDialog::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles, int select ) | 214 void PreviewDialog::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles, int select ) |
202 { | 215 { |
203 m_imagefiles = imagefiles; | 216 m_imagefiles = imagefiles; |
204 m_cachefiles = cachefiles; | 217 m_cachefiles = cachefiles; |
205 m_thumbPanel->SetFiles( m_imagefiles, m_cachefiles, select ); | 218 m_thumbPanel->SetFiles( m_imagefiles, m_cachefiles, select ); |
206 | 219 |
207 wxString title = wxT("プレビュー @ ") + m_imagefiles[0].BeforeLast( wxFILE_SEP_PATH ); | 220 wxString title = wxT("プレビュー @ ") + m_imagefiles[0].BeforeLast( wxFILE_SEP_PATH ); |
208 this->SetTitle( title ); | 221 this->SetTitle( title ); |
209 } | 222 } |
210 | 223 |
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 | |
211 void PreviewDialog::OnPrint( wxCommandEvent& WXUNUSED(event) ) | 249 void PreviewDialog::OnPrint( wxCommandEvent& WXUNUSED(event) ) |
212 { | 250 { |
213 wxString html; | 251 wxString html; |
214 html = html + wxT("<html><body>\n"); | 252 html = html + wxT("<html><body>\n"); |
215 | 253 |