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 default font button #157

Open
wants to merge 8 commits into
base: experimental
Choose a base branch
from
1 change: 1 addition & 0 deletions app/bin/mytetra.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<file>resource/pic/edit_italic.svg</file>
<file>resource/pic/edit_listdot.svg</file>
<file>resource/pic/edit_listnumeric.svg</file>
<file>resource/pic/edit_defaultfont.svg</file>
<file>resource/pic/edit_monospace.svg</file>
<file>resource/pic/edit_settings.svg</file>
<file>resource/pic/edit_showformatting.svg</file>
Expand Down
97 changes: 97 additions & 0 deletions app/bin/resource/pic/edit_defaultfont.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/bin/resource/translations/mytetra_ru.qm
Binary file not shown.
1,170 changes: 636 additions & 534 deletions app/bin/resource/translations/mytetra_ru.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/src/libraries/ShortcutManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ void ShortcutManager::initDefaultKeyTable()
defaultKeyTable.insert("editor-strikeout", Data{ QKeySequence("Ctrl+Shift+S"), tr("Strike out"), tr("") });
defaultKeyTable.insert("editor-superscript", Data{ QKeySequence("Ctrl+Shift+P"), tr("Superscript"), tr("") });
defaultKeyTable.insert("editor-subscript", Data{ QKeySequence("Ctrl+Shift+B"), tr("Subscript"), tr("") });
defaultKeyTable.insert("editor-defaultFont", Data{ QKeySequence("Ctrl+Alt+F"), tr("Set default font"), tr("") });
defaultKeyTable.insert("editor-monospace", Data{ QKeySequence("Ctrl+T"), tr("Monospace"), tr("") });
defaultKeyTable.insert("editor-code", Data{ QKeySequence("Ctrl+M"), tr("Code"), tr("Select a whole paragraphs to format text as code") });
defaultKeyTable.insert("editor-lowercase", Data{ QKeySequence(""), tr("Lowercase"), tr("") });
Expand Down
3 changes: 3 additions & 0 deletions app/src/libraries/wyedit/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ void Editor::setupToolsSignals(void)
connect(editorToolBarAssistant->subscript, &QAction::triggered,
typefaceFormatter, &TypefaceFormatter::onSubScriptClicked);

connect(editorToolBarAssistant->defaultFont, &QAction::triggered,
typefaceFormatter, &TypefaceFormatter::onDefaultFontClicked);

connect(editorToolBarAssistant->monospace, &QAction::triggered,
typefaceFormatter, &TypefaceFormatter::onMonospaceClicked);

Expand Down
6 changes: 6 additions & 0 deletions app/src/libraries/wyedit/EditorToolBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ void EditorToolBar::setupToolBarTools(void)
subscript->setIcon(QIcon(":/resource/pic/edit_sub.svg"));
subscript->setObjectName("editor_tb_subscript");

// Кнопка Set the font
defaultFont=new QAction(this);
defaultFont->setIcon(QIcon(":/resource/pic/edit_defaultfont.svg"));
defaultFont->setObjectName("editor_tb_defaultFont");

// Кнопка Monospace
monospace=new QAction(this);
monospace->setIcon(QIcon(":/resource/pic/edit_monospace.svg"));
Expand Down Expand Up @@ -359,6 +364,7 @@ void EditorToolBar::setupShortcuts(void)
shortcutManager.initAction("editor-strikeout", strikeout);
shortcutManager.initAction("editor-superscript", superscript);
shortcutManager.initAction("editor-subscript", subscript);
shortcutManager.initAction("editor-defaultFont", defaultFont);
shortcutManager.initAction("editor-monospace", monospace);
shortcutManager.initAction("editor-code", code);
shortcutManager.initAction("editor-clear", clear);
Expand Down
1 change: 1 addition & 0 deletions app/src/libraries/wyedit/EditorToolBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class EditorToolBar : public QWidget
QAction *italic;
QAction *underline;
QAction *strikeout; // Зачеркивание текста
QAction *defaultFont;
QAction *monospace;
QAction *superscript;
QAction *subscript;
Expand Down
27 changes: 26 additions & 1 deletion app/src/libraries/wyedit/formatters/TypefaceFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,26 @@ void TypefaceFormatter::smartFormat(int formatType)
}


// Задаём фрагменту шрифт по умолчанию
void TypefaceFormatter::onDefaultFontClicked(void)
{
textArea->textCursor().beginEditBlock();

// Устанавливается шрифт
QFont font;
font.fromString(editorConfig->get_default_font());
emit changeFontFamily(font.family());
// Устанавливается нужный размер
emit changeFontPointSize(editorConfig->get_default_font_size());

// Новый установленный шрифт показывается в выпадающем списке шрифтов
emit changeFontselectOnDisplay(font.family());
// В выпадающем списке размеров выставляется установленный размер
emit changeFontsizeOnDisplay( editorConfig->get_default_font_size() );

textArea->textCursor().endEditBlock();
}

// Форматирование моноширинным шрифтом
void TypefaceFormatter::onMonospaceClicked(void)
{
Expand Down Expand Up @@ -270,6 +290,7 @@ void TypefaceFormatter::onCodeClicked(void)
return;

textArea->textCursor().beginEditBlock();
// Далее при любом выходе из метода нужно вызывать textArea->textCursor().endEditBlock()

// Обработка мягкого переноса в выделенном тексте
// Учитываются мягкие переносы до выделенного текста (1-й символ до выделения) и в выделенных абзацах
Expand Down Expand Up @@ -300,8 +321,12 @@ void TypefaceFormatter::onCodeClicked(void)

if(blockStart<=selectStart && blockStop>=selectStop)
enableIndent=false; // Выбран кусок текста в пределах блока
else
else{
qDebug() << "The selection is outside one block";
//Хорошо бы писать в статусную строку сообщение, почему форматирование не выполнено
textArea->textCursor().endEditBlock();
return;
}
}
else
enableIndent=true; // Выбран четко блок (блоки) текста, нужно делать отступ
Expand Down
1 change: 1 addition & 0 deletions app/src/libraries/wyedit/formatters/TypefaceFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public slots:
void onStrikeOutClicked(void); // Зачеркивание текста
void onSuperScriptClicked(void);
void onSubScriptClicked(void);
void onDefaultFontClicked(void);
void onMonospaceClicked(void);
void onCodeClicked(void);
void onClearClicked(void);
Expand Down
7 changes: 4 additions & 3 deletions app/src/views/mainWindow/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,11 +1076,12 @@ void MainWindow::setIcon(void)
{
connect(trayIcon, &QSystemTrayIcon::activated,
this, &MainWindow::iconActivated);

QIcon icon = QIcon(":/resource/pic/logo.svg");
QIcon icon = QIcon::fromTheme("mytetra");
trayIcon->setIcon(icon);
trayIcon->setToolTip("MyTetra");
setWindowIcon(icon);

// tray_icon->setToolTip(iconComboBox->itemText(index));
}

Expand Down