summaryrefslogtreecommitdiff
path: root/tools/viewsvg/mainwindow.cpp
blob: 10215b83c5e5bd8bbe415ee0efd6a93ebc404bb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <QMessageBox>
#include <QTimer>
#include <QFile>

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    SvgView::init();

    ui->cmbBoxSize->setCurrentIndex(1);
    ui->cmbBoxBackground->setCurrentIndex(1);

    ui->svgView->setFitToView(true);
    ui->svgView->setBackgound(SvgView::Backgound::White);

    connect(ui->svgView, &SvgView::loadError, this, [this](const QString &msg){
        QMessageBox::critical(this, "Error", msg);
    });

    QTimer::singleShot(5, this, &MainWindow::onStart);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::onStart()
{
    ui->svgView->setFocus();

    const auto args = QCoreApplication::arguments();
    if (args.size() != 2) {
        return;
    }

    ui->svgView->loadFile(args.at(1));
}

void MainWindow::on_cmbBoxSize_activated(int index)
{
    ui->svgView->setFitToView(index == 1);
}

void MainWindow::on_cmbBoxBackground_activated(int index)
{
    ui->svgView->setBackgound(SvgView::Backgound(index));
}

void MainWindow::on_chBoxDrawBorder_toggled(bool checked)
{
    ui->svgView->setDrawImageBorder(checked);
}