Mercurial > mercurial > hgweb_searcher03.cgi
diff 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 |
line wrap: on
line diff
--- a/src/preview.cpp Sat May 24 10:25:13 2014 +0900 +++ b/src/preview.cpp Thu Jun 05 04:19:03 2014 +0900 @@ -1,5 +1,5 @@ // Filename : preview.cpp -// Last Change: 23-May-2014. +// Last Change: 04-Jun-2014. // #include "marksheet.h" @@ -134,8 +134,10 @@ { wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL ); - m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxALWAYS_SHOW_SB ); + m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL|wxALWAYS_SHOW_SB ); + m_scrolledWindow->Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PreviewDialog::OnWheel ), NULL, this ); m_bitmap = new wxStaticBitmap( m_scrolledWindow, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); + m_bitmap->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( PreviewDialog::OnDClick ), NULL, this ); bSizerTop->Add( m_scrolledWindow, 1, wxALL|wxEXPAND, 5 ); wxBoxSizer* bSizerMenu = new wxBoxSizer( wxVERTICAL ); @@ -164,31 +166,24 @@ PreviewDialog::~PreviewDialog() { + m_scrolledWindow->Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( PreviewDialog::OnWheel ), NULL, this ); + m_bitmap->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( PreviewDialog::OnDClick ), NULL, this ); } // Event Table BEGIN_EVENT_TABLE( PreviewDialog, wxDialog ) - EVT_BUTTON( ID_PRINT, PreviewDialog::OnPrint ) + EVT_BUTTON( ID_PRINT, PreviewDialog::OnPrint ) END_EVENT_TABLE() #define WIDTH 2480 #define HEIGHT 3509 void PreviewDialog::SetPreviewImage( int n ) { - int w, h; - m_scrolledWindow->GetSize( &w, &h ); - h = h * WIDTH / ( w - 200 ); + m_preview = m_imagefiles[n]; + m_zoom = 1.0; + SetZoom( m_zoom ); - wxImage img; - img.LoadFile( m_imagefiles[n], wxBITMAP_TYPE_JPEG ); - wxBitmap bmp( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ); - m_bitmap->SetBitmap( bmp ); - - m_scrolledWindow->Scroll( 0, 0 ); - m_scrolledWindow->SetScrollbars( 10, 10, 0, h/10 ); - m_preview = m_imagefiles[n]; - - // + // file info float z; long l; GetScore( &z, &l, m_imagefiles[n] ); @@ -198,6 +193,24 @@ m_textInfo->SetValue( info ); } +void PreviewDialog::SetZoom( float zoom ) +{ + int w, h; + m_scrolledWindow->GetSize( &w, &h ); + w = (int)( zoom * h * WIDTH / HEIGHT ); + h = (int)( zoom * h ); + + m_bitmap->SetBitmap( wxNullBitmap ); + wxImage img; + img.LoadFile( m_preview, wxBITMAP_TYPE_JPEG ); + wxBitmap bmp( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ); + m_bitmap->SetBitmap( bmp ); + m_bitmap->Centre( wxHORIZONTAL ); + + m_scrolledWindow->Scroll( 0, 0 ); + m_scrolledWindow->SetScrollbars( 10, 10, 0, h/10 ); +} + void PreviewDialog::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles, int select ) { m_imagefiles = imagefiles; @@ -208,6 +221,31 @@ this->SetTitle( title ); } +void PreviewDialog::OnWheel( wxMouseEvent& event ) +{ + if ( event.ControlDown() ) { + if ( event.GetWheelRotation() < 0 ) { + if ( m_zoom > 2.1 ) return; + m_zoom *= 1.3; + } + else { + if ( m_zoom <= 1.0 ) return; + m_zoom /= 1.3; + } + SetZoom( m_zoom ); + return; + } + event.Skip(); +} + +void PreviewDialog::OnDClick( wxMouseEvent& WXUNUSED(event) ) +{ + if ( m_zoom > 2.1 ) m_zoom = 1.0; + else m_zoom *= 1.3; + + SetZoom( m_zoom ); +} + void PreviewDialog::OnPrint( wxCommandEvent& WXUNUSED(event) ) { wxString html;