Skip to content

Commit

Permalink
fix: adapt compact mode
Browse files Browse the repository at this point in the history
  adapt compact mode

Log: adpat compact mode
Bug: https://pms.uniontech.com/bug-view-279779.html
  • Loading branch information
starhcq committed Nov 7, 2024
1 parent 03dbe6d commit e4f573f
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 2 deletions.
41 changes: 41 additions & 0 deletions application/filtercontent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#define BUTTON_WIDTH_MIN 68
#define BUTTON_HEIGHT_MIN 36
#define BUTTON_HEIGHT_MIN_COMPACT 24
#define BUTTON_EXPORT_WIDTH_MIN 142
#define FONT_20_MIN_WIDTH 821
#define FONT_18_MIN_WIDTH 100
Expand Down Expand Up @@ -250,6 +251,11 @@ void FilterContent::initConnections()
connect(typeCbx, SIGNAL(currentIndexChanged(int)), this,
SLOT(slot_cbxLogTypeChanged(int))); // add by Airy
connect(auditTypeCbx, SIGNAL(currentIndexChanged(int)), this, SLOT(slot_cbxAuditTypeChanged(int)));
#ifdef DTKWIDGET_CLASS_DSizeMode
// 紧凑模式信号处理
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, &FilterContent::updateSizeMode);
updateSizeMode();
#endif
}

/**
Expand Down Expand Up @@ -956,3 +962,38 @@ void FilterContent::setChangedcomboxstate(bool value)
{
m_bIsCombox = value;
}

void FilterContent::updateSizeMode()
{
int nBtnHeight = BUTTON_HEIGHT_MIN;
#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::isCompactMode())
nBtnHeight = BUTTON_HEIGHT_MIN_COMPACT;
else
nBtnHeight = BUTTON_HEIGHT_MIN;
#else
nBtnHeight = BUTTON_HEIGHT_MIN;
#endif

if (cbx_lv) {
cbx_lv->setMinimumSize(QSize(LEVEL_COMBO_WIDTH, nBtnHeight));
}
if (cbx_dnf_lv) {
cbx_dnf_lv->setMinimumSize(QSize(LEVEL_COMBO_WIDTH, nBtnHeight));
}
if (cbx_app) {
cbx_app->setMinimumSize(QSize(LEVEL_COMBO_WIDTH, nBtnHeight));
}
if (cbx_submodule) {
cbx_submodule->setMinimumSize(QSize(LEVEL_COMBO_WIDTH, nBtnHeight));
}
if (cbx_status) {
cbx_status->setMinimumSize(QSize(LEVEL_COMBO_WIDTH, nBtnHeight));
}
if (typeCbx) {
typeCbx->setMinimumSize(QSize(LEVEL_COMBO_WIDTH, nBtnHeight));
}
if (auditTypeCbx) {
auditTypeCbx->setMinimumSize(QSize(LEVEL_COMBO_WIDTH, nBtnHeight));
}
}
6 changes: 6 additions & 0 deletions application/filtercontent.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class FilterContent : public Dtk::Widget::DFrame
* @param value
*/
void setChangedcomboxstate(bool value);

private slots:
/**
* @brief 根据布局模式(紧凑)变更更新界面布局
*/
void updateSizeMode();
protected:
// void resizeEvent(QResizeEvent *event) override;
void paintEvent(QPaintEvent *event) override;
Expand Down
29 changes: 29 additions & 0 deletions application/logcollectormain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#define LEFT_LIST_WIDTH 200
DWIDGET_USE_NAMESPACE

const int BUTTON_SIZE = 36;
const int BUTTON_SIZE_COMPACT = 24;

//刷新间隔
static const QString refreshIntervalKey = "base.RefreshInterval";
/**
Expand Down Expand Up @@ -429,6 +432,12 @@ void LogCollectorMain::initConnection()
connect(m_topRightWgt, &FilterContent::sigStatusChanged, this, &LogCollectorMain::slotClearInfoandFocus);
//开关机日志下拉框选项切换清空搜索栏
connect(m_topRightWgt, &FilterContent::sigLogtypeChanged, this, &LogCollectorMain::slotClearInfoandFocus);

#ifdef DTKWIDGET_CLASS_DSizeMode
// 紧凑模式信号处理
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, &LogCollectorMain::updateSizeMode);
updateSizeMode();
#endif
}

void LogCollectorMain::slotClearInfoandFocus()
Expand All @@ -441,6 +450,26 @@ void LogCollectorMain::slotClearInfoandFocus()
}
}

void LogCollectorMain::updateSizeMode()
{
int nBtnSize = BUTTON_SIZE;
#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::isCompactMode())
nBtnSize = BUTTON_SIZE_COMPACT;
else
nBtnSize = BUTTON_SIZE;
#else
nBtnSize = BUTTON_SIZE;
#endif

if (m_exportAllBtn) {
m_exportAllBtn->setFixedSize(QSize(nBtnSize, nBtnSize));
}
if (m_refreshBtn) {
m_refreshBtn->setFixedSize(QSize(nBtnSize, nBtnSize));
}
}

/**
* @brief LogCollectorMain::initShortCut 初始化快捷键
*/
Expand Down
5 changes: 5 additions & 0 deletions application/logcollectormain.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public slots:
*/
void slotClearInfoandFocus();

private slots:
/**
* @brief 根据布局模式(紧凑)变更更新界面布局
*/
void updateSizeMode();
protected:
void closeEvent(QCloseEvent *event);

