Skip to content

Commit

Permalink
feat: 紧凑模式适配
Browse files Browse the repository at this point in the history
紧凑模式适配

Log: 紧凑模式适配

Task: https://pms.uniontech.com/task-view-296453.html
  • Loading branch information
feeengli authored and deepin-bot[bot] committed Oct 18, 2023
1 parent e78e5e7 commit 956acf5
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 36 deletions.
3 changes: 0 additions & 3 deletions deepin-font-manager/globaldef.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
#define MIN_WINDOWS_HEIGHT 300

// Tool Search bar
#define FTM_TITLE_FIXED_HEIGHT 50
#define FTM_TITLE_FIXED_WIDTH 58
#define FTM_SEARCH_BAR_W 358
#define FTM_SEARCH_BAR_H 44
#define FTM_ADDBUTTON_PATAM 38

// Left navigation bar
#define FTM_LEFT_SIDE_BAR_WIDTH 160
Expand Down
36 changes: 36 additions & 0 deletions deepin-font-manager/interfaces/dfontpreviewitemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ const int CHECKBOX_SIZE = 20;
const int COLLECT_ICON_SIZE = 24;
const int COLLECT_ICON_RIGHT_MARGIN = 19;
const int COLLECT_ICON_TOP_MARGIN = 10;
const int COLLECT_ICON_TOP_COMPACT_MARGIN = 1;

const int FONT_NAME_HEIGHT = 30;
const int FONT_NAME_COMPACT_HEIGHT = 21;
const int FONT_NAME_LEFT_MARGIN = 50;
const int FONT_NAME_TOP_MARGIN = 3;
const int FONT_PREVIEW_LEFT_MARGIN = 50;
const int FONT_PREVIEW_RIGHT_MARGIN = COLLECT_ICON_SIZE + COLLECT_ICON_RIGHT_MARGIN;
const int FONT_PREVIEW_TOP_MARGIN = FONT_NAME_HEIGHT + FONT_NAME_TOP_MARGIN;
const int FONT_PREVIEW_TOP_COMPACT_MARGIN = FONT_NAME_COMPACT_HEIGHT + 5;
const int FONT_PREVIEW_BOTTOM_MARGIN = 10;
const int FONT_PREVIEW_BOTTOM_COMPACT_MARGIN = 5;

DFontPreviewItemDelegate::DFontPreviewItemDelegate(QAbstractItemView *parent)
: QStyledItemDelegate(parent)
Expand Down Expand Up @@ -78,6 +82,12 @@ void DFontPreviewItemDelegate::paintForegroundCheckBox(QPainter *painter, const

QRect rect = QRect(option.rect.x() + 25, option.rect.y() + 10, checkBoxWidth, checkBoxHeight);

#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::instance()->sizeMode() == DGuiApplicationHelper::SizeMode::CompactMode) {
rect = QRect(option.rect.x() + 25, option.rect.y() + 6, checkBoxWidth, checkBoxHeight);
}
#endif

QStyleOptionButton checkBoxOption;
checkBoxOption.state |= QStyle::State_Enabled;
checkBoxOption.state |= itemData.isEnabled() ? QStyle::State_On : QStyle::State_Off;
Expand Down Expand Up @@ -116,6 +126,11 @@ void DFontPreviewItemDelegate::paintForegroundFontName(QPainter *painter, const

QRect fontNameRect = QRect(option.rect.x() + FONT_NAME_LEFT_MARGIN, option.rect.y() + FONT_NAME_TOP_MARGIN,
option.rect.width() - 20, FONT_NAME_HEIGHT);
#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::instance()->sizeMode() == DGuiApplicationHelper::SizeMode::CompactMode) {
fontNameRect.setHeight(FONT_NAME_COMPACT_HEIGHT);
}
#endif

