Skip to content

Commit

Permalink
qimageuploader: refactor UploadTreeView keyboard shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
zenden2k committed Oct 28, 2024
1 parent 78718f6 commit 4b4ed69
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 26 deletions.
6 changes: 6 additions & 0 deletions Source/qimageuploader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ target_link_libraries(${PROJECT_NAME} Qt5::Widgets)

if(WIN32)
target_link_libraries(${PROJECT_NAME} gdi32 dwmapi)
if (IU_ENABLE_WEBVIEW2)
set_target_properties(${PROJECT_NAME} PROPERTIES VS_GLOBAL_WebView2LoaderPreference "Static")
set_target_properties(${PROJECT_NAME} PROPERTIES VS_USER_PROPS "${CMAKE_SOURCE_DIR}/ImageUploader.Core.props")
set_target_properties(${PROJECT_NAME} PROPERTIES VS_PACKAGE_REFERENCES "${WEBVIEW2_PACKAGES_REFERENCES}")
endif()
endif()

target_link_libraries(qimageuploader iucore iuvideo ${COMMON_LIBS_LIST})

if(WIN32)

add_custom_command(TARGET qimageuploader
POST_BUILD
COMMAND python "${CMAKE_SOURCE_DIR}/../Utils/Version/set_binary_version.py" "${CMAKE_SOURCE_DIR}/versioninfo.h" $<TARGET_FILE:qimageuploader> $<CONFIG>
Expand Down
84 changes: 64 additions & 20 deletions Source/qimageuploader/Gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,21 @@ MainWindow::MainWindow(CUploadEngineList* engineList, LogWindow* logWindow, QWid
ui->treeView->setColumnWidth(1, 150); // Status column
ui->treeView->setColumnWidth(2, 150); // Progress column
ui->treeView->setSelectionBehavior(QAbstractItemView::SelectRows);

connect(ui->treeView, &QTreeView::doubleClicked, this, &MainWindow::itemDoubleClicked);
connect(ui->treeView, &QTreeView::customContextMenuRequested, this, &MainWindow::onCustomContextMenu);

copyDirectLinkAction_ = new QAction(tr("Copy direct link"), this);
copyDirectLinkAction_->setShortcut(QKeySequence::Copy);
connect(copyDirectLinkAction_, &QAction::triggered, this, &MainWindow::onCopyDirectLinkTriggered);

copyFilePathAction_ = new QAction(tr("Copy file path to clipboard"), this);
copyFilePathAction_->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C));
connect(copyFilePathAction_, &QAction::triggered, this, &MainWindow::onCopyFilePathTriggered);

ui->treeView->addAction(copyDirectLinkAction_);
ui->treeView->addAction(copyFilePathAction_);

const ServerProfile imageProfile = settings->imageServer.getByIndex(0);

