commit 3751edec219493acf9d0e66d1935f98eb17eb24d Author: Ivan I. Ovchinnikov Date: Mon Dec 5 23:53:37 2022 +0300 initial (hope final) diff --git a/PDF_Reader.pro b/PDF_Reader.pro new file mode 100644 index 0000000..431d642 --- /dev/null +++ b/PDF_Reader.pro @@ -0,0 +1,8 @@ +QT += core gui axcontainer +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +TARGET = PDF_Reader +TEMPLATE = app +SOURCES += main.cpp\ + mainwindow.cpp +HEADERS += mainwindow.h +FORMS += mainwindow.ui diff --git a/PDF_Reader.pro.user b/PDF_Reader.pro.user new file mode 100644 index 0000000..0cc0ad3 --- /dev/null +++ b/PDF_Reader.pro.user @@ -0,0 +1,264 @@ + + + + + + EnvironmentId + {9e761060-3d68-4c1e-a2de-b1c2717309fc} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + -fno-delayed-template-parsing + + true + Builtin.BuildSystem + + true + true + Builtin.DefaultTidyAndClazy + 2 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 5.12.12 MinGW 64-bit + Desktop Qt 5.12.12 MinGW 64-bit + qt.qt5.51212.win64_mingw73_kit + 0 + 0 + 0 + + 0 + C:\Software\BMSTU-rty\PDF_Reader\build-PDF_Reader-Desktop_Qt_5_12_12_MinGW_64_bit-Debug + C:/Software/BMSTU-rty/PDF_Reader/build-PDF_Reader-Desktop_Qt_5_12_12_MinGW_64_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Отладка + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + C:\Software\BMSTU-rty\PDF_Reader\build-PDF_Reader-Desktop_Qt_5_12_12_MinGW_64_bit-Release + C:/Software/BMSTU-rty/PDF_Reader/build-PDF_Reader-Desktop_Qt_5_12_12_MinGW_64_bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Выпуск + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + C:\Software\BMSTU-rty\PDF_Reader\build-PDF_Reader-Desktop_Qt_5_12_12_MinGW_64_bit-Profile + C:/Software/BMSTU-rty/PDF_Reader/build-PDF_Reader-Desktop_Qt_5_12_12_MinGW_64_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Профилирование + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Развёртывание + Развёртывание + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + Qt4ProjectManager.Qt4RunConfiguration:C:/Software/BMSTU-rty/PDF_Reader/PDF_Reader/PDF_Reader.pro + C:/Software/BMSTU-rty/PDF_Reader/PDF_Reader/PDF_Reader.pro + false + true + true + false + true + C:/Software/BMSTU-rty/PDF_Reader/build-PDF_Reader-Desktop_Qt_5_12_12_MinGW_64_bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b48f94e --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..ffe4499 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,144 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + QMenuBar *menuBar = new QMenuBar(); + m_menuFile = menuBar->addMenu("&File"); + m_openAction = new QAction("&Open"); + m_openAction->setStatusTip(tr("Open a document")); + m_menuFile->addAction(m_openAction); + m_menuFile->addSeparator(); + m_quitAction = new QAction("&Quit"); + m_quitAction->setShortcut(tr("CTRL+Q")); + m_quitAction->setStatusTip(tr("Quit application")); + m_menuFile->addAction(m_quitAction); + + connect(this->m_openAction, &QAction::triggered, this, &MainWindow::slotOpenAction); + connect(this->m_quitAction, &QAction::triggered, qApp, &QApplication::quit); + + this->setMenuBar(menuBar); + show(); +} + +MainWindow::~MainWindow() +{ + delete ui; + +} + +void MainWindow::slotOpenAction() { + m_filename = QFileDialog::getOpenFileName( + this, tr("Выберите файл"), "../", tr("PDF (*.pdf) ;; DOCX (*.docx) ;; XLSX (*.xlsx) ;; PPTX (*.pptx)")); + if (m_filename != "") { + qDebug() << "Close file!\n"; + closeFile(); + + if (m_filename.endsWith(".pdf")) { + openPDF(m_filename); + } else if (m_filename.endsWith(".pptx")) { + openPPTX(m_filename); + } else if (m_filename.endsWith(".docx")) { + openDOCX(m_filename); + } else if (m_filename.endsWith(".xlsx")) { + openXLSX(m_filename); + } + } +} + +void MainWindow::closeFile() { + if (axObj != nullptr) { + QProcess process; + QString strCmd; + strCmd = "taskkill /im winword.exe /f"; + process.execute(strCmd); + strCmd = "taskkill /im EXCEL.exe /f"; + process.execute(strCmd); + strCmd = "taskkill /im POWERPNT.exe /f"; + process.execute(strCmd); + strCmd = "taskkill /im AcroRd32.exe /f"; + process.execute(strCmd); + process.close(); + axObj->close(); + axObj->clear(); + delete axObj; + axObj = nullptr; + } +} + + +void MainWindow::openPDF(QString &filename) { + axObj = new QAxWidget(this); + setCentralWidget(axObj); + if(!axObj->setControl("Adobe PDF Reader")) + QMessageBox::critical(this, "Error", "Make sure you have Adobe Reader (and its ActiveX) installed!"); + axObj->dynamicCall("LoadFile(QString)", filename); +} + +void MainWindow::openPPTX(QString &filename) { + axObj = new QAxWidget("Powerpoint.Application", this); + setCentralWidget(axObj); + if (axObj == nullptr) + { + return; + } + if (!axObj->setControl(filename)) + { + return; + } + axObj->dynamicCall("LoadFile(const QString&)", filename); + axObj->dynamicCall("SetVisible (bool Visible)", "true"); + axObj->setProperty("DisplayAlerts", false); + axObj->setProperty("DisplayScrollBars", true); + axObj->setGeometry(this->geometry()); + axObj->show(); + + /* run slideshow */ + // // Open parameter + // QList param_list; + // param_list.append(filename); + // param_list.append(1); + // param_list.append(1); + // param_list.append(0); + // // Open a template file + // QAxObject *presentations = axObj->querySubObject("Presentations"); + // QAxObject *presentation = presentations->querySubObject("Open(const QString&,int,int,int)", param_list); + // // Start the slides + // QAxObject *slideshow = presentation->querySubObject("SlideShowSettings"); + // slideshow->setProperty("RangeType", "ppShowAll"); + // slideshow->dynamicCall("run()"); + +} + +void MainWindow::openXLSX(QString &filename) { + axObj = new QAxWidget("Excel.Application", this); + setCentralWidget(axObj); + if (axObj == nullptr) + { + return; + } + axObj->dynamicCall("SetVisible (bool Visible)", "false"); + axObj->setProperty("DisplayAlerts", false); + axObj->setProperty("DisplayScrollBars", true); // Show scroll bar + axObj->setGeometry(this->geometry()); + axObj->setControl(filename); + axObj->show(); +} +void MainWindow::openDOCX(QString &filename) { + axObj = new QAxWidget("Word.Application", this); + setCentralWidget(axObj); + if (axObj == nullptr) + { + return; + } + axObj->dynamicCall("SetVisible (bool Visible)", "false"); + axObj->setFocusPolicy(Qt::StrongFocus); + axObj->setProperty("DisplayAlerts", false); + axObj->setProperty("DisplayHorizontalScrollBar", true); // Show scroll bar + axObj->setGeometry(this->geometry()); + axObj->setControl(filename); + axObj->show(); +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..82eda96 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,40 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + + +#include +#include +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private: + Ui::MainWindow *ui; + + QAxWidget *axObj{nullptr}; + QString m_filename; + void openPDF(QString&); + void openPPTX(QString&); + void openXLSX(QString&); + void openDOCX(QString&); + void closeFile(); + QMenuBar *mb{nullptr}; + QMenu *m_menuFile{nullptr}; + QAction *m_openAction{nullptr}; + QAction *m_quitAction{nullptr}; + +private slots: + void slotOpenAction(); +}; + +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..35706ff --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,36 @@ + + + MainWindow + + + + 0 + 0 + 400 + 300 + + + + MainWindow + + + + + + 0 + 0 + 400 + 20 + + + + + + Open + + + + + + +