Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add panel padding property #1940

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions panel/config/configplacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ ConfigPlacement::ConfigPlacement(LXQtPanel *panel, QWidget *parent) :
fillComboBox_alignment();

mOldPanelSize = mPanel->panelSize();
mOldPadding = mPanel->padding();
mOldIconSize = mPanel->iconSize();
mOldLineCount = mPanel->lineCount();

Expand Down Expand Up @@ -91,6 +92,7 @@ ConfigPlacement::ConfigPlacement(LXQtPanel *panel, QWidget *parent) :
reset();

connect(ui->spinBox_panelSize, QOverload<int>::of(&QSpinBox::valueChanged), this, &ConfigPlacement::editChanged);
connect(ui->spinBox_padding, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](){ mPanel->setPadding(ui->spinBox_padding->value(), true); });
connect(ui->spinBox_iconSize, QOverload<int>::of(&QSpinBox::valueChanged), this, &ConfigPlacement::editChanged);
connect(ui->spinBox_lineCount, QOverload<int>::of(&QSpinBox::valueChanged), this, &ConfigPlacement::editChanged);

Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions panel/config/configplacement.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private slots:
int getMaxLength();

// old values for reset
int mOldPadding;
int mOldPanelSize;
int mOldIconSize;
int mOldLineCount;
Expand Down
20 changes: 17 additions & 3 deletions panel/config/configplacement.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>382</width>
<height>359</height>
<height>442</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -62,7 +62,7 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QSpinBox" name="spinBox_length">
<property name="toolTip">
<string>&lt;p&gt;Negative pixel value sets the panel length to that many pixels less than available screen space.&lt;/p&gt;&lt;p/&gt;&lt;p&gt;&lt;i&gt;E.g. &quot;Length&quot; set to -100px, screen size is 1000px, then real panel length will be 900 px.&lt;/i&gt;&lt;/p&gt;</string>
Expand All @@ -83,13 +83,27 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_padding">
<property name="text">
<string>Padding:</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QSpinBox" name="spinBox_padding">
<property name="suffix">
<string> px</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_length">
<property name="text">
<string>Length:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<item row="2" column="2">
<widget class="QComboBox" name="comboBox_lengthType">
<item>
<property name="text">
Expand Down
24 changes: 24 additions & 0 deletions panel/lxqtpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
163 changes: 163 additions & 0 deletions panel/lxqtpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down