Mercurial > mercurial > hgweb_searcher03.cgi
changeset 14:ac17a73e39b3
Zoom in / out in Preview Dialog.
author | pyon@macmini |
---|---|
date | Thu, 05 Jun 2014 04:19:03 +0900 |
parents | bbd65edf71d4 |
children | de222bc84e48 |
files | Changes include/preview.h src/preview.cpp |
diffstat | 3 files changed, 72 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Sat May 24 10:25:13 2014 +0900 +++ b/Changes Thu Jun 05 04:19:03 2014 +0900 @@ -1,3 +1,9 @@ +version 03.15 +2014-06-05 + Zoom in / out in PreviewDialog. + +---- + version 03.14 2014-05-23 Implement Hhs DB update dialog.
--- a/include/preview.h Sat May 24 10:25:13 2014 +0900 +++ b/include/preview.h Thu Jun 05 04:19:03 2014 +0900 @@ -1,5 +1,5 @@ // Filename : preview.h -// Last Change: 23-May-2014. +// Last Change: 04-Jun-2014. // #ifndef __PREVIEW_H__ @@ -29,12 +29,12 @@ PThumbnailPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ); ~PThumbnailPanel(); - void OnClick0( wxMouseEvent& event ); - void OnClick1( wxMouseEvent& event ); - void OnClick2( wxMouseEvent& event ); - void OnClick3( wxMouseEvent& event ); - void OnClick4( wxMouseEvent& event ); - void OnClick5( wxMouseEvent& event ); + void OnClick0( wxMouseEvent& WXUNUSED(event) ); + void OnClick1( wxMouseEvent& WXUNUSED(event) ); + void OnClick2( wxMouseEvent& WXUNUSED(event) ); + void OnClick3( wxMouseEvent& WXUNUSED(event) ); + void OnClick4( wxMouseEvent& WXUNUSED(event) ); + void OnClick5( wxMouseEvent& WXUNUSED(event) ); void SetFiles( wxArrayString imagefiles, wxArrayString cachefiles, int select ); void SetImageList( int selected ); void Preview( int n ); @@ -48,6 +48,7 @@ wxString m_preview; wxArrayString m_imagefiles; wxArrayString m_cachefiles; + float m_zoom; protected: wxScrolledWindow* m_scrolledWindow; @@ -63,9 +64,11 @@ ~PreviewDialog(); void SetFiles( wxArrayString imagefiles, wxArrayString cachefiles, int select ); - void SetPreviewSize( void ); + void SetZoom( float zoom ); void SetPreviewImage( int n ); - void OnPrint( wxCommandEvent& event ); + void OnWheel( wxMouseEvent& event ); + void OnDClick( wxMouseEvent& WXUNUSED(event) ); + void OnPrint( wxCommandEvent& WXUNUSED(event) ); }; enum {
--- 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;