summaryrefslogtreecommitdiffstats
path: root/k9author/k9menubutton.cpp
blob: 73908e98ff01976097e8434cfbb56b8d6c3b0161 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
//
// C++ Implementation: k9menubutton
//
// Description: 
//
//
// Author: Jean-Michel PETIT <k9copy@free.fr>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "k9menubutton.h"
#include <qpainter.h>
#include <qwmatrix.h>
#include <qbitmap.h>

k9CanvasSprite::k9CanvasSprite (QCanvasPixmapArray *a,QCanvas *canvas,k9MenuButton *button) : QCanvasSprite(a,canvas) {
    m_button=button;
}

void k9CanvasSprite::update() {
    m_button->update();
}


k9MenuButton* k9CanvasSprite::getButton() const {
    return m_button;
}

void k9MenuButton::select(bool _value) {
  /*  if (_value) {
        m_lt->show();
        m_mt->show();
        m_rt->show();
        m_lm->show();
        m_rm->show();
        m_lb->show();
        m_mb->show();
        m_rb->show();
    } else {
        m_lt->hide();
        m_mt->hide();
        m_rt->hide();
        m_lm->hide();
        m_rm->hide();
        m_lb->hide();
        m_mb->hide();
        m_rb->hide();
    }*/
}

void k9MenuButton::update() {
    int x=m_sprite->x()-5;
    int y=m_sprite->y()-5;
    int w=m_width;
    int h=m_height;

    int count=m_canvas->allItems().count();
/*
    m_lt->move(x,y);
    m_lt->setZ(count--);

    m_mt->move(x+w/2,y);
    m_mt->setZ(count--);

    m_rt->move(x+w,y);
    m_rt->setZ(count--);

    m_lm->move(x,y+h/2);
    m_lm->setZ(count--);

    m_rm->move(x+w,y+h/2);
    m_rm->setZ(count--);

    m_lb->move(x,y+h);
    m_lb->setZ(count--);

    m_mb->move(x+w/2,y+h);
    m_mb->setZ(count--);

    m_rb->move(x+w,y+h);
    m_rb->setZ(count--);
*/
    switch(m_textPosition) {
        case RIGHT:
            m_text->move(x+2+w,y+2+h/2-m_text->boundingRect().height()/2);
            break;
        case BOTTOM:
            m_text->move(x+2+w/2 - m_text->boundingRect().width()/2,y+2+h);
            break;
    }
    m_text->show();
    m_text->setZ(count --);

    m_sprite->setZ(count--);
    emit sigsetLeft(getLeft());
    emit sigsetTop(getTop());
    emit sigsetWidth(getWidth());
    emit sigsetHeight(getHeight());
}

k9MenuButton::k9MenuButton(QCanvas *parent, const char *name)
 : QObject(parent, name),m_width(0),m_height(0)
{
    m_canvas=parent;
    m_sprite=NULL;
    m_pixmap=NULL;
    m_text=new QCanvasText("",m_canvas);
    m_text->setColor(Qt::yellow);

}


k9MenuButton::~k9MenuButton()
{
}

void k9MenuButton::setImage(const QImage &_image) {
    m_image=_image;
    emit sigsetImage(this,_image);
    loadImage();

}

void k9MenuButton::setImage(const QString &_fileName){
    m_image.load(_fileName);
    emit sigsetImage(this,m_image);
    loadImage();
}

void k9MenuButton::loadImage() {
    QImage tmp=m_image.smoothScale(m_width,m_height);
    int x=0,y=0;
    if (m_sprite) {
        x=m_sprite->x();
        y=m_sprite->y();
        delete m_sprite;
    } 
    QPixmap pix;
    pix.convertFromImage(tmp);
    
    m_pixmap=new QCanvasPixmap(pix,QPoint(0,0));


    m_pixmapArray.setImage(0,m_pixmap);
    m_sprite = new k9CanvasSprite(&m_pixmapArray,m_canvas,this);
    m_sprite->move(x,y);
    m_sprite->show();
    update();
    m_canvas->update();
}

void k9MenuButton::setWidth(int _value,bool _reload) {
    m_width=_value;
    emit sigsetWidth(_value);
    if (_reload)
        loadImage();
}

int k9MenuButton::getWidth() {
    return m_width;
}

void k9MenuButton::setHeight(int _value,bool _reload) {
    m_height=_value;
    emit sigsetHeight(_value);
    if (_reload)
        loadImage();
}

int k9MenuButton::getHeight() {
    return m_height;
}

void k9MenuButton::setTop(int _value,bool _reload) {
    m_sprite->setY(_value);
    emit sigsetTop(_value);
    if (_reload)
        loadImage();
}

void k9MenuButton::setLeft(int _value,bool _reload) {
    m_sprite->setX(_value);
    emit sigsetLeft(_value);
    if (_reload)
        loadImage();
}

int k9MenuButton::getTop() {
    return m_sprite->y();
}

int k9MenuButton::getLeft() {
    return m_sprite->x();
}

void k9MenuButton::setFont(QFont _font) {
    m_text->setFont(_font);
    update();
    m_canvas->update();
    emit sigsetFont(_font);
}

QFont k9MenuButton::getFont() {
    return m_text->font();
}

void k9MenuButton::setColor(QColor _color) {
    m_text->setColor(_color);
    m_canvas->update();
    emit sigsetColor(_color);
}

QColor k9MenuButton::getColor() {
    return m_text->color();
}

void k9MenuButton::setText(QString _text) {
    m_text->setText(_text);
    update();
    m_canvas->update();
    emit sigsetText(_text);
}

QString k9MenuButton::getText() {
    return m_text->text();
}



void k9MenuButton::moveBy(int _x,int _y,bool _reload) {
    int x=getLeft();
    int y=getTop();
    m_sprite->moveBy(_x,_y);
    emit sigsetLeft(x+_x);
    emit sigsetTop(y+_y);

    if(_reload)
        loadImage();
}
#include "k9menubutton.moc"




k9MenuButton::eTextPosition k9MenuButton::getTextPosition() const {
    return m_textPosition;
}


void k9MenuButton::setTextPosition(const eTextPosition& _value) {
    m_textPosition = _value;
    update();
    m_canvas->update();
    emit sigsetTextPosition(_value);
}


QImage k9MenuButton::getImage() const {
    return m_image;
}


QString k9MenuButton::getScript() const {
    return m_script;
}


void k9MenuButton::setScript(const QString& _value) {
    m_script = _value;
}


int k9MenuButton::getAngle() const {
    return m_angle;
}


void k9MenuButton::setAngle(int _value) {
    m_angle = _value;
}


k9CanvasSprite* k9MenuButton::getSprite() const {
    return m_sprite;
}


int k9MenuButton::getNum() const {
    return m_num;
}


void k9MenuButton::setNum(int _value) {
    m_num = _value;
}