Skip to content

Commit

Permalink
v0.4.7 release
Browse files Browse the repository at this point in the history
  • Loading branch information
dail8859 committed Feb 5, 2022
2 parents 14c151f + d79d50a commit 49a5c17
Show file tree
Hide file tree
Showing 32 changed files with 423 additions and 275 deletions.
70 changes: 70 additions & 0 deletions src/NotepadNext/EditorPrintPreviewRenderer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* This file is part of Notepad Next.
* Copyright 2022 Justin Dailey
*
* Notepad Next is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Notepad Next is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Notepad Next. If not, see <https://www.gnu.org/licenses/>.
*/


#include "EditorPrintPreviewRenderer.h"
#include "ScintillaNext.h"

#include <QPrinter>
#include <QDebug>
#include <QPainter>

EditorPrintPreviewRenderer::EditorPrintPreviewRenderer(ScintillaNext *editor)
: QObject(), editor(editor)
{
}

void EditorPrintPreviewRenderer::render(QPrinter *printer)
{
QRectF printableArea(QPointF(0, 0), printer->pageRect(QPrinter::DevicePixel).size());

qInfo() << "Print from page" << printer->fromPage() << "to" << printer->toPage();
qInfo() << "Paper:" << printer->paperRect(QPrinter::DevicePixel);
qInfo() << "Page:" << printer->pageRect(QPrinter::DevicePixel);
qInfo() << "Printable Area:" << printableArea;

const int fromPage = printer->fromPage();
const int toPage = printer->toPage();

// The printer starts with a valid page initially
bool needsNewPage = false;

int startPos = 0;
int pageNum = 1;

QPainter painter(printer);

do {
bool needsToDraw = (fromPage == 0 && toPage == 0) || (fromPage <= pageNum && pageNum <= toPage);

if (needsToDraw) {
if (needsNewPage) {
printer->newPage();
}
else {
needsNewPage = true;
}
}

startPos = editor->formatRange(needsToDraw, printer, printer,
printableArea.toRect(), printer->paperRect(QPrinter::DevicePixel).toRect(),
startPos, editor->length());

pageNum++;
} while (startPos < editor->length());
}
43 changes: 43 additions & 0 deletions src/NotepadNext/EditorPrintPreviewRenderer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* This file is part of Notepad Next.
* Copyright 2022 Justin Dailey
*
* Notepad Next is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Notepad Next is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Notepad Next. If not, see <https://www.gnu.org/licenses/>.
*/


#ifndef EDITORPRINTPREVIEWRENDERER_H
#define EDITORPRINTPREVIEWRENDERER_H

#include <QObject>


class ScintillaNext;
class QPrinter;

class EditorPrintPreviewRenderer : public QObject
{
Q_OBJECT

public:
explicit EditorPrintPreviewRenderer(ScintillaNext *editor);

public slots:
void render(QPrinter *printer);

private:
ScintillaNext *editor;
};

#endif // EDITORPRINTPREVIEWRENDERER_H
24 changes: 15 additions & 9 deletions src/NotepadNext/NotepadNext.pro
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ SOURCES += \
ComboBoxDelegate.cpp \
DockedEditor.cpp \
EditorManager.cpp \
EditorPrintPreviewRenderer.cpp \
Finder.cpp \
IFaceTable.cpp \
IFaceTableMixer.cpp \
Expand All @@ -85,10 +86,11 @@ SOURCES += \
decorators/BetterMultiSelection.cpp \
decorators/EditorConfigAppDecorator.cpp \
decorators/SurroundSelection.cpp \
dialogs/EditorInspectorDock.cpp \
docks/EditorInspectorDock.cpp \
dialogs/FindReplaceDialog.cpp \
dialogs/LanguageInspectorDock.cpp \
dialogs/LuaConsoleDock.cpp \
docks/FolderAsWorkspaceDock.cpp \
docks/LanguageInspectorDock.cpp \
docks/LuaConsoleDock.cpp \
dialogs/MacroRunDialog.cpp \
dialogs/MacroSaveDialog.cpp \
dialogs/MainWindow.cpp \
Expand All @@ -108,6 +110,7 @@ HEADERS += \
DockedEditor.h \
DockedEditorTitleBar.h \
EditorManager.h \
EditorPrintPreviewRenderer.h \
Finder.h \
FocusWatcher.h \
IFaceTable.h \
Expand All @@ -132,10 +135,11 @@ HEADERS += \
decorators/BetterMultiSelection.h \
decorators/EditorConfigAppDecorator.h \
decorators/SurroundSelection.h \
dialogs/EditorInspectorDock.h \
docks/EditorInspectorDock.h \
dialogs/FindReplaceDialog.h \
dialogs/LanguageInspectorDock.h \
dialogs/LuaConsoleDock.h \
docks/FolderAsWorkspaceDock.h \
docks/LanguageInspectorDock.h \
docks/LuaConsoleDock.h \
dialogs/MacroRunDialog.h \
dialogs/MacroSaveDialog.h \
dialogs/MainWindow.h \
Expand All @@ -150,11 +154,12 @@ HEADERS += \

