aboutsummaryrefslogtreecommitdiff
path: root/lumina-fm/widgets/SlideshowWidget.cpp
diff options
context:
space:
mode:
authorKen Moore <moorekou@gmail.com>2015-08-17 16:00:00 -0400
committerKen Moore <moorekou@gmail.com>2015-08-17 16:00:00 -0400
commitf809e720d7bf5c2b314c705ad5600776afcf6659 (patch)
tree3a85e35b1e7f670a2a1c53cf017800dcc3a7aec6 /lumina-fm/widgets/SlideshowWidget.cpp
parentTouch up the new Grey-Dark color scheme a bit - now the highlight/accent colo... (diff)
downloadlumina-f809e720d7bf5c2b314c705ad5600776afcf6659.tar.gz
lumina-f809e720d7bf5c2b314c705ad5600776afcf6659.tar.bz2
lumina-f809e720d7bf5c2b314c705ad5600776afcf6659.zip
Convert the multimedia player and slideshow viewer into separate classes/widgets for lumina-fm, and add the new UI for the directory browser as well (no .h/.cpp source files filled out yet for it yet though).
These new widgets/classes are tied into the build for compilation purposes, but they are not actually used in the app yet.
Diffstat (limited to 'lumina-fm/widgets/SlideshowWidget.cpp')
-rw-r--r--lumina-fm/widgets/SlideshowWidget.cpp146
1 files changed, 146 insertions, 0 deletions
diff --git a/lumina-fm/widgets/SlideshowWidget.cpp b/lumina-fm/widgets/SlideshowWidget.cpp
new file mode 100644
index 00000000..ff7113b6
--- /dev/null
+++ b/lumina-fm/widgets/SlideshowWidget.cpp
@@ -0,0 +1,146 @@
+//===========================================
+// Lumina-DE source code
+// Copyright (c) 2015, Ken Moore
+// Available under the 3-clause BSD license
+// See the LICENSE file for full details
+//===========================================
+#include "SlideshowWidget.h"
+#include "ui_SlideshowWidget.h"
+
+#include <QImageWriter>
+#include <QMessageBox>
+
+SlideshowWidget::SlideshowWidget(QWidget *parent) : QWidget(parent), ui(new Ui::SlideshowWidget){
+ ui->setupUi(this); //load the designer file
+
+ UpdateIcons();
+ UpdateText();
+}
+
+SlideshowWidget::~SlideshowWidget(){
+
+}
+
+// ================
+// PUBLIC SLOTS
+// ================
+void SlideshowWidget::LoadImages(QList<LFileInfo> list){
+ ui->combo_image_name->clear();
+ for(int i=0; i<list.length(); i++){
+ if(list[i].isImage()){ ui->combo_image_name->addItem(list[i].fileName(), list[i].absoluteFilePath() ); }
+ }
+}
+
+//Theme change functions
+void SlideshowWidget::UpdateIcons(){
+ ui->tool_image_goBegin->setIcon( LXDG::findIcon("go-first-view","") );
+ ui->tool_image_goEnd->setIcon( LXDG::findIcon("go-last-view","") );
+ ui->tool_image_goPrev->setIcon( LXDG::findIcon("go-previous-view","") );
+ ui->tool_image_goNext->setIcon( LXDG::findIcon("go-next-view","") );
+ ui->tool_image_remove->setIcon( LXDG::findIcon("edit-delete","") );
+ ui->tool_image_rotateleft->setIcon( LXDG::findIcon("object-rotate-left","") );
+ ui->tool_image_rotateright->setIcon( LXDG::findIcon("object-rotate-right","") );
+}
+
+void SlideshowWidget::UpdateText(){
+ ui->retranslateUi(this);
+}
+
+
+// =================
+// PRIVATE
+// =================
+void SlideshowWidget::UpdateImage(){
+ if( !ui->label_image->isVisible() ){ return; } //don't update if not visible - can cause strange resizing issues
+ QString file = ui->combo_image_name->currentData().toString();
+ /*if(!file.endsWith("/")){ file.append("/"); }
+ file.append(ui->combo_image_name->currentText());*/
+ //qDebug() << "Show Image:" << file;
+ QPixmap pix(file);
+ if(pix.size().width() > ui->label_image->contentsRect().width() || pix.size().height() > ui->label_image->contentsRect().height()){
+ pix = pix.scaled(ui->label_image->contentsRect().size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ }
+ ui->label_image->setPixmap(pix);
+ //Now set/load the buttons
+ ui->tool_image_goBegin->setEnabled(ui->combo_image_name->currentIndex()>0);
+ ui->tool_image_goPrev->setEnabled(ui->combo_image_name->currentIndex()>0);
+ ui->tool_image_goEnd->setEnabled(ui->combo_image_name->currentIndex()<(ui->combo_image_name->count()-1));
+ ui->tool_image_goNext->setEnabled(ui->combo_image_name->currentIndex()<(ui->combo_image_name->count()-1));
+ ui->label_image_index->setText( QString::number(ui->combo_image_name->currentIndex()+1)+"/"+QString::number(ui->combo_image_name->count()) );
+ static QList<QByteArray> writeableformats;
+ if(writeableformats.isEmpty()){
+ writeableformats = QImageWriter::supportedImageFormats();
+ qDebug() << "Writeable image formats:" << writeableformats;
+ }
+ bool canwrite = writeableformats.contains(file.section(".",-1).toLower().toLocal8Bit()); //compare the suffix with the list
+ bool isUserWritable = QFileInfo(file).isWritable();
+ ui->tool_image_remove->setEnabled(isUserWritable);
+ ui->tool_image_rotateleft->setEnabled(isUserWritable && canwrite);
+ ui->tool_image_rotateright->setEnabled(isUserWritable && canwrite);
+}
+
+
+// =================
+// PRIVATE SLOTS
+// =================
+// Picture rotation options
+void SlideshowWidget::on_combo_image_name_indexChanged(int index){
+ if(index>=0 && !ui->combo_image_name->currentData().toString().isEmpty()){
+ UpdateImage();
+ }
+}
+
+void SlideshowWidget::on_tool_image_goEnd_clicked(){
+ ui->combo_image_name->setCurrentIndex( ui->combo_image_name->count()-1 );
+}
+
+void SlideshowWidget::on_tool_image_goNext_clicked(){
+ ui->combo_image_name->setCurrentIndex( ui->combo_image_name->currentIndex()+1 );
+}
+
+void SlideshowWidget::on_tool_image_goPrev_clicked(){
+ ui->combo_image_name->setCurrentIndex( ui->combo_image_name->currentIndex()-1 );
+}
+
+void SlideshowWidget::on_tool_image_goBegin_clicked(){
+ ui->combo_image_name->setCurrentIndex(0);
+}
+
+// Picture modification options
+void SlideshowWidget::on_tool_image_remove_clicked(){
+ QString file = ui->combo_image_name->currentData().toString();
+ //Verify permanent removal of file/dir
+ if(QMessageBox::Yes != QMessageBox::question(this, tr("Verify Removal"), tr("WARNING: This will permanently delete the file from the system!")+"\n"+tr("Are you sure you want to continue?")+"\n\n"+file, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) ){
+ return; //cancelled
+ }
+ if( QFile::remove(file) ){
+ int index = ui->combo_image_name->currentIndex();
+ ui->combo_image_name->removeItem( index );
+ }
+}
+
+void SlideshowWidget::on_tool_image_rotateleft_clicked(){
+ //First load the file fresh (not the scaled version in the UI)
+ QString file = ui->combo_image_name->currentData().toString();
+ QPixmap pix(file);
+ //Now rotate the image 90 degrees counter-clockwise
+ QTransform trans;
+ pix = pix.transformed( trans.rotate(-90) , Qt::SmoothTransformation);
+ //Now save the image back to the same file
+ pix.save(file);
+ //Now re-load the image in the UI
+ UpdateImage();
+}
+
+void SlideshowWidget::on_tool_image_rotateright_clicked(){
+ //First load the file fresh (not the scaled version in the UI)
+ QString file = ui->combo_image_name->currentData().toString();
+ QPixmap pix(file);
+ //Now rotate the image 90 degrees counter-clockwise
+ QTransform trans;
+ pix = pix.transformed( trans.rotate(90) , Qt::SmoothTransformation);
+ //Now save the image back to the same file
+ pix.save(file);
+ //Now re-load the image in the UI
+ UpdateImage();
+}
bgstack15