Add a draft test page.
The gradients are not recorded or played back by BPicture currently, so they're not visible outside the dummyWindow (code commented out). Needs to be polished before R1. Another issue is that ConfigPage() allow user to switch to another printer than the one selected when Print Test Page button was pressed. We needs a programmatic way to setup a printjob config for a specific printer... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40251 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
a6b6cbbcdd
commit
260f2d0994
@ -9,6 +9,7 @@ Preference Printers :
|
||||
PrinterListView.cpp
|
||||
JobListView.cpp
|
||||
SpoolFolder.cpp
|
||||
TestPageView.cpp
|
||||
TransportMenu.cpp
|
||||
Globals.cpp
|
||||
:
|
||||
@ -28,6 +29,7 @@ DoCatalogs Printers :
|
||||
JobListView.cpp
|
||||
PrinterListView.cpp
|
||||
PrintersWindow.cpp
|
||||
TestPageView.cpp
|
||||
TransportMenu.cpp
|
||||
;
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "JobListView.h"
|
||||
#include "Messages.h"
|
||||
#include "PrinterListView.h"
|
||||
#include "TestPageView.h"
|
||||
#include "SpoolFolder.h"
|
||||
|
||||
|
||||
@ -165,20 +166,39 @@ PrintersWindow::MessageReceived(BMessage* msg)
|
||||
void
|
||||
PrintersWindow::PrintTestPage(PrinterItem* printer)
|
||||
{
|
||||
BPrintJob job("TestPage");
|
||||
BPrintJob job(B_TRANSLATE("Test Page"));
|
||||
job.ConfigPage();
|
||||
|
||||
// job.ConfigJob();
|
||||
|
||||
// enforce job config
|
||||
BMessage* settings = job.Settings();
|
||||
settings->AddInt32("copies", 1);
|
||||
settings->AddInt32("first_page", 1);
|
||||
settings->AddInt32("last_page", -1);
|
||||
|
||||
printf("print job settings:\n");
|
||||
settings->PrintToStream();
|
||||
settings = job.Settings();
|
||||
|
||||
// BRect pageRect = job.PrintableRect();
|
||||
|
||||
job.BeginJob();
|
||||
|
||||
// TestPageView testPage(pageRect, printer);
|
||||
// job.DrawView(testPage, pageRect, BPoint(0.0, 0.0));
|
||||
|
||||
BRect pageRect = job.PrintableRect();
|
||||
// BWindow* dummyWindow = new BWindow(pageRect, "dummy", B_TITLED_WINDOW, 0);
|
||||
// dummyWindow->Show();
|
||||
TestPageView* testPage = new TestPageView(pageRect, printer);
|
||||
// views cannot be printed unless they're attached to a window
|
||||
// just hide our test page...
|
||||
testPage->Hide();
|
||||
AddChild(testPage);
|
||||
// dummyWindow->AddChild(testPage);
|
||||
|
||||
job.DrawView(testPage, pageRect, BPoint(0.0, 0.0));
|
||||
job.SpoolPage();
|
||||
|
||||
RemoveChild(testPage);
|
||||
delete testPage;
|
||||
|
||||
if (!job.CanContinue())
|
||||
return;
|
||||
|
||||
@ -276,7 +296,7 @@ PrintersWindow::_BuildGUI()
|
||||
fPrintTestPage = new BButton(BRect(5,60,5,60), "print_test_page",
|
||||
B_TRANSLATE("Print test page"), new BMessage(kMsgPrintTestPage),
|
||||
B_FOLLOW_RIGHT);
|
||||
// printersBox->AddChild(fPrintTestPage);
|
||||
printersBox->AddChild(fPrintTestPage);
|
||||
fPrintTestPage->ResizeToPreferred();
|
||||
|
||||
if (fPrintTestPage->Bounds().Width() > maxWidth)
|
||||
|
131
src/preferences/printers/TestPageView.cpp
Normal file
131
src/preferences/printers/TestPageView.cpp
Normal file
@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Philippe Houdoin
|
||||
*/
|
||||
|
||||
|
||||
#include "TestPageView.h"
|
||||
|
||||
#include <Catalog.h>
|
||||
#include <GradientLinear.h>
|
||||
|
||||
#include "PrinterListView.h"
|
||||
|
||||
|
||||
#undef B_TRANSLATE_CONTEXT
|
||||
#define B_TRANSLATE_CONTEXT "TestPageView"
|
||||
|
||||
|
||||
TestPageView::TestPageView(BRect frame, PrinterItem* printer)
|
||||
: BView(frame, "testpage", B_FOLLOW_NONE, B_WILL_DRAW),
|
||||
fPrinter(printer)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TestPageView::Draw(BRect updateRect)
|
||||
{
|
||||
// TODO: build using layout manager the page content,
|
||||
// using subviews, to adapt any page format.
|
||||
|
||||
// Draw corners
|
||||
|
||||
float width = Bounds().Width();
|
||||
float height = Bounds().Height();
|
||||
float minDimension = MIN(width, height);
|
||||
|
||||
float size = minDimension * 0.02;
|
||||
|
||||
BPoint pt = Bounds().LeftTop();
|
||||
StrokeLine(pt, BPoint(pt.x + size, pt.y));
|
||||
StrokeLine(pt, BPoint(pt.x, pt.y + size));
|
||||
|
||||
pt = Bounds().RightTop();
|
||||
StrokeLine(pt, BPoint(pt.x - size, pt.y));
|
||||
StrokeLine(pt, BPoint(pt.x, pt.y + size));
|
||||
|
||||
pt = Bounds().RightBottom();
|
||||
StrokeLine(pt, BPoint(pt.x - size, pt.y));
|
||||
StrokeLine(pt, BPoint(pt.x, pt.y - size));
|
||||
|
||||
pt = Bounds().LeftBottom();
|
||||
StrokeLine(pt, BPoint(pt.x + size, pt.y));
|
||||
StrokeLine(pt, BPoint(pt.x, pt.y - size));
|
||||
|
||||
// Draw some text
|
||||
|
||||
BString text;
|
||||
|
||||
text = B_TRANSLATE("Test Page for '%printer_name%'");
|
||||
text.ReplaceFirst("%printer_name%", fPrinter->Name());
|
||||
|
||||
SetFont(be_bold_font);
|
||||
MovePenTo(50, 50);
|
||||
DrawString(text);
|
||||
|
||||
SetFont(be_plain_font);
|
||||
text = B_TRANSLATE("Driver: %driver%");
|
||||
text.ReplaceFirst("%driver%", fPrinter->Driver());
|
||||
MovePenTo(50, 80);
|
||||
DrawString(text);
|
||||
|
||||
if (strlen(fPrinter->Transport()) > 0) {
|
||||
text = B_TRANSLATE("Transport: %transport% %transport_address%");
|
||||
text.ReplaceFirst("%transport%", fPrinter->Transport());
|
||||
text.ReplaceFirst("%transport_address%", fPrinter->TransportAddress());
|
||||
MovePenTo(50, 110);
|
||||
DrawString(text);
|
||||
}
|
||||
|
||||
// Draw some gradients
|
||||
|
||||
BRect rect(50, 140, 50 + 200, 140 + 20);
|
||||
BGradientLinear gradient(rect.LeftTop(), rect.RightBottom());
|
||||
rgb_color white = make_color(255, 255, 255);
|
||||
gradient.AddColor(white, 0.0);
|
||||
|
||||
// Red gradient
|
||||
gradient.AddColor(make_color(255, 0, 0), 255.0);
|
||||
FillRect(rect, gradient);
|
||||
StrokeRect(rect);
|
||||
|
||||
// Green gradient
|
||||
rect.OffsetBy(0, 20);
|
||||
gradient.SetColor(1, make_color(0, 255, 0));
|
||||
FillRect(rect, gradient);
|
||||
StrokeRect(rect);
|
||||
|
||||
// Blue gradient
|
||||
rect.OffsetBy(0, 20);
|
||||
gradient.SetColor(1, make_color(0, 0, 255));
|
||||
FillRect(rect, gradient);
|
||||
StrokeRect(rect);
|
||||
|
||||
// Yellow gradient
|
||||
rect.OffsetBy(0, 20);
|
||||
gradient.SetColor(1, make_color(255, 255, 0));
|
||||
FillRect(rect, gradient);
|
||||
StrokeRect(rect);
|
||||
|
||||
// Magenta gradient
|
||||
rect.OffsetBy(0, 20);
|
||||
gradient.SetColor(1, make_color(255, 0, 255));
|
||||
FillRect(rect, gradient);
|
||||
StrokeRect(rect);
|
||||
|
||||
// Cyan gradient
|
||||
rect.OffsetBy(0, 20);
|
||||
gradient.SetColor(1, make_color(0, 255, 255));
|
||||
FillRect(rect, gradient);
|
||||
StrokeRect(rect);
|
||||
|
||||
// Gray gradient
|
||||
rect.OffsetBy(0, 20);
|
||||
gradient.SetColor(1, make_color(0, 0, 0));
|
||||
FillRect(rect, gradient);
|
||||
StrokeRect(rect);
|
||||
}
|
26
src/preferences/printers/TestPageView.h
Normal file
26
src/preferences/printers/TestPageView.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2011, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Philippe Houdoin
|
||||
*/
|
||||
#ifndef _PRINTERS_TESTPAGEVIEW_H
|
||||
#define _PRINTERS_TESTPAGEVIEW_H
|
||||
|
||||
|
||||
#include <View.h>
|
||||
|
||||
class PrinterItem;
|
||||
|
||||
class TestPageView : public BView {
|
||||
public:
|
||||
TestPageView(BRect rect, PrinterItem* printer);
|
||||
|
||||
void Draw(BRect rect);
|
||||
|
||||
private:
|
||||
PrinterItem* fPrinter;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user