FORMS += \
QuickFindWidget.ui \
dialogs/EditorInspectorDock.ui \
dialogs/LanguageInspectorDock.ui \
docks/EditorInspectorDock.ui \
docks/FolderAsWorkspaceDock.ui \
docks/LanguageInspectorDock.ui \
dialogs/MainWindow.ui \
dialogs/FindReplaceDialog.ui \
dialogs/LuaConsoleDock.ui \
docks/LuaConsoleDock.ui \
dialogs/MacroRunDialog.ui \
dialogs/MacroSaveDialog.ui \
dialogs/PreferencesDialog.ui
Expand All @@ -165,6 +170,7 @@ RESOURCES += \

INCLUDEPATH += $$PWD/decorators
INCLUDEPATH += $$PWD/dialogs
INCLUDEPATH += $$PWD/docks
INCLUDEPATH += $$PWD/widgets


Expand Down
33 changes: 20 additions & 13 deletions src/NotepadNext/NotepadNextApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ struct luabridge::Stack <QString const&>
NotepadNextApplication::NotepadNextApplication(int &argc, char **argv)
: SingleApplication(argc, argv, true, opts)
{
}

bool NotepadNextApplication::init()
{
qInfo(Q_FUNC_INFO);

luaState = new LuaState();

recentFilesListManager = new RecentFilesListManager(this);
editorManager = new EditorManager(this);
settings = new Settings(this);
Expand Down Expand Up @@ -84,13 +92,7 @@ NotepadNextApplication::NotepadNextApplication(int &argc, char **argv)

EditorConfigAppDecorator *ecad = new EditorConfigAppDecorator(this);
ecad->setEnabled(true);
}

bool NotepadNextApplication::initGui()
{
qInfo(Q_FUNC_INFO);

luaState = new LuaState();
luaState->executeFile(":/scripts/init.lua");
LuaExtension::Instance().Initialise(luaState->L, Q_NULLPTR);

Expand Down Expand Up @@ -137,7 +139,7 @@ bool NotepadNextApplication::initGui()
}
});

QObject::connect(this, &SingleApplication::instanceStarted, this->windows.first(), &MainWindow::bringWindowToForeground);
QObject::connect(this, &SingleApplication::instanceStarted, windows.first(), &MainWindow::bringWindowToForeground);

QObject::connect(this, &SingleApplication::receivedMessage, [&] (quint32 instanceId, QByteArray message) {
Q_UNUSED(instanceId)
Expand Down Expand Up @@ -176,7 +178,6 @@ bool NotepadNextApplication::initGui()
// Everything should be ready at this point

windows.first()->show();
windows.first()->bringWindowToForeground();

return true;
}
Expand All @@ -187,14 +188,16 @@ QString NotepadNextApplication::getFileDialogFilter() const

QString filter = getLuaState()->executeAndReturn<QString>(
R"=(
local filter = {"All files (*)"}
local filter = {}
for name, L in pairs(languages) do
local extensions = {}
for _, ext in ipairs(L.extensions) do
extensions[#extensions + 1] = "*." .. ext
end
filter[#filter + 1] = name .. " Files (" .. table.concat(extensions, " ") .. ")"
end
table.sort(filter, function (a, b) return a:lower() < b:lower() end)
table.insert(filter, 1, "All files (*)")
return table.concat(filter, ";;")
)=");

Expand Down Expand Up @@ -266,16 +269,20 @@ void NotepadNextApplication::setEditorLanguage(ScintillaNext *editor, const QStr

QString NotepadNextApplication::detectLanguageFromExtension(const QString &extension) const
{
qInfo(Q_FUNC_INFO);

return getLuaState()->executeAndReturn<QString>(QString(R"(
local ext = "%1"
for name, L in pairs(languages) do
for _, v in ipairs(L.extensions) do
if v == ext then
return name
if L.extensions then
for _, v in ipairs(L.extensions) do
if v == ext then
return name
end
end
end
end
return "null"
return "Text"
)").arg(extension).toLatin1().constData());
}

Expand Down
2 changes: 1 addition & 1 deletion src/NotepadNext/NotepadNextApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class NotepadNextApplication : public SingleApplication
public:
NotepadNextApplication(int &argc, char **argv);

bool initGui();
bool init();

RecentFilesListManager *getRecentFilesListManager() const { return recentFilesListManager; }
EditorManager *getEditorManager() const { return editorManager; }
Expand Down
2 changes: 1 addition & 1 deletion src/NotepadNext/ScintillaNext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <QTextCodec>


const int CHUNK_SIZE = 1024 * 64; // Not sure what is best
const int CHUNK_SIZE = 1024 * 1024 * 4; // Not sure what is best


static bool writeToDisk(const QByteArray &data, const QString &path)
Expand Down
Loading

0 comments on commit 49a5c17

Please sign in to comment.