Mercurial > mercurial > hgweb_searcher03.cgi
annotate src/preview.cpp @ 12:52958cd4a073
Implement Force Mask button in Batch Print Mode.
| author | pyon@macmini |
|---|---|
| date | Sun, 18 May 2014 19:49:15 +0900 |
| parents | dfcf8c973219 |
| children | bbd65edf71d4 |
| rev | line source |
|---|---|
| 9 | 1 // Filename : preview.cpp |
|
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
2 // Last Change: 16-May-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 /* サムネイル表示 */ | |
| 62 void PThumbnailPanel::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles ) | |
| 63 { | |
| 64 m_imagefiles = imagefiles; | |
| 65 | |
| 66 wxBitmap bmp; | |
| 67 bmp.LoadFile( cachefiles[0], wxBITMAP_TYPE_PNG ); m_bitmap0->SetBitmap( bmp ); | |
| 68 bmp.LoadFile( cachefiles[1], wxBITMAP_TYPE_PNG ); m_bitmap1->SetBitmap( bmp ); | |
| 69 bmp.LoadFile( cachefiles[2], wxBITMAP_TYPE_PNG ); m_bitmap2->SetBitmap( bmp ); | |
| 70 bmp.LoadFile( cachefiles[3], wxBITMAP_TYPE_PNG ); m_bitmap3->SetBitmap( bmp ); | |
| 71 bmp.LoadFile( cachefiles[4], wxBITMAP_TYPE_PNG ); m_bitmap4->SetBitmap( bmp ); | |
| 72 bmp.LoadFile( cachefiles[5], wxBITMAP_TYPE_PNG ); m_bitmap5->SetBitmap( bmp ); | |
| 73 } | |
| 74 /* 画像クリックで拡大表示 */ | |
| 75 void PThumbnailPanel::OnClick0( wxMouseEvent& WXUNUSED(event) ) { Preview( 0 ); } | |
| 76 void PThumbnailPanel::OnClick1( wxMouseEvent& WXUNUSED(event) ) { Preview( 1 ); } | |
| 77 void PThumbnailPanel::OnClick2( wxMouseEvent& WXUNUSED(event) ) { Preview( 2 ); } | |
| 78 void PThumbnailPanel::OnClick3( wxMouseEvent& WXUNUSED(event) ) { Preview( 3 ); } | |
| 79 void PThumbnailPanel::OnClick4( wxMouseEvent& WXUNUSED(event) ) { Preview( 4 ); } | |
| 80 void PThumbnailPanel::OnClick5( wxMouseEvent& WXUNUSED(event) ) { Preview( 5 ); } | |
| 81 void PThumbnailPanel::Preview( int n ) | |
| 82 { | |
| 83 if ( m_imagefiles.GetCount() < n + 1 ) return; | |
| 84 m_parent->SetPreviewImage( n ); | |
| 85 } | |
| 86 | |
| 87 | |
| 88 //////////////////////////////////////////////////////// | |
| 89 // プレビューダイアログ | |
| 9 | 90 PreviewDialog::PreviewDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) |
| 91 : wxDialog( parent, id, title, pos, size, style ) | |
| 92 { | |
| 93 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL ); | |
| 94 | |
| 95 m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxALWAYS_SHOW_SB ); | |
| 96 m_bitmap = new wxStaticBitmap( m_scrolledWindow, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); | |
| 97 bSizerTop->Add( m_scrolledWindow, 1, wxALL|wxEXPAND, 5 ); | |
| 98 | |
| 99 wxBoxSizer* bSizerMenu = new wxBoxSizer( wxVERTICAL ); | |
| 100 | |
| 10 | 101 m_thumbPanel = new PThumbnailPanel( this, wxID_ANY, wxDefaultPosition, wxSize( 100, -1 ), wxSUNKEN_BORDER ); |
| 102 bSizerMenu->Add( m_thumbPanel, 0, wxALL|wxEXPAND, 5 ); | |
| 9 | 103 |
|
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
104 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
|
105 m_textInfo->SetBackgroundColour( wxColour( 192, 192, 192 ) ); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
106 bSizerMenu->Add( m_textInfo, 0, wxRIGHT|wxLEFT|wxBOTTOM, 5 ); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
107 |
| 9 | 108 m_buttonPrint = new wxButton( this, ID_PRINT, wxT("印刷"), wxDefaultPosition, wxDefaultSize, 0 ); |
| 109 bSizerMenu->Add( m_buttonPrint, 0, wxALL, 5 ); | |
|
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
110 |
| 11 | 111 bSizerMenu->Add( 0, 0, 0, 0, 5 ); |
| 9 | 112 |
| 113 m_buttonClose = new wxButton( this, wxID_CANCEL, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 ); | |
| 114 m_buttonClose->SetDefault(); | |
| 115 bSizerMenu->Add( m_buttonClose, 0, wxALL, 5 ); | |
| 116 | |
| 117 bSizerTop->Add( bSizerMenu, 0, wxALL|wxEXPAND, 5 ); | |
| 118 | |
| 119 this->SetSizer( bSizerTop ); | |
| 120 this->Layout(); | |
| 121 } | |
| 122 | |
| 123 PreviewDialog::~PreviewDialog() | |
| 124 { | |
| 125 } | |
| 126 | |
| 127 // Event Table | |
| 128 BEGIN_EVENT_TABLE( PreviewDialog, wxDialog ) | |
|
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
129 EVT_BUTTON( ID_PRINT, PreviewDialog::OnPrint ) |
| 9 | 130 END_EVENT_TABLE() |
| 131 | |
| 132 #define WIDTH 2480 | |
| 133 #define HEIGHT 3509 | |
| 10 | 134 void PreviewDialog::SetPreviewImage( int n ) |
| 9 | 135 { |
| 136 int w, h; | |
| 137 m_scrolledWindow->GetSize( &w, &h ); | |
| 138 h = h * WIDTH / ( w - 200 ); | |
| 139 | |
| 140 wxImage img; | |
| 10 | 141 img.LoadFile( m_imagefiles[n], wxBITMAP_TYPE_JPEG ); |
| 9 | 142 wxBitmap bmp( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ); |
| 143 m_bitmap->SetBitmap( bmp ); | |
| 144 | |
| 11 | 145 m_scrolledWindow->Scroll( 0, 0 ); |
| 9 | 146 m_scrolledWindow->SetScrollbars( 10, 10, 0, h/10 ); |
| 10 | 147 m_preview = m_imagefiles[n]; |
|
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
148 |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
149 // |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
150 float z; |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
151 long l; |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
152 GetScore( &z, &l, m_imagefiles[n] ); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
153 wxString info = m_imagefiles[n].AfterLast( wxFILE_SEP_PATH ); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
154 info += wxString::Format( wxT("\n%z = %f"), z ); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
155 info += wxString::Format( wxT("\n%l = %ld"), l ); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
156 m_textInfo->SetValue( info ); |
| 10 | 157 } |
| 158 | |
| 159 void PreviewDialog::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles ) | |
| 160 { | |
| 161 m_imagefiles = imagefiles; | |
| 162 m_cachefiles = cachefiles; | |
| 163 m_thumbPanel->SetFiles( m_imagefiles, m_cachefiles ); | |
|
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
164 |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
165 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
|
166 this->SetTitle( title ); |
| 9 | 167 } |
| 168 | |
|
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
169 void PreviewDialog::OnPrint( wxCommandEvent& WXUNUSED(event) ) |
| 9 | 170 { |
| 171 wxString html; | |
| 172 html = html + wxT("<html><body>\n"); | |
| 173 | |
| 174 wxString tmpjpg = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH + wxT("preview.jpg"); | |
| 175 | |
| 176 wxCopyFile( m_preview, tmpjpg, true ); | |
| 177 | |
| 178 html = html + wxT("<img src=\"") + tmpjpg + wxT("\" width=\"750\" height=\"1060\"/>"); | |
| 179 html = html + wxT("</body></html>"); | |
| 180 | |
| 181 // start printing | |
| 182 wxHtmlPrintout hpout( wxT("Searcher03") ); | |
| 183 hpout.SetMargins( 0, 0, 0, 0, 0 ); | |
| 184 wxPrintDialogData pd; | |
| 185 wxPrinter p( &pd ); | |
| 186 | |
| 187 hpout.SetHtmlText( html, wxEmptyString, false ); | |
| 188 p.Print( NULL, &hpout, true ); | |
| 189 } | |
| 190 |
