1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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();
}
|