Kstars

thumbnaileditor.cpp
1 /*
2  SPDX-FileCopyrightText: 2005 Jason Harris <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "thumbnaileditor.h"
8 
9 #include "thumbnailpicker.h"
10 #include "ui_thumbnaileditor.h"
11 
12 #include <KLocalizedString>
13 
14 #include <QHBoxLayout>
15 #include <QLabel>
16 #include <QMouseEvent>
17 #include <QPaintEvent>
18 #include <QPixmap>
19 
20 #include <QDebug>
21 #include <QDialogButtonBox>
22 #include <QPushButton>
23 
24 ThumbnailEditorUI::ThumbnailEditorUI(QWidget *parent) : QFrame(parent)
25 {
26  setupUi(this);
27 }
28 
29 ThumbnailEditor::ThumbnailEditor(ThumbnailPicker *_tp, double _w, double _h) : QDialog(_tp), tp(_tp)
30 {
31 #ifdef Q_OS_OSX
32  setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
33 #endif
34  ui = new ThumbnailEditorUI(this);
35  w = _w;
36  h = _h;
37  ui->MessageLabel->setText(i18n("Crop region will be scaled to [ %1 * %2 ]", w, h));
38 
39  setWindowTitle(i18nc("@title:window", "Edit Thumbnail Image"));
40  QVBoxLayout *mainLayout = new QVBoxLayout;
41  mainLayout->addWidget(ui);
42  setLayout(mainLayout);
43 
45  mainLayout->addWidget(buttonBox);
46  connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
47  connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
48 
49  ui->ImageCanvas->setCropRect(tp->imageRect()->x(), tp->imageRect()->y(), tp->imageRect()->width(),
50  tp->imageRect()->height());
51  ui->ImageCanvas->setImage(tp->currentListImage());
52 
53  //DEBUG
54  //qDebug() << Q_FUNC_INFO << tp->currentListImage()->size();
55 
56  connect(ui->ImageCanvas, SIGNAL(cropRegionModified()), SLOT(slotUpdateCropLabel()));
57  slotUpdateCropLabel();
58 
59  update();
60 }
61 
62 QPixmap ThumbnailEditor::thumbnail()
63 {
64  QImage im = ui->ImageCanvas->croppedImage().toImage();
66  return QPixmap::fromImage(im);
67 }
68 
69 void ThumbnailEditor::slotUpdateCropLabel()
70 {
71  QRect *r = ui->ImageCanvas->cropRect();
72  ui->CropLabel->setText(i18n("Crop region: [%1,%2 %3x%4]", r->left(), r->top(), r->width(), r->height()));
73 }
Dialog for modifying an object's thumbnail image.
QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags)
int width() const const
QImage scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
int left() const const
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
int top() const const
IgnoreAspectRatio
QString i18n(const char *text, const TYPE &arg...)
int height() const const
void update(Part *part, const QByteArray &data, qint64 dataSize)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
SmoothTransformation
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:58 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.