Skip to content

Commit

Permalink
You can now see if the file is modified in the tab bar, fixed ask to …
Browse files Browse the repository at this point in the history
…save changes on close, fixed export pdf, way cleaner about dialog, editor now has focus after tab change, android improvement
  • Loading branch information
tim-gromeyer committed Aug 8, 2022
1 parent 0303a08 commit af20a9e
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 1,001 deletions.
3 changes: 2 additions & 1 deletion 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Find Qt for QmarkdownTextEdit and SingleApplication
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)

Expand Down Expand Up @@ -41,13 +42,13 @@ endif()

# include(${CMAKE_CURRENT_LIST_DIR}/hunspell.cmake)


include_directories(${CMAKE_CURRENT_LIST_DIR}/qmarkdowntextedit)
include_directories(${CMAKE_CURRENT_LIST_DIR}/md4c/src)


set(3rdparty
md4c-html
qmarkdowntextedit
# hunspell
${singleapp}
)
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ set(PROJECT_SOURCES
src/main.cpp
src/mainwindow.cpp
src/mainwindow.h
src/about.cpp
src/about.h
src/markdowneditor.cpp
src/markdowneditor.h
src/markdownparser.cpp
Expand Down
847 changes: 0 additions & 847 deletions src/about.cpp

This file was deleted.

88 changes: 0 additions & 88 deletions src/about.h

This file was deleted.

6 changes: 4 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ int main(int argc, char *argv[])
parser.process(a);

#ifndef NOT_SUPPORTET
if(a.sendMessage(QByteArrayLiteral("file://") +
parser.positionalArguments().join(QLatin1Char(' ')).toLatin1()))
if (a.isSecondary()) {
a.sendMessage(QByteArrayLiteral("file://") +
parser.positionalArguments().join(QLatin1Char(' ')).toLatin1());
return 0;
}
#endif

MainWindow w(parser.positionalArguments());
Expand Down
85 changes: 56 additions & 29 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
// imports
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "about.h"
#include "markdownparser.h"
#include "highlighter.h"
#include "spellchecker.h"
Expand Down Expand Up @@ -102,6 +101,9 @@ MainWindow::MainWindow(const QStringList &files, QWidget *parent)
ui->menu_View->removeAction(ui->actionOpen_in_web_browser);
ui->menu_View->removeAction(ui->actionAuto_add_file_path_to_icon_path);
#endif
#ifdef Q_OS_ANDROID
mode->deleteLater();
#endif

QMetaObject::invokeMethod(this, [files, this]{
loadFiles(files);
Expand Down Expand Up @@ -430,7 +432,7 @@ void MainWindow::onEditorChanged(const int index)

setCurrDir(editor->getDir());

// editor->setFocus(Qt::TabFocusReason);
editor->setFocus(Qt::TabFocusReason);

onTextChanged();
}
Expand All @@ -453,30 +455,44 @@ MarkdownEditor *MainWindow::createEditor()
connect(editor->document(), &QTextDocument::modificationChanged,
ui->actionSave, &QAction::setEnabled);
connect(editor->document(), &QTextDocument::modificationChanged,
this, &QMainWindow::setWindowModified);
this, &MainWindow::onModificationChanged);
connect(editor->document(), &QTextDocument::undoAvailable,
ui->actionUndo, &QAction::setEnabled);
connect(editor->document(), &QTextDocument::redoAvailable,
ui->actionRedo, &QAction::setEnabled);
connect(editor, &QMarkdownTextEdit::zoomIn, this,
[editor]{ static_cast<QPlainTextEdit*>(editor)->zoomOut(-1); });
connect(editor, &QMarkdownTextEdit::zoomOut, this,
[editor]{ static_cast<QPlainTextEdit*>(editor)->zoomIn(-1); });
connect(editor->horizontalScrollBar(), &QScrollBar::valueChanged,
ui->textBrowser->horizontalScrollBar(), &QScrollBar::setValue);

return editor;
}

void MainWindow::receivedMessage(const qint32 &id, const QByteArray &msg)
void MainWindow::receivedMessage(const qint32 id, const QByteArray &msg)
{
QString f = QString::fromLatin1(msg); // is a bit faster
f.remove(0, 7);
f.remove(0, 7); // remove "file://" which is added programaticly

qInfo() << "markdownedit: instance" << id << "started and send folowing message:" << f;

if (f.isEmpty())
if (f.isEmpty()) // it's the case when you start a new app
onFileNew();
else
openFiles(f.split(QChar(QChar::Space)));
openFiles(f.split(QChar(QChar::Space))); // if you selected files
}

void MainWindow::onModificationChanged(const bool m)
{
setWindowModified(m);

const int curr = ui->tabWidget_2->currentIndex();

QString old = ui->tabWidget_2->tabBar()->tabText(curr);

if (m && !old.endsWith(QChar('*')))
old.append(QChar('*'));
else if (!m && old.endsWith(QChar('*')))
old.remove(old.length() -1, 1);

ui->tabWidget_2->tabBar()->setTabText(curr, old);
}

MarkdownEditor* MainWindow::currentEditor()
Expand Down Expand Up @@ -626,8 +642,6 @@ void MainWindow::changeSpelling(const bool checked)

