Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to work with parentheticals in comic books #230

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ void SettingsManager::Implementation::loadShortcutsForComicBookSettings()
blocksJumpsModel->appendRow(blocksJumpsModelRow(TextParagraphType::PanelHeading));
blocksJumpsModel->appendRow(blocksJumpsModelRow(TextParagraphType::Description));
blocksJumpsModel->appendRow(blocksJumpsModelRow(TextParagraphType::Character));
blocksJumpsModel->appendRow(blocksJumpsModelRow(TextParagraphType::Parenthetical));
blocksJumpsModel->appendRow(blocksJumpsModelRow(TextParagraphType::Dialogue));
blocksJumpsModel->appendRow(blocksJumpsModelRow(TextParagraphType::InlineNote));
blocksJumpsModel->appendRow(blocksJumpsModelRow(TextParagraphType::UnformattedText));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ HEADERS += \
text/handlers/key_press_handler_facade.h \
text/handlers/page_handler.h \
text/handlers/panel_handler.h \
text/handlers/parenthetical_handler.h \
text/handlers/pre_handler.h \
text/handlers/prepare_handler.h \
text/handlers/sequence_footer_handler.h \
Expand All @@ -63,6 +64,7 @@ SOURCES += \
text/handlers/key_press_handler_facade.cpp \
text/handlers/page_handler.cpp \
text/handlers/panel_handler.cpp \
text/handlers/parenthetical_handler.cpp \
text/handlers/pre_handler.cpp \
text/handlers/prepare_handler.cpp \
text/handlers/sequence_footer_handler.cpp \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ void ComicBookTextView::Implementation::reconfigureTemplate(bool _withModelReini
const QVector<TextParagraphType> types = {
TextParagraphType::PageHeading, TextParagraphType::PanelHeading,
TextParagraphType::Description, TextParagraphType::Character,
TextParagraphType::Dialogue, TextParagraphType::InlineNote,
TextParagraphType::UnformattedText, TextParagraphType::SequenceHeading,
TextParagraphType::Parenthetical, TextParagraphType::Dialogue,
TextParagraphType::InlineNote, TextParagraphType::UnformattedText,
TextParagraphType::SequenceHeading,
};
for (const auto type : types) {
if (!usedTemplate.paragraphStyle(type).isActive()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,11 @@ void ComicBookTextEdit::addParagraph(BusinessLayer::TextParagraphType _type)
d->document.setParagraphType(BusinessLayer::TextParagraphType::Dialogue, cursor);
}
//
// Если вставляется реплика, то разделяем страницу и ставим курсор во вторую колонку
// Если вставляется ремарка, или реплика, то разделяем страницу и ставим курсор во вторую
// колонку
//
else if (_type == BusinessLayer::TextParagraphType::Dialogue) {
else if (_type == BusinessLayer::TextParagraphType::Parenthetical
|| _type == BusinessLayer::TextParagraphType::Dialogue) {
const auto cursorPosition = textCursor().position();
d->document.splitParagraph(textCursor());
auto cursor = textCursor();
Expand Down Expand Up @@ -447,7 +449,8 @@ void ComicBookTextEdit::setCurrentParagraphType(TextParagraphType _type)
// На реплику
//
else if (d->comicBookTemplate().placeDialoguesInTable()
&& _type == TextParagraphType::Dialogue) {
&& (_type == TextParagraphType::Parenthetical
|| _type == TextParagraphType::Dialogue)) {
//
// Если текущий блок не в таблице, то создаём её и текущий блок помещаем в неё как персонажа
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "../comic_book_text_edit.h"

#include <business_layer/templates/comic_book_template.h>
#include <data_layer/storage/settings_storage.h>
#include <data_layer/storage/storage_facade.h>

#include <QKeyEvent>
#include <QTextBlock>
Expand Down Expand Up @@ -183,4 +185,85 @@ void DialogHandler::handleBackspace(QKeyEvent* _event)
StandardKeyHandler::handleBackspace(_event);
}

void DialogHandler::handleOther(QKeyEvent* _event)
{
//
// Получим необходимые значения
//
// ... курсор в текущем положении
QTextCursor cursor = editor()->textCursor();
// ... блок текста в котором находится курсор
const QTextBlock currentBlock = cursor.block();
// ... текст до курсора
const QString cursorBackwardText = currentBlock.text().left(cursor.positionInBlock());
// ... текст после курсора
const QString cursorForwardText = currentBlock.text().mid(cursor.positionInBlock());
// ... необходимо ли менять стиль при открытой скобке на ремарку
const bool needToCheckOpenBracket
= editor()->comicBookTemplate().paragraphStyle(TextParagraphType::Parenthetical).isActive()
&& settingsValue(DataStorageLayer::
kComponentsComicBookEditorUseOpenBracketInDialogueForParentheticalKey)
.toBool();


//
// Обработка
//
if (needToCheckOpenBracket && cursorBackwardText.endsWith("(") && _event != nullptr
&& _event->text() == "(") {
//! Если нажата открывающая скобка

//
// Удалим лишнюю скобку
//
editor()->textCursor().deletePreviousChar();

if (cursorForwardText.isEmpty() && cursorBackwardText == "(") {
//! Если текст пуст

//
// Cменить стиль на ремарку
//
editor()->setCurrentParagraphType(TextParagraphType::Parenthetical);
} else {
//! Если текст не пуст

//
// Разрываем диалог ремаркой
//

//
// ... оставляем пустой блок реплики
//
// если скобка нажата в начале строки, то делаем лишь один перевод строки
//
if (cursorBackwardText != "(") {
editor()->addParagraph(TextParagraphType::Dialogue);
}
//
// ... если после скобки нет текста, не добавляем новый параграф
//
if (!cursorForwardText.isEmpty()) {
editor()->addParagraph(TextParagraphType::Dialogue);

//
// ... возвращаем курсор к пустому блоку
//
cursor = editor()->textCursor();
cursor.movePosition(QTextCursor::PreviousBlock);
editor()->setTextCursorAndKeepScrollBars(cursor);
}

//
// ... делаем блок под курсором ремаркой
//
editor()->setCurrentParagraphType(TextParagraphType::Parenthetical);
}
} else {
//! В противном случае, обрабатываем в базовом классе

StandardKeyHandler::handleOther(_event);
}
}

} // namespace KeyProcessingLayer
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class DialogHandler : public StandardKeyHandler
void handleEnter(QKeyEvent* _event = nullptr) override;
void handleTab(QKeyEvent* _event = nullptr) override;
void handleBackspace(QKeyEvent* _event = nullptr) override;
void handleOther(QKeyEvent* _event = nullptr) override;
/** @} */
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "inline_note_handler.h"
#include "page_handler.h"
#include "panel_handler.h"
#include "parenthetical_handler.h"
#include "pre_handler.h"
#include "prepare_handler.h"
#include "sequence_footer_handler.h"
Expand Down Expand Up @@ -38,6 +39,7 @@ class KeyPressHandlerFacade::Implementation
QScopedPointer<PanelHandler> panelHandler;
QScopedPointer<DescriptionHandler> actionHandler;
QScopedPointer<CharacterHandler> characterHandler;
QScopedPointer<ParentheticalHandler> parentheticalHandler;
QScopedPointer<DialogHandler> dialogHandler;
QScopedPointer<InlineNoteHandler> inlineNoteHandler;
QScopedPointer<SequenceHeadingHandler> sequenceHeadingHandler;
Expand All @@ -54,6 +56,7 @@ KeyPressHandlerFacade::Implementation::Implementation(Ui::ComicBookTextEdit* _ed
, panelHandler(new PanelHandler(_editor))
, actionHandler(new DescriptionHandler(_editor))
, characterHandler(new CharacterHandler(_editor))
, parentheticalHandler(new ParentheticalHandler(_editor))
, dialogHandler(new DialogHandler(_editor))
, inlineNoteHandler(new InlineNoteHandler(_editor))
, sequenceHeadingHandler(new SequenceHeadingHandler(_editor))
Expand Down Expand Up @@ -154,6 +157,10 @@ AbstractKeyHandler* KeyPressHandlerFacade::handlerFor(TextParagraphType _type)
return d->characterHandler.data();
}

case TextParagraphType::Parenthetical: {
return d->parentheticalHandler.data();
}

case TextParagraphType::Dialogue: {
return d->dialogHandler.data();
}
Expand Down
Loading
Loading