diff --git a/panel/config/configplacement.cpp b/panel/config/configplacement.cpp index d14d545c7..8d2b4ae02 100644 --- a/panel/config/configplacement.cpp +++ b/panel/config/configplacement.cpp @@ -59,6 +59,7 @@ ConfigPlacement::ConfigPlacement(LXQtPanel *panel, QWidget *parent) : fillComboBox_alignment(); mOldPanelSize = mPanel->panelSize(); + mOldPadding = mPanel->padding(); mOldIconSize = mPanel->iconSize(); mOldLineCount = mPanel->lineCount(); @@ -91,6 +92,7 @@ ConfigPlacement::ConfigPlacement(LXQtPanel *panel, QWidget *parent) : reset(); connect(ui->spinBox_panelSize, QOverload::of(&QSpinBox::valueChanged), this, &ConfigPlacement::editChanged); + connect(ui->spinBox_padding, QOverload::of(&QSpinBox::valueChanged), this, [this](){ mPanel->setPadding(ui->spinBox_padding->value(), true); }); connect(ui->spinBox_iconSize, QOverload::of(&QSpinBox::valueChanged), this, &ConfigPlacement::editChanged); connect(ui->spinBox_lineCount, QOverload::of(&QSpinBox::valueChanged), this, &ConfigPlacement::editChanged); @@ -116,6 +118,7 @@ ConfigPlacement::ConfigPlacement(LXQtPanel *panel, QWidget *parent) : void ConfigPlacement::reset() { ui->spinBox_panelSize->setValue(mOldPanelSize); + ui->spinBox_padding->setValue(mOldPadding); ui->spinBox_iconSize->setValue(mOldIconSize); ui->spinBox_lineCount->setValue(mOldLineCount); diff --git a/panel/config/configplacement.h b/panel/config/configplacement.h index 6a928135b..8f29b081d 100644 --- a/panel/config/configplacement.h +++ b/panel/config/configplacement.h @@ -74,6 +74,7 @@ private slots: int getMaxLength(); // old values for reset + int mOldPadding; int mOldPanelSize; int mOldIconSize; int mOldLineCount; diff --git a/panel/config/configplacement.ui b/panel/config/configplacement.ui index f8e77323e..a7d1d55df 100644 --- a/panel/config/configplacement.ui +++ b/panel/config/configplacement.ui @@ -7,7 +7,7 @@ 0 0 382 - 359 + 442 @@ -62,7 +62,7 @@ 0 - + <p>Negative pixel value sets the panel length to that many pixels less than available screen space.</p><p/><p><i>E.g. "Length" set to -100px, screen size is 1000px, then real panel length will be 900 px.</i></p> @@ -83,13 +83,27 @@ + + + Padding: + + + + + + + px + + + + Length: - + diff --git a/panel/lxqtpanel.cpp b/panel/lxqtpanel.cpp index 05d903089..e0a8422cb 100644 --- a/panel/lxqtpanel.cpp +++ b/panel/lxqtpanel.cpp @@ -63,6 +63,14 @@ #define CFG_KEY_SCREENNUM "desktop" #define CFG_KEY_POSITION "position" #define CFG_KEY_PANELSIZE "panelSize" +#define CFG_KEY_BOTTOMINSET "bottomInset" +#define CFG_KEY_TOPINSET "topInset" +#define CFG_KEY_LEFTINSET "leftInset" +#define CFG_KEY_RIGHTINSET "rightInset" +#define CFG_KEY_BOTTOMPADDING "bottomPadding" +#define CFG_KEY_TOPPADDING "topPadding" +#define CFG_KEY_LEFTPADDING "leftPadding" +#define CFG_KEY_RIGHTPADDING "rightPadding" #define CFG_KEY_ICONSIZE "iconSize" #define CFG_KEY_LINECNT "lineCount" #define CFG_KEY_LENGTH "width" @@ -305,6 +313,14 @@ void LXQtPanel::readSettings() // By default we are using size & count from theme. setPanelSize(mSettings->value(QStringLiteral(CFG_KEY_PANELSIZE), PANEL_DEFAULT_SIZE).toInt(), false); + setBottomInset(mSettings->value(QStringLiteral(CFG_KEY_BOTTOMINSET), int{0}).toInt(), false); + setTopInset(mSettings->value(QStringLiteral(CFG_KEY_TOPINSET), int{0}).toInt(), false); + setLeftInset(mSettings->value(QStringLiteral(CFG_KEY_LEFTINSET), int{0}).toInt(), false); + setRightInset(mSettings->value(QStringLiteral(CFG_KEY_RIGHTINSET), int{0}).toInt(), false); + setBottomPadding(mSettings->value(QStringLiteral(CFG_KEY_BOTTOMPADDING), int{0}).toInt(), false); + setTopPadding(mSettings->value(QStringLiteral(CFG_KEY_TOPPADDING), int{0}).toInt(), false); + setLeftPadding(mSettings->value(QStringLiteral(CFG_KEY_LEFTPADDING), int{0}).toInt(), false); + setRightPadding(mSettings->value(QStringLiteral(CFG_KEY_RIGHTPADDING), int{0}).toInt(), false); setIconSize(mSettings->value(QStringLiteral(CFG_KEY_ICONSIZE), PANEL_DEFAULT_ICON_SIZE).toInt(), false); setLineCount(mSettings->value(QStringLiteral(CFG_KEY_LINECNT), PANEL_DEFAULT_LINE_COUNT).toInt(), false); @@ -357,6 +373,14 @@ void LXQtPanel::saveSettings(bool later) //mSettings->setValue(CFG_KEY_PLUGINS, mPlugins->pluginNames()); mSettings->setValue(QStringLiteral(CFG_KEY_PANELSIZE), mPanelSize); + mSettings->setValue(QStringLiteral(CFG_KEY_BOTTOMINSET), bottomInset()); + mSettings->setValue(QStringLiteral(CFG_KEY_TOPINSET), topInset()); + mSettings->setValue(QStringLiteral(CFG_KEY_LEFTINSET), leftInset()); + mSettings->setValue(QStringLiteral(CFG_KEY_RIGHTINSET), rightInset()); + mSettings->setValue(QStringLiteral(CFG_KEY_BOTTOMPADDING), bottomPadding()); + mSettings->setValue(QStringLiteral(CFG_KEY_TOPPADDING), topPadding()); + mSettings->setValue(QStringLiteral(CFG_KEY_LEFTPADDING), leftPadding()); + mSettings->setValue(QStringLiteral(CFG_KEY_RIGHTPADDING), rightPadding()); mSettings->setValue(QStringLiteral(CFG_KEY_ICONSIZE), mIconSize); mSettings->setValue(QStringLiteral(CFG_KEY_LINECNT), mLineCount); diff --git a/panel/lxqtpanel.h b/panel/lxqtpanel.h index f3be5cd96..fee0df82c 100644 --- a/panel/lxqtpanel.h +++ b/panel/lxqtpanel.h @@ -78,6 +78,16 @@ class LXQT_PANEL_API LXQtPanel : public QFrame, public ILXQtPanel Q_OBJECT Q_PROPERTY(QString position READ qssPosition) + Q_PROPERTY(int inset READ inset WRITE setInset NOTIFY insetChanged) + Q_PROPERTY(int bottomInset READ bottomInset WRITE setBottomInset NOTIFY bottomInsetChanged) + Q_PROPERTY(int topInset READ topInset WRITE setTopInset NOTIFY topInsetChanged) + Q_PROPERTY(int leftInset READ leftInset WRITE setLeftInset NOTIFY leftInsetChanged) + Q_PROPERTY(int rightInset READ rightInset WRITE setRightInset NOTIFY rightInsetChanged) + Q_PROPERTY(int padding READ padding WRITE setPadding NOTIFY paddingChanged) + Q_PROPERTY(int bottomPadding READ bottomPadding WRITE setBottomPadding NOTIFY bottomPaddingChanged) + Q_PROPERTY(int topPadding READ topPadding WRITE setTopPadding NOTIFY topPaddingChanged) + Q_PROPERTY(int leftPadding READ leftPadding WRITE setLeftPadding NOTIFY leftPaddingChanged) + Q_PROPERTY(int rightPadding READ rightPadding WRITE setRightPadding NOTIFY rightPaddingChanged) // for configuration dialog friend class ConfigPanelWidget; @@ -209,6 +219,22 @@ class LXQT_PANEL_API LXQtPanel : public QFrame, public ILXQtPanel static ILXQtPanel::Position strToPosition(const QString &str, ILXQtPanel::Position defaultValue); // Settings + int inset() const { + auto cm = contentsMargins(); + return (cm.bottom() == cm.top()) == (cm.left() == cm.right()) ? cm.left() : 0; + } + int bottomInset() const { return contentsMargins().bottom(); } + int topInset() const { return contentsMargins().top(); } + int leftInset() const { return contentsMargins().left(); } + int rightInset() const { return contentsMargins().right(); } + int padding() const { + auto cm = LXQtPanelWidget->contentsMargins() + contentsMargins(); + return (cm.bottom() == cm.top()) == (cm.left() == cm.right()) ? cm.left() : 0; + } + int bottomPadding() const { return LXQtPanelWidget->contentsMargins().bottom() + contentsMargins().bottom(); } + int topPadding() const { return LXQtPanelWidget->contentsMargins().top() + contentsMargins().top(); } + int leftPadding() const { return LXQtPanelWidget->contentsMargins().left() + contentsMargins().left(); } + int rightPadding() const { return LXQtPanelWidget->contentsMargins().right() + contentsMargins().right(); } int iconSize() const override { return mIconSize; } //!< Implement ILXQtPanel::iconSize(). int lineCount() const override { return mLineCount; } //!< Implement ILXQtPanel::lineCount(). int panelSize() const { return mPanelSize; } @@ -296,6 +322,132 @@ public slots: * @param save If true, saveSettings(true) will be called. */ void setPanelSize(int value, bool save); + void setInset(int value, bool save = true) { + if (value != inset()) { + setContentsMargins(value, value, value, value); + if (save) { + saveSettings(true); + } + emit insetChanged(); + } + } //!< \sa setPanelSize() + void setBottomInset(int value, bool save = true) { + auto cm = contentsMargins(); + if (value != cm.bottom()) { + cm.setBottom(value); + setContentsMargins(cm); + if (save) { + saveSettings(true); + } + emit bottomInsetChanged(); + } + } //!< \sa setPanelSize() + void setTopInset(int value, bool save = true) { + auto cm = contentsMargins(); + if (value != cm.top()) { + cm.setTop(value); + setContentsMargins(cm); + if (save) { + saveSettings(true); + } + emit topInsetChanged(); + } + } //!< \sa setPanelSize() + void setLeftInset(int value, bool save = true) { + auto cm = contentsMargins(); + if (value != cm.left()) { + cm.setLeft(value); + setContentsMargins(cm); + if (save) { + saveSettings(true); + } + emit leftInsetChanged(); + } + } //!< \sa setPanelSize() + void setRightInset(int value, bool save = true) { + auto cm = contentsMargins(); + if (value != cm.right()) { + cm.setRight(value); + setContentsMargins(cm); + if (save) { + saveSettings(true); + } + emit rightInsetChanged(); + } + } //!< \sa setPanelSize() + void setPadding(int value, bool save = true) { + auto inset_ = inset(); + if (inset_ != 0) { + value = value - inset_; + } + if (value != padding()) { + LXQtPanelWidget->setContentsMargins(value, value, value, value); + if (save) { + saveSettings(true); + } + emit paddingChanged(); + } + } //!< \sa setPanelSize() + void setBottomPadding(int value, bool save = true) { + auto cm = LXQtPanelWidget->contentsMargins(); + auto inset_ = bottomInset(); + if (inset_ != 0) { + value = value - inset_; + } + if (value != cm.bottom()) { + cm.setBottom(value); + setContentsMargins(cm); + if (save) { + saveSettings(true); + } + emit bottomPaddingChanged(); + } + } //!< \sa setPanelSize() + void setTopPadding(int value, bool save = true) { + auto cm = LXQtPanelWidget->contentsMargins(); + auto inset_ = topInset(); + if (inset_ != 0) { + value = value - inset_; + } + if (value != cm.top()) { + cm.setTop(value); + setContentsMargins(cm); + if (save) { + saveSettings(true); + } + emit topPaddingChanged(); + } + } //!< \sa setPanelSize() + void setLeftPadding(int value, bool save = true) { + auto cm = LXQtPanelWidget->contentsMargins(); + auto inset_ = leftInset(); + if (inset_ != 0) { + value = value - inset_; + } + if (value != cm.left()) { + cm.setLeft(value); + setContentsMargins(cm); + if (save) { + saveSettings(true); + } + emit leftPaddingChanged(); + } + } //!< \sa setPanelSize() + void setRightPadding(int value, bool save = true) { + auto cm = LXQtPanelWidget->contentsMargins(); + auto inset_ = bottomInset(); + if (inset_ != 0) { + value = value - inset_; + } + if (value != cm.right()) { + cm.setRight(value); + setContentsMargins(cm); + if (save) { + saveSettings(true); + } + emit rightPaddingChanged(); + } + } //!< \sa setPanelSize() void setIconSize(int value, bool save); //!< \sa setPanelSize() void setLineCount(int value, bool save); //!< \sa setPanelSize() void setLength(int length, bool inPercents, bool save); //!< \sa setPanelSize() @@ -347,6 +499,16 @@ public slots: * parameter to identify the LXQtPanel that should be removed. */ void deletedByUser(LXQtPanel *self); + void insetChanged(); + void bottomInsetChanged(); + void topInsetChanged(); + void leftInsetChanged(); + void rightInsetChanged(); + void paddingChanged(); + void bottomPaddingChanged(); + void topPaddingChanged(); + void leftPaddingChanged(); + void rightPaddingChanged(); /** * @brief This signal is just a relay signal. The pluginAdded signal * of the PanelPluginsModel (mPlugins) will be connected to this @@ -662,6 +824,7 @@ private slots: QColor mFontColor; //!< Font color that is used in the style sheet. QColor mBackgroundColor; //!< Background color that is used in the style sheet. QString mBackgroundImage; //!< Background image that is used in the style sheet. + /** * @brief Determines the opacity of the background color. The value * should be in the range from 0 to 100. This will not affect the opacity