Commit a8a182bc authored by Michael Reeves's avatar Michael Reeves

Update QT API usage.

parent dca8fa43
......@@ -21,6 +21,7 @@
#ifndef UTILS_H
#define UTILS_H
#include <QFontMetrics>
#include <QStringList>
#include <QString>
......@@ -29,6 +30,27 @@ class Utils{
static bool wildcardMultiMatch(const QString& wildcard, const QString& testString, bool bCaseSensitive);
static QString getArguments(QString cmd, QString& program, QStringList& args);
inline static bool isEndOfLine( QChar c ) { return c=='\n' || c=='\r' || c=='\x0b'; }
//Where posiable use QTextLayout in place of these functions especially when dealing with non-latin scripts.
inline static int getHorizontalAdvance(const QFontMetrics &metrics, const QString& s)
{
//Warning: The Qt API used here is not accurate for some non-latin characters.
#if QT_VERSION < QT_VERSION_CHECK(5,12,0)
return metrics.width(s);
#else
return metrics.horizontalAdvance(s);
#endif
}
inline static int getHorizontalAdvance(const QFontMetrics &metrics, const QChar& c)
{
//Warning: The Qt API used here is not accurate for some non-latin characters.
#if QT_VERSION < QT_VERSION_CHECK(5,12,0)
return metrics.width(s);
#else
return metrics.horizontalAdvance(c);
#endif
}
};
#endif
......@@ -92,7 +92,7 @@ class LineData
QtNumberType mFirstNonWhiteChar = 0;
qint64 mOffset = 0;
QtNumberType mSize = 0;
Q_DECL_DEPRECATED bool bContainsPureComment = false;
bool bContainsPureComment = false;//TODO: Move me
public:
explicit LineData() = default; // needed for Qt internal reasons should not be used.
......
......@@ -290,7 +290,7 @@ int DiffTextWindow::getFirstLine()
void DiffTextWindow::setHorizScrollOffset(int horizScrollOffset)
{
int fontWidth = fontMetrics().width('0');
int fontWidth = Utils::getHorizontalAdvance(fontMetrics(), '0');
int xOffset = d->leftInfoWidth() * fontWidth;
int deltaX = d->m_horizScrollOffset - std::max(0, horizScrollOffset);
......@@ -436,7 +436,7 @@ void DiffTextWindow::mousePressEvent(QMouseEvent* e)
int pos;
convertToLinePos(e->x(), e->y(), line, pos);
int fontWidth = fontMetrics().width('0');
int fontWidth = Utils::getHorizontalAdvance(fontMetrics(), '0');
int xOffset = d->leftInfoWidth() * fontWidth;
if((!d->m_pOptions->m_bRightToLeftLanguage && e->x() < xOffset) || (d->m_pOptions->m_bRightToLeftLanguage && e->x() > width() - xOffset))
......@@ -566,7 +566,7 @@ void DiffTextWindow::mouseMoveEvent(QMouseEvent* e)
// Scroll because mouse moved out of the window
const QFontMetrics& fm = fontMetrics();
int fontWidth = fm.width('0');
int fontWidth = Utils::getHorizontalAdvance(fm, '0');
int deltaX = 0;
int deltaY = 0;
if(!d->m_pOptions->m_bRightToLeftLanguage)
......@@ -760,7 +760,7 @@ void DiffTextWindowData::prepareTextLayout(QTextLayout& textLayout, bool /*bFirs
int leading = m_pDiffTextWindow->fontMetrics().leading();
int height = 0;
int fontWidth = m_pDiffTextWindow->fontMetrics().width('0');
int fontWidth = Utils::getHorizontalAdvance(m_pDiffTextWindow->fontMetrics(), '0');
int xOffset = leftInfoWidth() * fontWidth - m_horizScrollOffset;
int textWidth = visibleTextWidth;
if(textWidth < 0)
......@@ -817,7 +817,7 @@ void DiffTextWindowData::writeLine(
const QFontMetrics& fm = p.fontMetrics();
int fontHeight = fm.lineSpacing();
int fontAscent = fm.ascent();
int fontWidth = fm.width('0');
int fontWidth = Utils::getHorizontalAdvance(fm, '0');
int xOffset = leftInfoWidth() * fontWidth - m_horizScrollOffset;
int yOffset = (line - m_firstLine) * fontHeight;
......@@ -1031,7 +1031,7 @@ void DiffTextWindow::paintEvent(QPaintEvent* e)
int endLine = std::min(d->m_firstLine + getNofVisibleLines() + 2, getNofLines());
RLPainter p(this, d->m_pOptions->m_bRightToLeftLanguage, width(), fontMetrics().width('0'));
RLPainter p(this, d->m_pOptions->m_bRightToLeftLanguage, width(), Utils::getHorizontalAdvance(fontMetrics(), '0'));
p.setFont(font());
p.QPainter::fillRect(invalidRect, d->m_pOptions->m_bgColor);
......@@ -1187,7 +1187,7 @@ void DiffTextWindow::resizeEvent(QResizeEvent* e)
QSize s = e->size();
QFontMetrics fm = fontMetrics();
int visibleLines = s.height() / fm.lineSpacing() - 2;
int visibleColumns = s.width() / fm.width('0') - d->leftInfoWidth();
int visibleColumns = s.width() / Utils::getHorizontalAdvance(fm, '0') - d->leftInfoWidth();
if(e->size().height() != e->oldSize().height())
emit resizeHeightChangedSignal(visibleLines);
if(e->size().width() != e->oldSize().width())
......@@ -1206,7 +1206,7 @@ int DiffTextWindow::getNofVisibleLines()
int DiffTextWindow::getVisibleTextAreaWidth()
{
QFontMetrics fm = fontMetrics();
return width() - d->leftInfoWidth() * fm.width('0');
return width() - d->leftInfoWidth() * Utils::getHorizontalAdvance(fm, '0');
}
QString DiffTextWindow::getSelection()
......@@ -1580,7 +1580,7 @@ void DiffTextWindow::recalcWordWrapHelper(int wrapLineVectorSize, int visibleTex
if(visibleTextWidth < 0)
visibleTextWidth = getVisibleTextAreaWidth();
else
visibleTextWidth -= d->leftInfoWidth() * fontMetrics().width('0');
visibleTextWidth -= d->leftInfoWidth() * Utils::getHorizontalAdvance(fontMetrics(), '0');
int i;
int wrapLineIdx = 0;
int size = d->m_pDiff3LineVector->size();
......@@ -1841,8 +1841,7 @@ void DiffTextWindowFrame::setFirstLine(int firstLine)
int l = pDTW->calcTopLineInFile(firstLine);
int w = d->m_pTopLine->fontMetrics().width(
s + ' ' + QString().fill('0', lineNumberWidth));
int w = Utils::getHorizontalAdvance(d->m_pTopLine->fontMetrics(), s + ' ' + QString().fill('0', lineNumberWidth));
d->m_pTopLine->setMinimumWidth(w);
if(l == -1)
......
......@@ -591,13 +591,14 @@ class DirectoryMergeWindow::DirMergeItemDelegate : public QStyledItemDelegate
thePainter->drawRect(x + 1, y + yOffset - 1, icon.width() + 2, icon.height() + 2);
thePainter->setPen(Qt::white);
QString s(QChar('A' + i - 1));
thePainter->drawText(x + 2 + (icon.width() - thePainter->fontMetrics().width(s)) / 2,
thePainter->drawText(x + 2 + (icon.width() - Utils::getHorizontalAdvance(thePainter->fontMetrics(), s)) / 2,
y + yOffset + (icon.height() + thePainter->fontMetrics().ascent()) / 2 - 1,
s);
}
else
{
thePainter->setPen(m_pDMW->palette().background().color());
thePainter->setPen(m_pDMW->palette().window().color());
thePainter->drawRect(x + 1, y + yOffset - 1, icon.width() + 2, icon.height() + 2);
}
return;
......
......@@ -133,7 +133,7 @@ void FileAccess::loadData()
m_fileInfo.setCaching(true);
if(parent() == nullptr)
m_baseDir = m_fileInfo.absoluteFilePath();
m_baseDir.setPath(m_fileInfo.absoluteFilePath());
else
m_baseDir = m_pParent->m_baseDir;
......
......@@ -816,7 +816,7 @@ void printDiffTextWindow(RLPainter& painter, const QRect& view, const QString& h
painter.translate(0, view.top());
pDiffTextWindow->print(painter, view, line, linesPerPage);
painter.resetMatrix();
painter.resetTransform();
}
void KDiff3App::slotFilePrint()
......@@ -863,7 +863,7 @@ void KDiff3App::slotFilePrint()
{
slotStatusMsg(i18n("Printing..."));
// create a painter to paint on the printer object
RLPainter painter(&printer, m_pOptions->m_bRightToLeftLanguage, width(), fontMetrics().width('W'));
RLPainter painter(&printer, m_pOptions->m_bRightToLeftLanguage, width(), Utils::getHorizontalAdvance(fontMetrics(),'W'));
QPaintDevice* pPaintDevice = painter.device();
int dpiy = pPaintDevice->logicalDpiY();
......@@ -880,7 +880,7 @@ void KDiff3App::slotFilePrint()
QString topLineText = i18n("Top line");
//int headerWidth = fm.width( m_sd1.getAliasName() + ", "+topLineText+": 01234567" );
int headerLines = fm.width(m_sd1.getAliasName() + ", " + topLineText + ": 01234567") / columnWidth + 1;
int headerLines = Utils::getHorizontalAdvance(fm, m_sd1.getAliasName() + ", " + topLineText + ": 01234567") / columnWidth + 1;
int headerMargin = headerLines * fm.height() + 3; // Text + one horizontal line
int footerMargin = fm.height() + 3;
......@@ -1005,7 +1005,7 @@ void KDiff3App::slotFilePrint()
QString s = bPrintCurrentPage ? QString("")
: QString::number(page) + '/' + QString::number(totalNofPages);
if(bPrintSelection) s += i18n(" (Selection)");
painter.drawText((view.right() - painter.fontMetrics().width(s)) / 2,
painter.drawText((view.right() - Utils::getHorizontalAdvance(painter.fontMetrics(), s)) / 2,
view.bottom() + painter.fontMetrics().ascent() + 5, s);
bFirstPrintedPage = true;
......
......@@ -665,7 +665,7 @@ int MergeResultWindow::getNofVisibleLines()
int MergeResultWindow::getTextXOffset()
{
QFontMetrics fm = fontMetrics();
return 3 * fm.width('0');
return 3 * Utils::getHorizontalAdvance(fm, '0');
}
void MergeResultWindow::resizeEvent(QResizeEvent* e)
......@@ -1874,7 +1874,7 @@ void MergeResultWindow::writeLine(
else
Q_ASSERT(true);
xOffset -= fm.width('0');
xOffset -= Utils::getHorizontalAdvance(fm, '0');
p.setPen(m_pOptions->m_fgColor);
if(rangeMark & 1) // begin mark
{
......@@ -1924,7 +1924,7 @@ void MergeResultWindow::paintEvent(QPaintEvent*)
bool bOldSelectionContainsData = m_selection.selectionContainsData();
const QFontMetrics& fm = fontMetrics();
int fontWidth = fm.width('0');
int fontWidth = Utils::getHorizontalAdvance(fm, '0');
if(!m_bCursorUpdate) // Don't redraw everything for blinking cursor?
{
......@@ -2214,7 +2214,7 @@ void MergeResultWindow::mouseMoveEvent(QMouseEvent* e)
// Scroll because mouse moved out of the window
const QFontMetrics& fm = fontMetrics();
int fontWidth = fm.width('0');
int fontWidth = Utils::getHorizontalAdvance(fm, '0');
int topLineYOffset = 0;
int deltaX = 0;
int deltaY = 0;
......
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