void MainWindow::disablePreview(const bool checked)
{
if (ui->actionDisable_preview->isChecked() != checked) return;

ui->tabWidget->setHidden(checked);

dontUpdate = checked;
Expand Down Expand Up @@ -814,12 +828,12 @@ void MainWindow::exportPdf()

if (file.isEmpty()) return;

QPrinter printer;
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(file);
printer.setResolution(QPrinter::HighResolution);

printPreview(&printer);
ui->textBrowser->setHtml(html);
ui->textBrowser->print(&printer);

statusBar()->show();
statusBar()->showMessage(tr("Pdf exported to %1").arg(
Expand Down Expand Up @@ -1066,12 +1080,12 @@ void MainWindow::onFileOpen()
};
QFileDialog::getOpenFileContent("Markdown (*.md *.markdown *.mkd)", fileContentReady);
#else
QFileDialog dialog(this, tr("Open MarkDown File"));
QFileDialog dialog(this, tr("Open Markdown File"));
dialog.setMimeTypeFilters({"text/markdown"});
dialog.setAcceptMode(QFileDialog::AcceptOpen);
if (dialog.exec() == QDialog::Accepted) {
const QString file = dialog.selectedFiles().at(0);
if (file == path) return;
if (file == path || file.isEmpty()) return;
openFile(file);
}
#endif
Expand Down Expand Up @@ -1173,15 +1187,30 @@ bool MainWindow::onFileSaveAs()

void MainWindow::onHelpAbout()
{
About dialog(tr("About MarkdownEdit"), this);
dialog.setAppUrl(QStringLiteral("https://software-made-easy.github.io/MarkdownEdit/"));
dialog.setDescription(tr("MarkdownEdit, as the name suggests, is a simple and easy program to create and edit Markdown files."));

dialog.addCredit(tr("<p>Thanks to <a href=\"https://github.com/Waqar144\">Waqar Ahmed</a> for helping with development</p>"));
dialog.addCredit(tr("<p>The conversion from Markdown to HTML is done with the help of the <a href=\"https://github.com/mity/md4c\">md4c</a> library by <em>Martin Mitáš</em>.</p>"));
dialog.addCredit(tr("<p>The <a href=\"https://github.com/pbek/qmarkdowntextedit\">widget</a> used for writing was created by <em>Patrizio Bekerle</em>.</p>"));

dialog.exec();
QMessageBox::about(this, tr("About MarkdownEdit"), tr("<h2>MarkdownEdit</h2>\n"
"<p>MarkdownEdit, as the name suggests, is a simple and easy program to create and edit Markdown files.</p>\n"
"<h2>About</h2>\n"
"<table class=\"table\">\n"
"<tbody>\n"
"<tr>\n"
"<td>Version:&nbsp;</td>\n"
"<td>&nbsp;%1</td>\n"
"</tr>\n"
"<tr>\n"
"<td>&nbsp;Qt Version:</td>\n"
"<td>&nbsp;%2</td>\n"
"</tr>\n"
"<tr>\n"
"<td>&nbsp;Homepage:</td>\n"
"<td><span style=\"font-size: medium; white-space: pre-wrap; background-color: transparent; font-style: italic; color: #a8abb0;\"><a href=\"https://software-made-easy.github.io/MarkdownEdit/\">https://software-made-easy.github.io/MarkdownEdit/</a></span></td>\n"
"</tr>\n"
"</tbody>\n"
"</table>\n"
"<h2>Credits</h2>\n"
"<p>Thanks to <a href=\"https://github.com/Waqar144\">Waqar Ahmed</a> for help with development.</p>\n"
"<p>The conversion from Markdown to HTML is done using the <a href=\"https://github.com/mity/md4c\">md4c</a> library by <em>Martin Mitáš</em>.</p>\n"
"<p>The <a href=\"https://github.com/pbek/qmarkdowntextedit\">widget</a> used for writing was created by <em>Patrizio Bekerle</em>.</p>"
).arg(QStringLiteral(APP_VERSION), qVersion()));
}

void MainWindow::openRecent() {
Expand Down Expand Up @@ -1265,10 +1294,8 @@ void MainWindow::loadSettings() {

highlighting = settings->value(QStringLiteral("highlighting"), true).toBool();
ui->actionHighlighting_activated->setChecked(highlighting);
// changeHighlighting(highlighting); not loaded yet

setPath = settings->value(QStringLiteral("setPath"), true).toBool();
// changeAddtoIconPath(setPath); files aren't loaded yet

recentOpened = settings->value(QStringLiteral("recent"), QStringList()).toStringList();
if (!recentOpened.isEmpty()) {
Expand Down
4 changes: 3 additions & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MainWindow : public QMainWindow
void closeEvent(QCloseEvent *e) override;

public slots:
void receivedMessage(const qint32 &, const QByteArray &);
void receivedMessage(const qint32, const QByteArray &);

void toForeground();

Expand All @@ -67,6 +67,8 @@ private slots:

void onFileChanged(const QString &);

void onModificationChanged(const bool);

void setupThings();
void setupConnections();

Expand Down
7 changes: 5 additions & 2 deletions src/spellchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <enchant++.h>
#endif


// Needed for wasm
#ifndef QStringViewLiteral
# define QStringViewLiteral(str) QStringView(QT_UNICODE_LITERAL(str))
Expand Down Expand Up @@ -114,7 +115,7 @@ void SpellChecker::checkSpelling(const QString &text)
continue;

if (c == QLatin1Char('h')) {
if (textLength -i >= 10) { // http 4; :// 7; * >1; .de 10
if (textLength -i >= 11) { // http 4; :// 7; * >1; .de 11
if (SUBSTR(text, i, 4) == QStringViewLiteral("http")) {
const int last = i;

Expand Down Expand Up @@ -252,11 +253,13 @@ const QStringList SpellChecker::getLanguageList()
enchant::Broker *broker = get_enchant_broker();
QStringList languages;
broker->list_dicts(dict_describe_cb, &languages);
std::sort(languages.begin(), languages.end());

if (languages.isEmpty())
qWarning() << "No language dict found";

languages.removeDuplicates();
languages.sort();


return languages;
#endif
Expand Down
Loading

0 comments on commit af20a9e

Please sign in to comment.