Skip to content

Commit

Permalink
feat: 【UI】 Adapt compact mode
Browse files Browse the repository at this point in the history
 【UI】 Adapt compact mode

Log: 【UI】 Adapt compact mode
Task: https://pms.uniontech.com/task-view-292059.html
  • Loading branch information
starhcq committed Sep 20, 2023
1 parent 18f1c0d commit 1beb400
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 50 deletions.
6 changes: 3 additions & 3 deletions src/drawshape/drawTools/cpentool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void CPenTool::registerAttributionWidgets()
auto streakBeginStyle = new CComBoxSettingWgt(tr("Start"));
auto pStreakStartComboBox = new QComboBox;
setWgtAccesibleName(pStreakStartComboBox, "Line start style combox");
pStreakStartComboBox->setFixedSize(QSize(90, 36));
pStreakStartComboBox->setFixedWidth(90);
pStreakStartComboBox->setIconSize(QSize(34, 20));
pStreakStartComboBox->setFocusPolicy(Qt::NoFocus);

Expand Down Expand Up @@ -108,7 +108,7 @@ void CPenTool::registerAttributionWidgets()
streakEndStyle->setAttribution(EStreakEndStyle);
auto pStreakEndComboBox = new QComboBox;
setWgtAccesibleName(pStreakEndComboBox, "Line end style combox");
pStreakEndComboBox->setFixedSize(QSize(90, 36));
pStreakEndComboBox->setFixedWidth(90);
pStreakEndComboBox->setIconSize(QSize(34, 20));
pStreakEndComboBox->setFocusPolicy(Qt::NoFocus);

Expand Down Expand Up @@ -143,7 +143,7 @@ void CPenTool::registerAttributionWidgets()

m_pPenStyleComboBox->view()->installEventFilter(this);

m_pPenStyleComboBox->setFixedSize(QSize(230, 36));
m_pPenStyleComboBox->setFixedWidth(230);;
m_pPenStyleComboBox->setIconSize(QSize(24, 20));
m_pPenStyleComboBox->setFocusPolicy(Qt::NoFocus);

Expand Down
31 changes: 27 additions & 4 deletions src/drawshape/drawTools/cpicturetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "cgraphicslayer.h"
#include "filehander.h"

const int BUTTON_NORMAL = 38;
const int BUTTON_COMPACT = 26;

class CPictureTool::CPictureTool_private
{
Expand Down Expand Up @@ -90,7 +92,6 @@ void CPictureTool::registerAttributionWidgets()

auto m_rightRotateBtn = new QPushButton;
m_rightRotateBtn->setObjectName("PicRightRotateBtn");
m_rightRotateBtn->setMaximumSize(QSize(38, 38));
m_rightRotateBtn->setIcon(QIcon::fromTheme("ddc_clockwise rotation_normal"));
m_rightRotateBtn->setIconSize(QSize(48, 48));
m_rightRotateBtn->setToolTip(tr("Rotate 90° CW"));
Expand All @@ -107,7 +108,6 @@ void CPictureTool::registerAttributionWidgets()

auto m_flipHBtn = new QPushButton;
m_flipHBtn->setObjectName("PicFlipHBtn");
m_flipHBtn->setMaximumSize(QSize(38, 38));
m_flipHBtn->setIcon(QIcon::fromTheme("ddc_flip horizontal_normal"));
m_flipHBtn->setIconSize(QSize(48, 48));
m_flipHBtn->setToolTip(tr("Flip horizontally"));
Expand All @@ -127,7 +127,6 @@ void CPictureTool::registerAttributionWidgets()

auto m_flipVBtn = new QPushButton;
m_flipVBtn->setObjectName("PicFlipVBtn");
m_flipVBtn->setMaximumSize(QSize(38, 38));
m_flipVBtn->setIcon(QIcon::fromTheme("ddc_flip vertical_normal"));
m_flipVBtn->setIconSize(QSize(48, 48));
m_flipVBtn->setToolTip(tr("Flip vertically"));
Expand All @@ -146,7 +145,6 @@ void CPictureTool::registerAttributionWidgets()

auto m_flipAdjustment = new QPushButton;
m_flipAdjustment->setObjectName("PicFlipAdjustmentBtn");
m_flipAdjustment->setMaximumSize(QSize(38, 38));
m_flipAdjustment->setIcon(QIcon::fromTheme("ddc_flip_adjustment_normal"));
m_flipAdjustment->setIconSize(QSize(48, 48));
m_flipAdjustment->setToolTip(tr("Auto fit"));
Expand Down Expand Up @@ -175,6 +173,31 @@ void CPictureTool::registerAttributionWidgets()
}
});


