aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Humpula <michal.humpula@seznam.cz>2014-01-19 15:51:58 (GMT)
committerMichal Humpula <michal.humpula@seznam.cz>2014-01-19 16:50:47 (GMT)
commit60c47b178a0409ed7963b40dd927091f77468e97 (patch)
treebd15ae22305a870d365365ae6fbc31af024ef3ad
parente53632b0e86a12a3cf1f7b0a49170160eaf211a5 (diff)
add back the KTextEditor::Document print interface
* extend KatePrint to do printing without view
-rw-r--r--src/document/katedocument.cpp13
-rw-r--r--src/document/katedocument.h6
-rw-r--r--src/include/ktexteditor/document.h16
-rw-r--r--src/printing/kateprinter.cpp32
-rw-r--r--src/printing/kateprinter.h33
-rw-r--r--src/printing/printpainter.cpp12
-rw-r--r--src/printing/printpainter.h10
7 files changed, 102 insertions, 20 deletions
diff --git a/src/document/katedocument.cpp b/src/document/katedocument.cpp
index ab825b4..cb2e264 100644
--- a/src/document/katedocument.cpp
+++ b/src/document/katedocument.cpp
@@ -48,6 +48,7 @@
#include "katescriptmanager.h"
#include "kateswapfile.h"
#include "katepartdebug.h"
+#include "printing/kateprinter.h"
#include <KTextEditor/DocumentCursor>
#include <KTextEditor/Attribute>
@@ -1939,6 +1940,18 @@ uint KTextEditor::DocumentPrivate::editableMarks() const
}
//END
+//BEGIN KTextEditor::PrintInterface stuff
+bool KTextEditor::DocumentPrivate::print()
+{
+ return KatePrinter::print(this);
+}
+
+void KTextEditor::DocumentPrivate::printPreview()
+{
+ KatePrinter::printPreview(this);
+}
+//END KTextEditor::PrintInterface stuff
+
//BEGIN KTextEditor::DocumentInfoInterface (### unfinished)
QString KTextEditor::DocumentPrivate::mimeType()
{
diff --git a/src/document/katedocument.h b/src/document/katedocument.h
index a9520ef..26eae68 100644
--- a/src/document/katedocument.h
+++ b/src/document/katedocument.h
@@ -520,6 +520,12 @@ private:
QHash<int, QString> m_markDescriptions;
uint m_editableMarks;
+ // KTextEditor::PrintInterface
+ //
+public Q_SLOTS:
+ virtual bool print();
+ virtual void printPreview();
+
//
// KTextEditor::DocumentInfoInterface ( ### unfinished )
//
diff --git a/src/include/ktexteditor/document.h b/src/include/ktexteditor/document.h
index 0df4600..95ba764 100644
--- a/src/include/ktexteditor/document.h
+++ b/src/include/ktexteditor/document.h
@@ -839,6 +839,22 @@ Q_SIGNALS:
*/
void highlightingModeChanged(KTextEditor::Document *document);
+ /*
+ * Access to print routines
+ */
+public:
+ /**
+ * Print the document. This should result in showing the print dialog.
+ *
+ * @returns true if document was printed
+ */
+ virtual bool print() = 0;
+
+ /**
+ * Shows the print preview dialog/
+ */
+ virtual void printPreview() = 0;
+
private:
/**
* private d-pointer, pointing to the internal implementation
diff --git a/src/printing/kateprinter.cpp b/src/printing/kateprinter.cpp
index 5b12797..a787233 100644
--- a/src/printing/kateprinter.cpp
+++ b/src/printing/kateprinter.cpp
@@ -45,7 +45,7 @@ class KatePrinterPrivate : public QObject
{
Q_OBJECT
public:
- KatePrinterPrivate(KTextEditor::ViewPrivate *view);
+ KatePrinterPrivate(KTextEditor::DocumentPrivate *doc, KTextEditor::ViewPrivate *view = 0);
~KatePrinterPrivate();
bool print(QPrinter *printer);
@@ -59,11 +59,11 @@ private:
PrintPainter *m_painter;
};
-KatePrinterPrivate::KatePrinterPrivate(KTextEditor::ViewPrivate *view)
+KatePrinterPrivate::KatePrinterPrivate(KTextEditor::DocumentPrivate *doc, KTextEditor::ViewPrivate *view)
: QObject()
- , m_view (view)
- , m_doc(m_view->doc())
- , m_painter(new PrintPainter(m_view))
+ , m_view(view)
+ , m_doc(doc)
+ , m_painter(new PrintPainter(m_doc, m_view))
{
}
@@ -94,7 +94,7 @@ bool KatePrinterPrivate::print(QPrinter *printer)
QScopedPointer<QPrintDialog> printDialog(KdePrint::createPrintDialog(printer, KdePrint::SystemSelectsPages, tabs, parentWidget));
- if (m_view->selection()) {
+ if (m_view && m_view->selection()) {
printer->setPrintRange(QPrinter::Selection);
printDialog->setOption(QAbstractPrintDialog::PrintSelection, true);
}
@@ -145,14 +145,30 @@ void KatePrinterPrivate::paint(QPrinter *printer)
bool KatePrinter::print(KTextEditor::ViewPrivate *view)
{
QPrinter printer;
- KatePrinterPrivate p(view);
+ KatePrinterPrivate p(view->doc(), view);
return p.print(&printer);
}
bool KatePrinter::printPreview(KTextEditor::ViewPrivate *view)
{
QPrinter printer;
- KatePrinterPrivate p(view);
+ KatePrinterPrivate p(view->doc(), view);
+ QPrintPreviewDialog preview(&printer);
+ QObject::connect(&preview, SIGNAL(paintRequested(QPrinter*)), &p, SLOT(paint(QPrinter*)));
+ return preview.exec();
+}
+
+bool KatePrinter::print(KTextEditor::DocumentPrivate *doc)
+{
+ QPrinter printer;
+ KatePrinterPrivate p(doc);
+ return p.print(&printer);
+}
+
+bool KatePrinter::printPreview(KTextEditor::DocumentPrivate *doc)
+{
+ QPrinter printer;
+ KatePrinterPrivate p(doc);
QPrintPreviewDialog preview(&printer);
QObject::connect(&preview, SIGNAL(paintRequested(QPrinter*)), &p, SLOT(paint(QPrinter*)));
return preview.exec();
diff --git a/src/printing/kateprinter.h b/src/printing/kateprinter.h
index 6e08d25..665ef5d 100644
--- a/src/printing/kateprinter.h
+++ b/src/printing/kateprinter.h
@@ -23,12 +23,39 @@
#ifndef __KATE_PRINTER_H__
#define __KATE_PRINTER_H__
-namespace KTextEditor { class ViewPrivate; }
+namespace KTextEditor
+{
+class DocumentPrivate;
+class ViewPrivate;
+}
namespace KatePrinter
{
-bool print(KTextEditor::ViewPrivate *doc);
-bool printPreview(KTextEditor::ViewPrivate *doc);
+ /**
+ * Launches print dialog for specified @view
+ * @returns true if document was successfully printed
+ */
+ bool print(KTextEditor::ViewPrivate *view);
+
+ /**
+ * Launches print preview dialog for specified @view
+ * @returns true if document was printed
+ */
+ bool printPreview(KTextEditor::ViewPrivate *view);
+
+ /**
+ * Overloaded print function for document
+ * Usefull when there is no view for the document. Consequently this function
+ * cannot print only selected portion of document.
+ */
+ bool print(KTextEditor::DocumentPrivate *doc);
+
+ /**
+ * Overloaded print function for document
+ * Usefull when there is no view for the document. Consequently this function
+ * cannot print only selected portion of document.
+ */
+ bool printPreview(KTextEditor::DocumentPrivate *doc);
};
#endif
diff --git a/src/printing/printpainter.cpp b/src/printing/printpainter.cpp
index e776eac..5fb5d9c 100644
--- a/src/printing/printpainter.cpp
+++ b/src/printing/printpainter.cpp
@@ -83,9 +83,9 @@ public:
KTextEditor::Range selectionRange;
};
-PrintPainter::PrintPainter(KTextEditor::ViewPrivate *view)
- : m_view (view)
- , m_doc(m_view->doc())
+PrintPainter::PrintPainter(KTextEditor::DocumentPrivate *doc, KTextEditor::ViewPrivate *view)
+ : m_view(view)
+ , m_doc(doc)
, m_colorScheme()
, m_printGuide(false)
, m_printLineNumbers(false)
@@ -108,7 +108,7 @@ PrintPainter::PrintPainter(KTextEditor::ViewPrivate *view)
{
m_folding = new Kate::TextFolding(m_doc->buffer());
- m_renderer = new KateRenderer(m_doc, *m_folding, m_view);
+ m_renderer = new KateRenderer(m_doc, *m_folding);
m_renderer->config()->setSchema(m_colorScheme);
m_renderer->setPrinterFriendly(true);
@@ -237,7 +237,7 @@ void PrintPainter::configure(const QPrinter *printer, PageLayout &pl) const
pl.selectionOnly = (printer->printRange() == QPrinter::Selection);
pl.lastline = m_doc->lastLine();
- if (pl.selectionOnly) {
+ if (m_view && pl.selectionOnly) {
// set a line range from the first selected line to the last
pl.selectionRange = m_view->selectionRange();
pl.firstline = pl.selectionRange.start().line();
@@ -649,7 +649,7 @@ void PrintPainter::paintLine(QPainter &painter, const uint line, uint &y, uint &
// selectionOnly: clip non-selection parts and adjust painter position if needed
int _xadjust = 0;
if (pl.selectionOnly) {
- if (m_view->blockSelection()) {
+ if (m_view && m_view->blockSelection()) {
int _x = m_renderer->cursorToX(rangeptr->viewLine(0), pl.selectionRange.start());
int _x1 = m_renderer->cursorToX(rangeptr->viewLine(rangeptr->viewLineCount() - 1), pl.selectionRange.end());
_xadjust = _x;
diff --git a/src/printing/printpainter.h b/src/printing/printpainter.h
index e2ac76b..c9e3e93 100644
--- a/src/printing/printpainter.h
+++ b/src/printing/printpainter.h
@@ -27,8 +27,12 @@
#include <QColor>
#include <QFont>
-namespace KTextEditor { class DocumentPrivate; }
-namespace KTextEditor { class ViewPrivate; }
+namespace KTextEditor
+{
+class DocumentPrivate;
+class ViewPrivate;
+}
+
class KateRenderer;
class QPrinter;
class QPainter;
@@ -50,7 +54,7 @@ class PageLayout;
class PrintPainter
{
public:
- PrintPainter(KTextEditor::ViewPrivate *view);
+ PrintPainter(KTextEditor::DocumentPrivate *doc, KTextEditor::ViewPrivate *view);
~PrintPainter();
void paint(QPrinter *printer) const;