Skip to content

Commit

Permalink
exp approach 2
Browse files Browse the repository at this point in the history
  • Loading branch information
r3yc0n1c committed Mar 18, 2024
1 parent 0c29709 commit 219f27d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 20 deletions.
65 changes: 46 additions & 19 deletions src/dialogs/VersionInfoDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,55 @@

VersionInfoDialog::VersionInfoDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::VersionInfoDialog), core(Core())
{
{
ui->setupUi(this);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));

// Get version information
fillVersionInfo();

// Setup context menu and actions
copyActionLeftTreewidget = new QAction(tr("Copy"), this);
copyActionLeftTreewidget->setIcon(QIcon(":/img/icons/copy.svg"));
copyActionLeftTreewidget->setShortcut(QKeySequence::StandardKey::Copy);
copyActionLeftTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);

copyActionRightTreewidget = new QAction(tr("Copy"), this);
copyActionRightTreewidget->setIcon(QIcon(":/img/icons/copy.svg"));
copyActionRightTreewidget->setShortcut(QKeySequence::StandardKey::Copy);
copyActionRightTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);

selAllActionLeftTreewidget = new QAction(tr("Select All"), this);
selAllActionLeftTreewidget->setShortcut(QKeySequence::StandardKey::SelectAll);
selAllActionLeftTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);

selAllActionRightTreewidget = new QAction(tr("Select All"), this);
selAllActionRightTreewidget->setShortcut(QKeySequence::StandardKey::SelectAll);
selAllActionRightTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);

connect(copyActionLeftTreewidget, &QAction::triggered, this, [this](){
CopyTreeWidgetSelection(ui->leftTreeWidget);
});

connect(copyActionRightTreewidget, &QAction::triggered, this, [this](){
CopyTreeWidgetSelection(ui->rightTreeWidget);
});

connect(selAllActionLeftTreewidget, &QAction::triggered, this, [this](){
ui->leftTreeWidget->selectAll();
});

connect(selAllActionRightTreewidget, &QAction::triggered, this, [this](){
ui->rightTreeWidget->selectAll();
});

ui->leftTreeWidget->addAction(copyActionLeftTreewidget);
ui->leftTreeWidget->addAction(selAllActionLeftTreewidget);

ui->rightTreeWidget->addAction(copyActionRightTreewidget);
ui->rightTreeWidget->addAction(selAllActionRightTreewidget);

contextMenu = new QMenu(this);
}

VersionInfoDialog::~VersionInfoDialog() {}
Expand All @@ -38,24 +81,8 @@ void VersionInfoDialog::CopyTreeWidgetSelection(QTreeWidget *t)
}

void VersionInfoDialog::contextMenuEvent(QContextMenuEvent *event){
QAction *copyAction = new QAction(tr("Copy"), this);
copyAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
copyAction->setShortcut(QKeySequence::Copy);

connect(copyAction, &QAction::triggered, this, [this](){
if(ui->rightTreeWidget->hasFocus()){
CopyTreeWidgetSelection(ui->rightTreeWidget);
}
else if(ui->leftTreeWidget->hasFocus()){
CopyTreeWidgetSelection(ui->leftTreeWidget);
}
});

QMenu menu(this);
menu.addAction(copyAction);
menu.exec(event->globalPos());

addAction(copyAction);
contextMenu->exec(event->globalPos());
event->accept();
}

void VersionInfoDialog::fillVersionInfo()
Expand Down
8 changes: 7 additions & 1 deletion src/dialogs/VersionInfoDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ class VersionInfoDialog : public QDialog
Q_OBJECT

public:
explicit VersionInfoDialog(QWidget *parent = nullptr);
explicit VersionInfoDialog(QWidget *parent = nullptr);
~VersionInfoDialog();

private slots:
void CopyTreeWidgetSelection(QTreeWidget *t);

protected:
QMenu *contextMenu = nullptr;
QAction *copyActionLeftTreewidget = nullptr;
QAction *copyActionRightTreewidget = nullptr;
QAction *selAllActionLeftTreewidget = nullptr;
QAction *selAllActionRightTreewidget = nullptr;

void contextMenuEvent(QContextMenuEvent *event) override;

private:
Expand Down
6 changes: 6 additions & 0 deletions src/dialogs/VersionInfoDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTreeWidget" name="leftTreeWidget">
<property name="contextMenuPolicy">
<enum>Qt::ActionsContextMenu</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
Expand Down Expand Up @@ -106,6 +109,9 @@
</item>
<item>
<widget class="QTreeWidget" name="rightTreeWidget">
<property name="contextMenuPolicy">
<enum>Qt::ActionsContextMenu</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
Expand Down

0 comments on commit 219f27d

Please sign in to comment.