mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 19:11:39 -06:00
Printing support #1525: shortcuts for the hex and text editors
Print shortcuts are added in the context of the text and hex editors of the Edit Database Cell dock.
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QtXml/QDomDocument>
|
||||
#include <QMessageBox>
|
||||
#include <QPrinter>
|
||||
#include <QPrintPreviewDialog>
|
||||
|
||||
EditDialog::EditDialog(QWidget* parent)
|
||||
: QDialog(parent),
|
||||
@@ -48,6 +50,12 @@ EditDialog::EditDialog(QWidget* parent)
|
||||
connect(sciEdit, SIGNAL(textChanged()), this, SLOT(updateApplyButton()));
|
||||
connect(sciEdit, SIGNAL(textChanged()), this, SLOT(editTextChanged()));
|
||||
|
||||
// Create shortcuts for the widgets that doesn't have its own printing mechanism.
|
||||
QShortcut* shortcutPrintHex = new QShortcut(QKeySequence::Print, hexEdit, nullptr, nullptr, Qt::WidgetShortcut);
|
||||
connect(shortcutPrintHex, &QShortcut::activated, this, &EditDialog::openPrintDialog);
|
||||
QShortcut* shortcutPrintText = new QShortcut(QKeySequence::Print, ui->editorText, nullptr, nullptr, Qt::WidgetShortcut);
|
||||
connect(shortcutPrintText, &QShortcut::activated, this, &EditDialog::openPrintDialog);
|
||||
|
||||
mustIndentAndCompact = Settings::getValue("databrowser", "indent_compact").toBool();
|
||||
ui->buttonIndent->setChecked(mustIndentAndCompact);
|
||||
|
||||
@@ -1022,3 +1030,33 @@ void EditDialog::setStackCurrentIndex(int editMode)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void EditDialog::openPrintDialog()
|
||||
{
|
||||
QPrinter printer;
|
||||
QPrintPreviewDialog *dialog = new QPrintPreviewDialog(&printer);
|
||||
|
||||
QTextDocument *document = new QTextDocument();
|
||||
switch (dataSource) {
|
||||
case TextBuffer:
|
||||
document->setPlainText(ui->editorText->toPlainText());
|
||||
break;
|
||||
case SciBuffer:
|
||||
// This case isn't really expected because the Scintilla widget has it's own printing slot
|
||||
document->setPlainText(sciEdit->text());
|
||||
break;
|
||||
case HexBuffer:
|
||||
document->setPlainText(hexEdit->toReadableString());
|
||||
document->setDefaultFont(hexEdit->font());
|
||||
break;
|
||||
}
|
||||
|
||||
connect(dialog, &QPrintPreviewDialog::paintRequested, [&](QPrinter *previewPrinter) {
|
||||
document->print(previewPrinter);
|
||||
});
|
||||
|
||||
dialog->exec();
|
||||
|
||||
delete dialog;
|
||||
delete document;
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ private:
|
||||
bool promptInvalidData(const QString& dataType, const QString& errorString);
|
||||
void setDataInBuffer(const QByteArray& data, DataSources source);
|
||||
void setStackCurrentIndex(int editMode);
|
||||
void openPrintDialog();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user