Mercurial > mercurial > hgweb_searcher03.cgi
comparison src/preview.cpp @ 10:29021e6e1ebe
Implement thumbnail list in PreviewDialog.
author | pyon@macmini |
---|---|
date | Mon, 28 Apr 2014 18:14:04 +0900 |
parents | b455f2d8aac9 |
children | dfcf8c973219 |
comparison
equal
deleted
inserted
replaced
9:b455f2d8aac9 | 10:29021e6e1ebe |
---|---|
1 // Filename : preview.cpp | 1 // Filename : preview.cpp |
2 // Last Change: 24-Apr-2014. | 2 // Last Change: 28-Apr-2014. |
3 // | 3 // |
4 | 4 |
5 #include "preview.h" | 5 #include "preview.h" |
6 #define THUMB_W 60 | 6 #define THUMB_W 60 |
7 #define THUMB_H 75 | 7 #define THUMB_H 75 |
8 | 8 |
9 // サムネイルパネル | |
10 PThumbnailPanel::PThumbnailPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) | |
11 : wxPanel( parent, id, pos, size, style ) | |
12 { | |
13 m_parent = (PreviewDialog*)parent; | |
14 | |
15 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL ); | |
16 this->SetBackgroundColour( wxColour( 192, 192, 192 ) ); | |
17 | |
18 wxString thumb = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("thumbnail.png"); | |
19 wxBitmap bmp = wxBitmap( thumb, wxBITMAP_TYPE_PNG ); | |
20 | |
21 m_bitmap0 = new wxStaticBitmap( this, wxID_ANY, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); | |
22 bSizer->Add( m_bitmap0, 0, wxALL|wxALIGN_CENTER, 5 ); | |
23 m_bitmap0->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick0 ), NULL, this ); | |
24 | |
25 m_bitmap1 = new wxStaticBitmap(this, wxID_ANY, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); | |
26 bSizer->Add( m_bitmap1, 0, wxALL|wxALIGN_CENTER, 5 ); | |
27 m_bitmap1->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick1 ), NULL, this ); | |
28 | |
29 m_bitmap2 = new wxStaticBitmap( this, wxID_ANY, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); | |
30 bSizer->Add( m_bitmap2, 0, wxALL|wxALIGN_CENTER, 5 ); | |
31 m_bitmap2->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick2 ), NULL, this ); | |
32 | |
33 m_bitmap3 = new wxStaticBitmap(this, wxID_ANY, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); | |
34 bSizer->Add( m_bitmap3, 0, wxALL|wxALIGN_CENTER, 5 ); | |
35 m_bitmap3->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick3 ), NULL, this ); | |
36 | |
37 m_bitmap4 = new wxStaticBitmap( this, wxID_ANY, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); | |
38 bSizer->Add( m_bitmap4, 0, wxALL|wxALIGN_CENTER, 5 ); | |
39 m_bitmap4->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick4 ), NULL, this ); | |
40 | |
41 m_bitmap5 = new wxStaticBitmap(this, wxID_ANY, bmp, wxDefaultPosition, wxSize( THUMB_W, THUMB_H ), 0 ); | |
42 bSizer->Add( m_bitmap5, 0, wxALL|wxALIGN_CENTER, 5 ); | |
43 m_bitmap5->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick5 ), NULL, this ); | |
44 | |
45 this->SetSizer( bSizer ); | |
46 this->Layout(); | |
47 } | |
48 | |
49 PThumbnailPanel::~PThumbnailPanel() | |
50 { | |
51 m_bitmap0->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick0 ), NULL, this ); | |
52 m_bitmap1->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick1 ), NULL, this ); | |
53 m_bitmap2->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick2 ), NULL, this ); | |
54 m_bitmap3->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick3 ), NULL, this ); | |
55 m_bitmap4->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick4 ), NULL, this ); | |
56 m_bitmap5->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( PThumbnailPanel::OnClick5 ), NULL, this ); | |
57 } | |
58 | |
59 // Functions | |
60 /* サムネイル表示 */ | |
61 void PThumbnailPanel::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles ) | |
62 { | |
63 m_imagefiles = imagefiles; | |
64 | |
65 wxBitmap bmp; | |
66 bmp.LoadFile( cachefiles[0], wxBITMAP_TYPE_PNG ); m_bitmap0->SetBitmap( bmp ); | |
67 bmp.LoadFile( cachefiles[1], wxBITMAP_TYPE_PNG ); m_bitmap1->SetBitmap( bmp ); | |
68 bmp.LoadFile( cachefiles[2], wxBITMAP_TYPE_PNG ); m_bitmap2->SetBitmap( bmp ); | |
69 bmp.LoadFile( cachefiles[3], wxBITMAP_TYPE_PNG ); m_bitmap3->SetBitmap( bmp ); | |
70 bmp.LoadFile( cachefiles[4], wxBITMAP_TYPE_PNG ); m_bitmap4->SetBitmap( bmp ); | |
71 bmp.LoadFile( cachefiles[5], wxBITMAP_TYPE_PNG ); m_bitmap5->SetBitmap( bmp ); | |
72 } | |
73 /* 画像クリックで拡大表示 */ | |
74 void PThumbnailPanel::OnClick0( wxMouseEvent& WXUNUSED(event) ) { Preview( 0 ); } | |
75 void PThumbnailPanel::OnClick1( wxMouseEvent& WXUNUSED(event) ) { Preview( 1 ); } | |
76 void PThumbnailPanel::OnClick2( wxMouseEvent& WXUNUSED(event) ) { Preview( 2 ); } | |
77 void PThumbnailPanel::OnClick3( wxMouseEvent& WXUNUSED(event) ) { Preview( 3 ); } | |
78 void PThumbnailPanel::OnClick4( wxMouseEvent& WXUNUSED(event) ) { Preview( 4 ); } | |
79 void PThumbnailPanel::OnClick5( wxMouseEvent& WXUNUSED(event) ) { Preview( 5 ); } | |
80 void PThumbnailPanel::Preview( int n ) | |
81 { | |
82 if ( m_imagefiles.GetCount() < n + 1 ) return; | |
83 m_parent->SetPreviewImage( n ); | |
84 } | |
85 | |
86 | |
87 //////////////////////////////////////////////////////// | |
88 // プレビューダイアログ | |
9 PreviewDialog::PreviewDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) | 89 PreviewDialog::PreviewDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) |
10 : wxDialog( parent, id, title, pos, size, style ) | 90 : wxDialog( parent, id, title, pos, size, style ) |
11 { | 91 { |
12 //this->SetSizeHints( wxDefaultSize, wxDefaultSize ); | |
13 | |
14 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL ); | 92 wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL ); |
15 | 93 |
16 m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxALWAYS_SHOW_SB ); | 94 m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxALWAYS_SHOW_SB ); |
17 m_bitmap = new wxStaticBitmap( m_scrolledWindow, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); | 95 m_bitmap = new wxStaticBitmap( m_scrolledWindow, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); |
18 bSizerTop->Add( m_scrolledWindow, 1, wxALL|wxEXPAND, 5 ); | 96 bSizerTop->Add( m_scrolledWindow, 1, wxALL|wxEXPAND, 5 ); |
19 | 97 |
20 wxBoxSizer* bSizerMenu = new wxBoxSizer( wxVERTICAL ); | 98 wxBoxSizer* bSizerMenu = new wxBoxSizer( wxVERTICAL ); |
21 | 99 |
22 /* | 100 m_thumbPanel = new PThumbnailPanel( this, wxID_ANY, wxDefaultPosition, wxSize( 100, -1 ), wxSUNKEN_BORDER ); |
23 m_listCtrl = new wxListCtrl( this, ID_PLIST, wxDefaultPosition, wxSize( 140, -1 ), wxLC_ICON ); | 101 bSizerMenu->Add( m_thumbPanel, 0, wxALL|wxEXPAND, 5 ); |
24 m_imageList = new wxImageList( THUMB_W, THUMB_H ); | |
25 m_listCtrl->AssignImageList( m_imageList, wxIMAGE_LIST_NORMAL ); | |
26 bSizerMenu->Add( m_listCtrl, 1, wxRIGHT|wxLEFT|wxBOTTOM|wxEXPAND, 5 ); | |
27 */ | |
28 | 102 |
29 m_buttonPrint = new wxButton( this, ID_PRINT, wxT("印刷"), wxDefaultPosition, wxDefaultSize, 0 ); | 103 m_buttonPrint = new wxButton( this, ID_PRINT, wxT("印刷"), wxDefaultPosition, wxDefaultSize, 0 ); |
30 bSizerMenu->Add( m_buttonPrint, 0, wxALL, 5 ); | 104 bSizerMenu->Add( m_buttonPrint, 0, wxALL, 5 ); |
31 bSizerMenu->Add( 0, 0, 1, 0, 5 ); | 105 bSizerMenu->Add( 0, 0, 1, 0, 5 ); |
32 | 106 |
49 EVT_BUTTON( ID_PRINT, PreviewDialog::OnPrint ) | 123 EVT_BUTTON( ID_PRINT, PreviewDialog::OnPrint ) |
50 END_EVENT_TABLE() | 124 END_EVENT_TABLE() |
51 | 125 |
52 #define WIDTH 2480 | 126 #define WIDTH 2480 |
53 #define HEIGHT 3509 | 127 #define HEIGHT 3509 |
54 void PreviewDialog::SetImage( wxString file ) | 128 void PreviewDialog::SetPreviewImage( int n ) |
55 { | 129 { |
56 int w, h; | 130 int w, h; |
57 m_scrolledWindow->GetSize( &w, &h ); | 131 m_scrolledWindow->GetSize( &w, &h ); |
58 h = h * WIDTH / ( w - 200 ); | 132 h = h * WIDTH / ( w - 200 ); |
59 | 133 |
60 wxImage img; | 134 wxImage img; |
61 img.LoadFile( file, wxBITMAP_TYPE_JPEG ); | 135 img.LoadFile( m_imagefiles[n], wxBITMAP_TYPE_JPEG ); |
62 wxBitmap bmp( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ); | 136 wxBitmap bmp( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) ); |
63 m_bitmap->SetBitmap( bmp ); | 137 m_bitmap->SetBitmap( bmp ); |
64 | 138 |
65 m_scrolledWindow->SetScrollbars( 10, 10, 0, h/10 ); | 139 m_scrolledWindow->SetScrollbars( 10, 10, 0, h/10 ); |
66 m_preview = file; | 140 m_preview = m_imagefiles[n]; |
141 } | |
142 | |
143 void PreviewDialog::SetFiles( wxArrayString imagefiles, wxArrayString cachefiles ) | |
144 { | |
145 m_imagefiles = imagefiles; | |
146 m_cachefiles = cachefiles; | |
147 m_thumbPanel->SetFiles( m_imagefiles, m_cachefiles ); | |
67 } | 148 } |
68 | 149 |
69 void PreviewDialog::OnPrint( wxCommandEvent& WXUNUSED(envet) ) | 150 void PreviewDialog::OnPrint( wxCommandEvent& WXUNUSED(envet) ) |
70 { | 151 { |
71 wxString html; | 152 wxString html; |