|
1 | 1 | #include "ExtendedScintilla.h" |
2 | 2 | #include "FindReplaceDialog.h" |
3 | 3 | #include "Settings.h" |
| 4 | + |
4 | 5 | #include "Qsci/qscilexer.h" |
| 6 | +#include "Qsci/qsciprinter.h" |
5 | 7 |
|
6 | 8 | #include <QFile> |
7 | 9 | #include <QDropEvent> |
|
11 | 13 | #include <QAction> |
12 | 14 | #include <QMenu> |
13 | 15 | #include <QPalette> |
| 16 | +#include <QPrintDialog> |
14 | 17 | #include <cmath> |
15 | 18 |
|
16 | 19 |
|
@@ -51,10 +54,13 @@ ExtendedScintilla::ExtendedScintilla(QWidget* parent) : |
51 | 54 | // Connect signals |
52 | 55 | connect(this, SIGNAL(linesChanged()), this, SLOT(updateLineNumberAreaWidth())); |
53 | 56 |
|
54 | | - // The shortcut is constrained to the Widget context so it does not conflict with other SqlTextEdit widgets in the Main Window. |
| 57 | + // The shortcuts are constrained to the Widget context so they do not conflict with other SqlTextEdit widgets in the Main Window. |
55 | 58 | QShortcut* shortcutFindReplace = new QShortcut(QKeySequence(tr("Ctrl+H")), this, nullptr, nullptr, Qt::WidgetShortcut); |
56 | 59 | connect(shortcutFindReplace, SIGNAL(activated()), this, SLOT(openFindReplaceDialog())); |
57 | 60 |
|
| 61 | + QShortcut* shortcutPrint = new QShortcut(QKeySequence(tr("Ctrl+P")), this, nullptr, nullptr, Qt::WidgetShortcut); |
| 62 | + connect(shortcutPrint, &QShortcut::activated, this, &ExtendedScintilla::openPrintDialog); |
| 63 | + |
58 | 64 | // Prepare for adding the find/replace option to the QScintilla context menu |
59 | 65 | setContextMenuPolicy(Qt::CustomContextMenu); |
60 | 66 | connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showContextMenu(const QPoint &))); |
@@ -223,14 +229,28 @@ void ExtendedScintilla::showContextMenu(const QPoint &pos) |
223 | 229 |
|
224 | 230 | QAction* findReplaceAction = new QAction(QIcon(":/icons/text_replace"), tr("Find and Replace..."), this); |
225 | 231 | findReplaceAction->setShortcut(QKeySequence(tr("Ctrl+H"))); |
226 | | - connect(findReplaceAction, &QAction::triggered, [&]() { |
227 | | - openFindReplaceDialog(); |
228 | | - }); |
| 232 | + connect(findReplaceAction, &QAction::triggered, this, &ExtendedScintilla::openFindReplaceDialog); |
| 233 | + |
| 234 | + QAction* printAction = new QAction(QIcon(":/icons/print"), tr("Print..."), this); |
| 235 | + printAction->setShortcut(QKeySequence(tr("Ctrl+P"))); |
| 236 | + connect(printAction, &QAction::triggered, this, &ExtendedScintilla::openPrintDialog); |
229 | 237 |
|
230 | 238 | // This has to be created here, otherwise the set of enabled options would not update accordingly. |
231 | 239 | QMenu* editContextMenu = createStandardContextMenu(); |
232 | 240 | editContextMenu->addSeparator(); |
233 | 241 | editContextMenu->addAction(findReplaceAction); |
| 242 | + editContextMenu->addAction(printAction); |
234 | 243 |
|
235 | 244 | editContextMenu->exec(mapToGlobal(pos)); |
236 | 245 | } |
| 246 | + |
| 247 | +void ExtendedScintilla::openPrintDialog() |
| 248 | +{ |
| 249 | + QsciPrinter* printer = new QsciPrinter; |
| 250 | + |
| 251 | + QPrintDialog printDialog(printer, this); |
| 252 | + if (printDialog.exec() == QDialog::Accepted) |
| 253 | + printer->printRange(this); |
| 254 | + |
| 255 | + delete printer; |
| 256 | +} |
0 commit comments