Mercurial > mercurial > hgweb_searcher03.cgi
annotate src/preview.cpp @ 13:bbd65edf71d4
Implement Hhs DB update dialog.
| author | pyon@macmini |
|---|---|
| date | Sat, 24 May 2014 10:25:13 +0900 |
| parents | 52958cd4a073 |
| children | ac17a73e39b3 |
| rev | line source |
|---|---|
| 9 | 1 // Filename : preview.cpp |
| 13 | 2 // Last Change: 23-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 /* サムネイル表示 */ | |
| 13 | 62 void PThumbnailPanel::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles, int select ) |
| 10 | 63 { |
| 64 m_imagefiles = imagefiles; | |
| 65 | |
| 66 wxBitmap bmp; | |
| 13 | 67 m_imageList.Create( THUMB_W, THUMB_H ); |
| 68 | |
| 69 bmp.LoadFile( cachefiles[0], wxBITMAP_TYPE_PNG ); m_imageList.Add( bmp ); | |
| 70 bmp.LoadFile( cachefiles[1], wxBITMAP_TYPE_PNG ); m_imageList.Add( bmp ); | |
| 71 bmp.LoadFile( cachefiles[2], wxBITMAP_TYPE_PNG ); m_imageList.Add( bmp ); | |
| 72 bmp.LoadFile( cachefiles[3], wxBITMAP_TYPE_PNG ); m_imageList.Add( bmp ); | |
| 73 bmp.LoadFile( cachefiles[4], wxBITMAP_TYPE_PNG ); m_imageList.Add( bmp ); | |
| 74 bmp.LoadFile( cachefiles[5], wxBITMAP_TYPE_PNG ); m_imageList.Add( bmp ); | |
| 75 SetImageList( select ); | |
| 10 | 76 } |
| 77 /* 画像クリックで拡大表示 */ | |
| 78 void PThumbnailPanel::OnClick0( wxMouseEvent& WXUNUSED(event) ) { Preview( 0 ); } | |
| 79 void PThumbnailPanel::OnClick1( wxMouseEvent& WXUNUSED(event) ) { Preview( 1 ); } | |
| 80 void PThumbnailPanel::OnClick2( wxMouseEvent& WXUNUSED(event) ) { Preview( 2 ); } | |
| 81 void PThumbnailPanel::OnClick3( wxMouseEvent& WXUNUSED(event) ) { Preview( 3 ); } | |
| 82 void PThumbnailPanel::OnClick4( wxMouseEvent& WXUNUSED(event) ) { Preview( 4 ); } | |
| 83 void PThumbnailPanel::OnClick5( wxMouseEvent& WXUNUSED(event) ) { Preview( 5 ); } | |
| 84 void PThumbnailPanel::Preview( int n ) | |
| 85 { | |
| 86 if ( m_imagefiles.GetCount() < n + 1 ) return; | |
| 13 | 87 SetImageList( n ); |
| 10 | 88 m_parent->SetPreviewImage( n ); |
| 89 } | |
| 13 | 90 /* サムネイル表示 */ |
| 91 void PThumbnailPanel::SetImageList( int selected ) | |
| 92 { | |
| 93 m_bitmap0->SetBitmap( m_imageList.GetBitmap(0) ); | |
| 94 m_bitmap1->SetBitmap( m_imageList.GetBitmap(1) ); | |
| 95 m_bitmap2->SetBitmap( m_imageList.GetBitmap(2) ); | |
| 96 m_bitmap3->SetBitmap( m_imageList.GetBitmap(3) ); | |
| 97 m_bitmap4->SetBitmap( m_imageList.GetBitmap(4) ); | |
| 98 m_bitmap5->SetBitmap( m_imageList.GetBitmap(5) ); | |
| 10 | 99 |
| 13 | 100 wxImage image = m_imageList.GetBitmap( selected ).ConvertToImage(); |
| 101 unsigned char *data = image.GetData(); | |
| 102 for ( int y = 0; y < THUMB_H; y++ ) | |
| 103 for ( int x = 0; x <THUMB_W; x++ ) | |
| 104 data[ ( y * THUMB_W + x ) * 3 + 2 ] = 255; // 文字色:黒(0,0,0)->青(0,0,255) | |
| 105 | |
| 106 wxBitmap bmp_mask( image ); | |
| 107 | |
| 108 switch ( selected ) { | |
| 109 case 0: | |
| 110 m_bitmap0->SetBitmap( bmp_mask ); | |
| 111 break; | |
| 112 case 1: | |
| 113 m_bitmap1->SetBitmap( bmp_mask ); | |
| 114 break; | |
| 115 case 2: | |
| 116 m_bitmap2->SetBitmap( bmp_mask ); | |
| 117 break; | |
| 118 case 3: | |
| 119 m_bitmap3->SetBitmap( bmp_mask ); | |
| 120 break; | |
| 121 case 4: | |
| 122 m_bitmap4->SetBitmap( bmp_mask ); | |
| 123 break; | |
| 124 case 5: | |
| 125 m_bitmap5->SetBitmap( bmp_mask ); | |
| 126 break; | |
| 127 } | |
| 128 } | |
| 10 | 129 |
| 130 //////////////////////////////////////////////////////// | |
| 131 // プレビューダイアログ | |
| 9 | 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 ) | |
| 134 { | |
| 135 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL ); | |
| 136 | |
| 137 m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxALWAYS_SHOW_SB ); | |
| 138 m_bitmap = new wxStaticBitmap( m_scrolledWindow, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); | |
| 139 bSizerTop->Add( m_scrolledWindow, 1, wxALL|wxEXPAND, 5 ); | |
| 140 | |
| 141 wxBoxSizer* bSizerMenu = new wxBoxSizer( wxVERTICAL ); | |
| 142 | |
| 10 | 143 m_thumbPanel = new PThumbnailPanel( this, wxID_ANY, wxDefaultPosition, wxSize( 100, -1 ), wxSUNKEN_BORDER ); |
| 144 bSizerMenu->Add( m_thumbPanel, 0, wxALL|wxEXPAND, 5 ); | |
| 9 | 145 |
|
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
146 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
|
147 m_textInfo->SetBackgroundColour( wxColour( 192, 192, 192 ) ); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
148 bSizerMenu->Add( m_textInfo, 0, wxRIGHT|wxLEFT|wxBOTTOM, 5 ); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
149 |
| 9 | 150 m_buttonPrint = new wxButton( this, ID_PRINT, wxT("印刷"), wxDefaultPosition, wxDefaultSize, 0 ); |
| 151 bSizerMenu->Add( m_buttonPrint, 0, wxALL, 5 ); | |
|
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
152 |
| 11 | 153 bSizerMenu->Add( 0, 0, 0, 0, 5 ); |
| 9 | 154 |
| 155 m_buttonClose = new wxButton( this, wxID_CANCEL, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 ); | |
| 156 m_buttonClose->SetDefault(); | |
| 157 bSizerMenu->Add( m_buttonClose, 0, wxALL, 5 ); | |
| 158 | |
| 159 bSizerTop->Add( bSizerMenu, 0, wxALL|wxEXPAND, 5 ); | |
| 160 | |
| 161 this->SetSizer( bSizerTop ); | |
| 162 this->Layout(); | |
| 163 } | |
| 164 | |
| 165 PreviewDialog::~PreviewDialog() | |
| 166 { | |
| 167 } | |
| 168 | |
| 169 // Event Table | |
| 170 BEGIN_EVENT_TABLE( PreviewDialog, wxDialog ) | |
|
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
171 EVT_BUTTON( ID_PRINT, PreviewDialog::OnPrint ) |
| 9 | 172 END_EVENT_TABLE() |
| 173 | |
| 174 #define WIDTH 2480 | |
| 175 #define HEIGHT 3509 | |
| 10 | 176 void PreviewDialog::SetPreviewImage( int n ) |
| 9 | 177 { |
| 178 int w, h; | |
| 179 m_scrolledWindow->GetSize( &w, &h ); | |
| 180 h = h * WIDTH / ( w - 200 ); | |
| 181 | |
| 182 wxImage img; | |
| 10 | 183 img.LoadFile( m_imagefiles[n], wxBITMAP_TYPE_JPEG ); |
| 9 | 184 wxBitmap bmp( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ); |
| 185 m_bitmap->SetBitmap( bmp ); | |
| 186 | |
| 11 | 187 m_scrolledWindow->Scroll( 0, 0 ); |
| 9 | 188 m_scrolledWindow->SetScrollbars( 10, 10, 0, h/10 ); |
| 10 | 189 m_preview = m_imagefiles[n]; |
|
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
190 |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
191 // |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
192 float z; |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
193 long l; |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
194 GetScore( &z, &l, m_imagefiles[n] ); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
195 wxString info = m_imagefiles[n].AfterLast( wxFILE_SEP_PATH ); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
196 info += wxString::Format( wxT("\n%z = %f"), z ); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
197 info += wxString::Format( wxT("\n%l = %ld"), l ); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
198 m_textInfo->SetValue( info ); |
| 10 | 199 } |
| 200 | |
| 13 | 201 void PreviewDialog::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles, int select ) |
| 10 | 202 { |
| 203 m_imagefiles = imagefiles; | |
| 204 m_cachefiles = cachefiles; | |
| 13 | 205 m_thumbPanel->SetFiles( m_imagefiles, m_cachefiles, select ); |
|
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
206 |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
207 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
|
208 this->SetTitle( title ); |
| 9 | 209 } |
| 210 | |
|
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
11
diff
changeset
|
211 void PreviewDialog::OnPrint( wxCommandEvent& WXUNUSED(event) ) |
| 9 | 212 { |
| 213 wxString html; | |
| 214 html = html + wxT("<html><body>\n"); | |
| 215 | |
| 216 wxString tmpjpg = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH + wxT("preview.jpg"); | |
| 217 | |
| 218 wxCopyFile( m_preview, tmpjpg, true ); | |
| 219 | |
| 220 html = html + wxT("<img src=\"") + tmpjpg + wxT("\" width=\"750\" height=\"1060\"/>"); | |
| 221 html = html + wxT("</body></html>"); | |
| 222 | |
| 223 // start printing | |
| 224 wxHtmlPrintout hpout( wxT("Searcher03") ); | |
| 225 hpout.SetMargins( 0, 0, 0, 0, 0 ); | |
| 226 wxPrintDialogData pd; | |
| 227 wxPrinter p( &pd ); | |
| 228 | |
| 229 hpout.SetHtmlText( html, wxEmptyString, false ); | |
| 230 p.Print( NULL, &hpout, true ); | |
| 231 } | |
| 232 |
