24 #include <QtGui/QKeyEvent>
25 #include <QtGui/QTextCursor>
26 #include <QtGui/QTextList>
27 #include <QtGui/QTextBlock>
28 #include <QtGui/QTextDocumentFragment>
33 NestedListHelper::NestedListHelper(
QTextEdit *te)
36 listBottomMargin = 12;
41 NestedListHelper::~NestedListHelper()
45 bool NestedListHelper::handleBeforeKeyPressEvent(
QKeyEvent *event)
50 if ((event->
key() != Qt::Key_Backspace)
58 &&
event->key() == Qt::Key_Backspace
66 &&
event->key() == Qt::Key_Backspace
87 bool NestedListHelper::canIndent()
const
89 if ((textEdit->textCursor().block().isValid())
92 QTextBlock block = textEdit->textCursor().block();
105 bool NestedListHelper::canDedent()
const
107 QTextBlock thisBlock = textEdit->textCursor().block();
110 int nextBlockIndent = 0;
111 int thisBlockIndent = 0;
116 if (thisBlockIndent >= nextBlockIndent)
124 bool NestedListHelper::handleAfterKeyPressEvent(
QKeyEvent *event)
127 if ((event->
key() != Qt::Key_Backspace)
128 && (event->
key() != Qt::Key_Return))
132 bool handled =
false;
146 if ((event->
key() == Qt::Key_Return) || (event->
key() == Qt::Key_Backspace)) {
147 reformatBoundingItemSpacing();
158 bool NestedListHelper::handleAfterDropEvent(
QDropEvent *dropEvent)
168 if (firstDroppedItemIndent < minimumIndent) {
174 int endOfDrop = bottomOfSelection().position();
176 droppedBlock = droppedBlock.
next();
181 list->
add(droppedBlock);
186 reformatBoundingItemSpacing();
190 void NestedListHelper::processList(
QTextList* list)
197 bool processingSubList =
false;
199 block = block.
next();
203 if (nextItemIndent < thisListIndent) {
205 }
else if (nextItemIndent > thisListIndent) {
206 if (processingSubList) {
209 processingSubList =
true;
210 processList(nextList);
212 processingSubList =
false;
220 void NestedListHelper::reformatList(
QTextBlock block)
238 void NestedListHelper::reformatList()
241 reformatList(cursor.
block());
262 void NestedListHelper::handleOnIndentMore()
269 QTextListFormat::Style style;
270 cursor = topOfSelection();
276 cursor = bottomOfSelection();
282 style = QTextListFormat::ListDisc;
285 handleOnBulletType(style);
294 reformatBoundingItemSpacing();
297 void NestedListHelper::handleOnIndentLess()
304 listFmt = currentList->
format();
305 if (listFmt.
indent() > 1) {
308 reformatList(cursor.
block());
315 reformatBoundingItemSpacing();
319 void NestedListHelper::handleOnBulletType(
int styleIndex)
322 if (styleIndex != 0) {
323 QTextListFormat::Style style = (QTextListFormat::Style)styleIndex;
330 listFmt = currentList->
format();
343 reformatBoundingItemSpacing();
346 reformatBoundingItemSpacing();
350 void NestedListHelper::reformatBoundingItemSpacing(
QTextBlock block)
357 int nextBlockTopMargin = listNoMargin;
358 int previousBlockBottomMargin = listNoMargin;
359 int thisBlockBottomMargin = listBottomMargin;
360 int thisBlockTopMargin = listTopMargin;
366 thisBlockTopMargin = listNoMargin;
370 thisBlockBottomMargin = listNoMargin;
374 thisBlockTopMargin = listNoMargin;
377 thisBlockBottomMargin = listNoMargin;
390 if (nextBlockValid) {
391 block = block.
next();
399 if (prevBlockValid) {
408 void NestedListHelper::reformatBoundingItemSpacing()
410 reformatBoundingItemSpacing(topOfSelection().block());
411 reformatBoundingItemSpacing(bottomOfSelection().block());
void removeSelectedText()
QTextBlock previous() const
QTextListFormat format() const
void setObjectIndex(int index)
void setStyle(Style style)
QTextList * createList(const QTextListFormat &format)
QTextList * currentList() const
void add(const QTextBlock &block)
bool movePosition(MoveOperation operation, MoveMode mode, int n)
void setIndent(int indentation)
bool hasSelection() const
void setFormat(const QTextListFormat &format)
void setBlockFormat(const QTextBlockFormat &format)
bool atBlockStart() const
void setBottomMargin(qreal margin)
void setTopMargin(qreal margin)
QTextBlockFormat blockFormat() const
QTextList * textList() const
int itemNumber(const QTextBlock &block) const
QTextBlock item(int i) const
void setPosition(int pos, MoveMode m)