| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
#include <qpainter.h> |
|---|
| 8 |
#include <qpixmap.h> |
|---|
| 9 |
#include "GraphIcon.h" |
|---|
| 10 |
#include "structures.h" |
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
const int NUM_PIX = 100; |
|---|
| 15 |
QPixmap *pix = NULL; |
|---|
| 16 |
QPixmap *icon = NULL; |
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
void allocate_pix() |
|---|
| 20 |
{ |
|---|
| 21 |
QPixmap::setDefaultOptimization(QPixmap::MemoryOptim); |
|---|
| 22 |
pix = new QPixmap[NUM_PIX]; |
|---|
| 23 |
for (int i = 0; i < NUM_PIX; i++) pix[i].resize(ICON_W, ICON_H); |
|---|
| 24 |
|
|---|
| 25 |
pix[0].fill(QColor(50,150,150)); |
|---|
| 26 |
pix[1].fill(QColor(50,150,50)); |
|---|
| 27 |
|
|---|
| 28 |
for (i = 2; i < NUM_PIX; i++) |
|---|
| 29 |
pix[i].fill(QColor(230 * (rand()/(double)RAND_MAX),230 * (rand()/(double)RAND_MAX),230 * (rand()/(double)RAND_MAX))); |
|---|
| 30 |
|
|---|
| 31 |
icon = new QPixmap(ICON_W, ICON_H); |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
GraphIcon::GraphIcon() |
|---|
| 36 |
{ |
|---|
| 37 |
this->parent = NULL; |
|---|
| 38 |
selected = false; |
|---|
| 39 |
|
|---|
| 40 |
w = ICON_W; |
|---|
| 41 |
h = ICON_H; |
|---|
| 42 |
|
|---|
| 43 |
ul_x = ul_y = 0; |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
if (!pix) allocate_pix(); |
|---|
| 50 |
background = pix + (int)((NUM_PIX-1)*(rand()/(double)RAND_MAX)); |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
draw(); |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
GraphIcon::GraphIcon(AuthorNode *parent) |
|---|
| 58 |
{ |
|---|
| 59 |
this->parent = parent; |
|---|
| 60 |
selected = false; |
|---|
| 61 |
|
|---|
| 62 |
w = ICON_W; |
|---|
| 63 |
h = ICON_H; |
|---|
| 64 |
|
|---|
| 65 |
ul_x = ul_y = 0; |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
if (!pix) allocate_pix(); |
|---|
| 73 |
if (parent->type == NODE_STORY) background = pix + 0; |
|---|
| 74 |
else background = pix + 1; |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
draw(); |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
QPixmap* |
|---|
| 82 |
GraphIcon::getIcon() {draw(); return icon;} |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
GraphIcon::~GraphIcon() |
|---|
| 86 |
{ |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
void |
|---|
| 93 |
GraphIcon::select() |
|---|
| 94 |
{ |
|---|
| 95 |
selected = true; |
|---|
| 96 |
draw(); |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
void |
|---|
| 100 |
GraphIcon::deselect() |
|---|
| 101 |
{ |
|---|
| 102 |
selected = false; |
|---|
| 103 |
draw(); |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
void |
|---|
| 108 |
GraphIcon::draw() |
|---|
| 109 |
{ |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
QPainter p(icon); |
|---|
| 113 |
p.drawPixmap(background->rect().topLeft(), *background); |
|---|
| 114 |
|
|---|
| 115 |
if (parent) { |
|---|
| 116 |
p.setPen(QColor(220,220,220)); |
|---|
| 117 |
p.drawText(10, 10, width()-20, height()-20, Qt::AlignCenter, parent->name.c_str()); |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
if (!selected) |
|---|
| 122 |
p.setPen(QPen(QColor(150,150,150), 5)); |
|---|
| 123 |
else |
|---|
| 124 |
p.setPen(QPen(QColor(255,0,0), 7)); |
|---|
| 125 |
p.drawRect(icon->rect()); |
|---|
| 126 |
|
|---|
| 127 |
p.end(); |
|---|
| 128 |
} |
|---|