int btnSize = BUTTON_NORMAL;
#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::instance()->sizeMode() == DGuiApplicationHelper::CompactMode)
btnSize = BUTTON_COMPACT;

connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, [=](DGuiApplicationHelper::SizeMode sizeMode) {
int nBtnSize = 0;
if (sizeMode == DGuiApplicationHelper::NormalMode)
nBtnSize = BUTTON_NORMAL;
else
nBtnSize = BUTTON_COMPACT;
m_leftRotateBtn->setMaximumSize(QSize(nBtnSize, nBtnSize));
m_rightRotateBtn->setMaximumSize(QSize(nBtnSize, nBtnSize));
m_flipHBtn->setMaximumSize(QSize(nBtnSize, nBtnSize));
m_flipVBtn->setMaximumSize(QSize(nBtnSize, nBtnSize));
m_flipAdjustment->setMaximumSize(QSize(nBtnSize, nBtnSize));
});
#endif
m_leftRotateBtn->setMaximumSize(QSize(btnSize, btnSize));
m_rightRotateBtn->setMaximumSize(QSize(btnSize, btnSize));
m_flipHBtn->setMaximumSize(QSize(btnSize, btnSize));
m_flipVBtn->setMaximumSize(QSize(btnSize, btnSize));
m_flipAdjustment->setMaximumSize(QSize(btnSize, btnSize));

drawBoard()->attributionWidget()->installComAttributeWgt(EImageAdaptScene, m_flipAdjustment, true);
}
CPictureTool::~CPictureTool()
Expand Down
12 changes: 1 addition & 11 deletions src/frame/AttributesWidgets/private/blurwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,8 @@ void BlurWidget::initUI()

penLabel->setText(tr("Type"));

QFont ft;
ft.setPixelSize(TEXT_SIZE);
penLabel->setFont(ft);

auto m_blurBtn = new DToolButton(this);
setWgtAccesibleName(m_blurBtn, "Blur type button");
m_blurBtn->setMaximumSize(QSize(38, 38));
m_blurBtn->setIconSize(QSize(38, 38));
m_blurBtn->setToolTip(tr("Blur"));
m_blurBtn->setCheckable(true);
Expand All @@ -102,7 +97,6 @@ void BlurWidget::initUI()

auto m_masicBtn = new DToolButton(this);
setWgtAccesibleName(m_masicBtn, "Masic type button");
m_masicBtn->setMaximumSize(QSize(38, 38));
m_masicBtn->setIconSize(QSize(38, 38));
m_masicBtn->setToolTip(tr("Mosaic"));
m_masicBtn->setCheckable(true);
Expand All @@ -120,15 +114,13 @@ void BlurWidget::initUI()

connect(m_TypeButtons, QOverload<int, bool>::of(&QButtonGroup::buttonToggled), this, [ = ](int tp, bool checked) {
if (checked) {
// emit blurTypeChanged(EBlurEffect(tp));
emit blurEffectChanged(getEffect());
}
});

DLabel *penWidthLabel = new DLabel(this);
penWidthLabel->setObjectName("Width");
penWidthLabel->setText(tr("Width"));
penWidthLabel->setFont(ft);

m_spinboxForLineWidth = new CSpinBox(this);
m_spinboxForLineWidth->setObjectName("BlurPenWidth");
Expand All @@ -140,22 +132,20 @@ void BlurWidget::initUI()

