File: QFitsWedge.cpp

package info (click to toggle)
dpuser 4.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,084 kB
  • sloc: cpp: 124,807; ansic: 6,866; lex: 1,113; makefile: 777; yacc: 742; sh: 78
file content (60 lines) | stat: -rw-r--r-- 1,792 bytes parent folder | download | duplicates (4)
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
#include <QPainter>

#include "QFitsWedge.h"
#include "QFitsMainView.h"
#include "QFitsMainWindow.h"
#include "QFitsSingleBuffer.h"

QFitsWedge::QFitsWedge(QFitsMainView *parent) : QWidget(parent), myParent(parent) {
    image = new QImage(1, 1, QImage::Format_Indexed8);
    image->setColorCount(NCOLORS);
    setMinimumHeight(10);
    setMaximumHeight(10);
}

void QFitsWedge::paintEvent(QPaintEvent *e) {
    if ((fitsMainWindow->getCurrentBuffer() == NULL) ||
        fitsMainWindow->getCurrentBuffer()->getAppearance().hideWedge)
    {
        return;
    }

    QFitsSingleBuffer *sb = fitsMainWindow->getActualSB();
    if (sb != NULL) {
        QImage *sbImg = sb->getImage();
        for (int i = 0; i < NCOLORS; i++) {
            image->setColor(i, sbImg->color(i));
        }

        QPixmap pm(width(), height());
        QPainter p;
        p.begin(&pm);
        p.drawImage(0, 0, *image);
        p.end();

        QPainter painter(this);
        painter.drawPixmap(width()/2-pm.width()/2,
                           height()/2-pm.height()/2,
                           pm, 0, 0,
                           pm.width(), pm.height());
    }
}

void QFitsWedge::resizeEvent(QResizeEvent *e) {
    if (image != NULL) {
        delete image;
    }
    image = new QImage(width(), height(), QImage::Format_Indexed8);
    image->setColorCount(NCOLORS);

    for (int y = 0; y < image->height(); y++) { // set image pixels
        uchar *p = image->scanLine(y);
        for (int x = 0; x < image->width(); x++) {
            *p++ = (unsigned char)((image->width() - x) * (NCOLORS-1) / image->width());
        }
    }
    for (int i = 0; i < NCOLORS; i++) {
        image->setColor(i, colourTable[i]);
    }
    update();
}