Changeset View
Changeset View
Standalone View
Standalone View
kmplot/maindlg.cpp
Show All 12 Lines | |||||
32 | #include <QImageWriter> | 32 | #include <QImageWriter> | ||
33 | #include <QMainWindow> | 33 | #include <QMainWindow> | ||
34 | #include <QMenu> | 34 | #include <QMenu> | ||
35 | #include <QMimeDatabase> | 35 | #include <QMimeDatabase> | ||
36 | #include <QMimeType> | 36 | #include <QMimeType> | ||
37 | #include <QPixmap> | 37 | #include <QPixmap> | ||
38 | #include <QPrintDialog> | 38 | #include <QPrintDialog> | ||
39 | #include <QPrinter> | 39 | #include <QPrinter> | ||
40 | #include <QPrintPreviewDialog> | ||||
41 | #include <QPrintPreviewWidget> | ||||
40 | #include <QStandardPaths> | 42 | #include <QStandardPaths> | ||
41 | #include <QSvgGenerator> | 43 | #include <QSvgGenerator> | ||
42 | #include <QTemporaryFile> | 44 | #include <QTemporaryFile> | ||
43 | #include <QTimer> | 45 | #include <QTimer> | ||
44 | 46 | | |||
45 | // KDE includes | 47 | // KDE includes | ||
46 | #include <KActionCollection> | 48 | #include <KActionCollection> | ||
47 | #include <KConfigDialog> | 49 | #include <KConfigDialog> | ||
Show All 24 Lines | |||||
225 | } | 227 | } | ||
226 | 228 | | |||
227 | void MainDlg::setupActions() | 229 | void MainDlg::setupActions() | ||
228 | { | 230 | { | ||
229 | // standard actions | 231 | // standard actions | ||
230 | m_recentFiles = KStandardAction::openRecent( this, SLOT(slotOpenRecent(QUrl)), this ); | 232 | m_recentFiles = KStandardAction::openRecent( this, SLOT(slotOpenRecent(QUrl)), this ); | ||
231 | actionCollection()->addAction( "file_open_recent", m_recentFiles ); | 233 | actionCollection()->addAction( "file_open_recent", m_recentFiles ); | ||
232 | actionCollection()->addAction( KStandardAction::Print, "file_print", this, SLOT(slotPrint()) ); | 234 | actionCollection()->addAction( KStandardAction::Print, "file_print", this, SLOT(slotPrint()) ); | ||
235 | actionCollection()->addAction( KStandardAction::PrintPreview, "file_print_preview", this, SLOT(slotPrintPreview()) ); | ||||
aacid: maybe use a new style connect here? | |||||
There is no addAction(KStandardAction::StandardAction, QString, QObject, Func) prototype in KActionCollection, so it's OK. cfeck: There is no `addAction(KStandardAction::StandardAction, QString, QObject, Func)` prototype in… | |||||
aacid: oh, someone should fix that :) | |||||
233 | KStandardAction::save( this, SLOT(slotSave()), actionCollection() ); | 236 | KStandardAction::save( this, SLOT(slotSave()), actionCollection() ); | ||
234 | KStandardAction::saveAs( this, SLOT(slotSaveas()), actionCollection() ); | 237 | KStandardAction::saveAs( this, SLOT(slotSaveas()), actionCollection() ); | ||
235 | 238 | | |||
236 | QAction *prefs = KStandardAction::preferences( this, SLOT(slotSettings()), actionCollection()); | 239 | QAction *prefs = KStandardAction::preferences( this, SLOT(slotSettings()), actionCollection()); | ||
237 | prefs->setText( i18n( "Configure KmPlot..." ) ); | 240 | prefs->setText( i18n( "Configure KmPlot..." ) ); | ||
238 | 241 | | |||
239 | // KmPlot specific actions | 242 | // KmPlot specific actions | ||
240 | 243 | | |||
Show All 24 Lines | 689 | { | |||
688 | View::self()->setPrintBackground( printdlg->printBackground() ); | 691 | View::self()->setPrintBackground( printdlg->printBackground() ); | ||
689 | View::self()->setPrintWidth( printdlg->printWidth() ); | 692 | View::self()->setPrintWidth( printdlg->printWidth() ); | ||
690 | View::self()->setPrintHeight( printdlg->printHeight() ); | 693 | View::self()->setPrintHeight( printdlg->printHeight() ); | ||
691 | View::self()->draw(&prt, View::Printer); | 694 | View::self()->draw(&prt, View::Printer); | ||
692 | } | 695 | } | ||
693 | delete printDialog; | 696 | delete printDialog; | ||
694 | } | 697 | } | ||
695 | 698 | | |||
699 | void MainDlg::slotPrintPreview() | ||||
700 | { | ||||
701 | QPrinter prt( QPrinter::PrinterResolution ); | ||||
702 | prt.setResolution( 72 ); | ||||
703 | QPrintPreviewDialog preview( &prt ); | ||||
704 | KPrinterDlg* printdlg = new KPrinterDlg( m_parent ); | ||||
If you are creating them here to delete them in the end of the function, why don't you create them on the stack? tcanabrava: If you are creating them here to delete them in the end of the function, why don't you create… | |||||
The same pattern can be found above. Just for other possible reviewers, the discussions on this topic can be found by the following addresses https://blogs.kde.org/node/3919 https://phabricator.kde.org/D7285 https://phabricator.kde.org/D17697 It seems that this is a questionable decision but it might be of some sense. Thanks in advance for your opinions. yurchor: The same pattern can be found above.
Just for other possible reviewers, the discussions on… | |||||
705 | QList<QToolBar *> toolbarlist = preview.findChildren<QToolBar *>(); | ||||
706 | if(!toolbarlist.isEmpty()) | ||||
707 | { | ||||
708 | QAction *printSettings = toolbarlist.first()->addAction( QIcon::fromTheme( "configure" ), i18n("Print Settings") ); | ||||
709 | QList<QPrintPreviewWidget*> previewWidgetsList = preview.findChildren<QPrintPreviewWidget*>(); | ||||
710 | QPrintPreviewWidget *previewWidget = previewWidgetsList.first(); | ||||
711 | connect( printSettings, &QAction::triggered, [&preview, previewWidget, printdlg, &prt]{ | ||||
712 | QDialog *printSettingsDialog = new QDialog( &preview, Qt::WindowFlags() ); | ||||
713 | printSettingsDialog->setWindowTitle( i18n("Print Settings") ); | ||||
714 | QVBoxLayout *mainLayout = new QVBoxLayout; | ||||
715 | printSettingsDialog->setLayout(mainLayout); | ||||
716 | mainLayout->addWidget(printdlg); | ||||
717 | QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok|QDialogButtonBox::Cancel ); | ||||
718 | connect(buttonBox, &QDialogButtonBox::accepted, [previewWidget, printSettingsDialog]{ | ||||
719 | previewWidget->updatePreview(); | ||||
720 | printSettingsDialog->close(); | ||||
721 | } ); | ||||
722 | connect(buttonBox, &QDialogButtonBox::rejected, printSettingsDialog, &QDialog::reject); | ||||
723 | mainLayout->addWidget(buttonBox); | ||||
724 | printSettingsDialog->show(); | ||||
725 | }); | ||||
726 | } | ||||
727 | connect(&preview, &QPrintPreviewDialog::paintRequested, [&printdlg](QPrinter *p){ | ||||
728 | View::self()->setPrintHeaderTable( printdlg->printHeaderTable() ); | ||||
729 | View::self()->setPrintBackground( printdlg->printBackground() ); | ||||
730 | View::self()->setPrintWidth( printdlg->printWidth() ); | ||||
731 | View::self()->setPrintHeight( printdlg->printHeight() ); | ||||
732 | View::self()->draw( p, View::Printer ); | ||||
733 | } ); | ||||
734 | preview.exec(); | ||||
735 | } | ||||
696 | 736 | | |||
tcanabrava: create them on the stack do you don't need to call delete.
| |||||
697 | void MainDlg::editAxes() | 737 | void MainDlg::editAxes() | ||
698 | { | 738 | { | ||
699 | coordsDialog()->show(); | 739 | coordsDialog()->show(); | ||
700 | } | 740 | } | ||
701 | 741 | | |||
702 | 742 | | |||
703 | void MainDlg::editConstants() | 743 | void MainDlg::editConstants() | ||
704 | { | 744 | { | ||
Show All 11 Lines |
maybe use a new style connect here?