Changeset View
Changeset View
Standalone View
Standalone View
kmplot/maindlg.cpp
Show All 31 Lines | |||||
32 | #include <QIcon> | 32 | #include <QIcon> | ||
33 | #include <QImageWriter> | 33 | #include <QImageWriter> | ||
34 | #include <QMainWindow> | 34 | #include <QMainWindow> | ||
35 | #include <QMenu> | 35 | #include <QMenu> | ||
36 | #include <QMimeDatabase> | 36 | #include <QMimeDatabase> | ||
37 | #include <QMimeType> | 37 | #include <QMimeType> | ||
38 | #include <QPixmap> | 38 | #include <QPixmap> | ||
39 | #include <QPrintDialog> | 39 | #include <QPrintDialog> | ||
40 | #include <QPrinter> | 40 | #include <QPrintPreviewDialog> | ||
41 | #include <QPrintPreviewWidget> | ||||
41 | #include <QStandardPaths> | 42 | #include <QStandardPaths> | ||
42 | #include <QSvgGenerator> | 43 | #include <QSvgGenerator> | ||
43 | #include <QTemporaryFile> | 44 | #include <QTemporaryFile> | ||
44 | #include <QTimer> | 45 | #include <QTimer> | ||
45 | 46 | | |||
46 | // KDE includes | 47 | // KDE includes | ||
47 | #include <KActionCollection> | 48 | #include <KActionCollection> | ||
48 | #include <KConfigDialog> | 49 | #include <KConfigDialog> | ||
49 | #include <KConfigDialogManager> | 50 | #include <KConfigDialogManager> | ||
50 | #include <KHelpClient> | 51 | #include <KHelpClient> | ||
51 | #include <KIO/StatJob> | 52 | #include <KIO/StatJob> | ||
52 | #include <KIO/StoredTransferJob> | 53 | #include <KIO/StoredTransferJob> | ||
53 | #include <KLineEdit> | 54 | #include <KLineEdit> | ||
54 | #include <KMessageBox> | 55 | #include <KMessageBox> | ||
55 | #include <KStandardAction> | 56 | #include <KStandardAction> | ||
56 | #include <KToolBar> | 57 | #include <KToolBar> | ||
57 | #include <KToolInvocation> | 58 | #include <KToolInvocation> | ||
58 | 59 | | |||
59 | // local includes | 60 | // local includes | ||
60 | #include "calculator.h" | 61 | #include "calculator.h" | ||
61 | #include "functiontools.h" | 62 | #include "functiontools.h" | ||
62 | #include "functioneditor.h" | 63 | #include "functioneditor.h" | ||
63 | #include "kprinterdlg.h" | | |||
64 | #include "kconstanteditor.h" | 64 | #include "kconstanteditor.h" | ||
65 | #include "xparser.h" | 65 | #include "xparser.h" | ||
66 | 66 | | |||
67 | #include "settings.h" | 67 | #include "settings.h" | ||
68 | #include "ui_settingspagecolor.h" | 68 | #include "ui_settingspagecolor.h" | ||
69 | #include "ui_settingspagefonts.h" | 69 | #include "ui_settingspagefonts.h" | ||
70 | #include "ui_settingspagegeneral.h" | 70 | #include "ui_settingspagegeneral.h" | ||
71 | #include "ui_settingspagediagram.h" | 71 | #include "ui_settingspagediagram.h" | ||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Line(s) | |||||
227 | } | 227 | } | ||
228 | 228 | | |||
229 | void MainDlg::setupActions() | 229 | void MainDlg::setupActions() | ||
230 | { | 230 | { | ||
231 | // standard actions | 231 | // standard actions | ||
232 | m_recentFiles = KStandardAction::openRecent( this, SLOT(slotOpenRecent(QUrl)), this ); | 232 | m_recentFiles = KStandardAction::openRecent( this, SLOT(slotOpenRecent(QUrl)), this ); | ||
233 | actionCollection()->addAction( "file_open_recent", m_recentFiles ); | 233 | actionCollection()->addAction( "file_open_recent", m_recentFiles ); | ||
234 | 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 :) | |||||
235 | KStandardAction::save( this, SLOT(slotSave()), actionCollection() ); | 236 | KStandardAction::save( this, SLOT(slotSave()), actionCollection() ); | ||
236 | KStandardAction::saveAs( this, SLOT(slotSaveas()), actionCollection() ); | 237 | KStandardAction::saveAs( this, SLOT(slotSaveas()), actionCollection() ); | ||
237 | 238 | | |||
238 | QAction *prefs = KStandardAction::preferences( this, SLOT(slotSettings()), actionCollection()); | 239 | QAction *prefs = KStandardAction::preferences( this, SLOT(slotSettings()), actionCollection()); | ||
239 | prefs->setText( i18n( "Configure KmPlot..." ) ); | 240 | prefs->setText( i18n( "Configure KmPlot..." ) ); | ||
240 | 241 | | |||
241 | // KmPlot specific actions | 242 | // KmPlot specific actions | ||
242 | 243 | | |||
▲ Show 20 Lines • Show All 451 Lines • ▼ Show 20 Line(s) | 679 | { | |||
694 | resetUndoRedo(); | 695 | resetUndoRedo(); | ||
695 | View::self()->updateSliders(); | 696 | View::self()->updateSliders(); | ||
696 | View::self()->drawPlot(); | 697 | View::self()->drawPlot(); | ||
697 | } | 698 | } | ||
698 | 699 | | |||
699 | void MainDlg::slotPrint() | 700 | void MainDlg::slotPrint() | ||
700 | { | 701 | { | ||
701 | QPrinter prt( QPrinter::PrinterResolution ); | 702 | QPrinter prt( QPrinter::PrinterResolution ); | ||
702 | prt.setResolution( 72 ); | 703 | prt.setResolution( 72 ); | ||
703 | KPrinterDlg* printdlg = new KPrinterDlg( m_parent ); | 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… | |||||
704 | printdlg->setObjectName( "KmPlot page" ); | 705 | printdlg->setObjectName( "KmPlot page" ); | ||
705 | QPointer<QPrintDialog> printDialog = new QPrintDialog( &prt, m_parent ); | 706 | QPointer<QPrintDialog> printDialog = new QPrintDialog( &prt, m_parent ); | ||
706 | printDialog->setOptionTabs( QList<QWidget*>() << printdlg ); | 707 | printDialog->setOptionTabs( QList<QWidget*>() << printdlg ); | ||
707 | printDialog->setWindowTitle( i18n("Print Plot") ); | 708 | printDialog->setWindowTitle( i18n("Print Plot") ); | ||
708 | 709 | | |||
709 | if (printDialog->exec()) | 710 | if (printDialog->exec()) | ||
710 | { | 711 | { | ||
711 | View::self()->setPrintHeaderTable( printdlg->printHeaderTable() ); | 712 | setupPrinter(printdlg, &prt); | ||
712 | View::self()->setPrintBackground( printdlg->printBackground() ); | | |||
713 | View::self()->setPrintWidth( printdlg->printWidth() ); | | |||
714 | View::self()->setPrintHeight( printdlg->printHeight() ); | | |||
715 | View::self()->draw(&prt, View::Printer); | | |||
716 | } | 713 | } | ||
717 | delete printDialog; | 714 | delete printDialog; | ||
718 | } | 715 | } | ||
719 | 716 | | |||
717 | void MainDlg::slotPrintPreview() | ||||
718 | { | ||||
719 | QPrinter prt( QPrinter::PrinterResolution ); | ||||
720 | QPointer<QPrintPreviewDialog> preview = new QPrintPreviewDialog( &prt ); | ||||
721 | QPointer<KPrinterDlg> printdlg = new KPrinterDlg( m_parent ); | ||||
722 | QList<QToolBar *> toolbarlist = preview->findChildren<QToolBar *>(); | ||||
723 | if(!toolbarlist.isEmpty()) | ||||
724 | { | ||||
725 | QAction *printSettings = toolbarlist.first()->addAction( QIcon::fromTheme( "configure" ), i18n("Print Settings") ); | ||||
726 | QList<QPrintPreviewWidget*> previewWidgetsList = preview->findChildren<QPrintPreviewWidget*>(); | ||||
727 | QPrintPreviewWidget *previewWidget = previewWidgetsList.first(); | ||||
728 | connect( printSettings, &QAction::triggered, [preview, previewWidget, printdlg, &prt]{ | ||||
729 | QDialog *printSettingsDialog = new QDialog( preview, Qt::WindowFlags() ); | ||||
730 | printSettingsDialog->setWindowTitle( i18n("Print Settings") ); | ||||
731 | QVBoxLayout *mainLayout = new QVBoxLayout; | ||||
732 | printSettingsDialog->setLayout(mainLayout); | ||||
733 | mainLayout->addWidget(printdlg); | ||||
734 | QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok|QDialogButtonBox::Cancel ); | ||||
735 | connect(buttonBox, &QDialogButtonBox::accepted, [previewWidget, printSettingsDialog]{ | ||||
736 | previewWidget->updatePreview(); | ||||
tcanabrava: create them on the stack do you don't need to call delete.
| |||||
737 | printSettingsDialog->close(); | ||||
738 | } ); | ||||
739 | connect(buttonBox, &QDialogButtonBox::rejected, printSettingsDialog, &QDialog::reject); | ||||
740 | mainLayout->addWidget(buttonBox); | ||||
741 | printSettingsDialog->show(); | ||||
742 | }); | ||||
743 | } | ||||
744 | connect(preview, &QPrintPreviewDialog::paintRequested, [this, &printdlg, &prt]{ | ||||
745 | setupPrinter(printdlg, &prt); | ||||
746 | } ); | ||||
747 | preview->exec(); | ||||
748 | delete printdlg; | ||||
749 | delete preview; | ||||
750 | } | ||||
751 | | ||||
752 | void MainDlg::setupPrinter(KPrinterDlg *printDialog, QPrinter *printer) | ||||
753 | { | ||||
754 | View::self()->setPrintHeaderTable( printDialog->printHeaderTable() ); | ||||
755 | View::self()->setPrintBackground( printDialog->printBackground() ); | ||||
756 | View::self()->setPrintWidth( printDialog->printWidth() ); | ||||
757 | View::self()->setPrintHeight( printDialog->printHeight() ); | ||||
758 | View::self()->draw(printer, View::Printer); | ||||
759 | } | ||||
720 | 760 | | |||
721 | void MainDlg::editAxes() | 761 | void MainDlg::editAxes() | ||
722 | { | 762 | { | ||
723 | coordsDialog()->show(); | 763 | coordsDialog()->show(); | ||
724 | } | 764 | } | ||
725 | 765 | | |||
726 | 766 | | |||
727 | void MainDlg::editConstants() | 767 | void MainDlg::editConstants() | ||
▲ Show 20 Lines • Show All 121 Lines • Show Last 20 Lines |
maybe use a new style connect here?