File indexing completed on 2024-04-14 03:41:15

0001 /*
0002     SPDX-FileCopyrightText: 2005 Jason Harris <kstars@30doradus.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "ui_thumbnailpicker.h"
0010 
0011 #include <KIO/Job>
0012 
0013 #include <QDialog>
0014 #include <QPixmap>
0015 
0016 class QRect;
0017 class KJob;
0018 class DetailDialog;
0019 class SkyObject;
0020 
0021 class ThumbnailPickerUI : public QFrame, public Ui::ThumbnailPicker
0022 {
0023     Q_OBJECT
0024   public:
0025     explicit ThumbnailPickerUI(QWidget *p);
0026 };
0027 
0028 /**
0029  * @short Dialog for modifying an object's thumbnail image
0030  *
0031  * @author Jason Harris
0032  */
0033 class ThumbnailPicker : public QDialog
0034 {
0035     Q_OBJECT
0036   public:
0037     ThumbnailPicker(SkyObject *o, const QPixmap &current, QWidget *parent = nullptr, double w = 200, double h = 200,
0038                     QString cap = i18n("Choose Thumbnail Image"));
0039     ~ThumbnailPicker() override;
0040 
0041     QPixmap *image() { return Image; }
0042     QPixmap *currentListImage() { return PixList.at(SelectedImageIndex); }
0043     bool imageFound() const { return bImageFound; }
0044     QRect *imageRect() const { return ImageRect; }
0045 
0046   private slots:
0047     void slotEditImage();
0048     void slotUnsetImage();
0049     void slotSetFromList(int i);
0050     void slotSetFromURL();
0051     void slotFillList();
0052     void slotProcessGoogleResult(KJob *);
0053 
0054     /** Make sure download has finished, then make sure file exists, then add image to list */
0055     void slotJobResult(KJob *);
0056 
0057   private:
0058     QPixmap shrinkImage(QPixmap *original, int newSize, bool setImage = false);
0059     void parseGooglePage(const QString &URL);
0060 
0061     int SelectedImageIndex;
0062     double thumbWidth, thumbHeight;
0063     ThumbnailPickerUI *ui;
0064     QPixmap *Image;
0065     SkyObject *Object;
0066     QList<KIO::Job *> JobList;
0067     QList<QPixmap *> PixList;
0068     bool bImageFound;
0069     QRect *ImageRect;
0070 };