QFontMetrics mt(nameFont);//特殊图案字体下截断字体名称/*UT000539*/
QString elidedText = mt.elidedText(itemData.strFontName, Qt::ElideRight, option.rect.width() - 120);
Expand Down Expand Up @@ -165,6 +180,14 @@ void DFontPreviewItemDelegate::paintForegroundCollectIcon(QPainter *painter, con
QRect collectIconRealRect = QRect(option.rect.right() - COLLECT_ICON_SIZE - COLLECT_ICON_RIGHT_MARGIN,
option.rect.top() + COLLECT_ICON_TOP_MARGIN,
COLLECT_ICON_SIZE, COLLECT_ICON_SIZE);
#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::instance()->sizeMode() == DGuiApplicationHelper::SizeMode::CompactMode) {
collectIconRealRect = QRect(option.rect.right() - COLLECT_ICON_SIZE - COLLECT_ICON_RIGHT_MARGIN,
option.rect.top() + COLLECT_ICON_TOP_COMPACT_MARGIN,
COLLECT_ICON_SIZE, COLLECT_ICON_SIZE);
}
#endif


// 获取系统活动色
QColor bgColor = Dtk::Gui::DGuiApplicationHelper::instance()->applicationPalette().highlight().color();
Expand Down Expand Up @@ -208,6 +231,13 @@ QRect DFontPreviewItemDelegate::adjustPreviewRect(const QRect bgRect) const
int fontRectWidth = bgRect.width() - FONT_PREVIEW_LEFT_MARGIN - FONT_PREVIEW_RIGHT_MARGIN;
fontPreviewRect = QRect(bgRect.x() + FONT_PREVIEW_LEFT_MARGIN, bgRect.y() + FONT_PREVIEW_TOP_MARGIN,
fontRectWidth, bgRect.height() - FONT_PREVIEW_TOP_MARGIN - FONT_PREVIEW_BOTTOM_MARGIN);

#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::instance()->sizeMode() == DGuiApplicationHelper::SizeMode::CompactMode) {
fontPreviewRect = QRect(bgRect.x() + FONT_PREVIEW_LEFT_MARGIN, bgRect.y() + FONT_PREVIEW_TOP_COMPACT_MARGIN,
fontRectWidth, bgRect.height() - FONT_PREVIEW_TOP_COMPACT_MARGIN - FONT_PREVIEW_BOTTOM_COMPACT_MARGIN);
}
#endif
return fontPreviewRect;
}

Expand Down Expand Up @@ -474,6 +504,12 @@ QSize DFontPreviewItemDelegate::sizeHint(const QStyleOptionViewItem &option, con
int fontSize = (false == index.data(FontSizeRole).isNull()) ? index.data(FontSizeRole).toInt() : FTM_DEFAULT_PREVIEW_FONTSIZE;

int itemHeight = FTM_PREVIEW_ITEM_HEIGHT;
#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::instance()->sizeMode() == DGuiApplicationHelper::SizeMode::CompactMode) {
itemHeight = FTM_PREVIEW_ITEM_COMPACT_HEIGHT;
}
#endif

if (fontSize > 30) {
itemHeight += static_cast<int>(((fontSize - 30) + 1) * 1.5);
}
Expand Down
4 changes: 2 additions & 2 deletions deepin-font-manager/views/dfdeletedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ QLayout *DFDeleteDialog::initBottomButtons()
layout->setContentsMargins(0, 0, 0, 0);

m_cancelBtn = new DPushButton(this);
m_cancelBtn->setFixedSize(170, 36);
m_cancelBtn->setFixedWidth(170);
m_cancelBtn->setText(DApplication::translate("DFDeleteDialog", "Cancel", "button"));

m_confirmBtn = new DWarningButton(this);
m_confirmBtn->setFixedSize(170, 36);
m_confirmBtn->setFixedWidth(170);
m_confirmBtn->setText(DApplication::translate("DeleteConfirmDailog", "Delete", "button"));

DVerticalLine *verticalSplite = new DVerticalLine(this);
Expand Down
15 changes: 4 additions & 11 deletions deepin-font-manager/views/dfinstallerrordialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,20 +273,13 @@ void DFInstallErrorDialog::initInstallErrorFontViews()
QFont btnFont = font();
//btnFont.setPixelSize(14);

