Skip to content

Commit

Permalink
QtCommon v3.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosier committed Aug 30, 2023
1 parent 182e8aa commit 8c7f5d9
Show file tree
Hide file tree
Showing 24 changed files with 3,909 additions and 69 deletions.
12 changes: 12 additions & 0 deletions custom_widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ file (GLOB CPP_INC
"scaled_tab_widget.h"
"scaled_table_view.h"
"scaled_tree_view.h"
"shared_isa_item_delegate.h"
"shared_isa_item_model.h"
"shared_isa_branch_label_navigation_widget.h"
"shared_isa_proxy_model.h"
"shared_isa_tree_view.h"
"shared_isa_widget.h"
"tab_bar.h"
"tree_view.h"
"tab_widget.h"
Expand Down Expand Up @@ -105,6 +111,12 @@ file (GLOB CPP_SRC
"scaled_tab_widget.cpp"
"scaled_table_view.cpp"
"scaled_tree_view.cpp"
"shared_isa_item_delegate.cpp"
"shared_isa_branch_label_navigation_widget.cpp"
"shared_isa_item_model.cpp"
"shared_isa_proxy_model.cpp"
"shared_isa_tree_view.cpp"
"shared_isa_widget.cpp"
"tab_bar.cpp"
"tab_widget.cpp"
"tree_view.cpp"
Expand Down
81 changes: 70 additions & 11 deletions custom_widgets/arrow_icon_combo_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
#include "scaled_check_box.h"
#include "scaled_label.h"

const static int kAllIndex = 0; ///< The index of the "All" checkbox, if used.
static const int kTextOffsetX = 4; ///< The spacing between the arrow and text, and after the text.
static const int kButtonBaseSize = 18; ///< The dimensions of the arrow when viewed at 100% DPI.
static const int kPenWidth = 3; ///< The width of the pen used to draw the arrow.
const static int kAllIndex = 0; ///< The index of the "All" checkbox, if used.
static const int kTextOffsetX = 4; ///< The spacing between the arrow and text, and after the text.
static const int kButtonBaseSize = 18; ///< The dimensions of the arrow when viewed at 100% DPI.
static const int kPenWidth = 3; ///< The width of the pen used to draw the arrow.

ArrowIconComboBox::ArrowIconComboBox(QWidget* parent)
: QPushButton(parent)
Expand Down Expand Up @@ -269,6 +269,18 @@ void ArrowIconComboBox::SetSelectedRow(int index)
}
}

void ArrowIconComboBox::ClearSelectedRow()
{
Q_ASSERT(item_list_ != nullptr);

if (item_list_ == nullptr)
{
return;
}

item_list_->setCurrentItem(nullptr);
}

void ArrowIconComboBox::AllCheckboxClicked(bool checked)
{
QListWidgetItem* current_item = nullptr;
Expand Down Expand Up @@ -543,10 +555,19 @@ void ArrowIconComboBox::RemoveItem(const QString& item_string)
{
Q_ASSERT(item_list_ != nullptr);

if (item_list_ != nullptr)
if (item_list_ == nullptr || item_list_->count() == 0)
{
const QList<QListWidgetItem*> list = item_list_->findItems(item_string, Qt::MatchExactly);
foreach (QListWidgetItem* item, list)
return;
}

for (int i = item_list_->count() - 1; i >= 0; i--)
{
QListWidgetItem* item = item_list_->item(i);

ScaledLabel* label_widget = qobject_cast<ScaledLabel*>(item_list_->itemWidget(item));
ScaledCheckBox* check_box_widget = qobject_cast<ScaledCheckBox*>(item_list_->itemWidget(item));

if ((label_widget != nullptr && label_widget->text() == item_string) || (check_box_widget != nullptr && check_box_widget->text() == item_string))
{
// if removing the "All" item, remove the "All" functionality from the combo box
if (all_choice_added_ == true && item_list_->item(kAllIndex) == item)
Expand All @@ -555,12 +576,33 @@ void ArrowIconComboBox::RemoveItem(const QString& item_string)
all_choice_added_ = false;
all_choice_selected_ = false;
}
item_list_->removeItemWidget(item);

item = item_list_->takeItem(i);
delete item;
}
}
}

void ArrowIconComboBox::RemoveItem(const int item_index)
{
Q_ASSERT(item_list_ != nullptr);

if (item_list_ == nullptr || item_index >= item_list_->count() || item_index < 0)
{
return;
}

if (all_choice_added_ == true && item_index == kAllIndex)
{
DisconnectSignals();
all_choice_added_ = false;
all_choice_selected_ = false;
}

QListWidgetItem* item = item_list_->takeItem(item_index);
delete item;
}

