Skip to content

Commit 4b4ed69

Browse files
committed
qimageuploader: refactor UploadTreeView keyboard shortcuts
1 parent 78718f6 commit 4b4ed69

File tree

4 files changed

+81
-26
lines changed

4 files changed

+81
-26
lines changed

Source/qimageuploader/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,17 @@ target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
7373

7474
if(WIN32)
7575
target_link_libraries(${PROJECT_NAME} gdi32 dwmapi)
76+
if (IU_ENABLE_WEBVIEW2)
77+
set_target_properties(${PROJECT_NAME} PROPERTIES VS_GLOBAL_WebView2LoaderPreference "Static")
78+
set_target_properties(${PROJECT_NAME} PROPERTIES VS_USER_PROPS "${CMAKE_SOURCE_DIR}/ImageUploader.Core.props")
79+
set_target_properties(${PROJECT_NAME} PROPERTIES VS_PACKAGE_REFERENCES "${WEBVIEW2_PACKAGES_REFERENCES}")
80+
endif()
7681
endif()
7782

7883
target_link_libraries(qimageuploader iucore iuvideo ${COMMON_LIBS_LIST})
7984

8085
if(WIN32)
86+
8187
add_custom_command(TARGET qimageuploader
8288
POST_BUILD
8389
COMMAND python "${CMAKE_SOURCE_DIR}/../Utils/Version/set_binary_version.py" "${CMAKE_SOURCE_DIR}/versioninfo.h" $<TARGET_FILE:qimageuploader> $<CONFIG>

Source/qimageuploader/Gui/MainWindow.cpp

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,21 @@ MainWindow::MainWindow(CUploadEngineList* engineList, LogWindow* logWindow, QWid
6666
ui->treeView->setColumnWidth(1, 150); // Status column
6767
ui->treeView->setColumnWidth(2, 150); // Progress column
6868
ui->treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
69+
6970
connect(ui->treeView, &QTreeView::doubleClicked, this, &MainWindow::itemDoubleClicked);
7071
connect(ui->treeView, &QTreeView::customContextMenuRequested, this, &MainWindow::onCustomContextMenu);
7172

73+
copyDirectLinkAction_ = new QAction(tr("Copy direct link"), this);
74+
copyDirectLinkAction_->setShortcut(QKeySequence::Copy);
75+
connect(copyDirectLinkAction_, &QAction::triggered, this, &MainWindow::onCopyDirectLinkTriggered);
76+
77+
copyFilePathAction_ = new QAction(tr("Copy file path to clipboard"), this);
78+
copyFilePathAction_->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C));
79+
connect(copyFilePathAction_, &QAction::triggered, this, &MainWindow::onCopyFilePathTriggered);
80+
81+
ui->treeView->addAction(copyDirectLinkAction_);
82+
ui->treeView->addAction(copyFilePathAction_);
83+
7284
const ServerProfile imageProfile = settings->imageServer.getByIndex(0);
7385

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

99111
iconsLoadingThread_->start();
100112