Expand Down
28 changes: 28 additions & 0 deletions application/loglistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <QShortcut>
#include <QAbstractButton>
#define ITEM_HEIGHT 40
#define ITEM_HEIGHT_COMPACT 24
#define ITEM_WIDTH 108
#define ICON_SIZE 16

Expand Down Expand Up @@ -136,6 +137,12 @@ LogListView::LogListView(QWidget *parent)
});

connect(LogApplicationHelper::instance(), &LogApplicationHelper::sigValueChanged, this, &LogListView::slot_valueChanged_dConfig_or_gSetting);

#ifdef DTKWIDGET_CLASS_DSizeMode
// 紧凑模式信号处理
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, &LogListView::updateSizeMode);
updateSizeMode();
#endif
}

/**
Expand Down Expand Up @@ -592,3 +599,24 @@ void LogListView::slot_valueChanged_dConfig_or_gSetting(const QString &key)
}
}
}

void LogListView::updateSizeMode()
{
int nItemHeight = ITEM_HEIGHT;
#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::isCompactMode())
nItemHeight = ITEM_HEIGHT_COMPACT;
else
nItemHeight = ITEM_HEIGHT;
#else
nItemHeight = ITEM_HEIGHT;
#endif

if (m_pModel) {
int nCount = m_pModel->rowCount();
for (int i = 0; i < nCount; i++) {
QStandardItem* item = m_pModel->item(i);
item->setSizeHint(QSize(ITEM_WIDTH, nItemHeight));
}
}
}
5 changes: 5 additions & 0 deletions application/loglistview.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public slots:
void requestshowRightMenu(const QPoint &pos);
void slot_valueChanged_dConfig_or_gSetting(const QString &key);

private slots:
/**
* @brief 根据布局模式(紧凑)变更更新界面布局
*/
void updateSizeMode();
protected:
void paintEvent(QPaintEvent *event) override;
void currentChanged(const QModelIndex &current, const QModelIndex &previous) override;
Expand Down
33 changes: 32 additions & 1 deletion application/logviewheaderview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <DStyle>

static const int kSpacingMargin = 4;
#define ROW_HEIGHT 36
#define ROW_HEIGHT_COMPACT 24

LogViewHeaderView::LogViewHeaderView(Qt::Orientation orientation, QWidget *parent)
: DHeaderView(orientation, parent)
Expand All @@ -27,6 +29,12 @@ LogViewHeaderView::LogViewHeaderView(Qt::Orientation orientation, QWidget *paren
setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
setFixedHeight(37);
setFocusPolicy(Qt::NoFocus);

#ifdef DTKWIDGET_CLASS_DSizeMode
// 紧凑模式信号处理
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, &LogViewHeaderView::updateSizeMode);
updateSizeMode();
#endif
}

LogViewHeaderView::~LogViewHeaderView()
Expand Down Expand Up @@ -191,7 +199,16 @@ void LogViewHeaderView::paintEvent(QPaintEvent *event)

QSize LogViewHeaderView::sizeHint() const
{
return QSize(width(), 36 + m_spacing);
int nRowHeight = ROW_HEIGHT;
#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::isCompactMode())
nRowHeight = ROW_HEIGHT_COMPACT;
else
nRowHeight = ROW_HEIGHT;
#else
nRowHeight = ROW_HEIGHT;
#endif
return QSize(width(), nRowHeight + m_spacing);
}
/**
* @brief LogViewHeaderView::sectionSizeHint 根据是否有排序箭头返回逻辑字段合适的尺寸
Expand All @@ -216,3 +233,17 @@ int LogViewHeaderView::sectionSizeHint(int logicalIndex) const
return fm.width(buf) + margin * 2;
}
}

void LogViewHeaderView::updateSizeMode()
{
int nRowHeight = ROW_HEIGHT;
#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::isCompactMode())
nRowHeight = ROW_HEIGHT_COMPACT;
else
nRowHeight = ROW_HEIGHT;
#else
nRowHeight = ROW_HEIGHT;
#endif
setFixedHeight(nRowHeight);
}
5 changes: 5 additions & 0 deletions application/logviewheaderview.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class LogViewHeaderView : public DHeaderView
inline int getSpacing() const { return m_spacing; }
inline void setSpacing(int spacing) { m_spacing = spacing; }

private slots:
/**
* @brief 根据布局模式(紧凑)变更更新界面布局
*/
void updateSizeMode();
protected:
void paintEvent(QPaintEvent *e) override;
virtual void paintSection(QPainter *painter, const QRect &rect,
Expand Down
14 changes: 13 additions & 1 deletion application/logviewitemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ DWIDGET_USE_NAMESPACE
#define ICON_WIDTH 24
#define ICON_HEIGHT 24

#define ROW_HEIGHT 36
#define ROW_HEIGHT_COMPACT 24

LogViewItemDelegate::LogViewItemDelegate(QObject *parent)
: QStyledItemDelegate(parent)
{
Expand Down Expand Up @@ -121,7 +124,16 @@ QSize LogViewItemDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QSize size = QStyledItemDelegate::sizeHint(option, index);
size.setHeight(36);
int nRowHeight = ROW_HEIGHT;
#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::isCompactMode())
nRowHeight = ROW_HEIGHT_COMPACT;
else
nRowHeight = ROW_HEIGHT;
#else
nRowHeight = ROW_HEIGHT;
#endif
size.setHeight(nRowHeight);
return size;
}
/**
Expand Down

0 comments on commit e4f573f

Please sign in to comment.