add popup window

Change-Id: I27dbba9bfb4823a530499aa65cbad7e6d181c055
This commit is contained in:
石博文 2016-07-18 09:32:01 +08:00 committed by Hualet Wang
parent b5543494ba
commit 6372853152
6 changed files with 30 additions and 7 deletions

View File

@ -80,7 +80,9 @@ void DockItem::leaveEvent(QEvent *e)
m_hover = false;
m_popupTipsDelayTimer->stop();
PopupWindow->hide();
// auto hide if popup is not model window
if (!PopupWindow->model())
PopupWindow->hide();
update();
@ -135,7 +137,7 @@ void DockItem::showContextMenu()
DBusMenu *menuInter = new DBusMenu(path.path(), this);
connect(menuInter, &DBusMenu::ItemInvoked, this, &DockItem::invokedMenuItem);
connect(menuInter, &DBusMenu::MenuUnregistered, this, &DockItem::menuUnregistered);
connect(menuInter, &DBusMenu::MenuUnregistered, this, &DockItem::requestRefershWindowVisible);
connect(menuInter, &DBusMenu::MenuUnregistered, menuInter, &DBusMenu::deleteLater, Qt::QueuedConnection);
menuInter->ShowMenu(QString(QJsonDocument(menuObject).toJson()));
@ -143,6 +145,10 @@ void DockItem::showContextMenu()
void DockItem::showHoverTips()
{
// another model popup window is alread exists
if (PopupWindow->isVisible() && PopupWindow->model())
return;
QWidget * const content = popupTips();
if (!content)
return;
@ -150,8 +156,11 @@ void DockItem::showHoverTips()
showPopupWindow(content);
}
void DockItem::showPopupWindow(QWidget *content, const bool model)
void DockItem::showPopupWindow(QWidget * const content, const bool model)
{
if (model)
emit requestWindowAutoHide(false);
DockPopupWindow *popup = PopupWindow.get();
QWidget *lastContent = popup->getContent();
if (lastContent)
@ -173,6 +182,16 @@ void DockItem::showPopupWindow(QWidget *content, const bool model)
popup->show(p, model);
}
void DockItem::popupWindowAccept()
{
if (!PopupWindow->isVisible())
return;
PopupWindow->hide();
emit requestWindowAutoHide(true);
}
void DockItem::invokedMenuItem(const QString &itemId, const bool checked)
{
Q_UNUSED(itemId)

View File

@ -32,7 +32,8 @@ public:
signals:
void dragStarted() const;
void menuUnregistered() const;
void requestWindowAutoHide(const bool autoHide) const;
void requestRefershWindowVisible() const;
protected:
void paintEvent(QPaintEvent *e);
@ -46,7 +47,8 @@ protected:
void showContextMenu();
void showHoverTips();
void showPopupWindow(QWidget *content, const bool model = false);
void showPopupWindow(QWidget * const content, const bool model = false);
void popupWindowAccept();
virtual void invokedMenuItem(const QString &itemId, const bool checked);
virtual const QString contextMenu() const;
virtual QWidget *popupTips();

View File

@ -147,7 +147,6 @@ void PluginsItem::mouseClicked()
// request popup applet
QWidget *w = m_pluginInter->itemPopupApplet(m_itemKey);
qDebug() << w;
if (w)
showPopupWindow(w, true);
}

View File

@ -164,7 +164,8 @@ void MainPanel::dropEvent(QDropEvent *e)
void MainPanel::initItemConnection(DockItem *item)
{
connect(item, &DockItem::dragStarted, this, &MainPanel::itemDragStarted);
connect(item, &DockItem::menuUnregistered, this, &MainPanel::requestRefershWindowVisible);
connect(item, &DockItem::requestRefershWindowVisible, this, &MainPanel::requestRefershWindowVisible);
connect(item, &DockItem::requestWindowAutoHide, this, &MainPanel::requestWindowAutoHide);
}
DockItem *MainPanel::itemAt(const QPoint &point)

View File

@ -28,6 +28,7 @@ public:
int position();
signals:
void requestWindowAutoHide(const bool autoHide) const;
void requestRefershWindowVisible() const;
private:

View File

@ -125,6 +125,7 @@ void MainWindow::initConnections()
connect(m_settings, &DockSettings::autoHideChanged, this, &MainWindow::updatePanelVisible);
connect(m_mainPanel, &MainPanel::requestRefershWindowVisible, this, &MainWindow::updatePanelVisible, Qt::QueuedConnection);
connect(m_mainPanel, &MainPanel::requestWindowAutoHide, m_settings, &DockSettings::setAutoHide);
connect(m_positionUpdateTimer, &QTimer::timeout, this, &MainWindow::updatePosition, Qt::QueuedConnection);