Show current displayed page number and added ability to scale the page contents contributed by Dr.H.Reh.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10608 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer 2005-01-07 17:11:35 +00:00
parent fe970f9d5d
commit dc8938772a
4 changed files with 74 additions and 7 deletions

View File

@ -29,6 +29,8 @@ THE SOFTWARE.
*/ */
#include <stdlib.h>
#include <InterfaceKit.h> #include <InterfaceKit.h>
#include <SupportKit.h> #include <SupportKit.h>
#include "PrinterDriver.h" #include "PrinterDriver.h"
@ -196,8 +198,7 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
mf->MenuItem()->SetLabel(item->Label()); mf->MenuItem()->SetLabel(item->Label());
// add orientation menu // add orientation menu
y += h + kMargin; y += h + kMargin;
m = new BPopUpMenu("orientation"); m = new BPopUpMenu("orientation");
m->SetRadioMode(true); m->SetRadioMode(true);
@ -231,6 +232,28 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
/////////////////// ///////////////////
item->SetMarked(true); item->SetMarked(true);
mf->MenuItem()->SetLabel(item->Label()); mf->MenuItem()->SetLabel(item->Label());
// add scale text control
y += h + kMargin;
BString scale;
float scale0;
if (fSetupMsg->FindFloat("scale", &scale0) == B_OK) {
scale << (int)(100.0 * scale0);
} else {
scale = "100";
}
fScaleControl = new BTextControl(BRect(x, y, x + 100, y + 20), "scale", "Scale [%]:",
scale.String(),
NULL, B_FOLLOW_RIGHT);
int num;
for (num = 0; num <= 255; num++) {
fScaleControl->TextView()->DisallowChar(num);
}
for (num = 0; num <= 9; num++) {
fScaleControl->TextView()->AllowChar('0' + num);
}
panel->AddChild(fScaleControl);
// add a "OK" button, and make it default // add a "OK" button, and make it default
button = new BButton(r, NULL, "OK", new BMessage(OK_MSG), button = new BButton(r, NULL, "OK", new BMessage(OK_MSG),
@ -319,6 +342,17 @@ PageSetupWindow::UpdateSetupMessage()
fSetupMsg->AddInt32("units", units); fSetupMsg->AddInt32("units", units);
} }
} }
// scaling factor
float scale = atoi(fScaleControl->Text()) / 100.0;
if (scale <= 0.0) { // sanity check
scale = 1.0;
}
if (fSetupMsg->HasFloat("scale")) {
fSetupMsg->ReplaceFloat("scale", scale);
} else {
fSetupMsg->AddFloat("scale", scale);
}
} }

View File

@ -68,6 +68,7 @@ private:
BMessage * fSetupMsg; BMessage * fSetupMsg;
BMenuField * fPageSizeMenu; BMenuField * fPageSizeMenu;
BMenuField * fOrientationMenu; BMenuField * fOrientationMenu;
BTextControl * fScaleControl;
void UpdateSetupMessage(); void UpdateSetupMessage();

View File

