Skip to content

Commit

Permalink
fix: adapt compact mode
Browse files Browse the repository at this point in the history
  • Loading branch information
starhcq committed Nov 7, 2024
1 parent 0c34cda commit c8cb6cb
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 5 deletions.
45 changes: 43 additions & 2 deletions src/deepin-draw/widgets/dzoommenucombobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
#include <QKeyEvent>
#include <QComboBox>

const int FLOATING_SIZE = 32;
const int FLOATING_SIZE_COMPACT = 22;
const int ICON_SIZE = 24;
const int ICON_SIZE_COMPACT = 18;
const int BTN_HEIGHT = 36;
const int BTN_HEIGHT_COMPACT = 24;
DZoomMenuComboBox::DZoomMenuComboBox(DWidget *parent):
DWidget(parent)
, m_floatingSize(32)
, m_floatingSize(FLOATING_SIZE)
, m_currentIndex(-1)
{
initUI();
Expand Down Expand Up @@ -163,6 +169,36 @@ void DZoomMenuComboBox::slotActionToggled(QAction *action)
}
}

void DZoomMenuComboBox::updateSizeMode()
{
int nIconSize = ICON_SIZE;

Check warning on line 174 in src/deepin-draw/widgets/dzoommenucombobox.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Redundant initialization for 'nIconSize'. The initialized value is overwritten before it is read.

Check warning on line 174 in src/deepin-draw/widgets/dzoommenucombobox.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Redundant initialization for 'nIconSize'. The initialized value is overwritten before it is read.
int nBtnHeight = BTN_HEIGHT;

Check warning on line 175 in src/deepin-draw/widgets/dzoommenucombobox.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Redundant initialization for 'nBtnHeight'. The initialized value is overwritten before it is read.

Check warning on line 175 in src/deepin-draw/widgets/dzoommenucombobox.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Redundant initialization for 'nBtnHeight'. The initialized value is overwritten before it is read.
#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::isCompactMode()) {
m_floatingSize = FLOATING_SIZE_COMPACT;
nIconSize = ICON_SIZE_COMPACT;
nBtnHeight = BTN_HEIGHT_COMPACT;
} else {
m_floatingSize = FLOATING_SIZE;
nIconSize = ICON_SIZE;
nBtnHeight = BTN_HEIGHT;
}
#else
m_floatingSize = FLOATINGSIZE;
#endif

if (m_increaseBtn) {
m_increaseBtn->setFixedSize(QSize(m_floatingSize, m_floatingSize));
}
if (m_reduceBtn) {
m_reduceBtn->setFixedSize(QSize(m_floatingSize, m_floatingSize));
}
if (m_btn) {
m_btn->setIconSize(QSize(nIconSize, nIconSize));
m_btn->setFixedSize(QSize(nBtnHeight, nBtnHeight));
}
}

