Commit 9aad3e66 authored by slopez's avatar slopez

initial import

parents
Simon Lopez <simon DOT lopez AT ayolo DOT org>
TEMPLATE = app
QT = gui core
win32 {
DEFINES += QT_DLL
CONFIG += release dll app_bundle qt windows
TEMPLATE = app
DEPENDPATH += . build src ui
RC_FILE = win.rc
}
macx {
}
!win32 {
CONFIG += qt release warn_on console
}
DESTDIR = bin
OBJECTS_DIR = build
MOC_DIR = build
UI_DIR = build
FORMS = ui/mainwindow.ui
HEADERS = src/ventetickets.h
SOURCES = src/ventetickets.cpp src/main.cpp
REQUIREMENTS
QT4.4 or higher
BUILDING
qmake-qt4
make
#include <QApplication>
#include "ventetickets.h"
//
QString AppVersion("0.1");
int main(int argc, char ** argv)
{
QApplication app( argc, argv );
VenteTickets win;
win.show();
app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
return app.exec();
}
#include "ventetickets.h"
#include <QPrinterInfo>
#include <QPrinter>
#include <QMessageBox>
#include <QPainter>
#include <QPoint>
#include <QInputDialog>
#include <QFileDialog>
/**
* Constructor
* set some defaults setings
*/
VenteTickets::VenteTickets( QWidget * parent, Qt::WFlags f)
: QMainWindow(parent, f)
{
setWindowTitle("Vente de tickets");
setupUi(this);
EventName="";
/* printer */
//if we can't find the default printer, we choose one
if(!SetPrinterInfo("TSP100"))
SelectPrinter(true);
//default background image
ticketImg=QImage("ticketAE.png");
// if we can't load the default ticket background, we choose one
if (ticketImg.isNull())
Load_image(true);
else
ticketImg=ticketImg.scaledToWidth(Printer.pageRect().width()/2,
Qt::SmoothTransformation);
/* Connect signals */
SigConnect();
}
/**
* Signal connections
*/
void VenteTickets::SigConnect()
{
connect(actionTickets,SIGNAL(activated()),this,SLOT(Load_image()));
connect(actionEventName,SIGNAL(activated()),this,SLOT(SetEventName()));
connect(actionA_propos,SIGNAL(activated()),this,SLOT(About()));
connect(actionImprimante,SIGNAL(activated()),this,SLOT(SelectPrinter()));
connect(vente10, SIGNAL( released() ), this, SLOT(Print10()));
connect(vente20, SIGNAL( released() ), this, SLOT(Print20()));
}
/**
* Load event name
*/
void VenteTickets::SetEventName()
{
EventName = QInputDialog::getText(this,
QString::fromUtf8("Nom de l'évennement"),
QString::fromUtf8("Nom :"),
QLineEdit::Normal,
EventName);
}
/**
* Load ticket's image
* @param force force image selection
*/
void VenteTickets::Load_image(bool force)
{
QString fileName;
while(fileName.isEmpty() && force)
{
fileName = QFileDialog::getOpenFileName(0,
"Open File",
QDir::currentPath(),
"All images (*.png *.jpg)");
if (!fileName.isEmpty())
{
QImage image(fileName);
if (image.isNull())
{
QMessageBox::information(0,
"Erreur",
"Impossible de charger le fichier");
}
else
{
ticketImg=image.scaledToWidth(Printer.pageRect().width()/2,
Qt::SmoothTransformation);
}
}
}
return;
}
void VenteTickets::Load_image()
{
Load_image(true);
}
/**
* SelectPrinter
* @param force force printer selection
*/
void VenteTickets::SelectPrinter(bool force)
{
QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters();
QStringList sprinters;
for (int c = 0; c < printers.size(); ++c)
sprinters << printers[c].printerName();
printers.clear();
bool set = SetPrinterInfo(QInputDialog::getItem(this,
QString::fromUtf8("Imprimante"),
QString::fromUtf8("Imprimante :"),
sprinters,
0,
false));
while(!set && force)
{
set = SetPrinterInfo(QInputDialog::getItem(this,
QString::fromUtf8("Imprimante"),
QString::fromUtf8("Imprimante :"),
sprinters,
0,
false));
}
}
void VenteTickets::SelectPrinter()
{
SelectPrinter(false);
}
/**
* About box
*/
void VenteTickets::About()
{
QString about = "<h3>Vente de tickets :<h3>";
about += QString::fromUtf8("<h4>Développeur(s) :</h4>");
about += "<ul>";
about += "<li> Simon Lopez";
about += "</ul>";
about += QString::fromUtf8("<h4>Basé sur </h4>");
about += "Qt ";
about += QT_VERSION_STR;
static QMessageBox* mbox = new QMessageBox (QMessageBox::Information,
QString::fromUtf8("À propos"),
about);
mbox->setButtonText ( 1, "OK" );
mbox->show();
}
/**
* Set printer name
* @param name name of the printer
*/
bool VenteTickets::SetPrinterInfo(QString name)
{
QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters();
for (int c = 0; c < printers.size(); ++c)
{
if (printers[c].printerName()==name
|| printers[c].printerName().indexOf(name,1)!=-1)
{
Printer.setPrinterName(printers[c].printerName());
Printer.setColorMode(QPrinter::GrayScale);
Printer.setPageMargins(0,0,0,0,QPrinter::Millimeter);
#ifdef Q_WS_WIN
Printer.setPaperSize(QSizeF(70,2000),QPrinter::Millimeter);
#else
Printer.setPaperSize(QPrinter::A4);
Printer.setPaperSize(QSize(Printer.paperSize(QPrinter::Millimeter).width()
,2000)
,QPrinter::Millimeter);
#endif
printers.clear();
return true;
}
}
printers.clear();
return false;
}
/**
* Print 10 tickets
*/
void VenteTickets::Print10()
{
lcd10tik->display(lcd10tik->intValue()+1);
Print(10);
}
/**
* Print 20 tickets
*/
void VenteTickets::Print20()
{
lcd20tik->display(lcd20tik->intValue()+1);
Print(20);
}
/**
* Print tickets
* @param nb number of tickets to print
*/
void VenteTickets::Print(int nb)
{
QPainter Painter(&Printer);
int header=0;
Painter.setPen(Qt::blue);
#ifdef Q_WS_WIN
Painter.setFont(QFont("Arial", 15, 1));
#else
Painter.setFont(QFont("Arial", 50, 1));
#endif
Painter.setViewport(Printer.pageRect ());
if(EventName!="")
{
#ifdef Q_WS_WIN
header=30;
Painter.drawText(QRect(0,
0,
Printer.pageRect().width(),
20),
Qt::AlignCenter,
EventName);
#else
header=100;
Painter.drawText(QRect(0,
0,
Printer.pageRect().width(),
50),
Qt::AlignCenter,
EventName);
#endif
}
for(int i=0;i<(nb/2);i++)
{
Painter.drawImage(QPoint(0,i*ticketImg.height()+header),
ticketImg);
Painter.drawRect(0,
i*ticketImg.height()+header,
ticketImg.width(),
ticketImg.height());
Painter.drawImage(QPoint(ticketImg.width(),i*ticketImg.height()+header),
ticketImg);
Painter.drawRect(ticketImg.width(),
i*ticketImg.height()+header,
ticketImg.width(),
ticketImg.height());
}
Painter.end();
}
#ifndef VENTETICKETS_H
#define VENTETICKETS_H
#include <QMainWindow>
#include <QString>
#include <QPrinter>
#include "ui_mainwindow.h"
class VenteTickets : public QMainWindow, public Ui::MainWindow
{
Q_OBJECT
public:
VenteTickets( QWidget * parent = 0, Qt::WFlags f = 0 );
private:
QString EventName;
QPrinter Printer;
QImage ticketImg;
void SigConnect();
bool SetPrinterInfo(QString name);
void Print(int nb);
void Load_image(bool force);
void SelectPrinter(bool force);
private slots:
void SetEventName();
void About();
void Load_image();
void SelectPrinter();
void Print10();
void Print20();
};
#endif
This diff is collapsed.
IDI_ICON1 ICON "icons/ae.ico"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment