Main.cpp#include <qapplication.h>
#include <qwidget.h>
#include <qpixmap.h>
#include <qpushbutton.h>
#include <qfiledialog.h>
#include <qstring.h>
#include <qimage.h>
#include <qpainter.h>
#include "Openf.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QWidget frame(0,"",Qt::WStyle_StaysOnTop);
QString file_name;
Openf widg(&file_name);
QPushButton *button = new QPushButton("Full screen", &frame, 0);
QPushButton *button1 = new QPushButton("Normal screen", &frame, 0);
QPushButton *quit_prg = new QPushButton("Quit", &frame, 0);
QPushButton *open_im = new QPushButton("Open", &frame, 0);
widg.setUpdatesEnabled( TRUE );
widg.show();
frame.setCaption("Convert");
QObject::connect(button, SIGNAL(clicked()), &widg, SLOT(showFullScreen()));
QObject::connect(button, SIGNAL(clicked()), &widg, SLOT(setSizePict()));
QObject::connect(button1, SIGNAL(clicked()), &widg, SLOT(showNormal()));
QObject::connect(quit_prg, SIGNAL(clicked()), &app, SLOT(quit()));
QObject::connect(open_im, SIGNAL(clicked()), &widg, SLOT(drawPict()));
QObject::connect(open_im, SIGNAL(clicked()), &widg, SLOT(out()));
button1->move(button->x()+button1->width(), button->y());
open_im->move(button1->x()+open_im->width(), button1->y());
quit_prg->move(open_im->x()+quit_prg->width(), button1->y());
frame.setFixedSize(quit_prg->x()+quit_prg->width(), button->y()+button->height());
frame.show();
app.setMainWidget(&frame);
return app.exec();
}
Openf.h#ifndef _openf_h_
#define _openf_h_
#include <qwidget.h>
#include <qstring.h>
#include <qpainter.h>
#include <qimage.h>
#include <qpushbutton.h>
//---------------------------------------------------------------------------------------------
class Openf: public QWidget
{
Q_OBJECT
public:
QString *d;
QPainter *draw;
QImage *pict;
QImage *pict_draw;
Openf::Openf():QWidget()
{
draw = new QPainter(this);
pict = new QImage();
pict_draw = new QImage();
};
Openf(QWidget* parent, const char* name);
Openf(QString *p):QWidget()
{
d = p;
draw = new QPainter(this);
pict = new QImage();
};
QString retName() const
{
return s;
};
private:
QString s;
protected:
virtual void paintEvent(QPaintEvent *pe);
virtual void resizeEvent(QResizeEvent *re);
public slots:
void drawPict();
void getPictName();
void setSizePict();
void out();
};
#endif//
Openf.cpp
#include "qfiledialog.h"
#include "iostream.h"
#include "Openf.h"
Openf::Openf(QWidget* parent, const char* name)
:QWidget(parent,name)
{
draw = new QPainter(this);
pict = new QImage();
pict_draw = new QImage();
}
void Openf::getPictName()
{
*d = QFileDialog::getOpenFileName();
}
void Openf::drawPict()
{
getPictName();
pict->load(*d);
this->resize(pict->size());
draw->drawImage(0, 0, *pict);
this->show();
}
void Openf::out()
{
using namespace std;
cout << *d << endl;
}
void Openf::paintEvent(QPaintEvent *pe)
{
using namespace std;
{
cout << this->width() << "\t" << this->height() << "\t" << this->isFullScreen() <<endl;
};
if (!d->isEmpty())
{
draw->drawImage(0, 0, *pict);
};
}
void Openf::resizeEvent(QResizeEvent *re)
{
if (!d->isEmpty())
{
*pict = pict->smoothScale(this->size(),QImage::ScaleMin);
draw->drawImage(0, 0, *pict);
pict->reset();
pict->load(*d);
};
}
void Openf::setSizePict()
{
if (!d->isEmpty())
{
*pict = pict->smoothScale(this->size(),QImage::ScaleMin);
draw->drawImage(0, 0, *pict);
pict->reset();
pict->load(*d);
};
}