@ -28,6 +28,7 @@ THE SOFTWARE.
*/ */
#include <Debug.h> #include <Debug.h>
#include <String.h>
#include "Preview.h" #include "Preview.h"
@ -174,16 +175,16 @@ void PreviewView::DrawPage(BRect rect)
// draw page contents // draw page contents
PushState(); PushState();
// print job coordinates are relative to the printable rect
BRect printRect = fReader.PrintableRect(); BRect printRect = fReader.PrintableRect();
SetOrigin(kPreviewLeftMargin + printRect.left*ZoomFactor(), SetOrigin(kPreviewLeftMargin + printRect.left*ZoomFactor(),
kPreviewTopMargin + printRect.top*ZoomFactor() ); kPreviewTopMargin + printRect.top*ZoomFactor() );
SetScale(ZoomFactor()); SetScale(ZoomFactor() * fReader.GetScale());
fCachedPage->Draw(this); fCachedPage->Draw(this);
PopState(); PopState();
} }
void PreviewView::Draw(BRect rect) { void PreviewView::Draw(BRect rect) {
if (fReader.InitCheck() == B_OK) { if (fReader.InitCheck() == B_OK) {
if (!IsPageLoaded(fPage)) { if (!IsPageLoaded(fPage)) {
@ -280,6 +281,9 @@ void PreviewView::FixScrollbars() {
PreviewWindow::PreviewWindow(BFile* jobFile) PreviewWindow::PreviewWindow(BFile* jobFile)
: BlockingWindow(BRect(20, 24, 400, 600), "Preview", B_DOCUMENT_WINDOW, 0) : BlockingWindow(BRect(20, 24, 400, 600), "Preview", B_DOCUMENT_WINDOW, 0)
{ {
const float kButtonDistance = 30;
const float kPageTextDistance = 15;
float top = 7; float top = 7;
float left = 20; float left = 20;
float width, height; float width, height;
@ -294,17 +298,32 @@ PreviewWindow::PreviewWindow(BFile* jobFile)
fPrev->ResizeToPreferred(); fPrev->ResizeToPreferred();
width = fPrev->Bounds().Width()+1; width = fPrev->Bounds().Width()+1;
height = fPrev->Bounds().Height()+1; height = fPrev->Bounds().Height()+1;
left = fPrev->Frame().right + 30; left = fPrev->Frame().right + kButtonDistance;
fNext = new BButton(BRect(left, top, left+10, top+10), "Next", "Next Page", new BMessage(MSG_NEXT_PAGE)); fNext = new BButton(BRect(left, top, left+10, top+10), "Next", "Next Page", new BMessage(MSG_NEXT_PAGE));
AddChild(fNext); AddChild(fNext);
fNext->ResizeTo(width, height); fNext->ResizeTo(width, height);
left = fNext->Frame().right + 70; left = fNext->Frame().right + kPageTextDistance;
fPageText = new BStringView(BRect(left, top, left + 100, top + 15), "pageText", "");
fPageText->SetAlignment(B_ALIGN_CENTER);
AddChild(fPageText);
// estimate max. width
float pageTextWidth = fPageText->StringWidth("Page 99999 of 99999 Pages");
// estimate height
BFont font;
fPageText->GetFont(&font);
float pageTextHeight = font.Size() + 2;
// resize to estimated size
fPageText->ResizeTo(pageTextWidth, pageTextHeight);
left += pageTextWidth + kPageTextDistance;
fPageText->MoveBy(0, (height - font.Size()) / 2);
fZoomIn = new BButton(BRect(left, top, left+10, top+10), "ZoomIn", "Zoom In", new BMessage(MSG_ZOOM_IN)); fZoomIn = new BButton(BRect(left, top, left+10, top+10), "ZoomIn", "Zoom In", new BMessage(MSG_ZOOM_IN));
AddChild(fZoomIn); AddChild(fZoomIn);
fZoomIn->ResizeTo(width, height); fZoomIn->ResizeTo(width, height);
left = fZoomIn->Frame().right + 30; left = fZoomIn->Frame().right + kButtonDistance;
fZoomOut = new BButton(BRect(left, top, left+10, top+10), "ZoomOut", "Zoom Out", new BMessage(MSG_ZOOM_OUT)); fZoomOut = new BButton(BRect(left, top, left+10, top+10), "ZoomOut", "Zoom Out", new BMessage(MSG_ZOOM_OUT));
AddChild(fZoomOut); AddChild(fZoomOut);
@ -363,6 +382,17 @@ void PreviewWindow::UpdateControls() {
fNext->SetEnabled(!fPreview->ShowsLastPage()); fNext->SetEnabled(!fPreview->ShowsLastPage());
fZoomIn->SetEnabled(fPreview->CanZoomIn()); fZoomIn->SetEnabled(fPreview->CanZoomIn());
fZoomOut->SetEnabled(fPreview->CanZoomOut()); fZoomOut->SetEnabled(fPreview->CanZoomOut());
BString text("Page ");
text << fPreview->CurrentPage()
<< " of "
<< fPreview->NumberOfPages();
if (fPreview->NumberOfPages() == 1) {
text << " Page";
} else {
text << " Pages";
}
fPageText->SetText(text.String());
} }
void PreviewWindow::MessageReceived(BMessage* m) { void PreviewWindow::MessageReceived(BMessage* m) {

View File

@ -76,6 +76,7 @@ public:
bool ShowsFirstPage() const; bool ShowsFirstPage() const;
bool ShowsLastPage() const; bool ShowsLastPage() const;
int CurrentPage() const { return fPage + 1; }
int NumberOfPages() const; int NumberOfPages() const;
void ShowNextPage(); void ShowNextPage();
void ShowPrevPage(); void ShowPrevPage();
@ -88,6 +89,7 @@ public:
class PreviewWindow : public BlockingWindow { class PreviewWindow : public BlockingWindow {
BButton *fNext, *fPrev, *fZoomIn, *fZoomOut; BButton *fNext, *fPrev, *fZoomIn, *fZoomOut;
BStringView* fPageText;
PreviewView* fPreview; PreviewView* fPreview;
BScrollView* fPreviewScroller; BScrollView* fPreviewScroller;
float fButtonBarHeight; float fButtonBarHeight;