m_quitInstallBtn = new DPushButton;
m_quitInstallBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_quitInstallBtn = new DPushButton(this);
m_quitInstallBtn->setFont(btnFont);
// m_quitInstallBtn->setFixedSize(204, btnHeight);
m_quitInstallBtn->setMinimumSize(204, btnHeight);
m_quitInstallBtn->setMaximumSize(204, btnHeight + 5);
m_quitInstallBtn->setMinimumWidth(204);
m_quitInstallBtn->setText(DApplication::translate("ExceptionWindow", "Exit", "button"));

m_continueInstallBtn = new DSuggestButton;
m_continueInstallBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

// m_continueInstallBtn->setFixedSize(204, btnHeight);
m_continueInstallBtn->setMinimumSize(204, btnHeight);
m_continueInstallBtn->setMaximumSize(204, btnHeight + 5);
m_continueInstallBtn = new DSuggestButton(this);
m_continueInstallBtn->setMinimumWidth(204);
m_continueInstallBtn->setFont(btnFont);
m_continueInstallBtn->setText(DApplication::translate("ExceptionWindow", "Continue", "button"));

Expand Down
22 changes: 14 additions & 8 deletions deepin-font-manager/views/dfinstallerrorlistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ void DFInstallErrorListDelegate::drawCheckBox(QPainter *painter, DFInstallErrorI
checkBoxOption.state |= QStyle::State_Off;
}

