Commit 7d598e1a authored by Michal Humpula's avatar Michal Humpula 🔥
Browse files

break down the kateprinter.cpp

removing the read/write margin settings, it should be
fixed in Qt 5.0
parent a35e76ab
......@@ -100,6 +100,11 @@ variableeditor/variableeditor.cpp
variableeditor/variableitem.cpp
variableeditor/katehelpbutton.cpp
# printing classes
printing/kateprinter.cpp
printing/printpainter.cpp
printing/printconfigwidgets.cpp
# rendering stuff (katerenderer and helpers)
render/katerenderer.cpp
render/katerenderrange.cpp
......@@ -165,7 +170,6 @@ utils/kateconfig.cpp
utils/katebookmarks.cpp
utils/kateautoindent.cpp
utils/katetemplatehandler.cpp
utils/kateprinter.cpp
utils/kateglobal.cpp
utils/katecmd.cpp
utils/katepartpluginmanager.cpp
......
......@@ -34,7 +34,7 @@
#include "katetextline.h"
#include "katedocumenthelpers.h"
#include "katehighlighthelpers.h"
#include "kateprinter.h"
#include "printing/kateprinter.h"
#include "katerenderer.h"
#include "kateregexp.h"
#include "kateplaintextsearch.h"
......
/* This file is part of the KDE libraries and the Kate part.
*
* Copyright (C) 2002-2010 Anders Lund <anders@alweb.dk>
*
* Rewritten based on code of Copyright (c) 2002 Michael Goffioul <kdeprint@swing.be>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "kateprinter.h"
#include "kateconfig.h"
#include "katedocument.h"
#include <KConfigGroup>
#include <KSharedConfig>
#include <KDEPrintDialog>
#include <QApplication>
#include <QPrinter>
#include <QPrintDialog>
#include <QPrintPreviewDialog>
#include "printconfigwidgets.h"
#include "printpainter.h"
using namespace KatePrinter;
//BEGIN KatePrinterPrivate
class KatePrinterPrivate : public QObject
{
Q_OBJECT
public:
KatePrinterPrivate(KateDocument *doc);
~KatePrinterPrivate();
bool print(QPrinter *printer);
public Q_SLOTS:
void paint(QPrinter *printer);
private:
KateDocument *m_doc;
PrintPainter *m_painter;
};
KatePrinterPrivate::KatePrinterPrivate(KateDocument* doc)
: QObject()
, m_doc(doc)
, m_painter(new PrintPainter(doc))
{
}
KatePrinterPrivate::~KatePrinterPrivate()
{
delete m_painter;
}
bool KatePrinterPrivate::print(QPrinter *printer)
{
// docname is now always there, including the right Untitled name
printer->setDocName(m_doc->documentName());
KatePrintTextSettings *kpts = new KatePrintTextSettings;
KatePrintHeaderFooter *kphf = new KatePrintHeaderFooter;
KatePrintLayout *kpl = new KatePrintLayout;
QList<QWidget*> tabs;
tabs << kpts;
tabs << kphf;
tabs << kpl;
QWidget *parentWidget = m_doc->widget();
if (!parentWidget) {
parentWidget = QApplication::activeWindow();
}
QScopedPointer<QPrintDialog> printDialog(KdePrint::createPrintDialog(printer, KdePrint::SystemSelectsPages, tabs, parentWidget));
if (m_doc->activeView()->selection()) {
printer->setPrintRange(QPrinter::Selection);
printDialog->setOption(QAbstractPrintDialog::PrintSelection, true);
}
if (!printDialog->exec())
return false;
// configure the painter
m_painter->setPrintGuide(kpts->printGuide());
m_painter->setPrintLineNumbers(kpts->printLineNumbers());
m_painter->setColorScheme(kpl->colorScheme());
m_painter->setUseBackground(kpl->useBackground());
m_painter->setUseBox(kpl->useBox());
m_painter->setBoxMargin(kpl->boxMargin());
m_painter->setBoxWidth(kpl->boxWidth());
m_painter->setBoxColor(kpl->boxColor());
m_painter->setHeadersFont(kphf->font());
m_painter->setUseHeader(kphf->useHeader());
m_painter->setHeaderBackground(kphf->headerBackground());
m_painter->setHeaderForeground(kphf->headerForeground());
m_painter->setUseHeaderBackground(kphf->useHeaderBackground());
m_painter->setHeaderFormat(kphf->headerFormat());
m_painter->setUseFooter(kphf->useFooter());
m_painter->setFooterBackground(kphf->footerBackground());
m_painter->setFooterForeground(kphf->footerForeground());
m_painter->setUseFooterBackground(kphf->useFooterBackground());
m_painter->setFooterFormat(kphf->footerFormat());
m_painter->paint(printer);
return true;
}
void KatePrinterPrivate::paint(QPrinter *printer)
{
m_painter->paint(printer);
}
//END KatePrinterPrivate
//BEGIN KatePrinter
bool KatePrinter::print(KateDocument *doc)
{
QPrinter printer;
KatePrinterPrivate p(doc);
return p.print(&printer);
}
bool KatePrinter::printPreview(KateDocument *doc)
{
QPrinter printer;
KatePrinterPrivate p(doc);
QPrintPreviewDialog preview(&printer);
QObject::connect(&preview, SIGNAL(paintRequested(QPrinter *)), &p, SLOT(paint(QPrinter *)));
return preview.exec();
}
//END KatePrinter
#include "kateprinter.moc"
// kate: space-indent on; indent-width 2; replace-tabs on;
/* This file is part of the KDE libraries and the Kate part.
*
* Copyright (C) 2002-2010 Anders Lund <anders@alweb.dk>
*
* Rewritten based on code of Copyright (c) 2002 Michael Goffioul <kdeprint@swing.be>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __KATE_PRINTER_CONFIG_WIDGETS_H__
#define __KATE_PRINTER_CONFIG_WIDGETS_H__
#include <QWidget>
class QCheckBox;
class QLabel;
class KLineEdit;
class KColorButton;
class KComboBox;
class QSpinBox;
class QGroupBox;
namespace KatePrinter
{
//BEGIN Text settings
/*
* Text settings page:
* - Print Line Numbers
* () Smart () Yes () No
*/
class KatePrintTextSettings : public QWidget
{
Q_OBJECT
public:
explicit KatePrintTextSettings( QWidget *parent=0 );
~KatePrintTextSettings();
bool printLineNumbers();
bool printGuide();
private:
void readSettings();
void writeSettings();
QCheckBox *cbLineNumbers;
QCheckBox *cbGuide;
};
//END Text Settings
//BEGIN Header/Footer
/*
* Header & Footer page:
* - enable header/footer
* - header/footer props
* o formats
* o colors
*/
class KatePrintHeaderFooter : public QWidget
{
Q_OBJECT
public:
explicit KatePrintHeaderFooter( QWidget *parent=0 );
~KatePrintHeaderFooter();
QFont font();
bool useHeader();
QStringList headerFormat();
QColor headerForeground();
QColor headerBackground();
bool useHeaderBackground();
bool useFooter();
QStringList footerFormat();
QColor footerForeground();
QColor footerBackground();
bool useFooterBackground();
public Q_SLOTS:
void setHFFont();
void showContextMenu(const QPoint& pos);
private:
void readSettings();
void writeSettings();
QCheckBox *cbEnableHeader, *cbEnableFooter;
QLabel *lFontPreview;
QGroupBox *gbHeader, *gbFooter;
KLineEdit *leHeaderLeft, *leHeaderCenter, *leHeaderRight;
KColorButton *kcbtnHeaderFg, *kcbtnHeaderBg;
QCheckBox *cbHeaderEnableBgColor;
KLineEdit *leFooterLeft, *leFooterCenter, *leFooterRight;
KColorButton *kcbtnFooterFg, *kcbtnFooterBg;
QCheckBox *cbFooterEnableBgColor;
};
//END Header/Footer
//BEGIN Layout
/*
* Layout page:
* - Color scheme
* - Use Box
* - Box properties
* o Width
* o Margin
* o Color
*/
class KatePrintLayout : public QWidget
{
Q_OBJECT
public:
explicit KatePrintLayout( QWidget *parent=0 );
~KatePrintLayout();
QString colorScheme();
bool useBackground();
bool useBox();
int boxWidth();
int boxMargin();
QColor boxColor();
private:
void readSettings();
void writeSettings();
KComboBox *cmbSchema;
QCheckBox *cbEnableBox;
QCheckBox *cbDrawBackground;
QGroupBox *gbBoxProps;
QSpinBox *sbBoxWidth;
QSpinBox *sbBoxMargin;
KColorButton* kcbtnBoxColor;
};
//END Layout
};
#endif
This diff is collapsed.
/* This file is part of the KDE libraries and the Kate part.
*
* Copyright (C) 2002-2010 Anders Lund <anders@alweb.dk>
*
* Rewritten based on code of Copyright (c) 2002 Michael Goffioul <kdeprint@swing.be>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __KATE_PRINTER_PAINTER_H__
#define __KATE_PRINTER_PAINTER_H__
#include <QString>
#include <QColor>
#include <QFont>
class KateDocument;
class QPrinter;
namespace KatePrinter
{
class PrintPainter
{
public:
PrintPainter(KateDocument *doc);
void paint(QPrinter *printer) const;
// Attributes
void setColorScheme(const QString &scheme) { m_colorScheme = scheme; }
void setPrintGuide(const bool on) { m_printGuide = on; }
void setPrintLineNumbers(const bool on) { m_printLineNumbers = on; }
void setUseHeader(const bool on) { m_useHeader = on; }
void setUseFooter(const bool on) { m_useFooter = on; }
void setUseBackground(const bool on) { m_useBackground = on; }
void setUseBox(const bool on) { m_useBox = on; }
void setBoxMargin(const int margin) { m_boxMargin = margin; }
void setBoxWidth(const int width) { m_boxWidth = width; }
void setBoxColor(const QColor &color) { m_boxColor = color; }
void setHeadersFont(const QFont &font) { m_fhFont = font; }
void setHeaderBackground(const QColor &color) { m_headerBackground = color; }
void setHeaderForeground(const QColor &color) { m_headerForeground = color; }
void setUseHeaderBackground(const bool on) { m_useHeaderBackground = on; }
void setFooterBackground(const QColor &color) { m_footerBackground = color; }
void setFooterForeground(const QColor &color) { m_footerForeground = color; }
void setUseFooterBackground(const bool on) { m_useFooterBackground = on; }
void setHeaderFormat(const QStringList &list) { m_headerFormat = list; }
void setFooterFormat(const QStringList &list) { m_footerFormat = list; }
private:
KateDocument *m_doc;
QString m_colorScheme;
bool m_printGuide;
bool m_printLineNumbers;
bool m_useHeader;
bool m_useFooter;
bool m_useBackground;
bool m_useBox;
bool m_useHeaderBackground;
bool m_useFooterBackground;
int m_boxMargin;
int m_boxWidth;
QColor m_boxColor;
QColor m_headerBackground;
QColor m_headerForeground;
QColor m_footerBackground;
QColor m_footerForeground;
QFont m_fhFont;
QStringList m_headerFormat;
QStringList m_footerFormat;
};
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment