-
-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
423 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* This file is part of Notepad Next. | ||
* Copyright 2022 Justin Dailey | ||
* | ||
* Notepad Next is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Notepad Next 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Notepad Next. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#include "EditorPrintPreviewRenderer.h" | ||
#include "ScintillaNext.h" | ||
|
||
#include <QPrinter> | ||
#include <QDebug> | ||
#include <QPainter> | ||
|
||
EditorPrintPreviewRenderer::EditorPrintPreviewRenderer(ScintillaNext *editor) | ||
: QObject(), editor(editor) | ||
{ | ||
} | ||
|
||
void EditorPrintPreviewRenderer::render(QPrinter *printer) | ||
{ | ||
QRectF printableArea(QPointF(0, 0), printer->pageRect(QPrinter::DevicePixel).size()); | ||
|
||
qInfo() << "Print from page" << printer->fromPage() << "to" << printer->toPage(); | ||
qInfo() << "Paper:" << printer->paperRect(QPrinter::DevicePixel); | ||
qInfo() << "Page:" << printer->pageRect(QPrinter::DevicePixel); | ||
qInfo() << "Printable Area:" << printableArea; | ||
|
||
const int fromPage = printer->fromPage(); | ||
const int toPage = printer->toPage(); | ||
|
||
// The printer starts with a valid page initially | ||
bool needsNewPage = false; | ||
|
||
int startPos = 0; | ||
int pageNum = 1; | ||
|
||
QPainter painter(printer); | ||
|
||
do { | ||
bool needsToDraw = (fromPage == 0 && toPage == 0) || (fromPage <= pageNum && pageNum <= toPage); | ||
|
||
if (needsToDraw) { | ||
if (needsNewPage) { | ||
printer->newPage(); | ||
} | ||
else { | ||
needsNewPage = true; | ||
} | ||
} | ||
|
||
startPos = editor->formatRange(needsToDraw, printer, printer, | ||
printableArea.toRect(), printer->paperRect(QPrinter::DevicePixel).toRect(), | ||
startPos, editor->length()); | ||
|
||
pageNum++; | ||
} while (startPos < editor->length()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* This file is part of Notepad Next. | ||
* Copyright 2022 Justin Dailey | ||
* | ||
* Notepad Next is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Notepad Next 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Notepad Next. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#ifndef EDITORPRINTPREVIEWRENDERER_H | ||
#define EDITORPRINTPREVIEWRENDERER_H | ||
|
||
#include <QObject> | ||
|
||
|
||
class ScintillaNext; | ||
class QPrinter; | ||
|
||
class EditorPrintPreviewRenderer : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit EditorPrintPreviewRenderer(ScintillaNext *editor); | ||
|
||
public slots: | ||
void render(QPrinter *printer); | ||
|
||
private: | ||
ScintillaNext *editor; | ||
}; | ||
|
||
#endif // EDITORPRINTPREVIEWRENDERER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.