#include <iostream>
#include <QtGui>
const char stipple_bits[12][8] =
{
{ 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF },
{ 0x0018, 0x0018, 0x0018, 0x00FF, 0x00FF, 0x0018, 0x0018, 0x0018 },
{ 0x0049, 0x0092, 0x0024, 0x0049, 0x0092, 0x0024, 0x0049, 0x0092 },
{ 0x0000, 0x003c, 0x007e, 0x0066, 0x0066, 0x007e, 0x003c, 0x0000 },
{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 },
{ 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055 },
{ 0x0089, 0x0044, 0x0010, 0x0022, 0x0094, 0x0002, 0x0068, 0x0001 },
{ 0x0088, 0x0088, 0x0011, 0x0011, 0x0044, 0x0044, 0x0022, 0x0022 },
{ 0x003c, 0x0042, 0x00a5, 0x00a5, 0x0081, 0x00bd, 0x0042, 0x003c },
{ 0x0038, 0x0038, 0x0038, 0x0092, 0x007c, 0x0010, 0x0028, 0x006c },
{ 0x0054, 0x0029, 0x0084, 0x0029, 0x0080, 0x000c, 0x00a4, 0x0040 },
{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 }
};
{
qreal scalex, scaley;
public:
protected:
};
{
setAutoFillBackground(true);
scalex = 1.0;
scaley = 1.0;
}
{
unsigned int fill_style = 2;
/*! Creating the appropriate pattern*/
patternFillArray.fromRawData(stipple_bits[fill_style],8);
image.loadFromData(patternFillArray);
image.setColor(1,Qt::red);
painter.scale(scalex, scaley);
painter.
setBrush(QBrush(image
));
QRectF rectangle
(0.0,
0.0,
500.0,
500.0);
painter.drawRect(rectangle);
}
switch(event->button()) {
case Qt::LeftButton:
scalex *= .7;
scaley *= .7;
std::cout << "Zoom out" << std::endl;
break;
case Qt::RightButton:
scalex *= 1.2;
scaley *= 1.2;
std::cout << "Zoom in" << std::endl;
break;
}
update();
}
{
public:
};
{
PaintMe *pm = new PaintMe(this);
pm->setGeometry(10, 10, 480, 480);
pm->show();
}
int main(int argc, char *argv[])
{
Window window;
window.setGeometry(100, 100, 500, 500);
window.show();
return app.exec();
}
#include <iostream>
#include <QtGui>
const char stipple_bits[12][8] =
{
{ 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF },
{ 0x0018, 0x0018, 0x0018, 0x00FF, 0x00FF, 0x0018, 0x0018, 0x0018 },
{ 0x0049, 0x0092, 0x0024, 0x0049, 0x0092, 0x0024, 0x0049, 0x0092 },
{ 0x0000, 0x003c, 0x007e, 0x0066, 0x0066, 0x007e, 0x003c, 0x0000 },
{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 },
{ 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055 },
{ 0x0089, 0x0044, 0x0010, 0x0022, 0x0094, 0x0002, 0x0068, 0x0001 },
{ 0x0088, 0x0088, 0x0011, 0x0011, 0x0044, 0x0044, 0x0022, 0x0022 },
{ 0x003c, 0x0042, 0x00a5, 0x00a5, 0x0081, 0x00bd, 0x0042, 0x003c },
{ 0x0038, 0x0038, 0x0038, 0x0092, 0x007c, 0x0010, 0x0028, 0x006c },
{ 0x0054, 0x0029, 0x0084, 0x0029, 0x0080, 0x000c, 0x00a4, 0x0040 },
{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 }
};
class PaintMe : public QWidget
{
qreal scalex, scaley;
public:
PaintMe(QWidget *parent = 0);
void mousePressEvent (QMouseEvent *);
protected:
void paintEvent(QPaintEvent *event);
};
PaintMe::PaintMe(QWidget *parent)
: QWidget(parent)
{
setPalette(QPalette(QColor(250, 250, 200)));
setAutoFillBackground(true);
scalex = 1.0;
scaley = 1.0;
}
void PaintMe::paintEvent(QPaintEvent * /* event */)
{
unsigned int fill_style = 2;
/*! Creating the appropriate pattern*/
QByteArray patternFillArray;
patternFillArray.fromRawData(stipple_bits[fill_style],8);
QImage image(QSize(8,8),QImage::Format_MonoLSB);
image.loadFromData(patternFillArray);
image.setColor(1,Qt::red);
QPainter painter(this);
painter.scale(scalex, scaley);
painter.setBrush(QBrush(image));
QRectF rectangle(0.0, 0.0, 500.0, 500.0);
painter.drawRect(rectangle);
}
void PaintMe::mousePressEvent (QMouseEvent *event) {
switch(event->button()) {
case Qt::LeftButton:
scalex *= .7;
scaley *= .7;
std::cout << "Zoom out" << std::endl;
break;
case Qt::RightButton:
scalex *= 1.2;
scaley *= 1.2;
std::cout << "Zoom in" << std::endl;
break;
}
update();
}
class Window : public QWidget
{
public:
Window(QWidget *parent = 0);
};
Window::Window(QWidget *parent)
: QWidget(parent)
{
PaintMe *pm = new PaintMe(this);
pm->setGeometry(10, 10, 480, 480);
pm->show();
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Window window;
window.setGeometry(100, 100, 500, 500);
window.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks