Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Keyboard shortcuts #128

Merged
merged 6 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ui/command_tab_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "command_buffer_model.h"
#include "command_buffer_view.h"
#include "search_dialog.h"
#include "shortcuts.h"

#include "dive_core/command_hierarchy.h"

Expand Down
71 changes: 65 additions & 6 deletions ui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
#include "property_panel.h"
#include "search_dialog.h"
#include "shader_view.h"
#include "shortcuts.h"
#include "shortcuts_window.h"
#include "text_file_view.h"
#include "tree_view_combo_box.h"

Expand Down Expand Up @@ -191,10 +193,10 @@ MainWindow::MainWindow()
m_overview_tab_view = new OverviewTabView(m_data_core->GetCaptureMetadata(),
*m_event_selection);
m_event_state_view = new EventStateView(*m_data_core);
m_tab_widget->addTab(m_overview_tab_view, "Overview");
m_overview_view_tab_index = m_tab_widget->addTab(m_overview_tab_view, "Overview");

m_tab_widget->addTab(m_command_tab_view, "Commands");
m_shader_view_index = m_tab_widget->addTab(m_shader_view, "Shaders");
m_command_view_tab_index = m_tab_widget->addTab(m_command_tab_view, "Commands");
m_shader_view_tab_index = m_tab_widget->addTab(m_shader_view, "Shaders");
m_event_state_view_tab_index = m_tab_widget->addTab(m_event_state_view, "Event State");
#if defined(ENABLE_CAPTURE_BUFFERS)
m_buffer_view = new BufferView(*m_data_core);
Expand Down Expand Up @@ -322,6 +324,7 @@ MainWindow::MainWindow()
CreateActions();
CreateMenus();
CreateStatusBar();
CreateShortcuts();
CreateToolBars();
UpdateRecentFileActions(Settings::Get()->ReadRecentFiles());

Expand Down Expand Up @@ -694,6 +697,13 @@ void MainWindow::OnAbout()
about->exec();
}

//--------------------------------------------------------------------------------------------------
void MainWindow::OnShortcuts()
{
ShortcutsDialog *shortcuts = new ShortcutsDialog();
wangra-google marked this conversation as resolved.
Show resolved Hide resolved
shortcuts->exec();
}

//--------------------------------------------------------------------------------------------------
void MainWindow::closeEvent(QCloseEvent *closeEvent)
{
Expand Down Expand Up @@ -892,6 +902,11 @@ void MainWindow::CreateActions()
m_capture_delay_action->setShortcut(QKeySequence("Ctrl+f5"));
connect(m_capture_delay_action, &QAction::triggered, this, &MainWindow::OnCaptureTrigger);

// Shortcuts action
m_shortcuts_action = new QAction(tr("&Shortcuts"), this);
m_shortcuts_action->setStatusTip(tr("Display application keyboard shortcuts"));
connect(m_shortcuts_action, &QAction::triggered, this, &MainWindow::OnShortcuts);
GrantComm marked this conversation as resolved.
Show resolved Hide resolved

// About action
m_about_action = new QAction(tr("&About Dive"), this);
m_about_action->setStatusTip(tr("Display application version information"));
Expand All @@ -917,6 +932,7 @@ void MainWindow::CreateMenus()
m_capture_menu->addAction(m_capture_action);

m_help_menu = menuBar()->addMenu(tr("&Help"));
m_help_menu->addAction(m_shortcuts_action);
m_help_menu->addAction(m_about_action);
}

Expand All @@ -943,6 +959,49 @@ void MainWindow::CreateToolBars()
m_file_tool_bar->addWidget(m_capture_button);
}

//--------------------------------------------------------------------------------------------------
void MainWindow::CreateShortcuts()
{
// Search Shortcut
QShortcut *searchShortcut = new QShortcut(QKeySequence(SHORTCUT_EVENTS_SEARCH), this);
connect(searchShortcut, &QShortcut::activated, this, &MainWindow::OnSearchTrigger);

// Commands Search Shortcut
QShortcut *searchCommandsShortcut = new QShortcut(QKeySequence(SHORTCUT_COMMANDS_SEARCH), this);
connect(searchCommandsShortcut, &QShortcut::activated, [this]() {
if (m_tab_widget->currentIndex() == m_command_view_tab_index)
{
m_command_tab_view->OnSearchCommandBuffer();
}
else
{
m_tab_widget->setCurrentIndex(m_command_view_tab_index);
m_command_tab_view->OnSearchCommandBuffer();
}
});

// Overview Shortcut
QShortcut *overviewTabShortcut = new QShortcut(QKeySequence(SHORTCUT_OVERVIEW_TAB), this);
connect(overviewTabShortcut, &QShortcut::activated, [this]() {
m_tab_widget->setCurrentIndex(m_overview_view_tab_index);
});
// Commands Shortcut
QShortcut *commandTabShortcut = new QShortcut(QKeySequence(SHORTCUT_COMMANDS_TAB), this);
connect(commandTabShortcut, &QShortcut::activated, [this]() {
m_tab_widget->setCurrentIndex(m_command_view_tab_index);
});
// Shaders Shortcut
QShortcut *shaderTabShortcut = new QShortcut(QKeySequence(SHORTCUT_SHADERS_TAB), this);
connect(shaderTabShortcut, &QShortcut::activated, [this]() {
m_tab_widget->setCurrentIndex(m_shader_view_tab_index);
});
// Event State Shortcut
QShortcut *eventStateTabShortcut = new QShortcut(QKeySequence(SHORTCUT_EVENT_STATE_TAB), this);
connect(eventStateTabShortcut, &QShortcut::activated, [this]() {
m_tab_widget->setCurrentIndex(m_event_state_view_tab_index);
});
}