imageServerWidget_ = new ServerSelectorWidget(uploadEngineManager_.get(), false, this);
Expand Down Expand Up @@ -98,12 +110,12 @@ MainWindow::MainWindow(CUploadEngineList* engineList, LogWindow* logWindow, QWid

iconsLoadingThread_->start();

QMenu* contextMenu = new QMenu(this);
QAction* exitAction = contextMenu->addAction(tr("Exit"));
QMenu* trayContextMenu = new QMenu(this);
QAction* exitAction = trayContextMenu->addAction(tr("Exit"));
connect(exitAction, &QAction::triggered, this, &MainWindow::quitApp);
systemTrayIcon_ = new QSystemTrayIcon(this);
systemTrayIcon_->setIcon(QIcon(":/res/icon_main.ico"));
systemTrayIcon_->setContextMenu(contextMenu);
systemTrayIcon_->setContextMenu(trayContextMenu);
connect(systemTrayIcon_, &QSystemTrayIcon::activated, [&](QSystemTrayIcon::ActivationReason reason) {
if (reason == QSystemTrayIcon::Trigger || reason == QSystemTrayIcon::DoubleClick){
setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
Expand Down Expand Up @@ -299,7 +311,7 @@ void MainWindow::onCustomContextMenu(const QPoint& point) {
if (index.isValid()) {
UploadTreeModel::InternalItem* internalItem = uploadTreeModel_->getInternalItem(index);
QMenu* contextMenu = new QMenu(ui->treeView);
//ui->treeView->setContextMenuPolicy(Qt::ActionsContextMenu);

QAction* viewCodeAction = new QAction(tr("View HTML/BBCode"), contextMenu);

contextMenu->addAction(viewCodeAction);
Expand All @@ -315,19 +327,13 @@ void MainWindow::onCustomContextMenu(const QPoint& point) {
QString viewUrl = QString::fromStdString(uploadResult->getDownloadUrl());

if (!directUrl.isEmpty()) {
QAction* copyDirectLinkAction = new QAction(tr("Copy direct link"), contextMenu);
copyDirectLinkAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
connect(copyDirectLinkAction, &QAction::triggered, [directUrl](bool checked) {
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(directUrl);
});
contextMenu->addAction(copyDirectLinkAction);
contextMenu->addAction(copyDirectLinkAction_);
}

if (!viewUrl.isEmpty()) {
QAction* copyViewLinkAction = new QAction(tr("Copy view link"), contextMenu);
if (directUrl.isEmpty()) {
copyViewLinkAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
copyViewLinkAction->setShortcut(QKeySequence::Copy);
}
connect(copyViewLinkAction, &QAction::triggered, [viewUrl](bool checked) {
QClipboard* clipboard = QApplication::clipboard();
Expand Down Expand Up @@ -355,14 +361,7 @@ void MainWindow::onCustomContextMenu(const QPoint& point) {
QDesktopServices::openUrl("file:///" + fileName);
});
contextMenu->addAction(openInProgram);

QAction* copyPathAction = new QAction(tr("Copy file path to clipboard"), contextMenu);
connect(copyPathAction, &QAction::triggered, [fileName](bool checked)
{
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(fileName);
});
contextMenu->addAction(copyPathAction);
contextMenu->addAction(copyFilePathAction_);
}

}
Expand All @@ -381,6 +380,39 @@ void MainWindow::fillServerIcons() {
fileServerWidget_->fillServerIcons();
}

void MainWindow::onCopyDirectLinkTriggered(bool checked) {
QModelIndex index = getUploadTreeViewSelectedIndex();

if (!index.isValid()) {
return;
}

QString url = ui->treeView->model()->data(index, Qt::UserRole).toString();
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(url);
}

void MainWindow::onCopyFilePathTriggered(bool checked) {
QModelIndex index = getUploadTreeViewSelectedIndex();

if (!index.isValid()) {
return;
}

UploadTreeModel::InternalItem* internalItem = uploadTreeModel_->getInternalItem(index);

if (!internalItem || !internalItem->task) {
return;

}
auto fileTask = std::dynamic_pointer_cast<FileUploadTask>(internalItem->task);

if (fileTask) {
QString fileName = U2Q(fileTask->getFileName());
QApplication::clipboard()->setText(fileName);
}
}

void MainWindow::on_actionAboutProgram_triggered() {
AboutDialog dlg(this);
dlg.setModal(true);
Expand Down Expand Up @@ -415,3 +447,15 @@ void MainWindow::closeEvent(QCloseEvent *event) {
saveOptions();
}

QModelIndex MainWindow::getUploadTreeViewSelectedIndex() {
QItemSelectionModel * selection = ui->treeView->selectionModel();
QModelIndexList indexes = selection->selectedIndexes();

if(indexes.size() < 1) {
return {};
}
std::sort(indexes.begin(), indexes.end());
QModelIndex index = indexes.first();
return index;
}

5 changes: 5 additions & 0 deletions Source/qimageuploader/Gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ private slots:
void onCustomContextMenu(const QPoint &point);
void onShowLog();
void fillServerIcons();
void onCopyDirectLinkTriggered(bool checked);
void onCopyFilePathTriggered(bool checked);
protected:
bool addFileToList(QString fileName);
bool addMultipleFilesToList(QStringList fileNames);
Expand All @@ -55,6 +57,7 @@ private slots:
void quitApp();
void saveOptions();
void closeEvent(QCloseEvent *event) override;
QModelIndex getUploadTreeViewSelectedIndex();
private:
std::unique_ptr<Ui::MainWindow> ui;
UploadTreeModel* uploadTreeModel_;
Expand All @@ -67,6 +70,8 @@ private slots:
LogWindow* logWindow_;
CUploadEngineList* engineList_;
QThread* iconsLoadingThread_{};
QAction* copyDirectLinkAction_ = nullptr;
QAction* copyFilePathAction_ = nullptr;
};

#endif // MAINWINDOW_H
12 changes: 6 additions & 6 deletions Source/qimageuploader/Gui/controls/UploadTreeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ UploadTreeView::UploadTreeView(QWidget *parent): QTreeView(parent) {

void UploadTreeView::keyPressEvent(QKeyEvent * event)
{
if(event->matches(QKeySequence::Copy)) {
copy();
} else {
//if(event->matches(QKeySequence::Copy)) {
// copy();
//} else {
QTreeView::keyPressEvent(event);
}
///}
}

void UploadTreeView::copy() {
QItemSelectionModel * selection = selectionModel();
/*QItemSelectionModel * selection = selectionModel();
QModelIndexList indexes = selection->selectedIndexes();
if(indexes.size() < 1) {
Expand All @@ -29,5 +29,5 @@ void UploadTreeView::copy() {
QModelIndex index = indexes.first();
QString url = model()->data(index, Qt::UserRole).toString();
QApplication::clipboard()->setText(url);
QApplication::clipboard()->setText(url);*/
}

0 comments on commit 4b4ed69

Please sign in to comment.