if (!Application::isTabletSystemEnvir())
m_spinboxForLineWidth->setFixedWidth(90);
m_spinboxForLineWidth->setMaximumHeight(36);
m_spinboxForLineWidth->setSuffix("px");
m_spinboxForLineWidth->lineEdit()->setClearButtonEnabled(false);
m_spinboxForLineWidth->setFont(ft);

QWidget *groupWidget = new QWidget(this);
QHBoxLayout *groupLayout = new QHBoxLayout(this);
groupLayout->addWidget(penWidthLabel);
groupLayout->setSpacing(10);
groupLayout->addWidget(m_spinboxForLineWidth);
groupWidget->setLayout(groupLayout);


m_pLineWidthLabel = new DLabel(this);
m_pLineWidthLabel->setObjectName("Width Label");
m_pLineWidthLabel->setText(QString("%1px").arg(m_spinboxForLineWidth->value()));
m_pLineWidthLabel->setFont(ft);
m_pLineWidthLabel->setFixedWidth(60);
m_pLineWidthLabel->hide();

Expand Down
67 changes: 48 additions & 19 deletions src/frame/AttributesWidgets/private/ccutwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@

DGUI_USE_NAMESPACE

const int BTN_SPACING = 6;
const int SEPARATE_SPACING = 5;
const int PUSHBUTTON_FONT_SIZE = 12;
const int TEXT_SIZE = 12;

const int TOOL_BUTTON_NORMAL = 38;
const int TOOL_BUTTON_COMPACT = 26;
const int ICON_SIZE_NORMAL = 48;
const int ICON_SIZE_COMPACT = 36;
CCutWidget::CCutWidget(DWidget *parent)
: DrawAttribution::CAttriBaseOverallWgt(parent)
{
Expand Down Expand Up @@ -345,15 +346,6 @@ void CCutWidget::initUI()
m_originalBtn->setFont(pushBtnFont);
_allWgts << m_originalBtn;

//修复切换维语和藏语后,裁剪模式按钮大小不一致
int unifyHeight = m_originalBtn->height() + 8;
m_scaleBtn1_1->setFixedHeight(unifyHeight);
m_scaleBtn2_3->setFixedHeight(unifyHeight);
m_scaleBtn8_5->setFixedHeight(unifyHeight);
m_scaleBtn16_9->setFixedHeight(unifyHeight);
m_freeBtn->setFixedHeight(unifyHeight);
m_originalBtn->setFixedHeight(unifyHeight);

m_scaleBtn1_1->setCheckable(true);
m_scaleBtn2_3->setCheckable(true);
m_scaleBtn8_5->setCheckable(true);
Expand All @@ -368,23 +360,60 @@ void CCutWidget::initUI()
m_doneBtn = new ToolButton(this, BUTTON_STYLE);
qobject_cast<ToolButton *>(m_doneBtn)->setShowText(false);
setWgtAccesibleName(m_doneBtn, "Cut done pushbutton");
//m_doneBtn->setFixedSize(QSize(38, 38));
m_doneBtn->setMaximumHeight(unifyHeight);
m_doneBtn->setIcon(QIcon::fromTheme("ddc_cutting_normal"));
m_doneBtn->setIconSize(QSize(48, 48));
m_doneBtn->setText(QObject::tr("OK"));


//m_cancelBtn = new QPushButton(this);
m_cancelBtn = new ToolButton(this, BUTTON_STYLE);
qobject_cast<ToolButton *>(m_cancelBtn)->setShowText(false);
setWgtAccesibleName(m_cancelBtn, "Cut cancel pushbutton");
//m_cancelBtn->setFixedSize(QSize(38, 38));
m_cancelBtn->setMaximumHeight(unifyHeight);
m_cancelBtn->setIcon(QIcon::fromTheme("ddc_cancel_normal"));
m_cancelBtn->setIconSize(QSize(48, 48));
m_cancelBtn->setText(QObject::tr("Cancel"));


//修复切换维语和藏语后,裁剪模式按钮大小不一致
int unifyHeight = TOOL_BUTTON_NORMAL;
int iconSize = ICON_SIZE_NORMAL;
#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::instance()->sizeMode() == DGuiApplicationHelper::CompactMode) {
unifyHeight = TOOL_BUTTON_COMPACT;
iconSize = ICON_SIZE_COMPACT;
}

connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, [=](DGuiApplicationHelper::SizeMode sizeMode) {
int nHeight = 0;
int nIconSize = 0;
if (sizeMode == DGuiApplicationHelper::NormalMode) {
nHeight = TOOL_BUTTON_NORMAL;
nIconSize = ICON_SIZE_NORMAL;
} else {
nHeight = TOOL_BUTTON_COMPACT;
nIconSize = ICON_SIZE_COMPACT;
}

m_scaleBtn1_1->setFixedHeight(nHeight);
m_scaleBtn2_3->setFixedHeight(nHeight);
m_scaleBtn8_5->setFixedHeight(nHeight);
m_scaleBtn16_9->setFixedHeight(nHeight);
m_freeBtn->setFixedHeight(nHeight);
m_originalBtn->setFixedHeight(nHeight);
m_doneBtn->setFixedHeight(nHeight);
m_cancelBtn->setFixedHeight(nHeight );
m_doneBtn->setIconSize(QSize(nIconSize, nIconSize));
m_cancelBtn->setIconSize(QSize(nIconSize, nIconSize));
});
#endif
m_scaleBtn1_1->setFixedHeight(unifyHeight);
m_scaleBtn2_3->setFixedHeight(unifyHeight);
m_scaleBtn8_5->setFixedHeight(unifyHeight);
m_scaleBtn16_9->setFixedHeight(unifyHeight);
m_freeBtn->setFixedHeight(unifyHeight);
m_originalBtn->setFixedHeight(unifyHeight);
m_doneBtn->setFixedHeight(unifyHeight);
m_cancelBtn->setFixedHeight(unifyHeight);
m_doneBtn->setIconSize(QSize(iconSize, iconSize));
m_cancelBtn->setIconSize(QSize(iconSize, iconSize));

m_sizeWidget->setProperty(AttriWidgetReWidth, QSize(210, unifyHeight));
m_scaleBtn1_1->setProperty(WidgetAlignInVerWindow, 0);
m_scaleBtn2_3->setProperty(WidgetAlignInVerWindow, 0);
Expand Down
2 changes: 2 additions & 0 deletions src/frame/ccentralwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class DrawBoard::DrawBoard_private
//_borad->installEventFilter(_leftScrollArea);
_leftScrollArea->installEventFilter(_borad);

_toolManager->setScrollArea(_leftScrollArea);

QVBoxLayout *subVLay = new QVBoxLayout;
subVLay->setContentsMargins(0, 0, 0, 0);
subVLay->setSpacing(0);
Expand Down
53 changes: 50 additions & 3 deletions src/frame/clefttoolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ DGUI_USE_NAMESPACE

const int BTN_SPACING = 12;
bool blocked = false;
const int TOOL_MANAGER_WIDTH = 68;
const int TOOL_MANAGER_WIDTH_NORMAL = 68;
const int TOOL_MANAGER_WIDTH_COMPACT = 48;
const int TOOL_BTN_SIZE_NORMAL = 37;
const int TOOL_BTN_SIZE_COMPACT = 28;

DrawToolManager::DrawToolManager(DrawBoard *parent)
: DFrame(parent), m_drawBoard(parent)
Expand All @@ -53,6 +56,11 @@ DrawToolManager::~DrawToolManager()

}

void DrawToolManager::setScrollArea(DScrollArea *area)
{
m_scrollArea = area;
}

