1/* Copyright (C) 1997 Mathias Mueller <in5y158@public.uni-hamburg.de>
2 * Copyright (C) 2006 Mauricio Piacentini <mauricio@tabuleiro.com>
3 *
4 * Kmahjongg is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
17
18#include "FrameImage.h"
19#include "prefs.h"
20
21#include <qevent.h>
22#include <qimage.h>
23#include <qpainter.h>
24#include <qtextstream.h>
25
26#include <kcomponentdata.h>
27#include <kfiledialog.h>
28#include <klocale.h>
29#include <kmessagebox.h>
30#include <kpushbutton.h>
31#include <kstandarddirs.h>
32#include <KStandardGuiItem>
33#include <kimageio.h>
34#include <kvbox.h>
35
36
37FrameImage::FrameImage(QWidget *parent, const QSize &initialImageSize)
38 : KGameCanvasWidget(parent)
39{
40 rx = -1;
41 thePixmap = new QPixmap(initialImageSize);
42}
43
44FrameImage::~FrameImage()
45{
46 delete thePixmap;
47}
48
49void FrameImage::resizeEvent(QResizeEvent *ev)
50{
51 *thePixmap = QPixmap(ev->size());
52}
53
54void FrameImage::paintEvent(QPaintEvent *pa)
55{
56 //QFrame::paintEvent(pa);
57
58 QPainter p(this);
59
60 QPen line;
61// line.setStyle(Qt::DotLine);
62 line.setWidth(1);
63 line.setColor(Qt::red);
64 p.setPen(line);
65 p.setBackgroundMode(Qt::OpaqueMode);
66 p.setBackground(Qt::black);
67
68 int x = pa->rect().left();
69 int y = pa->rect().top();
70 int h = pa->rect().height();
71 int w = pa->rect().width();
72
73// p.drawPixmap(x+frameWidth(),y+frameWidth(),*thePixmap,x+frameWidth(),y+frameWidth(),w-(2*frameWidth()),h-(2*frameWidth()));
74 p.drawPixmap(x, y, *thePixmap, x, y, w - 2, h - 2);
75 if (rx >=0) {
76 p.drawRect(rx + rs, ry, rw - rs, rh - rs);
77 p.drawLine(rx, ry + rs, rx, ry + rh);
78 p.drawLine(rx, ry + rs, rx + rs, ry);
79 p.drawLine(rx, ry + rh, rx + rs, ry + rh - rs);
80 p.drawLine(rx, ry + rh, rx + rw - rs, ry + rh);
81 p.drawLine(rx + rw - rs, ry + rh, rx + rw, ry + rh - rs);
82
83 int midX = rx + rs + ((rw - rs) / 2);
84 int midY = ry + ((rh - rs) / 2);
85 switch (rt) {
86 case 0: // delete mode cursor
87 p.drawLine(rx + rs, ry, rx + rw, ry + rh - rs);
88 p.drawLine(rx + rw, ry, rx + rs, ry + rh - rs);
89
90 break;
91 case 1: // insert cursor
92 p.drawLine(midX, ry, midX, ry + rh - rs);
93 p.drawLine(rx + rs, midY, rx + rw, midY);
94
95 break;
96 case 2: // move mode cursor
97 p.drawLine(midX, ry, rx + rw, midY);
98 p.drawLine(rx + rw, midY, midX, ry + rh - rs);
99 p.drawLine(midX, ry + rh - rs, rx + rs, midY);
100 p.drawLine(rx + rs, midY, midX, ry);
101
102 break;
103 }
104 }
105}
106
107void FrameImage::setRect(int x, int y, int w, int h, int s, int t)
108{
109 rx = x;
110 ry = y;
111 rw = w;
112 rh = h;
113 rt = t;
114 rs = s;
115}
116
117void FrameImage::mousePressEvent(QMouseEvent *m)
118{
119 emit mousePressed(m);
120}
121
122void FrameImage::mouseMoveEvent(QMouseEvent *e)
123{
124 emit mouseMoved(e);
125}
126
127
128#include "FrameImage.moc"
129