[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/kspread
From: Stefan Nikolaus <nikolaus4 () googlemail ! com>
Date: 2008-05-29 16:00:01
Message-ID: 1212076801.155803.8648.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 814190 by nikolaus:
Printing Use the page layout from the print dialog.
M +13 -8 PrintManager.cpp
M +5 -3 PrintManager.h
M +46 -0 PrintSettings.cpp
M +16 -0 PrintSettings.h
M +24 -9 ui/PrintJob.cpp
--- trunk/koffice/kspread/PrintManager.cpp #814189:814190
@@ -39,6 +39,7 @@
SheetView* sheetView;
QMap<int, QRect> pages; // page number to cell range
Region printRegion;
+ PrintSettings settings;
KoZoomHandler* zoomHandler;
public:
@@ -49,11 +50,11 @@
void PrintManager::Private::calculatePages()
{
int pageNumber = 1;
- const double printWidth = sheet->printSettings()->printWidth();
- const double printHeight = sheet->printSettings()->printHeight();
+ const double printWidth = settings.printWidth();
+ const double printHeight = settings.printHeight();
kDebug() << "printWidth" << printWidth << "printHeight" << printHeight;
- if (sheet->printSettings()->pageOrder() == PrintSettings::LeftToRight)
+ if (settings.pageOrder() == PrintSettings::LeftToRight)
{
// kDebug() << "processing printRanges" << printRegion;
// iterate over the print ranges
@@ -111,7 +112,7 @@
}
}
}
- else // if (sheet->printSettings()->pageOrder() == PrintSettings::TopToBottom)
+ else // if (settings.pageOrder() == PrintSettings::TopToBottom)
{
// kDebug() << "processing printRanges" << printRegion;
// iterate over the print ranges
@@ -196,8 +197,10 @@
{
d->sheet = sheet;
d->sheetView = new SheetView(sheet);
+ d->settings = *sheet->printSettings();
d->printRegion = Region(1, 1, KS_colMax, KS_rowMax, sheet);
d->zoomHandler = new KoZoomHandler();
+ d->calculatePages();
}
PrintManager::~PrintManager()
@@ -207,15 +210,17 @@
delete d;
}
-int PrintManager::setupPages()
+void PrintManager::setPrintSettings(const PrintSettings& settings)
{
+ if (settings == d->settings)
+ return;
+ d->settings = settings;
d->calculatePages();
- return d->pages.count();
}
bool PrintManager::print(QPainter& painter, QPrinter* printer)
{
- const KoPageLayout pageLayout = d->sheet->printSettings()->pageLayout();
+ const KoPageLayout pageLayout = d->settings.pageLayout();
kDebug(36004) << "PageLayout:"
<< "w" << pageLayout.width
<< "h" << pageLayout.height
@@ -248,7 +253,7 @@
void PrintManager::printPage(int page, QPainter& painter)
{
- const KoPageLayout pageLayout = d->sheet->printSettings()->pageLayout();
+ const KoPageLayout pageLayout = d->settings.pageLayout();
kDebug(36004) << "PageLayout:"
<< "w" << pageLayout.width
<< "h" << pageLayout.height
--- trunk/koffice/kspread/PrintManager.h #814189:814190
@@ -25,6 +25,7 @@
namespace KSpread
{
+class PrintSettings;
class Sheet;
class PrintManager
@@ -41,10 +42,11 @@
virtual ~PrintManager();
/**
- * Setups the pages using the current page layout.
- * \return the number of pages
+ * Sets the print settings.
+ * If the settings differ from the existing ones, the pages are recreated.
+ * \param settings the print settings
*/
- int setupPages();
+ void setPrintSettings(const PrintSettings& settings);
/**
* \return \c false if nothing to print.
--- trunk/koffice/kspread/PrintSettings.cpp #814189:814190
@@ -67,6 +67,19 @@
d->pageOrder = LeftToRight;
}
+PrintSettings::PrintSettings(const PrintSettings& other)
+ : d(new Private)
+{
+ d->pageLayout = other.d->pageLayout;
+ d->printGrid = other.d->printGrid;
+ d->printCharts = other.d->printCharts;
+ d->printObjects = other.d->printObjects;
+ d->printGraphics = other.d->printGraphics;
+ d->printCommentIndicator = other.d->printCommentIndicator;
+ d->printFormulaIndicator = other.d->printFormulaIndicator;
+ d->pageOrder = other.d->pageOrder;
+}
+
PrintSettings::~PrintSettings()
{
delete d;
@@ -173,3 +186,36 @@
{
d->printFormulaIndicator = printFormulaIndicator;
}
+
+void PrintSettings::operator=(const PrintSettings& other)
+{
+ d->pageLayout = other.d->pageLayout;
+ d->printGrid = other.d->printGrid;
+ d->printCharts = other.d->printCharts;
+ d->printObjects = other.d->printObjects;
+ d->printGraphics = other.d->printGraphics;
+ d->printCommentIndicator = other.d->printCommentIndicator;
+ d->printFormulaIndicator = other.d->printFormulaIndicator;
+ d->pageOrder = other.d->pageOrder;
+}
+
+bool PrintSettings::operator==(const PrintSettings& other) const
+{
+ if (d->pageLayout != other.d->pageLayout)
+ return false;
+ if (d->printGrid != other.d->printGrid)
+ return false;
+ if (d->printCharts != other.d->printCharts)
+ return false;
+ if (d->printObjects != other.d->printObjects)
+ return false;
+ if (d->printGraphics != other.d->printGraphics)
+ return false;
+ if (d->printCommentIndicator != other.d->printCommentIndicator)
+ return false;
+ if (d->printFormulaIndicator != other.d->printFormulaIndicator)
+ return false;
+ if (d->pageOrder != other.d->pageOrder)
+ return false;
+ return true;
+}
--- trunk/koffice/kspread/PrintSettings.h #814189:814190
@@ -40,6 +40,11 @@
PrintSettings();
/**
+ * Constructor.
+ */
+ PrintSettings(const PrintSettings& other);
+
+ /**
* Destructor.
*/
virtual ~PrintSettings();
@@ -135,6 +140,17 @@
*/
void setPrintFormulaIndicator(bool printFormulaIndicator);
+ /**
+ * Assignment operator.
+ */
+ void operator=(const PrintSettings& settings);
+
+ /**
+ * Equality operator.
+ */
+ bool operator==(const PrintSettings& other) const;
+ inline bool operator!=(const PrintSettings& other) const { return \
!operator==(other); } +
private:
class Private;
Private * const d;
--- trunk/koffice/kspread/ui/PrintJob.cpp #814189:814190
@@ -44,14 +44,23 @@
QList<Sheet*> selectedSheets;
public:
- int setupPages();
+ int setupPages(const QPrinter& printer);
};
-int PrintJob::Private::setupPages()
+int PrintJob::Private::setupPages(const QPrinter& printer)
{
- // Setup the pages.
- // TODO Stefan: Use the current page layout.
- // TODO Stefan: Only perform layouting, if necessary, i.e. after page layout \
changes. + // Create the page layout.
+ KoPageLayout pageLayout;
+ const QSizeF size = printer.paperSize(QPrinter::Point);
+ pageLayout.format = KoPageFormat::guessFormat(POINT_TO_MM(size.width()), \
POINT_TO_MM(size.height())); + pageLayout.orientation = (printer.orientation() == \
QPrinter::Landscape) + ? KoPageFormat::Landscape : \
KoPageFormat::Portrait; + pageLayout.width = size.width();
+ pageLayout.height = size.height();
+ printer.getPageMargins(&pageLayout.left, &pageLayout.top, &pageLayout.right, \
&pageLayout.bottom, + QPrinter::Point);
+
+ // Create the list of sheet, that should be printed.
selectedSheets.clear();
if (sheetSelectPage->allSheetsButton->isChecked())
selectedSheets = view->doc()->map()->sheetList();
@@ -72,9 +81,16 @@
}
}
+ // (Re-)Create the pages of the sheets.
int pageCount = 0;
for (int i = 0; i < selectedSheets.count(); ++i)
- pageCount += selectedSheets[i]->printManager()->setupPages();
+ {
+ // Use the defaults from each sheet and use the print dialog's page layout.
+ PrintSettings settings = *selectedSheets[i]->printSettings();
+ settings.setPageLayout(pageLayout);
+ selectedSheets[i]->printManager()->setPrintSettings(settings);
+ pageCount += selectedSheets[i]->printManager()->pageCount();
+ }
return pageCount;
}
@@ -107,7 +123,7 @@
d->sheetSelectPage->prependAvailableSheet(sheet->sheetName());
}
- const int pageCount = d->setupPages();
+ const int pageCount = d->setupPages(printer());
printer().setFromTo(1, pageCount);
}
@@ -134,14 +150,13 @@
void PrintJob::startPrinting(RemovePolicy removePolicy)
{
// Setup the pages.
- d->setupPages();
+ d->setupPages(printer());
// Start the printing.
KoPrintingDialog::startPrinting(removePolicy);
}
void PrintJob::preparePage(int pageNumber)
{
- printer().setPaperSize(QPrinter::A4);
}
void PrintJob::printPage(int pageNumber, QPainter &painter)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic