mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Printing support: print dialog from QScintilla widgets
Add printing support for QScintilla widgets (SQL, JSON and XML). It can be
access through the contextual menu, shortcut (Ctrl+P) or (in the case of
the "Execute SQL" tab) from a button in the toolbar.
Ctrl+P was previously assigned to Plot Dock since
63c338c359 but, as it was foreseen in that
commit, it should be assign to print is ever supported. This change must
be mentioned in release notes.
First part of printing support. See issue #1525.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#include "ExtendedScintilla.h"
|
||||
#include "FindReplaceDialog.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#include "Qsci/qscilexer.h"
|
||||
#include "Qsci/qsciprinter.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QDropEvent>
|
||||
@@ -11,6 +13,7 @@
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QPalette>
|
||||
#include <QPrintDialog>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
@@ -51,10 +54,13 @@ ExtendedScintilla::ExtendedScintilla(QWidget* parent) :
|
||||
// Connect signals
|
||||
connect(this, SIGNAL(linesChanged()), this, SLOT(updateLineNumberAreaWidth()));
|
||||
|
||||
// The shortcut is constrained to the Widget context so it does not conflict with other SqlTextEdit widgets in the Main Window.
|
||||
// The shortcuts are constrained to the Widget context so they do not conflict with other SqlTextEdit widgets in the Main Window.
|
||||
QShortcut* shortcutFindReplace = new QShortcut(QKeySequence(tr("Ctrl+H")), this, nullptr, nullptr, Qt::WidgetShortcut);
|
||||
connect(shortcutFindReplace, SIGNAL(activated()), this, SLOT(openFindReplaceDialog()));
|
||||
|
||||
QShortcut* shortcutPrint = new QShortcut(QKeySequence(tr("Ctrl+P")), this, nullptr, nullptr, Qt::WidgetShortcut);
|
||||
connect(shortcutPrint, &QShortcut::activated, this, &ExtendedScintilla::openPrintDialog);
|
||||
|
||||
// Prepare for adding the find/replace option to the QScintilla context menu
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showContextMenu(const QPoint &)));
|
||||
@@ -223,14 +229,28 @@ void ExtendedScintilla::showContextMenu(const QPoint &pos)
|
||||
|
||||
QAction* findReplaceAction = new QAction(QIcon(":/icons/text_replace"), tr("Find and Replace..."), this);
|
||||
findReplaceAction->setShortcut(QKeySequence(tr("Ctrl+H")));
|
||||
connect(findReplaceAction, &QAction::triggered, [&]() {
|
||||
openFindReplaceDialog();
|
||||
});
|
||||
connect(findReplaceAction, &QAction::triggered, this, &ExtendedScintilla::openFindReplaceDialog);
|
||||
|
||||
QAction* printAction = new QAction(QIcon(":/icons/print"), tr("Print..."), this);
|
||||
printAction->setShortcut(QKeySequence(tr("Ctrl+P")));
|
||||
connect(printAction, &QAction::triggered, this, &ExtendedScintilla::openPrintDialog);
|
||||
|
||||
// This has to be created here, otherwise the set of enabled options would not update accordingly.
|
||||
QMenu* editContextMenu = createStandardContextMenu();
|
||||
editContextMenu->addSeparator();
|
||||
editContextMenu->addAction(findReplaceAction);
|
||||
editContextMenu->addAction(printAction);
|
||||
|
||||
editContextMenu->exec(mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void ExtendedScintilla::openPrintDialog()
|
||||
{
|
||||
QsciPrinter* printer = new QsciPrinter;
|
||||
|
||||
QPrintDialog printDialog(printer, this);
|
||||
if (printDialog.exec() == QDialog::Accepted)
|
||||
printer->printRange(this);
|
||||
|
||||
delete printer;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public slots:
|
||||
// Set error indicator from position to end of line
|
||||
void setErrorIndicator(int position);
|
||||
void openFindReplaceDialog();
|
||||
void openPrintDialog();
|
||||
|
||||
protected:
|
||||
void dropEvent(QDropEvent* e);
|
||||
|
||||
@@ -253,9 +253,7 @@ void MainWindow::init()
|
||||
|
||||
// Add menu item for plot dock
|
||||
ui->viewMenu->insertAction(ui->viewDBToolbarAction, ui->dockPlot->toggleViewAction());
|
||||
QList<QKeySequence> plotkeyseqlist;
|
||||
plotkeyseqlist << QKeySequence(tr("Ctrl+P")) << QKeySequence(tr("Ctrl+D"));
|
||||
ui->viewMenu->actions().at(1)->setShortcuts(plotkeyseqlist);
|
||||
ui->viewMenu->actions().at(1)->setShortcut(QKeySequence(tr("Ctrl+D")));
|
||||
ui->viewMenu->actions().at(1)->setIcon(QIcon(":/icons/log_dock"));
|
||||
|
||||
// Add menu item for schema dock
|
||||
@@ -3276,6 +3274,15 @@ void MainWindow::openFindReplaceDialog()
|
||||
sqlWidget->getEditor()->openFindReplaceDialog();
|
||||
}
|
||||
|
||||
void MainWindow::openSqlPrintDialog()
|
||||
{
|
||||
// The slot for the shortcut must discover which sqltexedit widget has the focus and then open its dialog.
|
||||
SqlExecutionArea* sqlWidget = qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->currentWidget());
|
||||
|
||||
if (sqlWidget)
|
||||
sqlWidget->getEditor()->openPrintDialog();
|
||||
}
|
||||
|
||||
void MainWindow::saveAsView(QString query)
|
||||
{
|
||||
// Let the user select a name for the new view and make sure it doesn't already exist
|
||||
|
||||
@@ -295,6 +295,7 @@ private slots:
|
||||
void renameSqlTab(int index);
|
||||
void setFindFrameVisibility(bool show);
|
||||
void openFindReplaceDialog();
|
||||
void openSqlPrintDialog();
|
||||
void saveFilterAsView();
|
||||
void exportFilteredTable();
|
||||
void updateInsertDeleteRecordButton();
|
||||
|
||||
@@ -915,6 +915,7 @@ You can drag SQL statements from an object row and drop them into other applicat
|
||||
<addaction name="actionSqlOpenTab"/>
|
||||
<addaction name="actionSqlOpenFile"/>
|
||||
<addaction name="actionSqlSaveFilePopup"/>
|
||||
<addaction name="actionSqlPrint"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExecuteSql"/>
|
||||
<addaction name="actionSqlExecuteLine"/>
|
||||
@@ -2250,6 +2251,27 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
|
||||
<string>Use escaped identifiers (e.g. "Table1") when dragging the objects and dropping them into the editor </string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSqlPrint">
|
||||
<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>Print text from current SQL editor tab [Ctrl+P]</string>
|
||||
</property>
|
||||
<property name="statusTip">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string>Open a dialog for printing the text in the current SQL editor tab</string>
|
||||
</property>
|
||||
<property name="shortcutContext">
|
||||
<enum>Qt::WidgetShortcut</enum>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
@@ -3613,6 +3635,18 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
|
||||
<x>518</x>
|
||||
<y>314</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>actionSqlPrint</sender>
|
||||
<signal>triggered()</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>openSqlPrintDialog()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>-1</x>
|
||||
<y>-1</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>518</x>
|
||||
<y>314</y>
|
||||
|
||||
@@ -66,5 +66,6 @@
|
||||
<file alias="log_dock">application_side_list.png</file>
|
||||
<file alias="db_attach">database_link.png</file>
|
||||
<file alias="text_indent">text_indent.png</file>
|
||||
<file alias="print">printer.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
BIN
src/icons/printer.png
Normal file
BIN
src/icons/printer.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 731 B |
Reference in New Issue
Block a user