Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/calendar-client/src/dialog/myscheduleview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,21 @@ void CMyScheduleView::slotAutoFeed(const QFont &font)
resultStr += str;
}

if (strList.count() * h > 100) {
const int scheduleContentH = strList.count() * h;
const bool needScroll = scheduleContentH > 100;
if (needScroll) {
m_scheduleLabelH = 100;
} else {
int minH = 17;
Comment on lines +98 to 103

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider extracting the hardcoded height values into named constants for maintainability.

Since 100 (scroll threshold) and 17 (minimum label height) are reused and encode layout assumptions, please extract them into clearly named constants (e.g. kScheduleScrollThreshold, kScheduleMinHeight) or class members to document intent and simplify future UI changes.

Suggested implementation:

        resultStr += str;
    }

    static constexpr int kScheduleScrollThreshold = 100;
    static constexpr int kScheduleMinHeight = 17;

    const int scheduleContentH = strList.count() * h;
    const bool needScroll = scheduleContentH > kScheduleScrollThreshold;
    if (needScroll) {
        m_scheduleLabelH = kScheduleScrollThreshold;
    } else {
        int minH = kScheduleMinHeight;
        m_scheduleLabelH = scheduleContentH;
        m_scheduleLabelH = m_scheduleLabelH >= minH ? m_scheduleLabelH : minH;
    }
    //更新控件高度
    area->setFixedHeight(m_scheduleLabelH);
    area->setVerticalScrollBarPolicy(needScroll ? Qt::ScrollBarAsNeeded : Qt::ScrollBarAlwaysOff);
    area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    m_scheduleLabel->setText(resultStr);
    m_scheduleLabel->setFixedHeight(needScroll ? scheduleContentH : m_scheduleLabelH);

    m_timeLabelH = 26;

If these layout constants are used elsewhere in MyScheduleView or other files, consider moving kScheduleScrollThreshold and kScheduleMinHeight to class scope (e.g. as static constexpr members in the corresponding header) or to an anonymous namespace at the top of this .cpp file, and then use those shared definitions instead of function-local ones.

m_scheduleLabelH = strList.count() * h;
m_scheduleLabelH = scheduleContentH;
m_scheduleLabelH = m_scheduleLabelH >= minH ? m_scheduleLabelH : minH;
}
//更新控件高度
area->setFixedHeight(m_scheduleLabelH);
area->setVerticalScrollBarPolicy(needScroll ? Qt::ScrollBarAsNeeded : Qt::ScrollBarAlwaysOff);
area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_scheduleLabel->setText(resultStr);
m_scheduleLabel->setFixedHeight(needScroll ? scheduleContentH : m_scheduleLabelH);

m_timeLabelH = 26;
if (m_scheduleInfo->lunnar()) {
Expand Down Expand Up @@ -185,6 +190,11 @@ void CMyScheduleView::setLabelTextColor(const int type)
setPaletteTextColor(m_timeLabel, timeColor);
}

void CMyScheduleView::updateDialogIcon()
{
setIcon(QIcon::fromTheme("dde-calendar"));
}

/**
* @brief setPaletteTextColor 设置调色板颜色
* @param widget 需要设置的widget
Expand Down Expand Up @@ -301,8 +311,7 @@ void CMyScheduleView::initUI()
m_Title->setAlignment(Qt::AlignCenter);
DFontSizeManager::instance()->bind(m_Title, DFontSizeManager::T5, QFont::DemiBold);
//设置日期图标
QIcon t_icon(CDynamicIcon::getInstance()->getPixmap());
setIcon(t_icon);
updateDialogIcon();
m_Title->setText(tr("My Event"));
m_Title->move(90, 0); // center x: (400-220)/2

Expand All @@ -315,6 +324,8 @@ void CMyScheduleView::initUI()
area->setFocusPolicy(Qt::FocusPolicy::NoFocus);
area->setFrameShape(QFrame::NoFrame);
area->setFixedWidth(363);
area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
area->setBackgroundRole(QPalette::Window);
area->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
area->setWidgetResizable(true);
Expand Down Expand Up @@ -379,6 +390,9 @@ void CMyScheduleView::initConnection()
QObject::connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged,
this,
&CMyScheduleView::setLabelTextColor);
QObject::connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged,
this,
&CMyScheduleView::updateDialogIcon);
//如果为节假日日程
if (CScheduleOperation::isFestival(m_scheduleInfo)) {
qCDebug(ClientLogger) << "Adding close button for festival schedule";
Expand Down
1 change: 1 addition & 0 deletions src/calendar-client/src/dialog/myscheduleview.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public slots:
//界面初始化
void initUI();
void initConnection();
void updateDialogIcon();
//设置label文字颜色
void setLabelTextColor(const int type);
//设置调色板颜色
Expand Down
Loading