20 #include <config-kstars.h>
27 #include <QApplication>
28 #include <QPaintEvent>
29 #include <QScrollArea>
32 #include <QProgressDialog>
40 #include <KActionCollection>
42 #include <KProgressDialog>
43 #include <KMessageBox>
44 #include <KFileDialog>
48 #define ZOOM_DEFAULT 100.0
51 #define ZOOM_LOW_INCR 10
52 #define ZOOM_HIGH_INCR 50
93 emit
newStatus(KGlobal::locale()->formatNumber( buffer[(
int) (y * width + x)]),
FITS_VALUE);
97 int index = x + y * width;
104 ra.
setD(wcs_coord[index].ra);
105 dec.
setD(wcs_coord[index].dec);
107 emit
newStatus(QString(
"%1 , %2").arg( ra.toHMSString()).arg(dec.toDMSString()),
FITS_WCS);
110 setCursor(Qt::CrossCursor);
133 display_image = NULL;
138 setBackgroundRole(QPalette::Dark);
140 guide_x = guide_y = guide_box = -1;
147 image_frame->setMouseTracking(
true);
158 delete(display_image);
164 QProgressDialog fitsProg;
171 if (image_data->
loadFITS(inFilename, &fitsProg) ==
false)
174 image_data->
getSize(¤tWidth, ¤tHeight);
176 image_width = currentWidth;
177 image_height = currentHeight;
179 image_frame->
setSize(currentWidth, currentHeight);
181 hasWCS = image_data->
hasWCS();
183 delete (display_image);
184 display_image = NULL;
186 display_image =
new QImage(currentWidth, currentHeight, QImage::Format_Indexed8);
188 display_image->setNumColors(256);
189 for (
int i=0; i < 256; i++)
190 display_image->setColor(i, qRgb(i,i,i));
208 setAlignment(Qt::AlignCenter);
218 return image_data->
saveFITS(newFilename);
225 double bscale, bzero;
233 KMessageBox::error(0, i18n(
"FITS image is saturated and cannot be displayed."), i18n(
"FITS Open"));
238 bscale = 255. / (max - min);
239 bzero = (-min) * (255. / (max - min));
241 image_frame->setScaledContents(
true);
242 currentWidth = display_image->width();
243 currentHeight = display_image->height();
246 for (
int j = 0; j < image_height; j++)
247 for (
int i = 0; i < image_width; i++)
249 val = image_buffer[j * image_width + i];
250 display_image->setPixel(i, j, ((
int) (val * bscale + bzero)));
256 if ((display_image->width() > width() || display_image->height() > height()))
259 currentZoom = floor( (
INITIAL_W / currentWidth) * 10.) * 10.;
263 currentZoom = floor( (
INITIAL_H / currentHeight) * 10.) * 10.;
265 currentWidth = image_width * (currentZoom /
ZOOM_DEFAULT);
266 currentHeight = image_height * (currentZoom /
ZOOM_DEFAULT);
277 currentWidth = image_width;
278 currentHeight = image_height;
287 currentWidth = image_width * (currentZoom /
ZOOM_DEFAULT);
288 currentHeight = image_height * (currentZoom /
ZOOM_DEFAULT);
299 setWidget(image_frame);
322 currentWidth = image_width * (currentZoom /
ZOOM_DEFAULT);
323 currentHeight = image_height * (currentZoom /
ZOOM_DEFAULT);
344 currentWidth = image_width * (currentZoom /
ZOOM_DEFAULT);
345 currentHeight = image_height * (currentZoom /
ZOOM_DEFAULT);
355 QPixmap displayPixmap;
358 if (display_image == NULL)
362 ok = displayPixmap.convertFromImage(display_image->scaled( (
int) currentWidth, (
int) currentHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation));
364 ok = displayPixmap.convertFromImage(*display_image);
370 QPainter painter(&displayPixmap);
374 image_frame->setPixmap(displayPixmap);
375 image_frame->resize( (
int) currentWidth, (
int) currentHeight);
385 currentWidth = image_width;
386 currentHeight = image_height;
408 painter->setPen(QPen(Qt::red, 2));
416 for (
int i=0; i < starCenters.count() ; i++)
418 x1 = (starCenters[i]->x - starCenters[i]->width/2) * (currentZoom /
ZOOM_DEFAULT);
419 y1 = (starCenters[i]->y - starCenters[i]->width/2) * (currentZoom /
ZOOM_DEFAULT);
420 w = (starCenters[i]->width) * (currentZoom /
ZOOM_DEFAULT);
422 painter->drawEllipse(x1, y1, w, w);
428 painter->setPen(QPen(Qt::green, 2));
430 int mid = guide_box/2;
432 if (mid == -1 || guide_x == -1 || guide_y == -1)
435 int x1 = (guide_x - mid) * (currentZoom /
ZOOM_DEFAULT);
436 int y1 = (guide_y - mid) * (currentZoom /
ZOOM_DEFAULT);
439 painter->drawRect(x1, y1, w, w);
462 if (markStars ==
true)
465 if (count >= 0 && isVisible())
478 #include "fitsview.moc"
FITSImage * getImageData()
void setGuideSquare(int x, int y)
bool loadFITS(const QString &filename)
void processPointSelection(int x, int y)
wcs_point * getWCSCoord()
virtual void mousePressEvent(QMouseEvent *e)
void setSize(double w, double h)
void guideStarSelected(int x, int y)
void drawOverlay(QPainter *)
int saveFITS(const QString &filename)
int rescale(FITSZoom type)
void newStatus(const QString &msg, FITSBar id)
void pointSelected(int x, int y)
int saveFITS(const QString &filename)
virtual void mouseMoveEvent(QMouseEvent *e)
void toggleStars(bool enable)
void drawStarCentroid(QPainter *)
QList< Edge * > getStarCenters()
void drawGuideBox(QPainter *)
void getMinMax(double *min, double *max)
FITSLabel(FITSView *img, QWidget *parent=NULL)
void getCenterSelection(int *x, int *y)
T clamp(T x, T min, T max)
Clamp value into range.
FITSView(QWidget *parent=0, FITSMode mode=FITS_NORMAL)
void setD(const double &x)
Sets floating-point value of angle, in degrees.
void actionUpdated(const QString &name, bool enable)
void setGuideBoxSize(int size)
void getSize(double *w, double *h)
bool loadFITS(const QString &filename, QProgressDialog *progress=NULL)
void newStatus(const QString &msg, FITSBar id)