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:
parent
fe970f9d5d
commit
dc8938772a
|
@ -29,6 +29,8 @@ THE SOFTWARE.
|
|||
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <InterfaceKit.h>
|
||||
#include <SupportKit.h>
|
||||
#include "PrinterDriver.h"
|
||||
|
@ -196,8 +198,7 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
|||
mf->MenuItem()->SetLabel(item->Label());
|
||||
|
||||
// add orientation menu
|
||||
y += h + kMargin;
|
||||
|
||||
y += h + kMargin;
|
||||
m = new BPopUpMenu("orientation");
|
||||
m->SetRadioMode(true);
|
||||
|
||||
|
@ -231,6 +232,28 @@ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName)
|
|||
///////////////////
|
||||
item->SetMarked(true);
|
||||
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
|
||||
button = new BButton(r, NULL, "OK", new BMessage(OK_MSG),
|
||||
|
@ -319,6 +342,17 @@ PageSetupWindow::UpdateSetupMessage()
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ private:
|
|||
BMessage * fSetupMsg;
|
||||
BMenuField * fPageSizeMenu;
|
||||
BMenuField * fOrientationMenu;
|
||||
BTextControl * fScaleControl;
|
||||
|
||||
void UpdateSetupMessage();
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ THE SOFTWARE.
|
|||
*/
|
||||
|
||||
#include <Debug.h>
|
||||
#include <String.h>
|
||||
|
||||
#include "Preview.h"
|
||||
|
||||
|
@ -174,16 +175,16 @@ void PreviewView::DrawPage(BRect rect)
|
|||
// draw page contents
|
||||
PushState();
|
||||
|
||||
// print job coordinates are relative to the printable rect
|
||||
BRect printRect = fReader.PrintableRect();
|
||||
SetOrigin(kPreviewLeftMargin + printRect.left*ZoomFactor(),
|
||||
kPreviewTopMargin + printRect.top*ZoomFactor() );
|
||||
|
||||
SetScale(ZoomFactor());
|
||||
SetScale(ZoomFactor() * fReader.GetScale());
|
||||
fCachedPage->Draw(this);
|
||||
PopState();
|
||||
}
|
||||
|
||||
|
||||
void PreviewView::Draw(BRect rect) {
|
||||
if (fReader.InitCheck() == B_OK) {
|
||||
if (!IsPageLoaded(fPage)) {
|
||||
|
@ -280,6 +281,9 @@ void PreviewView::FixScrollbars() {
|
|||
PreviewWindow::PreviewWindow(BFile* jobFile)
|
||||
: BlockingWindow(BRect(20, 24, 400, 600), "Preview", B_DOCUMENT_WINDOW, 0)
|
||||
{
|
||||
const float kButtonDistance = 30;
|
||||
const float kPageTextDistance = 15;
|
||||
|
||||
float top = 7;
|
||||
float left = 20;
|
||||
float width, height;
|
||||
|
@ -294,17 +298,32 @@ PreviewWindow::PreviewWindow(BFile* jobFile)
|
|||
fPrev->ResizeToPreferred();
|
||||
width = fPrev->Bounds().Width()+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));
|
||||
AddChild(fNext);
|
||||
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));
|
||||
AddChild(fZoomIn);
|
||||
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));
|
||||
AddChild(fZoomOut);
|
||||
|
@ -363,6 +382,17 @@ void PreviewWindow::UpdateControls() {
|
|||
fNext->SetEnabled(!fPreview->ShowsLastPage());
|
||||
fZoomIn->SetEnabled(fPreview->CanZoomIn());
|
||||
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) {
|
||||
|
|
|
@ -76,6 +76,7 @@ public:
|
|||
|
||||
bool ShowsFirstPage() const;
|
||||
bool ShowsLastPage() const;
|
||||
int CurrentPage() const { return fPage + 1; }
|
||||
int NumberOfPages() const;
|
||||
void ShowNextPage();
|
||||
void ShowPrevPage();
|
||||
|
@ -88,6 +89,7 @@ public:
|
|||
|
||||
class PreviewWindow : public BlockingWindow {
|
||||
BButton *fNext, *fPrev, *fZoomIn, *fZoomOut;
|
||||
BStringView* fPageText;
|
||||
PreviewView* fPreview;
|
||||
BScrollView* fPreviewScroller;
|
||||
float fButtonBarHeight;
|
||||
|
|
Loading…
Reference in New Issue