ShowImage: Multipage images displayed in sequence.

* The correct page is displayed.
* Next/Previous/First/Last page are enabled and disable
  as Next/Previous File.
* Add in the status bar current page/ total page.
* Fixes #11959.
This commit is contained in:
Janus 2015-04-09 19:18:15 +00:00
parent 35df7c671e
commit baa27ccb30
5 changed files with 54 additions and 18 deletions

View File

@ -503,6 +503,20 @@ ImageFileNavigator::PreviousPage()
} }
bool
ImageFileNavigator::HasNextPage()
{
return fDocumentIndex < fDocumentCount;
}
bool
ImageFileNavigator::HasPreviousPage()
{
return fDocumentIndex > 1;
}
bool bool
ImageFileNavigator::GoToPage(int32 page) ImageFileNavigator::GoToPage(int32 page)
{ {

View File

@ -43,6 +43,8 @@ public:
bool LastPage(); bool LastPage();
bool NextPage(); bool NextPage();
bool PreviousPage(); bool PreviousPage();
bool HasNextPage();
bool HasPreviousPage();
bool GoToPage(int32 page); bool GoToPage(int32 page);
bool FirstFile(); bool FirstFile();

View File

@ -150,12 +150,13 @@ ShowImageStatusView::MouseDown(BPoint where)
void void
ShowImageStatusView::Update(const entry_ref& ref, const BString& text, ShowImageStatusView::Update(const entry_ref& ref, const BString& text,
const BString& imageType, float zoom) const BString& pages, const BString& imageType, float zoom)
{ {
fRef = ref; fRef = ref;
_SetFrameText(text); _SetFrameText(text);
_SetZoomText(zoom); _SetZoomText(zoom);
_SetPagesText(pages);
_SetImageTypeText(imageType); _SetImageTypeText(imageType);
_ValidatePreferredSize(); _ValidatePreferredSize();
@ -175,21 +176,28 @@ ShowImageStatusView::SetZoom(float zoom)
void void
ShowImageStatusView::_SetFrameText(const BString& text) ShowImageStatusView::_SetFrameText(const BString& text)
{ {
fCellText[0] = text; fCellText[kFrameSizeCell] = text;
} }
void void
ShowImageStatusView::_SetZoomText(float zoom) ShowImageStatusView::_SetZoomText(float zoom)
{ {
fCellText[1].SetToFormat("%.0f%%", zoom * 100); fCellText[kZoomCell].SetToFormat("%.0f%%", zoom * 100);
}
void
ShowImageStatusView::_SetPagesText(const BString& pages)
{
fCellText[kPagesCell] = pages;
} }
void void
ShowImageStatusView::_SetImageTypeText(const BString& imageType) ShowImageStatusView::_SetImageTypeText(const BString& imageType)
{ {
fCellText[2] = imageType; fCellText[kImageTypeCell] = imageType;
} }

View File

@ -18,6 +18,7 @@
enum { enum {
kFrameSizeCell, kFrameSizeCell,
kZoomCell, kZoomCell,
kPagesCell,
kImageTypeCell, kImageTypeCell,
kStatusCellCount kStatusCellCount
}; };
@ -34,12 +35,13 @@ public:
virtual void MouseDown(BPoint where); virtual void MouseDown(BPoint where);
void Update(const entry_ref& ref, void Update(const entry_ref& ref,
const BString& text, const BString& imageType, const BString& text, const BString& pages,
float zoom); const BString& imageType, float zoom);
void SetZoom(float zoom); void SetZoom(float zoom);
private: private:
void _SetFrameText(const BString& text); void _SetFrameText(const BString& text);
void _SetZoomText(float zoom); void _SetZoomText(float zoom);
void _SetPagesText(const BString& pages);
void _SetImageTypeText(const BString& imageType); void _SetImageTypeText(const BString& imageType);
void _ValidatePreferredSize(); void _ValidatePreferredSize();
BScrollView* fScrollView; BScrollView* fScrollView;

View File

@ -615,6 +615,15 @@ ShowImageWindow::MessageReceived(BMessage* message)
break; break;
} }
int32 page = message->FindInt32("page");
int32 pageCount = message->FindInt32("pageCount");
if (!first && page != fNavigator.CurrentPage()) {
// ignore older pages
if (bitmapOwner != NULL)
bitmapOwner->ReleaseReference();
break;
}
status_t status = fImageView->SetImage(message); status_t status = fImageView->SetImage(message);
if (status != B_OK) { if (status != B_OK) {
if (bitmapOwner != NULL) if (bitmapOwner != NULL)
@ -629,8 +638,7 @@ ShowImageWindow::MessageReceived(BMessage* message)
} }
fImageType = message->FindString("type"); fImageType = message->FindString("type");
fNavigator.SetTo(ref, message->FindInt32("page"), fNavigator.SetTo(ref, page, pageCount);
message->FindInt32("pageCount"));
fImageView->FitToBounds(); fImageView->FitToBounds();
if (first) { if (first) {
@ -680,12 +688,12 @@ ShowImageWindow::MessageReceived(BMessage* message)
int32 pages = fNavigator.PageCount(); int32 pages = fNavigator.PageCount();
int32 currentPage = fNavigator.CurrentPage(); int32 currentPage = fNavigator.CurrentPage();
bool enable = pages > 1 ? true : false; _EnableMenuItem(fBar, MSG_PAGE_FIRST,
_EnableMenuItem(fBar, MSG_PAGE_FIRST, enable); fNavigator.HasPreviousPage());
_EnableMenuItem(fBar, MSG_PAGE_LAST, enable); _EnableMenuItem(fBar, MSG_PAGE_LAST, fNavigator.HasNextPage());
_EnableMenuItem(fBar, MSG_PAGE_NEXT, enable); _EnableMenuItem(fBar, MSG_PAGE_NEXT, fNavigator.HasNextPage());
_EnableMenuItem(fBar, MSG_PAGE_PREV, enable); _EnableMenuItem(fBar, MSG_PAGE_PREV, fNavigator.HasPreviousPage());
fGoToPageMenu->SetEnabled(enable); fGoToPageMenu->SetEnabled(pages > 1);
_EnableMenuItem(fBar, MSG_FILE_NEXT, fNavigator.HasNextFile()); _EnableMenuItem(fBar, MSG_FILE_NEXT, fNavigator.HasNextFile());
_EnableMenuItem(fBar, MSG_FILE_PREV, fNavigator.HasPreviousFile()); _EnableMenuItem(fBar, MSG_FILE_PREV, fNavigator.HasPreviousFile());
@ -1054,14 +1062,16 @@ ShowImageWindow::MessageReceived(BMessage* message)
void void
ShowImageWindow::_UpdateStatusText(const BMessage* message) ShowImageWindow::_UpdateStatusText(const BMessage* message)
{ {
BString status; BString frameText;
if (fImageView->Bitmap() != NULL) { if (fImageView->Bitmap() != NULL) {
BRect bounds = fImageView->Bitmap()->Bounds(); BRect bounds = fImageView->Bitmap()->Bounds();
status << bounds.IntegerWidth() + 1 frameText << bounds.IntegerWidth() + 1
<< "x" << bounds.IntegerHeight() + 1; << "x" << bounds.IntegerHeight() + 1;
} }
BString pages;
fStatusView->Update(fNavigator.CurrentRef(), status, fImageType, if (fNavigator.PageCount() > 1)
pages << fNavigator.CurrentPage() << "/" << fNavigator.PageCount();
fStatusView->Update(fNavigator.CurrentRef(), frameText, pages, fImageType,
fImageView->Zoom()); fImageView->Zoom());
} }