1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Open downloaded image with mouse click on thumbnail

This commit is contained in:
Vincas Dargis 2016-02-14 17:20:11 +02:00
parent d614f74947
commit 857dfbcd4c
3 changed files with 28 additions and 14 deletions

View File

@ -53,7 +53,7 @@ FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file)
// hide the QWidget background (background-color: transparent doesn't seem to work)
setAttribute(Qt::WA_TranslucentBackground, true);
ui->previewLabel->hide();
ui->previewButton->hide();
ui->filenameLabel->setText(file.fileName);
ui->progressBar->setValue(0);
ui->fileSizeLabel->setText(getHumanReadableSize(file.filesize));
@ -86,6 +86,7 @@ FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file)
connect(Core::getInstance(), &Core::fileTransferBrokenUnbroken, this, &FileTransferWidget::fileTransferBrokenUnbroken);
connect(ui->topButton, &QPushButton::clicked, this, &FileTransferWidget::onTopButtonClicked);
connect(ui->bottomButton, &QPushButton::clicked, this, &FileTransferWidget::onBottomButtonClicked);
connect(ui->previewButton, &QPushButton::clicked, this, &FileTransferWidget::onPreviewButtonClicked);
setupButtons();
@ -482,7 +483,7 @@ void FileTransferWidget::handleButton(QPushButton *btn)
}
}
if (btn->objectName() == "ok")
if (btn->objectName() == "ok" || btn->objectName() == "previewButton")
{
Widget::confirmExecutableOpen(QFileInfo(fileInfo.filePath));
}
@ -501,13 +502,13 @@ void FileTransferWidget::showPreview(const QString &filename)
if (previewExtensions.contains(QFileInfo(filename).suffix()))
{
const int size = qMax(ui->previewLabel->width(), ui->previewLabel->height());
const int size = qMax(ui->previewButton->width(), ui->previewButton->height());
QPixmap pmap = QPixmap(filename).scaled(QSize(size, size),
Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
ui->previewLabel->setPixmap(pmap);
ui->previewLabel->show();
ui->previewLabel->setCursor(Qt::PointingHandCursor);
ui->previewButton->setIcon(QIcon(pmap));
ui->previewButton->setIconSize(pmap.size());
ui->previewButton->show();
// Show mouseover preview, but make sure it's not larger than 50% of the screen width/height
QRect desktopSize = QApplication::desktop()->screenGeometry();
QImage image = QImage(filename).scaled(0.5 * desktopSize.width(),
@ -518,7 +519,7 @@ void FileTransferWidget::showPreview(const QString &filename)
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, "PNG");
buffer.close();
ui->previewLabel->setToolTip("<img src=data:image/png;base64," + imageData.toBase64() + "/>");
ui->previewButton->setToolTip("<img src=data:image/png;base64," + imageData.toBase64() + "/>");
}
}
@ -531,3 +532,8 @@ void FileTransferWidget::onBottomButtonClicked()
{
handleButton(ui->bottomButton);
}
void FileTransferWidget::onPreviewButtonClicked()
{
handleButton(ui->previewButton);
}

View File

@ -70,6 +70,7 @@ protected:
private slots:
void onTopButtonClicked();
void onBottomButtonClicked();
void onPreviewButtonClicked();
private:
Ui::FileTransferWidget *ui;

View File

@ -270,7 +270,7 @@
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="previewLabel">
<widget class="QPushButton" name="previewButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -289,14 +289,21 @@
<height>60</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="lineWidth">
<number>2</number>
<property name="icon">
<iconset resource="../../../res.qrc">
<normaloff>:/ui/fileTransferInstance/no.svg</normaloff>:/ui/fileTransferInstance/no.svg</iconset>
</property>
<property name="text">
<string>[preview]</string>
<property name="iconSize">
<size>
<width>32</width>
<height>18</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>