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",
|
||||
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").
|
||||
|
|
|
@ -14,6 +14,25 @@
|
|||
<string>Form</string>
|
||||
</property>
|
||||
<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">
|
||||
<widget class="QPushButton" name="m_open">
|
||||
<property name="sizePolicy">
|
||||
|
@ -59,6 +78,21 @@
|
|||
</property>
|
||||
</widget>
|
||||
</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">
|
||||
<widget class="QPushButton" name="m_rotateleft">
|
||||
<property name="enabled">
|
||||
|
@ -74,7 +108,7 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<item row="9" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
|
@ -87,37 +121,7 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</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="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">
|
||||
<item row="0" column="1" rowspan="11">
|
||||
<widget class="QLabel" name="m_image">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
|
@ -136,26 +140,7 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<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="10" column="0" colspan="2">
|
||||
<item row="11" column="0" colspan="2">
|
||||
<widget class="QListWidget" name="m_thumbnail">
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
|
@ -165,6 +150,105 @@
|
|||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue