Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit fa7f0a25 authored by Joachim Eibl's avatar Joachim Eibl

Handling of Tabs and white space

parent 706e3427
......@@ -318,7 +318,9 @@ int DiffTextWindow::getMaxTextWidth()
for( int i = 0; i< d->m_size; ++i )
{
QTextLayout textLayout( d->getString(i), font(), this );
// TODO: Tabs
QTextOption textOption;
textOption.setTabStop( fontMetrics().width(' ') * d->m_pOptions->m_tabSize );
textLayout.setTextOption( textOption );
textLayout.beginLayout();
/*QTextLine textLine = */textLayout.createLine();
textLayout.endLayout();
......@@ -666,6 +668,9 @@ void DiffTextWindow::convertToLinePos( int x, int y, int& line, int& pos )
{
QString s = d->getLineString( line );
QTextLayout textLayout( s, font(), this );
QTextOption textOption;
textOption.setTabStop( fontMetrics().width(' ') * d->m_pOptions->m_tabSize );
textLayout.setTextOption( textOption );
textLayout.beginLayout();
QTextLine line = textLayout.createLine();
textLayout.endLayout();
......@@ -754,12 +759,31 @@ private:
qreal m_width;
MyPainter* m_pPainter;
QFontMetrics m_fm;
int m_tabStop;
bool m_bShowWhiteSpaceCharacters;
QVector<QTextLayout::FormatRange> m_formatRanges;
void draw()
{
if ( m_pPainter && !m_text.isEmpty() )
{
QTextLayout textLayout( m_text, m_font, m_pPainter->device() );
QTextOption textOption;
textOption.setTabStop( m_tabStop );
if ( m_bShowWhiteSpaceCharacters )
textOption.setFlags( QTextOption::ShowTabsAndSpaces );
textLayout.setTextOption( textOption );
if ( m_bShowWhiteSpaceCharacters )
{
// This additional format is only necessary for the tab arrow
QList<QTextLayout::FormatRange> formats;
QTextLayout::FormatRange formatRange;
formatRange.start = 0;
formatRange.length = m_text.length();
formatRange.format.setFont( m_font );
formats.append( formatRange );
textLayout.setAdditionalFormats(formats);
}
textLayout.beginLayout();
QTextLine line = textLayout.createLine();
line.setPosition(QPointF(0, m_fm.leading()));
......@@ -772,7 +796,7 @@ private:
}
}
public:
DrawTextOptimizer( MyPainter* pPainter, int x, int y )
DrawTextOptimizer( MyPainter* pPainter, int x, int y, int tabStop, bool bShowWhiteSpaceCharacters )
: m_fm(pPainter->fontMetrics())
{
m_pos = QPoint(x,y);
......@@ -781,6 +805,8 @@ public:
m_pen = m_pPainter->pen();
m_background = QColor(Qt::white); // TODO
m_width = 0;
m_tabStop = tabStop;
m_bShowWhiteSpaceCharacters = bShowWhiteSpaceCharacters;
}
~DrawTextOptimizer() { end(); }
void setFont( const QFont& f )
......@@ -920,21 +946,12 @@ void DiffTextWindowData::writeLine(
int lineLength = m_bWordWrap ? wrapLineOffset+wrapLineLength : lineString.length();
DrawTextOptimizer dto( &p, xOffset, yOffset + fontAscent );
DrawTextOptimizer dto( &p, xOffset, yOffset + fontAscent, fm.width(' ') * m_pOptions->m_tabSize,
m_pOptions->m_bShowWhiteSpaceCharacters );
for( i=wrapLineOffset; i<lineLength; ++i )
{
int spaces = 1;
if ( lineString[i]=='\t' )
{
spaces = tabber( outPos, m_pOptions->m_tabSize );
s[0] = ' ';
}
else
{
s[0] = lineString[i];
}
s[0] = lineString[i];
QColor c = m_pOptions->m_fgColor;
int cchanged = charChanged[i] | whatChanged;
......@@ -970,17 +987,14 @@ void DiffTextWindowData::writeLine(
}
dto.setPen( c );
if ( s[0]==' ' && c!=m_pOptions->m_fgColor && charChanged[i]!=0 )
{
if ( m_pOptions->m_bShowWhiteSpaceCharacters && m_pOptions->m_bShowWhiteSpace)
{
dto.setBackground(c);
}
}
else
{
dto.drawText( s );
}
// if ( (s[0]==' ' || s[0]=='\t') && c!=m_pOptions->m_fgColor && charChanged[i]!=0 )
// {
// if ( m_pOptions->m_bShowWhiteSpaceCharacters && m_pOptions->m_bShowWhiteSpace)
// {
// dto.setBackground(c);
// }
// }
dto.drawText( s );
dto.setFont(normalFont);
}
else
......@@ -993,7 +1007,7 @@ void DiffTextWindowData::writeLine(
}
}
outPos += spaces;
++outPos;
} // end for
dto.end();
// if( m_selection.lineWithin( line ) && m_selection.lineWithin( line+1 ) )
......@@ -1617,6 +1631,9 @@ void DiffTextWindow::recalcWordWrap( bool bWordWrap, int wrapLineVectorSize, int
int leading = fontMetrics().leading();
qreal height = 0;
QTextLayout textLayout( s, font(), this);
QTextOption textOption;
textOption.setTabStop( fontMetrics().width(' ') * d->m_pOptions->m_tabSize );
textLayout.setTextOption( textOption );
textLayout.beginLayout();
while (1) {
QTextLine line = textLayout.createLine();
......
......@@ -557,7 +557,7 @@ void KDiff3App::initActions( KActionCollection* ac )
chooseC = KDiff3::createAction< KToggleAction >(i18n("Select Line(s) From C"), QIcon(QPixmap(iconC)), i18n("Choose\nC"), KShortcut( Qt::CTRL+Qt::Key_3 ), this, SLOT(slotChooseC()), ac, "merge_choose_c");
autoAdvance = KDiff3::createAction< KToggleAction >(i18n("Automatically Go to Next Unsolved Conflict After Source Selection"), QIcon(QPixmap(autoadvance)), i18n("Auto\nNext"), this, SLOT(slotAutoAdvanceToggled()), ac, "merge_autoadvance");
showWhiteSpaceCharacters = KDiff3::createAction< KToggleAction >(i18n("Show Space && Tabulator Characters for Differences"), QIcon(QPixmap(showwhitespacechars)), i18n("White\nCharacters"), this, SLOT(slotShowWhiteSpaceToggled()), ac, "diff_show_whitespace_characters");
showWhiteSpaceCharacters = KDiff3::createAction< KToggleAction >(i18n("Show Space && Tabulator Characters"), QIcon(QPixmap(showwhitespacechars)), i18n("White\nCharacters"), this, SLOT(slotShowWhiteSpaceToggled()), ac, "diff_show_whitespace_characters");
showWhiteSpace = KDiff3::createAction< KToggleAction >(i18n("Show White Space"), QIcon(QPixmap(showwhitespace)), i18n("White\nDeltas"), this, SLOT(slotShowWhiteSpaceToggled()), ac, "diff_show_whitespace");
showLineNumbers = KDiff3::createAction< KToggleAction >(i18n("Show Line Numbers"), QIcon(QPixmap(showlinenumbers)), i18n("Line\nNumbers"), this, SLOT(slotShowLineNumbersToggled()), ac, "diff_showlinenumbers");
......
......@@ -766,9 +766,11 @@ KFontChooser::KFontChooser( QWidget* pParent )
m_pLabel = new QLabel( "", this );
m_pLabel->setFont( m_font );
m_pLabel->setMinimumWidth(200);
m_pLabel->setText( "The quick brown fox jumps over the river\n"
QChar visualTab(0x2192);
QChar visualSpace((ushort)0xb7);
m_pLabel->setText( QString("The quick brown fox jumps over the river\n"
"but the little red hen escapes with a shiver.\n"
":-)");
":-)")+visualTab+visualSpace);
pLayout->addWidget(m_pLabel);
}
......@@ -786,29 +788,9 @@ void KFontChooser::setFont( const QFont& font, bool )
void KFontChooser::slotSelectFont()
{
for(;;)
{
bool bOk;
m_font = QFontDialog::getFont(&bOk, m_font );
m_pLabel->setFont( m_font );
QFontMetrics fm(m_font);
// Variable width font.
if ( fm.width('W')!=fm.width('i') )
{
int result = KMessageBox::warningYesNo(m_pParent, i18n(
"You selected a variable width font.\n\n"
"Because this program doesn't handle variable width fonts\n"
"correctly, you might experience problems while editing.\n\n"
"Do you want to continue or do you want to select another font."),
i18n("Incompatible font."),
i18n("Continue at my own risk"), i18n("Select another font"));
if (result==KMessageBox::Yes)
return;
}
else
return;
}
bool bOk;
m_font = QFontDialog::getFont(&bOk, m_font );
m_pLabel->setFont( m_font );
}
......
This diff is collapsed.
......@@ -378,7 +378,7 @@ private:
int srcSelect, e_MergeDetails mergeDetails, int rangeMark, bool bUserModified, bool bLineRemoved, bool bWhiteSpaceConflict
);
void setFastSelector(MergeLineList::iterator i);
void convertToLinePos( int x, int y, int& line, int& pos );
int convertToLine( int y );
bool event(QEvent*);
virtual void mousePressEvent ( QMouseEvent* e );
virtual void mouseDoubleClickEvent ( QMouseEvent* e );
......@@ -392,7 +392,6 @@ private:
QPixmap m_pixmap;
int m_firstLine;
int m_horizScrollOffset;
int m_nofColumns;
int m_nofLines;
int m_totalSize; //Same as m_nofLines, but calculated differently
bool m_bMyUpdate;
......@@ -405,7 +404,7 @@ private:
int m_cursorXPos;
int m_cursorXPixelPos;
int m_cursorYPos;
int m_cursorOldXPos;
int m_cursorOldXPixelPos;
bool m_bCursorOn; // blinking on and off each second
QTimer m_cursorTimer;
bool m_bCursorUpdate;
......
......@@ -1711,23 +1711,6 @@ void OptionDialog::slotOk( void )
{
slotApply();
// My system returns variable width fonts even though I
// disabled this. Even QFont::fixedPitch() doesn't work.
QFontMetrics fm(m_options.m_font);
if ( fm.width('W')!=fm.width('i') )
{
int result = KMessageBox::warningYesNo(this, i18n(
"You selected a variable width font.\n\n"
"Because this program doesn't handle variable width fonts\n"
"correctly, you might experience problems while editing.\n\n"
"Do you want to continue or do you want to select another font."),
i18n("Incompatible Font"),
KGuiItem( i18n("Continue at Own Risk") ),
KGuiItem( i18n("Select Another Font")) );
if (result==KMessageBox::No)
return;
}
accept();
}
......
......@@ -1646,14 +1646,14 @@ void KDiff3App::slotShowWhiteSpaceToggled()
m_pOptions->m_bShowWhiteSpaceCharacters = showWhiteSpaceCharacters->isChecked();
m_pOptions->m_bShowWhiteSpace = showWhiteSpace->isChecked();
showWhiteSpaceCharacters->setEnabled( showWhiteSpace->isChecked() );
if ( m_pDiffTextWindow1!=0 )
m_pDiffTextWindow1->update();
if ( m_pDiffTextWindow2!=0 )
m_pDiffTextWindow2->update();
if ( m_pDiffTextWindow3!=0 )
m_pDiffTextWindow3->update();
if ( m_pMergeResultWindow !=0 )
m_pMergeResultWindow->update();
if ( m_pOverview!=0 )
m_pOverview->slotRedraw();
}
......
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