Commit 18f3466e authored by Michael Reeves's avatar Michael Reeves

Move and rename custom painter

parent cdd175db
......@@ -14,6 +14,7 @@
#include "diff.h"
#include <QMouseEvent>
#include <QPainter>
#include <QPixmap>
#include <QSize>
......
/***************************************************************************
* Copyright (C) 2003-2007 by Joachim Eibl <joachim.eibl at gmx.de> *
* Copyright (C) 2018 Michael Reeves reeves.87@gmail.com *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef RLPAINTER_H
#define RLPAINTER_H
#include <QPainter>
// Helper class that swaps left and right for some commands.
class RLPainter : public QPainter
{
int m_factor;
int m_xOffset;
int m_fontWidth;
public:
RLPainter(QPaintDevice* pd, bool bRTL, int width, int fontWidth)
: QPainter(pd)
{
if(bRTL)
{
m_fontWidth = fontWidth;
m_factor = -1;
m_xOffset = width - 1;
}
else
{
m_fontWidth = 0;
m_factor = 1;
m_xOffset = 0;
}
}
void fillRect(int x, int y, int w, int h, const QBrush& b)
{
if(m_factor == 1)
QPainter::fillRect(m_xOffset + x, y, w, h, b);
else
QPainter::fillRect(m_xOffset - x - w, y, w, h, b);
}
void drawText(int x, int y, const QString& s, bool bAdapt = false)
{
Qt::LayoutDirection ld = (m_factor == 1 || !bAdapt) ? Qt::LeftToRight : Qt::RightToLeft;
//QPainter::setLayoutDirection( ld );
if(ld == Qt::RightToLeft) // Reverse the text
{
QString s2;
for(int i = s.length() - 1; i >= 0; --i)
{
s2 += s[i];
}
QPainter::drawText(m_xOffset - m_fontWidth * s.length() + m_factor * x, y, s2);
return;
}
QPainter::drawText(m_xOffset - m_fontWidth * s.length() + m_factor * x, y, s);
}
void drawLine(int x1, int y1, int x2, int y2)
{
QPainter::drawLine(m_xOffset + m_factor * x1, y1, m_xOffset + m_factor * x2, y2);
}
};
#endif
......@@ -12,7 +12,6 @@
#ifndef DIFF_H
#define DIFF_H
#include <QPainter>
#include <QList>
#include "common.h"
......@@ -363,61 +362,6 @@ void correctManualDiffAlignment(Diff3LineList& d3ll, ManualDiffHelpList* pManual
void calcDiff3LineListTrim(Diff3LineList& d3ll, const LineData* pldA, const LineData* pldB, const LineData* pldC, ManualDiffHelpList* pManualDiffHelpList);
// Helper class that swaps left and right for some commands.
class MyPainter : public QPainter
{
int m_factor;
int m_xOffset;
int m_fontWidth;
public:
MyPainter(QPaintDevice* pd, bool bRTL, int width, int fontWidth)
: QPainter(pd)
{
if(bRTL)
{
m_fontWidth = fontWidth;
m_factor = -1;
m_xOffset = width - 1;
}
else
{
m_fontWidth = 0;
m_factor = 1;
m_xOffset = 0;
}
}
void fillRect(int x, int y, int w, int h, const QBrush& b)
{
if(m_factor == 1)
QPainter::fillRect(m_xOffset + x, y, w, h, b);
else
QPainter::fillRect(m_xOffset - x - w, y, w, h, b);
}
void drawText(int x, int y, const QString& s, bool bAdapt = false)
{
Qt::LayoutDirection ld = (m_factor == 1 || !bAdapt) ? Qt::LeftToRight : Qt::RightToLeft;
//QPainter::setLayoutDirection( ld );
if(ld == Qt::RightToLeft) // Reverse the text
{
QString s2;
for(int i = s.length() - 1; i >= 0; --i)
{
s2 += s[i];
}
QPainter::drawText(m_xOffset - m_fontWidth * s.length() + m_factor * x, y, s2);
return;
}
QPainter::drawText(m_xOffset - m_fontWidth * s.length() + m_factor * x, y, s);
}
void drawLine(int x1, int y1, int x2, int y2)
{
QPainter::drawLine(m_xOffset + m_factor * x1, y1, m_xOffset + m_factor * x2, y2);
}
};
bool fineDiff(
Diff3LineList& diff3LineList,
......
......@@ -16,6 +16,7 @@
#include "kdiff3.h"
#include "merger.h"
#include "options.h"
#include "RLPainter.h"
#include <algorithm>
#include <cmath>
......@@ -131,12 +132,12 @@ class DiffTextWindowData
QString getLineString(int line);
void writeLine(
MyPainter& p, const LineData* pld,
RLPainter& p, const LineData* pld,
const DiffList* pLineDiff1, const DiffList* pLineDiff2, int line,
int whatChanged, int whatChanged2, int srcLineIdx,
int wrapLineOffset, int wrapLineLength, bool bWrapLine, const QRect& invalidRect, int deviceWidth);
void draw(MyPainter& p, const QRect& invalidRect, int deviceWidth, int beginLine, int endLine);
void draw(RLPainter& p, const QRect& invalidRect, int deviceWidth, int beginLine, int endLine);
QStatusBar* m_pStatusBar;
......@@ -791,7 +792,7 @@ void DiffTextWindowData::prepareTextLayout(QTextLayout& textLayout, bool /*bFirs
}
void DiffTextWindowData::writeLine(
MyPainter& p,
RLPainter& p,
const LineData* pld,
const DiffList* pLineDiff1,
const DiffList* pLineDiff2,
......@@ -1024,7 +1025,7 @@ void DiffTextWindow::paintEvent(QPaintEvent* e)
int endLine = std::min(d->m_firstLine + getNofVisibleLines() + 2, getNofLines());
MyPainter p(this, d->m_pOptions->m_bRightToLeftLanguage, width(), fontMetrics().width('0'));
RLPainter p(this, d->m_pOptions->m_bRightToLeftLanguage, width(), fontMetrics().width('0'));
p.setFont(font());
p.QPainter::fillRect(invalidRect, d->m_pOptions->m_bgColor);
......@@ -1039,7 +1040,7 @@ void DiffTextWindow::paintEvent(QPaintEvent* e)
emit newSelection();
}
void DiffTextWindow::print(MyPainter& p, const QRect&, int firstLine, int nofLinesPerPage)
void DiffTextWindow::print(RLPainter& p, const QRect&, int firstLine, int nofLinesPerPage)
{
if(d->m_pDiff3LineVector == nullptr || !updatesEnabled() ||
(d->m_diff3WrapLineVector.empty() && d->m_bWordWrap))
......@@ -1055,7 +1056,7 @@ void DiffTextWindow::print(MyPainter& p, const QRect&, int firstLine, int nofLin
d->m_firstLine = oldFirstLine;
}
void DiffTextWindowData::draw(MyPainter& p, const QRect& invalidRect, int deviceWidth, int beginLine, int endLine)
void DiffTextWindowData::draw(RLPainter& p, const QRect& invalidRect, int deviceWidth, int beginLine, int endLine)
{
m_lineNumberWidth = m_pOptions->m_bShowLineNumbers ? (int)log10((double)std::max(m_size, 1)) + 1 : 0;
......
......@@ -23,6 +23,7 @@ class Options;
class DiffTextWindowData;
class DiffTextWindowFrame;
class EncodingLabel;
class RLPainter;
class DiffTextWindow : public QWidget
{
......@@ -67,7 +68,7 @@ public:
void setPaintingAllowed( bool bAllowPainting );
void recalcWordWrap( bool bWordWrap, int wrapLineVectorSize, int visibleTextWidth);
void recalcWordWrapHelper( int wrapLineVectorSize, int visibleTextWidth, int cacheListIdx);
void print( MyPainter& painter, const QRect& r, int firstLine, int nofLinesPerPage );
void print( RLPainter& painter, const QRect& r, int firstLine, int nofLinesPerPage );
Q_SIGNALS:
void resizeHeightChangedSignal(int nofVisibleLines);
void resizeWidthChangedSignal(int nofVisibleColumns);
......
......@@ -39,6 +39,7 @@
#include <QSplitter>
#include <QStyledItemDelegate>
#include <QTextStream>
#include <QPainter>
#include <KLocalizedString>
#include <KMessageBox>
......
......@@ -22,6 +22,7 @@
#include "smalldialogs.h"
#include "difftextwindow.h"
#include "mergeresultwindow.h"
#include "RLPainter.h"
// include files for QT
#include <QClipboard>
#include <QCheckBox>
......@@ -58,7 +59,7 @@
#define ID_STATUS_MSG 1
#define MAIN_TOOLBAR_NAME QLatin1String("mainToolBar")
void printDiffTextWindow(MyPainter& painter, const QRect& view, const QString& headerText, DiffTextWindow* pDiffTextWindow, int line, int linesPerPage, const QColor& fgColor);
void printDiffTextWindow(RLPainter& painter, const QRect& view, const QString& headerText, DiffTextWindow* pDiffTextWindow, int line, int linesPerPage, const QColor& fgColor);
KActionCollection* KDiff3App::actionCollection()
{
if(m_pKDiff3Shell == nullptr)
......@@ -767,7 +768,7 @@ void KDiff3App::slotFileSaveAs()
slotStatusMsg(i18n("Ready."));
}
void printDiffTextWindow(MyPainter& painter, const QRect& view, const QString& headerText, DiffTextWindow* pDiffTextWindow, int line, int linesPerPage, const QColor &fgColor)
void printDiffTextWindow(RLPainter& painter, const QRect& view, const QString& headerText, DiffTextWindow* pDiffTextWindow, int line, int linesPerPage, const QColor &fgColor)
{
QRect clipRect = view;
clipRect.setTop(0);
......@@ -846,7 +847,7 @@ void KDiff3App::slotFilePrint()
{
slotStatusMsg(i18n("Printing..."));
// create a painter to paint on the printer object
MyPainter painter(&printer, m_pOptions->m_bRightToLeftLanguage, width(), fontMetrics().width('W'));
RLPainter painter(&printer, m_pOptions->m_bRightToLeftLanguage, width(), fontMetrics().width('W'));
QPaintDevice* pPaintDevice = painter.device();
int dpiy = pPaintDevice->logicalDpiY();
......
......@@ -11,6 +11,7 @@
#include "mergeresultwindow.h"
#include "options.h"
#include "RLPainter.h"
#include <QApplication>
#include <QClipboard>
......@@ -1753,7 +1754,7 @@ QVector<QTextLayout::FormatRange> MergeResultWindow::getTextLayoutForLine(int li
}
void MergeResultWindow::writeLine(
MyPainter& p, int line, const QString& str,
RLPainter& p, int line, const QString& str,
int srcSelect, e_MergeDetails mergeDetails, int rangeMark, bool bUserModified, bool bLineRemoved, bool bWhiteSpaceConflict)
{
const QFontMetrics& fm = fontMetrics();
......@@ -1907,7 +1908,7 @@ void MergeResultWindow::paintEvent(QPaintEvent*)
if(size() != m_pixmap.size())
m_pixmap = QPixmap(size());
MyPainter p(&m_pixmap, m_pOptions->m_bRightToLeftLanguage, width(), fontWidth);
RLPainter p(&m_pixmap, m_pOptions->m_bRightToLeftLanguage, width(), fontWidth);
p.setFont(font());
p.QPainter::fillRect(rect(), m_pOptions->m_bgColor);
......
......@@ -22,6 +22,7 @@
#include <QTextLayout>
class QPainter;
class RLPainter;
enum e_MergeSrcSelector
{
......@@ -307,7 +308,7 @@ private:
void myUpdate(int afterMilliSecs);
void timerEvent(QTimerEvent*) override;
void writeLine(
MyPainter& p, int line, const QString& str,
RLPainter& p, int line, const QString& str,
int srcSelect, e_MergeDetails mergeDetails, int rangeMark, bool bUserModified, bool bLineRemoved, bool bWhiteSpaceConflict
);
void setFastSelector(MergeLineList::iterator i);
......
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