mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-07-12 14:21:01 -04:00
refactor: Improve UX
This commit is contained in:
@@ -5,8 +5,9 @@
|
||||
#include "AgentListItem.hpp"
|
||||
|
||||
#include "SettingsTheme.hpp"
|
||||
#include "TagChip.hpp"
|
||||
#include "SettingsUiBuilders.hpp"
|
||||
|
||||
#include <utils/elidinglabel.h>
|
||||
#include <utils/theme/theme.h>
|
||||
|
||||
#include <QEvent>
|
||||
@@ -16,73 +17,52 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QPalette>
|
||||
#include <QScopedValueRollback>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace QodeAssist::Settings {
|
||||
|
||||
AgentListItem::AgentListItem(const AgentConfig &cfg, QWidget *parent)
|
||||
: QFrame(parent)
|
||||
, m_name(cfg.name)
|
||||
, m_model(cfg.model)
|
||||
{
|
||||
setObjectName(QStringLiteral("AgentListItem"));
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
setAutoFillBackground(true);
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
|
||||
auto *dot = new QLabel(QStringLiteral("●"), this);
|
||||
QFont df = dot->font();
|
||||
df.setPixelSize(10);
|
||||
dot->setFont(df);
|
||||
QPalette dp = dot->palette();
|
||||
dp.setColor(QPalette::WindowText, Utils::creatorColor(Utils::Theme::PanelTextColorMid));
|
||||
dot->setPalette(dp);
|
||||
|
||||
auto *nameLbl = new QLabel(cfg.name, this);
|
||||
QFont nf = nameLbl->font();
|
||||
m_nameLabel = new QLabel(this);
|
||||
QFont nf = m_nameLabel->font();
|
||||
nf.setBold(true);
|
||||
nf.setPixelSize(12);
|
||||
nameLbl->setFont(nf);
|
||||
m_nameLabel->setFont(nf);
|
||||
m_nameLabel->setTextFormat(Qt::RichText);
|
||||
|
||||
auto *headerRow = new QHBoxLayout;
|
||||
headerRow->setContentsMargins(0, 0, 0, 0);
|
||||
headerRow->setSpacing(6);
|
||||
headerRow->addWidget(dot, 0, Qt::AlignVCenter);
|
||||
headerRow->addWidget(nameLbl, 1);
|
||||
|
||||
auto *col = new QVBoxLayout;
|
||||
col->setContentsMargins(0, 0, 0, 0);
|
||||
col->setSpacing(2);
|
||||
col->addLayout(headerRow);
|
||||
|
||||
m_modelLabel = new QLabel(cfg.model, this);
|
||||
m_modelLabel = new Utils::ElidingLabel(this);
|
||||
m_modelLabel->setElideMode(Qt::ElideMiddle);
|
||||
m_modelLabel->setFont(monospaceFont(11));
|
||||
m_modelLabel->setContentsMargins(16, 0, 0, 0);
|
||||
m_modelLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||
QPalette mp = m_modelLabel->palette();
|
||||
mp.setColor(QPalette::WindowText, Utils::creatorColor(Utils::Theme::PanelTextColorMid));
|
||||
m_modelLabel->setPalette(mp);
|
||||
m_modelLabel->setText(cfg.model);
|
||||
m_modelLabel->setVisible(!cfg.model.isEmpty());
|
||||
col->addWidget(m_modelLabel);
|
||||
|
||||
if (!cfg.tags.isEmpty()) {
|
||||
auto *tagsHolder = new QWidget(this);
|
||||
auto *tagsLay = new QHBoxLayout(tagsHolder);
|
||||
tagsLay->setContentsMargins(16, 2, 0, 0);
|
||||
tagsLay->setSpacing(3);
|
||||
for (const QString &t : cfg.tags) {
|
||||
auto *chip = new TagChip(t, -1, tagsHolder);
|
||||
connect(chip, &TagChip::clicked, this, &AgentListItem::tagClicked);
|
||||
m_chips.append(chip);
|
||||
tagsLay->addWidget(chip);
|
||||
}
|
||||
tagsLay->addStretch(1);
|
||||
col->addWidget(tagsHolder);
|
||||
}
|
||||
auto *row = new QHBoxLayout(this);
|
||||
row->setContentsMargins(8, 4, 8, 4);
|
||||
row->setSpacing(8);
|
||||
row->addWidget(m_nameLabel, 0);
|
||||
row->addWidget(m_modelLabel, 1);
|
||||
|
||||
auto *outer = new QVBoxLayout(this);
|
||||
outer->setContentsMargins(5, 6, 8, 6);
|
||||
outer->setSpacing(0);
|
||||
outer->addLayout(col);
|
||||
QStringList tipLines;
|
||||
if (!cfg.description.isEmpty())
|
||||
tipLines << cfg.description;
|
||||
if (!cfg.model.isEmpty())
|
||||
tipLines << tr("Model: %1").arg(cfg.model);
|
||||
if (!cfg.tags.isEmpty())
|
||||
tipLines << tr("Tags: %1").arg(cfg.tags.join(QStringLiteral(", ")));
|
||||
setToolTip(tipLines.join(QStringLiteral("\n")));
|
||||
|
||||
updateNameText();
|
||||
applyTheme();
|
||||
}
|
||||
|
||||
@@ -94,20 +74,26 @@ void AgentListItem::setSelected(bool selected)
|
||||
applyTheme();
|
||||
}
|
||||
|
||||
void AgentListItem::setActiveTags(const QSet<QString> &active)
|
||||
{
|
||||
for (auto *chip : m_chips)
|
||||
chip->setActive(active.contains(chip->tag()));
|
||||
}
|
||||
|
||||
void AgentListItem::setModel(const QString &model)
|
||||
{
|
||||
if (!m_modelLabel)
|
||||
return;
|
||||
m_model = model;
|
||||
m_modelLabel->setText(model);
|
||||
m_modelLabel->setVisible(!model.isEmpty());
|
||||
}
|
||||
|
||||
void AgentListItem::setFilterHighlight(const QString &lowerFilter)
|
||||
{
|
||||
if (m_filter == lowerFilter)
|
||||
return;
|
||||
m_filter = lowerFilter;
|
||||
updateNameText();
|
||||
}
|
||||
|
||||
void AgentListItem::updateNameText()
|
||||
{
|
||||
m_nameLabel->setText(filterHighlightedHtml(m_name, m_filter));
|
||||
}
|
||||
|
||||
void AgentListItem::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton)
|
||||
@@ -133,6 +119,7 @@ void AgentListItem::applyTheme()
|
||||
"#AgentListItem { background:transparent;"
|
||||
" border-top:1px solid %1; border-left:3px solid %2; }")
|
||||
.arg(cssColor(Utils::creatorColor(Utils::Theme::SplitterColor)), accent));
|
||||
updateNameText();
|
||||
}
|
||||
|
||||
} // namespace QodeAssist::Settings
|
||||
|
||||
Reference in New Issue
Block a user