101-
QMenu* contextMenu = new QMenu(this);
102-
QAction* exitAction = contextMenu->addAction(tr("Exit"));
113+
QMenu* trayContextMenu = new QMenu(this);
114+
QAction* exitAction = trayContextMenu->addAction(tr("Exit"));
103115
connect(exitAction, &QAction::triggered, this, &MainWindow::quitApp);
104116
systemTrayIcon_ = new QSystemTrayIcon(this);
105117
systemTrayIcon_->setIcon(QIcon(":/res/icon_main.ico"));
106-
systemTrayIcon_->setContextMenu(contextMenu);
118+
systemTrayIcon_->setContextMenu(trayContextMenu);
107119
connect(systemTrayIcon_, &QSystemTrayIcon::activated, [&](QSystemTrayIcon::ActivationReason reason) {
108120
if (reason == QSystemTrayIcon::Trigger || reason == QSystemTrayIcon::DoubleClick){
109121
setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
@@ -299,7 +311,7 @@ void MainWindow::onCustomContextMenu(const QPoint& point) {
299311
if (index.isValid()) {
300312
UploadTreeModel::InternalItem* internalItem = uploadTreeModel_->getInternalItem(index);
301313
QMenu* contextMenu = new QMenu(ui->treeView);
302-
//ui->treeView->setContextMenuPolicy(Qt::ActionsContextMenu);
314+
303315
QAction* viewCodeAction = new QAction(tr("View HTML/BBCode"), contextMenu);
304316

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

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

327333
if (!viewUrl.isEmpty()) {
328334
QAction* copyViewLinkAction = new QAction(tr("Copy view link"), contextMenu);
329335
if (directUrl.isEmpty()) {
330-
copyViewLinkAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
336+
copyViewLinkAction->setShortcut(QKeySequence::Copy);
331337
}
332338
connect(copyViewLinkAction, &QAction::triggered, [viewUrl](bool checked) {
333339
QClipboard* clipboard = QApplication::clipboard();
@@ -355,14 +361,7 @@ void MainWindow::onCustomContextMenu(const QPoint& point) {
355361
QDesktopServices::openUrl("file:///" + fileName);
356362
});
357363
contextMenu->addAction(openInProgram);
358-
359-
QAction* copyPathAction = new QAction(tr("Copy file path to clipboard"), contextMenu);
360-
connect(copyPathAction, &QAction::triggered, [fileName](bool checked)
361-
{
362-
QClipboard* clipboard = QApplication::clipboard();
363-
clipboard->setText(fileName);
364-
});
365-
contextMenu->addAction(copyPathAction);
364+
contextMenu->addAction(copyFilePathAction_);
366365
}
367366

368367
}
@@ -381,6 +380,39 @@ void MainWindow::fillServerIcons() {
381380
fileServerWidget_->fillServerIcons();
382381
}
383382

383+
void MainWindow::onCopyDirectLinkTriggered(bool checked) {
384+
QModelIndex index = getUploadTreeViewSelectedIndex();
385+
386+
if (!index.isValid()) {
387+
return;
388+
}
389+
390+
QString url = ui->treeView->model()->data(index, Qt::UserRole).toString();
391+
QClipboard* clipboard = QApplication::clipboard();
392+
clipboard->setText(url);
393+
}
394+
395+
void MainWindow::onCopyFilePathTriggered(bool checked) {
396+
QModelIndex index = getUploadTreeViewSelectedIndex();
397+
398+
if (!index.isValid()) {
399+
return;
400+
}
401+
402+
UploadTreeModel::InternalItem* internalItem = uploadTreeModel_->getInternalItem(index);
403+
404+
if (!internalItem || !internalItem->task) {
405+
return;
406+
407+
}
408+
auto fileTask = std::dynamic_pointer_cast<FileUploadTask>(internalItem->task);
409+
410+
if (fileTask) {
411+
QString fileName = U2Q(fileTask->getFileName());
412+
QApplication::clipboard()->setText(fileName);
413+
}
414+
}
415+
384416
void MainWindow::on_actionAboutProgram_triggered() {
385417
AboutDialog dlg(this);
386418
dlg.setModal(true);
@@ -415,3 +447,15 @@ void MainWindow::closeEvent(QCloseEvent *event) {
415447
saveOptions();
416448
}
417449

450+
QModelIndex MainWindow::getUploadTreeViewSelectedIndex() {
451+
QItemSelectionModel * selection = ui->treeView->selectionModel();
452+
QModelIndexList indexes = selection->selectedIndexes();
453+
454+
if(indexes.size() < 1) {
455+
return {};
456+
}
457+
std::sort(indexes.begin(), indexes.end());
458+
QModelIndex index = indexes.first();
459+
return index;
460+
}
461+

Source/qimageuploader/Gui/MainWindow.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ private slots:
4747
void onCustomContextMenu(const QPoint &point);
4848
void onShowLog();
4949
void fillServerIcons();
50+
void onCopyDirectLinkTriggered(bool checked);
51+
void onCopyFilePathTriggered(bool checked);
5052
protected:
5153
bool addFileToList(QString fileName);
5254
bool addMultipleFilesToList(QStringList fileNames);
@@ -55,6 +57,7 @@ private slots:
5557
void quitApp();
5658
void saveOptions();
5759
void closeEvent(QCloseEvent *event) override;
60+
QModelIndex getUploadTreeViewSelectedIndex();
5861
private:
5962
std::unique_ptr<Ui::MainWindow> ui;
6063
UploadTreeModel* uploadTreeModel_;
@@ -67,6 +70,8 @@ private slots:
6770
LogWindow* logWindow_;
6871
CUploadEngineList* engineList_;
6972
QThread* iconsLoadingThread_{};
73+
QAction* copyDirectLinkAction_ = nullptr;
74+
QAction* copyFilePathAction_ = nullptr;
7075
};
7176

7277
#endif // MAINWINDOW_H

Source/qimageuploader/Gui/controls/UploadTreeView.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ UploadTreeView::UploadTreeView(QWidget *parent): QTreeView(parent) {
1111

1212
void UploadTreeView::keyPressEvent(QKeyEvent * event)
1313
{
14-
if(event->matches(QKeySequence::Copy)) {
15-
copy();
16-
} else {
14+
//if(event->matches(QKeySequence::Copy)) {
15+
// copy();
16+
//} else {
1717
QTreeView::keyPressEvent(event);
18-
}
18+
///}
1919
}
2020

2121
void UploadTreeView::copy() {
22-
QItemSelectionModel * selection = selectionModel();
22+
/*QItemSelectionModel * selection = selectionModel();
2323
QModelIndexList indexes = selection->selectedIndexes();
2424
2525
if(indexes.size() < 1) {
@@ -29,5 +29,5 @@ void UploadTreeView::copy() {
2929
QModelIndex index = indexes.first();
3030
3131
QString url = model()->data(index, Qt::UserRole).toString();
32-
QApplication::clipboard()->setText(url);
32+
QApplication::clipboard()->setText(url);*/
3333
}

0 commit comments

Comments
 (0)