diff --git a/src/common/utils.h b/src/common/utils.h index f488e158d..75a1153d6 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -48,10 +48,21 @@ extern __attribute__((visibility("default"))) int __maxFontSize; #define SPACEWIDTH 10 // 控件通用高度 #define COMMONHEIGHT 36 +#define COMMONHEIGHT_COMPACT 24 // 图标大小 #define ICONSIZE_50 50 #define ICONSIZE_36 36 #define ICONSIZE_20 20 +#define ICONSIZE_40_COMPACT 40 +#define ICON_CTX_SIZE_32 32 +#define ICON_CTX_SIZE_24 24 +// 竖向分割线高度 +#define VERTICAL_HEIGHT 28 +#define VERTICAL_WIDTH 3 +#define VERTICAL_HEIGHT_COMPACT 17 +#define VERTICAL_WIDTH_COMPACT 1 +// 设置框统一宽度 +#define SETTING_DIALOG_WIDTH 459 // limit font size #define DEFAULT_MIN_FONT_SZIE 5 @@ -71,6 +82,7 @@ extern __attribute__((visibility("default"))) int __maxFontSize; #define WINDOW_DEFAULT_SIZE QSize(WINDOW_DEFAULT_WIDTH, WINDOW_DEFAULT_HEIGHT) //终端窗口默认尺寸 #define ICON_EXIT_FULL_SIZE QSize(ICONSIZE_36, ICONSIZE_36) //退出全屏按钮尺寸 #define WIN_TITLE_BAR_HEIGHT 50 //标题栏高度 +#define WIN_TITLE_BAR_HEIGHT_COMPACT 40 //标题栏高度(紧凑模式) #define WINDOW_MIN_WIDTH 610 //终端窗口最小宽度 @@ -79,6 +91,7 @@ extern __attribute__((visibility("default"))) int __maxFontSize; //Encode Plugin #define ENCODE_ITEM_WIDTH 220 #define ENCODE_ITEM_HEIGHT 60 +#define ENCODE_ITEM_HEIGHT_COMPACT 50 //字体信息 struct FontData{ diff --git a/src/customcommand/customcommandoptdlg.cpp b/src/customcommand/customcommandoptdlg.cpp index 478fec8fd..cbaa8fb4a 100644 --- a/src/customcommand/customcommandoptdlg.cpp +++ b/src/customcommand/customcommandoptdlg.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -135,17 +134,19 @@ void CustomCommandOptDlg::initUI() addContent(contentFrame); //判断是添加操作窗口还是修改操作窗口 if (CCT_ADD == m_type) { - setFixedSize(m_iFixedWidth, m_iFixedHeightAddSize); setTitle(tr("Add Command")); initCommandFromClipBoardText(); +#ifdef DTKWIDGET_CLASS_DSizeMode + getMainLayout()->addSpacing(m_iSpaceSizeSeven); +#else getMainLayout()->addSpacing(m_iSpaceSizeEighteen); +#endif } else { - setFixedSize(m_iFixedWidth, m_iFixedHeightEditSize); setTitle(tr("Edit Command")); - QWidget *deleteCmdWidget = new QWidget(this); - deleteCmdWidget->setFixedHeight(m_iFixedHeight); + m_deleteCmdWidget = new QWidget(this); + m_deleteCmdWidget->setFixedHeight(m_iFixedHeight); QHBoxLayout *deleteCmdLayout = new QHBoxLayout(); deleteCmdLayout->setSpacing(m_iSpaceSizeZero); @@ -157,9 +158,9 @@ void CustomCommandOptDlg::initUI() deleteCmdLayout->addStretch(); deleteCmdLayout->addWidget(deleteCmdBtn); deleteCmdLayout->addStretch(); - deleteCmdWidget->setLayout(deleteCmdLayout); + m_deleteCmdWidget->setLayout(deleteCmdLayout); - getMainLayout()->addWidget(deleteCmdWidget); + getMainLayout()->addWidget(m_deleteCmdWidget); connect(deleteCmdBtn, &DCommandLinkButton::clicked, this, &CustomCommandOptDlg::slotDelCurCustomCommand); @@ -182,6 +183,27 @@ void CustomCommandOptDlg::initUI() m_lastCmdShortcut = m_shortCutLineEdit->keySequence().toString(); connect(this, &CustomCommandOptDlg::confirmBtnClicked, this, &CustomCommandOptDlg::slotAddSaveButtonClicked); connect(m_shortCutLineEdit, &KeySequenceEdit::editingFinished, this, &CustomCommandOptDlg::slotShortCutLineEditingFinished); + +#ifdef DTKWIDGET_CLASS_DSizeMode + updateSizeMode(); + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, &CustomCommandOptDlg::updateSizeMode); + // 字体变更时更新布局 + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::fontChanged, this, [this](){ + if (isVisible() && layout()) { + layout()->invalidate(); + updateGeometry(); + // 根据新界面布局,刷新界面大小 + QTimer::singleShot(0, this, [=](){ resize(SETTING_DIALOG_WIDTH, minimumSizeHint().height()); }); + } + }); + +#else + if (CCT_ADD == m_type) { + setFixedSize(m_iFixedWidth, m_iFixedHeightAddSize); + } else { + setFixedSize(m_iFixedWidth, m_iFixedHeightEditSize); + } +#endif } inline void CustomCommandOptDlg::slotNameLineEditingFinished() @@ -237,7 +259,7 @@ inline void CustomCommandOptDlg::slotShortCutLineEditingFinished(const QKeySeque void CustomCommandOptDlg::initUITitle() { QVBoxLayout *mainLayout = new QVBoxLayout(); - mainLayout->setSpacing(0); + mainLayout->setSpacing(SPACEHEIGHT); mainLayout->setContentsMargins(0, 0, 0, 10); QHBoxLayout *titleLayout = new QHBoxLayout(); @@ -475,14 +497,12 @@ void CustomCommandOptDlg::addCancelConfirmButtons() m_cancelBtn = new DPushButton(this); m_cancelBtn->setObjectName("CustomCancelButton");//Add by ut001000 renfeixiang 2020-08-13 m_cancelBtn->setFixedWidth(209); - m_cancelBtn->setFixedHeight(36); m_cancelBtn->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); m_cancelBtn->setFont(btnFont); m_confirmBtn = new DSuggestButton(this); m_confirmBtn->setObjectName("CustomConfirmButton");//Add by ut001000 renfeixiang 2020-08-13 m_confirmBtn->setFixedWidth(209); - m_confirmBtn->setFixedHeight(36); m_confirmBtn->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); m_confirmBtn->setFont(btnFont); @@ -491,17 +511,17 @@ void CustomCommandOptDlg::addCancelConfirmButtons() setTabOrder(m_confirmBtn, m_closeButton);//设置右上角关闭按钮的tab键控制顺序 - DVerticalLine *verticalLine = new DVerticalLine(this); - DPalette pa = DApplicationHelper::instance()->palette(verticalLine); + m_verticalLine = new DVerticalLine(this); + DPalette pa = DApplicationHelper::instance()->palette(m_verticalLine); QColor splitColor = pa.color(DPalette::ItemBackground); pa.setBrush(DPalette::Background, splitColor); - verticalLine->setPalette(pa); - verticalLine->setBackgroundRole(QPalette::Background); - verticalLine->setAutoFillBackground(true); - verticalLine->setFixedSize(3, 28); + m_verticalLine->setPalette(pa); + m_verticalLine->setBackgroundRole(QPalette::Background); + m_verticalLine->setAutoFillBackground(true); + m_verticalLine->setFixedSize(3, 28); buttonsLayout->addWidget(m_cancelBtn); - buttonsLayout->addWidget(verticalLine); + buttonsLayout->addWidget(m_verticalLine); buttonsLayout->addWidget(m_confirmBtn); /************************ Add by m000743 sunchengxi 2020-04-15:默认enter回车按下,走确认校验流程 Begin************************/ m_confirmBtn->setDefault(true); @@ -621,6 +641,42 @@ inline void CustomCommandOptDlg::slotSetShortCutLineEditFocus() m_shortCutLineEdit->setFocus(); } +/** + * @brief 接收 DGuiApplicationHelper::sizeModeChanged() 信号, 根据不同的布局模式调整 + * 当前界面的布局. 只能在界面创建完成后调用. + */ +void CustomCommandOptDlg::updateSizeMode() +{ +#ifdef DTKWIDGET_CLASS_DSizeMode + if (DGuiApplicationHelper::isCompactMode()) { + m_titleBar->setFixedHeight(WIN_TITLE_BAR_HEIGHT_COMPACT); + m_logoIcon->setFixedSize(QSize(ICONSIZE_40_COMPACT, ICONSIZE_40_COMPACT)); + m_closeButton->setIconSize(QSize(ICONSIZE_40_COMPACT, ICONSIZE_40_COMPACT)); + m_verticalLine->setFixedSize(VERTICAL_WIDTH_COMPACT, VERTICAL_HEIGHT_COMPACT); + if (m_deleteCmdWidget) { + m_deleteCmdWidget->setFixedHeight(m_iFixedHeightCompact); + } + + } else { + m_titleBar->setFixedHeight(WIN_TITLE_BAR_HEIGHT); + m_logoIcon->setFixedSize(QSize(ICONSIZE_50, ICONSIZE_50)); + m_closeButton->setIconSize(QSize(ICONSIZE_50, ICONSIZE_50)); + m_verticalLine->setFixedSize(VERTICAL_WIDTH, VERTICAL_HEIGHT); + if (m_deleteCmdWidget) { + m_deleteCmdWidget->setFixedHeight(m_iFixedHeight); + } + } + + if (layout()) { + layout()->invalidate(); + } + + updateGeometry(); + // 根据新界面布局,刷新界面大小 + QTimer::singleShot(0, this, [=](){ resize(SETTING_DIALOG_WIDTH, minimumSizeHint().height()); }); +#endif +} + void CustomCommandOptDlg::addContent(QWidget *content) { Q_ASSERT(nullptr != m_contentLayout); diff --git a/src/customcommand/customcommandoptdlg.h b/src/customcommand/customcommandoptdlg.h index 8d261c6d8..5514f1ee1 100644 --- a/src/customcommand/customcommandoptdlg.h +++ b/src/customcommand/customcommandoptdlg.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -203,6 +204,11 @@ private slots: void slotSetShortCutLineEditFocus(); + /** + * @brief 根据布局模式(紧凑)变更更新界面布局 + */ + void updateSizeMode(); + private: /** * @brief 初始化自定义命令操作窗口界面布局 @@ -232,8 +238,11 @@ private slots: QVBoxLayout *m_contentLayout = nullptr; QVBoxLayout *m_mainLayout = nullptr; + QWidget *m_deleteCmdWidget = nullptr; + DPushButton *m_cancelBtn = nullptr; DSuggestButton *m_confirmBtn = nullptr; + DVerticalLine *m_verticalLine = nullptr; QDialog::DialogCode m_confirmResultCode; // 快捷键冲突弹窗 @@ -247,7 +256,14 @@ private slots: const int m_iLayoutRightSize = 30; const int m_iFixedWidth = 459; +#ifdef DTKWIDGET_CLASS_DSizeMode + const int m_iFixedHeight = 34; + const int m_iFixedHeightCompact = 24; + const int m_iSpaceSizeSeven = 7; +#else const int m_iFixedHeight = 54; + const int m_iSpaceSizeEighteen = 18; +#endif const int m_iFixedHeightAddSize = 262; const int m_iFixedHeightEditSize = 296; @@ -256,7 +272,6 @@ private slots: const int m_iSpaceSizeZero = 0; const int m_iSpaceSizeTen = 10; - const int m_iSpaceSizeEighteen = 18; const int m_iSingleShotTime = 30; diff --git a/src/customcommand/customcommandpanel.cpp b/src/customcommand/customcommandpanel.cpp index f9d57082a..e56812405 100644 --- a/src/customcommand/customcommandpanel.cpp +++ b/src/customcommand/customcommandpanel.cpp @@ -193,7 +193,6 @@ void CustomCommandPanel::initUI() m_pushButton = new DPushButton(this); m_pushButton->setObjectName("CustomAddCommandButton");//Add by ut001000 renfeixiang 2020-08-13 - m_pushButton->setFixedHeight(36); m_pushButton->setText(tr("Add Command")); m_textLabel = new DLabel(this); diff --git a/src/customcommand/customcommandsearchrstpanel.cpp b/src/customcommand/customcommandsearchrstpanel.cpp index 574747b0c..7f4387c04 100644 --- a/src/customcommand/customcommandsearchrstpanel.cpp +++ b/src/customcommand/customcommandsearchrstpanel.cpp @@ -37,7 +37,7 @@ void CustomCommandSearchRstPanel::initUI() m_rebackButton->setObjectName("CustomRebackButton"); m_backButton = m_rebackButton; m_backButton->setIcon(DStyle::StandardPixmap::SP_ArrowLeave); - m_backButton->setFixedSize(QSize(36, 36)); + m_backButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); m_backButton->setFocusPolicy(Qt::TabFocus); m_label = new DLabel(this); diff --git a/src/encodeplugin/encodelistview.cpp b/src/encodeplugin/encodelistview.cpp index 0d17b0e46..1dfba8927 100644 --- a/src/encodeplugin/encodelistview.cpp +++ b/src/encodeplugin/encodelistview.cpp @@ -42,9 +42,6 @@ EncodeListView::EncodeListView(QWidget *parent) : DListView(parent), m_encodeMod setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - //add by ameng 设置属性,修复BUG#20074 - setItemSize(QSize(ENCODE_ITEM_WIDTH, ENCODE_ITEM_HEIGHT)); - /***add by ut001121 zhangmeng 20200628 设置视图边距,留出空间给滚动条显示 修复BUG35378***/ setViewportMargins(MARGINS_LEFT, MARGINS_TOP, MARGINS_RIGHT, MARGINS_BOTTOM); @@ -63,6 +60,16 @@ EncodeListView::EncodeListView(QWidget *parent) : DListView(parent), m_encodeMod /** add by ut001121 zhangmeng 20200811 for sp3 Touch screen interaction */ Service::instance()->setScrollerTouchGesture(this); + +#ifdef DTKWIDGET_CLASS_DSizeMode + setItemSize(QSize(ENCODE_ITEM_WIDTH, DGuiApplicationHelper::isCompactMode() ? ENCODE_ITEM_HEIGHT_COMPACT : ENCODE_ITEM_HEIGHT)); + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, [this](){ + setItemSize(QSize(ENCODE_ITEM_WIDTH, DGuiApplicationHelper::isCompactMode() ? ENCODE_ITEM_HEIGHT_COMPACT : ENCODE_ITEM_HEIGHT)); + }); +#else + //add by ameng 设置属性,修复BUG#20074 + setItemSize(QSize(ENCODE_ITEM_WIDTH, ENCODE_ITEM_HEIGHT)); +#endif } void EncodeListView::initEncodeItems() @@ -248,12 +255,13 @@ void EncodeDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt, option.state = option.state & (~QStyle::State_Selected); initStyleOption(&option, index); + /// Note: 实际绘制的选项框相较设置值 -10px 以达到间距,没有采用 setSpacing() 设置,存疑 // 背景区域 QRect bgRect; bgRect.setX(option.rect.x() + 1/* + 10*/); bgRect.setY(option.rect.y() + 1/* + 10*/); bgRect.setWidth(option.rect.width() - 1); - bgRect.setHeight(option.rect.height() - 10); + bgRect.setHeight(option.rect.height() - 9); // 绘画路径 QPainterPath path; @@ -302,7 +310,7 @@ void EncodeDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt, // 绘画文本 int checkIconSize = 16; QString strCmdName = index.data().toString(); - QRect cmdNameRect = QRect(10, bgRect.top(), bgRect.width() - checkIconSize, 50); + QRect cmdNameRect = QRect(10, bgRect.top(), bgRect.width() - checkIconSize, bgRect.height()); painter->drawText(cmdNameRect, Qt::AlignLeft | Qt::AlignVCenter, strCmdName); // 绘画边框 @@ -351,6 +359,11 @@ QSize EncodeDelegate::sizeHint(const QStyleOptionViewItem &option, { Q_UNUSED(index) +#ifdef DTKWIDGET_CLASS_DSizeMode + int height = DGuiApplicationHelper::isCompactMode() ? ENCODE_ITEM_HEIGHT_COMPACT : ENCODE_ITEM_HEIGHT; + return QSize(option.rect.width() - 100, height); +#else return QSize(option.rect.width() - 100, 60); +#endif } diff --git a/src/remotemanage/remotemanagementpanel.cpp b/src/remotemanage/remotemanagementpanel.cpp index fe903c74b..81b5e664a 100644 --- a/src/remotemanage/remotemanagementpanel.cpp +++ b/src/remotemanage/remotemanagementpanel.cpp @@ -179,10 +179,8 @@ void RemoteManagementPanel::initUI() m_pushButton = new DPushButton(this); m_pushButton->setObjectName("RemoteAddPushButton"); - m_searchEdit->setFixedHeight(COMMONHEIGHT); m_searchEdit->setClearButtonEnabled(true); - m_pushButton->setFixedHeight(COMMONHEIGHT); m_pushButton->setText(tr("Add Server")); m_textLabel = new DLabel(this); @@ -265,6 +263,5 @@ void RemoteManagementPanel::initUI() qInfo() << "set focus on add search edit"; } } - }); } diff --git a/src/remotemanage/remotemanagementsearchpanel.cpp b/src/remotemanage/remotemanagementsearchpanel.cpp index 18137d24e..84778fa83 100644 --- a/src/remotemanage/remotemanagementsearchpanel.cpp +++ b/src/remotemanage/remotemanagementsearchpanel.cpp @@ -30,7 +30,7 @@ void RemoteManagementSearchPanel::initUI() m_rebackButton = new IconButton(this); m_rebackButton->setObjectName("RemoteSearchRebackButton"); m_rebackButton->setIcon(DStyle::StandardPixmap::SP_ArrowLeave); - m_rebackButton->setFixedSize(QSize(ICONSIZE_36, ICONSIZE_36)); + m_rebackButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); m_rebackButton->setFocusPolicy(Qt::TabFocus); m_listWidget = new ListView(ListType_Remote, this); diff --git a/src/remotemanage/serverconfiggrouppanel.cpp b/src/remotemanage/serverconfiggrouppanel.cpp index 14a2530eb..36c6db404 100644 --- a/src/remotemanage/serverconfiggrouppanel.cpp +++ b/src/remotemanage/serverconfiggrouppanel.cpp @@ -38,7 +38,6 @@ void ServerConfigGroupPanel::initUI() m_listWidget->setObjectName("RemoteGroupListWidget");//Add by ut001000 renfeixiang 2020-08-14 m_rebackButton->setIcon(DStyle::StandardPixmap::SP_ArrowLeave); - m_rebackButton->setFixedSize(QSize(ICONSIZE_36, ICONSIZE_36)); m_rebackButton->setObjectName("RemoteGroupRebackButton"); m_searchEdit->setFixedWidth(GROUPSEARCHWIDTH); diff --git a/src/remotemanage/serverconfigoptdlg.cpp b/src/remotemanage/serverconfigoptdlg.cpp index e2f88b844..d4c74ae68 100644 --- a/src/remotemanage/serverconfigoptdlg.cpp +++ b/src/remotemanage/serverconfigoptdlg.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -258,12 +257,12 @@ void ServerConfigOptDlg::initUI() pa.setBrush(DPalette::ButtonText, brush); pAddSaveButton->setPalette(pa); QHBoxLayout *pBtHbLayout = new QHBoxLayout(); - DVerticalLine *line = new DVerticalLine(); - line->setFixedSize(3, 28); + m_bottomVLine = new DVerticalLine(); + m_bottomVLine->setFixedSize(3, 28); pBtHbLayout->setContentsMargins(10, 0, 10, 0); pBtHbLayout->setSpacing(9); pBtHbLayout->addWidget(pCancelButton); - pBtHbLayout->addWidget(line); + pBtHbLayout->addWidget(m_bottomVLine); pBtHbLayout->addWidget(pAddSaveButton); m_VBoxLayout->addLayout(pBtHbLayout); setLayout(m_VBoxLayout); @@ -281,6 +280,17 @@ void ServerConfigOptDlg::initUI() // 设置焦点顺序 setTabOrder(pAddSaveButton, m_closeButton); + +#ifdef DTKWIDGET_CLASS_DSizeMode + updateSizeMode(); + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, &ServerConfigOptDlg::updateSizeMode); + // 仅在紧凑模式下处理,此模式下调整字体大小可能导致布局间距存在差异。 + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::fontChanged, this, [this](){ + if (DGuiApplicationHelper::isCompactMode()) { + QTimer::singleShot(0, this, [=](){ resize(SETTING_DIALOG_WIDTH, sizeHint().height()); }); + } + }); +#endif } inline void ServerConfigOptDlg::handleThemeTypeChanged(DGuiApplicationHelper::ColorType themeType) @@ -301,6 +311,43 @@ inline void ServerConfigOptDlg::handleThemeTypeChanged(DGuiApplicationHelper::Co m_delServer->setPalette(palette); } +/** + * @brief 接收 DGuiApplicationHelper::sizeModeChanged() 信号, 根据不同的布局模式调整 + * 当前界面的布局. 只能在界面创建完成后调用. + * 在此界面中调整标题栏组件、文本Label的属性,调整后修改设置框界面大小。 + */ +void ServerConfigOptDlg::updateSizeMode() +{ +#ifdef DTKWIDGET_CLASS_DSizeMode + QList labelList = findChildren(); + + if (DGuiApplicationHelper::isCompactMode()) { + for (DLabel *label : labelList) { + label->setFixedHeight(COMMONHEIGHT_COMPACT); + } + + m_iconLabel->setFixedSize(ICONSIZE_40_COMPACT, ICONSIZE_40_COMPACT); + m_closeButton->setFixedWidth(ICONSIZE_40_COMPACT); + m_closeButton->setIconSize(QSize(ICONSIZE_40_COMPACT, ICONSIZE_40_COMPACT)); + DFontSizeManager::instance()->bind(m_advancedOptions, DFontSizeManager::T6, QFont::Normal); + m_bottomVLine->setFixedSize(VERTICAL_WIDTH_COMPACT, VERTICAL_HEIGHT_COMPACT); + } else { + for (DLabel *label : labelList) { + label->setMinimumHeight(COMMONHEIGHT); + } + + m_iconLabel->setFixedSize(ICONSIZE_50, ICONSIZE_50); + m_closeButton->setFixedWidth(ICONSIZE_50); + m_closeButton->setIconSize(QSize(ICONSIZE_50, ICONSIZE_50)); + DFontSizeManager::instance()->bind(m_advancedOptions, DFontSizeManager::T8, QFont::Normal); + m_bottomVLine->setFixedSize(VERTICAL_WIDTH, VERTICAL_HEIGHT); + } + + // 根据新界面布局,刷新界面大小 + QTimer::singleShot(0, this, [=](){ resize(SETTING_DIALOG_WIDTH, sizeHint().height()); }); +#endif +} + void ServerConfigOptDlg::initData() { QList textCodeList = getTextCodec(); @@ -446,6 +493,15 @@ void ServerConfigOptDlg::resetCurServer(ServerConfig *config) void ServerConfigOptDlg::setAdvanceRegionVisible(bool isVisible) { + // 点击【高级选项】展开,优先隐藏选项,防止因布局变更导致的闪烁问题。 + bool focustOnAdvanced = m_advancedOptions->hasFocus(); + if (isVisible) { + //切换【高级选项】的焦点 + m_advancedOptions->hide(); + } else { + m_advancedOptions->show(); + } + //隐藏或显示【高级选项】下方的控件 int hideRow = m_pGridLayout->rowCount(); for(int row = 0; row < m_pGridLayout->rowCount(); row ++) { @@ -454,6 +510,7 @@ void ServerConfigOptDlg::setAdvanceRegionVisible(bool isVisible) QWidget *cell = item ? item->widget() : nullptr; if(nullptr == cell) continue; + //获取【高级选项】对应的行 if(cell == m_advancedOptions) hideRow = row; @@ -466,12 +523,24 @@ void ServerConfigOptDlg::setAdvanceRegionVisible(bool isVisible) cell->setVisible(isVisible); } } - //点击【高级选项】展开 - if(isVisible) { - //切换【高级选项】的焦点 - m_advancedOptions->hide(); - if(m_advancedOptions->hasFocus()) + + // 继续展开删除选项,重设界面大小 + if (isVisible) { + if (focustOnAdvanced) { m_group->setFocus(); + } + +#ifdef DTKWIDGET_CLASS_DSizeMode + //修改界面 + if (SCT_MODIFY == m_type) { + m_delServer->show(); + } else { + m_delServer->hide(); + } + //singleShot是为了避免size和resize的不一样 + QTimer::singleShot(0, this, [=](){ resize(SETTING_DIALOG_WIDTH, sizeHint().height()); }); + +#else //修改界面 if (SCT_MODIFY == m_type) { m_delServer->show(); @@ -481,10 +550,15 @@ void ServerConfigOptDlg::setAdvanceRegionVisible(bool isVisible) m_delServer->hide(); QTimer::singleShot(0, this, [=](){resize(459, 630);}); } +#endif } else { - m_advancedOptions->show(); m_delServer->hide(); - resize(459, 392); + +#ifdef DTKWIDGET_CLASS_DSizeMode + resize(SETTING_DIALOG_WIDTH, sizeHint().height()); +#else + resize(459, 392); +#endif } } diff --git a/src/remotemanage/serverconfigoptdlg.h b/src/remotemanage/serverconfigoptdlg.h index 34d2010f9..a2dcd17e2 100644 --- a/src/remotemanage/serverconfigoptdlg.h +++ b/src/remotemanage/serverconfigoptdlg.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -114,6 +115,11 @@ private slots: void slotFileChooseDialog(); void handleThemeTypeChanged(DGuiApplicationHelper::ColorType themeType); + /** + * @brief 根据布局模式(紧凑)变更更新界面布局 + */ + void updateSizeMode(); + private: ServerConfigOptType m_type; ServerConfig *m_curServer = nullptr; @@ -137,6 +143,7 @@ private slots: TermCommandLinkButton *m_delServer = nullptr; bool m_bDelOpt = false; QGridLayout *m_pGridLayout = nullptr; + DVerticalLine *m_bottomVLine = nullptr; /** * @brief 服务器配置选项初始化UI界面 @@ -174,7 +181,6 @@ private slots: * @author m000714 戴正文 */ inline void setLabelStyle(DLabel *); - }; #endif // SERVERCONFIGOPTDLG_H diff --git a/src/views/commonpanel.cpp b/src/views/commonpanel.cpp index b7d17d495..6d2e597f3 100644 --- a/src/views/commonpanel.cpp +++ b/src/views/commonpanel.cpp @@ -4,14 +4,34 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "commonpanel.h" +#include "utils.h" #include +#ifdef DTKWIDGET_CLASS_DSizeMode +#include +#endif #include #include CommonPanel::CommonPanel(QWidget *parent) : QFrame(parent) { +#ifdef DTKWIDGET_CLASS_DSizeMode + // 布局模式变更时,刷新当前界面的布局,主要是按钮等高度调整等导致的效果不一致 + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, [this](){ + QRect rect = geometry(); + // 50 - 40 = 10 px + constexpr int offset = WIN_TITLE_BAR_HEIGHT - WIN_TITLE_BAR_HEIGHT_COMPACT; + // 普通转紧凑模式时增加高度,反之则降低高度 + rect.setHeight(rect.height() + DSizeModeHelper::element(offset, -offset)); + setGeometry(rect); + + if (layout()) { + layout()->invalidate(); + updateGeometry(); + } + }); +#endif } void CommonPanel::clearSearchInfo() diff --git a/src/views/customthemesettingdialog.cpp b/src/views/customthemesettingdialog.cpp index a1265cdc8..92ea2d0d9 100644 --- a/src/views/customthemesettingdialog.cpp +++ b/src/views/customthemesettingdialog.cpp @@ -158,7 +158,23 @@ CustomThemeSettingDialog::CustomThemeSettingDialog(QWidget *parent) : DAbstractD initUITitle(); initUI(); initTitleConnections(); + +#ifdef DTKWIDGET_CLASS_DSizeMode + setFixedWidth(SETTING_DIALOG_WIDTH); + + updateSizeMode(); + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, &CustomThemeSettingDialog::updateSizeMode); + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::fontChanged, this, [this](){ + if (isVisible() && layout()) { + layout()->invalidate(); + updateGeometry(); + // 根据新界面布局,刷新界面大小 + QTimer::singleShot(0, this, [=](){ resize(SETTING_DIALOG_WIDTH, minimumSizeHint().height()); }); + } + }); +#else setFixedSize(459, 378); +#endif } void CustomThemeSettingDialog::initUITitle() @@ -401,7 +417,6 @@ void CustomThemeSettingDialog::addCancelConfirmButtons() QFont btnFont; m_cancelBtn = new DPushButton(this); m_cancelBtn->setFixedWidth(209); - m_cancelBtn->setFixedHeight(36); m_cancelBtn->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); m_cancelBtn->setFont(btnFont); m_cancelBtn->setText(tr("Cancel", "button")); @@ -409,7 +424,6 @@ void CustomThemeSettingDialog::addCancelConfirmButtons() m_confirmBtn = new DSuggestButton(this); m_confirmBtn->setFixedWidth(209); - m_confirmBtn->setFixedHeight(36); m_confirmBtn->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); m_confirmBtn->setFont(btnFont); m_confirmBtn->setText(tr("Confirm", "button")); @@ -423,17 +437,17 @@ void CustomThemeSettingDialog::addCancelConfirmButtons() setTabOrder(m_confirmBtn, m_closeButton);//设置右上角关闭按钮的tab键控制顺序 - DVerticalLine *verticalLine = new DVerticalLine(this); - DPalette pa = DApplicationHelper::instance()->palette(verticalLine); + m_verticalLine = new DVerticalLine(this); + DPalette pa = DApplicationHelper::instance()->palette(m_verticalLine); QColor splitColor = pa.color(DPalette::ItemBackground); pa.setBrush(DPalette::Background, splitColor); - verticalLine->setPalette(pa); - verticalLine->setBackgroundRole(QPalette::Background); - verticalLine->setAutoFillBackground(true); - verticalLine->setFixedSize(3, 28); + m_verticalLine->setPalette(pa); + m_verticalLine->setBackgroundRole(QPalette::Background); + m_verticalLine->setAutoFillBackground(true); + m_verticalLine->setFixedSize(3, 28); buttonsLayout->addWidget(m_cancelBtn); - buttonsLayout->addWidget(verticalLine); + buttonsLayout->addWidget(m_verticalLine); buttonsLayout->addWidget(m_confirmBtn); m_confirmBtn->setDefault(true); @@ -511,6 +525,35 @@ void CustomThemeSettingDialog::clearFocussSlot() m_logoIcon->setFocus(); } +/** + * @brief 接收 DGuiApplicationHelper::sizeModeChanged() 信号, 根据不同的布局模式调整 + * 当前界面的布局. 只能在界面创建完成后调用. + */ +void CustomThemeSettingDialog::updateSizeMode() +{ +#ifdef DTKWIDGET_CLASS_DSizeMode + if (DGuiApplicationHelper::isCompactMode()) { + m_titleBar->setFixedHeight(WIN_TITLE_BAR_HEIGHT_COMPACT); + m_logoIcon->setFixedSize(QSize(ICONSIZE_40_COMPACT, ICONSIZE_40_COMPACT)); + m_closeButton->setIconSize(QSize(ICONSIZE_40_COMPACT, ICONSIZE_40_COMPACT)); + m_verticalLine->setFixedSize(VERTICAL_WIDTH_COMPACT, VERTICAL_HEIGHT_COMPACT); + + } else { + m_titleBar->setFixedHeight(WIN_TITLE_BAR_HEIGHT); + m_logoIcon->setFixedSize(QSize(ICONSIZE_50, ICONSIZE_50)); + m_closeButton->setIconSize(QSize(ICONSIZE_50, ICONSIZE_50)); + m_verticalLine->setFixedSize(VERTICAL_WIDTH, VERTICAL_HEIGHT); + } + + if (layout()) { + layout()->invalidate(); + } + updateGeometry(); + // 根据新界面布局,刷新界面大小 + QTimer::singleShot(0, this, [=](){ resize(SETTING_DIALOG_WIDTH, minimumSizeHint().height()); }); +#endif +} + void CustomThemeSettingDialog::loadConfiguration() { //重置单选按钮的tab焦点状态 diff --git a/src/views/customthemesettingdialog.h b/src/views/customthemesettingdialog.h index 406cdd128..80623d8e6 100644 --- a/src/views/customthemesettingdialog.h +++ b/src/views/customthemesettingdialog.h @@ -207,6 +207,12 @@ public slots: */ void clearFocussSlot(); +private: + /** + * @brief 根据布局模式(紧凑)切换更新界面布局 + */ + Q_SLOT void updateSizeMode(); + private: //标题栏 QWidget *m_titleBar = nullptr; @@ -226,6 +232,8 @@ public slots: DPushButton *m_cancelBtn = nullptr; //确认按钮 DSuggestButton *m_confirmBtn = nullptr; + //竖向分割线 + DVerticalLine *m_verticalLine = nullptr; //预览区域 ThemePreviewArea *m_themePreviewArea = nullptr; //深色主题风格单选按钮 diff --git a/src/views/focusframe.cpp b/src/views/focusframe.cpp index 7df555c7a..6ba5fc00e 100644 --- a/src/views/focusframe.cpp +++ b/src/views/focusframe.cpp @@ -31,11 +31,14 @@ void FocusFrame::paintEvent(QPaintEvent *event) // 去锯齿 painter.setRenderHint(QPainter::SmoothPixmapTransform, true); painter.setRenderHint(QPainter::Antialiasing); + // 焦点若在,则画边框 if (m_isFocus) { // 边框 QPainterPath FramePath; - paintRoundedRect(FramePath, QRect(2, 2, 218, 58)); + // 效果和以下代码类似,兼容紧凑模式 + // 类似: paintRoundedRect(FramePath, QRect(2, 2, 218, 58)); + paintRoundedRect(FramePath, rect().adjusted(2, 2, 0, 0)); // 获取活动色 QPen pen(pa.color(DPalette::Highlight), 2); painter.setPen(pen); @@ -44,7 +47,8 @@ void FocusFrame::paintEvent(QPaintEvent *event) // 绘制背景 QPainterPath itemBackgroudPath; - paintRoundedRect(itemBackgroudPath, QRect(4, 4, 214, 54)); + // 类似: paintRoundedRect(itemBackgroudPath, QRect(4, 4, 214, 54)); + paintRoundedRect(FramePath, rect().adjusted(4, 4, -2, -2)); // 产品要有悬浮效果的 // painter.fillPath(itemBackgroudPath, QBrush(pa.color(DPalette::ObviousBackground))); // ui要有框,背景不变 @@ -53,7 +57,8 @@ void FocusFrame::paintEvent(QPaintEvent *event) // 焦点不在,不绘制 // 绘制背景 QPainterPath itemBackgroudPath; - paintRoundedRect(itemBackgroudPath, QRect(0, 0, 220, 60)); + // 类似: paintRoundedRect(itemBackgroudPath, QRect(0, 0, 220, 60)); + paintRoundedRect(itemBackgroudPath, rect().adjusted(0, 0, 1, 1)); // 产品要有悬浮效果的 // painter.fillPath(itemBackgroudPath, QBrush(pa.color(DPalette::ObviousBackground))); // ui要有框,背景不变 diff --git a/src/views/itemwidget.cpp b/src/views/itemwidget.cpp index 14a696dfe..54e733d3d 100644 --- a/src/views/itemwidget.cpp +++ b/src/views/itemwidget.cpp @@ -14,6 +14,12 @@ #include #include +// 不同布局模式配置 +const int s_ItemHeight = 60; +const QMargins s_ItemIconContentMargins = {8, 8, 8, 8}; +const int s_ItemHeightCompact = 52; +const QMargins s_ItemIconContentMarginsCompact = {4, 4, 4, 4}; + // 需要选择Item类型 ItemWidget::ItemWidget(ItemFuncType itemType, QWidget *parent) : FocusFrame(parent) @@ -249,6 +255,27 @@ void ItemWidget::onFocusOut(Qt::FocusReason type) } } +/** + * @brief 根据布局模式(紧凑)变更更新界面布局,ItemWidget 不绑定变更信号, + * 而是通过外部 ListView 处理。 + */ +void ItemWidget::updateSizeMode() +{ +#ifdef DTKWIDGET_CLASS_DSizeMode + if (DGuiApplicationHelper::isCompactMode()) { + m_iconLayout->setContentsMargins(s_ItemIconContentMarginsCompact); + setFixedSize(220, s_ItemHeightCompact); + setFont(m_firstline, DFontSizeManager::T6, ItemTextColor_Text); + setFont(m_secondline, DFontSizeManager::T7, ItemTextColor_TextTips); + } else { + m_iconLayout->setContentsMargins(s_ItemIconContentMargins); + setFixedSize(220, s_ItemHeight); + setFont(m_firstline, DFontSizeManager::T7, ItemTextColor_Text); + setFont(m_secondline, DFontSizeManager::T8, ItemTextColor_TextTips); + } +#endif +} + void ItemWidget::initUI() { // 初始化控件大小 @@ -301,6 +328,9 @@ void ItemWidget::initUI() m_mainLayout->addLayout(m_funcLayout); m_mainLayout->addStretch(); setLayout(m_mainLayout); + + // 根据不同布局初始化界面 + updateSizeMode(); } void ItemWidget::initConnections() diff --git a/src/views/itemwidget.h b/src/views/itemwidget.h index 98edda912..cfa0ee7f9 100644 --- a/src/views/itemwidget.h +++ b/src/views/itemwidget.h @@ -154,6 +154,11 @@ public slots: */ void onFocusOut(Qt::FocusReason type); + /** + * @brief 根据布局模式(紧凑)切换更新界面布局, 将被外部 ListView 统一调用,为公共接口 + */ + void updateSizeMode(); + signals: // 功能按钮被点击 // 参数: item的名称 (数据的唯一值) diff --git a/src/views/listview.cpp b/src/views/listview.cpp index 18c552886..51f3b32b2 100644 --- a/src/views/listview.cpp +++ b/src/views/listview.cpp @@ -416,10 +416,22 @@ void ListView::onCustomItemModify(const QString &key, bool isFocusOn) m_pdlg->show(); } +/** + * @brief 接收 DGuiApplicationHelper::sizeModeChanged() 信号, 根据不同的布局模式调整 + * 当前界面的布局. 只能在界面创建完成后调用. + */ +void ListView::updateSizeMode() +{ +#ifdef DTKWIDGET_CLASS_DSizeMode + // 遍历子项进行更新 + for (ItemWidget *item : m_itemList) { + item->updateSizeMode(); + } +#endif +} + inline void ListView::onCustomCommandOptDlgFinished(int result) { - int tempResult = result; - // 弹窗隐藏或消失 //Service::instance()->setIsDialogShow(window(), false);//暂时保留 @@ -603,6 +615,10 @@ void ListView::initUI() m_mainWidget->setLayout(m_mainLayout); setWidget(m_mainWidget); +#ifdef DTKWIDGET_CLASS_DSizeMode + updateSizeMode(); + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, &ListView::updateSizeMode); +#endif } void ListView::setItemIcon(ItemFuncType type, ItemWidget *item) diff --git a/src/views/listview.h b/src/views/listview.h index 8991dc96a..29703fe8a 100644 --- a/src/views/listview.h +++ b/src/views/listview.h @@ -316,6 +316,11 @@ private slots: * @param isFocusOn 是否有焦点 */ void onCustomItemModify(const QString &key, bool isFocusOn); + + /** + * @brief 根据布局模式(紧凑)变更更新界面布局 + */ + Q_SLOT void updateSizeMode(); }; #endif // LISTVIEW_H diff --git a/src/views/pagesearchbar.cpp b/src/views/pagesearchbar.cpp index b09eb09cb..6c40aad9e 100644 --- a/src/views/pagesearchbar.cpp +++ b/src/views/pagesearchbar.cpp @@ -8,6 +8,10 @@ #include "mainwindow.h" #include +#include +#ifdef DTKWIDGET_CLASS_DSizeMode +#include +#endif #include #include @@ -21,7 +25,7 @@ PageSearchBar::PageSearchBar(QWidget *parent) : DFloatingWidget(parent) Utils::set_Object_Name(this); // Init hide(); - setFixedSize(barWidth, barHight + 12); + setFixedSize(barWidth, barHight); // 设置窗体透明度的,需求为100% QGraphicsOpacityEffect *opacityEffect = new QGraphicsOpacityEffect; setGraphicsEffect(opacityEffect); @@ -35,10 +39,16 @@ PageSearchBar::PageSearchBar(QWidget *parent) : DFloatingWidget(parent) QHBoxLayout *m_layout = new QHBoxLayout(); m_layout->setSpacing(widgetSpace); m_layout->setContentsMargins(layoutMargins, layoutMargins, layoutMargins, layoutMargins); + m_layout->setAlignment(Qt::AlignVCenter); m_layout->addWidget(m_searchEdit); m_layout->addWidget(m_findPrevButton); m_layout->addWidget(m_findNextButton); setLayout(m_layout); + +#ifdef DTKWIDGET_CLASS_DSizeMode + updateSizeMode(); + QObject::connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, &PageSearchBar::updateSizeMode); +#endif } bool PageSearchBar::isFocus() @@ -156,7 +166,6 @@ void PageSearchBar::initSearchEdit() m_searchEdit->setFocusPolicy(Qt::StrongFocus); m_searchEdit->setFocusProxy(m_searchEdit->lineEdit()); m_searchEdit->setObjectName("PageSearchBarSearchEdit");//Add by ut001000 renfeixiang 2020-08-13 - m_searchEdit->lineEdit()->setMinimumHeight(widgetHight); // 保留原文字,图标 saveOldHoldContent(); @@ -188,6 +197,46 @@ void PageSearchBar::initSearchEdit() }); } +/** + * @brief 接收 DGuiApplicationHelper::sizeModeChanged() 信号, 根据不同的布局模式调整 + * 当前界面的布局. 只能在界面创建完成后调用. + */ +void PageSearchBar::updateSizeMode() +{ +#ifdef DTKWIDGET_CLASS_DSizeMode + DIconButton *searchIconBtn = m_searchEdit->findChild(); + + if (DGuiApplicationHelper::isCompactMode()) { + setFixedSize(barWidthCompact, barHeightCompact); + setContentsMargins(compactMarigin, compactMarigin, compactMarigin, compactMarigin); + m_findPrevButton->setFixedSize(btnWidthCompact, btnHeightCompact); + m_findNextButton->setFixedSize(btnWidthCompact, btnHeightCompact); + m_searchEdit->setFixedHeight(COMMONHEIGHT_COMPACT); + + if (searchIconBtn) { + searchIconBtn->setIconSize(QSize(ICON_CTX_SIZE_24, ICON_CTX_SIZE_24)); + } + } else { + setFixedSize(barWidth, barHight); + setContentsMargins(defaultMarigin, defaultMarigin, defaultMarigin, defaultMarigin); + m_findPrevButton->setFixedSize(widgetHight, widgetHight); + m_findNextButton->setFixedSize(widgetHight, widgetHight); + m_searchEdit->setFixedHeight(COMMONHEIGHT); + + if (searchIconBtn) { + searchIconBtn->setIconSize(QSize(ICON_CTX_SIZE_32, ICON_CTX_SIZE_32)); + } + } + + if (layout()) { + layout()->setContentsMargins(DSizeModeHelper::element(compactLayoutMarigins, defaultLayoutMarigins)); + layout()->setSpacing(DSizeModeHelper::element(9, widgetSpace)); + layout()->invalidate(); + update(); + } +#endif +} + void PageSearchBar::setNoMatchAlert(bool isAlert) { m_searchEdit->setAlert(isAlert); diff --git a/src/views/pagesearchbar.h b/src/views/pagesearchbar.h index a3a4f9673..6cafe9399 100644 --- a/src/views/pagesearchbar.h +++ b/src/views/pagesearchbar.h @@ -103,12 +103,16 @@ class PageSearchBar : public DFloatingWidget * @author ut000610 daizhengwen */ void initSearchEdit(); + /** + * @brief 根据布局模式更新界面布局 + */ + Q_SLOT void updateSizeMode(); DIconButton *m_findNextButton = nullptr; DIconButton *m_findPrevButton = nullptr; DSearchEdit *m_searchEdit = nullptr; - const int barHight = 50; + const int barHight = 62; const int barWidth = 382; const int layoutMargins = 7; const int widgetHight = 36; @@ -117,10 +121,19 @@ class PageSearchBar : public DFloatingWidget const int iconHight = 6; const int iconWidth = 12; + // 紧凑模式下控件调整 + const int defaultMarigin = 6; + const int compactMarigin = 3; + const QMargins defaultLayoutMarigins = {7, 7, 7, 7}; + const QMargins compactLayoutMarigins = {11, 0, 10, 0}; + const int barWidthCompact = 358 + 5; + const int barHeightCompact = 40; + const int btnWidthCompact = 24; + const int btnHeightCompact = 22; + const qreal opacity = 0.9; QString m_originalPlaceHolder; //原文字 - // 方便性能测试,记住查找开始时间 qint64 m_searchStartTime = 0; }; diff --git a/src/views/rightpanel.cpp b/src/views/rightpanel.cpp index 1a52ae38d..2336b5505 100644 --- a/src/views/rightpanel.cpp +++ b/src/views/rightpanel.cpp @@ -11,6 +11,10 @@ #include #include +#ifdef DTKWIDGET_CLASS_DSizeMode +#include +#endif + //qt #include @@ -20,14 +24,25 @@ RightPanel::RightPanel(QWidget *parent) : QWidget(parent) { // hide by default. QWidget::hide(); - + // Init theme panel. setFixedWidth(240 + 2); - // Init theme panel. - // 插件不支持resize,下面代码不需要了 -// DAnchorsBase::setAnchor(this, Qt::AnchorTop, parent, Qt::AnchorTop); -// DAnchorsBase::setAnchor(this, Qt::AnchorBottom, parent, Qt::AnchorBottom); -// DAnchorsBase::setAnchor(this, Qt::AnchorRight, parent, Qt::AnchorRight); +#ifdef DTKWIDGET_CLASS_DSizeMode + // 布局模式变更时,刷新当前界面的布局,主要是按钮等高度调整等导致的效果不一致 + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, [this](){ + QRect rect = geometry(); + // 50 - 40 = 10 px + constexpr int offset = WIN_TITLE_BAR_HEIGHT - WIN_TITLE_BAR_HEIGHT_COMPACT; + // 普通转紧凑模式时增加高度,反之则降低高度 + rect.setHeight(rect.height() + DSizeModeHelper::element(offset, -offset)); + setGeometry(rect); + + if (layout()) { + layout()->invalidate(); + updateGeometry(); + } + }); +#endif } void RightPanel::showAnim() @@ -43,8 +58,13 @@ void RightPanel::showAnim() /***mod begin by ut001121 zhangmeng 20200918 修复BUG48374 全屏下插件被截断的问题***/ int panelHeight = windowRect.height(); MainWindow *w = Utils::getMainWindow(this); - if (w && w->titlebar()->isVisible()) + if (w && w->titlebar()->isVisible()) { +#ifdef DTKWIDGET_CLASS_DSizeMode + panelHeight -= DSizeModeHelper::element(WIN_TITLE_BAR_HEIGHT_COMPACT, WIN_TITLE_BAR_HEIGHT); +#else panelHeight -= WIN_TITLE_BAR_HEIGHT; +#endif + } animation->setStartValue(QRect(windowRect.width(), rect.y(), rect.width(), panelHeight)); animation->setEndValue(QRect(windowRect.width() - rect.width(), rect.y(), rect.width(), panelHeight)); @@ -66,8 +86,13 @@ void RightPanel::hideAnim() /***mod begin by ut001121 zhangmeng 20200918 修复BUG48374 全屏下插件被截断的问题***/ int panelHeight = windowRect.height(); MainWindow *w = Utils::getMainWindow(this); - if (w && w->titlebar()->isVisible()) + if (w && w->titlebar()->isVisible()) { +#ifdef DTKWIDGET_CLASS_DSizeMode + panelHeight -= DSizeModeHelper::element(WIN_TITLE_BAR_HEIGHT_COMPACT, WIN_TITLE_BAR_HEIGHT); +#else panelHeight -= WIN_TITLE_BAR_HEIGHT; +#endif + } animation->setStartValue(QRect(windowRect.width() - rect.width(), rect.y(), rect.width(), panelHeight)); animation->setEndValue(QRect(windowRect.width(), rect.y(), rect.width(), panelHeight)); diff --git a/src/views/tabbar.cpp b/src/views/tabbar.cpp index eedf616d3..545be25f4 100644 --- a/src/views/tabbar.cpp +++ b/src/views/tabbar.cpp @@ -26,6 +26,10 @@ #include #include +#ifdef DTKWIDGET_CLASS_DSizeMode +#include +#endif + //TermTabStyle类开始,该类用于设置tab标签样式 TermTabStyle::TermTabStyle() : m_tabCount(0) { @@ -161,7 +165,6 @@ TabBar::TabBar(QWidget *parent) : DTabBar(parent), m_rightClickTab(-1) setFocusPolicy(Qt::TabFocus); setStartDragDistance(40); - setTabHeight(36); setTabItemMinWidth(110); setTabItemMaxWidth(450); @@ -180,6 +183,13 @@ TabBar::TabBar(QWidget *parent) : DTabBar(parent), m_rightClickTab(-1) connect(this, &DTabBar::tabIsRemoved, this, &TabBar::handleTabIsRemoved); connect(this, &DTabBar::tabReleaseRequested, this, &TabBar::handleTabReleased); connect(this, &DTabBar::dragActionChanged, this, &TabBar::handleDragActionChanged); + +#ifdef DTKWIDGET_CLASS_DSizeMode + setTabHeight(DSizeModeHelper::element(COMMONHEIGHT_COMPACT, COMMONHEIGHT)); + QObject::connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, [this](){ + setTabHeight(DSizeModeHelper::element(COMMONHEIGHT_COMPACT, COMMONHEIGHT)); + }); +#endif } TabBar::~TabBar() diff --git a/src/views/tabrenamedlg.cpp b/src/views/tabrenamedlg.cpp index 5dd74da5f..e011e3e93 100644 --- a/src/views/tabrenamedlg.cpp +++ b/src/views/tabrenamedlg.cpp @@ -6,11 +6,12 @@ #include "tabrenamedlg.h" #include "utils.h" -#include #include +#include #include #include +#include #include TabRenameDlg::TabRenameDlg(QWidget *parent) : DAbstractDialog(parent) @@ -24,7 +25,7 @@ void TabRenameDlg::initUi() { setWindowModality(Qt::ApplicationModal); // 设置最小值 => 以免一开始挤在一起 - setMinimumSize(456, 226); + setMinimumWidth(SETTING_DIALOG_WIDTH); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); QVBoxLayout *mainLayout = new QVBoxLayout(); @@ -151,8 +152,14 @@ void TabRenameDlg::initContentWidget() // 添加控件 m_mainLayout->setSpacing(10); m_mainLayout->addWidget(m_titlelabel); - m_mainLayout->addWidget(m_normalWidget); - m_mainLayout->addWidget(m_remoteWidget); + + QVBoxLayout *contentLayout = new QVBoxLayout(); + contentLayout->setSpacing(10); + contentLayout->setContentsMargins(20, 0, 20, 10); + contentLayout->addWidget(m_normalWidget); + contentLayout->addWidget(m_remoteWidget); + m_mainLayout->addLayout(contentLayout); + m_mainLayout->addWidget(m_buttonWidget); contentwidget->setLayout(m_mainLayout); @@ -180,6 +187,20 @@ void TabRenameDlg::initConnections() connect(m_closeButton, &DPushButton::clicked, this, [ = ] { close(); }); + +#ifdef DTKWIDGET_CLASS_DSizeMode + updateSizeMode(); + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, &TabRenameDlg::updateSizeMode); + // 字体变更时进行重新布局 + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::fontChanged, this, [this](){ + if (isVisible() && layout()) { + layout()->invalidate(); + // 根据新界面布局,刷新界面大小 + updateGeometry(); + QTimer::singleShot(0, this, [=](){ resize(SETTING_DIALOG_WIDTH, minimumSizeHint().height()); }); + } + }); +#endif } void TabRenameDlg::initTitleLabel() @@ -219,20 +240,47 @@ void TabRenameDlg::initButtonWidget() m_cancelButton = new DPushButton(QObject::tr("Cancel", "button")); Utils::setSpaceInWord(m_cancelButton); - m_cancelButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); DFontSizeManager::instance()->bind(m_cancelButton, DFontSizeManager::T6); m_confirmButton = new DSuggestButton(QObject::tr("Confirm", "button")); Utils::setSpaceInWord(m_confirmButton); - m_confirmButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); DFontSizeManager::instance()->bind(m_confirmButton, DFontSizeManager::T6); - DVerticalLine *verticalLine = new DVerticalLine; - verticalLine->setFixedSize(1, 28); + m_verticalLine = new DVerticalLine; + m_verticalLine->setFixedSize(1, 28); buttonTAbLayout->addWidget(m_cancelButton); - buttonTAbLayout->addWidget(verticalLine); + buttonTAbLayout->addWidget(m_verticalLine); buttonTAbLayout->addWidget(m_confirmButton); m_buttonWidget->setLayout(buttonTAbLayout); } + +/** + * @brief 接收 DGuiApplicationHelper::sizeModeChanged() 信号, 根据不同的布局模式调整 + * 当前界面的布局. 只能在界面创建完成后调用. + */ +void TabRenameDlg::updateSizeMode() +{ +#ifdef DTKWIDGET_CLASS_DSizeMode + if (DGuiApplicationHelper::isCompactMode()) { + m_titleBar->setFixedHeight(WIN_TITLE_BAR_HEIGHT_COMPACT); + m_logoIcon->setPixmap(QIcon::fromTheme("deepin-terminal").pixmap(QSize(ICON_CTX_SIZE_24, ICON_CTX_SIZE_24))); + m_closeButton->setIconSize(QSize(ICONSIZE_40_COMPACT, ICONSIZE_40_COMPACT)); + m_verticalLine->setFixedSize(1, VERTICAL_HEIGHT_COMPACT); + + } else { + m_titleBar->setFixedHeight(WIN_TITLE_BAR_HEIGHT); + m_logoIcon->setPixmap(QIcon::fromTheme("deepin-terminal").pixmap(QSize(ICON_CTX_SIZE_32, ICON_CTX_SIZE_32))); + m_closeButton->setIconSize(QSize(ICONSIZE_50, ICONSIZE_50)); + m_verticalLine->setFixedSize(1, VERTICAL_HEIGHT); + } + + if (layout()) { + layout()->invalidate(); + } + // 根据新界面布局,刷新界面大小 + updateGeometry(); + QTimer::singleShot(0, this, [=](){ resize(SETTING_DIALOG_WIDTH, minimumSizeHint().height()); }); +#endif +} diff --git a/src/views/tabrenamedlg.h b/src/views/tabrenamedlg.h index 88daae188..833f7982e 100644 --- a/src/views/tabrenamedlg.h +++ b/src/views/tabrenamedlg.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -122,6 +123,12 @@ class TabRenameDlg : public DAbstractDialog Q_SIGNALS: void tabTitleFormatRename(const QString &tabTitleFormat, const QString &remoteTabTitleFormat); +private: + /** + * @brief 根据布局模式(紧凑)切换更新界面布局 + */ + Q_SLOT void updateSizeMode(); + private: QWidget *m_titleBar = nullptr; QWidget *m_content = nullptr; @@ -143,9 +150,9 @@ class TabRenameDlg : public DAbstractDialog DLabel *m_titlelabel = nullptr; DPushButton *m_cancelButton = nullptr; DSuggestButton *m_confirmButton = nullptr; + DVerticalLine *m_verticalLine = nullptr; DWindowCloseButton *m_closeButton = nullptr; - }; #endif // TABRENAMEDLG_H diff --git a/src/views/tabrenamewidget.cpp b/src/views/tabrenamewidget.cpp index 03c2589a4..5167e2e40 100644 --- a/src/views/tabrenamewidget.cpp +++ b/src/views/tabrenamewidget.cpp @@ -30,23 +30,18 @@ void TabRenameWidget::initUi() m_layout->setSpacing(10); // widet 自己设置0 0 0 0 this->setContentsMargins(0, 0, 0, 0); - this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // 内容输入框 m_inputedit = new DLineEdit(this); m_inputedit->setText("%n:%d"); - m_inputedit->setMinimumHeight(36); m_inputedit->setMaximumWidth(172); m_inputedit->setMinimumWidth(135); DFontSizeManager::instance()->bind(m_inputedit, DFontSizeManager::T6); // 插入按钮 m_choseButton = new DPushButton(tr("Insert"), this); - m_choseButton->setMinimumHeight(36); - m_choseButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); // 添加下拉菜单 m_choseButton->setMenu(m_choseMenu); - DFontSizeManager::instance()->bind(m_choseButton, DFontSizeManager::T6); m_choseButton->setAutoDefault(false); m_choseButton->setDefault(false); diff --git a/src/views/termwidgetpage.cpp b/src/views/termwidgetpage.cpp index 50683929d..e1b2ac6d6 100644 --- a/src/views/termwidgetpage.cpp +++ b/src/views/termwidgetpage.cpp @@ -51,9 +51,15 @@ TermWidgetPage::TermWidgetPage(const TermProperties &properties, QWidget *parent /******** Modify by nt001000 renfeixiang 2020-05-27:修改 增加参数区别remove和purge卸载命令 Begin***************/ m_currentTerm = w; + +#ifdef DTKWIDGET_CLASS_DSizeMode + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, [this](){ + m_findBar->move(width() - m_findBar->width(), 0); + }, Qt::QueuedConnection); +#endif } -inline void TermWidgetPage::handleKeywordChanged(QString keyword) +inline void TermWidgetPage::handleKeywordChanged(const QString &keyword) { handleUpdateSearchKeyword(keyword); } @@ -523,7 +529,7 @@ void TermWidgetPage::showSearchBar(int state) //Add by ut001000 renfeixiang 2020-12-02 在搜索框弹出时,添加设置Term的m_bHasSelect为false函数 if (m_currentTerm != nullptr) m_currentTerm->setNoHasSelect(); - m_findBar->move(width() - SEARCHBAR_RIGHT_MARGIN, 0); + m_findBar->move(width() - m_findBar->width(), 0); QTimer::singleShot(10, this, [ = ] { m_findBar->focus(); }); } else if (SearchBar_Hide == state) { m_findBar->hide(); diff --git a/src/views/termwidgetpage.h b/src/views/termwidgetpage.h index feb90fbc5..0478d684e 100644 --- a/src/views/termwidgetpage.h +++ b/src/views/termwidgetpage.h @@ -361,7 +361,7 @@ private slots: * @author ut000438 王亮 * @param keyword 搜索关键词 */ - void handleKeywordChanged(QString keyword); + void handleKeywordChanged(const QString &keyword); /** * @brief 处理主题变化的槽 * @author ut000438 王亮 diff --git a/src/views/titlebar.cpp b/src/views/titlebar.cpp index fc0c8333b..49de9620c 100644 --- a/src/views/titlebar.cpp +++ b/src/views/titlebar.cpp @@ -14,6 +14,10 @@ #include #include +#ifdef DTKWIDGET_CLASS_DSizeMode +#include +#endif + static const int VER_RESIZED_ALLOWED_OFF = 3;//允许的垂直偏移量 static const int VER_RESIZED_MIN_HEIGHT = 30;//resize的最小高度 @@ -29,10 +33,18 @@ TitleBar::TitleBar(QWidget *parent) : QWidget(parent), m_layout(new QHBoxLayout( // this->setPalette(palette); this->setBackgroundRole(DPalette::Base); this->setAutoFillBackground(true); - // daizhengwen fix bug#22927 动画出的矩形框会 -50 设置标题栏为50 - this->setFixedHeight(WIN_TITLE_BAR_HEIGHT); /********************* Modify by m000714 daizhengwen End ************************/ m_layout->setContentsMargins(0, 0, 0, 0); + +#ifdef DTKWIDGET_CLASS_DSizeMode + setFixedHeight(DSizeModeHelper::element(WIN_TITLE_BAR_HEIGHT_COMPACT, WIN_TITLE_BAR_HEIGHT)); + QObject::connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, [this](){ + setFixedHeight(DSizeModeHelper::element(WIN_TITLE_BAR_HEIGHT_COMPACT, WIN_TITLE_BAR_HEIGHT)); + }); +#else + // daizhengwen fix bug#22927 动画出的矩形框会 -50 设置标题栏为50 + this->setFixedHeight(WIN_TITLE_BAR_HEIGHT); +#endif } TitleBar::~TitleBar()