diff --git a/plugin-customcommand/custombutton.cpp b/plugin-customcommand/custombutton.cpp index a8ae7ac5f..213deb9ed 100644 --- a/plugin-customcommand/custombutton.cpp +++ b/plugin-customcommand/custombutton.cpp @@ -31,35 +31,13 @@ #include #include -class LeftAlignedTextStyle : public QProxyStyle -{ - using QProxyStyle::QProxyStyle; -public: - - virtual void drawItemText(QPainter * painter, const QRect & rect, int flags - , const QPalette & pal, bool enabled, const QString & text - , QPalette::ColorRole textRole = QPalette::NoRole) const override; -}; - -void LeftAlignedTextStyle::drawItemText(QPainter * painter, const QRect & rect, int flags - , const QPalette & pal, bool enabled, const QString & text - , QPalette::ColorRole textRole) const -{ - QString txt = text; - // get the button text because the text that's given to this function may be middle-elided - if (const QToolButton *tb = dynamic_cast(painter->device())) - txt = tb->text(); - txt = QFontMetrics(painter->font()).elidedText(txt, Qt::ElideRight, rect.width()); - QProxyStyle::drawItemText(painter, rect, (flags & ~Qt::AlignHCenter) | Qt::AlignLeft, pal, enabled, txt, textRole); -} - - CustomButton::CustomButton(ILXQtPanelPlugin *plugin, QWidget* parent): QToolButton(parent), mPlugin(plugin), mPanel(plugin->panel()), - mMaxWidth(200) - + mAutoRotate(false), + mMaxWidth(200), + mSizeHint(QSize()) { setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setAutoRaise(true); @@ -67,9 +45,7 @@ CustomButton::CustomButton(ILXQtPanelPlugin *plugin, QWidget* parent): setMinimumWidth(1); setMinimumHeight(1); setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - setStyle(new LeftAlignedTextStyle()); - updateWidth(); - + updateButton(); } CustomButton::~CustomButton() = default; @@ -83,59 +59,75 @@ void CustomButton::wheelEvent(QWheelEvent *event) void CustomButton::setMaxWidth(int maxWidth) { - mMaxWidth = maxWidth; - updateWidth(); -} - -void CustomButton::updateWidth() -{ - int newWidth = qMin(sizeHint().width(), mMaxWidth); - if (mOrigin == Qt::TopLeftCorner) { - setFixedWidth(newWidth); - - setMinimumHeight(1); - setMaximumHeight(QWIDGETSIZE_MAX); - } - else { - setMinimumWidth(1); - setMaximumWidth(QWIDGETSIZE_MAX); - - setFixedHeight(newWidth); - } - update(); + if (mMaxWidth != maxWidth) + mMaxWidth = maxWidth; } void CustomButton::setOrigin(Qt::Corner newOrigin) { - if (mOrigin != newOrigin) { + if (mOrigin != newOrigin) mOrigin = newOrigin; - updateWidth(); - } } -void CustomButton::setAutoRotation(bool value) +void CustomButton::setAutoRotation(bool rotate) { - if (value) { - switch (mPanel->position()) - { - case ILXQtPanel::PositionTop: - case ILXQtPanel::PositionBottom: - setOrigin(Qt::TopLeftCorner); - break; + if (mSizeHint == sizeHint() && mAutoRotate == rotate && mPanelPosition == mPanel->position()) + return; - case ILXQtPanel::PositionLeft: + mSizeHint = sizeHint(); + mAutoRotate = rotate; + mPanelPosition = mPanel->position(); + int length = 0; + + switch (mPanel->position()) + { + case ILXQtPanel::PositionTop: + case ILXQtPanel::PositionBottom: + setOrigin(Qt::TopLeftCorner); + length = qMin(mSizeHint.width(), mMaxWidth); + setFixedWidth(length); + + setMinimumHeight(1); + setMaximumHeight(QWIDGETSIZE_MAX); + break; + + case ILXQtPanel::PositionLeft: + if (rotate) { setOrigin(Qt::BottomLeftCorner); - break; + length = qMin(mSizeHint.width(), mMaxWidth); + } + else { + setOrigin(Qt::TopLeftCorner); + length = qMin(mSizeHint.height(), mMaxWidth); + } + setMinimumWidth(1); + setMaximumWidth(QWIDGETSIZE_MAX); - case ILXQtPanel::PositionRight: + setFixedHeight(length); + break; + + case ILXQtPanel::PositionRight: + if (rotate) { setOrigin(Qt::TopRightCorner); - break; + length = qMin(mSizeHint.width(), mMaxWidth); + } + else { + setOrigin(Qt::TopLeftCorner); + length = qMin(mSizeHint.height(), mMaxWidth); } + setMinimumWidth(1); + setMaximumWidth(QWIDGETSIZE_MAX); + + setFixedHeight(length); + break; } - else - setOrigin(Qt::TopLeftCorner); + update(); +} +void CustomButton::updateButton() +{ + setAutoRotation(mAutoRotate); } void CustomButton::paintEvent(QPaintEvent *event) diff --git a/plugin-customcommand/custombutton.h b/plugin-customcommand/custombutton.h index 5a24e9304..53eaeb697 100644 --- a/plugin-customcommand/custombutton.h +++ b/plugin-customcommand/custombutton.h @@ -40,9 +40,9 @@ class CustomButton : public QToolButton ~CustomButton(); public slots: - void setAutoRotation(bool value); void setMaxWidth(int maxWidth); - void updateWidth(); + void setAutoRotation(bool rotate); + void updateButton(); protected: void wheelEvent(QWheelEvent *event) override; @@ -54,8 +54,11 @@ private slots: private: ILXQtPanelPlugin *mPlugin; ILXQtPanel *mPanel; + ILXQtPanel::Position mPanelPosition; + bool mAutoRotate; Qt::Corner mOrigin; int mMaxWidth; + QSize mSizeHint; signals: void wheelScrolled(int); diff --git a/plugin-customcommand/lxqtcustomcommand.cpp b/plugin-customcommand/lxqtcustomcommand.cpp index 0792de3b1..e4eb109fc 100644 --- a/plugin-customcommand/lxqtcustomcommand.cpp +++ b/plugin-customcommand/lxqtcustomcommand.cpp @@ -42,7 +42,8 @@ LXQtCustomCommand::LXQtCustomCommand(const ILXQtPanelPluginStartupInfo &startupI mDelayedRunTimer(new QTimer(this)), mFirstRun(true), mOutput(QString()), - mAutoRotate(true) + mAutoRotate(true), + mExpandToRows(false) { mButton = new CustomButton(this); mButton->setObjectName(QLatin1String("CustomButton")); @@ -76,7 +77,7 @@ QWidget *LXQtCustomCommand::widget() void LXQtCustomCommand::realign() { - mButton->setAutoRotation(mAutoRotate); + mButton->updateButton(); } QDialog *LXQtCustomCommand::configureDialog() @@ -91,17 +92,17 @@ void LXQtCustomCommand::settingsChanged() { bool shouldRun = false; - bool oldAutoRotate = mAutoRotate; + bool oldExpandToRows = mExpandToRows; QString oldFont = mFont; QString oldCommand = mCommand; bool oldRunWithBash = mRunWithBash; bool oldRepeat = mRepeat; int oldRepeatTimer = mRepeatTimer; QString oldIcon = mIcon; - QString oldText = mText; int oldMaxWidth = mMaxWidth; mAutoRotate = settings()->value(QStringLiteral("autoRotate"), true).toBool(); + mExpandToRows = settings()->value(QStringLiteral("expandToRows")).toBool(); mFont = settings()->value(QStringLiteral("font"), mButton->font().toString()).toString(); mCommand = settings()->value(QStringLiteral("command"), QStringLiteral("echo Configure...")).toString(); mRunWithBash = settings()->value(QStringLiteral("runWithBash"), true).toBool(); @@ -126,7 +127,6 @@ void LXQtCustomCommand::settingsChanged() } else { mButton->setFont(newFont); - updateButton(); } } if (oldCommand != mCommand || oldRunWithBash != mRunWithBash || oldRepeat != mRepeat) @@ -135,18 +135,16 @@ void LXQtCustomCommand::settingsChanged() if (oldRepeatTimer != mRepeatTimer) mTimer->setInterval(mRepeatTimer * 1000); - if (oldIcon != mIcon) { + if (oldIcon != mIcon) mButton->setIcon(XdgIcon::fromTheme(mIcon, QIcon(mIcon))); - updateButton(); - } - else if (oldText != mText) - updateButton(); if (oldMaxWidth != mMaxWidth) mButton->setMaxWidth(mMaxWidth); - if (oldAutoRotate != mAutoRotate) - mButton->setAutoRotation(mAutoRotate); + if (oldExpandToRows != mExpandToRows) + pluginFlagsChanged(); + + mButton->setAutoRotation(mAutoRotate); if (mFirstRun) { mFirstRun = false; @@ -190,7 +188,7 @@ void LXQtCustomCommand::updateButton() { mButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); mButton->setText(newText); - mButton->updateWidth(); + mButton->updateButton(); } void LXQtCustomCommand::handleWheelScrolled(int yDelta) diff --git a/plugin-customcommand/lxqtcustomcommand.h b/plugin-customcommand/lxqtcustomcommand.h index d37cf03ef..cd16b5474 100644 --- a/plugin-customcommand/lxqtcustomcommand.h +++ b/plugin-customcommand/lxqtcustomcommand.h @@ -49,6 +49,7 @@ class LXQtCustomCommand : public QObject, public ILXQtPanelPlugin virtual ILXQtPanelPlugin::Flags flags() const { return PreferRightAlignment | HaveConfigDialog ; } void realign(); QDialog *configureDialog(); + bool isSeparate() const { return mExpandToRows; } protected slots: virtual void settingsChanged(); @@ -74,6 +75,7 @@ private slots: QString mOutput; bool mAutoRotate; + bool mExpandToRows; QString mFont; QString mCommand; bool mRunWithBash; diff --git a/plugin-customcommand/lxqtcustomcommandconfiguration.cpp b/plugin-customcommand/lxqtcustomcommandconfiguration.cpp index 8daa4ff5f..7796e9a9b 100644 --- a/plugin-customcommand/lxqtcustomcommandconfiguration.cpp +++ b/plugin-customcommand/lxqtcustomcommandconfiguration.cpp @@ -42,6 +42,7 @@ LXQtCustomCommandConfiguration::LXQtCustomCommandConfiguration(PluginSettings *s connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &LXQtCustomCommandConfiguration::buttonBoxClicked); connect(ui->autoRotateCheckBox, &QCheckBox::toggled, this, &LXQtCustomCommandConfiguration::autoRotateChanged); + connect(ui->expandToRowsCheckBox, &QCheckBox::toggled, this, &LXQtCustomCommandConfiguration::expandToRowsChanged); connect(ui->fontButton, &QPushButton::clicked, this, &LXQtCustomCommandConfiguration::fontButtonClicked); connect(ui->commandPlainTextEdit, &QPlainTextEdit::textChanged, this, &LXQtCustomCommandConfiguration::commandPlainTextEditChanged); connect(ui->runWithBashCheckBox, &QCheckBox::toggled, this, &LXQtCustomCommandConfiguration::runWithBashCheckBoxChanged); @@ -75,6 +76,7 @@ void LXQtCustomCommandConfiguration::buttonBoxClicked(QAbstractButton *btn) void LXQtCustomCommandConfiguration::loadSettings() { mAutoRotate = settings().value(QStringLiteral("autoRotate"), true).toBool(); + mExpandToRows = settings().value(QStringLiteral("expandToRows"), false).toBool(); mFont = settings().value(QStringLiteral("font"), font().toString()).toString(); mCommand = settings().value(QStringLiteral("command"), QStringLiteral("echo Configure...")).toString(); mRunWithBash = settings().value(QStringLiteral("runWithBash"), true).toBool(); @@ -91,6 +93,7 @@ void LXQtCustomCommandConfiguration::loadSettings() void LXQtCustomCommandConfiguration::setUiValues() { ui->autoRotateCheckBox->setChecked(mAutoRotate); + ui->expandToRowsCheckBox->setChecked(mExpandToRows); ui->fontButton->setText(mFont); ui->commandPlainTextEdit->setPlainText(mCommand); ui->runWithBashCheckBox->setChecked(mRunWithBash); @@ -110,6 +113,11 @@ void LXQtCustomCommandConfiguration::autoRotateChanged(bool autoRotate) settings().setValue(QStringLiteral("autoRotate"), autoRotate); } +void LXQtCustomCommandConfiguration::expandToRowsChanged(bool expand) +{ + settings().setValue(QStringLiteral("expandToRows"), expand); +} + void LXQtCustomCommandConfiguration::fontButtonClicked() { bool ok; diff --git a/plugin-customcommand/lxqtcustomcommandconfiguration.h b/plugin-customcommand/lxqtcustomcommandconfiguration.h index 958db6d11..12ad2cfa7 100644 --- a/plugin-customcommand/lxqtcustomcommandconfiguration.h +++ b/plugin-customcommand/lxqtcustomcommandconfiguration.h @@ -43,6 +43,7 @@ class LXQtCustomCommandConfiguration : public LXQtPanelPluginConfigDialog private: bool mAutoRotate; + bool mExpandToRows; QString mFont; QString mCommand; bool mRunWithBash; @@ -59,6 +60,7 @@ private slots: void buttonBoxClicked(QAbstractButton *btn); void setUiValues(); void autoRotateChanged(bool autoRotate); + void expandToRowsChanged(bool expand); void fontButtonClicked(); void fontChanged(QString fontString); void commandPlainTextEditChanged(); diff --git a/plugin-customcommand/lxqtcustomcommandconfiguration.ui b/plugin-customcommand/lxqtcustomcommandconfiguration.ui index afa860c56..38d971927 100644 --- a/plugin-customcommand/lxqtcustomcommandconfiguration.ui +++ b/plugin-customcommand/lxqtcustomcommandconfiguration.ui @@ -7,7 +7,7 @@ 0 0 500 - 500 + 520 @@ -22,14 +22,87 @@ - - - - Use icon from theme or browse file + + + + + 0 + 0 + + + + + 0 + 0 + + + QFrame::NoFrame + + + QFrame::Raised + + + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Repeat command after: + + + + + + + false + + + + 0 + 0 + + + + second(s) + + + 1 + + + 86400 + + + 1 + + + 5 + + + + - + Run with "bash -c" @@ -39,44 +112,41 @@ - - + + - Select Font + %1 - - false + + Use %1 to display command output - - + + - Text - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + Autorotate when the panel is vertical - - - - Command - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + Use icon from theme or browse file - - + + - Font + Select Font + + + false - + px @@ -95,17 +165,17 @@ - - + + - %1 + Command - - Use %1 to display command output + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - + Icon @@ -115,24 +185,7 @@ - - - - Browse - - - false - - - - - - - Autorotate when the panel is vertical - - - - + @@ -155,93 +208,47 @@ - + - Max Width + Text Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - 0 - 0 - + + + + Browse - - - 0 - 0 - + + false - - QFrame::NoFrame + + + + + + Font - - QFrame::Raised + + + + + + Max Width - - 0 + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Expand to all panel rows - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - Repeat command after: - - - - - - - false - - - - 0 - 0 - - - - second(s) - - - 1 - - - 86400 - - - 1 - - - 5 - - - - @@ -323,6 +330,7 @@ autoRotateCheckBox + expandToRowsCheckBox fontButton commandPlainTextEdit runWithBashCheckBox