Seamly2D
Code documentation
me_shortcuts_dialog.cpp
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file me_shortcuts_dialog.h
4  ** @author DSCaskey <dscaskey@gmail.com>
5  ** @date 5 14, 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 "me_shortcuts_dialog.h"
30 #include "ui_me_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 "../mapplication.h"
46 
47 //---------------------------------------------------------------------------------------------------------------------
49  : QDialog(parent)
50  , ui(new Ui::MeShortcutsDialog)
51  , isInitialized(false)
52 {
53  ui->setupUi(this);
54  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
55 
56  connect(ui->clipboard_ToolButton, &QToolButton::clicked, this, &MeShortcutsDialog::copyToClipboard);
57  connect(ui->printer_ToolButton, &QToolButton::clicked, this, &MeShortcutsDialog::sendToPrinter);
58  connect(ui->pdf_ToolButton, &QToolButton::clicked, this, &MeShortcutsDialog::exportPdf);
59 }
60 
61 //---------------------------------------------------------------------------------------------------------------------
63 {
64  delete ui;
65 }
66 
67 //---------------------------------------------------------------------------------------------------------------------
68 void MeShortcutsDialog::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  //QClipboard *clipboard = QApplication::clipboard();
91  //clipboard->setText(ui->shortcuts_TextBrowser->toPlainText());
92 
93  ui->shortcuts_TextBrowser->selectAll();
94  ui->shortcuts_TextBrowser->copy();
95 }
97 {
98  QPrinter printer;
99  QPrintDialog printDialog(&printer);
100  if(printDialog.exec())
101  {
102  QTextDocument textDocument;
103  textDocument.setHtml(ui->shortcuts_TextBrowser->toHtml());
104  textDocument.print(&printer);
105  }
106 }
107 
109 {
110  QString filename = QFileDialog::getSaveFileName(nullptr, tr("Export PDF"), QString(),
111  "*.pdf", nullptr, QFileDialog::DontUseNativeDialog);
112 
113  if (QFileInfo(filename).suffix().isEmpty())
114  {
115  filename.append(".pdf");
116  }
117  QPrinter printer(QPrinter::PrinterResolution);
118  printer.setOutputFormat(QPrinter::PdfFormat);
119  printer.setPageSize(printer.pageLayout().pageSize());
120  printer.setOutputFileName(filename);
121 
122  QTextDocument textDocument;
123  textDocument.setHtml(ui->shortcuts_TextBrowser->toHtml());
124  textDocument.setPageSize(printer.pageLayout().paintRectPixels(printer.resolution()).size());
125  textDocument.print(&printer);
126 }
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE
MeShortcutsDialog(QWidget *parent=nullptr)
Ui::MeShortcutsDialog * ui