mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
Printing support #1525: print images in Editor Dialog and menu in hex
Added support for printing images in the Editor Dialog. A new action added that can be activated through the context menu or shortcut for printing. The same approach is applied to the hex editor, which also lacked a context menu. Consequently the specific shortcut can be deleted.
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QPrinter>
|
||||
#include <QPrintPreviewDialog>
|
||||
#include <QPainter>
|
||||
|
||||
EditDialog::EditDialog(QWidget* parent)
|
||||
: QDialog(parent),
|
||||
@@ -50,12 +51,14 @@ 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);
|
||||
// Create shortcuts for the widgets that doesn't have its own print action or printing mechanism.
|
||||
QShortcut* shortcutPrintText = new QShortcut(QKeySequence::Print, ui->editorText, nullptr, nullptr, Qt::WidgetShortcut);
|
||||
connect(shortcutPrintText, &QShortcut::activated, this, &EditDialog::openPrintDialog);
|
||||
|
||||
// Add actions to editors that have a context menu based on actions. This also activates the shortcuts.
|
||||
ui->editorImage->addAction(ui->actionPrintImage);
|
||||
ui->editorBinary->addAction(ui->actionPrint);
|
||||
|
||||
mustIndentAndCompact = Settings::getValue("databrowser", "indent_compact").toBool();
|
||||
ui->buttonIndent->setChecked(mustIndentAndCompact);
|
||||
|
||||
@@ -359,6 +362,8 @@ void EditDialog::importData()
|
||||
|
||||
void EditDialog::exportData()
|
||||
{
|
||||
openPrintImageDialog();
|
||||
return;
|
||||
QStringList filters;
|
||||
switch (dataType) {
|
||||
case Image: {
|
||||
@@ -1060,3 +1065,23 @@ void EditDialog::openPrintDialog()
|
||||
delete dialog;
|
||||
delete document;
|
||||
}
|
||||
|
||||
void EditDialog::openPrintImageDialog()
|
||||
{
|
||||
QPrinter printer;
|
||||
QPrintPreviewDialog *dialog = new QPrintPreviewDialog(&printer);
|
||||
|
||||
connect(dialog, &QPrintPreviewDialog::paintRequested, [&](QPrinter *previewPrinter) {
|
||||
QPainter painter(previewPrinter);
|
||||
QRect rect = painter.viewport();
|
||||
QSize size = ui->editorImage->pixmap()->size();
|
||||
size.scale(rect.size(), Qt::KeepAspectRatio);
|
||||
painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
|
||||
painter.setWindow(ui->editorImage->pixmap()->rect());
|
||||
painter.drawPixmap(0, 0, *ui->editorImage->pixmap());
|
||||
});
|
||||
|
||||
dialog->exec();
|
||||
|
||||
delete dialog;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ private slots:
|
||||
void switchEditorMode(bool autoSwitchForType);
|
||||
void updateCellInfoAndMode(const QByteArray& data);
|
||||
void setMustIndentAndCompact(bool enable);
|
||||
void openPrintDialog();
|
||||
void openPrintImageDialog();
|
||||
|
||||
signals:
|
||||
void recordTextUpdated(const QPersistentModelIndex& idx, const QByteArray& data, bool isBlob);
|
||||
@@ -89,7 +91,6 @@ private:
|
||||
bool promptInvalidData(const QString& dataType, const QString& errorString);
|
||||
void setDataInBuffer(const QByteArray& data, DataSources source);
|
||||
void setStackCurrentIndex(int editMode);
|
||||
void openPrintDialog();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -216,7 +216,11 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="editorBinary"/>
|
||||
<widget class="QWidget" name="editorBinary">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::ActionsContextMenu</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QScrollArea" name="editorImageScrollArea">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
@@ -233,6 +237,9 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="editorImage">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::ActionsContextMenu</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
@@ -302,6 +309,36 @@ Errors are indicated with a red squiggle underline.</string>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
<action name="actionPrintImage">
|
||||
<property name="icon">
|
||||
<iconset resource="icons/icons.qrc">
|
||||
<normaloff>:/icons/print</normaloff>:/icons/print</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Print...</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Open preview dialog for printing displayed image</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+P</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPrint">
|
||||
<property name="icon">
|
||||
<iconset resource="icons/icons.qrc">
|
||||
<normaloff>:/icons/print</normaloff>:/icons/print</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Print...</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Open preview dialog for printing displayed text</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+P</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>buttonExport</tabstop>
|
||||
@@ -439,6 +476,38 @@ Errors are indicated with a red squiggle underline.</string>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>actionPrintImage</sender>
|
||||
<signal>triggered()</signal>
|
||||
<receiver>EditDialog</receiver>
|
||||
<slot>openPrintImageDialog()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>-1</x>
|
||||
<y>-1</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>308</x>
|
||||
<y>190</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>actionPrint</sender>
|
||||
<signal>triggered()</signal>
|
||||
<receiver>EditDialog</receiver>
|
||||
<slot>openPrintDialog()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>-1</x>
|
||||
<y>-1</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>308</x>
|
||||
<y>190</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>importData()</slot>
|
||||
|
||||
Reference in New Issue
Block a user