mirror of
https://bitbucket.org/smil3y/kde-playground.git
synced 2025-02-23 18:32:51 +00:00
kimageviewer: implement format conversion
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
a3b72a8224
commit
b24459422e
4 changed files with 162 additions and 56 deletions
|
@ -43,7 +43,7 @@ K_EXPORT_PLUGIN(KImageViewerPartFactory(KAboutData(
|
||||||
"1.0.0",
|
"1.0.0",
|
||||||
ki18n("Simple image viewer for KDE."),
|
ki18n("Simple image viewer for KDE."),
|
||||||
KAboutData::License_GPL_V2,
|
KAboutData::License_GPL_V2,
|
||||||
ki18n("(c) 2014 Ivailo Monev"),
|
ki18n("(c) 2014-2020 Ivailo Monev"),
|
||||||
KLocalizedString(),
|
KLocalizedString(),
|
||||||
"http://github.com/fluxer/kde-playground",
|
"http://github.com/fluxer/kde-playground",
|
||||||
"xakepa10@gmail.com").
|
"xakepa10@gmail.com").
|
||||||
|
|
|
@ -14,6 +14,25 @@
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="7" column="0">
|
||||||
|
<widget class="QComboBox" name="m_view">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Ignore</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Keep</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Expanding</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QPushButton" name="m_open">
|
<widget class="QPushButton" name="m_open">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -59,6 +78,21 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="10" column="0">
|
||||||
|
<widget class="QPushButton" name="m_quit">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Quit</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="application-exit">
|
||||||
|
<normaloff/>
|
||||||
|
</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="5" column="0">
|
<item row="5" column="0">
|
||||||
<widget class="QPushButton" name="m_rotateleft">
|
<widget class="QPushButton" name="m_rotateleft">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
|
@ -74,7 +108,7 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="8" column="0">
|
<item row="9" column="0">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
|
@ -87,37 +121,7 @@
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="0">
|
<item row="0" column="1" rowspan="11">
|
||||||
<widget class="QPushButton" name="m_rotateright">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Rotate right</string>
|
|
||||||
</property>
|
|
||||||
<property name="icon">
|
|
||||||
<iconset theme="object-rotate-right">
|
|
||||||
<normaloff/>
|
|
||||||
</iconset>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="9" column="0">
|
|
||||||
<widget class="QPushButton" name="m_quit">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Quit</string>
|
|
||||||
</property>
|
|
||||||
<property name="icon">
|
|
||||||
<iconset theme="application-exit">
|
|
||||||
<normaloff/>
|
|
||||||
</iconset>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1" rowspan="10">
|
|
||||||
<widget class="QLabel" name="m_image">
|
<widget class="QLabel" name="m_image">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||||
|
@ -136,26 +140,7 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="0">
|
<item row="11" column="0" colspan="2">
|
||||||
<widget class="QComboBox" name="m_view">
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Ignore</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Keep</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Expanding</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="10" column="0" colspan="2">
|
|
||||||
<widget class="QListWidget" name="m_thumbnail">
|
<widget class="QListWidget" name="m_thumbnail">
|
||||||
<property name="verticalScrollBarPolicy">
|
<property name="verticalScrollBarPolicy">
|
||||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||||
|
@ -165,6 +150,105 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="6" column="0">
|
||||||
|
<widget class="QPushButton" name="m_rotateright">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Rotate right</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="object-rotate-right">
|
||||||
|
<normaloff/>
|
||||||
|
</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="8" column="0">
|
||||||
|
<widget class="QComboBox" name="m_format">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Keep</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Mono</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>MonoLSB</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Indexed8</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>RGB32</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>ARGB32</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>ARGB32_Premultiplied</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>RGB16</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>ARGB8565_Premultiplied</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>RGB666</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>ARGB6666_Premultiplied</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>RGB555</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>ARGB8555_Premultiplied</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>RGB888</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>RGB444</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>ARGB4444_Premultiplied</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
|
@ -44,6 +44,7 @@ KImageWidget::KImageWidget(QWidget *parent)
|
||||||
connect(m_ui->m_rotateleft, SIGNAL(clicked()), this, SLOT(rotateLeft()));
|
connect(m_ui->m_rotateleft, SIGNAL(clicked()), this, SLOT(rotateLeft()));
|
||||||
connect(m_ui->m_rotateright, SIGNAL(clicked()), this, SLOT(rotateRight()));
|
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_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()));
|
connect(m_ui->m_quit, SIGNAL(clicked()), qApp, SLOT(quit()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,6 +107,22 @@ bool KImageWidget::changeMode(QString mode)
|
||||||
return false;
|
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)
|
bool KImageWidget::setImage(QString path, Qt::AspectRatioMode mode)
|
||||||
{
|
{
|
||||||
QPixmap p;
|
QPixmap p;
|
||||||
|
@ -202,8 +219,8 @@ QSize KImageWidget::sizeHint() const
|
||||||
|
|
||||||
QPixmap KImageWidget::resizeIfNeeded(QPixmap pixmap, Qt::AspectRatioMode mode)
|
QPixmap KImageWidget::resizeIfNeeded(QPixmap pixmap, Qt::AspectRatioMode mode)
|
||||||
{
|
{
|
||||||
if (pixmap.height() > m_ui->m_image->height()) {
|
if (pixmap.height() > m_ui->m_image->height() || pixmap.width() > m_ui->m_image->width()) {
|
||||||
return pixmap.scaled(m_ui->m_image->size(), mode);
|
return pixmap.scaled(m_ui->m_image->size() - QSize(3, 3), mode);
|
||||||
}
|
}
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
@ -215,6 +232,7 @@ void KImageWidget::resizeEvent(QResizeEvent *event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_ui->m_image->setPixmap(resizeIfNeeded(m_original, m_mode));
|
m_ui->m_image->setPixmap(resizeIfNeeded(m_original, m_mode));
|
||||||
|
QWidget::resizeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
} //namespace KImageViewer
|
} //namespace KImageViewer
|
||||||
|
|
|
@ -57,11 +57,15 @@ public slots:
|
||||||
bool rotateLeft();
|
bool rotateLeft();
|
||||||
bool rotateRight();
|
bool rotateRight();
|
||||||
bool changeMode(QString mode);
|
bool changeMode(QString mode);
|
||||||
|
bool changeFormat(QString mode);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// reimplementation
|
||||||
|
void resizeEvent(QResizeEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui_KImageUI *m_ui;
|
Ui_KImageUI *m_ui;
|
||||||
QPixmap resizeIfNeeded(QPixmap pixmap, Qt::AspectRatioMode mode);
|
QPixmap resizeIfNeeded(QPixmap pixmap, Qt::AspectRatioMode mode);
|
||||||
void resizeEvent(QResizeEvent *event);
|
|
||||||
int m_resizehits;
|
int m_resizehits;
|
||||||
QPixmap m_original;
|
QPixmap m_original;
|
||||||
Qt::AspectRatioMode m_mode;
|
Qt::AspectRatioMode m_mode;
|
||||||
|
|
Loading…
Add table
Reference in a new issue