mirror of
https://github.com/ONLYOFFICE/desktop-apps.git
synced 2026-04-07 14:09:22 +08:00
[win-nix] fix bug 45650
This commit is contained in:
@ -72,6 +72,7 @@
|
||||
</qresource>
|
||||
<qresource prefix="/title/icons">
|
||||
<file alias="buttons.svg">res/icons/webeditor/buttons.svg</file>
|
||||
<file alias="secure.svg">res/icons/webeditor/secureicon.svg</file>
|
||||
</qresource>
|
||||
<qresource prefix="/styles">
|
||||
<file>res/styles/styles.qss</file>
|
||||
|
||||
@ -235,6 +235,8 @@ QWidget * CEditorWindow::createMainPanel(QWidget * parent, const QString& title)
|
||||
m_boxTitleBtns->layout()->addWidget(m_buttonMaximize);
|
||||
m_boxTitleBtns->layout()->addWidget(m_buttonClose);
|
||||
|
||||
d_ptr->customizeTitleLabel();
|
||||
|
||||
// m_boxTitleBtns->setFixedSize(282*m_dpiRatio, TOOLBTN_HEIGHT*m_dpiRatio);
|
||||
|
||||
// QWidget * _lb = new QWidget;
|
||||
@ -345,6 +347,7 @@ void CEditorWindow::setScreenScalingFactor(int newfactor)
|
||||
|
||||
adjustGeometry();
|
||||
recalculatePlaces();
|
||||
updateTitleCaption();
|
||||
}
|
||||
|
||||
void CEditorWindow::recalculatePlaces()
|
||||
@ -481,3 +484,9 @@ AscEditorType CEditorWindow::editorType() const
|
||||
{
|
||||
return d_ptr.get()->panel()->data()->contentType();
|
||||
}
|
||||
|
||||
int CEditorWindow::calcTitleCaptionWidth()
|
||||
{
|
||||
int base_width = CSingleWindowPlatform::calcTitleCaptionWidth();
|
||||
return d_ptr->calcTitleLabelWidth(base_width);
|
||||
}
|
||||
|
||||
@ -85,6 +85,7 @@ protected:
|
||||
void onDpiChanged(int,int) override;
|
||||
|
||||
void setScreenScalingFactor(int) override;
|
||||
int calcTitleCaptionWidth() override;
|
||||
|
||||
void onLocalFileSaveAs(void *);
|
||||
|
||||
|
||||
@ -109,6 +109,8 @@ class CEditorWindowPrivate : public CCefEventsGate
|
||||
bool isPrinting = false,
|
||||
isFullScreen = false;
|
||||
QWidget * fs_parent = nullptr;
|
||||
QLabel * iconcrypted = nullptr;
|
||||
QWidget * boxtitlelabel = nullptr;
|
||||
|
||||
QMap<QString, CSVGPushButton*> m_mapTitleButtons;
|
||||
|
||||
@ -204,14 +206,17 @@ public:
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// update title caption for elipsis
|
||||
window->updateTitleCaption();
|
||||
}
|
||||
|
||||
int _btncount = /*iconuser ? 4 :*/ 3;
|
||||
int diffW = (titleLeftOffset - TOOLBTN_WIDTH * _btncount) * window->m_dpiRatio; // 4 right tool buttons: close, min, max, user icon
|
||||
diffW -= _user_width;
|
||||
|
||||
diffW > 0 ? window->m_labelTitle->setContentsMargins(0, 0, diffW, 2*window->m_dpiRatio) :
|
||||
window->m_labelTitle->setContentsMargins(-diffW, 0, 0, 2*window->m_dpiRatio);
|
||||
// diffW > 0 ? window->m_labelTitle->setContentsMargins(0, 0, diffW, 2*window->m_dpiRatio) :
|
||||
// window->m_labelTitle->setContentsMargins(-diffW, 0, 0, 2*window->m_dpiRatio);
|
||||
}
|
||||
}
|
||||
|
||||
@ -385,13 +390,18 @@ public:
|
||||
int diffW = (titleLeftOffset - (TOOLBTN_WIDTH * _btncount)) * f; // 4 tool buttons: min+max+close+usericon
|
||||
|
||||
if ( iconuser ) {
|
||||
iconuser->setMaximumWidth(200 * f);
|
||||
iconuser->setContentsMargins(12*f,0,12*f,2*f);
|
||||
iconuser->adjustSize();
|
||||
diffW -= iconuser->width();
|
||||
}
|
||||
|
||||
diffW > 0 ? window->m_labelTitle->setContentsMargins(0, 0, diffW, 2*f) :
|
||||
window->m_labelTitle->setContentsMargins(-diffW, 0, 0, 2*f);
|
||||
if ( iconcrypted ) {
|
||||
iconcrypted->setPixmap(QIcon{":/title/icons/secure.svg"}.pixmap(QSize(20,20) * f));
|
||||
}
|
||||
|
||||
diffW > 0 ? boxtitlelabel->setContentsMargins(0, 0, diffW, 2*f) :
|
||||
boxtitlelabel->setContentsMargins(-diffW, 0, 0, 2*f);
|
||||
|
||||
for (auto btn: m_mapTitleButtons) {
|
||||
btn->setFixedSize(QSize(TOOLBTN_WIDTH*f, TOOLBTN_HEIGHT*f));
|
||||
@ -499,6 +509,18 @@ public:
|
||||
return iconuser;
|
||||
}
|
||||
|
||||
QLabel * iconCrypted()
|
||||
{
|
||||
if ( !iconcrypted ) {
|
||||
iconcrypted = new QLabel(window->m_boxTitleBtns);
|
||||
iconcrypted->setObjectName("iconcrypted");
|
||||
|
||||
iconcrypted->setPixmap(QIcon{":/title/icons/secure.svg"}.pixmap(QSize(20,20) * window->m_dpiRatio));
|
||||
}
|
||||
|
||||
return iconcrypted;
|
||||
}
|
||||
|
||||
QPushButton * buttonDock()
|
||||
{
|
||||
if ( !btndock ) {
|
||||
@ -512,6 +534,10 @@ public:
|
||||
void onWebAppsFeatures(int, std::wstring f) override
|
||||
{
|
||||
panel()->data()->setFeatures(f);
|
||||
|
||||
if ( panel()->data()->hasFeature(L"crypted\":true") && boxtitlelabel && !iconcrypted ) {
|
||||
qobject_cast<QBoxLayout *>(boxtitlelabel->layout())->insertWidget(0, iconCrypted());
|
||||
}
|
||||
}
|
||||
|
||||
void onWebTitleChanged(int, std::wstring json) override
|
||||
@ -558,6 +584,33 @@ public:
|
||||
return m_panel->data()->hasFeature(L"viewmode\":true");
|
||||
}
|
||||
|
||||
auto calcTitleLabelWidth(int basewidth) const -> int {
|
||||
if ( iconuser )
|
||||
basewidth -= iconuser->width();
|
||||
|
||||
basewidth -= boxtitlelabel->contentsMargins().left() + boxtitlelabel->contentsMargins().right();
|
||||
if ( iconcrypted )
|
||||
basewidth -= iconcrypted->width();
|
||||
|
||||
basewidth -= m_mapTitleButtons.count() * (TOOLBTN_WIDTH + 1) * window->m_dpiRatio;
|
||||
|
||||
return basewidth;
|
||||
}
|
||||
|
||||
auto customizeTitleLabel() {
|
||||
window->m_boxTitleBtns->layout()->removeWidget(window->m_labelTitle);
|
||||
|
||||
boxtitlelabel = new QWidget;
|
||||
boxtitlelabel->setLayout(new QHBoxLayout);
|
||||
boxtitlelabel->layout()->setSpacing(0);
|
||||
boxtitlelabel->layout()->setMargin(0);
|
||||
|
||||
if ( m_panel->data()->hasFeature(L"crypted\":true") && !iconcrypted ) {
|
||||
boxtitlelabel->layout()->addWidget(iconCrypted());
|
||||
}
|
||||
|
||||
boxtitlelabel->layout()->addWidget(window->m_labelTitle);
|
||||
qobject_cast<QHBoxLayout*>(window->m_boxTitleBtns->layout())->insertWidget(1, boxtitlelabel);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -87,6 +87,8 @@ CElipsisLabel::CElipsisLabel(const QString &text, QWidget *parent)
|
||||
|
||||
void CElipsisLabel::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QLabel::resizeEvent(event);
|
||||
|
||||
if ( event->size().width() != event->oldSize().width() ) {
|
||||
QString elt = ellipsis_text_(this, orig_text, elide_mode);
|
||||
QLabel::setText(elt);
|
||||
@ -106,6 +108,14 @@ auto CElipsisLabel::setEllipsisMode(Qt::TextElideMode mode) -> void
|
||||
elide_mode = mode;
|
||||
}
|
||||
|
||||
auto CElipsisLabel::updateText() -> void
|
||||
{
|
||||
QString elt = ellipsis_text_(this, orig_text, elide_mode);
|
||||
if ( elt != text() ) {
|
||||
QLabel::setText(elt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CSingleWindowBase::CSingleWindowBase()
|
||||
: pimpl{new impl}
|
||||
@ -176,6 +186,15 @@ void CSingleWindowBase::setWindowTitle(const QString& title)
|
||||
}
|
||||
}
|
||||
|
||||
int CSingleWindowBase::calcTitleCaptionWidth()
|
||||
{
|
||||
if ( pimpl->is_custom_window() ) {
|
||||
return m_boxTitleBtns->width() - (m_buttonMaximize->width() * 3);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//#include <QSvgRenderer>
|
||||
//#include <QPainter>
|
||||
QWidget * CSingleWindowBase::createMainPanel(QWidget * parent, const QString& title)
|
||||
@ -191,13 +210,13 @@ QWidget * CSingleWindowBase::createMainPanel(QWidget * parent, const QString& ti
|
||||
|
||||
m_labelTitle = new CElipsisLabel(title);
|
||||
m_labelTitle->setObjectName("labelTitle");
|
||||
m_labelTitle->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
|
||||
m_labelTitle->setMouseTracking(true);
|
||||
m_labelTitle->setEllipsisMode(Qt::ElideMiddle);
|
||||
m_labelTitle->setMaximumWidth(100);
|
||||
|
||||
// layoutBtns->addStretch();
|
||||
layoutBtns->addWidget(m_labelTitle, 1);
|
||||
// layoutBtns->addStretch();
|
||||
layoutBtns->addStretch();
|
||||
layoutBtns->addWidget(m_labelTitle, 0);
|
||||
layoutBtns->addStretch();
|
||||
|
||||
QSize small_btn_size(TOOLBTN_WIDTH*m_dpiRatio, TOOLBTN_HEIGHT*m_dpiRatio);
|
||||
|
||||
@ -224,7 +243,6 @@ QWidget * CSingleWindowBase::createMainPanel(QWidget * parent, const QString& ti
|
||||
m_buttonClose = _creatToolButton("toolButtonClose", parent);
|
||||
QObject::connect(m_buttonClose, &QPushButton::clicked, [=]{onCloseEvent();});
|
||||
|
||||
|
||||
// m_pButtonMaximize = new QPushButton(parent);
|
||||
// m_pButtonMaximize->setFixedSize(small_btn_size);
|
||||
// m_pButtonMaximize->setIconSize(QSize(16,16));
|
||||
@ -257,6 +275,11 @@ void CSingleWindowBase::onMaximizeEvent()
|
||||
|
||||
}
|
||||
|
||||
void CSingleWindowBase::onSizeEvent(int)
|
||||
{
|
||||
updateTitleCaption();
|
||||
}
|
||||
|
||||
void CSingleWindowBase::onExitSizeMove()
|
||||
{
|
||||
|
||||
@ -278,10 +301,20 @@ QPushButton * CSingleWindowBase::createToolButton(QWidget * parent)
|
||||
|
||||
void CSingleWindowBase::adjustGeometry()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CSingleWindowBase::isCustomWindowStyle()
|
||||
{
|
||||
return pimpl->is_custom_window();
|
||||
}
|
||||
|
||||
void CSingleWindowBase::updateTitleCaption()
|
||||
{
|
||||
if ( m_labelTitle ) {
|
||||
int _width = calcTitleCaptionWidth();
|
||||
if ( !(_width < 0) ) {
|
||||
m_labelTitle->setMaximumWidth(_width);
|
||||
m_labelTitle->updateText();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,6 +46,7 @@ public:
|
||||
|
||||
auto setText(const QString&) -> void;
|
||||
auto setEllipsisMode(Qt::TextElideMode) -> void;
|
||||
auto updateText() -> void;
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
@ -95,6 +96,8 @@ protected:
|
||||
virtual QPushButton * createToolButton(QWidget * parent = nullptr);
|
||||
virtual void onExitSizeMove();
|
||||
virtual void onDpiChanged(int newfactor, int prevfactor);
|
||||
virtual int calcTitleCaptionWidth();
|
||||
virtual void updateTitleCaption();
|
||||
|
||||
inline int dpiCorrectValue(int v) const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user