Skip to content

Commit

Permalink
QtCommon v4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosier committed Jun 25, 2024
1 parent 78a9a00 commit 6377814
Show file tree
Hide file tree
Showing 43 changed files with 385 additions and 548 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.24)
project(QtCommon)

# Define version information
set(QTCOMMON_MAJOR_VERSION 3)
set(QTCOMMON_MINOR_VERSION 14)
set(QTCOMMON_MAJOR_VERSION 4)
set(QTCOMMON_MINOR_VERSION 0)
if (NOT QTCOMMON_PATCH_NUMBER)
set(QTCOMMON_PATCH_NUMBER 0)
endif ()
Expand Down
31 changes: 20 additions & 11 deletions cmake/devtools_qt_helper.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#######################################################################################################################
### Copyright (c) 2019-2021 Advanced Micro Devices, Inc. All rights reserved.
### Copyright (c) 2019-2024 Advanced Micro Devices, Inc. All rights reserved.
### @author AMD Developer Tools Team
#######################################################################################################################

Expand Down Expand Up @@ -31,8 +31,6 @@ if (NOT Qt6_DIR)
endif ()
endif ()



if (Qt5_DIR OR Qt6_DIR)
#######################################################################################################################
# Setup the INSTALL target to include Qt DLLs
Expand All @@ -57,7 +55,7 @@ if (Qt5_DIR OR Qt6_DIR)
if (WIN32)
if (Qt6_DIR)
set(DEPLOYQT_POST_BUILD_COMMAND
${DEPLOYQT_EXECUTABLE} $<TARGET_FILE:${target}> -verbose 0 --release --no-compiler-runtime --no-translations
${DEPLOYQT_EXECUTABLE} $<TARGET_FILE:${target}> -verbose 0 --no-compiler-runtime --no-translations --no-system-d3d-compiler --no-system-dxc-compiler --no-opengl-sw --no-network
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
else ()
set(DEPLOYQT_POST_BUILD_COMMAND
Expand All @@ -67,7 +65,7 @@ if (Qt5_DIR OR Qt6_DIR)
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} $<TARGET_FILE:${target}> -qmake=${QT_QMAKE_EXECUTABLE} -verbose=0 -unsupported-allow-new-glibc
${DEPLOYQT_EXECUTABLE} $<TARGET_FILE:${target}> -qmake=${QT_QMAKE_EXECUTABLE} -verbose=0 -unsupported-allow-new-glibc -no-translations
WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
elseif (include_mac)
set(DEPLOYQT_POST_BUILD_COMMAND
Expand Down Expand Up @@ -96,14 +94,25 @@ if (Qt5_DIR OR Qt6_DIR)

# 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}
if (Qt5_DIR)
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)
else ()
install(FILES
${target_file_dir}/Qt6Core${qt_suffix}
${target_file_dir}/Qt6Gui${qt_suffix}
${target_file_dir}/Qt6Svg${qt_suffix}
${target_file_dir}/Qt6Widgets${qt_suffix}
DESTINATION . COMPONENT ${component})

install(FILES ${target_file_dir}/Qt5Network${qt_suffix} DESTINATION . COMPONENT ${component} OPTIONAL)
install(FILES ${target_file_dir}/Qt6Network${qt_suffix} DESTINATION . COMPONENT ${component} OPTIONAL)
endif ()

install(DIRECTORY ${target_file_dir}/iconengines DESTINATION . COMPONENT ${component})
install(DIRECTORY ${target_file_dir}/imageformats DESTINATION . COMPONENT ${component})
Expand Down
46 changes: 28 additions & 18 deletions source/qt_common/custom_widgets/arrow_icon_combo_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <QPainter>

#include "common_definitions.h"
#include "scaling_manager.h"
#include "qt_util.h"
#include "scaling_manager.h"

#include "scaled_check_box.h"
#include "scaled_label.h"
Expand All @@ -30,6 +30,7 @@ ArrowIconComboBox::ArrowIconComboBox(QWidget* parent)
, retain_default_text_(false)
, all_choice_added_(false)
, all_choice_selected_(false)
, first_show_(true)
, size_(kButtonBaseSize)
, show_border_(false)
, direction_(Direction::DownArrow)
Expand Down Expand Up @@ -68,7 +69,7 @@ void ArrowIconComboBox::OnScaleFactorChanged()

// Setting a new scaled size will cause the vertices to get recalculated
// and update the geometry of the widget.
SetSize(ScalingManager::Get().Scaled(kButtonBaseSize));
SetSize(kButtonBaseSize);

updateGeometry();
update();
Expand Down Expand Up @@ -385,17 +386,17 @@ int ArrowIconComboBox::LastCheckedIndex()
QListWidgetItem* current_item = nullptr;
for (int i = 0; i < item_list_->count(); i++)
{
current_item = item_list_->item(i);
current_item = item_list_->item(i);
QCheckBox* item_checkbox = qobject_cast<QCheckBox*>(item_list_->itemWidget(current_item));

// If there is a disabled item (that is checked), return it's index to be re enabled.
// If there are other reasons why a checked item may be disabled besides it being the
// If there are other reasons why a checked item may be disabled besides it being the
// last checked item, this will have unintended results.
if (!item_checkbox->isEnabled() && IsChecked(i))
{
return i;
}

// Count the number of checked items.
if (IsChecked(i))
{
Expand Down Expand Up @@ -525,7 +526,6 @@ 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)
{
Expand Down Expand Up @@ -773,10 +773,8 @@ QSize ArrowIconComboBox::sizeHint() const
{
ensurePolished();

ScalingManager& sm = ScalingManager::Get();

// There are two offsets - one between the arrow and the text, and another after the text.
const int total_scaled_text_offsets = 2.0 * sm.Scaled(kTextOffsetX);
const int total_scaled_text_offsets = 2.0 * kTextOffsetX;

QSize size_hint;

Expand Down Expand Up @@ -900,19 +898,14 @@ void ArrowIconComboBox::paintEvent(QPaintEvent* event)
{
Q_UNUSED(event);

// Get the ScalingManager
ScalingManager& sm = ScalingManager::Get();
const int scaled_text_offset_x = sm.Scaled(kTextOffsetX);
const int scaled_text_offset_x = kTextOffsetX;

// Set up the painter
QPainter painter;
painter.begin(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.save();

// Paint background
painter.fillRect(rect(), palette().window());

// Set properties for the lines
QPen pen;

Expand All @@ -925,7 +918,7 @@ void ArrowIconComboBox::paintEvent(QPaintEvent* event)
pen.setColor(Qt::lightGray);
}

pen.setWidth(sm.Scaled(pen_width_));
pen.setWidth(pen_width_);
painter.setPen(pen);

const int half_height = height() / 2;
Expand Down Expand Up @@ -1009,7 +1002,7 @@ void ArrowIconComboBox::paintEvent(QPaintEvent* event)
{
pen.setColor(QtCommon::QtUtils::ColorTheme::Get().GetCurrentThemeColors().arrow_icon_border_color);
}
pen.setWidth(sm.Scaled(1.0));
pen.setWidth(1.0);
painter.setPen(pen);
painter.drawRect(this->rect());
}
Expand Down Expand Up @@ -1137,3 +1130,20 @@ void ArrowIconComboBox::focusOutEvent(QFocusEvent* event)
// Pass the event onto the base class.
QPushButton::focusOutEvent(event);
}

void ArrowIconComboBox::showEvent(QShowEvent* show_event)
{
QPushButton::showEvent(show_event);

if (first_show_ == true)
{
QtCommon::QtUtils::InvalidateFontMetrics(this);

SetSize(kButtonBaseSize);

updateGeometry();
update();

first_show_ = false;
}
}
10 changes: 8 additions & 2 deletions source/qt_common/custom_widgets/arrow_icon_combo_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define QTCOMMON_CUSTOM_WIDGETS_ARROW_ICON_COMBO_BOX_H_

#include <memory>

#include <QCheckBox>
#include <QLabel>
#include <QListWidgetItem>
Expand Down Expand Up @@ -139,14 +140,14 @@ class ArrowIconComboBox : public QPushButton
void SetRowHidden(int list_index, bool hidden);

/// @Brief Disables/enables the item at the given index. If the index is invalid, does nothing.
///
///
/// @param list_index The index of the item to be disabled/enabled.
/// @param disabled Whether the item should be disabled (true) or enabled (false).
void SetDisabled(int list_index, bool disabled);

/// @Brief Gets the index of the last checked item if there is one.
/// Helper function to aid in disabling the last checked item.
///
///
/// @Return Returns -1 if there are multiple checked items and none are disabled.
/// If there is only 1 item checked, it returns the index of that item. If there
/// are multiple items checked, but 1 is disabled, it returns the index of that
Expand Down Expand Up @@ -337,6 +338,10 @@ class ArrowIconComboBox : public QPushButton
/// \param event A QFocusEvent to inform why focus was lost.
void focusOutEvent(QFocusEvent* event) Q_DECL_OVERRIDE;

/// Override the show event to invalidate the font metrics when first shown.
/// \param show_event The QShowEvent.
void showEvent(QShowEvent* show_event) Q_DECL_OVERRIDE;

private slots:
/// Handle what happens when a list item is clicked
/// \param item The clicked item
Expand Down Expand Up @@ -401,6 +406,7 @@ private slots:
bool retain_default_text_; ///< Flag to retain default text when selection changes.
bool all_choice_added_; ///< Indicates that an "All" checkbox has already been added to a multi-select combobox.
bool all_choice_selected_; ///< Does this combo box have the "All" option selected.
bool first_show_; ///< Boolean to track the first time this widget is shown to invalidate the font metrics.

int size_; ///< The size of the encompassing rect.
QColor color_; ///< The color of the arrow's lines.
Expand Down
2 changes: 1 addition & 1 deletion source/qt_common/custom_widgets/colored_legend_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void ColoredLegendScene::Update()
text_legends_[i]->setFont(text_font);
const int text_width = font_metrics.boundingRect(text_legends_[i]->toPlainText()).width();

x_pos += text_width + ScalingManager::Get().Scaled(kHorizontalSpacingAfterText);
x_pos += text_width + kHorizontalSpacingAfterText;
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/qt_common/custom_widgets/completion_bar_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void CompletionBarWidget::SetFillPercentage(qreal percentage)

QSize CompletionBarWidget::sizeHint() const
{
return ScalingManager::Get().Scaled(QSize(kDefaultWidth_, kDefaultHeight_));
return QSize(kDefaultWidth_, kDefaultHeight_);
}

void CompletionBarWidget::paintEvent(QPaintEvent* paint_event)
Expand Down
13 changes: 7 additions & 6 deletions source/qt_common/custom_widgets/donut_pie_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "donut_pie_widget.h"

#include <math.h>

#include <QFontMetrics>
#include <QPainter>
#include <QQueue>

Expand Down Expand Up @@ -39,7 +41,7 @@ DonutPieWidget::~DonutPieWidget()

QSize DonutPieWidget::sizeHint() const
{
return ScalingManager::Get().Scaled(QSize(size_, size_));
return QSize(size_, size_);
}

void DonutPieWidget::paintEvent(QPaintEvent* paint_event)
Expand All @@ -49,16 +51,15 @@ void DonutPieWidget::paintEvent(QPaintEvent* paint_event)
QPainter painter(this);

painter.setRenderHint(QPainter::Antialiasing);
painter.fillRect(rect(), palette().window());

const int width = rect().width();
const int height = rect().height();

const qreal scaled_arc_width = ScalingManager::Get().Scaled(arc_width_);
const qreal scaled_arc_width = arc_width_;

// Determine widest label.
int max_width = 0;
const QFontMetrics& font_metrics = ScalingManager::Get().ScaledFontMetrics(font());
const QFontMetrics& font_metrics = QFontMetrics(font());
for (unsigned int index = 0; index < num_segments_; ++index)
{
const int text_width = font_metrics.boundingRect(slices_[index].slice_text_).width();
Expand Down Expand Up @@ -147,7 +148,7 @@ void DonutPieWidget::paintEvent(QPaintEvent* paint_event)
}

// Draw the description text
font.setPixelSize(ScalingManager::Get().Scaled(value_font_size_));
font.setPixelSize(value_font_size_);
painter.setFont(font);

int text_width = QtCommon::QtUtils::GetPainterTextWidth(&painter, text_line_one_);
Expand All @@ -156,7 +157,7 @@ void DonutPieWidget::paintEvent(QPaintEvent* paint_event)
int desc_y_pos = (height * 52) / 100;
painter.drawText(desc_x_pos, desc_y_pos, text_line_one_);

font.setPixelSize(ScalingManager::Get().Scaled(text_font_size_));
font.setPixelSize(text_font_size_);
painter.setFont(font);
text_width = QtCommon::QtUtils::GetPainterTextWidth(&painter, text_line_two_);
desc_x_pos = (width - text_width) / 2;
Expand Down
Loading

0 comments on commit 6377814

Please sign in to comment.