void ArrowIconComboBox::SetAnchor(QPoint point)
{
int height = item_list_->GetListWidgetHeight();
Expand Down Expand Up @@ -723,7 +765,7 @@ void ArrowIconComboBox::ListItemClicked(QListWidgetItem* item)

void ArrowIconComboBox::mousePressEvent(QMouseEvent* event)
{
Q_UNUSED(event);
QPushButton::mousePressEvent(event);

if (item_list_ != nullptr)
{
Expand Down Expand Up @@ -784,8 +826,8 @@ void ArrowIconComboBox::paintEvent(QPaintEvent* event)
Q_UNUSED(event);

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

// Set up the painter
QPainter painter;
Expand Down Expand Up @@ -945,6 +987,23 @@ void ArrowIconComboBox::SetHighLightSubStringData(QVector<StringHighlightData> s
string_highlight_data_ = string_highlight_data;
}

void ArrowIconComboBox::RemoveEventFilter()
{
qApp->removeEventFilter(this);
}

void ArrowIconComboBox::ToggleDirection()
{
if (direction_ == ArrowIconComboBox::Direction::UpArrow)
{
SetDirection(ArrowIconComboBox::Direction::DownArrow);
}
else
{
SetDirection(ArrowIconComboBox::Direction::UpArrow);
}
}

void ArrowIconComboBox::ClearHighLightSubStringData()
{
string_highlight_data_.clear();
Expand Down
15 changes: 14 additions & 1 deletion custom_widgets/arrow_icon_combo_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,14 @@ class ArrowIconComboBox : public QPushButton
/// \param role Data role defaults to Qt::UserRole.
QVariant ItemData(int index, int role = Qt::UserRole) const;

/// Remove a list item.
/// Remove all list items with the given string.
/// \param item_string The string to be removed from the list.
void RemoveItem(const QString& item_string);

/// Remove a single list item at the given index.
/// \param item_index The index to be removed from the list.
void RemoveItem(const int item_index);

/// Is an item in the list checked
/// \param list_index The index of the item in the list to test
/// \return true if checked, false otherwise
Expand Down Expand Up @@ -163,6 +167,9 @@ class ArrowIconComboBox : public QPushButton
/// \param index the list index to select
void SetSelectedRow(int index);

/// @brief Clear any row that is currently shown as selected.
void ClearSelectedRow();

/// Specify a maximum height of the pop-up list.
/// \param height new height
void SetMaximumHeight(int height);
Expand Down Expand Up @@ -239,6 +246,12 @@ class ArrowIconComboBox : public QPushButton
/// \param value The boolean to indicate if the border should be drawn
void SetShowBorder(bool value);

/// @brief Remove the event filter that was installed during initialization.
void RemoveEventFilter();

/// @brief Toggle the direction of the arrow next to the combo box.
void ToggleDirection();

signals:
/// Emitted when the list has been opened.
void Opened();
Expand Down
21 changes: 18 additions & 3 deletions custom_widgets/donut_pie_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ DonutPieWidget::DonutPieWidget(QWidget* parent)
, arc_width_(1.0)
, text_line_one_("")
, text_line_two_("")
, size_(kDefaultWidthAndHeight_)
, value_font_size_(kValuePixelFontSize_)
, text_font_size_(kTextPixelFontSize_)

{
connect(&ScalingManager::Get(), &ScalingManager::ScaleFactorChanged, this, &QWidget::updateGeometry);
}
Expand All @@ -34,7 +38,7 @@ DonutPieWidget::~DonutPieWidget()

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

void DonutPieWidget::paintEvent(QPaintEvent* paint_event)
Expand Down Expand Up @@ -139,7 +143,7 @@ void DonutPieWidget::paintEvent(QPaintEvent* paint_event)
}

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

Expand All @@ -149,7 +153,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(kTextPixelFontSize_));
font.setPixelSize(ScalingManager::Get().Scaled(text_font_size_));
painter.setFont(font);
text_width = QtCommon::QtUtils::GetPainterTextWidth(&painter, text_line_two_);
desc_x_pos = (width - text_width) / 2;
Expand Down Expand Up @@ -205,3 +209,14 @@ void DonutPieWidget::SetTextLineTwo(const QString& text)
{
text_line_two_ = text;
}

void DonutPieWidget::SetFontSizes(int value_font_size, int text_font_size)
{
value_font_size_ = value_font_size;
text_font_size_ = text_font_size;
}

void DonutPieWidget::SetSize(int size)
{
size_ = size;
}
85 changes: 54 additions & 31 deletions custom_widgets/donut_pie_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// \author AMD Developer Tools Team
/// \file
/// \brief Header for a donut pie widget.
///
///
/// This is like a pie chart, but with a hole in the center.
//=============================================================================

Expand All @@ -18,54 +18,74 @@ class DonutPieWidget : public QWidget
Q_OBJECT

public:

/// Explicit constructor
/// \param parent The parent widget
/// Explicit constructor.
///
/// @param [in] parent The parent widget
explicit DonutPieWidget(QWidget* parent);

/// Virtual destructor
/// Virtual destructor.
virtual ~DonutPieWidget();

/// Custom sizeHint implementation that supports DPI scaling.
/// \return A default sizeHint since the size of this widget can grow to fit
/// @brief Custom sizeHint implementation that supports DPI scaling.
///
/// @return A default sizeHint since the size of this widget can grow to fit
/// the space allowed by the layout.
virtual QSize sizeHint() const Q_DECL_OVERRIDE;

/// Set the number of segments for this control. This is the number of
/// @brief Set the number of segments for this control. This is the number of
/// unique data elements to be shown in this control
/// \param numSegments the number of segments needed
///
/// @param [in] numSegments the number of segments needed
void SetNumSegments(unsigned int numSegments);

/// Set the value for the given index for the control.
/// \param index the index whose value is to change
/// \param value the new value to use
/// @brief Set the value for the given index for the control.
///
/// @param [in] index the index whose value is to change
/// @param [in] value the new value to use
void SetIndexValue(unsigned int index, qreal value);

/// Set the fill color for the given index for the control.
/// \param index the index whose color is to change
/// \param fillColor the color to use
/// @brief Set the fill color for the given index for the control.
///
/// @param [in] index the index whose color is to change
/// @param [in] fillColor the color to use
void SetIndexColor(unsigned int index, const QColor& fillColor);

/// Set the text to be displayed in the pie segment.
/// \param index the index whose text is to change
/// \param text the text to be shown
/// @brief Set the text to be displayed in the pie segment.
///
/// @param [in] index the index whose text is to change
/// @param [in] text the text to be shown
void SetIndexText(unsigned int index, const QString& text);

/// Set how wide the donut section should be.
/// \param arcWidth the width of the donut arc
/// @brief Set how wide the donut section should be.
///
/// @param [in] arcWidth the width of the donut arc
void SetArcWidth(qreal arcWidth);

/// Set the first line of text inside the donut
/// \param text Text to set
/// @brief Set the first line of text inside the donut
///
/// @param [in] text Text to set
void SetTextLineOne(const QString& text);

/// Set the second line of text inside the donut
/// \param text Text to set
/// @brief Set the second line of text inside the donut
///
/// @param [in] text Text to set
void SetTextLineTwo(const QString& text);

/// @brief Set the size of the font parameters for the donut.
///
/// @param [in] value_font_size The size of the font used to display the numeric value, in pixels.
/// @param [in] text_font_size The size of the font used to display the donut text, in pixels.
void SetFontSizes(int value_font_size, int text_font_size);

/// @brief Set the width/height size of the donut.
///
/// @param [in] size The width/height of the donut.
void SetSize(int size);

protected:
/// Implementation of Qt's paint for this item.
/// \param paint_event The paint event.
/// @brief Implementation of Qt's paint for this item.
///
/// @param [in] paint_event The paint event.
virtual void paintEvent(QPaintEvent* paint_event) Q_DECL_OVERRIDE;

private:
Expand Down Expand Up @@ -94,15 +114,18 @@ class DonutPieWidget : public QWidget
const int kValuePixelFontSize_ = 36;

/// Default font pixel-size for writing the text.
const int kTextPixelFontSize_ = 14;
const int kTextPixelFontSize_ = 14;

/// Vector of slice data.
QVector<SliceData> slices_;

unsigned int num_segments_; ///< number of segments (values) in the pie control
qreal arc_width_; ///< width of the control arc, in pixels. This is used as the size of the pen used to draw the arc
QString text_line_one_; ///< text in the center of the donut
QString text_line_two_; ///< text in the center of the donut
unsigned int num_segments_; ///< Number of segments (values) in the pie control.
qreal arc_width_; ///< Width of the control arc, in pixels. This is used as the size of the pen used to draw the arc.
QString text_line_one_; ///< Text in the center of the donut.
QString text_line_two_; ///< Text in the center of the donut.
int size_; ///< The width / height of the donut.
int value_font_size_; ///< The font size used to display the donut value, in pixels.
int text_font_size_; ///< The font size used to display the donut text, in pixels.
};

#endif // QTCOMMON_CUSTOM_WIDGETS_DONUT_PIE_WIDGET_H_
Loading

0 comments on commit 8c7f5d9

Please sign in to comment.