Skip to content

Commit

Permalink
Show Auto-Hiding Panels with Delay (lxqt#387)
Browse files Browse the repository at this point in the history
* Show Auto-Hiding Panels with Delay

Made to supercede lxqt#375.

The delay is from 0 to 2s.

* panel: Handle DND correctly for (un)hiding

We have to accept the DragEnter event for next Drag* events to be
delivered -> we need the DragLeave event for correctly hide panel (if
neccessary).

* Polish Panel Auto-hide UI configuration

As discussed at: lxqt#387.
  • Loading branch information
tsujan authored and agaida committed Dec 29, 2016
1 parent 75467c7 commit daca11e
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 102 deletions.
4 changes: 4 additions & 0 deletions panel/config/configpanelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ ConfigPanelWidget::ConfigPanelWidget(LXQtPanel *panel, QWidget *parent) :
mOldHidable = mPanel->hidable();

mOldAnimation = mPanel->animationTime();
mOldShowDelay = mPanel->showDelay();

ui->spinBox_panelSize->setMinimum(PANEL_MINIMUM_SIZE);
ui->spinBox_panelSize->setMaximum(PANEL_MAXIMUM_SIZE);
Expand All @@ -101,6 +102,7 @@ ConfigPanelWidget::ConfigPanelWidget(LXQtPanel *panel, QWidget *parent) :
connect(ui->comboBox_position, SIGNAL(activated(int)), this, SLOT(positionChanged()));
connect(ui->checkBox_hidable, SIGNAL(toggled(bool)), this, SLOT(editChanged()));
connect(ui->spinBox_animation, SIGNAL(valueChanged(int)), this, SLOT(editChanged()));
connect(ui->spinBox_delay, SIGNAL(valueChanged(int)), this, SLOT(editChanged()));

connect(ui->checkBox_customFontColor, SIGNAL(toggled(bool)), this, SLOT(editChanged()));
connect(ui->pushButton_customFontColor, SIGNAL(clicked(bool)), this, SLOT(pickFontColor()));
Expand All @@ -127,6 +129,7 @@ void ConfigPanelWidget::reset()
ui->checkBox_hidable->setChecked(mOldHidable);

ui->spinBox_animation->setValue(mOldAnimation);
ui->spinBox_delay->setValue(mOldShowDelay);

fillComboBox_alignment();
ui->comboBox_alignment->setCurrentIndex(mOldAlignment + 1);
Expand Down Expand Up @@ -261,6 +264,7 @@ void ConfigPanelWidget::editChanged()
mPanel->setPosition(mScreenNum, mPosition, true);
mPanel->setHidable(ui->checkBox_hidable->isChecked(), true);
mPanel->setAnimationTime(ui->spinBox_animation->value(), true);
mPanel->setShowDelay(ui->spinBox_delay->value(), true);

mPanel->setFontColor(ui->checkBox_customFontColor->isChecked() ? mFontColor : QColor(), true);
if (ui->checkBox_customBgColor->isChecked())
Expand Down
1 change: 1 addition & 0 deletions panel/config/configpanelwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ private slots:
ILXQtPanel::Position mOldPosition;
bool mOldHidable;
int mOldAnimation;
int mOldShowDelay;
int mOldScreenNum;
QColor mOldFontColor;
QColor mOldBackgroundColor;
Expand Down
193 changes: 93 additions & 100 deletions panel/config/configpanelwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -201,80 +201,15 @@
<property name="title">
<string>Alignment &amp;&amp; position</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox_hidable">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Auto-hide</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QSpinBox" name="spinBox_animation">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Zero means no animation</string>
</property>
<property name="suffix">
<string> ms</string>
</property>
<property name="maximum">
<number>500</number>
</property>
<property name="singleStep">
<number>50</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_position">
<property name="text">
<string>Position:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_animation">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Zero means no animation</string>
</property>
<property name="text">
<string>Animation duration:</string>
</property>
</widget>
</item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_alignment">
<property name="text">
<string>Alignment:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>5</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1" colspan="3">
<item row="0" column="1">
<widget class="QComboBox" name="comboBox_alignment">
<property name="currentIndex">
<number>1</number>
Expand All @@ -296,9 +231,99 @@
</item>
</widget>
</item>
<item row="2" column="1" colspan="3">
<item row="1" column="0">
<widget class="QLabel" name="label_position">
<property name="text">
<string>Position:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBox_position"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="checkBox_hidable">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>A&amp;uto-hide</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_animation">
<property name="toolTip">
<string>Zero means no animation</string>
</property>
<property name="text">
<string>Animation duration:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>102</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="2">
<widget class="QSpinBox" name="spinBox_animation">
<property name="toolTip">
<string>Zero means no animation</string>
</property>
<property name="suffix">
<string> ms</string>
</property>
<property name="maximum">
<number>500</number>
</property>
<property name="singleStep">
<number>50</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_delay">
<property name="toolTip">
<string>Zero means no delay</string>
</property>
<property name="text">
<string>Show with delay:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="spinBox_delay">
<property name="toolTip">
<string>Zero means no delay</string>
</property>
<property name="suffix">
<string> ms</string>
</property>
<property name="maximum">
<number>2000</number>
</property>
<property name="singleStep">
<number>50</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -636,37 +661,5 @@
</hint>
</hints>
</connection>
<connection>
<sender>checkBox_hidable</sender>
<signal>toggled(bool)</signal>
<receiver>label_animation</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>59</x>
<y>198</y>
</hint>
<hint type="destinationlabel">
<x>211</x>
<y>198</y>
</hint>
</hints>
</connection>
<connection>
<sender>checkBox_hidable</sender>
<signal>toggled(bool)</signal>
<receiver>spinBox_animation</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>59</x>
<y>198</y>
</hint>
<hint type="destinationlabel">
<x>319</x>
<y>198</y>
</hint>
</hints>
</connection>
</connections>
</ui>
25 changes: 23 additions & 2 deletions panel/lxqtpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <QDesktopWidget>
#include <QMenu>
#include <QMessageBox>
#include <QDropEvent>
#include <XdgIcon>
#include <XdgDirs>

Expand Down Expand Up @@ -74,6 +75,7 @@
#define CFG_KEY_PLUGINS "plugins"
#define CFG_KEY_HIDABLE "hidable"
#define CFG_KEY_ANIMATION "animation-duration"
#define CFG_KEY_SHOW_DELAY "show-delay"
#define CFG_KEY_LOCKPANEL "lockPanel"

/************************************************
Expand Down Expand Up @@ -189,6 +191,10 @@ LXQtPanel::LXQtPanel(const QString &configGroup, LXQt::Settings *settings, QWidg
mHideTimer.setInterval(PANEL_HIDE_DELAY);
connect(&mHideTimer, SIGNAL(timeout()), this, SLOT(hidePanelWork()));

mShowDelayTimer.setSingleShot(true);
mShowDelayTimer.setInterval(PANEL_SHOW_DELAY);
connect(&mShowDelayTimer, &QTimer::timeout, [this] { showPanel(mAnimationTime > 0); });

connect(QApplication::desktop(), &QDesktopWidget::resized, this, &LXQtPanel::ensureVisible);
connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, &LXQtPanel::ensureVisible);

Expand Down Expand Up @@ -234,6 +240,7 @@ void LXQtPanel::readSettings()
mHidden = mHidable;

mAnimationTime = mSettings->value(CFG_KEY_ANIMATION, mAnimationTime).toInt();
mShowDelayTimer.setInterval(mSettings->value(CFG_KEY_SHOW_DELAY, mShowDelayTimer.interval()).toInt());

// By default we are using size & count from theme.
setPanelSize(mSettings->value(CFG_KEY_PANELSIZE, PANEL_DEFAULT_SIZE).toInt(), false);
Expand Down Expand Up @@ -306,6 +313,7 @@ void LXQtPanel::saveSettings(bool later)

mSettings->setValue(CFG_KEY_HIDABLE, mHidable);
mSettings->setValue(CFG_KEY_ANIMATION, mAnimationTime);
mSettings->setValue(CFG_KEY_SHOW_DELAY, mShowDelayTimer.interval());

mSettings->setValue(CFG_KEY_LOCKPANEL, mLockPanel);

Expand Down Expand Up @@ -984,14 +992,16 @@ bool LXQtPanel::event(QEvent *event)
break;
}
case QEvent::DragEnter:
event->ignore();
dynamic_cast<QDropEvent *>(event)->setDropAction(Qt::IgnoreAction);
event->accept();
//no break intentionally
case QEvent::Enter:
showPanel(mAnimationTime > 0);
mShowDelayTimer.start();
break;

case QEvent::Leave:
case QEvent::DragLeave:
mShowDelayTimer.stop();
hidePanel();
break;

Expand Down Expand Up @@ -1286,6 +1296,17 @@ void LXQtPanel::setAnimationTime(int animationTime, bool save)
saveSettings(true);
}

void LXQtPanel::setShowDelay(int showDelay, bool save)
{
if (mShowDelayTimer.interval() == showDelay)
return;

mShowDelayTimer.setInterval(showDelay);

if (save)
saveSettings(true);
}

bool LXQtPanel::isPluginSingletonAndRunnig(QString const & pluginId) const
{
Plugin const * plugin = mPlugins->pluginByID(pluginId);
Expand Down
8 changes: 8 additions & 0 deletions panel/lxqtpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class LXQT_PANEL_API LXQtPanel : public QFrame, public ILXQtPanel
int opacity() const { return mOpacity; }
bool hidable() const { return mHidable; }
int animationTime() const { return mAnimationTime; }
int showDelay() const { return mShowDelayTimer.interval(); }

/*!
* \brief Checks if a given Plugin is running and has the
Expand Down Expand Up @@ -295,6 +296,7 @@ public slots:
void setOpacity(int opacity, bool save); //!< \sa setPanelSize()
void setHidable(bool hidable, bool save); //!< \sa setPanelSize()
void setAnimationTime(int animationTime, bool save); //!< \sa setPanelSize()
void setShowDelay(int showDelay, bool save); //!< \sa setPanelSize()

/**
* @brief Saves the current configuration, i.e. writes the current
Expand Down Expand Up @@ -619,6 +621,12 @@ private slots:
* \sa mHidden, mHideTimer, showPanel(), hidePanel(), hidePanelWork()
*/
int mAnimationTime;
/**
* @brief The timer used for showing an auto-hiding panel wih delay.
*
* \sa showPanel()
*/
QTimer mShowDelayTimer;

QColor mFontColor; //!< Font color that is used in the style sheet.
QColor mBackgroundColor; //!< Background color that is used in the style sheet.
Expand Down
2 changes: 2 additions & 0 deletions panel/lxqtpanellimits.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@
#define PANEL_HIDE_DELAY 500
#define PANEL_HIDE_FIRST_TIME (5000 - PANEL_HIDE_DELAY)

#define PANEL_SHOW_DELAY 0

#define SETTINGS_SAVE_DELAY 3000
#endif // LXQTPANELLIMITS_H

0 comments on commit daca11e

Please sign in to comment.