Commit 84e66285 authored by Gustavo Carneiro's avatar Gustavo Carneiro
Browse files

Move printContent to KonsolePrintManager

parent bc386e19
......@@ -506,6 +506,7 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
, _searchResultRect(QRect())
, _drawOverlay(false)
, _scrollBar(nullptr)
, _printManager(nullptr)
{
// terminal applications are not designed with Right-To-Left in mind,
// so the layout is forced to Left-To-Right
......@@ -579,6 +580,18 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
connect(KonsoleSettings::self(), &KonsoleSettings::configChanged, this, &TerminalDisplay::setupHeaderVisibility);
_terminalPainter = new TerminalPainter(this);
auto ldrawBackground = [this](QPainter &painter,
const QRect &rect, const QColor &backgroundColor, bool useOpacitySetting) {
_terminalPainter->drawBackground(painter, rect, backgroundColor, useOpacitySetting);
};
auto ldrawContents = [this](QPainter &paint, const QRect &rect) {
_terminalPainter->drawContents(paint, rect);
};
auto lgetBackgroundColor = [this]() {
return getBackgroundColor();
};
_printManager = new KonsolePrintManager(ldrawBackground, ldrawContents, lgetBackgroundColor);
}
TerminalDisplay::~TerminalDisplay()
......@@ -595,6 +608,7 @@ TerminalDisplay::~TerminalDisplay()
_outputSuspendedMessageWidget = nullptr;
delete _terminalPainter;
delete _printManager;
}
void TerminalDisplay::setupHeaderVisibility()
......@@ -1029,28 +1043,6 @@ void TerminalDisplay::paintEvent(QPaintEvent* pe)
}
}
void TerminalDisplay::printContent(QPainter& painter, bool friendly)
{
// TODO: Move this code to KonsolePrintManager
// Reinitialize the font with the printers paint device so the font
// measurement calculations will be done correctly
QFont savedFont = getVTFont();
QFont font(savedFont, painter.device());
painter.setFont(font);
setVTFont(font);
QRect rect(0, 0, _usedColumns, _usedLines);
_printerFriendly = friendly;
if (!friendly) {
_terminalPainter->drawBackground(painter, rect, getBackgroundColor(),
true /* use opacity setting */);
}
_terminalPainter->drawContents(painter, rect);
_printerFriendly = false;
setVTFont(savedFont);
}
QPoint TerminalDisplay::cursorPosition() const
{
if (!_screenWindow.isNull()) {
......@@ -3186,14 +3178,21 @@ void TerminalDisplay::applyProfile(const Profile::Ptr &profile)
void TerminalDisplay::printScreen()
{
auto lambda = [this](QPainter& painter, bool friendly) {
printContent(painter, friendly);
auto lprintContent = [this](QPainter &painter, bool friendly) {
_printerFriendly = friendly;
QPoint columnLines(_usedLines, _usedColumns);
auto lfontget = [this]() { return getVTFont(); };
auto lfontset = [this](const QFont &f) { setVTFont(f); };
_printManager->printContent(painter, friendly, columnLines, lfontget, lfontset);
_printerFriendly = false;
};
KonsolePrintManager::printRequest(lambda, this);
_printManager->printRequest(lprintContent, this);
}
Character TerminalDisplay::getCursorCharacter(int column, int line)
{
return _image[loc(column, line)];
}
......@@ -52,6 +52,8 @@ namespace Konsole {
class TerminalPainter;
class TerminalScrollBar;
class KonsolePrintManager;
class FilterChain;
class TerminalImageFilterChain;
class SessionController;
......@@ -334,9 +336,6 @@ public:
*/
void selectAll();
// TODO: Move this code to KonsolePrintManager
void printContent(QPainter &painter, bool friendly);
/**
* Gets the foreground of the display
* @see setForegroundColor(), setColorTable(), setBackgroundColor()
......@@ -840,6 +839,8 @@ private:
TerminalPainter *_terminalPainter;
TerminalScrollBar *_scrollBar;
KonsolePrintManager *_printManager;
};
}
......
......@@ -26,6 +26,9 @@
#include "PrintOptions.h"
// Qt
#include <QRect>
#include <QFont>
#include <QPoint>
#include <QWidget>
#include <QPrinter>
#include <QPainter>
......@@ -38,6 +41,13 @@
using namespace Konsole;
KonsolePrintManager::KonsolePrintManager(pDrawBackground drawBackground, pDrawContents drawContents, pColorGet colorGet)
{
_drawBackground = drawBackground;
_drawContents = drawContents;
_backgroundColor = colorGet;
}
void KonsolePrintManager::printRequest(pPrintContent pContent, QWidget *parent)
{
if (!pContent) {
......@@ -72,3 +82,22 @@ void KonsolePrintManager::printRequest(pPrintContent pContent, QWidget *parent)
pContent(painter, configGroup.readEntry("PrinterFriendly", true));
}
void KonsolePrintManager::printContent(QPainter &painter, bool friendly, QPoint columnsLines,
pVTFontGet vtFontGet, pVTFontSet vtFontSet)
{
// Reinitialize the font with the printers paint device so the font
// measurement calculations will be done correctly
QFont savedFont = vtFontGet();
QFont font(savedFont, painter.device());
painter.setFont(font);
vtFontSet(font);
QRect rect(0, 0, columnsLines.y(), columnsLines.x());
if (!friendly) {
_drawBackground(painter, rect, _backgroundColor(), true);
}
_drawContents(painter, rect);
vtFontSet(savedFont);
}
......@@ -24,6 +24,10 @@
#include <functional>
class QFont;
class QRect;
class QColor;
class QPoint;
class QWidget;
class QPainter;
......@@ -33,7 +37,25 @@ namespace Konsole
{
public:
typedef std::function<void (QPainter&, bool)> pPrintContent;
static void printRequest(pPrintContent pContent, QWidget *parent);
typedef std::function<QFont ()> pVTFontGet;
typedef std::function<void (const QFont)> pVTFontSet;
typedef std::function<void (QPainter &painter,
const QRect &rect,
const QColor &backgroundColor,
bool useOpacitySetting)> pDrawBackground;
typedef std::function<void (QPainter &paint, const QRect &rect)> pDrawContents;
typedef std::function<QColor ()> pColorGet;
KonsolePrintManager(pDrawBackground drawBackground, pDrawContents drawContents, pColorGet colorGet);
~KonsolePrintManager() = default;
void printRequest(pPrintContent pContent, QWidget *parent);
void printContent(QPainter &painter, bool friendly, QPoint columnsLines, pVTFontGet vtFontGet, pVTFontSet vtFontSet);
private:
pDrawBackground _drawBackground;
pDrawContents _drawContents;
pColorGet _backgroundColor;
};
}
......
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