//--------------------------------------------------------------------------------------------------
void MainWindow::CreateStatusBar()
{
Expand Down Expand Up @@ -1054,7 +1113,7 @@ void MainWindow::OnCrossReference(Dive::CrossRef ref)
{
case Dive::CrossRefType::kShaderAddress:
if (m_shader_view->OnCrossReference(ref))
m_tab_widget->setCurrentIndex(m_shader_view_index);
m_tab_widget->setCurrentIndex(m_shader_view_tab_index);
break;
case Dive::CrossRefType::kGFRIndex: m_command_hierarchy_view->setCurrentNode(ref.Id()); break;
default:
Expand All @@ -1075,6 +1134,6 @@ void MainWindow::OnFileLoaded()
//--------------------------------------------------------------------------------------------------
void MainWindow::OnSwitchToShaderTab()
{
DIVE_ASSERT(m_shader_view_index >= 0);
m_tab_widget->setCurrentIndex(m_shader_view_index);
DIVE_ASSERT(m_shader_view_tab_index >= 0);
m_tab_widget->setCurrentIndex(m_shader_view_tab_index);
}
7 changes: 6 additions & 1 deletion ui/main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private slots:
void OnCaptureTrigger();
void OnExpandToLevel();
void OnAbout();
void OnShortcuts();
void OnSaveCapture();
void OnSearchTrigger();
void OnCheckboxStateChanged(int state);
Expand All @@ -96,6 +97,7 @@ private slots:
void CreateActions();
void CreateMenus();
void CreateToolBars();
void CreateShortcuts();
void CreateStatusBar();
void ShowTempStatus(const QString &status_message);
void ExpandResizeHierarchyView();
Expand All @@ -118,6 +120,7 @@ private slots:
QAction *m_capture_setting_action;
QMenu *m_help_menu;
QAction *m_about_action;
QAction *m_shortcuts_action;
QToolBar *m_file_tool_bar;
TraceDialog *m_trace_dig;

Expand Down Expand Up @@ -156,9 +159,11 @@ private slots:
// Right pane
QTabWidget *m_tab_widget;
CommandTabView *m_command_tab_view;
int m_command_view_tab_index;
OverviewTabView *m_overview_tab_view;
int m_overview_view_tab_index;
ShaderView *m_shader_view;
int m_shader_view_index;
int m_shader_view_tab_index;
EventStateView *m_event_state_view;
int m_event_state_view_tab_index;
#if defined(ENABLE_CAPTURE_BUFFERS)
Expand Down
15 changes: 14 additions & 1 deletion ui/search_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
#include "QPushButton"
#include "QShortcut"
#include "QVBoxLayout"
#include "shortcuts.h"

//--------------------------------------------------------------------------------------------------
SearchDialog::SearchDialog(QWidget* parent, const QString& title) : QDialog(parent)
SearchDialog::SearchDialog(QWidget* parent, const QString& title) :
QDialog(parent)

{
m_input = new QLineEdit;
Expand All @@ -37,6 +39,17 @@ SearchDialog::SearchDialog(QWidget* parent, const QString& title) : QDialog(pare
connect(m_prev, SIGNAL(clicked()), this, SLOT(prevSearchedItem()));
connect(m_next, SIGNAL(clicked()), this, SLOT(nextSearchedItem()));

QShortcut* previousSearchItemShortcut = new QShortcut(QKeySequence(
SHORTCUT_PREVIOUS_SEARCH_RESULT),
this);
connect(previousSearchItemShortcut,
&QShortcut::activated,
this,
&SearchDialog::prevSearchedItem);

QShortcut* nextSearchShortcut = new QShortcut(QKeySequence(SHORTCUT_NEXT_SEARCH_RESULT), this);
connect(nextSearchShortcut, &QShortcut::activated, this, &SearchDialog::nextSearchedItem);

QHBoxLayout* search_buttons_layout = new QHBoxLayout;
search_buttons_layout->addWidget(m_input);
search_buttons_layout->addWidget(m_search);
Expand Down
24 changes: 24 additions & 0 deletions ui/shortcuts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright 2024 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#define SHORTCUT_EVENTS_SEARCH "Ctrl+F"
#define SHORTCUT_COMMANDS_SEARCH "Ctrl+Shift+F"
#define SHORTCUT_NEXT_SEARCH_RESULT "Ctrl+Shift+N"
#define SHORTCUT_PREVIOUS_SEARCH_RESULT "Ctrl+Shift+P"
#define SHORTCUT_OVERVIEW_TAB "Ctrl+Shift+O"
#define SHORTCUT_COMMANDS_TAB "Ctrl+Shift+C"
#define SHORTCUT_SHADERS_TAB "Ctrl+Shift+H"
#define SHORTCUT_EVENT_STATE_TAB "Ctrl+Shift+E"
96 changes: 96 additions & 0 deletions ui/shortcuts_window.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
Copyright 2024 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "shortcuts_window.h"
#include <qfont.h>
#include <qlabel.h>
#include <QCoreApplication>
#include <QDir>
#include <QFile>
#include <QHBoxLayout>
#include <QIcon>
#include <QLabel>
#include <QPixmap>
#include <QPlainTextEdit>
#include <QPushButton>
#include <QSizePolicy>
#include <QVBoxLayout>
#include <iostream>
#include <sstream>
#include "shortcuts.h"

// =================================================================================================
// ShortcutsDialog
// =================================================================================================

ShortcutsDialog::ShortcutsDialog(QWidget *parent)
{
// Build shortcuts string
std::ostringstream os;
os << "Begin an Events Search: ";
os << SHORTCUT_EVENTS_SEARCH << std::endl;
os << std::endl;
os << "Begin a Commands Search: ";
os << SHORTCUT_COMMANDS_SEARCH << std::endl;
os << std::endl;
os << "View the next search result: ";
os << SHORTCUT_NEXT_SEARCH_RESULT << std::endl;
os << std::endl;
os << "View the previous search result: ";
os << SHORTCUT_PREVIOUS_SEARCH_RESULT << std::endl;
os << std::endl;
os << "View the Overview tab: ";
os << SHORTCUT_OVERVIEW_TAB << std::endl;
os << std::endl;
os << "View the Commands tab: ";
os << SHORTCUT_COMMANDS_TAB << std::endl;
os << std::endl;
os << "View the Shaders tab: ";
os << SHORTCUT_SHADERS_TAB << std::endl;
os << std::endl;
os << "View the Event State tab: ";
os << SHORTCUT_EVENT_STATE_TAB << std::endl;
os << std::endl;
m_shortcut_information = new QLabel(os.str().c_str());

// Set the font for the shortcuts string
QFont font = m_shortcut_information->font();
font.setBold(true);

// Shortcuts layout is shortcut Info
m_shortcuts_layout = new QHBoxLayout;
m_shortcuts_layout->addWidget(m_shortcut_information);

// Close button
m_close_button = new QPushButton;
m_close_button->setText("Close");
connect(m_close_button, SIGNAL(clicked()), this, SLOT(close()));

m_button_layout = new QHBoxLayout;
m_button_layout->addStretch();
m_button_layout->addWidget(m_close_button);

// Main layout is Shortcuts + Close Button
m_main_layout = new QVBoxLayout;
m_main_layout->addLayout(m_shortcuts_layout);
m_main_layout->setAlignment(m_shortcuts_layout, Qt::AlignCenter);
m_main_layout->addLayout(m_button_layout);

// Disable help icon, set size, title, and layout
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setMinimumSize(640, 480);
setWindowTitle("Dive Keyboard Shortcuts");
setLayout(m_main_layout);
}
42 changes: 42 additions & 0 deletions ui/shortcuts_window.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2024 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <QDialog>

#pragma once

// Forward declarations
class QLabel;
class QHBoxLayout;
class QPlainTextEdit;
class QPushButton;
class QVBoxLayout;

class ShortcutsDialog : public QDialog
{
Q_OBJECT

public:
ShortcutsDialog(QWidget *parent = 0);

private:
QLabel *m_shortcut_information; // The shortcut info.
QPushButton *m_close_button; // A button to close the dialog.
QHBoxLayout
*m_shortcuts_layout; // The shortcuts layout is the shortcut info arranged horizontally
QHBoxLayout *m_button_layout; // The button layout is stretch + Close Button
QVBoxLayout *m_main_layout; // The main layout Shortcuts + Close button arranged vertically
};
Loading