Corrected indentation, added license/copyright

Signed-off-by: Maximilian Güntner <maximilian.guentner@gmail.com>
This commit is contained in:
Maximilian Güntner 2013-11-02 15:23:53 +01:00
parent 04cdfce782
commit 5d93242b34
2 changed files with 93 additions and 82 deletions

View file

@ -1,4 +1,12 @@
/*
* Copyright (c) 2013 Maximilian Güntner <maximilian.guentner@gmail.com>
*
* This file is subject to the terms and conditions of version 2 of
* the GNU General Public License. See the file gpl-2.0.txt in the main
* directory of this archive for more details.
*
* Original License:
*
* This file is part of the Nepomuk widgets collection
* Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr>
*
@ -34,61 +42,60 @@
#include <QtGui/QColor>
#include <QtGui/QPalette>
struct GroupedLineEdit::Private
{
struct Block {
int start;
int end;
QString text;
};
QVector<Block> blocks;
QVector<QColor> colors;
struct GroupedLineEdit::Private {
struct Block {
int start;
int end;
QString text;
};
QVector<Block> blocks;
QVector<QColor> colors;
};
GroupedLineEdit::GroupedLineEdit(QWidget* parent)
: QPlainTextEdit(parent),
d(new Private)
: QPlainTextEdit(parent),
d(new Private)
{
setWordWrapMode(QTextOption::NoWrap);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setWordWrapMode(QTextOption::NoWrap);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
document()->setMaximumBlockCount(1);
document()->setMaximumBlockCount(1);
}
GroupedLineEdit::~GroupedLineEdit()
{
delete d;
delete d;
}
QString GroupedLineEdit::text() const
{
// Remove the block crosses from the text
return toPlainText();
// Remove the block crosses from the text
return toPlainText();
}
int GroupedLineEdit::cursorPosition() const
{
return textCursor().positionInBlock();
return textCursor().positionInBlock();
}
void GroupedLineEdit::addBlock(int start, int end)
{
Private::Block block;
Private::Block block;
block.start = start;
block.end = end;
block.text = text().mid(start, end-start+1).trimmed();
d->blocks.append(block);
viewport()->update();
block.start = start;
block.end = end;
block.text = text().mid(start, end-start+1).trimmed();
d->blocks.append(block);
viewport()->update();
}
void GroupedLineEdit::addColor(QColor color)
{
d->colors.append(color);
d->colors.append(color);
}
void GroupedLineEdit::removeAllColors()
@ -107,98 +114,95 @@ QStringList GroupedLineEdit::getBlockStringList()
void GroupedLineEdit::setCursorPosition(int position)
{
QTextCursor c = textCursor();
c.setPosition(position, QTextCursor::MoveAnchor);
setTextCursor(c);
QTextCursor c = textCursor();
c.setPosition(position, QTextCursor::MoveAnchor);
setTextCursor(c);
}
void GroupedLineEdit::setText(const QString &text)
{
setPlainText(text);
setPlainText(text);
}
void GroupedLineEdit::clear()
{
QPlainTextEdit::clear();
removeAllBlocks();
QPlainTextEdit::clear();
removeAllBlocks();
}
void GroupedLineEdit::selectAll()
{
QTextCursor c = textCursor();
QTextCursor c = textCursor();
c.select(QTextCursor::LineUnderCursor);
c.select(QTextCursor::LineUnderCursor);
setTextCursor(c);
setTextCursor(c);
}
void GroupedLineEdit::removeAllBlocks()
{
d->blocks.clear();
viewport()->update();
d->blocks.clear();
viewport()->update();
}
QSize GroupedLineEdit::sizeHint() const
{
QSize rs(
40,
document()->findBlock(0).layout()->lineAt(0).height() +
document()->documentMargin() * 2 +
frameWidth() * 2
);
QSize rs(
40,
document()->findBlock(0).layout()->lineAt(0).height() +
document()->documentMargin() * 2 +
frameWidth() * 2
);
return rs;
return rs;
}
QSize GroupedLineEdit::minimumSizeHint() const
{
return sizeHint();
return sizeHint();
}
void GroupedLineEdit::keyPressEvent(QKeyEvent *e)
{
switch (e->key()) {
case Qt::Key_Return:
case Qt::Key_Enter:
emit editingFinished();
return;
}
QPlainTextEdit::keyPressEvent(e);
switch (e->key()) {
case Qt::Key_Return:
case Qt::Key_Enter:
emit editingFinished();
return;
}
QPlainTextEdit::keyPressEvent(e);
}
void GroupedLineEdit::paintEvent(QPaintEvent *e)
{
QTextLine line = document()->findBlock(0).layout()->lineAt(0);
QPainter painter(viewport());
QTextLine line = document()->findBlock(0).layout()->lineAt(0);
QPainter painter(viewport());
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
painter.fillRect(0, 0, viewport()->width(), viewport()->height(), palette().base());
painter.fillRect(0, 0, viewport()->width(), viewport()->height(), palette().base());
QVectorIterator<QColor> i(d->colors);
i.toFront();
foreach (const Private::Block &block, d->blocks) {
qreal start_x = line.cursorToX(block.start, QTextLine::Trailing);
qreal end_x = line.cursorToX(block.end + 1, QTextLine::Leading);
QPainterPath path;
QRectF rectangle(
start_x - 1.0 - double(horizontalScrollBar()->value()),
1.0,
end_x - start_x + 2.0,
double(viewport()->height() - 2)
);
if (! i.hasNext())
i.toFront();
path.addRoundedRect(rectangle, 5.0, 5.0);
painter.setPen(i.peekNext());
painter.setBrush(i.next().lighter(180));
painter.drawPath(path);
}
QVectorIterator<QColor> i(d->colors);
i.toFront();
foreach (const Private::Block &block, d->blocks) {
qreal start_x = line.cursorToX(block.start, QTextLine::Trailing);
qreal end_x = line.cursorToX(block.end + 1, QTextLine::Leading);
QPainterPath path;
QRectF rectangle(
start_x - 1.0 - double(horizontalScrollBar()->value()),
1.0,
end_x - start_x + 2.0,
double(viewport()->height() - 2)
);
if (! i.hasNext())
i.toFront();
path.addRoundedRect(rectangle, 5.0, 5.0);
painter.setPen(i.peekNext());
painter.setBrush(i.next().lighter(180));
painter.drawPath(path);
}
QPlainTextEdit::paintEvent(e);
QPlainTextEdit::paintEvent(e);
}

View file

@ -1,4 +1,11 @@
/* Original License:
/*
* Copyright (c) 2013 Maximilian Güntner <maximilian.guentner@gmail.com>
*
* This file is subject to the terms and conditions of version 2 of
* the GNU General Public License. See the file gpl-2.0.txt in the main
* directory of this archive for more details.
*
* Original License:
*
* This file is part of the Nepomuk widgets collection
* Copyright (c) 2013 Denis Steckelmacher <steckdenis@yahoo.fr>