bool DZoomMenuComboBox::eventFilter(QObject *o, QEvent *e)
{
if (o == m_menu) {
Expand Down Expand Up @@ -220,7 +256,7 @@ void DZoomMenuComboBox::initUI()
m_reduceBtn->setIconSize(QSize(16, 16));
m_increaseBtn->setIconSize(QSize(16, 16));
m_btn->setIconSize(QSize(24, 24));
m_label->setFixedSize(QSize(50, 24));
m_label->setFixedSize(QSize(40, 24));

connect(m_reduceBtn, &DFloatingButton::clicked, this, [ = ]() {
emit signalLeftBtnClicked();
Expand All @@ -244,4 +280,9 @@ void DZoomMenuComboBox::initConnection()
connect(m_menu, &QMenu::aboutToHide, this, [ = ]() {
this->setFocus();
});
#ifdef DTKWIDGET_CLASS_DSizeMode
// 紧凑模式信号处理
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, &DZoomMenuComboBox::updateSizeMode);
updateSizeMode();
#endif
}
5 changes: 5 additions & 0 deletions src/deepin-draw/widgets/dzoommenucombobox.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ protected slots:
* @bref: slotActionToggled 处理子选项点击事件
*/
void slotActionToggled(QAction *action);
private slots:
/**
* @brief 根据布局模式(紧凑)变更更新界面布局
*/
void updateSizeMode();
protected:
bool eventFilter(QObject *o, QEvent *e) override;
private:
Expand Down
25 changes: 25 additions & 0 deletions src/deepin-draw/widgets/toptoolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
const int MINHEIGHT = 38;
const int Text_Size = 14;

const int BTN_HEIGHT = 35;
const int BTN_HEIGHT_COMPACT = 23;
TopTilte::TopTilte(DWidget *parent)
: DFrame(parent)
{
Expand Down Expand Up @@ -88,6 +90,12 @@ void TopTilte::initUI()
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

connect(m_editDrawBorad, &QToolButton::toggled, this, &TopTilte::editProportion);

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

void TopTilte::initComboBox()
Expand Down Expand Up @@ -313,6 +321,23 @@ void TopTilte::slotMenuShow()
{
}

void TopTilte::updateSizeMode()
{
int nHeight= BTN_HEIGHT;

Check warning on line 326 in src/deepin-draw/widgets/toptoolbar.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Redundant initialization for 'nHeight'. The initialized value is overwritten before it is read.

Check warning on line 326 in src/deepin-draw/widgets/toptoolbar.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Redundant initialization for 'nHeight'. The initialized value is overwritten before it is read.
#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::isCompactMode())
nHeight = BTN_HEIGHT_COMPACT;
else
nHeight = BTN_HEIGHT;
#else
nBtnSize = BTN_HEIGHT;
#endif

if (m_editDrawBorad) {
m_editDrawBorad->setFixedSize(QSize(nHeight, nHeight));
}
}

DMenu *TopTilte::mainMenu()
{
return m_mainMenu;
Expand Down
5 changes: 4 additions & 1 deletion src/deepin-draw/widgets/toptoolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ private slots:
* @brief slotMenuShow 显示主菜单触发函数
*/
void slotMenuShow();

/**
* @brief 根据布局模式(紧凑)变更更新界面布局
*/
void updateSizeMode();
protected:
void resizeEvent(QResizeEvent *event) override;
virtual void enterEvent(QEvent *event) override; //进入QWidget瞬间事件
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const int PANEL_WIDTH = 334;
const int ORIGIN_HEIGHT = 56;
const int EXPAND_HEIGHT = 475;
const int RADIUS = 8;
const QSize COLOR_BORDER_SIZE = QSize(24, 24);
const QSize COLOR_BORDER_SIZE = QSize(36, 36);
const QColor PANEL_TITLE_COLOR = QColor(0, 0, 0);
const qreal PANEL_TITLE_COLOR_ALPHA = 0.4;
const QColor PANEL_BACK_GROUND = QColor("#000000");
Expand Down Expand Up @@ -364,7 +364,7 @@ CColorButton::CColorButton(const QColor &color, QWidget *parent)
: QPushButton(parent)
, m_color(color)
{
resize(COLOR_BORDER_SIZE);
setFixedSize(COLOR_BORDER_SIZE);
setCheckable(true);

connect(this, &CColorButton::clicked, this, [ = ]() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ const QColor PICK_TITLE_COLOR = QColor(0, 0, 0);
const qreal PICK_TITLE_COLOR_ALPHA = 0.4;
const int CONST_LABEL_HEIGHT = 36;
const int OFFSET_EXPEND_HEADER = 15;
const int BUTTON_SIZE = 36;
const int BUTTON_SIZE_COMPACT = 24;
PickColorWidget::PickColorWidget(QWidget *parent, bool bUseOldUi)
: QWidget(parent)
, m_bUseOldUI(bUseOldUi)
{
if (bUseOldUi) {
initOldUi();
Expand Down Expand Up @@ -211,6 +214,12 @@ void PickColorWidget::initConnects()
}
}
});

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

void PickColorWidget::initOldUi()
Expand Down Expand Up @@ -387,3 +396,24 @@ void PickColorWidget::hideEvent(QHideEvent *event)
QWidget::hideEvent(event);
}

void PickColorWidget::updateSizeMode()
{
int nBtnSize = BUTTON_SIZE;

Check warning on line 401 in src/drawboard/drawboard/widgets/colorWidget/private/cpickcolorwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Redundant initialization for 'nBtnSize'. The initialized value is overwritten before it is read.

Check warning on line 401 in src/drawboard/drawboard/widgets/colorWidget/private/cpickcolorwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Redundant initialization for 'nBtnSize'. The initialized value is overwritten before it is read.

Check warning on line 401 in src/drawboard/drawboard/widgets/colorWidget/private/cpickcolorwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Redundant initialization for 'nBtnSize'. The initialized value is overwritten before it is read.

Check warning on line 401 in src/drawboard/drawboard/widgets/colorWidget/private/cpickcolorwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Redundant initialization for 'nBtnSize'. The initialized value is overwritten before it is read.
#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::isCompactMode())
nBtnSize = BUTTON_SIZE_COMPACT;
else
nBtnSize = BUTTON_SIZE;
#else
nBtnSize = BUTTON_SIZE;
#endif

if (m_picker) {
m_picker->setFixedSize(QSize(55, nBtnSize));
if (m_bUseOldUI)
m_picker->setIconSize(QSize(15,15));
else
m_picker->setIconSize(QSize(nBtnSize, nBtnSize));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class DRAWLIB_EXPORT PickColorWidget : public QWidget
void previewedColorChanged(const QColor &color);
void heightChanged();

private slots:
/**
* @brief 根据布局模式(紧凑)变更更新界面布局
*/
void updateSizeMode();
private:
/**
* @brief updateColor 更新颜色
Expand All @@ -86,6 +91,7 @@ class DRAWLIB_EXPORT PickColorWidget : public QWidget
ColorPickerInterface *m_cp;
CAlphaControlWidget *m_alphaControlWidget;
QColor curColor;
bool m_bUseOldUI = false;
};

#endif // CPICKCOLORWIDGET_H
28 changes: 28 additions & 0 deletions src/drawboard/drawboard/widgets/dialog/cexportimagedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@
#include <QApplication>
#include <QLineEdit>

#ifdef USE_DTK
#include <DGuiApplicationHelper>
DGUI_USE_NAMESPACE
#endif

#define NAME_MAX 255
const QSize DIALOG_SIZE = QSize(380, 280);
const QSize LINE_EDIT_SIZE = QSize(250, 35);
const QSize LINE_EDIT_SIZE_COMPACT = QSize(250, 23);
const QSize TIP_LABEL_MAXSIZE = QSize(103, 12);
const int MAX_PERCENT_VALUE = 100;
const int MIN_PERCENT_VALUE = 0;
Expand Down Expand Up @@ -261,6 +267,11 @@ void CExportImageDialog::initConnection()
});
#endif

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

void CExportImageDialog::slotOnSavePathChange(int index)
Expand Down Expand Up @@ -342,6 +353,23 @@ void CExportImageDialog::slotOnQualityChanged(int value)
m_quality = value;
}

void CExportImageDialog::updateSizeMode()
{
int nHeight= LINE_EDIT_SIZE.height();

Check warning on line 358 in src/drawboard/drawboard/widgets/dialog/cexportimagedialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Redundant initialization for 'nHeight'. The initialized value is overwritten before it is read.

Check warning on line 358 in src/drawboard/drawboard/widgets/dialog/cexportimagedialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Redundant initialization for 'nHeight'. The initialized value is overwritten before it is read.
#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::isCompactMode())
nHeight = LINE_EDIT_SIZE_COMPACT.height();
else
nHeight = LINE_EDIT_SIZE.height();
#else
nBtnSize = LINE_EDIT_SIZE.height();;
#endif

if (m_fileNameEdit) {
m_fileNameEdit->setFixedHeight(nHeight);
}
}

void CExportImageDialog::showDirChoseDialog()
{
QFileDialog dialog(this);
Expand Down
4 changes: 4 additions & 0 deletions src/drawboard/drawboard/widgets/dialog/cexportimagedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ private slots:
void slotOnFormatChange(int index);
int execCheckFile(const QString &text);
void slotOnQualityChanged(int value);
/**
* @brief 根据布局模式(紧凑)变更更新界面布局
*/
void updateSizeMode();
signals:
void signalDoSave(QString);

Expand Down

0 comments on commit c8cb6cb

Please sign in to comment.