File indexing completed on 2024-05-05 12:22:28
0001 /* 0002 SPDX-FileCopyrightText: 2002-2010 Anders Lund <anders@alweb.dk> 0003 0004 Rewritten based on code of: 0005 SPDX-FileCopyrightText: 2002 Michael Goffioul <kdeprint@swing.be> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #ifndef KATE_PRINT_PAINTER_H 0011 #define KATE_PRINT_PAINTER_H 0012 0013 #include <QColor> 0014 #include <QFont> 0015 #include <QString> 0016 0017 namespace KTextEditor 0018 { 0019 class DocumentPrivate; 0020 class ViewPrivate; 0021 } 0022 0023 class QPrinter; 0024 class QPainter; 0025 0026 class KateRenderer; 0027 0028 namespace Kate 0029 { 0030 class TextFolding; 0031 } 0032 namespace KTextEditor 0033 { 0034 class Range; 0035 } 0036 0037 namespace KatePrinter 0038 { 0039 class PageLayout; 0040 0041 class PrintPainter 0042 { 0043 public: 0044 PrintPainter(KTextEditor::DocumentPrivate *doc, KTextEditor::ViewPrivate *view); 0045 ~PrintPainter(); 0046 0047 PrintPainter(const PrintPainter &) = delete; 0048 PrintPainter &operator=(const PrintPainter &) = delete; 0049 0050 void paint(QPrinter *printer) const; 0051 0052 // Attributes 0053 void setColorScheme(const QString &scheme); 0054 0055 void setPrintGuide(const bool on) 0056 { 0057 m_printGuide = on; 0058 } 0059 void setPrintLineNumbers(const bool on) 0060 { 0061 m_printLineNumbers = on; 0062 } 0063 void setDontPrintFoldedCode(bool p) 0064 { 0065 m_dontPrintFoldedCode = p; 0066 } 0067 void setUseHeader(const bool on) 0068 { 0069 m_useHeader = on; 0070 } 0071 void setUseFooter(const bool on) 0072 { 0073 m_useFooter = on; 0074 } 0075 void setUseBackground(const bool on) 0076 { 0077 m_useBackground = on; 0078 } 0079 void setUseBox(const bool on); 0080 void setBoxMargin(const int margin) 0081 { 0082 m_boxMargin = margin; 0083 } 0084 void setBoxWidth(const int width); 0085 void setBoxColor(const QColor &color); 0086 void setHeadersFont(const QFont &font) 0087 { 0088 m_fhFont = font; 0089 } 0090 void setTextFont(const QFont &font); 0091 0092 void setHeaderBackground(const QColor &color); 0093 void setHeaderForeground(const QColor &color); 0094 void setUseHeaderBackground(const bool on) 0095 { 0096 m_useHeaderBackground = on; 0097 } 0098 0099 void setFooterBackground(const QColor &color); 0100 void setFooterForeground(const QColor &color); 0101 void setUseFooterBackground(const bool on) 0102 { 0103 m_useFooterBackground = on; 0104 } 0105 0106 void setHeaderFormat(const QStringList &list) 0107 { 0108 m_headerFormat = list; 0109 } 0110 void setFooterFormat(const QStringList &list) 0111 { 0112 m_footerFormat = list; 0113 } 0114 0115 private: 0116 void paintLineNumber(QPainter &painter, const uint number, const PageLayout &pl) const; 0117 void paintLine(QPainter &painter, const uint line, uint &y, uint &remainder, const PageLayout &pl) const; 0118 void paintNewPage(QPainter &painter, const uint currentPage, uint &y, const PageLayout &pl) const; 0119 0120 void paintBackground(QPainter &painter, const uint y, const PageLayout &pl) const; 0121 void paintBox(QPainter &painter, uint &y, const PageLayout &pl) const; 0122 void paintGuide(QPainter &painter, uint &y, const PageLayout &pl) const; 0123 0124 void paintHeader(QPainter &painter, const uint currentPage, uint &y, const PageLayout &pl) const; 0125 void paintFooter(QPainter &painter, const uint currentPage, const PageLayout &pl) const; 0126 void configure(const QPrinter *printer, PageLayout &layout) const; 0127 0128 void updateCache(); 0129 0130 private: 0131 KTextEditor::ViewPrivate *m_view; 0132 KTextEditor::DocumentPrivate *m_doc; 0133 0134 bool m_printGuide; 0135 bool m_printLineNumbers; 0136 bool m_dontPrintFoldedCode; 0137 bool m_useHeader; 0138 bool m_useFooter; 0139 bool m_useBackground; 0140 bool m_useBox; 0141 bool m_useHeaderBackground; 0142 bool m_useFooterBackground; 0143 0144 int m_boxMargin; 0145 int m_boxWidth; 0146 QColor m_boxColor; 0147 0148 QColor m_headerBackground; 0149 QColor m_headerForeground; 0150 QColor m_footerBackground; 0151 QColor m_footerForeground; 0152 0153 QFont m_fhFont; 0154 0155 QStringList m_headerFormat; 0156 QStringList m_footerFormat; 0157 0158 /* Internal vars */ 0159 KateRenderer *m_renderer; 0160 0161 int m_fontHeight; 0162 uint m_lineNumberWidth; 0163 }; 0164 0165 } 0166 0167 #endif