From ce01f2faf667496c4ed2196fc4b370a01aeab2c9 Mon Sep 17 00:00:00 2001 From: rekols Date: Sat, 1 Dec 2018 23:42:38 +0800 Subject: [PATCH] fix: optimize theme panel popup. Change-Id: Iebfc90b03bb14a0cc1882bef9387a36c8f5ce82a --- src/themewidgets/themelistmodel.cpp | 5 +---- src/themewidgets/themepanel.cpp | 18 +++++++++++------- src/themewidgets/themepanel.h | 1 - src/window.cpp | 9 +++++++-- src/window.h | 1 + 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/themewidgets/themelistmodel.cpp b/src/themewidgets/themelistmodel.cpp index ae5aad59..282274c1 100644 --- a/src/themewidgets/themelistmodel.cpp +++ b/src/themewidgets/themelistmodel.cpp @@ -68,13 +68,10 @@ QVariant ThemeListModel::data(const QModelIndex &index, int role) const switch (role) { case ThemeName: return name; - case ThemePath: - return m_themes.at(r).second; - + return path; case FrameNormalColor: return m_frameNormalColor; - case FrameSelectedColor: return m_frameSelectedColor; } diff --git a/src/themewidgets/themepanel.cpp b/src/themewidgets/themepanel.cpp index 66915583..5cd094d3 100644 --- a/src/themewidgets/themepanel.cpp +++ b/src/themewidgets/themepanel.cpp @@ -40,6 +40,8 @@ ThemePanel::ThemePanel(QWidget *parent) layout->setMargin(0); layout->setSpacing(0); + setFixedWidth(250); + QWidget::hide(); connect(m_themeView, &ThemeListView::focusOut, this, &ThemePanel::hide); connect(m_themeView, &ThemeListView::themeChanged, this, &ThemePanel::themeChanged); @@ -89,26 +91,28 @@ void ThemePanel::popup() m_themeView->setFocus(); QRect rect = geometry(); + QRect parentRect = parentWidget()->topLevelWidget()->geometry(); QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry"); animation->setDuration(250); - animation->setEasingCurve(QEasingCurve::InOutCubic); - animation->setStartValue(QRect(rect.x(), rect.y(), 0, rect.height())); - animation->setEndValue(QRect(rect.x(), rect.y(), 250, rect.height())); + animation->setEasingCurve(QEasingCurve::OutQuad); + animation->setStartValue(QRect(parentRect.width(), rect.y(), rect.width(), rect.height())); + animation->setEndValue(QRect(parentRect.width() - rect.width(), rect.y(), rect.width(), rect.height())); animation->start(); connect(animation, &QPropertyAnimation::valueChanged, [=] { m_themeView->adjustScrollbarMargins(); }); - connect(animation, &QPropertyAnimation::finished, this, &ThemePanel::popupFinished); connect(animation, &QPropertyAnimation::finished, animation, &QPropertyAnimation::deleteLater); } void ThemePanel::hide() { QRect rect = geometry(); + QRect parentRect = parentWidget()->topLevelWidget()->geometry(); QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry"); animation->setDuration(250); - animation->setEasingCurve(QEasingCurve::InOutCubic); - animation->setStartValue(QRect(rect.x(), rect.y(), 250, rect.height())); - animation->setEndValue(QRect(rect.x(), rect.y(), 0, rect.height())); + animation->setEasingCurve(QEasingCurve::OutQuad); + animation->setStartValue(QRect(parentRect.width() - rect.width(), rect.y(), rect.width(), rect.height())); + animation->setEndValue(QRect(parentRect.width(), rect.y(), rect.width(), rect.height())); + animation->start(); connect(animation, &QPropertyAnimation::finished, [=] { QWidget::hide(); }); diff --git a/src/themewidgets/themepanel.h b/src/themewidgets/themepanel.h index c01348a9..3e692e35 100644 --- a/src/themewidgets/themepanel.h +++ b/src/themewidgets/themepanel.h @@ -42,7 +42,6 @@ class ThemePanel : public QWidget signals: void themeChanged(const QString &path); - void popupFinished(); protected: void paintEvent(QPaintEvent *); diff --git a/src/window.cpp b/src/window.cpp index 04b73626..57e88925 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -225,8 +225,7 @@ void Window::initTitlebar() connect(saveAsAction, &QAction::triggered, this, &Window::saveAsFile); connect(printAction, &QAction::triggered, this, &Window::popupPrintDialog); connect(settingAction, &QAction::triggered, this, &Window::popupSettingsDialog); - connect(switchThemeAction, &QAction::triggered, m_themePanel, &ThemePanel::popup); - connect(m_themePanel, &ThemePanel::popupFinished, [=] { m_themePanel->setSelectionTheme(m_themePath); }); + connect(switchThemeAction, &QAction::triggered, this, &Window::popupThemePanel); } int Window::getTabIndex(const QString &file) @@ -757,6 +756,12 @@ void Window::popupPrintDialog() preview.exec(); } +void Window::popupThemePanel() +{ + m_themePanel->setSelectionTheme(m_themePath); + m_themePanel->popup(); +} + void Window::toggleFullscreen() { if (isFullScreen()) { diff --git a/src/window.h b/src/window.h index dc742563..14e949c5 100644 --- a/src/window.h +++ b/src/window.h @@ -84,6 +84,7 @@ class Window : public DMainWindow void popupJumpLineBar(); void popupSettingsDialog(); void popupPrintDialog(); + void popupThemePanel(); void toggleFullscreen();