Description: Add auto-expansion feature This is patch 3/4 adding autoexpansion support to the spacer plugin. Author: Palo Kisa Origin: upstream Bug: https://github.com/lxqt/lxqt/issues/1038 Applied-Upstream: commit:b57a178 Last-Update: 2018-08-16 --- a/plugin-spacer/spacer.cpp +++ b/plugin-spacer/spacer.cpp @@ -55,6 +55,7 @@ Spacer::Spacer(const ILXQtPanelPluginSta QObject() , ILXQtPanelPlugin(startupInfo) , mSize(8) + , mExpandable(false) { settingsChanged(); } @@ -65,8 +66,12 @@ Spacer::Spacer(const ILXQtPanelPluginSta void Spacer::settingsChanged() { mSize = settings()->value("size", 8).toInt(); + const bool old_expandable = mExpandable; + mExpandable = settings()->value("expandable", false).toBool(); mSpacer.setType(settings()->value("spaceType", SpacerConfiguration::msTypes[0]).toString()); setSizes(); + if (old_expandable != mExpandable) + pluginFlagsChanged(); } /************************************************ @@ -82,21 +87,30 @@ QDialog *Spacer::configureDialog() ************************************************/ void Spacer::setSizes() { - if (panel()->isHorizontal()) + if (mExpandable) { - mSpacer.setOrientation("horizontal"); - mSpacer.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); - mSpacer.setFixedWidth(mSize); - mSpacer.setMinimumHeight(0); - mSpacer.setMaximumHeight(QWIDGETSIZE_MAX); - } - else + mSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + mSpacer.setMinimumSize({1, 1}); + mSpacer.setMaximumSize({QWIDGETSIZE_MAX, QWIDGETSIZE_MAX}); + mSpacer.setOrientation(panel()->isHorizontal() ? "horizontal" : "vertical"); + } else { - mSpacer.setOrientation("vertical"); - mSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - mSpacer.setFixedHeight(mSize); - mSpacer.setMinimumWidth(0); - mSpacer.setMaximumWidth(QWIDGETSIZE_MAX); + if (panel()->isHorizontal()) + { + mSpacer.setOrientation("horizontal"); + mSpacer.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + mSpacer.setFixedWidth(mSize); + mSpacer.setMinimumHeight(0); + mSpacer.setMaximumHeight(QWIDGETSIZE_MAX); + } + else + { + mSpacer.setOrientation("vertical"); + mSpacer.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + mSpacer.setFixedHeight(mSize); + mSpacer.setMinimumWidth(0); + mSpacer.setMaximumWidth(QWIDGETSIZE_MAX); + } } } --- a/plugin-spacer/spacer.h +++ b/plugin-spacer/spacer.h @@ -61,6 +61,7 @@ public: virtual QString themeId() const override { return "Spacer"; } bool isSeparate() const override { return true; } + bool isExpandable() const override { return mExpandable; } virtual ILXQtPanelPlugin::Flags flags() const override { return HaveConfigDialog; } QDialog *configureDialog() override; @@ -76,6 +77,7 @@ private: private: SpacerWidget mSpacer; int mSize; + int mExpandable; }; class SpacerPluginLibrary: public QObject, public ILXQtPanelPluginLibrary --- a/plugin-spacer/spacerconfiguration.cpp +++ b/plugin-spacer/spacerconfiguration.cpp @@ -52,6 +52,8 @@ SpacerConfiguration::SpacerConfiguration connect(ui->sizeSB, static_cast(&QSpinBox::valueChanged), this, &SpacerConfiguration::sizeChanged); connect(ui->typeCB, static_cast(&QComboBox::currentIndexChanged), this, &SpacerConfiguration::typeChanged); + //Note: if there will be more than 2 radio buttons for width/size type, this simple setting logic will break + connect(ui->sizeExpandRB, &QAbstractButton::toggled, this, &SpacerConfiguration::widthTypeChanged); } SpacerConfiguration::~SpacerConfiguration() @@ -63,6 +65,10 @@ void SpacerConfiguration::loadSettings() { ui->sizeSB->setValue(settings().value("size", 8).toInt()); ui->typeCB->setCurrentIndex(ui->typeCB->findData(settings().value("spaceType", msTypes[0]).toString())); + const bool expandable = settings().value("expandable", false).toBool(); + ui->sizeExpandRB->setChecked(expandable); + ui->sizeFixedRB->setChecked(!expandable); + ui->sizeSB->setDisabled(expandable); } void SpacerConfiguration::sizeChanged(int value) @@ -74,3 +80,8 @@ void SpacerConfiguration::typeChanged(in { settings().setValue("spaceType", ui->typeCB->itemData(index, Qt::UserRole)); } + +void SpacerConfiguration::widthTypeChanged(bool expandableChecked) +{ + settings().setValue("expandable", expandableChecked); +} --- a/plugin-spacer/spacerconfiguration.h +++ b/plugin-spacer/spacerconfiguration.h @@ -58,6 +58,7 @@ private slots: void loadSettings(); void sizeChanged(int value); void typeChanged(int index); + void widthTypeChanged(bool expandableChecked); }; #endif // SPACERCONFIGURATION_H --- a/plugin-spacer/spacerconfiguration.ui +++ b/plugin-spacer/spacerconfiguration.ui @@ -6,6 +6,8 @@ 0 0 + 289 + 135 @@ -19,7 +21,7 @@ - + 4 @@ -32,21 +34,14 @@ - + Space type: - - - - false - - - - + Qt::Horizontal @@ -56,6 +51,27 @@ + + + + fixed + + + + + + + false + + + + + + + expandable + + + @@ -65,6 +81,32 @@ clicked(QAbstractButton*) SpacerConfiguration close() + + + 20 + 20 + + + 20 + 20 + + + + + sizeFixedRB + toggled(bool) + sizeSB + setEnabled(bool) + + + 152 + 21 + + + 244 + 21 + +