[haiku-commits] r40251 - haiku/trunk/src/preferences/printers

  • From: philippe.houdoin@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 20 Jan 2011 12:58:03 +0100 (CET)

Author: phoudoin
Date: 2011-01-20 12:58:03 +0100 (Thu, 20 Jan 2011)
New Revision: 40251
Changeset: http://dev.haiku-os.org/changeset/40251

Added:
   haiku/trunk/src/preferences/printers/TestPageView.cpp
   haiku/trunk/src/preferences/printers/TestPageView.h
Modified:
   haiku/trunk/src/preferences/printers/Jamfile
   haiku/trunk/src/preferences/printers/PrintersWindow.cpp
Log:
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...


Modified: haiku/trunk/src/preferences/printers/Jamfile
===================================================================
--- haiku/trunk/src/preferences/printers/Jamfile        2011-01-20 10:54:48 UTC 
(rev 40250)
+++ haiku/trunk/src/preferences/printers/Jamfile        2011-01-20 11:58:03 UTC 
(rev 40251)
@@ -9,6 +9,7 @@
        PrinterListView.cpp
        JobListView.cpp
        SpoolFolder.cpp
+       TestPageView.cpp
        TransportMenu.cpp
        Globals.cpp
        :
@@ -28,6 +29,7 @@
        JobListView.cpp
        PrinterListView.cpp
        PrintersWindow.cpp
+       TestPageView.cpp
        TransportMenu.cpp
 ;
 

Modified: haiku/trunk/src/preferences/printers/PrintersWindow.cpp
===================================================================
--- haiku/trunk/src/preferences/printers/PrintersWindow.cpp     2011-01-20 
10:54:48 UTC (rev 40250)
+++ haiku/trunk/src/preferences/printers/PrintersWindow.cpp     2011-01-20 
11:58:03 UTC (rev 40251)
@@ -28,6 +28,7 @@
 #include "JobListView.h"
 #include "Messages.h"
 #include "PrinterListView.h"
+#include "TestPageView.h"
 #include "SpoolFolder.h"
 
 
@@ -165,20 +166,39 @@
 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 @@
        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)

Added: haiku/trunk/src/preferences/printers/TestPageView.cpp
===================================================================
--- haiku/trunk/src/preferences/printers/TestPageView.cpp                       
        (rev 0)
+++ haiku/trunk/src/preferences/printers/TestPageView.cpp       2011-01-20 
11:58:03 UTC (rev 40251)
@@ -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);
+}

Added: haiku/trunk/src/preferences/printers/TestPageView.h
===================================================================
--- haiku/trunk/src/preferences/printers/TestPageView.h                         
(rev 0)
+++ haiku/trunk/src/preferences/printers/TestPageView.h 2011-01-20 11:58:03 UTC 
(rev 40251)
@@ -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


Other related posts:

  • » [haiku-commits] r40251 - haiku/trunk/src/preferences/printers - philippe . houdoin