diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e5003aa --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +*~ +*.pyc +*.orig +*.swp +__pycache__/ +test/build/linux +test/build/mac +test/build/win +.vscode +*.aps +.DS_Store +.idea/ +.vs/ +out/ +cmake-build*/ +source/version.h +Buildinfo.properties +CMakeSettings.json \ No newline at end of file diff --git a/Buildinfo.properties.in b/Buildinfo.properties.in new file mode 100644 index 0000000..538418b --- /dev/null +++ b/Buildinfo.properties.in @@ -0,0 +1,2 @@ +BUILD_NUMBER=@QTCOMMON_BUILD_NUMBER@ +VERSION_NUMBER=@QTCOMMON_MAJOR_VERSION@.@QTCOMMON_MINOR_VERSION@ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c09e27..b27df47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,53 @@ -cmake_minimum_required(VERSION 3.11) +cmake_minimum_required(VERSION 3.24) project(QtCommon) +# Define version information +set(QTCOMMON_MAJOR_VERSION 3) +set(QTCOMMON_MINOR_VERSION 12) +if (NOT QTCOMMON_PATCH_NUMBER) + set(QTCOMMON_PATCH_NUMBER 0) +endif () +if (NOT QTCOMMON_BUILD_NUMBER) + set(QTCOMMON_BUILD_NUMBER 0) +endif () +string(TIMESTAMP DATE "\"%m/%d/%Y\"") +string(TIMESTAMP YEAR "\"%Y\"") + +# Check if top-level project before attempting to query Qt dependencies +# This allows for consuming projects to override the Qt version used such as using +# Qt6 instead of Qt5 +if (PROJECT_IS_TOP_LEVEL) + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + include(dev_tools) + include(devtools_qt_helper) +endif () + +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Buildinfo.properties.in" "${CMAKE_CURRENT_SOURCE_DIR}/Buildinfo.properties") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/source/version.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/source/version.h") + # Custom Widgets -add_subdirectory(custom_widgets) +add_subdirectory(source/qt_common/custom_widgets) # Utilities -add_subdirectory(utils) \ No newline at end of file +add_subdirectory(source/qt_common/utils) + +if (BUILD_TESTS) + # Tests + add_subdirectory(test) +endif () + +# Packaging +set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) +set(CPACK_COMPONENTS_GROUPING IGNORE) + +if (${CMAKE_BUILD_TYPE} MATCHES "Debug") + set(CPACK_ARCHIVE_GUITEST_FILE_NAME "QtCommon_GuiTest_Debug-${QTCOMMON_MAJOR_VERSION}.${QTCOMMON_MINOR_VERSION}.${QTCOMMON_PATCH_NUMBER}.${QTCOMMON_BUILD_NUMBER}") +else () + set(CPACK_ARCHIVE_GUITEST_FILE_NAME "QtCommon_GuiTest_${QTCOMMON_MAJOR_VERSION}.${QTCOMMON_MINOR_VERSION}.${QTCOMMON_PATCH_NUMBER}.${QTCOMMON_BUILD_NUMBER}") +endif () + +include(CPack) + +cpack_add_component(GuiTest + DISPLAY_NAME "Gui Test" + DESCRIPTION "QtCommon Gui Tests") \ No newline at end of file diff --git a/cmake/dev_tools.cmake b/cmake/dev_tools.cmake new file mode 100644 index 0000000..356f447 --- /dev/null +++ b/cmake/dev_tools.cmake @@ -0,0 +1,77 @@ +####################################################################################################################### +### Copyright (c) 2019-2023 Advanced Micro Devices, Inc. All rights reserved. +### \author AMD Developer Tools Team +####################################################################################################################### + +cmake_minimum_required(VERSION 3.10) + +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + string(REPLACE " /W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +endif () + +# Apply options to a developer tools target. +# These options are hard requirements to build. If they cannot be applied, we +# will need to fix the offending target to ensure it complies. +function(devtools_target_options name) + + set_target_properties(${name} PROPERTIES + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED ON) + + get_target_property(target_type ${name} TYPE) + if (${target_type} STREQUAL "INTERFACE_LIBRARY") + return() + endif () + + if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang") + + target_compile_options(${name} + PRIVATE + -Wall + -Werror + -Wextra + -Wno-unused-variable + -Wno-missing-field-initializers + -Wno-unknown-pragmas + ) + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + target_compile_options(${name} + PRIVATE + /W4 + /WX + /MP + + # disable warning C4201: nonstandard extension used: nameless struct/union + /wd4201 + + # TODO this warning is caused by the QT header files - use pragma to disable at source + # disable warning C4127: conditional expression is constant + /wd4127 + + # Disable warnings about deprecated features + # See: https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996?view=vs-2019 + # This happens when using later versions of Qt than RDP defaults to. + /wd4996 + ) + else () + + message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER_ID} is not supported!") + + endif () + + # GNU specific flags + if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + target_compile_options(${name} PRIVATE -Wno-maybe-uninitialized) + endif () + + if (UNIX AND NOT APPLE) + target_compile_definitions(${name} + PRIVATE + _LINUX + + # Use _DEBUG on Unix for Debug Builds (defined automatically on Windows) + $<$:_DEBUG> + ) + endif () + +endfunction() diff --git a/cmake/devtools_qt_helper.cmake b/cmake/devtools_qt_helper.cmake new file mode 100644 index 0000000..ed853d3 --- /dev/null +++ b/cmake/devtools_qt_helper.cmake @@ -0,0 +1,152 @@ +####################################################################################################################### +### Copyright (c) 2019-2021 Advanced Micro Devices, Inc. All rights reserved. +### @author AMD Developer Tools Team +####################################################################################################################### + +cmake_minimum_required(VERSION 3.10) + +# linuxdeployqt +if (UNIX AND NOT APPLE) + include(FetchContent) + FetchContent_Declare( + linuxdeployqt + URL "http://bdcartifactory.amd.com/artifactory/DevToolsBDC/Assets/radeon_developer_panel/linuxdeployqt.zip" + SOURCE_DIR ${PROJECT_SOURCE_DIR}/external/linuxdeployqt + ) + FetchContent_MakeAvailable(linuxdeployqt) + + find_program(LINUXDEPLOYQT "linuxdeployqt" HINTS "${PROJECT_SOURCE_DIR}/external/linuxdeployqt") + if (LINUXDEPLOYQT) + message(STATUS "Found linuxdeployqt: ${LINUXDEPLOYQT}") + else () + message(ERROR "linuxdeployqt not found but is required for build") + endif () +endif () + +# Attempt to automatically find Qt on the local machine +if (UNIX AND NOT APPLE) + find_package(Qt6 QUIET COMPONENTS Core Widgets Network Gui Test GuiPrivate) +else () + find_package(Qt6 QUIET COMPONENTS Core Widgets Network Gui Test) +endif () + +if (Qt6_DIR) + message(STATUS "Qt6 cmake package found at ${Qt6_DIR}") +endif () + +if (NOT Qt6_DIR) + # Attempt to query Qt 5 + if (UNIX AND NOT APPLE) + find_package(Qt5 QUIET COMPONENTS Core Widgets Network Gui Test X11Extras) + else () + find_package(Qt5 QUIET COMPONENTS Core Widgets Network Gui Test) + endif () + + if (Qt5_DIR) + message(STATUS "Qt5 cmake package found at ${Qt5_DIR}") + else () + message(WARNING "Qt5 cmake package not found. Please specify Qt5_DIR manually or in the CMAKE_PREFIX_PATH") + endif () +endif () + + + +if (Qt5_DIR OR Qt6_DIR) + ####################################################################################################################### + # Setup the INSTALL target to include Qt DLLs + ## + # Logic used to find and use Qt's internal deployment tool to copy Qt-based dependencies and DLLs upon building, so + # that we can run the application from an IDE and so that we just have a simple build directory with all dependencies + # already deployed that we can easily distribute + ####################################################################################################################### + get_target_property(_qmake_executable Qt::qmake IMPORTED_LOCATION) + get_filename_component(_qt_bin_dir "${_qmake_executable}" DIRECTORY) + if (WIN32) + find_program(DEPLOYQT_EXECUTABLE windeployqt HINTS "${_qt_bin_dir}") + elseif (APPLE) + find_program(DEPLOYQT_EXECUTABLE macdeployqt HINTS "${_qt_bin_dir}") + elseif (UNIX) + find_program(QT_QMAKE_EXECUTABLE qmake HINTS "${_qt_bin_dir}") + set(DEPLOYQT_EXECUTABLE ${LINUXDEPLOYQT}) + endif () + + function(deploy_qt_build target include_mac) + if (DEPLOYQT_EXECUTABLE) + if (WIN32) + if (Qt6_DIR) + set(DEPLOYQT_POST_BUILD_COMMAND + ${DEPLOYQT_EXECUTABLE} $ -verbose 0 --release --no-compiler-runtime --no-translations + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) + else () + set(DEPLOYQT_POST_BUILD_COMMAND + ${DEPLOYQT_EXECUTABLE} $ -verbose 0 --no-compiler-runtime --no-translations --no-angle --no-system-d3d-compiler --no-opengl-sw + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) + endif () + elseif (UNIX AND NOT APPLE) + set(DEPLOYQT_POST_BUILD_COMMAND + ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH=${EXTERNAL_DIR}/libtraceevent/lib:${EXTERNAL_DIR}/libtracefs/lib + ${DEPLOYQT_EXECUTABLE} $ -qmake=${QT_QMAKE_EXECUTABLE} -verbose=0 -unsupported-allow-new-glibc + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) + elseif (include_mac) + set(DEPLOYQT_POST_BUILD_COMMAND + ${DEPLOYQT_EXECUTABLE} $.app -verbose=0 -no-strip + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) + endif () + + # Deploy Qt to build directory after a successful build + add_custom_command( + TARGET ${target} POST_BUILD + COMMAND ${DEPLOYQT_POST_BUILD_COMMAND} + ) + endif () + endfunction() + + function(deploy_qt_install_hook target component) + if (DEPLOYQT_EXECUTABLE) + deploy_qt_build(${target} TRUE) + + set(target_file_dir "$") + + # Handle installation of Qt dependencies + if (WIN32) + # Debug dlls end with a `d.dll` + set(qt_suffix "$<$:d>.dll") + + # Due to windows requiring DLLs be shipped adjacent we must be explicit here... + # TODO: Maybe eventually we could look into some sort of manifest file? + install(FILES + ${target_file_dir}/Qt5Core${qt_suffix} + ${target_file_dir}/Qt5Gui${qt_suffix} + ${target_file_dir}/Qt5Svg${qt_suffix} + ${target_file_dir}/Qt5Widgets${qt_suffix} + DESTINATION . COMPONENT ${component}) + + install(FILES ${target_file_dir}/Qt5Network${qt_suffix} DESTINATION . COMPONENT ${component} OPTIONAL) + + install(DIRECTORY ${target_file_dir}/iconengines DESTINATION . COMPONENT ${component}) + install(DIRECTORY ${target_file_dir}/imageformats DESTINATION . COMPONENT ${component}) + install(DIRECTORY ${target_file_dir}/platforms DESTINATION . COMPONENT ${component}) + install(DIRECTORY ${target_file_dir}/styles DESTINATION . COMPONENT ${component}) + elseif (UNIX AND NOT APPLE) + # This is only needed for Linux as Apple platforms deploy Qt into the app bundle + install(FILES + ${target_file_dir}/qt.conf + DESTINATION . COMPONENT ${component}) + install(DIRECTORY ${target_file_dir}/lib DESTINATION . COMPONENT ${component}) + install(DIRECTORY ${target_file_dir}/plugins DESTINATION . COMPONENT ${component}) + endif () + + else () + message(FATAL_ERROR "Qt deployment executable not found.") + endif () + endfunction() + + # Apply Qt-project specific options + # Currently, this is only used for an issue with Clang on Windows + function(DevDriverApplyQtOptions target) + # WA: On Windows with Clang, we need rtti to compile. - August 2019 + iF (WIN32 AND ${CMAKE_CXX_COMPILER_ID} MATCHES " Clang ") + target_compile_options(${target} PUBLIC -frtti) + endif () + endfunction() +endif () diff --git a/custom_widgets/CMakeLists.txt b/source/qt_common/custom_widgets/CMakeLists.txt similarity index 88% rename from custom_widgets/CMakeLists.txt rename to source/qt_common/custom_widgets/CMakeLists.txt index 1bd3258..c870edc 100644 --- a/custom_widgets/CMakeLists.txt +++ b/source/qt_common/custom_widgets/CMakeLists.txt @@ -1,16 +1,9 @@ -cmake_minimum_required (VERSION 3.5.1) -project (QtCustomWidgets) - -set (QTCUSTOMWIDGETS_VERSION_MAJOR 1) -set (QTCUSTOMWIDGETS_VERSION_MINOR 0) +cmake_minimum_required (VERSION 3.24) # Build Qt .ui MOC files for the library. set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) -# Find Qt libraries to resolve dependencies. -find_package(Qt5 COMPONENTS Widgets Gui REQUIRED) - # Add all header and source files within the directory to the library. file (GLOB CPP_INC "arrow_icon_combo_box.h" @@ -58,6 +51,7 @@ file (GLOB CPP_INC "shared_isa_proxy_model.h" "shared_isa_tree_view.h" "shared_isa_widget.h" + "shared_isa_vertical_scroll_bar.h" "tab_bar.h" "tree_view.h" "tab_widget.h" @@ -117,6 +111,7 @@ file (GLOB CPP_SRC "shared_isa_proxy_model.cpp" "shared_isa_tree_view.cpp" "shared_isa_widget.cpp" + "shared_isa_vertical_scroll_bar.cpp" "tab_bar.cpp" "tab_widget.cpp" "tree_view.cpp" @@ -125,10 +120,13 @@ file (GLOB CPP_SRC ) # Pick up the source files that are relevant to the platform -add_library(${PROJECT_NAME} STATIC ${CPP_SRC} ${CPP_INC} ${UI_SRC}) +add_library(QtCustomWidgets STATIC ${CPP_SRC} ${CPP_INC} ${UI_SRC}) # Include QtCommon root directory -include_directories(AFTER ../) +include_directories(AFTER ../..) +target_include_directories(QtCustomWidgets PUBLIC ${PROJECT_SOURCE_DIR}/source PRIVATE . ../utils) # Set binary suffix -target_link_libraries(${PROJECT_NAME} Qt5::Widgets) +target_link_libraries(QtCustomWidgets Qt::Widgets) + +devtools_target_options(QtCustomWidgets) diff --git a/custom_widgets/arrow_icon_combo_box.cpp b/source/qt_common/custom_widgets/arrow_icon_combo_box.cpp similarity index 96% rename from custom_widgets/arrow_icon_combo_box.cpp rename to source/qt_common/custom_widgets/arrow_icon_combo_box.cpp index 81fdea2..e6c01ec 100644 --- a/custom_widgets/arrow_icon_combo_box.cpp +++ b/source/qt_common/custom_widgets/arrow_icon_combo_box.cpp @@ -11,8 +11,9 @@ #include #include -#include "utils/scaling_manager.h" -#include "utils/qt_util.h" +#include "common_definitions.h" +#include "scaling_manager.h" +#include "qt_util.h" #include "scaled_check_box.h" #include "scaled_label.h" @@ -30,10 +31,7 @@ ArrowIconComboBox::ArrowIconComboBox(QWidget* parent) , all_choice_added_(false) , all_choice_selected_(false) , size_(kButtonBaseSize) - , color_(Qt::GlobalColor::gray) - , border_color_(Qt::GlobalColor::black) , show_border_(false) - , font_color_(Qt::GlobalColor::black) , direction_(Direction::DownArrow) , pen_width_(kPenWidth) , highlight_substring_(false) @@ -43,6 +41,12 @@ ArrowIconComboBox::ArrowIconComboBox(QWidget* parent) CreateVertices(); + use_fixed_font_color_ = false; + use_fixed_border_color_ = false; + font_color_ = QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().graphics_scene_text_color; + border_color_ = QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().arrow_icon_border_color; + color_ = Qt::GlobalColor::gray; + connect(&ScalingManager::Get(), &ScalingManager::ScaleFactorChanged, this, &ArrowIconComboBox::OnScaleFactorChanged); } @@ -451,6 +455,7 @@ QCheckBox* ArrowIconComboBox::AddCheckboxItem(const QString& item_text, const QV checkbox->setFont(item_list_->font()); checkbox->setChecked(checked); checkbox->setCursor(Qt::PointingHandCursor); + checkbox->UpdateIndicatorSize(); if (is_all_option) { @@ -880,7 +885,14 @@ void ArrowIconComboBox::paintEvent(QPaintEvent* event) painter.setFont(this->font()); if (isEnabled()) { - pen.setColor(font_color_); + if (use_fixed_font_color_) + { + pen.setColor(font_color_); + } + else + { + pen.setColor(QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().graphics_scene_text_color); + } } else { @@ -919,7 +931,14 @@ void ArrowIconComboBox::paintEvent(QPaintEvent* event) // if it is requested. if (show_border_ && (hasFocus() || underMouse())) { - pen.setColor(border_color_); + if (use_fixed_border_color_) + { + pen.setColor(border_color_); + } + else + { + pen.setColor(QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().arrow_icon_border_color); + } pen.setWidth(sm.Scaled(1.0)); painter.setPen(pen); painter.drawRect(this->rect()); @@ -931,6 +950,7 @@ void ArrowIconComboBox::paintEvent(QPaintEvent* event) void ArrowIconComboBox::SetBorderColor(const QColor& color) { border_color_ = color; + use_fixed_border_color_ = true; } void ArrowIconComboBox::SetShowBorder(bool value) @@ -948,6 +968,7 @@ void ArrowIconComboBox::SetColor(const QColor& color) void ArrowIconComboBox::SetFontColor(const QColor& color) { font_color_ = color; + use_fixed_font_color_ = true; update(); } diff --git a/custom_widgets/arrow_icon_combo_box.h b/source/qt_common/custom_widgets/arrow_icon_combo_box.h similarity index 98% rename from custom_widgets/arrow_icon_combo_box.h rename to source/qt_common/custom_widgets/arrow_icon_combo_box.h index 3be67be..5dca41c 100644 --- a/custom_widgets/arrow_icon_combo_box.h +++ b/source/qt_common/custom_widgets/arrow_icon_combo_box.h @@ -14,7 +14,7 @@ #include #include -#include "list_widget.h" +#include "qt_common/custom_widgets/list_widget.h" /// struct for highlight data struct StringHighlightData @@ -388,8 +388,10 @@ private slots: int size_; ///< The size of the encompassing rect. QColor color_; ///< The color of the arrow's lines. QColor border_color_; ///< The color of the widget border, if border requested. + bool use_fixed_border_color_; ///< Whether the border color was set to a fixed color. bool show_border_; ///< The boolean to indicate if border requested. QColor font_color_; ///< The text font color. + bool use_fixed_font_color_; ///< Whether the font color was set to a fixed color. Direction direction_; ///< The direction of the arrow. int pen_width_; ///< The width of the pen. QPointF vertices_[kNumberOfVertices]; ///< The vertices of the arrow. diff --git a/custom_widgets/check_box_widget.cpp b/source/qt_common/custom_widgets/check_box_widget.cpp similarity index 97% rename from custom_widgets/check_box_widget.cpp rename to source/qt_common/custom_widgets/check_box_widget.cpp index da8aaa2..7f3a236 100644 --- a/custom_widgets/check_box_widget.cpp +++ b/source/qt_common/custom_widgets/check_box_widget.cpp @@ -9,9 +9,9 @@ #include -#include "utils/common_definitions.h" -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "common_definitions.h" +#include "qt_util.h" +#include "scaling_manager.h" static const QString kStringOff = "OFF"; ///< Default off text for the checkbox. static const QString kStringOn = "ON"; ///< Default on text for the checkbox. diff --git a/custom_widgets/check_box_widget.h b/source/qt_common/custom_widgets/check_box_widget.h similarity index 100% rename from custom_widgets/check_box_widget.h rename to source/qt_common/custom_widgets/check_box_widget.h diff --git a/custom_widgets/colored_legend_graphics_view.cpp b/source/qt_common/custom_widgets/colored_legend_graphics_view.cpp similarity index 97% rename from custom_widgets/colored_legend_graphics_view.cpp rename to source/qt_common/custom_widgets/colored_legend_graphics_view.cpp index a88bcb9..a9c0a69 100644 --- a/custom_widgets/colored_legend_graphics_view.cpp +++ b/source/qt_common/custom_widgets/colored_legend_graphics_view.cpp @@ -8,7 +8,7 @@ #include "colored_legend_graphics_view.h" -#include "utils/scaling_manager.h" +#include "scaling_manager.h" ColoredLegendGraphicsView::ColoredLegendGraphicsView(QWidget* parent) : QGraphicsView(parent) diff --git a/custom_widgets/colored_legend_graphics_view.h b/source/qt_common/custom_widgets/colored_legend_graphics_view.h similarity index 100% rename from custom_widgets/colored_legend_graphics_view.h rename to source/qt_common/custom_widgets/colored_legend_graphics_view.h diff --git a/custom_widgets/colored_legend_scene.cpp b/source/qt_common/custom_widgets/colored_legend_scene.cpp similarity index 87% rename from custom_widgets/colored_legend_scene.cpp rename to source/qt_common/custom_widgets/colored_legend_scene.cpp index b0ced2b..5dafde6 100644 --- a/custom_widgets/colored_legend_scene.cpp +++ b/source/qt_common/custom_widgets/colored_legend_scene.cpp @@ -10,8 +10,8 @@ #include #include -#include "utils/scaling_manager.h" -#include "utils/qt_util.h" +#include "scaling_manager.h" +#include "qt_util.h" #include "colored_legend_graphics_view.h" @@ -20,11 +20,13 @@ ColoredLegendScene::ColoredLegendScene(QWidget* parent) , legend_mode_(LegendMode::kColor) { connect(&ScalingManager::Get(), &ScalingManager::ScaleFactorChanged, this, &ColoredLegendScene::Update); + connect(&QtCommon::QtUtils::ColorTheme::Get(), &QtCommon::QtUtils::ColorTheme::ColorThemeUpdated, this, &ColoredLegendScene::Update); } ColoredLegendScene::~ColoredLegendScene() { disconnect(&ScalingManager::Get(), &ScalingManager::ScaleFactorChanged, this, &ColoredLegendScene::Update); + disconnect(&QtCommon::QtUtils::ColorTheme::Get(), &QtCommon::QtUtils::ColorTheme::ColorThemeUpdated, this, &ColoredLegendScene::Update); } void ColoredLegendScene::AddColorLegendItem(const QColor& color, const QString& description) @@ -36,8 +38,8 @@ void ColoredLegendScene::AddColorLegendItem(const QColor& color, const QString& if (this->views().count() > 0) { QtCommon::QtUtils::InvalidateFontMetrics(this->views()[0]); - font_metrics = this->views()[0]->fontMetrics(); - text_font = this->views()[0]->font(); + font_metrics = this->views()[0]->fontMetrics(); + text_font = this->views()[0]->font(); } // Set size of square based on font height + offsets above and below. @@ -48,6 +50,7 @@ void ColoredLegendScene::AddColorLegendItem(const QColor& color, const QString& legend_item.text_item_ = new QGraphicsTextItem(description); legend_item.text_item_->setPos(0, 0); + legend_item.text_item_->setFont(text_font); legend_item.rect_item_->setRect(0, 0, square_height, square_height); @@ -132,6 +135,7 @@ void ColoredLegendScene::Update() item.rect_item_->setPos(x_pos, y_pos_top); item.rect_item_->setRect(0, 0, scaled_base_height, scaled_base_height); item.text_item_->setPos(x_pos + scaled_base_height, y_pos_top - kVerticalSpacingAroundText); + item.text_item_->setDefaultTextColor(QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().graphics_scene_text_color); item.text_item_->setFont(text_font); const int text_width = font_metrics.boundingRect(item.text_item_->toPlainText()).width(); @@ -143,6 +147,7 @@ void ColoredLegendScene::Update() for (int i = 0; i < text_legends_.size(); i++) { text_legends_[i]->setPos(x_pos, y_pos_top); + text_legends_[i]->setDefaultTextColor(QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().graphics_scene_text_color); text_legends_[i]->setFont(text_font); const int text_width = font_metrics.boundingRect(text_legends_[i]->toPlainText()).width(); diff --git a/custom_widgets/colored_legend_scene.h b/source/qt_common/custom_widgets/colored_legend_scene.h similarity index 97% rename from custom_widgets/colored_legend_scene.h rename to source/qt_common/custom_widgets/colored_legend_scene.h index 1c1447c..f2dbb95 100644 --- a/custom_widgets/colored_legend_scene.h +++ b/source/qt_common/custom_widgets/colored_legend_scene.h @@ -10,7 +10,7 @@ #include -#include "graphics_scene.h" +#include "qt_common/custom_widgets/graphics_scene.h" class QGraphicsView; diff --git a/custom_widgets/completion_bar_widget.cpp b/source/qt_common/custom_widgets/completion_bar_widget.cpp similarity index 97% rename from custom_widgets/completion_bar_widget.cpp rename to source/qt_common/custom_widgets/completion_bar_widget.cpp index d808178..36b355d 100644 --- a/custom_widgets/completion_bar_widget.cpp +++ b/source/qt_common/custom_widgets/completion_bar_widget.cpp @@ -9,7 +9,7 @@ #include -#include "utils/scaling_manager.h" +#include "scaling_manager.h" CompletionBarWidget::CompletionBarWidget(QWidget* parent) : QWidget(parent) diff --git a/custom_widgets/completion_bar_widget.h b/source/qt_common/custom_widgets/completion_bar_widget.h similarity index 100% rename from custom_widgets/completion_bar_widget.h rename to source/qt_common/custom_widgets/completion_bar_widget.h diff --git a/custom_widgets/donut_pie_widget.cpp b/source/qt_common/custom_widgets/donut_pie_widget.cpp similarity index 96% rename from custom_widgets/donut_pie_widget.cpp rename to source/qt_common/custom_widgets/donut_pie_widget.cpp index bf5cd7b..2126b5d 100644 --- a/custom_widgets/donut_pie_widget.cpp +++ b/source/qt_common/custom_widgets/donut_pie_widget.cpp @@ -14,8 +14,9 @@ #include #include -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "common_definitions.h" +#include "qt_util.h" +#include "scaling_manager.h" DonutPieWidget::DonutPieWidget(QWidget* parent) : QWidget(parent) @@ -135,7 +136,10 @@ void DonutPieWidget::paintEvent(QPaintEvent* paint_event) } // draw the text labels on the arcs - painter.setPen(palette().windowText().color()); + QColor text_color = QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().graphics_scene_text_color; + + painter.setPen(text_color); + for (unsigned int loop = 0; loop < num_segments_; loop++) { const QPoint label_pos = label_positions.dequeue(); @@ -145,7 +149,6 @@ void DonutPieWidget::paintEvent(QPaintEvent* paint_event) // Draw the description text font.setPixelSize(ScalingManager::Get().Scaled(value_font_size_)); painter.setFont(font); - painter.setPen(Qt::black); int text_width = QtCommon::QtUtils::GetPainterTextWidth(&painter, text_line_one_); diff --git a/custom_widgets/donut_pie_widget.h b/source/qt_common/custom_widgets/donut_pie_widget.h similarity index 100% rename from custom_widgets/donut_pie_widget.h rename to source/qt_common/custom_widgets/donut_pie_widget.h diff --git a/custom_widgets/double_slider_widget.cpp b/source/qt_common/custom_widgets/double_slider_widget.cpp similarity index 99% rename from custom_widgets/double_slider_widget.cpp rename to source/qt_common/custom_widgets/double_slider_widget.cpp index db0a602..86d0d83 100644 --- a/custom_widgets/double_slider_widget.cpp +++ b/source/qt_common/custom_widgets/double_slider_widget.cpp @@ -14,8 +14,8 @@ #include #include -#include "utils/common_definitions.h" -#include "utils/scaling_manager.h" +#include "common_definitions.h" +#include "scaling_manager.h" /// Stylesheet for the double slider widget. static const QString kCustomSliderStylesheet( diff --git a/custom_widgets/double_slider_widget.h b/source/qt_common/custom_widgets/double_slider_widget.h similarity index 100% rename from custom_widgets/double_slider_widget.h rename to source/qt_common/custom_widgets/double_slider_widget.h diff --git a/custom_widgets/elided_line_label.cpp b/source/qt_common/custom_widgets/elided_line_label.cpp similarity index 100% rename from custom_widgets/elided_line_label.cpp rename to source/qt_common/custom_widgets/elided_line_label.cpp diff --git a/custom_widgets/elided_line_label.h b/source/qt_common/custom_widgets/elided_line_label.h similarity index 100% rename from custom_widgets/elided_line_label.h rename to source/qt_common/custom_widgets/elided_line_label.h diff --git a/custom_widgets/expanding_scroll_area.cpp b/source/qt_common/custom_widgets/expanding_scroll_area.cpp similarity index 99% rename from custom_widgets/expanding_scroll_area.cpp rename to source/qt_common/custom_widgets/expanding_scroll_area.cpp index e664b14..1b76543 100644 --- a/custom_widgets/expanding_scroll_area.cpp +++ b/source/qt_common/custom_widgets/expanding_scroll_area.cpp @@ -13,7 +13,7 @@ #include #include -#include "utils/scaling_manager.h" +#include "scaling_manager.h" ExpandingScrollArea::ExpandingScrollArea(QWidget* parent) : QScrollArea(parent) diff --git a/custom_widgets/expanding_scroll_area.h b/source/qt_common/custom_widgets/expanding_scroll_area.h similarity index 100% rename from custom_widgets/expanding_scroll_area.h rename to source/qt_common/custom_widgets/expanding_scroll_area.h diff --git a/custom_widgets/file_loading_widget.cpp b/source/qt_common/custom_widgets/file_loading_widget.cpp similarity index 99% rename from custom_widgets/file_loading_widget.cpp rename to source/qt_common/custom_widgets/file_loading_widget.cpp index a405e0b..745acbe 100644 --- a/custom_widgets/file_loading_widget.cpp +++ b/source/qt_common/custom_widgets/file_loading_widget.cpp @@ -15,7 +15,7 @@ #include #include -#include "utils/scaling_manager.h" +#include "scaling_manager.h" /// Speed of the animation. /// Kept in source file to avoid poluting header with diff --git a/custom_widgets/file_loading_widget.h b/source/qt_common/custom_widgets/file_loading_widget.h similarity index 100% rename from custom_widgets/file_loading_widget.h rename to source/qt_common/custom_widgets/file_loading_widget.h diff --git a/custom_widgets/graphics_scene.cpp b/source/qt_common/custom_widgets/graphics_scene.cpp similarity index 100% rename from custom_widgets/graphics_scene.cpp rename to source/qt_common/custom_widgets/graphics_scene.cpp diff --git a/custom_widgets/graphics_scene.h b/source/qt_common/custom_widgets/graphics_scene.h similarity index 100% rename from custom_widgets/graphics_scene.h rename to source/qt_common/custom_widgets/graphics_scene.h diff --git a/custom_widgets/graphics_view.cpp b/source/qt_common/custom_widgets/graphics_view.cpp similarity index 100% rename from custom_widgets/graphics_view.cpp rename to source/qt_common/custom_widgets/graphics_view.cpp diff --git a/custom_widgets/graphics_view.h b/source/qt_common/custom_widgets/graphics_view.h similarity index 100% rename from custom_widgets/graphics_view.h rename to source/qt_common/custom_widgets/graphics_view.h diff --git a/custom_widgets/icon_button.cpp b/source/qt_common/custom_widgets/icon_button.cpp similarity index 95% rename from custom_widgets/icon_button.cpp rename to source/qt_common/custom_widgets/icon_button.cpp index 2dabb5a..c9934d5 100644 --- a/custom_widgets/icon_button.cpp +++ b/source/qt_common/custom_widgets/icon_button.cpp @@ -15,7 +15,7 @@ #include #include -#include "utils/scaling_manager.h" +#include "scaling_manager.h" IconButton::IconButton(QWidget* parent) : QPushButton(parent) @@ -104,7 +104,11 @@ void IconButton::paintEvent(QPaintEvent* event) } } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void IconButton::enterEvent(QEvent* event) +#else +void IconButton::enterEvent(QEnterEvent* event) +#endif { QPushButton::enterEvent(event); setAttribute(Qt::WA_UnderMouse, true); diff --git a/custom_widgets/icon_button.h b/source/qt_common/custom_widgets/icon_button.h similarity index 96% rename from custom_widgets/icon_button.h rename to source/qt_common/custom_widgets/icon_button.h index 2d6fe6f..682c4c9 100644 --- a/custom_widgets/icon_button.h +++ b/source/qt_common/custom_widgets/icon_button.h @@ -71,7 +71,11 @@ class IconButton : public QPushButton /// Event triggered when the mouse is over the button. /// \param event Pointer to the event object. +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) virtual void enterEvent(QEvent* event) Q_DECL_OVERRIDE; +#else + virtual void enterEvent(QEnterEvent *event) Q_DECL_OVERRIDE; +#endif /// Event triggered when the mouse is no longer over the button. /// \param event Pointer to the event object. diff --git a/custom_widgets/list_widget.cpp b/source/qt_common/custom_widgets/list_widget.cpp similarity index 99% rename from custom_widgets/list_widget.cpp rename to source/qt_common/custom_widgets/list_widget.cpp index 3866a51..08ef914 100644 --- a/custom_widgets/list_widget.cpp +++ b/source/qt_common/custom_widgets/list_widget.cpp @@ -15,9 +15,9 @@ #include #include -#include "utils/common_definitions.h" -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "common_definitions.h" +#include "qt_util.h" +#include "scaling_manager.h" #include "arrow_icon_combo_box.h" #include "scaled_label.h" diff --git a/custom_widgets/list_widget.h b/source/qt_common/custom_widgets/list_widget.h similarity index 100% rename from custom_widgets/list_widget.h rename to source/qt_common/custom_widgets/list_widget.h diff --git a/custom_widgets/message_overlay.cpp b/source/qt_common/custom_widgets/message_overlay.cpp similarity index 81% rename from custom_widgets/message_overlay.cpp rename to source/qt_common/custom_widgets/message_overlay.cpp index c519f55..dee49a8 100644 --- a/custom_widgets/message_overlay.cpp +++ b/source/qt_common/custom_widgets/message_overlay.cpp @@ -10,6 +10,8 @@ #include #include +#include "qt_common/utils/qt_util.h" + #include "message_overlay_container.h" #include "ui_message_overlay.h" @@ -67,17 +69,44 @@ void MessageOverlay::SetType(Type type) if (type == Type::Error) { // red - ui_->translucentColorSlice->setStyleSheet(QStringLiteral("background-color: rgba(254, 30, 55, 128);")); + if (QtCommon::QtUtils::ColorTheme::Get().GetColorTheme() == kColorThemeTypeLight) + { + ui_->translucentColorSlice->setStyleSheet(QStringLiteral("background-color: rgba(254, 30, 55, 128);")); + ui_->titleLabel->setStyleSheet(QStringLiteral("color: rgb(85, 87, 83);\nbackground-color: rgba(255, 255, 255, 0);")); + } + else + { + ui_->translucentColorSlice->setStyleSheet(QStringLiteral("background-color: rgba(154, 20, 45, 180);")); + ui_->titleLabel->setStyleSheet(QStringLiteral("color: rgb(240, 240, 240);\nbackground-color: rgba(255, 255, 255, 0);")); + } } else if (type == Type::Info) { // blue - ui_->translucentColorSlice->setStyleSheet(QStringLiteral("background-color: rgba(88, 166, 255, 128);")); + if (QtCommon::QtUtils::ColorTheme::Get().GetColorTheme() == kColorThemeTypeLight) + { + ui_->translucentColorSlice->setStyleSheet(QStringLiteral("background-color: rgba(88, 166, 255, 128);")); + ui_->titleLabel->setStyleSheet(QStringLiteral("color: rgb(85, 87, 83);\nbackground-color: rgba(255, 255, 255, 0);")); + } + else + { + ui_->translucentColorSlice->setStyleSheet(QStringLiteral("background-color: rgba(44, 83, 155, 180);")); + ui_->titleLabel->setStyleSheet(QStringLiteral("color: rgb(240, 240, 240);\nbackground-color: rgba(255, 255, 255, 0);")); + } } else { // yellow - ui_->translucentColorSlice->setStyleSheet(QStringLiteral("background-color: rgba(255, 240, 0, 128);")); + if (QtCommon::QtUtils::ColorTheme::Get().GetColorTheme() == kColorThemeTypeLight) + { + ui_->translucentColorSlice->setStyleSheet(QStringLiteral("background-color: rgba(255, 240, 0, 128);")); + ui_->titleLabel->setStyleSheet(QStringLiteral("color: rgb(85, 87, 83);\nbackground-color: rgba(255, 255, 255, 0);")); + } + else + { + ui_->translucentColorSlice->setStyleSheet(QStringLiteral("background-color: rgba(155, 140, 0, 180);")); + ui_->titleLabel->setStyleSheet(QStringLiteral("color: rgb(240, 240, 240);\nbackground-color: rgba(255, 255, 255, 0);")); + } } } diff --git a/custom_widgets/message_overlay.h b/source/qt_common/custom_widgets/message_overlay.h similarity index 100% rename from custom_widgets/message_overlay.h rename to source/qt_common/custom_widgets/message_overlay.h diff --git a/custom_widgets/message_overlay.ui b/source/qt_common/custom_widgets/message_overlay.ui similarity index 99% rename from custom_widgets/message_overlay.ui rename to source/qt_common/custom_widgets/message_overlay.ui index edefc9f..3b5f08e 100644 --- a/custom_widgets/message_overlay.ui +++ b/source/qt_common/custom_widgets/message_overlay.ui @@ -287,7 +287,7 @@ background-color: rgba(255, 255, 255, 0); ScaledLabel QLabel -
custom_widgets/scaled_label.h
+
scaled_label.h
1
diff --git a/custom_widgets/message_overlay_container.cpp b/source/qt_common/custom_widgets/message_overlay_container.cpp similarity index 100% rename from custom_widgets/message_overlay_container.cpp rename to source/qt_common/custom_widgets/message_overlay_container.cpp diff --git a/custom_widgets/message_overlay_container.h b/source/qt_common/custom_widgets/message_overlay_container.h similarity index 100% rename from custom_widgets/message_overlay_container.h rename to source/qt_common/custom_widgets/message_overlay_container.h diff --git a/custom_widgets/navigation_bar.cpp b/source/qt_common/custom_widgets/navigation_bar.cpp similarity index 95% rename from custom_widgets/navigation_bar.cpp rename to source/qt_common/custom_widgets/navigation_bar.cpp index 7a6a420..a85a053 100644 --- a/custom_widgets/navigation_bar.cpp +++ b/source/qt_common/custom_widgets/navigation_bar.cpp @@ -8,7 +8,7 @@ #include -#include "utils/scaling_manager.h" +#include "scaling_manager.h" const QString kBrowseBackNormalResource_ = ":/Resources/assets/browse_back_normal.svg"; const QString kBrowseBackPressedResource_ = ":/Resources/assets/browse_back_pressed.svg"; @@ -29,7 +29,11 @@ NavigationBar::NavigationBar(QWidget* parent) { layout_.setAlignment(Qt::AlignCenter); layout_.setSpacing(10); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) layout_.setMargin(20); +#else + layout_.setContentsMargins(20, 20, 20, 20); +#endif browse_back_button_.setStyleSheet(kNavigationButtonStyle_); EnableBackButton(false); diff --git a/custom_widgets/navigation_bar.h b/source/qt_common/custom_widgets/navigation_bar.h similarity index 100% rename from custom_widgets/navigation_bar.h rename to source/qt_common/custom_widgets/navigation_bar.h diff --git a/custom_widgets/navigation_list_model.cpp b/source/qt_common/custom_widgets/navigation_list_model.cpp similarity index 100% rename from custom_widgets/navigation_list_model.cpp rename to source/qt_common/custom_widgets/navigation_list_model.cpp diff --git a/custom_widgets/navigation_list_model.h b/source/qt_common/custom_widgets/navigation_list_model.h similarity index 100% rename from custom_widgets/navigation_list_model.h rename to source/qt_common/custom_widgets/navigation_list_model.h diff --git a/custom_widgets/navigation_list_view.cpp b/source/qt_common/custom_widgets/navigation_list_view.cpp similarity index 98% rename from custom_widgets/navigation_list_view.cpp rename to source/qt_common/custom_widgets/navigation_list_view.cpp index bbd0197..80957c4 100644 --- a/custom_widgets/navigation_list_view.cpp +++ b/source/qt_common/custom_widgets/navigation_list_view.cpp @@ -11,7 +11,7 @@ #include #include -#include "utils/scaling_manager.h" +#include "scaling_manager.h" NavigationListView::NavigationListView(QWidget* parent) : QListView(parent) diff --git a/custom_widgets/navigation_list_view.h b/source/qt_common/custom_widgets/navigation_list_view.h similarity index 100% rename from custom_widgets/navigation_list_view.h rename to source/qt_common/custom_widgets/navigation_list_view.h diff --git a/custom_widgets/navigation_list_widget.cpp b/source/qt_common/custom_widgets/navigation_list_widget.cpp similarity index 86% rename from custom_widgets/navigation_list_widget.cpp rename to source/qt_common/custom_widgets/navigation_list_widget.cpp index 69a88cf..2e4ce18 100644 --- a/custom_widgets/navigation_list_widget.cpp +++ b/source/qt_common/custom_widgets/navigation_list_widget.cpp @@ -11,13 +11,15 @@ #include #include -#include "utils/scaling_manager.h" +#include "common_definitions.h" +#include "scaling_manager.h" +#include "qt_util.h" NavigationListWidget::NavigationListWidget(QWidget* parent) : QListWidget(parent) { setMouseTracking(true); - setStyleSheet(kMainListWidgetStylesheet_); + SetStyleSheet(); connect(&ScalingManager::Get(), &ScalingManager::ScaleFactorChanged, this, &NavigationListWidget::OnScaleFactorChanged); } @@ -99,3 +101,15 @@ void NavigationListWidget::OnScaleFactorChanged() updateGeometry(); } + +void NavigationListWidget::SetStyleSheet() +{ + if (QtCommon::QtUtils::ColorTheme::Get().GetColorTheme() == kColorThemeTypeLight) + { + setStyleSheet(kMainListWidgetStylesheet_); + } + else + { + setStyleSheet(kMainListWidgetDarkStylesheet_); + } +} diff --git a/custom_widgets/navigation_list_widget.h b/source/qt_common/custom_widgets/navigation_list_widget.h similarity index 74% rename from custom_widgets/navigation_list_widget.h rename to source/qt_common/custom_widgets/navigation_list_widget.h index 8bf2e6c..3b9cfde 100644 --- a/custom_widgets/navigation_list_widget.h +++ b/source/qt_common/custom_widgets/navigation_list_widget.h @@ -31,6 +31,9 @@ class NavigationListWidget : public QListWidget /// \return the size necessary to display the entire list. virtual QSize sizeHint() const Q_DECL_OVERRIDE; + /// Set either thelight theme or dark theme stylsheet based on the current color theme. + void SetStyleSheet(); + private slots: /// Respond to changes in scaling factor by resizing the font used in the ListWidget /// and then updating the geometry. @@ -40,7 +43,7 @@ private slots: /// Default width to use as the sizeHint if there are no items in the list. const uint32_t kDefaultWidth_ = 200; - /// Custom stylesheet + /// Custom light theme stylesheet const QString kMainListWidgetStylesheet_ = QString( "QListWidget" "{" @@ -67,6 +70,33 @@ private slots: "color: rgb(51, 51, 51);" "}"); + /// Custom dark theme stylesheet + const QString kMainListWidgetDarkStylesheet_ = QString( + "QListWidget" + "{" + "background: rgb(40, 40, 40);" + "border-right: 2px groove gray;" + "outline: none;" + "border: none;" + "}" + + "QListWidget::item:hover" + "{" + "background: rgb(70, 70, 70);" + "}" + + "QListWidget::item:selected" + "{" + "background: rgb(100, 150, 200);" + "}" + + "QListWidget::item" + "{" + "border-bottom: none;" + "padding: 7px;" + "color: rgb(255, 255, 255);" + "}"); + /// Calculates the width of the widest item in the list. int GetListWidgetWidth() const; diff --git a/custom_widgets/quick_link_button_widget.cpp b/source/qt_common/custom_widgets/quick_link_button_widget.cpp similarity index 84% rename from custom_widgets/quick_link_button_widget.cpp rename to source/qt_common/custom_widgets/quick_link_button_widget.cpp index 1998708..ac8bfd3 100644 --- a/custom_widgets/quick_link_button_widget.cpp +++ b/source/qt_common/custom_widgets/quick_link_button_widget.cpp @@ -14,16 +14,15 @@ #include #include -#include "utils/common_definitions.h" -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "common_definitions.h" +#include "qt_util.h" +#include "scaling_manager.h" QuickLinkButtonWidget::QuickLinkButtonWidget(QWidget* parent) : QPushButton("test", parent) , title_string_("") , description_line_one_("") , description_line_two_("") - , text_color_(Qt::black) { setCursor(Qt::PointingHandCursor); setContentsMargins(kContentsMargin_, kContentsMargin_, kContentsMargin_, kContentsMargin_); @@ -32,6 +31,8 @@ QuickLinkButtonWidget::QuickLinkButtonWidget(QWidget* parent) tmp_font.setPointSizeF(kButtonFontPointSize); setFont(tmp_font); + highlighted_ = false; + connect(&ScalingManager::Get(), &ScalingManager::ScaleFactorChanged, this, &QuickLinkButtonWidget::OnScaleFactorChanged); } @@ -87,8 +88,9 @@ void QuickLinkButtonWidget::paintEvent(QPaintEvent* event) desc_font.setBold(false); // Draw background for the button. - painter.setPen(kBackgroundColor_); - painter.setBrush(kBackgroundColor_); + painter.setPen(QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().quick_link_button_background_color); + painter.setBrush(QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().quick_link_button_background_color); + painter.drawRect(0, 0, width(), height()); // Initialize X and Y offsets to be in the top left corner of the contents rect. @@ -99,7 +101,16 @@ void QuickLinkButtonWidget::paintEvent(QPaintEvent* event) // Update the y_offset by the font ascent so that it points to the desired // baseline of the title text. painter.setFont(title_font); - painter.setPen(text_color_); + + if (highlighted_) + { + painter.setPen(QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().link_text_color); + } + else + { + painter.setPen(QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().graphics_scene_text_color); + } + y_offset += painter.fontMetrics().ascent(); painter.drawText(x_offset, y_offset, title_string_); @@ -116,13 +127,17 @@ void QuickLinkButtonWidget::paintEvent(QPaintEvent* event) void QuickLinkButtonWidget::leaveEvent(QEvent* event) { QPushButton::leaveEvent(event); - - text_color_ = Qt::black; + + highlighted_ = false; } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void QuickLinkButtonWidget::enterEvent(QEvent* event) +#else +void QuickLinkButtonWidget::enterEvent(QEnterEvent *event) +#endif { QPushButton::enterEvent(event); - text_color_ = kHighlightColor_; + highlighted_ = true; } \ No newline at end of file diff --git a/custom_widgets/quick_link_button_widget.h b/source/qt_common/custom_widgets/quick_link_button_widget.h similarity index 79% rename from custom_widgets/quick_link_button_widget.h rename to source/qt_common/custom_widgets/quick_link_button_widget.h index 01e0903..c30bba5 100644 --- a/custom_widgets/quick_link_button_widget.h +++ b/source/qt_common/custom_widgets/quick_link_button_widget.h @@ -54,8 +54,11 @@ class QuickLinkButtonWidget : public QPushButton /// Overridden mouse hover enter event. /// \param event The event +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) virtual void enterEvent(QEvent* event) Q_DECL_OVERRIDE; - +#else + virtual void enterEvent(QEnterEvent* event) Q_DECL_OVERRIDE; +#endif /// Overridden mouse hover leave event. /// \param event The event virtual void leaveEvent(QEvent* event) Q_DECL_OVERRIDE; @@ -69,15 +72,17 @@ private slots: void OnScaleFactorChanged(); private: - const int kLineSpacing_ = 5; ///< Number of pixels between lines of text - const int kContentsMargin_ = 5; ///< Number of pixels margin between text and edge of button - const QColor kBackgroundColor_ = QColor(241, 241, 241); ///< Background color of the button - const QColor kHighlightColor_ = QColor(0, 0, 255); ///< Color of text when the mouse is over the button + const int kLineSpacing_ = 5; ///< Number of pixels between lines of text + const int kContentsMargin_ = 5; ///< Number of pixels margin between text and edge of button + + const QColor kLightThemeBackgroundColor_ = QColor(241, 241, 241); ///< Background color of the button for light theme + + const QColor kDarkThemeBackgroundColor_ = QColor(50, 50, 50); ///< Background color of the button for dark theme QString title_string_; ///< Title string QString description_line_one_; ///< Description string one QString description_line_two_; ///< Description string two - QColor text_color_; ///< Current text color + bool highlighted_; ///< Whether text should be highlighted }; #endif // QTCOMMON_CUSTOM_WIDGETS_QUICK_LINK_BUTTON_WIDGET_H_ diff --git a/custom_widgets/recent_trace_mini_widget.cpp b/source/qt_common/custom_widgets/recent_trace_mini_widget.cpp similarity index 83% rename from custom_widgets/recent_trace_mini_widget.cpp rename to source/qt_common/custom_widgets/recent_trace_mini_widget.cpp index 1397ce2..dd0e7fd 100644 --- a/custom_widgets/recent_trace_mini_widget.cpp +++ b/source/qt_common/custom_widgets/recent_trace_mini_widget.cpp @@ -8,21 +8,19 @@ #include "recent_trace_mini_widget.h" #include -#include #include #include #include -#include "utils/common_definitions.h" +#include "common_definitions.h" RecentTraceMiniWidget::RecentTraceMiniWidget(QWidget* parent) : QWidget(parent) { - path_signal_mapper_ = new QSignalMapper(this); path_button_ = new ScaledPushButton(this); path_button_->setCursor(Qt::PointingHandCursor); - path_button_->setStyleSheet(kLinkButtonStylesheet); + path_button_->SetLinkStyleSheet(); // Additional settings for the path button QSizePolicy policy(QSizePolicy::Fixed, QSizePolicy::Fixed); @@ -36,7 +34,6 @@ RecentTraceMiniWidget::RecentTraceMiniWidget(QWidget* parent) RecentTraceMiniWidget::~RecentTraceMiniWidget() { - delete path_signal_mapper_; delete path_button_; } @@ -67,9 +64,7 @@ void RecentTraceMiniWidget::SetFile(const RecentFileData& file) path_button_->setToolTip(path); // Connect path label clicked() signal to this widgets clicked(QString) signal - path_signal_mapper_->setMapping(path_button_, path); - connect(path_button_, SIGNAL(clicked()), path_signal_mapper_, SLOT(map())); - connect(path_signal_mapper_, SIGNAL(mapped(QString)), this, SIGNAL(clicked(QString))); + connect(path_button_, &QPushButton::clicked, [=]() { emit clicked(QString(path)); }); } QString RecentTraceMiniWidget::GetPath() const diff --git a/custom_widgets/recent_trace_mini_widget.h b/source/qt_common/custom_widgets/recent_trace_mini_widget.h similarity index 91% rename from custom_widgets/recent_trace_mini_widget.h rename to source/qt_common/custom_widgets/recent_trace_mini_widget.h index a6fb74a..c8a0bc9 100644 --- a/custom_widgets/recent_trace_mini_widget.h +++ b/source/qt_common/custom_widgets/recent_trace_mini_widget.h @@ -10,12 +10,10 @@ #include #include -#include #include -#include "utils/common_definitions.h" - -#include "scaled_push_button.h" +#include "qt_common/utils/common_definitions.h" +#include "qt_common/custom_widgets/scaled_push_button.h" /// Widget that represents a single trace in the recent traces pane class RecentTraceMiniWidget : public QWidget @@ -50,9 +48,6 @@ class RecentTraceMiniWidget : public QWidget /// on to the path button. virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE; -private: - QSignalMapper* path_signal_mapper_; ///< Path label signal mapper - signals: void clicked(QString); }; diff --git a/custom_widgets/recent_trace_widget.cpp b/source/qt_common/custom_widgets/recent_trace_widget.cpp similarity index 90% rename from custom_widgets/recent_trace_widget.cpp rename to source/qt_common/custom_widgets/recent_trace_widget.cpp index d12bd5c..b016009 100644 --- a/custom_widgets/recent_trace_widget.cpp +++ b/source/qt_common/custom_widgets/recent_trace_widget.cpp @@ -8,14 +8,13 @@ #include "recent_trace_widget.h" #include -#include #include #include -#include "utils/common_definitions.h" -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "common_definitions.h" +#include "qt_util.h" +#include "scaling_manager.h" /// String buffer size. static const int kBufferSize = 64; @@ -23,7 +22,6 @@ static const int kBufferSize = 64; RecentTraceWidget::RecentTraceWidget(QWidget* parent) : RecentTraceMiniWidget(parent) { - delete_signal_mapper_ = new QSignalMapper(this); delete_button_ = new ScaledPushButton(this); open_file_location_button_ = new ScaledPushButton(this); @@ -39,19 +37,18 @@ RecentTraceWidget::RecentTraceWidget(QWidget* parent) // Set the size policy for various labels access_label_->setSizePolicy(policy); delete_button_->setSizePolicy(policy); - delete_button_->setStyleSheet(kLinkButtonStylesheet); + delete_button_->SetLinkStyleSheet(); delete_button_->setCursor(Qt::PointingHandCursor); delete_button_->setText("Remove from list"); open_file_location_button_->setSizePolicy(policy); - open_file_location_button_->setStyleSheet(kLinkButtonStylesheet); + open_file_location_button_->SetLinkStyleSheet(); open_file_location_button_->setCursor(Qt::PointingHandCursor); open_file_location_button_->setText("Open file location"); } RecentTraceWidget::~RecentTraceWidget() { - delete delete_signal_mapper_; } void RecentTraceWidget::changeEvent(QEvent* event) @@ -161,9 +158,7 @@ void RecentTraceWidget::SetRecentFileData(const RecentFileData& file) // Connect path label clicked() signal to this widgets clicked(QString) signal // with the delete button as the parameter - delete_signal_mapper_->setMapping(delete_button_, path); - connect(delete_button_, SIGNAL(clicked()), delete_signal_mapper_, SLOT(map())); - connect(delete_signal_mapper_, SIGNAL(mapped(QString)), this, SIGNAL(clickedDelete(QString))); + connect(delete_button_, &QPushButton::clicked, [=]() { emit clickedDelete(QString(path)); }); // Connect clicked() signal for "Open file location" button. connect(open_file_location_button_, &QPushButton::clicked, this, &RecentTraceWidget::OpenFileLocation); diff --git a/custom_widgets/recent_trace_widget.h b/source/qt_common/custom_widgets/recent_trace_widget.h similarity index 97% rename from custom_widgets/recent_trace_widget.h rename to source/qt_common/custom_widgets/recent_trace_widget.h index 3612fd8..6277609 100644 --- a/custom_widgets/recent_trace_widget.h +++ b/source/qt_common/custom_widgets/recent_trace_widget.h @@ -12,7 +12,6 @@ #define QTCOMMON_CUSTOM_WIDGETS_RECENT_TRACE_WIDGET_H_ #include -#include #include #include "recent_trace_mini_widget.h" @@ -89,7 +88,6 @@ public slots: private: QHBoxLayout* option_buttons_layout_; ///< The layout that holds the option buttons. - QSignalMapper* delete_signal_mapper_; ///< Delete button signal mapper ScaledPushButton* delete_button_; ///< Button to delete this trace file ScaledPushButton* open_file_location_button_; ///< Button to open file browser for this trace file. }; diff --git a/custom_widgets/ruler_widget.cpp b/source/qt_common/custom_widgets/ruler_widget.cpp similarity index 93% rename from custom_widgets/ruler_widget.cpp rename to source/qt_common/custom_widgets/ruler_widget.cpp index c89542c..850b6ba 100644 --- a/custom_widgets/ruler_widget.cpp +++ b/source/qt_common/custom_widgets/ruler_widget.cpp @@ -10,8 +10,8 @@ #include /* log2 */ #include -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "qt_util.h" +#include "scaling_manager.h" // min and max tick step. This is the number of pixels between each tick or // vertical line on the ruler. Currently assumes a value between 5 and 10 pixels @@ -19,15 +19,13 @@ static const double kMinimumTickStep = 5.0; static const double kMaximumTickStep = 10.0; -static const QColor kRulerMarkerColor = QColor(51, 51, 51); -static const QColor kRulerEdgeColor = QColor(230, 230, 230); -static const QColor kRulerBackgroundColor = QColor(248, 248, 248); -static const float kRulerFontPointSize = 8.25f; +static const float kRulerFontPointSize = 8.25f; void RulerWidget::PaintRulerBackground(QPainter* painter, const QRectF& rect) { - painter->setPen(kRulerEdgeColor); - painter->setBrush(kRulerBackgroundColor); + painter->setPen(QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().ruler_edge_color); + painter->setBrush(QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().ruler_background_color); + painter->drawRect(rect); } @@ -61,7 +59,7 @@ void RulerWidget::PaintRuler(QPainter* painter, font.setPointSizeF(kRulerFontPointSize); painter->setFont(font); - QPen pen(kRulerMarkerColor); + QPen pen(QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().ruler_marker_color); painter->setPen(pen); // convert maxtime, minvisible, maxvisible to nanoseconds if time units not clock @@ -112,7 +110,7 @@ void RulerWidget::PaintRuler(QPainter* painter, tick_step = ruler_length / num_sections; } - uint64_t count = 0; + uint64_t count = 0; double clock_label = 0; double scale_increment = time_period; @@ -120,7 +118,7 @@ void RulerWidget::PaintRuler(QPainter* painter, // quick calculation to start the ruler at the start of the draw region const double starting_time = GetStartingTime(min_visible_time, time_period, use_time_period); - count = starting_time / sm.Scaled(scale_increment); + count = starting_time / sm.Scaled(scale_increment); clock_label = sm.Scaled(scale_increment) * count; double x_pos = rect.left() + (count * tick_step); diff --git a/custom_widgets/ruler_widget.h b/source/qt_common/custom_widgets/ruler_widget.h similarity index 98% rename from custom_widgets/ruler_widget.h rename to source/qt_common/custom_widgets/ruler_widget.h index 4a81ece..fcc6bb4 100644 --- a/custom_widgets/ruler_widget.h +++ b/source/qt_common/custom_widgets/ruler_widget.h @@ -10,7 +10,7 @@ #include -#include "utils/common_definitions.h" +#include "qt_common/utils/common_definitions.h" class QColor; diff --git a/custom_widgets/scaled_check_box.cpp b/source/qt_common/custom_widgets/scaled_check_box.cpp similarity index 98% rename from custom_widgets/scaled_check_box.cpp rename to source/qt_common/custom_widgets/scaled_check_box.cpp index ce76b11..29df961 100644 --- a/custom_widgets/scaled_check_box.cpp +++ b/source/qt_common/custom_widgets/scaled_check_box.cpp @@ -11,8 +11,8 @@ #include #include -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "qt_util.h" +#include "scaling_manager.h" ScaledCheckBox::ScaledCheckBox(QWidget* parent) : ScaledCheckBox({}, parent) diff --git a/custom_widgets/scaled_check_box.h b/source/qt_common/custom_widgets/scaled_check_box.h similarity index 100% rename from custom_widgets/scaled_check_box.h rename to source/qt_common/custom_widgets/scaled_check_box.h diff --git a/custom_widgets/scaled_combo_box.cpp b/source/qt_common/custom_widgets/scaled_combo_box.cpp similarity index 97% rename from custom_widgets/scaled_combo_box.cpp rename to source/qt_common/custom_widgets/scaled_combo_box.cpp index a58f2b5..ae683bd 100644 --- a/custom_widgets/scaled_combo_box.cpp +++ b/source/qt_common/custom_widgets/scaled_combo_box.cpp @@ -9,8 +9,8 @@ #include #include -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "qt_util.h" +#include "scaling_manager.h" ScaledComboBox::ScaledComboBox(QWidget* parent) : QComboBox(parent) diff --git a/custom_widgets/scaled_combo_box.h b/source/qt_common/custom_widgets/scaled_combo_box.h similarity index 100% rename from custom_widgets/scaled_combo_box.h rename to source/qt_common/custom_widgets/scaled_combo_box.h diff --git a/custom_widgets/scaled_cycle_button.cpp b/source/qt_common/custom_widgets/scaled_cycle_button.cpp similarity index 98% rename from custom_widgets/scaled_cycle_button.cpp rename to source/qt_common/custom_widgets/scaled_cycle_button.cpp index 6fc0d9c..bddfdbd 100644 --- a/custom_widgets/scaled_cycle_button.cpp +++ b/source/qt_common/custom_widgets/scaled_cycle_button.cpp @@ -8,7 +8,7 @@ #include -#include "utils/scaling_manager.h" +#include "scaling_manager.h" ScaledCycleButton::ScaledCycleButton(QWidget* parent) : QPushButton(parent) diff --git a/custom_widgets/scaled_cycle_button.h b/source/qt_common/custom_widgets/scaled_cycle_button.h similarity index 100% rename from custom_widgets/scaled_cycle_button.h rename to source/qt_common/custom_widgets/scaled_cycle_button.h diff --git a/custom_widgets/scaled_double_spin_box.cpp b/source/qt_common/custom_widgets/scaled_double_spin_box.cpp similarity index 96% rename from custom_widgets/scaled_double_spin_box.cpp rename to source/qt_common/custom_widgets/scaled_double_spin_box.cpp index 7b6c506..67145f1 100644 --- a/custom_widgets/scaled_double_spin_box.cpp +++ b/source/qt_common/custom_widgets/scaled_double_spin_box.cpp @@ -6,8 +6,8 @@ //============================================================================= #include "scaled_double_spin_box.h" -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "qt_util.h" +#include "scaling_manager.h" ScaledDoubleSpinBox::ScaledDoubleSpinBox(QWidget* parent) : QDoubleSpinBox(parent) diff --git a/custom_widgets/scaled_double_spin_box.h b/source/qt_common/custom_widgets/scaled_double_spin_box.h similarity index 100% rename from custom_widgets/scaled_double_spin_box.h rename to source/qt_common/custom_widgets/scaled_double_spin_box.h diff --git a/custom_widgets/scaled_font_combo_box.cpp b/source/qt_common/custom_widgets/scaled_font_combo_box.cpp similarity index 97% rename from custom_widgets/scaled_font_combo_box.cpp rename to source/qt_common/custom_widgets/scaled_font_combo_box.cpp index ebed569..6336177 100644 --- a/custom_widgets/scaled_font_combo_box.cpp +++ b/source/qt_common/custom_widgets/scaled_font_combo_box.cpp @@ -8,8 +8,8 @@ #include "scaled_font_combo_box.h" -#include "utils/scaling_manager.h" -#include "utils/qt_util.h" +#include "scaling_manager.h" +#include "qt_util.h" ScaledFontComboBox::ScaledFontComboBox(QWidget* parent) : QFontComboBox(parent) diff --git a/custom_widgets/scaled_font_combo_box.h b/source/qt_common/custom_widgets/scaled_font_combo_box.h similarity index 100% rename from custom_widgets/scaled_font_combo_box.h rename to source/qt_common/custom_widgets/scaled_font_combo_box.h diff --git a/custom_widgets/scaled_group_box.cpp b/source/qt_common/custom_widgets/scaled_group_box.cpp similarity index 96% rename from custom_widgets/scaled_group_box.cpp rename to source/qt_common/custom_widgets/scaled_group_box.cpp index 34810c5..7d1bfca 100644 --- a/custom_widgets/scaled_group_box.cpp +++ b/source/qt_common/custom_widgets/scaled_group_box.cpp @@ -6,8 +6,8 @@ //============================================================================= #include "scaled_group_box.h" -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "qt_util.h" +#include "scaling_manager.h" ScaledGroupBox::ScaledGroupBox(QWidget* parent) : QGroupBox(parent) diff --git a/custom_widgets/scaled_group_box.h b/source/qt_common/custom_widgets/scaled_group_box.h similarity index 100% rename from custom_widgets/scaled_group_box.h rename to source/qt_common/custom_widgets/scaled_group_box.h diff --git a/custom_widgets/scaled_header_view.cpp b/source/qt_common/custom_widgets/scaled_header_view.cpp similarity index 99% rename from custom_widgets/scaled_header_view.cpp rename to source/qt_common/custom_widgets/scaled_header_view.cpp index 35c9a75..373853d 100644 --- a/custom_widgets/scaled_header_view.cpp +++ b/source/qt_common/custom_widgets/scaled_header_view.cpp @@ -11,7 +11,7 @@ #include #include -#include "utils/scaling_manager.h" +#include "scaling_manager.h" ScaledHeaderView::ScaledHeaderView(Qt::Orientation orientation, QWidget* parent) : QHeaderView(orientation, parent) diff --git a/custom_widgets/scaled_header_view.h b/source/qt_common/custom_widgets/scaled_header_view.h similarity index 100% rename from custom_widgets/scaled_header_view.h rename to source/qt_common/custom_widgets/scaled_header_view.h diff --git a/custom_widgets/scaled_label.cpp b/source/qt_common/custom_widgets/scaled_label.cpp similarity index 93% rename from custom_widgets/scaled_label.cpp rename to source/qt_common/custom_widgets/scaled_label.cpp index 0dcab7b..5ee71aa 100644 --- a/custom_widgets/scaled_label.cpp +++ b/source/qt_common/custom_widgets/scaled_label.cpp @@ -8,9 +8,9 @@ #include -#include "utils/common_definitions.h" -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "common_definitions.h" +#include "qt_util.h" +#include "scaling_manager.h" ScaledLabel::ScaledLabel(QWidget* parent) : QLabel(parent) diff --git a/custom_widgets/scaled_label.h b/source/qt_common/custom_widgets/scaled_label.h similarity index 100% rename from custom_widgets/scaled_label.h rename to source/qt_common/custom_widgets/scaled_label.h diff --git a/custom_widgets/scaled_line_edit.cpp b/source/qt_common/custom_widgets/scaled_line_edit.cpp similarity index 96% rename from custom_widgets/scaled_line_edit.cpp rename to source/qt_common/custom_widgets/scaled_line_edit.cpp index 9cd4719..70563ec 100644 --- a/custom_widgets/scaled_line_edit.cpp +++ b/source/qt_common/custom_widgets/scaled_line_edit.cpp @@ -6,8 +6,8 @@ //============================================================================= #include "scaled_line_edit.h" -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "qt_util.h" +#include "scaling_manager.h" ScaledLineEdit::ScaledLineEdit(QWidget* parent) : QLineEdit(parent) diff --git a/custom_widgets/scaled_line_edit.h b/source/qt_common/custom_widgets/scaled_line_edit.h similarity index 100% rename from custom_widgets/scaled_line_edit.h rename to source/qt_common/custom_widgets/scaled_line_edit.h diff --git a/custom_widgets/scaled_menu_bar.cpp b/source/qt_common/custom_widgets/scaled_menu_bar.cpp similarity index 98% rename from custom_widgets/scaled_menu_bar.cpp rename to source/qt_common/custom_widgets/scaled_menu_bar.cpp index e6ae76d..573c532 100644 --- a/custom_widgets/scaled_menu_bar.cpp +++ b/source/qt_common/custom_widgets/scaled_menu_bar.cpp @@ -6,7 +6,7 @@ //============================================================================= #include "scaled_menu_bar.h" -#include "utils/scaling_manager.h" +#include "scaling_manager.h" ScaledMenuBar::ScaledMenuBar(QWidget* parent) : QMenuBar(parent) diff --git a/custom_widgets/scaled_menu_bar.h b/source/qt_common/custom_widgets/scaled_menu_bar.h similarity index 100% rename from custom_widgets/scaled_menu_bar.h rename to source/qt_common/custom_widgets/scaled_menu_bar.h diff --git a/custom_widgets/scaled_push_button.cpp b/source/qt_common/custom_widgets/scaled_push_button.cpp similarity index 82% rename from custom_widgets/scaled_push_button.cpp rename to source/qt_common/custom_widgets/scaled_push_button.cpp index 412a097..ed8f5a4 100644 --- a/custom_widgets/scaled_push_button.cpp +++ b/source/qt_common/custom_widgets/scaled_push_button.cpp @@ -6,8 +6,9 @@ //============================================================================= #include "scaled_push_button.h" -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "common_definitions.h" +#include "qt_util.h" +#include "scaling_manager.h" ScaledPushButton::ScaledPushButton(QWidget* parent) : QPushButton(parent) @@ -64,3 +65,17 @@ void ScaledPushButton::OnScaleFactorChanged() adjustSize(); } } + +void ScaledPushButton::SetLinkStyleSheet() +{ + connect(&QtCommon::QtUtils::ColorTheme::Get(), &QtCommon::QtUtils::ColorTheme::ColorThemeUpdated, this, &ScaledPushButton::UpdateLinkButtonStyleSheet); + + UpdateLinkButtonStyleSheet(); +} + +void ScaledPushButton::UpdateLinkButtonStyleSheet() +{ + setStyleSheet(QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().link_button_style_sheet); +} + + diff --git a/custom_widgets/scaled_push_button.h b/source/qt_common/custom_widgets/scaled_push_button.h similarity index 80% rename from custom_widgets/scaled_push_button.h rename to source/qt_common/custom_widgets/scaled_push_button.h index b38d9d9..94d6793 100644 --- a/custom_widgets/scaled_push_button.h +++ b/source/qt_common/custom_widgets/scaled_push_button.h @@ -35,10 +35,16 @@ class ScaledPushButton : public QPushButton /// @param size Maximum size for the icon. Smaller icons will not be scaled up. void setIconSize(const QSize& size); + /// @brief Sets the correct link button stylesheet based on the current color theme and connects a slot to update if color theme is changed. + void SetLinkStyleSheet(); + private slots: /// @brief Callback for when the DPI scale factor changes. void OnScaleFactorChanged(); + /// @brief Slot function to set the correct link button stylesheet based on the current color theme when the color theme is changed. + void UpdateLinkButtonStyleSheet(); + private: QSize base_icon_size_; ///< Base icon size DPI scaling will be calculated from. }; diff --git a/custom_widgets/scaled_spin_box.cpp b/source/qt_common/custom_widgets/scaled_spin_box.cpp similarity index 96% rename from custom_widgets/scaled_spin_box.cpp rename to source/qt_common/custom_widgets/scaled_spin_box.cpp index bef287b..7555288 100644 --- a/custom_widgets/scaled_spin_box.cpp +++ b/source/qt_common/custom_widgets/scaled_spin_box.cpp @@ -6,8 +6,8 @@ //============================================================================= #include "scaled_spin_box.h" -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "qt_util.h" +#include "scaling_manager.h" ScaledSpinBox::ScaledSpinBox(QWidget* parent) : QSpinBox(parent) diff --git a/custom_widgets/scaled_spin_box.h b/source/qt_common/custom_widgets/scaled_spin_box.h similarity index 100% rename from custom_widgets/scaled_spin_box.h rename to source/qt_common/custom_widgets/scaled_spin_box.h diff --git a/custom_widgets/scaled_tab_widget.cpp b/source/qt_common/custom_widgets/scaled_tab_widget.cpp similarity index 96% rename from custom_widgets/scaled_tab_widget.cpp rename to source/qt_common/custom_widgets/scaled_tab_widget.cpp index 8581210..60852a6 100644 --- a/custom_widgets/scaled_tab_widget.cpp +++ b/source/qt_common/custom_widgets/scaled_tab_widget.cpp @@ -8,8 +8,8 @@ #include -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "qt_util.h" +#include "scaling_manager.h" ScaledTabWidget::ScaledTabWidget(QWidget* parent) : QTabWidget(parent) diff --git a/custom_widgets/scaled_tab_widget.h b/source/qt_common/custom_widgets/scaled_tab_widget.h similarity index 100% rename from custom_widgets/scaled_tab_widget.h rename to source/qt_common/custom_widgets/scaled_tab_widget.h diff --git a/custom_widgets/scaled_table_view.cpp b/source/qt_common/custom_widgets/scaled_table_view.cpp similarity index 97% rename from custom_widgets/scaled_table_view.cpp rename to source/qt_common/custom_widgets/scaled_table_view.cpp index 47b6c1e..0c708cf 100644 --- a/custom_widgets/scaled_table_view.cpp +++ b/source/qt_common/custom_widgets/scaled_table_view.cpp @@ -10,9 +10,9 @@ #include #include -#include "utils/common_definitions.h" -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "common_definitions.h" +#include "qt_util.h" +#include "scaling_manager.h" /// Specifies the default number of rows to measure when calculating /// column width if the HeaderView's ResizeMode is set to ResizeToContents. diff --git a/custom_widgets/scaled_table_view.h b/source/qt_common/custom_widgets/scaled_table_view.h similarity index 100% rename from custom_widgets/scaled_table_view.h rename to source/qt_common/custom_widgets/scaled_table_view.h diff --git a/custom_widgets/scaled_tree_view.cpp b/source/qt_common/custom_widgets/scaled_tree_view.cpp similarity index 97% rename from custom_widgets/scaled_tree_view.cpp rename to source/qt_common/custom_widgets/scaled_tree_view.cpp index 1d8a720..a8153e2 100644 --- a/custom_widgets/scaled_tree_view.cpp +++ b/source/qt_common/custom_widgets/scaled_tree_view.cpp @@ -10,9 +10,9 @@ #include #include -#include "utils/common_definitions.h" -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "common_definitions.h" +#include "qt_util.h" +#include "scaling_manager.h" /// Specifies the default number of rows to measure when calculating /// column width if the HeaderView's ResizeMode is set to ResizeToContents. diff --git a/custom_widgets/scaled_tree_view.h b/source/qt_common/custom_widgets/scaled_tree_view.h similarity index 100% rename from custom_widgets/scaled_tree_view.h rename to source/qt_common/custom_widgets/scaled_tree_view.h diff --git a/custom_widgets/shared_isa_branch_label_navigation_widget.cpp b/source/qt_common/custom_widgets/shared_isa_branch_label_navigation_widget.cpp similarity index 76% rename from custom_widgets/shared_isa_branch_label_navigation_widget.cpp rename to source/qt_common/custom_widgets/shared_isa_branch_label_navigation_widget.cpp index 060fa48..7ce8262 100644 --- a/custom_widgets/shared_isa_branch_label_navigation_widget.cpp +++ b/source/qt_common/custom_widgets/shared_isa_branch_label_navigation_widget.cpp @@ -9,6 +9,9 @@ #include "shared_isa_item_model.h" +#include "common_definitions.h" +#include "qt_util.h" + const QString kIsaBranchLabelBackNormalResource_ = ":/Resources/assets/browse_back_disabled.svg"; const QString kIsaBranchLabelBackDisabledResource_ = ":/Resources/assets/browse_back_normal.svg"; const QString kIsaBranchLabelForwardNormalResource_ = ":/Resources/assets/browse_fwd_disabled.svg"; @@ -22,30 +25,25 @@ SharedIsaBranchLabelNavigationWidget::SharedIsaBranchLabelNavigationWidget(QWidg layout_.insertWidget(1, branch_label_history_combo_); - browse_back_button_.SetNormalIcon(QIcon(kIsaBranchLabelBackNormalResource_)); - browse_back_button_.SetHoverIcon(QIcon(kIsaBranchLabelBackNormalResource_)); - browse_back_button_.SetDisabledIcon(QIcon(kIsaBranchLabelBackDisabledResource_)); - - browse_forward_button_.SetNormalIcon(QIcon(kIsaBranchLabelForwardNormalResource_)); - browse_forward_button_.SetHoverIcon(QIcon(kIsaBranchLabelForwardNormalResource_)); - browse_forward_button_.SetDisabledIcon(QIcon(kIsaBranchLabelForwardDisabledResource_)); - connect(&browse_back_button_, &QAbstractButton::pressed, this, &SharedIsaBranchLabelNavigationWidget::BackPressed); connect(&browse_forward_button_, &QAbstractButton::pressed, this, &SharedIsaBranchLabelNavigationWidget::ForwardPressed); connect(branch_label_history_combo_, &ArrowIconComboBox::SelectedItem, this, &SharedIsaBranchLabelNavigationWidget::HistoryEntrySelected); + connect( + &QtCommon::QtUtils::ColorTheme::Get(), &QtCommon::QtUtils::ColorTheme::ColorThemeUpdated, this, &SharedIsaBranchLabelNavigationWidget::SetButtonIcons); + ClearHistory(); // Override the style set in the base class. - const QString button_style = "IconButton { margin: 0px; padding: 0px; border: none; background-color: white; background: white; color: rgb(51,51,51); } "; + SetButtonIcons(); - browse_back_button_.setStyleSheet(button_style); - browse_forward_button_.setStyleSheet(button_style); + browse_back_button_.setStyleSheet(""); + browse_forward_button_.setStyleSheet(""); layout_.setAlignment(Qt::AlignTop); - layout_.setMargin(0); + layout_.setContentsMargins(0, 0, 0, 0); } SharedIsaBranchLabelNavigationWidget::~SharedIsaBranchLabelNavigationWidget() @@ -173,4 +171,28 @@ void SharedIsaBranchLabelNavigationWidget::TrimHistory() EnableForwardButton(false); } -} \ No newline at end of file +} + +void SharedIsaBranchLabelNavigationWidget::SetButtonIcons() +{ + if (QtCommon::QtUtils::ColorTheme::Get().GetColorTheme() == kColorThemeTypeLight) + { + browse_back_button_.SetNormalIcon(QIcon(kIsaBranchLabelBackNormalResource_)); + browse_back_button_.SetHoverIcon(QIcon(kIsaBranchLabelBackNormalResource_)); + browse_back_button_.SetDisabledIcon(QIcon(kIsaBranchLabelBackDisabledResource_)); + + browse_forward_button_.SetNormalIcon(QIcon(kIsaBranchLabelForwardNormalResource_)); + browse_forward_button_.SetHoverIcon(QIcon(kIsaBranchLabelForwardNormalResource_)); + browse_forward_button_.SetDisabledIcon(QIcon(kIsaBranchLabelForwardDisabledResource_)); + } + else + { + browse_back_button_.SetNormalIcon(QIcon(kIsaBranchLabelBackDisabledResource_)); + browse_back_button_.SetHoverIcon(QIcon(kIsaBranchLabelBackDisabledResource_)); + browse_back_button_.SetDisabledIcon(QIcon(kIsaBranchLabelBackNormalResource_)); + + browse_forward_button_.SetNormalIcon(QIcon(kIsaBranchLabelForwardDisabledResource_)); + browse_forward_button_.SetHoverIcon(QIcon(kIsaBranchLabelForwardDisabledResource_)); + browse_forward_button_.SetDisabledIcon(QIcon(kIsaBranchLabelForwardNormalResource_)); + } +} diff --git a/custom_widgets/shared_isa_branch_label_navigation_widget.h b/source/qt_common/custom_widgets/shared_isa_branch_label_navigation_widget.h similarity index 97% rename from custom_widgets/shared_isa_branch_label_navigation_widget.h rename to source/qt_common/custom_widgets/shared_isa_branch_label_navigation_widget.h index e3a2887..a9f809b 100644 --- a/custom_widgets/shared_isa_branch_label_navigation_widget.h +++ b/source/qt_common/custom_widgets/shared_isa_branch_label_navigation_widget.h @@ -68,6 +68,9 @@ public slots: /// @brief Trim any entries between the current index and the end of the history. void TrimHistory(); + /// @brief Sets the icons of the button widget. + void SetButtonIcons(); + ArrowIconComboBox* branch_label_history_combo_; ///< The combo box that holds the navigation history. int history_index_; ///< The current location into the navigation history. }; diff --git a/custom_widgets/shared_isa_item_delegate.cpp b/source/qt_common/custom_widgets/shared_isa_item_delegate.cpp similarity index 92% rename from custom_widgets/shared_isa_item_delegate.cpp rename to source/qt_common/custom_widgets/shared_isa_item_delegate.cpp index 2ce5c46..e19f75d 100644 --- a/custom_widgets/shared_isa_item_delegate.cpp +++ b/source/qt_common/custom_widgets/shared_isa_item_delegate.cpp @@ -16,7 +16,10 @@ #include "shared_isa_item_model.h" #include "shared_isa_tree_view.h" -#include "utils/shared_isa_dictionary.h" + +#include "qt_common/utils/common_definitions.h" +#include "qt_common/utils/shared_isa_dictionary.h" +#include "qt_common/utils/qt_util.h" /// @brief Paint a token's text using a color based on its type or syntax. /// @@ -33,12 +36,22 @@ static void PaintTokenText(const SharedIsaItemModel::Token& token, const QRect& if (token.type == SharedIsaItemModel::TokenType::kBranchLabelType) { + QColor operand_color; + if (QtCommon::QtUtils::ColorTheme::Get().GetColorTheme() == kColorThemeTypeLight) + { + operand_color = QtCommon::QtUtils::kIsaLightThemeColorDarkMagenta; + } + else + { + operand_color = QtCommon::QtUtils::kIsaDarkThemeColorDarkMagenta; + } + // Operand that is the target of a branch instruction. - color = QtCommon::QtUtils::kIsaColorDarkMagenta; + color = operand_color; } else if (!QtCommon::QtUtils::IsaColorCodingDictionaryInstance::GetInstance().ShouldHighlight(token.token_text, color)) { - color = QColor("black").lighter(150); + color = pen.color(); } pen.setColor(color); @@ -48,21 +61,12 @@ static void PaintTokenText(const SharedIsaItemModel::Token& token, const QRect& painter->drawText(token_rectangle, Qt::TextSingleLine, token.token_text.c_str()); } -/// @brief Paint a black comma. +/// @brief Paint a comma. /// /// @param [in] comma_rectangle The rectangle to paint to. /// @param [in] painter The painter. -/// @param [in] color_coding_enabled True to color the comma black, false to color it grey. -static void PaintCommaText(const QRect& comma_rectangle, QPainter* painter, bool color_coding_enabled) +static void PaintCommaText(const QRect& comma_rectangle, QPainter* painter) { - if (color_coding_enabled) - { - QPen pen = painter->pen(); - QColor color = QColor("black").lighter(150); - pen.setColor(color); - painter->setPen(pen); - } - painter->drawText(comma_rectangle, ","); } @@ -123,7 +127,12 @@ bool SharedIsaItemDelegate::editorEvent(QEvent* event, QAbstractItemModel* model if (branch_label_indices.size() > 1) { // Label is referenced by more than 1 branch instruction so show a popup menu with all of the branch instructions. +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) view_->ShowBranchInstructionsMenu(branch_label_indices, mouse_event->globalPos()); +#else + view_->ShowBranchInstructionsMenu(branch_label_indices, mouse_event->globalPosition().toPoint()); +#endif + } else { @@ -216,9 +225,13 @@ void SharedIsaItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& painter->setFont(initialized_option.font); - auto pen = painter->pen(); - pen.setColor(source_model_index.data(Qt::ForegroundRole).value()); - painter->setPen(pen); + QVariant color_data = source_model_index.data(Qt::ForegroundRole); + if (color_data != QVariant()) + { + auto pen = painter->pen(); + pen.setColor(color_data.value()); + painter->setPen(pen); + } if (source_model_index.column() == SharedIsaItemModel::kLineNumber) { @@ -305,7 +318,9 @@ void SharedIsaItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& const bool color_coding_enabled = source_model_index.data(SharedIsaItemModel::kLineEnabledRole).toBool(); + painter->save(); PaintTokenText(op_code_token, op_code_rectangle, painter, color_coding_enabled); + painter->restore(); } } } @@ -361,6 +376,7 @@ void SharedIsaItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& static_cast(token_index)); } + painter->save(); PaintTokenText(token, token_rectangle, painter, color_coding_enabled); if (token.type == SharedIsaItemModel::TokenType::kBranchLabelType) @@ -371,6 +387,7 @@ void SharedIsaItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& // Re-use color and draw a line underneath the target of the branch instruction. painter->drawLine(label_underline_start, label_underline_end); } + painter->restore(); token_rectangle.adjust(initialized_option.fontMetrics.horizontalAdvance(token_text), 0, 0, 0); @@ -386,7 +403,7 @@ void SharedIsaItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& // Add a comma if it is not the last operand. if (i < tokens.size() - 1) { - PaintCommaText(token_rectangle, painter, color_coding_enabled); + PaintCommaText(token_rectangle, painter); token_rectangle.adjust(initialized_option.fontMetrics.horizontalAdvance(QString(SharedIsaItemModel::kOperandDelimiter)), 0, 0, 0); } @@ -474,12 +491,10 @@ bool SharedIsaItemDelegate::CodeBlockLabelPinnedToTop(const QModelIndex& source_ void SharedIsaItemDelegate::PaintColumnSeparator(QPainter* painter, const QRect& rectangle) const { - static const QColor column_separator_color = QColor(230, 230, 230); - painter->save(); auto pen = painter->pen(); - pen.setColor(column_separator_color); + pen.setColor(QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().column_separator_color); painter->setPen(pen); painter->drawLine(rectangle.topRight(), rectangle.bottomRight()); @@ -668,7 +683,17 @@ void SharedIsaItemDelegate::PaintTokenHighlight(const SharedIsaItemModel::Token& QRect highlighted_operand_rectangle = isa_token_rectangle; highlighted_operand_rectangle.setWidth(font_metrics.horizontalAdvance(token.token_text.c_str())); - painter->fillRect(highlighted_operand_rectangle, QtCommon::QtUtils::kIsaColorLightPink); + QColor higlight_color; + if (QtCommon::QtUtils::ColorTheme::Get().GetColorTheme() == kColorThemeTypeLight) + { + higlight_color = QtCommon::QtUtils::kIsaLightThemeColorLightPink; + } + else + { + higlight_color = QtCommon::QtUtils::kIsaDarkThemeColorDarkDarkPurple; + } + + painter->fillRect(highlighted_operand_rectangle, higlight_color); } else if (mouse_over_isa_token_.token_text == token.token_text && code_block_index == mouse_over_code_block_index_ && instruction_index == mouse_over_instruction_index_ && mouse_over_token_index_ == token_index) @@ -678,6 +703,16 @@ void SharedIsaItemDelegate::PaintTokenHighlight(const SharedIsaItemModel::Token& QRect highlighted_token_rectangle = isa_token_rectangle; highlighted_token_rectangle.setWidth(font_metrics.horizontalAdvance(token.token_text.c_str())); - painter->fillRect(highlighted_token_rectangle, QtCommon::QtUtils::kIsaColorLightLightPink); + QColor higlight_color; + if (QtCommon::QtUtils::ColorTheme::Get().GetColorTheme() == kColorThemeTypeLight) + { + higlight_color = QtCommon::QtUtils::kIsaLightThemeColorLightPink; + } + else + { + higlight_color = QtCommon::QtUtils::kIsaDarkThemeColorDarkDarkPurple; + } + + painter->fillRect(highlighted_token_rectangle, higlight_color); } } diff --git a/custom_widgets/shared_isa_item_delegate.h b/source/qt_common/custom_widgets/shared_isa_item_delegate.h similarity index 100% rename from custom_widgets/shared_isa_item_delegate.h rename to source/qt_common/custom_widgets/shared_isa_item_delegate.h diff --git a/custom_widgets/shared_isa_item_model.cpp b/source/qt_common/custom_widgets/shared_isa_item_model.cpp similarity index 92% rename from custom_widgets/shared_isa_item_model.cpp rename to source/qt_common/custom_widgets/shared_isa_item_model.cpp index d7d0f68..60845f6 100644 --- a/custom_widgets/shared_isa_item_model.cpp +++ b/source/qt_common/custom_widgets/shared_isa_item_model.cpp @@ -6,7 +6,10 @@ //============================================================================= #include "shared_isa_item_model.h" -#include "utils/shared_isa_dictionary.h" + +#include "qt_common/utils/shared_isa_dictionary.h" +#include "qt_common/utils/qt_util.h" +#include "qt_common/utils/common_definitions.h" #include @@ -137,27 +140,46 @@ QVariant SharedIsaItemModel::data(const QModelIndex& index, int role) const break; } case Qt::ForegroundRole: { - // Start out all text as black. - // - // Provide a different starting color for code block comments and code block labels with matching branching instructions. - // // This role is not useful for columns with multi-coloring in the same column. - data.setValue(QColor(Qt::black)); + // Default to color theme's text color. + data.setValue(QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().graphics_scene_text_color); if (!index.parent().isValid() && index.column() == kOpCode) { - const auto& code_block = code_blocks_.at(index.row()); + // Provide a different starting color for code block comments and code block labels with matching branching instructions. + const auto& code_block = code_blocks_.at(index.row()); + if (code_block.row_type == RowType::kComment) { + QColor comment_color; + if (QtCommon::QtUtils::ColorTheme::Get().GetColorTheme() == kColorThemeTypeLight) + { + comment_color = QtCommon::QtUtils::kIsaLightThemeColorLightBlue; + } + else + { + comment_color = QtCommon::QtUtils::kIsaDarkThemeColorLightBlue; + } + // This is a code block comment; provide light blue as its text color. - data.setValue(QtCommon::QtUtils::kIsaColorLightBlue); + data.setValue(comment_color); } else if (code_block.row_type == RowType::kCodeBlock && !code_block.mapped_branch_instructions.empty()) { + QColor label_color; + if (QtCommon::QtUtils::ColorTheme::Get().GetColorTheme() == kColorThemeTypeLight) + { + label_color = QtCommon::QtUtils::kIsaLightThemeColorDarkMagenta; + } + else + { + label_color = QtCommon::QtUtils::kIsaDarkThemeColorDarkMagenta; + } + // This is a code block label that is called by a branch instruction(s); provide purple as its text color. - data.setValue(QtCommon::QtUtils::kIsaColorDarkMagenta); + data.setValue(label_color); } } diff --git a/custom_widgets/shared_isa_item_model.h b/source/qt_common/custom_widgets/shared_isa_item_model.h similarity index 97% rename from custom_widgets/shared_isa_item_model.h rename to source/qt_common/custom_widgets/shared_isa_item_model.h index 56c63bf..1f4b14f 100644 --- a/custom_widgets/shared_isa_item_model.h +++ b/source/qt_common/custom_widgets/shared_isa_item_model.h @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -238,8 +239,8 @@ class SharedIsaItemModel : public QAbstractItemModel std::vector code_blocks_; ///< Isa stored in this model as a container of a convenience data structure. - QFont fixed_font_; ///< A fixed font set by an application to assist caching size hints for columns. - int fixed_font_character_width_; ///< Cache the width of a single character of the fixed font. + QFont fixed_font_; ///< A fixed font set by an application to assist caching size hints for columns. + int fixed_font_character_width_; ///< Cache the width of a single character of the fixed font. private: std::array column_widths_ = {0, 0, 0, 0, 0}; ///< Cached column widths. diff --git a/custom_widgets/shared_isa_proxy_model.cpp b/source/qt_common/custom_widgets/shared_isa_proxy_model.cpp similarity index 100% rename from custom_widgets/shared_isa_proxy_model.cpp rename to source/qt_common/custom_widgets/shared_isa_proxy_model.cpp diff --git a/custom_widgets/shared_isa_proxy_model.h b/source/qt_common/custom_widgets/shared_isa_proxy_model.h similarity index 100% rename from custom_widgets/shared_isa_proxy_model.h rename to source/qt_common/custom_widgets/shared_isa_proxy_model.h diff --git a/custom_widgets/shared_isa_tree_view.cpp b/source/qt_common/custom_widgets/shared_isa_tree_view.cpp similarity index 68% rename from custom_widgets/shared_isa_tree_view.cpp rename to source/qt_common/custom_widgets/shared_isa_tree_view.cpp index f647d47..561cb77 100644 --- a/custom_widgets/shared_isa_tree_view.cpp +++ b/source/qt_common/custom_widgets/shared_isa_tree_view.cpp @@ -23,6 +23,9 @@ #include "shared_isa_item_delegate.h" #include "shared_isa_widget.h" +#include "common_definitions.h" +#include "qt_util.h" + /// @brief Compare function that sorts model indices by their position on screen. /// /// @param lhs The left hand side model index. @@ -44,6 +47,8 @@ static bool CompareModelIndices(const std::pair& lhs, const SharedIsaTreeView::SharedIsaTreeView(QWidget* parent) : ScaledTreeView(parent) + , shared_isa_widget_(nullptr) + , shared_isa_scroll_bar_(nullptr) , copy_line_numbers_(true) { setObjectName("isa_tree_view_"); @@ -79,8 +84,6 @@ SharedIsaTreeView::SharedIsaTreeView(QWidget* parent) SharedIsaItemDelegate* shared_isa_item_delegate = new SharedIsaItemDelegate(this); setItemDelegate(shared_isa_item_delegate); - connect(verticalScrollBar(), &QScrollBar::valueChanged, this, &SharedIsaTreeView::ScrollBarScrolled); - // Allow contiguous selection per rows. setSelectionMode(QAbstractItemView::SelectionMode::ContiguousSelection); setSelectionBehavior(QAbstractItemView::SelectRows); @@ -88,12 +91,128 @@ SharedIsaTreeView::SharedIsaTreeView(QWidget* parent) // Disable alternating row colors and have this view paint them manually instead. // The default alternating row color behavior would otherwise paint over our attempt to let labels and comments span columns. setAlternatingRowColors(false); + + // Scroll bar to show hot spots and text search matches. + shared_isa_scroll_bar_ = new SharedIsaVerticalScrollBar(this); + setVerticalScrollBar(shared_isa_scroll_bar_); + connect(shared_isa_scroll_bar_, &QScrollBar::valueChanged, this, &SharedIsaTreeView::ScrollBarScrolled); } SharedIsaTreeView::~SharedIsaTreeView() { } +void SharedIsaTreeView::SetHotSpotLineNumber(const QModelIndex instruction_source_index) +{ + if (!instruction_source_index.parent().isValid()) + { + // Should be an instruction index. + shared_isa_scroll_bar_->SetHotSpotLineNumber(-1); + return; + } + + int line_number = 0; + const QSortFilterProxyModel* proxy_model = qobject_cast(model()); + + // Get the relative line number of the requested hot spot instruction, accounting for the + // expand/collapse state of previous code blocks. + + if (proxy_model != nullptr) + { + const QModelIndex instruction_proxy_index = proxy_model->mapFromSource(instruction_source_index); + const QModelIndex code_block_proxy_index = proxy_model->mapFromSource(instruction_source_index.parent()); + + for (int i = 0; i < code_block_proxy_index.row(); i++) + { + line_number++; // +1 for previous code block's line number. + + const QModelIndex next_code_block_index = proxy_model->index(i, SharedIsaItemModel::Columns::kLineNumber); + + // Add previous code block instruction count if previous code block is expanded. + if (isExpanded(next_code_block_index)) + { + line_number += proxy_model->rowCount(next_code_block_index); + } + } + + line_number++; // +1 for hot spot code block's line number. + + // Add the hot spot instruction's index if its code block is expanded. + if (isExpanded(code_block_proxy_index)) + { + line_number += instruction_proxy_index.row(); + } + } + + shared_isa_scroll_bar_->SetHotSpotLineNumber(line_number); +} + +void SharedIsaTreeView::SetSearchMatchLineNumbers(const std::set& source_indices) +{ + std::set line_numbers; + + const QSortFilterProxyModel* proxy_model = qobject_cast(model()); + + for (const auto& source_index : source_indices) + { + int line_number = 0; + + QModelIndex proxy_index = source_index; + QModelIndex proxy_index_parent = source_index.parent(); + + // Get the relative line number of the requested search match index, accounting for the + // expand/collapse state of previous code blocks. + + if (proxy_model != nullptr) + { + proxy_index = proxy_model->mapFromSource(proxy_index); + + int row = 0; + + if (proxy_index_parent.isValid()) + { + // Search match matches an instruction. + + proxy_index_parent = proxy_model->mapFromSource(proxy_index_parent); + + row = proxy_index_parent.row(); + } + else + { + // Search match matches a code block. + + row = proxy_index.row(); + } + + for (int i = 0; i < row; i++) + { + line_number++; // +1 for previous code block's line number. + + const QModelIndex next_code_block_index = proxy_model->index(i, SharedIsaItemModel::Columns::kLineNumber); + + // Add previous code block instruction count if previous code block is expanded. + if (isExpanded(next_code_block_index)) + { + line_number += proxy_model->rowCount(next_code_block_index); + } + } + + line_number++; // +1 for search match code block's line number. + + // If a search match matches an instruction (not a code block), and its parent code block is expanded, + // add the instruction's index too. + if (proxy_index_parent.isValid() && isExpanded(proxy_index_parent)) + { + line_number += proxy_index.row(); + } + + line_numbers.emplace(line_number); + } + } + + shared_isa_scroll_bar_->SetSearchMatchLineNumbers(line_numbers); +} + void SharedIsaTreeView::ShowBranchInstructionsMenu(QVector source_indices, QPoint global_position) { QMenu branch_instruction_menu(this); @@ -156,9 +275,11 @@ void SharedIsaTreeView::ReplayBranchOrLabelSelection(QModelIndex branch_label_so void SharedIsaTreeView::drawRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { - static bool alternate_row = false; - static const QColor background_row_color = QColor(240, 240, 240); - static const QColor search_match_row_color = QColor(192, 192, 255); + static bool alternate_row = false; + + const QColor background_row_color = QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().isa_background_row_color; + + const QColor search_match_row_color = QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().isa_search_match_row_color; // Manually paint a gray background color for every other row. @@ -170,8 +291,15 @@ void SharedIsaTreeView::drawRow(QPainter* painter, const QStyleOptionViewItem& o alternate_row = false; } + bool code_block_pinned = false; + + if (index.parent().isValid() && view_index_y_position == 0) + { + code_block_pinned = true; + } + // If something in this row matches the search, then give it a special background. - if (shared_isa_widget_->DoesIndexMatchSearch(index)) + if (shared_isa_widget_->DoesIndexMatchSearch(index) && !code_block_pinned) { painter->fillRect(option.rect, search_match_row_color); } diff --git a/custom_widgets/shared_isa_tree_view.h b/source/qt_common/custom_widgets/shared_isa_tree_view.h similarity index 82% rename from custom_widgets/shared_isa_tree_view.h rename to source/qt_common/custom_widgets/shared_isa_tree_view.h index a3b990e..edf658d 100644 --- a/custom_widgets/shared_isa_tree_view.h +++ b/source/qt_common/custom_widgets/shared_isa_tree_view.h @@ -12,6 +12,7 @@ #include "scaled_tree_view.h" #include "shared_isa_item_model.h" +#include "shared_isa_vertical_scroll_bar.h" // Forward declaration to prevent a circular dependency. class SharedIsaWidget; @@ -24,7 +25,8 @@ class SharedIsaTreeView : public ScaledTreeView Q_OBJECT public: - /// @brief Constructor; set default properties on tree and header, create and set delegate. + + /// @brief Constructor; set default properties on tree and header, create delegate and scroll bar. /// /// @param [in] parent The parent widget. explicit SharedIsaTreeView(QWidget* parent = nullptr); @@ -32,6 +34,18 @@ class SharedIsaTreeView : public ScaledTreeView /// @brief Destructor. virtual ~SharedIsaTreeView(); + /// @brief Set the line # of a hot spot to paint a red rectangle in the scroll bar. + /// Use an instruction's source index to get its relative line number. + /// + /// @param [in] instruction_source_index The source index of the hot spot instruction. + void SetHotSpotLineNumber(const QModelIndex instruction_source_index); + + /// @brief Set the line #(s) of text search matches to paint a purple rectangle(s) in the scroll bar. + /// Use instructions' source indices to get their relative line numbers. + /// + /// @param [in] source_indices The source indices of the text search matches. + void SetSearchMatchLineNumbers(const std::set& source_indices); + /// @brief Show a popup menu that scrolls to a branch label instruction after pressing a menu action. /// /// @param source_indices [in] Source model indices of branch instructions. @@ -134,8 +148,9 @@ public slots: /// @param [in] value The new value of the scroll bar. void ScrollBarScrolled(int value); - SharedIsaWidget* shared_isa_widget_; ///< The Isa widget. - bool copy_line_numbers_; ///< Whether the line number text is to be included when copying isa text. True by default. + SharedIsaWidget* shared_isa_widget_; ///< The Isa widget. + SharedIsaVerticalScrollBar* shared_isa_scroll_bar_; ///< Scroll bar to paint red and purple rectangles corresponding to hot spots and text search matches. + bool copy_line_numbers_; ///< Whether the line number text is to be included when copying isa text. True by default. }; #endif // QTCOMMON_CUSTOM_WIDGETS_SHARED_ISA_TREE_VIEW_H_ diff --git a/source/qt_common/custom_widgets/shared_isa_vertical_scroll_bar.cpp b/source/qt_common/custom_widgets/shared_isa_vertical_scroll_bar.cpp new file mode 100644 index 0000000..ff8bf8f --- /dev/null +++ b/source/qt_common/custom_widgets/shared_isa_vertical_scroll_bar.cpp @@ -0,0 +1,106 @@ +//============================================================================= +// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved. +/// @author AMD Developer Tools Team +/// @file +/// @brief Shared isa tree vertical scroll bar implementation. +//============================================================================= + +#include "shared_isa_vertical_scroll_bar.h" + +#include +#include + +#include "shared_isa_tree_view.h" + +#include "qt_util.h" + +SharedIsaVerticalScrollBar::SharedIsaVerticalScrollBar(QWidget* parent) + : QScrollBar(parent) + , hot_spot_line_number_(-1) +{ +} + +SharedIsaVerticalScrollBar::~SharedIsaVerticalScrollBar() +{ +} + +void SharedIsaVerticalScrollBar::SetHotSpotLineNumber(int line_number) +{ + hot_spot_line_number_ = line_number; + + update(); +} + +void SharedIsaVerticalScrollBar::SetSearchMatchLineNumbers(const std::set& line_numbers) +{ + search_match_line_numbers_ = line_numbers; + + update(); +} + +void SharedIsaVerticalScrollBar::paintEvent(QPaintEvent* event) +{ + // Let Qt paint entire scrollbar first. + QScrollBar::paintEvent(event); + + if (search_match_line_numbers_.empty() && hot_spot_line_number_ == -1) + { + return; + } + + QStyleOptionSlider option; + this->initStyleOption(&option); + + // Get the pixel height of the up arrow button in this scroll bar. + const qreal button_pixel_height = + style()->subControlRect(QStyle::CC_ScrollBar, qstyleoption_cast(&option), QStyle::SC_ScrollBarSubLine).height(); + + // Get the pixel height of the scrollable space in this scroll bar. + qreal scroll_bar_pixel_height = style()->pixelMetric(QStyle::PM_SliderSpaceAvailable, qstyleoption_cast(&option)); + scroll_bar_pixel_height = scroll_bar_pixel_height - (2 * button_pixel_height); + + // Get the # of lines of isa. + const qreal number_lines = maximum() - minimum() + pageStep(); + + // Get the pixel height of a single row mapped to the inside of the scroll bar; round up to 1 pixel. + qreal row_in_scroll_bar_pixel_height = (scroll_bar_pixel_height * 1) / number_lines; + row_in_scroll_bar_pixel_height = (row_in_scroll_bar_pixel_height < 1.0) ? 1.0 : row_in_scroll_bar_pixel_height; + + // Turn on AA and paint using floats to try and help improve accuracy. + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + + // Get the width and height of the rectangle(s) we want to paint inside this scroll bar. + const qreal scroll_bar_half_width = option.rect.width() / 2; + QRectF scroll_bar_rectangle = option.rect; + scroll_bar_rectangle.adjust(1, 0, -1, 0); + scroll_bar_rectangle.setHeight(row_in_scroll_bar_pixel_height); + + if (!search_match_line_numbers_.empty()) + { + for (const auto& search_match_line_number : search_match_line_numbers_) + { + // Normalize the y pixel position of the search match line number(s). + const qreal qreal_search_match_line_number = search_match_line_number; + const qreal search_match_y_pixel_position = ((scroll_bar_pixel_height * qreal_search_match_line_number) / number_lines) + button_pixel_height; + + // Paint the search match rectangle on top and to the right. + QRectF search_match_rectangle = scroll_bar_rectangle; + search_match_rectangle.adjust(scroll_bar_half_width, search_match_y_pixel_position, 0, search_match_y_pixel_position); + QColor search_match_row_color = QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().isa_search_match_row_color; + painter.fillRect(search_match_rectangle, search_match_row_color); + } + } + + if (hot_spot_line_number_ != -1) + { + // Normalize the y pixel position of the hot spot line number. + const qreal qreal_hot_spot_line_number = hot_spot_line_number_; + const qreal hot_spot_y_pixel_position = ((scroll_bar_pixel_height * qreal_hot_spot_line_number) / number_lines) + button_pixel_height; + + // Paint hot spot rectangle on top and to the left. + QRectF hot_spot_rectangle = scroll_bar_rectangle; + hot_spot_rectangle.adjust(0, hot_spot_y_pixel_position, -scroll_bar_half_width, hot_spot_y_pixel_position); + painter.fillRect(hot_spot_rectangle, Qt::red); + } +} \ No newline at end of file diff --git a/source/qt_common/custom_widgets/shared_isa_vertical_scroll_bar.h b/source/qt_common/custom_widgets/shared_isa_vertical_scroll_bar.h new file mode 100644 index 0000000..c675df6 --- /dev/null +++ b/source/qt_common/custom_widgets/shared_isa_vertical_scroll_bar.h @@ -0,0 +1,50 @@ +//============================================================================= +// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved. +/// @author AMD Developer Tools Team +/// @file +/// @brief Header for a shared isa tree vertical scroll bar. +//============================================================================= + +#ifndef QTCOMMON_CUSTOM_WIDGETS_SHARED_ISA_VERTICAL_SCROLL_BAR_H_ +#define QTCOMMON_CUSTOM_WIDGETS_SHARED_ISA_VERTICAL_SCROLL_BAR_H_ + +#include + +#include + +/// @brief SharedIsaVerticalScrollBar is a scroll bar that custom paints the relative position +/// of hot spots and text search matches as red and purple rectangles, inside of the scroll bar. +class SharedIsaVerticalScrollBar final : public QScrollBar +{ + Q_OBJECT + +public: + /// @brief Constructor. + /// + /// @param [in] parent The parent widget. + explicit SharedIsaVerticalScrollBar(QWidget* parent = nullptr); + + /// @brief Destructor. + virtual ~SharedIsaVerticalScrollBar(); + + /// @brief Set the line # of a hot spot to paint a red rectangle. + /// + /// @param [in] line_number The line # of the hot spot. + void SetHotSpotLineNumber(int line_number); + + /// @brief Set the line #(s) of text search matches to paint a purple rectangle(s). + /// + /// @param [in] line_numbers The line #(s) of the text search matches. + void SetSearchMatchLineNumbers(const std::set& line_numbers); + +protected: + /// @brief Override paint to paint red hot spots and purple text search matches. + /// + /// @param [in] The paint event. + void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE; + + int hot_spot_line_number_; ///< Line number of a hot spot. + std::set search_match_line_numbers_; ///< Line number(s) of text search matches. +}; + +#endif // QTCOMMON_CUSTOM_WIDGETS_SHARED_ISA_VERTICAL_SCROLL_BAR_H_ diff --git a/custom_widgets/shared_isa_widget.cpp b/source/qt_common/custom_widgets/shared_isa_widget.cpp similarity index 82% rename from custom_widgets/shared_isa_widget.cpp rename to source/qt_common/custom_widgets/shared_isa_widget.cpp index 2a796cc..a10a540 100644 --- a/custom_widgets/shared_isa_widget.cpp +++ b/source/qt_common/custom_widgets/shared_isa_widget.cpp @@ -134,10 +134,18 @@ void SharedIsaWidget::SetModelAndView(QWidget* navigation_widget_par connect( ui_->branch_label_navigation_, &SharedIsaBranchLabelNavigationWidget::Navigate, ui_->isa_tree_view_, &SharedIsaTreeView::ReplayBranchOrLabelSelection); + + // Listen to isa tree expand/collapse of code block indicies to update the search match indices. + connect(ui_->isa_tree_view_, &QTreeView::collapsed, this, &SharedIsaWidget::RefreshSearchMatchLineNumbers); + connect(ui_->isa_tree_view_, &QTreeView::expanded, this, &SharedIsaWidget::RefreshSearchMatchLineNumbers); } void SharedIsaWidget::ExpandCollapseAll(bool expand, bool resize_contents, std::deque* collapsed_blocks) { + // Disconnect to prevent duplicate updates. + disconnect(ui_->isa_tree_view_, &QTreeView::collapsed, this, &SharedIsaWidget::RefreshSearchMatchLineNumbers); + disconnect(ui_->isa_tree_view_, &QTreeView::expanded, this, &SharedIsaWidget::RefreshSearchMatchLineNumbers); + if (expand) { if (collapsed_blocks == nullptr) @@ -185,6 +193,12 @@ void SharedIsaWidget::ExpandCollapseAll(bool expand, bool resize_contents, std:: { ui_->isa_tree_view_->collapseAll(); } + + RefreshSearchMatchLineNumbers(QModelIndex()); + + // Reconnect to resume normal updates. + connect(ui_->isa_tree_view_, &QTreeView::collapsed, this, &SharedIsaWidget::RefreshSearchMatchLineNumbers); + connect(ui_->isa_tree_view_, &QTreeView::expanded, this, &SharedIsaWidget::RefreshSearchMatchLineNumbers); } SharedIsaWidget::ExpandCollapseState SharedIsaWidget::SaveExpandState() @@ -217,6 +231,10 @@ void SharedIsaWidget::RestoreExpandState(ExpandCollapseState expand_collapse_sta return; } + // Disconnect to prevent duplicate updates. + disconnect(ui_->isa_tree_view_, &QTreeView::collapsed, this, &SharedIsaWidget::RefreshSearchMatchLineNumbers); + disconnect(ui_->isa_tree_view_, &QTreeView::expanded, this, &SharedIsaWidget::RefreshSearchMatchLineNumbers); + int code_block_row = 0; for (const bool is_code_block_expanded : expand_collapse_state) @@ -228,6 +246,12 @@ void SharedIsaWidget::RestoreExpandState(ExpandCollapseState expand_collapse_sta code_block_row++; } + + RefreshSearchMatchLineNumbers(QModelIndex()); + + // Reconnect to resume normal updates. + connect(ui_->isa_tree_view_, &QTreeView::collapsed, this, &SharedIsaWidget::RefreshSearchMatchLineNumbers); + connect(ui_->isa_tree_view_, &QTreeView::expanded, this, &SharedIsaWidget::RefreshSearchMatchLineNumbers); } void SharedIsaWidget::ClearHistory() @@ -257,6 +281,9 @@ void SharedIsaWidget::Search() matches_.clear(); + std::set match_source_indices; + ui_->isa_tree_view_->SetSearchMatchLineNumbers(match_source_indices); + auto text = ui_->search_->text(); if (!text.isEmpty()) @@ -297,13 +324,22 @@ void SharedIsaWidget::Search() ui_->isa_tree_view_->selectionModel()->select(view_index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); } + + for (const QModelIndex& match_view_index : matches_) + { + QModelIndex match_source_index = proxy_model_->mapToSource(match_view_index); + match_source_indices.emplace(match_source_index); + } + + ui_->isa_tree_view_->SetSearchMatchLineNumbers(match_source_indices); } } search_timer_.stop(); - // Update screen rect. + // Update the isa tree and its scroll bar. ui_->isa_tree_view_->viewport()->update(); + ui_->isa_tree_view_->verticalScrollBar()->update(); } void SharedIsaWidget::keyPressEvent(QKeyEvent* event) @@ -356,11 +392,27 @@ void SharedIsaWidget::ShowHideColumnClicked(bool checked) if (source_column_index != SharedIsaItemModel::kColumnCount) { + int proxy_index = proxy_model_->mapFromSource(proxy_model_->sourceModel()->index(0, source_column_index)).column(); + int visual_index = header->visualIndex(proxy_index); + proxy_model_->SetColumnVisibility(source_column_index, checked, header); + if (checked) { ui_->isa_tree_view_->resizeColumnToContents(proxy_model_->mapFromSource(proxy_model_->sourceModel()->index(0, source_column_index)).column()); } + else + { + // If the last column was just removed, resize the column with the next logical index to prevent a bug where it gets too large. + if (visual_index == proxy_model_->columnCount()) + { + // Check if there was a next logical index. + if (header->visualIndex(proxy_index) != -1) + { + ui_->isa_tree_view_->resizeColumnToContents(proxy_index); + } + } + } } // If there is only one column being shown, we need to disable the checkbox for that column. @@ -447,6 +499,21 @@ void SharedIsaWidget::ToggleViewingOptions() ui_->viewing_options_checkboxes_widget_->setVisible(viewing_options_visible_); } +void SharedIsaWidget::RefreshSearchMatchLineNumbers(const QModelIndex& index) +{ + Q_UNUSED(index); + + std::set match_source_indices; + + for (const QModelIndex& match_proxy_index : matches_) + { + QModelIndex match_source_index = proxy_model_->mapToSource(match_proxy_index); + match_source_indices.emplace(match_source_index); + } + + ui_->isa_tree_view_->SetSearchMatchLineNumbers(match_source_indices); +} + void SharedIsaWidget::BranchLabelNavigationForward() { if (ui_->branch_label_navigation_->ForwardButton().isEnabled()) diff --git a/custom_widgets/shared_isa_widget.h b/source/qt_common/custom_widgets/shared_isa_widget.h similarity index 90% rename from custom_widgets/shared_isa_widget.h rename to source/qt_common/custom_widgets/shared_isa_widget.h index c7e4ae7..ee0f9cc 100644 --- a/custom_widgets/shared_isa_widget.h +++ b/source/qt_common/custom_widgets/shared_isa_widget.h @@ -134,6 +134,12 @@ private slots: /// @brief Respond to Viewing Options button press; toggle the visibility state of the Viewing Options. void ToggleViewingOptions(); + /// @brief Force the isa scroll bar to recalculate the relative positions of search match indices, in case + /// any previous indices were expanded or collapsed. + /// + /// @param [in] index The view index of the code block that was expanded or collapsed. + void RefreshSearchMatchLineNumbers(const QModelIndex& index); + private: /// @brief Line validator class to restrict the 'Go to line...' input. class LineValidator final : public QValidator @@ -203,11 +209,11 @@ private slots: Ui::SharedIsaWidget* ui_; ///< The Qt ui form. SharedIsaProxyModel* proxy_model_; ///< Internal proxy model to assist hiding columns. - LineValidator* go_to_line_validator_; ///< Validate input to the 'Go To Line' line edit. - QTimer search_timer_; ///< Search delay timer. - QModelIndexList matches_; ///< Cache of list of matches from find query. - int find_index_; ///< Cache of current find selection index. - bool viewing_options_visible_; ///< Visibilty state of the Viewing Options widget. + LineValidator* go_to_line_validator_; ///< Validate input to the 'Go To Line' line edit. + QTimer search_timer_; ///< Search delay timer. + QModelIndexList matches_; ///< Cache of list of matches from find query. + int find_index_; ///< Cache of current find selection index. + bool viewing_options_visible_; ///< Visibilty state of the Viewing Options widget. }; #endif // QTCOMMON_CUSTOM_WIDGETS_SHARED_ISA_WIDGET_H_ diff --git a/custom_widgets/shared_isa_widget.ui b/source/qt_common/custom_widgets/shared_isa_widget.ui similarity index 93% rename from custom_widgets/shared_isa_widget.ui rename to source/qt_common/custom_widgets/shared_isa_widget.ui index 24c0a9e..251bb0d 100644 --- a/custom_widgets/shared_isa_widget.ui +++ b/source/qt_common/custom_widgets/shared_isa_widget.ui @@ -82,7 +82,7 @@ Viewing Options - + :/Resources/assets/PullDownOff_Gray.svg:/Resources/assets/PullDownOff_Gray.svg @@ -246,43 +246,43 @@ ScaledLabel QLabel -
custom_widgets/scaled_label.h
+
qt_common/custom_widgets/scaled_label.h
1
ArrowIconComboBox QPushButton -
custom_widgets/arrow_icon_combo_box.h
+
qt_common/custom_widgets/arrow_icon_combo_box.h
TextSearchWidget QLineEdit -
custom_widgets/text_search_widget.h
+
qt_common/custom_widgets/text_search_widget.h
ScaledCheckBox QCheckBox -
custom_widgets/scaled_check_box.h
+
qt_common/custom_widgets/scaled_check_box.h
SharedIsaTreeView QTreeView -
custom_widgets/shared_isa_tree_view.h
+
qt_common/custom_widgets/shared_isa_tree_view.h
SharedIsaBranchLabelNavigationWidget QWidget -
custom_widgets/shared_isa_branch_label_navigation_widget.h
+
qt_common/custom_widgets/shared_isa_branch_label_navigation_widget.h
1
ScaledLineEdit QLineEdit -
custom_widgets/scaled_line_edit.h
+
qt_common/custom_widgets/scaled_line_edit.h
- + diff --git a/custom_widgets/tab_bar.cpp b/source/qt_common/custom_widgets/tab_bar.cpp similarity index 79% rename from custom_widgets/tab_bar.cpp rename to source/qt_common/custom_widgets/tab_bar.cpp index 677da91..49886be 100644 --- a/custom_widgets/tab_bar.cpp +++ b/source/qt_common/custom_widgets/tab_bar.cpp @@ -15,8 +15,8 @@ #include #include -#include "utils/qt_util.h" -#include "utils/scaling_manager.h" +#include "qt_util.h" +#include "scaling_manager.h" TabBar::TabBar(QWidget* parent) : QTabBar(parent) @@ -71,7 +71,7 @@ void TabBar::setTabEnabled(int index, bool enable) QSize TabBar::minimumTabSizeHint(int index) const { - if (index == SpacerIndex() || tabText(index).isEmpty()) + if (index == SpacerIndex()) { return QSize(0, QTabBar::tabSizeHint(index).height()); } @@ -90,28 +90,7 @@ QSize TabBar::tabSizeHint(int index) const int height = QTabBar::tabSizeHint(index).height(); if (index == SpacerIndex()) { - QSize size = QSize(CalcSpacerWidth(), height); - return size; - } - else if ((index == count() - 1) && stretch_last_) - { - // Find the main container window - QMainWindow* main_window = nullptr; - for (QWidget* widget : qApp->topLevelWidgets()) - { - if (widget->inherits("QMainWindow")) - { - main_window = qobject_cast(widget); - break; - } - } - - if (main_window != nullptr) - { - // Stretch to fit the width of the window - int main_window_width = main_window->geometry().width(); - return QSize(main_window_width, height); - } + return QSize(CalcSpacerWidth(), height); } else if (tabText(index).isEmpty()) { @@ -119,15 +98,15 @@ QSize TabBar::tabSizeHint(int index) const QWidget* widget = tabButton(index, QTabBar::ButtonPosition::LeftSide); if (widget) { - width += widget->width(); + width = widget->geometry().width(); } widget = tabButton(index, QTabBar::ButtonPosition::RightSide); if (widget) { - width += widget->width(); + width = widget->geometry().width(); } - return QSize(width, height); + return QSize(width,height); } else { @@ -136,8 +115,6 @@ QSize TabBar::tabSizeHint(int index) const size_hint.setHeight(size_hint.height() + ScalingManager::Get().Scaled(contentsMargins().top() + contentsMargins().bottom())); return size_hint; } - - return QTabBar::tabSizeHint(index); } void TabBar::SetSpacerIndex(int index) diff --git a/custom_widgets/tab_bar.h b/source/qt_common/custom_widgets/tab_bar.h similarity index 100% rename from custom_widgets/tab_bar.h rename to source/qt_common/custom_widgets/tab_bar.h diff --git a/custom_widgets/tab_widget.cpp b/source/qt_common/custom_widgets/tab_widget.cpp similarity index 97% rename from custom_widgets/tab_widget.cpp rename to source/qt_common/custom_widgets/tab_widget.cpp index a88e1e5..59e9fa4 100644 --- a/custom_widgets/tab_widget.cpp +++ b/source/qt_common/custom_widgets/tab_widget.cpp @@ -7,7 +7,7 @@ //============================================================================= #include "tab_widget.h" -#include "utils/scaling_manager.h" +#include "scaling_manager.h" #include diff --git a/custom_widgets/tab_widget.h b/source/qt_common/custom_widgets/tab_widget.h similarity index 100% rename from custom_widgets/tab_widget.h rename to source/qt_common/custom_widgets/tab_widget.h diff --git a/custom_widgets/text_search_widget.cpp b/source/qt_common/custom_widgets/text_search_widget.cpp similarity index 95% rename from custom_widgets/text_search_widget.cpp rename to source/qt_common/custom_widgets/text_search_widget.cpp index ed62fba..57e407f 100644 --- a/custom_widgets/text_search_widget.cpp +++ b/source/qt_common/custom_widgets/text_search_widget.cpp @@ -7,8 +7,8 @@ #include "text_search_widget.h" -#include "utils/common_definitions.h" -#include "utils/scaling_manager.h" +#include "common_definitions.h" +#include "scaling_manager.h" static const QString kTextSearchStylesheet = "QLineEdit {\ diff --git a/custom_widgets/text_search_widget.h b/source/qt_common/custom_widgets/text_search_widget.h similarity index 100% rename from custom_widgets/text_search_widget.h rename to source/qt_common/custom_widgets/text_search_widget.h diff --git a/custom_widgets/timeline_view.cpp b/source/qt_common/custom_widgets/timeline_view.cpp similarity index 99% rename from custom_widgets/timeline_view.cpp rename to source/qt_common/custom_widgets/timeline_view.cpp index 5122925..5082830 100644 --- a/custom_widgets/timeline_view.cpp +++ b/source/qt_common/custom_widgets/timeline_view.cpp @@ -14,8 +14,8 @@ #include #include -#include "utils/common_definitions.h" -#include "utils/scaling_manager.h" +#include "common_definitions.h" +#include "scaling_manager.h" static const QColor kSelectionColor = QColor(0, 118, 215); static const quint64 kZoomToSelectionPercentage = 10; diff --git a/custom_widgets/timeline_view.h b/source/qt_common/custom_widgets/timeline_view.h similarity index 100% rename from custom_widgets/timeline_view.h rename to source/qt_common/custom_widgets/timeline_view.h diff --git a/custom_widgets/tree_view.cpp b/source/qt_common/custom_widgets/tree_view.cpp similarity index 100% rename from custom_widgets/tree_view.cpp rename to source/qt_common/custom_widgets/tree_view.cpp diff --git a/custom_widgets/tree_view.h b/source/qt_common/custom_widgets/tree_view.h similarity index 100% rename from custom_widgets/tree_view.h rename to source/qt_common/custom_widgets/tree_view.h diff --git a/utils/CMakeLists.txt b/source/qt_common/utils/CMakeLists.txt similarity index 72% rename from utils/CMakeLists.txt rename to source/qt_common/utils/CMakeLists.txt index b0d0e5f..68b907a 100644 --- a/utils/CMakeLists.txt +++ b/source/qt_common/utils/CMakeLists.txt @@ -1,8 +1,4 @@ -cmake_minimum_required (VERSION 3.5.1) -project (QtUtils) - -set (QTUTIL_VERSION_MAJOR 1) -set (QTUTIL_VERSION_MINOR 0) +cmake_minimum_required (VERSION 3.24) # Build Qt .ui MOC files for the library. set(CMAKE_AUTOMOC ON) @@ -36,10 +32,11 @@ file (GLOB CPP_SRC ) # Pick up the source files that are relevant to the platform -add_library(${PROJECT_NAME} STATIC ${CPP_SRC} ${CPP_INC}) - -# Find Qt libraries to resolve dependencies. -find_package(Qt5 COMPONENTS Widgets REQUIRED) +add_library(QtUtils STATIC ${CPP_SRC} ${CPP_INC}) # Set binary suffix -target_link_libraries(${PROJECT_NAME} Qt5::Widgets) +target_link_libraries(QtUtils Qt::Widgets) + +target_include_directories(QtUtils PUBLIC ${PROJECT_SOURCE_DIR}/source PRIVATE . ../custom_widgets) + +devtools_target_options(QtUtils) \ No newline at end of file diff --git a/utils/color_generator.cpp b/source/qt_common/utils/color_generator.cpp similarity index 100% rename from utils/color_generator.cpp rename to source/qt_common/utils/color_generator.cpp diff --git a/utils/color_generator.h b/source/qt_common/utils/color_generator.h similarity index 100% rename from utils/color_generator.h rename to source/qt_common/utils/color_generator.h diff --git a/utils/color_palette.cpp b/source/qt_common/utils/color_palette.cpp similarity index 100% rename from utils/color_palette.cpp rename to source/qt_common/utils/color_palette.cpp diff --git a/utils/color_palette.h b/source/qt_common/utils/color_palette.h similarity index 100% rename from utils/color_palette.h rename to source/qt_common/utils/color_palette.h diff --git a/source/qt_common/utils/common_definitions.h b/source/qt_common/utils/common_definitions.h new file mode 100644 index 0000000..fcf646a --- /dev/null +++ b/source/qt_common/utils/common_definitions.h @@ -0,0 +1,121 @@ +//============================================================================= +/// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved. +/// \author AMD Developer Tools Team +/// \file +/// \brief A set of common definitions used across multiple QtCommon components. +//============================================================================= + +#ifndef QTCOMMON_UTILS_COMMON_DEFINITIONS_H_ +#define QTCOMMON_UTILS_COMMON_DEFINITIONS_H_ + +/// Conversion factors between font points and pixels. +static const float kPointsToPixels = 1.33f; + +/// Conversion factors between pixels and font points. +static const float kPixelsToPoints = 0.75f; + +/// Default font point size for buttons. +static const float kButtonFontPointSize = 9.75f; + +/// Default font pixel size for buttons. +static const int kButtonFontPixelSize = kButtonFontPointSize * kPointsToPixels; + +/// Default check box width in pixels. +static const int kDefaultCheckBoxWidth = 10; + +/// Default ruler height in pixels. +static const int kDefaultRulerHeight = 50; + +/// Dark theme link button stylesheet. +const static QString kDarkLinkButtonStylesheet( + "QPushButton" + "{" + "background-color: none;" + "color: rgb(42, 130, 218);" + "border: none;" + "text-align: left" + "}" + + "QPushButton:hover" + "{" + "background-color: none;" + "color: rgb(255, 128, 0);" + "}"); + +/// Light theme link button stylesheet. +const static QString kLinkButtonStylesheet( + "QPushButton" + "{" + "background-color: none;" + "color: rgb(0, 0, 255);" + "border: none;" + "text-align: left" + "}" + + "QPushButton:hover" + "{" + "background-color: none;" + "color: rgb(255, 128, 0);" + "}"); + +#ifdef Q_OS_WIN + +/// Value to set Windows to use dark mode colors for the window title bar. +static const int kUseDarkModeColors = 26; + +#endif + +struct RecentFileData +{ + QString path; ///< Full path to the file + QString keywords; ///< Keywords designated to this trace + QString api; ///< DX12 or Vulkan + QString created; ///< When was this trace created? + QString accessed; ///< When was this trace read? + QString events; ///< How many events in this trace? + QString device_id; ///< The GPU used to collect this trace + QString device_revision_id; ///< The GPU's revision ID + QString device_string; ///< The device string as reported by the driver +}; + +/// Struct to keep track of colors for custom painting. +struct DefaultThemeColors +{ + QColor graphics_scene_text_color; ///< Default text color. + QColor link_text_color; ///< Default link text color. + QColor arrow_icon_border_color; ///< Default border color for the arow icon combo box. + QColor column_separator_color; ///< Default column separator color for the shared isa tree view. + QColor isa_background_row_color; ///< Default secondary background row color in the shared isa viewer. + QColor isa_search_match_row_color; ///< Default search match row color in the shared isa viewer. + QColor quick_link_button_background_color; ///< Background color of the quick links button for light theme. + QColor ruler_marker_color; ///< Marker color for the ruler widget. + QColor ruler_edge_color; ///< Edge color for the ruler widget. + QColor ruler_background_color; ///< Background color for the ruler widget. + + QString link_button_style_sheet; ///< Default link_button style sheet. +}; + +enum TimeUnitType +{ + kTimeUnitTypeMin, ///< The minimum value of the TimeUnitType enums + kTimeUnitTypeClk = kTimeUnitTypeMin, ///< Hardware clocks + kTimeUnitTypeNanosecond, ///< Nanoseconds (1 / 1,000,000,000 seconds) + kTimeUnitTypeMicrosecond, ///< Microseconds (1 / 1,000,000 seconds) + kTimeUnitTypeMillisecond, ///< Milliseconds (1 / 1,000 seconds) + kTimeUnitTypeSecond, ///< Seconds + kTimeUnitTypeMinute, ///< Minutes + kTimeUnitTypeHour, ///< Hours + + kTimeUnitTypeMax, ///< The maximum value of the TimeUnitType enums (not a valid time unit) +}; + +/// \brief Enum for all color themes +enum ColorThemeType +{ + kColorThemeTypeLight = 0, ///< Light theme. + kColorThemeTypeDark = 1, ///< Dark theme. + + kColorThemeTypeCount ///< Number of theme types. +}; + +#endif // QTCOMMON_UTILS_COMMON_DEFINITIONS_H_ diff --git a/utils/locale_setting.cpp b/source/qt_common/utils/locale_setting.cpp similarity index 98% rename from utils/locale_setting.cpp rename to source/qt_common/utils/locale_setting.cpp index 8fc1139..c256edf 100644 --- a/utils/locale_setting.cpp +++ b/source/qt_common/utils/locale_setting.cpp @@ -8,6 +8,9 @@ #include "locale_setting.h" #ifdef _WIN32 +#ifndef NOMINMAX +#define NOMINMAX +#endif #include #endif //_WIN32 diff --git a/utils/locale_setting.h b/source/qt_common/utils/locale_setting.h similarity index 100% rename from utils/locale_setting.h rename to source/qt_common/utils/locale_setting.h diff --git a/utils/model_view_mapper.cpp b/source/qt_common/utils/model_view_mapper.cpp similarity index 100% rename from utils/model_view_mapper.cpp rename to source/qt_common/utils/model_view_mapper.cpp diff --git a/utils/model_view_mapper.h b/source/qt_common/utils/model_view_mapper.h similarity index 100% rename from utils/model_view_mapper.h rename to source/qt_common/utils/model_view_mapper.h diff --git a/utils/qt_util.cpp b/source/qt_common/utils/qt_util.cpp similarity index 63% rename from utils/qt_util.cpp rename to source/qt_common/utils/qt_util.cpp index 49e5f32..ec4d293 100644 --- a/utils/qt_util.cpp +++ b/source/qt_common/utils/qt_util.cpp @@ -10,20 +10,39 @@ #include #include +#include #include #include #include #include #include +#include +#include #include #include #include "common_definitions.h" #include "scaling_manager.h" -#ifdef _WIN32 +#ifdef Q_OS_WIN +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include #pragma warning(disable : 4714) // prevent warning caused by QString::trimmed() -#endif // _WIN32 + +/// Helper class to set the windows compostion attribute data. +struct WindowCompositioAttributeData +{ + int attribute; ///< The windows composition attribute that will be changed, use dark mode colors. + PVOID pv_data; ///< The value of that attribute, true or false. + SIZE_T cb_data; ///< Size of the value. +}; + +/// Function to set the Window color. +using fnSetWindowCompositionAttribute = BOOL(WINAPI*)(HWND hwnd, WindowCompositioAttributeData*); + +#endif // Q_OS_WIN namespace QtCommon { @@ -97,7 +116,7 @@ namespace QtCommon } const int row_count = model->rowCount(); - const int elide_width = QtUtils::GetTextWidth(tree_view->font(), QString(0x2026)); + const int elide_width = QtUtils::GetTextWidth(tree_view->font(), QString(QChar(0x2026))); QFontMetrics fm(header->font()); header->setFixedHeight(fm.height() + (margin * 2)); @@ -154,7 +173,7 @@ namespace QtCommon } const int row_count = model->rowCount(); - const int elide_width = QtUtils::GetTextWidth(table->font(), QString(0x2026)); + const int elide_width = QtUtils::GetTextWidth(table->font(), QString(QChar(0x2026))); QFontMetrics fm(header->font()); header->setFixedHeight(fm.height() + (margin * 2)); @@ -215,7 +234,7 @@ namespace QtCommon } const int row_count = model->rowCount(); - const int elide_width = QtCommon::QtUtils::GetTextWidth(tree_view->font(), QString(0x2026)); + const int elide_width = QtCommon::QtUtils::GetTextWidth(tree_view->font(), QString(QChar(0x2026))); for (int column = 0; column < column_count; column++) { @@ -391,6 +410,17 @@ namespace QtCommon } break; + case kTimeUnitTypeHour: { + out.setRealNumberPrecision(0); + uint64_t hours = static_cast(time / (60 * 60 * 1000000000.0)); + uint64_t mins = static_cast(fmod((time / (60 * 1000000000.0)), 60)); + uint64_t secs = static_cast(fmod((time / 1000000000.0), 60)); + uint64_t fraction = static_cast(fmod((time / 10000.0), 100000)); + out << hours << ":" << QString::number(mins).rightJustified(2, '0') << ":" << QString::number(secs).rightJustified(2, '0') << "." + << QString::number(fraction).leftJustified(5, '0'); + } + break; + case kTimeUnitTypeClk: default: out << (quint64)clk << " clk"; @@ -437,6 +467,11 @@ namespace QtCommon int QtUtils::ShowMessageBox(QWidget* parent, QMessageBox::StandardButtons buttons, QMessageBox::Icon icon, const QString& title, const QString& message) { QMessageBox message_box(parent); + + #ifdef Q_OS_WIN + SetDarkWindowTitleBar(message_box.winId(), ColorTheme::Get().GetColorTheme() == kColorThemeTypeDark); + #endif + message_box.setWindowTitle(title); message_box.setText(message); message_box.setStandardButtons(buttons); @@ -446,4 +481,168 @@ namespace QtCommon return message_box.exec(); } +#ifdef Q_OS_WIN + void QtUtils::SetDarkWindowTitleBar(WId window_id, bool set_dark) + { + HWND hwnd = reinterpret_cast(window_id); + + HMODULE user32 = GetModuleHandleW(L"user32.dll"); + fnSetWindowCompositionAttribute SetWindowCompositionAttribute = + reinterpret_cast(GetProcAddress(user32, "SetWindowCompositionAttribute")); + BOOL dark = TRUE; + if (!set_dark) + { + dark = FALSE; + } + WindowCompositioAttributeData attrib_data = {kUseDarkModeColors, &dark, sizeof(dark)}; + SetWindowCompositionAttribute(hwnd, &attrib_data); + } +#endif + + ColorThemeType QtUtils::DetectOsSetting() + { +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + Qt::ColorScheme color_scheme = QGuiApplication::styleHints()->colorScheme(); + if (color_scheme == Qt::ColorScheme::Light) + { + return kColorThemeTypeLight; + } + + if (color_scheme == Qt::ColorScheme::Dark) + { + return kColorThemeTypeDark; + } +#endif + +#ifdef Q_OS_WIN + QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", QSettings::NativeFormat); + if (settings.value("AppsUseLightTheme") == 0) + { + return kColorThemeTypeDark; + } + else + { + return kColorThemeTypeLight; + } +#endif + +#ifdef Q_OS_LINUX + QStringList string_list = (QStringList() << "get" + << "org.gnome.desktop.interface" + << "gtk-theme"); + + QProcess process; + process.start("gsettings", string_list); + process.waitForFinished(-1); + + QByteArray std_out = process.readAllStandardOutput(); + QByteArray std_err = process.readAllStandardError(); + + if (std_out.contains("-dark")) + { + return kColorThemeTypeDark; + } + else + { + return kColorThemeTypeLight; + } +#endif + + return kColorThemeTypeLight; + } + + QtUtils::ColorTheme& QtUtils::ColorTheme::Get() + { + static ColorTheme instance; + return instance; + } + + ColorThemeType QtUtils::ColorTheme::GetColorTheme() + { + return theme_type_; + } + + DefaultThemeColors QtUtils::ColorTheme::GetCurrentThemeColors() + { + return theme_colors_[theme_type_]; + } + + QPalette QtUtils::ColorTheme::GetCurrentPalette() + { + return palette_[theme_type_]; + } + + void QtUtils::ColorTheme::SetColorTheme(ColorThemeType color_theme) + { + theme_type_ = color_theme; + } + + QtUtils::ColorTheme::ColorTheme() + { + theme_colors_[kColorThemeTypeLight].graphics_scene_text_color = Qt::black; + theme_colors_[kColorThemeTypeLight].link_text_color = QColor(0, 0, 255); + theme_colors_[kColorThemeTypeLight].arrow_icon_border_color = Qt::black; + theme_colors_[kColorThemeTypeLight].column_separator_color = QColor(230, 230, 230); + theme_colors_[kColorThemeTypeLight].isa_background_row_color = QColor(240, 240, 240); + theme_colors_[kColorThemeTypeLight].isa_search_match_row_color = QColor(192, 192, 255); + theme_colors_[kColorThemeTypeLight].quick_link_button_background_color = QColor(241, 241, 241); + theme_colors_[kColorThemeTypeLight].ruler_marker_color = QColor(51, 51, 51); + theme_colors_[kColorThemeTypeLight].ruler_edge_color = QColor(230, 230, 230); + theme_colors_[kColorThemeTypeLight].ruler_background_color = QColor(248, 248, 248); + theme_colors_[kColorThemeTypeLight].link_button_style_sheet = kLinkButtonStylesheet; + + theme_colors_[kColorThemeTypeDark].graphics_scene_text_color = QColor(240, 240, 240); + theme_colors_[kColorThemeTypeDark].link_text_color = QColor(42, 130, 218); + theme_colors_[kColorThemeTypeDark].arrow_icon_border_color = QColor(240, 240, 240); + theme_colors_[kColorThemeTypeDark].column_separator_color = QColor(20, 20, 20); + theme_colors_[kColorThemeTypeDark].isa_background_row_color = QColor(50, 50, 50); + theme_colors_[kColorThemeTypeDark].isa_search_match_row_color = QColor(40, 40, 120); + theme_colors_[kColorThemeTypeDark].quick_link_button_background_color = QColor(50, 50, 50); + theme_colors_[kColorThemeTypeDark].ruler_marker_color = QColor(230, 230, 230); + theme_colors_[kColorThemeTypeDark].ruler_edge_color = QColor(50, 50, 50); + theme_colors_[kColorThemeTypeDark].ruler_background_color = QColor(20, 20, 20); + theme_colors_[kColorThemeTypeDark].link_button_style_sheet = kDarkLinkButtonStylesheet; + + QColor white_color = Qt::white; + QColor very_light_color = QColor(240, 240, 240); + QColor black_text = Qt::black; + QColor disabled_color = Qt::gray; + + palette_[kColorThemeTypeLight].setColor(QPalette::Window, white_color); + palette_[kColorThemeTypeLight].setColor(QPalette::WindowText, black_text); + palette_[kColorThemeTypeLight].setColor(QPalette::Base, white_color); + palette_[kColorThemeTypeLight].setColor(QPalette::AlternateBase, very_light_color); + palette_[kColorThemeTypeLight].setColor(QPalette::Text, black_text); + palette_[kColorThemeTypeLight].setColor(QPalette::Disabled, QPalette::Text, disabled_color); + palette_[kColorThemeTypeLight].setColor(QPalette::Button, white_color); + palette_[kColorThemeTypeLight].setColor(QPalette::ButtonText, black_text); + palette_[kColorThemeTypeLight].setColor(QPalette::Disabled, QPalette::ButtonText, disabled_color); + palette_[kColorThemeTypeLight].setColor(QPalette::BrightText, Qt::red); + palette_[kColorThemeTypeLight].setColor(QPalette::Link, QColor(0, 0, 255)); + palette_[kColorThemeTypeLight].setColor(QPalette::Highlight, QColor(30, 120, 230)); + palette_[kColorThemeTypeLight].setColor(QPalette::HighlightedText, Qt::white); + palette_[kColorThemeTypeLight].setColor(QPalette::Disabled, QPalette::HighlightedText, disabled_color); + + QColor very_dark_color = QColor(20, 20, 20); + QColor dark_color = QColor(35, 35, 35); + QColor white_text = QColor(240, 240, 240); + + palette_[kColorThemeTypeDark].setColor(QPalette::Window, dark_color); + palette_[kColorThemeTypeDark].setColor(QPalette::WindowText, white_text); + palette_[kColorThemeTypeDark].setColor(QPalette::Base, dark_color); + palette_[kColorThemeTypeDark].setColor(QPalette::AlternateBase, very_dark_color); + palette_[kColorThemeTypeDark].setColor(QPalette::Text, white_text); + palette_[kColorThemeTypeDark].setColor(QPalette::Disabled, QPalette::Text, disabled_color); + palette_[kColorThemeTypeDark].setColor(QPalette::Button, dark_color); + palette_[kColorThemeTypeDark].setColor(QPalette::ButtonText, white_text); + palette_[kColorThemeTypeDark].setColor(QPalette::Disabled, QPalette::ButtonText, disabled_color); + palette_[kColorThemeTypeDark].setColor(QPalette::BrightText, Qt::red); + palette_[kColorThemeTypeDark].setColor(QPalette::Link, QColor(42, 130, 218)); + palette_[kColorThemeTypeDark].setColor(QPalette::Highlight, QColor(40, 80, 160, 140)); + palette_[kColorThemeTypeDark].setColor(QPalette::HighlightedText, Qt::white); + palette_[kColorThemeTypeDark].setColor(QPalette::Disabled, QPalette::HighlightedText, disabled_color); + + theme_type_ = kColorThemeTypeLight; + } + } // namespace QtCommon diff --git a/utils/qt_util.h b/source/qt_common/utils/qt_util.h similarity index 72% rename from utils/qt_util.h rename to source/qt_common/utils/qt_util.h index dcdc85a..31f3518 100644 --- a/utils/qt_util.h +++ b/source/qt_common/utils/qt_util.h @@ -20,6 +20,8 @@ #include #include +#include "common_definitions.h" + namespace QtCommon { namespace QtUtils @@ -119,6 +121,61 @@ namespace QtCommon /// \return message box exec result int ShowMessageBox(QWidget* parent, QMessageBox::StandardButtons buttons, QMessageBox::Icon icon, const QString& title, const QString& message); +#ifdef Q_OS_WIN + /// \brief Helper function to set the title bar to be dark in windows + /// \param window_id the window id + /// \param set_dark whether the window title bar should be set to dark. + void SetDarkWindowTitleBar(WId window_id, bool set_dark = true); +#endif + + /// \brief Detects the app color theme settings of the current OS + /// \return The app color theme of the OS. Returns light theme by default. + ColorThemeType DetectOsSetting(); + + /// \brief Helper singleton class to keep track of current color theme + class ColorTheme : public QObject + { + Q_OBJECT + + public: + /// \brief Get the instance of the class + static ColorTheme& Get(); + + /// \brief Get the current color theme + /// \return The enum value of the color theme + ColorThemeType GetColorTheme(); + + /// \brief Get a container of commonly used colors based on the current color theme. + /// \return The container of commonly used colors. + DefaultThemeColors GetCurrentThemeColors(); + + /// \brief Get a QPalette based on the current color theme. + /// \return The palette for the current color theme. + QPalette GetCurrentPalette(); + + /// \brief Set the current color theme + /// \param theme_type The color theme that is to be applied. + void SetColorTheme(ColorThemeType theme_type); + + signals: + void ColorThemeUpdated(); + + private: + /// \brief Constructor defaults to light color theme + ColorTheme(); + + /// \brief Default destructor + ~ColorTheme() = default; + + /// \brief Turn off copy and assignment constructors + ColorTheme(const ColorTheme&) = delete; + ColorTheme operator=(ColorTheme&) = delete; + + ColorThemeType theme_type_; ///< Holds the current color theme value. + DefaultThemeColors theme_colors_[kColorThemeTypeCount]; ///< Array of commonly used colors with a value for each color theme. + QPalette palette_[kColorThemeTypeCount]; ///< Array of palettes for each color theme. + }; + } // namespace QtUtils } // namespace QtCommon diff --git a/utils/restore_cursor_position.h b/source/qt_common/utils/restore_cursor_position.h similarity index 100% rename from utils/restore_cursor_position.h rename to source/qt_common/utils/restore_cursor_position.h diff --git a/utils/scaling_manager.cpp b/source/qt_common/utils/scaling_manager.cpp similarity index 100% rename from utils/scaling_manager.cpp rename to source/qt_common/utils/scaling_manager.cpp diff --git a/utils/scaling_manager.h b/source/qt_common/utils/scaling_manager.h similarity index 100% rename from utils/scaling_manager.h rename to source/qt_common/utils/scaling_manager.h diff --git a/source/qt_common/utils/shared_isa_dictionary.cpp b/source/qt_common/utils/shared_isa_dictionary.cpp new file mode 100644 index 0000000..e595f0c --- /dev/null +++ b/source/qt_common/utils/shared_isa_dictionary.cpp @@ -0,0 +1,110 @@ +//============================================================================= +// Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. +/// @author AMD Developer Tools Team +/// @file +/// @brief Implementation for an isa dictionary. +//============================================================================= + +#include "shared_isa_dictionary.h" + +#include "common_definitions.h" +#include "qt_util.h" + +namespace QtCommon +{ + namespace QtUtils + { + IsaColorCodingDictionaryInstance& IsaColorCodingDictionaryInstance::GetInstance() + { + static IsaColorCodingDictionaryInstance instance; + return instance; + } + + bool IsaColorCodingDictionaryInstance::ShouldHighlight(const std::string& str, QColor& color) const + { + color = QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().graphics_scene_text_color; + + QColor tree_colors; + + bool should_highlight = prefix_tree_[QtCommon::QtUtils::ColorTheme::Get().GetColorTheme()].PrefixFoundInTree(str, tree_colors); + + if (tree_colors != nullptr) + { + color = tree_colors; + } + + return should_highlight; + } + + IsaColorCodingDictionaryInstance::IsaColorCodingDictionaryInstance() + { + prefix_tree_[kColorThemeTypeLight].Insert("s_buffer", kIsaLightThemeColorLightOrange); + prefix_tree_[kColorThemeTypeLight].Insert("s_load", kIsaLightThemeColorLightOrange); + prefix_tree_[kColorThemeTypeLight].Insert("s_waitcnt", kIsaLightThemeColorPink); + prefix_tree_[kColorThemeTypeLight].Insert("expcnt", kIsaLightThemeColorPink); + prefix_tree_[kColorThemeTypeLight].Insert("vmcnt", kIsaLightThemeColorPink); + prefix_tree_[kColorThemeTypeLight].Insert("lgkmcnt", kIsaLightThemeColorPink); + prefix_tree_[kColorThemeTypeLight].Insert("s_swap", kIsaLightThemeColorRed); + prefix_tree_[kColorThemeTypeLight].Insert("s_branch", kIsaLightThemeColorRed); + prefix_tree_[kColorThemeTypeLight].Insert("s_cbranch", kIsaLightThemeColorRed); + prefix_tree_[kColorThemeTypeLight].Insert("s_setpc", kIsaLightThemeColorRed); + prefix_tree_[kColorThemeTypeLight].Insert("ds_", kIsaLightThemeColorBlue); + prefix_tree_[kColorThemeTypeLight].Insert("buffer_", kIsaLightThemeColorPurple); + prefix_tree_[kColorThemeTypeLight].Insert("tbuffer_", kIsaLightThemeColorPurple); + prefix_tree_[kColorThemeTypeLight].Insert("image_", kIsaLightThemeColorPurple); + prefix_tree_[kColorThemeTypeLight].Insert("global_load", kIsaLightThemeColorPurple); + prefix_tree_[kColorThemeTypeLight].Insert("idxen", kIsaLightThemeColorPurple); + prefix_tree_[kColorThemeTypeLight].Insert("s_", kIsaLightThemeColorBlue); + prefix_tree_[kColorThemeTypeLight].Insert("s[", kIsaLightThemeColorBlue); // Scalar register. + prefix_tree_[kColorThemeTypeLight].Insert("[s", kIsaLightThemeColorBlue); // Scalar register range. + prefix_tree_[kColorThemeTypeLight].Insert("|s", kIsaLightThemeColorBlue); // Scalar register absolute value. + prefix_tree_[kColorThemeTypeLight].Insert("-s", kIsaLightThemeColorBlue); // Scalar register negative value. + prefix_tree_[kColorThemeTypeLight].Insert("v_", kIsaLightThemeColorLightGreen); + prefix_tree_[kColorThemeTypeLight].Insert("v[", kIsaLightThemeColorLightGreen); // Vector register. + prefix_tree_[kColorThemeTypeLight].Insert("[v", kIsaLightThemeColorLightGreen); // Vector register range. + prefix_tree_[kColorThemeTypeLight].Insert("|v", kIsaLightThemeColorLightGreen); // Vector register absolute value. + prefix_tree_[kColorThemeTypeLight].Insert("-v", kIsaLightThemeColorLightGreen); // Vector register negative value. + prefix_tree_[kColorThemeTypeLight].Insert("//", kIsaLightThemeColorLightBlue); // Comments. + + for (size_t i = 0; i <= 9; ++i) + { + prefix_tree_[kColorThemeTypeLight].Insert("s" + std::to_string(i), kIsaLightThemeColorBlue); + prefix_tree_[kColorThemeTypeLight].Insert("v" + std::to_string(i), kIsaLightThemeColorLightGreen); + } + + prefix_tree_[kColorThemeTypeDark].Insert("s_buffer", kIsaDarkThemeColorLightOrange); + prefix_tree_[kColorThemeTypeDark].Insert("s_load", kIsaDarkThemeColorLightOrange); + prefix_tree_[kColorThemeTypeDark].Insert("s_waitcnt", kIsaDarkThemeColorPink); + prefix_tree_[kColorThemeTypeDark].Insert("expcnt", kIsaDarkThemeColorPink); + prefix_tree_[kColorThemeTypeDark].Insert("vmcnt", kIsaDarkThemeColorPink); + prefix_tree_[kColorThemeTypeDark].Insert("lgkmcnt", kIsaDarkThemeColorPink); + prefix_tree_[kColorThemeTypeDark].Insert("s_swap", kIsaDarkThemeColorRed); + prefix_tree_[kColorThemeTypeDark].Insert("s_branch", kIsaDarkThemeColorRed); + prefix_tree_[kColorThemeTypeDark].Insert("s_cbranch", kIsaDarkThemeColorRed); + prefix_tree_[kColorThemeTypeDark].Insert("s_setpc", kIsaDarkThemeColorRed); + prefix_tree_[kColorThemeTypeDark].Insert("ds_", kIsaDarkThemeColorBlue); + prefix_tree_[kColorThemeTypeDark].Insert("buffer_", kIsaDarkThemeColorPurple); + prefix_tree_[kColorThemeTypeDark].Insert("tbuffer_", kIsaDarkThemeColorPurple); + prefix_tree_[kColorThemeTypeDark].Insert("image_", kIsaDarkThemeColorPurple); + prefix_tree_[kColorThemeTypeDark].Insert("global_load", kIsaDarkThemeColorPurple); + prefix_tree_[kColorThemeTypeDark].Insert("idxen", kIsaDarkThemeColorPurple); + prefix_tree_[kColorThemeTypeDark].Insert("s_", kIsaDarkThemeColorBlue); + prefix_tree_[kColorThemeTypeDark].Insert("s[", kIsaDarkThemeColorBlue); // Scalar register. + prefix_tree_[kColorThemeTypeDark].Insert("[s", kIsaDarkThemeColorBlue); // Scalar register range. + prefix_tree_[kColorThemeTypeDark].Insert("|s", kIsaDarkThemeColorBlue); // Scalar register absolute value. + prefix_tree_[kColorThemeTypeDark].Insert("-s", kIsaDarkThemeColorBlue); // Scalar register negative value. + prefix_tree_[kColorThemeTypeDark].Insert("v_", kIsaDarkThemeColorLightGreen); + prefix_tree_[kColorThemeTypeDark].Insert("v[", kIsaDarkThemeColorLightGreen); // Vector register. + prefix_tree_[kColorThemeTypeDark].Insert("[v", kIsaDarkThemeColorLightGreen); // Vector register range. + prefix_tree_[kColorThemeTypeDark].Insert("|v", kIsaDarkThemeColorLightGreen); // Vector register absolute value. + prefix_tree_[kColorThemeTypeDark].Insert("-v", kIsaDarkThemeColorLightGreen); // Vector register negative value. + prefix_tree_[kColorThemeTypeDark].Insert("//", kIsaDarkThemeColorLightBlue); // Comments. + + for (size_t i = 0; i <= 9; ++i) + { + prefix_tree_[kColorThemeTypeDark].Insert("s" + std::to_string(i), kIsaDarkThemeColorBlue); + prefix_tree_[kColorThemeTypeDark].Insert("v" + std::to_string(i), kIsaDarkThemeColorLightGreen); + } + } + } // namespace QtUtils +} // namespace QtCommon diff --git a/utils/shared_isa_dictionary.h b/source/qt_common/utils/shared_isa_dictionary.h similarity index 80% rename from utils/shared_isa_dictionary.h rename to source/qt_common/utils/shared_isa_dictionary.h index adbdd92..490cc7e 100644 --- a/utils/shared_isa_dictionary.h +++ b/source/qt_common/utils/shared_isa_dictionary.h @@ -15,20 +15,35 @@ #include #include +#include "common_definitions.h" + namespace QtCommon { namespace QtUtils { - static const QColor kIsaColorLightOrange = QColor(255, 128, 0); ///< Light orange. - static const QColor kIsaColorPink = QColor(255, 0, 128); ///< Pink. - static const QColor kIsaColorLightPink = QColor(255, 142, 255, 200); ///< Light pink. - static const QColor kIsaColorLightLightPink = QColor(255, 200, 255, 200); ///< Light light pink. - static const QColor kIsaColorRed = QColor(255, 0, 0); ///< Red. - static const QColor kIsaColorBlue = QColor(0, 0, 255); ///< Blue. - static const QColor kIsaColorLightBlue = QColor(0, 128, 213); ///< Light blue. - static const QColor kIsaColorLightGreen = QColor(0, 128, 0); ///< Light green. - static const QColor kIsaColorPurple = QColor(128, 0, 255); ///< Purple. - static const QColor kIsaColorDarkMagenta = Qt::darkMagenta; ///< Dark magenta. + // Light Theme Colors. + static const QColor kIsaLightThemeColorLightOrange = QColor(255, 128, 0); ///< Light orange. + static const QColor kIsaLightThemeColorPink = QColor(255, 0, 128); ///< Pink. + static const QColor kIsaLightThemeColorLightPink = QColor(255, 142, 255, 200); ///< Light pink. + static const QColor kIsaLightThemeColorLightLightPink = QColor(255, 200, 255, 200); ///< Light light pink. + static const QColor kIsaLightThemeColorRed = QColor(255, 0, 0); ///< Red. + static const QColor kIsaLightThemeColorBlue = QColor(0, 0, 255); ///< Blue. + static const QColor kIsaLightThemeColorLightBlue = QColor(0, 128, 213); ///< Light blue. + static const QColor kIsaLightThemeColorLightGreen = QColor(0, 128, 0); ///< Light green. + static const QColor kIsaLightThemeColorPurple = QColor(128, 0, 255); ///< Purple. + static const QColor kIsaLightThemeColorDarkMagenta = Qt::darkMagenta; ///< Dark magenta. + + // Dark theme colors. + static const QColor kIsaDarkThemeColorLightOrange = QColor(255, 128, 0); ///< Light orange. + static const QColor kIsaDarkThemeColorPink = QColor(240, 64, 128); ///< Pink. + static const QColor kIsaDarkThemeColorDarkDarkPurple = QColor(60, 0, 60, 200); ///< Dark dark purple. + static const QColor kIsaDarkThemeColorLightLightPink = QColor(240, 200, 240, 200); ///< Light light pink. + static const QColor kIsaDarkThemeColorRed = QColor(240, 64, 64); ///< Red. + static const QColor kIsaDarkThemeColorBlue = QColor(64, 96, 220); ///< Blue. + static const QColor kIsaDarkThemeColorLightBlue = QColor(64, 164, 212); ///< Light blue. + static const QColor kIsaDarkThemeColorLightGreen = QColor(32, 142, 32); ///< Light green. + static const QColor kIsaDarkThemeColorPurple = QColor(164, 64, 240); ///< Purple. + static const QColor kIsaDarkThemeColorDarkMagenta = QColor(142, 64, 142); ///< Dark magenta. /// @brief Class defining a prefix tree node. template @@ -256,7 +271,7 @@ namespace QtCommon /// @brief Disable assignment operator. IsaColorCodingDictionaryInstance& operator=(const IsaColorCodingDictionaryInstance&) = delete; - PrefixTree prefix_tree_; ///< The prefix tree that is used as a dictionary to decide the coloring profile. + PrefixTree prefix_tree_[kColorThemeTypeCount]; ///< The prefix tree that is used as a dictionary to decide the coloring profile. }; } // namespace QtUtils } // namespace QtCommon diff --git a/utils/zoom_icon_group_manager.cpp b/source/qt_common/utils/zoom_icon_group_manager.cpp similarity index 75% rename from utils/zoom_icon_group_manager.cpp rename to source/qt_common/utils/zoom_icon_group_manager.cpp index 5002aa7..482277f 100644 --- a/utils/zoom_icon_group_manager.cpp +++ b/source/qt_common/utils/zoom_icon_group_manager.cpp @@ -1,5 +1,5 @@ //============================================================================= -/// Copyright (c) 2019-2020 Advanced Micro Devices, Inc. All rights reserved. +/// Copyright (c) 2019-2023 Advanced Micro Devices, Inc. All rights reserved. /// \author AMD Developer Tools Team /// \file /// \brief Implementation for the zoom icon group manager class which handles @@ -56,3 +56,19 @@ void ZoomIconGroupManager::ZoomReset() zoom_reset_icon_->SetEnabled(false); zoom_to_selection_icon_->SetEnabled(false); } + +void ZoomIconGroupManager::SetButtonStates(bool zoom_in, bool zoom_out, bool zoom_selection, bool zoom_reset) +{ + zoom_in_icon_->SetEnabled(zoom_in); + zoom_out_icon_->SetEnabled(zoom_out); + zoom_reset_icon_->SetEnabled(zoom_reset); + zoom_to_selection_icon_->SetEnabled(zoom_selection); +} + +void ZoomIconGroupManager::GetButtonStates(bool& zoom_in, bool& zoom_out, bool& zoom_selection, bool& zoom_reset) +{ + zoom_in = zoom_in_icon_->IsEnabled(); + zoom_out = zoom_out_icon_->IsEnabled(); + zoom_reset = zoom_reset_icon_->IsEnabled(); + zoom_selection = zoom_to_selection_icon_->IsEnabled(); +} diff --git a/utils/zoom_icon_group_manager.h b/source/qt_common/utils/zoom_icon_group_manager.h similarity index 54% rename from utils/zoom_icon_group_manager.h rename to source/qt_common/utils/zoom_icon_group_manager.h index cc7614c..69d07ea 100644 --- a/utils/zoom_icon_group_manager.h +++ b/source/qt_common/utils/zoom_icon_group_manager.h @@ -1,5 +1,5 @@ //============================================================================= -/// Copyright (c) 2019-2020 Advanced Micro Devices, Inc. All rights reserved. +/// Copyright (c) 2019-2023 Advanced Micro Devices, Inc. All rights reserved. /// \author AMD Developer Tools Team /// \file /// \brief Header for the zoom icon group manager class which handles a group @@ -29,35 +29,59 @@ typedef struct ZoomIconManagerConfiguration QString zoom_to_selection_resource_disabled; ///< The resource for the zoom to selection icon when it is disabled. } ZoomIconManagerConfiguration; -/// Manages the interactions between zoom in, zoom out, zoom to selection, +/// @brief Manages the interactions between zoom in, zoom out, zoom to selection, /// and zoom reset buttons. class ZoomIconGroupManager { public: - /// Constructor - /// \param zoom_config The configuration for this object. + /// @brief Constructor. + /// + /// @param [in] zoom_config The configuration for this object. explicit ZoomIconGroupManager(const ZoomIconManagerConfiguration& zoom_config); - /// Destructor + /// @brief Destructor. ~ZoomIconGroupManager(); - /// Set up the icons for the 'zoom in' button. - /// \param zoom Is any further zoom in possible? True if so, false - /// if fully zoomed in + /// @brief Set up the icons for the 'zoom in' button. + /// + /// @param [in] zoom Is any further zoom in possible? True if so, false + /// if fully zoomed in. void ZoomIn(bool zoom); - /// Set up the icons for the 'zoom out' button. - /// \param zoom Is any further zoom out possible? True if so, false - /// if fully zoomed out + /// @brief Set up the icons for the 'zoom out' button. + /// + /// @param [in] zoom Is any further zoom out possible? True if so, false + /// if fully zoomed out. void ZoomOut(bool zoom); - /// Set up the icons for the 'zoom to selection' button. - /// \param selected_region Has a region been selected? True if so. + /// @brief Set up the icons for the 'zoom to selection' button. + /// + /// @param [in] selected_region Has a region been selected? True if so. void ZoomToSelection(bool selected_region); - /// Set up the icons for the 'zoom reset' button. + /// @brief Set up the icons for the 'zoom reset' button. void ZoomReset(); + /// @brief Explicitly set the button state parameters. + /// + /// Used for cases where the reset zoom position isn't at the minimum zoom level. + /// + /// @param [in] zoom_in Is any further zoom in possible? True if so, false otherwise. + /// @param [in] zoom_out Is any further zoom out possible? True if so, false otherwise. + /// @param [in] zoom_selection Is a zoom-to-selection possible? True if so, false otherwise. + /// @param [in] zoom_reset Is a reset possible? True if so, false otherwise. + void SetButtonStates(bool zoom_in, bool zoom_out, bool zoom_selection, bool zoom_reset); + + /// @brief Get the button state parameters. + /// + /// Used for when the manager is destroyed and recreated to save and restore zoom state. + /// + /// @param [out] zoom_in Set to whether any further zoom in is possible? True if so, false otherwise. + /// @param [out] zoom_out Set to whether any further zoom out is possible? True if so, false otherwise. + /// @param [out] zoom_selection Set to whether a zoom-to-selection is possible? True if so, false otherwise. + /// @param [out] zoom_reset Set to whether a reset is possible? True if so, false otherwise. + void GetButtonStates(bool& zoom_in, bool& zoom_out, bool& zoom_selection, bool& zoom_reset); + private: ZoomIconManager* zoom_in_icon_; ///< The zoom in icon. ZoomIconManager* zoom_out_icon_; ///< The zoom out icon. diff --git a/utils/zoom_icon_manager.cpp b/source/qt_common/utils/zoom_icon_manager.cpp similarity index 87% rename from utils/zoom_icon_manager.cpp rename to source/qt_common/utils/zoom_icon_manager.cpp index e738092..70b6bc4 100644 --- a/utils/zoom_icon_manager.cpp +++ b/source/qt_common/utils/zoom_icon_manager.cpp @@ -1,5 +1,5 @@ //============================================================================= -/// Copyright (c) 2019-2020 Advanced Micro Devices, Inc. All rights reserved. +/// Copyright (c) 2019-2023 Advanced Micro Devices, Inc. All rights reserved. /// \author AMD Developer Tools Team /// \file /// \brief Implementation for the zoom icon manager class. @@ -35,3 +35,8 @@ void ZoomIconManager::SetEnabled(bool enable) icon_->setEnabled(false); } } + +bool ZoomIconManager::IsEnabled() +{ + return icon_->isEnabled(); +} diff --git a/utils/zoom_icon_manager.h b/source/qt_common/utils/zoom_icon_manager.h similarity index 87% rename from utils/zoom_icon_manager.h rename to source/qt_common/utils/zoom_icon_manager.h index 578548b..86c2c35 100644 --- a/utils/zoom_icon_manager.h +++ b/source/qt_common/utils/zoom_icon_manager.h @@ -1,5 +1,5 @@ //============================================================================= -/// Copyright (c) 2019-2020 Advanced Micro Devices, Inc. All rights reserved. +/// Copyright (c) 2019-2023 Advanced Micro Devices, Inc. All rights reserved. /// \author AMD Developer Tools Team /// \file /// \brief Header for the zoom icon manager class. Handles the zoom icon @@ -31,6 +31,11 @@ class ZoomIconManager /// \param enable Is the state to be enabled void SetEnabled(bool enable); + /// @brief Get the state of a zoom icon. + /// + /// @return true if the zoom icon is enabled, false otherwise. + bool IsEnabled(); + private: QPushButton* icon_; ///< The ui icon widget QString enabled_asset_; ///< The asset corresponding to the enabled state diff --git a/source/version.h.in b/source/version.h.in new file mode 100644 index 0000000..1aab8ac --- /dev/null +++ b/source/version.h.in @@ -0,0 +1,24 @@ +//============================================================================= +// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved. +/// @author AMD Developer Tools Team +/// @file +/// @brief QtCommon version header +//============================================================================= + +#ifndef QTCOMMON_VERSION_H_ +#define QTCOMMON_VERSION_H_ + +#define STRINGIFY_MACRO_(a) #a +#define STRINGIFY_MACRO(a) STRINGIFY_MACRO_(a) +#define STRINGIFY_VERSION(major, minor, patch, build) STRINGIFY_MACRO(v) STRINGIFY_MACRO(major) "." STRINGIFY_MACRO(minor) "." STRINGIFY_MACRO(patch) "." STRINGIFY_MACRO(build) + +#define QTCOMMON_MAJOR_VERSION @QTCOMMON_MAJOR_VERSION@ ///< Major version number. +#define QTCOMMON_MINOR_VERSION @QTCOMMON_MINOR_VERSION@ ///< Minor version number. +#define QTCOMMON_PATCH_NUMBER @QTCOMMON_PATCH_NUMBER@ ///< Patch number. +#define QTCOMMON_BUILD_NUMBER @QTCOMMON_BUILD_NUMBER@ ///< Build number. +#define QTCOMMON_BUILD_SUFFIX @QTCOMMON_BUILD_SUFFIX@ ///< Build suffix +#define QTCOMMON_BUILD_DATE_STRING @DATE@ +#define QTCOMMON_BUILD_YEAR @YEAR@ +#define QTCOMMON_VERSION STRINGIFY_VERSION(QTCOMMON_MAJOR_VERSION, QTCOMMON_MINOR_VERSION, QTCOMMON_PATCH_NUMBER, QTCOMMON_BUILD_NUMBER) + +#endif diff --git a/utils/common_definitions.h b/utils/common_definitions.h deleted file mode 100644 index b8a5659..0000000 --- a/utils/common_definitions.h +++ /dev/null @@ -1,69 +0,0 @@ -//============================================================================= -/// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved. -/// \author AMD Developer Tools Team -/// \file -/// \brief A set of common definitions used across multiple QtCommon components. -//============================================================================= - -#ifndef QTCOMMON_UTILS_COMMON_DEFINITIONS_H_ -#define QTCOMMON_UTILS_COMMON_DEFINITIONS_H_ - -/// Conversion factors between font points and pixels. -static const float kPointsToPixels = 1.33f; - -/// Conversion factors between pixels and font points. -static const float kPixelsToPoints = 0.75f; - -/// Default font point size for buttons. -static const float kButtonFontPointSize = 9.75f; - -/// Default font pixel size for buttons. -static const int kButtonFontPixelSize = kButtonFontPointSize * kPointsToPixels; - -/// Default check box width in pixels. -static const int kDefaultCheckBoxWidth = 10; - -/// Default ruler height in pixels. -static const int kDefaultRulerHeight = 50; - -/// Link button stylesheet. -const static QString kLinkButtonStylesheet( - "QPushButton" - "{" - "color: rgb(0, 0, 255);" - "border: none;" - "text-align: left" - "}" - - "QPushButton:hover" - "{" - "color: rgb(255, 128, 0);" - "}"); - -struct RecentFileData -{ - QString path; ///< Full path to the file - QString keywords; ///< Keywords designated to this trace - QString api; ///< DX12 or Vulkan - QString created; ///< When was this trace created? - QString accessed; ///< When was this trace read? - QString events; ///< How many events in this trace? - QString device_id; ///< The GPU used to collect this trace - QString device_revision_id; ///< The GPU's revision ID - QString device_string; ///< The device string as reported by the driver -}; - -enum TimeUnitType -{ - kTimeUnitTypeMin, ///< The minimum value of the TimeUnitType enums - kTimeUnitTypeClk = kTimeUnitTypeMin, ///< Hardware clocks - kTimeUnitTypeNanosecond, ///< Nanoseconds (1 / 1,000,000,000 seconds) - kTimeUnitTypeMicrosecond, ///< Microseconds (1 / 1,000,000 seconds) - kTimeUnitTypeMillisecond, ///< Milliseconds (1 / 1,000 seconds) - kTimeUnitTypeSecond, ///< Seconds - kTimeUnitTypeMinute, ///< Minutes - - kTimeUnitTypeMax, ///< The maximum value of the TimeUnitType enums (not a valid time unit) -}; - -#endif // QTCOMMON_UTILS_COMMON_DEFINITIONS_H_ diff --git a/utils/shared_isa_dictionary.cpp b/utils/shared_isa_dictionary.cpp deleted file mode 100644 index 3acbe8b..0000000 --- a/utils/shared_isa_dictionary.cpp +++ /dev/null @@ -1,62 +0,0 @@ -//============================================================================= -// Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. -/// @author AMD Developer Tools Team -/// @file -/// @brief Implementation for an isa dictionary. -//============================================================================= - -#include "shared_isa_dictionary.h" - -namespace QtCommon -{ - namespace QtUtils - { - IsaColorCodingDictionaryInstance& IsaColorCodingDictionaryInstance::GetInstance() - { - static IsaColorCodingDictionaryInstance instance; - return instance; - } - - bool IsaColorCodingDictionaryInstance::ShouldHighlight(const std::string& str, QColor& color) const - { - return prefix_tree_.PrefixFoundInTree(str, color); - } - - IsaColorCodingDictionaryInstance::IsaColorCodingDictionaryInstance() - { - prefix_tree_.Insert("s_buffer", kIsaColorLightOrange); - prefix_tree_.Insert("s_load", kIsaColorLightOrange); - prefix_tree_.Insert("s_waitcnt", kIsaColorPink); - prefix_tree_.Insert("expcnt", kIsaColorPink); - prefix_tree_.Insert("vmcnt", kIsaColorPink); - prefix_tree_.Insert("lgkmcnt", kIsaColorPink); - prefix_tree_.Insert("s_swap", kIsaColorRed); - prefix_tree_.Insert("s_branch", kIsaColorRed); - prefix_tree_.Insert("s_cbranch", kIsaColorRed); - prefix_tree_.Insert("s_setpc", kIsaColorRed); - prefix_tree_.Insert("ds_", kIsaColorBlue); - prefix_tree_.Insert("buffer_", kIsaColorPurple); - prefix_tree_.Insert("tbuffer_", kIsaColorPurple); - prefix_tree_.Insert("image_", kIsaColorPurple); - prefix_tree_.Insert("global_load", kIsaColorPurple); - prefix_tree_.Insert("idxen", kIsaColorPurple); - prefix_tree_.Insert("s_", kIsaColorBlue); - prefix_tree_.Insert("s[", kIsaColorBlue); // Scalar register. - prefix_tree_.Insert("[s", kIsaColorBlue); // Scalar register range. - prefix_tree_.Insert("|s", kIsaColorBlue); // Scalar register absolute value. - prefix_tree_.Insert("-s", kIsaColorBlue); // Scalar register negative value. - prefix_tree_.Insert("v_", kIsaColorLightGreen); - prefix_tree_.Insert("v[", kIsaColorLightGreen); // Vector register. - prefix_tree_.Insert("[v", kIsaColorLightGreen); // Vector register range. - prefix_tree_.Insert("|v", kIsaColorLightGreen); // Vector register absolute value. - prefix_tree_.Insert("-v", kIsaColorLightGreen); // Vector register negative value. - prefix_tree_.Insert("//", kIsaColorLightBlue); // Comments. - - for (size_t i = 0; i <= 9; ++i) - { - prefix_tree_.Insert("s" + std::to_string(i), kIsaColorBlue); - prefix_tree_.Insert("v" + std::to_string(i), kIsaColorLightGreen); - } - } - } // namespace QtUtils -} // namespace QtCommon