2016-04-02 03:39:45 +03:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "ui_mainwindow.h"
|
2024-09-04 17:31:16 +03:00
|
|
|
|
2016-04-02 03:39:45 +03:00
|
|
|
#include <QDebug>
|
2024-09-04 17:31:16 +03:00
|
|
|
#include <QDir>
|
|
|
|
#include <QSqlDatabase>
|
2021-12-16 00:13:39 +03:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
2016-04-02 03:39:45 +03:00
|
|
|
#include <QDesktopWidget>
|
2021-08-23 08:07:08 +03:00
|
|
|
#else
|
|
|
|
#include <QScreen>
|
|
|
|
#endif
|
2016-04-02 03:39:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
MainWindow::MainWindow(QWidget* parent): QMainWindow(parent), ui(new Ui::MainWindow)
|
2016-04-02 03:39:45 +03:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2016-05-24 00:32:21 +03:00
|
|
|
|
2016-04-02 03:39:45 +03:00
|
|
|
m_preview = m_report.createPreviewWidget();
|
2016-05-24 00:32:21 +03:00
|
|
|
m_scalePercent = new QComboBox(this);
|
|
|
|
m_pageNavigator = new QSpinBox(this);
|
|
|
|
|
|
|
|
m_pageNavigator->setPrefix(tr("Page :"));
|
2024-09-04 17:31:16 +03:00
|
|
|
ui->toolBar->insertWidget(ui->actionZoom_Out, m_scalePercent);
|
|
|
|
ui->toolBar->insertWidget(ui->actionNext_Page, m_pageNavigator);
|
|
|
|
connect(m_scalePercent, SIGNAL(currentIndexChanged(QString)), this,
|
|
|
|
SLOT(scaleComboboxChanged(QString)));
|
2016-05-24 00:32:21 +03:00
|
|
|
connect(m_pageNavigator, SIGNAL(valueChanged(int)), this, SLOT(slotPageNavigatorChanged(int)));
|
2016-04-02 03:39:45 +03:00
|
|
|
ui->groupBox_2->layout()->addWidget(m_preview);
|
2024-09-04 17:31:16 +03:00
|
|
|
buildReportsTree(QApplication::applicationDirPath() + "/demo_reports/", ui->treeWidget);
|
2016-05-24 00:32:21 +03:00
|
|
|
connect(ui->actionZoomIn, SIGNAL(triggered()), m_preview, SLOT(zoomIn()));
|
|
|
|
connect(ui->actionZoom_Out, SIGNAL(triggered()), m_preview, SLOT(zoomOut()));
|
|
|
|
connect(ui->actionFirst_Page, SIGNAL(triggered()), m_preview, SLOT(firstPage()));
|
|
|
|
connect(ui->actionPrior_Page, SIGNAL(triggered()), m_preview, SLOT(priorPage()));
|
|
|
|
connect(ui->actionNext_Page, SIGNAL(triggered()), m_preview, SLOT(nextPage()));
|
|
|
|
connect(ui->actionLast_Page, SIGNAL(triggered()), m_preview, SLOT(lastPage()));
|
2024-09-04 17:31:16 +03:00
|
|
|
connect(m_preview, SIGNAL(scalePercentChanged(int)), this, SLOT(slotScalePercentChanged(int)));
|
|
|
|
// connect(ui->cbScalePercent, SIGNAL(currentIndexChanged(QString)), this,
|
|
|
|
// SLOT(scaleComboboxChanged(QString)));
|
2016-05-24 00:32:21 +03:00
|
|
|
connect(ui->actionFit_Width, SIGNAL(triggered()), m_preview, SLOT(fitWidth()));
|
|
|
|
connect(ui->actionFit_Page, SIGNAL(triggered()), m_preview, SLOT(fitPage()));
|
2016-04-02 03:39:45 +03:00
|
|
|
connect(m_preview, SIGNAL(pagesSet(int)), this, SLOT(slotPagesSet(int)));
|
|
|
|
connect(m_preview, SIGNAL(pageChanged(int)), this, SLOT(slotPageChanged(int)));
|
2016-05-24 00:32:21 +03:00
|
|
|
connect(ui->actionExport_to_PDF, SIGNAL(triggered()), m_preview, SLOT(printToPDF()));
|
|
|
|
connect(ui->actionPrint_Report, SIGNAL(triggered()), m_preview, SLOT(print()));
|
|
|
|
connect(ui->actionDesign_Report, SIGNAL(triggered()), this, SLOT(slotDesignReport()));
|
2016-05-24 00:39:56 +03:00
|
|
|
connect(ui->actionOne_to_One, SIGNAL(triggered()), this, SLOT(slotOneToOne()));
|
2016-04-02 03:39:45 +03:00
|
|
|
initPercentCombobox();
|
|
|
|
enableUI(false);
|
2021-12-16 00:13:39 +03:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
2024-09-04 17:31:16 +03:00
|
|
|
QDesktopWidget* desktop = QApplication::desktop();
|
2016-04-02 03:39:45 +03:00
|
|
|
|
|
|
|
int screenWidth = desktop->screenGeometry().width();
|
|
|
|
int screenHeight = desktop->screenGeometry().height();
|
2021-08-23 08:07:08 +03:00
|
|
|
#else
|
2024-09-04 17:31:16 +03:00
|
|
|
QScreen* screen = QGuiApplication::primaryScreen();
|
2021-08-23 08:07:08 +03:00
|
|
|
|
|
|
|
int screenWidth = screen->geometry().width();
|
|
|
|
int screenHeight = screen->geometry().height();
|
|
|
|
#endif
|
2016-04-02 03:39:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
int x = screenWidth * 0.1;
|
|
|
|
int y = screenHeight * 0.1;
|
2016-04-02 03:39:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
resize(screenWidth * 0.8, screenHeight * 0.8);
|
2016-04-02 03:39:45 +03:00
|
|
|
move(x, y);
|
2017-03-03 02:23:23 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (ui->treeWidget->topLevelItemCount() > 0) {
|
2017-03-03 02:23:23 +03:00
|
|
|
int index = 0;
|
2024-09-04 17:31:16 +03:00
|
|
|
while (index < ui->treeWidget->topLevelItemCount()) {
|
|
|
|
if (ui->treeWidget->topLevelItem(index)->childCount() > 0)
|
2017-03-03 02:23:23 +03:00
|
|
|
++index;
|
|
|
|
else {
|
2024-09-04 17:31:16 +03:00
|
|
|
m_report.loadFromFile(
|
|
|
|
ui->treeWidget->topLevelItem(index)->data(0, Qt::UserRole).toString());
|
2017-03-03 02:23:23 +03:00
|
|
|
ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(index));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-04-02 03:39:45 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
m_preview->refreshPages();
|
2016-04-02 03:39:45 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
MainWindow::~MainWindow() { delete ui; }
|
2016-04-02 03:39:45 +03:00
|
|
|
|
|
|
|
void MainWindow::enableUI(bool value)
|
|
|
|
{
|
2016-05-24 00:32:21 +03:00
|
|
|
ui->actionDesign_Report->setEnabled(value);
|
|
|
|
ui->actionPrint_Report->setEnabled(value);
|
|
|
|
ui->actionExport_to_PDF->setEnabled(value);
|
|
|
|
ui->actionFirst_Page->setEnabled(value);
|
|
|
|
ui->actionPrior_Page->setEnabled(value);
|
|
|
|
ui->actionNext_Page->setEnabled(value);
|
|
|
|
ui->actionLast_Page->setEnabled(value);
|
|
|
|
ui->actionZoomIn->setEnabled(value);
|
|
|
|
ui->actionZoom_Out->setEnabled(value);
|
|
|
|
ui->actionFit_Width->setEnabled(value);
|
|
|
|
ui->actionFit_Page->setEnabled(value);
|
|
|
|
ui->actionOne_to_One->setEnabled(value);
|
|
|
|
m_pageNavigator->setEnabled(value);
|
|
|
|
m_scalePercent->setEnabled(value);
|
2016-04-02 03:39:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::slotScalePercentChanged(int percent)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
// ui->cbScalePercent->setEditText(QString("%1%").arg(percent));
|
2016-05-24 00:32:21 +03:00
|
|
|
m_scalePercent->setEditText(QString("%1%").arg(percent));
|
2016-04-02 03:39:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::scaleComboboxChanged(QString text)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
m_preview->setScalePercent(text.remove(text.count() - 1, 1).toInt());
|
2016-04-02 03:39:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::slotPagesSet(int pagesCount)
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
// ui->sbPageNavigator->setSuffix(tr(" of %1").arg(pagesCount));
|
|
|
|
// ui->sbPageNavigator->setMinimum(1);
|
|
|
|
// ui->sbPageNavigator->setMaximum(pagesCount);
|
|
|
|
// ui->sbPageNavigator->setValue(1);
|
2016-05-24 00:32:21 +03:00
|
|
|
|
|
|
|
m_pageNavigator->setSuffix(tr(" of %1").arg(pagesCount));
|
|
|
|
m_pageNavigator->setMinimum(1);
|
|
|
|
m_pageNavigator->setMaximum(pagesCount);
|
|
|
|
m_pageNavigator->setValue(1);
|
2016-04-02 03:39:45 +03:00
|
|
|
enableUI(true);
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void MainWindow::slotPageChanged(int page) { m_pageNavigator->setValue(page); }
|
2016-05-24 00:32:21 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void MainWindow::slotPageNavigatorChanged(int page) { m_preview->pageNavigatorChanged(page); }
|
2016-04-02 03:39:45 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem* item, int)
|
2016-04-02 03:39:45 +03:00
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!m_report.isBusy()) {
|
|
|
|
m_report.loadFromFile(item->data(0, Qt::UserRole).toString());
|
2016-12-13 12:47:46 +03:00
|
|
|
m_preview->refreshPages();
|
|
|
|
}
|
2016-04-02 03:39:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::initPercentCombobox()
|
|
|
|
{
|
2024-09-04 17:31:16 +03:00
|
|
|
for (int i = 10; i < 310; i += 10) {
|
|
|
|
// ui->cbScalePercent->addItem(QString("%1%").arg(i));
|
2016-05-24 00:32:21 +03:00
|
|
|
m_scalePercent->addItem(QString("%1%").arg(i));
|
2016-04-02 03:39:45 +03:00
|
|
|
}
|
2024-09-04 17:31:16 +03:00
|
|
|
// ui->cbScalePercent->setCurrentIndex(4);
|
2016-05-24 00:32:21 +03:00
|
|
|
m_scalePercent->setCurrentIndex(4);
|
2016-04-02 03:39:45 +03:00
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
// void MainWindow::on_sbPageNavigator_valueChanged(int arg1)
|
2016-05-24 00:39:56 +03:00
|
|
|
//{
|
|
|
|
// m_preview->pageNavigatorChanged(arg1);
|
|
|
|
//}
|
2016-04-02 03:39:45 +03:00
|
|
|
|
2016-05-24 00:32:21 +03:00
|
|
|
void MainWindow::slotDesignReport()
|
2016-04-02 03:39:45 +03:00
|
|
|
{
|
|
|
|
m_report.designReport();
|
|
|
|
m_preview->refreshPages();
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
void MainWindow::slotOneToOne() { m_preview->setScalePercent(100); }
|