~keith-penguin/kdegames/trunk

« back to all changes in this revision

Viewing changes to kmahjongg/FrameImage.cpp

  • Committer: Keith Worrell
  • Date: 2009-03-18 05:35:28 UTC
  • Revision ID: keith.worrell@gmail.com-20090318053528-mx6x9c0ngmg0kg6p
imported project

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 1997 Mathias Mueller   <in5y158@public.uni-hamburg.de>
 
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
 
 
19
#include "FrameImage.h"
 
20
 
 
21
#include <kcomponentdata.h>
 
22
#include <kfiledialog.h>
 
23
#include <klocale.h>
 
24
#include <kmessagebox.h>
 
25
#include <kpushbutton.h>
 
26
#include <kstandarddirs.h>
 
27
#include <KStandardGuiItem>
 
28
#include <kimageio.h>
 
29
 
 
30
#include <qevent.h>
 
31
#include <qimage.h>
 
32
#include <qpainter.h>
 
33
#include <qtextstream.h>
 
34
#include <kvbox.h>
 
35
 
 
36
 
 
37
#include "prefs.h"
 
38
 
 
39
FrameImage::FrameImage (QWidget *parent, const QSize& initialImageSize)
 
40
  : KGameCanvasWidget(parent)
 
41
{
 
42
        rx = -1;
 
43
        thePixmap = new QPixmap(initialImageSize);
 
44
}
 
45
 
 
46
FrameImage::~FrameImage()
 
47
{
 
48
        delete thePixmap;
 
49
}
 
50
 
 
51
void FrameImage::resizeEvent( QResizeEvent* ev )
 
52
{
 
53
    *thePixmap = QPixmap(ev->size());
 
54
}
 
55
 
 
56
void FrameImage::paintEvent( QPaintEvent* pa )
 
57
{
 
58
    //QFrame::paintEvent(pa);
 
59
 
 
60
    QPainter p(this);
 
61
 
 
62
 
 
63
    QPen line;
 
64
    line.setStyle(Qt::DotLine);
 
65
    line.setWidth(2);
 
66
    line.setColor(Qt::yellow);
 
67
    p.setPen(line);
 
68
    p.setBackgroundMode(Qt::OpaqueMode);
 
69
    p.setBackground(Qt::black);
 
70
 
 
71
    int x = pa->rect().left();
 
72
    int y = pa->rect().top();
 
73
    int h = pa->rect().height();
 
74
    int w  = pa->rect().width();
 
75
 
 
76
    //p.drawPixmap(x+frameWidth(),y+frameWidth(),*thePixmap,x+frameWidth(),y+frameWidth(),w-(2*frameWidth()),h-(2*frameWidth()));
 
77
p.drawPixmap(x,y,*thePixmap,x,y,w-(2),h-(2));
 
78
    if (rx >=0) {
 
79
 
 
80
        p.drawRect(rx, ry, rw, rh);
 
81
        p.drawRect(rx+rs, ry, rw-rs, rh-rs);
 
82
        p.drawLine(rx, ry+rh, rx+rs, ry+rh-rs);
 
83
 
 
84
        int midX = rx+rs+((rw-rs)/2);
 
85
        int midY = ry+((rh-rs)/2);
 
86
        switch (rt) {
 
87
                case 0:  // delete mode cursor
 
88
                        p.drawLine(rx+rs, ry, rx+rw, ry+rh-rs);
 
89
                        p.drawLine(rx+rw, ry, rx+rs, ry+rh-rs);
 
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
                break;
 
95
                case 2: // move mode cursor
 
96
                        p.drawLine(midX, ry, rx+rw, midY);
 
97
                        p.drawLine(rx+rw, midY, midX, ry+rh-rs);
 
98
                        p.drawLine(midX, ry+rh-rs, rx+rs, midY);
 
99
                        p.drawLine(rx+rs, midY, midX, ry);
 
100
 
 
101
                break;
 
102
        }
 
103
 
 
104
    }
 
105
}
 
106
 
 
107
void 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
 
 
117
// Pass on the mouse presed event to our owner
 
118
 
 
119
void FrameImage::mousePressEvent(QMouseEvent *m) {
 
120
        emit mousePressed(m);
 
121
}
 
122
 
 
123
void FrameImage::mouseMoveEvent(QMouseEvent *e) {
 
124
        emit mouseMoved(e);
 
125
}
 
126
 
 
127
#include "FrameImage.moc"