Skip to content

Commit

Permalink
Added printing of selected lines
Browse files Browse the repository at this point in the history
  • Loading branch information
mezomish committed Jul 25, 2008
1 parent bea7b66 commit 136abca
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/CommandStorage.h
Expand Up @@ -40,6 +40,7 @@ typedef enum {
ID_EXIT = 1007,
ID_FILE_RELOAD = 1008,
ID_FILE_PRINT = 1009,
ID_FILE_PRINT_SELECTED = 1010,
//
ID_EDIT_CUT = 1101,
ID_EDIT_COPY = 1102,
Expand Down
8 changes: 8 additions & 0 deletions src/DocHandler.cpp
Expand Up @@ -482,6 +482,14 @@ void DocHandler::docPrint() {
doc->print();
}

void DocHandler::docPrintSelected() {
Juff::Document* doc = currentDoc();
if (doc->isNull())
return;

doc->printSelected();
}

void DocHandler::docClose() {
closeDocument(currentDoc());

Expand Down
1 change: 1 addition & 0 deletions src/DocHandler.h
Expand Up @@ -54,6 +54,7 @@ public slots:
void docSaveAs();
void docReload();
void docPrint();
void docPrintSelected();
void docClose();
void docCloseAll();
void processTheCommand();
Expand Down
1 change: 1 addition & 0 deletions src/Document.h
Expand Up @@ -74,6 +74,7 @@ Q_OBJECT
virtual Document::Status reload() = 0;
virtual Document::SaveRequest confirmForClose() = 0;
virtual void print() const = 0;
virtual void printSelected() const = 0;

virtual void processTheCommand(CommandID) = 0;
virtual void applySettings();
Expand Down
3 changes: 2 additions & 1 deletion src/JuffEd.cpp
Expand Up @@ -320,6 +320,7 @@ void JuffEd::createCommands() {
Command(ID_FILE_SAVE_AS,tr("Save as"), im->icon("fileSaveAs"), QKeySequence("Ctrl+Shift+S"), h, SLOT(docSaveAs())),
Command(ID_FILE_RELOAD, tr("Reload"), im->icon("reload"), QKeySequence("F5"), h, SLOT(docReload())),
Command(ID_FILE_PRINT, tr("Print"), im->icon("filePrint"), QKeySequence("Ctrl+P"), h, SLOT(docPrint())),
Command(ID_FILE_PRINT_SELECTED, tr("Print selected lines"), im->icon("filePrintSelected"), QKeySequence(), h, SLOT(docPrintSelected())),
Command(ID_FILE_CLOSE, tr("Close"), im->icon("fileClose"), QKeySequence("Ctrl+W"), h, SLOT(docClose())),
Command(ID_FILE_CLOSE_ALL, tr("Close all"), im->icon("fileCloseAll"), QKeySequence(), h, SLOT(docCloseAll())),
Command(ID_EXIT, tr("Exit"), im->icon("exit"), QKeySequence(), this, SLOT(exit())),
Expand Down Expand Up @@ -379,7 +380,7 @@ void JuffEd::createMenuBar() {
menuBar()->clear();

CommandID fileMenu[] = { ID_FILE_NEW, ID_FILE_OPEN, ID_FILE_SAVE, ID_FILE_SAVE_AS,
ID_FILE_RELOAD, ID_FILE_PRINT, ID_FILE_CLOSE, ID_FILE_CLOSE_ALL, ID_SEPARATOR,
ID_FILE_RELOAD, ID_FILE_PRINT, ID_FILE_PRINT_SELECTED, ID_FILE_CLOSE, ID_FILE_CLOSE_ALL, ID_SEPARATOR,
ID_SESSION_NEW, ID_SESSION_OPEN, ID_SESSION_SAVE, ID_SESSION_SAVE_AS,
ID_SEPARATOR, ID_EXIT, ID_NONE };

Expand Down
6 changes: 5 additions & 1 deletion src/NullDoc.cpp
Expand Up @@ -44,11 +44,15 @@ Juff::Document::Status NullDoc::reload() {
scream();
return StatusUnknownError;
}

void NullDoc::print() const {
scream();
}

void NullDoc::printSelected() const {
scream();
}

Juff::Document::Status NullDoc::open() {
scream();
return StatusUnknownError;
Expand Down
1 change: 1 addition & 0 deletions src/NullDoc.h
Expand Up @@ -34,6 +34,7 @@ class NullDoc : public Juff::Document {
virtual Juff::Document::Status close();
virtual Juff::Document::SaveRequest confirmForClose();
virtual void print() const;
virtual void printSelected() const;

virtual void processTheCommand(CommandID);

Expand Down
8 changes: 8 additions & 0 deletions src/TextDoc.cpp
Expand Up @@ -159,6 +159,14 @@ void TextDoc::print() const {
tdView->print();
}

void TextDoc::printSelected() const {
TextDocView* tdView = textDocView();
if (tdView == 0)
return;

tdView->printSelected();
}

Document::Status TextDoc::open() {
return readContent(fileName());
}
Expand Down
1 change: 1 addition & 0 deletions src/TextDoc.h
Expand Up @@ -37,6 +37,7 @@ Q_OBJECT
virtual Juff::Document::Status reload();
virtual Juff::Document::SaveRequest confirmForClose();
virtual void print() const;
virtual void printSelected() const;

virtual void processTheCommand(CommandID);
virtual void applySettings();
Expand Down
14 changes: 14 additions & 0 deletions src/TextDocView.cpp
Expand Up @@ -318,6 +318,20 @@ void TextDocView::print() {
}
}

void TextDocView::printSelected() {
QsciPrinter prn;
QPrintDialog dlg(&prn, this);
if (dlg.exec() == QDialog::Accepted) {
int lineFrom(-1), lineTo(-1), colFrom(-1), colTo(-1);
vInt_->edit_->getSelection(&lineFrom, &colFrom, &lineTo, &colTo);
if (colTo == 0)
--lineTo;

prn.setWrapMode(isAdjustedByWidth() ? QsciScintilla::WrapWord : QsciScintilla::WrapNone);
prn.printRange(vInt_->edit_, lineFrom, lineTo);
}
}


////////////////////////////////////////////////////////////
// EDIT
Expand Down
1 change: 1 addition & 0 deletions src/TextDocView.h
Expand Up @@ -71,6 +71,7 @@ Q_OBJECT
void undo();
void redo();
void print();
void printSelected();

void find(const QString& str, bool isRegExp, DocFindFlags flags);
void replace(const QString& from, bool isRegExp, const QString& to, DocFindFlags flags);
Expand Down

0 comments on commit 136abca

Please sign in to comment.