int checkBoxSize = 20;
int checkBoxSize = 16;
DCheckBox checkBox;
QRect checkboxRect = QRect(bgRect.left() + 10, bgRect.top() + 14 + 2, checkBoxSize - 4, checkBoxSize - 4);
QRect checkboxRect = QRect(bgRect.left() + 10, bgRect.top() + (bgRect.height() - checkBoxSize) / 2, checkBoxSize, checkBoxSize);
checkBoxOption.rect = checkboxRect;
DApplication::style()->drawPrimitive(QStyle::PE_IndicatorCheckBox,
&checkBoxOption,
Expand All @@ -82,9 +82,9 @@ void DFInstallErrorListDelegate::drawCheckBox(QPainter *painter, DFInstallErrorI
*************************************************************************/
void DFInstallErrorListDelegate::drawCheckBoxIcon(QPainter *painter, QRect bgRect) const
{
int checkBoxSize = 20;
QRect checkboxRect = QRect(bgRect.left() + 5, bgRect.top() + 10, checkBoxSize + 10, checkBoxSize + 10);
// QRect checkboxRect = QRect(bgRect.left() + 0, bgRect.top(), checkBoxSize - 4, checkBoxSize - 4);
int checkBoxSize = 30;
QRect checkboxRect = QRect(bgRect.left() + 5, bgRect.top() + (bgRect.height() - checkBoxSize) / 2, checkBoxSize, checkBoxSize);

DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType();
if (themeType == DGuiApplicationHelper::LightType) {
QImage checkBox("://checkbox_unchecked_light.svg");
Expand Down Expand Up @@ -129,10 +129,12 @@ void DFInstallErrorListDelegate::drawFontName(QPainter *painter, const QStyleOpt
m_StatusWidth = statusLabelMaxWidth;
int m_NameWidth = fontMetric.width(strFontFileName);

int fontFileNameRectHeight = 30;
QRect fontFileNameRect = QRect(bgRect.left() + fontNameLeft,
checkboxRect.top() - 5,
bgRect.top() + (bgRect.height() - fontFileNameRectHeight) / 2,
bgRect.width() - fontNameLeft - m_StatusWidth,
checkboxRect.height() + 15);
fontFileNameRectHeight);

QString elidedFontFileNameText;

if (m_NameWidth + m_StatusWidth < 360) {
Expand Down Expand Up @@ -434,7 +436,11 @@ QSize DFInstallErrorListDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
Q_UNUSED(index)

#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::instance()->sizeMode() == DGuiApplicationHelper::SizeMode::CompactMode) {
return QSize(option.rect.width(), 40);
}
#endif
return QSize(option.rect.width(), 48);
}

Expand Down
42 changes: 30 additions & 12 deletions deepin-font-manager/views/dfontmgrmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ void DFontMgrMainWindow::initConnections()
connect(m_fontPreviewListView, &DFontPreviewListView::deleteFinished, this, &DFontMgrMainWindow::setDeleteFinish);
connect(m_fontPreviewListView, &DFontPreviewListView::loadUserAddFont, this, &DFontMgrMainWindow::afterAllStartup);
connect(m_fontPreviewListView, &DFontPreviewListView::signalHandleDisableTTC, this, &DFontMgrMainWindow::onHandleDisableTTC);

#ifdef DTKWIDGET_CLASS_DSizeMode
connect(DGuiApplicationHelper::instance(),&DGuiApplicationHelper::sizeModeChanged,this, &DFontMgrMainWindow::slotSizeModeChanged);
#endif
}

/*************************************************************************
Expand Down Expand Up @@ -590,8 +594,6 @@ void DFontMgrMainWindow::initTileBar()
d->toolBarMenu = DFontMenuManager::getInstance()->createToolBarSettingsMenu();
titlebar()->setMenu(d->toolBarMenu);
titlebar()->setContentsMargins(0, 0, 0, 0);

titlebar()->setFixedHeight(FTM_TITLE_FIXED_HEIGHT);
}

/*************************************************************************
Expand All @@ -611,23 +613,21 @@ void DFontMgrMainWindow::initTileFrame()

//Action area add a extra space
d->titleActionArea = new QWidget(this);
d->titleActionArea->setFixedSize(QSize(FTM_TITLE_FIXED_WIDTH, FTM_TITLE_FIXED_HEIGHT));

QHBoxLayout *titleActionAreaLayout = new QHBoxLayout(d->titleActionArea);
titleActionAreaLayout->setSpacing(0);
titleActionAreaLayout->setContentsMargins(0, 0, 0, 0);
titleActionAreaLayout->setContentsMargins(5, 0, 0, 0);

// Add Font
d->addFontButton = new DIconButton(DStyle::StandardPixmap::SP_IncreaseElement, this);
d->addFontButton->setFixedSize(QSize(FTM_ADDBUTTON_PATAM, FTM_ADDBUTTON_PATAM));
d->addFontButton->setFlat(false);

titleActionAreaLayout->addWidget(d->addFontButton);

// Search font
d->searchFontEdit = new DSearchEdit(this);
DFontSizeManager::instance()->bind(d->searchFontEdit, DFontSizeManager::T6);
d->searchFontEdit->setFixedSize(QSize(FTM_SEARCH_BAR_W, FTM_SEARCH_BAR_H));
d->searchFontEdit->setFixedWidth(FTM_SEARCH_BAR_W);
d->searchFontEdit->setPlaceHolder(DApplication::translate("SearchBar", "Search"));

titlebar()->addWidget(d->titleActionArea, Qt::AlignLeft | Qt::AlignVCenter);
Expand Down Expand Up @@ -1162,7 +1162,7 @@ void DFontMgrMainWindow::installFontFromSys(const QStringList &files)
emit m_signalManager->installDuringPopErrorDialog(reduceSameFiles);
} else if (m_fIsInstalling || m_fontLoadingSpinner->isVisible()) {
qDebug() << "Font is installing , save installation task and reinstall later";
for (QString &it: reduceSameFiles) {
for (QString &it : reduceSameFiles) {
if (!m_waitForInstall.contains(it)) {
m_waitForInstall.append(it);
}
Expand Down Expand Up @@ -1979,6 +1979,25 @@ void DFontMgrMainWindow::onHandleDisableTTC(const QString &filePath, bool &isEna
isAapplyToAll = confirmDelDlg->getAapplyToAll();
}

#ifdef DTKWIDGET_CLASS_DSizeMode
void DFontMgrMainWindow::slotSizeModeChanged(DGuiApplicationHelper::SizeMode sizeMode)
{
// update search edit position
D_D(DFontMgrMainWindow);
int w = this->rect().width();
QPoint point = d->searchFontEdit->pos();
int x = point.x();
if (w >= 760) {
x = (w - FTM_SEARCH_BAR_W) / 2;
} else {
x = (760 - FTM_SEARCH_BAR_W) / 2 - (760 - w);
}
point.setX(x);
point.setY((titlebar()->height() - d->searchFontEdit->height()) / 2);
d->searchFontEdit->move(point);
}
#endif

/*************************************************************************
<Function> delCurrentFont
<Description> 字体删除处理函数
Expand Down Expand Up @@ -2175,14 +2194,13 @@ void DFontMgrMainWindow::resizeEvent(QResizeEvent *event)
int w = event->size().width();
QPoint point = d->searchFontEdit->pos();
int x = point.x();
if(w >= 760){
if (w >= 760) {
x = (w - FTM_SEARCH_BAR_W) / 2;
}
else {
} else {
x = (760 - FTM_SEARCH_BAR_W) / 2 - (760 - w);
}
point.setX(x);
point.setY(3); // titlebar()->size(): 50px searchFontEdit->size(): 44
point.setY((titlebar()->height() - d->searchFontEdit->height()) / 2); // titlebar()->size(): 50px searchFontEdit->size(): 44
d->searchFontEdit->move(point);

DMainWindow::resizeEvent(event);
Expand Down Expand Up @@ -2658,7 +2676,7 @@ bool DFontMgrMainWindow::eventFilter(QObject *obj, QEvent *event)
D_D(DFontMgrMainWindow);
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = dynamic_cast<QKeyEvent *>(event);
if (keyEvent->key() == Qt::Key_Tab) {
if (keyEvent->key() == Qt::Key_Tab) {
if (obj == d->searchFontEdit->lineEdit()) {
setNextTabFocus(obj);
//下个控件为titlebar时需要多执行一次keyPressEvent
Expand Down
5 changes: 5 additions & 0 deletions deepin-font-manager/views/dfontmgrmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <DHorizontalLine>
#include <DMainWindow>
#include <DFrame>
#include <DGuiApplicationHelper>

#include <QSettings>
#include <QDir>
Expand Down Expand Up @@ -318,6 +319,10 @@ public slots:
void onFontManagerFinished();
//禁用/启用ttc里的某个字体
void onHandleDisableTTC(const QString &filePath, bool &isEnable, bool &isConfirm, bool &isAapplyToAll);
#ifdef DTKWIDGET_CLASS_DSizeMode
//紧凑模式切换
void slotSizeModeChanged(DGuiApplicationHelper::SizeMode sizeMode);
#endif

protected:
DFontPreviewListView *m_fontPreviewListView;
Expand Down
11 changes: 11 additions & 0 deletions deepin-font-manager/views/dsplitlistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ QSize DNoFocusDelegate::sizeHint(const QStyleOptionViewItem &option,
Q_UNUSED(index)

int rowIndex = index.row();

#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::instance()->sizeMode() == DGuiApplicationHelper::SizeMode::CompactMode) {
if (FTM_SPLIT_LINE_INDEX == rowIndex) {
return QSize(option.rect.width(), 20);
} else {
return QSize(option.rect.width(), 24);
}
}
#endif

if (FTM_SPLIT_LINE_INDEX == rowIndex) {
return QSize(option.rect.width(), 24);
} else {
Expand Down
1 change: 1 addition & 0 deletions libdeepin-font-manager/dfontpreviewitemdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define FTM_DEFAULT_PREVIEW_DIGIT_TEXT QString("0123456789")
#define FTM_DEFAULT_PREVIEW_FONTSIZE 30
#define FTM_PREVIEW_ITEM_HEIGHT (72+2+10)
#define FTM_PREVIEW_ITEM_COMPACT_HEIGHT (48+2+10)

#define FONT_TTF QString("TrueType")
#define FONT_OTF QString("OpenType")
Expand Down

0 comments on commit 956acf5

Please sign in to comment.