Seamly2D
Code documentation
shortcuts_dialog.cpp
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file shortcuts_dialog.h
4  ** @author DSCaskey <dscaskey@gmail.com>
5  ** @date 5 11, 2022
6  **
7  ** @brief
8  ** @copyright
9  ** This source code is part of the Valentine project, a pattern making
10  ** program, whose allow create and modeling patterns of clothing.
11  ** Copyright (C) 2013-2015 Seamly2D project
12  ** All Rights Reserved.
13  **
14  ** Seamly2D is free software: you can redistribute it and/or modify
15  ** it under the terms of the GNU General Public License as published by
16  ** the Free Software Foundation, either version 3 of the License, or
17  ** (at your option) any later version.
18  **
19  ** Seamly2D is distributed in the hope that it will be useful,
20  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  ** GNU General Public License for more details.
23  **
24  ** You should have received a copy of the GNU General Public License
25  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
26  **
27  *************************************************************************/
28 
29 #include "shortcuts_dialog.h"
30 #include "ui_shortcuts_dialog.h"
31 
32 #include <QApplication>
33 #include <QClipboard>
34 #include <QFileDialog>
35 #include <QFont>
36 #include <QTextDocument>
37 #include <QPageLayout>
38 #include <QPrinter>
39 #include <QPrintPreviewDialog>
40 #include <QPrintDialog>
41 #include <QShowEvent>
42 #include <QString>
43 #include <QtWidgets>
44 
45 #include "../core/vapplication.h"
46 
47 //---------------------------------------------------------------------------------------------------------------------
49  : QDialog(parent)
50  , ui(new Ui::ShortcutsDialog)
51  , isInitialized(false)
52 {
53  ui->setupUi(this);
54  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
55 
56  connect(ui->clipboard_ToolButton, &QToolButton::clicked, this, &ShortcutsDialog::copyToClipboard);
57  connect(ui->printer_ToolButton, &QToolButton::clicked, this, &ShortcutsDialog::sendToPrinter);
58  connect(ui->pdf_ToolButton, &QToolButton::clicked, this, &ShortcutsDialog::exportPdf);
59 }
60 
61 //---------------------------------------------------------------------------------------------------------------------
63 {
64  delete ui;
65 }
66 
67 //---------------------------------------------------------------------------------------------------------------------
68 void ShortcutsDialog::showEvent(QShowEvent *event)
69 {
70  QDialog::showEvent(event);
71  if (event->spontaneous())
72  {
73  return;
74  }
75 
76  if (isInitialized)
77  {
78  return;
79  }
80  // do your init stuff here
81 
82  setMaximumSize(size());
83  setMinimumSize(size());
84 
85  isInitialized = true;//first show windows are held
86 }
87 
89 {
90  ui->shortcuts_TextBrowser->selectAll();
91  ui->shortcuts_TextBrowser->copy();
92 }
94 {
95  QPrinter printer;
96  QPrintDialog printDialog(&printer);
97  if(printDialog.exec())
98  {
99  QTextDocument textDocument;
100  textDocument.setHtml(ui->shortcuts_TextBrowser->toHtml());
101  textDocument.print(&printer);
102  }
103 }
104 
106 {
107  QString filename = QFileDialog::getSaveFileName(nullptr, tr("Export PDF"), QString(),
108  "*.pdf", nullptr, QFileDialog::DontUseNativeDialog);
109 
110  if (QFileInfo(filename).suffix().isEmpty())
111  {
112  filename.append(".pdf");
113  }
114  QPrinter printer(QPrinter::PrinterResolution);
115  printer.setOutputFormat(QPrinter::PdfFormat);
116  printer.setPageSize(printer.pageLayout().pageSize());
117  printer.setOutputFileName(filename);
118 
119  QTextDocument textDocument;
120  textDocument.setHtml(ui->shortcuts_TextBrowser->toHtml());
121  textDocument.setPageSize(printer.pageLayout().paintRectPixels(printer.resolution()).size());
122  textDocument.print(&printer);
123 }
virtual ~ShortcutsDialog()
Ui::ShortcutsDialog * ui
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE
ShortcutsDialog(QWidget *parent=nullptr)