- print support

This commit is contained in:
royqh1979@gmail.com 2021-10-07 07:52:20 +08:00
parent ec458a880a
commit b0442258db
12 changed files with 111 additions and 35 deletions

View File

@ -26,6 +26,7 @@ Version 0.6.0
- implement: config shortcuts
- implement: handle windows logout message
- fix: editor's inproject property not correctly setted (and may cause devcpp to crash when close project)
- implement: print
Version 0.5.0
- enhancement: support C++ using type alias;

View File

@ -1,4 +1,4 @@
QT += core gui
QT += core gui printsupport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

View File

@ -24,6 +24,9 @@
#include <QToolTip>
#include <QApplication>
#include <QInputDialog>
#include <QPrinter>
#include <QPrintDialog>
#include <QTextDocument>
#include "iconsmanager.h"
#include "debugger.h"
#include "editorlist.h"
@ -1997,6 +2000,44 @@ void Editor::insertCodeSnippet(const QString &code)
}
}
void Editor::print()
{
QPrinter printer;
QPrintDialog dialog(&printer, this);
dialog.setWindowTitle(tr("Print Document"));
// if (editor->selAvail())
// dialog.addEnabledOption(QAbstractPrintDialog::PrintSelection);
if (dialog.exec() != QDialog::Accepted) {
return;
}
QTextDocument doc;
// if (editor->selAvail()) {
// doc.setPlainText(editor->selText());
// } else {
QStringList lst = contents();
for (int i=0;i<lst.length();i++) {
int columns = 0;
QString line = lst[i];
QString newLine;
for (QChar ch:line) {
if (ch=='\t') {
int charCol = tabWidth() - (columns % tabWidth());
newLine += QString(charCol,' ');
columns += charCol;
} else {
newLine+=ch;
columns+=charColumns(ch);
}
}
lst[i]=newLine;
}
doc.setDefaultFont(font());
doc.setPlainText(lst.join(lineBreak()));
doc.print(&printer);
}
void Editor::showCompletion(bool autoComplete)
{
if (!pSettings->codeCompletion().enabled())
@ -3136,7 +3177,7 @@ void Editor::reformat()
return;
//we must remove all breakpoints and syntax issues
onLinesDeleted(1,lines()->count());
QByteArray content = lines()->text().toUtf8();
QByteArray content = text().toUtf8();
QStringList args = pSettings->codeFormatter().getArguments();
QByteArray newContent = runAndGetOutput("astyle.exe",
pSettings->dirs().app(),

View File

@ -158,6 +158,7 @@ public:
void reparseTodo();
void insertString(const QString& value, bool moveCursor);
void insertCodeSnippet(const QString& code);
void print();
const PCppParser &parser();

View File

@ -234,6 +234,7 @@ void MainWindow::updateEditorActions()
ui->actionRedo->setEnabled(false);
ui->actionSave->setEnabled(false);
ui->actionSaveAs->setEnabled(false);
ui->actionPrint->setEnabled(false);
ui->actionSelectAll->setEnabled(false);
ui->actionToggleComment->setEnabled(false);
ui->actionUnIndent->setEnabled(false);
@ -266,6 +267,7 @@ void MainWindow::updateEditorActions()
ui->actionUndo->setEnabled(e->canUndo());
ui->actionSave->setEnabled(e->modified());
ui->actionSaveAs->setEnabled(true);
ui->actionPrint->setEnabled(true);
ui->actionSelectAll->setEnabled(e->lines()->count()>0);
ui->actionToggleComment->setEnabled(!e->readOnly() && e->lines()->count()>0);
ui->actionUnIndent->setEnabled(!e->readOnly() && e->lines()->count()>0);
@ -891,10 +893,10 @@ void MainWindow::checkSyntaxInBack(Editor *e)
ui->tableIssues->clearIssues();
CompileTarget target =getCompileTarget();
if (target ==CompileTarget::Project) {
mCompilerManager->checkSyntax(e->filename(),e->lines()->text(),
mCompilerManager->checkSyntax(e->filename(),e->text(),
e->fileEncoding() == ENCODING_ASCII, mProject);
} else {
mCompilerManager->checkSyntax(e->filename(),e->lines()->text(),
mCompilerManager->checkSyntax(e->filename(),e->text(),
e->fileEncoding() == ENCODING_ASCII, nullptr);
}
// if not PrepareForCompile(cttStdin,True) then begin
@ -4108,3 +4110,12 @@ void MainWindow::on_btnCancelReplace_clicked()
{
showSearchReplacePanel(false);
}
void MainWindow::on_actionPrint_triggered()
{
Editor * editor = mEditorList->getEditor();
if (!editor)
return;
editor->print();
}

View File

@ -383,6 +383,8 @@ private slots:
void on_btnCancelReplace_clicked();
void on_actionPrint_triggered();
private:
Ui::MainWindow *ui;
EditorList *mEditorList;

View File

@ -854,6 +854,8 @@
<addaction name="actionClose_Project"/>
<addaction name="actionClose_All"/>
<addaction name="separator"/>
<addaction name="actionPrint"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
<widget class="QMenu" name="menuTools">
@ -1808,6 +1810,18 @@
<string>Shift+F6</string>
</property>
</action>
<action name="actionPrint">
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/055-package.png</normaloff>:/icons/images/newlook24/055-package.png</iconset>
</property>
<property name="text">
<string>Print...</string>
</property>
<property name="shortcut">
<string>Ctrl+P</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -538,6 +538,12 @@ QStringList SynEdit::contents()
return lines()->contents();
}
QString SynEdit::text()
{
QMutexLocker locker(&mMutex);
return lines()->text();
}
bool SynEdit::getPositionOfMouse(BufferCoord &aPos)
{
QPoint point = QCursor::pos();
@ -4147,7 +4153,7 @@ void SynEdit::setHighlighter(const PSynHighlighter &highlighter)
invalidate();
}
PSynEditStringList SynEdit::lines() const
const PSynEditStringList& SynEdit::lines() const
{
return mLines;
}

View File

@ -258,6 +258,7 @@ public:
virtual BufferCoord getMatchingBracketEx(BufferCoord APoint);
QStringList contents();
QString text();
bool getPositionOfMouse(BufferCoord& aPos);
bool getLineOfMouse(int& line);
@ -309,7 +310,7 @@ public:
QString lineText() const;
void setLineText(const QString s);
PSynEditStringList lines() const;
const PSynEditStringList& lines() const;
bool empty();
SynSelectionMode selectionMode() const;

View File

@ -25,7 +25,7 @@ static void ListIndexOutOfBounds(int index) {
int SynEditStringList::parenthesisLevels(int Index)
int SynEditStringList::parenthesisLevels(int Index) const
{
if (Index>=0 && Index < mList.size()) {
return mList[Index]->fRange.parenthesisLevel;
@ -33,7 +33,7 @@ int SynEditStringList::parenthesisLevels(int Index)
return 0;
}
int SynEditStringList::bracketLevels(int Index)
int SynEditStringList::bracketLevels(int Index) const
{
if (Index>=0 && Index < mList.size()) {
return mList[Index]->fRange.bracketLevel;
@ -41,7 +41,7 @@ int SynEditStringList::bracketLevels(int Index)
return 0;
}
int SynEditStringList::braceLevels(int Index)
int SynEditStringList::braceLevels(int Index) const
{
if (Index>=0 && Index < mList.size()) {
return mList[Index]->fRange.braceLevel;
@ -71,7 +71,7 @@ int SynEditStringList::lineColumns(int Index)
return 0;
}
int SynEditStringList::leftBraces(int Index)
int SynEditStringList::leftBraces(int Index) const
{
if (Index>=0 && Index < mList.size()) {
return mList[Index]->fLeftBraces;
@ -79,7 +79,7 @@ int SynEditStringList::leftBraces(int Index)
return 0;
}
int SynEditStringList::rightBraces(int Index)
int SynEditStringList::rightBraces(int Index) const
{
if (Index>=0 && Index < mList.size()) {
return mList[Index]->fRightBraces;
@ -87,8 +87,7 @@ int SynEditStringList::rightBraces(int Index)
return 0;
}
int SynEditStringList::lengthOfLongestLine()
{
int SynEditStringList::lengthOfLongestLine() {
if (mIndexOfLongestLine < 0) {
int MaxLen = -1;
mIndexOfLongestLine = -1;
@ -108,7 +107,7 @@ int SynEditStringList::lengthOfLongestLine()
return 0;
}
QString SynEditStringList::lineBreak()
QString SynEditStringList::lineBreak() const
{
switch(mFileEndingType) {
case FileEndingType::Linux:
@ -121,7 +120,7 @@ QString SynEditStringList::lineBreak()
return "\n";
}
const SynRangeState& SynEditStringList::ranges(int Index)
const SynRangeState& SynEditStringList::ranges(int Index) const
{
if (Index>=0 && Index < mList.size()) {
return mList[Index]->fRange;
@ -178,7 +177,7 @@ void SynEditStringList::setRange(int Index, const SynRangeState& ARange, int ALe
endUpdate();
}
QString SynEditStringList::getString(int Index)
QString SynEditStringList::getString(int Index) const
{
if (Index<0 || Index>=mList.count()) {
return QString();
@ -186,12 +185,12 @@ QString SynEditStringList::getString(int Index)
return mList[Index]->fString;
}
int SynEditStringList::count()
int SynEditStringList::count() const
{
return mList.count();
}
void *SynEditStringList::getObject(int Index)
void *SynEditStringList::getObject(int Index) const
{
if (Index<0 || Index>=mList.count()) {
return nullptr;
@ -199,7 +198,7 @@ void *SynEditStringList::getObject(int Index)
return mList[Index]->fObject;
}
QString SynEditStringList::text()
QString SynEditStringList::text() const
{
return getTextStr();
}
@ -227,7 +226,7 @@ void SynEditStringList::setContents(const QStringList &text)
}
}
QStringList SynEditStringList::contents()
QStringList SynEditStringList::contents() const
{
QStringList Result;
SynEditStringRecList list = mList;
@ -371,7 +370,7 @@ void SynEditStringList::deleteAt(int Index)
endUpdate();
}
QString SynEditStringList::getTextStr()
QString SynEditStringList::getTextStr() const
{
QString result;
for (int i=0;i<mList.count()-1;i++) {

View File

@ -50,23 +50,23 @@ class SynEditStringList : public QObject
public:
explicit SynEditStringList(SynEdit* pEdit,QObject* parent=nullptr);
int parenthesisLevels(int Index);
int bracketLevels(int Index);
int braceLevels(int Index);
int parenthesisLevels(int Index) const;
int bracketLevels(int Index) const;
int braceLevels(int Index) const;
int lineColumns(int Index);
int leftBraces(int Index);
int rightBraces(int Index);
int leftBraces(int Index) const;
int rightBraces(int Index) const;
int lengthOfLongestLine();
QString lineBreak();
const SynRangeState& ranges(int Index);
QString lineBreak() const;
const SynRangeState& ranges(int Index) const;
void setRange(int Index, const SynRangeState& ARange, int leftBraces, int rightBraces);
QString getString(int Index);
int count();
void* getObject(int Index);
QString text();
QString getString(int Index) const;
int count() const ;
void* getObject(int Index) const;
QString text() const;
void setText(const QString& text);
void setContents(const QStringList& text);
QStringList contents();
QStringList contents() const;
void putString(int Index, const QString& s);
void putObject(int Index, void * AObject);
@ -111,7 +111,7 @@ signals:
void inserted(int index, int count);
void putted(int index, int count);
protected:
QString getTextStr();
QString getTextStr() const;
void SetUpdateState(bool Updating);
void InsertItem(int Index, const QString& s);
void addItem(const QString& s);

View File

@ -21,7 +21,7 @@ EditorSnippetWidget::EditorSnippetWidget(const QString& name, const QString& gro
if (!index.isValid())
return;
PCodeSnippet snippet = mModel.snippets()[index.row()];
snippet->code = ui->editCode->lines()->text();
snippet->code = ui->editCode->text();
setSettingsChanged();
});
connect(ui->tblSnippets->selectionModel(), &QItemSelectionModel::currentChanged,