-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
297 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "screenshot_manager_dialog.h" | ||
#include "screenshot_preview.h" | ||
#include "qt_utils.h" | ||
#include "Utilities/File.h" | ||
|
||
#include <QApplication> | ||
#include <QDir> | ||
#include <QDirIterator> | ||
#include <QListWidget> | ||
#include <QScreen> | ||
#include <QVBoxLayout> | ||
|
||
screenshot_manager_dialog::screenshot_manager_dialog(QWidget* parent) : QDialog(parent) | ||
{ | ||
setWindowTitle(tr("Screenshots")); | ||
|
||
m_grid = new QListWidget(this); | ||
m_grid->setViewMode(QListWidget::IconMode); | ||
m_grid->setMovement(QListWidget::Static); | ||
m_grid->setResizeMode(QListWidget::Adjust); | ||
m_grid->setIconSize(QSize(160, 90)); | ||
m_grid->setGridSize(m_grid->iconSize() + QSize(10, 10)); | ||
|
||
const std::string screen_path = fs::get_config_dir() + "/screenshots/"; | ||
const QStringList filter{ QStringLiteral("*.png") }; | ||
QDirIterator dir_iter(QString::fromStdString(screen_path), filter, QDir::Files | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); | ||
|
||
while (dir_iter.hasNext()) | ||
{ | ||
const QString filepath = dir_iter.next(); | ||
|
||
QListWidgetItem* item = new QListWidgetItem; | ||
item->setData(Qt::UserRole, filepath); | ||
item->setIcon(QIcon(filepath)); | ||
item->setToolTip(filepath); | ||
|
||
m_grid->addItem(item); | ||
} | ||
|
||
connect(m_grid, &QListWidget::itemDoubleClicked, [this](QListWidgetItem* item) | ||
{ | ||
if (!item) | ||
{ | ||
return; | ||
} | ||
|
||
const QString filepath = item->data(Qt::UserRole).toString(); | ||
|
||
screenshot_preview* preview = new screenshot_preview(filepath); | ||
preview->show(); | ||
}); | ||
|
||
QVBoxLayout* layout = new QVBoxLayout; | ||
layout->setContentsMargins(0, 0, 0, 0); | ||
layout->addWidget(m_grid); | ||
setLayout(layout); | ||
|
||
resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include <QDialog> | ||
|
||
class QListWidget; | ||
|
||
class screenshot_manager_dialog : public QDialog | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
screenshot_manager_dialog(QWidget* parent = nullptr); | ||
|
||
private: | ||
QListWidget* m_grid = nullptr; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "screenshot_preview.h" | ||
#include "qt_utils.h" | ||
|
||
#include <QAction> | ||
#include <QApplication> | ||
#include <QClipboard> | ||
#include <QImage> | ||
#include <QImageReader> | ||
#include <QMenu> | ||
#include <QResizeEvent> | ||
|
||
screenshot_preview::screenshot_preview(const QString& filepath, QWidget* parent) | ||
: QLabel(parent) | ||
, m_filepath(filepath) | ||
{ | ||
QImageReader reader(filepath); | ||
reader.setAutoTransform(true); | ||
|
||
m_image = reader.read(); | ||
|
||
setWindowTitle(tr("Screenshot Preview")); | ||
setObjectName("screenshot_preview"); | ||
setContextMenuPolicy(Qt::CustomContextMenu); | ||
setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); | ||
setPixmap(QPixmap::fromImage(m_image)); | ||
setMinimumSize(160, 90); | ||
|
||
connect(this, &screenshot_preview::customContextMenuRequested, this, &screenshot_preview::show_context_menu); | ||
} | ||
#include <QDebug> | ||
|
||
void screenshot_preview::show_context_menu(const QPoint & pos) | ||
{ | ||
QMenu* menu = new QMenu(); | ||
menu->addAction(tr("&Copy"), [this]() { QGuiApplication::clipboard()->setImage(m_image); }); | ||
menu->addSeparator(); | ||
|
||
QAction* reset_act = menu->addAction(tr("To &Normal Size"), [this]() { scale(m_image.size()); }); | ||
reset_act->setEnabled(pixmap()->size() != m_image.size()); | ||
|
||
QAction* stretch_act = menu->addAction(tr("&Stretch to size"), [this]() { m_stretch = !m_stretch; scale(size()); }); | ||
stretch_act->setCheckable(true); | ||
stretch_act->setChecked(m_stretch); | ||
|
||
menu->addSeparator(); | ||
menu->addAction(tr("E&xit"), this, &QLabel::close); | ||
menu->exec(mapToGlobal(pos)); | ||
} | ||
|
||
void screenshot_preview::scale(const QSize& new_size) | ||
{ | ||
if (new_size != size()) | ||
{ | ||
resize(new_size); | ||
} | ||
|
||
setPixmap(QPixmap::fromImage(m_image.scaled(new_size, m_stretch ? Qt::IgnoreAspectRatio : Qt::KeepAspectRatio, Qt::SmoothTransformation))); | ||
} | ||
|
||
void screenshot_preview::resizeEvent(QResizeEvent* event) | ||
{ | ||
scale(event->size()); | ||
event->ignore(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include <QImage> | ||
#include <QLabel> | ||
|
||
class screenshot_preview : public QLabel | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
screenshot_preview(const QString& filepath, QWidget* parent = nullptr); | ||
|
||
protected: | ||
void resizeEvent(QResizeEvent* event); | ||
|
||
private Q_SLOTS: | ||
void show_context_menu(const QPoint& pos); | ||
|
||
private: | ||
void scale(const QSize& size); | ||
|
||
QString m_filepath; | ||
QImage m_image; | ||
double m_factor = 1.0; | ||
bool m_stretch = false; | ||
}; |