diff --git a/kimageviewer/kimagepart.cpp b/kimageviewer/kimagepart.cpp index e82a9572..dcfa4341 100644 --- a/kimageviewer/kimagepart.cpp +++ b/kimageviewer/kimagepart.cpp @@ -43,7 +43,7 @@ K_EXPORT_PLUGIN(KImageViewerPartFactory(KAboutData( "1.0.0", ki18n("Simple image viewer for KDE."), KAboutData::License_GPL_V2, - ki18n("(c) 2014 Ivailo Monev"), + ki18n("(c) 2014-2020 Ivailo Monev"), KLocalizedString(), "http://github.com/fluxer/kde-playground", "xakepa10@gmail.com"). diff --git a/kimageviewer/kimageui.ui b/kimageviewer/kimageui.ui index bcd6bd80..381eb53a 100644 --- a/kimageviewer/kimageui.ui +++ b/kimageviewer/kimageui.ui @@ -14,6 +14,25 @@ Form + + + + + Ignore + + + + + Keep + + + + + Expanding + + + + @@ -59,6 +78,21 @@ + + + + true + + + Quit + + + + + + + + @@ -74,7 +108,7 @@ - + Qt::Vertical @@ -87,37 +121,7 @@ - - - - false - - - Rotate right - - - - - - - - - - - - true - - - Quit - - - - - - - - - + @@ -136,26 +140,7 @@ - - - - - Ignore - - - - - Keep - - - - - Expanding - - - - - + Qt::ScrollBarAlwaysOff @@ -165,6 +150,105 @@ + + + + false + + + Rotate right + + + + + + + + + + + + + Keep + + + + + Mono + + + + + MonoLSB + + + + + Indexed8 + + + + + RGB32 + + + + + ARGB32 + + + + + ARGB32_Premultiplied + + + + + RGB16 + + + + + ARGB8565_Premultiplied + + + + + RGB666 + + + + + ARGB6666_Premultiplied + + + + + RGB555 + + + + + ARGB8555_Premultiplied + + + + + RGB888 + + + + + RGB444 + + + + + ARGB4444_Premultiplied + + + + diff --git a/kimageviewer/kimagewidget.cpp b/kimageviewer/kimagewidget.cpp index f52d82e4..151f3c05 100644 --- a/kimageviewer/kimagewidget.cpp +++ b/kimageviewer/kimagewidget.cpp @@ -44,6 +44,7 @@ KImageWidget::KImageWidget(QWidget *parent) connect(m_ui->m_rotateleft, SIGNAL(clicked()), this, SLOT(rotateLeft())); connect(m_ui->m_rotateright, SIGNAL(clicked()), this, SLOT(rotateRight())); connect(m_ui->m_view, SIGNAL(currentIndexChanged(QString)), this, SLOT(changeMode(QString))); + connect(m_ui->m_format, SIGNAL(currentIndexChanged(QString)), this, SLOT(changeFormat(QString))); connect(m_ui->m_quit, SIGNAL(clicked()), qApp, SLOT(quit())); } @@ -106,6 +107,22 @@ bool KImageWidget::changeMode(QString mode) return false; } +bool KImageWidget::changeFormat(QString format) +{ + qDebug() << format; + if (format == QLatin1String("Keep")) { + m_ui->m_image->setPixmap(resizeIfNeeded(m_original, m_mode)); + return true; + } else { + QImage temp = resizeIfNeeded(m_original, m_mode).toImage(); + QImage::Format imgformat = QImage::Format(m_ui->m_format->currentIndex()); + m_ui->m_image->setPixmap(QPixmap::fromImage(temp.convertToFormat(imgformat))); + qDebug() << imgformat << m_ui->m_image->pixmap()->toImage().format(); + return true; + } + return false; +} + bool KImageWidget::setImage(QString path, Qt::AspectRatioMode mode) { QPixmap p; @@ -202,8 +219,8 @@ QSize KImageWidget::sizeHint() const QPixmap KImageWidget::resizeIfNeeded(QPixmap pixmap, Qt::AspectRatioMode mode) { - if (pixmap.height() > m_ui->m_image->height()) { - return pixmap.scaled(m_ui->m_image->size(), mode); + if (pixmap.height() > m_ui->m_image->height() || pixmap.width() > m_ui->m_image->width()) { + return pixmap.scaled(m_ui->m_image->size() - QSize(3, 3), mode); } return pixmap; } @@ -215,6 +232,7 @@ void KImageWidget::resizeEvent(QResizeEvent *event) return; } m_ui->m_image->setPixmap(resizeIfNeeded(m_original, m_mode)); + QWidget::resizeEvent(event); } } //namespace KImageViewer diff --git a/kimageviewer/kimagewidget.h b/kimageviewer/kimagewidget.h index ce8f3c07..e53650f0 100644 --- a/kimageviewer/kimagewidget.h +++ b/kimageviewer/kimagewidget.h @@ -57,11 +57,15 @@ public slots: bool rotateLeft(); bool rotateRight(); bool changeMode(QString mode); + bool changeFormat(QString mode); + +protected: + // reimplementation + void resizeEvent(QResizeEvent *event); private: Ui_KImageUI *m_ui; QPixmap resizeIfNeeded(QPixmap pixmap, Qt::AspectRatioMode mode); - void resizeEvent(QResizeEvent *event); int m_resizehits; QPixmap m_original; Qt::AspectRatioMode m_mode;