forked from supertunaman/Hobby-Lobby-Coupon-Downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
84 lines (76 loc) · 2.73 KB
/
mainwindow.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "settingsdialog.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->applyToolbarSettings();
ui->graphicsView->setScene(&scene);
scene.setSceneRect(0, 0, 620, 940); // I pulled these numbers from my ass, justsayin'
connect(ui->horizontalSlider, SIGNAL(sliderMoved(int)), this, SLOT(drawCoupons(int)));
ui->statusBar->showMessage(tr("Grabbing Coupon page..."));
coupon.setUrl(QUrl("http://hobbylobby.com/weekly/coupon.cfm"));
ui->statusBar->showMessage(tr("Click the Get Coupon icon to fetch this week's Hobby Lobby coupon."));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionExit_triggered()
{
qApp->quit();
}
void MainWindow::on_actionGetCoupon_triggered()
{
ui->statusBar->showMessage(tr("Looking for Coupon...")); // I love status bar messages. They're so futuristic!
couponImg.loadFromData(coupon.getCoupon());
ui->statusBar->showMessage(tr("Got the coupon!"));
couponImg = couponImg.scaled(QSize(300, 179)); //This is about 60% the original size. It's pretty tough to read the text at this size
ui->horizontalSlider->setEnabled(true);
ui->actionPrint->setEnabled(true);
drawCoupons(ui->horizontalSlider->value());
}
void MainWindow::drawCoupons(int count)
{
scene.clear();
ui->graphicsView->show(); // had some weird issues earlier where the view wouldn't clear all the way.
coupon.drawCouponPage(&scene, couponImg, count);
ui->graphicsView->show();
}
void MainWindow::on_actionPrint_triggered()
{
QGraphicsScene printScene;
QPixmap img;
QPrinter printer;
QPrintDialog *dialog = new QPrintDialog(&printer, this);
dialog->setWindowTitle("Print Coupons");
if (dialog->exec() != QDialog::Accepted)
return;
QPainter painter(&printer);
printScene.setSceneRect(0, 0, 920, 1400);
img.loadFromData(coupon.couponFile);
coupon.drawCouponPage(&printScene, img, ui->horizontalSlider->value());
printScene.render(&painter);
ui->statusBar->showMessage("Coupon page sent to printer.");
}
void MainWindow::on_actionSettings_triggered()
{
SettingsDialog dialog(this);
dialog.exec();
this->applyToolbarSettings();
}
void MainWindow::applyToolbarSettings()
{
QSettings settings;
QString tba = settings.value("toolbar/area").toString();
if (tba == "top")
this->addToolBar(Qt::TopToolBarArea, ui->mainToolBar);
else if (tba == "right")
this->addToolBar(Qt::RightToolBarArea, ui->mainToolBar);
else if (tba == "bottom")
this->addToolBar(Qt::BottomToolBarArea, ui->mainToolBar);
else
this->addToolBar(Qt::LeftToolBarArea, ui->mainToolBar);
}