bool DrawToolManager::setCurrentTool(int tool, bool force)
{
return setCurrentTool(this->tool(tool), force);
Expand Down Expand Up @@ -145,6 +153,13 @@ void DrawToolManager::installTool(IDrawTool *pTool)
pTool->setParent(this);
pTool->setDrawBoard(drawBoard());
_tools.insert(pTool->getDrawToolMode(), pTool);

#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::instance()->sizeMode() == DGuiApplicationHelper::CompactMode)
button->setFixedSize(QSize(TOOL_BTN_SIZE_COMPACT, TOOL_BTN_SIZE_COMPACT));
else
button->setFixedSize(QSize(TOOL_BTN_SIZE_NORMAL, TOOL_BTN_SIZE_NORMAL));
#endif
}
}

Expand Down Expand Up @@ -189,7 +204,7 @@ void DrawToolManager::initUI()
this->setAutoFillBackground(true);

setMinimumHeight(460);//设置最小高度保证最小化显示正常
setFixedWidth(TOOL_MANAGER_WIDTH);
setFixedWidth(TOOL_MANAGER_WIDTH_NORMAL);

auto mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins(0, 0, 0, 0);
Expand All @@ -198,9 +213,41 @@ void DrawToolManager::initUI()
m_layout = new QVBoxLayout;
m_layout->setSpacing(BTN_SPACING);
m_layout->setMargin(0);
m_layout->setContentsMargins(10, 24, 0, 24);
m_layout->setContentsMargins(14, 24, 0, 24);
mainLayout->addLayout(m_layout);
mainLayout->addStretch();

#ifdef DTKWIDGET_CLASS_DSizeMode
if (DGuiApplicationHelper::instance()->sizeMode() == DGuiApplicationHelper::CompactMode) {
setFixedWidth(TOOL_MANAGER_WIDTH_COMPACT);
m_layout->setContentsMargins(9, 24, 0, 24);
}

connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, [=](DGuiApplicationHelper::SizeMode sizeMode) {
if (DGuiApplicationHelper::instance()->sizeMode() == DGuiApplicationHelper::CompactMode) {
this->setFixedWidth(TOOL_MANAGER_WIDTH_COMPACT);
if (m_scrollArea)
m_scrollArea->setFixedWidth(TOOL_MANAGER_WIDTH_COMPACT);
m_layout->setContentsMargins(9, 24, 0, 24);

if (toolButtonGroup) {
for (int i = 0; i < toolButtonGroup->buttons().size(); i++)
toolButtonGroup->buttons().at(i)->setFixedSize(QSize(TOOL_BTN_SIZE_COMPACT, TOOL_BTN_SIZE_COMPACT));
}
} else {
this->setFixedWidth(TOOL_MANAGER_WIDTH_NORMAL);
if (m_scrollArea)
m_scrollArea->setFixedWidth(TOOL_MANAGER_WIDTH_NORMAL);
m_layout->setContentsMargins(14, 24, 0, 24);

if (toolButtonGroup) {
for (int i = 0; i < toolButtonGroup->buttons().size(); i++)
toolButtonGroup->buttons().at(i)->setFixedSize(QSize(TOOL_BTN_SIZE_NORMAL, TOOL_BTN_SIZE_NORMAL));
}
}
});

#endif
}

void DrawToolManager::initDrawTools()
Expand Down
2 changes: 2 additions & 0 deletions src/frame/clefttoolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class DrawToolManager : public DFrame
explicit DrawToolManager(DrawBoard *parent = nullptr);
~DrawToolManager();

void setScrollArea(DScrollArea* area);
bool setCurrentTool(int tool, bool force = false);
bool setCurrentTool(IDrawTool *tool, bool force = false);

Expand Down Expand Up @@ -71,6 +72,7 @@ class DrawToolManager : public DFrame
CDrawToolFactory::CDrawToolsMap _tools;
DrawBoard *m_drawBoard = nullptr;

DScrollArea *m_scrollArea = nullptr;
};

#endif // RIGHTTOOLBAR_H
Loading

0 comments on commit 1beb400

Please sign in to comment.